@loopstack/advanced-workflows-examples 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -0
- package/dist/advanced-workflows-examples.module.d.ts +3 -0
- package/dist/advanced-workflows-examples.module.d.ts.map +1 -0
- package/dist/advanced-workflows-examples.module.js +95 -0
- package/dist/advanced-workflows-examples.module.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/workflows/agent-error-handling/agent-error-handling-failing-sub.workflow.d.ts +5 -0
- package/dist/workflows/agent-error-handling/agent-error-handling-failing-sub.workflow.d.ts.map +1 -0
- package/dist/workflows/agent-error-handling/agent-error-handling-failing-sub.workflow.js +29 -0
- package/dist/workflows/agent-error-handling/agent-error-handling-failing-sub.workflow.js.map +1 -0
- package/dist/workflows/agent-error-handling/agent-error-handling.ui.yaml +6 -0
- package/dist/workflows/agent-error-handling/agent-error-handling.workflow.d.ts +34 -0
- package/dist/workflows/agent-error-handling/agent-error-handling.workflow.d.ts.map +1 -0
- package/dist/workflows/agent-error-handling/agent-error-handling.workflow.js +158 -0
- package/dist/workflows/agent-error-handling/agent-error-handling.workflow.js.map +1 -0
- package/dist/workflows/agent-error-handling/templates/system.md +12 -0
- package/dist/workflows/agent-error-handling/tools/failing-sub-workflow.tool.d.ts +12 -0
- package/dist/workflows/agent-error-handling/tools/failing-sub-workflow.tool.d.ts.map +1 -0
- package/dist/workflows/agent-error-handling/tools/failing-sub-workflow.tool.js +40 -0
- package/dist/workflows/agent-error-handling/tools/failing-sub-workflow.tool.js.map +1 -0
- package/dist/workflows/agent-error-handling/tools/runtime-error.tool.d.ts +11 -0
- package/dist/workflows/agent-error-handling/tools/runtime-error.tool.d.ts.map +1 -0
- package/dist/workflows/agent-error-handling/tools/runtime-error.tool.js +33 -0
- package/dist/workflows/agent-error-handling/tools/runtime-error.tool.js.map +1 -0
- package/dist/workflows/agent-error-handling/tools/strict-schema.tool.d.ts +10 -0
- package/dist/workflows/agent-error-handling/tools/strict-schema.tool.d.ts.map +1 -0
- package/dist/workflows/agent-error-handling/tools/strict-schema.tool.js +31 -0
- package/dist/workflows/agent-error-handling/tools/strict-schema.tool.js.map +1 -0
- package/dist/workflows/batch-processing/batch-processing-example.workflow.d.ts +27 -0
- package/dist/workflows/batch-processing/batch-processing-example.workflow.d.ts.map +1 -0
- package/dist/workflows/batch-processing/batch-processing-example.workflow.js +93 -0
- package/dist/workflows/batch-processing/batch-processing-example.workflow.js.map +1 -0
- package/dist/workflows/custom-tool/custom-tool-example.ui.yaml +6 -0
- package/dist/workflows/custom-tool/custom-tool-example.workflow.d.ts +23 -0
- package/dist/workflows/custom-tool/custom-tool-example.workflow.d.ts.map +1 -0
- package/dist/workflows/custom-tool/custom-tool-example.workflow.js +95 -0
- package/dist/workflows/custom-tool/custom-tool-example.workflow.js.map +1 -0
- package/dist/workflows/custom-tool/index.d.ts +2 -0
- package/dist/workflows/custom-tool/index.d.ts.map +1 -0
- package/dist/workflows/custom-tool/index.js +18 -0
- package/dist/workflows/custom-tool/index.js.map +1 -0
- package/dist/workflows/custom-tool/services/math.service.d.ts +4 -0
- package/dist/workflows/custom-tool/services/math.service.d.ts.map +1 -0
- package/dist/workflows/custom-tool/services/math.service.js +20 -0
- package/dist/workflows/custom-tool/services/math.service.js.map +1 -0
- package/dist/workflows/custom-tool/tools/counter.tool.d.ts +7 -0
- package/dist/workflows/custom-tool/tools/counter.tool.d.ts.map +1 -0
- package/dist/workflows/custom-tool/tools/counter.tool.js +25 -0
- package/dist/workflows/custom-tool/tools/counter.tool.js.map +1 -0
- package/dist/workflows/custom-tool/tools/index.d.ts +3 -0
- package/dist/workflows/custom-tool/tools/index.d.ts.map +1 -0
- package/dist/workflows/custom-tool/tools/index.js +19 -0
- package/dist/workflows/custom-tool/tools/index.js.map +1 -0
- package/dist/workflows/custom-tool/tools/math-sum.tool.d.ts +16 -0
- package/dist/workflows/custom-tool/tools/math-sum.tool.d.ts.map +1 -0
- package/dist/workflows/custom-tool/tools/math-sum.tool.js +42 -0
- package/dist/workflows/custom-tool/tools/math-sum.tool.js.map +1 -0
- package/dist/workflows/dynamic-routing/dynamic-routing-example.workflow.d.ts +24 -0
- package/dist/workflows/dynamic-routing/dynamic-routing-example.workflow.d.ts.map +1 -0
- package/dist/workflows/dynamic-routing/dynamic-routing-example.workflow.js +115 -0
- package/dist/workflows/dynamic-routing/dynamic-routing-example.workflow.js.map +1 -0
- package/dist/workflows/error-retry/error-retry-example.ui.yaml +25 -0
- package/dist/workflows/error-retry/error-retry-example.workflow.d.ts +43 -0
- package/dist/workflows/error-retry/error-retry-example.workflow.d.ts.map +1 -0
- package/dist/workflows/error-retry/error-retry-example.workflow.js +343 -0
- package/dist/workflows/error-retry/error-retry-example.workflow.js.map +1 -0
- package/dist/workflows/error-retry/failing-child.workflow.d.ts +5 -0
- package/dist/workflows/error-retry/failing-child.workflow.d.ts.map +1 -0
- package/dist/workflows/error-retry/failing-child.workflow.js +36 -0
- package/dist/workflows/error-retry/failing-child.workflow.js.map +1 -0
- package/dist/workflows/error-retry/tools/slow.tool.d.ts +10 -0
- package/dist/workflows/error-retry/tools/slow.tool.d.ts.map +1 -0
- package/dist/workflows/error-retry/tools/slow.tool.js +27 -0
- package/dist/workflows/error-retry/tools/slow.tool.js.map +1 -0
- package/dist/workflows/error-retry/tools/step1.tool.d.ts +6 -0
- package/dist/workflows/error-retry/tools/step1.tool.d.ts.map +1 -0
- package/dist/workflows/error-retry/tools/step1.tool.js +26 -0
- package/dist/workflows/error-retry/tools/step1.tool.js.map +1 -0
- package/dist/workflows/error-retry/tools/step2.tool.d.ts +10 -0
- package/dist/workflows/error-retry/tools/step2.tool.d.ts.map +1 -0
- package/dist/workflows/error-retry/tools/step2.tool.js +29 -0
- package/dist/workflows/error-retry/tools/step2.tool.js.map +1 -0
- package/dist/workflows/fan-out/fan-out-example.workflow.d.ts +12 -0
- package/dist/workflows/fan-out/fan-out-example.workflow.d.ts.map +1 -0
- package/dist/workflows/fan-out/fan-out-example.workflow.js +68 -0
- package/dist/workflows/fan-out/fan-out-example.workflow.js.map +1 -0
- package/dist/workflows/module-config/consumers/default-greeting.module.d.ts +3 -0
- package/dist/workflows/module-config/consumers/default-greeting.module.d.ts.map +1 -0
- package/dist/workflows/module-config/consumers/default-greeting.module.js +21 -0
- package/dist/workflows/module-config/consumers/default-greeting.module.js.map +1 -0
- package/dist/workflows/module-config/consumers/default-greeting.workflow.d.ts +9 -0
- package/dist/workflows/module-config/consumers/default-greeting.workflow.d.ts.map +1 -0
- package/dist/workflows/module-config/consumers/default-greeting.workflow.js +47 -0
- package/dist/workflows/module-config/consumers/default-greeting.workflow.js.map +1 -0
- package/dist/workflows/module-config/consumers/french-greeting.module.d.ts +3 -0
- package/dist/workflows/module-config/consumers/french-greeting.module.d.ts.map +1 -0
- package/dist/workflows/module-config/consumers/french-greeting.module.js +23 -0
- package/dist/workflows/module-config/consumers/french-greeting.module.js.map +1 -0
- package/dist/workflows/module-config/consumers/french-greeting.workflow.d.ts +9 -0
- package/dist/workflows/module-config/consumers/french-greeting.workflow.d.ts.map +1 -0
- package/dist/workflows/module-config/consumers/french-greeting.workflow.js +47 -0
- package/dist/workflows/module-config/consumers/french-greeting.workflow.js.map +1 -0
- package/dist/workflows/module-config/consumers/german-greeting.module.d.ts +3 -0
- package/dist/workflows/module-config/consumers/german-greeting.module.d.ts.map +1 -0
- package/dist/workflows/module-config/consumers/german-greeting.module.js +23 -0
- package/dist/workflows/module-config/consumers/german-greeting.module.js.map +1 -0
- package/dist/workflows/module-config/consumers/german-greeting.workflow.d.ts +9 -0
- package/dist/workflows/module-config/consumers/german-greeting.workflow.d.ts.map +1 -0
- package/dist/workflows/module-config/consumers/german-greeting.workflow.js +47 -0
- package/dist/workflows/module-config/consumers/german-greeting.workflow.js.map +1 -0
- package/dist/workflows/module-config/consumers/nested-greeting.module.d.ts +3 -0
- package/dist/workflows/module-config/consumers/nested-greeting.module.d.ts.map +1 -0
- package/dist/workflows/module-config/consumers/nested-greeting.module.js +23 -0
- package/dist/workflows/module-config/consumers/nested-greeting.module.js.map +1 -0
- package/dist/workflows/module-config/consumers/nested-greeting.workflow.d.ts +9 -0
- package/dist/workflows/module-config/consumers/nested-greeting.workflow.d.ts.map +1 -0
- package/dist/workflows/module-config/consumers/nested-greeting.workflow.js +47 -0
- package/dist/workflows/module-config/consumers/nested-greeting.workflow.js.map +1 -0
- package/dist/workflows/module-config/greeter/greeter-agent.module.d.ts +8 -0
- package/dist/workflows/module-config/greeter/greeter-agent.module.d.ts.map +1 -0
- package/dist/workflows/module-config/greeter/greeter-agent.module.js +36 -0
- package/dist/workflows/module-config/greeter/greeter-agent.module.js.map +1 -0
- package/dist/workflows/module-config/greeter/greeter.constants.d.ts +6 -0
- package/dist/workflows/module-config/greeter/greeter.constants.d.ts.map +1 -0
- package/dist/workflows/module-config/greeter/greeter.constants.js +5 -0
- package/dist/workflows/module-config/greeter/greeter.constants.js.map +1 -0
- package/dist/workflows/module-config/greeter/greeter.module.d.ts +7 -0
- package/dist/workflows/module-config/greeter/greeter.module.d.ts.map +1 -0
- package/dist/workflows/module-config/greeter/greeter.module.js +47 -0
- package/dist/workflows/module-config/greeter/greeter.module.js.map +1 -0
- package/dist/workflows/module-config/greeter/greeter.tool.d.ts +17 -0
- package/dist/workflows/module-config/greeter/greeter.tool.d.ts.map +1 -0
- package/dist/workflows/module-config/greeter/greeter.tool.js +45 -0
- package/dist/workflows/module-config/greeter/greeter.tool.js.map +1 -0
- package/dist/workflows/module-config/greeter/index.d.ts +4 -0
- package/dist/workflows/module-config/greeter/index.d.ts.map +1 -0
- package/dist/workflows/module-config/greeter/index.js +20 -0
- package/dist/workflows/module-config/greeter/index.js.map +1 -0
- package/dist/workflows/sequence/sequence-example.workflow.d.ts +12 -0
- package/dist/workflows/sequence/sequence-example.workflow.d.ts.map +1 -0
- package/dist/workflows/sequence/sequence-example.workflow.js +67 -0
- package/dist/workflows/sequence/sequence-example.workflow.js.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-error-handling.workflow.d.ts +10 -0
- package/dist/workflows/sub-workflow/sub-workflow-error-handling.workflow.d.ts.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-error-handling.workflow.js +77 -0
- package/dist/workflows/sub-workflow/sub-workflow-error-handling.workflow.js.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-failing-sub.workflow.d.ts +5 -0
- package/dist/workflows/sub-workflow/sub-workflow-failing-sub.workflow.d.ts.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-failing-sub.workflow.js +36 -0
- package/dist/workflows/sub-workflow/sub-workflow-failing-sub.workflow.js.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-parent.workflow.d.ts +15 -0
- package/dist/workflows/sub-workflow/sub-workflow-parent.workflow.d.ts.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-parent.workflow.js +84 -0
- package/dist/workflows/sub-workflow/sub-workflow-parent.workflow.js.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-show-modes.workflow.d.ts +17 -0
- package/dist/workflows/sub-workflow/sub-workflow-show-modes.workflow.d.ts.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-show-modes.workflow.js +93 -0
- package/dist/workflows/sub-workflow/sub-workflow-show-modes.workflow.js.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-sub.workflow.d.ts +5 -0
- package/dist/workflows/sub-workflow/sub-workflow-sub.workflow.d.ts.map +1 -0
- package/dist/workflows/sub-workflow/sub-workflow-sub.workflow.js +36 -0
- package/dist/workflows/sub-workflow/sub-workflow-sub.workflow.js.map +1 -0
- package/dist/workflows/ui-documents/ui-documents-example.workflow.d.ts +6 -0
- package/dist/workflows/ui-documents/ui-documents-example.workflow.d.ts.map +1 -0
- package/dist/workflows/ui-documents/ui-documents-example.workflow.js +51 -0
- package/dist/workflows/ui-documents/ui-documents-example.workflow.js.map +1 -0
- package/dist/workflows/workflow-state/tool-results-example.workflow.d.ts +10 -0
- package/dist/workflows/workflow-state/tool-results-example.workflow.d.ts.map +1 -0
- package/dist/workflows/workflow-state/tool-results-example.workflow.js +48 -0
- package/dist/workflows/workflow-state/tool-results-example.workflow.js.map +1 -0
- package/dist/workflows/workflow-state/workflow-state-example.workflow.d.ts +11 -0
- package/dist/workflows/workflow-state/workflow-state-example.workflow.d.ts.map +1 -0
- package/dist/workflows/workflow-state/workflow-state-example.workflow.js +51 -0
- package/dist/workflows/workflow-state/workflow-state-example.workflow.js.map +1 -0
- package/package.json +56 -0
- package/src/advanced-workflows-examples.module.ts +83 -0
- package/src/index.ts +17 -0
- package/src/workflows/agent-error-handling/agent-error-handling-failing-sub.workflow.ts +13 -0
- package/src/workflows/agent-error-handling/agent-error-handling.ui.yaml +6 -0
- package/src/workflows/agent-error-handling/agent-error-handling.workflow.ts +130 -0
- package/src/workflows/agent-error-handling/templates/system.md +12 -0
- package/src/workflows/agent-error-handling/tools/failing-sub-workflow.tool.ts +32 -0
- package/src/workflows/agent-error-handling/tools/runtime-error.tool.ts +29 -0
- package/src/workflows/agent-error-handling/tools/strict-schema.tool.ts +21 -0
- package/src/workflows/batch-processing/batch-processing-example.workflow.ts +79 -0
- package/src/workflows/custom-tool/custom-tool-example.ui.yaml +6 -0
- package/src/workflows/custom-tool/custom-tool-example.workflow.ts +87 -0
- package/src/workflows/custom-tool/index.ts +1 -0
- package/src/workflows/custom-tool/services/math.service.ts +8 -0
- package/src/workflows/custom-tool/tools/counter.tool.ts +16 -0
- package/src/workflows/custom-tool/tools/index.ts +2 -0
- package/src/workflows/custom-tool/tools/math-sum.tool.ts +30 -0
- package/src/workflows/dynamic-routing/dynamic-routing-example.workflow.ts +86 -0
- package/src/workflows/error-retry/error-retry-example.ui.yaml +25 -0
- package/src/workflows/error-retry/error-retry-example.workflow.ts +286 -0
- package/src/workflows/error-retry/failing-child.workflow.ts +20 -0
- package/src/workflows/error-retry/tools/slow.tool.ts +17 -0
- package/src/workflows/error-retry/tools/step1.tool.ts +16 -0
- package/src/workflows/error-retry/tools/step2.tool.ts +20 -0
- package/src/workflows/fan-out/fan-out-example.workflow.ts +58 -0
- package/src/workflows/module-config/consumers/default-greeting.module.ts +12 -0
- package/src/workflows/module-config/consumers/default-greeting.workflow.ts +24 -0
- package/src/workflows/module-config/consumers/french-greeting.module.ts +14 -0
- package/src/workflows/module-config/consumers/french-greeting.workflow.ts +25 -0
- package/src/workflows/module-config/consumers/german-greeting.module.ts +14 -0
- package/src/workflows/module-config/consumers/german-greeting.workflow.ts +24 -0
- package/src/workflows/module-config/consumers/nested-greeting.module.ts +15 -0
- package/src/workflows/module-config/consumers/nested-greeting.workflow.ts +25 -0
- package/src/workflows/module-config/greeter/greeter-agent.module.ts +33 -0
- package/src/workflows/module-config/greeter/greeter.constants.ts +6 -0
- package/src/workflows/module-config/greeter/greeter.module.ts +48 -0
- package/src/workflows/module-config/greeter/greeter.tool.ts +38 -0
- package/src/workflows/module-config/greeter/index.ts +3 -0
- package/src/workflows/sequence/sequence-example.workflow.ts +57 -0
- package/src/workflows/sub-workflow/sub-workflow-error-handling.workflow.ts +63 -0
- package/src/workflows/sub-workflow/sub-workflow-failing-sub.workflow.ts +21 -0
- package/src/workflows/sub-workflow/sub-workflow-parent.workflow.ts +58 -0
- package/src/workflows/sub-workflow/sub-workflow-show-modes.workflow.ts +73 -0
- package/src/workflows/sub-workflow/sub-workflow-sub.workflow.ts +17 -0
- package/src/workflows/ui-documents/ui-documents-example.workflow.ts +43 -0
- package/src/workflows/workflow-state/tool-results-example.workflow.ts +28 -0
- package/src/workflows/workflow-state/workflow-state-example.workflow.ts +33 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Inject } from '@nestjs/common';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { BaseTool, Tool, ToolEnvelope } from '@loopstack/common';
|
|
4
|
+
import { GREETER_CONFIG } from './greeter.constants.js';
|
|
5
|
+
import type { GreeterConfig } from './greeter.constants.js';
|
|
6
|
+
|
|
7
|
+
export const GreeterArgsSchema = z.object({
|
|
8
|
+
name: z.string().describe('Name to greet'),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
type GreeterArgs = z.infer<typeof GreeterArgsSchema>;
|
|
12
|
+
|
|
13
|
+
export interface GreetResult {
|
|
14
|
+
message: string;
|
|
15
|
+
language: string;
|
|
16
|
+
greeting: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Tool({
|
|
20
|
+
name: 'greeter',
|
|
21
|
+
schema: GreeterArgsSchema,
|
|
22
|
+
})
|
|
23
|
+
export class GreeterTool extends BaseTool<GreeterArgs, object, GreetResult> {
|
|
24
|
+
@Inject(GREETER_CONFIG) private readonly config: GreeterConfig;
|
|
25
|
+
|
|
26
|
+
protected async handle(args: GreeterArgs): Promise<ToolEnvelope<GreetResult>> {
|
|
27
|
+
const language = this.config.language ?? 'en';
|
|
28
|
+
const greeting = this.config.greeting ?? 'Hello';
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
data: {
|
|
32
|
+
message: `${greeting}, ${args.name}! [language=${language}]`,
|
|
33
|
+
language,
|
|
34
|
+
greeting,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BaseWorkflow, MessageDocument, Transition, type TransitionInput, Workflow } from '@loopstack/common';
|
|
3
|
+
import { SequenceResultSchema, SequenceWorkflow } from '@loopstack/core';
|
|
4
|
+
|
|
5
|
+
type SequenceResultData = z.infer<typeof SequenceResultSchema>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Demonstrates `SequenceWorkflow` — runs three sub-workflows one at a time and
|
|
9
|
+
* receives a single aggregated callback after the last one completes.
|
|
10
|
+
*/
|
|
11
|
+
@Workflow({
|
|
12
|
+
title: 'Advanced - Sequence Example',
|
|
13
|
+
description:
|
|
14
|
+
'Runs multiple sub-workflows sequentially via SequenceWorkflow and aggregates results in a single callback.',
|
|
15
|
+
})
|
|
16
|
+
export class RunSubWorkflowExampleSequenceWorkflow extends BaseWorkflow {
|
|
17
|
+
constructor(private readonly sequence: SequenceWorkflow) {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Transition({ to: 'awaiting' })
|
|
22
|
+
async launch(_state: Record<string, unknown>) {
|
|
23
|
+
await this.sequence.run(
|
|
24
|
+
{
|
|
25
|
+
items: [
|
|
26
|
+
{ workflow: 'run_sub_workflow_example_sub', label: 'step-1' },
|
|
27
|
+
{ workflow: 'run_sub_workflow_example_sub', label: 'step-2' },
|
|
28
|
+
{ workflow: 'run_sub_workflow_example_sub', label: 'step-3' },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
{ callback: { transition: 'onComplete' }, label: 'Sequence children', show: 'link' },
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Transition({
|
|
36
|
+
from: 'awaiting',
|
|
37
|
+
to: 'end',
|
|
38
|
+
wait: true,
|
|
39
|
+
schema: SequenceResultSchema,
|
|
40
|
+
})
|
|
41
|
+
async onComplete(state: Record<string, unknown>, input: TransitionInput<SequenceResultData>) {
|
|
42
|
+
const results = input.data.results as Array<{ key: string; data?: unknown }>;
|
|
43
|
+
|
|
44
|
+
for (const entry of results) {
|
|
45
|
+
const data = (entry.data ?? {}) as { message?: string };
|
|
46
|
+
await this.documentStore.save(MessageDocument, {
|
|
47
|
+
role: 'assistant',
|
|
48
|
+
text: `Sequence ${entry.key}: ${data.message ?? '(no message)'}`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.setResult({ hasErrors: input.data.hasErrors, errorCount: input.data.errorCount } as unknown as Record<
|
|
53
|
+
string,
|
|
54
|
+
unknown
|
|
55
|
+
>);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BaseWorkflow, MessageDocument, Transition, type TransitionInput, Workflow } from '@loopstack/common';
|
|
2
|
+
import { RunSubWorkflowExampleFailingSubWorkflow } from './sub-workflow-failing-sub.workflow';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Launches the failing sub-workflow in both `show: 'inline'` and `show: 'link'` modes so the
|
|
6
|
+
* error UI can be inspected in each. The parent branches on `input.hasError` and surfaces
|
|
7
|
+
* `input.errorMessage` to demonstrate that the envelope carries the failure context — no
|
|
8
|
+
* need to query the child entity separately.
|
|
9
|
+
*/
|
|
10
|
+
@Workflow({
|
|
11
|
+
title: 'Advanced - Sub-Workflow Error Handling Example',
|
|
12
|
+
description:
|
|
13
|
+
'Demonstrates handling failed child workflows via input.hasError and input.errorMessage on the callback envelope.',
|
|
14
|
+
})
|
|
15
|
+
export class RunSubWorkflowExampleErrorHandlingWorkflow extends BaseWorkflow {
|
|
16
|
+
constructor(private readonly failingSub: RunSubWorkflowExampleFailingSubWorkflow) {
|
|
17
|
+
super();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Transition({ to: 'inline_awaiting' })
|
|
21
|
+
async launchInline(_state: Record<string, unknown>) {
|
|
22
|
+
await this.failingSub.run(
|
|
23
|
+
{},
|
|
24
|
+
{ callback: { transition: 'onInlineFinished' }, show: 'inline', label: 'Failing sub-workflow (inline)' },
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Transition({
|
|
29
|
+
from: 'inline_awaiting',
|
|
30
|
+
to: 'link_awaiting',
|
|
31
|
+
wait: true,
|
|
32
|
+
})
|
|
33
|
+
async onInlineFinished(state: Record<string, unknown>, input: TransitionInput) {
|
|
34
|
+
await this.documentStore.save(MessageDocument, {
|
|
35
|
+
role: 'assistant',
|
|
36
|
+
text: input.hasError
|
|
37
|
+
? `Inline child failed (status="${input.status}"): ${input.errorMessage ?? 'unknown error'}. Trying the same failing child with show: 'link' next.`
|
|
38
|
+
: `Inline child finished normally (status="${input.status}").`,
|
|
39
|
+
});
|
|
40
|
+
await this.failingSub.run(
|
|
41
|
+
{},
|
|
42
|
+
{ callback: { transition: 'onLinkFinished' }, show: 'link', label: 'Failing sub-workflow (link)' },
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Transition({
|
|
47
|
+
from: 'link_awaiting',
|
|
48
|
+
to: 'end',
|
|
49
|
+
wait: true,
|
|
50
|
+
})
|
|
51
|
+
async onLinkFinished(_state: Record<string, unknown>, input: TransitionInput) {
|
|
52
|
+
await this.documentStore.save(MessageDocument, {
|
|
53
|
+
role: 'assistant',
|
|
54
|
+
text: input.hasError
|
|
55
|
+
? `Link child failed (status="${input.status}"): ${input.errorMessage ?? 'unknown error'}. The parent recovered gracefully.`
|
|
56
|
+
: `Link child finished normally (status="${input.status}").`,
|
|
57
|
+
});
|
|
58
|
+
this.setResult({ childStatus: input.status, childErrorMessage: input.errorMessage } as unknown as Record<
|
|
59
|
+
string,
|
|
60
|
+
unknown
|
|
61
|
+
>);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseWorkflow, MessageDocument, Transition, Workflow } from '@loopstack/common';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A sub-workflow that always throws — useful for exercising the parent-side error UI
|
|
5
|
+
* (red link card, inline error message) and for verifying that callbacks still fire
|
|
6
|
+
* with `status: 'failed'` when a child crashes.
|
|
7
|
+
*/
|
|
8
|
+
@Workflow({
|
|
9
|
+
name: 'run_sub_workflow_example_failing_sub',
|
|
10
|
+
title: 'Advanced - Failing Sub-Workflow (child)',
|
|
11
|
+
})
|
|
12
|
+
export class RunSubWorkflowExampleFailingSubWorkflow extends BaseWorkflow {
|
|
13
|
+
@Transition({ to: 'end' })
|
|
14
|
+
async fail(_state: Record<string, unknown>) {
|
|
15
|
+
await this.documentStore.save(MessageDocument, {
|
|
16
|
+
role: 'assistant',
|
|
17
|
+
text: 'About to throw — this child always fails on purpose.',
|
|
18
|
+
});
|
|
19
|
+
throw new Error('Demo failure: this sub-workflow is wired to always throw.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BaseWorkflow, MessageDocument, Transition, type TransitionInput, Workflow } from '@loopstack/common';
|
|
3
|
+
import { RunSubWorkflowExampleSubWorkflow } from './sub-workflow-sub.workflow';
|
|
4
|
+
|
|
5
|
+
const SubWorkflowMessageSchema = z.object({ message: z.string() });
|
|
6
|
+
|
|
7
|
+
@Workflow({
|
|
8
|
+
title: 'Advanced - Sub-Workflow Example',
|
|
9
|
+
description:
|
|
10
|
+
'Launches a child workflow via .run() and resumes when it completes — basic parent/child composition pattern.',
|
|
11
|
+
})
|
|
12
|
+
export class RunSubWorkflowExampleParentWorkflow extends BaseWorkflow {
|
|
13
|
+
constructor(private readonly subWorkflow: RunSubWorkflowExampleSubWorkflow) {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Transition({ to: 'sub_workflow_started' })
|
|
18
|
+
async runWorkflow(_state: Record<string, unknown>) {
|
|
19
|
+
await this.subWorkflow.run(
|
|
20
|
+
{},
|
|
21
|
+
{ callback: { transition: 'subWorkflowCallback' }, show: 'link', label: 'Sub-Workflow' },
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Transition({
|
|
26
|
+
from: 'sub_workflow_started',
|
|
27
|
+
to: 'sub_workflow_ended',
|
|
28
|
+
wait: true,
|
|
29
|
+
schema: SubWorkflowMessageSchema,
|
|
30
|
+
})
|
|
31
|
+
async subWorkflowCallback(state: Record<string, unknown>, input: TransitionInput<{ message: string }>) {
|
|
32
|
+
await this.documentStore.save(MessageDocument, {
|
|
33
|
+
role: 'assistant',
|
|
34
|
+
text: `A message from sub workflow 1: ${input.data.message}`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Transition({ from: 'sub_workflow_ended', to: 'sub_workflow2_started' })
|
|
39
|
+
async runWorkflow2(_state: Record<string, unknown>) {
|
|
40
|
+
await this.subWorkflow.run(
|
|
41
|
+
{},
|
|
42
|
+
{ callback: { transition: 'subWorkflow2Callback' }, show: 'link', label: 'Sub-Workflow 2' },
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Transition({
|
|
47
|
+
from: 'sub_workflow2_started',
|
|
48
|
+
to: 'end',
|
|
49
|
+
wait: true,
|
|
50
|
+
schema: SubWorkflowMessageSchema,
|
|
51
|
+
})
|
|
52
|
+
async subWorkflow2Callback(state: Record<string, unknown>, input: TransitionInput<{ message: string }>) {
|
|
53
|
+
await this.documentStore.save(MessageDocument, {
|
|
54
|
+
role: 'assistant',
|
|
55
|
+
text: `A message from sub workflow 2: ${input.data.message}`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BaseWorkflow, MessageDocument, Transition, type TransitionInput, Workflow } from '@loopstack/common';
|
|
3
|
+
import { RunSubWorkflowExampleSubWorkflow } from './sub-workflow-sub.workflow';
|
|
4
|
+
|
|
5
|
+
const ShowMessageSchema = z.object({ message: z.string() });
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Demonstrates every `RunOptions.show` mode in one chained flow:
|
|
9
|
+
*
|
|
10
|
+
* 1. `show: 'inline'` — the child renders as an embedded iframe inside the parent's stream
|
|
11
|
+
* and auto-collapses once it reaches a terminal state.
|
|
12
|
+
* 2. `show: 'link'` — the child renders as a status link card; clicking opens the child
|
|
13
|
+
* in a separate window.
|
|
14
|
+
* 3. `show: 'hidden'` — the child runs without any UI in the parent's stream; the callback
|
|
15
|
+
* still fires normally.
|
|
16
|
+
*/
|
|
17
|
+
@Workflow({
|
|
18
|
+
title: 'Advanced - Sub-Workflow Show Modes Example',
|
|
19
|
+
})
|
|
20
|
+
export class RunSubWorkflowExampleShowModesWorkflow extends BaseWorkflow {
|
|
21
|
+
constructor(private readonly sub: RunSubWorkflowExampleSubWorkflow) {
|
|
22
|
+
super();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Transition({ to: 'inline_started' })
|
|
26
|
+
async runInline(_state: Record<string, unknown>) {
|
|
27
|
+
await this.sub.run(
|
|
28
|
+
{},
|
|
29
|
+
{ callback: { transition: 'onInlineDone' }, show: 'inline', label: 'Inline embed (iframe)' },
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Transition({
|
|
34
|
+
from: 'inline_started',
|
|
35
|
+
to: 'link_started',
|
|
36
|
+
wait: true,
|
|
37
|
+
schema: ShowMessageSchema,
|
|
38
|
+
})
|
|
39
|
+
async onInlineDone(state: Record<string, unknown>, input: TransitionInput<{ message: string }>) {
|
|
40
|
+
await this.documentStore.save(MessageDocument, {
|
|
41
|
+
role: 'assistant',
|
|
42
|
+
text: `Inline child returned: ${input.data.message}`,
|
|
43
|
+
});
|
|
44
|
+
await this.sub.run({}, { callback: { transition: 'onLinkDone' }, show: 'link', label: 'Status link card' });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Transition({
|
|
48
|
+
from: 'link_started',
|
|
49
|
+
to: 'hidden_started',
|
|
50
|
+
wait: true,
|
|
51
|
+
schema: ShowMessageSchema,
|
|
52
|
+
})
|
|
53
|
+
async onLinkDone(state: Record<string, unknown>, input: TransitionInput<{ message: string }>) {
|
|
54
|
+
await this.documentStore.save(MessageDocument, {
|
|
55
|
+
role: 'assistant',
|
|
56
|
+
text: `Link child returned: ${input.data.message}`,
|
|
57
|
+
});
|
|
58
|
+
await this.sub.run({}, { callback: { transition: 'onHiddenDone' }, show: 'hidden', label: 'Background child' });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@Transition({
|
|
62
|
+
from: 'hidden_started',
|
|
63
|
+
to: 'end',
|
|
64
|
+
wait: true,
|
|
65
|
+
schema: ShowMessageSchema,
|
|
66
|
+
})
|
|
67
|
+
async onHiddenDone(_state: Record<string, unknown>, input: TransitionInput<{ message: string }>) {
|
|
68
|
+
await this.documentStore.save(MessageDocument, {
|
|
69
|
+
role: 'assistant',
|
|
70
|
+
text: `Hidden child returned: ${input.data.message} — no LinkCard was rendered for it.`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseWorkflow, MessageDocument, Transition, Workflow } from '@loopstack/common';
|
|
2
|
+
|
|
3
|
+
@Workflow({
|
|
4
|
+
name: 'run_sub_workflow_example_sub',
|
|
5
|
+
title: 'Advanced - Sub-Workflow (child)',
|
|
6
|
+
})
|
|
7
|
+
export class RunSubWorkflowExampleSubWorkflow extends BaseWorkflow {
|
|
8
|
+
@Transition({ to: 'end' })
|
|
9
|
+
async message(_state: Record<string, unknown>) {
|
|
10
|
+
await this.documentStore.save(MessageDocument, {
|
|
11
|
+
role: 'assistant',
|
|
12
|
+
text: 'Sub workflow completed.',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
this.setResult({ message: 'Hi mom!' } as unknown as Record<string, unknown>);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseWorkflow,
|
|
3
|
+
ErrorDocument,
|
|
4
|
+
MarkdownDocument,
|
|
5
|
+
MessageDocument,
|
|
6
|
+
PlainDocument,
|
|
7
|
+
Transition,
|
|
8
|
+
Workflow,
|
|
9
|
+
} from '@loopstack/common';
|
|
10
|
+
|
|
11
|
+
@Workflow({
|
|
12
|
+
title: 'Advanced - UI Documents Example',
|
|
13
|
+
description:
|
|
14
|
+
'Smoke test for the built-in document types — MessageDocument, ErrorDocument, MarkdownDocument, PlainDocument.',
|
|
15
|
+
})
|
|
16
|
+
export class TestUiDocumentsWorkflow extends BaseWorkflow {
|
|
17
|
+
@Transition({ to: 'rendered' })
|
|
18
|
+
async renderAll(_state: Record<string, unknown>) {
|
|
19
|
+
// Message
|
|
20
|
+
await this.documentStore.save(MessageDocument, {
|
|
21
|
+
role: 'assistant',
|
|
22
|
+
text: 'This is the default message',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Error
|
|
26
|
+
await this.documentStore.save(ErrorDocument, {
|
|
27
|
+
error: 'This is an error message',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Markdown
|
|
31
|
+
await this.documentStore.save(MarkdownDocument, {
|
|
32
|
+
markdown: '# Markdown\n\nThis is `markdown`\n',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Plain Text
|
|
36
|
+
await this.documentStore.save(PlainDocument, {
|
|
37
|
+
text: 'This is plain text',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Transition({ from: 'rendered', to: 'end' })
|
|
42
|
+
done(_state: Record<string, unknown>) {}
|
|
43
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseWorkflow, MessageDocument, Transition, Workflow } from '@loopstack/common';
|
|
2
|
+
|
|
3
|
+
interface ToolResultsState {
|
|
4
|
+
storedMessage?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
@Workflow({
|
|
8
|
+
title: 'Advanced - Workflow Tool Result Example',
|
|
9
|
+
description: 'Storing tool results in workflow state and accessing them in later transitions.',
|
|
10
|
+
})
|
|
11
|
+
export class WorkflowToolResultsWorkflow extends BaseWorkflow {
|
|
12
|
+
@Transition({ to: 'data_created' })
|
|
13
|
+
async createSomeData(_state: ToolResultsState) {
|
|
14
|
+
await this.documentStore.save(MessageDocument, {
|
|
15
|
+
role: 'assistant',
|
|
16
|
+
text: `Stored in initial transition: Hello World.`,
|
|
17
|
+
});
|
|
18
|
+
this.assignState({ storedMessage: 'Hello World.' });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Transition({ from: 'data_created', to: 'end' })
|
|
22
|
+
async accessData(state: ToolResultsState) {
|
|
23
|
+
await this.documentStore.save(MessageDocument, {
|
|
24
|
+
role: 'assistant',
|
|
25
|
+
text: `Accessed from previous transition: ${state.storedMessage}`,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BaseWorkflow, MessageDocument, Transition, Workflow } from '@loopstack/common';
|
|
2
|
+
|
|
3
|
+
interface WorkflowStateState {
|
|
4
|
+
message?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
@Workflow({
|
|
8
|
+
title: 'Advanced - Workflow State Example',
|
|
9
|
+
description: 'Persisting typed state across transitions with assignState() and reading it in later steps.',
|
|
10
|
+
})
|
|
11
|
+
export class WorkflowStateWorkflow extends BaseWorkflow {
|
|
12
|
+
@Transition({ to: 'data_created' })
|
|
13
|
+
createSomeData(_state: WorkflowStateState) {
|
|
14
|
+
this.assignState({ message: 'Hello :)' });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Transition({ from: 'data_created', to: 'end' })
|
|
18
|
+
async showResults(state: WorkflowStateState) {
|
|
19
|
+
await this.documentStore.save(MessageDocument, {
|
|
20
|
+
role: 'assistant',
|
|
21
|
+
text: `Data from state: ${state.message}`,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await this.documentStore.save(MessageDocument, {
|
|
25
|
+
role: 'assistant',
|
|
26
|
+
text: `Use workflow helper method: ${this.messageInUpperCase(state.message!)}`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private messageInUpperCase(message: string): string {
|
|
31
|
+
return message?.toUpperCase();
|
|
32
|
+
}
|
|
33
|
+
}
|