@dexto/core 1.13.3 → 1.13.4
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.
|
@@ -38,6 +38,14 @@ function assistantOutputForFinishReason(finishReason) {
|
|
|
38
38
|
return { status: "complete" };
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
function blockSeparator(previousBlockId, blockId, accumulated, delta) {
|
|
42
|
+
if (delta === "" || accumulated === "") return "";
|
|
43
|
+
if (blockId === void 0 || previousBlockId === void 0 || blockId === previousBlockId) {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
if (accumulated.endsWith("\n\n")) return "";
|
|
47
|
+
return accumulated.endsWith("\n") ? "\n" : "\n\n";
|
|
48
|
+
}
|
|
41
49
|
class StreamProcessor {
|
|
42
50
|
/**
|
|
43
51
|
* @param contextManager Context manager for message persistence
|
|
@@ -65,6 +73,9 @@ class StreamProcessor {
|
|
|
65
73
|
reasoningText = "";
|
|
66
74
|
reasoningMetadata;
|
|
67
75
|
accumulatedText = "";
|
|
76
|
+
/** The stream block the last text or reasoning came from; a new id starts a new paragraph. */
|
|
77
|
+
lastTextBlockId;
|
|
78
|
+
lastReasoningBlockId;
|
|
68
79
|
logger;
|
|
69
80
|
hasStepUsage = false;
|
|
70
81
|
usageScopeId;
|
|
@@ -136,7 +147,7 @@ class StreamProcessor {
|
|
|
136
147
|
try {
|
|
137
148
|
for await (const event of stream.fullStream) {
|
|
138
149
|
switch (event.type) {
|
|
139
|
-
case "text-delta":
|
|
150
|
+
case "text-delta": {
|
|
140
151
|
if (textDeltaCount === 0) {
|
|
141
152
|
markTiming("first_text_delta_received");
|
|
142
153
|
}
|
|
@@ -155,20 +166,28 @@ class StreamProcessor {
|
|
|
155
166
|
}
|
|
156
167
|
);
|
|
157
168
|
}
|
|
169
|
+
const text = blockSeparator(
|
|
170
|
+
this.lastTextBlockId,
|
|
171
|
+
event.id,
|
|
172
|
+
this.accumulatedText,
|
|
173
|
+
event.text
|
|
174
|
+
) + event.text;
|
|
175
|
+
if (event.text !== "") this.lastTextBlockId = event.id;
|
|
158
176
|
await this.contextManager.appendAssistantText(
|
|
159
177
|
this.assistantMessageId,
|
|
160
|
-
|
|
178
|
+
text
|
|
161
179
|
);
|
|
162
|
-
this.accumulatedText +=
|
|
180
|
+
this.accumulatedText += text;
|
|
163
181
|
if (this.streaming) {
|
|
164
182
|
this.eventBus.emit("llm:chunk", {
|
|
165
183
|
chunkType: "text",
|
|
166
|
-
content:
|
|
184
|
+
content: text
|
|
167
185
|
});
|
|
168
186
|
}
|
|
169
187
|
markTiming("last_text_delta_emitted");
|
|
170
188
|
break;
|
|
171
|
-
|
|
189
|
+
}
|
|
190
|
+
case "reasoning-delta": {
|
|
172
191
|
if (reasoningDeltaCount === 0) {
|
|
173
192
|
markTiming("first_reasoning_delta_received");
|
|
174
193
|
}
|
|
@@ -180,18 +199,26 @@ class StreamProcessor {
|
|
|
180
199
|
lastDeltaReceivedAtMs = lastReasoningDeltaReceivedAtMs;
|
|
181
200
|
setStreamAttribute("last_delta_received_ms", lastDeltaReceivedAtMs);
|
|
182
201
|
setStreamAttribute("last_delta_kind", "reasoning");
|
|
183
|
-
|
|
202
|
+
const reasoning = blockSeparator(
|
|
203
|
+
this.lastReasoningBlockId,
|
|
204
|
+
event.id,
|
|
205
|
+
this.reasoningText,
|
|
206
|
+
event.text
|
|
207
|
+
) + event.text;
|
|
208
|
+
if (event.text !== "") this.lastReasoningBlockId = event.id;
|
|
209
|
+
this.reasoningText += reasoning;
|
|
184
210
|
if (event.providerMetadata) {
|
|
185
211
|
this.mergeReasoningMetadata(event.providerMetadata);
|
|
186
212
|
}
|
|
187
213
|
if (this.streaming) {
|
|
188
214
|
this.eventBus.emit("llm:chunk", {
|
|
189
215
|
chunkType: "reasoning",
|
|
190
|
-
content:
|
|
216
|
+
content: reasoning
|
|
191
217
|
});
|
|
192
218
|
}
|
|
193
219
|
markTiming("last_reasoning_delta_emitted");
|
|
194
220
|
break;
|
|
221
|
+
}
|
|
195
222
|
case "tool-input-start": {
|
|
196
223
|
handleToolInputStart(event);
|
|
197
224
|
break;
|
|
@@ -29,6 +29,9 @@ export declare class StreamProcessor {
|
|
|
29
29
|
private reasoningText;
|
|
30
30
|
private reasoningMetadata;
|
|
31
31
|
private accumulatedText;
|
|
32
|
+
/** The stream block the last text or reasoning came from; a new id starts a new paragraph. */
|
|
33
|
+
private lastTextBlockId;
|
|
34
|
+
private lastReasoningBlockId;
|
|
32
35
|
private logger;
|
|
33
36
|
private hasStepUsage;
|
|
34
37
|
private readonly usageScopeId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-processor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,IAAI,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,KAAK,EAAE,WAAW,EAAoB,gBAAgB,EAAc,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"stream-processor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,IAAI,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAK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,GAAE,OAAc,EACzB,eAAe,GAAE,OAAc;IAMrC,OAAO,CACT,QAAQ,EAAE,MAAM,gBAAgB,CAAC,aAAa,EAAE,OAAO,CAAC,GACzD,OAAO,CAAC,qBAAqB,CAAC;IAwgBjC,OAAO,CAAC,kCAAkC;IAoB1C,OAAO,CAAC,cAAc;IA4CtB,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,eAAe;YA8BT,gCAAgC;IA4B9C,OAAO,CAAC,sBAAsB;YAwChB,sBAAsB;IAMpC;;;;OAIG;YACW,2BAA2B;IAQzC;;OAEG;YACW,wBAAwB;YAQxB,yBAAyB;CAuC1C"}
|
|
@@ -16,6 +16,14 @@ function assistantOutputForFinishReason(finishReason) {
|
|
|
16
16
|
return { status: "complete" };
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
function blockSeparator(previousBlockId, blockId, accumulated, delta) {
|
|
20
|
+
if (delta === "" || accumulated === "") return "";
|
|
21
|
+
if (blockId === void 0 || previousBlockId === void 0 || blockId === previousBlockId) {
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
if (accumulated.endsWith("\n\n")) return "";
|
|
25
|
+
return accumulated.endsWith("\n") ? "\n" : "\n\n";
|
|
26
|
+
}
|
|
19
27
|
class StreamProcessor {
|
|
20
28
|
/**
|
|
21
29
|
* @param contextManager Context manager for message persistence
|
|
@@ -43,6 +51,9 @@ class StreamProcessor {
|
|
|
43
51
|
reasoningText = "";
|
|
44
52
|
reasoningMetadata;
|
|
45
53
|
accumulatedText = "";
|
|
54
|
+
/** The stream block the last text or reasoning came from; a new id starts a new paragraph. */
|
|
55
|
+
lastTextBlockId;
|
|
56
|
+
lastReasoningBlockId;
|
|
46
57
|
logger;
|
|
47
58
|
hasStepUsage = false;
|
|
48
59
|
usageScopeId;
|
|
@@ -114,7 +125,7 @@ class StreamProcessor {
|
|
|
114
125
|
try {
|
|
115
126
|
for await (const event of stream.fullStream) {
|
|
116
127
|
switch (event.type) {
|
|
117
|
-
case "text-delta":
|
|
128
|
+
case "text-delta": {
|
|
118
129
|
if (textDeltaCount === 0) {
|
|
119
130
|
markTiming("first_text_delta_received");
|
|
120
131
|
}
|
|
@@ -133,20 +144,28 @@ class StreamProcessor {
|
|
|
133
144
|
}
|
|
134
145
|
);
|
|
135
146
|
}
|
|
147
|
+
const text = blockSeparator(
|
|
148
|
+
this.lastTextBlockId,
|
|
149
|
+
event.id,
|
|
150
|
+
this.accumulatedText,
|
|
151
|
+
event.text
|
|
152
|
+
) + event.text;
|
|
153
|
+
if (event.text !== "") this.lastTextBlockId = event.id;
|
|
136
154
|
await this.contextManager.appendAssistantText(
|
|
137
155
|
this.assistantMessageId,
|
|
138
|
-
|
|
156
|
+
text
|
|
139
157
|
);
|
|
140
|
-
this.accumulatedText +=
|
|
158
|
+
this.accumulatedText += text;
|
|
141
159
|
if (this.streaming) {
|
|
142
160
|
this.eventBus.emit("llm:chunk", {
|
|
143
161
|
chunkType: "text",
|
|
144
|
-
content:
|
|
162
|
+
content: text
|
|
145
163
|
});
|
|
146
164
|
}
|
|
147
165
|
markTiming("last_text_delta_emitted");
|
|
148
166
|
break;
|
|
149
|
-
|
|
167
|
+
}
|
|
168
|
+
case "reasoning-delta": {
|
|
150
169
|
if (reasoningDeltaCount === 0) {
|
|
151
170
|
markTiming("first_reasoning_delta_received");
|
|
152
171
|
}
|
|
@@ -158,18 +177,26 @@ class StreamProcessor {
|
|
|
158
177
|
lastDeltaReceivedAtMs = lastReasoningDeltaReceivedAtMs;
|
|
159
178
|
setStreamAttribute("last_delta_received_ms", lastDeltaReceivedAtMs);
|
|
160
179
|
setStreamAttribute("last_delta_kind", "reasoning");
|
|
161
|
-
|
|
180
|
+
const reasoning = blockSeparator(
|
|
181
|
+
this.lastReasoningBlockId,
|
|
182
|
+
event.id,
|
|
183
|
+
this.reasoningText,
|
|
184
|
+
event.text
|
|
185
|
+
) + event.text;
|
|
186
|
+
if (event.text !== "") this.lastReasoningBlockId = event.id;
|
|
187
|
+
this.reasoningText += reasoning;
|
|
162
188
|
if (event.providerMetadata) {
|
|
163
189
|
this.mergeReasoningMetadata(event.providerMetadata);
|
|
164
190
|
}
|
|
165
191
|
if (this.streaming) {
|
|
166
192
|
this.eventBus.emit("llm:chunk", {
|
|
167
193
|
chunkType: "reasoning",
|
|
168
|
-
content:
|
|
194
|
+
content: reasoning
|
|
169
195
|
});
|
|
170
196
|
}
|
|
171
197
|
markTiming("last_reasoning_delta_emitted");
|
|
172
198
|
break;
|
|
199
|
+
}
|
|
173
200
|
case "tool-input-start": {
|
|
174
201
|
handleToolInputStart(event);
|
|
175
202
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexto/core",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
"nanoid": "^5.1.6",
|
|
175
175
|
"winston": "^3.17.0",
|
|
176
176
|
"yaml": "^2.8.3",
|
|
177
|
-
"@dexto/llm": "1.13.
|
|
177
|
+
"@dexto/llm": "1.13.4"
|
|
178
178
|
},
|
|
179
179
|
"devDependencies": {
|
|
180
180
|
"@opentelemetry/context-async-hooks": "^1.28.0",
|