Skip to content

Commit 299fc5d

Browse files
author
Roman Snapko
committed
Update step context structure to include stepDisplayName and stepIndex fields
1 parent 5bc8b0c commit 299fc5d

7 files changed

Lines changed: 56 additions & 31 deletions

File tree

packages/react-ui/src/app/features/ai/lib/enrich-context.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ export const createAdditionalContext = (
2323
flowVersionId: flowVersion.id,
2424
runId,
2525
currentStepId: stepData?.id ?? '',
26-
currentStepName: stepData?.name ?? '',
26+
currentStepDisplayName: stepData?.displayName ?? '',
27+
currentStepIndex: stepData?.stepIndex,
2728
steps: [
2829
{
2930
id: stepData?.id ?? '',
30-
stepName: stepData?.name ?? '',
31+
stepDisplayName: stepData?.displayName ?? '',
32+
stepIndex: stepData?.stepIndex,
3133
variables: variables.length > 0 ? variables : undefined,
3234
},
3335
],

packages/server/api/src/app/ai/chat/context-enrichment.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ async function enrichSteps(
181181
} catch (error) {
182182
return {
183183
id: step.id,
184-
stepName: step.stepName,
184+
stepDisplayName: step.stepDisplayName,
185+
stepIndex: step.stepIndex,
185186
variables: step.variables?.map((variable) => ({
186187
name: variable.name,
187188
value: String(error),
@@ -202,7 +203,8 @@ async function enrichStep(
202203
if (!step.variables || step.variables.length === 0) {
203204
return {
204205
id: step.id,
205-
stepName: step.stepName,
206+
stepDisplayName: step.stepDisplayName,
207+
stepIndex: step.stepIndex,
206208
variables: step.variables,
207209
};
208210
}
@@ -215,7 +217,8 @@ async function enrichStep(
215217

216218
return {
217219
id: step.id,
218-
stepName: step.stepName,
220+
stepDisplayName: step.stepDisplayName,
221+
stepIndex: step.stepIndex,
219222
variables: resolvedVariables,
220223
};
221224
}
@@ -257,7 +260,7 @@ async function resolveVariable(
257260
variableExpression: variable.value,
258261
flowVersion: flowData.flow.version,
259262
projectId,
260-
stepName: step.stepName,
263+
stepName: step.stepDisplayName,
261264
stepTestOutputs: flowData.stepTestOutputs,
262265
});
263266

packages/server/api/src/app/ai/chat/prompts.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ export const buildUIContextSection = async (
139139
contextParts.push(`step id ${flowContext.currentStepId}`);
140140
}
141141

142-
if (flowContext.currentStepName) {
143-
contextParts.push(`step name "${flowContext.currentStepName}"`);
142+
if (flowContext.currentStepDisplayName) {
143+
contextParts.push(`step name "${flowContext.currentStepDisplayName}"`);
144+
}
145+
146+
if (flowContext.currentStepIndex) {
147+
contextParts.push(`step index "${flowContext.currentStepIndex}"`);
144148
}
145149

146150
if (contextParts.length === 0) {

packages/server/api/test/unit/ai/context-enrichment.service.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('ContextEnrichmentService', () => {
111111
steps: [
112112
{
113113
id: 'step-1',
114-
stepName: 'step_1',
114+
stepDisplayName: 'step_1',
115115
variables: [
116116
{
117117
name: 'variable1',
@@ -159,7 +159,7 @@ describe('ContextEnrichmentService', () => {
159159
steps: [
160160
{
161161
id: 'step-1',
162-
stepName: 'step_1',
162+
stepDisplayName: 'step_1',
163163
variables: [
164164
{
165165
name: 'variable1',
@@ -196,7 +196,7 @@ describe('ContextEnrichmentService', () => {
196196
steps: [
197197
{
198198
id: 'step-1',
199-
stepName: 'step_1',
199+
stepDisplayName: 'step_1',
200200
},
201201
],
202202
};
@@ -219,7 +219,7 @@ describe('ContextEnrichmentService', () => {
219219
steps: [
220220
{
221221
id: 'step-1',
222-
stepName: 'step_1',
222+
stepDisplayName: 'step_1',
223223
variables: undefined,
224224
},
225225
],
@@ -241,7 +241,7 @@ describe('ContextEnrichmentService', () => {
241241
steps: [
242242
{
243243
id: 'step-1',
244-
stepName: 'step_1',
244+
stepDisplayName: 'step_1',
245245
variables: [
246246
{
247247
name: 'variable1',
@@ -280,7 +280,7 @@ describe('ContextEnrichmentService', () => {
280280
steps: [
281281
{
282282
id: 'step-1',
283-
stepName: 'step_1',
283+
stepDisplayName: 'step_1',
284284
variables: [
285285
{
286286
name: 'variable1',
@@ -305,7 +305,7 @@ describe('ContextEnrichmentService', () => {
305305
steps: [
306306
{
307307
id: 'step-1',
308-
stepName: 'step_1',
308+
stepDisplayName: 'step_1',
309309
variables: [
310310
{
311311
name: 'variable1',
@@ -338,7 +338,8 @@ describe('ContextEnrichmentService', () => {
338338
steps: [
339339
{
340340
id: 'step-1',
341-
stepName: 'step_1',
341+
stepDisplayName: 'step_1',
342+
stepIndex: undefined,
342343
variables: [
343344
{
344345
name: 'variable1',

packages/server/api/test/unit/ai/prompts.service.test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ describe('getSystemPrompt', () => {
257257
steps: [
258258
{
259259
id: 'step1',
260-
stepName: 'step1',
260+
stepDisplayName: 'step1',
261261
variables: [
262262
{ name: 'var1', value: 'value1' },
263263
{ name: 'var2', value: 'value2' },
264264
],
265265
},
266266
{
267267
id: 'step2',
268-
stepName: 'step2',
268+
stepDisplayName: 'step2',
269269
variables: [{ name: 'var3', value: 'value3' }],
270270
},
271271
],
@@ -301,8 +301,8 @@ describe('getSystemPrompt', () => {
301301
flowId: 'test-flow-id',
302302
flowVersionId: 'test-flow-version-id',
303303
steps: [
304-
{ id: 'step1', stepName: 'step1' },
305-
{ id: 'step2', stepName: 'step2' },
304+
{ id: 'step1', stepDisplayName: 'step1' },
305+
{ id: 'step2', stepDisplayName: 'step2' },
306306
],
307307
};
308308

@@ -358,16 +358,16 @@ describe('getSystemPrompt', () => {
358358
steps: [
359359
{
360360
id: 'step1',
361-
stepName: 'step1',
361+
stepDisplayName: 'step1',
362362
variables: [{ name: 'var1', value: 'value1' }],
363363
},
364364
{
365365
id: 'step2',
366-
stepName: 'step2',
366+
stepDisplayName: 'step2',
367367
},
368368
{
369369
id: 'step3',
370-
stepName: 'step3',
370+
stepDisplayName: 'step3',
371371
variables: [{ name: 'var2', value: 'value2' }],
372372
},
373373
],
@@ -549,7 +549,7 @@ describe('buildUIContextSection', () => {
549549
{
550550
flowId: TEST_IDS.flowId,
551551
flowVersionId: TEST_IDS.flowVersionId,
552-
currentStepName: TEST_IDS.currentStepName,
552+
currentStepDisplayName: TEST_IDS.currentStepName,
553553
},
554554
`flow ${TEST_IDS.flowId} with flowVersion ${TEST_IDS.flowVersionId} with step name "${TEST_IDS.currentStepName}"`,
555555
],
@@ -560,7 +560,7 @@ describe('buildUIContextSection', () => {
560560
flowVersionId: TEST_IDS.flowVersionId,
561561
runId: TEST_IDS.runId,
562562
currentStepId: TEST_IDS.currentStepId,
563-
currentStepName: TEST_IDS.currentStepName,
563+
currentStepDisplayName: TEST_IDS.currentStepName,
564564
},
565565
`flow ${TEST_IDS.flowId} with flowVersion ${TEST_IDS.flowVersionId} with run ${TEST_IDS.runId} with step id ${TEST_IDS.currentStepId} with step name "${TEST_IDS.currentStepName}"`,
566566
],
@@ -587,7 +587,7 @@ describe('buildUIContextSection', () => {
587587
flowVersionId: '',
588588
runId: TEST_IDS.runId,
589589
currentStepId: '',
590-
currentStepName: TEST_IDS.currentStepName,
590+
currentStepDisplayName: TEST_IDS.currentStepName,
591591
},
592592
`flow ${TEST_IDS.flowId} with run ${TEST_IDS.runId} with step name "${TEST_IDS.currentStepName}"`,
593593
],
@@ -598,7 +598,7 @@ describe('buildUIContextSection', () => {
598598
flowVersionId: TEST_IDS.flowVersionId,
599599
runId: undefined,
600600
currentStepId: undefined,
601-
currentStepName: undefined,
601+
currentStepDisplayName: undefined,
602602
},
603603
`flow ${TEST_IDS.flowId} with flowVersion ${TEST_IDS.flowVersionId}`,
604604
],
@@ -610,12 +610,14 @@ describe('buildUIContextSection', () => {
610610
steps: [
611611
{
612612
id: 'step1',
613-
stepName: 'Step One',
613+
stepDisplayName: 'Step One',
614+
stepIndex: 1,
614615
variables: [{ name: 'var1', value: 'value1' }],
615616
},
616617
{
617618
id: 'step2',
618-
stepName: 'Step Two',
619+
stepDisplayName: 'Step Two',
620+
stepIndex: 2,
619621
},
620622
],
621623
},

packages/shared/src/lib/ai/chat/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export type VariableContext = Static<typeof VariableContext>;
4343

4444
export const StepContext = Type.Object({
4545
id: Type.String(),
46-
stepName: Type.String(),
46+
stepDisplayName: Type.String(),
47+
stepIndex: Type.Optional(Type.Number()),
4748
variables: Type.Optional(Type.Array(VariableContext)),
4849
});
4950
export type StepContext = Static<typeof StepContext>;
@@ -53,7 +54,8 @@ export const ChatFlowContext = Type.Object({
5354
flowVersionId: Type.String(),
5455
runId: Type.Optional(Type.String()),
5556
currentStepId: Type.Optional(Type.String()),
56-
currentStepName: Type.Optional(Type.String()),
57+
currentStepDisplayName: Type.Optional(Type.String()),
58+
currentStepIndex: Type.Optional(Type.Number()),
5759
currentStepData: Type.Optional(Type.Any()),
5860
steps: Type.Array(StepContext),
5961
});

packages/shared/src/lib/flows/flow-helper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,16 @@ function getStep(
336336
);
337337
}
338338

339+
function getStepById(
340+
flowVersion: FlowVersion,
341+
stepId: string,
342+
): Action | TriggerWithOptionalId | undefined {
343+
if (flowVersion.trigger.id === stepId) {
344+
return flowVersion.trigger;
345+
}
346+
return getAllSteps(flowVersion.trigger).find((step) => step.id === stepId);
347+
}
348+
339349
function getStepWithIndex(
340350
flowVersion: FlowVersion,
341351
stepName: string,
@@ -1314,6 +1324,7 @@ export const flowHelper = {
13141324
},
13151325

13161326
getStep,
1327+
getStepById,
13171328
getStepWithIndex,
13181329
isAction,
13191330
isTrigger,

0 commit comments

Comments
 (0)