@pasko70/pibo 3.4.2 → 3.4.3
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/agent-runtime/routed-session.js +2 -1
- package/dist/apps/chat/chat-settings-routes.js +10 -0
- package/dist/apps/chat-ui/assets/{dist-B7Ju7u08.js → dist-B4YhOxh0.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-CAiO6h6z.js → dist-BkUu8WPA.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-BDnWOTcs.js → dist-C8GzUMPk.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-CXWLhBio.js → dist-Cyb4rVa6.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-CCR1HsaR.js → dist-DeMKnZR8.js} +1 -1
- package/dist/apps/chat-ui/assets/index-BOceJ0jM.css +1 -0
- package/dist/apps/chat-ui/assets/index-Dk4mbXAB.js +228 -0
- package/dist/apps/chat-ui/index.html +2 -2
- package/dist/apps/chat-vscode-web/assets/index-0oTGFHni.js +43 -0
- package/dist/apps/chat-vscode-web/index.html +1 -1
- package/dist/core/session-router.js +1 -0
- package/dist/core/user-settings.js +11 -0
- package/dist/shared/tool-call-metrics.js +68 -7
- package/dist/shared/tool-call-token-settings.js +45 -0
- package/npm-shrinkwrap.json +22 -13
- package/package.json +2 -1
- package/dist/apps/chat-ui/assets/index-0cCGS0o3.js +0 -228
- package/dist/apps/chat-ui/assets/index-BMJGoyM8.css +0 -1
- package/dist/apps/chat-vscode-web/assets/index-BD3Ogz9Z.js +0 -43
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<meta name="theme-color" content="#101d22" />
|
|
7
7
|
<title>Pibo</title>
|
|
8
|
-
<script type="module" crossorigin src="/apps/chat-vscode/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/apps/chat-vscode/assets/index-0oTGFHni.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/apps/chat-vscode/assets/index-b18ZkEo0.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
@@ -1552,6 +1552,7 @@ export class PiboSessionRouter {
|
|
|
1552
1552
|
return result;
|
|
1553
1553
|
},
|
|
1554
1554
|
statusResources,
|
|
1555
|
+
getToolMetricTokenCalculation: () => loadPiboUserSettings().toolMetrics.tokenCalculation,
|
|
1555
1556
|
});
|
|
1556
1557
|
this.sessions.set(piboSession.id, session);
|
|
1557
1558
|
return session;
|
|
@@ -4,6 +4,7 @@ import { piboHomePath } from "./pibo-home.js";
|
|
|
4
4
|
import { sanitizePreviewServerSettings } from "./preview-server-settings.js";
|
|
5
5
|
import { sanitizeTelemetryRetentionSettings } from "./telemetry-retention-settings.js";
|
|
6
6
|
import { sanitizeTelemetryStaleThresholdSettings } from "./telemetry-staleness.js";
|
|
7
|
+
import { DEFAULT_TOOL_METRIC_TOKEN_CALCULATION, parseToolMetricTokenCalculation, } from "../shared/tool-call-token-settings.js";
|
|
7
8
|
export const DEFAULT_USER_TIMEZONE = "UTC";
|
|
8
9
|
export const DEFAULT_WEB_ANNOTATIONS_TOGGLE_SHORTCUT = "Alt+Shift+A";
|
|
9
10
|
export const DEFAULT_TRANSCRIPTION_PROVIDER_ID = "openai-chatgpt";
|
|
@@ -64,6 +65,15 @@ export function sanitizeSpeechSettings(value) {
|
|
|
64
65
|
: {};
|
|
65
66
|
return { providerId: sanitizeTranscriptionProviderId(raw.providerId) ?? DEFAULT_SPEECH_PROVIDER_ID };
|
|
66
67
|
}
|
|
68
|
+
export function sanitizeToolMetricSettings(value) {
|
|
69
|
+
const raw = value && typeof value === "object" && !Array.isArray(value)
|
|
70
|
+
? value
|
|
71
|
+
: {};
|
|
72
|
+
return {
|
|
73
|
+
tokenCalculation: parseToolMetricTokenCalculation(raw.tokenCalculation)
|
|
74
|
+
?? DEFAULT_TOOL_METRIC_TOKEN_CALCULATION,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
67
77
|
export function sanitizeTimezone(value) {
|
|
68
78
|
if (typeof value !== "string")
|
|
69
79
|
return undefined;
|
|
@@ -87,6 +97,7 @@ function sanitizeUserSettings(value) {
|
|
|
87
97
|
shortcuts: sanitizeShortcutSettings(raw.shortcuts),
|
|
88
98
|
transcription: sanitizeTranscriptionSettings(raw.transcription),
|
|
89
99
|
speech: sanitizeSpeechSettings(raw.speech),
|
|
100
|
+
toolMetrics: sanitizeToolMetricSettings(raw.toolMetrics),
|
|
90
101
|
previewServers: sanitizePreviewServerSettings(raw.previewServers),
|
|
91
102
|
telemetryStaleThresholds: sanitizeTelemetryStaleThresholdSettings(raw.telemetryStaleThresholds),
|
|
92
103
|
telemetryRetention: sanitizeTelemetryRetentionSettings(raw.telemetryRetention),
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { DEFAULT_TOOL_METRIC_TOKEN_CALCULATION, sanitizeToolMetricTokenCalculation, toolMetricTokenBasis, } from "./tool-call-token-settings.js";
|
|
3
|
+
export const MAX_TIKTOKEN_PAYLOAD_CHARACTERS = 4_000_000;
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
let activeTokenizer;
|
|
6
|
+
/** Bounded structural walk; character mode never tokenizes, copies, or scans large strings. */
|
|
7
|
+
export function measureToolPayloadCharacters(payload) {
|
|
3
8
|
let budget = 10_000;
|
|
4
9
|
const seen = new WeakSet();
|
|
5
10
|
function size(value, depth) {
|
|
@@ -26,7 +31,6 @@ export function estimateToolPayloadTokens(payload) {
|
|
|
26
31
|
}
|
|
27
32
|
else {
|
|
28
33
|
const record = value;
|
|
29
|
-
// Binary/media payloads have no meaningful character-based token count.
|
|
30
34
|
if (["image", "audio", "document", "resource", "image_url"].includes(String(record.type)))
|
|
31
35
|
return NaN;
|
|
32
36
|
for (const key in record) {
|
|
@@ -44,7 +48,26 @@ export function estimateToolPayloadTokens(payload) {
|
|
|
44
48
|
}
|
|
45
49
|
try {
|
|
46
50
|
const chars = size(payload, 0);
|
|
47
|
-
return Number.isFinite(chars) ?
|
|
51
|
+
return Number.isFinite(chars) ? chars : undefined;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function estimateToolPayloadTokens(payload, calculation = DEFAULT_TOOL_METRIC_TOKEN_CALCULATION) {
|
|
58
|
+
try {
|
|
59
|
+
const normalized = sanitizeToolMetricTokenCalculation(calculation);
|
|
60
|
+
if (normalized.method === "characters") {
|
|
61
|
+
const chars = measureToolPayloadCharacters(payload);
|
|
62
|
+
if (chars === undefined)
|
|
63
|
+
return undefined;
|
|
64
|
+
const tokens = Math.ceil(chars / normalized.factor);
|
|
65
|
+
return Number.isSafeInteger(tokens) ? tokens : undefined;
|
|
66
|
+
}
|
|
67
|
+
const text = serializableToolPayloadText(payload);
|
|
68
|
+
if (text === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
return tiktokenPayloadTokens(text, normalized.encoding);
|
|
48
71
|
}
|
|
49
72
|
catch {
|
|
50
73
|
// Diagnostics must not turn an otherwise successful tool into a failure.
|
|
@@ -52,26 +75,64 @@ export function estimateToolPayloadTokens(payload) {
|
|
|
52
75
|
}
|
|
53
76
|
}
|
|
54
77
|
export class ToolCallMetricsCollector {
|
|
78
|
+
getCalculation;
|
|
55
79
|
active = new Map();
|
|
80
|
+
constructor(getCalculation = () => DEFAULT_TOOL_METRIC_TOKEN_CALCULATION) {
|
|
81
|
+
this.getCalculation = getCalculation;
|
|
82
|
+
}
|
|
56
83
|
start(id, args, now = performance.now()) {
|
|
57
84
|
if (this.active.has(id))
|
|
58
85
|
return;
|
|
59
|
-
|
|
86
|
+
const calculation = this.currentCalculation();
|
|
87
|
+
this.active.set(id, {
|
|
88
|
+
startedAt: now,
|
|
89
|
+
inputTokens: estimateToolPayloadTokens(args, calculation),
|
|
90
|
+
calculation,
|
|
91
|
+
});
|
|
60
92
|
}
|
|
61
93
|
finish(id, result, now = performance.now()) {
|
|
62
94
|
const started = this.active.get(id);
|
|
63
95
|
this.active.delete(id);
|
|
96
|
+
const calculation = started?.calculation ?? this.currentCalculation();
|
|
64
97
|
// Harness result metadata is not model-visible tool output.
|
|
65
98
|
const output = result && typeof result === "object" && "content" in result
|
|
66
99
|
? result.content : result;
|
|
67
100
|
return {
|
|
68
|
-
tokenBasis:
|
|
101
|
+
tokenBasis: toolMetricTokenBasis(calculation),
|
|
69
102
|
durationMs: started ? Math.max(0, now - started.startedAt) : undefined,
|
|
70
103
|
inputTokens: started?.inputTokens,
|
|
71
|
-
outputTokens: estimateToolPayloadTokens(output),
|
|
104
|
+
outputTokens: estimateToolPayloadTokens(output, calculation),
|
|
72
105
|
};
|
|
73
106
|
}
|
|
74
107
|
clear() {
|
|
75
108
|
this.active.clear();
|
|
76
109
|
}
|
|
110
|
+
currentCalculation() {
|
|
111
|
+
try {
|
|
112
|
+
return sanitizeToolMetricTokenCalculation(this.getCalculation());
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return DEFAULT_TOOL_METRIC_TOKEN_CALCULATION;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function serializableToolPayloadText(payload) {
|
|
120
|
+
const measuredCharacters = measureToolPayloadCharacters(payload);
|
|
121
|
+
if (measuredCharacters === undefined || measuredCharacters > MAX_TIKTOKEN_PAYLOAD_CHARACTERS)
|
|
122
|
+
return undefined;
|
|
123
|
+
if (typeof payload === "string")
|
|
124
|
+
return payload;
|
|
125
|
+
const serialized = JSON.stringify(payload);
|
|
126
|
+
return typeof serialized === "string" && serialized.length <= MAX_TIKTOKEN_PAYLOAD_CHARACTERS
|
|
127
|
+
? serialized
|
|
128
|
+
: undefined;
|
|
129
|
+
}
|
|
130
|
+
function tiktokenPayloadTokens(text, encoding) {
|
|
131
|
+
if (activeTokenizer?.encoding !== encoding) {
|
|
132
|
+
activeTokenizer?.tokenizer.free();
|
|
133
|
+
const tiktoken = require("tiktoken");
|
|
134
|
+
activeTokenizer = { encoding, tokenizer: tiktoken.get_encoding(encoding) };
|
|
135
|
+
}
|
|
136
|
+
const tokens = activeTokenizer.tokenizer.encode_ordinary(text).length;
|
|
137
|
+
return Number.isSafeInteger(tokens) ? tokens : undefined;
|
|
77
138
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const TIKTOKEN_ENCODINGS = [
|
|
2
|
+
"o200k_base",
|
|
3
|
+
"cl100k_base",
|
|
4
|
+
"p50k_base",
|
|
5
|
+
"r50k_base",
|
|
6
|
+
"p50k_edit",
|
|
7
|
+
"gpt2",
|
|
8
|
+
];
|
|
9
|
+
export const DEFAULT_TOOL_METRIC_TOKEN_CALCULATION = {
|
|
10
|
+
method: "characters",
|
|
11
|
+
factor: 4,
|
|
12
|
+
};
|
|
13
|
+
export function parseToolMetricTokenCalculation(value) {
|
|
14
|
+
if (!isRecord(value))
|
|
15
|
+
return undefined;
|
|
16
|
+
if (value.method === "characters") {
|
|
17
|
+
return typeof value.factor === "number" && Number.isFinite(value.factor) && value.factor > 0
|
|
18
|
+
? { method: "characters", factor: value.factor }
|
|
19
|
+
: undefined;
|
|
20
|
+
}
|
|
21
|
+
if (value.method === "tiktoken" && typeof value.encoding === "string" && TIKTOKEN_ENCODINGS.includes(value.encoding)) {
|
|
22
|
+
return { method: "tiktoken", encoding: value.encoding };
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
export function sanitizeToolMetricTokenCalculation(value) {
|
|
27
|
+
return parseToolMetricTokenCalculation(value) ?? DEFAULT_TOOL_METRIC_TOKEN_CALCULATION;
|
|
28
|
+
}
|
|
29
|
+
export function toolMetricTokenBasis(calculation) {
|
|
30
|
+
return calculation.method === "characters"
|
|
31
|
+
? `characters/${calculation.factor}`
|
|
32
|
+
: `tiktoken/${calculation.encoding}`;
|
|
33
|
+
}
|
|
34
|
+
export function toolMetricTokenBasisLabel(basis) {
|
|
35
|
+
if (!basis)
|
|
36
|
+
return "—";
|
|
37
|
+
if (basis === "chars/4")
|
|
38
|
+
return "chars ÷ 4";
|
|
39
|
+
if (basis.startsWith("characters/"))
|
|
40
|
+
return `chars ÷ ${basis.slice("characters/".length)}`;
|
|
41
|
+
return `tiktoken · ${basis.slice("tiktoken/".length)}`;
|
|
42
|
+
}
|
|
43
|
+
function isRecord(value) {
|
|
44
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45
|
+
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pasko70/pibo",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@pasko70/pibo",
|
|
9
|
-
"version": "3.4.
|
|
9
|
+
"version": "3.4.3",
|
|
10
10
|
"workspaces": [
|
|
11
11
|
"packages/workflows"
|
|
12
12
|
],
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"react-virtuoso": "^4.18.6",
|
|
40
40
|
"remark-gfm": "^4.0.1",
|
|
41
41
|
"tailwindcss": "^4.2.4",
|
|
42
|
+
"tiktoken": "^1.0.22",
|
|
42
43
|
"typebox": "1.1.38",
|
|
43
44
|
"xstate": "5.31.1"
|
|
44
45
|
},
|
|
@@ -11502,7 +11503,7 @@
|
|
|
11502
11503
|
"license": "MIT",
|
|
11503
11504
|
"peer": true,
|
|
11504
11505
|
"funding": {
|
|
11505
|
-
"type": "GitHub Sponsors
|
|
11506
|
+
"type": "GitHub Sponsors ❤",
|
|
11506
11507
|
"url": "https://github.com/sponsors/dmonad"
|
|
11507
11508
|
}
|
|
11508
11509
|
},
|
|
@@ -11781,7 +11782,7 @@
|
|
|
11781
11782
|
"node": ">=16"
|
|
11782
11783
|
},
|
|
11783
11784
|
"funding": {
|
|
11784
|
-
"type": "GitHub Sponsors
|
|
11785
|
+
"type": "GitHub Sponsors ❤",
|
|
11785
11786
|
"url": "https://github.com/sponsors/dmonad"
|
|
11786
11787
|
}
|
|
11787
11788
|
},
|
|
@@ -15811,6 +15812,12 @@
|
|
|
15811
15812
|
"url": "https://bevry.me/fund"
|
|
15812
15813
|
}
|
|
15813
15814
|
},
|
|
15815
|
+
"node_modules/tiktoken": {
|
|
15816
|
+
"version": "1.0.22",
|
|
15817
|
+
"resolved": "https://registry.npmjs.org/tiktoken/-/tiktoken-1.0.22.tgz",
|
|
15818
|
+
"integrity": "sha512-PKvy1rVF1RibfF3JlXBSP0Jrcw2uq3yXdgcEXtKTYn3QJ/cBRBHDnrJ5jHky+MENZ6DIPwNUGWpkVx+7joCpNA==",
|
|
15819
|
+
"license": "MIT"
|
|
15820
|
+
},
|
|
15814
15821
|
"node_modules/tinyglobby": {
|
|
15815
15822
|
"version": "0.2.17",
|
|
15816
15823
|
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
|
|
@@ -17073,6 +17080,16 @@
|
|
|
17073
17080
|
"node": ">=20.0"
|
|
17074
17081
|
}
|
|
17075
17082
|
},
|
|
17083
|
+
"node_modules/xstate": {
|
|
17084
|
+
"version": "5.31.1",
|
|
17085
|
+
"resolved": "https://registry.npmjs.org/xstate/-/xstate-5.31.1.tgz",
|
|
17086
|
+
"integrity": "sha512-3P7t7GQ61BvLu+8Cj6Zq7rcS34vecL9pvfN2ucUWmIFIUG+rAREviOs4Xy4OO3BuJHSz6RLU8eqDXxSbVotjDQ==",
|
|
17087
|
+
"license": "MIT",
|
|
17088
|
+
"funding": {
|
|
17089
|
+
"type": "opencollective",
|
|
17090
|
+
"url": "https://opencollective.com/xstate"
|
|
17091
|
+
}
|
|
17092
|
+
},
|
|
17076
17093
|
"node_modules/yallist": {
|
|
17077
17094
|
"version": "3.1.1",
|
|
17078
17095
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
|
@@ -17132,7 +17149,7 @@
|
|
|
17132
17149
|
"npm": ">=8.0.0"
|
|
17133
17150
|
},
|
|
17134
17151
|
"funding": {
|
|
17135
|
-
"type": "GitHub Sponsors
|
|
17152
|
+
"type": "GitHub Sponsors ❤",
|
|
17136
17153
|
"url": "https://github.com/sponsors/dmonad"
|
|
17137
17154
|
}
|
|
17138
17155
|
},
|
|
@@ -17204,14 +17221,6 @@
|
|
|
17204
17221
|
"dependencies": {
|
|
17205
17222
|
"xstate": "5.31.1"
|
|
17206
17223
|
}
|
|
17207
|
-
},
|
|
17208
|
-
"packages/workflows/node_modules/xstate": {
|
|
17209
|
-
"version": "5.31.1",
|
|
17210
|
-
"license": "MIT",
|
|
17211
|
-
"funding": {
|
|
17212
|
-
"type": "opencollective",
|
|
17213
|
-
"url": "https://opencollective.com/xstate"
|
|
17214
|
-
}
|
|
17215
17224
|
}
|
|
17216
17225
|
}
|
|
17217
17226
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pasko70/pibo",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
"react-virtuoso": "^4.18.6",
|
|
110
110
|
"remark-gfm": "^4.0.1",
|
|
111
111
|
"tailwindcss": "^4.2.4",
|
|
112
|
+
"tiktoken": "^1.0.22",
|
|
112
113
|
"typebox": "1.1.38",
|
|
113
114
|
"xstate": "5.31.1"
|
|
114
115
|
},
|