@arnilo/prism-hosts 0.0.0-stage → 0.13.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/CHANGELOG.md +394 -0
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/acp/README.md +87 -0
- package/acp/src/capabilities.ts +184 -0
- package/acp/src/errors.ts +24 -0
- package/acp/src/host.ts +36 -0
- package/acp/src/index.ts +25 -0
- package/acp/src/limits.ts +49 -0
- package/acp/src/mapper.ts +419 -0
- package/acp/src/permission.ts +37 -0
- package/acp/src/projection.ts +39 -0
- package/acp/src/prompt.ts +170 -0
- package/acp/src/serve.ts +345 -0
- package/acp/src/session-map.ts +49 -0
- package/ag-ui/README.md +56 -0
- package/ag-ui/src/a2ui.ts +570 -0
- package/ag-ui/src/ag-ui-mapper.ts +507 -0
- package/ag-ui/src/encrypted-value.ts +40 -0
- package/ag-ui/src/errors.ts +29 -0
- package/ag-ui/src/handler.ts +642 -0
- package/ag-ui/src/index.ts +177 -0
- package/ag-ui/src/input.ts +190 -0
- package/ag-ui/src/limits.ts +279 -0
- package/ag-ui/src/mcp-apps.ts +256 -0
- package/ag-ui/src/mcp.ts +94 -0
- package/ag-ui/src/projection.ts +201 -0
- package/ag-ui/src/projectors.ts +272 -0
- package/ag-ui/src/renderer/bind.ts +152 -0
- package/ag-ui/src/renderer/core.ts +270 -0
- package/ag-ui/src/renderer/index.ts +165 -0
- package/ag-ui/src/replay.ts +189 -0
- package/ag-ui/src/types.ts +66 -0
- package/channels/README.md +139 -0
- package/channels/src/admission.ts +8 -0
- package/channels/src/approvals.ts +262 -0
- package/channels/src/checkpoint-contract.ts +97 -0
- package/channels/src/delivery.ts +116 -0
- package/channels/src/host-ui.ts +356 -0
- package/channels/src/identity.ts +46 -0
- package/channels/src/index.ts +82 -0
- package/channels/src/limits.ts +49 -0
- package/channels/src/memory-stores.ts +112 -0
- package/channels/src/pairing.ts +178 -0
- package/channels/src/runtime-admit.ts +389 -0
- package/channels/src/runtime-core.ts +621 -0
- package/channels/src/runtime-reconcile.ts +299 -0
- package/channels/src/runtime-turn.ts +664 -0
- package/channels/src/runtime-types.ts +95 -0
- package/channels/src/runtime.ts +86 -0
- package/channels/src/secret-ref.ts +42 -0
- package/channels/src/signal.ts +790 -0
- package/channels/src/state.ts +355 -0
- package/channels/src/telegram.ts +1317 -0
- package/channels/src/types.ts +442 -0
- package/devtools/README.md +92 -0
- package/devtools/bin/prism-devtools.ts +63 -0
- package/devtools/src/args.ts +71 -0
- package/devtools/src/bun.d.ts +27 -0
- package/devtools/src/compare.ts +190 -0
- package/devtools/src/errors.ts +15 -0
- package/devtools/src/index.ts +25 -0
- package/devtools/src/replay.ts +36 -0
- package/devtools/src/security.ts +80 -0
- package/devtools/src/serve.ts +259 -0
- package/devtools/src/ui/assets.ts +108 -0
- package/devtools/src/ui/inspector.ts +182 -0
- package/driver-process/README.md +197 -0
- package/driver-process/src/abort.ts +74 -0
- package/driver-process/src/adapter.ts +211 -0
- package/driver-process/src/driver.ts +303 -0
- package/driver-process/src/errors.ts +17 -0
- package/driver-process/src/extend.ts +72 -0
- package/driver-process/src/index.ts +5 -0
- package/driver-process/src/inspect.ts +33 -0
- package/driver-process/src/session.ts +72 -0
- package/driver-process/src/testing.ts +394 -0
- package/driver-process/src/transports/json-rpc.ts +147 -0
- package/driver-process/src/transports/jsonl-stream.ts +12 -0
- package/driver-process/src/transports/types.ts +11 -0
- package/driver-process/src/turn.ts +106 -0
- package/evals/README.md +843 -0
- package/evals/src/calibration.ts +179 -0
- package/evals/src/citation-integrity.ts +98 -0
- package/evals/src/citations.ts +45 -0
- package/evals/src/compare-experiments.ts +153 -0
- package/evals/src/comparison.ts +230 -0
- package/evals/src/curate.ts +257 -0
- package/evals/src/dataset.ts +81 -0
- package/evals/src/erp-invariants.ts +163 -0
- package/evals/src/errors.ts +23 -0
- package/evals/src/experiment.ts +537 -0
- package/evals/src/failure-injection.ts +77 -0
- package/evals/src/feedback.ts +53 -0
- package/evals/src/index.ts +198 -0
- package/evals/src/injection.ts +247 -0
- package/evals/src/judge-panel.ts +109 -0
- package/evals/src/judge.ts +89 -0
- package/evals/src/limits.ts +50 -0
- package/evals/src/report-record.ts +47 -0
- package/evals/src/rubric-judge.ts +334 -0
- package/evals/src/scenario-runner.ts +317 -0
- package/evals/src/scenarios.ts +81 -0
- package/evals/src/score.ts +328 -0
- package/evals/src/scorer.ts +21 -0
- package/evals/src/state-match.ts +130 -0
- package/evals/src/stats.ts +635 -0
- package/evals/src/threshold.ts +117 -0
- package/evals/src/timeline.ts +38 -0
- package/evals/src/toolless-session.ts +33 -0
- package/evals/src/trace.ts +80 -0
- package/evals/src/trajectory.ts +623 -0
- package/evals/src/types.ts +672 -0
- package/evals/src/user-simulator.ts +101 -0
- package/evals/src/util.ts +207 -0
- package/headless/README.md +172 -0
- package/headless/src/answers.ts +91 -0
- package/headless/src/authority.ts +32 -0
- package/headless/src/errors.ts +36 -0
- package/headless/src/index.ts +17 -0
- package/headless/src/limits.ts +11 -0
- package/headless/src/pending.ts +16 -0
- package/headless/src/policy.ts +36 -0
- package/headless/src/resume.ts +103 -0
- package/headless/src/route.ts +153 -0
- package/headless/src/scheduler/clock.ts +22 -0
- package/headless/src/scheduler/cron.ts +19 -0
- package/headless/src/scheduler/firing.ts +58 -0
- package/headless/src/scheduler/index.ts +399 -0
- package/headless/src/scheduler/lease.ts +38 -0
- package/headless/src/scheduler/missed.ts +12 -0
- package/headless/src/scheduler/state.ts +132 -0
- package/host-builder/README.md +251 -0
- package/host-builder/bin/prism-host-builder.ts +169 -0
- package/host-builder/data/api.json +6197 -0
- package/host-builder/data/errors.json +558 -0
- package/host-builder/data/examples/acp.ts +63 -0
- package/host-builder/data/examples/adapters/conformance.ts +34 -0
- package/host-builder/data/examples/adapters/fixtures/rpc-server.json +26 -0
- package/host-builder/data/examples/adapters/fixtures/stream-cli.json +27 -0
- package/host-builder/data/examples/adapters/fixtures/workspace-config.json +28 -0
- package/host-builder/data/examples/adapters/rpc-server.dialect.ts +218 -0
- package/host-builder/data/examples/adapters/rpc-server.ts +309 -0
- package/host-builder/data/examples/adapters/stream-cli.dialect.ts +165 -0
- package/host-builder/data/examples/adapters/stream-cli.ts +256 -0
- package/host-builder/data/examples/adapters/workspace-config.dialect.ts +172 -0
- package/host-builder/data/examples/adapters/workspace-config.ts +251 -0
- package/host-builder/data/examples/advisor.ts +94 -0
- package/host-builder/data/examples/ag-ui-a2ui.ts +80 -0
- package/host-builder/data/examples/ag-ui-mcp-apps.ts +44 -0
- package/host-builder/data/examples/ag-ui-server.ts +118 -0
- package/host-builder/data/examples/agent-durable-approval.ts +43 -0
- package/host-builder/data/examples/api-key-auth.ts +23 -0
- package/host-builder/data/examples/approval.ts +92 -0
- package/host-builder/data/examples/attention-compiler.ts +81 -0
- package/host-builder/data/examples/autonomous-coding-loop.ts +343 -0
- package/host-builder/data/examples/behavior-evaluation.ts +303 -0
- package/host-builder/data/examples/build-workflow.ts +334 -0
- package/host-builder/data/examples/cache-aware-prompt-assembly.ts +139 -0
- package/host-builder/data/examples/caveman-ponytail.ts +197 -0
- package/host-builder/data/examples/cli.ts +31 -0
- package/host-builder/data/examples/coding-approval.ts +115 -0
- package/host-builder/data/examples/coding-browser-evaluation.ts +208 -0
- package/host-builder/data/examples/coding-compaction.ts +30 -0
- package/host-builder/data/examples/coding-goal-verify.ts +121 -0
- package/host-builder/data/examples/coding-tools-capability-gaps.ts +75 -0
- package/host-builder/data/examples/compaction.ts +36 -0
- package/host-builder/data/examples/connected-slack-mcp.ts +67 -0
- package/host-builder/data/examples/context.ts +29 -0
- package/host-builder/data/examples/custom-adapter.ts +256 -0
- package/host-builder/data/examples/custom-builders.ts +66 -0
- package/host-builder/data/examples/custom-loop.ts +89 -0
- package/host-builder/data/examples/custom-provider.ts +70 -0
- package/host-builder/data/examples/custom-session-store.ts +72 -0
- package/host-builder/data/examples/custom-tools-skills-context.ts +97 -0
- package/host-builder/data/examples/decision-models.ts +98 -0
- package/host-builder/data/examples/define-package.ts +188 -0
- package/host-builder/data/examples/delegate.ts +200 -0
- package/host-builder/data/examples/discover-skills.ts +65 -0
- package/host-builder/data/examples/drive-rag-sync.ts +44 -0
- package/host-builder/data/examples/durable-approval.ts +139 -0
- package/host-builder/data/examples/durable-investigation.ts +93 -0
- package/host-builder/data/examples/durable-loops-and-approvals.ts +94 -0
- package/host-builder/data/examples/enterprise-identity.ts +21 -0
- package/host-builder/data/examples/enterprise-policy-audit.ts +50 -0
- package/host-builder/data/examples/enterprise-work-connectors.ts +103 -0
- package/host-builder/data/examples/eval-injection.ts +73 -0
- package/host-builder/data/examples/eval-judges.ts +145 -0
- package/host-builder/data/examples/evals.ts +86 -0
- package/host-builder/data/examples/evaluation-gate.ts +40 -0
- package/host-builder/data/examples/execution-timeline.ts +173 -0
- package/host-builder/data/examples/external-agent.ts +541 -0
- package/host-builder/data/examples/external-app-db-backed.ts +344 -0
- package/host-builder/data/examples/governance-deny.ts +122 -0
- package/host-builder/data/examples/guardrail-packs.ts +240 -0
- package/host-builder/data/examples/headless-host.ts +245 -0
- package/host-builder/data/examples/hooks-audit-command.mjs +31 -0
- package/host-builder/data/examples/hooks-json.ts +87 -0
- package/host-builder/data/examples/host-builder-agent.ts +150 -0
- package/host-builder/data/examples/host-hooks.ts +71 -0
- package/host-builder/data/examples/host-step-loop-timeline.ts +212 -0
- package/host-builder/data/examples/hosted-sandbox.ts +48 -0
- package/host-builder/data/examples/instruction-injection.ts +127 -0
- package/host-builder/data/examples/jsonl-stores-branching.ts +49 -0
- package/host-builder/data/examples/long-term-memory.ts +158 -0
- package/host-builder/data/examples/manifest.ts +112 -0
- package/host-builder/data/examples/mcp-server.ts +48 -0
- package/host-builder/data/examples/mcp-trust.ts +173 -0
- package/host-builder/data/examples/memory-and-wiki.ts +315 -0
- package/host-builder/data/examples/memory-lifecycle.ts +302 -0
- package/host-builder/data/examples/memory-system.ts +255 -0
- package/host-builder/data/examples/messaging-agent.ts +70 -0
- package/host-builder/data/examples/minimal-host-app.ts +41 -0
- package/host-builder/data/examples/model-router-aggregate-budgets.ts +364 -0
- package/host-builder/data/examples/model-router.ts +106 -0
- package/host-builder/data/examples/obscura.ts +48 -0
- package/host-builder/data/examples/observability.ts +116 -0
- package/host-builder/data/examples/open-connector-sidecar.ts +105 -0
- package/host-builder/data/examples/openai-compatible.ts +70 -0
- package/host-builder/data/examples/package-skills.ts +85 -0
- package/host-builder/data/examples/phase9-coding-intelligence.ts +221 -0
- package/host-builder/data/examples/provider-registration.ts +29 -0
- package/host-builder/data/examples/provider-resolver.ts +39 -0
- package/host-builder/data/examples/rag.ts +40 -0
- package/host-builder/data/examples/remote-agent-server.ts +45 -0
- package/host-builder/data/examples/remote-agent.ts +124 -0
- package/host-builder/data/examples/research-ledger.ts +79 -0
- package/host-builder/data/examples/revocation-propagation.ts +287 -0
- package/host-builder/data/examples/run-feedback.ts +93 -0
- package/host-builder/data/examples/scanned-document-rag.ts +48 -0
- package/host-builder/data/examples/sdk-basics.ts +21 -0
- package/host-builder/data/examples/secure-agent.ts +55 -0
- package/host-builder/data/examples/semantic-memory.ts +52 -0
- package/host-builder/data/examples/serve-tools.ts +495 -0
- package/host-builder/data/examples/session-memory.ts +318 -0
- package/host-builder/data/examples/session-search.ts +131 -0
- package/host-builder/data/examples/session.ts +52 -0
- package/host-builder/data/examples/side-call.ts +68 -0
- package/host-builder/data/examples/signal-agent.ts +9 -0
- package/host-builder/data/examples/skills-progressive-disclosure.ts +88 -0
- package/host-builder/data/examples/skills.ts +19 -0
- package/host-builder/data/examples/sqlite-resume.ts +147 -0
- package/host-builder/data/examples/system-project-prompts.ts +74 -0
- package/host-builder/data/examples/system-prompts.ts +19 -0
- package/host-builder/data/examples/telegram-agent.ts +30 -0
- package/host-builder/data/examples/tool-narrowing-planes.ts +99 -0
- package/host-builder/data/examples/tools.ts +29 -0
- package/host-builder/data/examples/validator.ts +67 -0
- package/host-builder/data/examples/web-no-key.ts +85 -0
- package/host-builder/data/examples/web-research.ts +35 -0
- package/host-builder/data/examples/workflow-event-sink.ts +114 -0
- package/host-builder/data/examples/workflow-loop.ts +93 -0
- package/host-builder/data/examples/workflow-multimodal-document.ts +94 -0
- package/host-builder/data/examples/workflow-parallel-research.ts +111 -0
- package/host-builder/data/examples/workflow-postgres-resume.ts +75 -0
- package/host-builder/data/examples/workflow-research-and-review.ts +98 -0
- package/host-builder/data/examples/workflow-sqlite-resume.ts +163 -0
- package/host-builder/data/examples.json +130 -0
- package/host-builder/skills/prism-host-builder/SKILL.md +85 -0
- package/host-builder/skills/prism-host-builder/references/choosing.md +101 -0
- package/host-builder/skills/prism-host-builder/references/layout.md +52 -0
- package/host-builder/skills/prism-host-builder/references/pitfalls.md +50 -0
- package/host-builder/skills/prism-host-builder/references/recipes.md +129 -0
- package/host-builder/skills/prism-host-builder/references/security.md +52 -0
- package/host-builder/skills/prism-host-builder/references/upgrading.md +67 -0
- package/host-builder/skills/prism-host-builder/references/verification.md +108 -0
- package/host-builder/src/check/child.ts +108 -0
- package/host-builder/src/check/conformance.ts +13 -0
- package/host-builder/src/check/inspect.ts +20 -0
- package/host-builder/src/check/manifest.ts +23 -0
- package/host-builder/src/check/runner.ts +181 -0
- package/host-builder/src/check/targets.ts +65 -0
- package/host-builder/src/errors.ts +35 -0
- package/host-builder/src/index.ts +25 -0
- package/host-builder/src/indexes.ts +145 -0
- package/host-builder/src/install/install.ts +400 -0
- package/host-builder/src/install/targets.ts +50 -0
- package/host-builder/src/lookup/api.ts +127 -0
- package/host-builder/src/lookup/bound.ts +38 -0
- package/host-builder/src/lookup/docs.ts +238 -0
- package/host-builder/src/lookup/errors.ts +92 -0
- package/host-builder/src/lookup/examples.ts +117 -0
- package/host-builder/src/lookup/text.ts +60 -0
- package/host-builder/src/server.ts +300 -0
- package/host-builder/src/version.ts +38 -0
- package/mcp-server/README.md +219 -0
- package/mcp-server/src/bounds.ts +23 -0
- package/mcp-server/src/host.ts +31 -0
- package/mcp-server/src/index.ts +27 -0
- package/mcp-server/src/serve-tools.ts +408 -0
- package/mcp-server/src/serve.ts +329 -0
- package/mcp-server/src/server.ts +331 -0
- package/mcp-server/src/session-map.ts +47 -0
- package/mcp-server/src/skill-resources.ts +85 -0
- package/mcp-server/src/types.ts +215 -0
- package/package.json +130 -4
- package/remote/README.md +244 -0
- package/remote/src/attribution.ts +22 -0
- package/remote/src/auth.ts +30 -0
- package/remote/src/bun-module.d.ts +34 -0
- package/remote/src/channel.ts +86 -0
- package/remote/src/connect.ts +212 -0
- package/remote/src/dispatcher.ts +282 -0
- package/remote/src/errors.ts +59 -0
- package/remote/src/host-ui.ts +152 -0
- package/remote/src/http-gate.ts +43 -0
- package/remote/src/index.ts +53 -0
- package/remote/src/jsonl.ts +69 -0
- package/remote/src/limits.ts +43 -0
- package/remote/src/mirror.ts +90 -0
- package/remote/src/pending.ts +22 -0
- package/remote/src/protocol.ts +107 -0
- package/remote/src/serve.ts +560 -0
- package/remote/src/session-proxy.ts +219 -0
- package/remote/src/sse.ts +38 -0
- package/remote/src/stdio-client.ts +41 -0
- package/remote/src/testing-fixtures/serve-stdio.ts +32 -0
- package/remote/src/testing.ts +230 -0
- package/remote/src/transport.ts +139 -0
- package/remote/src/transports/client.ts +126 -0
- package/remote/src/transports/network.ts +268 -0
- package/remote/src/wire.ts +244 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createWorkflowTransitionChannel, type WorkflowEvent } from "@arnilo/prism-extensions/workflows";
|
|
2
|
+
import { createAgent, createSecretRedactor, providerDone, providerTextDelta, providerUsage } from "@arnilo/prism";
|
|
3
|
+
import { createMockProvider } from "@arnilo/prism/testing";
|
|
4
|
+
import { agentNode, conditionalNode, defineWorkflow, functionNode, runWorkflow } from "@arnilo/prism-extensions/workflows";
|
|
5
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
6
|
+
|
|
7
|
+
// Observability / event sink: a workflow with a conditional path produces
|
|
8
|
+
// events that the host collects and inspects. Demonstrates:
|
|
9
|
+
// - `WorkflowTransitionChannel` for bounded async subscribers
|
|
10
|
+
// - event-type classification post-run
|
|
11
|
+
// - conditional node skip reports
|
|
12
|
+
// Uses mock providers — no network.
|
|
13
|
+
|
|
14
|
+
const provider = createMockProvider([
|
|
15
|
+
providerTextDelta("Analysis result."),
|
|
16
|
+
providerUsage({ inputTokens: 6, outputTokens: 3, totalTokens: 9 }),
|
|
17
|
+
providerDone(),
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const agent = await createAgent({
|
|
21
|
+
model: { provider: "mock", model: "demo" },
|
|
22
|
+
packages: [providerPackage("test-provider", [provider])],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const research = agentNode({
|
|
26
|
+
agent,
|
|
27
|
+
input: (ctx) => ctx.workflowInput,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const shouldFlag = conditionalNode({
|
|
31
|
+
when: (_ctx) => true, // always true for demo
|
|
32
|
+
then: ["flag"],
|
|
33
|
+
else: [],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const flag = functionNode({
|
|
37
|
+
execute: async (ctx) => ({ flagged: true, upstream: ctx.upstream }),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const done = functionNode({
|
|
41
|
+
execute: async (ctx) => ({ summary: "complete", upstream: ctx.upstream }),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const workflow = defineWorkflow({
|
|
45
|
+
revision: "1",
|
|
46
|
+
id: "event-sink-demo",
|
|
47
|
+
nodes: { research, shouldFlag, flag, done },
|
|
48
|
+
edges: [
|
|
49
|
+
["research", "shouldFlag"],
|
|
50
|
+
["shouldFlag", "flag"],
|
|
51
|
+
["shouldFlag", "done"],
|
|
52
|
+
["flag", "done"],
|
|
53
|
+
],
|
|
54
|
+
limits: { maxConcurrency: 1, maxNodes: 32 },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export async function demo() {
|
|
58
|
+
const redactor = createSecretRedactor([]);
|
|
59
|
+
const bus = createWorkflowTransitionChannel({
|
|
60
|
+
workflowId: workflow.id,
|
|
61
|
+
runId: "event-sink-run",
|
|
62
|
+
maxQueuedEvents: 256,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const busEvents: WorkflowEvent[] = [];
|
|
66
|
+
|
|
67
|
+
const drain = (async () => {
|
|
68
|
+
for await (const event of bus.subscribe()) {
|
|
69
|
+
busEvents.push(event);
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
|
|
73
|
+
const result = await runWorkflow(
|
|
74
|
+
workflow,
|
|
75
|
+
{ query: "status" },
|
|
76
|
+
{
|
|
77
|
+
redactor,
|
|
78
|
+
ownership: { tenantId: "demo" },
|
|
79
|
+
signal: AbortSignal.timeout(30_000),
|
|
80
|
+
runId: "event-sink-run",
|
|
81
|
+
transitions: bus,
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
bus.close();
|
|
86
|
+
try {
|
|
87
|
+
await drain;
|
|
88
|
+
} catch {
|
|
89
|
+
/* iterator closed */
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Classify events
|
|
93
|
+
const byType = (events: WorkflowEvent[]) => {
|
|
94
|
+
const map = new Map<string, number>();
|
|
95
|
+
for (const e of events) map.set(e.type, (map.get(e.type) ?? 0) + 1);
|
|
96
|
+
return Object.fromEntries(map);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
status: result.status,
|
|
101
|
+
eventCount: busEvents.length,
|
|
102
|
+
byType: byType(busEvents),
|
|
103
|
+
hasAgentEvents: busEvents.some((e) => e.type === "agent_event"),
|
|
104
|
+
hasSkipped: busEvents.some((e) => e.type === "node_skipped"),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function main() {
|
|
109
|
+
console.log(JSON.stringify(await demo()));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
113
|
+
await main();
|
|
114
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createAgent, createMemorySessionStore, providerDone, providerTextDelta, toolCallContent, type ModelProvider } from "@arnilo/prism";
|
|
2
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
3
|
+
import { createScriptedHostUi } from "@arnilo/prism/testing";
|
|
4
|
+
import { approvalPackage } from "@arnilo/prism-extensions/approval";
|
|
5
|
+
import { defineWorkflow, functionNode, gateNode, loopAgentNode, workflowLoop } from "@arnilo/prism-extensions/workflows";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A generate-validate-revise loop as a `workflowLoop` (roadmap §2.12.13): one agent, one session. The
|
|
9
|
+
* generate step's tool call goes through `tool.call`, so `approvalPackage` gates it: denied under
|
|
10
|
+
* `deny`, run once under `ask` with a scripted `HostUi`. The first draft fails the `gateNode`
|
|
11
|
+
* validator and routes back for one revision. Offline on the mock provider; no credential.
|
|
12
|
+
* Run: npm run build:core && node examples/workflow-loop.ts
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const MODEL = { provider: "mock", model: "demo" } as const;
|
|
16
|
+
|
|
17
|
+
function scriptedProvider(): ModelProvider {
|
|
18
|
+
let turn = 0;
|
|
19
|
+
return {
|
|
20
|
+
id: "mock",
|
|
21
|
+
async *generate() {
|
|
22
|
+
turn += 1;
|
|
23
|
+
if (turn === 1) {
|
|
24
|
+
yield { type: "tool_call" as const, call: toolCallContent("call-1", "save_draft", { name: "draft.md" }) };
|
|
25
|
+
yield providerDone();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
yield providerTextDelta(turn === 2 ? "first draft" : "final answer");
|
|
29
|
+
yield providerDone();
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const generateValidateRevise = defineWorkflow({
|
|
35
|
+
id: "generate-validate-revise",
|
|
36
|
+
revision: "1",
|
|
37
|
+
limits: { maxSupersteps: 12 },
|
|
38
|
+
nodes: {
|
|
39
|
+
seed: functionNode({ execute: () => "start" }),
|
|
40
|
+
generate: loopAgentNode({
|
|
41
|
+
activation: "any",
|
|
42
|
+
input: (ctx) => (ctx.upstream.validate ? "Revise: the answer was not final." : "Draft the answer. Save it with save_draft."),
|
|
43
|
+
}),
|
|
44
|
+
validate: gateNode({
|
|
45
|
+
check: (ctx) => (String(ctx.upstream.generate).includes("final") ? { pass: true } : { pass: false, reason: "not final" }),
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
edges: [
|
|
49
|
+
["seed", "generate"],
|
|
50
|
+
["generate", "validate"],
|
|
51
|
+
["validate", "generate"],
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
async function run(mode: "deny" | "ask") {
|
|
56
|
+
const saved: string[] = [];
|
|
57
|
+
const scripted = createScriptedHostUi({ confirm: true });
|
|
58
|
+
const agent = await createAgent({
|
|
59
|
+
id: `workflow-loop-${mode}`,
|
|
60
|
+
model: MODEL,
|
|
61
|
+
slots: { store: createMemorySessionStore() },
|
|
62
|
+
host: { ui: scripted.ui },
|
|
63
|
+
packages: [providerPackage("test-provider", [scriptedProvider()]), workflowLoop(generateValidateRevise), approvalPackage({ mode })],
|
|
64
|
+
tools: {
|
|
65
|
+
add: [
|
|
66
|
+
{
|
|
67
|
+
name: "save_draft",
|
|
68
|
+
description: "Saves the draft",
|
|
69
|
+
parameters: { type: "object", properties: { name: { type: "string" } } },
|
|
70
|
+
effects: ["write"],
|
|
71
|
+
execute: (args, context) => {
|
|
72
|
+
saved.push(String(args.name));
|
|
73
|
+
return { toolCallId: context.toolCallId, name: "save_draft", value: "saved" };
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const result = await (await agent.session()).run("Write the answer");
|
|
80
|
+
await agent.dispose();
|
|
81
|
+
return { status: result.status, text: result.text, saved, confirmRequests: scripted.requestsOf("confirm").length };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function demo(): Promise<Record<string, unknown>> {
|
|
85
|
+
const deny = await run("deny");
|
|
86
|
+
const ask = await run("ask");
|
|
87
|
+
if (deny.saved.length !== 0 || ask.saved.length !== 1 || deny.text !== "final answer" || ask.text !== "final answer") {
|
|
88
|
+
throw new Error("workflow-loop: the approval gate did not govern the loop's tool call");
|
|
89
|
+
}
|
|
90
|
+
return { deny, ask };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (import.meta.url === `file://${process.argv[1]}`) console.log(JSON.stringify(await demo()));
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAgent,
|
|
3
|
+
createEnvRefCredentialResolver,
|
|
4
|
+
createSecretRedactor,
|
|
5
|
+
type Message,
|
|
6
|
+
providerDone,
|
|
7
|
+
providerTextDelta,
|
|
8
|
+
providerUsage,
|
|
9
|
+
} from "@arnilo/prism";
|
|
10
|
+
import { createMockProvider } from "@arnilo/prism/testing";
|
|
11
|
+
import { agentNode, createMemoryWorkflowCheckpoints, defineWorkflow, functionNode, runWorkflow } from "@arnilo/prism-extensions/workflows";
|
|
12
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
13
|
+
|
|
14
|
+
// Offline multimodal document workflow. Host constructs a bounded inline PDF
|
|
15
|
+
// block, passes it through a function node, then an agent node summarizes it.
|
|
16
|
+
// Credentials come only from a caller-supplied env object; Prism never reads
|
|
17
|
+
// process.env. Mock provider means no credential or network is consumed.
|
|
18
|
+
|
|
19
|
+
const callerEnv = { DEMO_API_KEY: "demo-workflow-key" };
|
|
20
|
+
const credentials = createEnvRefCredentialResolver(callerEnv);
|
|
21
|
+
const tinyPdfBase64 = Buffer.from("%PDF-1.4\n% offline demo\n").toString("base64");
|
|
22
|
+
|
|
23
|
+
const provider = createMockProvider([
|
|
24
|
+
providerTextDelta("Document summary: offline workflow brief."),
|
|
25
|
+
providerUsage({ inputTokens: 8, outputTokens: 5, totalTokens: 13 }),
|
|
26
|
+
providerDone(),
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
const agent = await createAgent({
|
|
30
|
+
model: {
|
|
31
|
+
provider: "mock",
|
|
32
|
+
model: "document-demo",
|
|
33
|
+
capabilities: { input: ["text", "document"] },
|
|
34
|
+
},
|
|
35
|
+
packages: [providerPackage("test-provider", [provider])],
|
|
36
|
+
instructions: "Summarize the supplied document without reproducing secrets.",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const prepare = functionNode({
|
|
40
|
+
execute: async (): Promise<Message> => ({
|
|
41
|
+
role: "user",
|
|
42
|
+
content: [
|
|
43
|
+
{ type: "text", text: "Summarize this bounded PDF." },
|
|
44
|
+
{
|
|
45
|
+
type: "document",
|
|
46
|
+
mediaType: "application/pdf",
|
|
47
|
+
name: "brief.pdf",
|
|
48
|
+
data: tinyPdfBase64,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const summarize = agentNode({
|
|
55
|
+
agent,
|
|
56
|
+
input: (ctx) => ctx.upstream.prepare,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const workflow = defineWorkflow({
|
|
60
|
+
revision: "1",
|
|
61
|
+
id: "multimodal-document",
|
|
62
|
+
nodes: { prepare, summarize },
|
|
63
|
+
edges: [["prepare", "summarize"]],
|
|
64
|
+
limits: {
|
|
65
|
+
maxNodes: 16,
|
|
66
|
+
maxConcurrency: 1,
|
|
67
|
+
maxNodeOutputBytes: 64 * 1_024,
|
|
68
|
+
maxCheckpointBytes: 128 * 1_024,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export async function demo() {
|
|
73
|
+
const credential = await credentials.resolve("env:DEMO_API_KEY", {});
|
|
74
|
+
const redactor = createSecretRedactor([credential?.value]);
|
|
75
|
+
const result = await runWorkflow(workflow, null, {
|
|
76
|
+
checkpoints: createMemoryWorkflowCheckpoints({ redactor }),
|
|
77
|
+
redactor,
|
|
78
|
+
ownership: { tenantId: "demo" },
|
|
79
|
+
signal: AbortSignal.timeout(30_000),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
status: result.status,
|
|
84
|
+
documentBytes: Buffer.from(tinyPdfBase64, "base64").byteLength,
|
|
85
|
+
credentialConfigured: Boolean(credential),
|
|
86
|
+
summarized: result.outputs.summarize !== undefined,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function main() {
|
|
91
|
+
console.log(JSON.stringify(await demo()));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (import.meta.url === `file://${process.argv[1]}`) await main();
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createWorkflowTransitionChannel, type WorkflowEvent } from "@arnilo/prism-extensions/workflows";
|
|
2
|
+
import { createAgent, createSecretRedactor, providerDone, providerTextDelta, providerUsage } from "@arnilo/prism";
|
|
3
|
+
import { createMockProvider } from "@arnilo/prism/testing";
|
|
4
|
+
import {
|
|
5
|
+
agentNode,
|
|
6
|
+
createMemoryWorkflowCheckpoints,
|
|
7
|
+
defineWorkflow,
|
|
8
|
+
fanOut,
|
|
9
|
+
functionNode,
|
|
10
|
+
joinNode,
|
|
11
|
+
runWorkflow,
|
|
12
|
+
} from "@arnilo/prism-extensions/workflows";
|
|
13
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
14
|
+
|
|
15
|
+
// True parallel research DAG: fan-out normalizes bounded topics, join exposes
|
|
16
|
+
// the array, three independent research branches execute concurrently, then a
|
|
17
|
+
// combine node joins their outputs and an agent synthesizes the final summary.
|
|
18
|
+
|
|
19
|
+
const provider = createMockProvider([
|
|
20
|
+
providerTextDelta("Synthesized summary of all research findings."),
|
|
21
|
+
providerUsage({ inputTokens: 10, outputTokens: 6, totalTokens: 16 }),
|
|
22
|
+
providerDone(),
|
|
23
|
+
]);
|
|
24
|
+
const summarizerAgent = await createAgent({
|
|
25
|
+
model: { provider: "mock", model: "demo" },
|
|
26
|
+
packages: [providerPackage("test-provider", [provider])],
|
|
27
|
+
instructions: "Synthesize research findings into a one-paragraph summary.",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const topicFan = fanOut({
|
|
31
|
+
items: (ctx) => (ctx.workflowInput as { topics: string[] }).topics,
|
|
32
|
+
route: (item) => functionNode({ execute: () => String(item) }),
|
|
33
|
+
maxFanOut: 3,
|
|
34
|
+
});
|
|
35
|
+
const topics = joinNode({ from: "fanOut" });
|
|
36
|
+
const research = (index: number) =>
|
|
37
|
+
functionNode({
|
|
38
|
+
execute: async (ctx) => {
|
|
39
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
40
|
+
const list = ctx.upstream.topics as string[];
|
|
41
|
+
return `Research result for "${list[index]}"`;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const researchA = research(0);
|
|
45
|
+
const researchB = research(1);
|
|
46
|
+
const researchC = research(2);
|
|
47
|
+
const combine = functionNode({
|
|
48
|
+
execute: async (ctx) => ({
|
|
49
|
+
findings: [ctx.upstream.researchA, ctx.upstream.researchB, ctx.upstream.researchC],
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
const summarise = agentNode({
|
|
53
|
+
agent: summarizerAgent,
|
|
54
|
+
input: (ctx) => ctx.upstream.combine,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const workflow = defineWorkflow({
|
|
58
|
+
revision: "1",
|
|
59
|
+
id: "parallel-research",
|
|
60
|
+
nodes: { fanOut: topicFan, topics, researchA, researchB, researchC, combine, summarise },
|
|
61
|
+
edges: [
|
|
62
|
+
["fanOut", "topics"],
|
|
63
|
+
["topics", "researchA"],
|
|
64
|
+
["topics", "researchB"],
|
|
65
|
+
["topics", "researchC"],
|
|
66
|
+
["researchA", "combine"],
|
|
67
|
+
["researchB", "combine"],
|
|
68
|
+
["researchC", "combine"],
|
|
69
|
+
["combine", "summarise"],
|
|
70
|
+
],
|
|
71
|
+
limits: { maxConcurrency: 3, maxFanOut: 3, maxNodes: 64 },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export async function demo() {
|
|
75
|
+
const redactor = createSecretRedactor([]);
|
|
76
|
+
const checkpoints = createMemoryWorkflowCheckpoints({ redactor });
|
|
77
|
+
const events: WorkflowEvent[] = [];
|
|
78
|
+
const result = await runWorkflow(
|
|
79
|
+
workflow,
|
|
80
|
+
{ topics: ["hooks", "signals", "suspense"] },
|
|
81
|
+
{
|
|
82
|
+
checkpoints,
|
|
83
|
+
redactor,
|
|
84
|
+
ownership: { tenantId: "demo" },
|
|
85
|
+
signal: AbortSignal.timeout(30_000),
|
|
86
|
+
transitions: workflowEvents((event) => events.push(event)),
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
const findings = (result.outputs.combine as { findings?: unknown[] })?.findings;
|
|
90
|
+
return {
|
|
91
|
+
status: result.status,
|
|
92
|
+
findingsCount: findings?.length ?? 0,
|
|
93
|
+
nodeStarted: events.filter((event) => event.type === "node_started").length,
|
|
94
|
+
nodeFinished: events.filter((event) => event.type === "node_finished").length,
|
|
95
|
+
hasSummary: result.outputs.summarise !== undefined,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function main() {
|
|
100
|
+
console.log(JSON.stringify(await demo()));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (import.meta.url === `file://${process.argv[1]}`) await main();
|
|
104
|
+
|
|
105
|
+
function workflowEvents(consume: (event: WorkflowEvent) => void) {
|
|
106
|
+
const channel = createWorkflowTransitionChannel({ workflowId: "events", runId: "events" });
|
|
107
|
+
void (async () => {
|
|
108
|
+
for await (const event of channel.subscribe()) consume(event);
|
|
109
|
+
})();
|
|
110
|
+
return channel;
|
|
111
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { createWorkflowCheckpoints, defineWorkflow, functionNode, resumeWorkflow, runWorkflow } from "@arnilo/prism-extensions/workflows";
|
|
3
|
+
import { createPostgresPersistence } from "@arnilo/prism-extensions/store-postgres";
|
|
4
|
+
import { Pool } from "pg";
|
|
5
|
+
|
|
6
|
+
// Opt-in PostgreSQL restart/resume example. Default execution is network-free
|
|
7
|
+
// and reports "skipped". Set PRISM_TEST_POSTGRES_URL to run against an explicit
|
|
8
|
+
// test database; a unique schema is created and dropped for isolation.
|
|
9
|
+
|
|
10
|
+
let failFirstAttempt = true;
|
|
11
|
+
const unstable = functionNode({
|
|
12
|
+
execute: async () => {
|
|
13
|
+
if (failFirstAttempt) throw new Error("simulated process failure");
|
|
14
|
+
return "recovered";
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const workflow = defineWorkflow({
|
|
18
|
+
revision: "1",
|
|
19
|
+
id: "postgres-resume-demo",
|
|
20
|
+
nodes: { unstable },
|
|
21
|
+
limits: { maxNodes: 16, maxConcurrency: 1, maxCheckpointBytes: 128 * 1_024 },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export async function demo(postgresUrl = process.env.PRISM_TEST_POSTGRES_URL) {
|
|
25
|
+
if (!postgresUrl) return { skipped: true, reason: "set PRISM_TEST_POSTGRES_URL" };
|
|
26
|
+
|
|
27
|
+
const schema = `prism_wf_demo_${randomUUID().replaceAll("-", "").slice(0, 12)}`;
|
|
28
|
+
const ownership = { tenantId: "demo" };
|
|
29
|
+
const runId = "postgres-resume-run";
|
|
30
|
+
const firstPool = new Pool({ connectionString: postgresUrl, max: 2 });
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const firstPersistence = await createPostgresPersistence({ pool: firstPool, schema });
|
|
34
|
+
const firstCheckpoints = createWorkflowCheckpoints({ store: firstPersistence.checkpoints });
|
|
35
|
+
await runWorkflow(workflow, null, {
|
|
36
|
+
checkpoints: firstCheckpoints,
|
|
37
|
+
ownership,
|
|
38
|
+
runId,
|
|
39
|
+
signal: AbortSignal.timeout(30_000),
|
|
40
|
+
}).catch(() => undefined);
|
|
41
|
+
await firstPool.end();
|
|
42
|
+
|
|
43
|
+
// New pool simulates a new host process reading durable state.
|
|
44
|
+
failFirstAttempt = false;
|
|
45
|
+
const secondPool = new Pool({ connectionString: postgresUrl, max: 2 });
|
|
46
|
+
const secondPersistence = await createPostgresPersistence({ pool: secondPool, schema });
|
|
47
|
+
const secondCheckpoints = createWorkflowCheckpoints({ store: secondPersistence.checkpoints });
|
|
48
|
+
const resumed = await resumeWorkflow(
|
|
49
|
+
workflow,
|
|
50
|
+
{ runId },
|
|
51
|
+
{
|
|
52
|
+
checkpoints: secondCheckpoints,
|
|
53
|
+
ownership,
|
|
54
|
+
signal: AbortSignal.timeout(30_000),
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
await secondPool.query(`DROP SCHEMA "${schema}" CASCADE`);
|
|
58
|
+
await secondPool.end();
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
skipped: false,
|
|
62
|
+
status: resumed.status,
|
|
63
|
+
sameRunId: resumed.runId === runId,
|
|
64
|
+
output: resumed.outputs.unstable,
|
|
65
|
+
};
|
|
66
|
+
} finally {
|
|
67
|
+
if (!firstPool.ended) await firstPool.end();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function main() {
|
|
72
|
+
console.log(JSON.stringify(await demo()));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (import.meta.url === `file://${process.argv[1]}`) await main();
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createWorkflowTransitionChannel, type WorkflowEvent } from "@arnilo/prism-extensions/workflows";
|
|
2
|
+
import { createAgent, createSecretRedactor, createToolRegistry, providerDone, providerTextDelta, providerUsage } from "@arnilo/prism";
|
|
3
|
+
import { createMockProvider } from "@arnilo/prism/testing";
|
|
4
|
+
import { agentNode, createMemoryWorkflowCheckpoints, defineWorkflow, runWorkflow } from "@arnilo/prism-extensions/workflows";
|
|
5
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
6
|
+
|
|
7
|
+
// Sequential research → draft → review pipeline with in-memory checkpoints.
|
|
8
|
+
// Three agent nodes chained: researcher gathers facts, writer produces draft,
|
|
9
|
+
// reviewer checks quality. Uses mock providers — no network, no credentials.
|
|
10
|
+
|
|
11
|
+
const provider = createMockProvider([
|
|
12
|
+
providerTextDelta("Key facts: hooks simplify state management in React."),
|
|
13
|
+
providerUsage({ inputTokens: 12, outputTokens: 8, totalTokens: 20 }),
|
|
14
|
+
providerDone(),
|
|
15
|
+
]);
|
|
16
|
+
const tools = createToolRegistry();
|
|
17
|
+
|
|
18
|
+
async function makeAgent(_name: string, system: string) {
|
|
19
|
+
return await createAgent({
|
|
20
|
+
model: { provider: "mock", model: "demo" },
|
|
21
|
+
packages: [providerPackage("test-provider", [provider])],
|
|
22
|
+
tools: { add: tools.list() },
|
|
23
|
+
instructions: system,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const researchAgent = await makeAgent("researcher", "You research a topic and return key facts.");
|
|
28
|
+
const writerAgent = await makeAgent("writer", "You write a draft based on provided facts.");
|
|
29
|
+
const reviewerAgent = await makeAgent("reviewer", "You review a draft for quality. Return approved/fix-needed.");
|
|
30
|
+
|
|
31
|
+
const researchNode = agentNode({
|
|
32
|
+
agent: researchAgent,
|
|
33
|
+
input: (ctx) => ({ topic: ctx.workflowInput }),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const draftNode = agentNode({
|
|
37
|
+
agent: writerAgent,
|
|
38
|
+
input: (ctx) => ({ facts: ctx.upstream.research }),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const reviewNode = agentNode({
|
|
42
|
+
agent: reviewerAgent,
|
|
43
|
+
input: (ctx) => ({ draft: ctx.upstream.draft }),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const workflow = defineWorkflow({
|
|
47
|
+
revision: "1",
|
|
48
|
+
id: "research-draft-review",
|
|
49
|
+
nodes: { research: researchNode, draft: draftNode, review: reviewNode },
|
|
50
|
+
edges: [
|
|
51
|
+
["research", "draft"],
|
|
52
|
+
["draft", "review"],
|
|
53
|
+
],
|
|
54
|
+
limits: { maxConcurrency: 1 },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export async function demo() {
|
|
58
|
+
const redactor = createSecretRedactor([]);
|
|
59
|
+
const checkpoints = createMemoryWorkflowCheckpoints({ redactor });
|
|
60
|
+
|
|
61
|
+
const events: WorkflowEvent[] = [];
|
|
62
|
+
const result = await runWorkflow(
|
|
63
|
+
workflow,
|
|
64
|
+
{ topic: "React hooks" },
|
|
65
|
+
{
|
|
66
|
+
checkpoints,
|
|
67
|
+
redactor,
|
|
68
|
+
ownership: { tenantId: "demo" },
|
|
69
|
+
signal: AbortSignal.timeout(30_000),
|
|
70
|
+
transitions: workflowEvents((e) => events.push(e)),
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const eventTypes = events.map((e) => e.type);
|
|
75
|
+
const allSucceeded = Object.values(result.outputs).every((v) => v !== undefined);
|
|
76
|
+
return {
|
|
77
|
+
status: result.status,
|
|
78
|
+
outputs: Object.keys(result.outputs),
|
|
79
|
+
eventTypes,
|
|
80
|
+
allSucceeded,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function main() {
|
|
85
|
+
console.log(JSON.stringify(await demo()));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
89
|
+
await main();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function workflowEvents(consume: (event: WorkflowEvent) => void) {
|
|
93
|
+
const channel = createWorkflowTransitionChannel({ workflowId: "events", runId: "events" });
|
|
94
|
+
void (async () => {
|
|
95
|
+
for await (const event of channel.subscribe()) consume(event);
|
|
96
|
+
})();
|
|
97
|
+
return channel;
|
|
98
|
+
}
|