@tencent-weixin/openclaw-weixin 2.4.4 → 2.4.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.
- package/CHANGELOG.md +34 -0
- package/CHANGELOG.zh_CN.md +34 -0
- package/dist/src/api/api.js +35 -1
- package/dist/src/api/api.js.map +1 -1
- package/dist/src/api/session-guard.js +3 -3
- package/dist/src/api/session-guard.js.map +1 -1
- package/dist/src/api/types.js.map +1 -1
- package/dist/src/cdn/cdn-upload.js +3 -2
- package/dist/src/cdn/cdn-upload.js.map +1 -1
- package/dist/src/cdn/upload.js +12 -3
- package/dist/src/cdn/upload.js.map +1 -1
- package/dist/src/monitor/monitor.js +8 -8
- package/dist/src/monitor/monitor.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +6 -5
- package/src/api/api.ts +50 -1
- package/src/api/session-guard.ts +3 -3
- package/src/api/types.ts +2 -1
- package/src/cdn/cdn-upload.ts +8 -2
- package/src/cdn/upload.ts +14 -3
- package/src/monitor/monitor.ts +9 -11
- package/dist/src/media/voice-outbound.js +0 -274
- package/dist/src/media/voice-outbound.js.map +0 -1
- package/dist/src/messaging/abort-fence.js +0 -70
- package/dist/src/messaging/abort-fence.js.map +0 -1
- package/dist/src/messaging/batch-session.js +0 -271
- package/dist/src/messaging/batch-session.js.map +0 -1
- package/dist/src/messaging/buttons.js +0 -117
- package/dist/src/messaging/buttons.js.map +0 -1
- package/dist/src/messaging/lane-key.js +0 -66
- package/dist/src/messaging/lane-key.js.map +0 -1
- package/dist/src/messaging/merged-record.js +0 -149
- package/dist/src/messaging/merged-record.js.map +0 -1
- package/dist/src/messaging/model-buttons.js +0 -182
- package/dist/src/messaging/model-buttons.js.map +0 -1
- package/dist/src/messaging/model-callback-handler.js +0 -133
- package/dist/src/messaging/model-callback-handler.js.map +0 -1
- package/dist/src/messaging/run-context.js +0 -9
- package/dist/src/messaging/run-context.js.map +0 -1
- package/dist/src/messaging/run-report-session.js +0 -123
- package/dist/src/messaging/run-report-session.js.map +0 -1
- package/dist/src/monitor/lane-scheduler.js +0 -46
- package/dist/src/monitor/lane-scheduler.js.map +0 -1
- package/dist/src/runtime.js +0 -54
- package/dist/src/runtime.js.map +0 -1
- package/dist/src/streaming/batch-session.js +0 -271
- package/dist/src/streaming/batch-session.js.map +0 -1
- package/dist/src/streaming/stream-piece.js +0 -54
- package/dist/src/streaming/stream-piece.js.map +0 -1
- package/dist/src/streaming/stream-pipeline.js +0 -431
- package/dist/src/streaming/stream-pipeline.js.map +0 -1
- package/dist/src/streaming/stream-session.js +0 -260
- package/dist/src/streaming/stream-session.js.map +0 -1
- package/dist/src/streaming/stream.js +0 -239
- package/dist/src/streaming/stream.js.map +0 -1
- package/dist/src/util/markdown-fences.js +0 -54
- package/dist/src/util/markdown-fences.js.map +0 -1
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import { onAgentEvent, } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
3
|
-
import { MessageItemType } from "../api/types.js";
|
|
4
|
-
import { logger } from "../util/logger.js";
|
|
5
|
-
/** Max chars for a tool result summary before truncation. */
|
|
6
|
-
const TOOL_OUTPUT_CHAR_LIMIT = 120_000;
|
|
7
|
-
/** Default size budget for a single batch sendMessage (bytes, JSON estimate). */
|
|
8
|
-
export const BATCH_SIZE_LIMIT_BYTES = 200 * 1024;
|
|
9
|
-
function estimateSizeBytes(items) {
|
|
10
|
-
try {
|
|
11
|
-
return Buffer.byteLength(JSON.stringify(items), "utf8");
|
|
12
|
-
}
|
|
13
|
-
catch {
|
|
14
|
-
return 0;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function truncateText(text, limit) {
|
|
18
|
-
if (text.length <= limit)
|
|
19
|
-
return text;
|
|
20
|
-
return `${text.slice(0, limit)}\n\n… truncated (${text.length} chars, showing first ${limit}).`;
|
|
21
|
-
}
|
|
22
|
-
function formatToolOutput(value) {
|
|
23
|
-
if (value === null || value === undefined)
|
|
24
|
-
return "";
|
|
25
|
-
if (typeof value === "number" || typeof value === "boolean")
|
|
26
|
-
return String(value);
|
|
27
|
-
let text;
|
|
28
|
-
if (typeof value === "string") {
|
|
29
|
-
text = value;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
if (typeof value === "object") {
|
|
33
|
-
const rec = value;
|
|
34
|
-
if (typeof rec.text === "string") {
|
|
35
|
-
text = rec.text;
|
|
36
|
-
}
|
|
37
|
-
else if (Array.isArray(rec.content)) {
|
|
38
|
-
const parts = rec.content
|
|
39
|
-
.map((item) => {
|
|
40
|
-
if (item && typeof item === "object") {
|
|
41
|
-
const e = item;
|
|
42
|
-
if (e.type === "text" && typeof e.text === "string")
|
|
43
|
-
return e.text;
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
})
|
|
47
|
-
.filter((p) => p !== null);
|
|
48
|
-
text = parts.length > 0 ? parts.join("\n") : JSON.stringify(value, null, 2);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
text = JSON.stringify(value, null, 2);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
text = String(value);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return truncateText(text, TOOL_OUTPUT_CHAR_LIMIT);
|
|
59
|
-
}
|
|
60
|
-
function tryStringifyArgs(args) {
|
|
61
|
-
if (args === undefined)
|
|
62
|
-
return undefined;
|
|
63
|
-
try {
|
|
64
|
-
return JSON.stringify(args);
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* BatchSession — accumulates thinking, tool calls, and text payloads during
|
|
72
|
-
* an AI turn and sends them all in a single sendMessage at finalize time.
|
|
73
|
-
*
|
|
74
|
-
* Drop priority when item_list > BATCH_SIZE_LIMIT_BYTES:
|
|
75
|
-
* 1. Drop ThinkingItem (largest, optional for client UX)
|
|
76
|
-
* 2. Drop all ToolCallStart/Result items
|
|
77
|
-
* 3. Always keep TextItem(s) — the actual reply
|
|
78
|
-
*
|
|
79
|
-
* Usage:
|
|
80
|
-
* const session = new BatchSession({ onSendBatch });
|
|
81
|
-
* // spread replyCallbacks + runId into replyOptions
|
|
82
|
-
* replyOptions = { ...replyOptions, runId: session.runId, ...session.replyCallbacks }
|
|
83
|
-
* // in deliver(): session.addTextPayload(text)
|
|
84
|
-
* // after dispatchReplyFromConfig: await session.finalize()
|
|
85
|
-
* // on error: await session.abort()
|
|
86
|
-
*/
|
|
87
|
-
export class BatchSession {
|
|
88
|
-
/** Run id this session listens for on the global agent event bus. */
|
|
89
|
-
runId;
|
|
90
|
-
thinkingText = null;
|
|
91
|
-
toolStarts = [];
|
|
92
|
-
toolResults = [];
|
|
93
|
-
textPayloads = [];
|
|
94
|
-
done = false;
|
|
95
|
-
unsubscribeAgentEvent;
|
|
96
|
-
onSendBatch;
|
|
97
|
-
constructor(deps) {
|
|
98
|
-
this.runId = deps.runId ?? crypto.randomUUID();
|
|
99
|
-
this.onSendBatch = deps.onSendBatch;
|
|
100
|
-
this.unsubscribeAgentEvent = onAgentEvent((evt) => this.handleRawAgentEvent(evt));
|
|
101
|
-
logger.debug(`BatchSession.ctor: runId=${this.runId} agentEventListener=registered`);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Spread into replyOptions so the SDK delivers thinking/tool events here.
|
|
105
|
-
* Also set `replyOptions.runId = session.runId` so agent events carry the
|
|
106
|
-
* matching runId.
|
|
107
|
-
*/
|
|
108
|
-
get replyCallbacks() {
|
|
109
|
-
return {
|
|
110
|
-
onReasoningStream: (payload) => this.handleReasoningStream(payload),
|
|
111
|
-
onReasoningEnd: () => { },
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Store a text payload from deliver(). Each call appends one TextItem to the
|
|
116
|
-
* final item_list in call order. Skips empty strings.
|
|
117
|
-
*/
|
|
118
|
-
addTextPayload(text) {
|
|
119
|
-
if (!text.trim())
|
|
120
|
-
return;
|
|
121
|
-
this.textPayloads.push(text);
|
|
122
|
-
logger.debug(`BatchSession.addTextPayload: len=${text.length} total=${this.textPayloads.length}`);
|
|
123
|
-
}
|
|
124
|
-
// ---- private callbacks --------------------------------------------------
|
|
125
|
-
handleReasoningStream(payload) {
|
|
126
|
-
if (this.done)
|
|
127
|
-
return;
|
|
128
|
-
const text = typeof payload.text === "string" ? payload.text : "";
|
|
129
|
-
if (text) {
|
|
130
|
-
this.thinkingText = text;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
handleRawAgentEvent(evt) {
|
|
134
|
-
if (this.done)
|
|
135
|
-
return;
|
|
136
|
-
if (evt.runId !== this.runId)
|
|
137
|
-
return;
|
|
138
|
-
if (evt.stream !== "tool")
|
|
139
|
-
return;
|
|
140
|
-
const data = evt.data;
|
|
141
|
-
if (typeof data.toolCallId !== "string" || !data.toolCallId)
|
|
142
|
-
return;
|
|
143
|
-
if (data.phase === "start") {
|
|
144
|
-
this.toolStarts.push({
|
|
145
|
-
tool_call_id: data.toolCallId,
|
|
146
|
-
tool_name: typeof data.name === "string" && data.name ? data.name : "tool",
|
|
147
|
-
args_json: tryStringifyArgs(data.args),
|
|
148
|
-
});
|
|
149
|
-
logger.debug(`BatchSession: tool_call_start tool=${data.name ?? "?"} id=${data.toolCallId}` +
|
|
150
|
-
` totalStarts=${this.toolStarts.length}`);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (data.phase === "result") {
|
|
154
|
-
this.toolResults.push({
|
|
155
|
-
tool_call_id: data.toolCallId,
|
|
156
|
-
summary: formatToolOutput(data.result),
|
|
157
|
-
});
|
|
158
|
-
logger.debug(`BatchSession: tool_call_result id=${data.toolCallId}` +
|
|
159
|
-
` totalResults=${this.toolResults.length}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// ---- item_list assembly -------------------------------------------------
|
|
163
|
-
/**
|
|
164
|
-
* Build the item_list applying the 200 KB budget.
|
|
165
|
-
*
|
|
166
|
-
* Order: [ThinkingItem?, ToolCallStart+Result pairs..., TextItem(s)...]
|
|
167
|
-
*
|
|
168
|
-
* If full list > maxBytes:
|
|
169
|
-
* - drop ThinkingItem and retry
|
|
170
|
-
* - if still > maxBytes, drop all tool items too
|
|
171
|
-
* - TextItem(s) are always kept
|
|
172
|
-
*/
|
|
173
|
-
buildItemList(maxBytes = BATCH_SIZE_LIMIT_BYTES) {
|
|
174
|
-
const textItems = this.textPayloads.map((t) => ({
|
|
175
|
-
type: MessageItemType.TEXT,
|
|
176
|
-
text_item: { text: t },
|
|
177
|
-
}));
|
|
178
|
-
const toolItems = [];
|
|
179
|
-
for (const start of this.toolStarts) {
|
|
180
|
-
toolItems.push({
|
|
181
|
-
type: MessageItemType.TOOL_CALL_START,
|
|
182
|
-
tool_call_start_item: {
|
|
183
|
-
tool_name: start.tool_name,
|
|
184
|
-
tool_call_id: start.tool_call_id,
|
|
185
|
-
args_json: start.args_json,
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
const result = this.toolResults.find((r) => r.tool_call_id === start.tool_call_id);
|
|
189
|
-
if (result) {
|
|
190
|
-
toolItems.push({
|
|
191
|
-
type: MessageItemType.TOOL_CALL_RESULT,
|
|
192
|
-
tool_call_result_item: {
|
|
193
|
-
tool_call_id: result.tool_call_id,
|
|
194
|
-
summary: result.summary,
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
const thinkingItem = this.thinkingText
|
|
200
|
-
? { type: MessageItemType.THINKING, thinking_item: { text: this.thinkingText } }
|
|
201
|
-
: null;
|
|
202
|
-
// Attempt 1: full list
|
|
203
|
-
const full = [
|
|
204
|
-
...(thinkingItem ? [thinkingItem] : []),
|
|
205
|
-
...toolItems,
|
|
206
|
-
...textItems,
|
|
207
|
-
];
|
|
208
|
-
if (full.length === 0)
|
|
209
|
-
return [];
|
|
210
|
-
const fullSize = estimateSizeBytes(full);
|
|
211
|
-
logger.debug(`BatchSession.buildItemList: items=${full.length} size=${fullSize}B` +
|
|
212
|
-
` thinking=${thinkingItem !== null} tools=${this.toolStarts.length}` +
|
|
213
|
-
` texts=${this.textPayloads.length}`);
|
|
214
|
-
if (fullSize <= maxBytes)
|
|
215
|
-
return full;
|
|
216
|
-
// Attempt 2: drop thinking
|
|
217
|
-
logger.warn(`BatchSession.buildItemList: size=${fullSize}B > limit=${maxBytes}B,` +
|
|
218
|
-
` dropping ThinkingItem (len=${this.thinkingText?.length ?? 0} chars).` +
|
|
219
|
-
` Full thinking content is in the log: ${logger.getLogFilePath()}`);
|
|
220
|
-
const withoutThinking = [...toolItems, ...textItems];
|
|
221
|
-
if (withoutThinking.length === 0)
|
|
222
|
-
return [];
|
|
223
|
-
const noThinkingSize = estimateSizeBytes(withoutThinking);
|
|
224
|
-
if (noThinkingSize <= maxBytes)
|
|
225
|
-
return withoutThinking;
|
|
226
|
-
// Attempt 3: drop tool items too
|
|
227
|
-
logger.warn(`BatchSession.buildItemList: size=${noThinkingSize}B still > limit=${maxBytes}B,` +
|
|
228
|
-
` dropping ${this.toolStarts.length} tool call(s) (${toolItems.length} items).` +
|
|
229
|
-
` Full tool content is in the log: ${logger.getLogFilePath()}`);
|
|
230
|
-
return textItems.length > 0 ? textItems : [];
|
|
231
|
-
}
|
|
232
|
-
// ---- lifecycle ----------------------------------------------------------
|
|
233
|
-
/**
|
|
234
|
-
* Assemble item_list, call onSendBatch once, then clean up. Idempotent.
|
|
235
|
-
*/
|
|
236
|
-
async finalize() {
|
|
237
|
-
if (this.done)
|
|
238
|
-
return;
|
|
239
|
-
this.done = true;
|
|
240
|
-
this.cleanup();
|
|
241
|
-
const items = this.buildItemList();
|
|
242
|
-
if (items.length === 0) {
|
|
243
|
-
logger.debug("BatchSession.finalize: item_list empty, skipping send");
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
logger.debug(`BatchSession.finalize: sending ${items.length} item(s)` +
|
|
247
|
-
` thinking=${this.thinkingText !== null}` +
|
|
248
|
-
` toolStarts=${this.toolStarts.length}` +
|
|
249
|
-
` texts=${this.textPayloads.length}`);
|
|
250
|
-
await this.onSendBatch(items);
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Discard all buffered data, release event listener. Does not send. Idempotent.
|
|
254
|
-
*/
|
|
255
|
-
async abort() {
|
|
256
|
-
if (this.done)
|
|
257
|
-
return;
|
|
258
|
-
this.done = true;
|
|
259
|
-
this.cleanup();
|
|
260
|
-
logger.debug("BatchSession.abort: discarded without send");
|
|
261
|
-
}
|
|
262
|
-
cleanup() {
|
|
263
|
-
try {
|
|
264
|
-
this.unsubscribeAgentEvent();
|
|
265
|
-
}
|
|
266
|
-
catch (err) {
|
|
267
|
-
logger.warn(`BatchSession.cleanup: unsubscribe failed err=${String(err)}`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
//# sourceMappingURL=batch-session.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch-session.js","sourceRoot":"","sources":["../../../src/streaming/batch-session.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EACL,YAAY,GACb,MAAM,2CAA2C,CAAC;AAKnD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,6DAA6D;AAC7D,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC,iFAAiF;AACjF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,GAAG,IAAI,CAAC;AAEjD,SAAS,iBAAiB,CAAC,KAAoB;IAC7C,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM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AI,CAAC,OAAO,EAAE,CAAC;QAEf,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACnC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;YACtE,OAAO;QACT,CAAC;QAED,MAAM,CAAC,KAAK,CACV,kCAAkC,KAAK,CAAC,MAAM,UAAU;YACtD,aAAa,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE;YACzC,eAAe,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACvC,UAAU,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CACvC,CAAC;QACF,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC7D,CAAC;IAEO,OAAO;QACb,IAAI,CAAC;YACH,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,gDAAgD,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stream piece JSON schema — what gets base64-encoded into PieceItem.piece_data
|
|
3
|
-
* and pushed onto the ilink uplink stream.
|
|
4
|
-
*
|
|
5
|
-
* The protocol distinguishes 7 `kind`s:
|
|
6
|
-
*
|
|
7
|
-
* Lifecycle (streaming, accumulative — multiple pieces per node):
|
|
8
|
-
* - "result" agent's final reply text stream
|
|
9
|
-
* - "thinking" agent's reasoning block stream
|
|
10
|
-
*
|
|
11
|
-
* Discrete (single-frame — exactly 1 piece per occurrence):
|
|
12
|
-
* - "tool_call_start" tool invocation start snapshot
|
|
13
|
-
* - "tool_call_result" tool invocation result snapshot
|
|
14
|
-
*
|
|
15
|
-
* Piece-only (no companion sendMessage / KV write):
|
|
16
|
-
* - "tool_progress" command stdout slices / patch file list
|
|
17
|
-
* - "compaction_start" context compaction begin signal
|
|
18
|
-
* - "compaction_end" context compaction end signal
|
|
19
|
-
*
|
|
20
|
-
* Each piece carries `client_id` (the renderer node id; equals the companion
|
|
21
|
-
* sendMessage's client_id when one exists), `root_id` (= the stream_start
|
|
22
|
-
* signal's client_id, shared across the whole stream), and an optional
|
|
23
|
-
* `parent_id` (subagent only, unused this iteration).
|
|
24
|
-
*
|
|
25
|
-
* Field naming follows pb conventions (snake_case) so the same wire format is
|
|
26
|
-
* readable on every consumer language.
|
|
27
|
-
*/
|
|
28
|
-
/**
|
|
29
|
-
* Parse the SDK's `itemId` (as seen on `onItemEvent`) and extract the
|
|
30
|
-
* `tool_call_id` + `item_kind` so the channel can build a `tool_progress` piece.
|
|
31
|
-
*
|
|
32
|
-
* The SDK encodes the source kind as a prefix:
|
|
33
|
-
* - "command:<callId>" → command output progress
|
|
34
|
-
* - "patch:<callId>" → apply_patch file list summary
|
|
35
|
-
*
|
|
36
|
-
* Other prefixes (e.g. "tool:..." / "search:..." / "analysis:...") and
|
|
37
|
-
* unprefixed values return null — the caller MUST then no-op (skip the piece)
|
|
38
|
-
* to honor the "only command + patch" filter described in the plan.
|
|
39
|
-
*/
|
|
40
|
-
export function parseToolCallIdFromItemId(itemId) {
|
|
41
|
-
if (typeof itemId !== "string" || itemId.length === 0)
|
|
42
|
-
return null;
|
|
43
|
-
const m = /^(command|patch):(.+)$/.exec(itemId);
|
|
44
|
-
if (!m)
|
|
45
|
-
return null;
|
|
46
|
-
return { item_kind: m[1], tool_call_id: m[2] };
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Encode a `StreamPiece` to the base64 string consumed by `PieceItem.piece_data`.
|
|
50
|
-
*/
|
|
51
|
-
export function encodeStreamPiece(piece) {
|
|
52
|
-
return Buffer.from(JSON.stringify(piece), "utf-8").toString("base64");
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=stream-piece.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream-piece.js","sourceRoot":"","sources":["../../../src/streaming/stream-piece.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AA2HH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAc;IACtD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnE,MAAM,CAAC,GAAG,wBAAwB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAwB,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAkB;IAClD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACxE,CAAC"}
|