Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions packages/core/src/Components/APIEndpoint.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,7 @@ async function resolveTemplateVariables(data: any, input: any, agent: Agent): Pr
if (isKeyTemplateVar(value as string)) {
data[key] = await parseKey(value as string, agent.teamId);
} else if (isTemplateVar(value as string)) {
// Parse using input values first, then agent variables.
// This correctly resolves cases where input values reference agent variables with the same name.
// Example: agent variables { user_id: "123" }, input { user_id: "{{user_id}}" }.
data[key] = TemplateString(value as string)
.parse(input)
.parse(agent.agentVariables).result;
data[key] = TemplateString(value as string).parse(input).result;
}
}

Expand Down
15 changes: 14 additions & 1 deletion packages/core/src/Components/Component.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IAgent as Agent } from '@sre/types/Agent.types';
import { Logger } from '@sre/helpers/Log.helper';
import { performTypeInference } from '@sre/helpers/TypeChecker.helper';
import { hookableClass, hookAsync } from '@sre/Core/HookService';
import { TemplateString } from '@sre/helpers/TemplateString.helper';

export type TComponentSchema = {
name: string;
Expand Down Expand Up @@ -123,7 +124,19 @@ export class Component {
if (agent.isKilled()) {
throw new Error('Agent killed');
}
const _input = await performTypeInference(input, config?.inputs, agent);

let _input = {};

// #region Resolve agent variables so that:
// - type inference works correctly
// - we don’t need a separate resolution step when the variable name
// matches the component input name
for (let [key, value] of Object.entries(input)) {
_input[key] = TemplateString(value as string).parse(agent.agentVariables).result;
}
// #endregion

_input = await performTypeInference(_input, config?.inputs, agent);

// modify the input object for component's process method
for (const [key, value] of Object.entries(_input)) {
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/Components/ServerlessCode.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export class ServerlessCode extends Component {
let codeInputs = {};

for (let field of componentInputs) {
// Parse using input values first, then agent variables.
// This correctly resolves cases where input values reference agent variables with the same name.
// Example: agent variables { user_id: "123" }, input { user_id: "{{user_id}}" }.
const inputValue = TemplateString(input[field.name]).parse(input).parse(agent.agentVariables).result;
const inputValue = TemplateString(input[field.name]).parse(input).result;

const _type = typeof inputValue;

Expand Down