@opencode/util 2.3.0 → 2.3.2
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/dist/session-turn.d.ts +0 -5
- package/dist/session-turn.js +0 -10
- package/dist/text-boundary.d.ts +13 -0
- package/dist/text-boundary.js +35 -0
- package/package.json +1 -1
package/dist/session-turn.d.ts
CHANGED
|
@@ -34,9 +34,4 @@ export declare function duration(messages: readonly Message[], message: Message,
|
|
|
34
34
|
* from request dispatch instead, which is what this measured for them before the field existed.
|
|
35
35
|
*/
|
|
36
36
|
export declare function tokensPerSecond(messages: readonly Message[], message: Message, options?: Options): number | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Milliseconds from the dispatch of the turn's first token-producing step to its first streamed token, or undefined
|
|
39
|
-
* until a step records one.
|
|
40
|
-
*/
|
|
41
|
-
export declare function timeToFirstToken(messages: readonly Message[], message: Message, options?: Options): number | undefined;
|
|
42
37
|
export declare function legacy(messages: readonly Message[]): boolean;
|
package/dist/session-turn.js
CHANGED
|
@@ -28,16 +28,6 @@ export function tokensPerSecond(messages, message, options = {}) {
|
|
|
28
28
|
// Aggregate before dividing so each step is weighted by its provider-active duration.
|
|
29
29
|
return output / (total / 1_000);
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Milliseconds from the dispatch of the turn's first token-producing step to its first streamed token, or undefined
|
|
33
|
-
* until a step records one.
|
|
34
|
-
*/
|
|
35
|
-
export function timeToFirstToken(messages, message, options = {}) {
|
|
36
|
-
const step = turnSteps(messages, message, options).find((item) => item.time.firstToken !== undefined);
|
|
37
|
-
if (step?.time.firstToken === undefined)
|
|
38
|
-
return;
|
|
39
|
-
return Math.max(0, step.time.firstToken - step.time.created);
|
|
40
|
-
}
|
|
41
31
|
export function legacy(messages) {
|
|
42
32
|
return !messages.some((message) => message.type === "idle");
|
|
43
33
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * as TextBoundary from "./text-boundary.js";
|
|
2
|
+
/**
|
|
3
|
+
* Clip text to a budget without ending or starting on half a character. `head` and `tail` count UTF-16 code units,
|
|
4
|
+
* like `.length`; `utf8Tail` counts bytes of UTF-8 output that has not been decoded yet. The result can be shorter
|
|
5
|
+
* than the budget by the part of the character at the cut, and `head("😀", 1)` is empty. Boundaries are code points,
|
|
6
|
+
* not graphemes, and malformed input is kept as it is everywhere except at the cut.
|
|
7
|
+
*/
|
|
8
|
+
/** The first `limit` code units of `text`, without a high surrogate whose pair the limit cut off. */
|
|
9
|
+
export declare function head(text: string, limit: number): string;
|
|
10
|
+
/** The last `limit` code units of `text`, without a low surrogate whose pair the limit cut off. */
|
|
11
|
+
export declare function tail(text: string, limit: number): string;
|
|
12
|
+
/** The last `limit` bytes of `bytes`, decoded, after skipping up to 3 continuation bytes of a cut character. */
|
|
13
|
+
export declare function utf8Tail(bytes: Uint8Array, limit: number): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export * as TextBoundary from "./text-boundary.js";
|
|
2
|
+
/**
|
|
3
|
+
* Clip text to a budget without ending or starting on half a character. `head` and `tail` count UTF-16 code units,
|
|
4
|
+
* like `.length`; `utf8Tail` counts bytes of UTF-8 output that has not been decoded yet. The result can be shorter
|
|
5
|
+
* than the budget by the part of the character at the cut, and `head("😀", 1)` is empty. Boundaries are code points,
|
|
6
|
+
* not graphemes, and malformed input is kept as it is everywhere except at the cut.
|
|
7
|
+
*/
|
|
8
|
+
/** The first `limit` code units of `text`, without a high surrogate whose pair the limit cut off. */
|
|
9
|
+
export function head(text, limit) {
|
|
10
|
+
if (text.length <= limit)
|
|
11
|
+
return text;
|
|
12
|
+
const code = text.charCodeAt(limit - 1);
|
|
13
|
+
return text.slice(0, code >= 0xd800 && code <= 0xdbff ? limit - 1 : limit);
|
|
14
|
+
}
|
|
15
|
+
/** The last `limit` code units of `text`, without a low surrogate whose pair the limit cut off. */
|
|
16
|
+
export function tail(text, limit) {
|
|
17
|
+
if (text.length <= limit)
|
|
18
|
+
return text;
|
|
19
|
+
const start = text.length - limit;
|
|
20
|
+
const code = text.charCodeAt(start);
|
|
21
|
+
return text.slice(code >= 0xdc00 && code <= 0xdfff ? start + 1 : start);
|
|
22
|
+
}
|
|
23
|
+
/** The last `limit` bytes of `bytes`, decoded, after skipping up to 3 continuation bytes of a cut character. */
|
|
24
|
+
export function utf8Tail(bytes, limit) {
|
|
25
|
+
if (bytes.length <= limit)
|
|
26
|
+
return decoder.decode(bytes);
|
|
27
|
+
const start = bytes.length - limit;
|
|
28
|
+
const end = Math.min(bytes.length, start + 3);
|
|
29
|
+
let index = start;
|
|
30
|
+
while (index < end && (bytes[index] & 0xc0) === 0x80)
|
|
31
|
+
index++;
|
|
32
|
+
return decoder.decode(bytes.subarray(index));
|
|
33
|
+
}
|
|
34
|
+
// Like Buffer#toString, keep a leading byte order mark.
|
|
35
|
+
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|