@plurnk/plurnk-service 1.0.3 → 1.0.5
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/SPEC.md +3 -3
- package/dist/core/Dispatcher.d.ts +0 -5
- package/dist/core/Dispatcher.d.ts.map +1 -1
- package/dist/core/Dispatcher.js +3 -4
- package/dist/core/Dispatcher.js.map +1 -1
- package/dist/core/Engine.d.ts.map +1 -1
- package/dist/core/Engine.js +8 -29
- package/dist/core/Engine.js.map +1 -1
- package/dist/core/Engine.sql +2 -21
- package/dist/core/PacketBuilder.d.ts +4 -5
- package/dist/core/PacketBuilder.d.ts.map +1 -1
- package/dist/core/PacketBuilder.js +23 -15
- package/dist/core/PacketBuilder.js.map +1 -1
- package/dist/core/content-hash.d.ts +2 -0
- package/dist/core/content-hash.d.ts.map +1 -0
- package/dist/core/content-hash.js +6 -0
- package/dist/core/content-hash.js.map +1 -0
- package/dist/core/scheme-types.d.ts +0 -5
- package/dist/core/scheme-types.d.ts.map +1 -1
- package/dist/core/token-ruler.d.ts +2 -0
- package/dist/core/token-ruler.d.ts.map +1 -0
- package/dist/core/token-ruler.js +18 -0
- package/dist/core/token-ruler.js.map +1 -0
- package/dist/schemes/_entry-crud.js +3 -3
- package/dist/schemes/_entry-crud.js.map +1 -1
- package/dist/schemes/_entry-manifest.d.ts.map +1 -1
- package/dist/schemes/_entry-manifest.js +6 -26
- package/dist/schemes/_entry-manifest.js.map +1 -1
- package/dist/server/Daemon.d.ts +2 -0
- package/dist/server/Daemon.d.ts.map +1 -1
- package/dist/server/Daemon.js +23 -7
- package/dist/server/Daemon.js.map +1 -1
- package/dist/server/loop-model.d.ts +3 -0
- package/dist/server/loop-model.d.ts.map +1 -0
- package/dist/server/loop-model.js +26 -0
- package/dist/server/loop-model.js.map +1 -0
- package/migrations/0000-00-00.01_schema.sql +2 -15
- package/package.json +14 -14
- package/dist/core/TokenGauge.d.ts +0 -16
- package/dist/core/TokenGauge.d.ts.map +0 -1
- package/dist/core/TokenGauge.js +0 -58
- package/dist/core/TokenGauge.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plurnk/plurnk-service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Plurnk agent runtime — the server / engine / core. Implements the @plurnk/plurnk-grammar contract.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,21 +59,21 @@
|
|
|
59
59
|
"prepack": "npm run build"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@plurnk/plurnk-agui": "1.0.
|
|
63
|
-
"@plurnk/plurnk-execs": "1.0.
|
|
64
|
-
"@plurnk/plurnk-execs-common": "1.0.
|
|
65
|
-
"@plurnk/plurnk-execs-mcp": "1.0.
|
|
66
|
-
"@plurnk/plurnk-execs-search": "1.0.
|
|
67
|
-
"@plurnk/plurnk-grammar": "1.0.
|
|
68
|
-
"@plurnk/plurnk-mimetypes": "1.0.
|
|
69
|
-
"@plurnk/plurnk-mimetypes-text-html": "1.0.
|
|
70
|
-
"@plurnk/plurnk-providers": "1.0.
|
|
71
|
-
"@plurnk/plurnk-schemes": "1.0.
|
|
72
|
-
"@plurnk/plurnk-schemes-http": "1.0.
|
|
62
|
+
"@plurnk/plurnk-agui": "1.0.5",
|
|
63
|
+
"@plurnk/plurnk-execs": "1.0.5",
|
|
64
|
+
"@plurnk/plurnk-execs-common": "1.0.5",
|
|
65
|
+
"@plurnk/plurnk-execs-mcp": "1.0.5",
|
|
66
|
+
"@plurnk/plurnk-execs-search": "1.0.5",
|
|
67
|
+
"@plurnk/plurnk-grammar": "1.0.5",
|
|
68
|
+
"@plurnk/plurnk-mimetypes": "1.0.5",
|
|
69
|
+
"@plurnk/plurnk-mimetypes-text-html": "1.0.5",
|
|
70
|
+
"@plurnk/plurnk-providers": "1.0.5",
|
|
71
|
+
"@plurnk/plurnk-schemes": "1.0.5",
|
|
72
|
+
"@plurnk/plurnk-schemes-http": "1.0.5",
|
|
73
73
|
"@possumtech/sqlrite": "5.2.0",
|
|
74
74
|
"diff": "^9.0.0",
|
|
75
|
-
"@plurnk/plurnk-mimetypes-embeddings": "1.0.
|
|
76
|
-
"@plurnk/plurnk-meta": "1.0.
|
|
75
|
+
"@plurnk/plurnk-mimetypes-embeddings": "1.0.5",
|
|
76
|
+
"@plurnk/plurnk-meta": "1.0.5"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@types/diff": "^7.0.2"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Mimetypes } from "@plurnk/plurnk-mimetypes";
|
|
2
|
-
import type { Provider } from "@plurnk/plurnk-providers";
|
|
3
|
-
import type { Db } from "./Db.ts";
|
|
4
|
-
import type { TelemetryEvent } from "@plurnk/plurnk-grammar";
|
|
5
|
-
export interface GaugeResolution {
|
|
6
|
-
tokenizerId: string;
|
|
7
|
-
exact: boolean;
|
|
8
|
-
count: (text: string) => Promise<number>;
|
|
9
|
-
}
|
|
10
|
-
export default class TokenGauge {
|
|
11
|
-
#private;
|
|
12
|
-
static contentHash(content: string): string;
|
|
13
|
-
static resolve(mimetypes: Mimetypes | undefined, provider: Provider, pushTelemetry?: (e: TelemetryEvent) => void): Promise<GaugeResolution>;
|
|
14
|
-
static tokensFor(db: Db, gauge: GaugeResolution, contentHash: string, content: string): Promise<number>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=TokenGauge.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TokenGauge.d.ts","sourceRoot":"","sources":["../../src/core/TokenGauge.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,EAAE,EAAc,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,WAAW,eAAe;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C;AAED,MAAM,CAAC,OAAO,OAAO,UAAU;;IAI3B,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE1C;IAQD,OAAa,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAsBhJ;IAID,OAAa,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAM5G;CACJ"}
|
package/dist/core/TokenGauge.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// #312 — the token gauge: derived token counts keyed on (content_hash, tokenizer_id), the
|
|
2
|
-
// deep_hash discipline applied to token arithmetic. The mimetypes Tokenizers seam (mimetypes#44)
|
|
3
|
-
// supplies the identity (tokenizer.json sha — NEVER the model id: deepseek pro↔flash share a
|
|
4
|
-
// vocab, so that swap recounts nothing; gemma↔deepseek recounts all) and the exact counter.
|
|
5
|
-
// When the seam resolves nothing exact for the active model, the provider's chars/2 upper bound
|
|
6
|
-
// is used AND SURFACED (`tokenizer_unavailable`, once per model) — an error-class signal, never
|
|
7
|
-
// a silent number. Resolutions are cached per model ref; derivation rows are shared session-wide.
|
|
8
|
-
import { createHash } from "node:crypto";
|
|
9
|
-
export default class TokenGauge {
|
|
10
|
-
static #resolutions = new Map();
|
|
11
|
-
static #warned = new Set();
|
|
12
|
-
static contentHash(content) {
|
|
13
|
-
return createHash("sha256").update(content).digest("hex");
|
|
14
|
-
}
|
|
15
|
-
// Resolve the active model's gauge: the seam's exact tokenizer, or the provider's surfaced
|
|
16
|
-
// upper bound labeled with a heuristic identity (so its rows never masquerade as exact ones).
|
|
17
|
-
// providers#37 (delivered, 0.35.0): Provider.servedModel is the backend's self-reported
|
|
18
|
-
// identity from the boot probe — an alias-fronted local backend ('turboderp' → the gguf name)
|
|
19
|
-
// resolves its exact tokenizer from turn 1. Absent (hosted/no-probe), the alias model tries;
|
|
20
|
-
// inexact runs as a SURFACED upper bound (#312 ask 3) — never a silent number.
|
|
21
|
-
static async resolve(mimetypes, provider, pushTelemetry) {
|
|
22
|
-
const key = provider.model;
|
|
23
|
-
const cached = TokenGauge.#resolutions.get(key);
|
|
24
|
-
if (cached !== undefined)
|
|
25
|
-
return cached;
|
|
26
|
-
let resolution;
|
|
27
|
-
try {
|
|
28
|
-
if (mimetypes === undefined)
|
|
29
|
-
throw new Error("no mimetypes seam");
|
|
30
|
-
const r = await mimetypes.tokenizer(provider.servedModel ?? provider.model);
|
|
31
|
-
resolution = { tokenizerId: r.exact ? r.tokenizerId : `heuristic:${r.tokenizerId}`, exact: r.exact, count: (text) => r.countTokens(text) };
|
|
32
|
-
if (!r.exact && !TokenGauge.#warned.has(key)) {
|
|
33
|
-
TokenGauge.#warned.add(key);
|
|
34
|
-
pushTelemetry?.({ source: "engine:tokens", kind: "tokenizer_unavailable", message: `no exact tokenizer for '${provider.model}' — counts are an upper bound (chars/2 class); budget refusals run conservative`, level: "warn" });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
resolution = { tokenizerId: "heuristic:provider", exact: false, count: async (text) => provider.countTokens(text) };
|
|
39
|
-
if (!TokenGauge.#warned.has(key)) {
|
|
40
|
-
TokenGauge.#warned.add(key);
|
|
41
|
-
pushTelemetry?.({ source: "engine:tokens", kind: "tokenizer_unavailable", message: `tokenizer seam resolved nothing for '${provider.model}' — provider upper bound in use`, level: "warn" });
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
TokenGauge.#resolutions.set(key, resolution);
|
|
45
|
-
return resolution;
|
|
46
|
-
}
|
|
47
|
-
// The keyed lookup: (content_hash, tokenizer_id) → tokens; miss → count + upsert. The row is
|
|
48
|
-
// shared by every entry carrying identical content, across models sharing a vocabulary.
|
|
49
|
-
static async tokensFor(db, gauge, contentHash, content) {
|
|
50
|
-
const hit = await db.token_count_get.get({ content_hash: contentHash, tokenizer_id: gauge.tokenizerId });
|
|
51
|
-
if (hit !== undefined)
|
|
52
|
-
return hit.tokens;
|
|
53
|
-
const tokens = await gauge.count(content);
|
|
54
|
-
await db.token_count_upsert.run({ content_hash: contentHash, tokenizer_id: gauge.tokenizerId, tokens });
|
|
55
|
-
return tokens;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=TokenGauge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TokenGauge.js","sourceRoot":"","sources":["../../src/core/TokenGauge.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,iGAAiG;AACjG,6FAA6F;AAC7F,4FAA4F;AAC5F,gGAAgG;AAChG,gGAAgG;AAChG,kGAAkG;AAElG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYzC,MAAM,CAAC,OAAO,OAAO,UAAU;IAC3B,MAAM,CAAC,YAAY,GAAG,IAAI,GAAG,EAA2B,CAAC;IACzD,MAAM,CAAC,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAEnC,MAAM,CAAC,WAAW,CAAC,OAAe;QAC9B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;IAED,2FAA2F;IAC3F,8FAA8F;IAC9F,wFAAwF;IACxF,8FAA8F;I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