@lunora/agent 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +39 -31
- package/dist/channels.d.ts +39 -31
- package/dist/channels.mjs +1 -181
- package/dist/component.d.mts +57 -68
- package/dist/component.d.ts +57 -68
- package/dist/component.mjs +2 -407
- package/dist/inbound.d.mts +20 -20
- package/dist/inbound.d.ts +20 -20
- package/dist/inbound.mjs +1 -32
- package/dist/index.d.mts +474 -490
- package/dist/index.d.ts +474 -490
- package/dist/index.mjs +1 -18
- package/dist/naming.d.mts +19 -19
- package/dist/naming.d.ts +19 -19
- package/dist/naming.mjs +1 -8
- package/dist/packem_shared/AGENT_MODULE-BXx-tSCe.mjs +1 -0
- package/dist/packem_shared/VoiceSessionDO-CTaBSdXk.mjs +1 -0
- package/dist/packem_shared/adaptMcpResult-18G7zpFo.mjs +2 -0
- package/dist/packem_shared/agentAsTool-CJCTyAQG.mjs +1 -0
- package/dist/packem_shared/base64-jU-Ci6Tu.mjs +1 -0
- package/dist/packem_shared/braintrustTelemetry-CnOI5WAw.mjs +1 -0
- package/dist/packem_shared/buildModelMessages-Dm2wVNQy.mjs +5 -0
- package/dist/packem_shared/codeTool-DYJVy-bH.mjs +1 -0
- package/dist/packem_shared/collectAgenticMemoryTools-DBcP8dUa.mjs +1 -0
- package/dist/packem_shared/combineTelemetry-oLCV_EPV.mjs +1 -0
- package/dist/packem_shared/common-Dck97z3Y.mjs +1 -0
- package/dist/packem_shared/compileAgentWorkflow-C4xqSw82.mjs +1 -0
- package/dist/packem_shared/consoleTelemetry-CaoI-NGg.mjs +1 -0
- package/dist/packem_shared/createAgentContext-B1IfI7ro.mjs +1 -0
- package/dist/packem_shared/createAgentGenerate-BUVImo85.mjs +3 -0
- package/dist/packem_shared/createDispatchRunner-CQ8HXscn-BrqT0bIG.mjs +1 -0
- package/dist/packem_shared/defineAgent-CKhzzmys.mjs +3 -0
- package/dist/packem_shared/defineSkill-DfJxCwfZ.mjs +1 -0
- package/dist/packem_shared/functionTool-CWHhkYqd.mjs +1 -0
- package/dist/packem_shared/graph-component-B2YmC2eL.mjs +2 -0
- package/dist/packem_shared/memory-DNRyyp1b.mjs +1 -0
- package/dist/packem_shared/normalizeEntityName-BQpyssvL.mjs +1 -0
- package/dist/packem_shared/otlpTelemetry-DcW9mOLV.mjs +1 -0
- package/dist/packem_shared/runAgentLoop-DNAt-pGz.mjs +3 -0
- package/dist/packem_shared/runVoiceTurn-PkMsfG_v.mjs +1 -0
- package/dist/packem_shared/sandboxComponent-BhaGHsQZ.mjs +1 -0
- package/dist/packem_shared/sentryTelemetry-Dr2aPuvl.mjs +1 -0
- package/dist/packem_shared/types.d-boAM2Yi1.d.mts +1114 -0
- package/dist/packem_shared/types.d-boAM2Yi1.d.ts +1114 -0
- package/dist/sandbox.d.mts +126 -122
- package/dist/sandbox.d.ts +126 -122
- package/dist/sandbox.mjs +1 -109
- package/dist/telemetry/index.d.mts +185 -104
- package/dist/telemetry/index.d.ts +185 -104
- package/dist/telemetry/index.mjs +1 -4
- package/package.json +8 -8
- package/dist/packem_shared/AGENT_MODULE-Dnt_-AAT.mjs +0 -24
- package/dist/packem_shared/VoiceSessionDO-DLoXsHGF.mjs +0 -297
- package/dist/packem_shared/adaptMcpResult-wtNMvLoP.mjs +0 -65
- package/dist/packem_shared/agentAsTool-Dt8NlU6k.mjs +0 -94
- package/dist/packem_shared/base64-BVwtgRJV.mjs +0 -18
- package/dist/packem_shared/braintrustTelemetry-wuGDErob.mjs +0 -47
- package/dist/packem_shared/buildModelMessages-BWFigaoo.mjs +0 -69
- package/dist/packem_shared/codeTool-CjgJOC9t.mjs +0 -122
- package/dist/packem_shared/collectAgenticMemoryTools-QrzpV-WX.mjs +0 -97
- package/dist/packem_shared/combineTelemetry-DCyaaWAI.mjs +0 -43
- package/dist/packem_shared/common-DAeFCot5.mjs +0 -61
- package/dist/packem_shared/compileAgentWorkflow-BxJjHgtD.mjs +0 -55
- package/dist/packem_shared/consoleTelemetry-z2MiP1jt.mjs +0 -93
- package/dist/packem_shared/createAgentContext-4xJGXNR4.mjs +0 -50
- package/dist/packem_shared/createAgentGenerate-BQv9YJ01.mjs +0 -192
- package/dist/packem_shared/createDispatchRunner-DSbp_dph-ZHTtxy3f.mjs +0 -69
- package/dist/packem_shared/defineAgent-D6maSbVc.mjs +0 -148
- package/dist/packem_shared/defineSkill-Ctf_S-rz.mjs +0 -22
- package/dist/packem_shared/functionTool-D6lCa2jB.mjs +0 -20
- package/dist/packem_shared/graph-component-aoUwO-f0.mjs +0 -216
- package/dist/packem_shared/memory-D4FPcBsX.mjs +0 -12
- package/dist/packem_shared/normalizeEntityName-CyEEWFkR.mjs +0 -3
- package/dist/packem_shared/runAgentLoop-Dhg4ZNvw.mjs +0 -493
- package/dist/packem_shared/runVoiceTurn-LnqLvCRR.mjs +0 -211
- package/dist/packem_shared/sandboxComponent-DR3pTwBL.mjs +0 -194
- package/dist/packem_shared/sentryTelemetry-CgqFJyLO.mjs +0 -36
- package/dist/packem_shared/types.d-BhJFTvz_.d.mts +0 -1114
- package/dist/packem_shared/types.d-BhJFTvz_.d.ts +0 -1114
package/dist/sandbox.mjs
CHANGED
|
@@ -1,109 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { jsonSchema } from 'ai';
|
|
3
|
-
import { toFunctionReference, SANDBOX_INVOKE_PATH } from './packem_shared/AGENT_MODULE-Dnt_-AAT.mjs';
|
|
4
|
-
|
|
5
|
-
const SANDBOX_REF = toFunctionReference(SANDBOX_INVOKE_PATH);
|
|
6
|
-
const DEFAULT_BROWSER_DESCRIPTION = 'Drive a headless browser: screenshot a page, render it to PDF, read its HTML content, or scrape it. Set `op` to "screenshot" | "pdf" | "content" | "scrape" and pass the target `url`.';
|
|
7
|
-
const DEFAULT_CONTAINER_DESCRIPTION = 'Talk to a sandboxed container: `fetch` an HTTP path on it, or `exec` a command inside it. Set `op` to "fetch" (with `path`) or "exec" (with `command`).';
|
|
8
|
-
const DEFAULT_FS_DESCRIPTION = 'Read and write files in a persistent sandbox filesystem. Set `op` to "ls" (list a directory), "read", "write" (with `content`), "rm", or "stat", and pass `path`.';
|
|
9
|
-
const defaultFsGate = (input) => input.op === "write" || input.op === "rm";
|
|
10
|
-
const FS_TOOL_SCHEMA = jsonSchema({
|
|
11
|
-
properties: {
|
|
12
|
-
content: { description: "write: the file contents.", type: "string" },
|
|
13
|
-
op: { description: "The filesystem operation to run.", enum: ["ls", "read", "write", "rm", "stat"], type: "string" },
|
|
14
|
-
path: { description: "The file or directory path, relative to the sandbox root.", type: "string" }
|
|
15
|
-
},
|
|
16
|
-
required: ["op"],
|
|
17
|
-
type: "object"
|
|
18
|
-
});
|
|
19
|
-
const BROWSER_TOOL_SCHEMA = jsonSchema({
|
|
20
|
-
properties: {
|
|
21
|
-
fullPage: { description: "screenshot: capture the full scrollable page rather than just the viewport.", type: "boolean" },
|
|
22
|
-
op: { description: "The browser operation to run.", enum: ["screenshot", "scrape", "pdf", "content"], type: "string" },
|
|
23
|
-
selector: { description: "scrape: optional CSS selector hint to narrow the extraction.", type: "string" },
|
|
24
|
-
type: { description: "screenshot: image encoding (default png).", enum: ["png", "jpeg"], type: "string" },
|
|
25
|
-
url: { description: "The URL to operate on.", type: "string" }
|
|
26
|
-
},
|
|
27
|
-
required: ["op", "url"],
|
|
28
|
-
type: "object"
|
|
29
|
-
});
|
|
30
|
-
const CONTAINER_EXEC_ROUTE = "/exec";
|
|
31
|
-
const CONTAINER_PATH_QUERY_SPLIT = /[?#]/u;
|
|
32
|
-
const normalizeContainerPath = (path) => {
|
|
33
|
-
const [raw = ""] = (path ?? "").split(CONTAINER_PATH_QUERY_SPLIT);
|
|
34
|
-
const segments = [];
|
|
35
|
-
for (const segment of raw.split("/")) {
|
|
36
|
-
if (segment === "" || segment === ".") {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (segment === "..") {
|
|
40
|
-
segments.pop();
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
segments.push(segment);
|
|
44
|
-
}
|
|
45
|
-
return `/${segments.join("/")}`;
|
|
46
|
-
};
|
|
47
|
-
const defaultContainerGate = (input) => {
|
|
48
|
-
if (input.op === "exec") {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
return normalizeContainerPath(input.path) === CONTAINER_EXEC_ROUTE;
|
|
52
|
-
};
|
|
53
|
-
const CONTAINER_TOOL_SCHEMA = jsonSchema({
|
|
54
|
-
properties: {
|
|
55
|
-
args: { description: "exec: command arguments.", items: { type: "string" }, type: "array" },
|
|
56
|
-
body: { description: "fetch: request body.", type: "string" },
|
|
57
|
-
command: { description: "exec: the command to run.", type: "string" },
|
|
58
|
-
method: { description: "fetch: HTTP method (default GET).", type: "string" },
|
|
59
|
-
op: { description: "The container operation to run.", enum: ["fetch", "exec"], type: "string" },
|
|
60
|
-
path: { description: "fetch: request path on the container (e.g. /health).", type: "string" }
|
|
61
|
-
},
|
|
62
|
-
required: ["op"],
|
|
63
|
-
type: "object"
|
|
64
|
-
});
|
|
65
|
-
const browserTool = (options = {}) => {
|
|
66
|
-
return {
|
|
67
|
-
description: options.description ?? DEFAULT_BROWSER_DESCRIPTION,
|
|
68
|
-
// Pin `kind` LAST so out-of-schema model input can never override it.
|
|
69
|
-
execute: (input, context) => context.run(SANDBOX_REF, { ...input, kind: "browser" }),
|
|
70
|
-
inputSchema: BROWSER_TOOL_SCHEMA,
|
|
71
|
-
isLunoraAgentTool: true,
|
|
72
|
-
...options.needsApproval === void 0 ? {} : { needsApproval: options.needsApproval }
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
const containerTool = (name, options = {}) => {
|
|
76
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
77
|
-
throw new LunoraError("INTERNAL", "@lunora/agent: containerTool requires a container `name` (the ctx.containers.<name> key from lunora/containers.ts)");
|
|
78
|
-
}
|
|
79
|
-
const needsApproval = options.needsApproval ?? defaultContainerGate;
|
|
80
|
-
return {
|
|
81
|
-
description: options.description ?? DEFAULT_CONTAINER_DESCRIPTION,
|
|
82
|
-
// Pin `kind`/`name` LAST so out-of-schema model input can never override
|
|
83
|
-
// the authoritative container the author pinned.
|
|
84
|
-
execute: (input, context) => context.run(SANDBOX_REF, { ...input, kind: "container", name }),
|
|
85
|
-
inputSchema: CONTAINER_TOOL_SCHEMA,
|
|
86
|
-
isLunoraAgentTool: true,
|
|
87
|
-
needsApproval
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
const fsTool = (bucket, options = {}) => {
|
|
91
|
-
if (typeof bucket !== "string" || bucket.length === 0) {
|
|
92
|
-
throw new LunoraError("INTERNAL", "@lunora/agent: fsTool requires an R2 `bucket` binding name (the r2_bucket declared in wrangler.jsonc)");
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
description: options.description ?? DEFAULT_FS_DESCRIPTION,
|
|
96
|
-
// Pin kind/bucket/root LAST so out-of-schema model input can never override
|
|
97
|
-
// the authoritative bucket + sandbox root the author pinned. `root` may be
|
|
98
|
-
// a function of the ctx (per-run/owner isolation), resolved here.
|
|
99
|
-
execute: (input, context) => {
|
|
100
|
-
const root = typeof options.root === "function" ? options.root(context) : options.root ?? "";
|
|
101
|
-
return context.run(SANDBOX_REF, { ...input, bucket, kind: "fs", root });
|
|
102
|
-
},
|
|
103
|
-
inputSchema: FS_TOOL_SCHEMA,
|
|
104
|
-
isLunoraAgentTool: true,
|
|
105
|
-
needsApproval: options.needsApproval ?? defaultFsGate
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export { browserTool, containerTool, fsTool };
|
|
1
|
+
import{LunoraError as p}from"@lunora/errors";import{jsonSchema as i}from"ai";import{toFunctionReference as a,SANDBOX_INVOKE_PATH as c}from"./packem_shared/AGENT_MODULE-BXx-tSCe.mjs";const s=a(c),d='Drive a headless browser: screenshot a page, render it to PDF, read its HTML content, or scrape it. Set `op` to "screenshot" | "pdf" | "content" | "scrape" and pass the target `url`.',u='Talk to a sandboxed container: `fetch` an HTTP path on it, or `exec` a command inside it. Set `op` to "fetch" (with `path`) or "exec" (with `command`).',h='Read and write files in a persistent sandbox filesystem. Set `op` to "ls" (list a directory), "read", "write" (with `content`), "rm", or "stat", and pass `path`.',l=e=>e.op==="write"||e.op==="rm",m=i({properties:{content:{description:"write: the file contents.",type:"string"},op:{description:"The filesystem operation to run.",enum:["ls","read","write","rm","stat"],type:"string"},path:{description:"The file or directory path, relative to the sandbox root.",type:"string"}},required:["op"],type:"object"}),g=i({properties:{fullPage:{description:"screenshot: capture the full scrollable page rather than just the viewport.",type:"boolean"},op:{description:"The browser operation to run.",enum:["screenshot","scrape","pdf","content"],type:"string"},selector:{description:"scrape: optional CSS selector hint to narrow the extraction.",type:"string"},type:{description:"screenshot: image encoding (default png).",enum:["png","jpeg"],type:"string"},url:{description:"The URL to operate on.",type:"string"}},required:["op","url"],type:"object"}),f="/exec",y=/[?#]/u,T=e=>{const[t=""]=(e??"").split(y),o=[];for(const r of t.split("/"))if(!(r===""||r===".")){if(r===".."){o.pop();continue}o.push(r)}return`/${o.join("/")}`},w=new Set(["DELETE","PATCH","POST","PUT"]),b=e=>e.op==="exec"||T(e.path)===f?!0:w.has((e.method??"GET").toUpperCase()),x=i({properties:{args:{description:"exec: command arguments.",items:{type:"string"},type:"array"},body:{description:"fetch: request body.",type:"string"},command:{description:"exec: the command to run.",type:"string"},method:{description:"fetch: HTTP method (default GET).",type:"string"},op:{description:"The container operation to run.",enum:["fetch","exec"],type:"string"},path:{description:"fetch: request path on the container (e.g. /health).",type:"string"}},required:["op"],type:"object"}),E=(e={})=>({description:e.description??d,execute:(t,o)=>o.run(s,{...t,kind:"browser"}),inputSchema:g,isLunoraAgentTool:!0,...e.needsApproval===void 0?{}:{needsApproval:e.needsApproval}}),L=(e,t={})=>{if(typeof e!="string"||e.length===0)throw new p("INTERNAL","@lunora/agent: containerTool requires a container `name` (the ctx.containers.<name> key from lunora/containers.ts)");const o=t.needsApproval??b;return{description:t.description??u,execute:(r,n)=>n.run(s,{...r,kind:"container",name:e}),inputSchema:x,isLunoraAgentTool:!0,needsApproval:o}},j=(e,t={})=>{if(typeof e!="string"||e.length===0)throw new p("INTERNAL","@lunora/agent: fsTool requires an R2 `bucket` binding name (the r2_bucket declared in wrangler.jsonc)");return{description:t.description??h,execute:(o,r)=>{const n=typeof t.root=="function"?t.root(r):t.root??"";return r.run(s,{...o,bucket:e,kind:"fs",root:n})},inputSchema:m,isLunoraAgentTool:!0,needsApproval:t.needsApproval??l}};export{E as browserTool,L as containerTool,j as fsTool};
|
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { Telemetry } from 'ai';
|
|
2
2
|
/**
|
|
3
|
-
* Privacy options shared by every telemetry integration in this package.
|
|
4
|
-
*
|
|
5
|
-
* Both flags default to **FALSE**. Without an explicit opt-in, no prompt,
|
|
6
|
-
* message, tool input, generated model text, or tool output is ever forwarded
|
|
7
|
-
* to a downstream tracer — only structural metadata (model id, finish reason,
|
|
8
|
-
* token counts, tool name, timing, success/failure) is recorded. This is the
|
|
9
|
-
* privacy-safe default: turn recording on deliberately, per integration.
|
|
10
|
-
* @experimental
|
|
11
|
-
*/
|
|
3
|
+
* Privacy options shared by every telemetry integration in this package.
|
|
4
|
+
*
|
|
5
|
+
* Both flags default to **FALSE**. Without an explicit opt-in, no prompt,
|
|
6
|
+
* message, tool input, generated model text, or tool output is ever forwarded
|
|
7
|
+
* to a downstream tracer — only structural metadata (model id, finish reason,
|
|
8
|
+
* token counts, tool name, timing, success/failure) is recorded. This is the
|
|
9
|
+
* privacy-safe default: turn recording on deliberately, per integration.
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
12
|
interface CommonOptions {
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
* When `true`, record model/tool **input** — prompts, messages, and tool
|
|
15
|
+
* call arguments. Default `false`.
|
|
16
|
+
*/
|
|
17
17
|
recordInputs?: boolean;
|
|
18
18
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
* When `true`, record model/tool **output** — generated text and tool
|
|
20
|
+
* results. Default `false`.
|
|
21
|
+
*/
|
|
22
22
|
recordOutputs?: boolean;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* The span handle a {@link BraintrustLike.traced} callback receives.
|
|
26
|
-
* @experimental
|
|
27
|
-
*/
|
|
25
|
+
* The span handle a {@link BraintrustLike.traced} callback receives.
|
|
26
|
+
* @experimental
|
|
27
|
+
*/
|
|
28
28
|
interface BraintrustSpan {
|
|
29
29
|
/** Attach structured fields to the current span. */
|
|
30
30
|
log: (event: Record<string, unknown>) => void;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* The minimal, **structural** slice of the `braintrust` SDK this bridge needs.
|
|
34
|
-
* `braintrust` is intentionally **not** a dependency — the app passes its own
|
|
35
|
-
* initialized logger, so this package stays dependency-free and works with any
|
|
36
|
-
* compatible Braintrust SDK version.
|
|
37
|
-
* @experimental
|
|
38
|
-
*/
|
|
33
|
+
* The minimal, **structural** slice of the `braintrust` SDK this bridge needs.
|
|
34
|
+
* `braintrust` is intentionally **not** a dependency — the app passes its own
|
|
35
|
+
* initialized logger, so this package stays dependency-free and works with any
|
|
36
|
+
* compatible Braintrust SDK version.
|
|
37
|
+
* @experimental
|
|
38
|
+
*/
|
|
39
39
|
interface BraintrustLike {
|
|
40
40
|
/** Run `callback` inside a new traced span and return its result. */
|
|
41
41
|
traced: <T>(callback: (span: BraintrustSpan) => T, args?: {
|
|
@@ -44,92 +44,173 @@ interface BraintrustLike {
|
|
|
44
44
|
}) => T;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* Options for {@link braintrustTelemetry}.
|
|
48
|
-
* @experimental
|
|
49
|
-
*/
|
|
47
|
+
* Options for {@link braintrustTelemetry}.
|
|
48
|
+
* @experimental
|
|
49
|
+
*/
|
|
50
50
|
interface BraintrustTelemetryOptions extends CommonOptions {
|
|
51
51
|
/** Span-name prefix for the language-model call (e.g. the agent name). */
|
|
52
52
|
functionId?: string;
|
|
53
53
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
* The caller's initialized Braintrust logger (dependency-injected). Import
|
|
55
|
+
* and initialize `braintrust` in your app and pass it as `logger`.
|
|
56
|
+
*/
|
|
57
57
|
logger: BraintrustLike;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* A dependency-injected Braintrust bridge for the ai@7 telemetry surface.
|
|
61
|
-
*
|
|
62
|
-
* It wraps model calls (`type: "llm"`) and tool executions (`type: "tool"`) in
|
|
63
|
-
* `logger.traced` spans and logs structural metadata. Prompts / tool arguments
|
|
64
|
-
* are logged only when `recordInputs` is set; generated text / tool results
|
|
65
|
-
* only when `recordOutputs` is set. `onError` opens a span and logs the error.
|
|
66
|
-
*
|
|
67
|
-
* The app owns Braintrust initialization; pass the logger in as `logger`.
|
|
68
|
-
* @experimental
|
|
69
|
-
*/
|
|
60
|
+
* A dependency-injected Braintrust bridge for the ai@7 telemetry surface.
|
|
61
|
+
*
|
|
62
|
+
* It wraps model calls (`type: "llm"`) and tool executions (`type: "tool"`) in
|
|
63
|
+
* `logger.traced` spans and logs structural metadata. Prompts / tool arguments
|
|
64
|
+
* are logged only when `recordInputs` is set; generated text / tool results
|
|
65
|
+
* only when `recordOutputs` is set. `onError` opens a span and logs the error.
|
|
66
|
+
*
|
|
67
|
+
* The app owns Braintrust initialization; pass the logger in as `logger`.
|
|
68
|
+
* @experimental
|
|
69
|
+
*/
|
|
70
70
|
declare const braintrustTelemetry: (options: BraintrustTelemetryOptions) => Telemetry;
|
|
71
71
|
/**
|
|
72
|
-
* Combine several {@link Telemetry} integrations into a single one that fans
|
|
73
|
-
* every lifecycle callback out to all of them and nests the two execution
|
|
74
|
-
* wrappers so multiple span-context wrappers compose correctly.
|
|
75
|
-
*
|
|
76
|
-
* Value callbacks (`onStart`, `onStepEnd`, `onToolExecutionEnd`, …) invoke each
|
|
77
|
-
* integration's matching callback (guarding `undefined`) and await them all in
|
|
78
|
-
* parallel. The wrappers (`executeLanguageModelCall`, `executeTool`) are
|
|
79
|
-
* composed by nesting right-to-left; integrations without a wrapper are skipped,
|
|
80
|
-
* and with none defined the plain `execute` still runs.
|
|
81
|
-
* @experimental
|
|
82
|
-
*/
|
|
72
|
+
* Combine several {@link Telemetry} integrations into a single one that fans
|
|
73
|
+
* every lifecycle callback out to all of them and nests the two execution
|
|
74
|
+
* wrappers so multiple span-context wrappers compose correctly.
|
|
75
|
+
*
|
|
76
|
+
* Value callbacks (`onStart`, `onStepEnd`, `onToolExecutionEnd`, …) invoke each
|
|
77
|
+
* integration's matching callback (guarding `undefined`) and await them all in
|
|
78
|
+
* parallel. The wrappers (`executeLanguageModelCall`, `executeTool`) are
|
|
79
|
+
* composed by nesting right-to-left; integrations without a wrapper are skipped,
|
|
80
|
+
* and with none defined the plain `execute` still runs.
|
|
81
|
+
* @experimental
|
|
82
|
+
*/
|
|
83
83
|
declare const combineTelemetry: (...integrations: Telemetry[]) => Telemetry;
|
|
84
84
|
/**
|
|
85
|
-
* Severity level passed to a {@link ConsoleLogger}.
|
|
86
|
-
* @experimental
|
|
87
|
-
*/
|
|
85
|
+
* Severity level passed to a {@link ConsoleLogger}.
|
|
86
|
+
* @experimental
|
|
87
|
+
*/
|
|
88
88
|
type ConsoleLogLevel = "error" | "info" | "warn";
|
|
89
89
|
/**
|
|
90
|
-
* Structured log sink. Receives a level, a static human message, and a bag of
|
|
91
|
-
* structured fields (never interpolated into the message, so log processors can
|
|
92
|
-
* index them). The default sink writes to `globalThis.console`.
|
|
93
|
-
* @experimental
|
|
94
|
-
*/
|
|
90
|
+
* Structured log sink. Receives a level, a static human message, and a bag of
|
|
91
|
+
* structured fields (never interpolated into the message, so log processors can
|
|
92
|
+
* index them). The default sink writes to `globalThis.console`.
|
|
93
|
+
* @experimental
|
|
94
|
+
*/
|
|
95
95
|
type ConsoleLogger = (level: ConsoleLogLevel, message: string, fields: Record<string, unknown>) => void;
|
|
96
96
|
/**
|
|
97
|
-
* Options for {@link consoleTelemetry}.
|
|
98
|
-
* @experimental
|
|
99
|
-
*/
|
|
97
|
+
* Options for {@link consoleTelemetry}.
|
|
98
|
+
* @experimental
|
|
99
|
+
*/
|
|
100
100
|
interface ConsoleTelemetryOptions extends CommonOptions {
|
|
101
101
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
* Identifier prefixed into every log message (e.g. the agent name). Helps
|
|
103
|
+
* correlate lines when several agents share one process. Optional.
|
|
104
|
+
*/
|
|
105
105
|
functionId?: string;
|
|
106
106
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
* Sink for structured log lines. Defaults to a `globalThis.console`-backed
|
|
108
|
+
* writer that routes `info`/`warn`/`error` to the matching console method.
|
|
109
|
+
*/
|
|
110
110
|
logger?: ConsoleLogger;
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
|
-
* A zero-dependency structured tracer for the ai@7 telemetry surface.
|
|
114
|
-
*
|
|
115
|
-
* It maps the generation lifecycle onto {@link ConsoleLogger} calls: operation
|
|
116
|
-
* start/end, per-step start/end, model-call end (model + finish reason +
|
|
117
|
-
* usage), and tool start/end (name, success, timing). By default it records
|
|
118
|
-
* **only structural metadata** — set `recordInputs` to also log prompts / tool
|
|
119
|
-
* arguments, and `recordOutputs` to log generated text / tool results.
|
|
120
|
-
*
|
|
121
|
-
* Every callback is defensive (event fields may be absent) and synchronous.
|
|
122
|
-
* @experimental
|
|
123
|
-
*/
|
|
113
|
+
* A zero-dependency structured tracer for the ai@7 telemetry surface.
|
|
114
|
+
*
|
|
115
|
+
* It maps the generation lifecycle onto {@link ConsoleLogger} calls: operation
|
|
116
|
+
* start/end, per-step start/end, model-call end (model + finish reason +
|
|
117
|
+
* usage), and tool start/end (name, success, timing). By default it records
|
|
118
|
+
* **only structural metadata** — set `recordInputs` to also log prompts / tool
|
|
119
|
+
* arguments, and `recordOutputs` to log generated text / tool results.
|
|
120
|
+
*
|
|
121
|
+
* Every callback is defensive (event fields may be absent) and synchronous.
|
|
122
|
+
* @experimental
|
|
123
|
+
*/
|
|
124
124
|
declare const consoleTelemetry: (options?: ConsoleTelemetryOptions) => Telemetry;
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
|
|
126
|
+
* Options for {@link otlpTelemetry}.
|
|
127
|
+
* @experimental
|
|
128
|
+
*/
|
|
129
|
+
interface OtlpTelemetryOptions extends CommonOptions {
|
|
130
|
+
/**
|
|
131
|
+
* Conversation / session id to tag each generation span with, emitted as the
|
|
132
|
+
* `gen_ai.conversation.id` semantic-convention attribute so a multi-turn
|
|
133
|
+
* conversation's model turns group in the trace store. On a deployed agent the
|
|
134
|
+
* platform wiring passes the run's `threadKey` here automatically (one thread =
|
|
135
|
+
* one conversation). Omitted → the attribute is absent (backward-compatible),
|
|
136
|
+
* and each turn's span is ungrouped.
|
|
137
|
+
*/
|
|
138
|
+
conversationId?: string;
|
|
139
|
+
/**
|
|
140
|
+
* The OTLP-over-HTTP collector base endpoint (e.g. the Lunora Cloud's `/v1`
|
|
141
|
+
* base). Spans are POSTed to `${endpoint}/v1/traces`; a trailing slash is
|
|
142
|
+
* tolerated. On the platform this is the injected `LUNORA_OTLP_ENDPOINT`.
|
|
143
|
+
*/
|
|
144
|
+
endpoint: string;
|
|
145
|
+
/**
|
|
146
|
+
* Extra headers merged onto every POST — typically the correlation headers
|
|
147
|
+
* the platform injects. `Content-Type: application/json` is set by default.
|
|
148
|
+
*/
|
|
149
|
+
headers?: Record<string, string>;
|
|
150
|
+
/** `service.name` resource attribute on every span. Defaults to `lunora`. */
|
|
151
|
+
serviceName?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Bearer token added as `Authorization: Bearer` (wins over any authorization
|
|
154
|
+
* in `headers`) — the injected `LUNORA_OTLP_TOKEN`. Omit for an
|
|
155
|
+
* unauthenticated collector.
|
|
156
|
+
*/
|
|
157
|
+
token?: string;
|
|
158
|
+
/**
|
|
159
|
+
* Trace id (32-hex) to hang every span of this run under, so one agent run
|
|
160
|
+
* reads as one trace. Pass a stable id derived from the run (e.g. the
|
|
161
|
+
* workflow run id). Omitted → each span mints its own trace id (still valid,
|
|
162
|
+
* just ungrouped).
|
|
163
|
+
*/
|
|
164
|
+
traceId?: string;
|
|
165
|
+
/**
|
|
166
|
+
* The Worker request's `waitUntil`, so a fire-and-forget export survives
|
|
167
|
+
* isolate teardown after the turn returns. Omit and the send degrades to
|
|
168
|
+
* best-effort.
|
|
169
|
+
*/
|
|
170
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* An OTLP-over-HTTP telemetry integration for `@lunora/agent`.
|
|
174
|
+
*
|
|
175
|
+
* The OTLP counterpart to the `sentryTelemetry` / `braintrustTelemetry` bridges:
|
|
176
|
+
* it wraps each language-model call and tool execution in an OTLP **span**
|
|
177
|
+
* (`gen_ai.*` semantic-convention attributes — model, provider, token usage,
|
|
178
|
+
* tool name) and ships it to a collector, so agent generations land in the same
|
|
179
|
+
* trace store as the rest of an app's telemetry (the Lunora Cloud, or any OTel
|
|
180
|
+
* collector). Plug it into `defineAgent({ telemetry: { isEnabled: true,
|
|
181
|
+
* integrations: [otlpTelemetry({ endpoint, token })] } })`.
|
|
182
|
+
*
|
|
183
|
+
* Emitting inside the turn's execution wrapper means one span per **real** turn:
|
|
184
|
+
* the agent loop memoizes each `step.do('llm:turn:N')`, so a Workflow replay
|
|
185
|
+
* returns the cached result without re-invoking `execute`, and no duplicate span
|
|
186
|
+
* is emitted. Privacy-safe by default — `recordInputs`/`recordOutputs` both
|
|
187
|
+
* default `false`, so no prompt or generated text leaves the worker without an
|
|
188
|
+
* explicit opt-in; only structural metadata + token counts are recorded.
|
|
189
|
+
*
|
|
190
|
+
* Each export is fire-and-forget (registered with `waitUntil` when supplied);
|
|
191
|
+
* every rejection is swallowed so a flaky collector never surfaces to the run.
|
|
192
|
+
*
|
|
193
|
+
* Two deliberate differences from the SDK-backed bridges, which delegate to a
|
|
194
|
+
* host tracer. First, no `onError`: a failed call already emits a span with
|
|
195
|
+
* `status.code === 2`, so the failure is on the trace and there is no host client
|
|
196
|
+
* to also notify. Second, flat not nested: every span gets `traceId` (shared when
|
|
197
|
+
* `traceId` is set) but no `parentSpanId`, so model-call and tool spans are
|
|
198
|
+
* siblings under the run rather than a tree — OTLP has no ambient span context to
|
|
199
|
+
* parent to here.
|
|
200
|
+
* @param options `endpoint` (+ optional `token`/`headers`/`serviceName`),
|
|
201
|
+
* `traceId` to group a run's spans, `waitUntil`, and the `recordInputs`/
|
|
202
|
+
* `recordOutputs` privacy flags.
|
|
203
|
+
* @experimental
|
|
204
|
+
*/
|
|
205
|
+
declare const otlpTelemetry: (options: OtlpTelemetryOptions) => Telemetry;
|
|
206
|
+
/**
|
|
207
|
+
* The minimal, **structural** slice of `@sentry/cloudflare` (equivalently
|
|
208
|
+
* `@sentry/node`/`@sentry/browser`) this bridge needs. `@sentry/cloudflare` is
|
|
209
|
+
* intentionally **not** a dependency — the app passes its own already-initialized
|
|
210
|
+
* Sentry namespace, so this package stays dependency-free and works with any
|
|
211
|
+
* compatible Sentry SDK version.
|
|
212
|
+
* @experimental
|
|
213
|
+
*/
|
|
133
214
|
interface SentryLike {
|
|
134
215
|
/** Capture a thrown value / exception. */
|
|
135
216
|
captureException: (exception: unknown) => unknown;
|
|
@@ -145,29 +226,29 @@ interface SentryLike {
|
|
|
145
226
|
}) => T) => T;
|
|
146
227
|
}
|
|
147
228
|
/**
|
|
148
|
-
* Options for {@link sentryTelemetry}.
|
|
149
|
-
* @experimental
|
|
150
|
-
*/
|
|
229
|
+
* Options for {@link sentryTelemetry}.
|
|
230
|
+
* @experimental
|
|
231
|
+
*/
|
|
151
232
|
interface SentryTelemetryOptions extends CommonOptions {
|
|
152
233
|
/** Span-name prefix for the language-model call (e.g. the agent name). */
|
|
153
234
|
functionId?: string;
|
|
154
235
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
236
|
+
* The caller's already-initialized Sentry namespace (dependency-injected).
|
|
237
|
+
* `import * as Sentry from "@sentry/cloudflare"` and pass it as `Sentry`.
|
|
238
|
+
*/
|
|
158
239
|
Sentry: SentryLike;
|
|
159
240
|
}
|
|
160
241
|
/**
|
|
161
|
-
* A dependency-injected Sentry bridge for the ai@7 telemetry surface.
|
|
162
|
-
*
|
|
163
|
-
* It wraps model calls and tool executions in Sentry spans (via
|
|
164
|
-
* `Sentry.startSpan`) so nested provider/tool work is correctly parented, and
|
|
165
|
-
* routes `onError` to `Sentry.captureException`. Span attributes carry only
|
|
166
|
-
* structural metadata (model, provider, tool name) unless `recordInputs` is
|
|
167
|
-
* set, in which case prompts / tool arguments are attached too.
|
|
168
|
-
*
|
|
169
|
-
* The app owns Sentry initialization; pass the namespace in as `Sentry`.
|
|
170
|
-
* @experimental
|
|
171
|
-
*/
|
|
242
|
+
* A dependency-injected Sentry bridge for the ai@7 telemetry surface.
|
|
243
|
+
*
|
|
244
|
+
* It wraps model calls and tool executions in Sentry spans (via
|
|
245
|
+
* `Sentry.startSpan`) so nested provider/tool work is correctly parented, and
|
|
246
|
+
* routes `onError` to `Sentry.captureException`. Span attributes carry only
|
|
247
|
+
* structural metadata (model, provider, tool name) unless `recordInputs` is
|
|
248
|
+
* set, in which case prompts / tool arguments are attached too.
|
|
249
|
+
*
|
|
250
|
+
* The app owns Sentry initialization; pass the namespace in as `Sentry`.
|
|
251
|
+
* @experimental
|
|
252
|
+
*/
|
|
172
253
|
declare const sentryTelemetry: (options: SentryTelemetryOptions) => Telemetry;
|
|
173
|
-
export { type BraintrustLike, type BraintrustSpan, type BraintrustTelemetryOptions, type CommonOptions, type ConsoleLogLevel, type ConsoleLogger, type ConsoleTelemetryOptions, type SentryLike, type SentryTelemetryOptions, braintrustTelemetry, combineTelemetry, consoleTelemetry, sentryTelemetry };
|
|
254
|
+
export { type BraintrustLike, type BraintrustSpan, type BraintrustTelemetryOptions, type CommonOptions, type ConsoleLogLevel, type ConsoleLogger, type ConsoleTelemetryOptions, type OtlpTelemetryOptions, type SentryLike, type SentryTelemetryOptions, braintrustTelemetry, combineTelemetry, consoleTelemetry, otlpTelemetry, sentryTelemetry };
|