@uselemma/tracing 7.12.5 → 7.12.6

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.
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Display text from chat and Responses content blocks.
4
+ * Reasoning and encrypted reasoning are not part of the reply.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isReplyReasoning = isReplyReasoning;
8
+ exports.readContentReply = readContentReply;
9
+ exports.textFromGenerationOutput = textFromGenerationOutput;
10
+ function isReplyReasoning(record) {
11
+ return (record.type === "reasoning" || typeof record.encrypted_content === "string");
12
+ }
13
+ function readContentReply(content) {
14
+ if (!Array.isArray(content))
15
+ return undefined;
16
+ const parts = [];
17
+ let recognized = false;
18
+ for (const block of content) {
19
+ if (!block || typeof block !== "object")
20
+ continue;
21
+ const record = block;
22
+ if (isReplyReasoning(record)) {
23
+ recognized = true;
24
+ continue;
25
+ }
26
+ if ((record.type === "text" || record.type === "output_text") &&
27
+ typeof record.text === "string") {
28
+ parts.push(record.text);
29
+ recognized = true;
30
+ }
31
+ }
32
+ return { parts, recognized };
33
+ }
34
+ function textFromContentParts(content) {
35
+ if (typeof content === "string")
36
+ return content;
37
+ const reply = readContentReply(content);
38
+ if (!reply || !reply.recognized)
39
+ return undefined;
40
+ return reply.parts.join("");
41
+ }
42
+ /** Reply text for a generation or Responses output list. */
43
+ function textFromGenerationOutput(output) {
44
+ if (!Array.isArray(output))
45
+ return output;
46
+ let text = "";
47
+ let sawUnhandled = false;
48
+ for (const item of output) {
49
+ if (!item || typeof item !== "object") {
50
+ sawUnhandled = true;
51
+ continue;
52
+ }
53
+ const record = item;
54
+ if (isReplyReasoning(record))
55
+ continue;
56
+ if (typeof record.text === "string") {
57
+ text += record.text;
58
+ continue;
59
+ }
60
+ if (typeof record.content === "string") {
61
+ text += record.content;
62
+ continue;
63
+ }
64
+ if (Array.isArray(record.content)) {
65
+ const fromParts = textFromContentParts(record.content);
66
+ if (fromParts !== undefined) {
67
+ text += fromParts;
68
+ continue;
69
+ }
70
+ }
71
+ sawUnhandled = true;
72
+ }
73
+ if (text)
74
+ return text;
75
+ // Reasoning-only output must not fall back to the raw item array.
76
+ if (!sawUnhandled && output.length > 0)
77
+ return "";
78
+ return output;
79
+ }
80
+ //# sourceMappingURL=reply-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reply-text.js","sourceRoot":"","sources":["../src/reply-text.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,4CAIC;AAQD,4CAoBC;AAUD,4DAgCC;AA1ED,SAAgB,gBAAgB,CAAC,MAA+B;IAC9D,OAAO,CACL,MAAM,CAAC,IAAI,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,iBAAiB,KAAK,QAAQ,CAC5E,CAAC;AACJ,CAAC;AAQD,SAAgB,gBAAgB,CAAC,OAAgB;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,SAAS;QAClD,MAAM,MAAM,GAAG,KAAgC,CAAC;QAChD,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,UAAU,GAAG,IAAI,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IACE,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,aAAa,CAAC;YACzD,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAC/B,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACxB,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;IAC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KAAK,SAAS,EAAE,CAAC;gBAC5B,IAAI,IAAI,SAAS,CAAC;gBAClB,SAAS;YACX,CAAC;QACH,CAAC;QACD,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IACD,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IACtB,kEAAkE;IAClE,IAAI,CAAC,YAAY,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IAClD,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uselemma/tracing",
3
- "version": "7.12.5",
3
+ "version": "7.12.6",
4
4
  "description": "HTTP tracing SDK for Lemma",
5
5
  "license": "MIT",
6
6
  "author": "Lemma",