@eum-agent/llm-capability-chat 0.0.0-stage → 1.1.0

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.
@@ -0,0 +1,9 @@
1
+ import { n as estimateTextTokens } from "./tokens-3kk-37Ys.js";
2
+ import { parentPort, workerData } from "node:worker_threads";
3
+ //#region src/token-worker.ts
4
+ /** Counts the original complete request away from the gateway event loop. */
5
+ if (!parentPort) throw new Error("token measurement requires a background worker");
6
+ parentPort.postMessage(estimateTextTokens(JSON.stringify(workerData)));
7
+ parentPort.close();
8
+ //#endregion
9
+ export {};
@@ -0,0 +1,51 @@
1
+ import { countTokens } from "gpt-tokenizer/encoding/o200k_base";
2
+ //#region src/tokens.ts
3
+ /** Local text measurement shared by request inspection and context displays. */
4
+ const ordinaryText = { disallowedSpecial: /* @__PURE__ */ new Set() };
5
+ /**
6
+ * Counts text with the bundled o200k_base encoding, without network access.
7
+ * This is an estimate for models whose encoding is unknown or different.
8
+ * Token-looking strings in user content remain ordinary text. The imported
9
+ * encoder and its bounded merge cache are reused across calls.
10
+ */
11
+ function estimateTextTokens(text) {
12
+ return countTokens(text, ordinaryText);
13
+ }
14
+ /** Keeps request JSON semantics without encoding its large original body strings on the caller. */
15
+ function displayInput(value, key = "", ancestors = /* @__PURE__ */ new Set()) {
16
+ if (value && typeof value === "object" && "toJSON" in value && typeof value.toJSON === "function") value = value.toJSON(key);
17
+ if (value instanceof Number || value instanceof String || value instanceof Boolean) value = value.valueOf();
18
+ if (typeof value === "function" || typeof value === "symbol" || value === void 0) return void 0;
19
+ if (value === null || typeof value !== "object") return value;
20
+ if (ancestors.has(value)) throw new TypeError("cyclic display request");
21
+ ancestors.add(value);
22
+ try {
23
+ if (Array.isArray(value)) return Array.from(value, (entry, index) => displayInput(entry, String(index), ancestors) ?? null);
24
+ const result = Object.create(null);
25
+ for (const name of Object.keys(value)) {
26
+ const entry = displayInput(value[name], name, ancestors);
27
+ if (entry !== void 0) result[name] = entry;
28
+ }
29
+ return result;
30
+ } finally {
31
+ ancestors.delete(value);
32
+ }
33
+ }
34
+ /** Counts the unchanged complete serialized request for display; inspection stays synchronous. */
35
+ function createDisplayTokenMeasurement(background, ownerSignal) {
36
+ return async (request, signal) => {
37
+ signal.throwIfAborted();
38
+ ownerSignal.throwIfAborted();
39
+ const value = await background.execute({
40
+ trustedModuleUrl: new URL(import.meta.resolve("@eum-agent/llm-capability-chat/token-worker")),
41
+ value: displayInput(request),
42
+ signal: AbortSignal.any([signal, ownerSignal])
43
+ });
44
+ signal.throwIfAborted();
45
+ ownerSignal.throwIfAborted();
46
+ if (!Number.isSafeInteger(value) || value < 0) throw new Error("token worker returned an invalid count");
47
+ return value;
48
+ };
49
+ }
50
+ //#endregion
51
+ export { estimateTextTokens as n, createDisplayTokenMeasurement as t };
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@eum-agent/llm-capability-chat",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "displayName": {
4
+ "en-US": "Chat Model Capability",
5
+ "zh-CN": "对话模型能力"
6
+ },
7
+ "version": "1.1.0",
8
+ "type": "module",
9
+ "description": "Chat Model Capability",
10
+ "license": "MIT",
11
+ "exports": {
12
+ ".": {
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./token-worker": {
16
+ "default": "./dist/token-worker.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "ui"
22
+ ],
23
+ "devDependencies": {
24
+ "@eum-agent/plugin": "1.1.0",
25
+ "@types/react": "^19.2.18",
26
+ "@types/react-dom": "^19.2.5",
27
+ "@testing-library/react": "^16.3.3",
28
+ "@testing-library/user-event": "^14.6.6",
29
+ "jsdom": "^30.0.1",
30
+ "vite": "^8.2.2",
31
+ "@eum-agent/kernel": "1.0.0",
32
+ "@eum-agent/protocol": "1.0.0",
33
+ "sharp": "0.34.5",
34
+ "react": "^19.2.0",
35
+ "react-dom": "^19.2.0",
36
+ "lucide-react": "^1.40.0",
37
+ "ajv": "8.20.0"
38
+ },
39
+ "dependencies": {
40
+ "zod": "^4.4.3",
41
+ "gpt-tokenizer": "4.0.0"
42
+ },
43
+ "yaoguang": {
44
+ "description": {
45
+ "en-US": "Chat Model Capability",
46
+ "zh-CN": "对话模型能力"
47
+ },
48
+ "dependencies": {
49
+ "@eum-agent/llm-management": "1.1.0"
50
+ },
51
+ "kind": "extension",
52
+ "foundationDependencies": {
53
+ "@eum-agent/infra-local": "1.0.1",
54
+ "@eum-agent/storage-sqlite": "1.1.0"
55
+ }
56
+ },
57
+ "scripts": {
58
+ "build": "tsdown && vite build",
59
+ "test": "vitest run",
60
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.ui.json"
61
+ }
6
62
  }