@lunora/agent 1.0.0-alpha.28 → 1.0.0-alpha.280
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.
- package/README.md +1 -2
- package/dist/channels.d.mts +23 -12
- package/dist/channels.d.ts +23 -12
- package/dist/channels.mjs +1 -1
- package/dist/component.d.mts +54 -2
- package/dist/component.d.ts +54 -2
- package/dist/component.mjs +2 -2
- package/dist/core.d.mts +204 -0
- package/dist/core.d.ts +204 -0
- package/dist/core.mjs +1 -0
- package/dist/inbound.d.mts +12 -10
- package/dist/inbound.d.ts +12 -10
- package/dist/inbound.mjs +1 -1
- package/dist/index.d.mts +172 -143
- package/dist/index.d.ts +172 -143
- package/dist/index.mjs +1 -1
- package/dist/naming.d.mts +15 -7
- package/dist/naming.d.ts +15 -7
- package/dist/naming.mjs +1 -1
- package/dist/packem_chunks/createAgentGenerate.mjs +3 -0
- package/dist/packem_chunks/otlpTelemetry.mjs +1 -0
- package/dist/packem_chunks/resolve-run.mjs +1 -0
- package/dist/packem_chunks/runAgentLoop.mjs +3 -0
- package/dist/packem_shared/AGENT_MODULE-CYBmT9SD.mjs +1 -0
- package/dist/packem_shared/DEFAULT_DISPATCH_TIMEOUT_MS-DiRHEqJU-BRtWNzq1.mjs +1 -0
- package/dist/packem_shared/SecretUnavailableError-DOy2M4Ak.mjs +1 -0
- package/dist/packem_shared/VoiceSessionDO-CdvG2L-D.mjs +1 -0
- package/dist/packem_shared/adaptMcpResult-CA-3ovJd.mjs +2 -0
- package/dist/packem_shared/agent-ai-CP87uSoZ.mjs +1 -0
- package/dist/packem_shared/agentAsTool-BF-7Dnzy.mjs +1 -0
- package/dist/packem_shared/app-call-options-BE0CQ6Qg.mjs +1 -0
- package/dist/packem_shared/braintrustTelemetry-Ck09dC4G.mjs +1 -0
- package/dist/packem_shared/branch-marker-boZ00zmk.mjs +1 -0
- package/dist/packem_shared/buildModelMessages-DVQdQ7_1.mjs +5 -0
- package/dist/packem_shared/codeTool-Cn8TuNjk.mjs +1 -0
- package/dist/packem_shared/collectAgenticMemoryTools-X7AqELV3.mjs +1 -0
- package/dist/packem_shared/combineTelemetry-DgE9W9G8.mjs +1 -0
- package/dist/packem_shared/common-DBc9y7Np.mjs +1 -0
- package/dist/packem_shared/compileAgentWorkflow-yZB8fbYc.mjs +1 -0
- package/dist/packem_shared/component-shared--SPcu0Iw.mjs +1 -0
- package/dist/packem_shared/consoleTelemetry-Cl-WQEsZ.mjs +1 -0
- package/dist/packem_shared/createAgentContext-C8k1y2Ot.mjs +1 -0
- package/dist/packem_shared/defineAgent-6Ih7L9E9.mjs +3 -0
- package/dist/packem_shared/defineSkill-DGGvDWNq.mjs +1 -0
- package/dist/packem_shared/fnv1a-BNN96GYb.mjs +1 -0
- package/dist/packem_shared/functionTool-Cf433Hdo.mjs +1 -0
- package/dist/packem_shared/in-flight-calls-C9QGq8uH.mjs +1 -0
- package/dist/packem_shared/inbound-shard-A7S7dnf_.mjs +1 -0
- package/dist/packem_shared/jsCodeTool-BJB3Fpm2.mjs +18 -0
- package/dist/packem_shared/jsonSchema-fhoaBWpN.mjs +1 -0
- package/dist/packem_shared/memory-JI0lUu84.mjs +1 -0
- package/dist/packem_shared/normalizeEntityName-BiUH5B5W.mjs +2 -0
- package/dist/packem_shared/positive-integer-ztHqqpBk.mjs +1 -0
- package/dist/packem_shared/run-shard-B7iMrAI0.mjs +1 -0
- package/dist/packem_shared/runVoiceTurn-DPa5UZ45.mjs +1 -0
- package/dist/packem_shared/sandbox-budgets-DDvj4Orr.mjs +1 -0
- package/dist/packem_shared/sandboxComponent-Du0yENEO.mjs +7 -0
- package/dist/packem_shared/sentryTelemetry-B1BuLxxj.mjs +1 -0
- package/dist/packem_shared/tool-output-Cmk3JWMG.mjs +1 -0
- package/dist/packem_shared/{types.d-boAM2Yi1.d.mts → types.d-Bzy_Qah6.d.mts} +435 -34
- package/dist/packem_shared/{types.d-boAM2Yi1.d.ts → types.d-Bzy_Qah6.d.ts} +435 -34
- package/dist/packem_shared/voice-turn-B9omvXoR.mjs +1 -0
- package/dist/packem_shared/webSearchTool-BzXW0R4r.mjs +1 -0
- package/dist/packem_shared/withAgentScheduleShard-Bn3bdW5b.mjs +1 -0
- package/dist/packem_shared/workflow-binding-Dm9hBzx_.mjs +1 -0
- package/dist/packem_shared/wrapUntrusted-BuHBC6sV.mjs +2 -0
- package/dist/reply.d.mts +58 -0
- package/dist/reply.d.ts +58 -0
- package/dist/reply.mjs +1 -0
- package/dist/sandbox.d.mts +159 -18
- package/dist/sandbox.d.ts +159 -18
- package/dist/sandbox.mjs +1 -1
- package/dist/skill-markdown.d.mts +36 -0
- package/dist/skill-markdown.d.ts +36 -0
- package/dist/skill-markdown.mjs +1 -0
- package/dist/telemetry/index.d.mts +165 -38
- package/dist/telemetry/index.d.ts +165 -38
- package/dist/telemetry/index.mjs +1 -1
- package/package.json +24 -9
- package/dist/packem_shared/AGENT_MODULE-BXx-tSCe.mjs +0 -1
- package/dist/packem_shared/VoiceSessionDO-CTaBSdXk.mjs +0 -1
- package/dist/packem_shared/adaptMcpResult-18G7zpFo.mjs +0 -2
- package/dist/packem_shared/agentAsTool-CJCTyAQG.mjs +0 -1
- package/dist/packem_shared/base64-jU-Ci6Tu.mjs +0 -1
- package/dist/packem_shared/braintrustTelemetry-CnOI5WAw.mjs +0 -1
- package/dist/packem_shared/buildModelMessages-Dm2wVNQy.mjs +0 -5
- package/dist/packem_shared/codeTool-DYJVy-bH.mjs +0 -1
- package/dist/packem_shared/collectAgenticMemoryTools-DBcP8dUa.mjs +0 -1
- package/dist/packem_shared/combineTelemetry-oLCV_EPV.mjs +0 -1
- package/dist/packem_shared/common-Dck97z3Y.mjs +0 -1
- package/dist/packem_shared/compileAgentWorkflow-C4xqSw82.mjs +0 -1
- package/dist/packem_shared/consoleTelemetry-CaoI-NGg.mjs +0 -1
- package/dist/packem_shared/createAgentContext-B1IfI7ro.mjs +0 -1
- package/dist/packem_shared/createAgentGenerate-BUVImo85.mjs +0 -3
- package/dist/packem_shared/createDispatchRunner-CQ8HXscn-BrqT0bIG.mjs +0 -1
- package/dist/packem_shared/defineAgent-CKhzzmys.mjs +0 -3
- package/dist/packem_shared/defineSkill-DfJxCwfZ.mjs +0 -1
- package/dist/packem_shared/functionTool-CWHhkYqd.mjs +0 -1
- package/dist/packem_shared/graph-component-B2YmC2eL.mjs +0 -2
- package/dist/packem_shared/memory-DNRyyp1b.mjs +0 -1
- package/dist/packem_shared/normalizeEntityName-BQpyssvL.mjs +0 -1
- package/dist/packem_shared/otlpTelemetry-DcW9mOLV.mjs +0 -1
- package/dist/packem_shared/runAgentLoop-DNAt-pGz.mjs +0 -3
- package/dist/packem_shared/runVoiceTurn-PkMsfG_v.mjs +0 -1
- package/dist/packem_shared/sandboxComponent-BhaGHsQZ.mjs +0 -1
- package/dist/packem_shared/sentryTelemetry-Dr2aPuvl.mjs +0 -1
|
@@ -9,11 +9,40 @@ import { FlexibleSchema, LanguageModel, ModelMessage, ToolSet, ToolChoice, ToolC
|
|
|
9
9
|
interface AgentFunctionReference {
|
|
10
10
|
__lunoraRef: string;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Per-call options an {@link AgentRunFunction} forwards to the dispatcher —
|
|
14
|
+
* a structural subset of `@lunora/dispatch`'s `RunFunctionOptions`, declared
|
|
15
|
+
* locally so this module stays free of that import.
|
|
16
|
+
* @experimental
|
|
17
|
+
*/
|
|
18
|
+
interface AgentRunOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Route the call to this shard instead of the default one. Pass
|
|
21
|
+
* {@link AgentToolContext.shardKey} when the target reads `.shardBy(...)` tables —
|
|
22
|
+
* `functionTool` does — and leave it unset for the agent's own `agents:*`
|
|
23
|
+
* functions, whose threads, state and secrets live on the default shard.
|
|
24
|
+
*/
|
|
25
|
+
shardKey?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Abort the dispatch after this many ms, overriding the runner's 30s
|
|
28
|
+
* default (`DEFAULT_DISPATCH_TIMEOUT_MS`).
|
|
29
|
+
*
|
|
30
|
+
* Load-bearing for any tool whose target legitimately runs longer than
|
|
31
|
+
* that. A dispatch timeout answers 503, which is NOT a deterministic
|
|
32
|
+
* dispatch failure, so the tool's `step.do` rethrows and the host retries
|
|
33
|
+
* the step — dispatching the same call again while the FIRST one is still
|
|
34
|
+
* running. For a side-effecting target (a container command, a billed page
|
|
35
|
+
* render) that is a second execution, not a second attempt. Set this at
|
|
36
|
+
* least as wide as the target's own budget, and give the target an inner
|
|
37
|
+
* deadline strictly under it so the target aborts itself first.
|
|
38
|
+
*/
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
}
|
|
12
41
|
/**
|
|
13
42
|
* `ctx.run`-shaped dispatcher the loop uses to call Lunora functions.
|
|
14
43
|
* @experimental
|
|
15
44
|
*/
|
|
16
|
-
type AgentRunFunction = (reference: AgentFunctionReference, args?: Record<string, unknown
|
|
45
|
+
type AgentRunFunction = (reference: AgentFunctionReference, args?: Record<string, unknown>, options?: AgentRunOptions) => Promise<unknown>;
|
|
17
46
|
/**
|
|
18
47
|
* Structural subset of the Cloudflare Workflows durable-step API the loop needs.
|
|
19
48
|
* @experimental
|
|
@@ -23,7 +52,7 @@ interface AgentStepLike {
|
|
|
23
52
|
/**
|
|
24
53
|
* Durably hibernate until an external event of `type` arrives, then return
|
|
25
54
|
* its payload. Used for human-in-the-loop approvals: a run pauses on
|
|
26
|
-
* `approval
|
|
55
|
+
* `approval:<toolCallId>` until a client resolves it. Like `do`, a resolved
|
|
27
56
|
* wait is memoized — a replay returns the recorded decision without pausing
|
|
28
57
|
* again. Signature mirrors `@lunora/workflow`'s `WorkflowStepLike`.
|
|
29
58
|
*/
|
|
@@ -42,15 +71,30 @@ interface AgentStepLike {
|
|
|
42
71
|
* `idempotencyKey`.
|
|
43
72
|
*
|
|
44
73
|
* The `idempotencyKey` is the deterministic durable-step name
|
|
45
|
-
* (`tool
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
74
|
+
* (`tool:<name>:<toolCallId>`, further suffixed per script step for a
|
|
75
|
+
* `codeTool`). A COMPLETED tool step is never re-run on a workflow replay
|
|
76
|
+
* (native step memoization) — but a step that FAILS mid-body is retried
|
|
77
|
+
* at-least-once, so a side-effecting tool (charge a card, send a mail) must
|
|
78
|
+
* dedupe on this key itself. `functionTool` forwards it to the dispatched
|
|
79
|
+
* function as `args.idempotencyKey` (pinned after the model input, so it
|
|
80
|
+
* can't be overridden) — a function that wants to dedupe declares
|
|
81
|
+
* `idempotencyKey: v.optional(v.string())` in its own args and checks it; a
|
|
82
|
+
* function that ignores it is unaffected (an undeclared arg field is dropped,
|
|
83
|
+
* not rejected).
|
|
49
84
|
* @experimental
|
|
50
85
|
*/
|
|
51
86
|
interface AgentToolContext {
|
|
87
|
+
/**
|
|
88
|
+
* How many sub-agent delegations deep this run already is — 0 for a run a
|
|
89
|
+
* user started, one more per `agent.asTool` hop. The loop copies it off
|
|
90
|
+
* {@link AgentRunInput.depth}; `agent.asTool` reads it to refuse spawning a
|
|
91
|
+
* child past the delegation-depth bound (see `as-tool.ts`). Absent is 0.
|
|
92
|
+
*/
|
|
93
|
+
depth?: number;
|
|
52
94
|
/** The Worker environment bindings. */
|
|
53
95
|
env: Record<string, unknown>;
|
|
96
|
+
/** The invoking context's `ctx.exports`, where Cloudflare exposes the declared agents (see `agent.asTool`). */
|
|
97
|
+
exports?: unknown;
|
|
54
98
|
/**
|
|
55
99
|
* Read the thread's synced state — dispatches the public owner-gated
|
|
56
100
|
* `agents:agentState` query through {@link AgentToolContext.run} (the same
|
|
@@ -67,6 +111,20 @@ interface AgentToolContext {
|
|
|
67
111
|
getState: () => Promise<Record<string, unknown> | undefined>;
|
|
68
112
|
/** Deterministic idempotency key — the tool's durable-step name. */
|
|
69
113
|
idempotencyKey: string;
|
|
114
|
+
/**
|
|
115
|
+
* The workflow instance (the run) this tool call belongs to. A provider-issued
|
|
116
|
+
* tool-call id can repeat across runs, so a secret request is claimed by this
|
|
117
|
+
* id, not by the call id alone.
|
|
118
|
+
*/
|
|
119
|
+
instanceId: string;
|
|
120
|
+
/**
|
|
121
|
+
* Verified owner of the thread this run belongs to (the loop copies it off
|
|
122
|
+
* {@link AgentRunInput.owner}); `undefined` on an anonymous/single-tenant
|
|
123
|
+
* thread. `agent.asTool` forwards it to the CHILD run, so a sub-agent thread
|
|
124
|
+
* under an owned parent inherits the same RLS scope instead of being created
|
|
125
|
+
* ownerless — which left it readable by anyone who knew its key.
|
|
126
|
+
*/
|
|
127
|
+
owner?: string;
|
|
70
128
|
/**
|
|
71
129
|
* Emit an EPHEMERAL progress event for this tool call on the agent's live
|
|
72
130
|
* channel — the same live-only sink the streamed token deltas ride. NOT
|
|
@@ -78,7 +136,10 @@ interface AgentToolContext {
|
|
|
78
136
|
* {@link AgentToolContext.toolCallId}. `data` must be JSON-serializable.
|
|
79
137
|
*/
|
|
80
138
|
reportProgress: (data: unknown) => void;
|
|
81
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* Dispatch a Lunora function (the workflow `ctx.run`). Calls go to the default
|
|
141
|
+
* shard unless they pass {@link AgentRunOptions.shardKey}.
|
|
142
|
+
*/
|
|
82
143
|
run: AgentRunFunction;
|
|
83
144
|
/**
|
|
84
145
|
* Replace the thread's synced state — dispatches the internal
|
|
@@ -102,11 +163,51 @@ interface AgentToolContext {
|
|
|
102
163
|
* skip the write when it is already present.
|
|
103
164
|
*/
|
|
104
165
|
setState: (state: Record<string, unknown>) => Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* The shard the run was started on ({@link AgentRunInput.shardKey}); `undefined`
|
|
168
|
+
* for the default shard. Pass it as {@link AgentRunOptions.shardKey} to reach the
|
|
169
|
+
* tenant's `.shardBy(...)` data from a hand-written tool.
|
|
170
|
+
*/
|
|
171
|
+
shardKey?: string;
|
|
172
|
+
/**
|
|
173
|
+
* The durable-step handle (`step.do`/`waitForEvent`). ALWAYS present:
|
|
174
|
+
* `agent-loop.ts` threads it into every tool's context unconditionally, and
|
|
175
|
+
* it is required rather than optional so a missing handle is a compile
|
|
176
|
+
* error instead of a silent durability downgrade. `codeTool` uses it to give
|
|
177
|
+
* each script step its OWN nested durable boundary — see `code-tool.ts` — so
|
|
178
|
+
* a failure at script step 3 retries only step 3, not steps 1–2's
|
|
179
|
+
* already-committed side effects. Cloudflare Workflows supports a `step.do`
|
|
180
|
+
* nested inside another `step.do`'s callback (the codeTool call's own
|
|
181
|
+
* enclosing step). Most tools never touch this directly; a test driving
|
|
182
|
+
* `execute`/`runToolScript` by hand passes a pass-through double.
|
|
183
|
+
*/
|
|
184
|
+
step: AgentStepLike;
|
|
105
185
|
/** The thread this tool call belongs to. */
|
|
106
186
|
threadKey: string;
|
|
107
187
|
/** The provider-issued tool-call id. */
|
|
108
188
|
toolCallId: string;
|
|
109
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* The view of {@link AgentToolContext} handed to a `needsApproval` gate
|
|
192
|
+
* function — every field except `setState`, `step`, and `reportProgress`.
|
|
193
|
+
*
|
|
194
|
+
* `setState` is dropped because a gate that mutates thread state is a side
|
|
195
|
+
* effect inside a decision predicate, and `reportProgress` because emitting a
|
|
196
|
+
* live event is the same thing in observable form — the decision is what the
|
|
197
|
+
* loop reports, not the deciding. `step` goes because the loop already runs the
|
|
198
|
+
* gate inside a durable step of its own, so a gate has no business opening
|
|
199
|
+
* another.
|
|
200
|
+
*
|
|
201
|
+
* `getState` and `run` stay: reads are legitimate gate inputs (gate on the
|
|
202
|
+
* caller's plan tier, on a spend total), and the gate resolves inside its own
|
|
203
|
+
* durable step, so they are replay-safe there. Note this makes the type a
|
|
204
|
+
* NARROWING, not a proof of purity — `run` takes any
|
|
205
|
+
* {@link AgentFunctionReference}, so a gate can still dispatch a mutation
|
|
206
|
+
* before approval. Nothing in the type system distinguishes a query reference
|
|
207
|
+
* from a mutation one; keeping the gate side-effect-free is the author's.
|
|
208
|
+
* @experimental
|
|
209
|
+
*/
|
|
210
|
+
type AgentApprovalContext = Omit<AgentToolContext, "reportProgress" | "setState" | "step">;
|
|
110
211
|
/**
|
|
111
212
|
* An agent tool. Unlike a raw AI SDK tool, `execute` is NOT handed to the
|
|
112
213
|
* model call — the loop runs it itself inside a named durable step so a
|
|
@@ -127,17 +228,35 @@ interface AgentToolDefinition<Input = unknown, Output = unknown> {
|
|
|
127
228
|
* Gate the tool behind a human approval (mirrors the AI SDK's
|
|
128
229
|
* `needsApproval`). When it resolves truthy the durable run PAUSES — the
|
|
129
230
|
* thread moves to `"awaiting_input"` and the workflow hibernates on
|
|
130
|
-
* `approval
|
|
231
|
+
* `approval:<toolCallId>` — until a client calls `agents:agentResolveApproval`.
|
|
131
232
|
* On approve the tool runs exactly as normal; on reject it is skipped and a
|
|
132
233
|
* tool result explaining the rejection is persisted so the next turn recovers.
|
|
133
234
|
* A boolean gates statically; a function gates per input. Default: `false`
|
|
134
|
-
* (unchanged behavior).
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
235
|
+
* (unchanged behavior).
|
|
236
|
+
*
|
|
237
|
+
* The boolean/`undefined` forms are compile-time constants re-derived
|
|
238
|
+
* identically on every replay — no durable step. The FUNCTION form runs
|
|
239
|
+
* inside its OWN durable step (`tool:approval-gate:<toolCallId>`, distinct
|
|
240
|
+
* from the tool's own step), so it now runs exactly once per call, not once
|
|
241
|
+
* per replay. It must still be otherwise pure: deterministic given its
|
|
242
|
+
* inputs (no `Date.now()`/`Math.random()`) and free of side effects — the
|
|
243
|
+
* context it receives is {@link AgentApprovalContext}, which has neither
|
|
244
|
+
* `setState` nor `reportProgress`; state writes and progress events belong
|
|
245
|
+
* only in `execute`, inside the tool's own memoized step. It still holds
|
|
246
|
+
* `run`, which the type cannot narrow to reads — see
|
|
247
|
+
* {@link AgentApprovalContext}.
|
|
248
|
+
*/
|
|
249
|
+
needsApproval?: ((input: Input, context: AgentApprovalContext) => boolean | Promise<boolean>) | boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Set by `requestSecretTool`. The loop never calls `execute` on such a tool: it
|
|
252
|
+
* pauses the run until a human supplies (or declines) a value and records
|
|
253
|
+
* `{ secretRef }` as the tool result, where `secretRef` is the request's
|
|
254
|
+
* slot, `<turn>:<tool-call id>`. The client answers the pause with the tool-call id it sees on it. `consumer` names the only tool
|
|
255
|
+
* that may read the value. The value never reaches the loop, the thread or the model.
|
|
139
256
|
*/
|
|
140
|
-
|
|
257
|
+
secretRequest?: {
|
|
258
|
+
consumer: string;
|
|
259
|
+
};
|
|
141
260
|
}
|
|
142
261
|
/**
|
|
143
262
|
* Author-supplied tool config (see {@link AgentToolDefinition}).
|
|
@@ -252,7 +371,7 @@ interface AgentMemoryOptions {
|
|
|
252
371
|
* (`key: "default"`) from {@link AgentConfig.memory}, then one per skill that
|
|
253
372
|
* carries `knowledge` (keyed by the skill's name). The key names the durable
|
|
254
373
|
* step — the default source keeps the historic `"memory:retrieve"`, a skill
|
|
255
|
-
* source uses `"memory:retrieve
|
|
374
|
+
* source uses `"memory:retrieve:<key>"` — so replay stays deterministic.
|
|
256
375
|
* @experimental
|
|
257
376
|
*/
|
|
258
377
|
interface AgentMemorySource extends AgentMemoryOptions {
|
|
@@ -260,14 +379,31 @@ interface AgentMemorySource extends AgentMemoryOptions {
|
|
|
260
379
|
key: string;
|
|
261
380
|
}
|
|
262
381
|
/**
|
|
263
|
-
* Cumulative or per-turn token usage — AI SDK `LanguageModelUsage` field names
|
|
382
|
+
* Cumulative or per-turn token usage — AI SDK `LanguageModelUsage` field names, plus
|
|
383
|
+
* the cache and reasoning breakdowns. The breakdowns are subsets of the totals they
|
|
384
|
+
* sit under (`cacheReadTokens` and `cacheWriteTokens` are part of `inputTokens`,
|
|
385
|
+
* `reasoningTokens` is part of `outputTokens`), so they are never added on top.
|
|
386
|
+
* Each is omitted when the provider reported none.
|
|
264
387
|
* @experimental
|
|
265
388
|
*/
|
|
266
389
|
interface AgentUsage {
|
|
267
|
-
/**
|
|
390
|
+
/** Input tokens served from the provider's prompt cache. */
|
|
391
|
+
cacheReadTokens?: number;
|
|
392
|
+
/** Input tokens written to the provider's prompt cache. */
|
|
393
|
+
cacheWriteTokens?: number;
|
|
394
|
+
/** Prompt (input) tokens, including any cache-read and cache-write tokens. */
|
|
268
395
|
inputTokens?: number;
|
|
269
|
-
/** Completion (output) tokens. */
|
|
396
|
+
/** Completion (output) tokens, including any reasoning tokens. */
|
|
270
397
|
outputTokens?: number;
|
|
398
|
+
/** Output tokens spent on hidden reasoning. */
|
|
399
|
+
reasoningTokens?: number;
|
|
400
|
+
/**
|
|
401
|
+
* Whether the provider's report covers every bucket it should carry: `complete` when all
|
|
402
|
+
* of it was reported, `partial` when some was, `unavailable` when none was. A run's total
|
|
403
|
+
* is `partial` as soon as one of its turns was not complete. Absent on a value written
|
|
404
|
+
* before this field existed; that row cannot say whether it was complete, so it reads as unknown.
|
|
405
|
+
*/
|
|
406
|
+
status?: "complete" | "partial" | "unavailable";
|
|
271
407
|
/** Input + output tokens. */
|
|
272
408
|
totalTokens?: number;
|
|
273
409
|
}
|
|
@@ -308,7 +444,7 @@ interface SkillConfig {
|
|
|
308
444
|
knowledge?: AgentMemoryOptions;
|
|
309
445
|
/**
|
|
310
446
|
* The skill's identifier — namespaces this skill's `knowledge` memory source
|
|
311
|
-
* (the durable step `memory:retrieve
|
|
447
|
+
* (the durable step `memory:retrieve:<name>`). Must be identifier-shaped.
|
|
312
448
|
*/
|
|
313
449
|
name: string;
|
|
314
450
|
/**
|
|
@@ -318,6 +454,12 @@ interface SkillConfig {
|
|
|
318
454
|
*/
|
|
319
455
|
tools?: Record<string, AnyAgentTool>;
|
|
320
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* The code-side parts of a markdown-authored skill — everything `SKILL.md`
|
|
459
|
+
* cannot carry. `name` and `instructions` come from the file itself.
|
|
460
|
+
* @experimental
|
|
461
|
+
*/
|
|
462
|
+
type SkillMarkdownExtras = Omit<SkillConfig, "instructions" | "name">;
|
|
321
463
|
/**
|
|
322
464
|
* A `defineSkill` result — config plus the brand the agent merge checks.
|
|
323
465
|
* @experimental
|
|
@@ -358,11 +500,43 @@ interface AgentStepFinishInfo {
|
|
|
358
500
|
}
|
|
359
501
|
/**
|
|
360
502
|
* Called after each LLM turn with that turn's text, tool calls, and usage. Runs
|
|
361
|
-
* inside a named durable step (`agent:step-finish
|
|
503
|
+
* inside a named durable step (`agent:step-finish:<turn>`) so it fires exactly
|
|
362
504
|
* once per turn even across a workflow replay.
|
|
363
505
|
* @experimental
|
|
364
506
|
*/
|
|
365
507
|
type AgentOnStepFinish = (info: AgentStepFinishInfo) => Promise<void> | void;
|
|
508
|
+
/**
|
|
509
|
+
* What {@link AgentConfig.onReply} is called with when a triggered run reaches
|
|
510
|
+
* its final answer.
|
|
511
|
+
* @experimental
|
|
512
|
+
*/
|
|
513
|
+
interface AgentReplyInfo {
|
|
514
|
+
/** The worker `env` — where an outbound credential (a bot token, a mailer binding) lives. */
|
|
515
|
+
env: Record<string, unknown>;
|
|
516
|
+
/** Where to reply, captured by the mapper that started this run. */
|
|
517
|
+
replyRef: AgentReplyRef;
|
|
518
|
+
/** The run's final answer. */
|
|
519
|
+
result: AgentRunResult;
|
|
520
|
+
/** The thread this run belongs to. */
|
|
521
|
+
threadKey: string;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Send a triggered run's answer back where it came from — the outbound half of
|
|
525
|
+
* an `onEmail` / `onInbound` trigger.
|
|
526
|
+
*
|
|
527
|
+
* Called once, automatically, when a run started with a `replyRef` produces a
|
|
528
|
+
* final answer; a run without one (an ordinary in-app `ctx.agents.<name>.run`)
|
|
529
|
+
* never calls it. It runs inside a named durable step, so a transient failure
|
|
530
|
+
* is retried and a workflow replay does not send the answer twice.
|
|
531
|
+
*
|
|
532
|
+
* Delivery is the app's call, because only the app has the credential: email
|
|
533
|
+
* has a home already (`replyToEmail(mailer, ref, body)` from
|
|
534
|
+
* `@lunora/agent/reply`), while Slack/GitHub/Discord bot tokens have no
|
|
535
|
+
* framework-owned store yet — read them from `info.env` and make the provider
|
|
536
|
+
* call.
|
|
537
|
+
* @experimental
|
|
538
|
+
*/
|
|
539
|
+
type AgentOnReply = (info: AgentReplyInfo) => Promise<void> | void;
|
|
366
540
|
/**
|
|
367
541
|
* The input {@link AgentConfig.prepareStep} sees before a turn runs.
|
|
368
542
|
* @experimental
|
|
@@ -404,6 +578,39 @@ type AgentPrepareStep = (input: AgentPrepareStepInput) => AgentPrepareStepResult
|
|
|
404
578
|
* start a run from an inbound email.
|
|
405
579
|
* @experimental
|
|
406
580
|
*/
|
|
581
|
+
/**
|
|
582
|
+
* Where a triggered run should send its answer back to — captured by the
|
|
583
|
+
* mapper, from fields the verified inbound payload already carries, and carried
|
|
584
|
+
* through the run so {@link AgentConfig.onReply} can answer in the same place
|
|
585
|
+
* the question was asked.
|
|
586
|
+
*
|
|
587
|
+
* A discriminated union rather than an opaque blob because each channel threads
|
|
588
|
+
* differently: email by RFC 5322 `In-Reply-To`/`References`, Slack by
|
|
589
|
+
* `thread_ts`, GitHub by issue number, Discord by channel (plus the triggering
|
|
590
|
+
* message for a true reply).
|
|
591
|
+
* @experimental
|
|
592
|
+
*/
|
|
593
|
+
type AgentReplyRef = {
|
|
594
|
+
channel: "discord";
|
|
595
|
+
channelId: string;
|
|
596
|
+
messageId?: string;
|
|
597
|
+
} | {
|
|
598
|
+
channel: "email";
|
|
599
|
+
from: string;
|
|
600
|
+
messageId: string;
|
|
601
|
+
references?: string;
|
|
602
|
+
to: string[];
|
|
603
|
+
} | {
|
|
604
|
+
channel: "github";
|
|
605
|
+
commentId?: number;
|
|
606
|
+
issueNumber: number;
|
|
607
|
+
owner: string;
|
|
608
|
+
repo: string;
|
|
609
|
+
} | {
|
|
610
|
+
channel: "slack";
|
|
611
|
+
channelId: string;
|
|
612
|
+
threadTs: string;
|
|
613
|
+
};
|
|
407
614
|
interface AgentEmailRun {
|
|
408
615
|
/** The user message that starts (or continues) the thread — the model's prompt. */
|
|
409
616
|
input: string;
|
|
@@ -414,6 +621,13 @@ interface AgentEmailRun {
|
|
|
414
621
|
* `email.from`.
|
|
415
622
|
*/
|
|
416
623
|
owner?: string;
|
|
624
|
+
/**
|
|
625
|
+
* Where to send the answer — see {@link AgentReplyRef}. Populate it from the
|
|
626
|
+
* event the mapper already has (`captureEmailReplyRef(email)` does it for
|
|
627
|
+
* email) and the run calls {@link AgentConfig.onReply} with it once the
|
|
628
|
+
* final answer is ready. Omit it and the run simply never replies.
|
|
629
|
+
*/
|
|
630
|
+
replyRef?: AgentReplyRef;
|
|
417
631
|
/** The thread key — reuse to continue a conversation (e.g. a ticket id parsed from the subject). */
|
|
418
632
|
threadKey: string;
|
|
419
633
|
/** Optional thread title, set on first creation. */
|
|
@@ -432,6 +646,53 @@ interface AgentEmailRun {
|
|
|
432
646
|
* @experimental
|
|
433
647
|
*/
|
|
434
648
|
type AgentEmailMapper = (email: InboundEmail) => AgentEmailRun | null | Promise<AgentEmailRun | null | undefined> | undefined;
|
|
649
|
+
/**
|
|
650
|
+
* Pick the shard an inbound-triggered run's tools use: the app maps a verified identity
|
|
651
|
+
* to a tenant shard. Return `undefined` for the default shard.
|
|
652
|
+
*
|
|
653
|
+
* This is the only way an inbound run gets a shard. A `shardKey` in the mapped run is
|
|
654
|
+
* dropped, because the mapper's output is built from attacker-written content. The hook
|
|
655
|
+
* runs after the sender or signature gate and after the mapper claimed the message, and
|
|
656
|
+
* it is handed only what the platform verified ({@link AgentEmailShardInput},
|
|
657
|
+
* {@link AgentChannelShardInput}). Returning a shard is an authorization decision, since
|
|
658
|
+
* the run's tools dispatch past `authorizeShard`: look the identity up in a table you
|
|
659
|
+
* trust. A throw fails the delivery rather than falling back to the default shard.
|
|
660
|
+
* @experimental
|
|
661
|
+
*/
|
|
662
|
+
type AgentInboundShardResolver<Input> = (input: Input) => Promise<string | undefined> | string | undefined;
|
|
663
|
+
/**
|
|
664
|
+
* What `resolveEmailShard` gets.
|
|
665
|
+
* @experimental
|
|
666
|
+
*/
|
|
667
|
+
interface AgentEmailShardInput {
|
|
668
|
+
/**
|
|
669
|
+
* The parsed message, for context only. Its headers are sender-written: `email.to`
|
|
670
|
+
* is the `To:` header, which any sender can set to another tenant's address, and
|
|
671
|
+
* `email.from` is only as good as the authentication verdicts. Never derive the
|
|
672
|
+
* shard from it.
|
|
673
|
+
*/
|
|
674
|
+
email: InboundEmail;
|
|
675
|
+
/**
|
|
676
|
+
* The SMTP envelope recipient Cloudflare Email Routing delivered this message to.
|
|
677
|
+
* Routing only delivers to addresses you configured, so this is the field to map
|
|
678
|
+
* to a tenant.
|
|
679
|
+
*/
|
|
680
|
+
envelopeTo: string;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* What `onInbound.resolveShard` gets: the channel and the workspace the signed payload
|
|
684
|
+
* belongs to, never the event's message content.
|
|
685
|
+
* @experimental
|
|
686
|
+
*/
|
|
687
|
+
interface AgentChannelShardInput {
|
|
688
|
+
channel: AgentInboundChannelKind;
|
|
689
|
+
/**
|
|
690
|
+
* The provider-set tenant id from the signature-verified body: Slack `team_id`,
|
|
691
|
+
* GitHub `installation.id`, Discord `guild_id`. `undefined` when the payload carries
|
|
692
|
+
* none (a DM interaction, a GitHub event outside an app installation).
|
|
693
|
+
*/
|
|
694
|
+
workspaceId: string | undefined;
|
|
695
|
+
}
|
|
435
696
|
/** The inbound webhook channels an agent can be triggered from — see `@lunora/agent/channels`. */
|
|
436
697
|
type AgentInboundChannelKind = "discord" | "github" | "slack";
|
|
437
698
|
/** The run-input an inbound-channel mapper returns — the same shape as {@link AgentEmailRun}. */
|
|
@@ -470,6 +731,8 @@ interface AgentInboundChannel {
|
|
|
470
731
|
channel: AgentInboundChannelKind;
|
|
471
732
|
/** Map a verified event to a run (or `null` to decline). */
|
|
472
733
|
map: AgentChannelMapper;
|
|
734
|
+
/** The shard a claimed event's run uses — see {@link AgentInboundShardResolver}. Default shard when absent. */
|
|
735
|
+
resolveShard?: AgentInboundShardResolver<AgentChannelShardInput>;
|
|
473
736
|
/**
|
|
474
737
|
* The verification credential, from `env`: an env-var NAME (string) or an
|
|
475
738
|
* `(env) => value` resolver. Slack → signing secret; GitHub → webhook secret;
|
|
@@ -484,6 +747,22 @@ interface AgentInboundChannel {
|
|
|
484
747
|
interface AgentConfig {
|
|
485
748
|
/** Restrict the tools the model may call, by name. Default: all tools. */
|
|
486
749
|
activeTools?: ReadonlyArray<string>;
|
|
750
|
+
/**
|
|
751
|
+
* How long a human-in-the-loop tool approval may stay pending before the
|
|
752
|
+
* run stops waiting — a Cloudflare Workflows duration: milliseconds, or a
|
|
753
|
+
* `"<n> <unit>"` string like `"3 days"` (the unit set is the host's, so a
|
|
754
|
+
* typo is a compile error). Default `"3 days"`.
|
|
755
|
+
*
|
|
756
|
+
* On timeout the call is treated as REJECTED (the run records why and
|
|
757
|
+
* continues down the normal rejection path), so a run whose approver never
|
|
758
|
+
* answers ends instead of hibernating forever.
|
|
759
|
+
*
|
|
760
|
+
* CLAMPED to one week. A longer wait would outlive the thread's
|
|
761
|
+
* abandoned-run horizon, letting a new run reclaim the thread while the
|
|
762
|
+
* approval is still pending — which is the exact failure this timeout
|
|
763
|
+
* exists to prevent, so it cannot be configured back into existence.
|
|
764
|
+
*/
|
|
765
|
+
approvalTimeout?: `${number} ${"day" | "hour" | "minute" | "month" | "second" | "week" | "year"}${"s" | ""}` | number;
|
|
487
766
|
/**
|
|
488
767
|
* Automatic thread-history compaction. When the persisted history exceeds
|
|
489
768
|
* `maxMessages`, the loop summarizes the older messages (all but the most
|
|
@@ -530,9 +809,9 @@ interface AgentConfig {
|
|
|
530
809
|
model: AgentModelInput;
|
|
531
810
|
/**
|
|
532
811
|
* Optional override for the deployed workflow name (`wrangler.jsonc`
|
|
533
|
-
* `workflows[].name`). Defaults to `agent
|
|
812
|
+
* `workflows[].name`). Defaults to `agent-<kebab-cased export name>`. Does
|
|
534
813
|
* NOT change the binding name, which is always derived from the export
|
|
535
|
-
* name (`support` → `
|
|
814
|
+
* name (`support` → `SupportAgentWorkflow`).
|
|
536
815
|
*/
|
|
537
816
|
name?: string;
|
|
538
817
|
/**
|
|
@@ -543,7 +822,16 @@ interface AgentConfig {
|
|
|
543
822
|
*
|
|
544
823
|
* - `"reject"` (default) — fail the new run fast with a `CONFLICT` error.
|
|
545
824
|
* - `"replace"` — terminate the in-flight instance and take the thread over.
|
|
546
|
-
* - `"queue"` —
|
|
825
|
+
* - `"queue"` — park the new run behind the one in flight (FIFO, up to five deep) and hibernate it until the thread is handed over.
|
|
826
|
+
*
|
|
827
|
+
* Each parked run is a live workflow instance waiting on an event, so the
|
|
828
|
+
* queue's depth cap is a real resource bound: past it, a start is rejected
|
|
829
|
+
* exactly as `"reject"` would. A `"replace"` arriving later supersedes the
|
|
830
|
+
* run in FLIGHT, not the queue — parked runs still take their turn after it.
|
|
831
|
+
*
|
|
832
|
+
* A dispatch with no instance id (the inbound-email / inbound-channel
|
|
833
|
+
* paths) cannot be parked, because nothing later can tell it apart from
|
|
834
|
+
* another such dispatch to wake it; `"queue"` rejects those.
|
|
547
835
|
*
|
|
548
836
|
* A workflow REPLAY re-enters the bootstrap under the SAME instance id and
|
|
549
837
|
* is never a concurrent run (the guard compares the stored instance id).
|
|
@@ -563,6 +851,12 @@ interface AgentConfig {
|
|
|
563
851
|
* signature over the raw body before calling `map`.
|
|
564
852
|
*/
|
|
565
853
|
onInbound?: AgentInboundChannel;
|
|
854
|
+
/**
|
|
855
|
+
* Called with the final answer when the run was triggered from a channel
|
|
856
|
+
* that gave it a `replyRef` — see {@link AgentOnReply}. This is how an
|
|
857
|
+
* inbound-triggered agent answers where it was asked.
|
|
858
|
+
*/
|
|
859
|
+
onReply?: AgentOnReply;
|
|
566
860
|
/** Called after each LLM turn — see {@link AgentOnStepFinish}. */
|
|
567
861
|
onStepFinish?: AgentOnStepFinish;
|
|
568
862
|
/**
|
|
@@ -577,7 +871,7 @@ interface AgentConfig {
|
|
|
577
871
|
* Opt this agent into being STARTED over the public RPC boundary — i.e. via
|
|
578
872
|
* the auto-registered `agents:agentRun` mutation an HTTP-only client (e.g.
|
|
579
873
|
* the `@lunora/mcp` server) calls. Default `false`: an agent is startable
|
|
580
|
-
* only from server-side app code (`ctx.agents
|
|
874
|
+
* only from server-side app code (`ctx.agents.<name>.run(...)`), so declaring
|
|
581
875
|
* an agent does NOT expose it to arbitrary RPC callers. Fail-closed — the run
|
|
582
876
|
* mutation refuses an agent that has not opted in, regardless of any MCP-side
|
|
583
877
|
* `allowAgents` configuration. A started thread is still owner-scoped to
|
|
@@ -594,6 +888,12 @@ interface AgentConfig {
|
|
|
594
888
|
* unknown-tool-name recovery as the only repair path.
|
|
595
889
|
*/
|
|
596
890
|
repairToolCall?: ToolCallRepairFunction<ToolSet>;
|
|
891
|
+
/**
|
|
892
|
+
* The shard an `onEmail` run's tools use — see {@link AgentInboundShardResolver}. Map
|
|
893
|
+
* `envelopeTo`, the routed recipient; the parsed headers are sender-written. Default
|
|
894
|
+
* shard when absent.
|
|
895
|
+
*/
|
|
896
|
+
resolveEmailShard?: AgentInboundShardResolver<AgentEmailShardInput>;
|
|
597
897
|
/**
|
|
598
898
|
* Reusable {@link SkillDefinition}s to compose in — each contributes an
|
|
599
899
|
* instruction fragment, tools (merged into the flat namespace; collisions
|
|
@@ -649,8 +949,20 @@ interface AgentVoiceConfig {
|
|
|
649
949
|
/**
|
|
650
950
|
* Spoken on connect before the first user turn — a fixed greeting synthesized
|
|
651
951
|
* through the TTS model. Omit for a silent-until-spoken-to session.
|
|
952
|
+
*
|
|
953
|
+
* Synthesized once per THREAD, not once per socket: the greeting's persisted
|
|
954
|
+
* row is keyed per thread, and a reconnect onto a thread that already exists
|
|
955
|
+
* gets the `ready` frame without paying for the same line again.
|
|
652
956
|
*/
|
|
653
957
|
greeting?: string;
|
|
958
|
+
/**
|
|
959
|
+
* Cap on how many turns one voice socket may run before it is closed with
|
|
960
|
+
* code `4002`. Every turn is a full LLM generation plus sentence-by-sentence
|
|
961
|
+
* TTS — billed and persisted — on a hibernatable socket that can live for
|
|
962
|
+
* days, and the one-turn-in-flight guard throttles nothing. Defaults to 100;
|
|
963
|
+
* a client that hits the cap reconnects for a fresh budget.
|
|
964
|
+
*/
|
|
965
|
+
maxTurns?: number;
|
|
654
966
|
/**
|
|
655
967
|
* TTS voice/speaker id forwarded to the TTS model (e.g. a Deepgram Aura voice
|
|
656
968
|
* like `"aura-asteria-en"`). Model-specific; omitted when unset so the model
|
|
@@ -685,11 +997,11 @@ interface AgentSubToolInput {
|
|
|
685
997
|
interface AgentAsToolOptions {
|
|
686
998
|
/** What the sub-agent does — shown to the parent's model (it decides from it). */
|
|
687
999
|
description: string;
|
|
688
|
-
/** Cap on child-run status polls before giving up. Default
|
|
1000
|
+
/** Cap on child-run status polls before giving up — a positive integer. Default 600 (with the 500 ms default interval, a five-minute budget). */
|
|
689
1001
|
maxPolls?: number;
|
|
690
1002
|
/**
|
|
691
|
-
* The child agent's export name — selects its `AGENT_
|
|
692
|
-
*
|
|
1003
|
+
* The child agent's export name — selects its `AGENT_<NAME>` Workflow
|
|
1004
|
+
* export key (e.g. `"researcher"` → `ResearcherAgentWorkflow`). The model-facing tool
|
|
693
1005
|
* name is the KEY assigned in the parent's `tools` map, not this.
|
|
694
1006
|
*/
|
|
695
1007
|
name: string;
|
|
@@ -725,11 +1037,43 @@ interface AgentDefinition extends AgentConfig {
|
|
|
725
1037
|
*/
|
|
726
1038
|
memorySources?: ReadonlyArray<AgentMemorySource>;
|
|
727
1039
|
}
|
|
1040
|
+
/**
|
|
1041
|
+
* What `agentEnsureThread` reports back to the loop.
|
|
1042
|
+
*
|
|
1043
|
+
* A discriminated union rather than a bag of optional booleans: the outcomes are
|
|
1044
|
+
* mutually exclusive, and the data each carries only exists for its own case.
|
|
1045
|
+
* `queued` has a position, `replaced` has the instance it took the thread from,
|
|
1046
|
+
* and the rest have nothing — encoding that as independent optional fields made
|
|
1047
|
+
* every reader re-derive which combination was legal.
|
|
1048
|
+
*
|
|
1049
|
+
* `completed` is the odd one: the thread was NOT (re)opened. This run already
|
|
1050
|
+
* reported its outcome and is replaying because only the reply was lost, so it
|
|
1051
|
+
* takes no ownership and revives nothing — it runs its body out of the step
|
|
1052
|
+
* journal to re-dispatch the effects that never landed.
|
|
1053
|
+
* @experimental
|
|
1054
|
+
*/
|
|
1055
|
+
type EnsureThreadOutcome = {
|
|
1056
|
+
outcome: "completed" | "continued" | "created";
|
|
1057
|
+
} | {
|
|
1058
|
+
outcome: "queued";
|
|
1059
|
+
position: number;
|
|
1060
|
+
} | {
|
|
1061
|
+
outcome: "replaced";
|
|
1062
|
+
priorInstanceId: string;
|
|
1063
|
+
};
|
|
728
1064
|
/**
|
|
729
1065
|
* Params of one agent run (the compiled workflow's payload).
|
|
730
1066
|
* @experimental
|
|
731
1067
|
*/
|
|
732
1068
|
interface AgentRunInput {
|
|
1069
|
+
/**
|
|
1070
|
+
* Sub-agent delegation depth. A run a user starts omits it (0); each
|
|
1071
|
+
* `agent.asTool` hop stamps its child one deeper, and the tool refuses to
|
|
1072
|
+
* delegate past the bound — `maxTurns` bounds one level's turns, this bounds
|
|
1073
|
+
* the TREE (every hop mints a distinct child `threadKey`, so the per-thread
|
|
1074
|
+
* run-queue cap never applies across them).
|
|
1075
|
+
*/
|
|
1076
|
+
depth?: number;
|
|
733
1077
|
/** The user message that starts (or continues) the thread. */
|
|
734
1078
|
input: string;
|
|
735
1079
|
/**
|
|
@@ -741,6 +1085,16 @@ interface AgentRunInput {
|
|
|
741
1085
|
* the first run.
|
|
742
1086
|
*/
|
|
743
1087
|
owner?: string;
|
|
1088
|
+
/** Where a triggered run sends its answer — see {@link AgentReplyRef}. */
|
|
1089
|
+
replyRef?: AgentReplyRef;
|
|
1090
|
+
/**
|
|
1091
|
+
* The shard whose app data the run's tools read and write. Set only by the boundary
|
|
1092
|
+
* that starts the run, from a source it trusts: `ctx.agents.<name>.run` uses the
|
|
1093
|
+
* shard of the mutation or action that calls it, a scheduled run the scheduling
|
|
1094
|
+
* shard, an inbound run the app's `resolveEmailShard` / `resolveShard` hook. A
|
|
1095
|
+
* value in the input is always overwritten, since the input may be a client's.
|
|
1096
|
+
*/
|
|
1097
|
+
shardKey?: string;
|
|
744
1098
|
/** The thread key — reuse to continue a conversation. */
|
|
745
1099
|
threadKey: string;
|
|
746
1100
|
/** Optional thread title, set on first creation. */
|
|
@@ -773,6 +1127,24 @@ interface AgentRunResult {
|
|
|
773
1127
|
*/
|
|
774
1128
|
interface AgentFunctionPaths {
|
|
775
1129
|
appendMessage: string;
|
|
1130
|
+
/**
|
|
1131
|
+
* The internal `agents:agentApprovalGranted` query the loop dispatches from
|
|
1132
|
+
* inside a tool's approval-gate step: whether the tool is granted for the thread.
|
|
1133
|
+
*/
|
|
1134
|
+
approvalGranted: string;
|
|
1135
|
+
/**
|
|
1136
|
+
* The internal `agents:agentCompleteRun` mutation the loop dispatches at the
|
|
1137
|
+
* end of a run: it writes the terminal status AND hands the thread to the
|
|
1138
|
+
* next queued run in the same mutation.
|
|
1139
|
+
*/
|
|
1140
|
+
completeRun: string;
|
|
1141
|
+
/**
|
|
1142
|
+
* The internal `agents:agentDeleteMessage` mutation the loop dispatches to
|
|
1143
|
+
* retire the HITL approval marker once the decision has landed.
|
|
1144
|
+
*/
|
|
1145
|
+
deleteMessage: string;
|
|
1146
|
+
/** The internal `agents:agentDiscardSecret` mutation a secret-consuming tool dispatches after it has used the value. */
|
|
1147
|
+
discardSecret: string;
|
|
776
1148
|
ensureThread: string;
|
|
777
1149
|
/** The internal `agents:agentEpisodeRecall` query the loop dispatches for an episodic-kind read. */
|
|
778
1150
|
episodeRecall: string;
|
|
@@ -782,7 +1154,14 @@ interface AgentFunctionPaths {
|
|
|
782
1154
|
graphTraverse: string;
|
|
783
1155
|
/** The internal `agents:agentGraphUpsert` mutation the loop dispatches on run-end graph extraction. */
|
|
784
1156
|
graphUpsert: string;
|
|
1157
|
+
/**
|
|
1158
|
+
* The internal `agents:agentHistory` query the loop dispatches for a compacting
|
|
1159
|
+
* turn: the stored running summary plus only the messages it does not yet cover.
|
|
1160
|
+
*/
|
|
1161
|
+
history: string;
|
|
785
1162
|
listMessages: string;
|
|
1163
|
+
/** The internal `agents:agentOpenSecretRequest` mutation that writes the pending request row when a run pauses. */
|
|
1164
|
+
openSecretRequest: string;
|
|
786
1165
|
patchThread: string;
|
|
787
1166
|
/**
|
|
788
1167
|
* The public `agents:agentRun` mutation an HTTP-only client (e.g. the
|
|
@@ -792,22 +1171,29 @@ interface AgentFunctionPaths {
|
|
|
792
1171
|
run: string;
|
|
793
1172
|
/** The internal `agents:agentSetState` mutation the loop dispatches for `setState`. */
|
|
794
1173
|
setState: string;
|
|
1174
|
+
/** The internal `agents:agentSettleSecretRequest` mutation that reads a paused request's outcome once its wait ends. */
|
|
1175
|
+
settleSecretRequest: string;
|
|
795
1176
|
/** The public owner-gated `agents:agentState` query (`getState` + `useAgentState`). */
|
|
796
1177
|
state: string;
|
|
1178
|
+
/** The internal `agents:agentTakeSecret` mutation a secret-consuming tool dispatches to read a supplied value. */
|
|
1179
|
+
takeSecret: string;
|
|
797
1180
|
}
|
|
798
1181
|
/**
|
|
799
1182
|
* Approval lifecycle marker on a message: `"awaiting_approval"` on the
|
|
800
1183
|
* placeholder written while a run pauses on a gated tool, then `"approved"` /
|
|
801
|
-
* `"rejected"` on the tool result once a client resolves it.
|
|
802
|
-
*
|
|
1184
|
+
* `"rejected"` on the tool result once a client resolves it. `"awaiting_secret"`
|
|
1185
|
+
* is the same pause for a {@link AgentToolDefinition.secretRequest} tool. Absent
|
|
1186
|
+
* on ordinary messages. Both pause markers are filtered out of the model prompt.
|
|
803
1187
|
* @experimental
|
|
804
1188
|
*/
|
|
805
|
-
type AgentMessageStatus = "approved" | "awaiting_approval" | "rejected";
|
|
1189
|
+
type AgentMessageStatus = "approved" | "awaiting_approval" | "awaiting_secret" | "rejected";
|
|
806
1190
|
/**
|
|
807
1191
|
* One persisted thread message, as the loop reads it back.
|
|
808
1192
|
* @experimental
|
|
809
1193
|
*/
|
|
810
1194
|
interface AgentMessageRow {
|
|
1195
|
+
/** On an approved tool result: `"thread"` when the approval also granted the tool for the rest of the thread. */
|
|
1196
|
+
approvalScope?: "thread";
|
|
811
1197
|
content: string;
|
|
812
1198
|
role: "assistant" | "system" | "tool" | "user";
|
|
813
1199
|
seq: number;
|
|
@@ -824,6 +1210,14 @@ interface AgentMessageRow {
|
|
|
824
1210
|
interface AgentToolCall {
|
|
825
1211
|
id: string;
|
|
826
1212
|
input: unknown;
|
|
1213
|
+
/**
|
|
1214
|
+
* Why this call was REJECTED before it could run: the model's arguments
|
|
1215
|
+
* failed the tool's input schema, or did not parse as JSON. Present only on
|
|
1216
|
+
* a rejected call — the loop records it as a recoverable tool result and
|
|
1217
|
+
* never executes the tool, because the `input` above is the raw value the
|
|
1218
|
+
* provider sent, not a validated one.
|
|
1219
|
+
*/
|
|
1220
|
+
invalid?: string;
|
|
827
1221
|
name: string;
|
|
828
1222
|
}
|
|
829
1223
|
/**
|
|
@@ -916,6 +1310,12 @@ type AgentCompact = (input: {
|
|
|
916
1310
|
messages: ModelMessage[];
|
|
917
1311
|
/** The compaction model (the config's `model`, else the agent's). */
|
|
918
1312
|
model: AgentModelInput;
|
|
1313
|
+
/**
|
|
1314
|
+
* The previous brief being folded into, when this is an incremental update.
|
|
1315
|
+
* A seam MUST merge it rather than summarise only the new messages, or facts
|
|
1316
|
+
* from earlier turns are lost until the next from-scratch rebuild.
|
|
1317
|
+
*/
|
|
1318
|
+
previousSummary?: string;
|
|
919
1319
|
}) => Promise<string>;
|
|
920
1320
|
/** The one-line summary an episodic-memory run records for later recency recall. */
|
|
921
1321
|
interface AgentEpisodeExtraction {
|
|
@@ -1018,11 +1418,12 @@ type AgentTokenSink = (event: AgentLiveEvent) => void;
|
|
|
1018
1418
|
*/
|
|
1019
1419
|
type AgentStreamGenerate = (options: AgentGenerateOptions, onDelta: (text: string) => void) => Promise<AgentGenerateResult>;
|
|
1020
1420
|
/**
|
|
1021
|
-
* Spec entry codegen emits per agent: `{
|
|
1421
|
+
* Spec entry codegen emits per agent: `{ className: "SupportAgentWorkflow", exportName: "support" }`.
|
|
1022
1422
|
* @experimental
|
|
1023
1423
|
*/
|
|
1024
1424
|
interface AgentBindingSpec {
|
|
1025
|
-
|
|
1425
|
+
/** The agent's export key — its generated class name, e.g. `SupportAgentWorkflow`. */
|
|
1426
|
+
className: string;
|
|
1026
1427
|
exportName: string;
|
|
1027
1428
|
/**
|
|
1028
1429
|
* Whether the app author opted this agent into public run-starts (via
|
|
@@ -1078,7 +1479,7 @@ interface AgentRunHandle {
|
|
|
1078
1479
|
id: string;
|
|
1079
1480
|
}
|
|
1080
1481
|
/**
|
|
1081
|
-
* The `ctx.agents
|
|
1482
|
+
* The `ctx.agents.<name>` producer handle.
|
|
1082
1483
|
* @experimental
|
|
1083
1484
|
*/
|
|
1084
1485
|
interface AgentHandle {
|
|
@@ -1111,4 +1512,4 @@ interface AgentHandle {
|
|
|
1111
1512
|
/** Read a run's workflow status by instance id. */
|
|
1112
1513
|
status: (id: string) => Promise<unknown>;
|
|
1113
1514
|
}
|
|
1114
|
-
export { AgentDefinition as A,
|
|
1515
|
+
export { AgentToolCall as $, AgentDefinition as A, AgentEmailRun as B, AgentEmailShardInput as C, AgentGenerateOptions as D, AgentGenerateResult as E, AgentHandle as F, AgentInboundShardResolver as G, AgentInstructionsContext as H, InboundChannelEvent as I, AgentLiveEvent as J, AgentMemoryOptions as K, AgentMemorySource as L, AgentMessageStatus as M, AgentOnReply as N, AgentOnStepFinish as O, AgentPrepareStep as P, AgentPrepareStepInput as Q, AgentPrepareStepResult as R, SkillMarkdownExtras as S, AgentProgressEvent as T, AgentReplyInfo as U, AgentRunHandle as V, AgentRunOptions as W, AgentStepFinishInfo as X, AgentStepInfo as Y, AgentThreadStatus as Z, AgentTokenDelta as _, AgentReplyRef as a, AgentToolConfig as a0, AgentUsage as a1, AgentVoiceConfig as a2, AgentWorkflowBindingLike as a3, AgentWorkflowInstanceLike as a4, EnsureThreadOutcome as a5, SkillConfig as a6, SkillDefinition as b, AgentToolDefinition as c, AgentToolContext as d, AgentCompact as e, AgentEpisodeExtract as f, AgentGraphExtract as g, AgentGenerate as h, AgentTokenSink as i, AgentRunInput as j, AgentFunctionPaths as k, AgentRunFunction as l, AgentStepLike as m, AgentStreamGenerate as n, AgentRunResult as o, AgentMessageRow as p, AgentConfig as q, AnyAgentTool as r, AgentAsToolOptions as s, AgentSubToolInput as t, AgentModelInput as u, AgentFunctionReference as v, AgentApprovalContext as w, AgentBindingSpec as x, AgentChannelShardInput as y, AgentEmailMapper as z };
|