@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
package/dist/core.d.mts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { x as AgentBindingSpec, l as AgentRunFunction, F as AgentHandle, q as AgentConfig, A as AgentDefinition, a0 as AgentToolConfig, c as AgentToolDefinition, v as AgentFunctionReference, a6 as SkillConfig, b as SkillDefinition, k as AgentFunctionPaths, j as AgentRunInput, o as AgentRunResult } from "./packem_shared/types.d-Bzy_Qah6.mjs";
|
|
2
|
+
export type { w as AgentApprovalContext, s as AgentAsToolOptions, z as AgentEmailMapper, B as AgentEmailRun, h as AgentGenerate, D as AgentGenerateOptions, E as AgentGenerateResult, H as AgentInstructionsContext, J as AgentLiveEvent, K as AgentMemoryOptions, L as AgentMemorySource, p as AgentMessageRow, M as AgentMessageStatus, u as AgentModelInput, N as AgentOnReply, O as AgentOnStepFinish, P as AgentPrepareStep, Q as AgentPrepareStepInput, R as AgentPrepareStepResult, T as AgentProgressEvent, U as AgentReplyInfo, a as AgentReplyRef, V as AgentRunHandle, W as AgentRunOptions, X as AgentStepFinishInfo, Y as AgentStepInfo, m as AgentStepLike, n as AgentStreamGenerate, t as AgentSubToolInput, Z as AgentThreadStatus, _ as AgentTokenDelta, i as AgentTokenSink, $ as AgentToolCall, d as AgentToolContext, a1 as AgentUsage, a2 as AgentVoiceConfig, a3 as AgentWorkflowBindingLike, a4 as AgentWorkflowInstanceLike, r as AnyAgentTool, a5 as EnsureThreadOutcome } from "./packem_shared/types.d-Bzy_Qah6.mjs";
|
|
3
|
+
import { FlexibleSchema } from 'ai';
|
|
4
|
+
import { jsonSchema as jsonSchema$1, ValidationResult, Schema } from '@ai-sdk/provider-utils';
|
|
5
|
+
import { WorkflowDefinition } from '@lunora/workflow';
|
|
6
|
+
import '@lunora/mail/inbound';
|
|
7
|
+
/**
|
|
8
|
+
* Build the `ctx.agents` producer surface from the codegen-emitted spec list
|
|
9
|
+
* (`LUNORA_AGENTS`), mirroring the `ctx.queues` property-access pattern: each
|
|
10
|
+
* declared agent resolves by its export key (the generated class name) off the
|
|
11
|
+
* invoking context's `exports` — or `env`, on a host without workflow exports —
|
|
12
|
+
* lazily, so a missing agent only errors when it is actually started.
|
|
13
|
+
*
|
|
14
|
+
* `cancel` also needs to write the thread's status, so it dispatches the agent
|
|
15
|
+
* runtime's `agentPatchThread` mutation. Production leaves `dispatch` undefined
|
|
16
|
+
* and the env-backed `createDispatchRunner` (the same runner the workflow body
|
|
17
|
+
* uses — it POSTs to `/_lunora/scheduler/dispatch`) is built on demand; tests
|
|
18
|
+
* inject a `dispatch` double.
|
|
19
|
+
*
|
|
20
|
+
* `shardKey` is the shard of the ctx this producer rides (the generated shard passes
|
|
21
|
+
* its own). Every run started here carries it, so the run's tools reach the same
|
|
22
|
+
* tenant's `.shardBy(...)` data the starting mutation could; absent for the default shard.
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
declare const createAgentContext: (env: Record<string, unknown>, specs: ReadonlyArray<AgentBindingSpec>, context?: {
|
|
26
|
+
dispatch?: AgentRunFunction;
|
|
27
|
+
exports?: unknown;
|
|
28
|
+
shardKey?: string;
|
|
29
|
+
}) => Record<string, AgentHandle>;
|
|
30
|
+
/**
|
|
31
|
+
* Declare a durable agent. The definition compiles onto a Cloudflare Workflow
|
|
32
|
+
* (each LLM turn and each tool call a named durable step; thread messages
|
|
33
|
+
* persisted idempotently in DO SQLite), invoked from mutations/actions via
|
|
34
|
+
* `ctx.agents.NAME.run(...)` and observed live by subscribing to the
|
|
35
|
+
* `agents:agentMessages` query.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* // lunora/agents.ts
|
|
39
|
+
* import { defineAgent, defineAgentTool } from "@lunora/agent";
|
|
40
|
+
*
|
|
41
|
+
* export const support = defineAgent({
|
|
42
|
+
* instructions: "You are a helpful support agent.",
|
|
43
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
44
|
+
* tools: {
|
|
45
|
+
* getWeather: defineAgentTool({
|
|
46
|
+
* description: "Look up the current weather for a city.",
|
|
47
|
+
* execute: async ({ city }, { run }) => run(api.weather.lookup, { city }),
|
|
48
|
+
* inputSchema: jsonSchema({ properties: { city: { type: "string" } }, required: ["city"], type: "object" }),
|
|
49
|
+
* }),
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* Declaring an agent is enough — codegen auto-registers the `agents:*` runtime
|
|
55
|
+
* functions (from `agentComponent()`) and the `ctx.agents` producer surface.
|
|
56
|
+
* @experimental
|
|
57
|
+
*/
|
|
58
|
+
declare const defineAgent: (config: AgentConfig) => AgentDefinition;
|
|
59
|
+
/**
|
|
60
|
+
* Runtime brand check for a {@link AgentDefinition}.
|
|
61
|
+
* @experimental
|
|
62
|
+
*/
|
|
63
|
+
declare const isAgentDefinition: (value: unknown) => value is AgentDefinition;
|
|
64
|
+
/**
|
|
65
|
+
* Declare an agent tool — see `AgentToolDefinition` for why `execute` runs in
|
|
66
|
+
* the loop's durable step (with an `AgentToolContext`) rather than inside the
|
|
67
|
+
* model call.
|
|
68
|
+
* @experimental
|
|
69
|
+
*/
|
|
70
|
+
declare const defineAgentTool: <Input, Output>(config: AgentToolConfig<Input, Output>) => AgentToolDefinition<Input, Output>;
|
|
71
|
+
/**
|
|
72
|
+
* Author-supplied config for {@link functionTool}.
|
|
73
|
+
* @experimental
|
|
74
|
+
*/
|
|
75
|
+
interface FunctionToolOptions<Input> {
|
|
76
|
+
/** What the tool does — shown to the model (the model decides from it). */
|
|
77
|
+
description: string;
|
|
78
|
+
/** The input schema shown to the model (a zod schema or `jsonSchema(...)`). */
|
|
79
|
+
inputSchema: FlexibleSchema<Input>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Expose any Lunora query/mutation/action as an agent tool. The returned
|
|
83
|
+
* definition's `execute` dispatches the referenced function through the loop's
|
|
84
|
+
* existing `run` seam (the workflow `ctx.run`) — so there is no bespoke wrapper
|
|
85
|
+
* per tool, and the call runs inside the loop's named durable step exactly like
|
|
86
|
+
* any other tool.
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { functionTool } from "@lunora/agent";
|
|
90
|
+
* import { api } from "./_generated/api";
|
|
91
|
+
*
|
|
92
|
+
* export const support = defineAgent({
|
|
93
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
94
|
+
* tools: {
|
|
95
|
+
* lookupOrder: functionTool(api.orders.byId, {
|
|
96
|
+
* description: "Look up an order by its id.",
|
|
97
|
+
* inputSchema: jsonSchema({ properties: { id: { type: "string" } }, required: ["id"], type: "object" }),
|
|
98
|
+
* }),
|
|
99
|
+
* },
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* The function reference may be a typed `api.*` reference or a `"module:name"`
|
|
104
|
+
* path. The model-provided input is passed as the function's args, so
|
|
105
|
+
* `inputSchema` should mirror the referenced function's argument validator —
|
|
106
|
+
* PLUS the call's `idempotencyKey`, pinned onto the args after the model
|
|
107
|
+
* input (so out-of-schema model input can never override it). A function
|
|
108
|
+
* that wants to dedupe a side-effecting call across an at-least-once step
|
|
109
|
+
* retry declares `idempotencyKey: v.optional(v.string())` in its own args
|
|
110
|
+
* and checks it; a function that ignores it is unaffected — an args field
|
|
111
|
+
* the function's own validator doesn't declare is dropped, not rejected.
|
|
112
|
+
* @experimental
|
|
113
|
+
*/
|
|
114
|
+
declare const functionTool: <Input extends Record<string, unknown> = Record<string, unknown>, Output = unknown>(reference: AgentFunctionReference | string, options: FunctionToolOptions<Input>) => AgentToolDefinition<Input, Output>;
|
|
115
|
+
/**
|
|
116
|
+
* `jsonSchema` from `@ai-sdk/provider-utils`, built without importing it. That package's root
|
|
117
|
+
* evaluates zod (about a hundred modules) as soon as anything is imported from it, and every
|
|
118
|
+
* tool module here builds a schema at module scope, so the root import put zod in every Worker's
|
|
119
|
+
* startup graph that wires an agent. A schema is a plain object, so the agent builds its own; the
|
|
120
|
+
* SDK itself is only imported where a zod schema has to be converted (`code-tool`).
|
|
121
|
+
*/
|
|
122
|
+
declare const jsonSchema: <OBJECT = unknown>(schema: Parameters<typeof jsonSchema$1>[0], { validate }?: {
|
|
123
|
+
validate?: (value: unknown) => PromiseLike<ValidationResult<OBJECT>> | ValidationResult<OBJECT>;
|
|
124
|
+
}) => Schema<OBJECT>;
|
|
125
|
+
/**
|
|
126
|
+
* The shard DO's `ctx.scheduler`, with every agent target stamped with the scheduling
|
|
127
|
+
* shard (`RunOptions.shardKey`) unless the app named one. A function job only lands on a
|
|
128
|
+
* shard the app names, but a scheduled agent run is the same act as `ctx.agents.<name>.run`
|
|
129
|
+
* from this shard, so its tools read this tenant's data like an immediate run's do. The
|
|
130
|
+
* stamp travels on the scheduler record, which the worker trusts over the job's args
|
|
131
|
+
* (`WorkerOptions.agentWorkflows`); it is applied before the deferral facade buffers the
|
|
132
|
+
* call, so an outbox retry replays it.
|
|
133
|
+
* @experimental
|
|
134
|
+
*/
|
|
135
|
+
declare const withAgentScheduleShard: <S extends object>(scheduler: S, specs: ReadonlyArray<AgentBindingSpec>, shardKey: string) => S;
|
|
136
|
+
/**
|
|
137
|
+
* Declare a reusable skill: a bundle of expertise — an instruction fragment,
|
|
138
|
+
* tools, and retrieval `knowledge` — an agent composes in via
|
|
139
|
+
* `defineAgent({ skills: [...] })`. Reuse-first: a skill's `tools` carry the
|
|
140
|
+
* SAME `AnyAgentTool` shape agents already use (`functionTool` / `mcpTools` /
|
|
141
|
+
* `agentAsTool`), and `knowledge` reuses `memory`'s `AgentMemoryOptions`
|
|
142
|
+
* retrieval verbatim.
|
|
143
|
+
*
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { defineSkill, functionTool } from "@lunora/agent";
|
|
146
|
+
*
|
|
147
|
+
* export const billing = defineSkill({
|
|
148
|
+
* name: "billing",
|
|
149
|
+
* instructions: "When asked about invoices, cite the invoice id.",
|
|
150
|
+
* knowledge: { source: "rag:searchBillingDocs", topK: 4 },
|
|
151
|
+
* tools: {
|
|
152
|
+
* lookupInvoice: functionTool(api.billing.invoiceById, {
|
|
153
|
+
* description: "Look up an invoice by id.",
|
|
154
|
+
* inputSchema: jsonSchema({ properties: { id: { type: "string" } }, required: ["id"], type: "object" }),
|
|
155
|
+
* }),
|
|
156
|
+
* },
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* The merge into the agent's flat namespace (tool-name collisions, instruction
|
|
161
|
+
* ordering, per-skill knowledge retrieval) happens in `defineAgent` — a skill
|
|
162
|
+
* only validates its own `name`; tool-name validation is deferred to the merge,
|
|
163
|
+
* which owns the flat model-facing namespace.
|
|
164
|
+
* @experimental
|
|
165
|
+
*/
|
|
166
|
+
declare const defineSkill: (config: SkillConfig) => SkillDefinition;
|
|
167
|
+
/**
|
|
168
|
+
* Runtime brand check for a {@link SkillDefinition}.
|
|
169
|
+
* @experimental
|
|
170
|
+
*/
|
|
171
|
+
declare const isSkillDefinition: (value: unknown) => value is SkillDefinition;
|
|
172
|
+
/**
|
|
173
|
+
* Compile a `defineAgent` definition into the workflow the generated
|
|
174
|
+
* `<Name>AgentWorkflow` entrypoint class runs. Codegen emits, per agent:
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* import LunoraWorkflow from "@lunora/workflow/do";
|
|
178
|
+
* import { compileAgentWorkflow } from "@lunora/agent";
|
|
179
|
+
* import { support } from "../agents.js";
|
|
180
|
+
*
|
|
181
|
+
* export class SupportAgentWorkflow extends LunoraWorkflow<AgentRunInput, AgentRunResult> {
|
|
182
|
+
* public constructor(ctx: ConstructorParameters<typeof LunoraWorkflow>[0], env: Record<string, unknown>) {
|
|
183
|
+
* super(ctx, env, compileAgentWorkflow(support, "support"), "support");
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* The workflow ctx supplies durability (`step.do`) and the Lunora dispatcher
|
|
189
|
+
* (`run`); the loop supplies determinism (step naming + idempotent persists).
|
|
190
|
+
* @experimental
|
|
191
|
+
*/
|
|
192
|
+
declare const compileAgentWorkflow: (agent: AgentDefinition, exportName: string, options?: {
|
|
193
|
+
paths?: AgentFunctionPaths;
|
|
194
|
+
}) => WorkflowDefinition<AgentRunInput, AgentRunResult>;
|
|
195
|
+
export { type AgentBindingSpec, type AgentConfig, type AgentDefinition, type AgentFunctionPaths, type AgentFunctionReference, type AgentHandle, type AgentRunFunction, type AgentRunInput, type AgentRunResult, type AgentToolConfig, type AgentToolDefinition, type FunctionToolOptions, type SkillConfig, type SkillDefinition, compileAgentWorkflow,
|
|
196
|
+
/**
|
|
197
|
+
* The part of `@lunora/agent` a Worker evaluates at startup: the definition builders
|
|
198
|
+
* a `lunora/agents.ts` calls at module scope, and what the generated shard and agent
|
|
199
|
+
* Workflow classes import. Nothing here statically reaches the agent loop, the model
|
|
200
|
+
* adapters or the AI SDK (and its zod); `compileAgentWorkflow` loads them on the first
|
|
201
|
+
* run. The `@lunora/agent` barrel re-exports all of this plus the heavy tools and
|
|
202
|
+
* runtime, so importing from it puts them back in the startup graph.
|
|
203
|
+
*/
|
|
204
|
+
createAgentContext, defineAgent, defineAgentTool, defineSkill, functionTool, isAgentDefinition, isSkillDefinition, jsonSchema, withAgentScheduleShard };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { x as AgentBindingSpec, l as AgentRunFunction, F as AgentHandle, q as AgentConfig, A as AgentDefinition, a0 as AgentToolConfig, c as AgentToolDefinition, v as AgentFunctionReference, a6 as SkillConfig, b as SkillDefinition, k as AgentFunctionPaths, j as AgentRunInput, o as AgentRunResult } from "./packem_shared/types.d-Bzy_Qah6.js";
|
|
2
|
+
export type { w as AgentApprovalContext, s as AgentAsToolOptions, z as AgentEmailMapper, B as AgentEmailRun, h as AgentGenerate, D as AgentGenerateOptions, E as AgentGenerateResult, H as AgentInstructionsContext, J as AgentLiveEvent, K as AgentMemoryOptions, L as AgentMemorySource, p as AgentMessageRow, M as AgentMessageStatus, u as AgentModelInput, N as AgentOnReply, O as AgentOnStepFinish, P as AgentPrepareStep, Q as AgentPrepareStepInput, R as AgentPrepareStepResult, T as AgentProgressEvent, U as AgentReplyInfo, a as AgentReplyRef, V as AgentRunHandle, W as AgentRunOptions, X as AgentStepFinishInfo, Y as AgentStepInfo, m as AgentStepLike, n as AgentStreamGenerate, t as AgentSubToolInput, Z as AgentThreadStatus, _ as AgentTokenDelta, i as AgentTokenSink, $ as AgentToolCall, d as AgentToolContext, a1 as AgentUsage, a2 as AgentVoiceConfig, a3 as AgentWorkflowBindingLike, a4 as AgentWorkflowInstanceLike, r as AnyAgentTool, a5 as EnsureThreadOutcome } from "./packem_shared/types.d-Bzy_Qah6.js";
|
|
3
|
+
import { FlexibleSchema } from 'ai';
|
|
4
|
+
import { jsonSchema as jsonSchema$1, ValidationResult, Schema } from '@ai-sdk/provider-utils';
|
|
5
|
+
import { WorkflowDefinition } from '@lunora/workflow';
|
|
6
|
+
import '@lunora/mail/inbound';
|
|
7
|
+
/**
|
|
8
|
+
* Build the `ctx.agents` producer surface from the codegen-emitted spec list
|
|
9
|
+
* (`LUNORA_AGENTS`), mirroring the `ctx.queues` property-access pattern: each
|
|
10
|
+
* declared agent resolves by its export key (the generated class name) off the
|
|
11
|
+
* invoking context's `exports` — or `env`, on a host without workflow exports —
|
|
12
|
+
* lazily, so a missing agent only errors when it is actually started.
|
|
13
|
+
*
|
|
14
|
+
* `cancel` also needs to write the thread's status, so it dispatches the agent
|
|
15
|
+
* runtime's `agentPatchThread` mutation. Production leaves `dispatch` undefined
|
|
16
|
+
* and the env-backed `createDispatchRunner` (the same runner the workflow body
|
|
17
|
+
* uses — it POSTs to `/_lunora/scheduler/dispatch`) is built on demand; tests
|
|
18
|
+
* inject a `dispatch` double.
|
|
19
|
+
*
|
|
20
|
+
* `shardKey` is the shard of the ctx this producer rides (the generated shard passes
|
|
21
|
+
* its own). Every run started here carries it, so the run's tools reach the same
|
|
22
|
+
* tenant's `.shardBy(...)` data the starting mutation could; absent for the default shard.
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
declare const createAgentContext: (env: Record<string, unknown>, specs: ReadonlyArray<AgentBindingSpec>, context?: {
|
|
26
|
+
dispatch?: AgentRunFunction;
|
|
27
|
+
exports?: unknown;
|
|
28
|
+
shardKey?: string;
|
|
29
|
+
}) => Record<string, AgentHandle>;
|
|
30
|
+
/**
|
|
31
|
+
* Declare a durable agent. The definition compiles onto a Cloudflare Workflow
|
|
32
|
+
* (each LLM turn and each tool call a named durable step; thread messages
|
|
33
|
+
* persisted idempotently in DO SQLite), invoked from mutations/actions via
|
|
34
|
+
* `ctx.agents.NAME.run(...)` and observed live by subscribing to the
|
|
35
|
+
* `agents:agentMessages` query.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* // lunora/agents.ts
|
|
39
|
+
* import { defineAgent, defineAgentTool } from "@lunora/agent";
|
|
40
|
+
*
|
|
41
|
+
* export const support = defineAgent({
|
|
42
|
+
* instructions: "You are a helpful support agent.",
|
|
43
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
44
|
+
* tools: {
|
|
45
|
+
* getWeather: defineAgentTool({
|
|
46
|
+
* description: "Look up the current weather for a city.",
|
|
47
|
+
* execute: async ({ city }, { run }) => run(api.weather.lookup, { city }),
|
|
48
|
+
* inputSchema: jsonSchema({ properties: { city: { type: "string" } }, required: ["city"], type: "object" }),
|
|
49
|
+
* }),
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* Declaring an agent is enough — codegen auto-registers the `agents:*` runtime
|
|
55
|
+
* functions (from `agentComponent()`) and the `ctx.agents` producer surface.
|
|
56
|
+
* @experimental
|
|
57
|
+
*/
|
|
58
|
+
declare const defineAgent: (config: AgentConfig) => AgentDefinition;
|
|
59
|
+
/**
|
|
60
|
+
* Runtime brand check for a {@link AgentDefinition}.
|
|
61
|
+
* @experimental
|
|
62
|
+
*/
|
|
63
|
+
declare const isAgentDefinition: (value: unknown) => value is AgentDefinition;
|
|
64
|
+
/**
|
|
65
|
+
* Declare an agent tool — see `AgentToolDefinition` for why `execute` runs in
|
|
66
|
+
* the loop's durable step (with an `AgentToolContext`) rather than inside the
|
|
67
|
+
* model call.
|
|
68
|
+
* @experimental
|
|
69
|
+
*/
|
|
70
|
+
declare const defineAgentTool: <Input, Output>(config: AgentToolConfig<Input, Output>) => AgentToolDefinition<Input, Output>;
|
|
71
|
+
/**
|
|
72
|
+
* Author-supplied config for {@link functionTool}.
|
|
73
|
+
* @experimental
|
|
74
|
+
*/
|
|
75
|
+
interface FunctionToolOptions<Input> {
|
|
76
|
+
/** What the tool does — shown to the model (the model decides from it). */
|
|
77
|
+
description: string;
|
|
78
|
+
/** The input schema shown to the model (a zod schema or `jsonSchema(...)`). */
|
|
79
|
+
inputSchema: FlexibleSchema<Input>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Expose any Lunora query/mutation/action as an agent tool. The returned
|
|
83
|
+
* definition's `execute` dispatches the referenced function through the loop's
|
|
84
|
+
* existing `run` seam (the workflow `ctx.run`) — so there is no bespoke wrapper
|
|
85
|
+
* per tool, and the call runs inside the loop's named durable step exactly like
|
|
86
|
+
* any other tool.
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { functionTool } from "@lunora/agent";
|
|
90
|
+
* import { api } from "./_generated/api";
|
|
91
|
+
*
|
|
92
|
+
* export const support = defineAgent({
|
|
93
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
94
|
+
* tools: {
|
|
95
|
+
* lookupOrder: functionTool(api.orders.byId, {
|
|
96
|
+
* description: "Look up an order by its id.",
|
|
97
|
+
* inputSchema: jsonSchema({ properties: { id: { type: "string" } }, required: ["id"], type: "object" }),
|
|
98
|
+
* }),
|
|
99
|
+
* },
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* The function reference may be a typed `api.*` reference or a `"module:name"`
|
|
104
|
+
* path. The model-provided input is passed as the function's args, so
|
|
105
|
+
* `inputSchema` should mirror the referenced function's argument validator —
|
|
106
|
+
* PLUS the call's `idempotencyKey`, pinned onto the args after the model
|
|
107
|
+
* input (so out-of-schema model input can never override it). A function
|
|
108
|
+
* that wants to dedupe a side-effecting call across an at-least-once step
|
|
109
|
+
* retry declares `idempotencyKey: v.optional(v.string())` in its own args
|
|
110
|
+
* and checks it; a function that ignores it is unaffected — an args field
|
|
111
|
+
* the function's own validator doesn't declare is dropped, not rejected.
|
|
112
|
+
* @experimental
|
|
113
|
+
*/
|
|
114
|
+
declare const functionTool: <Input extends Record<string, unknown> = Record<string, unknown>, Output = unknown>(reference: AgentFunctionReference | string, options: FunctionToolOptions<Input>) => AgentToolDefinition<Input, Output>;
|
|
115
|
+
/**
|
|
116
|
+
* `jsonSchema` from `@ai-sdk/provider-utils`, built without importing it. That package's root
|
|
117
|
+
* evaluates zod (about a hundred modules) as soon as anything is imported from it, and every
|
|
118
|
+
* tool module here builds a schema at module scope, so the root import put zod in every Worker's
|
|
119
|
+
* startup graph that wires an agent. A schema is a plain object, so the agent builds its own; the
|
|
120
|
+
* SDK itself is only imported where a zod schema has to be converted (`code-tool`).
|
|
121
|
+
*/
|
|
122
|
+
declare const jsonSchema: <OBJECT = unknown>(schema: Parameters<typeof jsonSchema$1>[0], { validate }?: {
|
|
123
|
+
validate?: (value: unknown) => PromiseLike<ValidationResult<OBJECT>> | ValidationResult<OBJECT>;
|
|
124
|
+
}) => Schema<OBJECT>;
|
|
125
|
+
/**
|
|
126
|
+
* The shard DO's `ctx.scheduler`, with every agent target stamped with the scheduling
|
|
127
|
+
* shard (`RunOptions.shardKey`) unless the app named one. A function job only lands on a
|
|
128
|
+
* shard the app names, but a scheduled agent run is the same act as `ctx.agents.<name>.run`
|
|
129
|
+
* from this shard, so its tools read this tenant's data like an immediate run's do. The
|
|
130
|
+
* stamp travels on the scheduler record, which the worker trusts over the job's args
|
|
131
|
+
* (`WorkerOptions.agentWorkflows`); it is applied before the deferral facade buffers the
|
|
132
|
+
* call, so an outbox retry replays it.
|
|
133
|
+
* @experimental
|
|
134
|
+
*/
|
|
135
|
+
declare const withAgentScheduleShard: <S extends object>(scheduler: S, specs: ReadonlyArray<AgentBindingSpec>, shardKey: string) => S;
|
|
136
|
+
/**
|
|
137
|
+
* Declare a reusable skill: a bundle of expertise — an instruction fragment,
|
|
138
|
+
* tools, and retrieval `knowledge` — an agent composes in via
|
|
139
|
+
* `defineAgent({ skills: [...] })`. Reuse-first: a skill's `tools` carry the
|
|
140
|
+
* SAME `AnyAgentTool` shape agents already use (`functionTool` / `mcpTools` /
|
|
141
|
+
* `agentAsTool`), and `knowledge` reuses `memory`'s `AgentMemoryOptions`
|
|
142
|
+
* retrieval verbatim.
|
|
143
|
+
*
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { defineSkill, functionTool } from "@lunora/agent";
|
|
146
|
+
*
|
|
147
|
+
* export const billing = defineSkill({
|
|
148
|
+
* name: "billing",
|
|
149
|
+
* instructions: "When asked about invoices, cite the invoice id.",
|
|
150
|
+
* knowledge: { source: "rag:searchBillingDocs", topK: 4 },
|
|
151
|
+
* tools: {
|
|
152
|
+
* lookupInvoice: functionTool(api.billing.invoiceById, {
|
|
153
|
+
* description: "Look up an invoice by id.",
|
|
154
|
+
* inputSchema: jsonSchema({ properties: { id: { type: "string" } }, required: ["id"], type: "object" }),
|
|
155
|
+
* }),
|
|
156
|
+
* },
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* The merge into the agent's flat namespace (tool-name collisions, instruction
|
|
161
|
+
* ordering, per-skill knowledge retrieval) happens in `defineAgent` — a skill
|
|
162
|
+
* only validates its own `name`; tool-name validation is deferred to the merge,
|
|
163
|
+
* which owns the flat model-facing namespace.
|
|
164
|
+
* @experimental
|
|
165
|
+
*/
|
|
166
|
+
declare const defineSkill: (config: SkillConfig) => SkillDefinition;
|
|
167
|
+
/**
|
|
168
|
+
* Runtime brand check for a {@link SkillDefinition}.
|
|
169
|
+
* @experimental
|
|
170
|
+
*/
|
|
171
|
+
declare const isSkillDefinition: (value: unknown) => value is SkillDefinition;
|
|
172
|
+
/**
|
|
173
|
+
* Compile a `defineAgent` definition into the workflow the generated
|
|
174
|
+
* `<Name>AgentWorkflow` entrypoint class runs. Codegen emits, per agent:
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* import LunoraWorkflow from "@lunora/workflow/do";
|
|
178
|
+
* import { compileAgentWorkflow } from "@lunora/agent";
|
|
179
|
+
* import { support } from "../agents.js";
|
|
180
|
+
*
|
|
181
|
+
* export class SupportAgentWorkflow extends LunoraWorkflow<AgentRunInput, AgentRunResult> {
|
|
182
|
+
* public constructor(ctx: ConstructorParameters<typeof LunoraWorkflow>[0], env: Record<string, unknown>) {
|
|
183
|
+
* super(ctx, env, compileAgentWorkflow(support, "support"), "support");
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* The workflow ctx supplies durability (`step.do`) and the Lunora dispatcher
|
|
189
|
+
* (`run`); the loop supplies determinism (step naming + idempotent persists).
|
|
190
|
+
* @experimental
|
|
191
|
+
*/
|
|
192
|
+
declare const compileAgentWorkflow: (agent: AgentDefinition, exportName: string, options?: {
|
|
193
|
+
paths?: AgentFunctionPaths;
|
|
194
|
+
}) => WorkflowDefinition<AgentRunInput, AgentRunResult>;
|
|
195
|
+
export { type AgentBindingSpec, type AgentConfig, type AgentDefinition, type AgentFunctionPaths, type AgentFunctionReference, type AgentHandle, type AgentRunFunction, type AgentRunInput, type AgentRunResult, type AgentToolConfig, type AgentToolDefinition, type FunctionToolOptions, type SkillConfig, type SkillDefinition, compileAgentWorkflow,
|
|
196
|
+
/**
|
|
197
|
+
* The part of `@lunora/agent` a Worker evaluates at startup: the definition builders
|
|
198
|
+
* a `lunora/agents.ts` calls at module scope, and what the generated shard and agent
|
|
199
|
+
* Workflow classes import. Nothing here statically reaches the agent loop, the model
|
|
200
|
+
* adapters or the AI SDK (and its zod); `compileAgentWorkflow` loads them on the first
|
|
201
|
+
* run. The `@lunora/agent` barrel re-exports all of this plus the heavy tools and
|
|
202
|
+
* runtime, so importing from it puts them back in the startup graph.
|
|
203
|
+
*/
|
|
204
|
+
createAgentContext, defineAgent, defineAgentTool, defineSkill, functionTool, isAgentDefinition, isSkillDefinition, jsonSchema, withAgentScheduleShard };
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as t}from"./packem_shared/createAgentContext-C8k1y2Ot.mjs";import{defineAgent as n,defineAgentTool as r,isAgentDefinition as i}from"./packem_shared/defineAgent-6Ih7L9E9.mjs";import{functionTool as a}from"./packem_shared/functionTool-Cf433Hdo.mjs";import{default as m}from"./packem_shared/jsonSchema-fhoaBWpN.mjs";import{default as x}from"./packem_shared/withAgentScheduleShard-Bn3bdW5b.mjs";import{defineSkill as g,isSkillDefinition as u}from"./packem_shared/defineSkill-DGGvDWNq.mjs";import{default as c}from"./packem_shared/compileAgentWorkflow-yZB8fbYc.mjs";export{c as compileAgentWorkflow,t as createAgentContext,n as defineAgent,r as defineAgentTool,g as defineSkill,a as functionTool,i as isAgentDefinition,u as isSkillDefinition,m as jsonSchema,x as withAgentScheduleShard};
|
package/dist/inbound.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AgentDefinition } from "./packem_shared/types.d-
|
|
1
|
+
import { A as AgentDefinition } from "./packem_shared/types.d-Bzy_Qah6.mjs";
|
|
2
2
|
import '@lunora/mail/inbound';
|
|
3
3
|
import 'ai';
|
|
4
4
|
/**
|
|
@@ -7,12 +7,12 @@ import 'ai';
|
|
|
7
7
|
*/
|
|
8
8
|
interface AgentEmailTarget {
|
|
9
9
|
/**
|
|
10
|
-
* The agent definition —
|
|
11
|
-
*
|
|
10
|
+
* The agent definition — its `onEmail` mapper decides whether this agent claims
|
|
11
|
+
* the message and the run to start; `resolveEmailShard` picks the run's shard.
|
|
12
12
|
*/
|
|
13
|
-
agent: Pick<AgentDefinition, "onEmail">;
|
|
14
|
-
/** The
|
|
15
|
-
|
|
13
|
+
agent: Pick<AgentDefinition, "onEmail" | "resolveEmailShard">;
|
|
14
|
+
/** The agent's export key (its generated class name), resolved off `ctx.exports` or `env`. */
|
|
15
|
+
className: string;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The worker `email(message, env, ctx)` callback. Typed with `unknown`
|
|
@@ -24,10 +24,12 @@ type InboundAgentEmailHandler = (message: unknown, env: unknown, context: unknow
|
|
|
24
24
|
/**
|
|
25
25
|
* Build the inbound `email()` handler for one or more `onEmail` agents. The
|
|
26
26
|
* returned callback parses the message, then walks `targets` in order and starts
|
|
27
|
-
* a durable run for the first agent whose `onEmail` mapper returns a run.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* `
|
|
27
|
+
* a durable run for the first agent whose `onEmail` mapper returns a run.
|
|
28
|
+
*
|
|
29
|
+
* Two dispatch failures bounce the message permanently rather than retrying: a
|
|
30
|
+
* missing Workflow binding (run codegen/dev so `wrangler.jsonc` declares it) and
|
|
31
|
+
* a run carrying the reserved workflow branch-marker key. See
|
|
32
|
+
* {@link rejectPermanently}.
|
|
31
33
|
* @experimental
|
|
32
34
|
*/
|
|
33
35
|
declare const dispatchAgentEmail: (targets: ReadonlyArray<AgentEmailTarget>) => InboundAgentEmailHandler;
|
package/dist/inbound.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AgentDefinition } from "./packem_shared/types.d-
|
|
1
|
+
import { A as AgentDefinition } from "./packem_shared/types.d-Bzy_Qah6.js";
|
|
2
2
|
import '@lunora/mail/inbound';
|
|
3
3
|
import 'ai';
|
|
4
4
|
/**
|
|
@@ -7,12 +7,12 @@ import 'ai';
|
|
|
7
7
|
*/
|
|
8
8
|
interface AgentEmailTarget {
|
|
9
9
|
/**
|
|
10
|
-
* The agent definition —
|
|
11
|
-
*
|
|
10
|
+
* The agent definition — its `onEmail` mapper decides whether this agent claims
|
|
11
|
+
* the message and the run to start; `resolveEmailShard` picks the run's shard.
|
|
12
12
|
*/
|
|
13
|
-
agent: Pick<AgentDefinition, "onEmail">;
|
|
14
|
-
/** The
|
|
15
|
-
|
|
13
|
+
agent: Pick<AgentDefinition, "onEmail" | "resolveEmailShard">;
|
|
14
|
+
/** The agent's export key (its generated class name), resolved off `ctx.exports` or `env`. */
|
|
15
|
+
className: string;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The worker `email(message, env, ctx)` callback. Typed with `unknown`
|
|
@@ -24,10 +24,12 @@ type InboundAgentEmailHandler = (message: unknown, env: unknown, context: unknow
|
|
|
24
24
|
/**
|
|
25
25
|
* Build the inbound `email()` handler for one or more `onEmail` agents. The
|
|
26
26
|
* returned callback parses the message, then walks `targets` in order and starts
|
|
27
|
-
* a durable run for the first agent whose `onEmail` mapper returns a run.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* `
|
|
27
|
+
* a durable run for the first agent whose `onEmail` mapper returns a run.
|
|
28
|
+
*
|
|
29
|
+
* Two dispatch failures bounce the message permanently rather than retrying: a
|
|
30
|
+
* missing Workflow binding (run codegen/dev so `wrangler.jsonc` declares it) and
|
|
31
|
+
* a run carrying the reserved workflow branch-marker key. See
|
|
32
|
+
* {@link rejectPermanently}.
|
|
31
33
|
* @experimental
|
|
32
34
|
*/
|
|
33
35
|
declare const dispatchAgentEmail: (targets: ReadonlyArray<AgentEmailTarget>) => InboundAgentEmailHandler;
|
package/dist/inbound.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createInboundEmailHandler as m,authenticatesFrom as d,parseInboundEmail as u}from"@lunora/mail/inbound";import{h as p,B as g}from"./packem_shared/branch-marker-boZ00zmk.mjs";import{w as f}from"./packem_shared/run-shard-B7iMrAI0.mjs";import{r as E}from"./packem_shared/workflow-binding-Dm9hBzx_.mjs";import{r as h}from"./packem_shared/inbound-shard-A7S7dnf_.mjs";const v="message could not be processed",c=(o,s)=>{console.error("@lunora/agent/inbound: bouncing message —",s),o.message.setReject(v)},I=o=>{const s=m({dispatch:async(a,e)=>{for(const r of o){const t=r.agent.onEmail;if(!t)continue;const n=await t(a);if(n==null)continue;const i=E(e.env,e.ctx?.exports,r.className,["create"]);if(i===void 0){c(e,`@lunora/agent: no "${r.className}" on ctx.exports or env for an inbound agent — run codegen/dev so wrangler.jsonc declares it`);return}if(p(n)){c(e,`@lunora/agent: inbound run params ${g}`);return}const l=await h(r.agent.resolveEmailShard,{email:a,envelopeTo:e.message.to},"resolveEmailShard");await i.create({params:f(n,l)});return}},parse:u,verify:d});return async(a,e,r)=>s(a,e,r)};export{I as dispatchAgentEmail};
|