teleton 0.6.0 → 0.7.1
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 +34 -31
- package/dist/{chunk-6L6KGATM.js → chunk-3YM57ZAV.js} +1638 -1749
- package/dist/{chunk-D5I7GBV7.js → chunk-FNV5FF35.js} +22 -13
- package/dist/{chunk-4IPJ25HE.js → chunk-HZNZT4TG.js} +1106 -711
- package/dist/chunk-LRCPA7SC.js +149 -0
- package/dist/chunk-ND2X5FWB.js +368 -0
- package/dist/chunk-NERLQY2H.js +421 -0
- package/dist/{chunk-YBA6IBGT.js → chunk-OCLG5GKI.js} +24 -24
- package/dist/{chunk-ADCMUNYU.js → chunk-RBU6JXD3.js} +60 -55
- package/dist/chunk-RCMD3U65.js +141 -0
- package/dist/{chunk-ECSCVEQQ.js → chunk-UCN6TI25.js} +7 -3
- package/dist/{chunk-WL2Q3VRD.js → chunk-UDD7FYOU.js} +12 -4
- package/dist/chunk-VAUJSSD3.js +20 -0
- package/dist/chunk-XBE4JB7C.js +8 -0
- package/dist/{chunk-GDCODBNO.js → chunk-XBKSS6DM.js} +2 -16
- package/dist/cli/index.js +878 -433
- package/dist/client-3VWE7NC4.js +29 -0
- package/dist/{get-my-gifts-KVULMBJ3.js → get-my-gifts-RI7FAXAL.js} +3 -1
- package/dist/index.js +17 -11
- package/dist/{memory-TVDOGQXS.js → memory-5SS3Q5EA.js} +7 -5
- package/dist/{migrate-QIEMPOMT.js → migrate-M7SJMDOL.js} +14 -9
- package/dist/{server-RSWVCVY3.js → server-DS5OARW6.js} +174 -85
- package/dist/setup-server-C7ZTPHD5.js +934 -0
- package/dist/{task-dependency-resolver-72DLY2HV.js → task-dependency-resolver-WKZWJLLM.js} +19 -15
- package/dist/{task-executor-VXB6DAV2.js → task-executor-PD3H4MLO.js} +4 -1
- package/dist/tool-adapter-Y3TCEQOC.js +145 -0
- package/dist/{tool-index-DKI2ZNOU.js → tool-index-MIVK3D7H.js} +14 -9
- package/dist/{transcript-7V4UNID4.js → transcript-UDJZP6NK.js} +2 -1
- package/dist/web/assets/complete-fZLnb5Ot.js +1 -0
- package/dist/web/assets/index-BqwoDycr.js +72 -0
- package/dist/web/assets/index-CRDIf07k.css +1 -0
- package/dist/web/assets/index.es-D81xLR29.js +11 -0
- package/dist/web/assets/login-telegram-BP7CJDmx.js +1 -0
- package/dist/web/assets/run-DOrDowjK.js +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +7 -3
- package/dist/chunk-2QUJLHCZ.js +0 -362
- package/dist/web/assets/index-BNhrx9S1.js +0 -67
- package/dist/web/assets/index-CqrrRLOh.css +0 -1
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_DEPENDENTS_PER_TASK
|
|
3
|
+
} from "./chunk-RO62LO6Z.js";
|
|
1
4
|
import {
|
|
2
5
|
BATCH_TRIGGER_DELAY_MS
|
|
3
6
|
} from "./chunk-4DU3C27M.js";
|
|
4
7
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
createLogger
|
|
9
|
+
} from "./chunk-RCMD3U65.js";
|
|
7
10
|
import "./chunk-QGM4M3NI.js";
|
|
8
11
|
|
|
9
12
|
// src/telegram/task-dependency-resolver.ts
|
|
13
|
+
var log = createLogger("Telegram");
|
|
10
14
|
var TaskDependencyResolver = class {
|
|
11
15
|
constructor(taskStore, bridge) {
|
|
12
16
|
this.taskStore = taskStore;
|
|
@@ -28,25 +32,25 @@ var TaskDependencyResolver = class {
|
|
|
28
32
|
const dependentIds = allDependentIds.slice(0, MAX_DEPENDENTS_PER_TASK);
|
|
29
33
|
const truncated = allDependentIds.length > MAX_DEPENDENTS_PER_TASK;
|
|
30
34
|
if (truncated) {
|
|
31
|
-
|
|
35
|
+
log.warn(
|
|
32
36
|
`\u26A0\uFE0F Task ${completedTaskId} has ${allDependentIds.length} dependents, only processing first ${MAX_DEPENDENTS_PER_TASK} (security limit)`
|
|
33
37
|
);
|
|
34
38
|
}
|
|
35
|
-
|
|
39
|
+
log.info(
|
|
36
40
|
`\u{1F4CA} Task ${completedTaskId} completed. Checking ${dependentIds.length} dependent task(s)...`
|
|
37
41
|
);
|
|
38
42
|
const tasksToTrigger = [];
|
|
39
43
|
for (const depId of dependentIds) {
|
|
40
44
|
const task = this.taskStore.getTask(depId);
|
|
41
45
|
if (!task) {
|
|
42
|
-
|
|
46
|
+
log.warn(`Dependent task ${depId} not found`);
|
|
43
47
|
continue;
|
|
44
48
|
}
|
|
45
49
|
if (task.status !== "pending") {
|
|
46
50
|
continue;
|
|
47
51
|
}
|
|
48
52
|
if (!this.taskStore.canExecute(depId)) {
|
|
49
|
-
|
|
53
|
+
log.info(`\u23F3 Task ${depId} still waiting for dependencies`);
|
|
50
54
|
continue;
|
|
51
55
|
}
|
|
52
56
|
tasksToTrigger.push(task.id);
|
|
@@ -58,7 +62,7 @@ var TaskDependencyResolver = class {
|
|
|
58
62
|
await this.triggerTask(tasksToTrigger[i]);
|
|
59
63
|
}
|
|
60
64
|
} catch (error) {
|
|
61
|
-
|
|
65
|
+
log.error({ err: error }, "Error in dependency resolver");
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
@@ -83,11 +87,11 @@ var TaskDependencyResolver = class {
|
|
|
83
87
|
const dependentIds = allDependentIds.slice(0, MAX_DEPENDENTS_PER_TASK);
|
|
84
88
|
const truncated = allDependentIds.length > MAX_DEPENDENTS_PER_TASK;
|
|
85
89
|
if (truncated) {
|
|
86
|
-
|
|
90
|
+
log.warn(
|
|
87
91
|
`\u26A0\uFE0F Task ${failedTaskId} has ${allDependentIds.length} dependents, only cancelling first ${MAX_DEPENDENTS_PER_TASK} (security limit)`
|
|
88
92
|
);
|
|
89
93
|
}
|
|
90
|
-
|
|
94
|
+
log.info(
|
|
91
95
|
`\u274C Task ${failedTaskId} failed. Cancelling ${dependentIds.length} dependent task(s)...`
|
|
92
96
|
);
|
|
93
97
|
for (const depId of dependentIds) {
|
|
@@ -105,12 +109,12 @@ var TaskDependencyResolver = class {
|
|
|
105
109
|
}
|
|
106
110
|
if (skipOnFailure) {
|
|
107
111
|
this.taskStore.cancelTask(depId);
|
|
108
|
-
|
|
112
|
+
log.info(`\u21B3 Cancelled task ${depId}: ${task.description}`);
|
|
109
113
|
await this.onTaskFail(depId);
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
} catch (error) {
|
|
113
|
-
|
|
117
|
+
log.error({ err: error }, "Error handling task failure cascade");
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
120
|
/**
|
|
@@ -120,18 +124,18 @@ var TaskDependencyResolver = class {
|
|
|
120
124
|
try {
|
|
121
125
|
const task = this.taskStore.getTask(taskId);
|
|
122
126
|
if (!task) {
|
|
123
|
-
|
|
127
|
+
log.warn(`Cannot trigger task ${taskId}: not found`);
|
|
124
128
|
return;
|
|
125
129
|
}
|
|
126
|
-
|
|
130
|
+
log.info(`\u{1F680} Triggering dependent task: ${task.description}`);
|
|
127
131
|
const gramJsClient = this.bridge.getClient().getClient();
|
|
128
132
|
const me = await gramJsClient.getMe();
|
|
129
133
|
await gramJsClient.sendMessage(me, {
|
|
130
134
|
message: `[TASK:${taskId}] ${task.description}`
|
|
131
135
|
});
|
|
132
|
-
|
|
136
|
+
log.info(`\u21B3 Sent [TASK:${taskId}] to Saved Messages`);
|
|
133
137
|
} catch (error) {
|
|
134
|
-
|
|
138
|
+
log.error({ err: error }, `Error triggering task ${taskId}`);
|
|
135
139
|
this.taskStore.failTask(taskId, `Failed to trigger: ${error}`);
|
|
136
140
|
}
|
|
137
141
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getErrorMessage
|
|
3
|
+
} from "./chunk-XBE4JB7C.js";
|
|
1
4
|
import {
|
|
2
5
|
MAX_JSON_FIELD_CHARS,
|
|
3
6
|
MAX_TOTAL_PROMPT_CHARS,
|
|
@@ -42,7 +45,7 @@ async function executeScheduledTask(task, agent, toolContext, toolRegistry, pare
|
|
|
42
45
|
{
|
|
43
46
|
toolExecuted: payload.tool,
|
|
44
47
|
toolParams: payload.params,
|
|
45
|
-
toolError:
|
|
48
|
+
toolError: getErrorMessage(error)
|
|
46
49
|
},
|
|
47
50
|
parentResults
|
|
48
51
|
);
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLogger
|
|
3
|
+
} from "./chunk-RCMD3U65.js";
|
|
4
|
+
import "./chunk-QGM4M3NI.js";
|
|
5
|
+
|
|
6
|
+
// src/cocoon/tool-adapter.ts
|
|
7
|
+
import { randomUUID } from "crypto";
|
|
8
|
+
var log = createLogger("Cocoon");
|
|
9
|
+
var TOOL_PREAMBLE = `
|
|
10
|
+
|
|
11
|
+
# Tools
|
|
12
|
+
|
|
13
|
+
You may call one or more functions to assist with the user query.
|
|
14
|
+
|
|
15
|
+
You are provided with function signatures within <tools></tools> XML tags:
|
|
16
|
+
<tools>
|
|
17
|
+
`;
|
|
18
|
+
var TOOL_POSTAMBLE = `</tools>
|
|
19
|
+
|
|
20
|
+
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
|
|
21
|
+
<tool_call>
|
|
22
|
+
{"name": <function-name>, "arguments": <args-json-object>}
|
|
23
|
+
</tool_call>`;
|
|
24
|
+
function injectToolsIntoSystemPrompt(systemPrompt, tools) {
|
|
25
|
+
if (!tools || tools.length === 0) return systemPrompt;
|
|
26
|
+
const toolLines = tools.map(
|
|
27
|
+
(t) => JSON.stringify({
|
|
28
|
+
type: "function",
|
|
29
|
+
function: {
|
|
30
|
+
name: t.name,
|
|
31
|
+
description: t.description,
|
|
32
|
+
parameters: t.parameters
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
return systemPrompt + TOOL_PREAMBLE + toolLines.join("\n") + "\n" + TOOL_POSTAMBLE;
|
|
37
|
+
}
|
|
38
|
+
var UNSUPPORTED_FIELDS = ["tools", "tool_choice", "store", "reasoning_effort", "stream_options"];
|
|
39
|
+
function stripCocoonPayload(payload) {
|
|
40
|
+
if (typeof payload !== "object" || payload === null) return;
|
|
41
|
+
const obj = payload;
|
|
42
|
+
for (const field of UNSUPPORTED_FIELDS) {
|
|
43
|
+
delete obj[field];
|
|
44
|
+
}
|
|
45
|
+
obj.presence_penalty = obj.presence_penalty ?? 1.5;
|
|
46
|
+
}
|
|
47
|
+
var TOOL_CALL_OPEN = "<tool_call>";
|
|
48
|
+
var TOOL_CALL_CLOSE = "</tool_call>";
|
|
49
|
+
var THINK_RE = /<think>[\s\S]*?<\/think>/g;
|
|
50
|
+
function extractJsonObject(text, startIndex) {
|
|
51
|
+
let braceCount = 0;
|
|
52
|
+
let inString = false;
|
|
53
|
+
let escaped = false;
|
|
54
|
+
for (let i = startIndex; i < text.length; i++) {
|
|
55
|
+
const ch = text[i];
|
|
56
|
+
if (escaped) {
|
|
57
|
+
escaped = false;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (ch === "\\" && inString) {
|
|
61
|
+
escaped = true;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ch === '"') {
|
|
65
|
+
inString = !inString;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!inString) {
|
|
69
|
+
if (ch === "{") braceCount++;
|
|
70
|
+
if (ch === "}") {
|
|
71
|
+
braceCount--;
|
|
72
|
+
if (braceCount === 0) {
|
|
73
|
+
return { json: text.slice(startIndex, i + 1), endIndex: i };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function parseToolCallsFromText(text, allowedTools) {
|
|
81
|
+
const cleaned = text.replace(THINK_RE, "").trim();
|
|
82
|
+
const calls = [];
|
|
83
|
+
let searchFrom = 0;
|
|
84
|
+
while (true) {
|
|
85
|
+
const openIdx = cleaned.indexOf(TOOL_CALL_OPEN, searchFrom);
|
|
86
|
+
if (openIdx === -1) break;
|
|
87
|
+
const contentStart = openIdx + TOOL_CALL_OPEN.length;
|
|
88
|
+
const closeIdx = cleaned.indexOf(TOOL_CALL_CLOSE, contentStart);
|
|
89
|
+
if (closeIdx === -1) break;
|
|
90
|
+
const braceStart = cleaned.indexOf("{", contentStart);
|
|
91
|
+
if (braceStart === -1 || braceStart >= closeIdx) {
|
|
92
|
+
searchFrom = closeIdx + TOOL_CALL_CLOSE.length;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const extracted = extractJsonObject(cleaned, braceStart);
|
|
96
|
+
if (extracted) {
|
|
97
|
+
try {
|
|
98
|
+
const parsed = JSON.parse(extracted.json);
|
|
99
|
+
if (parsed.name && typeof parsed.name === "string") {
|
|
100
|
+
if (allowedTools && !allowedTools.has(parsed.name)) {
|
|
101
|
+
log.warn(`Cocoon: rejected tool call "${parsed.name}" \u2014 not in allowed set`);
|
|
102
|
+
} else {
|
|
103
|
+
calls.push({
|
|
104
|
+
type: "toolCall",
|
|
105
|
+
id: `cocoon_${randomUUID()}`,
|
|
106
|
+
name: parsed.name,
|
|
107
|
+
arguments: parsed.arguments ?? {}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} catch (e) {
|
|
112
|
+
log.debug(`Failed to parse tool call JSON: ${String(e)}`);
|
|
113
|
+
log.debug(`Raw: ${extracted.json.slice(0, 200)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
searchFrom = closeIdx + TOOL_CALL_CLOSE.length;
|
|
117
|
+
}
|
|
118
|
+
return calls;
|
|
119
|
+
}
|
|
120
|
+
function extractPlainText(text) {
|
|
121
|
+
let result = text.replace(THINK_RE, "");
|
|
122
|
+
let searchFrom = 0;
|
|
123
|
+
while (true) {
|
|
124
|
+
const openIdx = result.indexOf(TOOL_CALL_OPEN, searchFrom);
|
|
125
|
+
if (openIdx === -1) break;
|
|
126
|
+
const closeIdx = result.indexOf(TOOL_CALL_CLOSE, openIdx);
|
|
127
|
+
if (closeIdx === -1) break;
|
|
128
|
+
result = result.slice(0, openIdx) + result.slice(closeIdx + TOOL_CALL_CLOSE.length);
|
|
129
|
+
searchFrom = openIdx;
|
|
130
|
+
}
|
|
131
|
+
return result.trim();
|
|
132
|
+
}
|
|
133
|
+
function wrapToolResult(resultText) {
|
|
134
|
+
const safe = resultText.replace(/]]>/g, "]]]]><![CDATA[>");
|
|
135
|
+
return `<tool_response>
|
|
136
|
+
<![CDATA[${safe}]]>
|
|
137
|
+
</tool_response>`;
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
extractPlainText,
|
|
141
|
+
injectToolsIntoSystemPrompt,
|
|
142
|
+
parseToolCallsFromText,
|
|
143
|
+
stripCocoonPayload,
|
|
144
|
+
wrapToolResult
|
|
145
|
+
};
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
serializeEmbedding
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-4DU3C27M.js";
|
|
3
|
+
} from "./chunk-FNV5FF35.js";
|
|
4
|
+
import "./chunk-XBKSS6DM.js";
|
|
6
5
|
import {
|
|
7
6
|
TOOL_RAG_KEYWORD_WEIGHT,
|
|
8
7
|
TOOL_RAG_MIN_SCORE,
|
|
9
8
|
TOOL_RAG_VECTOR_WEIGHT
|
|
10
9
|
} from "./chunk-RO62LO6Z.js";
|
|
10
|
+
import "./chunk-VAUJSSD3.js";
|
|
11
|
+
import "./chunk-4DU3C27M.js";
|
|
11
12
|
import "./chunk-EYWNOHMJ.js";
|
|
13
|
+
import {
|
|
14
|
+
createLogger
|
|
15
|
+
} from "./chunk-RCMD3U65.js";
|
|
12
16
|
import "./chunk-QGM4M3NI.js";
|
|
13
17
|
|
|
14
18
|
// src/agent/tools/tool-index.ts
|
|
19
|
+
var log = createLogger("ToolRAG");
|
|
15
20
|
function escapeFts5Query(query) {
|
|
16
21
|
return query.replace(/["\*\-\+\(\)\:\^\~\?\.\@\#\$\%\&\!\[\]\{\}\|\\\/<>=,;'`]/g, " ").replace(/\s+/g, " ").trim();
|
|
17
22
|
}
|
|
@@ -46,7 +51,7 @@ var ToolIndex = class {
|
|
|
46
51
|
);
|
|
47
52
|
`);
|
|
48
53
|
} catch (error) {
|
|
49
|
-
|
|
54
|
+
log.error({ err: error }, "Failed to create vector table");
|
|
50
55
|
this.vectorEnabled = false;
|
|
51
56
|
}
|
|
52
57
|
}
|
|
@@ -95,7 +100,7 @@ var ToolIndex = class {
|
|
|
95
100
|
this._isIndexed = true;
|
|
96
101
|
return entries.length;
|
|
97
102
|
} catch (error) {
|
|
98
|
-
|
|
103
|
+
log.error({ err: error }, "Indexing failed");
|
|
99
104
|
this._isIndexed = false;
|
|
100
105
|
return 0;
|
|
101
106
|
}
|
|
@@ -141,9 +146,9 @@ var ToolIndex = class {
|
|
|
141
146
|
});
|
|
142
147
|
txn();
|
|
143
148
|
}
|
|
144
|
-
|
|
149
|
+
log.info(`Delta reindex: -${removed.length} +${added.length} tools`);
|
|
145
150
|
} catch (error) {
|
|
146
|
-
|
|
151
|
+
log.error({ err: error }, "Delta reindex failed");
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
154
|
/**
|
|
@@ -191,7 +196,7 @@ var ToolIndex = class {
|
|
|
191
196
|
vectorScore: 1 - row.distance
|
|
192
197
|
}));
|
|
193
198
|
} catch (error) {
|
|
194
|
-
|
|
199
|
+
log.error({ err: error }, "Vector search error");
|
|
195
200
|
return [];
|
|
196
201
|
}
|
|
197
202
|
}
|
|
@@ -216,7 +221,7 @@ var ToolIndex = class {
|
|
|
216
221
|
keywordScore: bm25ToScore(row.score)
|
|
217
222
|
}));
|
|
218
223
|
} catch (error) {
|
|
219
|
-
|
|
224
|
+
log.error({ err: error }, "FTS5 search error");
|
|
220
225
|
return [];
|
|
221
226
|
}
|
|
222
227
|
}
|
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
getTranscriptSize,
|
|
8
8
|
readTranscript,
|
|
9
9
|
transcriptExists
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-OCLG5GKI.js";
|
|
11
11
|
import "./chunk-EYWNOHMJ.js";
|
|
12
|
+
import "./chunk-RCMD3U65.js";
|
|
12
13
|
import "./chunk-QGM4M3NI.js";
|
|
13
14
|
export {
|
|
14
15
|
appendToTranscript,
|