@nexalab/agent-sdk 0.1.0 → 0.1.6

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.
Files changed (85) hide show
  1. package/README.md +94 -6
  2. package/dist/file-storage.d.ts +3 -0
  3. package/dist/file-storage.d.ts.map +1 -1
  4. package/dist/file-storage.js +9 -0
  5. package/dist/file-storage.js.map +1 -1
  6. package/dist/guided-flows/define-flow.d.ts +4 -0
  7. package/dist/guided-flows/define-flow.d.ts.map +1 -0
  8. package/dist/guided-flows/define-flow.js +34 -0
  9. package/dist/guided-flows/define-flow.js.map +1 -0
  10. package/dist/guided-flows/errors.d.ts +11 -0
  11. package/dist/guided-flows/errors.d.ts.map +1 -0
  12. package/dist/guided-flows/errors.js +15 -0
  13. package/dist/guided-flows/errors.js.map +1 -0
  14. package/dist/guided-flows/events.d.ts +20 -0
  15. package/dist/guided-flows/events.d.ts.map +1 -0
  16. package/dist/guided-flows/events.js +17 -0
  17. package/dist/guided-flows/events.js.map +1 -0
  18. package/dist/guided-flows/index.d.ts +10 -0
  19. package/dist/guided-flows/index.d.ts.map +1 -0
  20. package/dist/guided-flows/index.js +6 -0
  21. package/dist/guided-flows/index.js.map +1 -0
  22. package/dist/guided-flows/persistence.d.ts +32 -0
  23. package/dist/guided-flows/persistence.d.ts.map +1 -0
  24. package/dist/guided-flows/persistence.js +37 -0
  25. package/dist/guided-flows/persistence.js.map +1 -0
  26. package/dist/guided-flows/requirements.d.ts +8 -0
  27. package/dist/guided-flows/requirements.d.ts.map +1 -0
  28. package/dist/guided-flows/requirements.js +21 -0
  29. package/dist/guided-flows/requirements.js.map +1 -0
  30. package/dist/guided-flows/runtime.d.ts +74 -0
  31. package/dist/guided-flows/runtime.d.ts.map +1 -0
  32. package/dist/guided-flows/runtime.js +423 -0
  33. package/dist/guided-flows/runtime.js.map +1 -0
  34. package/dist/guided-flows/state.d.ts +30 -0
  35. package/dist/guided-flows/state.d.ts.map +1 -0
  36. package/dist/guided-flows/state.js +84 -0
  37. package/dist/guided-flows/state.js.map +1 -0
  38. package/dist/guided-flows/steps.d.ts +12 -0
  39. package/dist/guided-flows/steps.d.ts.map +1 -0
  40. package/dist/guided-flows/steps.js +37 -0
  41. package/dist/guided-flows/steps.js.map +1 -0
  42. package/dist/guided-flows/tool-policy.d.ts +16 -0
  43. package/dist/guided-flows/tool-policy.d.ts.map +1 -0
  44. package/dist/guided-flows/tool-policy.js +33 -0
  45. package/dist/guided-flows/tool-policy.js.map +1 -0
  46. package/dist/guided-flows/types.d.ts +141 -0
  47. package/dist/guided-flows/types.d.ts.map +1 -0
  48. package/dist/guided-flows/types.js +2 -0
  49. package/dist/guided-flows/types.js.map +1 -0
  50. package/dist/hooks.d.ts +52 -0
  51. package/dist/hooks.d.ts.map +1 -1
  52. package/dist/hooks.js.map +1 -1
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +1 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/kernel.d.ts +23 -0
  58. package/dist/kernel.d.ts.map +1 -1
  59. package/dist/kernel.js +62 -4
  60. package/dist/kernel.js.map +1 -1
  61. package/dist/manifest.d.ts +3 -2
  62. package/dist/manifest.d.ts.map +1 -1
  63. package/dist/manifest.js +1 -0
  64. package/dist/manifest.js.map +1 -1
  65. package/dist/postgres-storage.d.ts +3 -0
  66. package/dist/postgres-storage.d.ts.map +1 -1
  67. package/dist/postgres-storage.js +9 -0
  68. package/dist/postgres-storage.js.map +1 -1
  69. package/dist/redis-storage.d.ts +3 -0
  70. package/dist/redis-storage.d.ts.map +1 -1
  71. package/dist/redis-storage.js +9 -0
  72. package/dist/redis-storage.js.map +1 -1
  73. package/dist/sessions.d.ts +5 -1
  74. package/dist/sessions.d.ts.map +1 -1
  75. package/dist/sessions.js +2 -2
  76. package/dist/sessions.js.map +1 -1
  77. package/dist/sqlite-storage.d.ts +3 -0
  78. package/dist/sqlite-storage.d.ts.map +1 -1
  79. package/dist/sqlite-storage.js +13 -1
  80. package/dist/sqlite-storage.js.map +1 -1
  81. package/dist/storage.d.ts +4 -0
  82. package/dist/storage.d.ts.map +1 -1
  83. package/dist/storage.js +8 -0
  84. package/dist/storage.js.map +1 -1
  85. package/package.json +21 -5
package/README.md CHANGED
@@ -20,6 +20,26 @@ For local workspace use:
20
20
  }
21
21
  ```
22
22
 
23
+ ## Documentation
24
+
25
+ The full documentation site is built with VitePress and lives in `docs/`. The API reference under `docs/api` is generated automatically from the TypeScript sources with TypeDoc:
26
+
27
+ ```bash
28
+ # Regenerate the API reference markdown from src/ into docs/api
29
+ pnpm docs:generate
30
+
31
+ # Develop the docs site (regenerates the API reference, then starts a dev server)
32
+ pnpm docs:dev
33
+
34
+ # Production build (regenerates the API reference, then builds the static site)
35
+ pnpm docs:build
36
+
37
+ # Preview the production build locally
38
+ pnpm docs:preview
39
+ ```
40
+
41
+ `docs:build` requires a successful `docs:generate` and is also validated in CI for every push/PR. The generated `docs/api` directory is not committed — it is always produced from source.
42
+
23
43
  ## Quick Start
24
44
 
25
45
  ### Premium `agent({...})` Kernel API
@@ -193,8 +213,54 @@ import { createSession, loadSession } from "@nexalab/agent-sdk/sessions";
193
213
  import { defineGuardrail, runInputGuardrails, runOutputGuardrails } from "@nexalab/agent-sdk/guardrails";
194
214
  import { createHookDispatcher } from "@nexalab/agent-sdk/hooks";
195
215
  import { zodSchemaToJsonSchema, parseStructuredOutput } from "@nexalab/agent-sdk/structured-output";
216
+ import { defineFlow } from "@nexalab/agent-sdk/guided-flows";
217
+ ```
218
+
219
+ ## Guided Flows
220
+
221
+ Build stateful, multi-turn conversations that must satisfy explicit requirements before completion.
222
+
223
+ Guided Flows combine natural conversation with typed state, step-specific tools, validation, branching, confirmations, and structured final outputs. Attach one or more to `agent({ flows })`; the runtime fills state from free-form messages in any order, never re-asks for what it already has, scopes tool availability per step (never beyond what the agent itself is permitted), and only returns a Zod-validated structured `output` once every requirement holds.
224
+
225
+ ```ts
226
+ import { agent, defineFlow } from "@nexalab/agent-sdk";
227
+ import { z } from "zod";
228
+
229
+ const gasOrderFlow = defineFlow({
230
+ id: "gas-order",
231
+ version: 1,
232
+ name: "Gas order",
233
+ goal: "Crear un pedido de gas valido y confirmado",
234
+ stateSchema: z.object({
235
+ customerName: z.string().optional(),
236
+ phone: z.string().optional(),
237
+ confirmed: z.boolean().default(false),
238
+ orderId: z.string().optional()
239
+ }),
240
+ initialState: { confirmed: false },
241
+ requirements: [
242
+ { id: "customer", description: "Customer identity known", satisfied: ({ state }) => Boolean(state.customerName && state.phone) },
243
+ { id: "confirmation", description: "Order confirmed", satisfied: ({ state }) => state.confirmed === true }
244
+ ],
245
+ steps: [
246
+ { id: "identify_customer", collect: ["customerName", "phone"] },
247
+ { id: "confirmation", collect: ["confirmed"], exit: ({ state }) => state.confirmed === true, tools: { denied: ["order.create"] } },
248
+ { id: "create_order", when: ({ state }) => state.confirmed === true, tools: { required: ["order.create"] }, exit: ({ state }) => Boolean(state.orderId) }
249
+ ],
250
+ protectedFields: { orderId: ["tool"] },
251
+ tools: { bindings: { "order.create": { applyResult: ({ result }) => ({ set: { orderId: result.output.orderId }, source: "tool" } as const) } } },
252
+ completion: ({ requirements, state }) => requirements.every((r) => r.satisfied) && Boolean(state.orderId),
253
+ outputSchema: z.object({ type: z.literal("gas_order"), orderId: z.string() }),
254
+ mapOutput: ({ state }) => ({ type: "gas_order" as const, orderId: state.orderId! })
255
+ });
256
+
257
+ const salesAgent = await agent({ name: "gas-sales-agent", model: "openai:gpt-4o-mini", flows: [gasOrderFlow], tools: [orderCreateTool] });
258
+ const result = await salesAgent.session("whatsapp:5214771234567").run("Quiero pedir gas");
259
+ console.log(result.text, result.flow, result.state, result.output);
196
260
  ```
197
261
 
262
+ See the full guide at [docs/guide/guided-flows.md](./docs/guide/guided-flows.md) and a complete runnable conversation at [`examples/guided-gas-order`](./examples/guided-gas-order) (`pnpm demo:guided-flow`).
263
+
198
264
  ## Agent Manifests + CLI
199
265
 
200
266
  Agents can be declared as YAML and run without writing code for the identity/model/instructions surface:
@@ -505,14 +571,36 @@ Recommended production wiring:
505
571
  - Use `pnpm harness` as the production readiness gate.
506
572
  - Use `pnpm smoke` and `pnpm pack:check` before publishing.
507
573
 
508
- ## Is It Frontier?
574
+ ```md
575
+ ## Frontier-ready architecture
509
576
 
510
- Yes, this is now a frontier-style agent SDK architecture: native tool calling, structured streaming, durable storage adapters, policy/approvals, evals, telemetry, replay, workflows, routing, multi-agent coordination, vector memory, queue contracts, package smoke checks, and a production harness.
577
+ Nexa Agent SDK is designed with a frontier-style agent architecture: native tool calling, structured streaming, durable storage adapters, policy and approvals, evals, telemetry, replay, workflows, routing, multi-agent coordination, vector memory, queue contracts, package smoke checks, and an extensible `ModelHarness` contract.
511
578
 
512
- The SDK intentionally stays dependency-light. Production apps still provide their actual infrastructure drivers and deployment policy through adapters.
579
+ The SDK remains dependency-light. Production applications provide their own infrastructure drivers and deployment policies through adapters.
513
580
 
514
- ## Open-core architecture
581
+ ## Extensible by design
515
582
 
516
- This package is designed as the fully-capable public half of an open-core split — see [docs/architecture/open-core-audit.md](./docs/architecture/open-core-audit.md), [open-core-target.md](./docs/architecture/open-core-target.md), and [open-core-migration.md](./docs/architecture/open-core-migration.md) for the module-by-module classification, target architecture, and phased plan. In short: everything in this repository is public and production-capable; strategic/proprietary intelligence (e.g. a future `FrontierHarness`) is designed to live in a separate private repository that *implements* this SDK's public contracts (`ModelHarness`, `ModelRoute`, `ContextEngineConfig`, ...) rather than forking or being vendored into it.
583
+ Nexa is built around stable contracts instead of hardcoded orchestration strategies.
517
584
 
518
- `pnpm verify:boundaries`, `pnpm verify:secrets`, and `pnpm verify:publish-safety` (all folded into `pnpm prepublish:check`) guard against private code or secrets ever entering an npm-published tarball from this repo.
585
+ Developers can extend or replace major runtime behaviors through interfaces for:
586
+
587
+ - model harnesses
588
+ - providers
589
+ - tools
590
+ - context
591
+ - memory
592
+ - storage
593
+ - routing
594
+ - telemetry
595
+ - evals
596
+
597
+ This makes it possible to build custom agent architectures without forking the core SDK.
598
+
599
+ ## Release safety
600
+
601
+ The repository includes automated checks for package boundaries, accidental credential exposure, and npm tarball contents:
602
+
603
+ ```bash
604
+ pnpm verify:boundaries
605
+ pnpm verify:secrets
606
+ pnpm verify:publish-safety
@@ -4,6 +4,7 @@ import type { MemoryRecord } from "./memory.js";
4
4
  import type { NexaStorage } from "./storage.js";
5
5
  import type { AgentRunSnapshot } from "./types.js";
6
6
  import type { WorkflowRun } from "./workflow.js";
7
+ import type { GuidedFlowRunState } from "./guided-flows/index.js";
7
8
  export declare class JsonFileStorage implements NexaStorage {
8
9
  private readonly rootDir;
9
10
  constructor(rootDir: string);
@@ -19,6 +20,8 @@ export declare class JsonFileStorage implements NexaStorage {
19
20
  listApprovals(status?: ApprovalRequest["status"]): Promise<ApprovalRequest[]>;
20
21
  saveWorkflow(run: WorkflowRun): Promise<void>;
21
22
  getWorkflow(id: string): Promise<WorkflowRun | undefined>;
23
+ saveFlowState(record: GuidedFlowRunState): Promise<void>;
24
+ getFlowState(sessionId: string, flowId: string): Promise<GuidedFlowRunState | undefined>;
22
25
  private path;
23
26
  }
24
27
  export declare function createJsonFileStorage(rootDir: string): JsonFileStorage;
@@ -1 +1 @@
1
- {"version":3,"file":"file-storage.d.ts","sourceRoot":"","sources":["../src/file-storage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,qBAAa,eAAgB,YAAW,WAAW;IACrC,OAAO,CAAC,QAAQ,C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E,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAI9F,OAAO,CAAC,IAAI;CAGb;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEtE"}
@@ -63,6 +63,12 @@ export class JsonFileStorage {
63
63
  async getWorkflow(id) {
64
64
  return readJson(this.path("workflows", `${id}.json`));
65
65
  }
66
+ async saveFlowState(record) {
67
+ await writeJson(this.path("guided-flows", flowStateFileName(record.sessionId, record.flowId)), record);
68
+ }
69
+ async getFlowState(sessionId, flowId) {
70
+ return readJson(this.path("guided-flows", flowStateFileName(sessionId, flowId)));
71
+ }
66
72
  path(...parts) {
67
73
  return join(this.rootDir, ...parts);
68
74
  }
@@ -97,4 +103,7 @@ async function readJsonArray(path) {
97
103
  function isMissingFile(error) {
98
104
  return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
99
105
  }
106
+ function flowStateFileName(sessionId, flowId) {
107
+ return `${encodeURIComponent(sessionId)}__${encodeURIComponent(flowId)}.json`;
108
+ }
100
109
  //# sourceMappingURL=file-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-storage.js","sourceRoot":"","sources":["../src/file-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAQ1C,MAAM,OAAO,eAAe;IACG;IAA7B,YAA6B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAEhD,KAAK,CAAC,OAAO,CAAC,GAAqB;QACjC,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC;QAC7D,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,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AI,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;AACnG,CAAC;AAED,SAAS,iBAAiB,CAAC,SAAiB,EAAE,MAAc;IAC1D,OAAO,GAAG,kBAAkB,CAAC,SAAS,CAAC,KAAK,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC;AAChF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { z } from "zod";
2
+ import type { GuidedFlow, GuidedFlowConfig } from "./types.js";
3
+ export declare function defineFlow<TStateSchema extends z.AnyZodObject, TOutputSchema extends z.ZodTypeAny>(config: GuidedFlowConfig<TStateSchema, TOutputSchema>): GuidedFlow<TStateSchema, TOutputSchema>;
4
+ //# sourceMappingURL=define-flow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-flow.d.ts","sourceRoot":"","sources":["../../src/guided-flows/define-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE/D,wBAAgB,UAAU,CAAC,YAAY,SAAS,CAAC,CAAC,YAAY,EAAE,aAAa,SAAS,CAAC,CAAC,UAAU,EAChG,MAAM,EAAE,gBAAgB,CAAC,YAAY,EAAE,aAAa,CAAC,GACpD,UAAU,CAAC,YAAY,EAAE,aAAa,CAAC,CAkCzC"}
@@ -0,0 +1,34 @@
1
+ import { GuidedFlowConfigError } from "./errors.js";
2
+ export function defineFlow(config) {
3
+ if (!config.id)
4
+ throw new GuidedFlowConfigError("defineFlow: `id` is required.");
5
+ if (!Number.isInteger(config.version) || config.version < 1) {
6
+ throw new GuidedFlowConfigError(`defineFlow(${config.id}): \`version\` must be a positive integer.`);
7
+ }
8
+ const stepIds = new Set();
9
+ for (const step of config.steps) {
10
+ if (stepIds.has(step.id))
11
+ throw new GuidedFlowConfigError(`defineFlow(${config.id}): duplicate step id "${step.id}".`);
12
+ stepIds.add(step.id);
13
+ }
14
+ const requirementIds = new Set();
15
+ for (const requirement of config.requirements) {
16
+ if (requirementIds.has(requirement.id)) {
17
+ throw new GuidedFlowConfigError(`defineFlow(${config.id}): duplicate requirement id "${requirement.id}".`);
18
+ }
19
+ requirementIds.add(requirement.id);
20
+ }
21
+ if (config.confirmation) {
22
+ const field = config.confirmation.stateField;
23
+ const shapeKeys = Object.keys(config.stateSchema.shape);
24
+ if (!shapeKeys.includes(String(field))) {
25
+ throw new GuidedFlowConfigError(`defineFlow(${config.id}): confirmation.stateField "${String(field)}" is not part of stateSchema.`);
26
+ }
27
+ }
28
+ const partialCheck = config.stateSchema.partial().safeParse(config.initialState);
29
+ if (!partialCheck.success) {
30
+ throw new GuidedFlowConfigError(`defineFlow(${config.id}): \`initialState\` does not match \`stateSchema\`: ${partialCheck.error.message}`);
31
+ }
32
+ return Object.freeze({ config, id: config.id, version: config.version });
33
+ }
34
+ //# sourceMappingURL=define-flow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-flow.js","sourceRoot":"","sources":["../../src/guided-flows/define-flow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,MAAM,UAAU,UAAU,CACxB,MAAqD;IAErD,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,qBAAqB,CAAC,+BAA+B,CAAC,CAAC;IACjF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,qBAAqB,CAAC,cAAc,MAAM,CAAC,EAAE,4CAA4C,CAAC,CAAC;IACvG,CAAC;IA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,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,qBAAqB,CAAC,cAAc,MAAM,CAAC,EAAE,uDAAuD,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9I,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare class GuidedFlowConfigError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class GuidedFlowOutputValidationError extends Error {
5
+ readonly flowId: string;
6
+ constructor(message: string, input: {
7
+ flowId: string;
8
+ cause?: unknown;
9
+ });
10
+ }
11
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/guided-flows/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,+BAAgC,SAAQ,KAAK;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAKxE"}
@@ -0,0 +1,15 @@
1
+ export class GuidedFlowConfigError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "GuidedFlowConfigError";
5
+ }
6
+ }
7
+ export class GuidedFlowOutputValidationError extends Error {
8
+ flowId;
9
+ constructor(message, input) {
10
+ super(message, input.cause !== undefined ? { cause: input.cause } : undefined);
11
+ this.name = "GuidedFlowOutputValidationError";
12
+ this.flowId = input.flowId;
13
+ }
14
+ }
15
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/guided-flows/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IAC/C,MAAM,CAAS;IAExB,YAAY,OAAe,EAAE,KAA0C;QACrE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC/E,IAAI,CAAC,IAAI,GAAG,iCAAiC,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { EventBus } from "../event-bus.js";
2
+ import type { JsonObject } from "../types.js";
3
+ export type FlowEventType = "flow.started" | "flow.resumed" | "flow.step.entered" | "flow.step.exited" | "flow.state.updated" | "flow.requirement.satisfied" | "flow.requirement.invalidated" | "flow.tool.requested" | "flow.tool.completed" | "flow.validation.failed" | "flow.waiting_for_user" | "flow.waiting_for_approval" | "flow.completed" | "flow.cancelled" | "flow.failed";
4
+ /** Input to {@link publishFlowEvent}. */
5
+ export type PublishFlowEventInput = {
6
+ type: FlowEventType;
7
+ flowId: string;
8
+ sessionId: string;
9
+ stepId?: string;
10
+ taskId?: string;
11
+ runId?: string;
12
+ payload?: JsonObject;
13
+ };
14
+ /**
15
+ * Publishes onto the agent's existing `EventBus` (`underlying.sdk.events`),
16
+ * which is already wired to `telemetry` and to storage's `EventJournal` when
17
+ * present — no parallel event system.
18
+ */
19
+ export declare function publishFlowEvent(events: EventBus, input: PublishFlowEventInput): Promise<void>;
20
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/guided-flows/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,aAAa,GACrB,cAAc,GACd,cAAc,GACd,mBAAmB,GACnB,kBAAkB,GAClB,oBAAoB,GACpB,4BAA4B,GAC5B,8BAA8B,GAC9B,qBAAqB,GACrB,qBAAqB,GACrB,wBAAwB,GACxB,uBAAuB,GACvB,2BAA2B,GAC3B,gBAAgB,GAChB,gBAAgB,GAChB,aAAa,CAAC;AAElB,yCAAyC;AACzC,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAUpG"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Publishes onto the agent's existing `EventBus` (`underlying.sdk.events`),
3
+ * which is already wired to `telemetry` and to storage's `EventJournal` when
4
+ * present — no parallel event system.
5
+ */
6
+ export async function publishFlowEvent(events, input) {
7
+ await events.publish({
8
+ type: input.type,
9
+ source: "guided-flow",
10
+ ...(input.taskId ? { taskId: input.taskId } : {}),
11
+ ...(input.runId ? { runId: input.runId } : {}),
12
+ ...(input.stepId ? { stepId: input.stepId } : {}),
13
+ visibility: input.type.includes("tool") ? "technical" : "user",
14
+ payload: { flowId: input.flowId, sessionId: input.sessionId, ...(input.payload ?? {}) }
15
+ });
16
+ }
17
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/guided-flows/events.ts"],"names":[],"mappings":"AA+BA;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAgB,EAAE,KAA4B;IACnF,MAAM,MAAM,CAAC,OAAO,CAAC;QACnB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,aAAa;QACrB,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9C,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM;QAC9D,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE;KACxF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,10 @@
1
+ export { defineFlow } from "./define-flow.js";
2
+ export type { EvaluatedRequirement, FlowPatchSource, FlowStatePatch, GuidedFlow, GuidedFlowConfig, GuidedFlowConfirmation, GuidedFlowManifestDescriptor, GuidedFlowRequirement, GuidedFlowRunMeta, GuidedFlowRunResult, GuidedFlowRunState, GuidedFlowStatus, GuidedFlowStep, GuidedFlowToolConfig, GuidedFlowTriggers, StepToolPolicy, ToolResultBinding } from "./types.js";
3
+ export { GuidedFlowConfigError, GuidedFlowOutputValidationError } from "./errors.js";
4
+ export { GuidedFlowRuntime } from "./runtime.js";
5
+ export type { GuidedFlowRuntimeOptions, GuidedFlowTurnInput, GuidedFlowTurnOutcome } from "./runtime.js";
6
+ export { createInMemoryGuidedFlowStateStore, hasGuidedFlowStateStore, InMemoryGuidedFlowStateStore, resolveGuidedFlowStateStore } from "./persistence.js";
7
+ export type { GuidedFlowStateStore } from "./persistence.js";
8
+ export { publishFlowEvent } from "./events.js";
9
+ export type { FlowEventType, PublishFlowEventInput } from "./events.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guided-flows/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EACV,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EACtB,4BAA4B,EAC5B,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACzG,OAAO,EACL,kCAAkC,EAClC,uBAAuB,EACvB,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { defineFlow } from "./define-flow.js";
2
+ export { GuidedFlowConfigError, GuidedFlowOutputValidationError } from "./errors.js";
3
+ export { GuidedFlowRuntime } from "./runtime.js";
4
+ export { createInMemoryGuidedFlowStateStore, hasGuidedFlowStateStore, InMemoryGuidedFlowStateStore, resolveGuidedFlowStateStore } from "./persistence.js";
5
+ export { publishFlowEvent } from "./events.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/guided-flows/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAoB9C,OAAO,EAAE,qBAAqB,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EACL,kCAAkC,EAClC,uBAAuB,EACvB,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { GuidedFlowRunState } from "./types.js";
2
+ /**
3
+ * Narrow, domain-specific storage contract — mirrors `workflow.ts`'s
4
+ * `WorkflowCheckpointStore` precedent instead of growing `NexaStorage` in
5
+ * `storage.ts`. A caller's `NexaStorage` (or any object) works automatically
6
+ * as soon as it implements these two methods (duck-typed, see
7
+ * `hasGuidedFlowStateStore` below) — `file-storage.ts`, `sqlite-storage.ts`,
8
+ * `postgres-storage.ts` and `redis-storage.ts` all implement it.
9
+ */
10
+ export type GuidedFlowStateStore = {
11
+ saveFlowState(record: GuidedFlowRunState): Promise<void> | void;
12
+ getFlowState(sessionId: string, flowId: string): Promise<GuidedFlowRunState | undefined> | GuidedFlowRunState | undefined;
13
+ listFlowStates?(sessionId: string): Promise<GuidedFlowRunState[]> | GuidedFlowRunState[];
14
+ deleteFlowState?(sessionId: string, flowId: string): Promise<void> | void;
15
+ };
16
+ export declare class InMemoryGuidedFlowStateStore implements GuidedFlowStateStore {
17
+ private readonly records;
18
+ saveFlowState(record: GuidedFlowRunState): void;
19
+ getFlowState(sessionId: string, flowId: string): GuidedFlowRunState | undefined;
20
+ listFlowStates(sessionId: string): GuidedFlowRunState[];
21
+ deleteFlowState(sessionId: string, flowId: string): void;
22
+ }
23
+ export declare function createInMemoryGuidedFlowStateStore(): InMemoryGuidedFlowStateStore;
24
+ export declare function hasGuidedFlowStateStore(value: unknown): value is GuidedFlowStateStore;
25
+ /**
26
+ * Resolves the effective store for an agent: prefers a store duck-typed off
27
+ * `config.storage` (so durable storage "just works" once configured), and
28
+ * otherwise falls back to a private in-memory store — Guided Flows always
29
+ * work with zero storage configuration.
30
+ */
31
+ export declare function resolveGuidedFlowStateStore(storage: unknown): GuidedFlowStateStore;
32
+ //# sourceMappingURL=persistence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../src/guided-flows/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAChE,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,GAAG,kBAAkB,GAAG,SAAS,CAAC;IAC1H,cAAc,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,GAAG,kBAAkB,EAAE,CAAC;IACzF,eAAe,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC3E,CAAC;AAEF,qBAAa,4BAA6B,YAAW,oBAAoB;IACvE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyC;IAEjE,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI;IAI/C,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAK/E,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,EAAE;IAIvD,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAGzD;AAED,wBAAgB,kCAAkC,IAAI,4BAA4B,CAEjF;AAMD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAErF;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,oBAAoB,CAGlF"}
@@ -0,0 +1,37 @@
1
+ export class InMemoryGuidedFlowStateStore {
2
+ records = new Map();
3
+ saveFlowState(record) {
4
+ this.records.set(recordKey(record.sessionId, record.flowId), structuredClone(record));
5
+ }
6
+ getFlowState(sessionId, flowId) {
7
+ const record = this.records.get(recordKey(sessionId, flowId));
8
+ return record ? structuredClone(record) : undefined;
9
+ }
10
+ listFlowStates(sessionId) {
11
+ return [...this.records.values()].filter((record) => record.sessionId === sessionId).map((record) => structuredClone(record));
12
+ }
13
+ deleteFlowState(sessionId, flowId) {
14
+ this.records.delete(recordKey(sessionId, flowId));
15
+ }
16
+ }
17
+ export function createInMemoryGuidedFlowStateStore() {
18
+ return new InMemoryGuidedFlowStateStore();
19
+ }
20
+ function recordKey(sessionId, flowId) {
21
+ return `${sessionId}::${flowId}`;
22
+ }
23
+ export function hasGuidedFlowStateStore(value) {
24
+ return Boolean(value && typeof value === "object" && "saveFlowState" in value && "getFlowState" in value);
25
+ }
26
+ /**
27
+ * Resolves the effective store for an agent: prefers a store duck-typed off
28
+ * `config.storage` (so durable storage "just works" once configured), and
29
+ * otherwise falls back to a private in-memory store — Guided Flows always
30
+ * work with zero storage configuration.
31
+ */
32
+ export function resolveGuidedFlowStateStore(storage) {
33
+ if (hasGuidedFlowStateStore(storage))
34
+ return storage;
35
+ return createInMemoryGuidedFlowStateStore();
36
+ }
37
+ //# sourceMappingURL=persistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../src/guided-flows/persistence.ts"],"names":[],"mappings":"AAiBA,MAAM,OAAO,4BAA4B;IACtB,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEjE,aAAa,CAAC,MAA0B;QACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,YAAY,CAAC,SAAiB,EAAE,MAAc;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;QAC9D,OAAO,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;IAED,cAAc,CAAC,SAAiB;QAC9B,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAChI,CAAC;IAED,eAAe,CAAC,SAAiB,EAAE,MAAc;QAC/C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,UAAU,kCAAkC;IAChD,OAAO,IAAI,4BAA4B,EAAE,CAAC;AAC5C,CAAC;AAED,SAAS,SAAS,CAAC,SAAiB,EAAE,MAAc;IAClD,OAAO,GAAG,SAAS,KAAK,MAAM,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,eAAe,IAAI,KAAK,IAAI,cAAc,IAAI,KAAK,CAAC,CAAC;AAC5G,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAAgB;IAC1D,IAAI,uBAAuB,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IACrD,OAAO,kCAAkC,EAAE,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { z } from "zod";
2
+ import type { EvaluatedRequirement, GuidedFlowConfig } from "./types.js";
3
+ export declare function evaluateRequirements<TStateSchema extends z.AnyZodObject, TOutputSchema extends z.ZodTypeAny>(config: GuidedFlowConfig<TStateSchema, TOutputSchema>, state: z.infer<TStateSchema>): EvaluatedRequirement[];
4
+ export declare function diffRequirements(previous: EvaluatedRequirement[], next: EvaluatedRequirement[]): {
5
+ newlySatisfied: string[];
6
+ newlyInvalidated: string[];
7
+ };
8
+ //# sourceMappingURL=requirements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requirements.d.ts","sourceRoot":"","sources":["../../src/guided-flows/requirements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEzE,wBAAgB,oBAAoB,CAAC,YAAY,SAAS,CAAC,CAAC,YAAY,EAAE,aAAa,SAAS,CAAC,CAAC,UAAU,EAC1G,MAAM,EAAE,gBAAgB,CAAC,YAAY,EAAE,aAAa,CAAC,EACrD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,GAC3B,oBAAoB,EAAE,CAMxB;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,GAAG;IAChG,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,CAUA"}
@@ -0,0 +1,21 @@
1
+ export function evaluateRequirements(config, state) {
2
+ return config.requirements.map((requirement) => ({
3
+ id: requirement.id,
4
+ description: requirement.description,
5
+ satisfied: Boolean(requirement.satisfied({ state }))
6
+ }));
7
+ }
8
+ export function diffRequirements(previous, next) {
9
+ const previousById = new Map(previous.map((requirement) => [requirement.id, requirement.satisfied]));
10
+ const newlySatisfied = [];
11
+ const newlyInvalidated = [];
12
+ for (const requirement of next) {
13
+ const before = previousById.get(requirement.id);
14
+ if (requirement.satisfied && before !== true)
15
+ newlySatisfied.push(requirement.id);
16
+ if (!requirement.satisfied && before === true)
17
+ newlyInvalidated.push(requirement.id);
18
+ }
19
+ return { newlySatisfied, newlyInvalidated };
20
+ }
21
+ //# sourceMappingURL=requirements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requirements.js","sourceRoot":"","sources":["../../src/guided-flows/requirements.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,oBAAoB,CAClC,MAAqD,EACrD,KAA4B;IAE5B,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC/C,EAAE,EAAE,WAAW,CAAC,EAAE;QAClB,WAAW,EAAE,WAAW,CAAC,WAAW;QACpC,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;KACrD,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAgC,EAAE,IAA4B;IAI7F,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACrG,MAAM,cAAc,GAAa,EAAE,CAAC;IACpC,MAAM,gBAAgB,GAAa,EAAE,CAAC;IACtC,KAAK,MAAM,WAAW,IAAI,IAAI,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAChD,IAAI,WAAW,CAAC,SAAS,IAAI,MAAM,KAAK,IAAI;YAAE,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAClF,IAAI,CAAC,WAAW,CAAC,SAAS,IAAI,MAAM,KAAK,IAAI;YAAE,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { ChatMessage, OpenAICompatibleChatClient } from "../openai-compatible.js";
2
+ import type { AgentToolRegistration } from "../openai-agent.js";
3
+ import type { ModelHarness } from "../model-harness.js";
4
+ import type { HookDispatcher } from "../hooks.js";
5
+ import type { EventBus } from "../event-bus.js";
6
+ import type { SkillDefinition } from "../skills.js";
7
+ import { type TenantContext } from "../tenancy.js";
8
+ import type { JsonObject } from "../types.js";
9
+ import type { GuidedFlowStateStore } from "./persistence.js";
10
+ import type { FlowStatePatch, GuidedFlow, GuidedFlowRunMeta, GuidedFlowRunState } from "./types.js";
11
+ export type GuidedFlowRuntimeOptions = {
12
+ flows: GuidedFlow<any, any>[];
13
+ client: OpenAICompatibleChatClient;
14
+ providerId: string;
15
+ model: string;
16
+ toolRegistrations: AgentToolRegistration[];
17
+ skills: SkillDefinition[];
18
+ hooks: HookDispatcher;
19
+ events: EventBus;
20
+ harness?: ModelHarness;
21
+ store: GuidedFlowStateStore;
22
+ flowSelector?: (input: {
23
+ text: string;
24
+ flows: GuidedFlow<any, any>[];
25
+ }) => string | undefined | Promise<string | undefined>;
26
+ };
27
+ export type GuidedFlowTurnInput = {
28
+ text: string;
29
+ messages: ChatMessage[];
30
+ sessionId: string;
31
+ tenant?: TenantContext;
32
+ explicitFlow?: string;
33
+ };
34
+ export type GuidedFlowTurnOutcome = {
35
+ handled: false;
36
+ } | {
37
+ handled: true;
38
+ text: string;
39
+ output?: unknown;
40
+ state: JsonObject;
41
+ flow: GuidedFlowRunMeta;
42
+ };
43
+ /**
44
+ * Drives Guided Flow turns. Constructed once per agent (by `kernel.ts` when
45
+ * `config.flows?.length`) and never streamed — `runStream()` in
46
+ * `openai-agent.ts` is untouched; internally this still uses the same
47
+ * `runNativeToolLoop`/`ModelHarness` contracts, just called directly rather
48
+ * than through `agent.run()`'s normal path.
49
+ */
50
+ export declare class GuidedFlowRuntime {
51
+ private readonly options;
52
+ constructor(options: GuidedFlowRuntimeOptions);
53
+ private flowById;
54
+ private requireFlow;
55
+ private soleFlow;
56
+ private key;
57
+ selectFlow(input: {
58
+ text: string;
59
+ sessionId: string;
60
+ tenant?: TenantContext;
61
+ explicitFlow?: string;
62
+ }): Promise<GuidedFlow | undefined>;
63
+ runTurn(input: GuidedFlowTurnInput): Promise<GuidedFlowTurnOutcome>;
64
+ private driveFlow;
65
+ private applyPatch;
66
+ private announceStepChange;
67
+ private forwardNativeEvent;
68
+ cancel(sessionId: string, flowId?: string, tenant?: TenantContext): Promise<void>;
69
+ resume(sessionId: string, flowId?: string, tenant?: TenantContext): Promise<GuidedFlowRunState | undefined>;
70
+ reset(sessionId: string, flowId?: string, tenant?: TenantContext): Promise<void>;
71
+ patchState(sessionId: string, flowId: string, patch: FlowStatePatch<Record<string, unknown>>, tenant?: TenantContext): Promise<GuidedFlowRunState>;
72
+ getState(sessionId: string, flowId?: string, tenant?: TenantContext): Promise<GuidedFlowRunState | undefined>;
73
+ }
74
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/guided-flows/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQ9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAEV,cAAc,EACd,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,EAGnB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IAC9B,MAAM,EAAE,0BAA0B,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,qBAAqB,EAAE,CAAC;IAC3C,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,QAAQ,CAAC;IACjB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,KAAK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