teleton 0.8.0 → 0.8.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/README.md +28 -11
- package/dist/{chunk-H36RFKRI.js → chunk-2IZU3REP.js} +572 -174
- package/dist/chunk-3UFPFWYP.js +12 -0
- package/dist/{chunk-NUGDTPE4.js → chunk-4L66JHQE.js} +2 -1
- package/dist/{chunk-TVRZJIZX.js → chunk-55SKE6YH.js} +4 -4
- package/dist/{setup-server-QXED3D2L.js → chunk-57URFK6M.js} +161 -210
- package/dist/chunk-5SEMA47R.js +75 -0
- package/dist/{chunk-JHYZYFZJ.js → chunk-7YKSXOQQ.js} +17 -2
- package/dist/{chunk-IJBWWQE4.js → chunk-C4NKJT2Z.js} +12 -0
- package/dist/{chunk-RQBAMUCV.js → chunk-GGXJLMOH.js} +1451 -743
- package/dist/{chunk-WIKM24GZ.js → chunk-H7MFXJZK.js} +7 -2
- package/dist/{chunk-U56QTM46.js → chunk-HEDJCLA6.js} +85 -44
- package/dist/{chunk-QVBSUYVX.js → chunk-J73TA3UM.js} +17 -9
- package/dist/{chunk-P36I6OIV.js → chunk-LC4TV3KL.js} +13 -2
- package/dist/{chunk-RCMD3U65.js → chunk-NQ6FZKCE.js} +13 -0
- package/dist/{chunk-SD4NLLYG.js → chunk-VYKW7FMV.js} +224 -93
- package/dist/chunk-W25Z7CM6.js +487 -0
- package/dist/{chunk-OJCLKU5Z.js → chunk-WFTC3JJW.js} +16 -0
- package/dist/{server-H3QA252W.js → chunk-XBSCYMKM.js} +369 -374
- package/dist/{chunk-PHSAHTK4.js → chunk-YOSUPUAJ.js} +75 -7
- package/dist/cli/index.js +67 -22
- package/dist/{client-LNZTDQSA.js → client-YOOHI776.js} +4 -4
- package/dist/{get-my-gifts-OMGKOEPM.js → get-my-gifts-Y7EN7RK4.js} +3 -3
- package/dist/index.js +15 -14
- package/dist/{memory-AS7WKGTW.js → memory-Q6EWGK2S.js} +7 -5
- package/dist/memory-hook-WUXJNVT5.js +18 -0
- package/dist/{migrate-POHWYEIW.js → migrate-WFU6COBN.js} +5 -5
- package/dist/server-GYZXKIKU.js +787 -0
- package/dist/server-YODFBZKG.js +392 -0
- package/dist/setup-server-IZBUOJRU.js +215 -0
- package/dist/{store-GAFULOOX.js → store-7M4XV6M5.js} +6 -6
- package/dist/{task-dependency-resolver-3FIKQ7Z6.js → task-dependency-resolver-L6UUMTHK.js} +3 -3
- package/dist/{task-executor-RUTFG6VG.js → task-executor-XBNJLUCS.js} +3 -3
- package/dist/{tasks-BEZ4QRI2.js → tasks-WQIKXDX5.js} +1 -1
- package/dist/{tool-adapter-IH5VGBOO.js → tool-adapter-IVX2XQJE.js} +1 -1
- package/dist/{tool-index-H3SHOJC3.js → tool-index-NYH57UWP.js} +9 -6
- package/dist/{transcript-IMNE6KU3.js → transcript-IM7G25OS.js} +2 -2
- package/dist/web/assets/index-BfYCdwLI.js +80 -0
- package/dist/web/assets/{index-BrVqauzj.css → index-DmlyQVhR.css} +1 -1
- package/dist/web/assets/{index.es-DkU1GvWU.js → index.es-DitvF-9H.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +14 -5
- package/dist/chunk-XBE4JB7C.js +0 -8
- package/dist/web/assets/index-DYeEkvJ6.js +0 -72
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getErrorMessage
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3UFPFWYP.js";
|
|
4
4
|
import {
|
|
5
5
|
createLogger
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-NQ6FZKCE.js";
|
|
7
7
|
|
|
8
8
|
// src/agent/tools/telegram/gifts/get-my-gifts.ts
|
|
9
9
|
import { Type } from "@sinclair/typebox";
|
|
@@ -14,6 +14,7 @@ var CATALOG_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
|
14
14
|
function extractEmoji(sticker) {
|
|
15
15
|
if (!sticker?.attributes) return null;
|
|
16
16
|
const attr = sticker.attributes.find(
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
|
|
17
18
|
(a) => a.className === "DocumentAttributeSticker" || a.className === "DocumentAttributeCustomEmoji"
|
|
18
19
|
);
|
|
19
20
|
return attr?.alt || null;
|
|
@@ -143,12 +144,15 @@ var telegramGetMyGiftsExecutor = async (params, context) => {
|
|
|
143
144
|
compactGift.slug = gift.slug;
|
|
144
145
|
compactGift.nftLink = `t.me/nft/${gift.slug}`;
|
|
145
146
|
const modelAttr = gift.attributes?.find(
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
|
|
146
148
|
(a) => a.className === "StarGiftAttributeModel"
|
|
147
149
|
);
|
|
148
150
|
const patternAttr = gift.attributes?.find(
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
|
|
149
152
|
(a) => a.className === "StarGiftAttributePattern"
|
|
150
153
|
);
|
|
151
154
|
const backdropAttr = gift.attributes?.find(
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
|
|
152
156
|
(a) => a.className === "StarGiftAttributeBackdrop"
|
|
153
157
|
);
|
|
154
158
|
compactGift.model = extractAttrSummary(modelAttr);
|
|
@@ -183,6 +187,7 @@ var telegramGetMyGiftsExecutor = async (params, context) => {
|
|
|
183
187
|
limited: limited.length,
|
|
184
188
|
unlimited: unlimited.length,
|
|
185
189
|
collectibles: collectibles.length,
|
|
190
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
|
|
186
191
|
canUpgrade: gifts.filter((g) => g.canUpgrade).length
|
|
187
192
|
},
|
|
188
193
|
totalCount: result.count
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
EMBEDDING_CACHE_MAX_ENTRIES,
|
|
8
8
|
EMBEDDING_CACHE_TTL_DAYS,
|
|
9
9
|
VOYAGE_BATCH_SIZE
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-C4NKJT2Z.js";
|
|
11
11
|
import {
|
|
12
12
|
fetchWithTimeout
|
|
13
13
|
} from "./chunk-XQUHC3JZ.js";
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from "./chunk-EYWNOHMJ.js";
|
|
17
17
|
import {
|
|
18
18
|
createLogger
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-NQ6FZKCE.js";
|
|
20
20
|
|
|
21
21
|
// src/memory/embeddings/provider.ts
|
|
22
22
|
var NoopEmbeddingProvider = class {
|
|
@@ -52,7 +52,7 @@ var AnthropicEmbeddingProvider = class {
|
|
|
52
52
|
this.dimensions = dims[this.model] ?? 512;
|
|
53
53
|
}
|
|
54
54
|
async embedQuery(text) {
|
|
55
|
-
const result = await this.embed([text]);
|
|
55
|
+
const result = await this.embed([text], "query");
|
|
56
56
|
return result[0] ?? [];
|
|
57
57
|
}
|
|
58
58
|
async embedBatch(texts) {
|
|
@@ -66,7 +66,7 @@ var AnthropicEmbeddingProvider = class {
|
|
|
66
66
|
}
|
|
67
67
|
return results;
|
|
68
68
|
}
|
|
69
|
-
async embed(texts) {
|
|
69
|
+
async embed(texts, inputType = "document") {
|
|
70
70
|
const response = await fetchWithTimeout(`${this.baseUrl}/embeddings`, {
|
|
71
71
|
method: "POST",
|
|
72
72
|
headers: {
|
|
@@ -76,7 +76,7 @@ var AnthropicEmbeddingProvider = class {
|
|
|
76
76
|
body: JSON.stringify({
|
|
77
77
|
input: texts,
|
|
78
78
|
model: this.model,
|
|
79
|
-
input_type:
|
|
79
|
+
input_type: inputType
|
|
80
80
|
})
|
|
81
81
|
});
|
|
82
82
|
if (!response.ok) {
|
|
@@ -90,8 +90,8 @@ var AnthropicEmbeddingProvider = class {
|
|
|
90
90
|
|
|
91
91
|
// src/memory/embeddings/local.ts
|
|
92
92
|
import { pipeline, env } from "@huggingface/transformers";
|
|
93
|
-
import { join } from "path";
|
|
94
|
-
import { mkdirSync } from "fs";
|
|
93
|
+
import { join, dirname } from "path";
|
|
94
|
+
import { mkdirSync, writeFileSync, renameSync, statSync, unlinkSync } from "fs";
|
|
95
95
|
var log = createLogger("Memory");
|
|
96
96
|
var modelCacheDir = join(TELETON_ROOT, "models");
|
|
97
97
|
try {
|
|
@@ -99,6 +99,36 @@ try {
|
|
|
99
99
|
} catch {
|
|
100
100
|
}
|
|
101
101
|
env.cacheDir = modelCacheDir;
|
|
102
|
+
var MIN_FILE_SIZES = { "onnx/model.onnx": 1e6 };
|
|
103
|
+
function isCacheFileValid(filePath, fileName) {
|
|
104
|
+
try {
|
|
105
|
+
return statSync(filePath).size >= (MIN_FILE_SIZES[fileName] ?? 1);
|
|
106
|
+
} catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function ensureModelCached(model) {
|
|
111
|
+
const files = ["config.json", "tokenizer_config.json", "tokenizer.json", "onnx/model.onnx"];
|
|
112
|
+
const baseUrl = `https://huggingface.co/${model}/resolve/main`;
|
|
113
|
+
for (const file of files) {
|
|
114
|
+
const localPath = join(modelCacheDir, model, file);
|
|
115
|
+
if (isCacheFileValid(localPath, file)) continue;
|
|
116
|
+
try {
|
|
117
|
+
unlinkSync(localPath);
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
log.info(`Downloading ${model}/${file}...`);
|
|
121
|
+
mkdirSync(dirname(localPath), { recursive: true });
|
|
122
|
+
const res = await fetch(`${baseUrl}/${file}`, { redirect: "follow" });
|
|
123
|
+
if (!res.ok) {
|
|
124
|
+
throw new Error(`Failed to download ${model}/${file}: ${res.status} ${res.statusText}`);
|
|
125
|
+
}
|
|
126
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
127
|
+
const tmpPath = localPath + ".tmp";
|
|
128
|
+
writeFileSync(tmpPath, buffer);
|
|
129
|
+
renameSync(tmpPath, localPath);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
102
132
|
var extractorPromise = null;
|
|
103
133
|
function getExtractor(model) {
|
|
104
134
|
if (!extractorPromise) {
|
|
@@ -106,7 +136,10 @@ function getExtractor(model) {
|
|
|
106
136
|
extractorPromise = pipeline("feature-extraction", model, {
|
|
107
137
|
dtype: "fp32",
|
|
108
138
|
// Explicit cache_dir to avoid any env race condition
|
|
109
|
-
cache_dir: modelCacheDir
|
|
139
|
+
cache_dir: modelCacheDir,
|
|
140
|
+
// Prevent pthread_setaffinity_np EINVAL on VPS/containers with restricted CPU sets.
|
|
141
|
+
// ONNX Runtime skips thread affinity when thread counts are explicit.
|
|
142
|
+
session_options: { intraOpNumThreads: 1, interOpNumThreads: 1 }
|
|
110
143
|
}).then((ext) => {
|
|
111
144
|
log.info(`Local embedding model ready`);
|
|
112
145
|
return ext;
|
|
@@ -131,14 +164,14 @@ var LocalEmbeddingProvider = class {
|
|
|
131
164
|
* Pre-download and load the model at startup.
|
|
132
165
|
* If loading fails, retries once then marks provider as disabled (FTS5-only).
|
|
133
166
|
* Call this once during app init — avoids retry spam on every message.
|
|
134
|
-
* @returns true if model loaded successfully, false if fallback to noop
|
|
135
167
|
*/
|
|
136
168
|
async warmup() {
|
|
137
169
|
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
138
170
|
try {
|
|
171
|
+
await ensureModelCached(this.model);
|
|
139
172
|
await getExtractor(this.model);
|
|
140
173
|
return true;
|
|
141
|
-
} catch
|
|
174
|
+
} catch {
|
|
142
175
|
if (attempt === 1) {
|
|
143
176
|
log.warn(`Embedding model load failed (attempt 1), retrying...`);
|
|
144
177
|
await new Promise((r) => setTimeout(r, 1e3));
|
|
@@ -174,28 +207,8 @@ var LocalEmbeddingProvider = class {
|
|
|
174
207
|
}
|
|
175
208
|
};
|
|
176
209
|
|
|
177
|
-
// src/memory/embeddings/
|
|
210
|
+
// src/memory/embeddings/utils.ts
|
|
178
211
|
import { createHash } from "crypto";
|
|
179
|
-
function createEmbeddingProvider(config) {
|
|
180
|
-
switch (config.provider) {
|
|
181
|
-
case "anthropic":
|
|
182
|
-
if (!config.apiKey) {
|
|
183
|
-
throw new Error("API key required for Anthropic embedding provider");
|
|
184
|
-
}
|
|
185
|
-
return new AnthropicEmbeddingProvider({
|
|
186
|
-
apiKey: config.apiKey,
|
|
187
|
-
model: config.model
|
|
188
|
-
});
|
|
189
|
-
case "local":
|
|
190
|
-
return new LocalEmbeddingProvider({
|
|
191
|
-
model: config.model
|
|
192
|
-
});
|
|
193
|
-
case "none":
|
|
194
|
-
return new NoopEmbeddingProvider();
|
|
195
|
-
default:
|
|
196
|
-
throw new Error(`Unknown embedding provider: ${config.provider}`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
212
|
function hashText(text) {
|
|
200
213
|
return createHash("sha256").update(text).digest("hex");
|
|
201
214
|
}
|
|
@@ -222,6 +235,16 @@ var CachedEmbeddingProvider = class _CachedEmbeddingProvider {
|
|
|
222
235
|
this.id = inner.id;
|
|
223
236
|
this.model = inner.model;
|
|
224
237
|
this.dimensions = inner.dimensions;
|
|
238
|
+
this.stmtCacheGet = db.prepare(
|
|
239
|
+
`SELECT embedding FROM embedding_cache WHERE hash = ? AND model = ? AND provider = ?`
|
|
240
|
+
);
|
|
241
|
+
this.stmtCachePut = db.prepare(
|
|
242
|
+
`INSERT OR REPLACE INTO embedding_cache (hash, embedding, model, provider, dims, created_at, accessed_at)
|
|
243
|
+
VALUES (?, ?, ?, ?, ?, unixepoch(), unixepoch())`
|
|
244
|
+
);
|
|
245
|
+
this.stmtCacheTouch = db.prepare(
|
|
246
|
+
`UPDATE embedding_cache SET accessed_at = unixepoch() WHERE hash = ? AND model = ? AND provider = ?`
|
|
247
|
+
);
|
|
225
248
|
}
|
|
226
249
|
id;
|
|
227
250
|
model;
|
|
@@ -230,21 +253,17 @@ var CachedEmbeddingProvider = class _CachedEmbeddingProvider {
|
|
|
230
253
|
hits = 0;
|
|
231
254
|
misses = 0;
|
|
232
255
|
ops = 0;
|
|
256
|
+
stmtCacheGet;
|
|
257
|
+
stmtCachePut;
|
|
258
|
+
stmtCacheTouch;
|
|
233
259
|
cacheGet(hash) {
|
|
234
|
-
return this.
|
|
235
|
-
`SELECT embedding FROM embedding_cache WHERE hash = ? AND model = ? AND provider = ?`
|
|
236
|
-
).get(hash, this.model, this.id);
|
|
260
|
+
return this.stmtCacheGet.get(hash, this.model, this.id);
|
|
237
261
|
}
|
|
238
262
|
cachePut(hash, blob) {
|
|
239
|
-
this.
|
|
240
|
-
`INSERT OR REPLACE INTO embedding_cache (hash, embedding, model, provider, dims, created_at, accessed_at)
|
|
241
|
-
VALUES (?, ?, ?, ?, ?, unixepoch(), unixepoch())`
|
|
242
|
-
).run(hash, blob, this.model, this.id, this.dimensions);
|
|
263
|
+
this.stmtCachePut.run(hash, blob, this.model, this.id, this.dimensions);
|
|
243
264
|
}
|
|
244
265
|
cacheTouch(hash) {
|
|
245
|
-
this.
|
|
246
|
-
`UPDATE embedding_cache SET accessed_at = unixepoch() WHERE hash = ? AND model = ? AND provider = ?`
|
|
247
|
-
).run(hash, this.model, this.id);
|
|
266
|
+
this.stmtCacheTouch.run(hash, this.model, this.id);
|
|
248
267
|
}
|
|
249
268
|
async warmup() {
|
|
250
269
|
return this.inner.warmup?.() ?? true;
|
|
@@ -335,13 +354,35 @@ var CachedEmbeddingProvider = class _CachedEmbeddingProvider {
|
|
|
335
354
|
}
|
|
336
355
|
};
|
|
337
356
|
|
|
357
|
+
// src/memory/embeddings/index.ts
|
|
358
|
+
function createEmbeddingProvider(config) {
|
|
359
|
+
switch (config.provider) {
|
|
360
|
+
case "anthropic":
|
|
361
|
+
if (!config.apiKey) {
|
|
362
|
+
throw new Error("API key required for Anthropic embedding provider");
|
|
363
|
+
}
|
|
364
|
+
return new AnthropicEmbeddingProvider({
|
|
365
|
+
apiKey: config.apiKey,
|
|
366
|
+
model: config.model
|
|
367
|
+
});
|
|
368
|
+
case "local":
|
|
369
|
+
return new LocalEmbeddingProvider({
|
|
370
|
+
model: config.model
|
|
371
|
+
});
|
|
372
|
+
case "none":
|
|
373
|
+
return new NoopEmbeddingProvider();
|
|
374
|
+
default:
|
|
375
|
+
throw new Error(`Unknown embedding provider: ${config.provider}`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
338
379
|
export {
|
|
339
380
|
NoopEmbeddingProvider,
|
|
340
381
|
AnthropicEmbeddingProvider,
|
|
341
382
|
LocalEmbeddingProvider,
|
|
342
|
-
CachedEmbeddingProvider,
|
|
343
|
-
createEmbeddingProvider,
|
|
344
383
|
hashText,
|
|
345
384
|
serializeEmbedding,
|
|
346
|
-
deserializeEmbedding
|
|
385
|
+
deserializeEmbedding,
|
|
386
|
+
CachedEmbeddingProvider,
|
|
387
|
+
createEmbeddingProvider
|
|
347
388
|
};
|
|
@@ -2,17 +2,17 @@ import {
|
|
|
2
2
|
getClaudeCodeApiKey,
|
|
3
3
|
getProviderMetadata,
|
|
4
4
|
refreshClaudeCodeApiKey
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-YOSUPUAJ.js";
|
|
6
6
|
import {
|
|
7
7
|
appendToTranscript,
|
|
8
8
|
readTranscript
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-LC4TV3KL.js";
|
|
10
10
|
import {
|
|
11
11
|
fetchWithTimeout
|
|
12
12
|
} from "./chunk-XQUHC3JZ.js";
|
|
13
13
|
import {
|
|
14
14
|
createLogger
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-NQ6FZKCE.js";
|
|
16
16
|
|
|
17
17
|
// src/agent/client.ts
|
|
18
18
|
import {
|
|
@@ -225,7 +225,7 @@ function getProviderModel(provider, modelId) {
|
|
|
225
225
|
}
|
|
226
226
|
modelCache.set(cacheKey, model);
|
|
227
227
|
return model;
|
|
228
|
-
} catch
|
|
228
|
+
} catch {
|
|
229
229
|
log.warn(`Model ${modelId} not found for ${provider}, falling back to ${meta.defaultModel}`);
|
|
230
230
|
const fallbackKey = `${provider}:${meta.defaultModel}`;
|
|
231
231
|
const fallbackCached = modelCache.get(fallbackKey);
|
|
@@ -262,7 +262,7 @@ async function chatWithContext(config, options) {
|
|
|
262
262
|
systemPrompt = "/no_think\n" + systemPrompt;
|
|
263
263
|
if (tools && tools.length > 0) {
|
|
264
264
|
cocoonAllowedTools = new Set(tools.map((t) => t.name));
|
|
265
|
-
const { injectToolsIntoSystemPrompt } = await import("./tool-adapter-
|
|
265
|
+
const { injectToolsIntoSystemPrompt } = await import("./tool-adapter-IVX2XQJE.js");
|
|
266
266
|
systemPrompt = injectToolsIntoSystemPrompt(systemPrompt, tools);
|
|
267
267
|
tools = void 0;
|
|
268
268
|
}
|
|
@@ -281,13 +281,13 @@ async function chatWithContext(config, options) {
|
|
|
281
281
|
cacheRetention: "long"
|
|
282
282
|
};
|
|
283
283
|
if (isCocoon) {
|
|
284
|
-
const { stripCocoonPayload } = await import("./tool-adapter-
|
|
284
|
+
const { stripCocoonPayload } = await import("./tool-adapter-IVX2XQJE.js");
|
|
285
285
|
completeOptions.onPayload = stripCocoonPayload;
|
|
286
286
|
}
|
|
287
287
|
let response = await complete(model, context, completeOptions);
|
|
288
288
|
if (provider === "claude-code" && response.stopReason === "error" && response.errorMessage && (response.errorMessage.includes("401") || response.errorMessage.toLowerCase().includes("unauthorized"))) {
|
|
289
289
|
log.warn("Claude Code token rejected (401), refreshing credentials and retrying...");
|
|
290
|
-
const refreshedKey = refreshClaudeCodeApiKey();
|
|
290
|
+
const refreshedKey = await refreshClaudeCodeApiKey();
|
|
291
291
|
if (refreshedKey) {
|
|
292
292
|
completeOptions.apiKey = refreshedKey;
|
|
293
293
|
response = await complete(model, context, completeOptions);
|
|
@@ -296,7 +296,7 @@ async function chatWithContext(config, options) {
|
|
|
296
296
|
if (isCocoon) {
|
|
297
297
|
const textBlock = response.content.find((b) => b.type === "text");
|
|
298
298
|
if (textBlock?.type === "text" && textBlock.text.includes("<tool_call>")) {
|
|
299
|
-
const { parseToolCallsFromText, extractPlainText } = await import("./tool-adapter-
|
|
299
|
+
const { parseToolCallsFromText, extractPlainText } = await import("./tool-adapter-IVX2XQJE.js");
|
|
300
300
|
const syntheticCalls = parseToolCallsFromText(textBlock.text, cocoonAllowedTools);
|
|
301
301
|
if (syntheticCalls.length > 0) {
|
|
302
302
|
const plainText = extractPlainText(textBlock.text);
|
|
@@ -331,9 +331,17 @@ async function chatWithContext(config, options) {
|
|
|
331
331
|
}
|
|
332
332
|
function loadContextFromTranscript(sessionId, systemPrompt) {
|
|
333
333
|
const messages = readTranscript(sessionId);
|
|
334
|
+
const seenToolCallIds = /* @__PURE__ */ new Set();
|
|
335
|
+
const deduped = messages.filter((msg) => {
|
|
336
|
+
if (msg.role !== "toolResult") return true;
|
|
337
|
+
const id = msg.toolCallId;
|
|
338
|
+
if (seenToolCallIds.has(id)) return false;
|
|
339
|
+
seenToolCallIds.add(id);
|
|
340
|
+
return true;
|
|
341
|
+
});
|
|
334
342
|
return {
|
|
335
343
|
systemPrompt,
|
|
336
|
-
messages
|
|
344
|
+
messages: deduped
|
|
337
345
|
};
|
|
338
346
|
}
|
|
339
347
|
function createClient(_config) {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-EYWNOHMJ.js";
|
|
4
4
|
import {
|
|
5
5
|
createLogger
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-NQ6FZKCE.js";
|
|
7
7
|
|
|
8
8
|
// src/session/transcript.ts
|
|
9
9
|
import {
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import { join } from "path";
|
|
20
20
|
var log = createLogger("Session");
|
|
21
21
|
var SESSIONS_DIR = join(TELETON_ROOT, "sessions");
|
|
22
|
+
var transcriptCache = /* @__PURE__ */ new Map();
|
|
22
23
|
function getTranscriptPath(sessionId) {
|
|
23
24
|
return join(SESSIONS_DIR, `${sessionId}.jsonl`);
|
|
24
25
|
}
|
|
@@ -36,6 +37,10 @@ function appendToTranscript(sessionId, message) {
|
|
|
36
37
|
} catch (error) {
|
|
37
38
|
log.error({ err: error }, `Failed to append to transcript ${sessionId}`);
|
|
38
39
|
}
|
|
40
|
+
const cached = transcriptCache.get(sessionId);
|
|
41
|
+
if (cached) {
|
|
42
|
+
cached.push(message);
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
function extractToolCallIds(msg) {
|
|
41
46
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -94,6 +99,8 @@ function sanitizeMessages(messages) {
|
|
|
94
99
|
return sanitized;
|
|
95
100
|
}
|
|
96
101
|
function readTranscript(sessionId) {
|
|
102
|
+
const cached = transcriptCache.get(sessionId);
|
|
103
|
+
if (cached) return [...cached];
|
|
97
104
|
const transcriptPath = getTranscriptPath(sessionId);
|
|
98
105
|
if (!existsSync(transcriptPath)) {
|
|
99
106
|
return [];
|
|
@@ -114,7 +121,9 @@ function readTranscript(sessionId) {
|
|
|
114
121
|
if (corruptCount > 0) {
|
|
115
122
|
log.warn(`${corruptCount} corrupt line(s) skipped in transcript ${sessionId}`);
|
|
116
123
|
}
|
|
117
|
-
|
|
124
|
+
const sanitized = sanitizeMessages(messages);
|
|
125
|
+
transcriptCache.set(sessionId, sanitized);
|
|
126
|
+
return sanitized;
|
|
118
127
|
} catch (error) {
|
|
119
128
|
log.error({ err: error }, `Failed to read transcript ${sessionId}`);
|
|
120
129
|
return [];
|
|
@@ -138,6 +147,7 @@ function deleteTranscript(sessionId) {
|
|
|
138
147
|
}
|
|
139
148
|
try {
|
|
140
149
|
unlinkSync(transcriptPath);
|
|
150
|
+
transcriptCache.delete(sessionId);
|
|
141
151
|
log.info(`Deleted transcript: ${sessionId}`);
|
|
142
152
|
return true;
|
|
143
153
|
} catch (error) {
|
|
@@ -154,6 +164,7 @@ function archiveTranscript(sessionId) {
|
|
|
154
164
|
}
|
|
155
165
|
try {
|
|
156
166
|
renameSync(transcriptPath, archivePath);
|
|
167
|
+
transcriptCache.delete(sessionId);
|
|
157
168
|
log.info(`Archived transcript: ${sessionId} \u2192 ${timestamp}.archived`);
|
|
158
169
|
return true;
|
|
159
170
|
} catch (error) {
|
|
@@ -88,12 +88,20 @@ var rootLogger = pino(
|
|
|
88
88
|
paths: [
|
|
89
89
|
"apiKey",
|
|
90
90
|
"api_key",
|
|
91
|
+
"api_hash",
|
|
92
|
+
"accessToken",
|
|
93
|
+
"access_token",
|
|
94
|
+
"refresh_token",
|
|
91
95
|
"password",
|
|
92
96
|
"secret",
|
|
93
97
|
"token",
|
|
94
98
|
"mnemonic",
|
|
95
99
|
"*.apiKey",
|
|
96
100
|
"*.api_key",
|
|
101
|
+
"*.api_hash",
|
|
102
|
+
"*.accessToken",
|
|
103
|
+
"*.access_token",
|
|
104
|
+
"*.refresh_token",
|
|
97
105
|
"*.password",
|
|
98
106
|
"*.secret",
|
|
99
107
|
"*.token",
|
|
@@ -120,6 +128,11 @@ function setLogLevel(level) {
|
|
|
120
128
|
const streams = multiStream.streams;
|
|
121
129
|
if (Array.isArray(streams) && streams[0]) {
|
|
122
130
|
streams[0].level = pino.levels.values[level] ?? 30;
|
|
131
|
+
} else {
|
|
132
|
+
process.stderr.write(
|
|
133
|
+
`[Logger] setLogLevel: pino multistream internal API changed, stdout level not updated
|
|
134
|
+
`
|
|
135
|
+
);
|
|
123
136
|
}
|
|
124
137
|
_verbose = level === "debug" || level === "trace";
|
|
125
138
|
}
|