@lunora/agent 1.0.0-alpha.1 → 1.0.0-alpha.10
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 +2 -0
- package/dist/channels.d.mts +42 -22
- package/dist/channels.d.ts +42 -22
- package/dist/channels.mjs +1 -1
- package/dist/component.d.mts +59 -56
- package/dist/component.d.ts +59 -56
- package/dist/component.mjs +20 -9
- package/dist/inbound.d.mts +21 -16
- package/dist/inbound.d.ts +21 -16
- package/dist/index.d.mts +500 -408
- package/dist/index.d.ts +500 -408
- package/dist/index.mjs +6 -6
- package/dist/naming.d.mts +23 -10
- package/dist/naming.d.ts +23 -10
- package/dist/packem_shared/{VoiceSessionDO-DLoXsHGF.mjs → VoiceSessionDO-BdwlLaXC.mjs} +2 -2
- package/dist/packem_shared/{agentAsTool-Dt8NlU6k.mjs → agentAsTool-CUHlWsmt.mjs} +5 -1
- package/dist/packem_shared/{braintrustTelemetry-wuGDErob.mjs → braintrustTelemetry-TP7Kwuuj.mjs} +1 -1
- package/dist/packem_shared/{common-DAeFCot5.mjs → common-DQXayow6.mjs} +29 -1
- package/dist/packem_shared/compileAgentWorkflow-DYFFyx7i.mjs +78 -0
- package/dist/packem_shared/{consoleTelemetry-z2MiP1jt.mjs → consoleTelemetry--3sWfu1R.mjs} +1 -1
- package/dist/packem_shared/{createAgentGenerate-BQv9YJ01.mjs → createAgentGenerate-DO7Z96zX.mjs} +1 -1
- package/dist/packem_shared/{defineAgent-D6maSbVc.mjs → defineAgent-DAwAZC9P.mjs} +1 -1
- package/dist/packem_shared/{graph-component-aoUwO-f0.mjs → graph-component-Bbaxxymp.mjs} +3 -2
- package/dist/packem_shared/{normalizeEntityName-CyEEWFkR.mjs → normalizeEntityName-BouctxLC.mjs} +1 -1
- package/dist/packem_shared/otlpTelemetry-DU5ZmoEV.mjs +177 -0
- package/dist/packem_shared/{runAgentLoop-Dhg4ZNvw.mjs → runAgentLoop-M8PKbtWT.mjs} +2 -2
- package/dist/packem_shared/{sentryTelemetry-CgqFJyLO.mjs → sentryTelemetry-A4F5ndh9.mjs} +1 -1
- 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 +129 -110
- package/dist/sandbox.d.ts +129 -110
- package/dist/sandbox.mjs +5 -1
- package/dist/telemetry/index.d.mts +190 -86
- package/dist/telemetry/index.d.ts +190 -86
- package/dist/telemetry/index.mjs +4 -3
- package/package.json +8 -8
- package/dist/packem_shared/compileAgentWorkflow-BxJjHgtD.mjs +0 -55
- package/dist/packem_shared/types.d-BWG0uUtX.d.mts +0 -1015
- package/dist/packem_shared/types.d-BWG0uUtX.d.ts +0 -1015
|
@@ -1,36 +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
|
-
|
|
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
|
+
*/
|
|
11
12
|
interface CommonOptions {
|
|
12
13
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
* When `true`, record model/tool **input** — prompts, messages, and tool
|
|
15
|
+
* call arguments. Default `false`.
|
|
16
|
+
*/
|
|
16
17
|
recordInputs?: boolean;
|
|
17
18
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
* When `true`, record model/tool **output** — generated text and tool
|
|
20
|
+
* results. Default `false`.
|
|
21
|
+
*/
|
|
21
22
|
recordOutputs?: boolean;
|
|
22
23
|
}
|
|
23
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* The span handle a {@link BraintrustLike.traced} callback receives.
|
|
26
|
+
* @experimental
|
|
27
|
+
*/
|
|
24
28
|
interface BraintrustSpan {
|
|
25
29
|
/** Attach structured fields to the current span. */
|
|
26
30
|
log: (event: Record<string, unknown>) => void;
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
|
-
* The minimal, **structural** slice of the `braintrust` SDK this bridge needs.
|
|
30
|
-
* `braintrust` is intentionally **not** a dependency — the app passes its own
|
|
31
|
-
* initialized logger, so this package stays dependency-free and works with any
|
|
32
|
-
* compatible Braintrust SDK version.
|
|
33
|
-
|
|
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
|
+
*/
|
|
34
39
|
interface BraintrustLike {
|
|
35
40
|
/** Run `callback` inside a new traced span and return its result. */
|
|
36
41
|
traced: <T>(callback: (span: BraintrustSpan) => T, args?: {
|
|
@@ -38,79 +43,174 @@ interface BraintrustLike {
|
|
|
38
43
|
type?: string;
|
|
39
44
|
}) => T;
|
|
40
45
|
}
|
|
41
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Options for {@link braintrustTelemetry}.
|
|
48
|
+
* @experimental
|
|
49
|
+
*/
|
|
42
50
|
interface BraintrustTelemetryOptions extends CommonOptions {
|
|
43
51
|
/** Span-name prefix for the language-model call (e.g. the agent name). */
|
|
44
52
|
functionId?: string;
|
|
45
53
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
* The caller's initialized Braintrust logger (dependency-injected). Import
|
|
55
|
+
* and initialize `braintrust` in your app and pass it as `logger`.
|
|
56
|
+
*/
|
|
49
57
|
logger: BraintrustLike;
|
|
50
58
|
}
|
|
51
59
|
/**
|
|
52
|
-
* A dependency-injected Braintrust bridge for the ai@7 telemetry surface.
|
|
53
|
-
*
|
|
54
|
-
* It wraps model calls (`type: "llm"`) and tool executions (`type: "tool"`) in
|
|
55
|
-
* `logger.traced` spans and logs structural metadata. Prompts / tool arguments
|
|
56
|
-
* are logged only when `recordInputs` is set; generated text / tool results
|
|
57
|
-
* only when `recordOutputs` is set. `onError` opens a span and logs the error.
|
|
58
|
-
*
|
|
59
|
-
* The app owns Braintrust initialization; pass the logger in as `logger`.
|
|
60
|
-
|
|
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
|
+
*/
|
|
61
70
|
declare const braintrustTelemetry: (options: BraintrustTelemetryOptions) => Telemetry;
|
|
62
71
|
/**
|
|
63
|
-
* Combine several {@link Telemetry} integrations into a single one that fans
|
|
64
|
-
* every lifecycle callback out to all of them and nests the two execution
|
|
65
|
-
* wrappers so multiple span-context wrappers compose correctly.
|
|
66
|
-
*
|
|
67
|
-
* Value callbacks (`onStart`, `onStepEnd`, `onToolExecutionEnd`, …) invoke each
|
|
68
|
-
* integration's matching callback (guarding `undefined`) and await them all in
|
|
69
|
-
* parallel. The wrappers (`executeLanguageModelCall`, `executeTool`) are
|
|
70
|
-
* composed by nesting right-to-left; integrations without a wrapper are skipped,
|
|
71
|
-
* and with none defined the plain `execute` still runs.
|
|
72
|
-
|
|
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
|
+
*/
|
|
73
83
|
declare const combineTelemetry: (...integrations: Telemetry[]) => Telemetry;
|
|
74
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Severity level passed to a {@link ConsoleLogger}.
|
|
86
|
+
* @experimental
|
|
87
|
+
*/
|
|
75
88
|
type ConsoleLogLevel = "error" | "info" | "warn";
|
|
76
89
|
/**
|
|
77
|
-
* Structured log sink. Receives a level, a static human message, and a bag of
|
|
78
|
-
* structured fields (never interpolated into the message, so log processors can
|
|
79
|
-
* index them). The default sink writes to `globalThis.console`.
|
|
80
|
-
|
|
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
|
+
*/
|
|
81
95
|
type ConsoleLogger = (level: ConsoleLogLevel, message: string, fields: Record<string, unknown>) => void;
|
|
82
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Options for {@link consoleTelemetry}.
|
|
98
|
+
* @experimental
|
|
99
|
+
*/
|
|
83
100
|
interface ConsoleTelemetryOptions extends CommonOptions {
|
|
84
101
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
* Identifier prefixed into every log message (e.g. the agent name). Helps
|
|
103
|
+
* correlate lines when several agents share one process. Optional.
|
|
104
|
+
*/
|
|
88
105
|
functionId?: string;
|
|
89
106
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
+
*/
|
|
93
110
|
logger?: ConsoleLogger;
|
|
94
111
|
}
|
|
95
112
|
/**
|
|
96
|
-
* A zero-dependency structured tracer for the ai@7 telemetry surface.
|
|
97
|
-
*
|
|
98
|
-
* It maps the generation lifecycle onto {@link ConsoleLogger} calls: operation
|
|
99
|
-
* start/end, per-step start/end, model-call end (model + finish reason +
|
|
100
|
-
* usage), and tool start/end (name, success, timing). By default it records
|
|
101
|
-
* **only structural metadata** — set `recordInputs` to also log prompts / tool
|
|
102
|
-
* arguments, and `recordOutputs` to log generated text / tool results.
|
|
103
|
-
*
|
|
104
|
-
* Every callback is defensive (event fields may be absent) and synchronous.
|
|
105
|
-
|
|
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
|
+
*/
|
|
106
124
|
declare const consoleTelemetry: (options?: ConsoleTelemetryOptions) => Telemetry;
|
|
107
125
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
*/
|
|
114
214
|
interface SentryLike {
|
|
115
215
|
/** Capture a thrown value / exception. */
|
|
116
216
|
captureException: (exception: unknown) => unknown;
|
|
@@ -125,26 +225,30 @@ interface SentryLike {
|
|
|
125
225
|
} | string) => void;
|
|
126
226
|
}) => T) => T;
|
|
127
227
|
}
|
|
128
|
-
/**
|
|
228
|
+
/**
|
|
229
|
+
* Options for {@link sentryTelemetry}.
|
|
230
|
+
* @experimental
|
|
231
|
+
*/
|
|
129
232
|
interface SentryTelemetryOptions extends CommonOptions {
|
|
130
233
|
/** Span-name prefix for the language-model call (e.g. the agent name). */
|
|
131
234
|
functionId?: string;
|
|
132
235
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
236
|
+
* The caller's already-initialized Sentry namespace (dependency-injected).
|
|
237
|
+
* `import * as Sentry from "@sentry/cloudflare"` and pass it as `Sentry`.
|
|
238
|
+
*/
|
|
136
239
|
Sentry: SentryLike;
|
|
137
240
|
}
|
|
138
241
|
/**
|
|
139
|
-
* A dependency-injected Sentry bridge for the ai@7 telemetry surface.
|
|
140
|
-
*
|
|
141
|
-
* It wraps model calls and tool executions in Sentry spans (via
|
|
142
|
-
* `Sentry.startSpan`) so nested provider/tool work is correctly parented, and
|
|
143
|
-
* routes `onError` to `Sentry.captureException`. Span attributes carry only
|
|
144
|
-
* structural metadata (model, provider, tool name) unless `recordInputs` is
|
|
145
|
-
* set, in which case prompts / tool arguments are attached too.
|
|
146
|
-
*
|
|
147
|
-
* The app owns Sentry initialization; pass the namespace in as `Sentry`.
|
|
148
|
-
|
|
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
|
+
*/
|
|
149
253
|
declare const sentryTelemetry: (options: SentryTelemetryOptions) => Telemetry;
|
|
150
|
-
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 };
|