@ironflow/node 0.20.0 → 0.20.2

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 (146) hide show
  1. package/LICENSE +181 -0
  2. package/package.json +8 -8
  3. package/dist/agent/agent.d.ts +0 -60
  4. package/dist/agent/agent.d.ts.map +0 -1
  5. package/dist/agent/agent.js +0 -133
  6. package/dist/agent/agent.js.map +0 -1
  7. package/dist/agent/approve.d.ts +0 -23
  8. package/dist/agent/approve.d.ts.map +0 -1
  9. package/dist/agent/approve.js +0 -42
  10. package/dist/agent/approve.js.map +0 -1
  11. package/dist/agent/dispatch.d.ts +0 -63
  12. package/dist/agent/dispatch.d.ts.map +0 -1
  13. package/dist/agent/dispatch.js +0 -130
  14. package/dist/agent/dispatch.js.map +0 -1
  15. package/dist/agent/errors.d.ts +0 -90
  16. package/dist/agent/errors.d.ts.map +0 -1
  17. package/dist/agent/errors.js +0 -136
  18. package/dist/agent/errors.js.map +0 -1
  19. package/dist/agent/index.d.ts +0 -30
  20. package/dist/agent/index.d.ts.map +0 -1
  21. package/dist/agent/index.js +0 -27
  22. package/dist/agent/index.js.map +0 -1
  23. package/dist/agent/internal-registry.d.ts +0 -27
  24. package/dist/agent/internal-registry.d.ts.map +0 -1
  25. package/dist/agent/internal-registry.js +0 -36
  26. package/dist/agent/internal-registry.js.map +0 -1
  27. package/dist/agent/internal.d.ts +0 -24
  28. package/dist/agent/internal.d.ts.map +0 -1
  29. package/dist/agent/internal.js +0 -29
  30. package/dist/agent/internal.js.map +0 -1
  31. package/dist/agent/llm.d.ts +0 -39
  32. package/dist/agent/llm.d.ts.map +0 -1
  33. package/dist/agent/llm.js +0 -59
  34. package/dist/agent/llm.js.map +0 -1
  35. package/dist/agent/mcp.d.ts +0 -51
  36. package/dist/agent/mcp.d.ts.map +0 -1
  37. package/dist/agent/mcp.js +0 -155
  38. package/dist/agent/mcp.js.map +0 -1
  39. package/dist/agent/memory.d.ts +0 -74
  40. package/dist/agent/memory.d.ts.map +0 -1
  41. package/dist/agent/memory.js +0 -130
  42. package/dist/agent/memory.js.map +0 -1
  43. package/dist/agent/spawn.d.ts +0 -20
  44. package/dist/agent/spawn.d.ts.map +0 -1
  45. package/dist/agent/spawn.js +0 -29
  46. package/dist/agent/spawn.js.map +0 -1
  47. package/dist/agent/tool.d.ts +0 -39
  48. package/dist/agent/tool.d.ts.map +0 -1
  49. package/dist/agent/tool.js +0 -103
  50. package/dist/agent/tool.js.map +0 -1
  51. package/dist/agent/types.d.ts +0 -363
  52. package/dist/agent/types.d.ts.map +0 -1
  53. package/dist/agent/types.js +0 -9
  54. package/dist/agent/types.js.map +0 -1
  55. package/dist/client.d.ts +0 -942
  56. package/dist/client.d.ts.map +0 -1
  57. package/dist/client.js +0 -1557
  58. package/dist/client.js.map +0 -1
  59. package/dist/command-dedup.d.ts +0 -61
  60. package/dist/command-dedup.d.ts.map +0 -1
  61. package/dist/command-dedup.js +0 -129
  62. package/dist/command-dedup.js.map +0 -1
  63. package/dist/config-client.d.ts +0 -58
  64. package/dist/config-client.d.ts.map +0 -1
  65. package/dist/config-client.js +0 -171
  66. package/dist/config-client.js.map +0 -1
  67. package/dist/function.d.ts +0 -53
  68. package/dist/function.d.ts.map +0 -1
  69. package/dist/function.js +0 -72
  70. package/dist/function.js.map +0 -1
  71. package/dist/index.d.ts +0 -71
  72. package/dist/index.d.ts.map +0 -1
  73. package/dist/index.js +0 -70
  74. package/dist/index.js.map +0 -1
  75. package/dist/internal/assert-defined.d.ts +0 -10
  76. package/dist/internal/assert-defined.d.ts.map +0 -1
  77. package/dist/internal/assert-defined.js +0 -15
  78. package/dist/internal/assert-defined.js.map +0 -1
  79. package/dist/internal/context.d.ts +0 -142
  80. package/dist/internal/context.d.ts.map +0 -1
  81. package/dist/internal/context.js +0 -306
  82. package/dist/internal/context.js.map +0 -1
  83. package/dist/internal/errors.d.ts +0 -66
  84. package/dist/internal/errors.d.ts.map +0 -1
  85. package/dist/internal/errors.js +0 -29
  86. package/dist/internal/errors.js.map +0 -1
  87. package/dist/internal/run-context.d.ts +0 -10
  88. package/dist/internal/run-context.d.ts.map +0 -1
  89. package/dist/internal/run-context.js +0 -23
  90. package/dist/internal/run-context.js.map +0 -1
  91. package/dist/kv.d.ts +0 -86
  92. package/dist/kv.d.ts.map +0 -1
  93. package/dist/kv.js +0 -261
  94. package/dist/kv.js.map +0 -1
  95. package/dist/projection-runner.d.ts +0 -83
  96. package/dist/projection-runner.d.ts.map +0 -1
  97. package/dist/projection-runner.js +0 -498
  98. package/dist/projection-runner.js.map +0 -1
  99. package/dist/projection.d.ts +0 -36
  100. package/dist/projection.d.ts.map +0 -1
  101. package/dist/projection.js +0 -55
  102. package/dist/projection.js.map +0 -1
  103. package/dist/secrets.d.ts +0 -6
  104. package/dist/secrets.d.ts.map +0 -1
  105. package/dist/secrets.js +0 -19
  106. package/dist/secrets.js.map +0 -1
  107. package/dist/serve.d.ts +0 -71
  108. package/dist/serve.d.ts.map +0 -1
  109. package/dist/serve.js +0 -460
  110. package/dist/serve.js.map +0 -1
  111. package/dist/step.d.ts +0 -18
  112. package/dist/step.d.ts.map +0 -1
  113. package/dist/step.js +0 -581
  114. package/dist/step.js.map +0 -1
  115. package/dist/subscribe.d.ts +0 -164
  116. package/dist/subscribe.d.ts.map +0 -1
  117. package/dist/subscribe.js +0 -487
  118. package/dist/subscribe.js.map +0 -1
  119. package/dist/test/index.d.ts +0 -22
  120. package/dist/test/index.d.ts.map +0 -1
  121. package/dist/test/index.js +0 -112
  122. package/dist/test/index.js.map +0 -1
  123. package/dist/test/test-step.d.ts +0 -21
  124. package/dist/test/test-step.d.ts.map +0 -1
  125. package/dist/test/test-step.js +0 -83
  126. package/dist/test/test-step.js.map +0 -1
  127. package/dist/types.d.ts +0 -108
  128. package/dist/types.d.ts.map +0 -1
  129. package/dist/types.js +0 -5
  130. package/dist/types.js.map +0 -1
  131. package/dist/version.d.ts +0 -2
  132. package/dist/version.d.ts.map +0 -1
  133. package/dist/version.js +0 -4
  134. package/dist/version.js.map +0 -1
  135. package/dist/webhook.d.ts +0 -22
  136. package/dist/webhook.d.ts.map +0 -1
  137. package/dist/webhook.js +0 -23
  138. package/dist/webhook.js.map +0 -1
  139. package/dist/worker-streaming.d.ts +0 -17
  140. package/dist/worker-streaming.d.ts.map +0 -1
  141. package/dist/worker-streaming.js +0 -510
  142. package/dist/worker-streaming.js.map +0 -1
  143. package/dist/worker.d.ts +0 -28
  144. package/dist/worker.d.ts.map +0 -1
  145. package/dist/worker.js +0 -559
  146. package/dist/worker.js.map +0 -1
@@ -1,103 +0,0 @@
1
- /**
2
- * tool() — durable, validated, idempotent tool invocation.
3
- *
4
- * Wraps step.run with:
5
- * - Required Zod input validation (per CEO plan, JS-only)
6
- * - Idempotency strategy: "byCall" (default) or "byArgs"
7
- * - Per-tool timeout (default 60s)
8
- *
9
- * defineTool() is a pass-through factory that preserves the input/output
10
- * generic types for callers. The runtime call helper is constructed by
11
- * makeTool() and bound onto AgentContext.tool.
12
- */
13
- import { createHash } from "node:crypto";
14
- import { ToolNotFoundError, ToolValidationError } from "./errors.js";
15
- import { normalizeDuration } from "./internal.js";
16
- /** Default per-tool timeout when the definition does not specify one. */
17
- const DEFAULT_TOOL_TIMEOUT = "60s";
18
- /**
19
- * Define a tool. Pass-through factory that preserves the input/output
20
- * generic types. Tools are typically registered via AgentConfig.tools so
21
- * the agent can dispatch LLM-requested calls by name.
22
- */
23
- export function defineTool(spec) {
24
- return spec;
25
- }
26
- /**
27
- * Build a ToolFn closure bound to the given step client and tool registry.
28
- *
29
- * Exported for use by agent.ts; not part of the public API surface.
30
- */
31
- export function makeTool(step, registry, runtime) {
32
- const tool = (async (defOrName, args) => {
33
- const def = resolveDefinition(defOrName, registry);
34
- return invokeTool(step, def, args, runtime);
35
- });
36
- return tool;
37
- }
38
- function resolveDefinition(defOrName, registry) {
39
- if (typeof defOrName === "string") {
40
- const found = registry.get(defOrName);
41
- if (!found) {
42
- throw new ToolNotFoundError(defOrName);
43
- }
44
- return found;
45
- }
46
- return defOrName;
47
- }
48
- async function invokeTool(step, def, args, runtime) {
49
- const validated = validateInput(def, args);
50
- const timeout = normalizeDuration(def.timeout) ?? DEFAULT_TOOL_TIMEOUT;
51
- const idempotent = def.idempotent ?? "byCall";
52
- if (idempotent === "byArgs") {
53
- const hash = hashArgs(validated);
54
- const cacheKey = `${def.name}:${hash}`;
55
- const cached = runtime.byArgsCache.get(cacheKey);
56
- if (cached) {
57
- return cached;
58
- }
59
- const promise = step.run(`tool.${def.name}.${hash}`, () => def.handler(validated), { timeout });
60
- runtime.byArgsCache.set(cacheKey, promise);
61
- return promise;
62
- }
63
- return step.run(`tool.${def.name}`, () => def.handler(validated), { timeout });
64
- }
65
- function validateInput(def, args) {
66
- const result = def.input.safeParse(args);
67
- if (!result.success) {
68
- throw new ToolValidationError(def.name, result.error.issues);
69
- }
70
- return result.data;
71
- }
72
- function hashArgs(args) {
73
- const serialized = stableStringify(args);
74
- return createHash("sha256").update(serialized).digest("hex").slice(0, 16);
75
- }
76
- /**
77
- * Stable-key JSON stringify so { a: 1, b: 2 } and { b: 2, a: 1 } hash to
78
- * the same value. Required for byArgs idempotency to behave intuitively
79
- * across calls that build args from object spreads in different orders.
80
- *
81
- * Objects exposing toJSON() (Date, custom serializers) defer to the host
82
- * JSON.stringify so different Dates do not collapse to the same hash.
83
- */
84
- function stableStringify(value) {
85
- if (value === null || typeof value !== "object") {
86
- return JSON.stringify(value);
87
- }
88
- if (typeof value.toJSON === "function") {
89
- return JSON.stringify(value);
90
- }
91
- if (Array.isArray(value)) {
92
- return `[${value.map(stableStringify).join(",")}]`;
93
- }
94
- const entries = Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
95
- return `{${entries
96
- .map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`)
97
- .join(",")}}`;
98
- }
99
- /** Construct an empty ToolRuntime. Used by agent() per run. */
100
- export function createToolRuntime() {
101
- return { byArgsCache: new Map() };
102
- }
103
- //# sourceMappingURL=tool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/agent/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,yEAAyE;AACzE,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAanC;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,IAAqC;IAErC,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAgB,EAChB,QAAgD,EAChD,OAAoB;IAEpB,MAAM,IAAI,GAAG,CAAC,KAAK,EACjB,SAAqC,EACrC,IAAa,EACK,EAAE;QACpB,MAAM,GAAG,GAAG,iBAAiB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACnD,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC,CAAW,CAAC;IACb,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,iBAAiB,CACxB,SAAqC,EACrC,QAAgD;IAEhD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,UAAU,CACvB,IAAgB,EAChB,GAAsB,EACtB,IAAa,EACb,OAAoB;IAEpB,MAAM,SA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,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7D,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAClB,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,iBAAiB;IAC/B,OAAO,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;AACpC,CAAC"}
@@ -1,363 +0,0 @@
1
- /**
2
- * Agent module type definitions.
3
- *
4
- * AgentContext extends the standard FunctionContext with agent-shaped
5
- * primitives (tool, llm, approve, memory, spawn). Wrappers compose
6
- * on top of the existing step client — no new server primitives.
7
- */
8
- import type { Duration, FunctionConfig, FunctionContext, IronflowEvent, IronflowFunction, Logger, RunInfo, SecretsClient, StepClient } from "@ironflow/core";
9
- import type { z } from "zod";
10
- /**
11
- * Idempotency strategy for tool() calls.
12
- *
13
- * - "byCall": each tool() invocation memoizes by call-site (default).
14
- * Matches existing step.run semantics — same call, same memoized result.
15
- * - "byArgs": memoize by SHA-256 hash of input args. Subsequent calls with
16
- * the same input return the cached result, even from different call sites.
17
- */
18
- export type ToolIdempotency = "byCall" | "byArgs";
19
- /**
20
- * A tool definition produced by defineTool().
21
- *
22
- * Tools are registered on AgentConfig.tools so the agent can dispatch
23
- * LLM-requested tool calls by name. Definitions are also callable
24
- * directly via ctx.tool(def, args) for type-safe invocation.
25
- */
26
- export interface ToolDefinition<TInput = unknown, TOutput = unknown> {
27
- /** Unique tool name (used for LLM dispatch). */
28
- readonly name: string;
29
- /** Optional human-readable description (surfaced to LLMs and MCP). */
30
- readonly description?: string;
31
- /** Required Zod schema for input validation. */
32
- readonly input: z.ZodType<TInput>;
33
- /** Idempotency strategy. Default: "byCall". */
34
- readonly idempotent?: ToolIdempotency;
35
- /** Per-tool timeout. Default: 60s. */
36
- readonly timeout?: Duration;
37
- /** Tool implementation. */
38
- readonly handler: (input: TInput) => Promise<TOutput>;
39
- }
40
- /**
41
- * Erased generic alias for arrays/registries holding tools of mixed
42
- * narrow input/output types. Use in container positions (e.g.
43
- * AgentConfig.tools) where TS array invariance otherwise rejects narrow
44
- * subtypes.
45
- */
46
- export type AnyToolDefinition = ToolDefinition<any, any>;
47
- /**
48
- * The tool helper available on AgentContext.
49
- *
50
- * Has two call shapes:
51
- * - by reference: tool(def, args) — type-safe, returns def's output type
52
- * - by name: tool(name, args) — for LLM-driven dispatch, returns unknown
53
- *
54
- * Both wrap step.run with Zod validation, idempotency keying, and timeout
55
- * enforcement. The by-name form requires the tool to be registered via
56
- * AgentConfig.tools.
57
- */
58
- export interface ToolFn {
59
- <TInput, TOutput>(def: ToolDefinition<TInput, TOutput>, args: TInput): Promise<TOutput>;
60
- (name: string, args: unknown): Promise<unknown>;
61
- }
62
- /**
63
- * Provider-agnostic completion request.
64
- *
65
- * The llm() wrapper is sugar — it does not own a provider router. Callers
66
- * pass a provider call (closure) that does the actual API call. The wrapper
67
- * memoizes the result and classifies known failure modes.
68
- */
69
- export interface LLMCompleteRequest {
70
- /** Conversation messages. Provider-shape-agnostic. */
71
- messages: ReadonlyArray<{
72
- role: string;
73
- content: unknown;
74
- }>;
75
- /** Optional tool definitions for function-calling providers. */
76
- tools?: ReadonlyArray<{
77
- name: string;
78
- description?: string;
79
- input?: unknown;
80
- }>;
81
- /**
82
- * Provider call closure. Must return a normalized LLMCompleteResult.
83
- *
84
- * The wrapper memoizes the closure's resolved value as a step. The
85
- * closure is responsible for the actual provider call and for mapping
86
- * provider-specific shapes onto LLMCompleteResult.
87
- */
88
- call: () => Promise<LLMCompleteResult>;
89
- /** Optional provider-passthrough metadata (model, temperature, …). */
90
- options?: Record<string, unknown>;
91
- }
92
- /**
93
- * Result of an llm() call.
94
- *
95
- * Shape is provider-agnostic. Callers narrow as needed.
96
- */
97
- export interface LLMCompleteResult {
98
- /** Raw assistant message content. */
99
- content?: unknown;
100
- /** Tool calls requested by the model, if any. */
101
- toolCalls?: ReadonlyArray<{
102
- name: string;
103
- input: unknown;
104
- }>;
105
- /**
106
- * Optional finish reason hint. When set, the wrapper inspects it to
107
- * raise classified errors:
108
- * - "refusal" → LLMRefusalError
109
- * - "max_tokens" / "length" → LLMMaxTokensError
110
- * Anything else passes through.
111
- */
112
- finishReason?: string;
113
- /** Provider-passthrough metadata (usage, raw, …). */
114
- metadata?: Record<string, unknown>;
115
- }
116
- /**
117
- * The llm client surface exposed to handlers.
118
- */
119
- export interface LLMClient {
120
- /** Run a memoized completion. Increments the agent turn counter. */
121
- complete(request: LLMCompleteRequest): Promise<LLMCompleteResult>;
122
- }
123
- /**
124
- * Options for approve().
125
- */
126
- export interface ApproveOptions<TPayload = unknown> {
127
- /** Time to wait for the approval event before timing out. */
128
- ttl: Duration;
129
- /** Payload to attach to the pending approval (visible to approvers). */
130
- payload?: TPayload;
131
- }
132
- /**
133
- * Result of approve().
134
- *
135
- * approved=false on timeout. The handler can distinguish timeout vs
136
- * explicit rejection by inspecting the reason field.
137
- */
138
- export interface ApproveResult<TPayload = unknown> {
139
- /** Whether the request was approved. */
140
- approved: boolean;
141
- /** User who approved/rejected, if recorded by the approver. */
142
- approver?: string;
143
- /** Payload echoed back from the approval event. */
144
- payload?: TPayload;
145
- /** Optional reason supplied by the approver, or "timeout". */
146
- reason?: string;
147
- }
148
- /**
149
- * Approval helper.
150
- */
151
- export type ApproveFn = <TPayload = unknown, TResult = unknown>(name: string, options: ApproveOptions<TPayload>) => Promise<ApproveResult<TResult>>;
152
- /**
153
- * Options for memory.get().
154
- */
155
- export interface MemoryGetOptions {
156
- /**
157
- * Disable the in-run cache for this read. Default: false (cache on).
158
- *
159
- * Cache invalidates on own writes within the same run.
160
- */
161
- bypassCache?: boolean;
162
- }
163
- /**
164
- * Options for memory.append().
165
- */
166
- export interface MemoryAppendOptions {
167
- /** Optional metadata attached to the appended event. */
168
- metadata?: Record<string, unknown>;
169
- }
170
- /**
171
- * Memory client.
172
- *
173
- * Wraps an entity stream keyed by the agent run. memory.entityStream()
174
- * requires a projection — raw replay is not exposed.
175
- */
176
- export interface MemoryClient {
177
- /**
178
- * Read the projected memory state.
179
- *
180
- * Returns undefined if the projection has no record for this run.
181
- */
182
- get<T = unknown>(options?: MemoryGetOptions): Promise<T | undefined>;
183
- /** Append a memory event (durable). */
184
- append<T = unknown>(eventName: string, data: T, options?: MemoryAppendOptions): Promise<void>;
185
- /**
186
- * Open a projection-backed entity stream view.
187
- *
188
- * Throws MemoryProjectionRequiredError if no projection name is supplied.
189
- */
190
- entityStream<T = unknown>(streamId: string, projectionName: string): Promise<T | undefined>;
191
- }
192
- /**
193
- * Configuration for the memory client.
194
- *
195
- * Memory is opt-in per agent: callers wire a streamId + projection name
196
- * via AgentConfig.memory.
197
- */
198
- export interface MemoryConfig {
199
- /** Entity stream ID for this agent's memory. */
200
- streamId: string;
201
- /** Projection name used by memory.get(). */
202
- projection: string;
203
- /**
204
- * Entity type recorded with appended events. Informational on the
205
- * server side; surfaces in audit/admin views. Defaults to "agent".
206
- */
207
- entityType?: string;
208
- }
209
- /**
210
- * Options for spawn().
211
- */
212
- export interface SpawnOptions<TInput = unknown> {
213
- /** Function ID to invoke as a sub-agent. */
214
- functionId: string;
215
- /** Input event payload for the sub-agent. */
216
- input: TInput;
217
- /** Whether to wait for completion. Default: true. */
218
- await?: boolean;
219
- }
220
- /**
221
- * Result of a spawn() call.
222
- *
223
- * Field availability depends on the await mode:
224
- * - await=true (default): output is the resolved sub-agent value;
225
- * runId is omitted because step.invoke does not return the run ID.
226
- * - await=false: runId is present (from step.invokeAsync); output is
227
- * omitted because the caller did not wait for completion.
228
- */
229
- export interface SpawnResult<TOutput = unknown> {
230
- /** Sub-run ID (for log/audit correlation). Present when await=false. */
231
- runId?: string;
232
- /** Sub-agent output. Present when await=true. */
233
- output?: TOutput;
234
- }
235
- /**
236
- * Spawn helper.
237
- */
238
- export type SpawnFn = <TInput = unknown, TOutput = unknown>(name: string, options: SpawnOptions<TInput>) => Promise<SpawnResult<TOutput>>;
239
- /**
240
- * Definition of a single MCP-exposed tool.
241
- *
242
- * Note: client-side scope hints are advisory. Authoritative authorization
243
- * is enforced server-side via api_keys + tool_scopes. See the agent-runtime
244
- * licensing docs for the auth model.
245
- */
246
- export interface McpToolDef<TInput = unknown, TOutput = unknown> {
247
- /** Tool name as exposed via MCP. */
248
- name: string;
249
- /** Human-readable description for MCP clients. */
250
- description: string;
251
- /** Zod input schema. */
252
- input: z.ZodType<TInput>;
253
- /** Optional Zod output schema (recommended). */
254
- output?: z.ZodType<TOutput>;
255
- /** Required scope strings for server-side RBAC. Hint to clients only. */
256
- scopes?: ReadonlyArray<string>;
257
- /** Tool implementation. */
258
- handler: (input: TInput) => Promise<TOutput>;
259
- }
260
- /**
261
- * Erased generic alias for arrays/registries holding MCP tools of mixed
262
- * narrow input/output types. Use in container positions where TS array
263
- * invariance otherwise rejects narrow McpToolDef subtypes (issue #634).
264
- */
265
- export type AnyMcpToolDef = McpToolDef<any, any>;
266
- /**
267
- * Configuration for exposeMcp().
268
- *
269
- * `name` doubles as the agent namespace surfaced to MCP clients
270
- * (qualified tool name = `${name}.${tool.name}`). The Ironflow server
271
- * uses it as the registry key — calling exposeMcp() twice with the
272
- * same name from the same API key rotates the HMAC secret.
273
- */
274
- export interface ExposeMcpConfig {
275
- /** Agent namespace + server name reported via MCP initialize. */
276
- name: string;
277
- /** Server version. */
278
- version: string;
279
- /** Tool registry. */
280
- tools: ReadonlyArray<AnyMcpToolDef>;
281
- /**
282
- * Public URL the Ironflow server will POST signed dispatch requests to.
283
- * Must point at the same `serve()` mount that hosts your push functions —
284
- * the mount appends `/ironflow/agent-tools/dispatch` and verifies HMAC.
285
- *
286
- * Required. No env fallback: the public URL is deployment-specific and
287
- * cannot be inferred at runtime.
288
- */
289
- callbackUrl: string;
290
- /**
291
- * Ironflow control-plane URL. Defaults to `IRONFLOW_URL` then
292
- * `IRONFLOW_SERVER_URL` env vars.
293
- */
294
- serverUrl?: string;
295
- /**
296
- * API key used to call AgentToolsService/RegisterTool. The key must
297
- * hold the `agent:tools:register` action. Defaults to
298
- * `IRONFLOW_API_KEY` env var.
299
- */
300
- apiKey?: string;
301
- }
302
- /**
303
- * Configuration for an agent.
304
- *
305
- * Extends FunctionConfig with:
306
- * - tools: ToolDefinition[] — registry for ctx.tool(name, args) dispatch
307
- * - memory: MemoryConfig — opt-in durable memory
308
- * - maxTurns: number — turn budget (default 20)
309
- */
310
- export interface AgentConfig<TEventSchema extends z.ZodType = z.ZodType> extends FunctionConfig<TEventSchema> {
311
- /** Tool definitions available for LLM-driven dispatch. */
312
- tools?: ReadonlyArray<AnyToolDefinition>;
313
- /** Durable memory configuration. */
314
- memory?: MemoryConfig;
315
- /**
316
- * Maximum number of agent turns (llm() calls) before
317
- * MaxTurnsExceededError is raised. Default: 20.
318
- */
319
- maxTurns?: number;
320
- }
321
- /**
322
- * Context passed to agent handlers.
323
- *
324
- * Extends FunctionContext with tool/llm/approve/memory/spawn helpers.
325
- * All helpers compose over the underlying StepClient — they record
326
- * durable steps under the hood.
327
- */
328
- export interface AgentContext<TEvent = unknown> extends FunctionContext<TEvent> {
329
- /** Standard fields from FunctionContext (re-asserted for IDE clarity). */
330
- readonly event: IronflowEvent<TEvent>;
331
- readonly step: StepClient;
332
- readonly run: RunInfo;
333
- readonly logger: Logger;
334
- readonly secrets: SecretsClient;
335
- /** Run a tool. Wraps step.run with Zod validation, idempotency, timeout. */
336
- readonly tool: ToolFn;
337
- /** Run an LLM call. Memoized step with classified error surface. */
338
- readonly llm: LLMClient;
339
- /** Wait for a human approval event. */
340
- readonly approve: ApproveFn;
341
- /** Read/write durable agent memory. */
342
- readonly memory: MemoryClient;
343
- /** Spawn a sub-agent. */
344
- readonly spawn: SpawnFn;
345
- /**
346
- * Number of llm() turns consumed so far in this run (read-only).
347
- *
348
- * Incremented before each llm() call. Comparison against
349
- * config.maxTurns drives MaxTurnsExceededError.
350
- */
351
- readonly turn: number;
352
- }
353
- /**
354
- * Agent handler signature.
355
- */
356
- export type AgentHandler<TEvent = unknown, TResult = unknown> = (ctx: AgentContext<TEvent>) => Promise<TResult>;
357
- /**
358
- * An agent is a specialized IronflowFunction whose handler accepts an
359
- * AgentContext. It registers like any other function — `serve()` and
360
- * `createWorker()` need no agent-specific awareness.
361
- */
362
- export type IronflowAgent<TEvent = unknown, TResult = unknown> = IronflowFunction<TEvent, TResult>;
363
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,MAAM,EACN,OAAO,EACP,aAAa,EACb,UAAU,EACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAM7B;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IACjE,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,CAAC,EAAE,eAAe,CAAC;IACtC,sCAAsC;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAC5B,2BAA2B;IAC3B,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvD;AAED;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEzD;;;;;;;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OAAO,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAEhC,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,oEAAoE;IACpE,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IAExB,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAE5B,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAE9B,yBAAyB;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,CAC9D,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,KACtB,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Agent module type definitions.
3
- *
4
- * AgentContext extends the standard FunctionContext with agent-shaped
5
- * primitives (tool, llm, approve, memory, spawn). Wrappers compose
6
- * on top of the existing step client — no new server primitives.
7
- */
8
- export {};
9
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}