@lunora/agent 1.0.0-alpha.25 → 1.0.0-alpha.250
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-mg6qrlU6-CT5Q5dbp.mjs +1 -0
- package/dist/packem_shared/SecretUnavailableError-BCp40Leh.mjs +1 -0
- package/dist/packem_shared/VoiceSessionDO-6V4O0pCj.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-BkCwoICu.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-DiaoOW2a.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-BwEzrHXM.mjs +1 -0
- package/dist/packem_shared/createAgentGenerate-C6mp2LqI.mjs +3 -0
- package/dist/packem_shared/defineAgent-CEx4uu1I.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-CmalZhT_.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-B2jdLcLZ.mjs +1 -0
- package/dist/packem_shared/runVoiceTurn-B9ULrImo.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-JcdqUZfZ.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 +40 -0
- package/dist/reply.d.ts +40 -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
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { A as AgentDefinition,
|
|
2
|
-
export type {
|
|
1
|
+
import { A as AgentDefinition, e as AgentCompact, f as AgentEpisodeExtract, g as AgentGraphExtract, h as AgentGenerate, i as AgentTokenSink, j as AgentRunInput, k as AgentFunctionPaths, l as AgentRunFunction, m as AgentStepLike, n as AgentStreamGenerate, o as AgentRunResult, p as AgentMessageRow, q as AgentConfig, b as SkillDefinition, r as AnyAgentTool, s as AgentAsToolOptions, t as AgentSubToolInput, c as AgentToolDefinition, u as AgentBindingSpec, v as AgentHandle, w as AgentToolConfig, x as AgentFunctionReference, y as AgentModelInput, d as AgentToolContext, z as SkillConfig } from "./packem_shared/types.d-vAmttAsE.mjs";
|
|
2
|
+
export type { B as AgentApprovalContext, C as AgentEmailMapper, D as AgentEmailRun, E as AgentGenerateOptions, F as AgentGenerateResult, G as AgentInstructionsContext, H as AgentLiveEvent, J as AgentMemoryOptions, K as AgentMemorySource, L as AgentMessageStatus, M as AgentOnReply, N as AgentOnStepFinish, O as AgentPrepareStep, P as AgentPrepareStepInput, Q as AgentPrepareStepResult, R as AgentProgressEvent, T as AgentReplyInfo, a as AgentReplyRef, U as AgentRunHandle, V as AgentRunOptions, W as AgentStepFinishInfo, X as AgentStepInfo, Y as AgentThreadStatus, Z as AgentTokenDelta, _ as AgentToolCall, $ as AgentUsage, a0 as AgentVoiceConfig, a1 as AgentWorkflowBindingLike, a2 as AgentWorkflowInstanceLike, a3 as EnsureThreadOutcome } from "./packem_shared/types.d-vAmttAsE.mjs";
|
|
3
3
|
export { type AgentComponent, agentComponent, agentExtension } from "./component.mjs";
|
|
4
4
|
import { FlexibleSchema, LanguageModel, ModelMessage } from 'ai';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
import { createAi } from '@lunora/ai';
|
|
5
|
+
export { type BrowserRenderResult, type BrowserToolInput, type BrowserToolOptions, type ContainerFsToolOptions, type ContainerToolInput, type ContainerToolOptions, type FsToolInput, type FsToolOptions, type JsCodeToolInput, type JsCodeToolOptions, type JsCodeToolResult, browserTool, containerFsTool, containerTool, fsTool, jsCodeTool } from "./sandbox.mjs";
|
|
6
|
+
export { agentClassName, agentDefaultName, voiceBindingName, voiceClassName } from "./naming.mjs";
|
|
7
|
+
import { createAi, AiWebSearchProvider, AiWebSearchItem } from '@lunora/ai/create';
|
|
8
8
|
import { WorkflowDefinition } from '@lunora/workflow';
|
|
9
9
|
import '@lunora/mail/inbound';
|
|
10
10
|
import '@lunora/server';
|
|
@@ -23,6 +23,8 @@ interface AgentLoopOptions {
|
|
|
23
23
|
env: Record<string, unknown>;
|
|
24
24
|
/** The agent's `lunora/agents.ts` export name (thread attribution). */
|
|
25
25
|
exportName: string;
|
|
26
|
+
/** The invoking context's `ctx.exports`, where Cloudflare exposes this and sibling agents. */
|
|
27
|
+
exports?: unknown;
|
|
26
28
|
/**
|
|
27
29
|
* The run-end episode-summary seam — production wires AI SDK `generateText`.
|
|
28
30
|
* Absent (the default) disables episode recording, so an agent with no
|
|
@@ -183,7 +185,7 @@ declare const agentAsTool: (options: AgentAsToolOptions) => AgentToolDefinition<
|
|
|
183
185
|
interface ToolScriptStep {
|
|
184
186
|
/** A stable name later steps reference the output by. */
|
|
185
187
|
id: string;
|
|
186
|
-
/** The tool's input; values may embed `{ "$from": "
|
|
188
|
+
/** The tool's input; values may embed `{ "$from": "<stepId>", "$path": "a.b" }` refs. */
|
|
187
189
|
input?: Record<string, unknown>;
|
|
188
190
|
/** The tool to call — one of the tools handed to {@link codeTool}. */
|
|
189
191
|
tool: string;
|
|
@@ -229,8 +231,8 @@ interface CodeToolOptions {
|
|
|
229
231
|
* SCRIPT that composes several of the tools you hand `codeTool` — chaining a
|
|
230
232
|
* later call's input to an earlier call's output — and the whole thing runs in a
|
|
231
233
|
* single turn. This is a SAFE interpreted data-flow between whitelisted tools
|
|
232
|
-
* (no `eval`, no isolate), so it runs natively in workerd; arbitrary
|
|
233
|
-
*
|
|
234
|
+
* (no `eval`, no isolate), so it runs natively in workerd; for arbitrary code
|
|
235
|
+
* in a Worker Loader isolate, see `jsCodeTool`.
|
|
234
236
|
*
|
|
235
237
|
* Each composed tool dispatches through the same durable context a normal call
|
|
236
238
|
* gets (inheriting RLS), with a per-step idempotency key. A code-mode script runs
|
|
@@ -239,6 +241,16 @@ interface CodeToolOptions {
|
|
|
239
241
|
* keep approval-gated tools as normal top-level tools. Gate the whole script via
|
|
240
242
|
* `opts.needsApproval` instead.
|
|
241
243
|
*
|
|
244
|
+
* STEP-OUTPUT CONTRACT — **every step's output must be JSON-serializable.** Each
|
|
245
|
+
* step runs inside its own durable `step.do`, so the workflow host serializes
|
|
246
|
+
* the returned value before the next step (or the tool result) ever sees it. A
|
|
247
|
+
* `Date` comes back as an ISO string, a `Map`/`Set` as `{}`, `undefined` as
|
|
248
|
+
* `null` or a dropped key, and a `bigint` throws outright. That applies to the
|
|
249
|
+
* value a later step reads through `{ "$from": … }` just as much as to the
|
|
250
|
+
* returned `results` — the hand-off is durable state, not an in-memory one. A
|
|
251
|
+
* composed tool that wants to pass a rich value should return its JSON form
|
|
252
|
+
* (`date.toISOString()`, `[...map]`) and let the consuming step rebuild it.
|
|
253
|
+
*
|
|
242
254
|
* ```ts
|
|
243
255
|
* import { codeTool, defineAgent, functionTool } from "@lunora/agent";
|
|
244
256
|
*
|
|
@@ -259,8 +271,9 @@ declare const codeTool: (tools: Record<string, AnyAgentTool>, options?: CodeTool
|
|
|
259
271
|
/**
|
|
260
272
|
* Build the `ctx.agents` producer surface from the codegen-emitted spec list
|
|
261
273
|
* (`LUNORA_AGENTS`), mirroring the `ctx.queues` property-access pattern: each
|
|
262
|
-
* declared agent resolves its
|
|
263
|
-
*
|
|
274
|
+
* declared agent resolves by its export key (the generated class name) off the
|
|
275
|
+
* invoking context's `exports` — or `env`, on a host without workflow exports —
|
|
276
|
+
* lazily, so a missing agent only errors when it is actually started.
|
|
264
277
|
*
|
|
265
278
|
* `cancel` also needs to write the thread's status, so it dispatches the agent
|
|
266
279
|
* runtime's `agentPatchThread` mutation. Production leaves `dispatch` undefined
|
|
@@ -269,7 +282,10 @@ declare const codeTool: (tools: Record<string, AnyAgentTool>, options?: CodeTool
|
|
|
269
282
|
* inject a `dispatch` double.
|
|
270
283
|
* @experimental
|
|
271
284
|
*/
|
|
272
|
-
declare const createAgentContext: (env: Record<string, unknown>, specs: ReadonlyArray<AgentBindingSpec>,
|
|
285
|
+
declare const createAgentContext: (env: Record<string, unknown>, specs: ReadonlyArray<AgentBindingSpec>, context?: {
|
|
286
|
+
dispatch?: AgentRunFunction;
|
|
287
|
+
exports?: unknown;
|
|
288
|
+
}) => Record<string, AgentHandle>;
|
|
273
289
|
/**
|
|
274
290
|
* Declare a durable agent. The definition compiles onto a Cloudflare Workflow
|
|
275
291
|
* (each LLM turn and each tool call a named durable step; thread messages
|
|
@@ -344,8 +360,14 @@ interface FunctionToolOptions<Input> {
|
|
|
344
360
|
* ```
|
|
345
361
|
*
|
|
346
362
|
* The function reference may be a typed `api.*` reference or a `"module:name"`
|
|
347
|
-
* path. The model-provided input is passed
|
|
348
|
-
* `inputSchema` should mirror the referenced function's argument validator
|
|
363
|
+
* path. The model-provided input is passed as the function's args, so
|
|
364
|
+
* `inputSchema` should mirror the referenced function's argument validator —
|
|
365
|
+
* PLUS the call's `idempotencyKey`, pinned onto the args after the model
|
|
366
|
+
* input (so out-of-schema model input can never override it). A function
|
|
367
|
+
* that wants to dedupe a side-effecting call across an at-least-once step
|
|
368
|
+
* retry declares `idempotencyKey: v.optional(v.string())` in its own args
|
|
369
|
+
* and checks it; a function that ignores it is unaffected — an args field
|
|
370
|
+
* the function's own validator doesn't declare is dropped, not rejected.
|
|
349
371
|
* @experimental
|
|
350
372
|
*/
|
|
351
373
|
declare const functionTool: <Input extends Record<string, unknown> = Record<string, unknown>, Output = unknown>(reference: AgentFunctionReference | string, options: FunctionToolOptions<Input>) => AgentToolDefinition<Input, Output>;
|
|
@@ -471,6 +493,17 @@ interface McpToolsOptions {
|
|
|
471
493
|
command?: string;
|
|
472
494
|
/** Identify this client to the server on connect. Default `"lunora-agent"`. */
|
|
473
495
|
name?: string;
|
|
496
|
+
/**
|
|
497
|
+
* Gate an adapted tool's call behind a human approval. Defaults to
|
|
498
|
+
* **unattended** (no gate) — matching today's behavior. An MCP tool's
|
|
499
|
+
* result feeds back into the model's context (`adaptMcpResult`), so a
|
|
500
|
+
* hostile downstream server can pair indirect prompt injection with an
|
|
501
|
+
* unattended mutating tool call; pass a boolean to gate every adapted
|
|
502
|
+
* tool the same way, or a predicate `(toolName, input) => boolean` to
|
|
503
|
+
* gate per tool (evaluated from replay-stable input, so keep it
|
|
504
|
+
* deterministic).
|
|
505
|
+
*/
|
|
506
|
+
needsApproval?: ((toolName: string, input: Record<string, unknown>) => boolean) | boolean;
|
|
474
507
|
/** Only adapt these tool names (default: every tool the server lists). */
|
|
475
508
|
only?: ReadonlyArray<string>;
|
|
476
509
|
/** Prefix added to each adapted tool's key (disambiguate multiple servers). */
|
|
@@ -510,6 +543,9 @@ declare const adaptMcpResult: (result: McpCallResult) => unknown;
|
|
|
510
543
|
* every call. In the Workers runtime only the HTTP/SSE transports run (stdio
|
|
511
544
|
* does not) — pass `url`, or inject an already-connected `client` for a custom
|
|
512
545
|
* transport (also the test seam).
|
|
546
|
+
*
|
|
547
|
+
* Every adapted tool runs UNATTENDED by default (no approval gate) — pass
|
|
548
|
+
* `opts.needsApproval` to change that; see {@link McpToolsOptions.needsApproval}.
|
|
513
549
|
* @experimental
|
|
514
550
|
*/
|
|
515
551
|
declare const mcpTools: (options: McpToolsOptions) => Promise<Record<string, AgentToolDefinition<Record<string, unknown>>>>;
|
|
@@ -556,6 +592,82 @@ declare const DEFAULT_AGENT_FUNCTION_PATHS: AgentFunctionPaths;
|
|
|
556
592
|
* @experimental
|
|
557
593
|
*/
|
|
558
594
|
declare const toFunctionReference: (source: AgentFunctionReference | string) => AgentFunctionReference;
|
|
595
|
+
/** The model's input to {@link requestSecretTool}: what the secret is for, shown to the person asked. */
|
|
596
|
+
interface SecretRequestInput {
|
|
597
|
+
label: string;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Thrown by {@link withSecret} when the value is no longer takeable. The loop
|
|
601
|
+
* records it as a deterministic tool failure, so the model can recover rather
|
|
602
|
+
* than the durable step retrying a read that can never succeed.
|
|
603
|
+
*/
|
|
604
|
+
declare class SecretUnavailableError extends Error {
|
|
605
|
+
readonly code = "SECRET_UNAVAILABLE";
|
|
606
|
+
constructor();
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* An agent tool that asks the human for a secret value (an API key, a token) and
|
|
610
|
+
* hands the model only an opaque `{ secretRef }` in return. The loop pauses the
|
|
611
|
+
* run until the owner supplies the value through `agents:agentSupplySecret`, or
|
|
612
|
+
* declines through `agents:agentDeclineSecret`. `execute` is never called: the
|
|
613
|
+
* loop resolves this tool itself.
|
|
614
|
+
*
|
|
615
|
+
* `consumer` names the one tool allowed to read the value. The model can pass the
|
|
616
|
+
* `secretRef` to any tool, but only the declared consumer's {@link withSecret} call
|
|
617
|
+
* takes it, so a prompt-injected model cannot route the value elsewhere.
|
|
618
|
+
*
|
|
619
|
+
* Codegen wires the secret store when a source in `lunora/` value-imports this tool
|
|
620
|
+
* from `@lunora/agent`: by a named import, a namespace import that reads it, or a
|
|
621
|
+
* relative barrel that re-exports it. Without that wiring the supply mutation refuses,
|
|
622
|
+
* and the refusal names the missing import. Requires a host that rates `secretValues`
|
|
623
|
+
* as supported.
|
|
624
|
+
*
|
|
625
|
+
* ```ts
|
|
626
|
+
* import { defineAgent, requestSecretTool } from "@lunora/agent";
|
|
627
|
+
*
|
|
628
|
+
* export const billing = defineAgent({
|
|
629
|
+
* tools: {
|
|
630
|
+
* requestApiKey: requestSecretTool({
|
|
631
|
+
* consumer: "chargeCard",
|
|
632
|
+
* description: "Ask the user for their payment-provider API key.",
|
|
633
|
+
* }),
|
|
634
|
+
* chargeCard: functionTool({ ... }), // reads the value with withSecret
|
|
635
|
+
* },
|
|
636
|
+
* });
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* The value transits the supply mutation's arguments, which are marked
|
|
640
|
+
* `v.sensitive`: the request log masks them. The run's history records only the
|
|
641
|
+
* request id.
|
|
642
|
+
* @experimental
|
|
643
|
+
*/
|
|
644
|
+
declare const requestSecretTool: (options: {
|
|
645
|
+
consumer: string;
|
|
646
|
+
description: string;
|
|
647
|
+
}) => AgentToolDefinition<SecretRequestInput, {
|
|
648
|
+
secretRef: string;
|
|
649
|
+
}>;
|
|
650
|
+
/**
|
|
651
|
+
* Read a human-supplied secret inside the tool that the request declared as its
|
|
652
|
+
* `consumer`, hand it to `use`, and return only what `use` returns. The value never
|
|
653
|
+
* leaves the callback: it is not a step output, not a tool result and not a message.
|
|
654
|
+
* The read is its own durable step named for this call, so a retry of the same step
|
|
655
|
+
* re-takes the value (the claimant is this step's name), while a different call
|
|
656
|
+
* cannot.
|
|
657
|
+
*
|
|
658
|
+
* Call it from inside a tool's `execute`. The discard runs as a separate durable step
|
|
659
|
+
* only after the take succeeded and `use` returned, so a call that is refused (the
|
|
660
|
+
* wrong tool, another thread, an expired request) cannot burn a value the declared
|
|
661
|
+
* consumer still needs. If `use` keeps failing, the value stays until its TTL expires,
|
|
662
|
+
* which is the backstop for a crash between the take and the discard. `use` must not
|
|
663
|
+
* return or log the value. A result that carries it is refused (the call fails with
|
|
664
|
+
* `LunoraError`) rather than journalled. An error that carries it is redacted before
|
|
665
|
+
* it propagates, so the step's retry, the failure the loop records and telemetry never
|
|
666
|
+
* see the value; `traceToolExecution` records the tool's input and output.
|
|
667
|
+
* @throws {SecretUnavailableError} when the request is unknown, not supplied, declared for another consumer, or from another thread
|
|
668
|
+
* @experimental
|
|
669
|
+
*/
|
|
670
|
+
declare const withSecret: <Result>(context: AgentToolContext, secretRef: string, use: (secret: string) => Promise<Result> | Result) => Promise<Result>;
|
|
559
671
|
/**
|
|
560
672
|
* Declare a reusable skill: a bundle of expertise — an instruction fragment,
|
|
561
673
|
* tools, and retrieval `knowledge` — an agent composes in via
|
|
@@ -592,12 +704,28 @@ declare const defineSkill: (config: SkillConfig) => SkillDefinition;
|
|
|
592
704
|
* @experimental
|
|
593
705
|
*/
|
|
594
706
|
declare const isSkillDefinition: (value: unknown) => value is SkillDefinition;
|
|
707
|
+
/**
|
|
708
|
+
* Wrap untrusted text for inclusion in a prompt. The text sits between a tag
|
|
709
|
+
* whose id is random per call, so payload text cannot forge the closing tag (it
|
|
710
|
+
* cannot know the id), and any `<` or `>` in it is escaped so it cannot form a
|
|
711
|
+
* tag at all. A mention or cashtag (`@`, `$`) not glued to a word, and a slash
|
|
712
|
+
* command `/` at the start of a token, get a zero-width space after them. Given a header map, the headers are rendered
|
|
713
|
+
* above the body with credential-like values redacted. A one-line note after the
|
|
714
|
+
* block tells the model the enclosed data is not to be followed as instructions.
|
|
715
|
+
*
|
|
716
|
+
* Use it on the text a mapper hands the model, e.g. `input: wrapUntrusted(email.text ?? "")`.
|
|
717
|
+
* @experimental
|
|
718
|
+
*/
|
|
719
|
+
declare const wrapUntrusted: (value: string, headers?: Headers | Readonly<Record<string, string>>) => string;
|
|
595
720
|
/**
|
|
596
721
|
* A control frame the server sends the client as a JSON text message (audio
|
|
597
722
|
* rides separate binary frames). `ready` announces the negotiated codec on
|
|
598
723
|
* connect; `user_transcript` carries the STT result; `assistant_delta` streams
|
|
599
724
|
* the live LLM text; `assistant_done` is the final turn text; `interrupted`
|
|
600
|
-
* acks a barge-in; `
|
|
725
|
+
* acks a barge-in; `assistant_discarded` says the turn failed, so the deltas
|
|
726
|
+
* already streamed for it are not an answer; `error` reports a failure. An
|
|
727
|
+
* `error` alone does not end a turn: a speech-synthesis failure reports one and
|
|
728
|
+
* the turn still completes.
|
|
601
729
|
* @experimental
|
|
602
730
|
*/
|
|
603
731
|
type VoiceServerFrame = {
|
|
@@ -615,6 +743,8 @@ type VoiceServerFrame = {
|
|
|
615
743
|
} | {
|
|
616
744
|
text: string;
|
|
617
745
|
type: "user_transcript";
|
|
746
|
+
} | {
|
|
747
|
+
type: "assistant_discarded";
|
|
618
748
|
} | {
|
|
619
749
|
type: "interrupted";
|
|
620
750
|
};
|
|
@@ -674,6 +804,13 @@ interface VoiceTurnResult {
|
|
|
674
804
|
interface RunVoiceTurnOptions {
|
|
675
805
|
/** The agent whose thread + models back this session. */
|
|
676
806
|
agent: AgentDefinition;
|
|
807
|
+
/**
|
|
808
|
+
* History-compaction seam — the SAME one the durable loop uses. Voice and
|
|
809
|
+
* text turns share one thread, so an agent that declares `compaction` must
|
|
810
|
+
* get it here too; absent (or with no `compaction` config) the turn takes
|
|
811
|
+
* the byte-identical uncompacted path.
|
|
812
|
+
*/
|
|
813
|
+
compact?: AgentCompact;
|
|
677
814
|
/** Stable per-socket id — the message-key prefix that keeps persisted rows idempotent. */
|
|
678
815
|
connectionId: string;
|
|
679
816
|
/** The Worker env (resolves a dynamic `instructions` thunk). */
|
|
@@ -755,6 +892,8 @@ declare class VoiceSessionDO {
|
|
|
755
892
|
protected readonly streamGenerate: AgentStreamGenerate;
|
|
756
893
|
protected readonly sttModel: string;
|
|
757
894
|
protected readonly ttsModel: string;
|
|
895
|
+
/** Turn budget for one socket — see {@link DEFAULT_MAX_SESSION_TURNS}. */
|
|
896
|
+
private readonly maxSessionTurns;
|
|
758
897
|
private readonly audioBuffers;
|
|
759
898
|
private readonly bufferedBytes;
|
|
760
899
|
private readonly controllers;
|
|
@@ -793,6 +932,8 @@ declare class VoiceSessionDO {
|
|
|
793
932
|
private synthesizeWithSignal;
|
|
794
933
|
/** Abort an in-flight turn and free a socket's transient buffers. */
|
|
795
934
|
private cleanupSocket;
|
|
935
|
+
/** Close a socket that broke a session bound, swallowing an already-closed error (never throw from a handler). */
|
|
936
|
+
private closeSocket;
|
|
796
937
|
/** Send a JSON control frame, swallowing a closed-socket error (never throw from a handler). */
|
|
797
938
|
private send;
|
|
798
939
|
/** Send a binary audio frame, swallowing a closed-socket error. */
|
|
@@ -806,17 +947,65 @@ declare class VoiceSessionDO {
|
|
|
806
947
|
*/
|
|
807
948
|
private waitForSocketDrain;
|
|
808
949
|
}
|
|
950
|
+
/**
|
|
951
|
+
* Config for {@link webSearchTool}.
|
|
952
|
+
* @experimental
|
|
953
|
+
*/
|
|
954
|
+
interface WebSearchToolOptions {
|
|
955
|
+
/** Alias of a provider key stored on the gateway to bill instead of the `default` alias. */
|
|
956
|
+
byokAlias?: string;
|
|
957
|
+
/** Overrides the description shown to the model. */
|
|
958
|
+
description?: string;
|
|
959
|
+
/**
|
|
960
|
+
* The AI Gateway that brokers and bills the search. Defaults to
|
|
961
|
+
* `LUNORA_AI_GATEWAY_ID`, else the account's `default` gateway.
|
|
962
|
+
*/
|
|
963
|
+
gatewayId?: string;
|
|
964
|
+
/** Maximum results per search, 1–10. Defaults to 5: every result is prompt the next turn pays for. */
|
|
965
|
+
limit?: number;
|
|
966
|
+
/** Defaults to the Web Search API's own default (`"ceramic"`). */
|
|
967
|
+
provider?: AiWebSearchProvider;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* What the model passes.
|
|
971
|
+
* @experimental
|
|
972
|
+
*/
|
|
973
|
+
interface WebSearchToolInput {
|
|
974
|
+
query: string;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* A batteries-included agent tool over the Cloudflare Web Search API (beta,
|
|
978
|
+
* `ctx.ai.websearch`), so an agent can ground an answer in live results.
|
|
979
|
+
* A search bills a provider key stored on the gateway (`byokAlias`, else the
|
|
980
|
+
* `default` alias) when there is one, otherwise AI Gateway credits; every
|
|
981
|
+
* provider runs under Zero Data Retention.
|
|
982
|
+
*
|
|
983
|
+
* It calls the `AI` binding straight from the tool's durable step: a search
|
|
984
|
+
* is a read, so the at-least-once step retry repeats nothing but a query, and
|
|
985
|
+
* there is no dispatcher action to register.
|
|
986
|
+
*
|
|
987
|
+
* ```ts
|
|
988
|
+
* import { defineAgent, webSearchTool } from "@lunora/agent";
|
|
989
|
+
*
|
|
990
|
+
* export const researcher = defineAgent({
|
|
991
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
992
|
+
* tools: { search: webSearchTool({ provider: "exa" }) },
|
|
993
|
+
* });
|
|
994
|
+
* ```
|
|
995
|
+
* @experimental
|
|
996
|
+
*/
|
|
997
|
+
declare const webSearchTool: (options?: WebSearchToolOptions) => AgentToolDefinition<WebSearchToolInput, AiWebSearchItem[] | string>;
|
|
809
998
|
/**
|
|
810
999
|
* Compile a `defineAgent` definition into the workflow the generated
|
|
811
|
-
*
|
|
1000
|
+
* `<Name>AgentWorkflow` entrypoint class runs. Codegen emits, per agent:
|
|
812
1001
|
*
|
|
813
1002
|
* ```ts
|
|
814
1003
|
* import LunoraWorkflow from "@lunora/workflow/do";
|
|
815
1004
|
* import { compileAgentWorkflow } from "@lunora/agent";
|
|
816
1005
|
* import { support } from "../agents.js";
|
|
817
1006
|
*
|
|
818
|
-
* export class SupportAgentWorkflow extends LunoraWorkflow
|
|
819
|
-
* public constructor(ctx: ConstructorParameters
|
|
1007
|
+
* export class SupportAgentWorkflow extends LunoraWorkflow<AgentRunInput, AgentRunResult> {
|
|
1008
|
+
* public constructor(ctx: ConstructorParameters<typeof LunoraWorkflow>[0], env: Record<string, unknown>) {
|
|
820
1009
|
* super(ctx, env, compileAgentWorkflow(support, "support"), "support");
|
|
821
1010
|
* }
|
|
822
1011
|
* }
|
|
@@ -829,4 +1018,4 @@ declare class VoiceSessionDO {
|
|
|
829
1018
|
declare const compileAgentWorkflow: (agent: AgentDefinition, exportName: string, options?: {
|
|
830
1019
|
paths?: AgentFunctionPaths;
|
|
831
1020
|
}) => WorkflowDefinition<AgentRunInput, AgentRunResult>;
|
|
832
|
-
export { AGENT_MODULE, type AgentAsToolOptions, type AgentBindingSpec, type AgentConfig, type AgentDefinition, type AgentFunctionPaths, type AgentFunctionReference, type AgentGenerate, type AgentHandle, type AgentLoopOptions, type AgentMemoryReadInput, type AgentMemorySearchHit, type AgentMemorySearchInput, type AgentMemorySearchResult, type AgentMessageRow, type AgentModelInput, type AgentRunFunction, type AgentRunInput, type AgentRunResult, type AgentStepLike, type AgentStreamGenerate, type AgentSubToolInput, type AgentTokenSink, type AgentToolConfig, type AgentToolDefinition, type AnyAgentTool, type CodeToolOptions, DEFAULT_AGENT_FUNCTION_PATHS, type FunctionToolOptions, type McpCallResult, type McpClientLike, type McpContentPart, type McpToolInfo, type McpToolsOptions, type RunVoiceTurnOptions, SANDBOX_INVOKE_PATH, SANDBOX_MODULE, type SkillConfig, type SkillDefinition, type ToolScript, type ToolScriptResult, type ToolScriptStep, type VoiceAudioSource, type VoiceClientFrame, type VoiceSend, type VoiceSendAudio, type VoiceServerFrame, VoiceSessionDO, type VoiceSynthesize, type VoiceTranscribe, type VoiceTurnResult, adaptMcpResult, agentAsTool, buildModelMessages, codeTool, collectAgenticMemoryTools, compileAgentWorkflow, createAgentContext, createAgentGenerate, createEpisodeExtract, createGraphExtract, createStreamGenerate, defineAgent, defineAgentTool, defineSkill, functionTool, isAgentDefinition, isSkillDefinition, mcpTools, resolveAgentModel, runAgentLoop, runVoiceTurn, splitForCompaction, toFunctionReference, toSearchResults };
|
|
1021
|
+
export { AGENT_MODULE, type AgentAsToolOptions, type AgentBindingSpec, type AgentConfig, type AgentDefinition, type AgentFunctionPaths, type AgentFunctionReference, type AgentGenerate, type AgentHandle, type AgentLoopOptions, type AgentMemoryReadInput, type AgentMemorySearchHit, type AgentMemorySearchInput, type AgentMemorySearchResult, type AgentMessageRow, type AgentModelInput, type AgentRunFunction, type AgentRunInput, type AgentRunResult, type AgentStepLike, type AgentStreamGenerate, type AgentSubToolInput, type AgentTokenSink, type AgentToolConfig, type AgentToolContext, type AgentToolDefinition, type AnyAgentTool, type CodeToolOptions, DEFAULT_AGENT_FUNCTION_PATHS, type FunctionToolOptions, type McpCallResult, type McpClientLike, type McpContentPart, type McpToolInfo, type McpToolsOptions, type RunVoiceTurnOptions, SANDBOX_INVOKE_PATH, SANDBOX_MODULE, type SecretRequestInput, SecretUnavailableError, type SkillConfig, type SkillDefinition, type ToolScript, type ToolScriptResult, type ToolScriptStep, type VoiceAudioSource, type VoiceClientFrame, type VoiceSend, type VoiceSendAudio, type VoiceServerFrame, VoiceSessionDO, type VoiceSynthesize, type VoiceTranscribe, type VoiceTurnResult, type WebSearchToolInput, type WebSearchToolOptions, adaptMcpResult, agentAsTool, buildModelMessages, codeTool, collectAgenticMemoryTools, compileAgentWorkflow, createAgentContext, createAgentGenerate, createEpisodeExtract, createGraphExtract, createStreamGenerate, defineAgent, defineAgentTool, defineSkill, functionTool, isAgentDefinition, isSkillDefinition, mcpTools, requestSecretTool, resolveAgentModel, runAgentLoop, runVoiceTurn, splitForCompaction, toFunctionReference, toSearchResults, webSearchTool, withSecret, wrapUntrusted };
|