stitchkit 0.100.2 → 0.101.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/CHANGELOG.md +153 -0
- package/README.md +2 -1
- package/dist/entrypoints/agent-runtime/browser.js +119 -119
- package/dist/entrypoints/agent-runtime/coding-tools.js +15 -20
- package/dist/entrypoints/agent-runtime/harness.js +55 -63
- package/dist/entrypoints/agent-runtime/openrouter.js +6 -6
- package/dist/entrypoints/agent-runtime/sandbox.js +20 -25
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +11 -13
- package/dist/entrypoints/agent-runtime/sqlite/node.js +11 -13
- package/dist/entrypoints/agent-runtime/testing.js +32 -34
- package/dist/entrypoints/agent-runtime.js +395 -402
- package/dist/entrypoints/application/diagnostic-journal.js +26 -27
- package/dist/entrypoints/application/directory-inbox.js +16 -17
- package/dist/entrypoints/application/grammy.js +13 -13
- package/dist/entrypoints/application/opentelemetry.js +13 -13
- package/dist/entrypoints/application/schemas.js +24 -24
- package/dist/entrypoints/application.js +209 -210
- package/dist/entrypoints/bin/upgrade-cli.js +2 -2
- package/dist/entrypoints/cli.js +81 -84
- package/dist/entrypoints/contract.js +54 -57
- package/dist/entrypoints/declaration.js +22 -22
- package/dist/entrypoints/files.js +18 -21
- package/dist/entrypoints/geo.js +7 -8
- package/dist/entrypoints/google.js +2 -2
- package/dist/entrypoints/index.js +150 -154
- package/dist/entrypoints/live.js +45 -47
- package/dist/entrypoints/node.js +68 -74
- package/dist/entrypoints/oauth.js +6 -6
- package/dist/entrypoints/observability.d.ts +1 -0
- package/dist/entrypoints/observability.d.ts.map +1 -1
- package/dist/entrypoints/observability.js +116 -87
- package/dist/entrypoints/primitives.js +35 -35
- package/dist/entrypoints/react/keyboard.d.ts +4 -0
- package/dist/entrypoints/react/keyboard.d.ts.map +1 -0
- package/dist/entrypoints/react/keyboard.js +397 -0
- package/dist/entrypoints/react.js +10 -10
- package/dist/entrypoints/release.js +7 -7
- package/dist/entrypoints/remote.js +15 -17
- package/dist/entrypoints/server.js +198 -200
- package/dist/entrypoints/telegram/html.d.ts +5 -0
- package/dist/entrypoints/telegram/html.d.ts.map +1 -0
- package/dist/entrypoints/telegram/html.js +26 -0
- package/dist/entrypoints/telegram/screens.d.ts +14 -0
- package/dist/entrypoints/telegram/screens.d.ts.map +1 -0
- package/dist/entrypoints/telegram/screens.js +2028 -0
- package/dist/entrypoints/telegram.d.ts +11 -3
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +779 -159
- package/dist/entrypoints/testing.js +75 -79
- package/dist/entrypoints/tools/connections.js +30 -32
- package/dist/entrypoints/tools/contract.js +18 -20
- package/dist/entrypoints/tools/invoker.js +12 -17
- package/dist/entrypoints/tools.js +224 -229
- package/dist/entrypoints/tracking/server.js +6 -6
- package/dist/entrypoints/tracking.js +40 -42
- package/dist/entrypoints/voice.js +3 -3
- package/dist/{index-eaysmdtq.js → index-0ndk4555.js} +56 -56
- package/dist/{index-2bxbyab0.js → index-1bx1xv1k.js} +1 -1
- package/dist/{index-p5r7qpdd.js → index-1eeqpadm.js} +4 -4
- package/dist/{index-hadmp193.js → index-3ct7hhq6.js} +210 -210
- package/dist/{index-e01r054k.js → index-45tdvqa3.js} +26 -26
- package/dist/{index-dce5wxcq.js → index-4s0fep5q.js} +8 -8
- package/dist/index-50ejfz75.js +9 -0
- package/dist/{index-m9zn6cpq.js → index-5107q189.js} +12 -12
- package/dist/{index-sbdmyz75.js → index-5cc6r990.js} +3 -3
- package/dist/{index-c6bxbsnc.js → index-7kxw1awn.js} +2 -2
- package/dist/{index-0r0fbk7z.js → index-7z9ym7t8.js} +28 -28
- package/dist/{index-p7hgdyhb.js → index-814xpr6d.js} +2 -2
- package/dist/{index-gtj3zc53.js → index-8kzct1d6.js} +99 -99
- package/dist/{index-1zbbzgfh.js → index-9pw0a51a.js} +4 -4
- package/dist/{index-79z7m7dt.js → index-a9pd417t.js} +35 -35
- package/dist/{index-ham5sz8m.js → index-aaj97r4y.js} +45 -45
- package/dist/{index-s812ycat.js → index-aan6hqb9.js} +3 -3
- package/dist/{index-10x2hbx0.js → index-adhgd4pe.js} +44 -44
- package/dist/{index-2gxzjvyr.js → index-afjvjyck.js} +23 -23
- package/dist/{index-qmy6zq75.js → index-ahvsksw5.js} +16 -16
- package/dist/{index-hr4tzbwq.js → index-ap3gqe56.js} +3 -3
- package/dist/{index-znfs20ss.js → index-b2bz0kdm.js} +16 -16
- package/dist/{index-r066jx76.js → index-c6aagrbd.js} +148 -120
- package/dist/{index-k30h66yd.js → index-ck71tbcf.js} +9 -9
- package/dist/{index-eqqvgdb3.js → index-ct75c3at.js} +2 -2
- package/dist/{index-gw8bmyaj.js → index-djjhhgjk.js} +41 -41
- package/dist/{index-8qt2m66q.js → index-dvwj1f43.js} +43 -43
- package/dist/index-e05cjgtf.js +144 -0
- package/dist/{index-yw4fzmdz.js → index-e6c2spsd.js} +79 -30
- package/dist/{index-fhwqwxe0.js → index-ej331hah.js} +1 -1
- package/dist/{index-9t3dffv2.js → index-ewbaywk5.js} +5 -5
- package/dist/{index-7p1f0vp2.js → index-fyphpknh.js} +25 -25
- package/dist/{index-83bdg97s.js → index-g149e9pk.js} +1 -1
- package/dist/{index-ngfhvfpd.js → index-g6a3na27.js} +4 -4
- package/dist/{index-qwhynv6x.js → index-h124epcf.js} +20 -20
- package/dist/{index-h6eeys1v.js → index-h97tqqp1.js} +9 -9
- package/dist/{index-zcgf3gqf.js → index-hby4qhax.js} +10 -10
- package/dist/{index-5jrd0yng.js → index-j8aw2c0e.js} +4 -4
- package/dist/{index-d8m8zpd8.js → index-jzczzcsb.js} +14 -14
- package/dist/index-kqnd6a85.js +26 -0
- package/dist/{index-35mh5bhj.js → index-kw1ws0cs.js} +12 -12
- package/dist/{index-4gcnakhx.js → index-m38ej7e5.js} +2 -2
- package/dist/{index-ndddxtyx.js → index-m79yr938.js} +19 -19
- package/dist/{index-5p2m7we1.js → index-m9fndta6.js} +11 -11
- package/dist/index-mnkk1ffz.js +150 -0
- package/dist/index-n15jny5b.js +4 -0
- package/dist/{index-2vtcmrj9.js → index-n53mswt3.js} +20 -20
- package/dist/{index-bt14acb5.js → index-n5yqxd3d.js} +21 -21
- package/dist/{index-bm5rx7n6.js → index-n9tyz8z3.js} +12 -12
- package/dist/index-nmaqxdx7.js +463 -0
- package/dist/{index-mqv3b5rh.js → index-nx6eazt0.js} +30 -30
- package/dist/{index-3z73fh2c.js → index-q0th8q0z.js} +9 -9
- package/dist/{index-v260df89.js → index-qjeggp8w.js} +20 -20
- package/dist/{index-zfrhfn82.js → index-r1z0rd9c.js} +20 -20
- package/dist/{index-wqgjfstn.js → index-r5c4fedv.js} +3 -3
- package/dist/{index-cyktc4bp.js → index-r5hsgkz5.js} +118 -118
- package/dist/{index-0b1ess5e.js → index-r7a7r7ha.js} +1 -1
- package/dist/{index-1j8pm5t0.js → index-rfkh44ss.js} +15 -15
- package/dist/index-rz3z13e9.js +47 -0
- package/dist/{index-k6gpggb9.js → index-s80awwsw.js} +35 -35
- package/dist/{index-vqr7f7v8.js → index-ssmd41kh.js} +124 -124
- package/dist/index-sznqf8fx.js +20 -0
- package/dist/{index-ensd0r74.js → index-v14qqmys.js} +41 -41
- package/dist/{index-paz6sgdp.js → index-v4a2fjtk.js} +36 -36
- package/dist/{index-d9pk3td4.js → index-w0eqdhyd.js} +14 -14
- package/dist/{index-5qn1kx34.js → index-w575evhq.js} +29 -29
- package/dist/{index-3gye9wzb.js → index-w5s3xftz.js} +26 -26
- package/dist/{index-tm88avnj.js → index-wykebpn9.js} +3 -3
- package/dist/{index-sh3s86na.js → index-xkhk5d6g.js} +17 -17
- package/dist/{index-6k1937bx.js → index-xqhede6x.js} +4 -4
- package/dist/{index-f4fx2tza.js → index-zs4ms3th.js} +181 -181
- package/dist/{index-k5hsfc3j.js → index-zsvzhjtk.js} +1 -1
- package/dist/internal/secret-shapes.d.ts +21 -0
- package/dist/internal/secret-shapes.d.ts.map +1 -0
- package/dist/observability/bounded-logger.d.ts +2 -0
- package/dist/observability/bounded-logger.d.ts.map +1 -1
- package/dist/observability/sanitize.d.ts +6 -0
- package/dist/observability/sanitize.d.ts.map +1 -1
- package/dist/observability/secret-values.d.ts +25 -0
- package/dist/observability/secret-values.d.ts.map +1 -0
- package/dist/react/keyboard/hooks.d.ts +71 -0
- package/dist/react/keyboard/hooks.d.ts.map +1 -0
- package/dist/react/keyboard/layers.d.ts +98 -0
- package/dist/react/keyboard/layers.d.ts.map +1 -0
- package/dist/react/keyboard/zone.d.ts +139 -0
- package/dist/react/keyboard/zone.d.ts.map +1 -0
- package/dist/telegram/bot-api.d.ts +7 -4
- package/dist/telegram/bot-api.d.ts.map +1 -1
- package/dist/telegram/crypto.d.ts +16 -0
- package/dist/telegram/crypto.d.ts.map +1 -0
- package/dist/telegram/html/check.d.ts +26 -0
- package/dist/telegram/html/check.d.ts.map +1 -0
- package/dist/telegram/html/nodes.d.ts +70 -0
- package/dist/telegram/html/nodes.d.ts.map +1 -0
- package/dist/telegram/html/parse.d.ts +35 -0
- package/dist/telegram/html/parse.d.ts.map +1 -0
- package/dist/telegram/html/render.d.ts +39 -0
- package/dist/telegram/html/render.d.ts.map +1 -0
- package/dist/telegram/init-data.d.ts +3 -44
- package/dist/telegram/init-data.d.ts.map +1 -1
- package/dist/telegram/operator-channel.d.ts +19 -3
- package/dist/telegram/operator-channel.d.ts.map +1 -1
- package/dist/telegram/operator-dedupe.d.ts +44 -0
- package/dist/telegram/operator-dedupe.d.ts.map +1 -0
- package/dist/telegram/screens/callback-codec.d.ts +34 -0
- package/dist/telegram/screens/callback-codec.d.ts.map +1 -0
- package/dist/telegram/screens/dispatch.d.ts +22 -0
- package/dist/telegram/screens/dispatch.d.ts.map +1 -0
- package/dist/telegram/screens/display.d.ts +70 -0
- package/dist/telegram/screens/display.d.ts.map +1 -0
- package/dist/telegram/screens/execute.d.ts +57 -0
- package/dist/telegram/screens/execute.d.ts.map +1 -0
- package/dist/telegram/screens/html.d.ts +36 -0
- package/dist/telegram/screens/html.d.ts.map +1 -0
- package/dist/telegram/screens/outcome.d.ts +74 -0
- package/dist/telegram/screens/outcome.d.ts.map +1 -0
- package/dist/telegram/screens/path.d.ts +29 -0
- package/dist/telegram/screens/path.d.ts.map +1 -0
- package/dist/telegram/screens/reconcile.d.ts +67 -0
- package/dist/telegram/screens/reconcile.d.ts.map +1 -0
- package/dist/telegram/screens/registry.d.ts +23 -0
- package/dist/telegram/screens/registry.d.ts.map +1 -0
- package/dist/telegram/screens/render.d.ts +70 -0
- package/dist/telegram/screens/render.d.ts.map +1 -0
- package/dist/telegram/screens/runtime.d.ts +133 -0
- package/dist/telegram/screens/runtime.d.ts.map +1 -0
- package/dist/telegram/screens/screen-types.d.ts +130 -0
- package/dist/telegram/screens/screen-types.d.ts.map +1 -0
- package/dist/telegram/screens/screen.d.ts +138 -0
- package/dist/telegram/screens/screen.d.ts.map +1 -0
- package/dist/telegram/screens/state.d.ts +115 -0
- package/dist/telegram/screens/state.d.ts.map +1 -0
- package/dist/telegram/screens/telegram-screens.d.ts +18 -0
- package/dist/telegram/screens/telegram-screens.d.ts.map +1 -0
- package/dist/telegram/screens/test-chat-telegram.d.ts +47 -0
- package/dist/telegram/screens/test-chat-telegram.d.ts.map +1 -0
- package/dist/telegram/screens/test-chat.d.ts +66 -0
- package/dist/telegram/screens/test-chat.d.ts.map +1 -0
- package/dist/telegram/screens/view.d.ts +89 -0
- package/dist/telegram/screens/view.d.ts.map +1 -0
- package/dist/telegram/send-failure.d.ts +25 -0
- package/dist/telegram/send-failure.d.ts.map +1 -1
- package/dist/telegram/update-intake.d.ts +82 -0
- package/dist/telegram/update-intake.d.ts.map +1 -0
- package/dist/telegram/update-store-check.d.ts +22 -0
- package/dist/telegram/update-store-check.d.ts.map +1 -0
- package/dist/telegram/update-store-postgres.d.ts +33 -0
- package/dist/telegram/update-store-postgres.d.ts.map +1 -0
- package/dist/telegram/update-store-sqlite.d.ts +26 -0
- package/dist/telegram/update-store-sqlite.d.ts.map +1 -0
- package/dist/telegram/update-store.d.ts +67 -0
- package/dist/telegram/update-store.d.ts.map +1 -0
- package/dist/telegram/user.d.ts +51 -0
- package/dist/telegram/user.d.ts.map +1 -0
- package/dist/telegram/webhook.d.ts +105 -0
- package/dist/telegram/webhook.d.ts.map +1 -0
- package/dist/tools/cli/args-fields.d.ts +8 -0
- package/dist/tools/cli/args-fields.d.ts.map +1 -1
- package/dist/tools/cli/args-route.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/help.d.ts.map +1 -1
- package/llms/cli.txt +8 -2
- package/llms/observability.txt +15 -2
- package/llms/react-keyboard.txt +193 -0
- package/llms/server.4.txt +16 -0
- package/llms/stitchkit.txt +10 -4
- package/llms/telegram-html.txt +35 -0
- package/llms/telegram-screens.txt +365 -0
- package/llms/telegram.txt +245 -11
- package/llms/{upgrading-0.74.0-0.100.0.txt → upgrading-0.74.0-0.101.0.txt} +39 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +889 -19
- package/llms.txt +12 -7
- package/package.json +17 -2
- package/dist/index-2k4yrqkc.js +0 -9
- package/dist/index-crykmqkr.js +0 -26
- package/dist/index-y64k3s0h.js +0 -150
- package/dist/index-y91ry9h2.js +0 -4
- /package/dist/{index-hffjpmq9.js → index-9jfdm5tg.js} +0 -0
- /package/dist/{index-zjjyynm3.js → index-d4pa2bgs.js} +0 -0
- /package/dist/{index-rxfy4cq7.js → index-dwfv9a85.js} +0 -0
- /package/dist/{index-5jm36zv1.js → index-gfk7nrht.js} +0 -0
- /package/dist/{index-b9aefrqd.js → index-n1dqr7gf.js} +0 -0
- /package/dist/{index-q3pyb9n0.js → index-sykb5ag7.js} +0 -0
- /package/dist/{index-48ffdxgk.js → index-xhzq2qvj.js} +0 -0
- /package/dist/{index-kzfs85xp.js → index-zsarb5xp.js} +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveRouteParamsSchema
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-m38ej7e5.js";
|
|
4
4
|
import {
|
|
5
5
|
isUnsafeKey
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-zsarb5xp.js";
|
|
7
7
|
import {
|
|
8
8
|
isRecord
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-9jfdm5tg.js";
|
|
10
10
|
|
|
11
11
|
// src/contract/tool-view.ts
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
var DECLARED_TOOL_VIEW = Symbol.for("stitchkit.toolView");
|
|
14
|
-
function
|
|
14
|
+
function withToolView2(endpoint, view) {
|
|
15
15
|
const declared = { ...view, [DECLARED_TOOL_VIEW]: true };
|
|
16
16
|
return { ...endpoint, tool: { ...endpoint.tool, view: declared } };
|
|
17
17
|
}
|
|
@@ -254,9 +254,9 @@ function assertResponseMetaEndpoint(prefix, key, ep) {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
// src/contract/define.ts
|
|
257
|
-
var
|
|
258
|
-
var
|
|
259
|
-
function
|
|
257
|
+
var ALL_TRANSPORTS2 = ["HTTP", "MCP", "AGENT", "CLI"];
|
|
258
|
+
var TOOL_TRANSPORTS2 = ["MCP", "AGENT", "CLI"];
|
|
259
|
+
function defineContract2(meta, endpoints) {
|
|
260
260
|
const materializedEndpoints = {};
|
|
261
261
|
for (const [key, endpoint] of Object.entries(endpoints)) {
|
|
262
262
|
const params = resolveRouteParamsSchema(endpoint.path, endpoint.params);
|
|
@@ -293,7 +293,7 @@ function defineContract(meta, endpoints) {
|
|
|
293
293
|
}
|
|
294
294
|
const transports = new Set(ep.expose ? ep.expose.filter((t) => t !== "HTTP") : ["MCP", "AGENT"]);
|
|
295
295
|
if (transports.size === 0) {
|
|
296
|
-
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" sets tool options but is not exposed on any tool transport (${
|
|
296
|
+
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" sets tool options but is not exposed on any tool transport (${TOOL_TRANSPORTS2.join(" / ")}) — a contract factory with toolExposure 'explicit' makes an omitted expose HTTP-only`);
|
|
297
297
|
}
|
|
298
298
|
if (tool.view !== undefined)
|
|
299
299
|
assertToolView(meta.prefix, key, ep);
|
|
@@ -314,4 +314,4 @@ function defineContract(meta, endpoints) {
|
|
|
314
314
|
return { meta, endpoints: materializedEndpoints };
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
export {
|
|
317
|
+
export { withToolView2, ALL_TRANSPORTS2, TOOL_TRANSPORTS2, defineContract2 };
|
|
@@ -22,8 +22,8 @@ function jsonSchemaFields(jsonSchema) {
|
|
|
22
22
|
continue;
|
|
23
23
|
for (const field of jsonSchemaFields(member)) {
|
|
24
24
|
const existing = byName.get(field.name);
|
|
25
|
-
const
|
|
26
|
-
byName.set(field.name, existing ? { ...field, required
|
|
25
|
+
const required = existing ? conjunctive ? existing.required || field.required : existing.required && field.required : field.required;
|
|
26
|
+
byName.set(field.name, existing ? { ...field, required } : field);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
return [...byName.values()];
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forbidden2,
|
|
3
|
+
conflict2
|
|
4
|
+
} from "./index-n53mswt3.js";
|
|
5
|
+
import {
|
|
6
|
+
probeAgentProcessSandbox2,
|
|
7
|
+
missingSandboxRestrictions2,
|
|
8
|
+
codingRefusal,
|
|
9
|
+
codingPathRefusal,
|
|
10
|
+
refuseMissingCodingPath
|
|
11
|
+
} from "./index-ahvsksw5.js";
|
|
1
12
|
import {
|
|
2
13
|
NumericFileHandle,
|
|
3
|
-
assertContainedFileCurrent,
|
|
4
|
-
assertContainedParentCurrent,
|
|
5
|
-
containedEntryMetadata,
|
|
6
14
|
descriptorPath,
|
|
7
15
|
listContainedDirectory,
|
|
8
16
|
missingContainedDirectories,
|
|
9
|
-
openContainedFile,
|
|
10
17
|
openContainedParent,
|
|
18
|
+
openContainedFile,
|
|
19
|
+
assertContainedFileCurrent,
|
|
20
|
+
assertContainedParentCurrent,
|
|
21
|
+
containedEntryMetadata,
|
|
11
22
|
openContainedParentFile,
|
|
12
23
|
readContainedUtf8Handle,
|
|
13
24
|
scanContainedFiles
|
|
14
|
-
} from "./index-
|
|
25
|
+
} from "./index-ej331hah.js";
|
|
15
26
|
import {
|
|
16
27
|
loadDarwinBinding
|
|
17
|
-
} from "./index-
|
|
18
|
-
import {
|
|
19
|
-
codingPathRefusal,
|
|
20
|
-
codingRefusal,
|
|
21
|
-
missingSandboxRestrictions,
|
|
22
|
-
probeAgentProcessSandbox,
|
|
23
|
-
refuseMissingCodingPath
|
|
24
|
-
} from "./index-qmy6zq75.js";
|
|
25
|
-
import {
|
|
26
|
-
defineRuntimeTool
|
|
27
|
-
} from "./index-d8m8zpd8.js";
|
|
28
|
+
} from "./index-d4pa2bgs.js";
|
|
28
29
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} from "./index-2vtcmrj9.js";
|
|
30
|
+
defineRuntimeTool2
|
|
31
|
+
} from "./index-jzczzcsb.js";
|
|
32
32
|
|
|
33
33
|
// src/agent-runtime/coding-tool-contract.ts
|
|
34
34
|
import { z } from "zod";
|
|
35
|
-
var
|
|
35
|
+
var AgentCodingToolLimitsSchema2 = z.object({
|
|
36
36
|
maxPathBytes: z.int().positive(),
|
|
37
37
|
maxReadBytes: z.int().positive(),
|
|
38
38
|
maxWriteBytes: z.int().positive(),
|
|
@@ -47,7 +47,7 @@ var AgentCodingToolLimitsSchema = z.object({
|
|
|
47
47
|
shellTimeoutMs: z.int().positive(),
|
|
48
48
|
shellTerminationGraceMs: z.int().positive()
|
|
49
49
|
}).strict();
|
|
50
|
-
var
|
|
50
|
+
var AgentCodingToolAuthorizationSchema2 = z.discriminatedUnion("operation", [
|
|
51
51
|
z.object({ operation: z.literal("read"), path: z.string().min(1) }).strict(),
|
|
52
52
|
z.object({
|
|
53
53
|
operation: z.literal("write"),
|
|
@@ -95,7 +95,7 @@ var AgentCodingToolAuthorizationSchema = z.discriminatedUnion("operation", [
|
|
|
95
95
|
cwd: z.string().min(1)
|
|
96
96
|
}).strict()
|
|
97
97
|
]);
|
|
98
|
-
var
|
|
98
|
+
var AgentCodingToolPathAuthorizationSchema2 = z.object({ path: z.string().min(1) }).strict();
|
|
99
99
|
var CodingDeniedEntrySchema = z.object({
|
|
100
100
|
path: z.string().min(1),
|
|
101
101
|
kind: z.enum(["file", "directory", "symlink", "other"])
|
|
@@ -170,7 +170,7 @@ var DEFAULT_LIMITS = {
|
|
|
170
170
|
shellTerminationGraceMs: 250
|
|
171
171
|
};
|
|
172
172
|
function resolveCodingToolLimits(input) {
|
|
173
|
-
return
|
|
173
|
+
return AgentCodingToolLimitsSchema2.parse({ ...DEFAULT_LIMITS, ...input });
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// src/agent-runtime/coding-tools.ts
|
|
@@ -238,14 +238,14 @@ async function existingCodingPath(root, requested, maxPathBytes) {
|
|
|
238
238
|
return { absolute: resolved, relative: path.relative(root, resolved) || "." };
|
|
239
239
|
}
|
|
240
240
|
async function authorizeCodingTool(config, request) {
|
|
241
|
-
const parsed =
|
|
241
|
+
const parsed = AgentCodingToolAuthorizationSchema2.parse(request);
|
|
242
242
|
if (!await config.authorize(parsed))
|
|
243
|
-
|
|
243
|
+
forbidden2("Coding tool permission denied");
|
|
244
244
|
}
|
|
245
245
|
async function isCodingPathAuthorized(config, path2) {
|
|
246
246
|
if (!config.authorizePath)
|
|
247
247
|
return true;
|
|
248
|
-
const parsed =
|
|
248
|
+
const parsed = AgentCodingToolPathAuthorizationSchema2.parse({ path: path2 });
|
|
249
249
|
return await config.authorizePath(parsed);
|
|
250
250
|
}
|
|
251
251
|
async function authorizeCodingPath(config, path2) {
|
|
@@ -427,7 +427,7 @@ async function digestFile(handle, size) {
|
|
|
427
427
|
return hash.digest("hex");
|
|
428
428
|
}
|
|
429
429
|
function createFileCodingTools(config, limits) {
|
|
430
|
-
const read =
|
|
430
|
+
const read = defineRuntimeTool2({
|
|
431
431
|
name: "read_file",
|
|
432
432
|
description: "Read a bounded UTF-8 slice from a host-authorized workspace file.",
|
|
433
433
|
identity: { serviceName: "coding", action: "read-file", method: "POST" },
|
|
@@ -491,7 +491,7 @@ function createFileCodingTools(config, limits) {
|
|
|
491
491
|
};
|
|
492
492
|
}
|
|
493
493
|
});
|
|
494
|
-
const write =
|
|
494
|
+
const write = defineRuntimeTool2({
|
|
495
495
|
name: "write_file",
|
|
496
496
|
description: "Write bounded UTF-8 content to a host-authorized workspace file.",
|
|
497
497
|
identity: { serviceName: "coding", action: "write-file", method: "POST" },
|
|
@@ -630,7 +630,7 @@ function compileWorkspaceGlob(pattern) {
|
|
|
630
630
|
}
|
|
631
631
|
function createListingCodingTools(config, limits) {
|
|
632
632
|
const excluded = new Set(config.search?.excludeDirectories ?? DEFAULT_EXCLUDED_DIRECTORIES);
|
|
633
|
-
const list =
|
|
633
|
+
const list = defineRuntimeTool2({
|
|
634
634
|
name: "list_directory",
|
|
635
635
|
description: "List the direct entries of one workspace directory.",
|
|
636
636
|
identity: { serviceName: "coding", action: "list-directory", method: "POST" },
|
|
@@ -672,7 +672,7 @@ function createListingCodingTools(config, limits) {
|
|
|
672
672
|
};
|
|
673
673
|
}
|
|
674
674
|
});
|
|
675
|
-
const glob =
|
|
675
|
+
const glob = defineRuntimeTool2({
|
|
676
676
|
name: "glob",
|
|
677
677
|
description: "List workspace files matching a `**`/`*`/`?` pattern.",
|
|
678
678
|
identity: { serviceName: "coding", action: "glob", method: "POST" },
|
|
@@ -894,7 +894,7 @@ async function editFile(config, limits, input) {
|
|
|
894
894
|
const source = read.text;
|
|
895
895
|
const baseSha256 = sha256(source);
|
|
896
896
|
if (input.expectedSha256 !== undefined && baseSha256 !== input.expectedSha256) {
|
|
897
|
-
|
|
897
|
+
conflict2("The file changed since it was read", {
|
|
898
898
|
message: "The file changed since it was read",
|
|
899
899
|
path: relative,
|
|
900
900
|
expectedSha256: input.expectedSha256,
|
|
@@ -956,7 +956,7 @@ async function editFile(config, limits, input) {
|
|
|
956
956
|
}
|
|
957
957
|
}
|
|
958
958
|
function createSearchAndPatchCodingTools(config, limits) {
|
|
959
|
-
const search =
|
|
959
|
+
const search = defineRuntimeTool2({
|
|
960
960
|
name: "search_files",
|
|
961
961
|
description: "Search bounded relative paths or UTF-8 file content under the workspace root.",
|
|
962
962
|
identity: { serviceName: "coding", action: "search", method: "POST" },
|
|
@@ -965,7 +965,7 @@ function createSearchAndPatchCodingTools(config, limits) {
|
|
|
965
965
|
transports: ["AGENT"],
|
|
966
966
|
handler: ({ input }) => searchFiles(config, limits, input)
|
|
967
967
|
});
|
|
968
|
-
const edit =
|
|
968
|
+
const edit = defineRuntimeTool2({
|
|
969
969
|
name: "edit_file",
|
|
970
970
|
description: "Replace an exact snippet in one workspace file.",
|
|
971
971
|
identity: { serviceName: "coding", action: "edit-file", method: "POST" },
|
|
@@ -1165,7 +1165,7 @@ async function runCodingShell(input) {
|
|
|
1165
1165
|
function createShellCodingTool(config, limits) {
|
|
1166
1166
|
const executables = config.executables ?? {};
|
|
1167
1167
|
const executableNames = Object.keys(executables).sort();
|
|
1168
|
-
return
|
|
1168
|
+
return defineRuntimeTool2({
|
|
1169
1169
|
name: "run_command",
|
|
1170
1170
|
description: "Run a finite host-declared executable with bounded arguments, time and output.",
|
|
1171
1171
|
identity: { serviceName: "coding", action: "shell", method: "POST" },
|
|
@@ -1199,13 +1199,13 @@ function createShellCodingTool(config, limits) {
|
|
|
1199
1199
|
let executableArgs = input.args;
|
|
1200
1200
|
let environment = config.environment ?? {};
|
|
1201
1201
|
if (config.sandbox) {
|
|
1202
|
-
const grade = await
|
|
1202
|
+
const grade = await probeAgentProcessSandbox2(config.sandbox.adapter);
|
|
1203
1203
|
if (grade.grade === "unavailable") {
|
|
1204
1204
|
codingRefusal("SANDBOX_UNAVAILABLE", "The configured process sandbox is unavailable", {
|
|
1205
1205
|
details: { reason: grade.reason }
|
|
1206
1206
|
});
|
|
1207
1207
|
}
|
|
1208
|
-
const missing =
|
|
1208
|
+
const missing = missingSandboxRestrictions2(grade, config.sandbox.required);
|
|
1209
1209
|
if (missing.length > 0) {
|
|
1210
1210
|
codingRefusal("SANDBOX_INSUFFICIENT", "The process sandbox lacks required restrictions", {
|
|
1211
1211
|
details: { missing, grade: grade.grade }
|
|
@@ -1223,7 +1223,7 @@ function createShellCodingTool(config, limits) {
|
|
|
1223
1223
|
executableArgs = [...prepared.args];
|
|
1224
1224
|
environment = prepared.environment ?? environment;
|
|
1225
1225
|
} catch (error) {
|
|
1226
|
-
const refreshed = await
|
|
1226
|
+
const refreshed = await probeAgentProcessSandbox2(config.sandbox.adapter, {
|
|
1227
1227
|
refresh: true
|
|
1228
1228
|
});
|
|
1229
1229
|
codingRefusal("SANDBOX_UNAVAILABLE", "The process sandbox failed while preparing a command", {
|
|
@@ -1277,7 +1277,7 @@ var AGENT_CODING_TOOL_NAMES = {
|
|
|
1277
1277
|
searchFiles: "search_files",
|
|
1278
1278
|
writeFile: "write_file"
|
|
1279
1279
|
};
|
|
1280
|
-
function
|
|
1280
|
+
function createAgentCodingTools2(config) {
|
|
1281
1281
|
if (!path5.isAbsolute(config.root))
|
|
1282
1282
|
throw new Error("Coding tool root must be absolute");
|
|
1283
1283
|
for (const executable of Object.values(config.executables ?? {})) {
|
|
@@ -1289,7 +1289,7 @@ function createAgentCodingTools(config) {
|
|
|
1289
1289
|
const artifactTools = [];
|
|
1290
1290
|
if (config.artifacts) {
|
|
1291
1291
|
const artifacts = config.artifacts;
|
|
1292
|
-
artifactTools.push(
|
|
1292
|
+
artifactTools.push(defineRuntimeTool2({
|
|
1293
1293
|
name: AGENT_CODING_TOOL_NAMES.readOutput,
|
|
1294
1294
|
description: "Read a bounded byte slice from one opaque coding output artifact.",
|
|
1295
1295
|
identity: { serviceName: "coding", action: "read-artifact", method: "POST" },
|
|
@@ -1338,7 +1338,7 @@ function createAgentCodingTools(config) {
|
|
|
1338
1338
|
}));
|
|
1339
1339
|
if (artifacts.search) {
|
|
1340
1340
|
const search = artifacts.search;
|
|
1341
|
-
artifactTools.push(
|
|
1341
|
+
artifactTools.push(defineRuntimeTool2({
|
|
1342
1342
|
name: AGENT_CODING_TOOL_NAMES.searchOutput,
|
|
1343
1343
|
description: "Search a durable spilled output without loading it into context.",
|
|
1344
1344
|
identity: { serviceName: "coding", action: "search-artifact", method: "POST" },
|
|
@@ -1386,4 +1386,4 @@ function createAgentCodingTools(config) {
|
|
|
1386
1386
|
];
|
|
1387
1387
|
}
|
|
1388
1388
|
|
|
1389
|
-
export {
|
|
1389
|
+
export { AgentCodingToolLimitsSchema2, AgentCodingToolAuthorizationSchema2, AgentCodingToolPathAuthorizationSchema2, createAgentCodingTools2 };
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
AppError2,
|
|
3
|
+
STITCH_ERROR_STATUS2,
|
|
4
|
+
isRetryableStatus2,
|
|
5
|
+
isStitchErrorCode2
|
|
6
|
+
} from "./index-n53mswt3.js";
|
|
5
7
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
normalizeError2,
|
|
9
|
+
validateDeclaredOutput
|
|
10
|
+
} from "./index-b2bz0kdm.js";
|
|
8
11
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
projectToolView
|
|
12
|
-
} from "./index-0r0fbk7z.js";
|
|
12
|
+
coerceJsonArgs2
|
|
13
|
+
} from "./index-9pw0a51a.js";
|
|
13
14
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
applyToolViewDefaults,
|
|
16
|
+
projectToolView,
|
|
17
|
+
objectShapeKeys
|
|
18
|
+
} from "./index-7z9ym7t8.js";
|
|
17
19
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
runWithRequestContext2,
|
|
21
|
+
getRequestContext2
|
|
22
|
+
} from "./index-r1z0rd9c.js";
|
|
20
23
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
isRetryableStatus,
|
|
24
|
-
isStitchErrorCode
|
|
25
|
-
} from "./index-2vtcmrj9.js";
|
|
24
|
+
formatZodError2
|
|
25
|
+
} from "./index-1eeqpadm.js";
|
|
26
26
|
import {
|
|
27
27
|
isUnsafeKey
|
|
28
|
-
} from "./index-
|
|
28
|
+
} from "./index-zsarb5xp.js";
|
|
29
29
|
import {
|
|
30
30
|
isRecord
|
|
31
|
-
} from "./index-
|
|
31
|
+
} from "./index-9jfdm5tg.js";
|
|
32
32
|
|
|
33
33
|
// src/tools/execute-args.ts
|
|
34
34
|
function parseToolCallArguments(method, callArgs, {
|
|
@@ -47,8 +47,8 @@ function parseToolCallArguments(method, callArgs, {
|
|
|
47
47
|
inputArgs[key] = value;
|
|
48
48
|
}
|
|
49
49
|
if (coerceJson) {
|
|
50
|
-
paramArgs =
|
|
51
|
-
inputArgs =
|
|
50
|
+
paramArgs = coerceJsonArgs2(paramArgs, method.paramsSchema);
|
|
51
|
+
inputArgs = coerceJsonArgs2(inputArgs, method.inputSchema);
|
|
52
52
|
}
|
|
53
53
|
if (toolSurface)
|
|
54
54
|
inputArgs = applyToolViewDefaults(inputArgs, method.toolView?.defaults);
|
|
@@ -61,7 +61,7 @@ function parseToolCallArguments(method, callArgs, {
|
|
|
61
61
|
return { ok: false, message: "Invalid params", thrown: err };
|
|
62
62
|
}
|
|
63
63
|
if (!result.success) {
|
|
64
|
-
return { ok: false, message: `Invalid params: ${
|
|
64
|
+
return { ok: false, message: `Invalid params: ${formatZodError2(result.error)}` };
|
|
65
65
|
}
|
|
66
66
|
params = result.data;
|
|
67
67
|
}
|
|
@@ -74,7 +74,7 @@ function parseToolCallArguments(method, callArgs, {
|
|
|
74
74
|
return { ok: false, message: "Invalid input", thrown: err };
|
|
75
75
|
}
|
|
76
76
|
if (!result.success) {
|
|
77
|
-
return { ok: false, message: `Invalid input: ${
|
|
77
|
+
return { ok: false, message: `Invalid input: ${formatZodError2(result.error)}` };
|
|
78
78
|
}
|
|
79
79
|
input = result.data;
|
|
80
80
|
}
|
|
@@ -84,13 +84,13 @@ function parseToolCallArguments(method, callArgs, {
|
|
|
84
84
|
// src/tools/execute-result.ts
|
|
85
85
|
var normalizedToolErrors = new WeakMap;
|
|
86
86
|
function toolResultFromError(err) {
|
|
87
|
-
const appErr =
|
|
87
|
+
const appErr = normalizeError2(err);
|
|
88
88
|
const result = {
|
|
89
89
|
ok: false,
|
|
90
90
|
code: appErr.code,
|
|
91
91
|
details: appErr.details ?? { message: appErr.message },
|
|
92
92
|
...appErr.hint && { hint: appErr.hint },
|
|
93
|
-
retryable: appErr.retryable ??
|
|
93
|
+
retryable: appErr.retryable ?? isRetryableStatus2(appErr.status)
|
|
94
94
|
};
|
|
95
95
|
normalizedToolErrors.set(result, { normalized: appErr, cause: err });
|
|
96
96
|
return result;
|
|
@@ -101,15 +101,15 @@ function toolErrorFromResult(result) {
|
|
|
101
101
|
return retained.normalized;
|
|
102
102
|
const details = isRecord(result.details) ? result.details : undefined;
|
|
103
103
|
const message = typeof details?.message === "string" ? details.message : result.code;
|
|
104
|
-
const status =
|
|
105
|
-
return new
|
|
104
|
+
const status = isStitchErrorCode2(result.code) ? STITCH_ERROR_STATUS2[result.code] : 500;
|
|
105
|
+
return new AppError2(result.code, message, status, details, result.hint, undefined, result.retryable);
|
|
106
106
|
}
|
|
107
107
|
function toolCauseFromResult(result) {
|
|
108
108
|
return normalizedToolErrors.get(result)?.cause;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
// src/tools/execute.ts
|
|
112
|
-
class
|
|
112
|
+
class ToolExecutionControlError2 extends Error {
|
|
113
113
|
reason;
|
|
114
114
|
constructor(reason) {
|
|
115
115
|
super(`Agent tool execution stopped: ${reason}`);
|
|
@@ -123,8 +123,8 @@ function isPlainObject(value) {
|
|
|
123
123
|
const proto = Object.getPrototypeOf(value);
|
|
124
124
|
return proto === Object.prototype || proto === null;
|
|
125
125
|
}
|
|
126
|
-
function
|
|
127
|
-
return value instanceof
|
|
126
|
+
function isToolExecutionControlError2(value) {
|
|
127
|
+
return value instanceof ToolExecutionControlError2;
|
|
128
128
|
}
|
|
129
129
|
var noProgress = async () => {
|
|
130
130
|
return;
|
|
@@ -134,10 +134,10 @@ async function executeToolMethod(method, call, options = {}) {
|
|
|
134
134
|
return inToolCallContext({ source: context.source, toolName, method }, () => runToolMethod(method, call, options));
|
|
135
135
|
}
|
|
136
136
|
function inToolCallContext(call, body) {
|
|
137
|
-
const parent =
|
|
137
|
+
const parent = getRequestContext2();
|
|
138
138
|
if (!parent)
|
|
139
139
|
return body();
|
|
140
|
-
return
|
|
140
|
+
return runWithRequestContext2({
|
|
141
141
|
...parent,
|
|
142
142
|
trace: parent.trace,
|
|
143
143
|
dimensions: parent.dimensions ? { ...parent.dimensions } : undefined,
|
|
@@ -205,7 +205,7 @@ async function resolveToolExtension(extension, keys, rawArgs, context) {
|
|
|
205
205
|
return { thrown: err };
|
|
206
206
|
}
|
|
207
207
|
if (!parsed.success)
|
|
208
|
-
return { invalid:
|
|
208
|
+
return { invalid: formatZodError2(parsed.error) };
|
|
209
209
|
try {
|
|
210
210
|
const resolved = await extension.resolve({ ...rawArgs, ...parsed.data });
|
|
211
211
|
return {
|
|
@@ -279,9 +279,9 @@ async function runToolMethod(method, { toolName, rawArgs, context }, {
|
|
|
279
279
|
return { kind: "args" };
|
|
280
280
|
};
|
|
281
281
|
const finishThrown = async (err) => {
|
|
282
|
-
const
|
|
283
|
-
if (
|
|
284
|
-
return
|
|
282
|
+
const before = await runBefore();
|
|
283
|
+
if (before?.kind === "failure")
|
|
284
|
+
return before.result;
|
|
285
285
|
await observed("onToolError", () => hooks?.onToolError?.({ toolName, error: err, context: hookContext, endpoint: method }));
|
|
286
286
|
return finish(toolResultFromError(err), err);
|
|
287
287
|
};
|
|
@@ -294,9 +294,9 @@ async function runToolMethod(method, { toolName, rawArgs, context }, {
|
|
|
294
294
|
if ("thrown" in resolved)
|
|
295
295
|
return finishThrown(resolved.thrown);
|
|
296
296
|
if ("invalid" in resolved) {
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
299
|
-
return
|
|
297
|
+
const before = await runBefore();
|
|
298
|
+
if (before?.kind === "failure")
|
|
299
|
+
return before.result;
|
|
300
300
|
return finish({
|
|
301
301
|
ok: false,
|
|
302
302
|
code: "VALIDATION_ERROR",
|
|
@@ -334,10 +334,10 @@ async function runToolMethod(method, { toolName, rawArgs, context }, {
|
|
|
334
334
|
toolSurface
|
|
335
335
|
}));
|
|
336
336
|
} catch (err) {
|
|
337
|
-
if (
|
|
337
|
+
if (isToolExecutionControlError2(err))
|
|
338
338
|
throw err;
|
|
339
339
|
return finishThrown(err);
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
export { parseToolCallArguments, toolResultFromError, toolErrorFromResult, toolCauseFromResult,
|
|
343
|
+
export { parseToolCallArguments, toolResultFromError, toolErrorFromResult, toolCauseFromResult, ToolExecutionControlError2, isToolExecutionControlError2, executeToolMethod };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRecord
|
|
3
|
+
} from "./index-9jfdm5tg.js";
|
|
4
|
+
|
|
5
|
+
// src/telegram/send-failure.ts
|
|
6
|
+
var BY_DESCRIPTION = [
|
|
7
|
+
[/bot was blocked by the user|bot was kicked/i, "blocked-by-user"],
|
|
8
|
+
[/user is deactivated|account is deactivated/i, "user-deactivated"],
|
|
9
|
+
[/can'?t initiate conversation|need to start a conversation/i, "not-started"],
|
|
10
|
+
[/chat not found|peer_id_invalid|user not found/i, "chat-not-found"],
|
|
11
|
+
[/too many requests|retry later|flood/i, "rate-limited"],
|
|
12
|
+
[
|
|
13
|
+
/message is too long|can'?t parse entities|message text is empty|wrong file identifier|button_url_invalid/i,
|
|
14
|
+
"message-invalid"
|
|
15
|
+
]
|
|
16
|
+
];
|
|
17
|
+
var TRAITS = {
|
|
18
|
+
"blocked-by-user": { retryable: false, recipientUnreachable: true },
|
|
19
|
+
"user-deactivated": { retryable: false, recipientUnreachable: true },
|
|
20
|
+
"chat-not-found": { retryable: false, recipientUnreachable: true },
|
|
21
|
+
"not-started": { retryable: false, recipientUnreachable: true },
|
|
22
|
+
"rate-limited": { retryable: true, recipientUnreachable: false },
|
|
23
|
+
"message-invalid": { retryable: false, recipientUnreachable: false },
|
|
24
|
+
"server-error": { retryable: true, recipientUnreachable: false },
|
|
25
|
+
unknown: { retryable: false, recipientUnreachable: false }
|
|
26
|
+
};
|
|
27
|
+
function isSendFailureReason(value) {
|
|
28
|
+
return Object.hasOwn(TRAITS, value);
|
|
29
|
+
}
|
|
30
|
+
var TELEGRAM_SEND_FAILURE_REASONS2 = Object.keys(TRAITS).filter(isSendFailureReason);
|
|
31
|
+
function numberAt(value, keys) {
|
|
32
|
+
if (!isRecord(value))
|
|
33
|
+
return;
|
|
34
|
+
for (const key of keys) {
|
|
35
|
+
const candidate = value[key];
|
|
36
|
+
if (typeof candidate === "number" && Number.isFinite(candidate))
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
function statusOf(value, depth = 0) {
|
|
42
|
+
if (!isRecord(value) || depth > 4)
|
|
43
|
+
return;
|
|
44
|
+
const direct = numberAt(value, ["error_code", "statusCode", "status"]);
|
|
45
|
+
if (direct !== undefined && direct >= 400 && direct < 600)
|
|
46
|
+
return direct;
|
|
47
|
+
const nested = value.cause ?? value.response ?? value.error;
|
|
48
|
+
return nested === value ? undefined : statusOf(nested, depth + 1);
|
|
49
|
+
}
|
|
50
|
+
function retryAfterOf(value, depth = 0) {
|
|
51
|
+
if (!isRecord(value) || depth > 4)
|
|
52
|
+
return;
|
|
53
|
+
const direct = numberAt(value.parameters, ["retry_after"]);
|
|
54
|
+
if (direct !== undefined)
|
|
55
|
+
return direct;
|
|
56
|
+
const nested = value.cause ?? value.response ?? value.error;
|
|
57
|
+
return nested === value ? undefined : retryAfterOf(nested, depth + 1);
|
|
58
|
+
}
|
|
59
|
+
function descriptionOf(value, depth = 0) {
|
|
60
|
+
if (typeof value === "string")
|
|
61
|
+
return value;
|
|
62
|
+
if (value instanceof Error) {
|
|
63
|
+
const nested = isRecord(value) ? descriptionOf(value.cause, depth + 1) : "";
|
|
64
|
+
return `${value.message} ${nested}`.trim();
|
|
65
|
+
}
|
|
66
|
+
if (!isRecord(value) || depth > 4)
|
|
67
|
+
return "";
|
|
68
|
+
const own = typeof value.description === "string" ? value.description : "";
|
|
69
|
+
const message = typeof value.message === "string" ? value.message : "";
|
|
70
|
+
const nested = descriptionOf(value.cause ?? value.response ?? value.error, depth + 1);
|
|
71
|
+
return [own, message, nested].filter(Boolean).join(" ");
|
|
72
|
+
}
|
|
73
|
+
function classifyTelegramSendFailure2(error) {
|
|
74
|
+
const status = statusOf(error);
|
|
75
|
+
const retryAfterSeconds = retryAfterOf(error);
|
|
76
|
+
const description = descriptionOf(error);
|
|
77
|
+
if (retryAfterSeconds !== undefined) {
|
|
78
|
+
return {
|
|
79
|
+
reason: "rate-limited",
|
|
80
|
+
...status !== undefined && { status },
|
|
81
|
+
retryAfterSeconds,
|
|
82
|
+
retryable: true,
|
|
83
|
+
recipientUnreachable: false,
|
|
84
|
+
evidence: "parameters"
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
for (const [pattern, reason] of BY_DESCRIPTION) {
|
|
88
|
+
if (pattern.test(description)) {
|
|
89
|
+
return {
|
|
90
|
+
reason,
|
|
91
|
+
...status !== undefined && { status },
|
|
92
|
+
...TRAITS[reason],
|
|
93
|
+
evidence: "description"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (status === 429) {
|
|
98
|
+
return {
|
|
99
|
+
reason: "rate-limited",
|
|
100
|
+
status,
|
|
101
|
+
retryable: true,
|
|
102
|
+
recipientUnreachable: false,
|
|
103
|
+
evidence: "status"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (status !== undefined && status >= 500) {
|
|
107
|
+
return {
|
|
108
|
+
reason: "server-error",
|
|
109
|
+
status,
|
|
110
|
+
retryable: true,
|
|
111
|
+
recipientUnreachable: false,
|
|
112
|
+
evidence: "status"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
reason: "unknown",
|
|
117
|
+
...status !== undefined && { status },
|
|
118
|
+
retryable: false,
|
|
119
|
+
recipientUnreachable: false,
|
|
120
|
+
evidence: "none"
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
var EDIT_REFUSALS = [
|
|
124
|
+
[/message is not modified/i, "not-modified"],
|
|
125
|
+
[
|
|
126
|
+
/message to (edit|delete) not found|message_id_invalid|message identifier is not specified/i,
|
|
127
|
+
"message-gone"
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
/message can'?t be (edited|deleted)|there is no (text|caption) in the message to edit/i,
|
|
131
|
+
"message-locked"
|
|
132
|
+
],
|
|
133
|
+
[/query is too old|query id is invalid/i, "query-expired"]
|
|
134
|
+
];
|
|
135
|
+
function classifyTelegramEditRefusal(error) {
|
|
136
|
+
const description = descriptionOf(error);
|
|
137
|
+
for (const [pattern, refusal] of EDIT_REFUSALS) {
|
|
138
|
+
if (pattern.test(description))
|
|
139
|
+
return refusal;
|
|
140
|
+
}
|
|
141
|
+
return "other";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { TELEGRAM_SEND_FAILURE_REASONS2, classifyTelegramSendFailure2, classifyTelegramEditRefusal };
|