@deepseek-ai/dsh-client-ui-session 0.2.0-rc.1 → 0.2.1-alpha.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.i18n.yaml +2 -2
- package/README.md +0 -2
- package/README.zh.md +0 -2
- package/lib/client.js +634 -0
- package/package.json +12 -12
package/README.i18n.yaml
CHANGED
package/README.md
CHANGED
package/README.zh.md
CHANGED
package/lib/client.js
CHANGED
|
@@ -8,8 +8,642 @@ window.__ModuleLoader__.load({
|
|
|
8
8
|
let _deepseek_ai_dsh_client_store = require("@deepseek-ai/dsh-client-store");
|
|
9
9
|
let _deepseek_ai_dsh_client_ui_slots = require("@deepseek-ai/dsh-client-ui-slots");
|
|
10
10
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
|
+
//#region ../../util/values/src/partial-json.ts
|
|
12
|
+
/**
|
|
13
|
+
* Lazily scanned view of one JSON object's top-level fields, built from text
|
|
14
|
+
* that may still be streaming or from an already parsed object. Nothing is
|
|
15
|
+
* scanned until a reader asks; the view remembers every question it answered
|
|
16
|
+
* and reports changed answers when the owner refreshes for publication.
|
|
17
|
+
* Used for model tool-call arguments: a row reads the fields it
|
|
18
|
+
* cares about at whatever granularity it displays, at every stage of the call.
|
|
19
|
+
* @module @deepseek-ai/dsh-util-values/src/partial-json
|
|
20
|
+
*/
|
|
21
|
+
const SIMPLE_ESCAPES = {
|
|
22
|
+
"\"": "\"",
|
|
23
|
+
"\\": "\\",
|
|
24
|
+
"/": "/",
|
|
25
|
+
b: "\b",
|
|
26
|
+
f: "\f",
|
|
27
|
+
n: "\n",
|
|
28
|
+
r: "\r",
|
|
29
|
+
t: " "
|
|
30
|
+
};
|
|
31
|
+
const CONTENT_ESCAPE = /[\\\u0000-\u001f]/u;
|
|
32
|
+
function isWhitespace(c) {
|
|
33
|
+
return c === " " || c === "\n" || c === "\r" || c === " ";
|
|
34
|
+
}
|
|
35
|
+
function isHex(c) {
|
|
36
|
+
return c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F";
|
|
37
|
+
}
|
|
38
|
+
(class PartialArguments {
|
|
39
|
+
/** The view of a call with no arguments available. */
|
|
40
|
+
static EMPTY = PartialArguments.fromObject({});
|
|
41
|
+
/**
|
|
42
|
+
* View finished argument text without scanning it until a reader asks.
|
|
43
|
+
* @param text - the complete argument JSON text.
|
|
44
|
+
* @returns a sealed view.
|
|
45
|
+
*/
|
|
46
|
+
static fromText(text) {
|
|
47
|
+
const view = new PartialArguments();
|
|
48
|
+
view.append(text);
|
|
49
|
+
view.sealed = true;
|
|
50
|
+
return view;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* View an already parsed argument payload, such as a PTC dispatch object.
|
|
54
|
+
* @param value - the parsed argument value.
|
|
55
|
+
* @returns a sealed view; a non-object payload has no fields.
|
|
56
|
+
*/
|
|
57
|
+
static fromObject(value) {
|
|
58
|
+
const view = new PartialArguments();
|
|
59
|
+
view.object = typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
60
|
+
view.sealed = true;
|
|
61
|
+
return view;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The source: text so far or a parsed object, plus whether it can still grow.
|
|
65
|
+
* These are the only enumerable fields, so two views over the same source
|
|
66
|
+
* compare equal structurally however far each has been read.
|
|
67
|
+
*/
|
|
68
|
+
chunks = [];
|
|
69
|
+
object;
|
|
70
|
+
sealed = false;
|
|
71
|
+
#ends = [];
|
|
72
|
+
#size = 0;
|
|
73
|
+
#consumed = 0;
|
|
74
|
+
#mode = "root";
|
|
75
|
+
#escape = false;
|
|
76
|
+
#keyStart = 0;
|
|
77
|
+
#keyEscaped = false;
|
|
78
|
+
#key = "";
|
|
79
|
+
#current = null;
|
|
80
|
+
#nestedEnds = [];
|
|
81
|
+
#nestedInString = false;
|
|
82
|
+
#invalidAt;
|
|
83
|
+
#invalidValue = false;
|
|
84
|
+
#entries = /* @__PURE__ */ new Map();
|
|
85
|
+
#order = [];
|
|
86
|
+
#reads = /* @__PURE__ */ new Map();
|
|
87
|
+
/** Whether this view rejects further appends; does not scan text or register reads. */
|
|
88
|
+
get isSealed() {
|
|
89
|
+
return this.sealed;
|
|
90
|
+
}
|
|
91
|
+
/** Whether indexing or a content read found invalid JSON; unread value contents are not validated. */
|
|
92
|
+
get invalid() {
|
|
93
|
+
this.scan();
|
|
94
|
+
return this.#mode === "invalid" || this.#invalidValue;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Retain streamed argument text without scanning or comparing observed answers.
|
|
98
|
+
* @param fragment - the text following every fragment appended before.
|
|
99
|
+
*/
|
|
100
|
+
append(fragment) {
|
|
101
|
+
if (this.sealed) throw new Error("PartialArguments: cannot append to a sealed view");
|
|
102
|
+
if (fragment.length === 0) return;
|
|
103
|
+
this.chunks.push(fragment);
|
|
104
|
+
this.#size += fragment.length;
|
|
105
|
+
this.#ends.push(this.#size);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reconcile a streamed prefix with authoritative complete text without joining the fragments.
|
|
109
|
+
* @param text - the final argument text, which replaces missing or conflicting deltas.
|
|
110
|
+
* @returns this view sealed with its caches retained when every character matches; otherwise a new sealed view.
|
|
111
|
+
*/
|
|
112
|
+
settle(text) {
|
|
113
|
+
if (this.object !== void 0 || text.length !== this.#size) return PartialArguments.fromText(text);
|
|
114
|
+
let offset = 0;
|
|
115
|
+
for (const chunk of this.chunks) {
|
|
116
|
+
if (!text.startsWith(chunk, offset)) return PartialArguments.fromText(text);
|
|
117
|
+
offset += chunk.length;
|
|
118
|
+
}
|
|
119
|
+
this.chunks = text.length === 0 ? [] : [text];
|
|
120
|
+
this.#ends = text.length === 0 ? [] : [text.length];
|
|
121
|
+
this.sealed = true;
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Compare observed answers and advance their publication baseline. Unread views remain unscanned.
|
|
126
|
+
* @returns whether any observed answer changed since its first read or the preceding refresh.
|
|
127
|
+
*/
|
|
128
|
+
refresh() {
|
|
129
|
+
if (this.#reads.size === 0) return false;
|
|
130
|
+
this.scan();
|
|
131
|
+
let changed = false;
|
|
132
|
+
let completions = false;
|
|
133
|
+
for (const read of this.#reads.values()) {
|
|
134
|
+
if (read.completion) {
|
|
135
|
+
completions = true;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
changed = this.refreshRead(read) || changed;
|
|
139
|
+
}
|
|
140
|
+
if (completions) {
|
|
141
|
+
for (const read of this.#reads.values()) if (read.completion) changed = this.refreshRead(read) || changed;
|
|
142
|
+
}
|
|
143
|
+
if (this.sealed) this.#reads.clear();
|
|
144
|
+
return changed;
|
|
145
|
+
}
|
|
146
|
+
refreshRead(read) {
|
|
147
|
+
const now = read.answer();
|
|
148
|
+
if (Object.is(now, read.last)) return false;
|
|
149
|
+
read.last = now;
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check whether no further fields can arrive.
|
|
154
|
+
* @returns whether the outer object closed, indexing failed, or the view is sealed; unread values are not validated.
|
|
155
|
+
*/
|
|
156
|
+
closed() {
|
|
157
|
+
return this.remember("closed", "", () => this.closedNow());
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* List discovered fields in first-appearance order.
|
|
161
|
+
* @returns top-level keys seen so far, in first-appearance order.
|
|
162
|
+
*/
|
|
163
|
+
keys() {
|
|
164
|
+
return this.remember("keys", "", () => this.keysNow(), (keys) => keys.length);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Check whether a top-level field has appeared.
|
|
168
|
+
* @param key - argument name.
|
|
169
|
+
* @returns whether the field has appeared (a string opened or another value began).
|
|
170
|
+
*/
|
|
171
|
+
has(key) {
|
|
172
|
+
return this.remember("has", key, () => this.hasNow(key));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Check whether a field's closing delimiter has arrived, without validating its contents.
|
|
176
|
+
* @param key - argument name.
|
|
177
|
+
* @returns whether its delimiter arrived and no content reader has reported an error for this value.
|
|
178
|
+
*/
|
|
179
|
+
complete(key) {
|
|
180
|
+
return this.remember("complete", key, () => this.completeNow(key));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Read string length without materializing its text.
|
|
184
|
+
* @param key - argument name.
|
|
185
|
+
* @param options - change granularity for a streaming string.
|
|
186
|
+
* @returns decoded UTF-16 length of the string field so far; undefined when absent or not a string.
|
|
187
|
+
*/
|
|
188
|
+
stringLength(key, options) {
|
|
189
|
+
const step = Math.max(1, Math.floor(options?.step ?? 1));
|
|
190
|
+
const offset = options?.offset ?? 0;
|
|
191
|
+
return this.remember(`length:${step}:${offset}`, key, () => this.lengthNow(key), (length) => length === void 0 ? void 0 : Math.ceil((length + offset) / step));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Check a string against a decoded UTF-16 length limit without materializing it.
|
|
195
|
+
* @param key - argument name.
|
|
196
|
+
* @param maxLength - decoded UTF-16 limit, floored to at least zero.
|
|
197
|
+
* @returns whether the string is longer than the limit; false when absent or not a string.
|
|
198
|
+
*/
|
|
199
|
+
stringExceeds(key, maxLength) {
|
|
200
|
+
const limit = Math.max(0, Math.floor(maxLength));
|
|
201
|
+
return this.remember(`exceeds:${limit}`, key, () => (this.lengthNow(key, limit + 1) ?? 0) > limit);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Read a decoded string, including a streaming prefix.
|
|
205
|
+
* @param key - argument name.
|
|
206
|
+
* @returns the string field's decoded text so far; undefined when absent or not a string.
|
|
207
|
+
*/
|
|
208
|
+
text(key) {
|
|
209
|
+
return this.remember("text", key, () => this.textNow(key));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Read at most the first decoded UTF-16 units of a string.
|
|
213
|
+
* @param key - argument name.
|
|
214
|
+
* @param maxLength - maximum decoded UTF-16 length, floored to at least one.
|
|
215
|
+
* @returns the bounded string prefix; undefined when absent or not a string.
|
|
216
|
+
*/
|
|
217
|
+
textPrefix(key, maxLength) {
|
|
218
|
+
const limit = Math.max(1, Math.floor(maxLength));
|
|
219
|
+
return this.remember(`prefix:${limit}`, key, () => this.textPrefixNow(key, limit));
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Read a completed non-string argument.
|
|
223
|
+
* @param key - argument name.
|
|
224
|
+
* @returns the parsed non-string value once it closed; undefined while open, absent, or a string.
|
|
225
|
+
*/
|
|
226
|
+
value(key) {
|
|
227
|
+
return this.remember("value", key, () => this.valueNow(key));
|
|
228
|
+
}
|
|
229
|
+
/** Answer a question and, on a streaming view, remember it for change detection. */
|
|
230
|
+
remember(kind, key, read, comparison) {
|
|
231
|
+
this.scan();
|
|
232
|
+
const result = read();
|
|
233
|
+
if (!this.sealed) {
|
|
234
|
+
const id = `${kind}/${key}`;
|
|
235
|
+
if (!this.#reads.has(id)) this.#reads.set(id, {
|
|
236
|
+
completion: kind === "complete",
|
|
237
|
+
answer: comparison === void 0 ? read : () => comparison(read()),
|
|
238
|
+
last: comparison === void 0 ? result : comparison(result)
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
closedNow() {
|
|
244
|
+
return this.sealed || this.#mode === "closed" || this.#mode === "invalid";
|
|
245
|
+
}
|
|
246
|
+
keysNow() {
|
|
247
|
+
return this.object === void 0 ? this.#order : Object.keys(this.object);
|
|
248
|
+
}
|
|
249
|
+
hasNow(key) {
|
|
250
|
+
return this.object === void 0 ? this.#entries.has(key) : Object.hasOwn(this.object, key);
|
|
251
|
+
}
|
|
252
|
+
completeNow(key) {
|
|
253
|
+
if (this.object !== void 0) return Object.hasOwn(this.object, key);
|
|
254
|
+
const entry = this.#entries.get(key);
|
|
255
|
+
return entry !== void 0 && entry.end >= 0 && (entry.kind === "string" ? entry.invalidAt === void 0 : !entry.invalid);
|
|
256
|
+
}
|
|
257
|
+
lengthNow(key, limit = Number.POSITIVE_INFINITY) {
|
|
258
|
+
if (this.object !== void 0) {
|
|
259
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
260
|
+
return typeof field === "string" ? field.length : void 0;
|
|
261
|
+
}
|
|
262
|
+
const entry = this.#entries.get(key);
|
|
263
|
+
if (entry?.kind !== "string") return void 0;
|
|
264
|
+
if (entry.text !== void 0 && entry.text.at === entry.end) return entry.text.length;
|
|
265
|
+
const read = entry.length ??= {
|
|
266
|
+
at: entry.start,
|
|
267
|
+
length: 0,
|
|
268
|
+
text: ""
|
|
269
|
+
};
|
|
270
|
+
this.readString(entry, read, limit, false);
|
|
271
|
+
return read.length;
|
|
272
|
+
}
|
|
273
|
+
textNow(key) {
|
|
274
|
+
if (this.object !== void 0) {
|
|
275
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
276
|
+
return typeof field === "string" ? field : void 0;
|
|
277
|
+
}
|
|
278
|
+
const entry = this.#entries.get(key);
|
|
279
|
+
if (entry?.kind !== "string") return void 0;
|
|
280
|
+
if (entry.text === void 0 && entry.end >= 0 && entry.needsDecoding && entry.invalidAt === void 0) {
|
|
281
|
+
let text;
|
|
282
|
+
try {
|
|
283
|
+
text = JSON.parse(`"${this.slice(entry.start, entry.end)}"`);
|
|
284
|
+
} catch (_error) {}
|
|
285
|
+
if (text !== void 0) entry.text = {
|
|
286
|
+
at: entry.end,
|
|
287
|
+
length: text.length,
|
|
288
|
+
text
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const read = entry.text ??= {
|
|
292
|
+
at: entry.start,
|
|
293
|
+
length: 0,
|
|
294
|
+
text: ""
|
|
295
|
+
};
|
|
296
|
+
this.readString(entry, read, Number.POSITIVE_INFINITY, true);
|
|
297
|
+
return read.text;
|
|
298
|
+
}
|
|
299
|
+
textPrefixNow(key, maxLength) {
|
|
300
|
+
if (this.object !== void 0) {
|
|
301
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
302
|
+
return typeof field === "string" ? field.slice(0, maxLength) : void 0;
|
|
303
|
+
}
|
|
304
|
+
const entry = this.#entries.get(key);
|
|
305
|
+
if (entry?.kind !== "string") return void 0;
|
|
306
|
+
const prefixes = entry.prefixes ??= /* @__PURE__ */ new Map();
|
|
307
|
+
let read = prefixes.get(maxLength);
|
|
308
|
+
if (read === void 0) {
|
|
309
|
+
read = {
|
|
310
|
+
at: entry.start,
|
|
311
|
+
length: 0,
|
|
312
|
+
text: ""
|
|
313
|
+
};
|
|
314
|
+
prefixes.set(maxLength, read);
|
|
315
|
+
}
|
|
316
|
+
this.readString(entry, read, maxLength, true);
|
|
317
|
+
return read.text;
|
|
318
|
+
}
|
|
319
|
+
valueNow(key) {
|
|
320
|
+
if (this.object !== void 0) {
|
|
321
|
+
if (!Object.hasOwn(this.object, key)) return void 0;
|
|
322
|
+
const field = this.object[key];
|
|
323
|
+
return typeof field === "string" ? void 0 : field;
|
|
324
|
+
}
|
|
325
|
+
const entry = this.#entries.get(key);
|
|
326
|
+
if (entry?.kind !== "value" || entry.end < 0 || entry.invalid) return void 0;
|
|
327
|
+
if (entry.parsed === void 0) try {
|
|
328
|
+
entry.parsed = JSON.parse(this.slice(entry.start, entry.end));
|
|
329
|
+
} catch (_error) {
|
|
330
|
+
entry.invalid = true;
|
|
331
|
+
this.#invalidValue = true;
|
|
332
|
+
}
|
|
333
|
+
return entry.parsed;
|
|
334
|
+
}
|
|
335
|
+
chunkAt(at) {
|
|
336
|
+
let low = 0;
|
|
337
|
+
let high = this.#ends.length;
|
|
338
|
+
while (low < high) {
|
|
339
|
+
const mid = low + high >>> 1;
|
|
340
|
+
if (this.#ends[mid] <= at) low = mid + 1;
|
|
341
|
+
else high = mid;
|
|
342
|
+
}
|
|
343
|
+
return low;
|
|
344
|
+
}
|
|
345
|
+
/** Materialize only a requested range, never the cumulative source. */
|
|
346
|
+
slice(start, end) {
|
|
347
|
+
if (start >= end) return "";
|
|
348
|
+
const first = this.chunkAt(start);
|
|
349
|
+
const last = this.chunkAt(end - 1);
|
|
350
|
+
const base = first === 0 ? 0 : this.#ends[first - 1];
|
|
351
|
+
if (first === last) return this.chunks[first].slice(start - base, end - base);
|
|
352
|
+
const parts = [this.chunks[first].slice(start - base)];
|
|
353
|
+
for (let i = first + 1; i < last; i++) parts.push(this.chunks[i]);
|
|
354
|
+
parts.push(this.chunks[last].slice(0, end - this.#ends[last - 1]));
|
|
355
|
+
return parts.join("");
|
|
356
|
+
}
|
|
357
|
+
readString(entry, read, limit, materialize) {
|
|
358
|
+
const end = Math.min(entry.end < 0 ? this.#consumed : entry.end, entry.invalidAt ?? Number.POSITIVE_INFINITY, this.#invalidAt ?? Number.POSITIVE_INFINITY);
|
|
359
|
+
if (!entry.needsDecoding) {
|
|
360
|
+
const length = Math.min(end - read.at, limit - read.length);
|
|
361
|
+
if (length <= 0) return;
|
|
362
|
+
if (materialize) read.text += this.slice(read.at, read.at + length);
|
|
363
|
+
read.at += length;
|
|
364
|
+
read.length += length;
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
let chunkIndex = this.chunkAt(read.at);
|
|
368
|
+
while (read.at < end && read.length < limit) {
|
|
369
|
+
const base = chunkIndex === 0 ? 0 : this.#ends[chunkIndex - 1];
|
|
370
|
+
const chunk = this.chunks[chunkIndex];
|
|
371
|
+
const remaining = chunk.slice(read.at - base, Math.min(chunk.length, end - base));
|
|
372
|
+
const boundary = remaining.search(CONTENT_ESCAPE);
|
|
373
|
+
const length = Math.min(boundary < 0 ? remaining.length : boundary, limit - read.length);
|
|
374
|
+
if (length > 0) {
|
|
375
|
+
if (materialize) read.text += remaining.slice(0, length);
|
|
376
|
+
read.at += length;
|
|
377
|
+
read.length += length;
|
|
378
|
+
if (read.at === base + chunk.length) chunkIndex++;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const type = remaining.length > 1 ? remaining[1] : read.at + 1 < end ? this.chunks[chunkIndex + 1][0] : void 0;
|
|
382
|
+
let decoded;
|
|
383
|
+
let width = 2;
|
|
384
|
+
if (remaining[0] === "\\" && type === void 0 && entry.end < 0) return;
|
|
385
|
+
if (remaining[0] === "\\" && type === "u") {
|
|
386
|
+
const hex = this.slice(read.at + 2, Math.min(end, read.at + 6));
|
|
387
|
+
let valid = true;
|
|
388
|
+
for (let i = 0; i < hex.length; i++) if (!isHex(hex[i])) valid = false;
|
|
389
|
+
if (valid) {
|
|
390
|
+
if (hex.length < 4 && entry.end < 0) return;
|
|
391
|
+
if (hex.length === 4) decoded = String.fromCharCode(Number.parseInt(hex, 16));
|
|
392
|
+
}
|
|
393
|
+
width = 6;
|
|
394
|
+
} else if (remaining[0] === "\\" && type !== void 0) decoded = SIMPLE_ESCAPES[type];
|
|
395
|
+
if (decoded === void 0) {
|
|
396
|
+
entry.invalidAt = read.at;
|
|
397
|
+
this.#invalidValue = true;
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (materialize) read.text += decoded;
|
|
401
|
+
read.length++;
|
|
402
|
+
read.at += width;
|
|
403
|
+
while (chunkIndex < this.chunks.length && read.at >= this.#ends[chunkIndex]) chunkIndex++;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/** Locate new field ranges without decoding or parsing their contents. */
|
|
407
|
+
scan() {
|
|
408
|
+
if (this.object !== void 0 || this.#consumed === this.#size) return;
|
|
409
|
+
for (let i = this.chunkAt(this.#consumed); i < this.chunks.length && this.#invalidAt === void 0; i++) {
|
|
410
|
+
const pending = this.chunks[i];
|
|
411
|
+
const base = i === 0 ? 0 : this.#ends[i - 1];
|
|
412
|
+
for (let index = this.#consumed - base; index < pending.length && this.#mode !== "invalid"; index++) {
|
|
413
|
+
if (this.#mode === "string" || this.#mode === "nested" && this.#nestedInString) {
|
|
414
|
+
const end = this.stringBoundary(pending, index);
|
|
415
|
+
this.#consumed += end - index;
|
|
416
|
+
index = end;
|
|
417
|
+
if (index === pending.length) break;
|
|
418
|
+
}
|
|
419
|
+
this.step(pending[index], this.#consumed);
|
|
420
|
+
this.#consumed++;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/** Only raw quotes and their preceding backslash runs can terminate a string. */
|
|
425
|
+
stringBoundary(fragment, start) {
|
|
426
|
+
let at = start;
|
|
427
|
+
while (true) {
|
|
428
|
+
const quote = fragment.indexOf("\"", at);
|
|
429
|
+
const end = quote < 0 ? fragment.length : quote;
|
|
430
|
+
if (this.#mode === "string") {
|
|
431
|
+
const entry = this.#current;
|
|
432
|
+
if (!entry.needsDecoding && CONTENT_ESCAPE.test(fragment.slice(at, end))) entry.needsDecoding = true;
|
|
433
|
+
}
|
|
434
|
+
let slashStart = end;
|
|
435
|
+
while (slashStart > at && fragment[slashStart - 1] === "\\") slashStart--;
|
|
436
|
+
const escaped = (end - slashStart) % 2 === 1 !== (slashStart === at && this.#escape);
|
|
437
|
+
this.#escape = quote < 0 && escaped;
|
|
438
|
+
if (quote < 0 || !escaped) return end;
|
|
439
|
+
at = quote + 1;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
step(c, at) {
|
|
443
|
+
switch (this.#mode) {
|
|
444
|
+
case "root":
|
|
445
|
+
if (isWhitespace(c)) return;
|
|
446
|
+
if (c === "{") {
|
|
447
|
+
this.#mode = "key-or-end";
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
this.fail();
|
|
451
|
+
return;
|
|
452
|
+
case "key-or-end":
|
|
453
|
+
if (isWhitespace(c)) return;
|
|
454
|
+
if (c === "}") {
|
|
455
|
+
this.#mode = "closed";
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (c === "\"") {
|
|
459
|
+
this.beginKey(at);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
this.fail();
|
|
463
|
+
return;
|
|
464
|
+
case "key-only":
|
|
465
|
+
if (isWhitespace(c)) return;
|
|
466
|
+
if (c === "\"") {
|
|
467
|
+
this.beginKey(at);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
this.fail();
|
|
471
|
+
return;
|
|
472
|
+
case "key":
|
|
473
|
+
this.stepKey(c, at);
|
|
474
|
+
return;
|
|
475
|
+
case "colon":
|
|
476
|
+
if (isWhitespace(c)) return;
|
|
477
|
+
if (c === ":") {
|
|
478
|
+
this.#mode = "value";
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
this.fail();
|
|
482
|
+
return;
|
|
483
|
+
case "value":
|
|
484
|
+
this.beginValue(c, at);
|
|
485
|
+
return;
|
|
486
|
+
case "string": {
|
|
487
|
+
const entry = this.#current;
|
|
488
|
+
entry.end = at;
|
|
489
|
+
this.#current = null;
|
|
490
|
+
this.#mode = "comma-or-end";
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
case "scalar":
|
|
494
|
+
this.stepScalar(c, at);
|
|
495
|
+
return;
|
|
496
|
+
case "nested":
|
|
497
|
+
this.stepNested(c, at);
|
|
498
|
+
return;
|
|
499
|
+
case "comma-or-end":
|
|
500
|
+
if (isWhitespace(c)) return;
|
|
501
|
+
if (c === ",") {
|
|
502
|
+
this.#mode = "key-only";
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (c === "}") {
|
|
506
|
+
this.#mode = "closed";
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
this.fail();
|
|
510
|
+
return;
|
|
511
|
+
case "closed":
|
|
512
|
+
if (isWhitespace(c)) return;
|
|
513
|
+
this.fail();
|
|
514
|
+
return;
|
|
515
|
+
/* v8 ignore next 2 -- scan() stops stepping once the view is invalid. */
|
|
516
|
+
case "invalid": return;
|
|
517
|
+
/* v8 ignore next 2 -- Every scanner mode has a handler above. */
|
|
518
|
+
default: assertNever(this.#mode);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
fail() {
|
|
522
|
+
this.#invalidAt = this.#consumed;
|
|
523
|
+
this.#mode = "invalid";
|
|
524
|
+
this.#current = null;
|
|
525
|
+
}
|
|
526
|
+
beginKey(at) {
|
|
527
|
+
this.#mode = "key";
|
|
528
|
+
this.#keyStart = at + 1;
|
|
529
|
+
this.#keyEscaped = false;
|
|
530
|
+
this.#escape = false;
|
|
531
|
+
}
|
|
532
|
+
stepKey(c, at) {
|
|
533
|
+
if (c < " ") {
|
|
534
|
+
this.fail();
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
if (this.#escape) {
|
|
538
|
+
this.#escape = false;
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (c === "\\") {
|
|
542
|
+
this.#escape = true;
|
|
543
|
+
this.#keyEscaped = true;
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (c !== "\"") return;
|
|
547
|
+
const raw = this.slice(this.#keyStart, at);
|
|
548
|
+
if (this.#keyEscaped) try {
|
|
549
|
+
this.#key = JSON.parse(`"${raw}"`);
|
|
550
|
+
} catch (_error) {
|
|
551
|
+
this.fail();
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
else this.#key = raw;
|
|
555
|
+
this.#mode = "colon";
|
|
556
|
+
}
|
|
557
|
+
open(entry) {
|
|
558
|
+
if (!this.#entries.has(this.#key)) this.#order.push(this.#key);
|
|
559
|
+
this.#entries.set(this.#key, entry);
|
|
560
|
+
this.#current = entry;
|
|
561
|
+
}
|
|
562
|
+
beginValue(c, at) {
|
|
563
|
+
if (isWhitespace(c)) return;
|
|
564
|
+
if (c === "\"") {
|
|
565
|
+
this.open({
|
|
566
|
+
kind: "string",
|
|
567
|
+
start: at + 1,
|
|
568
|
+
end: -1,
|
|
569
|
+
needsDecoding: false,
|
|
570
|
+
invalidAt: void 0,
|
|
571
|
+
length: void 0,
|
|
572
|
+
text: void 0,
|
|
573
|
+
prefixes: void 0
|
|
574
|
+
});
|
|
575
|
+
this.#escape = false;
|
|
576
|
+
this.#mode = "string";
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (c === "}" || c === "," || c === ":" || c === "]") {
|
|
580
|
+
this.fail();
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
this.open({
|
|
584
|
+
kind: "value",
|
|
585
|
+
start: at,
|
|
586
|
+
end: -1,
|
|
587
|
+
parsed: void 0,
|
|
588
|
+
invalid: false
|
|
589
|
+
});
|
|
590
|
+
if (c === "{" || c === "[") {
|
|
591
|
+
this.#mode = "nested";
|
|
592
|
+
this.#nestedEnds = [c === "{" ? "}" : "]"];
|
|
593
|
+
this.#nestedInString = false;
|
|
594
|
+
this.#escape = false;
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
this.#mode = "scalar";
|
|
598
|
+
}
|
|
599
|
+
stepScalar(c, at) {
|
|
600
|
+
if (c !== "," && c !== "}" && !isWhitespace(c)) return;
|
|
601
|
+
this.closeValue(at);
|
|
602
|
+
this.#mode = c === "," ? "key-only" : c === "}" ? "closed" : "comma-or-end";
|
|
603
|
+
}
|
|
604
|
+
stepNested(c, at) {
|
|
605
|
+
if (this.#nestedInString) {
|
|
606
|
+
this.#nestedInString = false;
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
if (c === "\"") {
|
|
610
|
+
this.#nestedInString = true;
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (c === "{" || c === "[") {
|
|
614
|
+
this.#nestedEnds.push(c === "{" ? "}" : "]");
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if (c === "}" || c === "]") {
|
|
618
|
+
if (this.#nestedEnds.pop() !== c) {
|
|
619
|
+
this.fail();
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (this.#nestedEnds.length === 0) {
|
|
623
|
+
this.closeValue(at + 1);
|
|
624
|
+
this.#mode = "comma-or-end";
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
closeValue(end) {
|
|
629
|
+
const entry = this.#current;
|
|
630
|
+
entry.end = end;
|
|
631
|
+
this.#current = null;
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
//#endregion
|
|
11
635
|
//#region ../../util/values/src/index.ts
|
|
12
636
|
/**
|
|
637
|
+
* Mark an unreachable closed-union branch.
|
|
638
|
+
* @param value - impossible value; an unhandled typed variant fails at the call site.
|
|
639
|
+
* @param context - optional switch-site label included in the failure message.
|
|
640
|
+
* @returns never; a runtime value that escaped its type always throws.
|
|
641
|
+
*/
|
|
642
|
+
function assertNever(value, context) {
|
|
643
|
+
const rendered = JSON.stringify(value) ?? String(value);
|
|
644
|
+
throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
13
647
|
* Weak-key lookup with a strongly retained iterable set of associated values.
|
|
14
648
|
*
|
|
15
649
|
* Each value must belong to only one key. The container performs no automatic
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-client-ui-session",
|
|
3
3
|
"description": "Session Controller adapter for React and session-scoped slots",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1-alpha.1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -37,21 +37,21 @@
|
|
|
37
37
|
},
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@deepseek-ai/cordis": "~4.0.
|
|
40
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/react": "~18.3.1",
|
|
44
44
|
"react": "^18.2.0",
|
|
45
|
-
"@deepseek-ai/dsh-api-
|
|
46
|
-
"@deepseek-ai/dsh-
|
|
47
|
-
"@deepseek-ai/
|
|
48
|
-
"@deepseek-ai/dsh-client-
|
|
49
|
-
"@deepseek-ai/dsh-
|
|
50
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.
|
|
51
|
-
"@deepseek-ai/dsh-
|
|
52
|
-
"@deepseek-ai/dsh-
|
|
53
|
-
"@deepseek-ai/dsh-
|
|
54
|
-
"@deepseek-ai/
|
|
45
|
+
"@deepseek-ai/dsh-api-remotes": "0.2.1-alpha.1",
|
|
46
|
+
"@deepseek-ai/dsh-api-session-controller": "0.2.1-alpha.1",
|
|
47
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.1",
|
|
48
|
+
"@deepseek-ai/dsh-client-store": "0.2.1-alpha.1",
|
|
49
|
+
"@deepseek-ai/dsh-client-test-runtime": "0.2.1-alpha.1",
|
|
50
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.1-alpha.1",
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.1-alpha.1",
|
|
52
|
+
"@deepseek-ai/dsh-remote-mock": "0.2.1-alpha.1",
|
|
53
|
+
"@deepseek-ai/dsh-util-values": "0.2.1-alpha.1",
|
|
54
|
+
"@deepseek-ai/dsh-session": "0.2.1-alpha.1"
|
|
55
55
|
},
|
|
56
56
|
"files": [
|
|
57
57
|
"lib/index.js",
|