@mastra/server 0.0.0-remove-cloud-span-transform-20250425214156 → 0.0.0-remove-unused-import-20250909212718
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 +3541 -0
- package/LICENSE.md +11 -42
- package/README.md +48 -135
- package/dist/chunk-3THIIWWW.cjs +484 -0
- package/dist/chunk-3THIIWWW.cjs.map +1 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
- package/dist/chunk-4QCXUEAT.js.map +1 -0
- package/dist/chunk-4RRMWXQ2.js +3522 -0
- package/dist/chunk-4RRMWXQ2.js.map +1 -0
- package/dist/chunk-5DP5XZH6.cjs +928 -0
- package/dist/chunk-5DP5XZH6.cjs.map +1 -0
- package/dist/chunk-5QUKZCEF.js +476 -0
- package/dist/chunk-5QUKZCEF.js.map +1 -0
- package/dist/chunk-66YYHFGF.js +761 -0
- package/dist/chunk-66YYHFGF.js.map +1 -0
- package/dist/chunk-6GMFZ5LK.js +2774 -0
- package/dist/chunk-6GMFZ5LK.js.map +1 -0
- package/dist/chunk-6LUKYSWE.cjs +610 -0
- package/dist/chunk-6LUKYSWE.cjs.map +1 -0
- package/dist/chunk-743UIDHI.cjs +2013 -0
- package/dist/chunk-743UIDHI.cjs.map +1 -0
- package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
- package/dist/chunk-7NADHFD2.cjs.map +1 -0
- package/dist/chunk-7QEJ5QG5.js +151 -0
- package/dist/chunk-7QEJ5QG5.js.map +1 -0
- package/dist/chunk-A3AL7EWJ.js +83 -0
- package/dist/chunk-A3AL7EWJ.js.map +1 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-A75S4TDD.js} +36 -10
- package/dist/chunk-A75S4TDD.js.map +1 -0
- package/dist/chunk-AK2FXLLB.cjs +849 -0
- package/dist/chunk-AK2FXLLB.cjs.map +1 -0
- package/dist/chunk-B2V3PUB7.js +591 -0
- package/dist/chunk-B2V3PUB7.js.map +1 -0
- package/dist/chunk-CY4TP3FK.js +16 -0
- package/dist/chunk-CY4TP3FK.js.map +1 -0
- package/dist/chunk-EMMSS5I5.cjs +37 -0
- package/dist/chunk-EMMSS5I5.cjs.map +1 -0
- package/dist/chunk-EMNGA4R4.js +845 -0
- package/dist/chunk-EMNGA4R4.js.map +1 -0
- package/dist/chunk-FALVL2VV.cjs +3525 -0
- package/dist/chunk-FALVL2VV.cjs.map +1 -0
- package/dist/chunk-FQNT7PI4.js +937 -0
- package/dist/chunk-FQNT7PI4.js.map +1 -0
- package/dist/chunk-G3PMV62Z.js +33 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/chunk-G4PUALCE.cjs +28 -0
- package/dist/chunk-G4PUALCE.cjs.map +1 -0
- package/dist/chunk-GU4EWMZB.cjs +769 -0
- package/dist/chunk-GU4EWMZB.cjs.map +1 -0
- package/dist/chunk-GUI3CROV.cjs +159 -0
- package/dist/chunk-GUI3CROV.cjs.map +1 -0
- package/dist/chunk-HJQKWRKQ.cjs +764 -0
- package/dist/chunk-HJQKWRKQ.cjs.map +1 -0
- package/dist/chunk-HVBBFCDH.cjs +2321 -0
- package/dist/chunk-HVBBFCDH.cjs.map +1 -0
- package/dist/chunk-HZJRQ5L3.cjs +1411 -0
- package/dist/chunk-HZJRQ5L3.cjs.map +1 -0
- package/dist/chunk-IGFMAZZ5.cjs +1150 -0
- package/dist/chunk-IGFMAZZ5.cjs.map +1 -0
- package/dist/chunk-IOQGI4ML.js +931 -0
- package/dist/chunk-IOQGI4ML.js.map +1 -0
- package/dist/chunk-IY34NOLA.cjs +150 -0
- package/dist/chunk-IY34NOLA.cjs.map +1 -0
- package/dist/chunk-J7BPKKOG.cjs +163 -0
- package/dist/chunk-J7BPKKOG.cjs.map +1 -0
- package/dist/chunk-KNGXRN26.cjs +335 -0
- package/dist/chunk-KNGXRN26.cjs.map +1 -0
- package/dist/{chunk-WTHDCRMY.js → chunk-KV6VHX4V.js} +33 -8
- package/dist/chunk-KV6VHX4V.js.map +1 -0
- package/dist/chunk-L265APUD.cjs +69 -0
- package/dist/chunk-L265APUD.cjs.map +1 -0
- package/dist/chunk-LF2ZLOFP.js +767 -0
- package/dist/chunk-LF2ZLOFP.js.map +1 -0
- package/dist/chunk-LYPU75T6.js +1147 -0
- package/dist/chunk-LYPU75T6.js.map +1 -0
- package/dist/chunk-M2YFWHSB.js +455 -0
- package/dist/chunk-M2YFWHSB.js.map +1 -0
- package/dist/chunk-MLGHQDZZ.js +15671 -0
- package/dist/chunk-MLGHQDZZ.js.map +1 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
- package/dist/chunk-MMROOK5J.js.map +1 -0
- package/dist/chunk-N7F33WAD.js +2290 -0
- package/dist/chunk-N7F33WAD.js.map +1 -0
- package/dist/chunk-NG5IVLEZ.js +1012 -0
- package/dist/chunk-NG5IVLEZ.js.map +1 -0
- package/dist/chunk-OGW6HHVI.js +1408 -0
- package/dist/chunk-OGW6HHVI.js.map +1 -0
- package/dist/chunk-OZLRIVC4.cjs +588 -0
- package/dist/chunk-OZLRIVC4.cjs.map +1 -0
- package/dist/chunk-P7CIEIJ3.js +925 -0
- package/dist/chunk-P7CIEIJ3.js.map +1 -0
- package/dist/chunk-P7RBMCBE.cjs +934 -0
- package/dist/chunk-P7RBMCBE.cjs.map +1 -0
- package/dist/chunk-PPYGWINI.cjs +2777 -0
- package/dist/chunk-PPYGWINI.cjs.map +1 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-PWTXZZTR.cjs} +37 -11
- package/dist/chunk-PWTXZZTR.cjs.map +1 -0
- package/dist/chunk-R7NOGUZG.js +65 -0
- package/dist/chunk-R7NOGUZG.js.map +1 -0
- package/dist/chunk-RCHEPTZZ.js +2006 -0
- package/dist/chunk-RCHEPTZZ.js.map +1 -0
- package/dist/chunk-RE4RPXT2.cjs +18 -0
- package/dist/chunk-RE4RPXT2.cjs.map +1 -0
- package/dist/chunk-RW2D3G4K.cjs +470 -0
- package/dist/chunk-RW2D3G4K.cjs.map +1 -0
- package/dist/chunk-SIGXR3JT.cjs +1043 -0
- package/dist/chunk-SIGXR3JT.cjs.map +1 -0
- package/dist/chunk-SPLSYTYW.cjs +88 -0
- package/dist/chunk-SPLSYTYW.cjs.map +1 -0
- package/dist/chunk-SQY4T6EJ.js +571 -0
- package/dist/chunk-SQY4T6EJ.js.map +1 -0
- package/dist/{chunk-5JNVY6DU.js → chunk-SYRRSBGL.js} +48 -12
- package/dist/chunk-SYRRSBGL.js.map +1 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-T3TIA3O6.cjs} +22 -19
- package/dist/chunk-T3TIA3O6.cjs.map +1 -0
- package/dist/{chunk-LFOBHRFO.js → chunk-TTHEEIZ3.js} +83 -65
- package/dist/chunk-TTHEEIZ3.js.map +1 -0
- package/dist/chunk-TVSIG4JE.cjs +940 -0
- package/dist/chunk-TVSIG4JE.cjs.map +1 -0
- package/dist/{chunk-RE6YL32K.js → chunk-U46VIX2V.js} +54 -30
- package/dist/chunk-U46VIX2V.js.map +1 -0
- package/dist/{chunk-4JINXASC.js → chunk-WHN4VX55.js} +7 -4
- package/dist/chunk-WHN4VX55.js.map +1 -0
- package/dist/chunk-WZC6CIVD.cjs +120 -0
- package/dist/chunk-WZC6CIVD.cjs.map +1 -0
- package/dist/chunk-YITREQVN.cjs +15707 -0
- package/dist/chunk-YITREQVN.cjs.map +1 -0
- package/dist/dist-26HWEQY6.js +3 -0
- package/dist/dist-26HWEQY6.js.map +1 -0
- package/dist/dist-3A5DXB37.cjs +20 -0
- package/dist/dist-3A5DXB37.cjs.map +1 -0
- package/dist/dist-3SJKQJGY.cjs +16 -0
- package/dist/dist-3SJKQJGY.cjs.map +1 -0
- package/dist/dist-4ZQSPE5K.js +3 -0
- package/dist/dist-4ZQSPE5K.js.map +1 -0
- package/dist/dist-5W5QNRTD.js +3 -0
- package/dist/dist-5W5QNRTD.js.map +1 -0
- package/dist/dist-653SRMPL.js +3 -0
- package/dist/dist-653SRMPL.js.map +1 -0
- package/dist/dist-6U6EFC5C.cjs +16 -0
- package/dist/dist-6U6EFC5C.cjs.map +1 -0
- package/dist/dist-7IHNNYMF.cjs +16 -0
- package/dist/dist-7IHNNYMF.cjs.map +1 -0
- package/dist/dist-B5IPRF6W.js +3 -0
- package/dist/dist-B5IPRF6W.js.map +1 -0
- package/dist/dist-EOMYFT4Y.cjs +16 -0
- package/dist/dist-EOMYFT4Y.cjs.map +1 -0
- package/dist/dist-EZZMMMNT.cjs +16 -0
- package/dist/dist-EZZMMMNT.cjs.map +1 -0
- package/dist/dist-F2ET4MNO.cjs +16 -0
- package/dist/dist-F2ET4MNO.cjs.map +1 -0
- package/dist/dist-H64VX6DE.js +3 -0
- package/dist/dist-H64VX6DE.js.map +1 -0
- package/dist/dist-HY7RMLJQ.cjs +16 -0
- package/dist/dist-HY7RMLJQ.cjs.map +1 -0
- package/dist/dist-M6S4P3FJ.js +3 -0
- package/dist/dist-M6S4P3FJ.js.map +1 -0
- package/dist/dist-NR7QSCQT.js +3 -0
- package/dist/dist-NR7QSCQT.js.map +1 -0
- package/dist/dist-QLFMCMCX.js +3 -0
- package/dist/dist-QLFMCMCX.js.map +1 -0
- package/dist/dist-UY46BFRP.js +3 -0
- package/dist/dist-UY46BFRP.js.map +1 -0
- package/dist/dist-WCQDRTIV.cjs +16 -0
- package/dist/dist-WCQDRTIV.cjs.map +1 -0
- package/dist/dist-WKYB3LTJ.cjs +16 -0
- package/dist/dist-WKYB3LTJ.cjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/server/a2a/protocol.d.ts +8 -0
- package/dist/server/a2a/protocol.d.ts.map +1 -0
- package/dist/server/a2a/store.cjs +25 -0
- package/dist/server/a2a/store.cjs.map +1 -0
- package/dist/server/a2a/store.d.ts +14 -0
- package/dist/server/a2a/store.d.ts.map +1 -0
- package/dist/server/a2a/store.js +23 -0
- package/dist/server/a2a/store.js.map +1 -0
- package/dist/server/a2a/tasks.d.ts +20 -0
- package/dist/server/a2a/tasks.d.ts.map +1 -0
- package/dist/server/handlers/a2a.cjs +32 -0
- package/dist/server/handlers/a2a.cjs.map +1 -0
- package/dist/server/handlers/a2a.d.ts +68 -0
- package/dist/server/handlers/a2a.d.ts.map +1 -0
- package/dist/server/handlers/a2a.js +3 -0
- package/dist/server/handlers/a2a.js.map +1 -0
- package/dist/server/handlers/agent-builder.cjs +68 -0
- package/dist/server/handlers/agent-builder.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.d.ts +87 -0
- package/dist/server/handlers/agent-builder.d.ts.map +1 -0
- package/dist/server/handlers/agent-builder.js +3 -0
- package/dist/server/handlers/agent-builder.js.map +1 -0
- package/dist/server/handlers/agents.cjs +37 -7
- package/dist/server/handlers/agents.cjs.map +1 -0
- package/dist/server/handlers/agents.d.ts +129 -6
- package/dist/server/handlers/agents.d.ts.map +1 -0
- package/dist/server/handlers/agents.js +3 -1
- package/dist/server/handlers/agents.js.map +1 -0
- package/dist/server/handlers/error.cjs +4 -2
- package/dist/server/handlers/error.cjs.map +1 -0
- package/dist/server/handlers/error.d.ts +2 -1
- package/dist/server/handlers/error.d.ts.map +1 -0
- package/dist/server/handlers/error.js +3 -1
- package/dist/server/handlers/error.js.map +1 -0
- package/dist/server/handlers/legacyWorkflows.cjs +48 -0
- package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +59 -0
- package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
- package/dist/server/handlers/legacyWorkflows.js +3 -0
- package/dist/server/handlers/legacyWorkflows.js.map +1 -0
- package/dist/server/handlers/logs.cjs +6 -4
- package/dist/server/handlers/logs.cjs.map +1 -0
- package/dist/server/handlers/logs.d.ts +34 -3
- package/dist/server/handlers/logs.d.ts.map +1 -0
- package/dist/server/handlers/logs.js +3 -1
- package/dist/server/handlers/logs.js.map +1 -0
- package/dist/server/handlers/memory.cjs +39 -9
- package/dist/server/handlers/memory.cjs.map +1 -0
- package/dist/server/handlers/memory.d.ts +118 -8
- package/dist/server/handlers/memory.d.ts.map +1 -0
- package/dist/server/handlers/memory.js +3 -1
- package/dist/server/handlers/memory.js.map +1 -0
- package/dist/server/handlers/network.cjs +7 -5
- package/dist/server/handlers/network.cjs.map +1 -0
- package/dist/server/handlers/network.d.ts +50 -4
- package/dist/server/handlers/network.d.ts.map +1 -0
- package/dist/server/handlers/network.js +3 -1
- package/dist/server/handlers/network.js.map +1 -0
- package/dist/server/handlers/observability.cjs +16 -0
- package/dist/server/handlers/observability.cjs.map +1 -0
- package/dist/server/handlers/observability.d.ts +23 -0
- package/dist/server/handlers/observability.d.ts.map +1 -0
- package/dist/server/handlers/observability.js +3 -0
- package/dist/server/handlers/observability.js.map +1 -0
- package/dist/server/handlers/scores.cjs +32 -0
- package/dist/server/handlers/scores.cjs.map +1 -0
- package/dist/server/handlers/scores.d.ts +49 -0
- package/dist/server/handlers/scores.d.ts.map +1 -0
- package/dist/server/handlers/scores.js +3 -0
- package/dist/server/handlers/scores.js.map +1 -0
- package/dist/server/handlers/telemetry.cjs +9 -3
- package/dist/server/handlers/telemetry.cjs.map +1 -0
- package/dist/server/handlers/telemetry.d.ts +33 -2
- package/dist/server/handlers/telemetry.d.ts.map +1 -0
- package/dist/server/handlers/telemetry.js +3 -1
- package/dist/server/handlers/telemetry.js.map +1 -0
- package/dist/server/handlers/tools.cjs +11 -5
- package/dist/server/handlers/tools.cjs.map +1 -0
- package/dist/server/handlers/tools.d.ts +25 -4
- package/dist/server/handlers/tools.d.ts.map +1 -0
- package/dist/server/handlers/tools.js +3 -1
- package/dist/server/handlers/tools.js.map +1 -0
- package/dist/server/handlers/utils.cjs +8 -2
- package/dist/server/handlers/utils.cjs.map +1 -0
- package/dist/server/handlers/utils.d.ts +8 -1
- package/dist/server/handlers/utils.d.ts.map +1 -0
- package/dist/server/handlers/utils.js +3 -1
- package/dist/server/handlers/utils.js.map +1 -0
- package/dist/server/handlers/vNextNetwork.cjs +220 -0
- package/dist/server/handlers/vNextNetwork.cjs.map +1 -0
- package/dist/server/handlers/vNextNetwork.d.ts +179 -0
- package/dist/server/handlers/vNextNetwork.d.ts.map +1 -0
- package/dist/server/handlers/vNextNetwork.js +213 -0
- package/dist/server/handlers/vNextNetwork.js.map +1 -0
- package/dist/server/handlers/vector.cjs +9 -7
- package/dist/server/handlers/vector.cjs.map +1 -0
- package/dist/server/handlers/vector.d.ts +51 -6
- package/dist/server/handlers/vector.d.ts.map +1 -0
- package/dist/server/handlers/vector.js +3 -1
- package/dist/server/handlers/vector.js.map +1 -0
- package/dist/server/handlers/voice.cjs +10 -4
- package/dist/server/handlers/voice.cjs.map +1 -0
- package/dist/server/handlers/voice.d.ts +39 -3
- package/dist/server/handlers/voice.d.ts.map +1 -0
- package/dist/server/handlers/voice.js +3 -1
- package/dist/server/handlers/voice.js.map +1 -0
- package/dist/server/handlers/workflows.cjs +35 -13
- package/dist/server/handlers/workflows.cjs.map +1 -0
- package/dist/server/handlers/workflows.d.ts +73 -10
- package/dist/server/handlers/workflows.d.ts.map +1 -0
- package/dist/server/handlers/workflows.js +3 -1
- package/dist/server/handlers/workflows.js.map +1 -0
- package/dist/server/handlers.cjs +52 -30
- package/dist/server/handlers.cjs.map +1 -0
- package/dist/server/handlers.d.ts +15 -10
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +16 -10
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/http-exception.d.ts +87 -0
- package/dist/server/http-exception.d.ts.map +1 -0
- package/dist/server/types.d.ts +10 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/utils.d.ts +42 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/package.json +51 -19
- package/dist/_tsup-dts-rollup.d.cts +0 -648
- package/dist/_tsup-dts-rollup.d.ts +0 -648
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-B66WVPGJ.js +0 -297
- package/dist/chunk-D3G23FP3.cjs +0 -126
- package/dist/chunk-FPIWDH5Y.cjs +0 -126
- package/dist/chunk-HCOPJZ4A.cjs +0 -164
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-QN4KF3BH.cjs +0 -18
- package/dist/chunk-R4J7XQYU.js +0 -156
- package/dist/chunk-RBQASTUP.js +0 -203
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-TZK63M5N.cjs +0 -317
- package/dist/chunk-ZHNKYTNS.cjs +0 -309
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/index.d.cts +0 -1
- package/dist/server/handlers/agents.d.cts +0 -6
- package/dist/server/handlers/error.d.cts +0 -1
- package/dist/server/handlers/logs.d.cts +0 -3
- package/dist/server/handlers/memory.d.cts +0 -8
- package/dist/server/handlers/network.d.cts +0 -4
- package/dist/server/handlers/telemetry.d.cts +0 -2
- package/dist/server/handlers/tools.d.cts +0 -4
- package/dist/server/handlers/utils.d.cts +0 -1
- package/dist/server/handlers/vNextWorkflows.cjs +0 -46
- package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
- package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
- package/dist/server/handlers/vNextWorkflows.js +0 -1
- package/dist/server/handlers/vector.d.cts +0 -6
- package/dist/server/handlers/voice.d.cts +0 -3
- package/dist/server/handlers/workflows.d.cts +0 -10
- package/dist/server/handlers.d.cts +0 -10
|
@@ -0,0 +1,1150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkSIGXR3JT_cjs = require('./chunk-SIGXR3JT.cjs');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
var anthropicErrorDataSchema = zod.z.object({
|
|
7
|
+
type: zod.z.literal("error"),
|
|
8
|
+
error: zod.z.object({
|
|
9
|
+
type: zod.z.string(),
|
|
10
|
+
message: zod.z.string()
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
var anthropicFailedResponseHandler = chunkSIGXR3JT_cjs.createJsonErrorResponseHandler({
|
|
14
|
+
errorSchema: anthropicErrorDataSchema,
|
|
15
|
+
errorToMessage: (data) => data.error.message
|
|
16
|
+
});
|
|
17
|
+
function prepareTools(mode) {
|
|
18
|
+
var _a;
|
|
19
|
+
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
20
|
+
const toolWarnings = [];
|
|
21
|
+
const betas = /* @__PURE__ */ new Set();
|
|
22
|
+
if (tools == null) {
|
|
23
|
+
return { tools: void 0, tool_choice: void 0, toolWarnings, betas };
|
|
24
|
+
}
|
|
25
|
+
const anthropicTools2 = [];
|
|
26
|
+
for (const tool of tools) {
|
|
27
|
+
switch (tool.type) {
|
|
28
|
+
case "function":
|
|
29
|
+
anthropicTools2.push({
|
|
30
|
+
name: tool.name,
|
|
31
|
+
description: tool.description,
|
|
32
|
+
input_schema: tool.parameters
|
|
33
|
+
});
|
|
34
|
+
break;
|
|
35
|
+
case "provider-defined":
|
|
36
|
+
switch (tool.id) {
|
|
37
|
+
case "anthropic.computer_20250124":
|
|
38
|
+
betas.add("computer-use-2025-01-24");
|
|
39
|
+
anthropicTools2.push({
|
|
40
|
+
name: tool.name,
|
|
41
|
+
type: "computer_20250124",
|
|
42
|
+
display_width_px: tool.args.displayWidthPx,
|
|
43
|
+
display_height_px: tool.args.displayHeightPx,
|
|
44
|
+
display_number: tool.args.displayNumber
|
|
45
|
+
});
|
|
46
|
+
break;
|
|
47
|
+
case "anthropic.computer_20241022":
|
|
48
|
+
betas.add("computer-use-2024-10-22");
|
|
49
|
+
anthropicTools2.push({
|
|
50
|
+
name: tool.name,
|
|
51
|
+
type: "computer_20241022",
|
|
52
|
+
display_width_px: tool.args.displayWidthPx,
|
|
53
|
+
display_height_px: tool.args.displayHeightPx,
|
|
54
|
+
display_number: tool.args.displayNumber
|
|
55
|
+
});
|
|
56
|
+
break;
|
|
57
|
+
case "anthropic.text_editor_20250124":
|
|
58
|
+
betas.add("computer-use-2025-01-24");
|
|
59
|
+
anthropicTools2.push({
|
|
60
|
+
name: tool.name,
|
|
61
|
+
type: "text_editor_20250124"
|
|
62
|
+
});
|
|
63
|
+
break;
|
|
64
|
+
case "anthropic.text_editor_20241022":
|
|
65
|
+
betas.add("computer-use-2024-10-22");
|
|
66
|
+
anthropicTools2.push({
|
|
67
|
+
name: tool.name,
|
|
68
|
+
type: "text_editor_20241022"
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
case "anthropic.bash_20250124":
|
|
72
|
+
betas.add("computer-use-2025-01-24");
|
|
73
|
+
anthropicTools2.push({
|
|
74
|
+
name: tool.name,
|
|
75
|
+
type: "bash_20250124"
|
|
76
|
+
});
|
|
77
|
+
break;
|
|
78
|
+
case "anthropic.bash_20241022":
|
|
79
|
+
betas.add("computer-use-2024-10-22");
|
|
80
|
+
anthropicTools2.push({
|
|
81
|
+
name: tool.name,
|
|
82
|
+
type: "bash_20241022"
|
|
83
|
+
});
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const toolChoice = mode.toolChoice;
|
|
96
|
+
if (toolChoice == null) {
|
|
97
|
+
return {
|
|
98
|
+
tools: anthropicTools2,
|
|
99
|
+
tool_choice: void 0,
|
|
100
|
+
toolWarnings,
|
|
101
|
+
betas
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const type = toolChoice.type;
|
|
105
|
+
switch (type) {
|
|
106
|
+
case "auto":
|
|
107
|
+
return {
|
|
108
|
+
tools: anthropicTools2,
|
|
109
|
+
tool_choice: { type: "auto" },
|
|
110
|
+
toolWarnings,
|
|
111
|
+
betas
|
|
112
|
+
};
|
|
113
|
+
case "required":
|
|
114
|
+
return {
|
|
115
|
+
tools: anthropicTools2,
|
|
116
|
+
tool_choice: { type: "any" },
|
|
117
|
+
toolWarnings,
|
|
118
|
+
betas
|
|
119
|
+
};
|
|
120
|
+
case "none":
|
|
121
|
+
return { tools: void 0, tool_choice: void 0, toolWarnings, betas };
|
|
122
|
+
case "tool":
|
|
123
|
+
return {
|
|
124
|
+
tools: anthropicTools2,
|
|
125
|
+
tool_choice: { type: "tool", name: toolChoice.toolName },
|
|
126
|
+
toolWarnings,
|
|
127
|
+
betas
|
|
128
|
+
};
|
|
129
|
+
default: {
|
|
130
|
+
const _exhaustiveCheck = type;
|
|
131
|
+
throw new chunkSIGXR3JT_cjs.UnsupportedFunctionalityError({
|
|
132
|
+
functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function convertToAnthropicMessagesPrompt({
|
|
138
|
+
prompt,
|
|
139
|
+
sendReasoning,
|
|
140
|
+
warnings
|
|
141
|
+
}) {
|
|
142
|
+
var _a, _b, _c, _d;
|
|
143
|
+
const betas = /* @__PURE__ */ new Set();
|
|
144
|
+
const blocks = groupIntoBlocks(prompt);
|
|
145
|
+
let system = void 0;
|
|
146
|
+
const messages = [];
|
|
147
|
+
function getCacheControl(providerMetadata) {
|
|
148
|
+
var _a2;
|
|
149
|
+
const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
150
|
+
const cacheControlValue = (_a2 = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a2 : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
151
|
+
return cacheControlValue;
|
|
152
|
+
}
|
|
153
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
154
|
+
const block = blocks[i];
|
|
155
|
+
const isLastBlock = i === blocks.length - 1;
|
|
156
|
+
const type = block.type;
|
|
157
|
+
switch (type) {
|
|
158
|
+
case "system": {
|
|
159
|
+
if (system != null) {
|
|
160
|
+
throw new chunkSIGXR3JT_cjs.UnsupportedFunctionalityError({
|
|
161
|
+
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
system = block.messages.map(({ content, providerMetadata }) => ({
|
|
165
|
+
type: "text",
|
|
166
|
+
text: content,
|
|
167
|
+
cache_control: getCacheControl(providerMetadata)
|
|
168
|
+
}));
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case "user": {
|
|
172
|
+
const anthropicContent = [];
|
|
173
|
+
for (const message of block.messages) {
|
|
174
|
+
const { role, content } = message;
|
|
175
|
+
switch (role) {
|
|
176
|
+
case "user": {
|
|
177
|
+
for (let j = 0; j < content.length; j++) {
|
|
178
|
+
const part = content[j];
|
|
179
|
+
const isLastPart = j === content.length - 1;
|
|
180
|
+
const cacheControl = (_a = getCacheControl(part.providerMetadata)) != null ? _a : isLastPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
181
|
+
switch (part.type) {
|
|
182
|
+
case "text": {
|
|
183
|
+
anthropicContent.push({
|
|
184
|
+
type: "text",
|
|
185
|
+
text: part.text,
|
|
186
|
+
cache_control: cacheControl
|
|
187
|
+
});
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case "image": {
|
|
191
|
+
anthropicContent.push({
|
|
192
|
+
type: "image",
|
|
193
|
+
source: part.image instanceof URL ? {
|
|
194
|
+
type: "url",
|
|
195
|
+
url: part.image.toString()
|
|
196
|
+
} : {
|
|
197
|
+
type: "base64",
|
|
198
|
+
media_type: (_b = part.mimeType) != null ? _b : "image/jpeg",
|
|
199
|
+
data: chunkSIGXR3JT_cjs.convertUint8ArrayToBase64(part.image)
|
|
200
|
+
},
|
|
201
|
+
cache_control: cacheControl
|
|
202
|
+
});
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case "file": {
|
|
206
|
+
if (part.mimeType !== "application/pdf") {
|
|
207
|
+
throw new chunkSIGXR3JT_cjs.UnsupportedFunctionalityError({
|
|
208
|
+
functionality: "Non-PDF files in user messages"
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
betas.add("pdfs-2024-09-25");
|
|
212
|
+
anthropicContent.push({
|
|
213
|
+
type: "document",
|
|
214
|
+
source: part.data instanceof URL ? {
|
|
215
|
+
type: "url",
|
|
216
|
+
url: part.data.toString()
|
|
217
|
+
} : {
|
|
218
|
+
type: "base64",
|
|
219
|
+
media_type: "application/pdf",
|
|
220
|
+
data: part.data
|
|
221
|
+
},
|
|
222
|
+
cache_control: cacheControl
|
|
223
|
+
});
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case "tool": {
|
|
231
|
+
for (let i2 = 0; i2 < content.length; i2++) {
|
|
232
|
+
const part = content[i2];
|
|
233
|
+
const isLastPart = i2 === content.length - 1;
|
|
234
|
+
const cacheControl = (_c = getCacheControl(part.providerMetadata)) != null ? _c : isLastPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
235
|
+
const toolResultContent = part.content != null ? part.content.map((part2) => {
|
|
236
|
+
var _a2;
|
|
237
|
+
switch (part2.type) {
|
|
238
|
+
case "text":
|
|
239
|
+
return {
|
|
240
|
+
type: "text",
|
|
241
|
+
text: part2.text,
|
|
242
|
+
cache_control: void 0
|
|
243
|
+
};
|
|
244
|
+
case "image":
|
|
245
|
+
return {
|
|
246
|
+
type: "image",
|
|
247
|
+
source: {
|
|
248
|
+
type: "base64",
|
|
249
|
+
media_type: (_a2 = part2.mimeType) != null ? _a2 : "image/jpeg",
|
|
250
|
+
data: part2.data
|
|
251
|
+
},
|
|
252
|
+
cache_control: void 0
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}) : JSON.stringify(part.result);
|
|
256
|
+
anthropicContent.push({
|
|
257
|
+
type: "tool_result",
|
|
258
|
+
tool_use_id: part.toolCallId,
|
|
259
|
+
content: toolResultContent,
|
|
260
|
+
is_error: part.isError,
|
|
261
|
+
cache_control: cacheControl
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
default: {
|
|
267
|
+
const _exhaustiveCheck = role;
|
|
268
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
messages.push({ role: "user", content: anthropicContent });
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
case "assistant": {
|
|
276
|
+
const anthropicContent = [];
|
|
277
|
+
for (let j = 0; j < block.messages.length; j++) {
|
|
278
|
+
const message = block.messages[j];
|
|
279
|
+
const isLastMessage = j === block.messages.length - 1;
|
|
280
|
+
const { content } = message;
|
|
281
|
+
for (let k = 0; k < content.length; k++) {
|
|
282
|
+
const part = content[k];
|
|
283
|
+
const isLastContentPart = k === content.length - 1;
|
|
284
|
+
const cacheControl = (_d = getCacheControl(part.providerMetadata)) != null ? _d : isLastContentPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
285
|
+
switch (part.type) {
|
|
286
|
+
case "text": {
|
|
287
|
+
anthropicContent.push({
|
|
288
|
+
type: "text",
|
|
289
|
+
text: (
|
|
290
|
+
// trim the last text part if it's the last message in the block
|
|
291
|
+
// because Anthropic does not allow trailing whitespace
|
|
292
|
+
// in pre-filled assistant responses
|
|
293
|
+
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
294
|
+
),
|
|
295
|
+
cache_control: cacheControl
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
case "reasoning": {
|
|
300
|
+
if (sendReasoning) {
|
|
301
|
+
anthropicContent.push({
|
|
302
|
+
type: "thinking",
|
|
303
|
+
thinking: part.text,
|
|
304
|
+
signature: part.signature,
|
|
305
|
+
cache_control: cacheControl
|
|
306
|
+
});
|
|
307
|
+
} else {
|
|
308
|
+
warnings.push({
|
|
309
|
+
type: "other",
|
|
310
|
+
message: "sending reasoning content is disabled for this model"
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
case "redacted-reasoning": {
|
|
316
|
+
anthropicContent.push({
|
|
317
|
+
type: "redacted_thinking",
|
|
318
|
+
data: part.data,
|
|
319
|
+
cache_control: cacheControl
|
|
320
|
+
});
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
case "tool-call": {
|
|
324
|
+
anthropicContent.push({
|
|
325
|
+
type: "tool_use",
|
|
326
|
+
id: part.toolCallId,
|
|
327
|
+
name: part.toolName,
|
|
328
|
+
input: part.args,
|
|
329
|
+
cache_control: cacheControl
|
|
330
|
+
});
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
messages.push({ role: "assistant", content: anthropicContent });
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
default: {
|
|
340
|
+
const _exhaustiveCheck = type;
|
|
341
|
+
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
prompt: { system, messages },
|
|
347
|
+
betas
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function groupIntoBlocks(prompt) {
|
|
351
|
+
const blocks = [];
|
|
352
|
+
let currentBlock = void 0;
|
|
353
|
+
for (const message of prompt) {
|
|
354
|
+
const { role } = message;
|
|
355
|
+
switch (role) {
|
|
356
|
+
case "system": {
|
|
357
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "system") {
|
|
358
|
+
currentBlock = { type: "system", messages: [] };
|
|
359
|
+
blocks.push(currentBlock);
|
|
360
|
+
}
|
|
361
|
+
currentBlock.messages.push(message);
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
case "assistant": {
|
|
365
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "assistant") {
|
|
366
|
+
currentBlock = { type: "assistant", messages: [] };
|
|
367
|
+
blocks.push(currentBlock);
|
|
368
|
+
}
|
|
369
|
+
currentBlock.messages.push(message);
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
case "user": {
|
|
373
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
|
|
374
|
+
currentBlock = { type: "user", messages: [] };
|
|
375
|
+
blocks.push(currentBlock);
|
|
376
|
+
}
|
|
377
|
+
currentBlock.messages.push(message);
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case "tool": {
|
|
381
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
|
|
382
|
+
currentBlock = { type: "user", messages: [] };
|
|
383
|
+
blocks.push(currentBlock);
|
|
384
|
+
}
|
|
385
|
+
currentBlock.messages.push(message);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
default: {
|
|
389
|
+
const _exhaustiveCheck = role;
|
|
390
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return blocks;
|
|
395
|
+
}
|
|
396
|
+
function mapAnthropicStopReason(finishReason) {
|
|
397
|
+
switch (finishReason) {
|
|
398
|
+
case "end_turn":
|
|
399
|
+
case "stop_sequence":
|
|
400
|
+
return "stop";
|
|
401
|
+
case "tool_use":
|
|
402
|
+
return "tool-calls";
|
|
403
|
+
case "max_tokens":
|
|
404
|
+
return "length";
|
|
405
|
+
default:
|
|
406
|
+
return "unknown";
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
var AnthropicMessagesLanguageModel = class {
|
|
410
|
+
constructor(modelId, settings, config) {
|
|
411
|
+
this.specificationVersion = "v1";
|
|
412
|
+
this.defaultObjectGenerationMode = "tool";
|
|
413
|
+
this.modelId = modelId;
|
|
414
|
+
this.settings = settings;
|
|
415
|
+
this.config = config;
|
|
416
|
+
}
|
|
417
|
+
supportsUrl(url) {
|
|
418
|
+
return url.protocol === "https:";
|
|
419
|
+
}
|
|
420
|
+
get provider() {
|
|
421
|
+
return this.config.provider;
|
|
422
|
+
}
|
|
423
|
+
get supportsImageUrls() {
|
|
424
|
+
return this.config.supportsImageUrls;
|
|
425
|
+
}
|
|
426
|
+
async getArgs({
|
|
427
|
+
mode,
|
|
428
|
+
prompt,
|
|
429
|
+
maxTokens = 4096,
|
|
430
|
+
// 4096: max model output tokens TODO update default in v5
|
|
431
|
+
temperature,
|
|
432
|
+
topP,
|
|
433
|
+
topK,
|
|
434
|
+
frequencyPenalty,
|
|
435
|
+
presencePenalty,
|
|
436
|
+
stopSequences,
|
|
437
|
+
responseFormat,
|
|
438
|
+
seed,
|
|
439
|
+
providerMetadata: providerOptions
|
|
440
|
+
}) {
|
|
441
|
+
var _a, _b, _c;
|
|
442
|
+
const type = mode.type;
|
|
443
|
+
const warnings = [];
|
|
444
|
+
if (frequencyPenalty != null) {
|
|
445
|
+
warnings.push({
|
|
446
|
+
type: "unsupported-setting",
|
|
447
|
+
setting: "frequencyPenalty"
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
if (presencePenalty != null) {
|
|
451
|
+
warnings.push({
|
|
452
|
+
type: "unsupported-setting",
|
|
453
|
+
setting: "presencePenalty"
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
if (seed != null) {
|
|
457
|
+
warnings.push({
|
|
458
|
+
type: "unsupported-setting",
|
|
459
|
+
setting: "seed"
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
if (responseFormat != null && responseFormat.type !== "text") {
|
|
463
|
+
warnings.push({
|
|
464
|
+
type: "unsupported-setting",
|
|
465
|
+
setting: "responseFormat",
|
|
466
|
+
details: "JSON response format is not supported."
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
const { prompt: messagesPrompt, betas: messagesBetas } = convertToAnthropicMessagesPrompt({
|
|
470
|
+
prompt,
|
|
471
|
+
sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
|
|
472
|
+
warnings
|
|
473
|
+
});
|
|
474
|
+
const anthropicOptions = chunkSIGXR3JT_cjs.parseProviderOptions({
|
|
475
|
+
provider: "anthropic",
|
|
476
|
+
providerOptions,
|
|
477
|
+
schema: anthropicProviderOptionsSchema
|
|
478
|
+
});
|
|
479
|
+
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
480
|
+
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
481
|
+
const baseArgs = {
|
|
482
|
+
// model id:
|
|
483
|
+
model: this.modelId,
|
|
484
|
+
// standardized settings:
|
|
485
|
+
max_tokens: maxTokens,
|
|
486
|
+
temperature,
|
|
487
|
+
top_k: topK,
|
|
488
|
+
top_p: topP,
|
|
489
|
+
stop_sequences: stopSequences,
|
|
490
|
+
// provider specific settings:
|
|
491
|
+
...isThinking && {
|
|
492
|
+
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
493
|
+
},
|
|
494
|
+
// prompt:
|
|
495
|
+
system: messagesPrompt.system,
|
|
496
|
+
messages: messagesPrompt.messages
|
|
497
|
+
};
|
|
498
|
+
if (isThinking) {
|
|
499
|
+
if (thinkingBudget == null) {
|
|
500
|
+
throw new chunkSIGXR3JT_cjs.UnsupportedFunctionalityError({
|
|
501
|
+
functionality: "thinking requires a budget"
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
if (baseArgs.temperature != null) {
|
|
505
|
+
baseArgs.temperature = void 0;
|
|
506
|
+
warnings.push({
|
|
507
|
+
type: "unsupported-setting",
|
|
508
|
+
setting: "temperature",
|
|
509
|
+
details: "temperature is not supported when thinking is enabled"
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
if (topK != null) {
|
|
513
|
+
baseArgs.top_k = void 0;
|
|
514
|
+
warnings.push({
|
|
515
|
+
type: "unsupported-setting",
|
|
516
|
+
setting: "topK",
|
|
517
|
+
details: "topK is not supported when thinking is enabled"
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
if (topP != null) {
|
|
521
|
+
baseArgs.top_p = void 0;
|
|
522
|
+
warnings.push({
|
|
523
|
+
type: "unsupported-setting",
|
|
524
|
+
setting: "topP",
|
|
525
|
+
details: "topP is not supported when thinking is enabled"
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
529
|
+
}
|
|
530
|
+
switch (type) {
|
|
531
|
+
case "regular": {
|
|
532
|
+
const {
|
|
533
|
+
tools,
|
|
534
|
+
tool_choice,
|
|
535
|
+
toolWarnings,
|
|
536
|
+
betas: toolsBetas
|
|
537
|
+
} = prepareTools(mode);
|
|
538
|
+
return {
|
|
539
|
+
args: { ...baseArgs, tools, tool_choice },
|
|
540
|
+
warnings: [...warnings, ...toolWarnings],
|
|
541
|
+
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
case "object-json": {
|
|
545
|
+
throw new chunkSIGXR3JT_cjs.UnsupportedFunctionalityError({
|
|
546
|
+
functionality: "json-mode object generation"
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
case "object-tool": {
|
|
550
|
+
const { name, description, parameters } = mode.tool;
|
|
551
|
+
return {
|
|
552
|
+
args: {
|
|
553
|
+
...baseArgs,
|
|
554
|
+
tools: [{ name, description, input_schema: parameters }],
|
|
555
|
+
tool_choice: { type: "tool", name }
|
|
556
|
+
},
|
|
557
|
+
warnings,
|
|
558
|
+
betas: messagesBetas
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
default: {
|
|
562
|
+
const _exhaustiveCheck = type;
|
|
563
|
+
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async getHeaders({
|
|
568
|
+
betas,
|
|
569
|
+
headers
|
|
570
|
+
}) {
|
|
571
|
+
return chunkSIGXR3JT_cjs.combineHeaders(
|
|
572
|
+
await chunkSIGXR3JT_cjs.resolve(this.config.headers),
|
|
573
|
+
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
|
|
574
|
+
headers
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
buildRequestUrl(isStreaming) {
|
|
578
|
+
var _a, _b, _c;
|
|
579
|
+
return (_c = (_b = (_a = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
|
|
580
|
+
}
|
|
581
|
+
transformRequestBody(args) {
|
|
582
|
+
var _a, _b, _c;
|
|
583
|
+
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
584
|
+
}
|
|
585
|
+
async doGenerate(options) {
|
|
586
|
+
var _a, _b, _c, _d;
|
|
587
|
+
const { args, warnings, betas } = await this.getArgs(options);
|
|
588
|
+
const {
|
|
589
|
+
responseHeaders,
|
|
590
|
+
value: response,
|
|
591
|
+
rawValue: rawResponse
|
|
592
|
+
} = await chunkSIGXR3JT_cjs.postJsonToApi({
|
|
593
|
+
url: this.buildRequestUrl(false),
|
|
594
|
+
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
595
|
+
body: this.transformRequestBody(args),
|
|
596
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
597
|
+
successfulResponseHandler: chunkSIGXR3JT_cjs.createJsonResponseHandler(
|
|
598
|
+
anthropicMessagesResponseSchema
|
|
599
|
+
),
|
|
600
|
+
abortSignal: options.abortSignal,
|
|
601
|
+
fetch: this.config.fetch
|
|
602
|
+
});
|
|
603
|
+
const { messages: rawPrompt, ...rawSettings } = args;
|
|
604
|
+
let text = "";
|
|
605
|
+
for (const content of response.content) {
|
|
606
|
+
if (content.type === "text") {
|
|
607
|
+
text += content.text;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
let toolCalls = void 0;
|
|
611
|
+
if (response.content.some((content) => content.type === "tool_use")) {
|
|
612
|
+
toolCalls = [];
|
|
613
|
+
for (const content of response.content) {
|
|
614
|
+
if (content.type === "tool_use") {
|
|
615
|
+
toolCalls.push({
|
|
616
|
+
toolCallType: "function",
|
|
617
|
+
toolCallId: content.id,
|
|
618
|
+
toolName: content.name,
|
|
619
|
+
args: JSON.stringify(content.input)
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const reasoning = response.content.filter(
|
|
625
|
+
(content) => content.type === "redacted_thinking" || content.type === "thinking"
|
|
626
|
+
).map(
|
|
627
|
+
(content) => content.type === "thinking" ? {
|
|
628
|
+
type: "text",
|
|
629
|
+
text: content.thinking,
|
|
630
|
+
signature: content.signature
|
|
631
|
+
} : {
|
|
632
|
+
type: "redacted",
|
|
633
|
+
data: content.data
|
|
634
|
+
}
|
|
635
|
+
);
|
|
636
|
+
return {
|
|
637
|
+
text,
|
|
638
|
+
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
639
|
+
toolCalls,
|
|
640
|
+
finishReason: mapAnthropicStopReason(response.stop_reason),
|
|
641
|
+
usage: {
|
|
642
|
+
promptTokens: response.usage.input_tokens,
|
|
643
|
+
completionTokens: response.usage.output_tokens
|
|
644
|
+
},
|
|
645
|
+
rawCall: { rawPrompt, rawSettings },
|
|
646
|
+
rawResponse: {
|
|
647
|
+
headers: responseHeaders,
|
|
648
|
+
body: rawResponse
|
|
649
|
+
},
|
|
650
|
+
response: {
|
|
651
|
+
id: (_a = response.id) != null ? _a : void 0,
|
|
652
|
+
modelId: (_b = response.model) != null ? _b : void 0
|
|
653
|
+
},
|
|
654
|
+
warnings,
|
|
655
|
+
providerMetadata: {
|
|
656
|
+
anthropic: {
|
|
657
|
+
cacheCreationInputTokens: (_c = response.usage.cache_creation_input_tokens) != null ? _c : null,
|
|
658
|
+
cacheReadInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : null
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
request: { body: JSON.stringify(args) }
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
async doStream(options) {
|
|
665
|
+
const { args, warnings, betas } = await this.getArgs(options);
|
|
666
|
+
const body = { ...args, stream: true };
|
|
667
|
+
const { responseHeaders, value: response } = await chunkSIGXR3JT_cjs.postJsonToApi({
|
|
668
|
+
url: this.buildRequestUrl(true),
|
|
669
|
+
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
670
|
+
body: this.transformRequestBody(body),
|
|
671
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
672
|
+
successfulResponseHandler: chunkSIGXR3JT_cjs.createEventSourceResponseHandler(
|
|
673
|
+
anthropicMessagesChunkSchema
|
|
674
|
+
),
|
|
675
|
+
abortSignal: options.abortSignal,
|
|
676
|
+
fetch: this.config.fetch
|
|
677
|
+
});
|
|
678
|
+
const { messages: rawPrompt, ...rawSettings } = args;
|
|
679
|
+
let finishReason = "unknown";
|
|
680
|
+
const usage = {
|
|
681
|
+
promptTokens: Number.NaN,
|
|
682
|
+
completionTokens: Number.NaN
|
|
683
|
+
};
|
|
684
|
+
const toolCallContentBlocks = {};
|
|
685
|
+
let providerMetadata = void 0;
|
|
686
|
+
let blockType = void 0;
|
|
687
|
+
return {
|
|
688
|
+
stream: response.pipeThrough(
|
|
689
|
+
new TransformStream({
|
|
690
|
+
transform(chunk, controller) {
|
|
691
|
+
var _a, _b, _c, _d;
|
|
692
|
+
if (!chunk.success) {
|
|
693
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const value = chunk.value;
|
|
697
|
+
switch (value.type) {
|
|
698
|
+
case "ping": {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
case "content_block_start": {
|
|
702
|
+
const contentBlockType = value.content_block.type;
|
|
703
|
+
blockType = contentBlockType;
|
|
704
|
+
switch (contentBlockType) {
|
|
705
|
+
case "text":
|
|
706
|
+
case "thinking": {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
case "redacted_thinking": {
|
|
710
|
+
controller.enqueue({
|
|
711
|
+
type: "redacted-reasoning",
|
|
712
|
+
data: value.content_block.data
|
|
713
|
+
});
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
case "tool_use": {
|
|
717
|
+
toolCallContentBlocks[value.index] = {
|
|
718
|
+
toolCallId: value.content_block.id,
|
|
719
|
+
toolName: value.content_block.name,
|
|
720
|
+
jsonText: ""
|
|
721
|
+
};
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
default: {
|
|
725
|
+
const _exhaustiveCheck = contentBlockType;
|
|
726
|
+
throw new Error(
|
|
727
|
+
`Unsupported content block type: ${_exhaustiveCheck}`
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
case "content_block_stop": {
|
|
733
|
+
if (toolCallContentBlocks[value.index] != null) {
|
|
734
|
+
const contentBlock = toolCallContentBlocks[value.index];
|
|
735
|
+
controller.enqueue({
|
|
736
|
+
type: "tool-call",
|
|
737
|
+
toolCallType: "function",
|
|
738
|
+
toolCallId: contentBlock.toolCallId,
|
|
739
|
+
toolName: contentBlock.toolName,
|
|
740
|
+
args: contentBlock.jsonText
|
|
741
|
+
});
|
|
742
|
+
delete toolCallContentBlocks[value.index];
|
|
743
|
+
}
|
|
744
|
+
blockType = void 0;
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
case "content_block_delta": {
|
|
748
|
+
const deltaType = value.delta.type;
|
|
749
|
+
switch (deltaType) {
|
|
750
|
+
case "text_delta": {
|
|
751
|
+
controller.enqueue({
|
|
752
|
+
type: "text-delta",
|
|
753
|
+
textDelta: value.delta.text
|
|
754
|
+
});
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
case "thinking_delta": {
|
|
758
|
+
controller.enqueue({
|
|
759
|
+
type: "reasoning",
|
|
760
|
+
textDelta: value.delta.thinking
|
|
761
|
+
});
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
case "signature_delta": {
|
|
765
|
+
if (blockType === "thinking") {
|
|
766
|
+
controller.enqueue({
|
|
767
|
+
type: "reasoning-signature",
|
|
768
|
+
signature: value.delta.signature
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
case "input_json_delta": {
|
|
774
|
+
const contentBlock = toolCallContentBlocks[value.index];
|
|
775
|
+
controller.enqueue({
|
|
776
|
+
type: "tool-call-delta",
|
|
777
|
+
toolCallType: "function",
|
|
778
|
+
toolCallId: contentBlock.toolCallId,
|
|
779
|
+
toolName: contentBlock.toolName,
|
|
780
|
+
argsTextDelta: value.delta.partial_json
|
|
781
|
+
});
|
|
782
|
+
contentBlock.jsonText += value.delta.partial_json;
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
default: {
|
|
786
|
+
const _exhaustiveCheck = deltaType;
|
|
787
|
+
throw new Error(
|
|
788
|
+
`Unsupported delta type: ${_exhaustiveCheck}`
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
case "message_start": {
|
|
794
|
+
usage.promptTokens = value.message.usage.input_tokens;
|
|
795
|
+
usage.completionTokens = value.message.usage.output_tokens;
|
|
796
|
+
providerMetadata = {
|
|
797
|
+
anthropic: {
|
|
798
|
+
cacheCreationInputTokens: (_a = value.message.usage.cache_creation_input_tokens) != null ? _a : null,
|
|
799
|
+
cacheReadInputTokens: (_b = value.message.usage.cache_read_input_tokens) != null ? _b : null
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
controller.enqueue({
|
|
803
|
+
type: "response-metadata",
|
|
804
|
+
id: (_c = value.message.id) != null ? _c : void 0,
|
|
805
|
+
modelId: (_d = value.message.model) != null ? _d : void 0
|
|
806
|
+
});
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
case "message_delta": {
|
|
810
|
+
usage.completionTokens = value.usage.output_tokens;
|
|
811
|
+
finishReason = mapAnthropicStopReason(value.delta.stop_reason);
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
case "message_stop": {
|
|
815
|
+
controller.enqueue({
|
|
816
|
+
type: "finish",
|
|
817
|
+
finishReason,
|
|
818
|
+
usage,
|
|
819
|
+
providerMetadata
|
|
820
|
+
});
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
case "error": {
|
|
824
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
default: {
|
|
828
|
+
const _exhaustiveCheck = value;
|
|
829
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
})
|
|
834
|
+
),
|
|
835
|
+
rawCall: { rawPrompt, rawSettings },
|
|
836
|
+
rawResponse: { headers: responseHeaders },
|
|
837
|
+
warnings,
|
|
838
|
+
request: { body: JSON.stringify(body) }
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
var anthropicMessagesResponseSchema = zod.z.object({
|
|
843
|
+
type: zod.z.literal("message"),
|
|
844
|
+
id: zod.z.string().nullish(),
|
|
845
|
+
model: zod.z.string().nullish(),
|
|
846
|
+
content: zod.z.array(
|
|
847
|
+
zod.z.discriminatedUnion("type", [
|
|
848
|
+
zod.z.object({
|
|
849
|
+
type: zod.z.literal("text"),
|
|
850
|
+
text: zod.z.string()
|
|
851
|
+
}),
|
|
852
|
+
zod.z.object({
|
|
853
|
+
type: zod.z.literal("thinking"),
|
|
854
|
+
thinking: zod.z.string(),
|
|
855
|
+
signature: zod.z.string()
|
|
856
|
+
}),
|
|
857
|
+
zod.z.object({
|
|
858
|
+
type: zod.z.literal("redacted_thinking"),
|
|
859
|
+
data: zod.z.string()
|
|
860
|
+
}),
|
|
861
|
+
zod.z.object({
|
|
862
|
+
type: zod.z.literal("tool_use"),
|
|
863
|
+
id: zod.z.string(),
|
|
864
|
+
name: zod.z.string(),
|
|
865
|
+
input: zod.z.unknown()
|
|
866
|
+
})
|
|
867
|
+
])
|
|
868
|
+
),
|
|
869
|
+
stop_reason: zod.z.string().nullish(),
|
|
870
|
+
usage: zod.z.object({
|
|
871
|
+
input_tokens: zod.z.number(),
|
|
872
|
+
output_tokens: zod.z.number(),
|
|
873
|
+
cache_creation_input_tokens: zod.z.number().nullish(),
|
|
874
|
+
cache_read_input_tokens: zod.z.number().nullish()
|
|
875
|
+
})
|
|
876
|
+
});
|
|
877
|
+
var anthropicMessagesChunkSchema = zod.z.discriminatedUnion("type", [
|
|
878
|
+
zod.z.object({
|
|
879
|
+
type: zod.z.literal("message_start"),
|
|
880
|
+
message: zod.z.object({
|
|
881
|
+
id: zod.z.string().nullish(),
|
|
882
|
+
model: zod.z.string().nullish(),
|
|
883
|
+
usage: zod.z.object({
|
|
884
|
+
input_tokens: zod.z.number(),
|
|
885
|
+
output_tokens: zod.z.number(),
|
|
886
|
+
cache_creation_input_tokens: zod.z.number().nullish(),
|
|
887
|
+
cache_read_input_tokens: zod.z.number().nullish()
|
|
888
|
+
})
|
|
889
|
+
})
|
|
890
|
+
}),
|
|
891
|
+
zod.z.object({
|
|
892
|
+
type: zod.z.literal("content_block_start"),
|
|
893
|
+
index: zod.z.number(),
|
|
894
|
+
content_block: zod.z.discriminatedUnion("type", [
|
|
895
|
+
zod.z.object({
|
|
896
|
+
type: zod.z.literal("text"),
|
|
897
|
+
text: zod.z.string()
|
|
898
|
+
}),
|
|
899
|
+
zod.z.object({
|
|
900
|
+
type: zod.z.literal("thinking"),
|
|
901
|
+
thinking: zod.z.string()
|
|
902
|
+
}),
|
|
903
|
+
zod.z.object({
|
|
904
|
+
type: zod.z.literal("tool_use"),
|
|
905
|
+
id: zod.z.string(),
|
|
906
|
+
name: zod.z.string()
|
|
907
|
+
}),
|
|
908
|
+
zod.z.object({
|
|
909
|
+
type: zod.z.literal("redacted_thinking"),
|
|
910
|
+
data: zod.z.string()
|
|
911
|
+
})
|
|
912
|
+
])
|
|
913
|
+
}),
|
|
914
|
+
zod.z.object({
|
|
915
|
+
type: zod.z.literal("content_block_delta"),
|
|
916
|
+
index: zod.z.number(),
|
|
917
|
+
delta: zod.z.discriminatedUnion("type", [
|
|
918
|
+
zod.z.object({
|
|
919
|
+
type: zod.z.literal("input_json_delta"),
|
|
920
|
+
partial_json: zod.z.string()
|
|
921
|
+
}),
|
|
922
|
+
zod.z.object({
|
|
923
|
+
type: zod.z.literal("text_delta"),
|
|
924
|
+
text: zod.z.string()
|
|
925
|
+
}),
|
|
926
|
+
zod.z.object({
|
|
927
|
+
type: zod.z.literal("thinking_delta"),
|
|
928
|
+
thinking: zod.z.string()
|
|
929
|
+
}),
|
|
930
|
+
zod.z.object({
|
|
931
|
+
type: zod.z.literal("signature_delta"),
|
|
932
|
+
signature: zod.z.string()
|
|
933
|
+
})
|
|
934
|
+
])
|
|
935
|
+
}),
|
|
936
|
+
zod.z.object({
|
|
937
|
+
type: zod.z.literal("content_block_stop"),
|
|
938
|
+
index: zod.z.number()
|
|
939
|
+
}),
|
|
940
|
+
zod.z.object({
|
|
941
|
+
type: zod.z.literal("error"),
|
|
942
|
+
error: zod.z.object({
|
|
943
|
+
type: zod.z.string(),
|
|
944
|
+
message: zod.z.string()
|
|
945
|
+
})
|
|
946
|
+
}),
|
|
947
|
+
zod.z.object({
|
|
948
|
+
type: zod.z.literal("message_delta"),
|
|
949
|
+
delta: zod.z.object({ stop_reason: zod.z.string().nullish() }),
|
|
950
|
+
usage: zod.z.object({ output_tokens: zod.z.number() })
|
|
951
|
+
}),
|
|
952
|
+
zod.z.object({
|
|
953
|
+
type: zod.z.literal("message_stop")
|
|
954
|
+
}),
|
|
955
|
+
zod.z.object({
|
|
956
|
+
type: zod.z.literal("ping")
|
|
957
|
+
})
|
|
958
|
+
]);
|
|
959
|
+
var anthropicProviderOptionsSchema = zod.z.object({
|
|
960
|
+
thinking: zod.z.object({
|
|
961
|
+
type: zod.z.union([zod.z.literal("enabled"), zod.z.literal("disabled")]),
|
|
962
|
+
budgetTokens: zod.z.number().optional()
|
|
963
|
+
}).optional()
|
|
964
|
+
});
|
|
965
|
+
var Bash20241022Parameters = zod.z.object({
|
|
966
|
+
command: zod.z.string(),
|
|
967
|
+
restart: zod.z.boolean().optional()
|
|
968
|
+
});
|
|
969
|
+
function bashTool_20241022(options = {}) {
|
|
970
|
+
return {
|
|
971
|
+
type: "provider-defined",
|
|
972
|
+
id: "anthropic.bash_20241022",
|
|
973
|
+
args: {},
|
|
974
|
+
parameters: Bash20241022Parameters,
|
|
975
|
+
execute: options.execute,
|
|
976
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
var Bash20250124Parameters = zod.z.object({
|
|
980
|
+
command: zod.z.string(),
|
|
981
|
+
restart: zod.z.boolean().optional()
|
|
982
|
+
});
|
|
983
|
+
function bashTool_20250124(options = {}) {
|
|
984
|
+
return {
|
|
985
|
+
type: "provider-defined",
|
|
986
|
+
id: "anthropic.bash_20250124",
|
|
987
|
+
args: {},
|
|
988
|
+
parameters: Bash20250124Parameters,
|
|
989
|
+
execute: options.execute,
|
|
990
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
var TextEditor20241022Parameters = zod.z.object({
|
|
994
|
+
command: zod.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
995
|
+
path: zod.z.string(),
|
|
996
|
+
file_text: zod.z.string().optional(),
|
|
997
|
+
insert_line: zod.z.number().int().optional(),
|
|
998
|
+
new_str: zod.z.string().optional(),
|
|
999
|
+
old_str: zod.z.string().optional(),
|
|
1000
|
+
view_range: zod.z.array(zod.z.number().int()).optional()
|
|
1001
|
+
});
|
|
1002
|
+
function textEditorTool_20241022(options = {}) {
|
|
1003
|
+
return {
|
|
1004
|
+
type: "provider-defined",
|
|
1005
|
+
id: "anthropic.text_editor_20241022",
|
|
1006
|
+
args: {},
|
|
1007
|
+
parameters: TextEditor20241022Parameters,
|
|
1008
|
+
execute: options.execute,
|
|
1009
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
var TextEditor20250124Parameters = zod.z.object({
|
|
1013
|
+
command: zod.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1014
|
+
path: zod.z.string(),
|
|
1015
|
+
file_text: zod.z.string().optional(),
|
|
1016
|
+
insert_line: zod.z.number().int().optional(),
|
|
1017
|
+
new_str: zod.z.string().optional(),
|
|
1018
|
+
old_str: zod.z.string().optional(),
|
|
1019
|
+
view_range: zod.z.array(zod.z.number().int()).optional()
|
|
1020
|
+
});
|
|
1021
|
+
function textEditorTool_20250124(options = {}) {
|
|
1022
|
+
return {
|
|
1023
|
+
type: "provider-defined",
|
|
1024
|
+
id: "anthropic.text_editor_20250124",
|
|
1025
|
+
args: {},
|
|
1026
|
+
parameters: TextEditor20250124Parameters,
|
|
1027
|
+
execute: options.execute,
|
|
1028
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
var Computer20241022Parameters = zod.z.object({
|
|
1032
|
+
action: zod.z.enum([
|
|
1033
|
+
"key",
|
|
1034
|
+
"type",
|
|
1035
|
+
"mouse_move",
|
|
1036
|
+
"left_click",
|
|
1037
|
+
"left_click_drag",
|
|
1038
|
+
"right_click",
|
|
1039
|
+
"middle_click",
|
|
1040
|
+
"double_click",
|
|
1041
|
+
"screenshot",
|
|
1042
|
+
"cursor_position"
|
|
1043
|
+
]),
|
|
1044
|
+
coordinate: zod.z.array(zod.z.number().int()).optional(),
|
|
1045
|
+
text: zod.z.string().optional()
|
|
1046
|
+
});
|
|
1047
|
+
function computerTool_20241022(options) {
|
|
1048
|
+
return {
|
|
1049
|
+
type: "provider-defined",
|
|
1050
|
+
id: "anthropic.computer_20241022",
|
|
1051
|
+
args: {
|
|
1052
|
+
displayWidthPx: options.displayWidthPx,
|
|
1053
|
+
displayHeightPx: options.displayHeightPx,
|
|
1054
|
+
displayNumber: options.displayNumber
|
|
1055
|
+
},
|
|
1056
|
+
parameters: Computer20241022Parameters,
|
|
1057
|
+
execute: options.execute,
|
|
1058
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
var Computer20250124Parameters = zod.z.object({
|
|
1062
|
+
action: zod.z.enum([
|
|
1063
|
+
"key",
|
|
1064
|
+
"hold_key",
|
|
1065
|
+
"type",
|
|
1066
|
+
"cursor_position",
|
|
1067
|
+
"mouse_move",
|
|
1068
|
+
"left_mouse_down",
|
|
1069
|
+
"left_mouse_up",
|
|
1070
|
+
"left_click",
|
|
1071
|
+
"left_click_drag",
|
|
1072
|
+
"right_click",
|
|
1073
|
+
"middle_click",
|
|
1074
|
+
"double_click",
|
|
1075
|
+
"triple_click",
|
|
1076
|
+
"scroll",
|
|
1077
|
+
"wait",
|
|
1078
|
+
"screenshot"
|
|
1079
|
+
]),
|
|
1080
|
+
coordinate: zod.z.tuple([zod.z.number().int(), zod.z.number().int()]).optional(),
|
|
1081
|
+
duration: zod.z.number().optional(),
|
|
1082
|
+
scroll_amount: zod.z.number().optional(),
|
|
1083
|
+
scroll_direction: zod.z.enum(["up", "down", "left", "right"]).optional(),
|
|
1084
|
+
start_coordinate: zod.z.tuple([zod.z.number().int(), zod.z.number().int()]).optional(),
|
|
1085
|
+
text: zod.z.string().optional()
|
|
1086
|
+
});
|
|
1087
|
+
function computerTool_20250124(options) {
|
|
1088
|
+
return {
|
|
1089
|
+
type: "provider-defined",
|
|
1090
|
+
id: "anthropic.computer_20250124",
|
|
1091
|
+
args: {
|
|
1092
|
+
displayWidthPx: options.displayWidthPx,
|
|
1093
|
+
displayHeightPx: options.displayHeightPx,
|
|
1094
|
+
displayNumber: options.displayNumber
|
|
1095
|
+
},
|
|
1096
|
+
parameters: Computer20250124Parameters,
|
|
1097
|
+
execute: options.execute,
|
|
1098
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
var anthropicTools = {
|
|
1102
|
+
bash_20241022: bashTool_20241022,
|
|
1103
|
+
bash_20250124: bashTool_20250124,
|
|
1104
|
+
textEditor_20241022: textEditorTool_20241022,
|
|
1105
|
+
textEditor_20250124: textEditorTool_20250124,
|
|
1106
|
+
computer_20241022: computerTool_20241022,
|
|
1107
|
+
computer_20250124: computerTool_20250124
|
|
1108
|
+
};
|
|
1109
|
+
function createAnthropic(options = {}) {
|
|
1110
|
+
var _a;
|
|
1111
|
+
const baseURL = (_a = chunkSIGXR3JT_cjs.withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
|
|
1112
|
+
const getHeaders = () => ({
|
|
1113
|
+
"anthropic-version": "2023-06-01",
|
|
1114
|
+
"x-api-key": chunkSIGXR3JT_cjs.loadApiKey({
|
|
1115
|
+
apiKey: options.apiKey,
|
|
1116
|
+
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
1117
|
+
description: "Anthropic"
|
|
1118
|
+
}),
|
|
1119
|
+
...options.headers
|
|
1120
|
+
});
|
|
1121
|
+
const createChatModel = (modelId, settings = {}) => new AnthropicMessagesLanguageModel(modelId, settings, {
|
|
1122
|
+
provider: "anthropic.messages",
|
|
1123
|
+
baseURL,
|
|
1124
|
+
headers: getHeaders,
|
|
1125
|
+
fetch: options.fetch,
|
|
1126
|
+
supportsImageUrls: true
|
|
1127
|
+
});
|
|
1128
|
+
const provider = function(modelId, settings) {
|
|
1129
|
+
if (new.target) {
|
|
1130
|
+
throw new Error(
|
|
1131
|
+
"The Anthropic model function cannot be called with the new keyword."
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
return createChatModel(modelId, settings);
|
|
1135
|
+
};
|
|
1136
|
+
provider.languageModel = createChatModel;
|
|
1137
|
+
provider.chat = createChatModel;
|
|
1138
|
+
provider.messages = createChatModel;
|
|
1139
|
+
provider.textEmbeddingModel = (modelId) => {
|
|
1140
|
+
throw new chunkSIGXR3JT_cjs.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
1141
|
+
};
|
|
1142
|
+
provider.tools = anthropicTools;
|
|
1143
|
+
return provider;
|
|
1144
|
+
}
|
|
1145
|
+
var anthropic = createAnthropic();
|
|
1146
|
+
|
|
1147
|
+
exports.anthropic = anthropic;
|
|
1148
|
+
exports.createAnthropic = createAnthropic;
|
|
1149
|
+
//# sourceMappingURL=chunk-IGFMAZZ5.cjs.map
|
|
1150
|
+
//# sourceMappingURL=chunk-IGFMAZZ5.cjs.map
|