orchajs 0.27.4 → 0.28.1
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 +31 -0
- package/dist/amarsia/analytics.d.ts +37 -3
- package/dist/amarsia/analytics.js +57 -5
- package/dist/amarsia/sync.js +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/cli-agents-template.d.ts +1 -1
- package/dist/cli-agents-template.js +9 -0
- package/dist/cli.js +1 -1
- package/dist/integrations/expo.d.ts +2 -1
- package/dist/integrations/expo.js +1 -1
- package/dist/integrations/webpack.d.ts +1 -1
- package/dist/orcha.d.ts +1 -1
- package/dist/orcha.js +1 -1
- package/dist/playground/server.js +1 -1
- package/dist/providers/bedrock.d.ts +2 -1
- package/dist/react-native.d.ts +1 -1
- package/dist/runtime/actions/execute.d.ts +1 -1
- package/dist/runtime/actions/execute.js +1 -1
- package/dist/runtime/agent.js +15 -2
- package/dist/runtime/create-orcha.js +15 -5
- package/dist/storage/cloud.d.ts +2 -1
- package/dist/storage/cloud.js +1 -1
- package/dist/telemetry/open-telemetry.d.ts +19 -0
- package/dist/telemetry/open-telemetry.js +630 -0
- package/dist/types.d.ts +13 -0
- package/dist-cjs/amarsia/analytics.js +60 -5
- package/dist-cjs/cli-agents-template.js +9 -0
- package/dist-cjs/runtime/agent.js +9 -2
- package/dist-cjs/runtime/create-orcha.js +12 -2
- package/dist-cjs/telemetry/open-telemetry.js +635 -0
- package/package.json +7 -4
|
@@ -21,7 +21,8 @@ var analytics_exports = {};
|
|
|
21
21
|
__export(analytics_exports, {
|
|
22
22
|
AmarsiaTelemetryClient: () => AmarsiaTelemetryClient,
|
|
23
23
|
sanitizeErrorMessage: () => sanitizeErrorMessage,
|
|
24
|
-
withAmarsiaTelemetry: () => withAmarsiaTelemetry
|
|
24
|
+
withAmarsiaTelemetry: () => withAmarsiaTelemetry,
|
|
25
|
+
withRunTelemetry: () => withRunTelemetry
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(analytics_exports);
|
|
27
28
|
var import_endpoint = require("./endpoint.js");
|
|
@@ -250,7 +251,7 @@ class AmarsiaTelemetryClient {
|
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
|
-
function
|
|
254
|
+
function withRunTelemetry(options) {
|
|
254
255
|
const { store, manifest, client } = options;
|
|
255
256
|
const projections = /* @__PURE__ */ new Map();
|
|
256
257
|
const pending = /* @__PURE__ */ new Map();
|
|
@@ -296,7 +297,15 @@ function withAmarsiaTelemetry(options) {
|
|
|
296
297
|
if (projection.isTest || !hasNewEvents) return;
|
|
297
298
|
for (const run of runs) {
|
|
298
299
|
const fact = projectRunFact(manifest, sessionId, run, projection);
|
|
299
|
-
if (fact)
|
|
300
|
+
if (fact) {
|
|
301
|
+
client.enqueue(
|
|
302
|
+
fact,
|
|
303
|
+
projectRunTelemetryDetails(
|
|
304
|
+
projection.runs.get(run) ?? [],
|
|
305
|
+
projection.sessionCreated
|
|
306
|
+
)
|
|
307
|
+
);
|
|
308
|
+
}
|
|
300
309
|
}
|
|
301
310
|
for (const run of progressRuns) {
|
|
302
311
|
const fact = projectRunFact(manifest, sessionId, run, projection);
|
|
@@ -324,7 +333,15 @@ function withAmarsiaTelemetry(options) {
|
|
|
324
333
|
run,
|
|
325
334
|
projection
|
|
326
335
|
);
|
|
327
|
-
if (fact)
|
|
336
|
+
if (fact) {
|
|
337
|
+
client.enqueue(
|
|
338
|
+
fact,
|
|
339
|
+
projectRunTelemetryDetails(
|
|
340
|
+
projection.runs.get(run) ?? [],
|
|
341
|
+
projection.sessionCreated
|
|
342
|
+
)
|
|
343
|
+
);
|
|
344
|
+
}
|
|
328
345
|
}
|
|
329
346
|
for (const run of progressRuns) {
|
|
330
347
|
const fact = projectRunFact(
|
|
@@ -346,6 +363,7 @@ function withAmarsiaTelemetry(options) {
|
|
|
346
363
|
}
|
|
347
364
|
};
|
|
348
365
|
}
|
|
366
|
+
const withAmarsiaTelemetry = withRunTelemetry;
|
|
349
367
|
function createProjection(events) {
|
|
350
368
|
const projection = {
|
|
351
369
|
seenSequences: /* @__PURE__ */ new Set(),
|
|
@@ -477,6 +495,42 @@ function projectRunFact(manifest, sessionId, run, projection) {
|
|
|
477
495
|
...typeof error?.retryable === "boolean" ? { error_retryable: error.retryable } : {}
|
|
478
496
|
};
|
|
479
497
|
}
|
|
498
|
+
function projectRunTelemetryDetails(runEvents, sessionCreated) {
|
|
499
|
+
const lineage = asRecord(sessionCreated?.data.lineage);
|
|
500
|
+
return {
|
|
501
|
+
modelCalls: runEvents.filter(
|
|
502
|
+
(event) => event.type === "message.created" && event.data.role === "assistant"
|
|
503
|
+
).map((event) => {
|
|
504
|
+
const usage = usageFields(asRecord(event.data.usage) ?? {});
|
|
505
|
+
const duration = numberValue(event.data.durationMs);
|
|
506
|
+
const endedAt = event.timestamp;
|
|
507
|
+
const endedAtMs = new Date(endedAt).getTime();
|
|
508
|
+
return {
|
|
509
|
+
provider: typeof event.data.provider === "string" ? event.data.provider : "unknown",
|
|
510
|
+
model: typeof event.data.model === "string" ? event.data.model : "unknown",
|
|
511
|
+
started_at: new Date(
|
|
512
|
+
Number.isFinite(endedAtMs) ? endedAtMs - duration : endedAtMs
|
|
513
|
+
).toISOString(),
|
|
514
|
+
ended_at: endedAt,
|
|
515
|
+
duration_ms: duration,
|
|
516
|
+
input_tokens: usage.input_tokens,
|
|
517
|
+
output_tokens: usage.output_tokens,
|
|
518
|
+
reasoning_tokens: usage.reasoning_tokens ?? 0,
|
|
519
|
+
cache_read_tokens: usage.cache_read_tokens,
|
|
520
|
+
cache_write_tokens: usage.cache_write_tokens,
|
|
521
|
+
...typeof event.data.responseId === "string" ? { response_id: event.data.responseId } : {},
|
|
522
|
+
...typeof event.data.stopReason === "string" ? { finish_reason: event.data.stopReason } : {}
|
|
523
|
+
};
|
|
524
|
+
}),
|
|
525
|
+
...lineage ? {
|
|
526
|
+
lineage: {
|
|
527
|
+
...typeof lineage.parentRunNumber === "number" ? { parentRunNumber: lineage.parentRunNumber } : {},
|
|
528
|
+
...typeof lineage.rootSessionId === "string" ? { rootSessionId: lineage.rootSessionId } : {},
|
|
529
|
+
...typeof lineage.rootRunNumber === "number" ? { rootRunNumber: lineage.rootRunNumber } : {}
|
|
530
|
+
}
|
|
531
|
+
} : {}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
480
534
|
function normalizeUsage(terminalUsage, assistants) {
|
|
481
535
|
const direct = asRecord(terminalUsage);
|
|
482
536
|
if (direct) {
|
|
@@ -650,5 +704,6 @@ function sanitizeErrorMessage(value) {
|
|
|
650
704
|
0 && (module.exports = {
|
|
651
705
|
AmarsiaTelemetryClient,
|
|
652
706
|
sanitizeErrorMessage,
|
|
653
|
-
withAmarsiaTelemetry
|
|
707
|
+
withAmarsiaTelemetry,
|
|
708
|
+
withRunTelemetry
|
|
654
709
|
});
|
|
@@ -130,6 +130,12 @@ required.
|
|
|
130
130
|
- \`amarsia.inference\` (optional): routes all model calls through Amarsia while
|
|
131
131
|
preserving the provider and model in each manifest. It reuses \`amarsia.key\`;
|
|
132
132
|
local provider credentials are not required.
|
|
133
|
+
- \`telemetry.otel\` (optional): set to \`true\` to emit spans through the
|
|
134
|
+
application's global OpenTelemetry provider, or pass
|
|
135
|
+
\`{ endpoint, headers? }\` to send OTLP/HTTP JSON directly to a collector.
|
|
136
|
+
Spans follow OpenTelemetry GenAI Semantic Conventions. Telemetry excludes
|
|
137
|
+
prompts, responses, action arguments, and action outputs. Subagents share
|
|
138
|
+
their root agent's trace; \`orcha.close()\` marks active runs interrupted.
|
|
133
139
|
- \`actions\` (optional): overrides the native local-action runtime or configures
|
|
134
140
|
its environment and sandbox settings.
|
|
135
141
|
- \`mcp.credentials\` (optional): runtime-only values used to resolve
|
|
@@ -807,6 +813,9 @@ type SessionCreated = SessionEvent<{
|
|
|
807
813
|
parentAgent: string;
|
|
808
814
|
parentSessionId: string;
|
|
809
815
|
parentCallId: string;
|
|
816
|
+
parentRunNumber?: number;
|
|
817
|
+
rootSessionId?: string;
|
|
818
|
+
rootRunNumber?: number;
|
|
810
819
|
};
|
|
811
820
|
}>; // type "session.created", no run
|
|
812
821
|
|
|
@@ -1849,11 +1849,15 @@ class RuntimeAgent {
|
|
|
1849
1849
|
call.arguments.input,
|
|
1850
1850
|
this.#projectRoot
|
|
1851
1851
|
);
|
|
1852
|
+
const parentLineage = sessionLineage(parentEvents);
|
|
1852
1853
|
const lineage = {
|
|
1853
1854
|
origin: "delegated",
|
|
1854
1855
|
parentAgent: this.#manifest.key,
|
|
1855
1856
|
parentSessionId,
|
|
1856
|
-
parentCallId: call.callId
|
|
1857
|
+
parentCallId: call.callId,
|
|
1858
|
+
parentRunNumber: writer.run,
|
|
1859
|
+
rootSessionId: parentLineage?.rootSessionId ?? parentSessionId,
|
|
1860
|
+
rootRunNumber: parentLineage?.rootRunNumber ?? writer.run
|
|
1857
1861
|
};
|
|
1858
1862
|
const childSessionId2 = child2.createDelegatedSessionId();
|
|
1859
1863
|
const initiated = writer.create("subagent.initiated", {
|
|
@@ -3260,7 +3264,10 @@ function sessionLineage(events) {
|
|
|
3260
3264
|
origin: "delegated",
|
|
3261
3265
|
parentAgent: value.parentAgent,
|
|
3262
3266
|
parentSessionId: value.parentSessionId,
|
|
3263
|
-
parentCallId: value.parentCallId
|
|
3267
|
+
parentCallId: value.parentCallId,
|
|
3268
|
+
...typeof value.parentRunNumber === "number" ? { parentRunNumber: value.parentRunNumber } : {},
|
|
3269
|
+
...typeof value.rootSessionId === "string" ? { rootSessionId: value.rootSessionId } : {},
|
|
3270
|
+
...typeof value.rootRunNumber === "number" ? { rootRunNumber: value.rootRunNumber } : {}
|
|
3264
3271
|
};
|
|
3265
3272
|
}
|
|
3266
3273
|
function requiredToolString(value, name) {
|
|
@@ -27,6 +27,7 @@ var import_analytics = require("../amarsia/analytics.js");
|
|
|
27
27
|
var import_compiler_hook = require("./compiler-hook.js");
|
|
28
28
|
var import_context = require("./context.js");
|
|
29
29
|
var import_optional_features = require("./optional-features.js");
|
|
30
|
+
var import_open_telemetry = require("../telemetry/open-telemetry.js");
|
|
30
31
|
class OrchaRuntimeCore {
|
|
31
32
|
#agents = /* @__PURE__ */ new Map();
|
|
32
33
|
#bundle;
|
|
@@ -108,11 +109,20 @@ class OrchaRuntimeCore {
|
|
|
108
109
|
projectRoot,
|
|
109
110
|
manifest
|
|
110
111
|
});
|
|
111
|
-
const
|
|
112
|
+
const telemetryClients = [];
|
|
113
|
+
if (configuration.amarsia?.key) {
|
|
114
|
+
telemetryClients.push(new import_analytics.AmarsiaTelemetryClient(configuration.amarsia));
|
|
115
|
+
}
|
|
116
|
+
if (configuration.telemetry?.otel) {
|
|
117
|
+
telemetryClients.push(
|
|
118
|
+
(0, import_open_telemetry.createOpenTelemetryClient)(configuration.telemetry.otel)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
const telemetry = telemetryClients.length === 0 ? void 0 : telemetryClients.length === 1 ? telemetryClients[0] : new import_open_telemetry.CompositeRunTelemetryClient(telemetryClients);
|
|
112
122
|
this.#telemetry = telemetry;
|
|
113
123
|
const createRuntimeStore = (manifest) => {
|
|
114
124
|
const store = createStore(manifest);
|
|
115
|
-
const runtimeStore = telemetry ? (0, import_analytics.
|
|
125
|
+
const runtimeStore = telemetry ? (0, import_analytics.withRunTelemetry)({ store, manifest, client: telemetry }) : store;
|
|
116
126
|
this.#stores.add(runtimeStore);
|
|
117
127
|
return runtimeStore;
|
|
118
128
|
};
|