@lunora/agent 1.0.0-alpha.26 → 1.0.0-alpha.261
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/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/inbound.d.mts +9 -7
- package/dist/inbound.d.ts +9 -7
- package/dist/inbound.mjs +1 -1
- package/dist/index.d.mts +207 -18
- package/dist/index.d.ts +207 -18
- 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_shared/AGENT_MODULE-CYBmT9SD.mjs +1 -0
- package/dist/packem_shared/DEFAULT_DISPATCH_TIMEOUT_MS-DiRHEqJU-CE08SIwv.mjs +1 -0
- package/dist/packem_shared/SecretUnavailableError-BCp40Leh.mjs +1 -0
- package/dist/packem_shared/VoiceSessionDO-REut3oqY.mjs +1 -0
- package/dist/packem_shared/adaptMcpResult-DFF_g58r.mjs +2 -0
- package/dist/packem_shared/agent-ai-CP87uSoZ.mjs +1 -0
- package/dist/packem_shared/agent-loop-BgOHoyg_.mjs +3 -0
- package/dist/packem_shared/agentAsTool-CA7Sha2i.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-Hm_Af6t4.mjs +1 -0
- package/dist/packem_shared/collectAgenticMemoryTools-BWdIhOfY.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-yYM18j57.mjs +1 -0
- package/dist/packem_shared/component-shared-DdXFbng-.mjs +1 -0
- package/dist/packem_shared/consoleTelemetry-Cl-WQEsZ.mjs +1 -0
- package/dist/packem_shared/createAgentContext-CqF7NfUY.mjs +1 -0
- package/dist/packem_shared/createAgentGenerate-DSLXAeY2.mjs +3 -0
- package/dist/packem_shared/defineAgent-D7wY7Jl3.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-C95ns65V.mjs +1 -0
- package/dist/packem_shared/in-flight-calls-C9QGq8uH.mjs +1 -0
- package/dist/packem_shared/jsCodeTool-CIlCK1bG.mjs +18 -0
- package/dist/packem_shared/normalizeEntityName-Rr5OQxhc.mjs +2 -0
- package/dist/packem_shared/otlpTelemetry-CiSI9HE_.mjs +1 -0
- package/dist/packem_shared/positive-integer-ztHqqpBk.mjs +1 -0
- package/dist/packem_shared/runAgentLoop-CoQUnwKs.mjs +1 -0
- package/dist/packem_shared/runVoiceTurn-BpC_9Mm3.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-vAmttAsE.d.mts} +355 -33
- package/dist/packem_shared/{types.d-boAM2Yi1.d.ts → types.d-vAmttAsE.d.ts} +355 -33
- package/dist/packem_shared/voice-turn-hIZ7r1ST.mjs +1 -0
- package/dist/packem_shared/webSearchTool-BobmV4cD.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 +157 -16
- package/dist/sandbox.d.ts +157 -16
- 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 +20 -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,33 @@ 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
|
+
* Abort the dispatch after this many ms, overriding the runner's 30s
|
|
21
|
+
* default (`DEFAULT_DISPATCH_TIMEOUT_MS`).
|
|
22
|
+
*
|
|
23
|
+
* Load-bearing for any tool whose target legitimately runs longer than
|
|
24
|
+
* that. A dispatch timeout answers 503, which is NOT a deterministic
|
|
25
|
+
* dispatch failure, so the tool's `step.do` rethrows and the host retries
|
|
26
|
+
* the step — dispatching the same call again while the FIRST one is still
|
|
27
|
+
* running. For a side-effecting target (a container command, a billed page
|
|
28
|
+
* render) that is a second execution, not a second attempt. Set this at
|
|
29
|
+
* least as wide as the target's own budget, and give the target an inner
|
|
30
|
+
* deadline strictly under it so the target aborts itself first.
|
|
31
|
+
*/
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
}
|
|
12
34
|
/**
|
|
13
35
|
* `ctx.run`-shaped dispatcher the loop uses to call Lunora functions.
|
|
14
36
|
* @experimental
|
|
15
37
|
*/
|
|
16
|
-
type AgentRunFunction = (reference: AgentFunctionReference, args?: Record<string, unknown
|
|
38
|
+
type AgentRunFunction = (reference: AgentFunctionReference, args?: Record<string, unknown>, options?: AgentRunOptions) => Promise<unknown>;
|
|
17
39
|
/**
|
|
18
40
|
* Structural subset of the Cloudflare Workflows durable-step API the loop needs.
|
|
19
41
|
* @experimental
|
|
@@ -23,7 +45,7 @@ interface AgentStepLike {
|
|
|
23
45
|
/**
|
|
24
46
|
* Durably hibernate until an external event of `type` arrives, then return
|
|
25
47
|
* its payload. Used for human-in-the-loop approvals: a run pauses on
|
|
26
|
-
* `approval
|
|
48
|
+
* `approval:<toolCallId>` until a client resolves it. Like `do`, a resolved
|
|
27
49
|
* wait is memoized — a replay returns the recorded decision without pausing
|
|
28
50
|
* again. Signature mirrors `@lunora/workflow`'s `WorkflowStepLike`.
|
|
29
51
|
*/
|
|
@@ -42,15 +64,30 @@ interface AgentStepLike {
|
|
|
42
64
|
* `idempotencyKey`.
|
|
43
65
|
*
|
|
44
66
|
* The `idempotencyKey` is the deterministic durable-step name
|
|
45
|
-
* (`tool
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
67
|
+
* (`tool:<name>:<toolCallId>`, further suffixed per script step for a
|
|
68
|
+
* `codeTool`). A COMPLETED tool step is never re-run on a workflow replay
|
|
69
|
+
* (native step memoization) — but a step that FAILS mid-body is retried
|
|
70
|
+
* at-least-once, so a side-effecting tool (charge a card, send a mail) must
|
|
71
|
+
* dedupe on this key itself. `functionTool` forwards it to the dispatched
|
|
72
|
+
* function as `args.idempotencyKey` (pinned after the model input, so it
|
|
73
|
+
* can't be overridden) — a function that wants to dedupe declares
|
|
74
|
+
* `idempotencyKey: v.optional(v.string())` in its own args and checks it; a
|
|
75
|
+
* function that ignores it is unaffected (an undeclared arg field is dropped,
|
|
76
|
+
* not rejected).
|
|
49
77
|
* @experimental
|
|
50
78
|
*/
|
|
51
79
|
interface AgentToolContext {
|
|
80
|
+
/**
|
|
81
|
+
* How many sub-agent delegations deep this run already is — 0 for a run a
|
|
82
|
+
* user started, one more per `agent.asTool` hop. The loop copies it off
|
|
83
|
+
* {@link AgentRunInput.depth}; `agent.asTool` reads it to refuse spawning a
|
|
84
|
+
* child past the delegation-depth bound (see `as-tool.ts`). Absent is 0.
|
|
85
|
+
*/
|
|
86
|
+
depth?: number;
|
|
52
87
|
/** The Worker environment bindings. */
|
|
53
88
|
env: Record<string, unknown>;
|
|
89
|
+
/** The invoking context's `ctx.exports`, where Cloudflare exposes the declared agents (see `agent.asTool`). */
|
|
90
|
+
exports?: unknown;
|
|
54
91
|
/**
|
|
55
92
|
* Read the thread's synced state — dispatches the public owner-gated
|
|
56
93
|
* `agents:agentState` query through {@link AgentToolContext.run} (the same
|
|
@@ -67,6 +104,20 @@ interface AgentToolContext {
|
|
|
67
104
|
getState: () => Promise<Record<string, unknown> | undefined>;
|
|
68
105
|
/** Deterministic idempotency key — the tool's durable-step name. */
|
|
69
106
|
idempotencyKey: string;
|
|
107
|
+
/**
|
|
108
|
+
* The workflow instance (the run) this tool call belongs to. A provider-issued
|
|
109
|
+
* tool-call id can repeat across runs, so a secret request is claimed by this
|
|
110
|
+
* id, not by the call id alone.
|
|
111
|
+
*/
|
|
112
|
+
instanceId: string;
|
|
113
|
+
/**
|
|
114
|
+
* Verified owner of the thread this run belongs to (the loop copies it off
|
|
115
|
+
* {@link AgentRunInput.owner}); `undefined` on an anonymous/single-tenant
|
|
116
|
+
* thread. `agent.asTool` forwards it to the CHILD run, so a sub-agent thread
|
|
117
|
+
* under an owned parent inherits the same RLS scope instead of being created
|
|
118
|
+
* ownerless — which left it readable by anyone who knew its key.
|
|
119
|
+
*/
|
|
120
|
+
owner?: string;
|
|
70
121
|
/**
|
|
71
122
|
* Emit an EPHEMERAL progress event for this tool call on the agent's live
|
|
72
123
|
* channel — the same live-only sink the streamed token deltas ride. NOT
|
|
@@ -102,11 +153,45 @@ interface AgentToolContext {
|
|
|
102
153
|
* skip the write when it is already present.
|
|
103
154
|
*/
|
|
104
155
|
setState: (state: Record<string, unknown>) => Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* The durable-step handle (`step.do`/`waitForEvent`). ALWAYS present:
|
|
158
|
+
* `agent-loop.ts` threads it into every tool's context unconditionally, and
|
|
159
|
+
* it is required rather than optional so a missing handle is a compile
|
|
160
|
+
* error instead of a silent durability downgrade. `codeTool` uses it to give
|
|
161
|
+
* each script step its OWN nested durable boundary — see `code-tool.ts` — so
|
|
162
|
+
* a failure at script step 3 retries only step 3, not steps 1–2's
|
|
163
|
+
* already-committed side effects. Cloudflare Workflows supports a `step.do`
|
|
164
|
+
* nested inside another `step.do`'s callback (the codeTool call's own
|
|
165
|
+
* enclosing step). Most tools never touch this directly; a test driving
|
|
166
|
+
* `execute`/`runToolScript` by hand passes a pass-through double.
|
|
167
|
+
*/
|
|
168
|
+
step: AgentStepLike;
|
|
105
169
|
/** The thread this tool call belongs to. */
|
|
106
170
|
threadKey: string;
|
|
107
171
|
/** The provider-issued tool-call id. */
|
|
108
172
|
toolCallId: string;
|
|
109
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* The view of {@link AgentToolContext} handed to a `needsApproval` gate
|
|
176
|
+
* function — every field except `setState`, `step`, and `reportProgress`.
|
|
177
|
+
*
|
|
178
|
+
* `setState` is dropped because a gate that mutates thread state is a side
|
|
179
|
+
* effect inside a decision predicate, and `reportProgress` because emitting a
|
|
180
|
+
* live event is the same thing in observable form — the decision is what the
|
|
181
|
+
* loop reports, not the deciding. `step` goes because the loop already runs the
|
|
182
|
+
* gate inside a durable step of its own, so a gate has no business opening
|
|
183
|
+
* another.
|
|
184
|
+
*
|
|
185
|
+
* `getState` and `run` stay: reads are legitimate gate inputs (gate on the
|
|
186
|
+
* caller's plan tier, on a spend total), and the gate resolves inside its own
|
|
187
|
+
* durable step, so they are replay-safe there. Note this makes the type a
|
|
188
|
+
* NARROWING, not a proof of purity — `run` takes any
|
|
189
|
+
* {@link AgentFunctionReference}, so a gate can still dispatch a mutation
|
|
190
|
+
* before approval. Nothing in the type system distinguishes a query reference
|
|
191
|
+
* from a mutation one; keeping the gate side-effect-free is the author's.
|
|
192
|
+
* @experimental
|
|
193
|
+
*/
|
|
194
|
+
type AgentApprovalContext = Omit<AgentToolContext, "reportProgress" | "setState" | "step">;
|
|
110
195
|
/**
|
|
111
196
|
* An agent tool. Unlike a raw AI SDK tool, `execute` is NOT handed to the
|
|
112
197
|
* model call — the loop runs it itself inside a named durable step so a
|
|
@@ -127,17 +212,35 @@ interface AgentToolDefinition<Input = unknown, Output = unknown> {
|
|
|
127
212
|
* Gate the tool behind a human approval (mirrors the AI SDK's
|
|
128
213
|
* `needsApproval`). When it resolves truthy the durable run PAUSES — the
|
|
129
214
|
* thread moves to `"awaiting_input"` and the workflow hibernates on
|
|
130
|
-
* `approval
|
|
215
|
+
* `approval:<toolCallId>` — until a client calls `agents:agentResolveApproval`.
|
|
131
216
|
* On approve the tool runs exactly as normal; on reject it is skipped and a
|
|
132
217
|
* tool result explaining the rejection is persisted so the next turn recovers.
|
|
133
218
|
* A boolean gates statically; a function gates per input. Default: `false`
|
|
134
|
-
* (unchanged behavior).
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
219
|
+
* (unchanged behavior).
|
|
220
|
+
*
|
|
221
|
+
* The boolean/`undefined` forms are compile-time constants re-derived
|
|
222
|
+
* identically on every replay — no durable step. The FUNCTION form runs
|
|
223
|
+
* inside its OWN durable step (`tool:approval-gate:<toolCallId>`, distinct
|
|
224
|
+
* from the tool's own step), so it now runs exactly once per call, not once
|
|
225
|
+
* per replay. It must still be otherwise pure: deterministic given its
|
|
226
|
+
* inputs (no `Date.now()`/`Math.random()`) and free of side effects — the
|
|
227
|
+
* context it receives is {@link AgentApprovalContext}, which has neither
|
|
228
|
+
* `setState` nor `reportProgress`; state writes and progress events belong
|
|
229
|
+
* only in `execute`, inside the tool's own memoized step. It still holds
|
|
230
|
+
* `run`, which the type cannot narrow to reads — see
|
|
231
|
+
* {@link AgentApprovalContext}.
|
|
139
232
|
*/
|
|
140
|
-
needsApproval?: ((input: Input, context:
|
|
233
|
+
needsApproval?: ((input: Input, context: AgentApprovalContext) => boolean | Promise<boolean>) | boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Set by `requestSecretTool`. The loop never calls `execute` on such a tool: it
|
|
236
|
+
* pauses the run until a human supplies (or declines) a value and records
|
|
237
|
+
* `{ secretRef }` as the tool result, where `secretRef` is the request's
|
|
238
|
+
* slot, `<turn>:<tool-call id>`. The client answers the pause with the tool-call id it sees on it. `consumer` names the only tool
|
|
239
|
+
* that may read the value. The value never reaches the loop, the thread or the model.
|
|
240
|
+
*/
|
|
241
|
+
secretRequest?: {
|
|
242
|
+
consumer: string;
|
|
243
|
+
};
|
|
141
244
|
}
|
|
142
245
|
/**
|
|
143
246
|
* Author-supplied tool config (see {@link AgentToolDefinition}).
|
|
@@ -252,7 +355,7 @@ interface AgentMemoryOptions {
|
|
|
252
355
|
* (`key: "default"`) from {@link AgentConfig.memory}, then one per skill that
|
|
253
356
|
* carries `knowledge` (keyed by the skill's name). The key names the durable
|
|
254
357
|
* step — the default source keeps the historic `"memory:retrieve"`, a skill
|
|
255
|
-
* source uses `"memory:retrieve
|
|
358
|
+
* source uses `"memory:retrieve:<key>"` — so replay stays deterministic.
|
|
256
359
|
* @experimental
|
|
257
360
|
*/
|
|
258
361
|
interface AgentMemorySource extends AgentMemoryOptions {
|
|
@@ -260,14 +363,31 @@ interface AgentMemorySource extends AgentMemoryOptions {
|
|
|
260
363
|
key: string;
|
|
261
364
|
}
|
|
262
365
|
/**
|
|
263
|
-
* Cumulative or per-turn token usage — AI SDK `LanguageModelUsage` field names
|
|
366
|
+
* Cumulative or per-turn token usage — AI SDK `LanguageModelUsage` field names, plus
|
|
367
|
+
* the cache and reasoning breakdowns. The breakdowns are subsets of the totals they
|
|
368
|
+
* sit under (`cacheReadTokens` and `cacheWriteTokens` are part of `inputTokens`,
|
|
369
|
+
* `reasoningTokens` is part of `outputTokens`), so they are never added on top.
|
|
370
|
+
* Each is omitted when the provider reported none.
|
|
264
371
|
* @experimental
|
|
265
372
|
*/
|
|
266
373
|
interface AgentUsage {
|
|
267
|
-
/**
|
|
374
|
+
/** Input tokens served from the provider's prompt cache. */
|
|
375
|
+
cacheReadTokens?: number;
|
|
376
|
+
/** Input tokens written to the provider's prompt cache. */
|
|
377
|
+
cacheWriteTokens?: number;
|
|
378
|
+
/** Prompt (input) tokens, including any cache-read and cache-write tokens. */
|
|
268
379
|
inputTokens?: number;
|
|
269
|
-
/** Completion (output) tokens. */
|
|
380
|
+
/** Completion (output) tokens, including any reasoning tokens. */
|
|
270
381
|
outputTokens?: number;
|
|
382
|
+
/** Output tokens spent on hidden reasoning. */
|
|
383
|
+
reasoningTokens?: number;
|
|
384
|
+
/**
|
|
385
|
+
* Whether the provider's report covers every bucket it should carry: `complete` when all
|
|
386
|
+
* of it was reported, `partial` when some was, `unavailable` when none was. A run's total
|
|
387
|
+
* is `partial` as soon as one of its turns was not complete. Absent on a value written
|
|
388
|
+
* before this field existed; that row cannot say whether it was complete, so it reads as unknown.
|
|
389
|
+
*/
|
|
390
|
+
status?: "complete" | "partial" | "unavailable";
|
|
271
391
|
/** Input + output tokens. */
|
|
272
392
|
totalTokens?: number;
|
|
273
393
|
}
|
|
@@ -308,7 +428,7 @@ interface SkillConfig {
|
|
|
308
428
|
knowledge?: AgentMemoryOptions;
|
|
309
429
|
/**
|
|
310
430
|
* The skill's identifier — namespaces this skill's `knowledge` memory source
|
|
311
|
-
* (the durable step `memory:retrieve
|
|
431
|
+
* (the durable step `memory:retrieve:<name>`). Must be identifier-shaped.
|
|
312
432
|
*/
|
|
313
433
|
name: string;
|
|
314
434
|
/**
|
|
@@ -318,6 +438,12 @@ interface SkillConfig {
|
|
|
318
438
|
*/
|
|
319
439
|
tools?: Record<string, AnyAgentTool>;
|
|
320
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* The code-side parts of a markdown-authored skill — everything `SKILL.md`
|
|
443
|
+
* cannot carry. `name` and `instructions` come from the file itself.
|
|
444
|
+
* @experimental
|
|
445
|
+
*/
|
|
446
|
+
type SkillMarkdownExtras = Omit<SkillConfig, "instructions" | "name">;
|
|
321
447
|
/**
|
|
322
448
|
* A `defineSkill` result — config plus the brand the agent merge checks.
|
|
323
449
|
* @experimental
|
|
@@ -358,11 +484,43 @@ interface AgentStepFinishInfo {
|
|
|
358
484
|
}
|
|
359
485
|
/**
|
|
360
486
|
* Called after each LLM turn with that turn's text, tool calls, and usage. Runs
|
|
361
|
-
* inside a named durable step (`agent:step-finish
|
|
487
|
+
* inside a named durable step (`agent:step-finish:<turn>`) so it fires exactly
|
|
362
488
|
* once per turn even across a workflow replay.
|
|
363
489
|
* @experimental
|
|
364
490
|
*/
|
|
365
491
|
type AgentOnStepFinish = (info: AgentStepFinishInfo) => Promise<void> | void;
|
|
492
|
+
/**
|
|
493
|
+
* What {@link AgentConfig.onReply} is called with when a triggered run reaches
|
|
494
|
+
* its final answer.
|
|
495
|
+
* @experimental
|
|
496
|
+
*/
|
|
497
|
+
interface AgentReplyInfo {
|
|
498
|
+
/** The worker `env` — where an outbound credential (a bot token, a mailer binding) lives. */
|
|
499
|
+
env: Record<string, unknown>;
|
|
500
|
+
/** Where to reply, captured by the mapper that started this run. */
|
|
501
|
+
replyRef: AgentReplyRef;
|
|
502
|
+
/** The run's final answer. */
|
|
503
|
+
result: AgentRunResult;
|
|
504
|
+
/** The thread this run belongs to. */
|
|
505
|
+
threadKey: string;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Send a triggered run's answer back where it came from — the outbound half of
|
|
509
|
+
* an `onEmail` / `onInbound` trigger.
|
|
510
|
+
*
|
|
511
|
+
* Called once, automatically, when a run started with a `replyRef` produces a
|
|
512
|
+
* final answer; a run without one (an ordinary in-app `ctx.agents.<name>.run`)
|
|
513
|
+
* never calls it. It runs inside a named durable step, so a transient failure
|
|
514
|
+
* is retried and a workflow replay does not send the answer twice.
|
|
515
|
+
*
|
|
516
|
+
* Delivery is the app's call, because only the app has the credential: email
|
|
517
|
+
* has a home already (`replyToEmail(mailer, ref, body)` from
|
|
518
|
+
* `@lunora/agent/reply`), while Slack/GitHub/Discord bot tokens have no
|
|
519
|
+
* framework-owned store yet — read them from `info.env` and make the provider
|
|
520
|
+
* call.
|
|
521
|
+
* @experimental
|
|
522
|
+
*/
|
|
523
|
+
type AgentOnReply = (info: AgentReplyInfo) => Promise<void> | void;
|
|
366
524
|
/**
|
|
367
525
|
* The input {@link AgentConfig.prepareStep} sees before a turn runs.
|
|
368
526
|
* @experimental
|
|
@@ -404,6 +562,39 @@ type AgentPrepareStep = (input: AgentPrepareStepInput) => AgentPrepareStepResult
|
|
|
404
562
|
* start a run from an inbound email.
|
|
405
563
|
* @experimental
|
|
406
564
|
*/
|
|
565
|
+
/**
|
|
566
|
+
* Where a triggered run should send its answer back to — captured by the
|
|
567
|
+
* mapper, from fields the verified inbound payload already carries, and carried
|
|
568
|
+
* through the run so {@link AgentConfig.onReply} can answer in the same place
|
|
569
|
+
* the question was asked.
|
|
570
|
+
*
|
|
571
|
+
* A discriminated union rather than an opaque blob because each channel threads
|
|
572
|
+
* differently: email by RFC 5322 `In-Reply-To`/`References`, Slack by
|
|
573
|
+
* `thread_ts`, GitHub by issue number, Discord by channel (plus the triggering
|
|
574
|
+
* message for a true reply).
|
|
575
|
+
* @experimental
|
|
576
|
+
*/
|
|
577
|
+
type AgentReplyRef = {
|
|
578
|
+
channel: "discord";
|
|
579
|
+
channelId: string;
|
|
580
|
+
messageId?: string;
|
|
581
|
+
} | {
|
|
582
|
+
channel: "email";
|
|
583
|
+
from: string;
|
|
584
|
+
messageId: string;
|
|
585
|
+
references?: string;
|
|
586
|
+
to: string[];
|
|
587
|
+
} | {
|
|
588
|
+
channel: "github";
|
|
589
|
+
commentId?: number;
|
|
590
|
+
issueNumber: number;
|
|
591
|
+
owner: string;
|
|
592
|
+
repo: string;
|
|
593
|
+
} | {
|
|
594
|
+
channel: "slack";
|
|
595
|
+
channelId: string;
|
|
596
|
+
threadTs: string;
|
|
597
|
+
};
|
|
407
598
|
interface AgentEmailRun {
|
|
408
599
|
/** The user message that starts (or continues) the thread — the model's prompt. */
|
|
409
600
|
input: string;
|
|
@@ -414,6 +605,13 @@ interface AgentEmailRun {
|
|
|
414
605
|
* `email.from`.
|
|
415
606
|
*/
|
|
416
607
|
owner?: string;
|
|
608
|
+
/**
|
|
609
|
+
* Where to send the answer — see {@link AgentReplyRef}. Populate it from the
|
|
610
|
+
* event the mapper already has (`captureEmailReplyRef(email)` does it for
|
|
611
|
+
* email) and the run calls {@link AgentConfig.onReply} with it once the
|
|
612
|
+
* final answer is ready. Omit it and the run simply never replies.
|
|
613
|
+
*/
|
|
614
|
+
replyRef?: AgentReplyRef;
|
|
417
615
|
/** The thread key — reuse to continue a conversation (e.g. a ticket id parsed from the subject). */
|
|
418
616
|
threadKey: string;
|
|
419
617
|
/** Optional thread title, set on first creation. */
|
|
@@ -484,6 +682,22 @@ interface AgentInboundChannel {
|
|
|
484
682
|
interface AgentConfig {
|
|
485
683
|
/** Restrict the tools the model may call, by name. Default: all tools. */
|
|
486
684
|
activeTools?: ReadonlyArray<string>;
|
|
685
|
+
/**
|
|
686
|
+
* How long a human-in-the-loop tool approval may stay pending before the
|
|
687
|
+
* run stops waiting — a Cloudflare Workflows duration: milliseconds, or a
|
|
688
|
+
* `"<n> <unit>"` string like `"3 days"` (the unit set is the host's, so a
|
|
689
|
+
* typo is a compile error). Default `"3 days"`.
|
|
690
|
+
*
|
|
691
|
+
* On timeout the call is treated as REJECTED (the run records why and
|
|
692
|
+
* continues down the normal rejection path), so a run whose approver never
|
|
693
|
+
* answers ends instead of hibernating forever.
|
|
694
|
+
*
|
|
695
|
+
* CLAMPED to one week. A longer wait would outlive the thread's
|
|
696
|
+
* abandoned-run horizon, letting a new run reclaim the thread while the
|
|
697
|
+
* approval is still pending — which is the exact failure this timeout
|
|
698
|
+
* exists to prevent, so it cannot be configured back into existence.
|
|
699
|
+
*/
|
|
700
|
+
approvalTimeout?: `${number} ${"day" | "hour" | "minute" | "month" | "second" | "week" | "year"}${"s" | ""}` | number;
|
|
487
701
|
/**
|
|
488
702
|
* Automatic thread-history compaction. When the persisted history exceeds
|
|
489
703
|
* `maxMessages`, the loop summarizes the older messages (all but the most
|
|
@@ -530,9 +744,9 @@ interface AgentConfig {
|
|
|
530
744
|
model: AgentModelInput;
|
|
531
745
|
/**
|
|
532
746
|
* Optional override for the deployed workflow name (`wrangler.jsonc`
|
|
533
|
-
* `workflows[].name`). Defaults to `agent
|
|
747
|
+
* `workflows[].name`). Defaults to `agent-<kebab-cased export name>`. Does
|
|
534
748
|
* NOT change the binding name, which is always derived from the export
|
|
535
|
-
* name (`support` → `
|
|
749
|
+
* name (`support` → `SupportAgentWorkflow`).
|
|
536
750
|
*/
|
|
537
751
|
name?: string;
|
|
538
752
|
/**
|
|
@@ -543,7 +757,16 @@ interface AgentConfig {
|
|
|
543
757
|
*
|
|
544
758
|
* - `"reject"` (default) — fail the new run fast with a `CONFLICT` error.
|
|
545
759
|
* - `"replace"` — terminate the in-flight instance and take the thread over.
|
|
546
|
-
* - `"queue"` —
|
|
760
|
+
* - `"queue"` — park the new run behind the one in flight (FIFO, up to five deep) and hibernate it until the thread is handed over.
|
|
761
|
+
*
|
|
762
|
+
* Each parked run is a live workflow instance waiting on an event, so the
|
|
763
|
+
* queue's depth cap is a real resource bound: past it, a start is rejected
|
|
764
|
+
* exactly as `"reject"` would. A `"replace"` arriving later supersedes the
|
|
765
|
+
* run in FLIGHT, not the queue — parked runs still take their turn after it.
|
|
766
|
+
*
|
|
767
|
+
* A dispatch with no instance id (the inbound-email / inbound-channel
|
|
768
|
+
* paths) cannot be parked, because nothing later can tell it apart from
|
|
769
|
+
* another such dispatch to wake it; `"queue"` rejects those.
|
|
547
770
|
*
|
|
548
771
|
* A workflow REPLAY re-enters the bootstrap under the SAME instance id and
|
|
549
772
|
* is never a concurrent run (the guard compares the stored instance id).
|
|
@@ -563,6 +786,12 @@ interface AgentConfig {
|
|
|
563
786
|
* signature over the raw body before calling `map`.
|
|
564
787
|
*/
|
|
565
788
|
onInbound?: AgentInboundChannel;
|
|
789
|
+
/**
|
|
790
|
+
* Called with the final answer when the run was triggered from a channel
|
|
791
|
+
* that gave it a `replyRef` — see {@link AgentOnReply}. This is how an
|
|
792
|
+
* inbound-triggered agent answers where it was asked.
|
|
793
|
+
*/
|
|
794
|
+
onReply?: AgentOnReply;
|
|
566
795
|
/** Called after each LLM turn — see {@link AgentOnStepFinish}. */
|
|
567
796
|
onStepFinish?: AgentOnStepFinish;
|
|
568
797
|
/**
|
|
@@ -577,7 +806,7 @@ interface AgentConfig {
|
|
|
577
806
|
* Opt this agent into being STARTED over the public RPC boundary — i.e. via
|
|
578
807
|
* the auto-registered `agents:agentRun` mutation an HTTP-only client (e.g.
|
|
579
808
|
* the `@lunora/mcp` server) calls. Default `false`: an agent is startable
|
|
580
|
-
* only from server-side app code (`ctx.agents
|
|
809
|
+
* only from server-side app code (`ctx.agents.<name>.run(...)`), so declaring
|
|
581
810
|
* an agent does NOT expose it to arbitrary RPC callers. Fail-closed — the run
|
|
582
811
|
* mutation refuses an agent that has not opted in, regardless of any MCP-side
|
|
583
812
|
* `allowAgents` configuration. A started thread is still owner-scoped to
|
|
@@ -649,8 +878,20 @@ interface AgentVoiceConfig {
|
|
|
649
878
|
/**
|
|
650
879
|
* Spoken on connect before the first user turn — a fixed greeting synthesized
|
|
651
880
|
* through the TTS model. Omit for a silent-until-spoken-to session.
|
|
881
|
+
*
|
|
882
|
+
* Synthesized once per THREAD, not once per socket: the greeting's persisted
|
|
883
|
+
* row is keyed per thread, and a reconnect onto a thread that already exists
|
|
884
|
+
* gets the `ready` frame without paying for the same line again.
|
|
652
885
|
*/
|
|
653
886
|
greeting?: string;
|
|
887
|
+
/**
|
|
888
|
+
* Cap on how many turns one voice socket may run before it is closed with
|
|
889
|
+
* code `4002`. Every turn is a full LLM generation plus sentence-by-sentence
|
|
890
|
+
* TTS — billed and persisted — on a hibernatable socket that can live for
|
|
891
|
+
* days, and the one-turn-in-flight guard throttles nothing. Defaults to 100;
|
|
892
|
+
* a client that hits the cap reconnects for a fresh budget.
|
|
893
|
+
*/
|
|
894
|
+
maxTurns?: number;
|
|
654
895
|
/**
|
|
655
896
|
* TTS voice/speaker id forwarded to the TTS model (e.g. a Deepgram Aura voice
|
|
656
897
|
* like `"aura-asteria-en"`). Model-specific; omitted when unset so the model
|
|
@@ -685,11 +926,11 @@ interface AgentSubToolInput {
|
|
|
685
926
|
interface AgentAsToolOptions {
|
|
686
927
|
/** What the sub-agent does — shown to the parent's model (it decides from it). */
|
|
687
928
|
description: string;
|
|
688
|
-
/** Cap on child-run status polls before giving up. Default
|
|
929
|
+
/** 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
930
|
maxPolls?: number;
|
|
690
931
|
/**
|
|
691
|
-
* The child agent's export name — selects its `AGENT_
|
|
692
|
-
*
|
|
932
|
+
* The child agent's export name — selects its `AGENT_<NAME>` Workflow
|
|
933
|
+
* export key (e.g. `"researcher"` → `ResearcherAgentWorkflow`). The model-facing tool
|
|
693
934
|
* name is the KEY assigned in the parent's `tools` map, not this.
|
|
694
935
|
*/
|
|
695
936
|
name: string;
|
|
@@ -725,11 +966,43 @@ interface AgentDefinition extends AgentConfig {
|
|
|
725
966
|
*/
|
|
726
967
|
memorySources?: ReadonlyArray<AgentMemorySource>;
|
|
727
968
|
}
|
|
969
|
+
/**
|
|
970
|
+
* What `agentEnsureThread` reports back to the loop.
|
|
971
|
+
*
|
|
972
|
+
* A discriminated union rather than a bag of optional booleans: the outcomes are
|
|
973
|
+
* mutually exclusive, and the data each carries only exists for its own case.
|
|
974
|
+
* `queued` has a position, `replaced` has the instance it took the thread from,
|
|
975
|
+
* and the rest have nothing — encoding that as independent optional fields made
|
|
976
|
+
* every reader re-derive which combination was legal.
|
|
977
|
+
*
|
|
978
|
+
* `completed` is the odd one: the thread was NOT (re)opened. This run already
|
|
979
|
+
* reported its outcome and is replaying because only the reply was lost, so it
|
|
980
|
+
* takes no ownership and revives nothing — it runs its body out of the step
|
|
981
|
+
* journal to re-dispatch the effects that never landed.
|
|
982
|
+
* @experimental
|
|
983
|
+
*/
|
|
984
|
+
type EnsureThreadOutcome = {
|
|
985
|
+
outcome: "completed" | "continued" | "created";
|
|
986
|
+
} | {
|
|
987
|
+
outcome: "queued";
|
|
988
|
+
position: number;
|
|
989
|
+
} | {
|
|
990
|
+
outcome: "replaced";
|
|
991
|
+
priorInstanceId: string;
|
|
992
|
+
};
|
|
728
993
|
/**
|
|
729
994
|
* Params of one agent run (the compiled workflow's payload).
|
|
730
995
|
* @experimental
|
|
731
996
|
*/
|
|
732
997
|
interface AgentRunInput {
|
|
998
|
+
/**
|
|
999
|
+
* Sub-agent delegation depth. A run a user starts omits it (0); each
|
|
1000
|
+
* `agent.asTool` hop stamps its child one deeper, and the tool refuses to
|
|
1001
|
+
* delegate past the bound — `maxTurns` bounds one level's turns, this bounds
|
|
1002
|
+
* the TREE (every hop mints a distinct child `threadKey`, so the per-thread
|
|
1003
|
+
* run-queue cap never applies across them).
|
|
1004
|
+
*/
|
|
1005
|
+
depth?: number;
|
|
733
1006
|
/** The user message that starts (or continues) the thread. */
|
|
734
1007
|
input: string;
|
|
735
1008
|
/**
|
|
@@ -741,6 +1014,8 @@ interface AgentRunInput {
|
|
|
741
1014
|
* the first run.
|
|
742
1015
|
*/
|
|
743
1016
|
owner?: string;
|
|
1017
|
+
/** Where a triggered run sends its answer — see {@link AgentReplyRef}. */
|
|
1018
|
+
replyRef?: AgentReplyRef;
|
|
744
1019
|
/** The thread key — reuse to continue a conversation. */
|
|
745
1020
|
threadKey: string;
|
|
746
1021
|
/** Optional thread title, set on first creation. */
|
|
@@ -773,6 +1048,24 @@ interface AgentRunResult {
|
|
|
773
1048
|
*/
|
|
774
1049
|
interface AgentFunctionPaths {
|
|
775
1050
|
appendMessage: string;
|
|
1051
|
+
/**
|
|
1052
|
+
* The internal `agents:agentApprovalGranted` query the loop dispatches from
|
|
1053
|
+
* inside a tool's approval-gate step: whether the tool is granted for the thread.
|
|
1054
|
+
*/
|
|
1055
|
+
approvalGranted: string;
|
|
1056
|
+
/**
|
|
1057
|
+
* The internal `agents:agentCompleteRun` mutation the loop dispatches at the
|
|
1058
|
+
* end of a run: it writes the terminal status AND hands the thread to the
|
|
1059
|
+
* next queued run in the same mutation.
|
|
1060
|
+
*/
|
|
1061
|
+
completeRun: string;
|
|
1062
|
+
/**
|
|
1063
|
+
* The internal `agents:agentDeleteMessage` mutation the loop dispatches to
|
|
1064
|
+
* retire the HITL approval marker once the decision has landed.
|
|
1065
|
+
*/
|
|
1066
|
+
deleteMessage: string;
|
|
1067
|
+
/** The internal `agents:agentDiscardSecret` mutation a secret-consuming tool dispatches after it has used the value. */
|
|
1068
|
+
discardSecret: string;
|
|
776
1069
|
ensureThread: string;
|
|
777
1070
|
/** The internal `agents:agentEpisodeRecall` query the loop dispatches for an episodic-kind read. */
|
|
778
1071
|
episodeRecall: string;
|
|
@@ -782,7 +1075,14 @@ interface AgentFunctionPaths {
|
|
|
782
1075
|
graphTraverse: string;
|
|
783
1076
|
/** The internal `agents:agentGraphUpsert` mutation the loop dispatches on run-end graph extraction. */
|
|
784
1077
|
graphUpsert: string;
|
|
1078
|
+
/**
|
|
1079
|
+
* The internal `agents:agentHistory` query the loop dispatches for a compacting
|
|
1080
|
+
* turn: the stored running summary plus only the messages it does not yet cover.
|
|
1081
|
+
*/
|
|
1082
|
+
history: string;
|
|
785
1083
|
listMessages: string;
|
|
1084
|
+
/** The internal `agents:agentOpenSecretRequest` mutation that writes the pending request row when a run pauses. */
|
|
1085
|
+
openSecretRequest: string;
|
|
786
1086
|
patchThread: string;
|
|
787
1087
|
/**
|
|
788
1088
|
* The public `agents:agentRun` mutation an HTTP-only client (e.g. the
|
|
@@ -792,22 +1092,29 @@ interface AgentFunctionPaths {
|
|
|
792
1092
|
run: string;
|
|
793
1093
|
/** The internal `agents:agentSetState` mutation the loop dispatches for `setState`. */
|
|
794
1094
|
setState: string;
|
|
1095
|
+
/** The internal `agents:agentSettleSecretRequest` mutation that reads a paused request's outcome once its wait ends. */
|
|
1096
|
+
settleSecretRequest: string;
|
|
795
1097
|
/** The public owner-gated `agents:agentState` query (`getState` + `useAgentState`). */
|
|
796
1098
|
state: string;
|
|
1099
|
+
/** The internal `agents:agentTakeSecret` mutation a secret-consuming tool dispatches to read a supplied value. */
|
|
1100
|
+
takeSecret: string;
|
|
797
1101
|
}
|
|
798
1102
|
/**
|
|
799
1103
|
* Approval lifecycle marker on a message: `"awaiting_approval"` on the
|
|
800
1104
|
* placeholder written while a run pauses on a gated tool, then `"approved"` /
|
|
801
|
-
* `"rejected"` on the tool result once a client resolves it.
|
|
802
|
-
*
|
|
1105
|
+
* `"rejected"` on the tool result once a client resolves it. `"awaiting_secret"`
|
|
1106
|
+
* is the same pause for a {@link AgentToolDefinition.secretRequest} tool. Absent
|
|
1107
|
+
* on ordinary messages. Both pause markers are filtered out of the model prompt.
|
|
803
1108
|
* @experimental
|
|
804
1109
|
*/
|
|
805
|
-
type AgentMessageStatus = "approved" | "awaiting_approval" | "rejected";
|
|
1110
|
+
type AgentMessageStatus = "approved" | "awaiting_approval" | "awaiting_secret" | "rejected";
|
|
806
1111
|
/**
|
|
807
1112
|
* One persisted thread message, as the loop reads it back.
|
|
808
1113
|
* @experimental
|
|
809
1114
|
*/
|
|
810
1115
|
interface AgentMessageRow {
|
|
1116
|
+
/** On an approved tool result: `"thread"` when the approval also granted the tool for the rest of the thread. */
|
|
1117
|
+
approvalScope?: "thread";
|
|
811
1118
|
content: string;
|
|
812
1119
|
role: "assistant" | "system" | "tool" | "user";
|
|
813
1120
|
seq: number;
|
|
@@ -824,6 +1131,14 @@ interface AgentMessageRow {
|
|
|
824
1131
|
interface AgentToolCall {
|
|
825
1132
|
id: string;
|
|
826
1133
|
input: unknown;
|
|
1134
|
+
/**
|
|
1135
|
+
* Why this call was REJECTED before it could run: the model's arguments
|
|
1136
|
+
* failed the tool's input schema, or did not parse as JSON. Present only on
|
|
1137
|
+
* a rejected call — the loop records it as a recoverable tool result and
|
|
1138
|
+
* never executes the tool, because the `input` above is the raw value the
|
|
1139
|
+
* provider sent, not a validated one.
|
|
1140
|
+
*/
|
|
1141
|
+
invalid?: string;
|
|
827
1142
|
name: string;
|
|
828
1143
|
}
|
|
829
1144
|
/**
|
|
@@ -916,6 +1231,12 @@ type AgentCompact = (input: {
|
|
|
916
1231
|
messages: ModelMessage[];
|
|
917
1232
|
/** The compaction model (the config's `model`, else the agent's). */
|
|
918
1233
|
model: AgentModelInput;
|
|
1234
|
+
/**
|
|
1235
|
+
* The previous brief being folded into, when this is an incremental update.
|
|
1236
|
+
* A seam MUST merge it rather than summarise only the new messages, or facts
|
|
1237
|
+
* from earlier turns are lost until the next from-scratch rebuild.
|
|
1238
|
+
*/
|
|
1239
|
+
previousSummary?: string;
|
|
919
1240
|
}) => Promise<string>;
|
|
920
1241
|
/** The one-line summary an episodic-memory run records for later recency recall. */
|
|
921
1242
|
interface AgentEpisodeExtraction {
|
|
@@ -1018,11 +1339,12 @@ type AgentTokenSink = (event: AgentLiveEvent) => void;
|
|
|
1018
1339
|
*/
|
|
1019
1340
|
type AgentStreamGenerate = (options: AgentGenerateOptions, onDelta: (text: string) => void) => Promise<AgentGenerateResult>;
|
|
1020
1341
|
/**
|
|
1021
|
-
* Spec entry codegen emits per agent: `{
|
|
1342
|
+
* Spec entry codegen emits per agent: `{ className: "SupportAgentWorkflow", exportName: "support" }`.
|
|
1022
1343
|
* @experimental
|
|
1023
1344
|
*/
|
|
1024
1345
|
interface AgentBindingSpec {
|
|
1025
|
-
|
|
1346
|
+
/** The agent's export key — its generated class name, e.g. `SupportAgentWorkflow`. */
|
|
1347
|
+
className: string;
|
|
1026
1348
|
exportName: string;
|
|
1027
1349
|
/**
|
|
1028
1350
|
* Whether the app author opted this agent into public run-starts (via
|
|
@@ -1078,7 +1400,7 @@ interface AgentRunHandle {
|
|
|
1078
1400
|
id: string;
|
|
1079
1401
|
}
|
|
1080
1402
|
/**
|
|
1081
|
-
* The `ctx.agents
|
|
1403
|
+
* The `ctx.agents.<name>` producer handle.
|
|
1082
1404
|
* @experimental
|
|
1083
1405
|
*/
|
|
1084
1406
|
interface AgentHandle {
|
|
@@ -1111,4 +1433,4 @@ interface AgentHandle {
|
|
|
1111
1433
|
/** Read a run's workflow status by instance id. */
|
|
1112
1434
|
status: (id: string) => Promise<unknown>;
|
|
1113
1435
|
}
|
|
1114
|
-
export { AgentDefinition as A,
|
|
1436
|
+
export { AgentUsage as $, AgentDefinition as A, AgentApprovalContext as B, AgentEmailMapper as C, AgentEmailRun as D, AgentGenerateOptions as E, AgentGenerateResult as F, AgentInstructionsContext as G, AgentLiveEvent as H, InboundChannelEvent as I, AgentMemoryOptions as J, AgentMemorySource as K, AgentMessageStatus as L, AgentOnReply as M, AgentOnStepFinish as N, AgentPrepareStep as O, AgentPrepareStepInput as P, AgentPrepareStepResult as Q, AgentProgressEvent as R, SkillMarkdownExtras as S, AgentReplyInfo as T, AgentRunHandle as U, AgentRunOptions as V, AgentStepFinishInfo as W, AgentStepInfo as X, AgentThreadStatus as Y, AgentTokenDelta as Z, AgentToolCall as _, AgentReplyRef as a, AgentVoiceConfig as a0, AgentWorkflowBindingLike as a1, AgentWorkflowInstanceLike as a2, EnsureThreadOutcome as a3, 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, AgentBindingSpec as u, AgentHandle as v, AgentToolConfig as w, AgentFunctionReference as x, AgentModelInput as y, SkillConfig as z };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as Y}from"./agent-loop-BgOHoyg_.mjs";import{buildModelMessages as Z}from"./buildModelMessages-DVQdQ7_1.mjs";import{toFunctionReference as A}from"./AGENT_MODULE-CYBmT9SD.mjs";const ut=t=>{let e="";for(let r=0;r<t.length;r+=32768)e+=String.fromCharCode(...t.subarray(r,r+32768));return btoa(e)},C=t=>{const e=atob(t),n=new Uint8Array(e.length);for(let r=0;r<e.length;r+=1)n[r]=e.codePointAt(r)??0;return n},F=t=>{const e=t.replaceAll("-","+").replaceAll("_","/"),n=e+"=".repeat((4-e.length%4)%4);return C(n)},H=new TextDecoder;new TextEncoder;const M="=",tt=t=>{if(t)try{const e=t[0]==="{"?t:H.decode(F(t)),n=JSON.parse(e);if(n&&typeof n=="object"&&!Array.isArray(n))return n}catch{}},yt=t=>{if(t){if(!t.startsWith(M))return t;try{return H.decode(F(t.slice(M.length)))}catch{return}}},ft=t=>{const e=Number(t);return Number.isFinite(e)&&e>0?e:void 0},lt=t=>typeof t=="number"&&Date.now()>=t,pt=t=>{try{t.send(JSON.stringify({code:"TOKEN_EXPIRED",error:{code:"TOKEN_EXPIRED",message:"authentication token expired"},message:"authentication token expired",type:"error"})),t.close?.(4001,"token_expired")}catch{}},et=16e3,nt=1,rt=16,P=/[.!?]\s/u,st=/\s/u,at=async function*(t){if(t instanceof Uint8Array){yield t;return}if(t instanceof ReadableStream){const e=t.getReader();try{for(;;){const{done:n,value:r}=await e.read();if(n)break;yield r}}finally{e.releaseLock()}return}yield*t},ht=(t,e=et,n=nt,r=rt)=>{const a=n*r/8,p=e*a,m=new ArrayBuffer(44+t.byteLength),s=new DataView(m),u=(y,b)=>{for(let d=0;d<b.length;d+=1)s.setUint8(y+d,b.codePointAt(d)??0)};u(0,"RIFF"),s.setUint32(4,36+t.byteLength,!0),u(8,"WAVE"),u(12,"fmt "),s.setUint32(16,16,!0),s.setUint16(20,1,!0),s.setUint16(22,n,!0),s.setUint32(24,e,!0),s.setUint32(28,p,!0),s.setUint16(32,a,!0),s.setUint16(34,r,!0),u(36,"data"),s.setUint32(40,t.byteLength,!0);const i=new Uint8Array(m);return i.set(t,44),i},it=t=>{const e=[];let n=t,r=P.exec(n);for(;r;){let a=r.index+1;for(;a<n.length&&st.test(n[a]??"");)a+=1;const p=n.slice(0,a).trim();p.length>0&&e.push(p),n=n.slice(a),r=P.exec(n)}return{rest:n,sentences:e}},gt=async t=>{const{agent:e,compact:n,connectionId:r,env:a,exportName:p,owner:m,paths:s,pcm:u,run:i,send:y,sendAudio:b,signal:d,streamGenerate:L,synthesize:B,text:O,threadKey:o,transcribe:$,turn:U,waitForDrain:K}=t;let _=!1,v=!1;const j=()=>v,h=()=>d.aborted||_,I=A(s.appendMessage),W=A(s.ensureThread),V=A(s.listMessages),x=A(s.patchThread);await i(W,{agent:p,key:o,...e.initialState===void 0?{}:{initialState:e.initialState},...m===void 0?{}:{owner:m}});try{const f=(O??(u?await $(u):"")).trim();if(f.length===0)return await i(x,{key:o,status:"idle"}),{assistantText:"",interrupted:!1,userText:""};y({text:f,type:"user_transcript"}),await i(I,{content:f,messageKey:`voice:${r}:${String(U)}:user`,role:"user",threadKey:o}),await i(x,{key:o,status:"running"});const R=typeof e.instructions=="function"?e.instructions({env:a,input:f,threadKey:o}):e.instructions,X=await i(V,{key:o}),{history:J,summary:N}=await Y({agent:e,compact:n,env:a},X),q=Z({history:J,...R===void 0?{}:{instructions:R},...N===void 0?{}:{summary:N}});let g="",E="",k=Promise.resolve();const z=async c=>{if(h()||c.length===0)return;let w=!1;try{for await(const l of at(await B(c,d))){if(h()||(await K?.(),h()))break;b(l),w=!0}}catch(l){y({message:l instanceof Error?l.message:String(l),type:"error"})}w&&(E=E.length>0?`${E} ${c}`:c)},D=c=>{k=k.then(async()=>z(c))},G=await L({messages:q,signal:d},c=>{if(h())return;v=!0,y({text:c,type:"assistant_delta"}),g+=c;const{rest:w,sentences:l}=it(g);g=w;for(const Q of l)D(Q)});!h()&&g.trim().length>0&&D(g.trim()),g="",await k;const S=h(),T=S?E:G.text;return await i(I,{content:T,messageKey:`voice:${r}:${String(U)}:assistant`,role:"assistant",threadKey:o}),await i(x,{key:o,status:"idle"}),y(S?{type:"interrupted"}:{text:T,type:"assistant_done"}),{assistantText:T,interrupted:S,userText:f}}catch(f){throw _=!0,j()&&y({type:"assistant_discarded"}),await i(x,{key:o,status:"idle"}),f}},mt=t=>tt(t),bt=t=>{if(typeof t=="object"&&t!==null&&"text"in t){const{text:e}=t;return typeof e=="string"?e:""}return""},xt=t=>{if(t instanceof Uint8Array||t instanceof ReadableStream)return t;if(t instanceof Response&&t.body)return t.body;if(typeof t=="object"&&t!==null&&"audio"in t){const{audio:e}=t;if(typeof e=="string")return C(e);if(e instanceof ReadableStream||e instanceof Uint8Array)return e}return new Uint8Array(0)};export{ft as a,pt as b,ht as c,yt as d,bt as e,xt as f,at as g,lt as i,mt as p,gt as r,ut as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsonSchema as c}from"@ai-sdk/provider-utils";import{LunoraError as h}from"@lunora/errors";import{r as u}from"./agent-ai-CP87uSoZ.mjs";const l=5,d="Search the web for current information. Returns up to a handful of results, each with a url, a title and (when the provider has one) a description. Use it for facts that may have changed after your training data, then cite the urls you relied on.",m=c({properties:{query:{description:"The search query, 1–1024 characters.",maxLength:1024,minLength:1,type:"string"}},required:["query"],type:"object"}),E=new Set(["BAD_REQUEST","INTERNAL","NOT_IMPLEMENTED"]),T=(t={})=>{const{description:a=d,limit:o=l,...n}=t;return{description:a,execute:async(s,i)=>{const r=u(i.env);if(!r)return"Web search is unavailable: this Worker has no `AI` binding. Answer from what you already know, and say that you could not search.";try{return(await r.websearch(s.query,{...n,limit:o})).items}catch(e){if(e instanceof h&&E.has(e.code))return`Web search failed: ${e.message}`;throw e}},inputSchema:m,isLunoraAgentTool:!0}};export{T as webSearchTool};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const l=(e,r,o)=>e?.[o]??r?.[o],f=(e,r,o,t)=>{const n=l(e,r,o);if(!(typeof n!="object"||n===null))return t.every(i=>typeof n[i]=="function")?n:void 0};export{f as r};
|