stitchkit 0.70.5 → 0.71.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.
- package/dist/agent-runtime/coding-tool-contract.d.ts +11 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-listing.d.ts +15 -0
- package/dist/agent-runtime/coding-tool-listing.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-paths.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-refusals.d.ts +59 -0
- package/dist/agent-runtime/coding-tool-refusals.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tools.d.ts +3 -1
- package/dist/agent-runtime/coding-tools.d.ts.map +1 -1
- package/dist/agent-runtime/compaction.d.ts +35 -0
- package/dist/agent-runtime/compaction.d.ts.map +1 -1
- package/dist/agent-runtime/contained-files.d.ts +21 -2
- package/dist/agent-runtime/contained-files.d.ts.map +1 -1
- package/dist/agent-runtime/provider-failure.d.ts +66 -0
- package/dist/agent-runtime/provider-failure.d.ts.map +1 -0
- package/dist/agent-runtime/purge.d.ts +28 -0
- package/dist/agent-runtime/purge.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/runtime.d.ts +31 -1
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/schemas.d.ts +1 -0
- package/dist/agent-runtime/schemas.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-purge.d.ts +7 -0
- package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite.d.ts.map +1 -1
- package/dist/agent-runtime/store-driver.d.ts +2 -0
- package/dist/agent-runtime/store-driver.d.ts.map +1 -1
- package/dist/agent-runtime/store-purge.d.ts +13 -0
- package/dist/agent-runtime/store-purge.d.ts.map +1 -0
- package/dist/agent-runtime/store.d.ts +3 -0
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/agent-runtime-coding-tools.js +438 -124
- package/dist/agent-runtime-harness.js +4 -4
- package/dist/agent-runtime-openrouter.d.ts +19 -0
- package/dist/agent-runtime-openrouter.d.ts.map +1 -1
- package/dist/agent-runtime-openrouter.js +2 -1
- package/dist/agent-runtime-sqlite-bun.js +2 -2
- package/dist/agent-runtime-sqlite-node.js +2 -2
- package/dist/agent-runtime.d.ts +5 -2
- package/dist/agent-runtime.d.ts.map +1 -1
- package/dist/agent-runtime.js +128 -16
- package/dist/cli.js +5 -5
- package/dist/{index-cx84zg25.js → index-118v0z41.js} +1 -1
- package/dist/{index-jw81xr75.js → index-19eet1qx.js} +127 -51
- package/dist/{index-ejv31h14.js → index-7qy2ex0m.js} +1 -1
- package/dist/{index-9sx8tbz2.js → index-cksjz4eg.js} +50 -1
- package/dist/{index-trrf7nch.js → index-ezmn6ac6.js} +3 -3
- package/dist/{index-ekkt4gy9.js → index-jqtsc9mj.js} +2 -2
- package/dist/{index-hxtm2xr2.js → index-k2zczx1g.js} +1 -1
- package/dist/{index-35wcrke5.js → index-m668wzyc.js} +13 -2
- package/dist/{index-w9m1wznn.js → index-nemjkxjp.js} +118 -1
- package/dist/{index-tnazr5tc.js → index-pz7ytdga.js} +3 -3
- package/dist/{index-1z5xxfst.js → index-rqpdar1e.js} +102 -5
- package/dist/{index-qm87g51s.js → index-s4c8wy8m.js} +1 -1
- package/dist/node.js +2 -2
- package/dist/observability/index.js +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -2
- package/dist/server/request.d.ts +19 -0
- package/dist/server/request.d.ts.map +1 -1
- package/dist/telegram/init-data.d.ts +134 -0
- package/dist/telegram/init-data.d.ts.map +1 -0
- package/dist/telegram/send-failure.d.ts +73 -0
- package/dist/telegram/send-failure.d.ts.map +1 -0
- package/dist/telegram.d.ts +3 -0
- package/dist/telegram.d.ts.map +1 -0
- package/dist/telegram.js +224 -0
- package/dist/tool-invoker.js +4 -4
- package/dist/tools.js +7 -7
- package/llms-full.txt +332 -9
- package/native/darwin-arm64.node +0 -0
- package/native/darwin-x64.node +0 -0
- package/package.json +6 -2
package/dist/telegram.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRecord
|
|
3
|
+
} from "./index-qyrqwr4c.js";
|
|
4
|
+
|
|
5
|
+
// src/telegram/init-data.ts
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
var TelegramInitDataUserSchema = z.object({
|
|
8
|
+
id: z.int(),
|
|
9
|
+
is_bot: z.boolean().optional(),
|
|
10
|
+
first_name: z.string(),
|
|
11
|
+
last_name: z.string().optional(),
|
|
12
|
+
username: z.string().optional(),
|
|
13
|
+
language_code: z.string().optional(),
|
|
14
|
+
is_premium: z.boolean().optional(),
|
|
15
|
+
allows_write_to_pm: z.boolean().optional(),
|
|
16
|
+
photo_url: z.string().optional()
|
|
17
|
+
}).transform((user) => ({
|
|
18
|
+
id: user.id,
|
|
19
|
+
firstName: user.first_name,
|
|
20
|
+
...user.is_bot !== undefined && { isBot: user.is_bot },
|
|
21
|
+
...user.last_name !== undefined && { lastName: user.last_name },
|
|
22
|
+
...user.username !== undefined && { username: user.username },
|
|
23
|
+
...user.language_code !== undefined && { languageCode: user.language_code },
|
|
24
|
+
...user.is_premium !== undefined && { isPremium: user.is_premium },
|
|
25
|
+
...user.allows_write_to_pm !== undefined && { allowsWriteToPm: user.allows_write_to_pm },
|
|
26
|
+
...user.photo_url !== undefined && { photoUrl: user.photo_url }
|
|
27
|
+
}));
|
|
28
|
+
var encoder = new TextEncoder;
|
|
29
|
+
async function hmacSha256(key, message) {
|
|
30
|
+
const imported = await crypto.subtle.importKey("raw", key, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
31
|
+
return crypto.subtle.sign("HMAC", imported, encoder.encode(message));
|
|
32
|
+
}
|
|
33
|
+
function toHex(buffer) {
|
|
34
|
+
return Array.from(new Uint8Array(buffer), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
35
|
+
}
|
|
36
|
+
function digestsEqual(a, b) {
|
|
37
|
+
if (a.length !== b.length)
|
|
38
|
+
return false;
|
|
39
|
+
let difference = 0;
|
|
40
|
+
for (let index = 0;index < a.length; index += 1) {
|
|
41
|
+
difference |= a.charCodeAt(index) ^ b.charCodeAt(index);
|
|
42
|
+
}
|
|
43
|
+
return difference === 0;
|
|
44
|
+
}
|
|
45
|
+
function optionalUser(raw, key) {
|
|
46
|
+
const encoded = raw[key];
|
|
47
|
+
if (encoded === undefined)
|
|
48
|
+
return;
|
|
49
|
+
return TelegramInitDataUserSchema.parse(JSON.parse(encoded));
|
|
50
|
+
}
|
|
51
|
+
async function verifyTelegramInitData(options) {
|
|
52
|
+
if (!options.botToken)
|
|
53
|
+
throw new TypeError("botToken is required to verify initData");
|
|
54
|
+
if (options.maxAgeSeconds !== undefined && (!Number.isFinite(options.maxAgeSeconds) || options.maxAgeSeconds < 0)) {
|
|
55
|
+
throw new TypeError("maxAgeSeconds must be a non-negative finite number");
|
|
56
|
+
}
|
|
57
|
+
const params = new URLSearchParams(options.initData);
|
|
58
|
+
const hash = params.get("hash");
|
|
59
|
+
if (!hash)
|
|
60
|
+
return { valid: false, reason: "missing-hash" };
|
|
61
|
+
const signed = {};
|
|
62
|
+
for (const [key, value] of params) {
|
|
63
|
+
if (key === "hash")
|
|
64
|
+
continue;
|
|
65
|
+
signed[key] = value;
|
|
66
|
+
}
|
|
67
|
+
const dataCheckString = Object.keys(signed).sort().map((key) => `${key}=${signed[key]}`).join(`
|
|
68
|
+
`);
|
|
69
|
+
const secretKey = await hmacSha256(encoder.encode("WebAppData"), options.botToken);
|
|
70
|
+
const expected = toHex(await hmacSha256(secretKey, dataCheckString));
|
|
71
|
+
if (!digestsEqual(expected, hash.toLowerCase())) {
|
|
72
|
+
return { valid: false, reason: "signature-mismatch" };
|
|
73
|
+
}
|
|
74
|
+
const authDateSeconds = Number(signed.auth_date);
|
|
75
|
+
if (!Number.isSafeInteger(authDateSeconds) || authDateSeconds <= 0) {
|
|
76
|
+
return { valid: false, reason: "malformed" };
|
|
77
|
+
}
|
|
78
|
+
const nowMs = options.now?.() ?? Date.now();
|
|
79
|
+
const ageSeconds = Math.floor(nowMs / 1000) - authDateSeconds;
|
|
80
|
+
if (options.maxAgeSeconds !== undefined && ageSeconds > options.maxAgeSeconds) {
|
|
81
|
+
return { valid: false, reason: "expired", ageSeconds };
|
|
82
|
+
}
|
|
83
|
+
let user;
|
|
84
|
+
let receiver;
|
|
85
|
+
try {
|
|
86
|
+
user = optionalUser(signed, "user");
|
|
87
|
+
receiver = optionalUser(signed, "receiver");
|
|
88
|
+
} catch {
|
|
89
|
+
return { valid: false, reason: "malformed" };
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
valid: true,
|
|
93
|
+
data: {
|
|
94
|
+
...user !== undefined && { user },
|
|
95
|
+
...receiver !== undefined && { receiver },
|
|
96
|
+
authDate: new Date(authDateSeconds * 1000),
|
|
97
|
+
ageSeconds,
|
|
98
|
+
...signed.query_id !== undefined && { queryId: signed.query_id },
|
|
99
|
+
...signed.start_param !== undefined && { startParam: signed.start_param },
|
|
100
|
+
...signed.chat_type !== undefined && { chatType: signed.chat_type },
|
|
101
|
+
...signed.chat_instance !== undefined && { chatInstance: signed.chat_instance },
|
|
102
|
+
raw: Object.freeze({ ...signed })
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// src/telegram/send-failure.ts
|
|
107
|
+
var BY_DESCRIPTION = [
|
|
108
|
+
[/bot was blocked by the user|bot was kicked/i, "blocked-by-user"],
|
|
109
|
+
[/user is deactivated|account is deactivated/i, "user-deactivated"],
|
|
110
|
+
[/can'?t initiate conversation|need to start a conversation/i, "not-started"],
|
|
111
|
+
[/chat not found|peer_id_invalid|user not found/i, "chat-not-found"],
|
|
112
|
+
[/too many requests|retry later|flood/i, "rate-limited"],
|
|
113
|
+
[
|
|
114
|
+
/message is too long|can'?t parse entities|message text is empty|wrong file identifier|button_url_invalid/i,
|
|
115
|
+
"message-invalid"
|
|
116
|
+
]
|
|
117
|
+
];
|
|
118
|
+
var RETRYABLE = new Set([
|
|
119
|
+
"rate-limited",
|
|
120
|
+
"server-error"
|
|
121
|
+
]);
|
|
122
|
+
var UNREACHABLE = new Set([
|
|
123
|
+
"blocked-by-user",
|
|
124
|
+
"user-deactivated",
|
|
125
|
+
"chat-not-found",
|
|
126
|
+
"not-started"
|
|
127
|
+
]);
|
|
128
|
+
function numberAt(value, keys) {
|
|
129
|
+
if (!isRecord(value))
|
|
130
|
+
return;
|
|
131
|
+
for (const key of keys) {
|
|
132
|
+
const candidate = value[key];
|
|
133
|
+
if (typeof candidate === "number" && Number.isFinite(candidate))
|
|
134
|
+
return candidate;
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
function statusOf(value, depth = 0) {
|
|
139
|
+
if (!isRecord(value) || depth > 4)
|
|
140
|
+
return;
|
|
141
|
+
const direct = numberAt(value, ["error_code", "statusCode", "status"]);
|
|
142
|
+
if (direct !== undefined && direct >= 400 && direct < 600)
|
|
143
|
+
return direct;
|
|
144
|
+
const nested = value.cause ?? value.response ?? value.error;
|
|
145
|
+
return nested === value ? undefined : statusOf(nested, depth + 1);
|
|
146
|
+
}
|
|
147
|
+
function retryAfterOf(value, depth = 0) {
|
|
148
|
+
if (!isRecord(value) || depth > 4)
|
|
149
|
+
return;
|
|
150
|
+
const direct = numberAt(value.parameters, ["retry_after"]);
|
|
151
|
+
if (direct !== undefined)
|
|
152
|
+
return direct;
|
|
153
|
+
const nested = value.cause ?? value.response ?? value.error;
|
|
154
|
+
return nested === value ? undefined : retryAfterOf(nested, depth + 1);
|
|
155
|
+
}
|
|
156
|
+
function descriptionOf(value, depth = 0) {
|
|
157
|
+
if (typeof value === "string")
|
|
158
|
+
return value;
|
|
159
|
+
if (value instanceof Error) {
|
|
160
|
+
const nested2 = isRecord(value) ? descriptionOf(value.cause, depth + 1) : "";
|
|
161
|
+
return `${value.message} ${nested2}`.trim();
|
|
162
|
+
}
|
|
163
|
+
if (!isRecord(value) || depth > 4)
|
|
164
|
+
return "";
|
|
165
|
+
const own = typeof value.description === "string" ? value.description : "";
|
|
166
|
+
const message = typeof value.message === "string" ? value.message : "";
|
|
167
|
+
const nested = descriptionOf(value.cause ?? value.response ?? value.error, depth + 1);
|
|
168
|
+
return [own, message, nested].filter(Boolean).join(" ");
|
|
169
|
+
}
|
|
170
|
+
function classifyTelegramSendFailure(error) {
|
|
171
|
+
const status = statusOf(error);
|
|
172
|
+
const retryAfterSeconds = retryAfterOf(error);
|
|
173
|
+
const description = descriptionOf(error);
|
|
174
|
+
if (retryAfterSeconds !== undefined) {
|
|
175
|
+
return {
|
|
176
|
+
reason: "rate-limited",
|
|
177
|
+
...status !== undefined && { status },
|
|
178
|
+
retryAfterSeconds,
|
|
179
|
+
retryable: true,
|
|
180
|
+
recipientUnreachable: false,
|
|
181
|
+
evidence: "parameters"
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
for (const [pattern, reason] of BY_DESCRIPTION) {
|
|
185
|
+
if (pattern.test(description)) {
|
|
186
|
+
return {
|
|
187
|
+
reason,
|
|
188
|
+
...status !== undefined && { status },
|
|
189
|
+
retryable: RETRYABLE.has(reason),
|
|
190
|
+
recipientUnreachable: UNREACHABLE.has(reason),
|
|
191
|
+
evidence: "description"
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (status === 429) {
|
|
196
|
+
return {
|
|
197
|
+
reason: "rate-limited",
|
|
198
|
+
status,
|
|
199
|
+
retryable: true,
|
|
200
|
+
recipientUnreachable: false,
|
|
201
|
+
evidence: "status"
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (status !== undefined && status >= 500) {
|
|
205
|
+
return {
|
|
206
|
+
reason: "server-error",
|
|
207
|
+
status,
|
|
208
|
+
retryable: true,
|
|
209
|
+
recipientUnreachable: false,
|
|
210
|
+
evidence: "status"
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
reason: "unknown",
|
|
215
|
+
...status !== undefined && { status },
|
|
216
|
+
retryable: false,
|
|
217
|
+
recipientUnreachable: false,
|
|
218
|
+
evidence: "none"
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
export {
|
|
222
|
+
verifyTelegramInitData,
|
|
223
|
+
classifyTelegramSendFailure
|
|
224
|
+
};
|
package/dist/tool-invoker.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createToolInvoker
|
|
3
|
-
} from "./index-
|
|
4
|
-
import"./index-
|
|
5
|
-
import"./index-
|
|
6
|
-
import"./index-
|
|
3
|
+
} from "./index-jqtsc9mj.js";
|
|
4
|
+
import"./index-7qy2ex0m.js";
|
|
5
|
+
import"./index-s4c8wy8m.js";
|
|
6
|
+
import"./index-nemjkxjp.js";
|
|
7
7
|
import"./index-22by16v6.js";
|
|
8
8
|
import"./index-cby4ar3v.js";
|
|
9
9
|
import"./index-nt1mp8km.js";
|
package/dist/tools.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
buildToolManifest,
|
|
6
6
|
mountAgent
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-ezmn6ac6.js";
|
|
8
8
|
import"./index-3xnq72rz.js";
|
|
9
9
|
import {
|
|
10
10
|
signJwt,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from "./index-vbf2p6me.js";
|
|
21
21
|
import {
|
|
22
22
|
createToolInvoker
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-jqtsc9mj.js";
|
|
24
24
|
import {
|
|
25
25
|
WaitTimeoutError,
|
|
26
26
|
createCli,
|
|
@@ -29,10 +29,10 @@ import {
|
|
|
29
29
|
fetchPinnedDocument,
|
|
30
30
|
readCapped,
|
|
31
31
|
runWaitOperation
|
|
32
|
-
} from "./index-
|
|
32
|
+
} from "./index-pz7ytdga.js";
|
|
33
33
|
import {
|
|
34
34
|
collectToolSurface
|
|
35
|
-
} from "./index-
|
|
35
|
+
} from "./index-k2zczx1g.js";
|
|
36
36
|
import {
|
|
37
37
|
createRuntimeToolFactory,
|
|
38
38
|
defineRuntimeTool
|
|
@@ -41,19 +41,19 @@ import {
|
|
|
41
41
|
collectTools,
|
|
42
42
|
createToolRunner,
|
|
43
43
|
formatToolError
|
|
44
|
-
} from "./index-
|
|
44
|
+
} from "./index-7qy2ex0m.js";
|
|
45
45
|
import {
|
|
46
46
|
ToolExecutionControlError,
|
|
47
47
|
coerceJsonArgs,
|
|
48
48
|
executeToolMethod,
|
|
49
49
|
isToolExecutionControlError,
|
|
50
50
|
toolResultFromError
|
|
51
|
-
} from "./index-
|
|
51
|
+
} from "./index-s4c8wy8m.js";
|
|
52
52
|
import {
|
|
53
53
|
getRequestContext,
|
|
54
54
|
getTraceId,
|
|
55
55
|
runWithRequestContext
|
|
56
|
-
} from "./index-
|
|
56
|
+
} from "./index-nemjkxjp.js";
|
|
57
57
|
import {
|
|
58
58
|
ManagedFileError
|
|
59
59
|
} from "./index-bfcpjw20.js";
|