@jsonstudio/llms 0.6.1399 → 0.6.1402

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.
Files changed (72) hide show
  1. package/dist/conversion/codecs/gemini-openai-codec.d.ts +1 -3
  2. package/dist/conversion/codecs/gemini-openai-codec.js +4 -10
  3. package/dist/conversion/compat/actions/gemini-cli-request.d.ts +2 -0
  4. package/dist/conversion/compat/actions/gemini-cli-request.js +490 -0
  5. package/dist/conversion/compat/profiles/chat-gemini-cli.json +27 -0
  6. package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +76 -348
  7. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +6 -0
  8. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +2 -0
  9. package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +95 -3
  10. package/dist/conversion/hub/pipeline/hub-pipeline.js +1365 -19
  11. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +22 -0
  12. package/dist/conversion/hub/policy/policy-engine.js +50 -3
  13. package/dist/conversion/hub/process/chat-process.js +5 -146
  14. package/dist/conversion/hub/response/provider-response.js +11 -10
  15. package/dist/conversion/hub/response/response-mappers.d.ts +1 -3
  16. package/dist/conversion/hub/response/response-mappers.js +2 -20
  17. package/dist/conversion/hub/tool-surface/tool-surface-engine.js +2 -1
  18. package/dist/conversion/responses/responses-openai-bridge.js +4 -3
  19. package/dist/conversion/shared/gemini-tool-utils.d.ts +1 -6
  20. package/dist/conversion/shared/gemini-tool-utils.js +164 -542
  21. package/dist/conversion/shared/mcp-injection.js +29 -0
  22. package/dist/conversion/shared/openai-message-normalize.js +3 -17
  23. package/dist/filters/special/request-tool-list-filter.js +21 -13
  24. package/dist/filters/special/tool-filter-hooks.js +60 -3
  25. package/dist/router/virtual-router/bootstrap.js +8 -6
  26. package/dist/router/virtual-router/engine-health.d.ts +1 -1
  27. package/dist/router/virtual-router/engine-health.js +110 -11
  28. package/dist/router/virtual-router/engine-selection/alias-selection.d.ts +0 -15
  29. package/dist/router/virtual-router/engine-selection/alias-selection.js +4 -85
  30. package/dist/router/virtual-router/engine-selection/route-utils.js +6 -12
  31. package/dist/router/virtual-router/engine-selection/tier-selection-select.js +17 -40
  32. package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -5
  33. package/dist/router/virtual-router/engine.js +6 -21
  34. package/dist/router/virtual-router/types.d.ts +1 -14
  35. package/dist/servertool/clock/config.d.ts +1 -1
  36. package/dist/servertool/clock/config.js +5 -9
  37. package/dist/servertool/engine.js +11 -88
  38. package/dist/servertool/handlers/gemini-empty-reply-continue.js +1 -2
  39. package/dist/sse/sse-to-json/builders/response-builder.js +0 -16
  40. package/package.json +1 -1
  41. package/dist/conversion/hub/pipeline/hub-pipeline/adapter-context.d.ts +0 -10
  42. package/dist/conversion/hub/pipeline/hub-pipeline/adapter-context.js +0 -142
  43. package/dist/conversion/hub/pipeline/hub-pipeline/anthropic-alias-map.d.ts +0 -6
  44. package/dist/conversion/hub/pipeline/hub-pipeline/anthropic-alias-map.js +0 -79
  45. package/dist/conversion/hub/pipeline/hub-pipeline/apply-patch-tool-mode.d.ts +0 -3
  46. package/dist/conversion/hub/pipeline/hub-pipeline/apply-patch-tool-mode.js +0 -46
  47. package/dist/conversion/hub/pipeline/hub-pipeline/execute-chat-process-entry.d.ts +0 -8
  48. package/dist/conversion/hub/pipeline/hub-pipeline/execute-chat-process-entry.js +0 -366
  49. package/dist/conversion/hub/pipeline/hub-pipeline/execute-request-stage.d.ts +0 -9
  50. package/dist/conversion/hub/pipeline/hub-pipeline/execute-request-stage.js +0 -390
  51. package/dist/conversion/hub/pipeline/hub-pipeline/node-results.d.ts +0 -3
  52. package/dist/conversion/hub/pipeline/hub-pipeline/node-results.js +0 -14
  53. package/dist/conversion/hub/pipeline/hub-pipeline/payload-normalize.d.ts +0 -2
  54. package/dist/conversion/hub/pipeline/hub-pipeline/payload-normalize.js +0 -144
  55. package/dist/conversion/hub/pipeline/hub-pipeline/policy.d.ts +0 -4
  56. package/dist/conversion/hub/pipeline/hub-pipeline/policy.js +0 -32
  57. package/dist/conversion/hub/pipeline/hub-pipeline/protocol.d.ts +0 -8
  58. package/dist/conversion/hub/pipeline/hub-pipeline/protocol.js +0 -63
  59. package/dist/conversion/hub/pipeline/hub-pipeline/resolve-protocol-hooks.d.ts +0 -2
  60. package/dist/conversion/hub/pipeline/hub-pipeline/resolve-protocol-hooks.js +0 -43
  61. package/dist/conversion/hub/pipeline/hub-pipeline/semantic-gate.d.ts +0 -1
  62. package/dist/conversion/hub/pipeline/hub-pipeline/semantic-gate.js +0 -29
  63. package/dist/conversion/hub/pipeline/hub-pipeline/servertool-runtime-config.d.ts +0 -2
  64. package/dist/conversion/hub/pipeline/hub-pipeline/servertool-runtime-config.js +0 -16
  65. package/dist/conversion/hub/pipeline/hub-pipeline/types.d.ts +0 -116
  66. package/dist/conversion/hub/pipeline/hub-pipeline/types.js +0 -1
  67. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_thought_signature_inject/index.d.ts +0 -10
  68. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_thought_signature_inject/index.js +0 -172
  69. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_thought_signature_capture/index.d.ts +0 -10
  70. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_thought_signature_capture/index.js +0 -71
  71. package/dist/conversion/hub/pipeline/thought-signature/thought-signature-center.d.ts +0 -14
  72. package/dist/conversion/hub/pipeline/thought-signature/thought-signature-center.js +0 -289
@@ -1,289 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import os from 'node:os';
5
- export const SKIP_THOUGHT_SIGNATURE = 'skip_thought_signature_validator';
6
- const MEMORY_TTL_MS = 12 * 60 * 60 * 1000;
7
- const DISK_TTL_MS = 12 * 60 * 60 * 1000;
8
- const WRITE_INTERVAL_MS = 60 * 1000;
9
- const MAX_ENTRIES_PER_SESSION = 50;
10
- const MAX_SESSIONS = 200;
11
- const TEXT_HASH_HEX_LEN = 16;
12
- const sessionStores = new Map();
13
- const sessionLast = new Map();
14
- const diskEntries = new Map();
15
- let dirty = false;
16
- let writeTimer;
17
- let cleanupTimer;
18
- const stats = {
19
- memoryHits: 0,
20
- diskHits: 0,
21
- misses: 0,
22
- writes: 0,
23
- lastWrite: 0
24
- };
25
- function resolveDefaultCachePath() {
26
- const env = (process.env.ROUTECODEX_THOUGHT_SIGNATURE_CACHE_PATH ||
27
- process.env.RCC_THOUGHT_SIGNATURE_CACHE_PATH ||
28
- '').trim();
29
- if (env)
30
- return env;
31
- const home = process.env.HOME || os.homedir() || '';
32
- return path.join(home, '.routecodex', 'antigravity-signature-cache.json');
33
- }
34
- const persistencePath = resolveDefaultCachePath();
35
- function now() {
36
- return Date.now();
37
- }
38
- function normalizeText(value) {
39
- if (typeof value !== 'string')
40
- return undefined;
41
- const trimmed = value.trim();
42
- return trimmed.length ? trimmed : undefined;
43
- }
44
- function normalizeSignature(value) {
45
- if (typeof value !== 'string')
46
- return undefined;
47
- const trimmed = value.trim();
48
- return trimmed.length ? trimmed : undefined;
49
- }
50
- function hashText(text) {
51
- return createHash('sha256').update(text, 'utf8').digest('hex').slice(0, TEXT_HASH_HEX_LEN);
52
- }
53
- function makeDiskKey(sessionKey, textHash) {
54
- return `${sessionKey}:${textHash}`;
55
- }
56
- function ensureSession(sessionKey) {
57
- let store = sessionStores.get(sessionKey);
58
- if (!store) {
59
- pruneSessionsIfNeeded();
60
- store = new Map();
61
- sessionStores.set(sessionKey, store);
62
- }
63
- return store;
64
- }
65
- function pruneSession(store) {
66
- const cutoff = now() - MEMORY_TTL_MS;
67
- for (const [key, entry] of store) {
68
- if (entry.timestamp < cutoff) {
69
- store.delete(key);
70
- }
71
- }
72
- if (store.size < MAX_ENTRIES_PER_SESSION)
73
- return;
74
- const entries = Array.from(store.entries()).sort((a, b) => a[1].timestamp - b[1].timestamp);
75
- const toRemove = entries.slice(0, Math.floor(MAX_ENTRIES_PER_SESSION / 4));
76
- for (const [key] of toRemove) {
77
- store.delete(key);
78
- }
79
- }
80
- function ensureCacheDir(filePath) {
81
- try {
82
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
83
- }
84
- catch {
85
- // best-effort
86
- }
87
- }
88
- function loadPersistedCache() {
89
- try {
90
- if (!fs.existsSync(persistencePath))
91
- return;
92
- const raw = fs.readFileSync(persistencePath, 'utf-8');
93
- if (!raw.trim())
94
- return;
95
- const parsed = JSON.parse(raw);
96
- if (!parsed || parsed.version !== '1.0')
97
- return;
98
- const cutoff = now() - DISK_TTL_MS;
99
- for (const [key, entry] of Object.entries(parsed.entries || {})) {
100
- if (!entry || typeof entry.signature !== 'string')
101
- continue;
102
- const ts = typeof entry.timestamp === 'number' ? entry.timestamp : now();
103
- if (ts < cutoff)
104
- continue;
105
- diskEntries.set(key, { signature: entry.signature, timestamp: ts });
106
- }
107
- }
108
- catch {
109
- // best-effort
110
- }
111
- }
112
- function schedulePersist() {
113
- if (writeTimer)
114
- return;
115
- writeTimer = setInterval(() => {
116
- if (dirty) {
117
- persistCache();
118
- }
119
- }, WRITE_INTERVAL_MS);
120
- if (typeof writeTimer.unref === 'function') {
121
- writeTimer.unref();
122
- }
123
- }
124
- function scheduleCleanup() {
125
- if (cleanupTimer)
126
- return;
127
- cleanupTimer = setInterval(() => {
128
- const cutoff = now() - MEMORY_TTL_MS;
129
- for (const store of sessionStores.values()) {
130
- for (const [key, entry] of store.entries()) {
131
- if (entry.timestamp < cutoff) {
132
- store.delete(key);
133
- }
134
- }
135
- }
136
- }, 30 * 60 * 1000);
137
- if (typeof cleanupTimer.unref === 'function') {
138
- cleanupTimer.unref();
139
- }
140
- }
141
- function pruneSessionsIfNeeded() {
142
- if (sessionStores.size < MAX_SESSIONS)
143
- return;
144
- const entries = [];
145
- for (const key of sessionStores.keys()) {
146
- const last = sessionLast.get(key);
147
- entries.push({ key, ts: last?.timestamp ?? 0 });
148
- }
149
- entries.sort((a, b) => a.ts - b.ts);
150
- const removeCount = Math.max(1, sessionStores.size - (MAX_SESSIONS - 1));
151
- for (const entry of entries.slice(0, removeCount)) {
152
- sessionStores.delete(entry.key);
153
- sessionLast.delete(entry.key);
154
- for (const diskKey of diskEntries.keys()) {
155
- if (diskKey.startsWith(`${entry.key}:`)) {
156
- diskEntries.delete(diskKey);
157
- }
158
- }
159
- }
160
- }
161
- function persistCache() {
162
- try {
163
- ensureCacheDir(persistencePath);
164
- const nowTs = now();
165
- const validDisk = {};
166
- for (const [key, entry] of diskEntries.entries()) {
167
- if (nowTs - entry.timestamp <= DISK_TTL_MS) {
168
- validDisk[key] = entry;
169
- }
170
- }
171
- const merged = { ...validDisk };
172
- for (const [sessionKey, store] of sessionStores.entries()) {
173
- for (const [textHash, entry] of store.entries()) {
174
- const diskKey = makeDiskKey(sessionKey, textHash);
175
- merged[diskKey] = { signature: entry.signature, timestamp: entry.timestamp };
176
- }
177
- }
178
- const data = {
179
- version: '1.0',
180
- memory_ttl_seconds: MEMORY_TTL_MS / 1000,
181
- disk_ttl_seconds: DISK_TTL_MS / 1000,
182
- entries: merged,
183
- statistics: {
184
- memory_hits: stats.memoryHits,
185
- disk_hits: stats.diskHits,
186
- misses: stats.misses,
187
- writes: stats.writes + 1,
188
- last_write: nowTs
189
- }
190
- };
191
- const tmpPath = path.join(os.tmpdir(), `antigravity-cache-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`);
192
- fs.writeFileSync(tmpPath, JSON.stringify(data, null, 2), 'utf-8');
193
- try {
194
- fs.renameSync(tmpPath, persistencePath);
195
- }
196
- catch {
197
- fs.writeFileSync(persistencePath, fs.readFileSync(tmpPath));
198
- try {
199
- fs.unlinkSync(tmpPath);
200
- }
201
- catch {
202
- // ignore cleanup errors
203
- }
204
- }
205
- stats.writes += 1;
206
- stats.lastWrite = nowTs;
207
- dirty = false;
208
- }
209
- catch {
210
- // best-effort
211
- }
212
- }
213
- loadPersistedCache();
214
- schedulePersist();
215
- scheduleCleanup();
216
- export function buildThoughtSignatureSessionKey(ctx, payload) {
217
- const sessionId = typeof ctx.sessionId === 'string'
218
- ? String(ctx.sessionId).trim()
219
- : typeof ctx.conversationId === 'string'
220
- ? String(ctx.conversationId).trim()
221
- : typeof ctx.requestId === 'string'
222
- ? String(ctx.requestId).trim()
223
- : '';
224
- if (!sessionId)
225
- return undefined;
226
- const model = (payload && typeof payload.model === 'string' && String(payload.model).trim()) ||
227
- (typeof ctx.clientModelId === 'string' ? String(ctx.clientModelId).trim() : '') ||
228
- (typeof ctx.originalModelId === 'string' ? String(ctx.originalModelId).trim() : '');
229
- const protocol = typeof ctx.providerProtocol === 'string' && ctx.providerProtocol.trim()
230
- ? ctx.providerProtocol.trim()
231
- : 'unknown';
232
- const modelKey = model || 'unknown';
233
- return `${protocol}:${modelKey}:${sessionId}`;
234
- }
235
- export function cacheThoughtSignature(sessionKey, text, signature) {
236
- const normalizedText = normalizeText(text);
237
- const normalizedSignature = normalizeSignature(signature);
238
- if (!sessionKey || !normalizedText || !normalizedSignature)
239
- return;
240
- const textHash = hashText(normalizedText);
241
- const store = ensureSession(sessionKey);
242
- if (store.size >= MAX_ENTRIES_PER_SESSION) {
243
- pruneSession(store);
244
- }
245
- store.set(textHash, { signature: normalizedSignature, timestamp: now() });
246
- sessionLast.set(sessionKey, { text: normalizedText, signature: normalizedSignature, timestamp: now() });
247
- dirty = true;
248
- }
249
- export function getCachedThoughtSignature(sessionKey, text) {
250
- if (!sessionKey)
251
- return undefined;
252
- const normalizedText = normalizeText(text);
253
- if (!normalizedText)
254
- return undefined;
255
- const textHash = hashText(normalizedText);
256
- const store = sessionStores.get(sessionKey);
257
- if (store) {
258
- const entry = store.get(textHash);
259
- if (entry) {
260
- if (now() - entry.timestamp <= MEMORY_TTL_MS) {
261
- stats.memoryHits += 1;
262
- return entry.signature;
263
- }
264
- store.delete(textHash);
265
- }
266
- }
267
- const diskKey = makeDiskKey(sessionKey, textHash);
268
- const diskEntry = diskEntries.get(diskKey);
269
- if (diskEntry && now() - diskEntry.timestamp <= DISK_TTL_MS) {
270
- stats.diskHits += 1;
271
- const mem = ensureSession(sessionKey);
272
- mem.set(textHash, { signature: diskEntry.signature, timestamp: now() });
273
- return diskEntry.signature;
274
- }
275
- stats.misses += 1;
276
- return undefined;
277
- }
278
- export function getLastThoughtSignature(sessionKey) {
279
- if (!sessionKey)
280
- return undefined;
281
- return sessionLast.get(sessionKey);
282
- }
283
- export function shouldHandleThoughtSignature(ctx) {
284
- const provider = typeof ctx.providerId === 'string' ? ctx.providerId.toLowerCase() : '';
285
- if (provider === 'antigravity')
286
- return true;
287
- const profile = typeof ctx.profileId === 'string' ? ctx.profileId.toLowerCase() : '';
288
- return profile.includes('antigravity');
289
- }