@superdurable/dex-agents 0.1.0 → 0.3.0

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 (168) hide show
  1. package/README.md +1608 -64
  2. package/dist/src/agent-built-in-tools.d.ts +81 -0
  3. package/dist/src/agent-built-in-tools.js +246 -0
  4. package/dist/src/agent-built-in-tools.js.map +1 -0
  5. package/dist/src/agent-context-compaction.d.ts +254 -0
  6. package/dist/src/agent-context-compaction.js +287 -0
  7. package/dist/src/agent-context-compaction.js.map +1 -0
  8. package/dist/src/agent-framework-runner.d.ts +456 -16
  9. package/dist/src/agent-framework-runner.js +4 -3
  10. package/dist/src/agent-framework-runner.js.map +1 -1
  11. package/dist/src/agent-plans.d.ts +48 -0
  12. package/dist/src/agent-plans.js +86 -0
  13. package/dist/src/agent-plans.js.map +1 -0
  14. package/dist/src/agent-session-cancellation-steps.d.ts +28 -0
  15. package/dist/src/agent-session-cancellation-steps.js +154 -0
  16. package/dist/src/agent-session-cancellation-steps.js.map +1 -0
  17. package/dist/src/agent-session-codecs.d.ts +65 -4
  18. package/dist/src/agent-session-codecs.js +343 -8
  19. package/dist/src/agent-session-codecs.js.map +1 -1
  20. package/dist/src/agent-session-failure.d.ts +58 -0
  21. package/dist/src/agent-session-failure.js +126 -0
  22. package/dist/src/agent-session-failure.js.map +1 -0
  23. package/dist/src/agent-session-flow-graph-cli.d.ts +2 -0
  24. package/dist/src/agent-session-flow-graph-cli.js +47 -0
  25. package/dist/src/agent-session-flow-graph-cli.js.map +1 -0
  26. package/dist/src/agent-session-flow-graph.d.ts +38 -0
  27. package/dist/src/agent-session-flow-graph.js +54 -0
  28. package/dist/src/agent-session-flow-graph.js.map +1 -0
  29. package/dist/src/agent-session-flow-graph.json +2187 -0
  30. package/dist/src/agent-session-flow.d.ts +317 -28
  31. package/dist/src/agent-session-flow.js +373 -21
  32. package/dist/src/agent-session-flow.js.map +1 -1
  33. package/dist/src/agent-session-persistence.d.ts +81 -4
  34. package/dist/src/agent-session-persistence.js +33 -2
  35. package/dist/src/agent-session-persistence.js.map +1 -1
  36. package/dist/src/agent-session-settings.d.ts +58 -0
  37. package/dist/src/agent-session-settings.js +81 -0
  38. package/dist/src/agent-session-settings.js.map +1 -0
  39. package/dist/src/agent-session-spend-limit.d.ts +156 -0
  40. package/dist/src/agent-session-spend-limit.js +42 -0
  41. package/dist/src/agent-session-spend-limit.js.map +1 -0
  42. package/dist/src/agent-session-start.d.ts +49 -0
  43. package/dist/src/agent-session-start.js +67 -0
  44. package/dist/src/agent-session-start.js.map +1 -0
  45. package/dist/src/agent-session-step-options.d.ts +78 -0
  46. package/dist/src/agent-session-step-options.js +71 -0
  47. package/dist/src/agent-session-step-options.js.map +1 -0
  48. package/dist/src/agent-session-step-types.d.ts +20 -0
  49. package/dist/src/agent-session-step-types.js +28 -0
  50. package/dist/src/agent-session-step-types.js.map +1 -0
  51. package/dist/src/agent-session-steps.d.ts +103 -8
  52. package/dist/src/agent-session-steps.js +997 -197
  53. package/dist/src/agent-session-steps.js.map +1 -1
  54. package/dist/src/agent-session-tracer.d.ts +61 -0
  55. package/dist/src/agent-session-tracer.js +608 -0
  56. package/dist/src/agent-session-tracer.js.map +1 -0
  57. package/dist/src/agent-session-transitions.d.ts +200 -26
  58. package/dist/src/agent-session-transitions.js +732 -32
  59. package/dist/src/agent-session-transitions.js.map +1 -1
  60. package/dist/src/agent-session-values.d.ts +696 -30
  61. package/dist/src/agent-session-values.js +39 -4
  62. package/dist/src/agent-session-values.js.map +1 -1
  63. package/dist/src/agent-session-wait-steps.d.ts +53 -0
  64. package/dist/src/agent-session-wait-steps.js +389 -0
  65. package/dist/src/agent-session-wait-steps.js.map +1 -0
  66. package/dist/src/agent-tracing-options.d.ts +107 -0
  67. package/dist/src/agent-tracing-options.js +20 -0
  68. package/dist/src/agent-tracing-options.js.map +1 -0
  69. package/dist/src/ai-sdk/ai-sdk-model-client.d.ts +40 -0
  70. package/dist/src/ai-sdk/ai-sdk-model-client.js +235 -0
  71. package/dist/src/ai-sdk/ai-sdk-model-client.js.map +1 -0
  72. package/dist/src/ai-sdk/index.d.ts +1 -0
  73. package/dist/src/ai-sdk/index.js +9 -0
  74. package/dist/src/ai-sdk/index.js.map +1 -0
  75. package/dist/src/index.d.ts +14 -3
  76. package/dist/src/index.js +12 -2
  77. package/dist/src/index.js.map +1 -1
  78. package/dist/src/mcp/index.d.ts +3 -0
  79. package/dist/src/mcp/index.js +10 -0
  80. package/dist/src/mcp/index.js.map +1 -0
  81. package/dist/src/mcp/mcp-resource-and-prompt-tools.d.ts +29 -0
  82. package/dist/src/mcp/mcp-resource-and-prompt-tools.js +185 -0
  83. package/dist/src/mcp/mcp-resource-and-prompt-tools.js.map +1 -0
  84. package/dist/src/mcp/mcp-server-config.d.ts +86 -0
  85. package/dist/src/mcp/mcp-server-config.js +38 -0
  86. package/dist/src/mcp/mcp-server-config.js.map +1 -0
  87. package/dist/src/mcp/mcp-tool-source.d.ts +470 -0
  88. package/dist/src/mcp/mcp-tool-source.js +1204 -0
  89. package/dist/src/mcp/mcp-tool-source.js.map +1 -0
  90. package/dist/src/stepwise/agent-definition.d.ts +166 -0
  91. package/dist/src/stepwise/agent-definition.js +9 -0
  92. package/dist/src/stepwise/agent-definition.js.map +1 -0
  93. package/dist/src/stepwise/function-tool.d.ts +130 -0
  94. package/dist/src/stepwise/function-tool.js +75 -0
  95. package/dist/src/stepwise/function-tool.js.map +1 -0
  96. package/dist/src/stepwise/index.d.ts +8 -0
  97. package/dist/src/stepwise/index.js +13 -0
  98. package/dist/src/stepwise/index.js.map +1 -0
  99. package/dist/src/stepwise/json-schema-validation.d.ts +9 -0
  100. package/dist/src/stepwise/json-schema-validation.js +141 -0
  101. package/dist/src/stepwise/json-schema-validation.js.map +1 -0
  102. package/dist/src/stepwise/model-client.d.ts +194 -0
  103. package/dist/src/stepwise/model-client.js +9 -0
  104. package/dist/src/stepwise/model-client.js.map +1 -0
  105. package/dist/src/stepwise/scripted-model-client.d.ts +99 -0
  106. package/dist/src/stepwise/scripted-model-client.js +156 -0
  107. package/dist/src/stepwise/scripted-model-client.js.map +1 -0
  108. package/dist/src/stepwise/stepwise-agent-runner.d.ts +171 -0
  109. package/dist/src/stepwise/stepwise-agent-runner.js +777 -0
  110. package/dist/src/stepwise/stepwise-agent-runner.js.map +1 -0
  111. package/dist/src/stepwise/stepwise-agent-session-flow.d.ts +35 -0
  112. package/dist/src/stepwise/stepwise-agent-session-flow.js +57 -0
  113. package/dist/src/stepwise/stepwise-agent-session-flow.js.map +1 -0
  114. package/dist/src/stepwise/stepwise-input-items.d.ts +12 -0
  115. package/dist/src/stepwise/stepwise-input-items.js +172 -0
  116. package/dist/src/stepwise/stepwise-input-items.js.map +1 -0
  117. package/dist/src/stepwise/tool-source.d.ts +103 -0
  118. package/dist/src/stepwise/tool-source.js +9 -0
  119. package/dist/src/stepwise/tool-source.js.map +1 -0
  120. package/dist/src/testing/agent-session-test-client.d.ts +65 -8
  121. package/dist/src/testing/agent-session-test-client.js +92 -22
  122. package/dist/src/testing/agent-session-test-client.js.map +1 -1
  123. package/dist/src/testing/context-window.d.ts +194 -0
  124. package/dist/src/testing/context-window.js +360 -0
  125. package/dist/src/testing/context-window.js.map +1 -0
  126. package/dist/src/testing/index.d.ts +2 -0
  127. package/dist/src/testing/index.js +2 -0
  128. package/dist/src/testing/index.js.map +1 -1
  129. package/dist/src/testing/private-dex-engine.d.ts +9 -0
  130. package/dist/src/testing/private-dex-engine.js +9 -1
  131. package/dist/src/testing/private-dex-engine.js.map +1 -1
  132. package/dist/src/testing/scripted-model-client.d.ts +1 -0
  133. package/dist/src/testing/scripted-model-client.js +10 -0
  134. package/dist/src/testing/scripted-model-client.js.map +1 -0
  135. package/dist/src/ui-stream/agent-event-json.d.ts +30 -0
  136. package/dist/src/ui-stream/agent-event-json.js +64 -0
  137. package/dist/src/ui-stream/agent-event-json.js.map +1 -0
  138. package/dist/src/ui-stream/agent-event-sse.d.ts +155 -0
  139. package/dist/src/ui-stream/agent-event-sse.js +167 -0
  140. package/dist/src/ui-stream/agent-event-sse.js.map +1 -0
  141. package/dist/src/ui-stream/agent-event-stream-positions.d.ts +42 -0
  142. package/dist/src/ui-stream/agent-event-stream-positions.js +153 -0
  143. package/dist/src/ui-stream/agent-event-stream-positions.js.map +1 -0
  144. package/dist/src/ui-stream/agent-session-record-reader.d.ts +74 -0
  145. package/dist/src/ui-stream/agent-session-record-reader.js +246 -0
  146. package/dist/src/ui-stream/agent-session-record-reader.js.map +1 -0
  147. package/dist/src/ui-stream/agent-ui-message-stream-responses.d.ts +219 -0
  148. package/dist/src/ui-stream/agent-ui-message-stream-responses.js +441 -0
  149. package/dist/src/ui-stream/agent-ui-message-stream-responses.js.map +1 -0
  150. package/dist/src/ui-stream/agent-ui-message-stream.d.ts +138 -0
  151. package/dist/src/ui-stream/agent-ui-message-stream.js +695 -0
  152. package/dist/src/ui-stream/agent-ui-message-stream.js.map +1 -0
  153. package/dist/src/ui-stream/agent-ui-message-types.d.ts +238 -0
  154. package/dist/src/ui-stream/agent-ui-message-types.js +57 -0
  155. package/dist/src/ui-stream/agent-ui-message-types.js.map +1 -0
  156. package/dist/src/ui-stream/agent-ui-messages.d.ts +68 -0
  157. package/dist/src/ui-stream/agent-ui-messages.js +222 -0
  158. package/dist/src/ui-stream/agent-ui-messages.js.map +1 -0
  159. package/dist/src/ui-stream/agent-ui-stream-cursor.d.ts +64 -0
  160. package/dist/src/ui-stream/agent-ui-stream-cursor.js +186 -0
  161. package/dist/src/ui-stream/agent-ui-stream-cursor.js.map +1 -0
  162. package/dist/src/ui-stream/index.d.ts +14 -0
  163. package/dist/src/ui-stream/index.js +22 -0
  164. package/dist/src/ui-stream/index.js.map +1 -0
  165. package/dist/src/ui-stream/server-sent-event-responses.d.ts +6 -0
  166. package/dist/src/ui-stream/server-sent-event-responses.js +34 -0
  167. package/dist/src/ui-stream/server-sent-event-responses.js.map +1 -0
  168. package/package.json +44 -5
@@ -0,0 +1,58 @@
1
+ import { FlowNotActiveOrNotFoundError, type Client } from "@superdurable/dex";
2
+ import type { AgentFrameworkRunner, DeferredToolOutcome } from "./agent-framework-runner.js";
3
+ import type { AgentSessionFlow } from "./agent-session-flow.js";
4
+ import type { AgentSnapshot, AgentUserMessage } from "./agent-session-values.js";
5
+ /**
6
+ * Reports a message sent to a session that failed. {@link sendAgentUserMessage} throws it in place of the Dex
7
+ * error for a closed Flow, and it stays a `FlowNotActiveOrNotFoundError`. The message did not reach the session.
8
+ * Messages queued earlier stay readable in {@link AgentSnapshot.queuedMessages} and never run.
9
+ */
10
+ export declare class AgentSessionFailedError extends FlowNotActiveOrNotFoundError {
11
+ readonly reason: string;
12
+ /**
13
+ * Creates the error from the Dex error it replaces.
14
+ * @param sessionId - The failed session.
15
+ * @param reason - Why the session failed, such as `run state of 67492 bytes exceeds the maximum of 65536 bytes`.
16
+ * @param cause - The Dex error for the closed Flow.
17
+ */
18
+ constructor(sessionId: string, reason: string, cause: FlowNotActiveOrNotFoundError);
19
+ }
20
+ /**
21
+ * Returns the snapshot of a session whose Flow failed, with what the session stores when it has room: status
22
+ * `failed`, the reason, no active turn, and no pending interrupts. `toolCalls` lists the active turn's calls, so it
23
+ * is empty too; a stale turn's calls will never finish. A snapshot with no state, or with status `failed`, is
24
+ * returned unchanged.
25
+ * @param snapshot - The stored snapshot.
26
+ * @param reason - The Flow's failure reason.
27
+ * @returns The snapshot to show.
28
+ */
29
+ export declare function withSessionFailure(snapshot: AgentSnapshot, reason: string): AgentSnapshot;
30
+ /**
31
+ * Returns why a session's Flow failed.
32
+ * @param client - An open Client.
33
+ * @param sessionId - Running or retained closed session.
34
+ * @returns The Flow's failure reason, or `undefined` when the Flow did not fail or does not exist.
35
+ */
36
+ export declare function readSessionFailure(client: Client, sessionId: string): Promise<string | undefined>;
37
+ /**
38
+ * Returns the session snapshot, with a failed Flow's status and reason. Prefer it to invoking `getAgentSnapshot`
39
+ * directly: that RPC reads only what the session stored. It costs one more call to Dex.
40
+ * @param client - An open Client whose Registry contains `flow`.
41
+ * @param flow - The registered agent session Flow.
42
+ * @param sessionId - Running or retained closed session.
43
+ * @returns The snapshot. See {@link withSessionFailure}.
44
+ */
45
+ export declare function readAgentSnapshot(client: Client, flow: AgentSessionFlow<AgentFrameworkRunner<DeferredToolOutcome>>, sessionId: string): Promise<AgentSnapshot>;
46
+ /**
47
+ * Queues one user message, and reports a failed session clearly.
48
+ * @param client - An open Client whose Registry contains `flow`.
49
+ * @param flow - The registered agent session Flow.
50
+ * @param sessionId - Running session.
51
+ * @param message - The user message.
52
+ * @returns `true` when queued; `false` for blank text, or for a `planMode` message when plan mode is off.
53
+ * @throws {@link AgentSessionFailedError} when the session failed. Its `reason` says why.
54
+ * @throws {FlowNotActiveOrNotFoundError} When the session is not running.
55
+ * @throws {DexServiceError} With `RESOURCE_EXHAUSTED` when the message does not fit under
56
+ * `limits.maxFlowStateBytes`. Nothing was queued, and the session stays as it was.
57
+ */
58
+ export declare function sendAgentUserMessage(client: Client, flow: AgentSessionFlow<AgentFrameworkRunner<DeferredToolOutcome>>, sessionId: string, message: AgentUserMessage): Promise<boolean>;
@@ -0,0 +1,126 @@
1
+ // Copyright (c) 2026 Super Durable, Inc.
2
+ //
3
+ // Licensed under the Sustainable Use License 1.0.
4
+ // You may not use this file except in compliance with the License.
5
+ // See the LICENSE file in the repository root.
6
+ //
7
+ // SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
+ // A session at the state limit may have no room left to store `AgentState`. The commit that would store it
9
+ // fails on the same limit, and the Flow closes without it. Dex always records that close, so a reader takes a
10
+ // failed Flow's status and reason from it.
11
+ import { FlowNotActiveOrNotFoundError, FlowNotFoundError } from "@superdurable/dex";
12
+ const unknownFailure = "the session's Flow failed";
13
+ /**
14
+ * Reports a message sent to a session that failed. {@link sendAgentUserMessage} throws it in place of the Dex
15
+ * error for a closed Flow, and it stays a `FlowNotActiveOrNotFoundError`. The message did not reach the session.
16
+ * Messages queued earlier stay readable in {@link AgentSnapshot.queuedMessages} and never run.
17
+ */
18
+ export class AgentSessionFailedError extends FlowNotActiveOrNotFoundError {
19
+ reason;
20
+ /**
21
+ * Creates the error from the Dex error it replaces.
22
+ * @param sessionId - The failed session.
23
+ * @param reason - Why the session failed, such as `run state of 67492 bytes exceeds the maximum of 65536 bytes`.
24
+ * @param cause - The Dex error for the closed Flow.
25
+ */
26
+ constructor(sessionId, reason, cause) {
27
+ super(cause.code, cause.subStatus, `session ${sessionId} failed: ${reason}`, cause.operation, sessionId, { cause });
28
+ this.reason = reason;
29
+ }
30
+ }
31
+ /**
32
+ * Returns the snapshot of a session whose Flow failed, with what the session stores when it has room: status
33
+ * `failed`, the reason, no active turn, and no pending interrupts. `toolCalls` lists the active turn's calls, so it
34
+ * is empty too; a stale turn's calls will never finish. A snapshot with no state, or with status `failed`, is
35
+ * returned unchanged.
36
+ * @param snapshot - The stored snapshot.
37
+ * @param reason - The Flow's failure reason.
38
+ * @returns The snapshot to show.
39
+ */
40
+ export function withSessionFailure(snapshot, reason) {
41
+ const state = snapshot.state;
42
+ if (state === null || !mayHideSessionFailure(snapshot)) {
43
+ return snapshot;
44
+ }
45
+ return {
46
+ ...snapshot,
47
+ state: {
48
+ ...state,
49
+ status: "failed",
50
+ turnCount: state.turnCount + (state.activeTurnId === null ? 0 : 1),
51
+ activeTurnId: null,
52
+ acceptsTurnControl: false,
53
+ lastTurnError: reason,
54
+ },
55
+ pendingInterrupts: [],
56
+ toolCalls: [],
57
+ };
58
+ }
59
+ /**
60
+ * Returns why a session's Flow failed.
61
+ * @param client - An open Client.
62
+ * @param sessionId - Running or retained closed session.
63
+ * @returns The Flow's failure reason, or `undefined` when the Flow did not fail or does not exist.
64
+ */
65
+ export async function readSessionFailure(client, sessionId) {
66
+ try {
67
+ if ((await client.describeFlow(sessionId)).status !== "failed") {
68
+ return undefined;
69
+ }
70
+ }
71
+ catch (error) {
72
+ if (error instanceof FlowNotFoundError) {
73
+ return undefined;
74
+ }
75
+ throw error;
76
+ }
77
+ return (await client.waitForFlow(sessionId)).errorMessage || unknownFailure;
78
+ }
79
+ /**
80
+ * Returns the session snapshot, with a failed Flow's status and reason. Prefer it to invoking `getAgentSnapshot`
81
+ * directly: that RPC reads only what the session stored. It costs one more call to Dex.
82
+ * @param client - An open Client whose Registry contains `flow`.
83
+ * @param flow - The registered agent session Flow.
84
+ * @param sessionId - Running or retained closed session.
85
+ * @returns The snapshot. See {@link withSessionFailure}.
86
+ */
87
+ export async function readAgentSnapshot(client, flow, sessionId) {
88
+ const snapshot = await client.invokeRPC(flow.getAgentSnapshot, sessionId);
89
+ if (!mayHideSessionFailure(snapshot)) {
90
+ return snapshot;
91
+ }
92
+ const reason = await readSessionFailure(client, sessionId);
93
+ return reason === undefined ? snapshot : withSessionFailure(snapshot, reason);
94
+ }
95
+ /** Reports whether the Flow's close could add to this snapshot. */
96
+ function mayHideSessionFailure(snapshot) {
97
+ return snapshot.state !== null && snapshot.state.status !== "failed";
98
+ }
99
+ /**
100
+ * Queues one user message, and reports a failed session clearly.
101
+ * @param client - An open Client whose Registry contains `flow`.
102
+ * @param flow - The registered agent session Flow.
103
+ * @param sessionId - Running session.
104
+ * @param message - The user message.
105
+ * @returns `true` when queued; `false` for blank text, or for a `planMode` message when plan mode is off.
106
+ * @throws {@link AgentSessionFailedError} when the session failed. Its `reason` says why.
107
+ * @throws {FlowNotActiveOrNotFoundError} When the session is not running.
108
+ * @throws {DexServiceError} With `RESOURCE_EXHAUSTED` when the message does not fit under
109
+ * `limits.maxFlowStateBytes`. Nothing was queued, and the session stays as it was.
110
+ */
111
+ export async function sendAgentUserMessage(client, flow, sessionId, message) {
112
+ try {
113
+ return await client.invokeRPC(flow.sendUserMessage, sessionId, message);
114
+ }
115
+ catch (error) {
116
+ if (!(error instanceof FlowNotActiveOrNotFoundError)) {
117
+ throw error;
118
+ }
119
+ const reason = await readSessionFailure(client, sessionId);
120
+ if (reason === undefined) {
121
+ throw error;
122
+ }
123
+ throw new AgentSessionFailedError(sessionId, reason, error);
124
+ }
125
+ }
126
+ //# sourceMappingURL=agent-session-failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-session-failure.js","sourceRoot":"","sources":["../../src/agent-session-failure.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ // Copyright (c) 2026 Super Durable, Inc.
3
+ //
4
+ // Licensed under the Sustainable Use License 1.0.
5
+ // You may not use this file except in compliance with the License.
6
+ // See the LICENSE file in the repository root.
7
+ //
8
+ // SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
9
+ import { writeFileSync } from "node:fs";
10
+ import { parseArgs } from "node:util";
11
+ import { renderSessionFlowGraph } from "./agent-session-flow-graph.js";
12
+ const usage = "usage: dex-agents-session-graph --flow-type TYPE --permission PERMISSION [--out FILE]\n";
13
+ function main() {
14
+ let values;
15
+ try {
16
+ ({ values } = parseArgs({
17
+ options: { "flow-type": { type: "string" }, permission: { type: "string" }, out: { type: "string" } },
18
+ }));
19
+ }
20
+ catch (error) {
21
+ process.stderr.write(`${error.message}\n${usage}`);
22
+ return 2;
23
+ }
24
+ const flowType = values["flow-type"];
25
+ const actionPermission = values.permission;
26
+ if (flowType === undefined || actionPermission === undefined) {
27
+ process.stderr.write(usage);
28
+ return 2;
29
+ }
30
+ let graph;
31
+ try {
32
+ graph = renderSessionFlowGraph({ flowType, actionPermission });
33
+ }
34
+ catch (error) {
35
+ process.stderr.write(`${error.message}\n`);
36
+ return 2;
37
+ }
38
+ if (values.out === undefined) {
39
+ process.stdout.write(graph);
40
+ }
41
+ else {
42
+ writeFileSync(values.out, graph);
43
+ }
44
+ return 0;
45
+ }
46
+ process.exitCode = main();
47
+ //# sourceMappingURL=agent-session-flow-graph-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-session-flow-graph-cli.js","sourceRoot":"","sources":["../../src/agent-session-flow-graph-cli.ts"],"names":[],"mappings":";AACA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,MAAM,KAAK,GAAG,yFAAyF,CAAC;AAExG,SAAS,IAAI;IACX,IAAI,MAAuG,CAAC;IAC5G,IAAI,CAAC;QACH,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;YACtB,OAAO,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;SACtG,CAAC,CAAC,CAAC;IACN,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAI,KAAe,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC;QAC9D,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IACrC,MAAM,gBAAgB,GAAG,MAAM,CAAC,UAAU,CAAC;IAC3C,IAAI,QAAQ,KAAK,SAAS,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QAC7D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,KAAa,CAAC;IAClB,IAAI,CAAC;QACH,KAAK,GAAG,sBAAsB,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAI,KAAe,CAAC,OAAO,IAAI,CAAC,CAAC;QACtD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,OAAO,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAC"}
@@ -0,0 +1,38 @@
1
+ /** What an application chooses for the session Flow Definition Graph of one agent. */
2
+ export interface SessionFlowGraphOptions {
3
+ /** The Flow type of the agent, as passed to `createAgentSessionFlow`. */
4
+ readonly flowType: string;
5
+ /** The permission every session Action requires, such as `support-agent.operate`. */
6
+ readonly actionPermission: string;
7
+ }
8
+ /**
9
+ * Renders the Flow Definition Graph 2.0 file of one agent's session Flow.
10
+ *
11
+ * `dexcli visualize` cannot read the session Flow: the Flow lives in this library, and the application chooses its
12
+ * Flow type. This function fills both choices into the graph that ships with the package. Write the text to a file in
13
+ * the directory that Dex Web reads with `--flow-rendering-dir`. Dex Web then draws the session Steps and offers the
14
+ * `resolve_interrupt`, `answer_question`, `steer_user_message`, and `cancel_turn` Actions. Those Actions have no
15
+ * condition, because each RPC checks current state itself.
16
+ *
17
+ * The Python core renders the same bytes, so a graph from either core serves a session on Workers of either language.
18
+ * Render the file again after you upgrade this package. The `dex-agents-session-graph` command does the same from a
19
+ * build or deployment script.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { writeFileSync } from "node:fs";
24
+ * import { renderSessionFlowGraph } from "@superdurable/dex-agents";
25
+ *
26
+ * writeFileSync(
27
+ * "definitions/support-agent.json",
28
+ * renderSessionFlowGraph({ flowType: "SupportAgent", actionPermission: "support-agent.operate" }),
29
+ * );
30
+ * ```
31
+ *
32
+ * @param options - The Flow type and the Action permission.
33
+ * @returns The graph as JSON text that ends with a newline.
34
+ * @throws {TypeError} When `flowType` is blank, or when `actionPermission` is not lowercase letters, digits, dots, and
35
+ * hyphens that start with a letter.
36
+ * @since 0.3.0
37
+ */
38
+ export declare function renderSessionFlowGraph(options: SessionFlowGraphOptions): string;
@@ -0,0 +1,54 @@
1
+ // Copyright (c) 2026 Super Durable, Inc.
2
+ //
3
+ // Licensed under the Sustainable Use License 1.0.
4
+ // You may not use this file except in compliance with the License.
5
+ // See the LICENSE file in the repository root.
6
+ //
7
+ // SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
+ import sessionFlowGraphTemplate from "./agent-session-flow-graph.json" with { type: "json" };
9
+ const actionPermissionPattern = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;
10
+ /**
11
+ * Renders the Flow Definition Graph 2.0 file of one agent's session Flow.
12
+ *
13
+ * `dexcli visualize` cannot read the session Flow: the Flow lives in this library, and the application chooses its
14
+ * Flow type. This function fills both choices into the graph that ships with the package. Write the text to a file in
15
+ * the directory that Dex Web reads with `--flow-rendering-dir`. Dex Web then draws the session Steps and offers the
16
+ * `resolve_interrupt`, `answer_question`, `steer_user_message`, and `cancel_turn` Actions. Those Actions have no
17
+ * condition, because each RPC checks current state itself.
18
+ *
19
+ * The Python core renders the same bytes, so a graph from either core serves a session on Workers of either language.
20
+ * Render the file again after you upgrade this package. The `dex-agents-session-graph` command does the same from a
21
+ * build or deployment script.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { writeFileSync } from "node:fs";
26
+ * import { renderSessionFlowGraph } from "@superdurable/dex-agents";
27
+ *
28
+ * writeFileSync(
29
+ * "definitions/support-agent.json",
30
+ * renderSessionFlowGraph({ flowType: "SupportAgent", actionPermission: "support-agent.operate" }),
31
+ * );
32
+ * ```
33
+ *
34
+ * @param options - The Flow type and the Action permission.
35
+ * @returns The graph as JSON text that ends with a newline.
36
+ * @throws {TypeError} When `flowType` is blank, or when `actionPermission` is not lowercase letters, digits, dots, and
37
+ * hyphens that start with a letter.
38
+ * @since 0.3.0
39
+ */
40
+ export function renderSessionFlowGraph(options) {
41
+ if (options.flowType.trim() === "") {
42
+ throw new TypeError("flowType must not be empty");
43
+ }
44
+ if (!actionPermissionPattern.test(options.actionPermission)) {
45
+ throw new TypeError(`actionPermission ${JSON.stringify(options.actionPermission)} is not a valid permission`);
46
+ }
47
+ const graph = structuredClone(sessionFlowGraphTemplate);
48
+ graph.flow.name = options.flowType;
49
+ for (const action of graph.v2.actions) {
50
+ action.requiredPermission = options.actionPermission;
51
+ }
52
+ return `${JSON.stringify(graph, null, 2)}\n`;
53
+ }
54
+ //# sourceMappingURL=agent-session-flow-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-session-flow-graph.js","sourceRoot":"","sources":["../../src/agent-session-flow-graph.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,wBAAwB,MAAM,iCAAiC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAE7F,MAAM,uBAAuB,GAAG,oCAAoC,CAAC;AAUrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgC;IACrE,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACnC,MAAM,IAAI,SAAS,CAAC,4BAA4B,CAAC,CAAC;IACpD,CAAC;IACD,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,SAAS,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,4BAA4B,CAAC,CAAC;IAChH,CAAC;IACD,MAAM,KAAK,GAAG,eAAe,CAAC,wBAAwB,CAAC,CAAC;IACxD,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;IACnC,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QACtC,MAAM,CAAC,kBAAkB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IACvD,CAAC;IACD,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC"}