stitchkit 0.128.0 → 0.130.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 +83 -0
- package/dist/agent-executor/acp/v1-connect.d.ts +87 -19
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-driver.d.ts +4 -2
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-handlers.d.ts +56 -0
- package/dist/agent-executor/acp/v1-handlers.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-map.d.ts +13 -2
- package/dist/agent-executor/acp/v1-map.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-permission.d.ts +44 -0
- package/dist/agent-executor/acp/v1-permission.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-protocol.d.ts +63 -10
- package/dist/agent-executor/acp/v1-protocol.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts +34 -7
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-turn.d.ts +51 -13
- package/dist/agent-executor/acp/v1-turn.d.ts.map +1 -1
- package/dist/agent-executor/claude/classify.d.ts +10 -0
- package/dist/agent-executor/claude/classify.d.ts.map +1 -1
- package/dist/agent-executor/claude/cli-driver.d.ts +4 -1
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
- package/dist/agent-executor/claude/events.d.ts +146 -0
- package/dist/agent-executor/claude/events.d.ts.map +1 -0
- package/dist/agent-executor/claude/limits.d.ts +7 -1
- package/dist/agent-executor/claude/limits.d.ts.map +1 -1
- package/dist/agent-executor/claude/protocol.d.ts +49 -9
- package/dist/agent-executor/claude/protocol.d.ts.map +1 -1
- package/dist/agent-executor/claude/session.d.ts +2 -0
- package/dist/agent-executor/claude/session.d.ts.map +1 -1
- package/dist/agent-executor/claude/transcript.d.ts +2 -2
- package/dist/agent-executor/claude/transcript.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/controls.d.ts +28 -0
- package/dist/agent-executor/claude-sdk/controls.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/driver.d.ts +208 -4
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/probe.d.ts +29 -0
- package/dist/agent-executor/claude-sdk/probe.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/query-loop.d.ts +94 -0
- package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/query-options.d.ts +29 -0
- package/dist/agent-executor/claude-sdk/query-options.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/session.d.ts +5 -5
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/turn-usage.d.ts +81 -0
- package/dist/agent-executor/claude-sdk/turn-usage.d.ts.map +1 -0
- package/dist/agent-executor/codex/classify.d.ts +4 -0
- package/dist/agent-executor/codex/classify.d.ts.map +1 -1
- package/dist/agent-executor/codex/connect.d.ts +46 -0
- package/dist/agent-executor/codex/connect.d.ts.map +1 -0
- package/dist/agent-executor/codex/control-client.d.ts +168 -0
- package/dist/agent-executor/codex/control-client.d.ts.map +1 -0
- package/dist/agent-executor/codex/driver.d.ts +71 -10
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/codex/handlers.d.ts +47 -0
- package/dist/agent-executor/codex/handlers.d.ts.map +1 -0
- package/dist/agent-executor/codex/limits.d.ts +11 -2
- package/dist/agent-executor/codex/limits.d.ts.map +1 -1
- package/dist/agent-executor/codex/protocol.d.ts +173 -4
- package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
- package/dist/agent-executor/codex/request-answers.d.ts +101 -0
- package/dist/agent-executor/codex/request-answers.d.ts.map +1 -0
- package/dist/agent-executor/codex/session-controls.d.ts +195 -0
- package/dist/agent-executor/codex/session-controls.d.ts.map +1 -0
- package/dist/agent-executor/codex/session.d.ts +55 -37
- package/dist/agent-executor/codex/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-server.d.ts +29 -0
- package/dist/agent-executor/codex/shared-server.d.ts.map +1 -0
- package/dist/agent-executor/codex/shared-thread.d.ts +46 -0
- package/dist/agent-executor/codex/shared-thread.d.ts.map +1 -0
- package/dist/agent-executor/codex/thread-controls.d.ts +128 -0
- package/dist/agent-executor/codex/thread-controls.d.ts.map +1 -0
- package/dist/agent-executor/codex/turn-input.d.ts +30 -0
- package/dist/agent-executor/codex/turn-input.d.ts.map +1 -0
- package/dist/agent-executor/codex/unix-socket-target.d.ts +26 -0
- package/dist/agent-executor/codex/unix-socket-target.d.ts.map +1 -0
- package/dist/agent-executor/codex/unix-socket.d.ts +26 -0
- package/dist/agent-executor/codex/unix-socket.d.ts.map +1 -0
- package/dist/agent-executor/codex/ws-frame.d.ts +15 -0
- package/dist/agent-executor/codex/ws-frame.d.ts.map +1 -0
- package/dist/agent-executor/contract.d.ts +79 -0
- package/dist/agent-executor/contract.d.ts.map +1 -1
- package/dist/agent-executor/engine-process.d.ts +9 -0
- package/dist/agent-executor/engine-process.d.ts.map +1 -1
- package/dist/agent-executor/engine.d.ts +6 -2
- package/dist/agent-executor/engine.d.ts.map +1 -1
- package/dist/agent-executor/executor-contract.d.ts +54 -0
- package/dist/agent-executor/executor-contract.d.ts.map +1 -1
- package/dist/agent-executor/handoff-schemas.d.ts +407 -0
- package/dist/agent-executor/handoff-schemas.d.ts.map +1 -0
- package/dist/agent-executor/handoff.d.ts +12 -0
- package/dist/agent-executor/handoff.d.ts.map +1 -0
- package/dist/agent-executor/hello.d.ts +80 -0
- package/dist/agent-executor/hello.d.ts.map +1 -1
- package/dist/agent-executor/image-input.d.ts +22 -0
- package/dist/agent-executor/image-input.d.ts.map +1 -1
- package/dist/agent-executor/projection.d.ts +2 -2
- package/dist/agent-executor/projection.d.ts.map +1 -1
- package/dist/agent-executor/session-primitives.d.ts +10 -1
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-executor/testing/conformance.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-driver.d.ts +41 -0
- package/dist/agent-executor/testing/replay-driver.d.ts.map +1 -0
- package/dist/agent-executor/testing/replay-gate.d.ts +11 -0
- package/dist/agent-executor/testing/replay-gate.d.ts.map +1 -0
- package/dist/agent-executor/testing/replay-runner.d.ts +27 -0
- package/dist/agent-executor/testing/replay-runner.d.ts.map +1 -0
- package/dist/agent-executor/testing/replay-scenarios.d.ts +21 -0
- package/dist/agent-executor/testing/replay-scenarios.d.ts.map +1 -0
- package/dist/agent-executor/testing/replay-transcript.d.ts +296 -0
- package/dist/agent-executor/testing/replay-transcript.d.ts.map +1 -0
- package/dist/agent-executor/vocabulary.d.ts +135 -0
- package/dist/agent-executor/vocabulary.d.ts.map +1 -1
- package/dist/agent-runtime/branch-observations.d.ts +5 -5
- package/dist/agent-runtime/deferred-tool-selection.d.ts.map +1 -1
- package/dist/agent-runtime/sql-rows.d.ts +10 -10
- package/dist/agent-runtime/terminal-commit.d.ts +10 -10
- package/dist/entrypoints/agent-executor/acp.d.ts +4 -1
- package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +852 -219
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts +5 -1
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/claude-sdk.js +1075 -136
- package/dist/entrypoints/agent-executor/claude.js +48 -23
- package/dist/entrypoints/agent-executor/codex.d.ts +11 -0
- package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/codex.js +3067 -388
- package/dist/entrypoints/agent-executor/testing.d.ts +4 -0
- package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/testing.js +1002 -2
- package/dist/entrypoints/agent-executor.d.ts +4 -2
- package/dist/entrypoints/agent-executor.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor.js +416 -28
- package/dist/entrypoints/agent-runtime/browser.js +1 -1
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +8 -8
- package/dist/entrypoints/agent-runtime/openrouter.js +2 -2
- package/dist/entrypoints/agent-runtime/postgres.js +6 -6
- package/dist/entrypoints/agent-runtime/realtime.js +4 -4
- package/dist/entrypoints/agent-runtime/sandbox.js +5 -5
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +5 -5
- package/dist/entrypoints/agent-runtime.js +21 -40
- package/dist/entrypoints/application/directory-inbox.js +2 -2
- package/dist/entrypoints/application/opentelemetry.js +2 -2
- package/dist/entrypoints/application.js +2 -2
- package/dist/entrypoints/cli/publish.js +3 -3
- package/dist/entrypoints/cli.js +8 -8
- package/dist/entrypoints/contract.js +2 -2
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/files.js +7 -7
- package/dist/entrypoints/handler.js +4 -4
- package/dist/entrypoints/http.js +5 -5
- package/dist/entrypoints/index.js +7 -7
- package/dist/entrypoints/node.js +5 -5
- package/dist/entrypoints/observability.js +4 -4
- package/dist/entrypoints/primitives.js +2 -2
- package/dist/entrypoints/process.js +5 -5
- package/dist/entrypoints/react.js +1 -1
- package/dist/entrypoints/remote.js +2 -2
- package/dist/entrypoints/server.js +6 -6
- package/dist/entrypoints/service-host/macos.js +5 -5
- package/dist/entrypoints/service-host.js +7 -7
- package/dist/entrypoints/spend.js +1 -1
- package/dist/entrypoints/sync/postgres.js +1 -1
- package/dist/entrypoints/sync.js +2 -2
- package/dist/entrypoints/telegram.js +2 -2
- package/dist/entrypoints/testing.js +5 -5
- package/dist/entrypoints/tools/agent.js +5 -5
- package/dist/entrypoints/tools/connections.js +2 -2
- package/dist/entrypoints/tools/invoker.js +4 -4
- package/dist/entrypoints/tools/mcp.d.ts +1 -0
- package/dist/entrypoints/tools/mcp.d.ts.map +1 -1
- package/dist/entrypoints/tools/mcp.js +5 -5
- package/dist/entrypoints/tools/toolkit.js +8 -8
- package/dist/entrypoints/tools.js +12 -12
- package/dist/entrypoints/tracking/contract.js +1 -1
- package/dist/entrypoints/xlsx.js +1 -1
- package/dist/{index-prf6ayhf.js → index-13wmzpa6.js} +1 -1
- package/dist/{index-n7f89hjw.js → index-17qgm6xe.js} +3 -3
- package/dist/{index-wv8dqy7q.js → index-205456mf.js} +1 -1
- package/dist/{index-pwskmywy.js → index-21cfxc4z.js} +1 -1
- package/dist/{index-13dnv6d0.js → index-2s8sy57y.js} +37 -104
- package/dist/{index-d4svrknj.js → index-39c2hj6h.js} +2 -2
- package/dist/{index-sfzfd2m2.js → index-39rmc00v.js} +1 -1
- package/dist/{index-ky3ardqn.js → index-3fym4j8n.js} +1 -1
- package/dist/{index-c5gp2gh6.js → index-5tdc0q43.js} +1 -1
- package/dist/{index-3ypvpkwr.js → index-669374qc.js} +1 -1
- package/dist/{index-5jyjb4s0.js → index-80acsm27.js} +1 -1
- package/dist/{index-xmr47znh.js → index-827bgv33.js} +1 -1
- package/dist/{index-v1mxss62.js → index-93n6jwy0.js} +3 -3
- package/dist/{index-d54npte7.js → index-9kpxz49v.js} +2 -2
- package/dist/{index-xv9jb84s.js → index-9sfhje6y.js} +3 -3
- package/dist/{index-9y0afd5f.js → index-apf5g7y9.js} +1 -1
- package/dist/{index-bh4pmtr9.js → index-dbp6xemn.js} +78 -8
- package/dist/{index-g3e57qj6.js → index-dcsxj68j.js} +2 -2
- package/dist/{index-waa6t4zx.js → index-dnzxxf8a.js} +1 -1
- package/dist/{index-gf92hc87.js → index-fgahdc7s.js} +2 -2
- package/dist/{index-kzavdze2.js → index-gr0kxymw.js} +5 -1
- package/dist/{index-e06z0tkb.js → index-gya4hwh3.js} +2 -2
- package/dist/{index-gzny6zsw.js → index-hab790s6.js} +5 -5
- package/dist/{index-bz3gn6cs.js → index-j0ef04jw.js} +2 -2
- package/dist/{index-rhb33thr.js → index-jcge9tx3.js} +1 -1
- package/dist/{index-4qvyhn23.js → index-jrn3prgm.js} +1 -1
- package/dist/index-kne9g2c5.js +30 -0
- package/dist/{index-pn5b11ce.js → index-mkfhpk11.js} +1 -1
- package/dist/{index-1qwrczr1.js → index-mttkdm5a.js} +1 -1
- package/dist/{index-rxnyygke.js → index-n3bm7zqq.js} +1 -1
- package/dist/{index-6wp4dn9d.js → index-p06z7g7w.js} +3 -3
- package/dist/{index-kt6dh1n6.js → index-p16q492v.js} +1 -1
- package/dist/index-p1qmpq0p.js +1300 -0
- package/dist/{index-t7wa7k12.js → index-pp97q86a.js} +1 -1
- package/dist/{index-39n02e0q.js → index-psye60qn.js} +1 -1
- package/dist/{index-5ptwb6ka.js → index-pzhqydxb.js} +1 -1
- package/dist/{index-7kfcb576.js → index-qa2jjb65.js} +1 -1
- package/dist/{index-rzeezh79.js → index-qhjmmsm2.js} +2 -2
- package/dist/{index-7grgs8cx.js → index-qpzyahe3.js} +2 -2
- package/dist/{index-jfecdk1e.js → index-r97ppg0g.js} +2 -2
- package/dist/{index-bmaz3jzy.js → index-rjs94dny.js} +1 -1
- package/dist/{index-5v5vg85s.js → index-rxh3qy4x.js} +32 -5
- package/dist/{index-en8e5zsj.js → index-ryxb427v.js} +1 -1
- package/dist/{index-y065r8g5.js → index-sd4e5x5j.js} +7 -7
- package/dist/{index-g56ht6qf.js → index-t3qcac2a.js} +1 -1
- package/dist/{index-m18xm96h.js → index-v759mzed.js} +156 -6
- package/dist/{index-4j8efqr3.js → index-x2fb37t0.js} +2 -2
- package/dist/{index-cbhxhma2.js → index-x5ayy5bn.js} +1 -0
- package/dist/index-y0a4gt1s.js +142 -0
- package/dist/{index-wavv538x.js → index-ybdq8kk2.js} +3 -3
- package/dist/{index-4gk6k3zc.js → index-ycr4pk0z.js} +1 -1
- package/dist/{index-0tyt97nk.js → index-yrr3n391.js} +1 -1
- package/dist/{index-v37b2cd6.js → index-z20pdxeb.js} +2 -2
- package/dist/{index-8x22nprv.js → index-z9d74jmb.js} +3 -3
- package/dist/{index-3tnwtz38.js → index-zhshhxew.js} +1 -1
- package/dist/{index-hj1zq7mh.js → index-znd1b57f.js} +3 -3
- package/dist/internal/positive-integer.d.ts +2 -0
- package/dist/internal/positive-integer.d.ts.map +1 -1
- package/dist/internal/unix-socket.d.ts +7 -0
- package/dist/internal/unix-socket.d.ts.map +1 -1
- package/dist/tools/internal/rank-tools.d.ts +10 -0
- package/dist/tools/internal/rank-tools.d.ts.map +1 -0
- package/dist/tools/mcp/handler.d.ts +7 -3
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/lazy-discovery.d.ts +47 -0
- package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -0
- package/dist/tools/mcp/mount.d.ts +7 -0
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +2 -2
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +7 -8
- package/llms/agent-executor-claude-sdk.txt +15 -10
- package/llms/agent-executor-claude.txt +1 -1
- package/llms/agent-executor-codex.txt +13 -3
- package/llms/agent-executor-testing.txt +5 -1
- package/llms/agent-executor.txt +9 -8
- package/llms/stitchkit.txt +74 -74
- package/llms/tools-mcp.txt +3 -2
- package/llms/tools.txt +24 -0
- package/llms/{upgrading-0.128.0.txt → upgrading-0.128.0-0.130.0.txt} +58 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +206 -107
- package/llms.txt +10 -10
- package/package.json +1 -1
- package/dist/index-0gqs8ght.js +0 -558
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
nextEventSeqByMaximum,
|
|
8
8
|
agentSqlTables,
|
|
9
9
|
createAgentRuntimeStore2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-dcsxj68j.js";
|
|
11
11
|
import {
|
|
12
12
|
canonicalAgentJson2
|
|
13
13
|
} from "./index-9xr44d2g.js";
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
scanSqlRecoverable,
|
|
23
23
|
listSqlConversations,
|
|
24
24
|
pageSqlConversationMessages
|
|
25
|
-
} from "./index-
|
|
25
|
+
} from "./index-zhshhxew.js";
|
|
26
26
|
import {
|
|
27
27
|
rollbackSqliteFailure
|
|
28
28
|
} from "./index-ttexdtjj.js";
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
} from "./index-0p0s5hrj.js";
|
|
5
5
|
import {
|
|
6
6
|
createAgentRuntimeEventSink2
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-205456mf.js";
|
|
8
8
|
import {
|
|
9
9
|
assertPositiveSafeInteger
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-gr0kxymw.js";
|
|
11
11
|
|
|
12
12
|
// src/agent-runtime/harness-control.ts
|
|
13
13
|
function reportAgentControlError(config, error, context) {
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
writeAllBytes,
|
|
10
10
|
writeAtomicFileStaged
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-pp97q86a.js";
|
|
12
12
|
import {
|
|
13
13
|
AtomicFilePublicationError2
|
|
14
14
|
} from "./index-2c5w2d1d.js";
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from "./index-jj9228tt.js";
|
|
22
22
|
import {
|
|
23
23
|
assertPositiveSafeInteger
|
|
24
|
-
} from "./index-
|
|
24
|
+
} from "./index-gr0kxymw.js";
|
|
25
25
|
import {
|
|
26
26
|
assertTimerMs
|
|
27
27
|
} from "./index-agy5fqgf.js";
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./index-xrgn784x.js";
|
|
8
8
|
import {
|
|
9
9
|
stagingName
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-psye60qn.js";
|
|
11
11
|
|
|
12
12
|
// src/internal/contained-write.ts
|
|
13
13
|
import { constants, fchmod, open as openDescriptor, write as writeDescriptor } from "node:fs";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
streamNativeCommand2
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-3fym4j8n.js";
|
|
4
4
|
import {
|
|
5
5
|
createBoundedLineDecoder
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-39rmc00v.js";
|
|
7
7
|
import {
|
|
8
8
|
assertPositiveSafeInteger
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-gr0kxymw.js";
|
|
10
10
|
|
|
11
11
|
// src/agent-executor/engine-process.ts
|
|
12
12
|
var ENGINE_LINE_BYTES = 8 * 1024 * 1024;
|
|
@@ -20,7 +20,13 @@ function spawnEngineProcess2(input) {
|
|
|
20
20
|
const maxLineBytes = input.maxLineBytes ?? ENGINE_LINE_BYTES;
|
|
21
21
|
const maxPendingStdinBytes = input.maxPendingStdinBytes ?? ENGINE_PENDING_STDIN_BYTES;
|
|
22
22
|
const maxStdinBytes = input.maxStdinBytes ?? ENGINE_STDIN_BYTES;
|
|
23
|
+
const stdoutMode = input.stdoutMode ?? "lines";
|
|
24
|
+
if (stdoutMode !== "lines" && stdoutMode !== "drain") {
|
|
25
|
+
throw new TypeError(`stdoutMode must be "lines" or "drain", received ${String(stdoutMode)}`);
|
|
26
|
+
}
|
|
23
27
|
let written = 0;
|
|
28
|
+
let pid;
|
|
29
|
+
const pidReady = Promise.withResolvers();
|
|
24
30
|
const encoder = new TextEncoder;
|
|
25
31
|
let writer;
|
|
26
32
|
let open = true;
|
|
@@ -41,7 +47,11 @@ function spawnEngineProcess2(input) {
|
|
|
41
47
|
ownerLoss: "terminate",
|
|
42
48
|
stdin,
|
|
43
49
|
maxStdinBytes,
|
|
44
|
-
signal: input.signal
|
|
50
|
+
signal: input.signal,
|
|
51
|
+
onLeaderStarted: ({ pid: startedPid }) => {
|
|
52
|
+
pid = startedPid;
|
|
53
|
+
pidReady.resolve(startedPid);
|
|
54
|
+
}
|
|
45
55
|
});
|
|
46
56
|
let tail = "";
|
|
47
57
|
(async () => {
|
|
@@ -52,6 +62,13 @@ function spawnEngineProcess2(input) {
|
|
|
52
62
|
}
|
|
53
63
|
} catch {}
|
|
54
64
|
})();
|
|
65
|
+
if (stdoutMode === "drain") {
|
|
66
|
+
(async () => {
|
|
67
|
+
try {
|
|
68
|
+
for await (const _chunk of command.stdout) {}
|
|
69
|
+
} catch {}
|
|
70
|
+
})();
|
|
71
|
+
}
|
|
55
72
|
const closeInput = () => {
|
|
56
73
|
if (!open)
|
|
57
74
|
return;
|
|
@@ -60,9 +77,15 @@ function spawnEngineProcess2(input) {
|
|
|
60
77
|
writer.close();
|
|
61
78
|
} catch {}
|
|
62
79
|
};
|
|
63
|
-
|
|
80
|
+
const onCommandSettled = () => {
|
|
81
|
+
closeInput();
|
|
82
|
+
pidReady.resolve(pid);
|
|
83
|
+
};
|
|
84
|
+
command.result.then(onCommandSettled, onCommandSettled);
|
|
64
85
|
const cleanLine = (line) => line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
65
86
|
async function* lines() {
|
|
87
|
+
if (stdoutMode === "drain")
|
|
88
|
+
return;
|
|
66
89
|
const decoder = createBoundedLineDecoder(maxLineBytes);
|
|
67
90
|
for await (const chunk of command.stdout) {
|
|
68
91
|
for (const line of decoder.push(chunk)) {
|
|
@@ -78,6 +101,10 @@ function spawnEngineProcess2(input) {
|
|
|
78
101
|
}
|
|
79
102
|
}
|
|
80
103
|
return {
|
|
104
|
+
get pid() {
|
|
105
|
+
return pid;
|
|
106
|
+
},
|
|
107
|
+
pidReady: pidReady.promise,
|
|
81
108
|
send(line) {
|
|
82
109
|
if (!open)
|
|
83
110
|
throw new Error("The engine process has closed its input");
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
assertUniqueToolName,
|
|
16
16
|
buildToolPresentationSchema,
|
|
17
17
|
projectedContractToolName
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-669374qc.js";
|
|
19
19
|
import {
|
|
20
20
|
unwrapZodWrappers,
|
|
21
21
|
objectShapeKeys,
|
|
@@ -34,11 +34,11 @@ import {
|
|
|
34
34
|
toolResultFromError,
|
|
35
35
|
toolErrorFromResult,
|
|
36
36
|
toolCauseFromResult
|
|
37
|
-
} from "./index-
|
|
37
|
+
} from "./index-n3bm7zqq.js";
|
|
38
38
|
import {
|
|
39
39
|
createToolRunner,
|
|
40
40
|
formatToolError
|
|
41
|
-
} from "./index-
|
|
41
|
+
} from "./index-fgahdc7s.js";
|
|
42
42
|
import {
|
|
43
43
|
isRepeatableRead
|
|
44
44
|
} from "./index-0x4mnwg5.js";
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
} from "./index-5y7j383h.js";
|
|
54
54
|
import {
|
|
55
55
|
writeContainedFile
|
|
56
|
-
} from "./index-
|
|
56
|
+
} from "./index-rjs94dny.js";
|
|
57
57
|
import {
|
|
58
58
|
openPinnedDirectory,
|
|
59
59
|
isSafeEntryName,
|
|
@@ -74,14 +74,14 @@ import {
|
|
|
74
74
|
} from "./index-n20tybgk.js";
|
|
75
75
|
import {
|
|
76
76
|
collectToolSurface
|
|
77
|
-
} from "./index-
|
|
77
|
+
} from "./index-x2fb37t0.js";
|
|
78
78
|
import {
|
|
79
79
|
assertNoLegacyTransports
|
|
80
80
|
} from "./index-akfgymyr.js";
|
|
81
81
|
import {
|
|
82
82
|
fetchGuarded,
|
|
83
83
|
readCapped
|
|
84
|
-
} from "./index-
|
|
84
|
+
} from "./index-apf5g7y9.js";
|
|
85
85
|
import {
|
|
86
86
|
isUnsafeKey,
|
|
87
87
|
safeJsonParse
|
|
@@ -98,7 +98,7 @@ import {
|
|
|
98
98
|
} from "./index-9pv126eh.js";
|
|
99
99
|
import {
|
|
100
100
|
assertPositiveSafeInteger
|
|
101
|
-
} from "./index-
|
|
101
|
+
} from "./index-gr0kxymw.js";
|
|
102
102
|
import {
|
|
103
103
|
isRecord,
|
|
104
104
|
isAsyncIterable,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
parseToolCallArguments,
|
|
11
11
|
toolResultFromError,
|
|
12
12
|
observed
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-n3bm7zqq.js";
|
|
14
14
|
import {
|
|
15
15
|
toolSurfaceOutputSchema,
|
|
16
16
|
staticInputRounds,
|
|
@@ -18,12 +18,12 @@ import {
|
|
|
18
18
|
validateResolvedInputRounds,
|
|
19
19
|
presentationMetadata,
|
|
20
20
|
prepareProjectedMcpTools
|
|
21
|
-
} from "./index-
|
|
21
|
+
} from "./index-669374qc.js";
|
|
22
22
|
import {
|
|
23
23
|
collectTools2,
|
|
24
24
|
createToolRunner,
|
|
25
25
|
formatToolError
|
|
26
|
-
} from "./index-
|
|
26
|
+
} from "./index-fgahdc7s.js";
|
|
27
27
|
import {
|
|
28
28
|
publishedToolAnnotations
|
|
29
29
|
} from "./index-0x4mnwg5.js";
|
|
@@ -33,6 +33,9 @@ import {
|
|
|
33
33
|
import {
|
|
34
34
|
jsonResponse
|
|
35
35
|
} from "./index-kyejf658.js";
|
|
36
|
+
import {
|
|
37
|
+
rankToolsByQuery
|
|
38
|
+
} from "./index-kne9g2c5.js";
|
|
36
39
|
import {
|
|
37
40
|
MCP_CATALOG_HEADER,
|
|
38
41
|
mcpCatalogMeta2,
|
|
@@ -51,11 +54,14 @@ import {
|
|
|
51
54
|
} from "./index-tazm4dxf.js";
|
|
52
55
|
import {
|
|
53
56
|
collectToolSurface
|
|
54
|
-
} from "./index-
|
|
57
|
+
} from "./index-x2fb37t0.js";
|
|
55
58
|
import {
|
|
56
59
|
runWithRequestContext2,
|
|
57
60
|
getRequestContext2
|
|
58
61
|
} from "./index-x6sp5vpa.js";
|
|
62
|
+
import {
|
|
63
|
+
defineRuntimeTool2
|
|
64
|
+
} from "./index-7csn6pva.js";
|
|
59
65
|
import {
|
|
60
66
|
AppError2
|
|
61
67
|
} from "./index-9pv126eh.js";
|
|
@@ -66,6 +72,9 @@ import {
|
|
|
66
72
|
import {
|
|
67
73
|
resolvePropagationContext2
|
|
68
74
|
} from "./index-y7sy1xdp.js";
|
|
75
|
+
import {
|
|
76
|
+
assertPositiveSafeInteger
|
|
77
|
+
} from "./index-gr0kxymw.js";
|
|
69
78
|
import {
|
|
70
79
|
isRecord
|
|
71
80
|
} from "./index-ps3djm8d.js";
|
|
@@ -150,6 +159,9 @@ function stampToolResult(result, stamp) {
|
|
|
150
159
|
return { ...result, _meta: { ...result._meta, ...mcpCatalogMeta2(stamp) } };
|
|
151
160
|
}
|
|
152
161
|
|
|
162
|
+
// src/tools/mcp/lazy-discovery.ts
|
|
163
|
+
import { z as z3 } from "zod";
|
|
164
|
+
|
|
153
165
|
// src/tools/mcp/prepare.ts
|
|
154
166
|
function textBlock(text) {
|
|
155
167
|
return [{ type: "text", text }];
|
|
@@ -582,7 +594,7 @@ function registerMcpTool(server, presentation, descriptor, config) {
|
|
|
582
594
|
}
|
|
583
595
|
const { name } = presentation;
|
|
584
596
|
const format = config.formatResult;
|
|
585
|
-
server.registerTool(name, stampToolRegistration(toolConfig, config.catalog), async (rawArgs, mcpContext) => stampToolResult(await runInMcpRequestContext(mcpContext, name, async () => {
|
|
597
|
+
return server.registerTool(name, stampToolRegistration(toolConfig, config.catalog), async (rawArgs, mcpContext) => stampToolResult(await runInMcpRequestContext(mcpContext, name, async () => {
|
|
586
598
|
const inspectErr = inspectOnlyError(config.lifecycle);
|
|
587
599
|
if (inspectErr)
|
|
588
600
|
return format(toolResultFromError(inspectErr), "none", name);
|
|
@@ -698,6 +710,122 @@ function mountPreparedRuntimeMcp(server, tools, config) {
|
|
|
698
710
|
}
|
|
699
711
|
}
|
|
700
712
|
|
|
713
|
+
// src/tools/mcp/lazy-discovery.ts
|
|
714
|
+
var DEFAULT_SEARCH_TOOL_NAME = "tool_search";
|
|
715
|
+
var DEFAULT_MAX_RESULTS = 10;
|
|
716
|
+
var HARD_MAX_RESULTS = 50;
|
|
717
|
+
var LazySearchInputSchema = z3.strictObject({
|
|
718
|
+
query: z3.string().trim().min(1).max(256),
|
|
719
|
+
limit: z3.int().positive().max(HARD_MAX_RESULTS).optional()
|
|
720
|
+
});
|
|
721
|
+
var LazySearchMatchSchema = z3.strictObject({
|
|
722
|
+
name: z3.string().min(1),
|
|
723
|
+
description: z3.string(),
|
|
724
|
+
newlyEnabled: z3.boolean()
|
|
725
|
+
});
|
|
726
|
+
var LazySearchOutputSchema = z3.strictObject({
|
|
727
|
+
query: z3.string(),
|
|
728
|
+
enabledTools: z3.array(z3.string()),
|
|
729
|
+
matches: z3.array(LazySearchMatchSchema),
|
|
730
|
+
totalHiddenRemaining: z3.int().nonnegative()
|
|
731
|
+
});
|
|
732
|
+
function validateMcpLazyDiscovery(rawConfig, contractToolNames, reservedToolNames = []) {
|
|
733
|
+
if (!isRecord(rawConfig)) {
|
|
734
|
+
throw new TypeError("[stitchkit] MCP discovery config must be an object");
|
|
735
|
+
}
|
|
736
|
+
if (rawConfig.mode !== "lazy") {
|
|
737
|
+
throw new TypeError(`[stitchkit] MCP discovery mode must be "lazy" (received ${JSON.stringify(rawConfig.mode)})`);
|
|
738
|
+
}
|
|
739
|
+
if (!Array.isArray(rawConfig.initialTools)) {
|
|
740
|
+
throw new TypeError("[stitchkit] MCP discovery.initialTools must be an array of tool names");
|
|
741
|
+
}
|
|
742
|
+
const searchToolName = rawConfig.searchToolName === undefined ? DEFAULT_SEARCH_TOOL_NAME : typeof rawConfig.searchToolName === "string" ? rawConfig.searchToolName.trim() : "";
|
|
743
|
+
if (searchToolName.length === 0) {
|
|
744
|
+
throw new TypeError("[stitchkit] MCP discovery.searchToolName must be a non-empty string");
|
|
745
|
+
}
|
|
746
|
+
if (rawConfig.maxResults !== undefined && typeof rawConfig.maxResults !== "number") {
|
|
747
|
+
throw new TypeError("[stitchkit] MCP discovery.maxResults must be a positive integer");
|
|
748
|
+
}
|
|
749
|
+
const maxResults = rawConfig.maxResults ?? DEFAULT_MAX_RESULTS;
|
|
750
|
+
assertPositiveSafeInteger("[stitchkit] MCP discovery.maxResults", maxResults);
|
|
751
|
+
if (maxResults > HARD_MAX_RESULTS) {
|
|
752
|
+
throw new RangeError(`[stitchkit] MCP discovery.maxResults (${maxResults}) must not exceed ${HARD_MAX_RESULTS}`);
|
|
753
|
+
}
|
|
754
|
+
const knownContract = new Set(contractToolNames);
|
|
755
|
+
const allOccupied = new Set([...contractToolNames, ...reservedToolNames]);
|
|
756
|
+
if (allOccupied.has(searchToolName)) {
|
|
757
|
+
throw new Error(`[stitchkit] MCP discovery.searchToolName "${searchToolName}" collides with an existing mounted tool`);
|
|
758
|
+
}
|
|
759
|
+
const initialTools = new Set;
|
|
760
|
+
for (const name of rawConfig.initialTools) {
|
|
761
|
+
if (typeof name !== "string" || name.trim().length === 0) {
|
|
762
|
+
throw new TypeError("[stitchkit] MCP discovery.initialTools entries must be non-empty strings");
|
|
763
|
+
}
|
|
764
|
+
if (!knownContract.has(name)) {
|
|
765
|
+
throw new Error(`[stitchkit] MCP discovery.initialTools contains unknown contract tool "${name}"`);
|
|
766
|
+
}
|
|
767
|
+
initialTools.add(name);
|
|
768
|
+
}
|
|
769
|
+
return { initialTools, searchToolName, maxResults };
|
|
770
|
+
}
|
|
771
|
+
function applyMcpLazyDiscovery(input) {
|
|
772
|
+
const { server, discovery, tools } = input;
|
|
773
|
+
const hiddenTools = [];
|
|
774
|
+
for (const entry of tools) {
|
|
775
|
+
if (!discovery.initialTools.has(entry.name)) {
|
|
776
|
+
entry.registered.enabled = false;
|
|
777
|
+
hiddenTools.push(entry);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
const searchTool = defineRuntimeTool2({
|
|
781
|
+
name: discovery.searchToolName,
|
|
782
|
+
description: "Search hidden tools by name or description and enable matching tools for this MCP session. " + "An exact tool name ranks first, followed by whole-phrase matches and multi-word matches.",
|
|
783
|
+
identity: { serviceName: "mcp", action: discovery.searchToolName, method: "POST" },
|
|
784
|
+
input: LazySearchInputSchema,
|
|
785
|
+
output: LazySearchOutputSchema,
|
|
786
|
+
expose: ["MCP"],
|
|
787
|
+
annotations: { readOnlyHint: true, idempotentHint: true },
|
|
788
|
+
handler: ({ input: args }) => {
|
|
789
|
+
const cap = Math.min(args.limit ?? discovery.maxResults, discovery.maxResults);
|
|
790
|
+
const ranked = rankToolsByQuery(args.query, hiddenTools).slice(0, cap);
|
|
791
|
+
const enabledTools = [];
|
|
792
|
+
const matches = [];
|
|
793
|
+
for (const entry of ranked) {
|
|
794
|
+
const newlyEnabled = !entry.registered.enabled;
|
|
795
|
+
if (newlyEnabled) {
|
|
796
|
+
entry.registered.enabled = true;
|
|
797
|
+
enabledTools.push(entry.name);
|
|
798
|
+
}
|
|
799
|
+
matches.push({
|
|
800
|
+
name: entry.name,
|
|
801
|
+
description: entry.description,
|
|
802
|
+
newlyEnabled
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
if (enabledTools.length > 0) {
|
|
806
|
+
server.sendToolListChanged();
|
|
807
|
+
}
|
|
808
|
+
const totalHiddenRemaining = hiddenTools.filter((entry) => !entry.registered.enabled).length;
|
|
809
|
+
return {
|
|
810
|
+
query: args.query,
|
|
811
|
+
enabledTools,
|
|
812
|
+
matches,
|
|
813
|
+
totalHiddenRemaining
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
const prepared = prepareMcpServerSurface({ services: [], runtimeTools: [searchTool] });
|
|
818
|
+
mountPreparedRuntimeMcp(server, prepared.runtimeTools, {
|
|
819
|
+
catalog: input.catalog,
|
|
820
|
+
context: input.context,
|
|
821
|
+
hooks: input.hooks,
|
|
822
|
+
lifecycle: input.lifecycle,
|
|
823
|
+
coerceJsonArgs: input.coerceJsonArgs,
|
|
824
|
+
onOutputStrip: input.onOutputStrip,
|
|
825
|
+
formatResult: (result, mode, toolName) => formatMcpResult(result, mode, toolName, input.errorHint)
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
|
|
701
829
|
// src/tools/mcp/mount.ts
|
|
702
830
|
function validateMcpSchemas2(config) {
|
|
703
831
|
prepareMcpSurface(config.services, {
|
|
@@ -724,6 +852,7 @@ function mountMcp2(mcpServer, services, config) {
|
|
|
724
852
|
}
|
|
725
853
|
function mountPreparedMcp(mcpServer, prepared, config) {
|
|
726
854
|
const lifecycle = resolveToolAccess("mountPreparedMcp", config);
|
|
855
|
+
const validatedDiscovery = config.discovery !== undefined ? validateMcpLazyDiscovery(config.discovery, prepared.map((descriptor) => descriptor.mountable.name), config.reservedToolNames) : undefined;
|
|
727
856
|
const runTool = createToolRunner({
|
|
728
857
|
source: "mcp",
|
|
729
858
|
toolSurface: true,
|
|
@@ -734,9 +863,10 @@ function mountPreparedMcp(mcpServer, prepared, config) {
|
|
|
734
863
|
coerceJsonArgs: config.coerceJsonArgs,
|
|
735
864
|
onOutputStrip: config.onOutputStrip
|
|
736
865
|
});
|
|
866
|
+
const registeredTools = [];
|
|
737
867
|
for (const descriptor of prepared) {
|
|
738
868
|
const { method, name } = descriptor.mountable;
|
|
739
|
-
registerMcpTool(mcpServer, {
|
|
869
|
+
const registered = registerMcpTool(mcpServer, {
|
|
740
870
|
name,
|
|
741
871
|
description: method.desc,
|
|
742
872
|
ui: method.ui
|
|
@@ -749,6 +879,21 @@ function mountPreparedMcp(mcpServer, prepared, config) {
|
|
|
749
879
|
lifecycle,
|
|
750
880
|
context: config.context
|
|
751
881
|
});
|
|
882
|
+
registeredTools.push({ name, description: method.desc, registered });
|
|
883
|
+
}
|
|
884
|
+
if (validatedDiscovery !== undefined) {
|
|
885
|
+
applyMcpLazyDiscovery({
|
|
886
|
+
server: mcpServer,
|
|
887
|
+
discovery: validatedDiscovery,
|
|
888
|
+
tools: registeredTools,
|
|
889
|
+
lifecycle,
|
|
890
|
+
hooks: config.hooks,
|
|
891
|
+
context: config.context,
|
|
892
|
+
catalog: config.catalog,
|
|
893
|
+
coerceJsonArgs: config.coerceJsonArgs,
|
|
894
|
+
errorHint: config.errorHint,
|
|
895
|
+
onOutputStrip: config.onOutputStrip
|
|
896
|
+
});
|
|
752
897
|
}
|
|
753
898
|
}
|
|
754
899
|
function buildMcpServer2(config, auth) {
|
|
@@ -833,6 +978,8 @@ function buildMcpServerFromPrepared(config, auth, prepared) {
|
|
|
833
978
|
inputRecursionDepth: config.inputRecursionDepth,
|
|
834
979
|
errorHint: config.errorHint,
|
|
835
980
|
onOutputStrip: config.onOutputStrip,
|
|
981
|
+
discovery: config.discovery,
|
|
982
|
+
reservedToolNames: prepared.runtimeTools.map((entry) => entry.definition.name),
|
|
836
983
|
...roundCodec !== undefined && {
|
|
837
984
|
multiRoundRuntime: {
|
|
838
985
|
codec: roundCodec,
|
|
@@ -933,6 +1080,9 @@ function prepareStaticSurface(config) {
|
|
|
933
1080
|
}
|
|
934
1081
|
function createMcpHandler2(config) {
|
|
935
1082
|
resolveToolAccess("createMcpHandler", config);
|
|
1083
|
+
if ("discovery" in config && config.discovery !== undefined) {
|
|
1084
|
+
throw new TypeError("[stitchkit] createMcpHandler: lazy tool discovery requires a stateful MCP session; use createStdioMcpServer, buildMcpServer, or mountMcp instead");
|
|
1085
|
+
}
|
|
936
1086
|
const buildPrepared = prepareStaticSurface(config);
|
|
937
1087
|
const authByCarrier = new WeakMap;
|
|
938
1088
|
let closed = false;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertPositiveSafeInteger
|
|
3
|
+
} from "./index-gr0kxymw.js";
|
|
4
|
+
import {
|
|
5
|
+
raceAbort
|
|
6
|
+
} from "./index-rptj3qnc.js";
|
|
7
|
+
|
|
8
|
+
// src/agent-executor/image-input.ts
|
|
9
|
+
var DEFAULT_MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
10
|
+
var CLAUDE_CLI_MAX_LINE_BYTES = 16 * 1024 * 1024;
|
|
11
|
+
var SUPPORTED_IMAGE_MEDIA_TYPES = new Set([
|
|
12
|
+
"image/png",
|
|
13
|
+
"image/jpeg",
|
|
14
|
+
"image/gif",
|
|
15
|
+
"image/webp"
|
|
16
|
+
]);
|
|
17
|
+
function isSupportedImageMediaType(value) {
|
|
18
|
+
return value === "image/png" || value === "image/jpeg" || value === "image/gif" || value === "image/webp";
|
|
19
|
+
}
|
|
20
|
+
function validateImageOptions(options) {
|
|
21
|
+
assertPositiveSafeInteger("maxImageBytes", options.maxImageBytes);
|
|
22
|
+
}
|
|
23
|
+
function bytesToBase64(bytes) {
|
|
24
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
25
|
+
}
|
|
26
|
+
async function resolveImageBytes(reference, options) {
|
|
27
|
+
assertPositiveSafeInteger("maxImageBytes", options.maxImageBytes);
|
|
28
|
+
let bytes;
|
|
29
|
+
try {
|
|
30
|
+
bytes = await options.resolveFile(reference);
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error("Failed to resolve image input");
|
|
33
|
+
}
|
|
34
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
35
|
+
throw new TypeError("resolveFile must return a Uint8Array");
|
|
36
|
+
}
|
|
37
|
+
if (bytes.byteLength === 0) {
|
|
38
|
+
throw new RangeError("The image is empty (0 bytes)");
|
|
39
|
+
}
|
|
40
|
+
if (bytes.byteLength > options.maxImageBytes) {
|
|
41
|
+
throw new RangeError(`The image is ${bytes.byteLength} bytes, over maxImageBytes ${options.maxImageBytes}`);
|
|
42
|
+
}
|
|
43
|
+
return bytes;
|
|
44
|
+
}
|
|
45
|
+
async function inlineOrderedParts(parts, options) {
|
|
46
|
+
const maxImageBytes = options.maxImageBytes ?? DEFAULT_MAX_IMAGE_BYTES;
|
|
47
|
+
assertPositiveSafeInteger("maxImageBytes", maxImageBytes);
|
|
48
|
+
const accepted = options.acceptedDescription ?? "text and images";
|
|
49
|
+
const extras = new Map;
|
|
50
|
+
for (let index = 0;index < parts.length; index += 1) {
|
|
51
|
+
const part = parts[index];
|
|
52
|
+
if (part === undefined)
|
|
53
|
+
continue;
|
|
54
|
+
const extra = options.validateExtra?.(part);
|
|
55
|
+
if (extra !== undefined) {
|
|
56
|
+
extras.set(index, extra);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (part.type === "text")
|
|
60
|
+
continue;
|
|
61
|
+
if (part.type !== "file") {
|
|
62
|
+
throw new TypeError(`${options.driverLabel} sends ${accepted}, received ${part.type}`);
|
|
63
|
+
}
|
|
64
|
+
if (!("mediaType" in part) || typeof part.mediaType !== "string" || !isSupportedImageMediaType(part.mediaType)) {
|
|
65
|
+
const mediaType = "mediaType" in part ? String(part.mediaType) : "unknown";
|
|
66
|
+
throw new TypeError(`${options.driverLabel} sends PNG, JPEG, GIF or WebP images only, received a file of ${mediaType}`);
|
|
67
|
+
}
|
|
68
|
+
if (options.resolveFile === undefined) {
|
|
69
|
+
throw new TypeError("An image needs resolveFile to read its bytes");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const resolved = [];
|
|
73
|
+
for (let index = 0;index < parts.length; index += 1) {
|
|
74
|
+
const part = parts[index];
|
|
75
|
+
if (part === undefined)
|
|
76
|
+
continue;
|
|
77
|
+
if (extras.has(index)) {
|
|
78
|
+
const extra = extras.get(index);
|
|
79
|
+
if (extra !== undefined)
|
|
80
|
+
resolved.push(extra);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (part.type === "text" && "text" in part && typeof part.text === "string") {
|
|
84
|
+
resolved.push({ type: "text", text: part.text });
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (part.type !== "file" || !("reference" in part) || typeof part.reference !== "string" || !("mediaType" in part) || typeof part.mediaType !== "string" || options.resolveFile === undefined) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const read = resolveImageBytes(part.reference, {
|
|
91
|
+
resolveFile: options.resolveFile,
|
|
92
|
+
maxImageBytes
|
|
93
|
+
});
|
|
94
|
+
const bytes = options.signal ? await raceAbort(read, options.signal) : await read;
|
|
95
|
+
resolved.push({
|
|
96
|
+
type: "image",
|
|
97
|
+
mediaType: part.mediaType,
|
|
98
|
+
base64: bytesToBase64(bytes)
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return resolved;
|
|
102
|
+
}
|
|
103
|
+
function inlineParts(parts, options) {
|
|
104
|
+
return inlineOrderedParts(parts, options);
|
|
105
|
+
}
|
|
106
|
+
function assertImageFrameBytes(serialized, maxBytes) {
|
|
107
|
+
const byteLength = Buffer.byteLength(serialized);
|
|
108
|
+
if (byteLength > maxBytes) {
|
|
109
|
+
throw new RangeError(`Turn input frame is ${byteLength} bytes, over the ${maxBytes}-byte frame limit`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function guardedTurnStarter(options) {
|
|
113
|
+
let preparing = false;
|
|
114
|
+
return async (input) => {
|
|
115
|
+
if (preparing)
|
|
116
|
+
throw new Error(options.busyMessage);
|
|
117
|
+
options.check(input);
|
|
118
|
+
preparing = true;
|
|
119
|
+
let parts;
|
|
120
|
+
try {
|
|
121
|
+
parts = await options.inline(input);
|
|
122
|
+
} finally {
|
|
123
|
+
preparing = false;
|
|
124
|
+
}
|
|
125
|
+
options.check(input);
|
|
126
|
+
return await options.dispatch(input, parts);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function imageTurnStarter(options) {
|
|
130
|
+
return guardedTurnStarter({
|
|
131
|
+
busyMessage: options.busyMessage,
|
|
132
|
+
check: options.check,
|
|
133
|
+
inline: (input) => inlineParts(input.input, {
|
|
134
|
+
...options.imageOptions,
|
|
135
|
+
driverLabel: options.driverLabel,
|
|
136
|
+
signal: options.signal
|
|
137
|
+
}),
|
|
138
|
+
dispatch: options.dispatch
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { DEFAULT_MAX_IMAGE_BYTES, CLAUDE_CLI_MAX_LINE_BYTES, isSupportedImageMediaType, validateImageOptions, bytesToBase64, resolveImageBytes, inlineOrderedParts, assertImageFrameBytes, guardedTurnStarter, imageTurnStarter };
|