Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/services/live/ContextTransformerExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class ContextTransformerExecutor {
}

// Build a raw context with the updated stage vars for condition evaluation
const conditionContext = this.contextBuilder.buildRawContext(conversation, stage, {}, {});
const conditionContext = this.contextBuilder.buildRawContext(conversation, stage, {}, {}, undefined, session.clientConnection.connectionType);

// Find and return stage actions triggered by variable changes
const triggeredActions = await this.findTriggeredActions(session, variableChangeEvents, stage.actions || {}, conditionContext);
Expand Down
21 changes: 11 additions & 10 deletions src/services/live/ConversationContextBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export class ConversationContextBuilder {
time: this.buildTimeContext((conversation.metadata?.timezone as string | undefined) ?? 'UTC'),
project: this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null),
channel,
stage: await this.buildStageContext(stage, this.buildRawContext(conversation, stage!, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null))),
stage: await this.buildStageContext(stage, this.buildRawContext(conversation, stage!, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null), channel)),
};

// Get all events from database; history is a filtered view on message events
Expand Down Expand Up @@ -601,7 +601,7 @@ export class ConversationContextBuilder {
time: this.buildTimeContext((conversation.metadata?.timezone as string | undefined) ?? 'UTC'),
project: this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null),
channel,
stage: await this.buildStageContext(stage, this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null))),
stage: await this.buildStageContext(stage, this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null), channel)),
};

// Load conversation history so templates can reference prior messages
Expand Down Expand Up @@ -655,7 +655,7 @@ export class ConversationContextBuilder {
]);

const projectContext = this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null);
const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, projectContext);
const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, projectContext, channel);

const context: ConversationContext = {
conversationId: conversation.id,
Expand Down Expand Up @@ -720,7 +720,7 @@ export class ConversationContextBuilder {
});

// Build raw context for condition evaluation
const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null));
const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null), channel);
rawContext.userInput = userInput;
rawContext.originalUserInput = originalUserInput;

Expand Down Expand Up @@ -792,7 +792,7 @@ export class ConversationContextBuilder {
]);

// Build raw context for condition evaluation
const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null));
const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null), channel);
rawContext.userInput = userInput;
rawContext.originalUserInput = originalUserInput;

Expand Down Expand Up @@ -888,7 +888,7 @@ export class ConversationContextBuilder {
}),
]);

const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null));
const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null), channel);
rawContext.userInput = userInput;
rawContext.originalUserInput = originalUserInput;

Expand Down Expand Up @@ -961,7 +961,7 @@ export class ConversationContextBuilder {
columns: { constants: true, timezone: true, languageCode: true },
});

const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null));
const rawContext = this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null), channel);
rawContext.userInput = userInput;
rawContext.originalUserInput = originalUserInput;

Expand Down Expand Up @@ -1093,7 +1093,7 @@ export class ConversationContextBuilder {
time: this.buildTimeContext((conversation.metadata?.timezone as string | undefined) ?? 'UTC'),
project: this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null),
channel,
stage: await this.buildStageContext(stage, this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null))),
stage: await this.buildStageContext(stage, this.buildRawContext(conversation, stage, user?.profile || {}, project?.constants || {}, this.buildProjectContext(project?.timezone ?? null, project?.languageCode ?? null), channel)),
};

// Get all events from database; history is a filtered view on message events
Expand Down Expand Up @@ -1121,7 +1121,7 @@ export class ConversationContextBuilder {
* @param stage - Stage entity
* @returns ConversationContext with only raw data and no filtering for actions or stage context.
*/
public buildRawContext(conversation: Conversation, stage: Stage, userProfile: Record<string, any>, consts: Record<string, any> = {}, projectContext: ConversationContext['project'] = { timezone: null, languageCode: null, language: null }): ConversationContext {
public buildRawContext(conversation: Conversation, stage: Stage, userProfile: Record<string, any>, consts: Record<string, any> = {}, projectContext: ConversationContext['project'] = { timezone: null, languageCode: null, language: null }, channel?: ApiKeyChannel): ConversationContext {
return {
conversationId: conversation.id,
projectId: conversation.projectId,
Expand Down Expand Up @@ -1156,7 +1156,8 @@ export class ConversationContextBuilder {
useKnowledge: stage.useKnowledge,
enterBehavior: stage.enterBehavior,
metadata: stage.metadata || undefined,
}
},
channel,
};
}
}
Loading