tubeless 0.2.15 → 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 (183) hide show
  1. package/README.md +3 -3
  2. package/dist/agent/agent-state.d.ts +8 -0
  3. package/dist/agent/agent-state.js +78 -0
  4. package/dist/agent/agent-state.js.map +1 -0
  5. package/dist/agent/agent-types.d.ts +104 -0
  6. package/dist/agent/agent-types.js +2 -0
  7. package/dist/agent/agent-types.js.map +1 -0
  8. package/dist/agent/agent.d.ts +14 -0
  9. package/dist/agent/agent.js +17 -0
  10. package/dist/agent/agent.js.map +1 -0
  11. package/dist/agent/compile-agent.d.ts +17 -0
  12. package/dist/agent/compile-agent.js +76 -0
  13. package/dist/agent/compile-agent.js.map +1 -0
  14. package/dist/agent/decision.d.ts +32 -0
  15. package/dist/agent/decision.js +81 -0
  16. package/dist/agent/decision.js.map +1 -0
  17. package/dist/agent/default-tool-bash.d.ts +14 -0
  18. package/dist/agent/default-tool-bash.js +112 -0
  19. package/dist/agent/default-tool-bash.js.map +1 -0
  20. package/dist/agent/default-tool-files.d.ts +56 -0
  21. package/dist/agent/default-tool-files.js +271 -0
  22. package/dist/agent/default-tool-files.js.map +1 -0
  23. package/dist/agent/default-tool-limits.d.ts +4 -0
  24. package/dist/agent/default-tool-limits.js +5 -0
  25. package/dist/agent/default-tool-limits.js.map +1 -0
  26. package/dist/agent/default-tool-schema.d.ts +5 -0
  27. package/dist/agent/default-tool-schema.js +33 -0
  28. package/dist/agent/default-tool-schema.js.map +1 -0
  29. package/dist/agent/default-tools.d.ts +69 -0
  30. package/dist/agent/default-tools.js +123 -0
  31. package/dist/agent/default-tools.js.map +1 -0
  32. package/dist/agent/environment.d.ts +90 -0
  33. package/dist/agent/environment.js +35 -0
  34. package/dist/agent/environment.js.map +1 -0
  35. package/dist/agent/execution-scope.d.ts +19 -0
  36. package/dist/agent/execution-scope.js +147 -0
  37. package/dist/agent/execution-scope.js.map +1 -0
  38. package/dist/agent/invocation.d.ts +9 -0
  39. package/dist/agent/invocation.js +26 -0
  40. package/dist/agent/invocation.js.map +1 -0
  41. package/dist/agent/model-agent.d.ts +30 -0
  42. package/dist/agent/model-agent.js +42 -0
  43. package/dist/agent/model-agent.js.map +1 -0
  44. package/dist/agent/model-prompt.d.ts +2 -0
  45. package/dist/agent/model-prompt.js +64 -0
  46. package/dist/agent/model-prompt.js.map +1 -0
  47. package/dist/agent/model-types.d.ts +18 -0
  48. package/dist/agent/model-types.js +2 -0
  49. package/dist/agent/model-types.js.map +1 -0
  50. package/dist/agent/node-environment.d.ts +3 -0
  51. package/dist/agent/node-environment.js +66 -0
  52. package/dist/agent/node-environment.js.map +1 -0
  53. package/dist/agent/node.d.ts +1 -0
  54. package/dist/agent/node.js +2 -0
  55. package/dist/agent/node.js.map +1 -0
  56. package/dist/agent/openai-http.d.ts +2 -0
  57. package/dist/agent/openai-http.js +51 -0
  58. package/dist/agent/openai-http.js.map +1 -0
  59. package/dist/agent/openai-protocol.d.ts +23 -0
  60. package/dist/agent/openai-protocol.js +120 -0
  61. package/dist/agent/openai-protocol.js.map +1 -0
  62. package/dist/agent/openai-tool-outputs.d.ts +7 -0
  63. package/dist/agent/openai-tool-outputs.js +59 -0
  64. package/dist/agent/openai-tool-outputs.js.map +1 -0
  65. package/dist/agent/openai.d.ts +16 -0
  66. package/dist/agent/openai.js +92 -0
  67. package/dist/agent/openai.js.map +1 -0
  68. package/dist/agent/pipeline-tool.d.ts +29 -0
  69. package/dist/agent/pipeline-tool.js +29 -0
  70. package/dist/agent/pipeline-tool.js.map +1 -0
  71. package/dist/agent/tool-failure.d.ts +6 -0
  72. package/dist/agent/tool-failure.js +19 -0
  73. package/dist/agent/tool-failure.js.map +1 -0
  74. package/dist/agent/tools.d.ts +44 -0
  75. package/dist/agent/tools.js +65 -0
  76. package/dist/agent/tools.js.map +1 -0
  77. package/dist/agent/turn.d.ts +26 -0
  78. package/dist/agent/turn.js +169 -0
  79. package/dist/agent/turn.js.map +1 -0
  80. package/dist/cli/cli-pipeline-command.js +5 -11
  81. package/dist/cli/cli-pipeline-command.js.map +1 -1
  82. package/dist/core/child-execution.d.ts +9 -1
  83. package/dist/core/child-execution.js +23 -6
  84. package/dist/core/child-execution.js.map +1 -1
  85. package/dist/core/execution-scope.d.ts +7 -0
  86. package/dist/core/execution-scope.js +14 -0
  87. package/dist/core/execution-scope.js.map +1 -0
  88. package/dist/core/pipeline-definition-identity.js +60 -2
  89. package/dist/core/pipeline-definition-identity.js.map +1 -1
  90. package/dist/core/pipeline-execute.d.ts +2 -0
  91. package/dist/core/pipeline-execute.js +7 -9
  92. package/dist/core/pipeline-execute.js.map +1 -1
  93. package/dist/core/pipeline-execution-error.d.ts +13 -14
  94. package/dist/core/pipeline-execution-error.js +66 -22
  95. package/dist/core/pipeline-execution-error.js.map +1 -1
  96. package/dist/core/pipeline-graph.js +6 -1
  97. package/dist/core/pipeline-graph.js.map +1 -1
  98. package/dist/core/pipeline-plan.d.ts +5 -0
  99. package/dist/core/pipeline-plan.js +8 -2
  100. package/dist/core/pipeline-plan.js.map +1 -1
  101. package/dist/core/pipeline-step-executor.js +11 -2
  102. package/dist/core/pipeline-step-executor.js.map +1 -1
  103. package/dist/core/pipeline-step-metadata.d.ts +3 -0
  104. package/dist/core/pipeline-step-metadata.js +3 -0
  105. package/dist/core/pipeline-step-metadata.js.map +1 -1
  106. package/dist/core/pipeline-steps.d.ts +3 -1
  107. package/dist/core/pipeline-steps.js +1 -1
  108. package/dist/core/pipeline-steps.js.map +1 -1
  109. package/dist/core/pipeline-types.d.ts +2 -0
  110. package/dist/core/pipeline-types.js.map +1 -1
  111. package/dist/core/pipeline.js +2 -1
  112. package/dist/core/pipeline.js.map +1 -1
  113. package/dist/core/prepared-options.d.ts +11 -0
  114. package/dist/core/prepared-options.js +29 -0
  115. package/dist/core/prepared-options.js.map +1 -0
  116. package/dist/node/atomic-text.js +1 -1
  117. package/dist/node/atomic-text.js.map +1 -1
  118. package/dist/reporter/live-ticker.js +4 -1
  119. package/dist/reporter/live-ticker.js.map +1 -1
  120. package/dist/run-store/agent-history.d.ts +48 -0
  121. package/dist/run-store/agent-history.js +138 -0
  122. package/dist/run-store/agent-history.js.map +1 -0
  123. package/dist/run-store/agent-projection.d.ts +33 -0
  124. package/dist/run-store/agent-projection.js +88 -0
  125. package/dist/run-store/agent-projection.js.map +1 -0
  126. package/dist/run-store/definition-diff.js +1 -0
  127. package/dist/run-store/definition-diff.js.map +1 -1
  128. package/dist/run-store/run-projection.js +13 -1
  129. package/dist/run-store/run-projection.js.map +1 -1
  130. package/dist/run-store/run-store-ndjson.js +50 -6
  131. package/dist/run-store/run-store-ndjson.js.map +1 -1
  132. package/dist/run-store/run-store-reader.d.ts +3 -1
  133. package/dist/run-store/run-store-reader.js +8 -0
  134. package/dist/run-store/run-store-reader.js.map +1 -1
  135. package/dist/run-store/run-store-sqlite.js +16 -1
  136. package/dist/run-store/run-store-sqlite.js.map +1 -1
  137. package/dist/run-store/run-store.d.ts +9 -1
  138. package/dist/run-store/run-store.js.map +1 -1
  139. package/dist/studio/run-store-ui-client-browser.js +2 -2
  140. package/dist/studio/run-store-ui-client.js +11 -7
  141. package/dist/studio/run-store-ui-client.js.map +1 -1
  142. package/dist/tracing/tracing-schema.d.ts +69 -0
  143. package/dist/tracing/tracing-schema.js +23 -0
  144. package/dist/tracing/tracing-schema.js.map +1 -1
  145. package/dist/utilities/batch.d.ts +11 -0
  146. package/dist/utilities/batch.js +10 -0
  147. package/dist/utilities/batch.js.map +1 -1
  148. package/dist/utilities/cache-key.js +19 -3
  149. package/dist/utilities/cache-key.js.map +1 -1
  150. package/dist/utilities/retry.d.ts +9 -3
  151. package/dist/utilities/retry.js +17 -11
  152. package/dist/utilities/retry.js.map +1 -1
  153. package/dist/workbench/workbench-agent-history.d.ts +3 -0
  154. package/dist/workbench/workbench-agent-history.js +53 -0
  155. package/dist/workbench/workbench-agent-history.js.map +1 -0
  156. package/dist/workbench/workbench-history.js +51 -5
  157. package/dist/workbench/workbench-history.js.map +1 -1
  158. package/dist/workbench/workbench-run.js +11 -4
  159. package/dist/workbench/workbench-run.js.map +1 -1
  160. package/docs/README.md +1 -0
  161. package/docs/agent-guide.md +72 -1
  162. package/docs/agents.md +606 -0
  163. package/docs/api-reference.md +88 -43
  164. package/docs/api-report.json +57 -9
  165. package/docs/child-pipeline-composition.md +12 -0
  166. package/docs/cli.md +11 -2
  167. package/docs/llms.txt +7 -0
  168. package/docs/recipes.md +65 -46
  169. package/examples/agent-delegation.ts +77 -0
  170. package/examples/agent-environment.ts +35 -0
  171. package/examples/agent-model.ts +11 -0
  172. package/examples/agent-openai-decision.ts +116 -0
  173. package/examples/agent-openai.ts +37 -0
  174. package/examples/agent-pipeline.ts +25 -0
  175. package/examples/agent-workspace.ts +97 -0
  176. package/examples/agent.ts +116 -0
  177. package/examples/inngest/functions.ts +6 -18
  178. package/examples/project/tubeless.project.ts +17 -0
  179. package/examples/shared/tubeless-job.ts +22 -0
  180. package/examples/step-functions/handler.ts +7 -13
  181. package/examples/temporal/activities.ts +6 -18
  182. package/package.json +29 -11
  183. package/skills/tubeless/SKILL.md +54 -0
package/README.md CHANGED
@@ -93,8 +93,8 @@ flags after `--`. Record runs with `--store` or `--trace`, then inspect them wit
93
93
 
94
94
  - Start with a [typed import](./examples/typed-import.ts) or add
95
95
  [dry runs and write gates](./examples/publish-with-gates.ts) to a publishing job.
96
- - Build a larger workflow with [child pipelines](./examples/child-pipeline.ts)
97
- and [fan-out](./examples/fan-out-progress.ts).
96
+ - Build workflows with [child pipelines](./examples/child-pipeline.ts) and [fan-out](./examples/fan-out-progress.ts).
97
+ - Run bounded model decisions, default filesystem/shell tools, custom tools, and subagents with [in-process agents](./docs/agents.md).
98
98
  - Optional: the [peloton example](./examples/peloton.ts) is a cycling-themed kitchen sink for the live TUI.
99
99
 
100
100
  The [recipe index](./docs/recipes.md) covers validation, retries, tracing, testing,
@@ -106,7 +106,7 @@ and more. For help authoring pipelines with a coding agent, install the
106
106
  [Website](https://tubeless.io/) · [Getting started](./docs/getting-started.md) · [CLI](./docs/cli.md) ·
107
107
  [Studio](./docs/studio.md) · [Concepts](./docs/concepts.md) ·
108
108
  [Comparison](./docs/comparison.md) · [API](./docs/api-reference.md) ·
109
- [Agents](./docs/agent-guide.md)
109
+ [Agent authoring guide](./docs/agent-guide.md)
110
110
 
111
111
  ## Contributing
112
112
 
@@ -0,0 +1,8 @@
1
+ import type { StandardSchemaV1 } from "../core/pipeline-types.js";
2
+ import type { AgentState } from "./agent-types.js";
3
+ export declare function agentError(code: string, message: string, cause?: unknown): Error;
4
+ export declare function ownState<T>(state: T): AgentState<T>;
5
+ export declare function checkSchema(schema: StandardSchemaV1, label: string): void;
6
+ export declare function jsonDescriptor(schema: StandardSchemaV1, explicit: Readonly<Record<string, unknown>> | undefined, label: string): Readonly<Record<string, unknown>>;
7
+ export declare function descriptorFingerprint(descriptor: Readonly<Record<string, unknown>>): string;
8
+ export declare function checkDescription(description: string): void;
@@ -0,0 +1,78 @@
1
+ import { createHash } from "node:crypto";
2
+ export function agentError(code, message, cause) {
3
+ return Object.assign(new Error(message, cause === undefined ? undefined : { cause }), { code });
4
+ }
5
+ /** Copy plain data into owned, frozen snapshots; repeated references are copied, cycles fail. */
6
+ function copy(value, ancestors, json) {
7
+ if (value === null || typeof value === "string" || typeof value === "boolean")
8
+ return value;
9
+ if (value === undefined && !json)
10
+ return value;
11
+ if (typeof value === "number" && Number.isFinite(value))
12
+ return value;
13
+ if (typeof value !== "object" || value === null)
14
+ throw new Error("Expected finite plain data");
15
+ if (ancestors.has(value))
16
+ throw new Error("Cyclic data is not supported");
17
+ if (!Array.isArray(value) &&
18
+ Object.getPrototypeOf(value) !== Object.prototype &&
19
+ Object.getPrototypeOf(value) !== null) {
20
+ throw new Error("Expected an array or plain record");
21
+ }
22
+ ancestors.add(value);
23
+ const result = Array.isArray(value)
24
+ ? new Array(value.length)
25
+ : {};
26
+ const keys = Reflect.ownKeys(value);
27
+ if (json)
28
+ keys.sort((a, b) => (String(a) < String(b) ? -1 : String(a) > String(b) ? 1 : 0));
29
+ for (const key of keys) {
30
+ if (Array.isArray(value) && key === "length")
31
+ continue;
32
+ const property = Object.getOwnPropertyDescriptor(value, key);
33
+ if (typeof key !== "string" || !("value" in property) || !property.enumerable) {
34
+ throw new Error("State and descriptors require enumerable data properties");
35
+ }
36
+ Object.defineProperty(result, key, {
37
+ value: copy(property.value, ancestors, json),
38
+ enumerable: true,
39
+ });
40
+ }
41
+ ancestors.delete(value);
42
+ return Object.freeze(result);
43
+ }
44
+ export function ownState(state) {
45
+ try {
46
+ // SAFETY: copying retains every plain-data value and only adds deep readonly ownership.
47
+ return copy(state, new Set(), false);
48
+ }
49
+ catch (cause) {
50
+ throw agentError("TUBELESS_AGENT_INVALID_STATE", "Agent state must contain finite primitives, arrays, and plain records", cause);
51
+ }
52
+ }
53
+ export function checkSchema(schema, label) {
54
+ if (schema?.["~standard"]?.version !== 1 || typeof schema["~standard"].validate !== "function") {
55
+ throw agentError("TUBELESS_AGENT_INVALID_DEFINITION", `${label} requires a Standard Schema validator`);
56
+ }
57
+ }
58
+ export function jsonDescriptor(schema, explicit, label) {
59
+ checkSchema(schema, label);
60
+ try {
61
+ const descriptor = explicit ?? schema["~standard"].jsonSchema?.input({ target: "draft-2020-12" });
62
+ if (descriptor === null || typeof descriptor !== "object" || Array.isArray(descriptor))
63
+ throw new Error("Missing JSON Schema object");
64
+ // SAFETY: the object guard and plain JSON copy validate the descriptor's representation.
65
+ return copy(descriptor, new Set(), true);
66
+ }
67
+ catch (cause) {
68
+ throw agentError("TUBELESS_AGENT_INVALID_DEFINITION", `${label} requires a JSON Schema input descriptor or explicit fallback`, cause);
69
+ }
70
+ }
71
+ export function descriptorFingerprint(descriptor) {
72
+ return `sha256:${createHash("sha256").update(JSON.stringify(descriptor)).digest("hex")}`;
73
+ }
74
+ export function checkDescription(description) {
75
+ if (typeof description !== "string" || !description.trim() || description.length > 4096)
76
+ throw agentError("TUBELESS_AGENT_INVALID_DEFINITION", "Tool description must be nonblank and at most 4096 characters");
77
+ }
78
+ //# sourceMappingURL=agent-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-state.js","sourceRoot":"","sources":["../../src/agent/agent-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,OAAe,EAAE,KAAe;IACvE,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAClG,CAAC;AAED,iGAAiG;AACjG,SAAS,IAAI,CAAC,KAAc,EAAE,SAAsB,EAAE,IAAa;IACjE,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5F,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC/F,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC1E,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS;QACjD,MAAM,CAAC,cAAc,CAAC,KAAK,CAA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AC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,UAAU,CACd,mCAAmC,EACnC,GAAG,KAAK,+DAA+D,EACvE,KAAK,CACN,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,UAA6C;IACjF,OAAO,UAAU,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAClD,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,WAAW,CAAC,MAAM,GAAG,IAAI;QACrF,MAAM,UAAU,CACd,mCAAmC,EACnC,+DAA+D,CAChE,CAAC;AACN,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { StandardSchemaV1 } from \"../core/pipeline-types.js\";\nimport type { AgentState } from \"./agent-types.js\";\n\nexport function agentError(code: string, message: string, cause?: unknown): Error {\n return Object.assign(new Error(message, cause === undefined ? undefined : { cause }), { code });\n}\n\n/** Copy plain data into owned, frozen snapshots; repeated references are copied, cycles fail. */\nfunction copy(value: unknown, ancestors: Set<object>, json: boolean): unknown {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (value === undefined && !json) return value;\n if (typeof value === \"number\" && Number.isFinite(value)) return value;\n if (typeof value !== \"object\" || value === null) throw new Error(\"Expected finite plain data\");\n if (ancestors.has(value)) throw new Error(\"Cyclic data is not supported\");\n if (\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n ) {\n throw new Error(\"Expected an array or plain record\");\n }\n ancestors.add(value);\n const result: Record<string, unknown> | unknown[] = Array.isArray(value)\n ? new Array(value.length)\n : {};\n const keys = Reflect.ownKeys(value);\n if (json) keys.sort((a, b) => (String(a) < String(b) ? -1 : String(a) > String(b) ? 1 : 0));\n for (const key of keys) {\n if (Array.isArray(value) && key === \"length\") continue;\n const property = Object.getOwnPropertyDescriptor(value, key)!;\n if (typeof key !== \"string\" || !(\"value\" in property) || !property.enumerable) {\n throw new Error(\"State and descriptors require enumerable data properties\");\n }\n Object.defineProperty(result, key, {\n value: copy(property.value, ancestors, json),\n enumerable: true,\n });\n }\n ancestors.delete(value);\n return Object.freeze(result);\n}\n\nexport function ownState<T>(state: T): AgentState<T> {\n try {\n // SAFETY: copying retains every plain-data value and only adds deep readonly ownership.\n return copy(state, new Set(), false) as AgentState<T>;\n } catch (cause) {\n throw agentError(\n \"TUBELESS_AGENT_INVALID_STATE\",\n \"Agent state must contain finite primitives, arrays, and plain records\",\n cause\n );\n }\n}\n\nexport function checkSchema(schema: StandardSchemaV1, label: string): void {\n if (schema?.[\"~standard\"]?.version !== 1 || typeof schema[\"~standard\"].validate !== \"function\") {\n throw agentError(\n \"TUBELESS_AGENT_INVALID_DEFINITION\",\n `${label} requires a Standard Schema validator`\n );\n }\n}\n\nexport function jsonDescriptor(\n schema: StandardSchemaV1,\n explicit: Readonly<Record<string, unknown>> | undefined,\n label: string\n): Readonly<Record<string, unknown>> {\n checkSchema(schema, label);\n try {\n const descriptor =\n explicit ?? schema[\"~standard\"].jsonSchema?.input({ target: \"draft-2020-12\" });\n if (descriptor === null || typeof descriptor !== \"object\" || Array.isArray(descriptor))\n throw new Error(\"Missing JSON Schema object\");\n // SAFETY: the object guard and plain JSON copy validate the descriptor's representation.\n return copy(descriptor, new Set(), true) as Readonly<Record<string, unknown>>;\n } catch (cause) {\n throw agentError(\n \"TUBELESS_AGENT_INVALID_DEFINITION\",\n `${label} requires a JSON Schema input descriptor or explicit fallback`,\n cause\n );\n }\n}\n\nexport function descriptorFingerprint(descriptor: Readonly<Record<string, unknown>>): string {\n return `sha256:${createHash(\"sha256\").update(JSON.stringify(descriptor)).digest(\"hex\")}`;\n}\n\nexport function checkDescription(description: string): void {\n if (typeof description !== \"string\" || !description.trim() || description.length > 4096)\n throw agentError(\n \"TUBELESS_AGENT_INVALID_DEFINITION\",\n \"Tool description must be nonblank and at most 4096 characters\"\n );\n}\n"]}
@@ -0,0 +1,104 @@
1
+ import type { PipelineStepContext, StandardSchemaV1 } from "../core/pipeline-types.js";
2
+ import type { AgentEnvironment, AgentEnvironmentProvider } from "./environment.js";
3
+ import type { DefaultAgentTools } from "./default-tools.js";
4
+ export type Awaitable<T> = T | Promise<T>;
5
+ export type Input<S extends StandardSchemaV1> = NonNullable<S["~standard"]["types"]>["input"];
6
+ export type Output<S extends StandardSchemaV1> = NonNullable<S["~standard"]["types"]>["output"];
7
+ /** Deeply read-only view of the owned plain-data state supplied to agent callbacks. */
8
+ export type AgentState<T> = {
9
+ readonly [K in keyof T]: AgentState<T[K]>;
10
+ };
11
+ declare const capabilityTypes: unique symbol;
12
+ /** Opaque capability created by defineTool or pipelineTool; model decisions contain data only. */
13
+ export interface AgentTool<Arguments, Result> {
14
+ readonly [capabilityTypes]: {
15
+ readonly input: Arguments;
16
+ readonly output: Result;
17
+ };
18
+ }
19
+ export type Tools = Readonly<Record<string, AgentTool<unknown, unknown>>>;
20
+ type RegisteredTools<Custom extends Tools> = Omit<DefaultAgentTools, keyof Custom> & Custom;
21
+ type ToolCall<Registry extends Tools> = {
22
+ [Name in keyof Registry & string]: {
23
+ readonly id: string;
24
+ readonly tool: Name;
25
+ readonly input: Registry[Name][typeof capabilityTypes]["input"];
26
+ };
27
+ }[keyof Registry & string];
28
+ /** One built-in or custom call with raw model arguments; custom names replace defaults. */
29
+ export type AgentCall<Registry extends Tools = {}> = ToolCall<RegisteredTools<Registry>>;
30
+ type ToolOutcome<Registry extends Tools> = {
31
+ [Name in keyof Registry & string]: {
32
+ readonly id: string;
33
+ readonly tool: Name;
34
+ } & ({
35
+ readonly ok: true;
36
+ readonly value: Registry[Name][typeof capabilityTypes]["output"];
37
+ } | {
38
+ readonly ok: false;
39
+ readonly error: {
40
+ readonly code: string;
41
+ readonly message: string;
42
+ };
43
+ });
44
+ }[keyof Registry & string];
45
+ /** Input-order result or deliberately recoverable handler failure, including default tools. */
46
+ export type AgentOutcome<Registry extends Tools = {}> = ToolOutcome<RegisteredTools<Registry>>;
47
+ /** A nonempty batch of independent calls, or the raw input to the final-result schema. */
48
+ export type AgentDecision<Registry extends Tools, Result> = {
49
+ readonly kind: "continue";
50
+ readonly calls: readonly [AgentCall<Registry>, ...AgentCall<Registry>[]];
51
+ readonly result?: never;
52
+ } | {
53
+ readonly kind: "finish";
54
+ readonly result: Result;
55
+ readonly calls?: never;
56
+ };
57
+ /** Finite limits for this agent and its descendants; child limits may only tighten them. */
58
+ export interface AgentLimits {
59
+ /** Decision callbacks, including finish. Defaults to 20. */
60
+ readonly maxTurns?: number;
61
+ /** Admitted subtree calls, including calls stopped before dispatch. Defaults to 100. */
62
+ readonly maxCalls?: number;
63
+ /** Subtree decision callback admissions. Defaults to 100; provider retries are application-owned. */
64
+ readonly maxDecisions?: number;
65
+ /** Pipeline-tool delegation edges below this agent. Defaults to 4; zero allows leaf tools only. */
66
+ readonly maxDepth?: number;
67
+ /** Active decision callbacks and leaf handlers across the subtree. Defaults to 1. */
68
+ readonly maxConcurrency?: number;
69
+ }
70
+ /** Step services and the workspace capability available to a registered tool. */
71
+ export interface AgentToolContext extends PipelineStepContext<{}> {
72
+ readonly environment: AgentEnvironment;
73
+ }
74
+ /** Model-facing descriptors and ordinary step services, without executable tools. */
75
+ export interface AgentDecisionContext<Options extends object> extends PipelineStepContext<Options> {
76
+ readonly environment: AgentEnvironment;
77
+ readonly turn: number;
78
+ readonly stateVersion: number;
79
+ readonly capabilities: readonly {
80
+ readonly name: string;
81
+ readonly description: string;
82
+ readonly inputJsonSchema: Readonly<Record<string, unknown>>;
83
+ }[];
84
+ readonly resultJsonSchema: Readonly<Record<string, unknown>>;
85
+ }
86
+ export interface AgentDefinition<Id extends string, Options extends StandardSchemaV1<object, object>, Result extends StandardSchemaV1, State, Registry extends Tools> {
87
+ readonly id: Id;
88
+ readonly name?: string;
89
+ readonly description?: string;
90
+ readonly implementationVersion?: string;
91
+ readonly inputSchema: Options;
92
+ readonly resultSchema: Result;
93
+ readonly resultJsonSchema?: Readonly<Record<string, unknown>>;
94
+ /** Extend the standard tools; a custom tool with the same name replaces that default. */
95
+ readonly tools?: Registry;
96
+ readonly limits?: AgentLimits;
97
+ /** Workspace capabilities; descendants inherit them unless explicitly replaced. */
98
+ readonly environment?: AgentEnvironmentProvider;
99
+ initialState(options: Output<Options>): State;
100
+ decide(state: AgentState<NoInfer<State>>, context: AgentDecisionContext<Output<Options>>): Awaitable<unknown>;
101
+ reduce?(state: AgentState<NoInfer<State>>, outcomes: readonly AgentOutcome<Registry>[]): NoInfer<State>;
102
+ dryRun?(state: AgentState<NoInfer<State>>, context: AgentDecisionContext<Output<Options>>): Awaitable<unknown>;
103
+ }
104
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=agent-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-types.js","sourceRoot":"","sources":["../../src/agent/agent-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PipelineStepContext, StandardSchemaV1 } from \"../core/pipeline-types.js\";\nimport type { AgentEnvironment, AgentEnvironmentProvider } from \"./environment.js\";\nimport type { DefaultAgentTools } from \"./default-tools.js\";\n\nexport type Awaitable<T> = T | Promise<T>;\nexport type Input<S extends StandardSchemaV1> = NonNullable<S[\"~standard\"][\"types\"]>[\"input\"];\nexport type Output<S extends StandardSchemaV1> = NonNullable<S[\"~standard\"][\"types\"]>[\"output\"];\n/** Deeply read-only view of the owned plain-data state supplied to agent callbacks. */\nexport type AgentState<T> = { readonly [K in keyof T]: AgentState<T[K]> };\ndeclare const capabilityTypes: unique symbol;\n\n/** Opaque capability created by defineTool or pipelineTool; model decisions contain data only. */\nexport interface AgentTool<Arguments, Result> {\n readonly [capabilityTypes]: { readonly input: Arguments; readonly output: Result };\n}\n\nexport type Tools = Readonly<Record<string, AgentTool<unknown, unknown>>>;\ntype RegisteredTools<Custom extends Tools> = Omit<DefaultAgentTools, keyof Custom> & Custom;\n\ntype ToolCall<Registry extends Tools> = {\n [Name in keyof Registry & string]: {\n readonly id: string;\n readonly tool: Name;\n readonly input: Registry[Name][typeof capabilityTypes][\"input\"];\n };\n}[keyof Registry & string];\n\n/** One built-in or custom call with raw model arguments; custom names replace defaults. */\nexport type AgentCall<Registry extends Tools = {}> = ToolCall<RegisteredTools<Registry>>;\n\ntype ToolOutcome<Registry extends Tools> = {\n [Name in keyof Registry & string]: {\n readonly id: string;\n readonly tool: Name;\n } & (\n | {\n readonly ok: true;\n readonly value: Registry[Name][typeof capabilityTypes][\"output\"];\n }\n | { readonly ok: false; readonly error: { readonly code: string; readonly message: string } }\n );\n}[keyof Registry & string];\n\n/** Input-order result or deliberately recoverable handler failure, including default tools. */\nexport type AgentOutcome<Registry extends Tools = {}> = ToolOutcome<RegisteredTools<Registry>>;\n\n/** A nonempty batch of independent calls, or the raw input to the final-result schema. */\nexport type AgentDecision<Registry extends Tools, Result> =\n | {\n readonly kind: \"continue\";\n readonly calls: readonly [AgentCall<Registry>, ...AgentCall<Registry>[]];\n readonly result?: never;\n }\n | { readonly kind: \"finish\"; readonly result: Result; readonly calls?: never };\n\n/** Finite limits for this agent and its descendants; child limits may only tighten them. */\nexport interface AgentLimits {\n /** Decision callbacks, including finish. Defaults to 20. */\n readonly maxTurns?: number;\n /** Admitted subtree calls, including calls stopped before dispatch. Defaults to 100. */\n readonly maxCalls?: number;\n /** Subtree decision callback admissions. Defaults to 100; provider retries are application-owned. */\n readonly maxDecisions?: number;\n /** Pipeline-tool delegation edges below this agent. Defaults to 4; zero allows leaf tools only. */\n readonly maxDepth?: number;\n /** Active decision callbacks and leaf handlers across the subtree. Defaults to 1. */\n readonly maxConcurrency?: number;\n}\n\n/** Step services and the workspace capability available to a registered tool. */\nexport interface AgentToolContext extends PipelineStepContext<{}> {\n readonly environment: AgentEnvironment;\n}\n\n/** Model-facing descriptors and ordinary step services, without executable tools. */\nexport interface AgentDecisionContext<Options extends object> extends PipelineStepContext<Options> {\n readonly environment: AgentEnvironment;\n readonly turn: number;\n readonly stateVersion: number;\n readonly capabilities: readonly {\n readonly name: string;\n readonly description: string;\n readonly inputJsonSchema: Readonly<Record<string, unknown>>;\n }[];\n readonly resultJsonSchema: Readonly<Record<string, unknown>>;\n}\n\nexport interface AgentDefinition<\n Id extends string,\n Options extends StandardSchemaV1<object, object>,\n Result extends StandardSchemaV1,\n State,\n Registry extends Tools,\n> {\n readonly id: Id;\n readonly name?: string;\n readonly description?: string;\n readonly implementationVersion?: string;\n readonly inputSchema: Options;\n readonly resultSchema: Result;\n readonly resultJsonSchema?: Readonly<Record<string, unknown>>;\n /** Extend the standard tools; a custom tool with the same name replaces that default. */\n readonly tools?: Registry;\n readonly limits?: AgentLimits;\n /** Workspace capabilities; descendants inherit them unless explicitly replaced. */\n readonly environment?: AgentEnvironmentProvider;\n initialState(options: Output<Options>): State;\n decide(\n state: AgentState<NoInfer<State>>,\n context: AgentDecisionContext<Output<Options>>\n ): Awaitable<unknown>;\n reduce?(\n state: AgentState<NoInfer<State>>,\n outcomes: readonly AgentOutcome<Registry>[]\n ): NoInfer<State>;\n dryRun?(\n state: AgentState<NoInfer<State>>,\n context: AgentDecisionContext<Output<Options>>\n ): Awaitable<unknown>;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { StandardSchemaV1 } from "../core/pipeline-types.js";
2
+ import type { AgentDefinition, Tools } from "./agent-types.js";
3
+ export { pipelineTool } from "./pipeline-tool.js";
4
+ export { defineTool, ToolError } from "./tools.js";
5
+ export type { DefaultAgentTools } from "./default-tools.js";
6
+ export type { AgentCall, AgentDecision, AgentDecisionContext, AgentLimits, AgentOutcome, AgentState, AgentTool, AgentToolContext, } from "./agent-types.js";
7
+ export type { AgentEnvironment, AgentEnvironmentContext, AgentEnvironmentProvider, AgentProjectInstruction, } from "./environment.js";
8
+ export { defineModelAgent } from "./model-agent.js";
9
+ export type { AgentModel, AgentModelRequest, AgentModelResponse } from "./model-types.js";
10
+ /** Build a bounded in-process agent as an ordinary pipeline with one target, agent. */
11
+ export declare function defineAgent<const Id extends string, const Options extends StandardSchemaV1<object, object>, const Result extends StandardSchemaV1, State, const Registry extends Tools = {}>(definition: AgentDefinition<Id, Options, Result, State, Registry>): import("../core/pipeline-types.js").Pipeline<import("./agent-types.js").Input<Options>, import("./agent-types.js").Output<Result>, "agent", "agent", Id> & {
12
+ readonly optionsSchema: Options;
13
+ readonly definition: import("../core/pipeline-types.js").PipelineDefinitionSnapshot;
14
+ };
@@ -0,0 +1,17 @@
1
+ import { agentError } from "./agent-state.js";
2
+ import { compileAgent } from "./compile-agent.js";
3
+ export { pipelineTool } from "./pipeline-tool.js";
4
+ export { defineTool, ToolError } from "./tools.js";
5
+ export { defineModelAgent } from "./model-agent.js";
6
+ /** Build a bounded in-process agent as an ordinary pipeline with one target, agent. */
7
+ export function defineAgent(definition) {
8
+ const { decide, dryRun } = definition;
9
+ if (typeof decide !== "function" || (dryRun !== undefined && typeof dryRun !== "function"))
10
+ throw agentError("TUBELESS_AGENT_INVALID_DEFINITION", "Agent requires callable decide/dryRun callbacks");
11
+ return compileAgent({
12
+ ...definition,
13
+ decide: async (state, context) => ({ decision: await decide(state, context), state }),
14
+ dryRun: dryRun && (async (state, context) => ({ decision: await dryRun(state, context), state })),
15
+ });
16
+ }
17
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAoBnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD,uFAAuF;AACvF,MAAM,UAAU,WAAW,CAMzB,UAAiE;IACjE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IACtC,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,MAAM,KAAK,UAAU,CAAC;QACxF,MAAM,UAAU,CACd,mCAAmC,EACnC,iDAAiD,CAClD,CAAC;IACJ,OAAO,YAAY,CAAuC;QACxD,GAAG,UAAU;QACb,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;QACrF,MAAM,EACJ,MAAM,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;KAC5F,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { StandardSchemaV1 } from \"../core/pipeline-types.js\";\nimport type { AgentDefinition, Tools } from \"./agent-types.js\";\nimport { agentError } from \"./agent-state.js\";\nimport { compileAgent } from \"./compile-agent.js\";\n\nexport { pipelineTool } from \"./pipeline-tool.js\";\nexport { defineTool, ToolError } from \"./tools.js\";\nexport type { DefaultAgentTools } from \"./default-tools.js\";\nexport type {\n AgentCall,\n AgentDecision,\n AgentDecisionContext,\n AgentLimits,\n AgentOutcome,\n AgentState,\n AgentTool,\n AgentToolContext,\n} from \"./agent-types.js\";\n\nexport type {\n AgentEnvironment,\n AgentEnvironmentContext,\n AgentEnvironmentProvider,\n AgentProjectInstruction,\n} from \"./environment.js\";\n\nexport { defineModelAgent } from \"./model-agent.js\";\nexport type { AgentModel, AgentModelRequest, AgentModelResponse } from \"./model-types.js\";\n\n/** Build a bounded in-process agent as an ordinary pipeline with one target, agent. */\nexport function defineAgent<\n const Id extends string,\n const Options extends StandardSchemaV1<object, object>,\n const Result extends StandardSchemaV1,\n State,\n const Registry extends Tools = {},\n>(definition: AgentDefinition<Id, Options, Result, State, Registry>) {\n const { decide, dryRun } = definition;\n if (typeof decide !== \"function\" || (dryRun !== undefined && typeof dryRun !== \"function\"))\n throw agentError(\n \"TUBELESS_AGENT_INVALID_DEFINITION\",\n \"Agent requires callable decide/dryRun callbacks\"\n );\n return compileAgent<Id, Options, Result, State, Registry>({\n ...definition,\n decide: async (state, context) => ({ decision: await decide(state, context), state }),\n dryRun:\n dryRun && (async (state, context) => ({ decision: await dryRun(state, context), state })),\n });\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { Pipeline, PipelineDefinitionSnapshot, StandardSchemaV1 } from "../core/pipeline-types.js";
2
+ import type { AgentDefinition, AgentDecisionContext, AgentState, Awaitable, Input, Output, Tools } from "./agent-types.js";
3
+ /** Accept raw or already-owned pending state; the turn snapshots it before tools run. */
4
+ export type RuntimeAgentDefinition<Id extends string, Options extends StandardSchemaV1<object, object>, Result extends StandardSchemaV1, State, Registry extends Tools> = Omit<AgentDefinition<Id, Options, Result, State, Registry>, "decide" | "dryRun"> & {
5
+ decide(state: AgentState<State>, context: AgentDecisionContext<Output<Options>>): Awaitable<{
6
+ decision: unknown;
7
+ state: State | AgentState<State>;
8
+ }>;
9
+ dryRun?(state: AgentState<State>, context: AgentDecisionContext<Output<Options>>): Awaitable<{
10
+ decision: unknown;
11
+ state: State | AgentState<State>;
12
+ }>;
13
+ };
14
+ export declare function compileAgent<const Id extends string, const Options extends StandardSchemaV1<object, object>, const Result extends StandardSchemaV1, State, const Registry extends Tools = {}>(definition: RuntimeAgentDefinition<Id, Options, Result, State, Registry>, resolveCwd?: boolean): Pipeline<Input<Options>, Output<Result>, "agent", "agent", Id> & {
15
+ readonly optionsSchema: Options;
16
+ readonly definition: PipelineDefinitionSnapshot;
17
+ };
@@ -0,0 +1,76 @@
1
+ import { createSteps, definePipeline } from "../core/pipeline.js";
2
+ import { STEP_AGENT } from "../core/pipeline-step-metadata.js";
3
+ import { agentError, checkSchema, descriptorFingerprint, jsonDescriptor, ownState, } from "./agent-state.js";
4
+ import { compileTool } from "./tools.js";
5
+ import { defaultTools } from "./default-tools.js";
6
+ import { resolvedLimits } from "./execution-scope.js";
7
+ import { createAgentTurn } from "./turn.js";
8
+ import { runAgentInvocation } from "./invocation.js";
9
+ export function compileAgent(definition, resolveCwd = false) {
10
+ const config = { ...definition };
11
+ checkSchema(config.inputSchema, "Agent input");
12
+ if (typeof config.initialState !== "function" ||
13
+ typeof config.decide !== "function" ||
14
+ (config.reduce !== undefined && typeof config.reduce !== "function") ||
15
+ (config.dryRun !== undefined && typeof config.dryRun !== "function"))
16
+ throw agentError("TUBELESS_AGENT_INVALID_DEFINITION", "Agent requires initialState and decide callbacks, and callable reduce/dryRun when supplied");
17
+ const limits = resolvedLimits(config.limits);
18
+ const resultJsonSchema = jsonDescriptor(config.resultSchema, config.resultJsonSchema, "Agent result");
19
+ const entries = Object.entries({ ...defaultTools, ...config.tools }).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
20
+ if (entries.length > 4096)
21
+ throw agentError("TUBELESS_AGENT_INVALID_DEFINITION", "Agent capability inventory exceeds 4096 tools");
22
+ const registry = new Map(entries.map(([name, tool]) => {
23
+ if (!/^[A-Za-z][A-Za-z0-9_-]{0,127}$/.test(name))
24
+ throw agentError("TUBELESS_AGENT_INVALID_DEFINITION", `Invalid tool name: ${name}`);
25
+ return [name, compileTool(config.id, name, tool)];
26
+ }));
27
+ const capabilities = Object.freeze([...registry.values()].map(({ name, description, inputJsonSchema }) => Object.freeze({ name, description, inputJsonSchema })));
28
+ const turn = createAgentTurn(config, registry, limits, { capabilities, resultJsonSchema });
29
+ const { iteratePipeline } = createSteps(config.inputSchema);
30
+ const agent = iteratePipeline("agent", {
31
+ pipeline: turn,
32
+ maxIterations: limits.maxTurns,
33
+ dryRun: config.dryRun ? undefined : "skip",
34
+ initialState: (_inputs, context) => {
35
+ return {
36
+ state: ownState(config.initialState(context.options)),
37
+ turn: 1,
38
+ stateVersion: 0,
39
+ calls: 0,
40
+ };
41
+ },
42
+ mapOptions: (execution, _inputs, context) => ({
43
+ execution,
44
+ options: context.options,
45
+ agentRunId: context.runId,
46
+ }),
47
+ transition: (result) => result,
48
+ });
49
+ const compiledAgent = agent;
50
+ const run = compiledAgent.run;
51
+ compiledAgent.run = (inputs, context) => runAgentInvocation({ environment: config.environment, limits, resolveCwd }, context, (scoped) => run(inputs, scoped));
52
+ Object.defineProperty(agent, STEP_AGENT, {
53
+ value: Object.freeze({
54
+ limits,
55
+ resultSchemaFingerprint: descriptorFingerprint(resultJsonSchema),
56
+ capabilities: Object.freeze([...registry.values()].map((tool) => Object.freeze({
57
+ name: tool.name,
58
+ description: tool.description,
59
+ inputSchemaFingerprint: descriptorFingerprint(tool.inputJsonSchema),
60
+ identity: tool.pipeline.definition.identity,
61
+ }))),
62
+ }),
63
+ });
64
+ const pipeline = definePipeline({
65
+ id: config.id,
66
+ name: config.name,
67
+ description: config.description,
68
+ implementationVersion: config.implementationVersion,
69
+ steps: [compiledAgent],
70
+ finalize: compiledAgent,
71
+ });
72
+ // SAFETY: the sole iteration step inherits Options, publishes the once-validated Result,
73
+ // and is the only target. This restores deferred generic inference at the factory boundary.
74
+ return pipeline;
75
+ }
76
+ //# sourceMappingURL=compile-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile-agent.js","sourceRoot":"","sources":["../../src/agent/compile-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAO/D,OAAO,EACL,UAAU,EACV,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,QAAQ,GACT,MAAM,kBAAkB,C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nE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ;aAC5C,CAAC,CACH,CACF;SACF,CAAC;KACH,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,cAAc,CAAC;QAC9B,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,qBAAqB,EAAE,MAAM,CAAC,qBAAqB;QACnD,KAAK,EAAE,CAAC,aAAa,CAAC;QACtB,QAAQ,EAAE,aAAa;KACxB,CAAC,CAAC;IACH,yFAAyF;IACzF,4FAA4F;IAC5F,OAAO,QAGN,CAAC;AACJ,CAAC","sourcesContent":["import { createSteps, definePipeline } from \"../core/pipeline.js\";\nimport { STEP_AGENT } from \"../core/pipeline-step-metadata.js\";\nimport type {\n Pipeline,\n PipelineDefinitionSnapshot,\n StandardSchemaV1,\n} from \"../core/pipeline-types.js\";\nimport type { AnyStep } from \"../core/pipeline-steps.js\";\nimport {\n agentError,\n checkSchema,\n descriptorFingerprint,\n jsonDescriptor,\n ownState,\n} from \"./agent-state.js\";\nimport { compileTool } from \"./tools.js\";\nimport { defaultTools } from \"./default-tools.js\";\nimport { resolvedLimits } from \"./execution-scope.js\";\nimport { createAgentTurn, type TurnState } from \"./turn.js\";\nimport { runAgentInvocation } from \"./invocation.js\";\nimport type {\n AgentDefinition,\n AgentDecisionContext,\n AgentState,\n Awaitable,\n Input,\n Output,\n Tools,\n} from \"./agent-types.js\";\n\n/** Accept raw or already-owned pending state; the turn snapshots it before tools run. */\nexport type RuntimeAgentDefinition<\n Id extends string,\n Options extends StandardSchemaV1<object, object>,\n Result extends StandardSchemaV1,\n State,\n Registry extends Tools,\n> = Omit<AgentDefinition<Id, Options, Result, State, Registry>, \"decide\" | \"dryRun\"> & {\n decide(\n state: AgentState<State>,\n context: AgentDecisionContext<Output<Options>>\n ): Awaitable<{\n decision: unknown;\n state: State | AgentState<State>;\n }>;\n dryRun?(\n state: AgentState<State>,\n context: AgentDecisionContext<Output<Options>>\n ): Awaitable<{\n decision: unknown;\n state: State | AgentState<State>;\n }>;\n};\n\nexport function compileAgent<\n const Id extends string,\n const Options extends StandardSchemaV1<object, object>,\n const Result extends StandardSchemaV1,\n State,\n const Registry extends Tools = {},\n>(\n definition: RuntimeAgentDefinition<Id, Options, Result, State, Registry>,\n resolveCwd = false\n): Pipeline<Input<Options>, Output<Result>, \"agent\", \"agent\", Id> & {\n readonly optionsSchema: Options;\n readonly definition: PipelineDefinitionSnapshot;\n} {\n const config = { ...definition };\n checkSchema(config.inputSchema, \"Agent input\");\n if (\n typeof config.initialState !== \"function\" ||\n typeof config.decide !== \"function\" ||\n (config.reduce !== undefined && typeof config.reduce !== \"function\") ||\n (config.dryRun !== undefined && typeof config.dryRun !== \"function\")\n )\n throw agentError(\n \"TUBELESS_AGENT_INVALID_DEFINITION\",\n \"Agent requires initialState and decide callbacks, and callable reduce/dryRun when supplied\"\n );\n const limits = resolvedLimits(config.limits);\n const resultJsonSchema = jsonDescriptor(\n config.resultSchema,\n config.resultJsonSchema,\n \"Agent result\"\n );\n const entries = Object.entries({ ...defaultTools, ...config.tools }).sort(([a], [b]) =>\n a < b ? -1 : a > b ? 1 : 0\n );\n if (entries.length > 4096)\n throw agentError(\n \"TUBELESS_AGENT_INVALID_DEFINITION\",\n \"Agent capability inventory exceeds 4096 tools\"\n );\n const registry = new Map(\n entries.map(([name, tool]) => {\n if (!/^[A-Za-z][A-Za-z0-9_-]{0,127}$/.test(name))\n throw agentError(\"TUBELESS_AGENT_INVALID_DEFINITION\", `Invalid tool name: ${name}`);\n return [name, compileTool(config.id, name, tool)];\n })\n );\n const capabilities = Object.freeze(\n [...registry.values()].map(({ name, description, inputJsonSchema }) =>\n Object.freeze({ name, description, inputJsonSchema })\n )\n );\n const turn = createAgentTurn(config, registry, limits, { capabilities, resultJsonSchema });\n const { iteratePipeline } = createSteps(config.inputSchema);\n const agent = iteratePipeline(\"agent\", {\n pipeline: turn,\n maxIterations: limits.maxTurns,\n dryRun: config.dryRun ? undefined : \"skip\",\n initialState: (_inputs, context): TurnState<State> => {\n return {\n state: ownState(config.initialState(context.options)),\n turn: 1,\n stateVersion: 0,\n calls: 0,\n };\n },\n mapOptions: (execution, _inputs, context) => ({\n execution,\n options: context.options,\n agentRunId: context.runId,\n }),\n transition: (result) => result,\n });\n const compiledAgent: AnyStep<Output<Options>> = agent;\n const run = compiledAgent.run;\n compiledAgent.run = (inputs, context) =>\n runAgentInvocation({ environment: config.environment, limits, resolveCwd }, context, (scoped) =>\n run(inputs, scoped)\n );\n Object.defineProperty(agent, STEP_AGENT, {\n value: Object.freeze({\n limits,\n resultSchemaFingerprint: descriptorFingerprint(resultJsonSchema),\n capabilities: Object.freeze(\n [...registry.values()].map((tool) =>\n Object.freeze({\n name: tool.name,\n description: tool.description,\n inputSchemaFingerprint: descriptorFingerprint(tool.inputJsonSchema),\n identity: tool.pipeline.definition.identity,\n })\n )\n ),\n }),\n });\n const pipeline = definePipeline({\n id: config.id,\n name: config.name,\n description: config.description,\n implementationVersion: config.implementationVersion,\n steps: [compiledAgent],\n finalize: compiledAgent,\n });\n // SAFETY: the sole iteration step inherits Options, publishes the once-validated Result,\n // and is the only target. This restores deferred generic inference at the factory boundary.\n return pipeline as unknown as Pipeline<Input<Options>, Output<Result>, \"agent\", \"agent\", Id> & {\n readonly optionsSchema: Options;\n readonly definition: PipelineDefinitionSnapshot;\n };\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import { PreparedOptions } from "../core/prepared-options.js";
2
+ import { type AgentExecutionScope } from "./execution-scope.js";
3
+ import type { PipelinePlan, PipelineStepContext } from "../core/pipeline-types.js";
4
+ import type { CompiledTool } from "./tools.js";
5
+ type PreparedTool = {
6
+ kind: "handler";
7
+ tool: Extract<CompiledTool, {
8
+ kind: "handler";
9
+ }>;
10
+ input: unknown;
11
+ } | {
12
+ kind: "pipeline";
13
+ tool: Extract<CompiledTool, {
14
+ kind: "pipeline";
15
+ }>;
16
+ options: object;
17
+ preparedOptions: PreparedOptions;
18
+ scope: AgentExecutionScope;
19
+ };
20
+ export type PreparedCall = PreparedTool & {
21
+ id: string;
22
+ plan: PipelinePlan;
23
+ };
24
+ export declare function decisionEnvelope(value: unknown): {
25
+ kind: "finish";
26
+ result: unknown;
27
+ } | {
28
+ kind: "continue";
29
+ calls: readonly unknown[];
30
+ };
31
+ export declare function prepareCalls(values: readonly unknown[], registry: ReadonlyMap<string, CompiledTool>, context: PipelineStepContext<object>): Promise<PreparedCall[]>;
32
+ export {};
@@ -0,0 +1,81 @@
1
+ import { PreparedOptions } from "../core/prepared-options.js";
2
+ import { agentScope } from "./execution-scope.js";
3
+ import { validateStandardSchema } from "../core/pipeline-validation.js";
4
+ import { throwIfAborted } from "../utilities/abort.js";
5
+ import { agentError } from "./agent-state.js";
6
+ function invalid(message) {
7
+ throw agentError("TUBELESS_AGENT_INVALID_DECISION", message);
8
+ }
9
+ function record(value) {
10
+ return (value !== null &&
11
+ typeof value === "object" &&
12
+ !Array.isArray(value) &&
13
+ (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null));
14
+ }
15
+ function keys(value, expected) {
16
+ return (Reflect.ownKeys(value).length === expected.length &&
17
+ expected.every((key) => Object.hasOwn(value, key)));
18
+ }
19
+ export function decisionEnvelope(value) {
20
+ if (!record(value))
21
+ return invalid("Agent decision must be a plain object");
22
+ if (value.kind === "finish" && keys(value, ["kind", "result"]))
23
+ return { kind: "finish", result: value.result };
24
+ if (value.kind !== "continue" ||
25
+ !keys(value, ["kind", "calls"]) ||
26
+ !Array.isArray(value.calls) ||
27
+ value.calls.length === 0)
28
+ return invalid("Agent decision must finish(result) or continue with a nonempty calls array");
29
+ // Leave call traversal to prepareCalls, after the turn admits the batch by length.
30
+ return { kind: "continue", calls: value.calls };
31
+ }
32
+ export async function prepareCalls(values, registry, context) {
33
+ const ids = new Set();
34
+ const calls = Array.from(values, (call) => {
35
+ if (!record(call) ||
36
+ !keys(call, ["id", "tool", "input"]) ||
37
+ typeof call.id !== "string" ||
38
+ !call.id.trim() ||
39
+ call.id.length > 256 ||
40
+ typeof call.tool !== "string" ||
41
+ !call.tool.trim())
42
+ return invalid("Each call requires a nonblank id (up to 256 characters), tool, and input");
43
+ if (ids.has(call.id))
44
+ return invalid(`Duplicate agent call id: ${call.id}`);
45
+ ids.add(call.id);
46
+ return { id: call.id, tool: call.tool, input: call.input };
47
+ });
48
+ // Resolve the complete registry membership before invoking any argument validators.
49
+ const entries = calls.map((call) => {
50
+ const tool = registry.get(call.tool);
51
+ if (!tool)
52
+ return invalid(`Unknown agent tool: ${call.tool}`);
53
+ return { call, tool };
54
+ });
55
+ const prepared = [];
56
+ for (const { call, tool } of entries) {
57
+ throwIfAborted(context.signal, "Agent batch validation");
58
+ let invocation;
59
+ if (tool.kind === "pipeline") {
60
+ const scope = agentScope(context).delegate();
61
+ const input = tool.mapOptions
62
+ ? await validateStandardSchema(tool.inputSchema, call.input, `Agent tool ${call.tool} input`)
63
+ : call.input;
64
+ // SAFETY: the private preparation boundary checks object shape, even for schema-less children.
65
+ const options = tool.mapOptions ? tool.mapOptions(input) : input;
66
+ const preparedOptions = await PreparedOptions.prepare(tool.pipeline.optionsSchema, options, `Pipeline ${tool.pipeline.id} options`);
67
+ invocation = { kind: "pipeline", tool, options, preparedOptions, scope };
68
+ }
69
+ else {
70
+ const input = await validateStandardSchema(tool.inputSchema, call.input, `Agent tool ${call.tool} input`);
71
+ invocation = { kind: "handler", tool, input };
72
+ }
73
+ throwIfAborted(context.signal, "Agent batch validation");
74
+ const plan = tool.pipeline.plan({ dryRun: context.dryRun, cache: context.cachePolicy });
75
+ if (!plan.ok)
76
+ return invalid(`Agent tool ${call.tool} has an invalid plan`);
77
+ prepared.push({ ...invocation, id: call.id, plan });
78
+ }
79
+ return prepared;
80
+ }
81
+ //# sourceMappingURL=decision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision.js","sourceR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C,OAAO,CACnD,IAAI,CAAC,QAAQ,CAAC,aAAa,EAC3B,OAAO,EACP,YAAY,IAAI,CAAC,QAAQ,CAAC,EAAE,UAAU,CACvC,CAAC;YACF,UAAU,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;QAC3E,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,MAAM,sBAAsB,CACxC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,KAAK,EACV,cAAc,IAAI,CAAC,IAAI,QAAQ,CAChC,CAAC;YACF,UAAU,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAChD,CAAC;QACD,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;QACxF,IAAI,CAAC,IAAI,CAAC,EAAE;YAAE,OAAO,OAAO,CAAC,cAAc,IAAI,CAAC,IAAI,sBAAsB,CAAC,CAAC;QAC5E,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,UAAU,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { PreparedOptions } from \"../core/prepared-options.js\";\nimport { agentScope, type AgentExecutionScope } from \"./execution-scope.js\";\nimport type { PipelinePlan, PipelineStepContext } from \"../core/pipeline-types.js\";\nimport { validateStandardSchema } from \"../core/pipeline-validation.js\";\nimport { throwIfAborted } from \"../utilities/abort.js\";\nimport { agentError } from \"./agent-state.js\";\nimport type { CompiledTool } from \"./tools.js\";\n\ntype PreparedTool =\n | {\n kind: \"handler\";\n tool: Extract<CompiledTool, { kind: \"handler\" }>;\n input: unknown;\n }\n | {\n kind: \"pipeline\";\n tool: Extract<CompiledTool, { kind: \"pipeline\" }>;\n options: object;\n preparedOptions: PreparedOptions;\n scope: AgentExecutionScope;\n };\n\nexport type PreparedCall = PreparedTool & {\n id: string;\n plan: PipelinePlan;\n};\n\nfunction invalid(message: string): never {\n throw agentError(\"TUBELESS_AGENT_INVALID_DECISION\", message);\n}\n\nfunction record(value: unknown): value is Record<string, unknown> {\n return (\n value !== null &&\n typeof value === \"object\" &&\n !Array.isArray(value) &&\n (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)\n );\n}\n\nfunction keys(value: Record<string, unknown>, expected: readonly string[]): boolean {\n return (\n Reflect.ownKeys(value).length === expected.length &&\n expected.every((key) => Object.hasOwn(value, key))\n );\n}\n\nexport function decisionEnvelope(\n value: unknown\n): { kind: \"finish\"; result: unknown } | { kind: \"continue\"; calls: readonly unknown[] } {\n if (!record(value)) return invalid(\"Agent decision must be a plain object\");\n if (value.kind === \"finish\" && keys(value, [\"kind\", \"result\"]))\n return { kind: \"finish\", result: value.result };\n if (\n value.kind !== \"continue\" ||\n !keys(value, [\"kind\", \"calls\"]) ||\n !Array.isArray(value.calls) ||\n value.calls.length === 0\n )\n return invalid(\"Agent decision must finish(result) or continue with a nonempty calls array\");\n // Leave call traversal to prepareCalls, after the turn admits the batch by length.\n return { kind: \"continue\", calls: value.calls };\n}\n\nexport async function prepareCalls(\n values: readonly unknown[],\n registry: ReadonlyMap<string, CompiledTool>,\n context: PipelineStepContext<object>\n): Promise<PreparedCall[]> {\n const ids = new Set<string>();\n const calls = Array.from(values, (call: unknown) => {\n if (\n !record(call) ||\n !keys(call, [\"id\", \"tool\", \"input\"]) ||\n typeof call.id !== \"string\" ||\n !call.id.trim() ||\n call.id.length > 256 ||\n typeof call.tool !== \"string\" ||\n !call.tool.trim()\n )\n return invalid(\"Each call requires a nonblank id (up to 256 characters), tool, and input\");\n if (ids.has(call.id)) return invalid(`Duplicate agent call id: ${call.id}`);\n ids.add(call.id);\n return { id: call.id, tool: call.tool, input: call.input };\n });\n // Resolve the complete registry membership before invoking any argument validators.\n const entries = calls.map((call) => {\n const tool = registry.get(call.tool);\n if (!tool) return invalid(`Unknown agent tool: ${call.tool}`);\n return { call, tool };\n });\n const prepared: PreparedCall[] = [];\n for (const { call, tool } of entries) {\n throwIfAborted(context.signal, \"Agent batch validation\");\n let invocation: PreparedTool;\n if (tool.kind === \"pipeline\") {\n const scope = agentScope(context)!.delegate();\n const input = tool.mapOptions\n ? await validateStandardSchema(\n tool.inputSchema,\n call.input,\n `Agent tool ${call.tool} input`\n )\n : call.input;\n // SAFETY: the private preparation boundary checks object shape, even for schema-less children.\n const options = tool.mapOptions ? tool.mapOptions(input) : (input as object);\n const preparedOptions = await PreparedOptions.prepare(\n tool.pipeline.optionsSchema,\n options,\n `Pipeline ${tool.pipeline.id} options`\n );\n invocation = { kind: \"pipeline\", tool, options, preparedOptions, scope };\n } else {\n const input = await validateStandardSchema(\n tool.inputSchema,\n call.input,\n `Agent tool ${call.tool} input`\n );\n invocation = { kind: \"handler\", tool, input };\n }\n throwIfAborted(context.signal, \"Agent batch validation\");\n const plan = tool.pipeline.plan({ dryRun: context.dryRun, cache: context.cachePolicy });\n if (!plan.ok) return invalid(`Agent tool ${call.tool} has an invalid plan`);\n prepared.push({ ...invocation, id: call.id, plan });\n }\n return prepared;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { PipelineStepContext } from "../core/pipeline-types.js";
2
+ export declare function bashTool(input: {
3
+ command: string;
4
+ cwd?: string | null;
5
+ timeoutMs?: number | null;
6
+ }, context: Pick<PipelineStepContext<object>, "cwd" | "signal">): Promise<{
7
+ cwd: string;
8
+ stdout: string;
9
+ stderr: string;
10
+ exitCode: number | null;
11
+ signal: string | null;
12
+ timedOut: boolean;
13
+ truncated: boolean;
14
+ }>;