@statelyai/agent 2.0.0-alpha.11 → 2.0.0-alpha.13

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 (66) hide show
  1. package/dist/ai-sdk.cjs +4 -5
  2. package/dist/ai-sdk.d.cts +7 -4
  3. package/dist/ai-sdk.d.mts +7 -4
  4. package/dist/ai-sdk.mjs +1 -2
  5. package/dist/{events-JiVPYrct.mjs → decision-BezSD_YC.mjs} +327 -20
  6. package/dist/{events-CRQj3VtP.cjs → decision-dWGhBh0P.cjs} +401 -28
  7. package/dist/errors-BQRk9eiZ.d.cts +19 -0
  8. package/dist/errors-C9rxnWbX.d.mts +19 -0
  9. package/dist/errors-CeSXQx0v.mjs +23 -0
  10. package/dist/errors-DUBBzRLP.cjs +28 -0
  11. package/dist/event-log-store-CNT_7F0V.cjs +452 -0
  12. package/dist/event-log-store-CriMgX1D.d.mts +144 -0
  13. package/dist/event-log-store-D7pWtIhb.mjs +411 -0
  14. package/dist/event-log-store-Ruq18mGp.d.cts +144 -0
  15. package/dist/index.cjs +1050 -705
  16. package/dist/index.d.cts +538 -565
  17. package/dist/index.d.mts +538 -565
  18. package/dist/index.mjs +950 -644
  19. package/dist/machines.cjs +752 -0
  20. package/dist/machines.d.cts +372 -0
  21. package/dist/machines.d.mts +372 -0
  22. package/dist/machines.mjs +741 -0
  23. package/dist/otel.cjs +268 -0
  24. package/dist/otel.d.cts +67 -0
  25. package/dist/otel.d.mts +67 -0
  26. package/dist/otel.mjs +267 -0
  27. package/dist/run-agent-C3mFDGTf.d.mts +1111 -0
  28. package/dist/run-agent-DnvtcnTZ.d.cts +1111 -0
  29. package/dist/setup-agent-DAZZSjDS.mjs +1711 -0
  30. package/dist/setup-agent-DP95MFrI.cjs +1836 -0
  31. package/dist/sqlite.cjs +135 -0
  32. package/dist/sqlite.d.cts +57 -0
  33. package/dist/sqlite.d.mts +57 -0
  34. package/dist/sqlite.mjs +133 -0
  35. package/dist/{text-logic-CaKqgX4Y.d.mts → text-logic-BDxwQNsD.d.cts} +155 -72
  36. package/dist/{text-logic-Ckhr2kKC.d.cts → text-logic-TkKPw8Aq.d.mts} +155 -72
  37. package/dist/{types-qm00QF91.d.mts → types-QbEfCVny.d.cts} +1 -1
  38. package/dist/{types-C9QiMjre.d.cts → types-_FXoFBGO.d.mts} +1 -1
  39. package/package.json +47 -39
  40. package/readme.md +49 -12
  41. package/schemas/agent-workflow.json +40 -21
  42. package/skills/generate-machine/SKILL.md +267 -0
  43. package/dist/adapter.cjs +0 -15
  44. package/dist/adapter.d.cts +0 -4
  45. package/dist/adapter.d.mts +0 -4
  46. package/dist/adapter.mjs +0 -2
  47. package/dist/decision-C3k4ve51.mjs +0 -227
  48. package/dist/decision-D8wJrM8W.cjs +0 -286
  49. package/dist/openai-compat.cjs +0 -309
  50. package/dist/openai-compat.d.cts +0 -59
  51. package/dist/openai-compat.d.mts +0 -59
  52. package/dist/openai-compat.mjs +0 -308
  53. package/dist/steps-BALp1eZo.d.mts +0 -198
  54. package/dist/steps-CVe54GPP.cjs +0 -420
  55. package/dist/steps-CkyyyuHd.mjs +0 -379
  56. package/dist/steps-MjnQI4aB.d.cts +0 -198
  57. package/dist/steps.cjs +0 -12
  58. package/dist/steps.d.cts +0 -3
  59. package/dist/steps.d.mts +0 -3
  60. package/dist/steps.mjs +0 -3
  61. package/dist/utils-BYqT_Dyv.d.cts +0 -108
  62. package/dist/utils-Do5wIJrh.d.mts +0 -108
  63. package/dist/zod.cjs +0 -31
  64. package/dist/zod.d.cts +0 -30
  65. package/dist/zod.d.mts +0 -30
  66. package/dist/zod.mjs +0 -30
@@ -1,108 +0,0 @@
1
- import { A as UserMessage, C as StandardSchemaV1, D as ToolMessage, E as ToolCallPart, T as TextPart, k as ToolResultPart, p as AssistantMessage, r as AgentMessage, v as FilePart, w as SystemMessage, y as ImagePart } from "./types-C9QiMjre.cjs";
2
- import { AnyMachineSnapshot, AnyStateMachine } from "xstate";
3
-
4
- //#region src/utils.d.ts
5
- /**
6
- * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
7
- * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
8
- * JSON-serializability: functions, `undefined`, and other non-JSON values are
9
- * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
10
- * plain-JSON deep clone, not a live snapshot.
11
- */
12
- declare function persistSnapshot<TSnapshot>(snapshot: TSnapshot): TSnapshot;
13
- /**
14
- * A stable, dependency-free structural fingerprint of a machine — a short hex
15
- * `djb2` hash over its **structural** config only: state ids/nesting, transition
16
- * event types and targets, invoke `src`s, `initial`, and any other serializable
17
- * config fields. Function values (context/output builders, prompts, inline
18
- * guards/actions) are excluded entirely, so two machines that differ only in
19
- * their prompts or executors hash identically; adding/removing/retargeting a
20
- * state or transition changes the hash.
21
- *
22
- * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
23
- * detect a structurally-edited machine on resume. It is a change detector, not
24
- * a cryptographic digest — collisions are possible but unlikely for real
25
- * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
26
- */
27
- declare function getMachineStructuralHash(machine: AnyStateMachine): string;
28
- /** Builds a {@link UserMessage} from a string or multimodal content parts. */
29
- declare function userMessage(content: string | Array<TextPart | ImagePart | FilePart>): UserMessage;
30
- /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
31
- declare function assistantMessage(content: string | Array<TextPart | FilePart | ToolCallPart | ToolResultPart>): AssistantMessage;
32
- /** Builds a {@link SystemMessage}. */
33
- declare function systemMessage(content: string): SystemMessage;
34
- /** Builds a {@link ToolMessage} from one or more tool-result parts. */
35
- declare function toolMessage(content: Array<ToolResultPart>): ToolMessage;
36
- type MetaOfSnapshot<TSnapshot extends {
37
- getMeta(): Record<string, unknown>;
38
- }> = NonNullable<ReturnType<TSnapshot["getMeta"]>[keyof ReturnType<TSnapshot["getMeta"]>]>;
39
- /**
40
- * Returns the merged `meta` of a snapshot's active state(s) — the typed
41
- * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
42
- *
43
- * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
44
- * state, but parallel/nested machines can have several. This shallow-merges
45
- * every active state's meta into one object (later/deeper entries win) and
46
- * returns `{}` when no active state declares meta.
47
- *
48
- * The return type is recovered from the snapshot's own `getMeta()` type, so a
49
- * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
50
- * output type. Pass an explicit `TMeta` to override when the snapshot is
51
- * untyped (e.g. `AnyMachineSnapshot`).
52
- *
53
- * @example HITL: read the current state's interaction protocol off an idle
54
- * snapshot to render for a human.
55
- * ```ts
56
- * const { interaction } = getStateMeta(result.snapshot);
57
- * ```
58
- */
59
- declare function getStateMeta<TSnapshot extends {
60
- getMeta(): Record<string, unknown>;
61
- } = AnyMachineSnapshot, TMeta = MetaOfSnapshot<TSnapshot>>(snapshot: TSnapshot): Partial<TMeta>;
62
- /**
63
- * Reads the run-owned message log off a snapshot settled by a `runAgent` call
64
- * that used `getRequests` (or `options.messages`) — the typed replacement for
65
- * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
66
- * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
67
- * so it survives a JSON persist/resume round-trip; this accessor works on the
68
- * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
69
- * when no log was stamped (e.g. a default invoke-driven run).
70
- *
71
- * The write path is `runAgent(..., { messages })`: an explicit seed that
72
- * overrides the resume snapshot's stamped log (fold in a user reply on
73
- * resume, or start a run with prior history).
74
- */
75
- declare function getAgentMessages(snapshot: unknown): AgentMessage[];
76
- /**
77
- * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
78
- * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
79
- * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
80
- * can't read directly — see the `ai-sdk` tool pass-through and `openai-compat`
81
- * tool serialization.
82
- */
83
- declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
84
- /**
85
- * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
86
- * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
87
- * `z.toJSONSchema`), awaiting it when the producer is async. Returns
88
- * `undefined` when the schema doesn't expose the extension. Use this to build
89
- * a provider request's `response_format`/tool `parameters` from a schema.
90
- */
91
- declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string, unknown> | undefined>;
92
- /**
93
- * Synchronous variant of {@link getJsonSchema}, for call sites that can't
94
- * await (building tool/event descriptors inline). An async JSON Schema
95
- * producer is treated as absent (returns `undefined`) — in practice Zod's
96
- * `z.toJSONSchema` resolves synchronously.
97
- */
98
- declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
99
- /**
100
- * Validates `value` against a {@link StandardSchemaV1}, synchronously.
101
- * Throws if the schema's `validate` returns a `Promise` (async validation is
102
- * not supported anywhere in this library) or if validation reports issues —
103
- * in which case the thrown `Error.message` joins every issue message with
104
- * `', '`.
105
- */
106
- declare function validateSchemaSync<T>(schema: StandardSchemaV1<T>, value: unknown): T;
107
- //#endregion
108
- export { getMachineStructuralHash as a, persistSnapshot as c, userMessage as d, validateSchemaSync as f, getJsonSchemaSync as i, systemMessage as l, getAgentMessages as n, getStateMeta as o, getJsonSchema as r, isStandardSchema as s, assistantMessage as t, toolMessage as u };
@@ -1,108 +0,0 @@
1
- import { A as UserMessage, C as StandardSchemaV1, D as ToolMessage, E as ToolCallPart, T as TextPart, k as ToolResultPart, p as AssistantMessage, r as AgentMessage, v as FilePart, w as SystemMessage, y as ImagePart } from "./types-qm00QF91.mjs";
2
- import { AnyMachineSnapshot, AnyStateMachine } from "xstate";
3
-
4
- //#region src/utils.d.ts
5
- /**
6
- * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
7
- * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
8
- * JSON-serializability: functions, `undefined`, and other non-JSON values are
9
- * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
10
- * plain-JSON deep clone, not a live snapshot.
11
- */
12
- declare function persistSnapshot<TSnapshot>(snapshot: TSnapshot): TSnapshot;
13
- /**
14
- * A stable, dependency-free structural fingerprint of a machine — a short hex
15
- * `djb2` hash over its **structural** config only: state ids/nesting, transition
16
- * event types and targets, invoke `src`s, `initial`, and any other serializable
17
- * config fields. Function values (context/output builders, prompts, inline
18
- * guards/actions) are excluded entirely, so two machines that differ only in
19
- * their prompts or executors hash identically; adding/removing/retargeting a
20
- * state or transition changes the hash.
21
- *
22
- * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
23
- * detect a structurally-edited machine on resume. It is a change detector, not
24
- * a cryptographic digest — collisions are possible but unlikely for real
25
- * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
26
- */
27
- declare function getMachineStructuralHash(machine: AnyStateMachine): string;
28
- /** Builds a {@link UserMessage} from a string or multimodal content parts. */
29
- declare function userMessage(content: string | Array<TextPart | ImagePart | FilePart>): UserMessage;
30
- /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
31
- declare function assistantMessage(content: string | Array<TextPart | FilePart | ToolCallPart | ToolResultPart>): AssistantMessage;
32
- /** Builds a {@link SystemMessage}. */
33
- declare function systemMessage(content: string): SystemMessage;
34
- /** Builds a {@link ToolMessage} from one or more tool-result parts. */
35
- declare function toolMessage(content: Array<ToolResultPart>): ToolMessage;
36
- type MetaOfSnapshot<TSnapshot extends {
37
- getMeta(): Record<string, unknown>;
38
- }> = NonNullable<ReturnType<TSnapshot["getMeta"]>[keyof ReturnType<TSnapshot["getMeta"]>]>;
39
- /**
40
- * Returns the merged `meta` of a snapshot's active state(s) — the typed
41
- * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
42
- *
43
- * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
44
- * state, but parallel/nested machines can have several. This shallow-merges
45
- * every active state's meta into one object (later/deeper entries win) and
46
- * returns `{}` when no active state declares meta.
47
- *
48
- * The return type is recovered from the snapshot's own `getMeta()` type, so a
49
- * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
50
- * output type. Pass an explicit `TMeta` to override when the snapshot is
51
- * untyped (e.g. `AnyMachineSnapshot`).
52
- *
53
- * @example HITL: read the current state's interaction protocol off an idle
54
- * snapshot to render for a human.
55
- * ```ts
56
- * const { interaction } = getStateMeta(result.snapshot);
57
- * ```
58
- */
59
- declare function getStateMeta<TSnapshot extends {
60
- getMeta(): Record<string, unknown>;
61
- } = AnyMachineSnapshot, TMeta = MetaOfSnapshot<TSnapshot>>(snapshot: TSnapshot): Partial<TMeta>;
62
- /**
63
- * Reads the run-owned message log off a snapshot settled by a `runAgent` call
64
- * that used `getRequests` (or `options.messages`) — the typed replacement for
65
- * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
66
- * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
67
- * so it survives a JSON persist/resume round-trip; this accessor works on the
68
- * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
69
- * when no log was stamped (e.g. a default invoke-driven run).
70
- *
71
- * The write path is `runAgent(..., { messages })`: an explicit seed that
72
- * overrides the resume snapshot's stamped log (fold in a user reply on
73
- * resume, or start a run with prior history).
74
- */
75
- declare function getAgentMessages(snapshot: unknown): AgentMessage[];
76
- /**
77
- * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
78
- * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
79
- * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
80
- * can't read directly — see the `ai-sdk` tool pass-through and `openai-compat`
81
- * tool serialization.
82
- */
83
- declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
84
- /**
85
- * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
86
- * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
87
- * `z.toJSONSchema`), awaiting it when the producer is async. Returns
88
- * `undefined` when the schema doesn't expose the extension. Use this to build
89
- * a provider request's `response_format`/tool `parameters` from a schema.
90
- */
91
- declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string, unknown> | undefined>;
92
- /**
93
- * Synchronous variant of {@link getJsonSchema}, for call sites that can't
94
- * await (building tool/event descriptors inline). An async JSON Schema
95
- * producer is treated as absent (returns `undefined`) — in practice Zod's
96
- * `z.toJSONSchema` resolves synchronously.
97
- */
98
- declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
99
- /**
100
- * Validates `value` against a {@link StandardSchemaV1}, synchronously.
101
- * Throws if the schema's `validate` returns a `Promise` (async validation is
102
- * not supported anywhere in this library) or if validation reports issues —
103
- * in which case the thrown `Error.message` joins every issue message with
104
- * `', '`.
105
- */
106
- declare function validateSchemaSync<T>(schema: StandardSchemaV1<T>, value: unknown): T;
107
- //#endregion
108
- export { getMachineStructuralHash as a, persistSnapshot as c, userMessage as d, validateSchemaSync as f, getJsonSchemaSync as i, systemMessage as l, getAgentMessages as n, getStateMeta as o, getJsonSchema as r, isStandardSchema as s, assistantMessage as t, toolMessage as u };
package/dist/zod.cjs DELETED
@@ -1,31 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let zod = require("zod");
3
- //#region src/zod/index.ts
4
- /**
5
- * A zod schema for an `AgentMessage[]` context/input field — the typed,
6
- * dependency-light replacement for the hand-rolled
7
- * `z.custom<AgentMessage[]>((value) => Array.isArray(value))` recipe repeated
8
- * across machines that carry a message transcript in context.
9
- *
10
- * `AgentMessage` is a structural union (see `src/types.ts`), not something to
11
- * re-declare as a zod object, so this stays a `z.custom` under the hood while
12
- * exposing the precise `z.ZodType<AgentMessage[]>` type. Validation checks that
13
- * the value is an array; element shape is trusted (the library's own message
14
- * builders and adapters produce well-formed `AgentMessage`s).
15
- *
16
- * `zod` is an optional peer of `@statelyai/agent` — this subpath is the only
17
- * place it's imported, mirroring how `./ai-sdk` gates on `ai`.
18
- *
19
- * @example
20
- * ```ts
21
- * import { z } from 'zod';
22
- * import { zodAgentMessages } from '@statelyai/agent/zod';
23
- *
24
- * const context = z.object({ messages: zodAgentMessages() });
25
- * ```
26
- */
27
- function zodAgentMessages() {
28
- return zod.z.custom((value) => Array.isArray(value));
29
- }
30
- //#endregion
31
- exports.zodAgentMessages = zodAgentMessages;
package/dist/zod.d.cts DELETED
@@ -1,30 +0,0 @@
1
- import { r as AgentMessage } from "./types-C9QiMjre.cjs";
2
- import { z } from "zod";
3
-
4
- //#region src/zod/index.d.ts
5
- /**
6
- * A zod schema for an `AgentMessage[]` context/input field — the typed,
7
- * dependency-light replacement for the hand-rolled
8
- * `z.custom<AgentMessage[]>((value) => Array.isArray(value))` recipe repeated
9
- * across machines that carry a message transcript in context.
10
- *
11
- * `AgentMessage` is a structural union (see `src/types.ts`), not something to
12
- * re-declare as a zod object, so this stays a `z.custom` under the hood while
13
- * exposing the precise `z.ZodType<AgentMessage[]>` type. Validation checks that
14
- * the value is an array; element shape is trusted (the library's own message
15
- * builders and adapters produce well-formed `AgentMessage`s).
16
- *
17
- * `zod` is an optional peer of `@statelyai/agent` — this subpath is the only
18
- * place it's imported, mirroring how `./ai-sdk` gates on `ai`.
19
- *
20
- * @example
21
- * ```ts
22
- * import { z } from 'zod';
23
- * import { zodAgentMessages } from '@statelyai/agent/zod';
24
- *
25
- * const context = z.object({ messages: zodAgentMessages() });
26
- * ```
27
- */
28
- declare function zodAgentMessages(): z.ZodType<AgentMessage[]>;
29
- //#endregion
30
- export { zodAgentMessages };
package/dist/zod.d.mts DELETED
@@ -1,30 +0,0 @@
1
- import { r as AgentMessage } from "./types-qm00QF91.mjs";
2
- import { z } from "zod";
3
-
4
- //#region src/zod/index.d.ts
5
- /**
6
- * A zod schema for an `AgentMessage[]` context/input field — the typed,
7
- * dependency-light replacement for the hand-rolled
8
- * `z.custom<AgentMessage[]>((value) => Array.isArray(value))` recipe repeated
9
- * across machines that carry a message transcript in context.
10
- *
11
- * `AgentMessage` is a structural union (see `src/types.ts`), not something to
12
- * re-declare as a zod object, so this stays a `z.custom` under the hood while
13
- * exposing the precise `z.ZodType<AgentMessage[]>` type. Validation checks that
14
- * the value is an array; element shape is trusted (the library's own message
15
- * builders and adapters produce well-formed `AgentMessage`s).
16
- *
17
- * `zod` is an optional peer of `@statelyai/agent` — this subpath is the only
18
- * place it's imported, mirroring how `./ai-sdk` gates on `ai`.
19
- *
20
- * @example
21
- * ```ts
22
- * import { z } from 'zod';
23
- * import { zodAgentMessages } from '@statelyai/agent/zod';
24
- *
25
- * const context = z.object({ messages: zodAgentMessages() });
26
- * ```
27
- */
28
- declare function zodAgentMessages(): z.ZodType<AgentMessage[]>;
29
- //#endregion
30
- export { zodAgentMessages };
package/dist/zod.mjs DELETED
@@ -1,30 +0,0 @@
1
- import { z } from "zod";
2
- //#region src/zod/index.ts
3
- /**
4
- * A zod schema for an `AgentMessage[]` context/input field — the typed,
5
- * dependency-light replacement for the hand-rolled
6
- * `z.custom<AgentMessage[]>((value) => Array.isArray(value))` recipe repeated
7
- * across machines that carry a message transcript in context.
8
- *
9
- * `AgentMessage` is a structural union (see `src/types.ts`), not something to
10
- * re-declare as a zod object, so this stays a `z.custom` under the hood while
11
- * exposing the precise `z.ZodType<AgentMessage[]>` type. Validation checks that
12
- * the value is an array; element shape is trusted (the library's own message
13
- * builders and adapters produce well-formed `AgentMessage`s).
14
- *
15
- * `zod` is an optional peer of `@statelyai/agent` — this subpath is the only
16
- * place it's imported, mirroring how `./ai-sdk` gates on `ai`.
17
- *
18
- * @example
19
- * ```ts
20
- * import { z } from 'zod';
21
- * import { zodAgentMessages } from '@statelyai/agent/zod';
22
- *
23
- * const context = z.object({ messages: zodAgentMessages() });
24
- * ```
25
- */
26
- function zodAgentMessages() {
27
- return z.custom((value) => Array.isArray(value));
28
- }
29
- //#endregion
30
- export { zodAgentMessages };