@ai-sdk/otel 1.0.132 → 1.0.133
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/CHANGELOG.md +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -29
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/legacy-open-telemetry.ts +6 -3
- package/src/open-telemetry.ts +3 -2
- package/src/stringify-for-telemetry.ts +36 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/otel
|
|
2
2
|
|
|
3
|
+
## 1.0.133
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9184a35: Add ordered text, file, and JSON parts to experimental decision state. Support image input in OpenAI Decisions and language model adapters. Gateway retains its existing string and JSON request format and rejects files, as does TypeSafe AI.
|
|
8
|
+
|
|
9
|
+
Arrays passed directly as state now contain decision state parts. Wrap JSON arrays in an object or a json part.
|
|
10
|
+
|
|
11
|
+
Normalize all public state forms into an array of parts before calling decision providers. Providers receive text and JSON objects as text and json parts.
|
|
12
|
+
|
|
13
|
+
Serialize decision file bytes as base64 in OpenTelemetry state attributes. Model-call spans record normalized state parts, while outer spans retain public state inputs.
|
|
14
|
+
|
|
15
|
+
Preserve native JSON state in TypeSafe AI when state contains one JSON part. Label shared state in language-model decision prompts.
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [9184a35]
|
|
18
|
+
- ai@7.0.133
|
|
19
|
+
- @ai-sdk/provider@4.0.25
|
|
20
|
+
|
|
3
21
|
## 1.0.132
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["OtelStepStartEvent","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent","AISDKContext","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent"],"sources":["../src/supplemental-attributes.ts","../src/open-telemetry.ts","../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/schemas.d.cts","../../provider-utils/dist/index.d.ts","../src/legacy-open-telemetry.ts"],"x_google_ignoreList":[2],"mappings":";;;;KAwBY;KASA,cAAc;EACxB,UAAU;EACV;EACA;EACA,gBAAgB;MACZ;KAEM;;;;EAIV,SAAS;;;;;EAMT,aAAa;;;;EAKb;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;EAGA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["OtelStepStartEvent","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent","AISDKContext","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent"],"sources":["../src/supplemental-attributes.ts","../src/open-telemetry.ts","../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/schemas.d.cts","../../provider-utils/dist/index.d.ts","../src/legacy-open-telemetry.ts"],"x_google_ignoreList":[2],"mappings":";;;;KAwBY;KASA,cAAc;EACxB,UAAU;EACV;EACA;EACA,gBAAgB;MACZ;KAEM;;;;EAIV,SAAS;;;;;EAMT,aAAa;;;;EAKb;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;EAGA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;;;UCnBQA,6BAA2B,2BAA2B;WACrD;;qBA2CE,yBAAyB;mBACnB;mBAEA;mBACA;mBACA;EAEL,YAAA,UAAS;UAMb;UAIA;UAIA;EAgCR,YAAY,KACV,QACA,YACA;IAEA;IACA;IACA,eAAe,YAAY;MACzB,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QACA,YACA;IAEA;IACA;IACA,eAAe,YAAY;MACzB,YAAY;;;;;EAchB,yBAAyB,KACvB,QACA;IAEA;IACA,eAAe,YAAY;MACzB,YAAY;EAUhB,QACE,OACI,oBAAoB,0BACpB,oBAAoB,4BACpB,oBAAoB,mBACpB,oBAAoB,oBACpB,oBAAoB,4BACpB,oBAAoB;EA4C1B,wCACE,OAAO,oBAAoBC;UAKrB;UAyDA;UAgEA;;EAqER,kBAAkB,OAAO;;EAmDzB,gBAAgB,OAAO;UA2Df;EA6DR,YAAY,OAAO;EAiEnB,qBAAqB,OAAO,wBAAwB;EAqCpD,mBAAmB,OAAO,sBAAsB;EA+BhD,UAAU,OAAO,yBAAyB;;EAgH1C,aAAa,OAAO,yBAAyB;EAI7C,MACE,OACI,qBAAqB,WACrB,kCACA,gBACA,iBACA,yBACA;EAuCN,sCACE,OAAO,oBAAoBC;UAKrB;UA+CA;UA6EA;UAmCA;EA6BR,aAAa,OAAO;EA8BpB,WAAW,OAAO;UAwBV;UAkDA;EAQR,cAAc,OAAO;EA2BrB,YAAY,OAAO;UAoBX;UA8CA;EAgBR,2BACE,OAAO,oBAAoBC;EAK7B,yBAAyB,OAAOC;EAIhC,sCACE,OAAOC;EAKT,oCAAoC,OAAOC;;EAK3C,6BACE,OAAO,oBAAoBH;;EAM7B,2BAA2B,OAAOC;;EAKlC,wCACE,OAAO,oBAAoBC;;EA8B7B,sCACE,OAAO,oBAAoBC;EAqB7B,QAAQ,OAAO,uBAAuB;EAkCtC,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -438,6 +438,45 @@ function mapFinishReason(reason) {
|
|
|
438
438
|
}[reason] ?? reason;
|
|
439
439
|
}
|
|
440
440
|
//#endregion
|
|
441
|
+
//#region src/stringify-for-telemetry.ts
|
|
442
|
+
/**
|
|
443
|
+
* Helper utility to serialize prompt content for OpenTelemetry tracing.
|
|
444
|
+
* It is initially created because normalized LanguageModelV4Prompt carries
|
|
445
|
+
* images as Uint8Arrays, on which JSON.stringify acts weirdly, converting
|
|
446
|
+
* them to objects with stringified indices as keys, e.g. {"0": 42, "1": 69 }.
|
|
447
|
+
*/
|
|
448
|
+
function stringifyForTelemetry(prompt) {
|
|
449
|
+
return JSON.stringify(prompt.map((message) => ({
|
|
450
|
+
...message,
|
|
451
|
+
content: typeof message.content === "string" ? message.content : message.content.map((part) => part.type === "file" ? {
|
|
452
|
+
...part,
|
|
453
|
+
data: serializeFileData(part.data)
|
|
454
|
+
} : part)
|
|
455
|
+
})));
|
|
456
|
+
}
|
|
457
|
+
function isDecisionStateParts(state) {
|
|
458
|
+
return Array.isArray(state);
|
|
459
|
+
}
|
|
460
|
+
/** Serialize decision files using the same representation as prompt files. */
|
|
461
|
+
function stringifyDecisionStateForTelemetry(state) {
|
|
462
|
+
return JSON.stringify(isDecisionStateParts(state) ? state.map((part) => part.type === "file" ? {
|
|
463
|
+
...part,
|
|
464
|
+
data: serializeFileData(part.data)
|
|
465
|
+
} : part) : state);
|
|
466
|
+
}
|
|
467
|
+
function serializeFileData(data) {
|
|
468
|
+
if (typeof data === "string") return data;
|
|
469
|
+
if (data instanceof URL) return data.toString();
|
|
470
|
+
if (data instanceof Uint8Array || data instanceof ArrayBuffer) return convertDataContentToBase64String(data);
|
|
471
|
+
switch (data.type) {
|
|
472
|
+
case "data": return convertDataContentToBase64String(data.data);
|
|
473
|
+
case "url": return data.url.toString();
|
|
474
|
+
case "reference": return data.reference;
|
|
475
|
+
case "text": return data.text;
|
|
476
|
+
default: return data;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
//#endregion
|
|
441
480
|
//#region src/record-span.ts
|
|
442
481
|
/**
|
|
443
482
|
* Record an error on a span. Sets the span status to error. If the error is
|
|
@@ -1517,7 +1556,7 @@ var OpenTelemetry = class {
|
|
|
1517
1556
|
"gen_ai.request.model": event.modelId,
|
|
1518
1557
|
...baseSupplementalAttributes,
|
|
1519
1558
|
...selectSupplementalAttributes(telemetry, this.supplementalAttributes, { experimental_decision: {
|
|
1520
|
-
"ai.decision.state": { input: () =>
|
|
1559
|
+
"ai.decision.state": { input: () => stringifyDecisionStateForTelemetry(event.state) },
|
|
1521
1560
|
"ai.decision.questions": { input: () => JSON.stringify(event.questions) }
|
|
1522
1561
|
} })
|
|
1523
1562
|
});
|
|
@@ -1589,7 +1628,7 @@ var OpenTelemetry = class {
|
|
|
1589
1628
|
"gen_ai.request.model": state.modelId,
|
|
1590
1629
|
...state.baseSupplementalAttributes,
|
|
1591
1630
|
...selectSupplementalAttributes(state.telemetry, this.supplementalAttributes, { experimental_decision: {
|
|
1592
|
-
"ai.decision.state": { input: () =>
|
|
1631
|
+
"ai.decision.state": { input: () => stringifyDecisionStateForTelemetry(event.state) },
|
|
1593
1632
|
"ai.decision.questions": { input: () => JSON.stringify(event.questions) }
|
|
1594
1633
|
} })
|
|
1595
1634
|
});
|
|
@@ -1722,31 +1761,6 @@ function getBaseTelemetryAttributes({ model, settings, headers, context }) {
|
|
|
1722
1761
|
};
|
|
1723
1762
|
}
|
|
1724
1763
|
//#endregion
|
|
1725
|
-
//#region src/stringify-for-telemetry.ts
|
|
1726
|
-
/**
|
|
1727
|
-
* Helper utility to serialize prompt content for OpenTelemetry tracing.
|
|
1728
|
-
* It is initially created because normalized LanguageModelV4Prompt carries
|
|
1729
|
-
* images as Uint8Arrays, on which JSON.stringify acts weirdly, converting
|
|
1730
|
-
* them to objects with stringified indices as keys, e.g. {"0": 42, "1": 69 }.
|
|
1731
|
-
*/
|
|
1732
|
-
function stringifyForTelemetry(prompt) {
|
|
1733
|
-
return JSON.stringify(prompt.map((message) => ({
|
|
1734
|
-
...message,
|
|
1735
|
-
content: typeof message.content === "string" ? message.content : message.content.map((part) => part.type === "file" ? {
|
|
1736
|
-
...part,
|
|
1737
|
-
data: serializeFileData(part.data)
|
|
1738
|
-
} : part)
|
|
1739
|
-
})));
|
|
1740
|
-
}
|
|
1741
|
-
function serializeFileData(data) {
|
|
1742
|
-
switch (data.type) {
|
|
1743
|
-
case "data": return data.data instanceof Uint8Array ? convertDataContentToBase64String(data.data) : data.data;
|
|
1744
|
-
case "url": return data.url.toString();
|
|
1745
|
-
case "reference": return data.reference;
|
|
1746
|
-
case "text": return data.text;
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
//#endregion
|
|
1750
1764
|
//#region src/legacy-open-telemetry.ts
|
|
1751
1765
|
function recordSpanError(span, error) {
|
|
1752
1766
|
if (error instanceof Error) {
|
|
@@ -2467,7 +2481,7 @@ var LegacyOpenTelemetry = class {
|
|
|
2467
2481
|
telemetry
|
|
2468
2482
|
}),
|
|
2469
2483
|
...baseTelemetryAttributes,
|
|
2470
|
-
"ai.decision.state": { input: () =>
|
|
2484
|
+
"ai.decision.state": { input: () => stringifyDecisionStateForTelemetry(event.state) },
|
|
2471
2485
|
"ai.decision.questions": { input: () => JSON.stringify(event.questions) }
|
|
2472
2486
|
});
|
|
2473
2487
|
const rootSpan = this.tracer.startSpan(event.operationId, { attributes });
|
|
@@ -2524,7 +2538,7 @@ var LegacyOpenTelemetry = class {
|
|
|
2524
2538
|
telemetry: state.telemetry
|
|
2525
2539
|
}),
|
|
2526
2540
|
...state.baseTelemetryAttributes,
|
|
2527
|
-
"ai.decision.state": { input: () =>
|
|
2541
|
+
"ai.decision.state": { input: () => stringifyDecisionStateForTelemetry(event.state) },
|
|
2528
2542
|
"ai.decision.questions": { input: () => JSON.stringify(event.questions) }
|
|
2529
2543
|
});
|
|
2530
2544
|
const span = this.tracer.startSpan(event.operationId, { attributes }, state.rootContext);
|