pybao-cli 1.5.13 → 1.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/REPL-UZDUISQL.js +50 -0
- package/dist/{acp-6D6QDJQY.js → acp-MSZ5RIQH.js} +31 -31
- package/dist/{agentsValidate-XFP3HZ4H.js → agentsValidate-YCZ5I5PH.js} +7 -7
- package/dist/{ask-6CZRJCSZ.js → ask-6TLUBL3F.js} +30 -30
- package/dist/{autoUpdater-VCCPGPDD.js → autoUpdater-QN6VW4H7.js} +3 -3
- package/dist/{chunk-DYRNDVME.js → chunk-6O5YLDUZ.js} +3 -3
- package/dist/{chunk-FEEOL2BF.js → chunk-6RRWB5RJ.js} +2 -2
- package/dist/{chunk-PH2OZGKF.js → chunk-6T2A6453.js} +1 -1
- package/dist/{chunk-MP2Z2WPA.js → chunk-7YDRRHHA.js} +3 -3
- package/dist/{chunk-CLDFSJRX.js → chunk-A5GK77ZR.js} +3 -3
- package/dist/{chunk-NMV2Y2OE.js → chunk-BJF6GJWS.js} +2 -2
- package/dist/{chunk-EN3EFAIN.js → chunk-CGCRCAEE.js} +848 -858
- package/dist/{chunk-EN3EFAIN.js.map → chunk-CGCRCAEE.js.map} +4 -4
- package/dist/{chunk-5SB6YYVT.js → chunk-CM2BHPBS.js} +1 -1
- package/dist/{chunk-UYEP4HDV.js → chunk-CM5VV5YR.js} +1 -1
- package/dist/{chunk-2YIYRACC.js → chunk-DPGWN2AL.js} +1 -1
- package/dist/{chunk-PMBP2S7T.js → chunk-E44XXHEZ.js} +2 -2
- package/dist/{chunk-2L7XKUEG.js → chunk-H4CJDGI2.js} +1 -1
- package/dist/{chunk-2L7XKUEG.js.map → chunk-H4CJDGI2.js.map} +1 -1
- package/dist/{chunk-IZKGIVR5.js → chunk-H5VJCPBX.js} +4 -4
- package/dist/{chunk-HBFOODQT.js → chunk-HMOYVZZY.js} +1 -1
- package/dist/{chunk-4CTIJSGF.js → chunk-K75MU5KH.js} +1 -1
- package/dist/{chunk-SQZQF7FX.js → chunk-LVDHERSS.js} +1 -1
- package/dist/{chunk-KDWAOC2Y.js → chunk-M3G65CDD.js} +2 -2
- package/dist/{chunk-PF2W6HQJ.js → chunk-MTNWIWXZ.js} +3 -3
- package/dist/{chunk-KHCVAV26.js → chunk-NBSAKUNJ.js} +1 -1
- package/dist/{chunk-DFQUXY7J.js → chunk-NQNZKPC7.js} +1 -1
- package/dist/{chunk-LHETO2A7.js → chunk-O6WNHWNP.js} +2 -2
- package/dist/{chunk-V6HDC2AS.js → chunk-OGAO5B2G.js} +4 -4
- package/dist/{chunk-GKLF5SMX.js → chunk-PLI6YIVF.js} +4 -4
- package/dist/{chunk-62DRY4WE.js → chunk-PTYPEDJX.js} +4 -4
- package/dist/{chunk-R5KHOF4Q.js → chunk-Q3UL5UMX.js} +1 -1
- package/dist/{chunk-IKZOQVSC.js → chunk-QQKZSWNE.js} +3 -3
- package/dist/{chunk-4V637EWT.js → chunk-SX6IOPJG.js} +15 -15
- package/dist/{chunk-VLE3RIPA.js → chunk-US3AHG74.js} +3 -3
- package/dist/{chunk-5AZPIB3O.js → chunk-UZSZ5W4A.js} +3 -3
- package/dist/{chunk-6Z7VRZE3.js → chunk-W56DNT4T.js} +2 -2
- package/dist/{chunk-LXKU7CVC.js → chunk-WO2262XL.js} +1 -1
- package/dist/{chunk-USAN2W2G.js → chunk-ZI6YQH7N.js} +1 -1
- package/dist/{cli-2YA4LC5A.js → cli-TXLGPEIZ.js} +91 -91
- package/dist/commands-2L54VTHI.js +54 -0
- package/dist/{config-NLO656A6.js → config-FBBJAQBM.js} +4 -4
- package/dist/{context-B5OAVYCB.js → context-FM42L2I3.js} +6 -6
- package/dist/{conversationPersistence-U3JD7OG2.js → conversationPersistence-SMHC4JEA.js} +3 -3
- package/dist/{conversationTracker-XMFEBWHY.js → conversationTracker-5NJSFW67.js} +4 -4
- package/dist/{customCommands-MP2IC4VW.js → customCommands-RILTFV7H.js} +4 -4
- package/dist/{env-IWFZNFTP.js → env-7TOA2FOC.js} +2 -2
- package/dist/{file-NKAAAB74.js → file-PFUV342Z.js} +4 -4
- package/dist/index.js +3 -3
- package/dist/{llm-VL7SVIXR.js → llm-MASKGBQQ.js} +31 -31
- package/dist/{llmLazy-JXN5R32R.js → llmLazy-TLVK4O63.js} +1 -1
- package/dist/{loader-QO3E224E.js → loader-5VE7OEBB.js} +4 -4
- package/dist/{lsp-3KQLSDLC.js → lsp-MHZMR42C.js} +6 -6
- package/dist/{lspAnchor-56RDVJJK.js → lspAnchor-ED7WVFHC.js} +6 -6
- package/dist/{mcp-QYGOVXNU.js → mcp-WYVQIEED.js} +7 -7
- package/dist/{mentionProcessor-M5UL6TT6.js → mentionProcessor-DU7CBOPE.js} +5 -5
- package/dist/{messages-IR7NEQMR.js → messages-WZUIVMCS.js} +1 -1
- package/dist/{model-JVW7GWZF.js → model-7PWK4YWQ.js} +5 -5
- package/dist/{openai-JJWBAQ7K.js → openai-KJV5P2P5.js} +5 -5
- package/dist/{outputStyles-NNT6NWAK.js → outputStyles-YX3XJZZO.js} +4 -4
- package/dist/{pluginRuntime-5ZYXGIUZ.js → pluginRuntime-5STYKO5H.js} +6 -6
- package/dist/{pluginValidation-6OLPIUNW.js → pluginValidation-OPAW65GB.js} +6 -6
- package/dist/prompts-6BWOXYS5.js +56 -0
- package/dist/{pybAgentSessionLoad-HN6WOHQP.js → pybAgentSessionLoad-ZI4WROR3.js} +4 -4
- package/dist/{pybAgentSessionResume-KEUXFVVT.js → pybAgentSessionResume-KIJKH4BL.js} +4 -4
- package/dist/{pybAgentStreamJsonSession-V24MOW3E.js → pybAgentStreamJsonSession-RFAAQTPP.js} +1 -1
- package/dist/{pybHooks-OEASV3O6.js → pybHooks-B27JL4BK.js} +4 -4
- package/dist/query-AVPC4YCP.js +56 -0
- package/dist/{registry-WDNZOTS2.js → registry-LNQ547CH.js} +5 -5
- package/dist/{ripgrep-YEEECTEY.js → ripgrep-EE2LKA6X.js} +3 -3
- package/dist/{skillMarketplace-N2W7WTS3.js → skillMarketplace-C5UG3TEI.js} +3 -3
- package/dist/{state-IB4ZDFMG.js → state-66WENTAD.js} +2 -2
- package/dist/{theme-5AY4LKLW.js → theme-QWGPXAO3.js} +5 -5
- package/dist/{toolPermissionSettings-J5VPVYUK.js → toolPermissionSettings-BD4QCGN3.js} +6 -6
- package/dist/tools-XFXUOR6Y.js +55 -0
- package/dist/{userInput-YJI6VWIU.js → userInput-CQPBO4J4.js} +32 -32
- package/package.json +1 -1
- package/scripts/session-behavior-invariant-gate.mjs +10 -1
- package/dist/REPL-4ET7DK5F.js +0 -50
- package/dist/commands-GZ2R547K.js +0 -54
- package/dist/prompts-ITAM2QAA.js +0 -56
- package/dist/query-4YMUBJ3B.js +0 -56
- package/dist/tools-VLTX3RMF.js +0 -55
- /package/dist/{REPL-4ET7DK5F.js.map → REPL-UZDUISQL.js.map} +0 -0
- /package/dist/{acp-6D6QDJQY.js.map → acp-MSZ5RIQH.js.map} +0 -0
- /package/dist/{agentsValidate-XFP3HZ4H.js.map → agentsValidate-YCZ5I5PH.js.map} +0 -0
- /package/dist/{ask-6CZRJCSZ.js.map → ask-6TLUBL3F.js.map} +0 -0
- /package/dist/{autoUpdater-VCCPGPDD.js.map → autoUpdater-QN6VW4H7.js.map} +0 -0
- /package/dist/{chunk-DYRNDVME.js.map → chunk-6O5YLDUZ.js.map} +0 -0
- /package/dist/{chunk-FEEOL2BF.js.map → chunk-6RRWB5RJ.js.map} +0 -0
- /package/dist/{chunk-PH2OZGKF.js.map → chunk-6T2A6453.js.map} +0 -0
- /package/dist/{chunk-MP2Z2WPA.js.map → chunk-7YDRRHHA.js.map} +0 -0
- /package/dist/{chunk-CLDFSJRX.js.map → chunk-A5GK77ZR.js.map} +0 -0
- /package/dist/{chunk-NMV2Y2OE.js.map → chunk-BJF6GJWS.js.map} +0 -0
- /package/dist/{chunk-5SB6YYVT.js.map → chunk-CM2BHPBS.js.map} +0 -0
- /package/dist/{chunk-UYEP4HDV.js.map → chunk-CM5VV5YR.js.map} +0 -0
- /package/dist/{chunk-2YIYRACC.js.map → chunk-DPGWN2AL.js.map} +0 -0
- /package/dist/{chunk-PMBP2S7T.js.map → chunk-E44XXHEZ.js.map} +0 -0
- /package/dist/{chunk-IZKGIVR5.js.map → chunk-H5VJCPBX.js.map} +0 -0
- /package/dist/{chunk-HBFOODQT.js.map → chunk-HMOYVZZY.js.map} +0 -0
- /package/dist/{chunk-4CTIJSGF.js.map → chunk-K75MU5KH.js.map} +0 -0
- /package/dist/{chunk-SQZQF7FX.js.map → chunk-LVDHERSS.js.map} +0 -0
- /package/dist/{chunk-KDWAOC2Y.js.map → chunk-M3G65CDD.js.map} +0 -0
- /package/dist/{chunk-PF2W6HQJ.js.map → chunk-MTNWIWXZ.js.map} +0 -0
- /package/dist/{chunk-KHCVAV26.js.map → chunk-NBSAKUNJ.js.map} +0 -0
- /package/dist/{chunk-DFQUXY7J.js.map → chunk-NQNZKPC7.js.map} +0 -0
- /package/dist/{chunk-LHETO2A7.js.map → chunk-O6WNHWNP.js.map} +0 -0
- /package/dist/{chunk-V6HDC2AS.js.map → chunk-OGAO5B2G.js.map} +0 -0
- /package/dist/{chunk-GKLF5SMX.js.map → chunk-PLI6YIVF.js.map} +0 -0
- /package/dist/{chunk-62DRY4WE.js.map → chunk-PTYPEDJX.js.map} +0 -0
- /package/dist/{chunk-R5KHOF4Q.js.map → chunk-Q3UL5UMX.js.map} +0 -0
- /package/dist/{chunk-IKZOQVSC.js.map → chunk-QQKZSWNE.js.map} +0 -0
- /package/dist/{chunk-4V637EWT.js.map → chunk-SX6IOPJG.js.map} +0 -0
- /package/dist/{chunk-VLE3RIPA.js.map → chunk-US3AHG74.js.map} +0 -0
- /package/dist/{chunk-5AZPIB3O.js.map → chunk-UZSZ5W4A.js.map} +0 -0
- /package/dist/{chunk-6Z7VRZE3.js.map → chunk-W56DNT4T.js.map} +0 -0
- /package/dist/{chunk-LXKU7CVC.js.map → chunk-WO2262XL.js.map} +0 -0
- /package/dist/{chunk-USAN2W2G.js.map → chunk-ZI6YQH7N.js.map} +0 -0
- /package/dist/{cli-2YA4LC5A.js.map → cli-TXLGPEIZ.js.map} +0 -0
- /package/dist/{commands-GZ2R547K.js.map → commands-2L54VTHI.js.map} +0 -0
- /package/dist/{config-NLO656A6.js.map → config-FBBJAQBM.js.map} +0 -0
- /package/dist/{context-B5OAVYCB.js.map → context-FM42L2I3.js.map} +0 -0
- /package/dist/{conversationPersistence-U3JD7OG2.js.map → conversationPersistence-SMHC4JEA.js.map} +0 -0
- /package/dist/{conversationTracker-XMFEBWHY.js.map → conversationTracker-5NJSFW67.js.map} +0 -0
- /package/dist/{customCommands-MP2IC4VW.js.map → customCommands-RILTFV7H.js.map} +0 -0
- /package/dist/{env-IWFZNFTP.js.map → env-7TOA2FOC.js.map} +0 -0
- /package/dist/{file-NKAAAB74.js.map → file-PFUV342Z.js.map} +0 -0
- /package/dist/{llm-VL7SVIXR.js.map → llm-MASKGBQQ.js.map} +0 -0
- /package/dist/{llmLazy-JXN5R32R.js.map → llmLazy-TLVK4O63.js.map} +0 -0
- /package/dist/{loader-QO3E224E.js.map → loader-5VE7OEBB.js.map} +0 -0
- /package/dist/{lsp-3KQLSDLC.js.map → lsp-MHZMR42C.js.map} +0 -0
- /package/dist/{lspAnchor-56RDVJJK.js.map → lspAnchor-ED7WVFHC.js.map} +0 -0
- /package/dist/{mcp-QYGOVXNU.js.map → mcp-WYVQIEED.js.map} +0 -0
- /package/dist/{mentionProcessor-M5UL6TT6.js.map → mentionProcessor-DU7CBOPE.js.map} +0 -0
- /package/dist/{messages-IR7NEQMR.js.map → messages-WZUIVMCS.js.map} +0 -0
- /package/dist/{model-JVW7GWZF.js.map → model-7PWK4YWQ.js.map} +0 -0
- /package/dist/{openai-JJWBAQ7K.js.map → openai-KJV5P2P5.js.map} +0 -0
- /package/dist/{outputStyles-NNT6NWAK.js.map → outputStyles-YX3XJZZO.js.map} +0 -0
- /package/dist/{pluginRuntime-5ZYXGIUZ.js.map → pluginRuntime-5STYKO5H.js.map} +0 -0
- /package/dist/{pluginValidation-6OLPIUNW.js.map → pluginValidation-OPAW65GB.js.map} +0 -0
- /package/dist/{prompts-ITAM2QAA.js.map → prompts-6BWOXYS5.js.map} +0 -0
- /package/dist/{pybAgentSessionLoad-HN6WOHQP.js.map → pybAgentSessionLoad-ZI4WROR3.js.map} +0 -0
- /package/dist/{pybAgentSessionResume-KEUXFVVT.js.map → pybAgentSessionResume-KIJKH4BL.js.map} +0 -0
- /package/dist/{pybAgentStreamJsonSession-V24MOW3E.js.map → pybAgentStreamJsonSession-RFAAQTPP.js.map} +0 -0
- /package/dist/{pybHooks-OEASV3O6.js.map → pybHooks-B27JL4BK.js.map} +0 -0
- /package/dist/{query-4YMUBJ3B.js.map → query-AVPC4YCP.js.map} +0 -0
- /package/dist/{registry-WDNZOTS2.js.map → registry-LNQ547CH.js.map} +0 -0
- /package/dist/{ripgrep-YEEECTEY.js.map → ripgrep-EE2LKA6X.js.map} +0 -0
- /package/dist/{skillMarketplace-N2W7WTS3.js.map → skillMarketplace-C5UG3TEI.js.map} +0 -0
- /package/dist/{state-IB4ZDFMG.js.map → state-66WENTAD.js.map} +0 -0
- /package/dist/{theme-5AY4LKLW.js.map → theme-QWGPXAO3.js.map} +0 -0
- /package/dist/{toolPermissionSettings-J5VPVYUK.js.map → toolPermissionSettings-BD4QCGN3.js.map} +0 -0
- /package/dist/{tools-VLTX3RMF.js.map → tools-XFXUOR6Y.js.map} +0 -0
- /package/dist/{userInput-YJI6VWIU.js.map → userInput-CQPBO4J4.js.map} +0 -0
|
@@ -2,18 +2,18 @@ import { createRequire as __pybCreateRequire } from "node:module";
|
|
|
2
2
|
const require = __pybCreateRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
loadPybAgentSessionMessages
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-LVDHERSS.js";
|
|
6
6
|
import {
|
|
7
7
|
listPybAgentSessions
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-DPGWN2AL.js";
|
|
9
9
|
import {
|
|
10
10
|
appendSessionCustomTitleRecord,
|
|
11
11
|
appendSessionTagRecord
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-CM2BHPBS.js";
|
|
13
13
|
import {
|
|
14
14
|
formatValidationResult,
|
|
15
15
|
validatePluginOrMarketplacePath
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-US3AHG74.js";
|
|
17
17
|
import {
|
|
18
18
|
ConversationTracker,
|
|
19
19
|
appendFinishState,
|
|
@@ -21,10 +21,10 @@ import {
|
|
|
21
21
|
getConversationTrackerForContext,
|
|
22
22
|
isFinishComplete,
|
|
23
23
|
mapFinishReason
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-Q3UL5UMX.js";
|
|
25
25
|
import {
|
|
26
26
|
FileSystemConversationPersistence
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-NBSAKUNJ.js";
|
|
28
28
|
import {
|
|
29
29
|
beginReplSessionScope
|
|
30
30
|
} from "./chunk-F4AXICO7.js";
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
runStopHooks,
|
|
40
40
|
runUserPromptSubmitHooks,
|
|
41
41
|
updateHookTranscriptForMessages
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-A5GK77ZR.js";
|
|
43
43
|
import {
|
|
44
44
|
DEFAULT_OUTPUT_STYLE,
|
|
45
45
|
getAvailableOutputStyles,
|
|
@@ -48,11 +48,11 @@ import {
|
|
|
48
48
|
getOutputStyleSystemPromptAdditions,
|
|
49
49
|
resolveOutputStyleName,
|
|
50
50
|
setCurrentOutputStyle
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-M3G65CDD.js";
|
|
52
52
|
import {
|
|
53
53
|
fetchCustomModels,
|
|
54
54
|
getModelFeatures
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-E44XXHEZ.js";
|
|
56
56
|
import {
|
|
57
57
|
getSessionState
|
|
58
58
|
} from "./chunk-XKYHFZEC.js";
|
|
@@ -60,7 +60,7 @@ import {
|
|
|
60
60
|
queryLLM,
|
|
61
61
|
queryQuick,
|
|
62
62
|
verifyApiKey
|
|
63
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-PLI6YIVF.js";
|
|
64
64
|
import {
|
|
65
65
|
DEFAULT_TIMEOUT_MS,
|
|
66
66
|
FallbackToolUseRejectedMessage,
|
|
@@ -74,7 +74,7 @@ import {
|
|
|
74
74
|
listMCPServers,
|
|
75
75
|
loadMergedSettings,
|
|
76
76
|
normalizeSandboxRuntimeConfigFromSettings
|
|
77
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-H5VJCPBX.js";
|
|
78
78
|
import {
|
|
79
79
|
addMarketplace,
|
|
80
80
|
disableSkillPlugin,
|
|
@@ -87,11 +87,11 @@ import {
|
|
|
87
87
|
refreshMarketplaceAsync,
|
|
88
88
|
removeMarketplace,
|
|
89
89
|
uninstallSkillPlugin
|
|
90
|
-
} from "./chunk-
|
|
90
|
+
} from "./chunk-ZI6YQH7N.js";
|
|
91
91
|
import {
|
|
92
92
|
loadToolPermissionContextFromDisk,
|
|
93
93
|
persistToolPermissionUpdateToDisk
|
|
94
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-6O5YLDUZ.js";
|
|
95
95
|
import {
|
|
96
96
|
applyToolPermissionContextUpdate,
|
|
97
97
|
applyToolPermissionContextUpdates,
|
|
@@ -102,13 +102,13 @@ import {
|
|
|
102
102
|
generateSystemReminders,
|
|
103
103
|
resetReminderSession,
|
|
104
104
|
systemReminderService
|
|
105
|
-
} from "./chunk-
|
|
105
|
+
} from "./chunk-BJF6GJWS.js";
|
|
106
106
|
import {
|
|
107
107
|
clearAgentCache,
|
|
108
108
|
getActiveAgents,
|
|
109
109
|
getAgentByType,
|
|
110
110
|
getAllAgents
|
|
111
|
-
} from "./chunk-
|
|
111
|
+
} from "./chunk-O6WNHWNP.js";
|
|
112
112
|
import {
|
|
113
113
|
API_ERROR_MESSAGE_PREFIX,
|
|
114
114
|
CANCEL_MESSAGE,
|
|
@@ -145,7 +145,7 @@ import {
|
|
|
145
145
|
reorderMessages,
|
|
146
146
|
resetAutoCompactTelemetry,
|
|
147
147
|
stripSystemMessages
|
|
148
|
-
} from "./chunk-
|
|
148
|
+
} from "./chunk-CM5VV5YR.js";
|
|
149
149
|
import {
|
|
150
150
|
getRequestStatus,
|
|
151
151
|
setRequestStatus,
|
|
@@ -175,7 +175,7 @@ import {
|
|
|
175
175
|
normalizeFilePath,
|
|
176
176
|
readTextContent,
|
|
177
177
|
writeTextContent
|
|
178
|
-
} from "./chunk-
|
|
178
|
+
} from "./chunk-W56DNT4T.js";
|
|
179
179
|
import {
|
|
180
180
|
parseBlockEdits
|
|
181
181
|
} from "./chunk-QWIBSCDN.js";
|
|
@@ -185,18 +185,18 @@ import {
|
|
|
185
185
|
ParserRegistry,
|
|
186
186
|
initParser,
|
|
187
187
|
loadLanguage
|
|
188
|
-
} from "./chunk-
|
|
188
|
+
} from "./chunk-OGAO5B2G.js";
|
|
189
189
|
import {
|
|
190
190
|
getSettingsFileCandidates,
|
|
191
191
|
loadSettingsWithLegacyFallback,
|
|
192
192
|
readSettingsFile
|
|
193
|
-
} from "./chunk-
|
|
193
|
+
} from "./chunk-WO2262XL.js";
|
|
194
194
|
import {
|
|
195
195
|
getCustomCommandDirectories,
|
|
196
196
|
hasCustomCommands,
|
|
197
197
|
loadCustomCommands,
|
|
198
198
|
reloadCustomCommands
|
|
199
|
-
} from "./chunk-
|
|
199
|
+
} from "./chunk-6RRWB5RJ.js";
|
|
200
200
|
import {
|
|
201
201
|
getSessionPlugins
|
|
202
202
|
} from "./chunk-BJSWTHRM.js";
|
|
@@ -205,7 +205,7 @@ import {
|
|
|
205
205
|
buildModelProfileKey,
|
|
206
206
|
getModelManager,
|
|
207
207
|
isDefaultSlowAndCapableModel
|
|
208
|
-
} from "./chunk-
|
|
208
|
+
} from "./chunk-UZSZ5W4A.js";
|
|
209
209
|
import {
|
|
210
210
|
getCodeStyle,
|
|
211
211
|
getContext,
|
|
@@ -213,16 +213,16 @@ import {
|
|
|
213
213
|
getIsGit,
|
|
214
214
|
getProjectDocs,
|
|
215
215
|
getProjectStructureStatisticsBlock
|
|
216
|
-
} from "./chunk-
|
|
216
|
+
} from "./chunk-PTYPEDJX.js";
|
|
217
217
|
import {
|
|
218
218
|
getRipgrepPath,
|
|
219
219
|
getRipgrepPolicyMode,
|
|
220
220
|
resolveRipgrepPolicy,
|
|
221
221
|
ripGrep
|
|
222
|
-
} from "./chunk-
|
|
222
|
+
} from "./chunk-K75MU5KH.js";
|
|
223
223
|
import {
|
|
224
224
|
getTheme
|
|
225
|
-
} from "./chunk-
|
|
225
|
+
} from "./chunk-6T2A6453.js";
|
|
226
226
|
import {
|
|
227
227
|
DEFAULT_GLOBAL_CONFIG,
|
|
228
228
|
enableConfigs,
|
|
@@ -235,7 +235,7 @@ import {
|
|
|
235
235
|
saveGlobalConfig,
|
|
236
236
|
setAllPointersToModel,
|
|
237
237
|
setModelPointer
|
|
238
|
-
} from "./chunk-
|
|
238
|
+
} from "./chunk-QQKZSWNE.js";
|
|
239
239
|
import {
|
|
240
240
|
AbortError
|
|
241
241
|
} from "./chunk-RQVLBMP7.js";
|
|
@@ -244,7 +244,7 @@ import {
|
|
|
244
244
|
getCurrentRequest,
|
|
245
245
|
logUserFriendly,
|
|
246
246
|
markPhase
|
|
247
|
-
} from "./chunk-
|
|
247
|
+
} from "./chunk-HMOYVZZY.js";
|
|
248
248
|
import {
|
|
249
249
|
ASCII_LOGO,
|
|
250
250
|
BunShell,
|
|
@@ -285,10 +285,10 @@ import {
|
|
|
285
285
|
setCwd,
|
|
286
286
|
shouldApplyToolOutputTruncation,
|
|
287
287
|
truncateToolOutput
|
|
288
|
-
} from "./chunk-
|
|
288
|
+
} from "./chunk-NQNZKPC7.js";
|
|
289
289
|
import {
|
|
290
290
|
MACRO
|
|
291
|
-
} from "./chunk-
|
|
291
|
+
} from "./chunk-H4CJDGI2.js";
|
|
292
292
|
import {
|
|
293
293
|
__export
|
|
294
294
|
} from "./chunk-I3J4JYES.js";
|
|
@@ -469,7 +469,7 @@ var getCommandSubcommandPrefix = memoize(
|
|
|
469
469
|
var getCommandPrefix = memoize(
|
|
470
470
|
async (command4, abortSignal) => {
|
|
471
471
|
const { systemPrompt, userPrompt } = buildBashCommandPrefixDetectionPrompt(command4);
|
|
472
|
-
const { API_ERROR_MESSAGE_PREFIX: API_ERROR_MESSAGE_PREFIX2, queryQuick: queryQuick2 } = await import("./llm-
|
|
472
|
+
const { API_ERROR_MESSAGE_PREFIX: API_ERROR_MESSAGE_PREFIX2, queryQuick: queryQuick2 } = await import("./llm-MASKGBQQ.js");
|
|
473
473
|
const response = await queryQuick2({
|
|
474
474
|
systemPrompt,
|
|
475
475
|
userPrompt,
|
|
@@ -4271,7 +4271,7 @@ function formatParseError(error) {
|
|
|
4271
4271
|
return error instanceof Error ? error.message : String(error);
|
|
4272
4272
|
}
|
|
4273
4273
|
async function defaultGateQuery(args) {
|
|
4274
|
-
const { API_ERROR_MESSAGE_PREFIX: API_ERROR_MESSAGE_PREFIX2, queryLLM: queryLLM2 } = await import("./llm-
|
|
4274
|
+
const { API_ERROR_MESSAGE_PREFIX: API_ERROR_MESSAGE_PREFIX2, queryLLM: queryLLM2 } = await import("./llm-MASKGBQQ.js");
|
|
4275
4275
|
const queryLLMFn = args.queryLLMOverride ?? queryLLM2;
|
|
4276
4276
|
const messages = [
|
|
4277
4277
|
{
|
|
@@ -6664,7 +6664,7 @@ var FileEditTool = {
|
|
|
6664
6664
|
const originalFileContent = currentFileContent;
|
|
6665
6665
|
let totalPatch = [];
|
|
6666
6666
|
const { SmartEdit } = await import("./smart-edit-AWHJDSU6.js");
|
|
6667
|
-
const { findLspAnchor } = await import("./lspAnchor-
|
|
6667
|
+
const { findLspAnchor } = await import("./lspAnchor-ED7WVFHC.js");
|
|
6668
6668
|
for (const op of editOperations) {
|
|
6669
6669
|
const normalizedSearch = normalizeLineEndings(op.search);
|
|
6670
6670
|
const normalizedReplace = normalizeLineEndings(op.replace);
|
|
@@ -12149,7 +12149,7 @@ async function createAndStoreApiKey(accessToken) {
|
|
|
12149
12149
|
}
|
|
12150
12150
|
saveGlobalConfig(config2);
|
|
12151
12151
|
try {
|
|
12152
|
-
const { resetAnthropicClient } = await import("./llm-
|
|
12152
|
+
const { resetAnthropicClient } = await import("./llm-MASKGBQQ.js");
|
|
12153
12153
|
resetAnthropicClient();
|
|
12154
12154
|
} catch {
|
|
12155
12155
|
}
|
|
@@ -16573,7 +16573,7 @@ async function refreshPluginRuntimeFromInstalls() {
|
|
|
16573
16573
|
const existingRoots = getSessionPlugins().map((p) => p.rootDir);
|
|
16574
16574
|
const dirs = Array.from(/* @__PURE__ */ new Set([...existingRoots, ...installedRoots]));
|
|
16575
16575
|
if (dirs.length === 0) return [];
|
|
16576
|
-
const { configureSessionPlugins } = await import("./pluginRuntime-
|
|
16576
|
+
const { configureSessionPlugins } = await import("./pluginRuntime-5STYKO5H.js");
|
|
16577
16577
|
const { errors } = await configureSessionPlugins({ pluginDirs: dirs });
|
|
16578
16578
|
return errors;
|
|
16579
16579
|
}
|
|
@@ -17248,7 +17248,7 @@ async function call(onDone, context) {
|
|
|
17248
17248
|
ModelConfig,
|
|
17249
17249
|
{
|
|
17250
17250
|
onClose: () => {
|
|
17251
|
-
import("./model-
|
|
17251
|
+
import("./model-7PWK4YWQ.js").then(({ reloadModelManager: reloadModelManager2 }) => {
|
|
17252
17252
|
reloadModelManager2();
|
|
17253
17253
|
triggerModelConfigChange();
|
|
17254
17254
|
onDone();
|
|
@@ -25557,7 +25557,7 @@ function useStatusLine() {
|
|
|
25557
25557
|
// src/ui/components/PromptInput.tsx
|
|
25558
25558
|
async function interpretHashCommand(input) {
|
|
25559
25559
|
try {
|
|
25560
|
-
const { queryQuick: queryQuick2 } = await import("./llm-
|
|
25560
|
+
const { queryQuick: queryQuick2 } = await import("./llm-MASKGBQQ.js");
|
|
25561
25561
|
const systemPrompt = [
|
|
25562
25562
|
"You're helping the user structure notes that will be added to their PYB.md file.",
|
|
25563
25563
|
"Format the user's input into a well-structured note that will be useful for later reference.",
|
|
@@ -25870,7 +25870,7 @@ function PromptInput({
|
|
|
25870
25870
|
if (messages2.length) {
|
|
25871
25871
|
if (mode === "bash") {
|
|
25872
25872
|
onQuery(messages2, newAbortController).then(async () => {
|
|
25873
|
-
const { getCwd: getCwd2 } = await import("./state-
|
|
25873
|
+
const { getCwd: getCwd2 } = await import("./state-66WENTAD.js");
|
|
25874
25874
|
setCurrentPwd(getCwd2());
|
|
25875
25875
|
});
|
|
25876
25876
|
} else {
|
|
@@ -30040,6 +30040,271 @@ function flushConversationTrackerTelemetrySnapshot(options = {}) {
|
|
|
30040
30040
|
return record;
|
|
30041
30041
|
}
|
|
30042
30042
|
|
|
30043
|
+
// src/services/ai/streamTyped/projector.ts
|
|
30044
|
+
function supportsRichToolResultByProvider(provider) {
|
|
30045
|
+
return String(provider ?? "").trim().toLowerCase() === "anthropic";
|
|
30046
|
+
}
|
|
30047
|
+
function extractToolResultText2(content) {
|
|
30048
|
+
if (typeof content === "string") return { text: content, hasNonTextBlock: false };
|
|
30049
|
+
if (!Array.isArray(content)) return { text: "", hasNonTextBlock: false };
|
|
30050
|
+
let hasNonTextBlock = false;
|
|
30051
|
+
const text = content.filter((block) => {
|
|
30052
|
+
if (!block || typeof block !== "object") return false;
|
|
30053
|
+
if (block.type === "text") return true;
|
|
30054
|
+
hasNonTextBlock = true;
|
|
30055
|
+
return false;
|
|
30056
|
+
}).map((block) => String(block.text ?? "")).join("\n");
|
|
30057
|
+
return { text, hasNonTextBlock };
|
|
30058
|
+
}
|
|
30059
|
+
function extractTaggedText(text, tagName) {
|
|
30060
|
+
const normalized = String(text ?? "").trim();
|
|
30061
|
+
if (!normalized.startsWith(`<${tagName}>`)) return null;
|
|
30062
|
+
const pattern = new RegExp(`<${tagName}>([\\s\\S]*?)<\\/${tagName}>`, "i");
|
|
30063
|
+
const match = normalized.match(pattern);
|
|
30064
|
+
const content = String(match?.[1] ?? "").trim();
|
|
30065
|
+
return content.length > 0 ? content : null;
|
|
30066
|
+
}
|
|
30067
|
+
function projectAssistantMessage(state, message) {
|
|
30068
|
+
const content = message?.message?.content;
|
|
30069
|
+
if (!Array.isArray(content)) return;
|
|
30070
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
30071
|
+
const block = content[i];
|
|
30072
|
+
if (!block || typeof block !== "object") continue;
|
|
30073
|
+
const type3 = String(block.type ?? "");
|
|
30074
|
+
if (type3 === "text") {
|
|
30075
|
+
const text = String(block.text ?? "");
|
|
30076
|
+
const toolProgressText = extractTaggedText(text, "tool-progress");
|
|
30077
|
+
if (toolProgressText) {
|
|
30078
|
+
state.parts.push(
|
|
30079
|
+
createSystemEventPart({
|
|
30080
|
+
requestId: state.requestId,
|
|
30081
|
+
eventType: "tool_progress",
|
|
30082
|
+
text: toolProgressText,
|
|
30083
|
+
source: state.source
|
|
30084
|
+
})
|
|
30085
|
+
);
|
|
30086
|
+
}
|
|
30087
|
+
const localStdoutText = extractTaggedText(text, "local-command-stdout");
|
|
30088
|
+
if (localStdoutText) {
|
|
30089
|
+
state.parts.push(
|
|
30090
|
+
createSystemEventPart({
|
|
30091
|
+
requestId: state.requestId,
|
|
30092
|
+
eventType: "local_command_stdout",
|
|
30093
|
+
text: localStdoutText,
|
|
30094
|
+
source: state.source
|
|
30095
|
+
})
|
|
30096
|
+
);
|
|
30097
|
+
}
|
|
30098
|
+
const localStderrText = extractTaggedText(text, "local-command-stderr");
|
|
30099
|
+
if (localStderrText) {
|
|
30100
|
+
state.parts.push(
|
|
30101
|
+
createSystemEventPart({
|
|
30102
|
+
requestId: state.requestId,
|
|
30103
|
+
eventType: "local_command_stderr",
|
|
30104
|
+
text: localStderrText,
|
|
30105
|
+
source: state.source
|
|
30106
|
+
})
|
|
30107
|
+
);
|
|
30108
|
+
}
|
|
30109
|
+
onTextStart({ textId: `text-${i}` }, state);
|
|
30110
|
+
onTextDelta({ textId: `text-${i}`, text }, state);
|
|
30111
|
+
onTextEnd({ textId: `text-${i}` }, state);
|
|
30112
|
+
continue;
|
|
30113
|
+
}
|
|
30114
|
+
if (type3 === "thinking" || type3 === "reasoning") {
|
|
30115
|
+
const text = String(block.thinking ?? block.reasoning ?? "");
|
|
30116
|
+
onReasoningStart({ reasoningId: `reasoning-${i}` }, state);
|
|
30117
|
+
onReasoningDelta({ reasoningId: `reasoning-${i}`, text }, state);
|
|
30118
|
+
onReasoningEnd({ reasoningId: `reasoning-${i}` }, state);
|
|
30119
|
+
continue;
|
|
30120
|
+
}
|
|
30121
|
+
if (type3 === "tool_use" || type3 === "server_tool_use" || type3 === "mcp_tool_use") {
|
|
30122
|
+
const toolCallId = String(block.id ?? `tool-${i}`);
|
|
30123
|
+
const toolName = String(block.name ?? "unknown");
|
|
30124
|
+
onToolCall({ toolCallId, toolName }, state);
|
|
30125
|
+
}
|
|
30126
|
+
}
|
|
30127
|
+
}
|
|
30128
|
+
function projectUserToolResult(projector, message) {
|
|
30129
|
+
const state = projector.state;
|
|
30130
|
+
const content = message?.message?.content;
|
|
30131
|
+
if (!Array.isArray(content)) return;
|
|
30132
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
30133
|
+
const block = content[i];
|
|
30134
|
+
if (!block || typeof block !== "object") continue;
|
|
30135
|
+
if (block.type !== "tool_result") continue;
|
|
30136
|
+
const toolCallId = String(block.tool_use_id ?? `tool-${i}`);
|
|
30137
|
+
const extracted = extractToolResultText2(block.content);
|
|
30138
|
+
if (extracted.hasNonTextBlock) {
|
|
30139
|
+
projector.richToolResultBlockCount += 1;
|
|
30140
|
+
if (!projector.supportsRichToolResult) {
|
|
30141
|
+
projector.downgradedToolResultCount += 1;
|
|
30142
|
+
}
|
|
30143
|
+
}
|
|
30144
|
+
onToolResult(
|
|
30145
|
+
{
|
|
30146
|
+
toolCallId,
|
|
30147
|
+
status: block.is_error ? "failed" : "completed",
|
|
30148
|
+
outputText: extracted.text
|
|
30149
|
+
},
|
|
30150
|
+
state
|
|
30151
|
+
);
|
|
30152
|
+
}
|
|
30153
|
+
}
|
|
30154
|
+
function projectProgressMessage(state, message) {
|
|
30155
|
+
const toolCallId = String(message?.toolUseID ?? "").trim();
|
|
30156
|
+
if (!toolCallId) return;
|
|
30157
|
+
const content = String(
|
|
30158
|
+
message?.content?.message?.content?.find?.((block) => block?.type === "text")?.text ?? ""
|
|
30159
|
+
);
|
|
30160
|
+
const extractedProgressText = extractTaggedText(content, "tool-progress");
|
|
30161
|
+
const normalizedContent = content.trim();
|
|
30162
|
+
const toolProgressText = extractedProgressText ?? (normalizedContent.length > 0 ? normalizedContent : void 0);
|
|
30163
|
+
if (toolProgressText) {
|
|
30164
|
+
state.parts.push(
|
|
30165
|
+
createSystemEventPart({
|
|
30166
|
+
requestId: state.requestId,
|
|
30167
|
+
eventType: "tool_progress",
|
|
30168
|
+
text: toolProgressText,
|
|
30169
|
+
toolCallId,
|
|
30170
|
+
source: state.source
|
|
30171
|
+
})
|
|
30172
|
+
);
|
|
30173
|
+
}
|
|
30174
|
+
onToolResult(
|
|
30175
|
+
{
|
|
30176
|
+
toolCallId,
|
|
30177
|
+
status: "running",
|
|
30178
|
+
outputText: content || void 0
|
|
30179
|
+
},
|
|
30180
|
+
state
|
|
30181
|
+
);
|
|
30182
|
+
}
|
|
30183
|
+
function createStreamTypedProjector(options) {
|
|
30184
|
+
const provider = String(options.provider ?? "").trim().toLowerCase();
|
|
30185
|
+
return {
|
|
30186
|
+
state: createAssemblerState(options.requestId, options.source ?? "query_main"),
|
|
30187
|
+
provider,
|
|
30188
|
+
supportsRichToolResult: typeof options.supportsRichToolResult === "boolean" ? options.supportsRichToolResult : supportsRichToolResultByProvider(provider),
|
|
30189
|
+
richToolResultBlockCount: 0,
|
|
30190
|
+
downgradedToolResultCount: 0
|
|
30191
|
+
};
|
|
30192
|
+
}
|
|
30193
|
+
function consumeProjectorCompatibilityMetrics(projector) {
|
|
30194
|
+
const snapshot = {
|
|
30195
|
+
provider: projector.provider || "unknown",
|
|
30196
|
+
supportsRichToolResult: projector.supportsRichToolResult,
|
|
30197
|
+
richToolResultBlockCount: projector.richToolResultBlockCount,
|
|
30198
|
+
downgradedToolResultCount: projector.downgradedToolResultCount
|
|
30199
|
+
};
|
|
30200
|
+
projector.richToolResultBlockCount = 0;
|
|
30201
|
+
projector.downgradedToolResultCount = 0;
|
|
30202
|
+
return snapshot;
|
|
30203
|
+
}
|
|
30204
|
+
function projectMessageToTypedParts(projector, message) {
|
|
30205
|
+
if (!message || typeof message !== "object") return [];
|
|
30206
|
+
if (message.type === "assistant") {
|
|
30207
|
+
projectAssistantMessage(projector.state, message);
|
|
30208
|
+
} else if (message.type === "user") {
|
|
30209
|
+
projectUserToolResult(projector, message);
|
|
30210
|
+
} else if (message.type === "progress") {
|
|
30211
|
+
projectProgressMessage(projector.state, message);
|
|
30212
|
+
}
|
|
30213
|
+
return flushTypedParts(projector.state);
|
|
30214
|
+
}
|
|
30215
|
+
function projectLifecycleEventsToTypedParts(projector, events) {
|
|
30216
|
+
if (!Array.isArray(events) || events.length === 0) return [];
|
|
30217
|
+
const parts = [];
|
|
30218
|
+
for (const event of events) {
|
|
30219
|
+
if (!event || typeof event !== "object") continue;
|
|
30220
|
+
if (event.eventType === "start-step") {
|
|
30221
|
+
parts.push(
|
|
30222
|
+
createStepStartPart({
|
|
30223
|
+
requestId: projector.state.requestId,
|
|
30224
|
+
stepId: event.stepId,
|
|
30225
|
+
timeStart: event.timestamp,
|
|
30226
|
+
source: projector.state.source
|
|
30227
|
+
})
|
|
30228
|
+
);
|
|
30229
|
+
continue;
|
|
30230
|
+
}
|
|
30231
|
+
if (event.eventType === "finish-step") {
|
|
30232
|
+
parts.push(
|
|
30233
|
+
createStepFinishPart({
|
|
30234
|
+
requestId: projector.state.requestId,
|
|
30235
|
+
stepId: event.stepId,
|
|
30236
|
+
reason: event.reason,
|
|
30237
|
+
completedAt: event.completedAt,
|
|
30238
|
+
costUSD: event.costUSD,
|
|
30239
|
+
...event.tokens ? { tokens: event.tokens } : {},
|
|
30240
|
+
source: projector.state.source
|
|
30241
|
+
})
|
|
30242
|
+
);
|
|
30243
|
+
}
|
|
30244
|
+
}
|
|
30245
|
+
return parts;
|
|
30246
|
+
}
|
|
30247
|
+
|
|
30248
|
+
// src/services/ai/streamTyped/skeletonReader.ts
|
|
30249
|
+
function pushText(parts, value) {
|
|
30250
|
+
const text = String(value ?? "").trim();
|
|
30251
|
+
if (!text) return;
|
|
30252
|
+
parts.push({ type: "text", text });
|
|
30253
|
+
}
|
|
30254
|
+
function getToolState(part) {
|
|
30255
|
+
if (part.partType !== "tool") return null;
|
|
30256
|
+
const payload = part.payload;
|
|
30257
|
+
return payload?.state ?? null;
|
|
30258
|
+
}
|
|
30259
|
+
function buildSkeletonBlocksFromTypedParts(input) {
|
|
30260
|
+
const result = [];
|
|
30261
|
+
for (const part of input.parts) {
|
|
30262
|
+
if (!part || typeof part !== "object") continue;
|
|
30263
|
+
if (part.partType === "text") {
|
|
30264
|
+
pushText(result, part.payload?.text);
|
|
30265
|
+
continue;
|
|
30266
|
+
}
|
|
30267
|
+
if (part.partType === "reasoning" && input.role === "assistant") {
|
|
30268
|
+
const reasoning = String(part.payload?.text ?? "").trim();
|
|
30269
|
+
if (!reasoning) continue;
|
|
30270
|
+
result.push({ type: "reasoning", reasoning });
|
|
30271
|
+
continue;
|
|
30272
|
+
}
|
|
30273
|
+
if (part.partType !== "tool") continue;
|
|
30274
|
+
const payload = part.payload;
|
|
30275
|
+
const state = getToolState(part);
|
|
30276
|
+
const status = String(
|
|
30277
|
+
state?.status ?? payload?.status ?? ""
|
|
30278
|
+
).toLowerCase();
|
|
30279
|
+
const toolName = String(payload?.toolName ?? "").trim();
|
|
30280
|
+
const toolCallId = String(payload?.toolCallId ?? "").trim();
|
|
30281
|
+
if (!toolCallId) continue;
|
|
30282
|
+
if (input.role === "assistant") {
|
|
30283
|
+
if (status !== "pending") continue;
|
|
30284
|
+
result.push({
|
|
30285
|
+
type: "tool_use",
|
|
30286
|
+
id: toolCallId,
|
|
30287
|
+
name: toolName || "unknown",
|
|
30288
|
+
input: state?.input && typeof state.input === "object" ? state.input : payload?.input && typeof payload.input === "object" ? payload.input : {}
|
|
30289
|
+
});
|
|
30290
|
+
continue;
|
|
30291
|
+
}
|
|
30292
|
+
if (status !== "completed" && status !== "failed" && status !== "interrupted") {
|
|
30293
|
+
continue;
|
|
30294
|
+
}
|
|
30295
|
+
const content = String(
|
|
30296
|
+
state?.output ?? state?.error ?? state?.reason ?? payload?.outputText ?? ""
|
|
30297
|
+
).trim();
|
|
30298
|
+
result.push({
|
|
30299
|
+
type: "tool_result",
|
|
30300
|
+
tool_use_id: toolCallId,
|
|
30301
|
+
content,
|
|
30302
|
+
...status === "failed" ? { is_error: true } : {}
|
|
30303
|
+
});
|
|
30304
|
+
}
|
|
30305
|
+
return result;
|
|
30306
|
+
}
|
|
30307
|
+
|
|
30043
30308
|
// src/app/queryLifecycleEvents.ts
|
|
30044
30309
|
function createStepId(input) {
|
|
30045
30310
|
const base = (input.queryId || input.requestId || "unknown").replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
@@ -30274,13 +30539,6 @@ function resolveQuerySessionFeatureFlags() {
|
|
|
30274
30539
|
rolloutReason: "rollout_disabled"
|
|
30275
30540
|
};
|
|
30276
30541
|
}
|
|
30277
|
-
function buildQueryTypedRequestId(args) {
|
|
30278
|
-
if (args.currentRequestId) return `query_${args.currentRequestId}`;
|
|
30279
|
-
if (args.fallbackQueryId) return `query_${args.fallbackQueryId}`;
|
|
30280
|
-
const now = args.now ?? Date.now();
|
|
30281
|
-
const randomSuffix = args.randomSuffix ?? Math.random().toString(36).slice(2, 10);
|
|
30282
|
-
return `query_${now}_${randomSuffix}`;
|
|
30283
|
-
}
|
|
30284
30542
|
function prepareQueryTypedProjector(args) {
|
|
30285
30543
|
const modelPointer = args.modelPointer || "main";
|
|
30286
30544
|
const modelResolution = args.resolveModelWithInfo(modelPointer);
|
|
@@ -30290,16 +30548,7 @@ function prepareQueryTypedProjector(args) {
|
|
|
30290
30548
|
source: "query_main",
|
|
30291
30549
|
provider: typedProvider
|
|
30292
30550
|
});
|
|
30293
|
-
return {
|
|
30294
|
-
}
|
|
30295
|
-
function findLatestValue(args) {
|
|
30296
|
-
for (let index = args.items.length - 1; index >= 0; index -= 1) {
|
|
30297
|
-
const value = args.selectValue(args.items[index]);
|
|
30298
|
-
if (value !== void 0 && value !== null) {
|
|
30299
|
-
return value;
|
|
30300
|
-
}
|
|
30301
|
-
}
|
|
30302
|
-
return void 0;
|
|
30551
|
+
return { typedProjector };
|
|
30303
30552
|
}
|
|
30304
30553
|
function prepareQuerySessionExecution(args) {
|
|
30305
30554
|
args.onRolloutApplied(args.featureFlags);
|
|
@@ -30321,14 +30570,15 @@ function prepareQuerySessionExecution(args) {
|
|
|
30321
30570
|
}
|
|
30322
30571
|
function prepareQuerySessionPrimaryPlan(args) {
|
|
30323
30572
|
const shouldPersistSession = args.toolUseContext.options?.persistSession !== false && !args.isTestEnv;
|
|
30324
|
-
|
|
30325
|
-
|
|
30326
|
-
|
|
30327
|
-
|
|
30328
|
-
|
|
30329
|
-
|
|
30330
|
-
|
|
30331
|
-
}
|
|
30573
|
+
let fallbackQueryId;
|
|
30574
|
+
for (let index = args.messages.length - 1; index >= 0; index -= 1) {
|
|
30575
|
+
const value = args.extractUserQueryId(args.messages[index]);
|
|
30576
|
+
if (value !== void 0 && value !== null) {
|
|
30577
|
+
fallbackQueryId = value;
|
|
30578
|
+
break;
|
|
30579
|
+
}
|
|
30580
|
+
}
|
|
30581
|
+
const typedRequestId = args.currentRequestId ? `query_${args.currentRequestId}` : fallbackQueryId ? `query_${fallbackQueryId}` : `query_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
30332
30582
|
args.policyCoordinator?.setRequestId(typedRequestId);
|
|
30333
30583
|
const { typedProjector } = prepareQueryTypedProjector({
|
|
30334
30584
|
requestId: typedRequestId,
|
|
@@ -30466,28 +30716,19 @@ async function* runQuerySessionPrimaryAdapter(args) {
|
|
|
30466
30716
|
runner: runQuerySessionPrimary
|
|
30467
30717
|
});
|
|
30468
30718
|
}
|
|
30469
|
-
async function*
|
|
30719
|
+
async function* runQuerySessionLegacyCompatAdapter(args) {
|
|
30470
30720
|
const primaryInput = createQuerySessionPrimaryAdapterInput(args);
|
|
30471
30721
|
yield* runSessionCompatStreams({
|
|
30472
|
-
routingContext: args.routingContext,
|
|
30473
|
-
primaryInput,
|
|
30474
|
-
primaryRunner: runQuerySessionPrimaryAdapter,
|
|
30475
|
-
fallbackInput: args.fallbackInput,
|
|
30476
|
-
fallbackRunner: args.fallbackRunner,
|
|
30477
|
-
toolUseContext: args.toolUseContext
|
|
30478
|
-
});
|
|
30479
|
-
}
|
|
30480
|
-
async function* runQuerySessionLegacyCompatAdapter(args) {
|
|
30481
|
-
const streamRunner = args.stream;
|
|
30482
|
-
yield* runQuerySessionCompatAdapter({
|
|
30483
|
-
...args,
|
|
30484
30722
|
routingContext: {
|
|
30485
30723
|
sessionId: args.toolUseContext.sessionId,
|
|
30486
30724
|
agentId: args.toolUseContext.agentId,
|
|
30487
30725
|
requestId: args.requestId
|
|
30488
30726
|
},
|
|
30727
|
+
primaryInput,
|
|
30728
|
+
primaryRunner: runQuerySessionPrimaryAdapter,
|
|
30489
30729
|
fallbackInput: args.messages,
|
|
30490
|
-
fallbackRunner:
|
|
30730
|
+
fallbackRunner: args.stream,
|
|
30731
|
+
toolUseContext: args.toolUseContext
|
|
30491
30732
|
});
|
|
30492
30733
|
}
|
|
30493
30734
|
function processQuerySessionTypedOutput(args) {
|
|
@@ -30577,38 +30818,16 @@ async function* runSessionOrchestrator(args) {
|
|
|
30577
30818
|
runner: selectedRunner
|
|
30578
30819
|
});
|
|
30579
30820
|
}
|
|
30580
|
-
function
|
|
30581
|
-
|
|
30582
|
-
}
|
|
30583
|
-
async function* runSessionOrchestratorWithContext(args) {
|
|
30584
|
-
const replaySeed = createSessionReplaySeed(args.routingContext);
|
|
30821
|
+
async function* runSessionCompatStreams(args) {
|
|
30822
|
+
const sessionContext = ensureSessionContext(args.toolUseContext);
|
|
30823
|
+
const replaySeed = `${args.routingContext.sessionId ?? ""}:${args.routingContext.agentId ?? ""}:${args.routingContext.requestId ?? ""}`;
|
|
30585
30824
|
yield* runSessionOrchestrator({
|
|
30586
|
-
input: args.input,
|
|
30587
|
-
replaySeed,
|
|
30588
|
-
sessionRunner: args.sessionRunner,
|
|
30589
|
-
fallbackRunner: args.fallbackRunner
|
|
30590
|
-
});
|
|
30591
|
-
}
|
|
30592
|
-
async function* runSessionOrchestratorStreams(args) {
|
|
30593
|
-
yield* runSessionOrchestratorWithContext({
|
|
30594
30825
|
input: void 0,
|
|
30595
|
-
|
|
30826
|
+
replaySeed,
|
|
30596
30827
|
sessionRunner: async function* () {
|
|
30597
|
-
yield* args.sessionStream();
|
|
30598
|
-
},
|
|
30599
|
-
fallbackRunner: async function* () {
|
|
30600
|
-
yield* args.fallbackStream();
|
|
30601
|
-
}
|
|
30602
|
-
});
|
|
30603
|
-
}
|
|
30604
|
-
async function* runSessionCompatStreams(args) {
|
|
30605
|
-
const sessionContext = ensureSessionContext(args.toolUseContext);
|
|
30606
|
-
yield* runSessionOrchestratorStreams({
|
|
30607
|
-
routingContext: args.routingContext,
|
|
30608
|
-
sessionStream: async function* () {
|
|
30609
30828
|
yield* args.primaryRunner(args.primaryInput);
|
|
30610
30829
|
},
|
|
30611
|
-
|
|
30830
|
+
fallbackRunner: async function* () {
|
|
30612
30831
|
yield* runSessionWithEngine({
|
|
30613
30832
|
input: args.fallbackInput,
|
|
30614
30833
|
sessionContext,
|
|
@@ -30653,75 +30872,81 @@ function resolveSessionEngineReplaySample(replaySeed) {
|
|
|
30653
30872
|
return hash % 100;
|
|
30654
30873
|
}
|
|
30655
30874
|
|
|
30656
|
-
// src/app/queryRuntime/
|
|
30657
|
-
var
|
|
30658
|
-
|
|
30659
|
-
|
|
30660
|
-
|
|
30661
|
-
|
|
30662
|
-
|
|
30663
|
-
|
|
30664
|
-
|
|
30665
|
-
|
|
30666
|
-
|
|
30667
|
-
|
|
30668
|
-
|
|
30669
|
-
|
|
30670
|
-
|
|
30875
|
+
// src/app/queryRuntime/lifecycle.ts
|
|
30876
|
+
var TOOL_PROGRESS_OPEN_TAG = ["<tool", "-progress>"].join("");
|
|
30877
|
+
var TOOL_PROGRESS_CLOSE_TAG = ["</tool", "-progress>"].join("");
|
|
30878
|
+
function isTextBlock(block) {
|
|
30879
|
+
return Boolean(
|
|
30880
|
+
block && typeof block === "object" && block.type === "text"
|
|
30881
|
+
);
|
|
30882
|
+
}
|
|
30883
|
+
function isToolResultBlock(block) {
|
|
30884
|
+
return Boolean(
|
|
30885
|
+
block && typeof block === "object" && block.type === "tool_result"
|
|
30886
|
+
);
|
|
30887
|
+
}
|
|
30888
|
+
function inferIsNewSessionForAutoCompact(messages) {
|
|
30889
|
+
const naturalMessages = messages.filter(
|
|
30890
|
+
(message) => message?.type === "user" || message?.type === "assistant"
|
|
30891
|
+
);
|
|
30892
|
+
const hasCompactionMarker = naturalMessages.some(
|
|
30893
|
+
(message) => message?.compaction?.type === "compaction"
|
|
30894
|
+
);
|
|
30895
|
+
return !hasCompactionMarker && naturalMessages.length <= 2;
|
|
30896
|
+
}
|
|
30897
|
+
function extractUserPromptTextFromMessages(messages) {
|
|
30898
|
+
const last2 = messages[messages.length - 1];
|
|
30899
|
+
if (!last2 || typeof last2 !== "object" || last2.type !== "user") {
|
|
30900
|
+
return null;
|
|
30671
30901
|
}
|
|
30672
|
-
const
|
|
30673
|
-
if (
|
|
30674
|
-
|
|
30902
|
+
const content = last2.message?.content;
|
|
30903
|
+
if (typeof content === "string") {
|
|
30904
|
+
return content;
|
|
30675
30905
|
}
|
|
30676
|
-
if (
|
|
30677
|
-
|
|
30906
|
+
if (!Array.isArray(content)) {
|
|
30907
|
+
return null;
|
|
30678
30908
|
}
|
|
30679
|
-
const
|
|
30680
|
-
if (
|
|
30681
|
-
return
|
|
30909
|
+
const hasToolResult = content.some((block) => isToolResultBlock(block));
|
|
30910
|
+
if (hasToolResult) {
|
|
30911
|
+
return null;
|
|
30682
30912
|
}
|
|
30683
|
-
|
|
30684
|
-
const start = fullMessage.slice(0, halfLength);
|
|
30685
|
-
const end = fullMessage.slice(-halfLength);
|
|
30686
|
-
return `${start}
|
|
30687
|
-
|
|
30688
|
-
... [${fullMessage.length - 1e4} characters truncated] ...
|
|
30689
|
-
|
|
30690
|
-
${end}`;
|
|
30913
|
+
return content.filter(isTextBlock).map((block) => String(block.text ?? "")).join("");
|
|
30691
30914
|
}
|
|
30692
|
-
function
|
|
30693
|
-
if (!
|
|
30915
|
+
function resolveLifecycleTokensFromUsage(usage) {
|
|
30916
|
+
if (!usage || typeof usage !== "object") {
|
|
30694
30917
|
return void 0;
|
|
30695
30918
|
}
|
|
30696
|
-
|
|
30697
|
-
|
|
30919
|
+
const usageLike = usage;
|
|
30920
|
+
const input = Number.isFinite(Number(usageLike.input_tokens)) ? Number(usageLike.input_tokens) : void 0;
|
|
30921
|
+
const output = Number.isFinite(Number(usageLike.output_tokens)) ? Number(usageLike.output_tokens) : void 0;
|
|
30922
|
+
if (input === void 0 && output === void 0) {
|
|
30923
|
+
return void 0;
|
|
30698
30924
|
}
|
|
30699
|
-
return
|
|
30700
|
-
}
|
|
30701
|
-
|
|
30702
|
-
|
|
30703
|
-
|
|
30704
|
-
return summary.length > 200 ? summary.slice(0, 200) : summary;
|
|
30925
|
+
return {
|
|
30926
|
+
...input === void 0 ? {} : { input },
|
|
30927
|
+
...output === void 0 ? {} : { output },
|
|
30928
|
+
total: (input ?? 0) + (output ?? 0)
|
|
30929
|
+
};
|
|
30705
30930
|
}
|
|
30706
|
-
function
|
|
30707
|
-
if (!
|
|
30708
|
-
|
|
30931
|
+
function resolveLifecycleTokensFromAssistantMessage(assistantMessage) {
|
|
30932
|
+
if (!assistantMessage || typeof assistantMessage !== "object") {
|
|
30933
|
+
return void 0;
|
|
30934
|
+
}
|
|
30935
|
+
const message = assistantMessage.message;
|
|
30936
|
+
if (!message || typeof message !== "object") {
|
|
30937
|
+
return void 0;
|
|
30938
|
+
}
|
|
30939
|
+
return resolveLifecycleTokensFromUsage(
|
|
30940
|
+
message.usage
|
|
30941
|
+
);
|
|
30709
30942
|
}
|
|
30710
|
-
function
|
|
30711
|
-
const
|
|
30712
|
-
const
|
|
30713
|
-
const
|
|
30714
|
-
const summary = detail ? summarizeError(detail) : "";
|
|
30943
|
+
function resolveStopHookSignal(args) {
|
|
30944
|
+
const hookEvent = args.agentId && args.agentId !== "main" ? "SubagentStop" : "Stop";
|
|
30945
|
+
const rawStopReason = args.assistantMessage && typeof args.assistantMessage === "object" && args.assistantMessage.message ? args.assistantMessage.message?.stop_reason ?? args.assistantMessage.message?.stopReason : void 0;
|
|
30946
|
+
const stopReason = rawStopReason ?? "end_turn";
|
|
30715
30947
|
return {
|
|
30716
|
-
|
|
30717
|
-
|
|
30718
|
-
is_error: true,
|
|
30719
|
-
tool_use_id: args.toolUseId,
|
|
30720
|
-
error_class: errorClass,
|
|
30721
|
-
...errorCode ? { error_code: errorCode } : {},
|
|
30722
|
-
...summary ? { error_summary: summary } : {},
|
|
30723
|
-
...detail ? { error_detail: detail } : {},
|
|
30724
|
-
...args.rootToolUseId ? { root_tool_use_id: args.rootToolUseId } : {}
|
|
30948
|
+
hookEvent,
|
|
30949
|
+
stopReason: String(stopReason ?? "")
|
|
30725
30950
|
};
|
|
30726
30951
|
}
|
|
30727
30952
|
|
|
@@ -30766,282 +30991,101 @@ function preprocessToolInput(tool, input) {
|
|
|
30766
30991
|
return input;
|
|
30767
30992
|
}
|
|
30768
30993
|
|
|
30769
|
-
// src/app/queryRuntime/
|
|
30770
|
-
|
|
30771
|
-
|
|
30772
|
-
|
|
30773
|
-
|
|
30774
|
-
(
|
|
30775
|
-
|
|
30776
|
-
|
|
30777
|
-
|
|
30778
|
-
|
|
30779
|
-
|
|
30780
|
-
|
|
30781
|
-
|
|
30782
|
-
|
|
30783
|
-
|
|
30784
|
-
|
|
30785
|
-
|
|
30786
|
-
|
|
30787
|
-
|
|
30788
|
-
|
|
30789
|
-
|
|
30790
|
-
|
|
30791
|
-
|
|
30792
|
-
|
|
30793
|
-
|
|
30794
|
-
|
|
30795
|
-
}).map((block) => String(block.text ?? "")).join("\n");
|
|
30796
|
-
return { text, hasNonTextBlock };
|
|
30797
|
-
}
|
|
30798
|
-
function extractTaggedText(text, tagName) {
|
|
30799
|
-
const normalized = String(text ?? "").trim();
|
|
30800
|
-
if (!normalized.startsWith(`<${tagName}>`)) return null;
|
|
30801
|
-
const pattern = new RegExp(`<${tagName}>([\\s\\S]*?)<\\/${tagName}>`, "i");
|
|
30802
|
-
const match = normalized.match(pattern);
|
|
30803
|
-
const content = String(match?.[1] ?? "").trim();
|
|
30804
|
-
return content.length > 0 ? content : null;
|
|
30805
|
-
}
|
|
30806
|
-
function projectAssistantMessage(state, message) {
|
|
30807
|
-
const content = message?.message?.content;
|
|
30808
|
-
if (!Array.isArray(content)) return;
|
|
30809
|
-
for (let i = 0; i < content.length; i += 1) {
|
|
30810
|
-
const block = content[i];
|
|
30811
|
-
if (!block || typeof block !== "object") continue;
|
|
30812
|
-
const type3 = String(block.type ?? "");
|
|
30813
|
-
if (type3 === "text") {
|
|
30814
|
-
const text = String(block.text ?? "");
|
|
30815
|
-
const toolProgressText = extractTaggedText(text, "tool-progress");
|
|
30816
|
-
if (toolProgressText) {
|
|
30817
|
-
state.parts.push(
|
|
30818
|
-
createSystemEventPart({
|
|
30819
|
-
requestId: state.requestId,
|
|
30820
|
-
eventType: "tool_progress",
|
|
30821
|
-
text: toolProgressText,
|
|
30822
|
-
source: state.source
|
|
30823
|
-
})
|
|
30824
|
-
);
|
|
30825
|
-
}
|
|
30826
|
-
const localStdoutText = extractTaggedText(text, "local-command-stdout");
|
|
30827
|
-
if (localStdoutText) {
|
|
30828
|
-
state.parts.push(
|
|
30829
|
-
createSystemEventPart({
|
|
30830
|
-
requestId: state.requestId,
|
|
30831
|
-
eventType: "local_command_stdout",
|
|
30832
|
-
text: localStdoutText,
|
|
30833
|
-
source: state.source
|
|
30834
|
-
})
|
|
30835
|
-
);
|
|
30836
|
-
}
|
|
30837
|
-
const localStderrText = extractTaggedText(text, "local-command-stderr");
|
|
30838
|
-
if (localStderrText) {
|
|
30839
|
-
state.parts.push(
|
|
30840
|
-
createSystemEventPart({
|
|
30841
|
-
requestId: state.requestId,
|
|
30842
|
-
eventType: "local_command_stderr",
|
|
30843
|
-
text: localStderrText,
|
|
30844
|
-
source: state.source
|
|
30845
|
-
})
|
|
30846
|
-
);
|
|
30847
|
-
}
|
|
30848
|
-
onTextStart({ textId: `text-${i}` }, state);
|
|
30849
|
-
onTextDelta({ textId: `text-${i}`, text }, state);
|
|
30850
|
-
onTextEnd({ textId: `text-${i}` }, state);
|
|
30851
|
-
continue;
|
|
30852
|
-
}
|
|
30853
|
-
if (type3 === "thinking" || type3 === "reasoning") {
|
|
30854
|
-
const text = String(block.thinking ?? block.reasoning ?? "");
|
|
30855
|
-
onReasoningStart({ reasoningId: `reasoning-${i}` }, state);
|
|
30856
|
-
onReasoningDelta({ reasoningId: `reasoning-${i}`, text }, state);
|
|
30857
|
-
onReasoningEnd({ reasoningId: `reasoning-${i}` }, state);
|
|
30858
|
-
continue;
|
|
30859
|
-
}
|
|
30860
|
-
if (type3 === "tool_use" || type3 === "server_tool_use" || type3 === "mcp_tool_use") {
|
|
30861
|
-
const toolCallId = String(block.id ?? `tool-${i}`);
|
|
30862
|
-
const toolName = String(block.name ?? "unknown");
|
|
30863
|
-
onToolCall({ toolCallId, toolName }, state);
|
|
30864
|
-
}
|
|
30994
|
+
// src/app/queryRuntime/stopHooks.ts
|
|
30995
|
+
async function runStopHookAttempt(args) {
|
|
30996
|
+
const stopOutcome = await runStopHooks({
|
|
30997
|
+
hookEvent: args.hookEvent,
|
|
30998
|
+
reason: args.stopReason,
|
|
30999
|
+
retryEntryKey: buildRetryEntryKey([
|
|
31000
|
+
args.context.sessionId,
|
|
31001
|
+
args.context.parentSessionId,
|
|
31002
|
+
args.context.childSessionId,
|
|
31003
|
+
args.context.agentId,
|
|
31004
|
+
args.stopReason
|
|
31005
|
+
]),
|
|
31006
|
+
retryAttempt: args.stopHookAttempts,
|
|
31007
|
+
sessionId: args.context.sessionId,
|
|
31008
|
+
parentSessionId: args.context.parentSessionId,
|
|
31009
|
+
childSessionId: args.context.childSessionId,
|
|
31010
|
+
agentId: args.context.agentId,
|
|
31011
|
+
permissionMode: args.context.options?.toolPermissionContext?.mode,
|
|
31012
|
+
cwd: getCwd(),
|
|
31013
|
+
transcriptPath: getHookTranscriptPath(args.context),
|
|
31014
|
+
safeMode: args.context.options?.safeMode ?? false,
|
|
31015
|
+
stopHookActive: args.stopHookActive,
|
|
31016
|
+
signal: args.context.abortController.signal
|
|
31017
|
+
});
|
|
31018
|
+
if (stopOutcome.systemMessages.length > 0) {
|
|
31019
|
+
queueHookSystemMessages(args.context, stopOutcome.systemMessages);
|
|
30865
31020
|
}
|
|
30866
|
-
|
|
30867
|
-
|
|
30868
|
-
const state = projector.state;
|
|
30869
|
-
const content = message?.message?.content;
|
|
30870
|
-
if (!Array.isArray(content)) return;
|
|
30871
|
-
for (let i = 0; i < content.length; i += 1) {
|
|
30872
|
-
const block = content[i];
|
|
30873
|
-
if (!block || typeof block !== "object") continue;
|
|
30874
|
-
if (block.type !== "tool_result") continue;
|
|
30875
|
-
const toolCallId = String(block.tool_use_id ?? `tool-${i}`);
|
|
30876
|
-
const extracted = extractToolResultText2(block.content);
|
|
30877
|
-
if (extracted.hasNonTextBlock) {
|
|
30878
|
-
projector.richToolResultBlockCount += 1;
|
|
30879
|
-
if (!projector.supportsRichToolResult) {
|
|
30880
|
-
projector.downgradedToolResultCount += 1;
|
|
30881
|
-
}
|
|
30882
|
-
}
|
|
30883
|
-
onToolResult(
|
|
30884
|
-
{
|
|
30885
|
-
toolCallId,
|
|
30886
|
-
status: block.is_error ? "failed" : "completed",
|
|
30887
|
-
outputText: extracted.text
|
|
30888
|
-
},
|
|
30889
|
-
state
|
|
30890
|
-
);
|
|
31021
|
+
if (stopOutcome.additionalContexts.length > 0) {
|
|
31022
|
+
queueHookAdditionalContexts(args.context, stopOutcome.additionalContexts);
|
|
30891
31023
|
}
|
|
30892
|
-
|
|
30893
|
-
|
|
30894
|
-
|
|
30895
|
-
|
|
30896
|
-
|
|
30897
|
-
|
|
30898
|
-
);
|
|
30899
|
-
const
|
|
30900
|
-
|
|
30901
|
-
|
|
30902
|
-
|
|
30903
|
-
|
|
30904
|
-
|
|
30905
|
-
requestId: state.requestId,
|
|
30906
|
-
eventType: "tool_progress",
|
|
30907
|
-
text: toolProgressText,
|
|
30908
|
-
toolCallId,
|
|
30909
|
-
source: state.source
|
|
30910
|
-
})
|
|
30911
|
-
);
|
|
31024
|
+
if (stopOutcome.decision !== "block") {
|
|
31025
|
+
return {
|
|
31026
|
+
shouldRetry: false,
|
|
31027
|
+
nextStopHookAttempts: args.stopHookAttempts
|
|
31028
|
+
};
|
|
31029
|
+
}
|
|
31030
|
+
queueHookSystemMessages(args.context, [stopOutcome.message]);
|
|
31031
|
+
const maxStopHookAttempts = args.maxStopHookAttempts ?? 5;
|
|
31032
|
+
if (args.stopHookAttempts < maxStopHookAttempts) {
|
|
31033
|
+
return {
|
|
31034
|
+
shouldRetry: true,
|
|
31035
|
+
nextStopHookAttempts: args.stopHookAttempts + 1
|
|
31036
|
+
};
|
|
30912
31037
|
}
|
|
30913
|
-
onToolResult(
|
|
30914
|
-
{
|
|
30915
|
-
toolCallId,
|
|
30916
|
-
status: "running",
|
|
30917
|
-
outputText: content || void 0
|
|
30918
|
-
},
|
|
30919
|
-
state
|
|
30920
|
-
);
|
|
30921
|
-
}
|
|
30922
|
-
function createStreamTypedProjector(options) {
|
|
30923
|
-
const provider = String(options.provider ?? "").trim().toLowerCase();
|
|
30924
31038
|
return {
|
|
30925
|
-
|
|
30926
|
-
|
|
30927
|
-
supportsRichToolResult: typeof options.supportsRichToolResult === "boolean" ? options.supportsRichToolResult : supportsRichToolResultByProvider(provider),
|
|
30928
|
-
richToolResultBlockCount: 0,
|
|
30929
|
-
downgradedToolResultCount: 0
|
|
31039
|
+
shouldRetry: false,
|
|
31040
|
+
nextStopHookAttempts: args.stopHookAttempts
|
|
30930
31041
|
};
|
|
30931
31042
|
}
|
|
30932
|
-
|
|
30933
|
-
|
|
30934
|
-
|
|
30935
|
-
|
|
30936
|
-
|
|
30937
|
-
|
|
30938
|
-
};
|
|
30939
|
-
projector.richToolResultBlockCount = 0;
|
|
30940
|
-
projector.downgradedToolResultCount = 0;
|
|
30941
|
-
return snapshot;
|
|
31043
|
+
|
|
31044
|
+
// src/app/queryRuntime/toolQueue.ts
|
|
31045
|
+
function isToolResultErrorBlock(block) {
|
|
31046
|
+
return Boolean(
|
|
31047
|
+
block && typeof block === "object" && block.type === "tool_result" && block.is_error === true
|
|
31048
|
+
);
|
|
30942
31049
|
}
|
|
30943
|
-
function
|
|
30944
|
-
|
|
30945
|
-
|
|
30946
|
-
|
|
30947
|
-
|
|
30948
|
-
|
|
30949
|
-
|
|
30950
|
-
|
|
30951
|
-
|
|
30952
|
-
return flushTypedParts(projector.state);
|
|
31050
|
+
function createQueuedWaitingProgressMessage(args) {
|
|
31051
|
+
return createProgressMessage(
|
|
31052
|
+
args.toolUseId,
|
|
31053
|
+
args.siblingToolUseIDs,
|
|
31054
|
+
createAssistantMessage(`${args.openTag}Waiting\u2026${args.closeTag}`),
|
|
31055
|
+
[],
|
|
31056
|
+
args.tools,
|
|
31057
|
+
{ progressState: "queued_waiting" }
|
|
31058
|
+
);
|
|
30953
31059
|
}
|
|
30954
|
-
function
|
|
30955
|
-
if (
|
|
30956
|
-
|
|
30957
|
-
for (const event of events) {
|
|
30958
|
-
if (!event || typeof event !== "object") continue;
|
|
30959
|
-
if (event.eventType === "start-step") {
|
|
30960
|
-
parts.push(
|
|
30961
|
-
createStepStartPart({
|
|
30962
|
-
requestId: projector.state.requestId,
|
|
30963
|
-
stepId: event.stepId,
|
|
30964
|
-
timeStart: event.timestamp,
|
|
30965
|
-
source: projector.state.source
|
|
30966
|
-
})
|
|
30967
|
-
);
|
|
30968
|
-
continue;
|
|
30969
|
-
}
|
|
30970
|
-
if (event.eventType === "finish-step") {
|
|
30971
|
-
parts.push(
|
|
30972
|
-
createStepFinishPart({
|
|
30973
|
-
requestId: projector.state.requestId,
|
|
30974
|
-
stepId: event.stepId,
|
|
30975
|
-
reason: event.reason,
|
|
30976
|
-
completedAt: event.completedAt,
|
|
30977
|
-
costUSD: event.costUSD,
|
|
30978
|
-
...event.tokens ? { tokens: event.tokens } : {},
|
|
30979
|
-
source: projector.state.source
|
|
30980
|
-
})
|
|
30981
|
-
);
|
|
30982
|
-
}
|
|
31060
|
+
function resolveToolQueueContextModifier(message) {
|
|
31061
|
+
if (message.type !== "user") {
|
|
31062
|
+
return void 0;
|
|
30983
31063
|
}
|
|
30984
|
-
|
|
31064
|
+
const modifyContext = message.toolUseResult?.contextModifier?.modifyContext;
|
|
31065
|
+
return typeof modifyContext === "function" ? modifyContext : void 0;
|
|
30985
31066
|
}
|
|
30986
|
-
|
|
30987
|
-
|
|
30988
|
-
function pushText(parts, value) {
|
|
30989
|
-
const text = String(value ?? "").trim();
|
|
30990
|
-
if (!text) return;
|
|
30991
|
-
parts.push({ type: "text", text });
|
|
31067
|
+
function isToolQueueNextTurnMessage(message) {
|
|
31068
|
+
return message.type === "user" || message.type === "assistant";
|
|
30992
31069
|
}
|
|
30993
|
-
function
|
|
30994
|
-
if (
|
|
30995
|
-
|
|
30996
|
-
return payload?.state ?? null;
|
|
30997
|
-
}
|
|
30998
|
-
function buildSkeletonBlocksFromTypedParts(input) {
|
|
30999
|
-
const result = [];
|
|
31000
|
-
for (const part of input.parts) {
|
|
31001
|
-
if (!part || typeof part !== "object") continue;
|
|
31002
|
-
if (part.partType === "text") {
|
|
31003
|
-
pushText(result, part.payload?.text);
|
|
31004
|
-
continue;
|
|
31005
|
-
}
|
|
31006
|
-
if (part.partType === "reasoning" && input.role === "assistant") {
|
|
31007
|
-
const reasoning = String(part.payload?.text ?? "").trim();
|
|
31008
|
-
if (!reasoning) continue;
|
|
31009
|
-
result.push({ type: "reasoning", reasoning });
|
|
31010
|
-
continue;
|
|
31011
|
-
}
|
|
31012
|
-
if (part.partType !== "tool") continue;
|
|
31013
|
-
const payload = part.payload;
|
|
31014
|
-
const state = getToolState(part);
|
|
31015
|
-
const status = String(
|
|
31016
|
-
state?.status ?? payload?.status ?? ""
|
|
31017
|
-
).toLowerCase();
|
|
31018
|
-
const toolName = String(payload?.toolName ?? "").trim();
|
|
31019
|
-
const toolCallId = String(payload?.toolCallId ?? "").trim();
|
|
31020
|
-
if (!toolCallId) continue;
|
|
31021
|
-
if (input.role === "assistant") {
|
|
31022
|
-
if (status !== "pending") continue;
|
|
31023
|
-
result.push({
|
|
31024
|
-
type: "tool_use",
|
|
31025
|
-
id: toolCallId,
|
|
31026
|
-
name: toolName || "unknown",
|
|
31027
|
-
input: state?.input && typeof state.input === "object" ? state.input : payload?.input && typeof payload.input === "object" ? payload.input : {}
|
|
31028
|
-
});
|
|
31029
|
-
continue;
|
|
31030
|
-
}
|
|
31031
|
-
if (status !== "completed" && status !== "failed" && status !== "interrupted") {
|
|
31032
|
-
continue;
|
|
31033
|
-
}
|
|
31034
|
-
const content = String(
|
|
31035
|
-
state?.output ?? state?.error ?? state?.reason ?? payload?.outputText ?? ""
|
|
31036
|
-
).trim();
|
|
31037
|
-
result.push({
|
|
31038
|
-
type: "tool_result",
|
|
31039
|
-
tool_use_id: toolCallId,
|
|
31040
|
-
content,
|
|
31041
|
-
...status === "failed" ? { is_error: true } : {}
|
|
31042
|
-
});
|
|
31070
|
+
function resolveToolQueueUserMessageErrorState(message) {
|
|
31071
|
+
if (message.type !== "user") {
|
|
31072
|
+
return { toolErrored: false };
|
|
31043
31073
|
}
|
|
31044
|
-
|
|
31074
|
+
const content = message.message?.content;
|
|
31075
|
+
if (!Array.isArray(content)) {
|
|
31076
|
+
return { toolErrored: false };
|
|
31077
|
+
}
|
|
31078
|
+
const errorBlocks = content.filter(
|
|
31079
|
+
(block) => isToolResultErrorBlock(block)
|
|
31080
|
+
);
|
|
31081
|
+
if (errorBlocks.length === 0) {
|
|
31082
|
+
return { toolErrored: false };
|
|
31083
|
+
}
|
|
31084
|
+
const fatalBlock = errorBlocks.find((block) => block.error_class === "fatal");
|
|
31085
|
+
if (fatalBlock && typeof fatalBlock.tool_use_id === "string") {
|
|
31086
|
+
return { toolErrored: true, fatalToolUseId: fatalBlock.tool_use_id };
|
|
31087
|
+
}
|
|
31088
|
+
return { toolErrored: true };
|
|
31045
31089
|
}
|
|
31046
31090
|
|
|
31047
31091
|
// src/utils/session/singleFactLayer.ts
|
|
@@ -31080,18 +31124,77 @@ function normalizeMessagesForSingleFactLayer(messages) {
|
|
|
31080
31124
|
});
|
|
31081
31125
|
}
|
|
31082
31126
|
|
|
31083
|
-
// src/app/queryRuntime/
|
|
31084
|
-
var
|
|
31085
|
-
|
|
31086
|
-
|
|
31087
|
-
|
|
31088
|
-
|
|
31089
|
-
|
|
31090
|
-
|
|
31091
|
-
|
|
31092
|
-
|
|
31093
|
-
|
|
31127
|
+
// src/app/queryRuntime/errorMapping.ts
|
|
31128
|
+
var ERROR_CLASS_BY_CODE = {
|
|
31129
|
+
ENOENT: "soft",
|
|
31130
|
+
EISDIR: "soft",
|
|
31131
|
+
EACCES: "retryable",
|
|
31132
|
+
EPERM: "retryable",
|
|
31133
|
+
EMFILE: "retryable",
|
|
31134
|
+
ENFILE: "retryable",
|
|
31135
|
+
EIO: "fatal",
|
|
31136
|
+
ENODEV: "fatal",
|
|
31137
|
+
EBUSY: "fatal"
|
|
31094
31138
|
};
|
|
31139
|
+
function formatError(error) {
|
|
31140
|
+
if (!(error instanceof Error)) {
|
|
31141
|
+
return String(error);
|
|
31142
|
+
}
|
|
31143
|
+
const parts = [error.message];
|
|
31144
|
+
if ("stderr" in error && typeof error.stderr === "string") {
|
|
31145
|
+
parts.push(error.stderr);
|
|
31146
|
+
}
|
|
31147
|
+
if ("stdout" in error && typeof error.stdout === "string") {
|
|
31148
|
+
parts.push(error.stdout);
|
|
31149
|
+
}
|
|
31150
|
+
const fullMessage = parts.filter(Boolean).join("\n");
|
|
31151
|
+
if (fullMessage.length <= 1e4) {
|
|
31152
|
+
return fullMessage;
|
|
31153
|
+
}
|
|
31154
|
+
const halfLength = 5e3;
|
|
31155
|
+
const start = fullMessage.slice(0, halfLength);
|
|
31156
|
+
const end = fullMessage.slice(-halfLength);
|
|
31157
|
+
return `${start}
|
|
31158
|
+
|
|
31159
|
+
... [${fullMessage.length - 1e4} characters truncated] ...
|
|
31160
|
+
|
|
31161
|
+
${end}`;
|
|
31162
|
+
}
|
|
31163
|
+
function extractErrorCode(error) {
|
|
31164
|
+
if (!error || typeof error !== "object") {
|
|
31165
|
+
return void 0;
|
|
31166
|
+
}
|
|
31167
|
+
if ("code" in error && typeof error.code === "string") {
|
|
31168
|
+
return error.code;
|
|
31169
|
+
}
|
|
31170
|
+
return void 0;
|
|
31171
|
+
}
|
|
31172
|
+
function summarizeError(detail) {
|
|
31173
|
+
const line = detail.split("\n").map((part) => part.trim()).find((part) => part.length > 0);
|
|
31174
|
+
const summary = line ?? detail.trim();
|
|
31175
|
+
return summary.length > 200 ? summary.slice(0, 200) : summary;
|
|
31176
|
+
}
|
|
31177
|
+
function getErrorClassFromCode(errorCode) {
|
|
31178
|
+
if (!errorCode) return "soft";
|
|
31179
|
+
return ERROR_CLASS_BY_CODE[errorCode] ?? "soft";
|
|
31180
|
+
}
|
|
31181
|
+
function createErrorToolResultBlock(args) {
|
|
31182
|
+
const detail = typeof args.errorDetail === "string" ? args.errorDetail : typeof args.content === "string" ? args.content : JSON.stringify(args.content);
|
|
31183
|
+
const errorCode = args.errorCode;
|
|
31184
|
+
const errorClass = args.errorClass ?? getErrorClassFromCode(errorCode);
|
|
31185
|
+
const summary = detail ? summarizeError(detail) : "";
|
|
31186
|
+
return {
|
|
31187
|
+
type: "tool_result",
|
|
31188
|
+
content: args.content,
|
|
31189
|
+
is_error: true,
|
|
31190
|
+
tool_use_id: args.toolUseId,
|
|
31191
|
+
error_class: errorClass,
|
|
31192
|
+
...errorCode ? { error_code: errorCode } : {},
|
|
31193
|
+
...summary ? { error_summary: summary } : {},
|
|
31194
|
+
...detail ? { error_detail: detail } : {},
|
|
31195
|
+
...args.rootToolUseId ? { root_tool_use_id: args.rootToolUseId } : {}
|
|
31196
|
+
};
|
|
31197
|
+
}
|
|
31095
31198
|
|
|
31096
31199
|
// src/app/queryRuntime/toolExecution.ts
|
|
31097
31200
|
function buildToolHookBaseArgs(context, toolUseId) {
|
|
@@ -31123,23 +31226,6 @@ function applyHookOutcomeSideEffects(context, hookOutcome) {
|
|
|
31123
31226
|
queueHookAdditionalContexts(context, hookOutcome.additionalContexts);
|
|
31124
31227
|
}
|
|
31125
31228
|
}
|
|
31126
|
-
function resolvePermissionExecutionPlan(args) {
|
|
31127
|
-
const effectiveShouldSkipPermissionCheck = args.hookPermissionDecision === "allow" ? true : args.hookPermissionDecision === "ask" ? false : args.shouldSkipPermissionCheck;
|
|
31128
|
-
const permissionContextForCall = args.hookPermissionDecision === "ask" && args.context.options?.toolPermissionContext && args.context.options.toolPermissionContext.mode !== "default" ? {
|
|
31129
|
-
...args.context,
|
|
31130
|
-
options: {
|
|
31131
|
-
...args.context.options,
|
|
31132
|
-
toolPermissionContext: {
|
|
31133
|
-
...args.context.options.toolPermissionContext,
|
|
31134
|
-
mode: "default"
|
|
31135
|
-
}
|
|
31136
|
-
}
|
|
31137
|
-
} : args.context;
|
|
31138
|
-
return {
|
|
31139
|
-
effectiveShouldSkipPermissionCheck,
|
|
31140
|
-
permissionContextForCall
|
|
31141
|
-
};
|
|
31142
|
-
}
|
|
31143
31229
|
function resolveToolResultAssistantContent(args) {
|
|
31144
31230
|
const rawContent = args.resultForAssistant ?? args.renderResultForAssistant(args.resultData);
|
|
31145
31231
|
const shouldTruncate = typeof rawContent === "string" && shouldApplyToolOutputTruncation(args.resultData);
|
|
@@ -31147,31 +31233,6 @@ function resolveToolResultAssistantContent(args) {
|
|
|
31147
31233
|
permissionMode: args.permissionMode
|
|
31148
31234
|
}).content : rawContent;
|
|
31149
31235
|
}
|
|
31150
|
-
function toStructuredToolResultMessages(newMessages) {
|
|
31151
|
-
if (!Array.isArray(newMessages)) {
|
|
31152
|
-
return [];
|
|
31153
|
-
}
|
|
31154
|
-
return newMessages.filter(
|
|
31155
|
-
(message) => Boolean(message) && typeof message === "object" && "type" in message
|
|
31156
|
-
);
|
|
31157
|
-
}
|
|
31158
|
-
function buildToolResultEnvelope(args) {
|
|
31159
|
-
return {
|
|
31160
|
-
blocks: [
|
|
31161
|
-
{
|
|
31162
|
-
type: "tool_result",
|
|
31163
|
-
content: args.content,
|
|
31164
|
-
tool_use_id: args.toolUseId
|
|
31165
|
-
}
|
|
31166
|
-
],
|
|
31167
|
-
toolUseResult: {
|
|
31168
|
-
data: args.resultData,
|
|
31169
|
-
resultForAssistant: args.content,
|
|
31170
|
-
...Array.isArray(args.newMessages) ? { newMessages: args.newMessages } : {},
|
|
31171
|
-
...args.contextModifier ? { contextModifier: args.contextModifier } : {}
|
|
31172
|
-
}
|
|
31173
|
-
};
|
|
31174
|
-
}
|
|
31175
31236
|
function createToolExecutionErrorBlock(args) {
|
|
31176
31237
|
const content = args.mode === "full" ? formatError(args.error) : `Tool execution failed: ${args.error instanceof Error ? args.error.message : String(args.error)}`;
|
|
31177
31238
|
return createErrorToolResultBlock({
|
|
@@ -31180,6 +31241,37 @@ function createToolExecutionErrorBlock(args) {
|
|
|
31180
31241
|
errorCode: extractErrorCode(args.error)
|
|
31181
31242
|
});
|
|
31182
31243
|
}
|
|
31244
|
+
function createToolNotFoundErrorMessage(args) {
|
|
31245
|
+
return createUserMessageFromBlocks([
|
|
31246
|
+
createErrorToolResultBlock({
|
|
31247
|
+
toolUseId: args.toolUseId,
|
|
31248
|
+
content: `Error: No such tool available: ${args.toolName}`,
|
|
31249
|
+
errorCode: "TOOL_NOT_FOUND",
|
|
31250
|
+
errorClass: "soft"
|
|
31251
|
+
})
|
|
31252
|
+
]);
|
|
31253
|
+
}
|
|
31254
|
+
function createSyntheticToolUseErrorMessage(args) {
|
|
31255
|
+
if (args.reason === "user_interrupted") {
|
|
31256
|
+
return createUserMessageFromBlocks([
|
|
31257
|
+
createErrorToolResultBlock({
|
|
31258
|
+
toolUseId: args.toolUseId,
|
|
31259
|
+
content: REJECT_MESSAGE,
|
|
31260
|
+
errorCode: "USER_INTERRUPTED",
|
|
31261
|
+
errorClass: "fatal"
|
|
31262
|
+
})
|
|
31263
|
+
]);
|
|
31264
|
+
}
|
|
31265
|
+
return createUserMessageFromBlocks([
|
|
31266
|
+
createErrorToolResultBlock({
|
|
31267
|
+
toolUseId: args.toolUseId,
|
|
31268
|
+
content: "<tool_use_error>Sibling tool call errored</tool_use_error>",
|
|
31269
|
+
errorCode: "SIBLING_ERROR",
|
|
31270
|
+
errorClass: "fatal",
|
|
31271
|
+
rootToolUseId: args.rootToolUseId
|
|
31272
|
+
})
|
|
31273
|
+
]);
|
|
31274
|
+
}
|
|
31183
31275
|
function resolveWarningText(warnings) {
|
|
31184
31276
|
if (!Array.isArray(warnings) || warnings.length === 0) {
|
|
31185
31277
|
return void 0;
|
|
@@ -31258,19 +31350,25 @@ function buildResultDispatchItems(args) {
|
|
|
31258
31350
|
tools: args.defaultTools
|
|
31259
31351
|
});
|
|
31260
31352
|
}
|
|
31261
|
-
const userMessage = buildToolResultEnvelope({
|
|
31262
|
-
toolUseId: args.toolUseId,
|
|
31263
|
-
content: args.content,
|
|
31264
|
-
resultData: args.resultData,
|
|
31265
|
-
newMessages: args.newMessages,
|
|
31266
|
-
contextModifier: args.contextModifier
|
|
31267
|
-
});
|
|
31268
31353
|
items.push({
|
|
31269
31354
|
kind: "user_message",
|
|
31270
|
-
blocks:
|
|
31271
|
-
|
|
31355
|
+
blocks: [
|
|
31356
|
+
{
|
|
31357
|
+
type: "tool_result",
|
|
31358
|
+
content: args.content,
|
|
31359
|
+
tool_use_id: args.toolUseId
|
|
31360
|
+
}
|
|
31361
|
+
],
|
|
31362
|
+
toolUseResult: {
|
|
31363
|
+
data: args.resultData,
|
|
31364
|
+
resultForAssistant: args.content,
|
|
31365
|
+
...Array.isArray(args.newMessages) ? { newMessages: args.newMessages } : {},
|
|
31366
|
+
...args.contextModifier ? { contextModifier: args.contextModifier } : {}
|
|
31367
|
+
}
|
|
31272
31368
|
});
|
|
31273
|
-
const structuredMessages =
|
|
31369
|
+
const structuredMessages = Array.isArray(args.newMessages) ? args.newMessages.filter(
|
|
31370
|
+
(message) => Boolean(message) && typeof message === "object" && "type" in message
|
|
31371
|
+
) : [];
|
|
31274
31372
|
for (const message of structuredMessages) {
|
|
31275
31373
|
items.push({
|
|
31276
31374
|
kind: "structured_message",
|
|
@@ -31303,37 +31401,207 @@ function buildWarningDispatchItems(args) {
|
|
|
31303
31401
|
}
|
|
31304
31402
|
];
|
|
31305
31403
|
}
|
|
31306
|
-
async function
|
|
31307
|
-
|
|
31308
|
-
|
|
31309
|
-
|
|
31310
|
-
|
|
31404
|
+
async function resolvePermissionCheckOutcome(args) {
|
|
31405
|
+
const effectiveShouldSkipPermissionCheck = args.hookPermissionDecision === "allow" ? true : args.hookPermissionDecision === "ask" ? false : args.shouldSkipPermissionCheck;
|
|
31406
|
+
const permissionContextForCall = args.hookPermissionDecision === "ask" && args.context.options?.toolPermissionContext && args.context.options.toolPermissionContext.mode !== "default" ? {
|
|
31407
|
+
...args.context,
|
|
31408
|
+
options: {
|
|
31409
|
+
...args.context.options,
|
|
31410
|
+
toolPermissionContext: {
|
|
31411
|
+
...args.context.options.toolPermissionContext,
|
|
31412
|
+
mode: "default"
|
|
31413
|
+
}
|
|
31414
|
+
}
|
|
31415
|
+
} : args.context;
|
|
31416
|
+
const permissionResult = effectiveShouldSkipPermissionCheck ? { result: true } : await args.canUseTool(
|
|
31311
31417
|
args.tool,
|
|
31312
31418
|
args.normalizedInput,
|
|
31313
|
-
{ ...
|
|
31419
|
+
{ ...permissionContextForCall, toolUseId: args.toolUseId },
|
|
31314
31420
|
args.assistantMessage
|
|
31315
31421
|
);
|
|
31422
|
+
return { permissionResult };
|
|
31316
31423
|
}
|
|
31317
|
-
async function
|
|
31318
|
-
const
|
|
31319
|
-
|
|
31320
|
-
|
|
31321
|
-
|
|
31424
|
+
async function* checkPermissionsAndCallTool(args) {
|
|
31425
|
+
const preprocessedInput = preprocessToolInput(args.tool, args.input);
|
|
31426
|
+
const isValidInput = args.tool.inputSchema.safeParse(preprocessedInput);
|
|
31427
|
+
if (!isValidInput.success) {
|
|
31428
|
+
const errorMessage = resolveInitialInputValidationMessage({
|
|
31429
|
+
toolName: args.tool.name,
|
|
31430
|
+
preprocessedInput,
|
|
31431
|
+
validationMessage: isValidInput.error.message
|
|
31432
|
+
});
|
|
31433
|
+
yield createUserMessageFromBlocks([
|
|
31434
|
+
createInputValidationErrorBlock({
|
|
31435
|
+
toolUseId: args.toolUseID,
|
|
31436
|
+
content: errorMessage
|
|
31437
|
+
})
|
|
31438
|
+
]);
|
|
31439
|
+
return;
|
|
31440
|
+
}
|
|
31441
|
+
let normalizedInput = normalizeToolInput(args.tool, isValidInput.data);
|
|
31442
|
+
const isValidCall = await args.tool.validateInput?.(
|
|
31443
|
+
normalizedInput,
|
|
31444
|
+
args.context
|
|
31445
|
+
);
|
|
31446
|
+
if (isValidCall?.result === false) {
|
|
31447
|
+
yield createUserMessageFromBlocks([
|
|
31448
|
+
createInputValidationErrorBlock({
|
|
31449
|
+
toolUseId: args.toolUseID,
|
|
31450
|
+
content: isValidCall.message
|
|
31451
|
+
})
|
|
31452
|
+
]);
|
|
31453
|
+
return;
|
|
31454
|
+
}
|
|
31455
|
+
const hookOutcome = await runPreToolUseHooks({
|
|
31456
|
+
toolName: args.tool.name,
|
|
31457
|
+
toolInput: normalizedInput,
|
|
31458
|
+
toolUseId: args.toolUseID,
|
|
31459
|
+
...buildToolHookBaseArgs(args.context, args.toolUseID)
|
|
31322
31460
|
});
|
|
31323
|
-
|
|
31324
|
-
|
|
31461
|
+
if (hookOutcome.kind === "block") {
|
|
31462
|
+
yield createUserMessageFromBlocks([
|
|
31463
|
+
createHookBlockedErrorBlock({
|
|
31464
|
+
toolUseId: args.toolUseID,
|
|
31465
|
+
content: hookOutcome.message
|
|
31466
|
+
})
|
|
31467
|
+
]);
|
|
31468
|
+
return;
|
|
31469
|
+
}
|
|
31470
|
+
const preWarningDispatchItems = buildWarningDispatchItems({
|
|
31471
|
+
warnings: hookOutcome.warnings,
|
|
31472
|
+
defaultTools: args.context.options?.tools ?? []
|
|
31473
|
+
});
|
|
31474
|
+
for (const dispatchItem of preWarningDispatchItems) {
|
|
31475
|
+
yield createProgressMessage(
|
|
31476
|
+
args.toolUseID,
|
|
31477
|
+
args.siblingToolUseIDs,
|
|
31478
|
+
createAssistantMessage(dispatchItem.warningText),
|
|
31479
|
+
[],
|
|
31480
|
+
dispatchItem.tools,
|
|
31481
|
+
{ progressState: "running" }
|
|
31482
|
+
);
|
|
31483
|
+
}
|
|
31484
|
+
applyHookOutcomeSideEffects(args.context, hookOutcome);
|
|
31485
|
+
const updatedInputResult = await resolveHookUpdatedInput({
|
|
31486
|
+
tool: args.tool,
|
|
31487
|
+
normalizedInput,
|
|
31488
|
+
updatedInput: hookOutcome.updatedInput,
|
|
31489
|
+
context: args.context
|
|
31490
|
+
});
|
|
31491
|
+
if (updatedInputResult.kind === "invalid") {
|
|
31492
|
+
yield createUserMessageFromBlocks([
|
|
31493
|
+
createInputValidationErrorBlock({
|
|
31494
|
+
toolUseId: args.toolUseID,
|
|
31495
|
+
content: updatedInputResult.message
|
|
31496
|
+
})
|
|
31497
|
+
]);
|
|
31498
|
+
return;
|
|
31499
|
+
}
|
|
31500
|
+
if (updatedInputResult.kind === "updated") {
|
|
31501
|
+
normalizedInput = normalizeToolInput(args.tool, updatedInputResult.normalizedInput);
|
|
31502
|
+
}
|
|
31503
|
+
const { permissionResult } = await resolvePermissionCheckOutcome({
|
|
31504
|
+
context: args.context,
|
|
31505
|
+
hookPermissionDecision: hookOutcome.kind === "allow" ? hookOutcome.permissionDecision : void 0,
|
|
31506
|
+
shouldSkipPermissionCheck: args.shouldSkipPermissionCheck,
|
|
31325
31507
|
canUseTool: args.canUseTool,
|
|
31326
31508
|
tool: args.tool,
|
|
31327
|
-
normalizedInput
|
|
31328
|
-
|
|
31329
|
-
toolUseId: args.toolUseId,
|
|
31509
|
+
normalizedInput,
|
|
31510
|
+
toolUseId: args.toolUseID,
|
|
31330
31511
|
assistantMessage: args.assistantMessage
|
|
31331
31512
|
});
|
|
31332
|
-
|
|
31333
|
-
|
|
31334
|
-
|
|
31335
|
-
|
|
31336
|
-
|
|
31513
|
+
if (permissionResult.result === false) {
|
|
31514
|
+
yield createUserMessageFromBlocks([
|
|
31515
|
+
createPermissionDeniedErrorBlock({
|
|
31516
|
+
toolUseId: args.toolUseID,
|
|
31517
|
+
content: permissionResult.message
|
|
31518
|
+
})
|
|
31519
|
+
]);
|
|
31520
|
+
return;
|
|
31521
|
+
}
|
|
31522
|
+
try {
|
|
31523
|
+
const generator = args.tool.call(normalizedInput, {
|
|
31524
|
+
...args.context,
|
|
31525
|
+
toolUseId: args.toolUseID
|
|
31526
|
+
});
|
|
31527
|
+
for await (const result of generator) {
|
|
31528
|
+
switch (result.type) {
|
|
31529
|
+
case "result": {
|
|
31530
|
+
const content = resolveToolResultAssistantContent({
|
|
31531
|
+
resultForAssistant: result.resultForAssistant,
|
|
31532
|
+
resultData: result.data,
|
|
31533
|
+
renderResultForAssistant: (data) => args.tool.renderResultForAssistant(data),
|
|
31534
|
+
permissionMode: args.context.options?.toolPermissionContext?.mode
|
|
31535
|
+
});
|
|
31536
|
+
const postOutcome = await runPostToolUseHooks({
|
|
31537
|
+
toolName: args.tool.name,
|
|
31538
|
+
toolInput: normalizedInput,
|
|
31539
|
+
toolResult: result.data,
|
|
31540
|
+
toolUseId: args.toolUseID,
|
|
31541
|
+
...buildToolHookBaseArgs(args.context, args.toolUseID)
|
|
31542
|
+
});
|
|
31543
|
+
applyHookOutcomeSideEffects(args.context, postOutcome);
|
|
31544
|
+
const dispatchItems = buildResultDispatchItems({
|
|
31545
|
+
toolUseId: args.toolUseID,
|
|
31546
|
+
content,
|
|
31547
|
+
resultData: result.data,
|
|
31548
|
+
newMessages: result.newMessages,
|
|
31549
|
+
contextModifier: result.contextModifier,
|
|
31550
|
+
defaultTools: args.context.options?.tools ?? [],
|
|
31551
|
+
postWarnings: postOutcome.warnings
|
|
31552
|
+
});
|
|
31553
|
+
for (const dispatchItem of dispatchItems) {
|
|
31554
|
+
if (dispatchItem.kind === "warning_progress") {
|
|
31555
|
+
yield createProgressMessage(
|
|
31556
|
+
args.toolUseID,
|
|
31557
|
+
args.siblingToolUseIDs,
|
|
31558
|
+
createAssistantMessage(dispatchItem.warningText),
|
|
31559
|
+
[],
|
|
31560
|
+
dispatchItem.tools,
|
|
31561
|
+
{ progressState: "running" }
|
|
31562
|
+
);
|
|
31563
|
+
continue;
|
|
31564
|
+
}
|
|
31565
|
+
if (dispatchItem.kind === "user_message") {
|
|
31566
|
+
yield createUserMessageFromBlocks(
|
|
31567
|
+
dispatchItem.blocks,
|
|
31568
|
+
dispatchItem.toolUseResult
|
|
31569
|
+
);
|
|
31570
|
+
continue;
|
|
31571
|
+
}
|
|
31572
|
+
yield dispatchItem.message;
|
|
31573
|
+
}
|
|
31574
|
+
return;
|
|
31575
|
+
}
|
|
31576
|
+
case "progress": {
|
|
31577
|
+
const progressPayload = buildRunningProgressPayload({
|
|
31578
|
+
content: result.content,
|
|
31579
|
+
normalizedMessages: result.normalizedMessages,
|
|
31580
|
+
tools: result.tools,
|
|
31581
|
+
defaultTools: args.context.options?.tools ?? []
|
|
31582
|
+
});
|
|
31583
|
+
yield createProgressMessage(
|
|
31584
|
+
args.toolUseID,
|
|
31585
|
+
args.siblingToolUseIDs,
|
|
31586
|
+
progressPayload.content,
|
|
31587
|
+
progressPayload.normalizedMessages,
|
|
31588
|
+
progressPayload.tools,
|
|
31589
|
+
{ progressState: "running" }
|
|
31590
|
+
);
|
|
31591
|
+
break;
|
|
31592
|
+
}
|
|
31593
|
+
}
|
|
31594
|
+
}
|
|
31595
|
+
} catch (error) {
|
|
31596
|
+
logError(error);
|
|
31597
|
+
yield createUserMessageFromBlocks([
|
|
31598
|
+
createToolExecutionErrorBlock({
|
|
31599
|
+
toolUseId: args.toolUseID,
|
|
31600
|
+
error,
|
|
31601
|
+
mode: "full"
|
|
31602
|
+
})
|
|
31603
|
+
]);
|
|
31604
|
+
}
|
|
31337
31605
|
}
|
|
31338
31606
|
|
|
31339
31607
|
// src/app/query.ts
|
|
@@ -31342,28 +31610,6 @@ function isToolUseLikeBlock(block) {
|
|
|
31342
31610
|
}
|
|
31343
31611
|
var __isToolUseLikeBlockForTests = isToolUseLikeBlock;
|
|
31344
31612
|
var reminderChannelRounds = [];
|
|
31345
|
-
function createSyntheticToolUseErrorMessage(args) {
|
|
31346
|
-
const { toolUseId, reason, rootToolUseId } = args;
|
|
31347
|
-
if (reason === "user_interrupted") {
|
|
31348
|
-
return createUserMessageFromBlocks([
|
|
31349
|
-
createErrorToolResultBlock({
|
|
31350
|
-
toolUseId,
|
|
31351
|
-
content: REJECT_MESSAGE,
|
|
31352
|
-
errorCode: "USER_INTERRUPTED",
|
|
31353
|
-
errorClass: "fatal"
|
|
31354
|
-
})
|
|
31355
|
-
]);
|
|
31356
|
-
}
|
|
31357
|
-
return createUserMessageFromBlocks([
|
|
31358
|
-
createErrorToolResultBlock({
|
|
31359
|
-
toolUseId,
|
|
31360
|
-
content: "<tool_use_error>Sibling tool call errored</tool_use_error>",
|
|
31361
|
-
errorCode: "SIBLING_ERROR",
|
|
31362
|
-
errorClass: "fatal",
|
|
31363
|
-
rootToolUseId
|
|
31364
|
-
})
|
|
31365
|
-
]);
|
|
31366
|
-
}
|
|
31367
31613
|
var ToolUseQueue = class {
|
|
31368
31614
|
toolDefinitions;
|
|
31369
31615
|
canUseTool;
|
|
@@ -31412,16 +31658,13 @@ var ToolUseQueue = class {
|
|
|
31412
31658
|
if (!entry.queuedProgressEmitted) {
|
|
31413
31659
|
entry.queuedProgressEmitted = true;
|
|
31414
31660
|
entry.pendingProgress.push(
|
|
31415
|
-
|
|
31416
|
-
entry.id,
|
|
31417
|
-
this.siblingToolUseIDs,
|
|
31418
|
-
|
|
31419
|
-
|
|
31420
|
-
|
|
31421
|
-
|
|
31422
|
-
this.toolUseContext.options.tools,
|
|
31423
|
-
{ progressState: "queued_waiting" }
|
|
31424
|
-
)
|
|
31661
|
+
createQueuedWaitingProgressMessage({
|
|
31662
|
+
toolUseId: entry.id,
|
|
31663
|
+
siblingToolUseIDs: this.siblingToolUseIDs,
|
|
31664
|
+
tools: this.toolUseContext.options.tools,
|
|
31665
|
+
openTag: TOOL_PROGRESS_OPEN_TAG,
|
|
31666
|
+
closeTag: TOOL_PROGRESS_CLOSE_TAG
|
|
31667
|
+
})
|
|
31425
31668
|
);
|
|
31426
31669
|
if (this.progressAvailableResolve) {
|
|
31427
31670
|
this.progressAvailableResolve();
|
|
@@ -31480,21 +31723,12 @@ var ToolUseQueue = class {
|
|
|
31480
31723
|
);
|
|
31481
31724
|
break;
|
|
31482
31725
|
}
|
|
31483
|
-
|
|
31484
|
-
|
|
31485
|
-
|
|
31486
|
-
const fatal = message.message.content.some(
|
|
31487
|
-
(block) => block.type === "tool_result" && block.is_error === true && block.error_class === "fatal"
|
|
31488
|
-
);
|
|
31489
|
-
if (fatal) {
|
|
31726
|
+
const errorState = resolveToolQueueUserMessageErrorState(message);
|
|
31727
|
+
if (errorState.toolErrored) {
|
|
31728
|
+
if (errorState.fatalToolUseId) {
|
|
31490
31729
|
this.hasFatalErrored = true;
|
|
31491
31730
|
if (!this.fatalToolUseId) {
|
|
31492
|
-
|
|
31493
|
-
(block) => block.type === "tool_result" && block.is_error === true && block.error_class === "fatal" && typeof block.tool_use_id === "string"
|
|
31494
|
-
);
|
|
31495
|
-
if (fatalBlock) {
|
|
31496
|
-
this.fatalToolUseId = fatalBlock.tool_use_id;
|
|
31497
|
-
}
|
|
31731
|
+
this.fatalToolUseId = errorState.fatalToolUseId;
|
|
31498
31732
|
}
|
|
31499
31733
|
}
|
|
31500
31734
|
toolErrored = true;
|
|
@@ -31507,10 +31741,9 @@ var ToolUseQueue = class {
|
|
|
31507
31741
|
}
|
|
31508
31742
|
} else {
|
|
31509
31743
|
results.push(message);
|
|
31510
|
-
|
|
31511
|
-
|
|
31512
|
-
|
|
31513
|
-
);
|
|
31744
|
+
const modifyContext = resolveToolQueueContextModifier(message);
|
|
31745
|
+
if (modifyContext) {
|
|
31746
|
+
contextModifiers.push(modifyContext);
|
|
31514
31747
|
}
|
|
31515
31748
|
}
|
|
31516
31749
|
}
|
|
@@ -31616,7 +31849,17 @@ async function* query(messages, systemPrompt, context, canUseTool, toolUseContex
|
|
|
31616
31849
|
requestId: context.requestId,
|
|
31617
31850
|
currentRequestId: getCurrentRequest()?.id,
|
|
31618
31851
|
isTestEnv: process.env.NODE_ENV === "test",
|
|
31619
|
-
hooks:
|
|
31852
|
+
hooks: {
|
|
31853
|
+
resolveModelWithInfo: (modelPointer) => getModelManager().resolveModelWithInfo(modelPointer),
|
|
31854
|
+
createStreamTypedProjector,
|
|
31855
|
+
normalizeMessagesForSingleFactLayer,
|
|
31856
|
+
projectLifecycleEventsToTypedParts,
|
|
31857
|
+
projectMessageToTypedParts,
|
|
31858
|
+
emitTypedPart,
|
|
31859
|
+
buildSkeletonBlocksFromTypedParts,
|
|
31860
|
+
flushTypedPartBuffer,
|
|
31861
|
+
consumeProjectorCompatibilityMetrics
|
|
31862
|
+
},
|
|
31620
31863
|
logUserFriendly,
|
|
31621
31864
|
stream: async function* (preparedMessages) {
|
|
31622
31865
|
yield* queryCore(
|
|
@@ -31833,23 +32076,7 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
31833
32076
|
}
|
|
31834
32077
|
updateHookTranscriptForMessages(toolUseContext, messages);
|
|
31835
32078
|
{
|
|
31836
|
-
const
|
|
31837
|
-
let userPromptText = null;
|
|
31838
|
-
if (last2 && typeof last2 === "object" && last2.type === "user") {
|
|
31839
|
-
const content = last2.message?.content;
|
|
31840
|
-
if (typeof content === "string") {
|
|
31841
|
-
userPromptText = content;
|
|
31842
|
-
} else if (Array.isArray(content)) {
|
|
31843
|
-
const hasToolResult = content.some(
|
|
31844
|
-
(b) => b && typeof b === "object" && b.type === "tool_result"
|
|
31845
|
-
);
|
|
31846
|
-
if (!hasToolResult) {
|
|
31847
|
-
userPromptText = content.filter(
|
|
31848
|
-
(b) => b && typeof b === "object" && b.type === "text"
|
|
31849
|
-
).map((b) => String(b.text ?? "")).join("");
|
|
31850
|
-
}
|
|
31851
|
-
}
|
|
31852
|
-
}
|
|
32079
|
+
const userPromptText = extractUserPromptTextFromMessages(messages);
|
|
31853
32080
|
if (userPromptText !== null) {
|
|
31854
32081
|
toolUseContext.options.lastUserPrompt = userPromptText;
|
|
31855
32082
|
const promptOutcome = await runUserPromptSubmitHooks({
|
|
@@ -31897,10 +32124,7 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
31897
32124
|
fullSystemPrompt.push(effectiveSystemReminders);
|
|
31898
32125
|
fullSystemPrompt.push("\n---\n");
|
|
31899
32126
|
}
|
|
31900
|
-
const planModeAdditions = getPlanModeSystemPromptAdditions(
|
|
31901
|
-
messages,
|
|
31902
|
-
toolUseContext
|
|
31903
|
-
);
|
|
32127
|
+
const planModeAdditions = getPlanModeSystemPromptAdditions(messages, toolUseContext);
|
|
31904
32128
|
if (planModeAdditions.length > 0) {
|
|
31905
32129
|
fullSystemPrompt.push(...planModeAdditions);
|
|
31906
32130
|
}
|
|
@@ -32032,17 +32256,12 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
32032
32256
|
const shouldSkipPermissionCheck = result.shouldSkipPermissionCheck;
|
|
32033
32257
|
const parentUserMessage = findNaturalUserMessageForParent(messages);
|
|
32034
32258
|
const toolUseMessages = assistantMessage.message.content.filter(isToolUseLikeBlock);
|
|
32035
|
-
const
|
|
32036
|
-
const lifecycleTokens = usage && typeof usage === "object" ? {
|
|
32037
|
-
...Number.isFinite(Number(usage.input_tokens)) ? { input: Number(usage.input_tokens) } : {},
|
|
32038
|
-
...Number.isFinite(Number(usage.output_tokens)) ? { output: Number(usage.output_tokens) } : {},
|
|
32039
|
-
...Number.isFinite(Number(usage.input_tokens)) || Number.isFinite(Number(usage.output_tokens)) ? {
|
|
32040
|
-
total: Number(usage.input_tokens ?? 0) + Number(usage.output_tokens ?? 0)
|
|
32041
|
-
} : {}
|
|
32042
|
-
} : void 0;
|
|
32259
|
+
const lifecycleTokens = resolveLifecycleTokensFromAssistantMessage(assistantMessage);
|
|
32043
32260
|
if (!toolUseMessages.length) {
|
|
32044
|
-
const
|
|
32045
|
-
|
|
32261
|
+
const { hookEvent: stopHookEvent, stopReason } = resolveStopHookSignal({
|
|
32262
|
+
agentId: toolUseContext.agentId,
|
|
32263
|
+
assistantMessage
|
|
32264
|
+
});
|
|
32046
32265
|
const finish = mapFinishReason(stopReason);
|
|
32047
32266
|
lifecycleEvents.finishStep({
|
|
32048
32267
|
stepId,
|
|
@@ -32053,56 +32272,28 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
32053
32272
|
costUSD: assistantMessage.costUSD,
|
|
32054
32273
|
...lifecycleTokens ? { tokens: lifecycleTokens } : {}
|
|
32055
32274
|
});
|
|
32056
|
-
const
|
|
32275
|
+
const stopHookResult = await runStopHookAttempt({
|
|
32276
|
+
context: toolUseContext,
|
|
32057
32277
|
hookEvent: stopHookEvent,
|
|
32058
|
-
|
|
32059
|
-
retryEntryKey: buildRetryEntryKey([
|
|
32060
|
-
toolUseContext.sessionId,
|
|
32061
|
-
toolUseContext.parentSessionId,
|
|
32062
|
-
toolUseContext.childSessionId,
|
|
32063
|
-
toolUseContext.agentId,
|
|
32064
|
-
String(stopReason ?? "")
|
|
32065
|
-
]),
|
|
32066
|
-
retryAttempt: stopHookAttempts,
|
|
32067
|
-
sessionId: toolUseContext.sessionId,
|
|
32068
|
-
parentSessionId: toolUseContext.parentSessionId,
|
|
32069
|
-
childSessionId: toolUseContext.childSessionId,
|
|
32070
|
-
agentId: toolUseContext.agentId,
|
|
32071
|
-
permissionMode: toolUseContext.options?.toolPermissionContext?.mode,
|
|
32072
|
-
cwd: getCwd(),
|
|
32073
|
-
transcriptPath: getHookTranscriptPath(toolUseContext),
|
|
32074
|
-
safeMode: toolUseContext.options?.safeMode ?? false,
|
|
32278
|
+
stopReason,
|
|
32075
32279
|
stopHookActive,
|
|
32076
|
-
|
|
32280
|
+
stopHookAttempts
|
|
32077
32281
|
});
|
|
32078
|
-
if (
|
|
32079
|
-
|
|
32080
|
-
|
|
32081
|
-
|
|
32082
|
-
|
|
32282
|
+
if (stopHookResult.shouldRetry) {
|
|
32283
|
+
yield* await queryCore(
|
|
32284
|
+
[...messages, assistantMessage],
|
|
32285
|
+
systemPrompt,
|
|
32286
|
+
context,
|
|
32287
|
+
canUseTool,
|
|
32083
32288
|
toolUseContext,
|
|
32084
|
-
|
|
32289
|
+
getBinaryFeedbackResponse,
|
|
32290
|
+
{
|
|
32291
|
+
stopHookActive: true,
|
|
32292
|
+
stopHookAttempts: stopHookResult.nextStopHookAttempts,
|
|
32293
|
+
startupEmitted: true
|
|
32294
|
+
}
|
|
32085
32295
|
);
|
|
32086
|
-
|
|
32087
|
-
if (stopOutcome.decision === "block") {
|
|
32088
|
-
queueHookSystemMessages(toolUseContext, [stopOutcome.message]);
|
|
32089
|
-
const MAX_STOP_HOOK_ATTEMPTS = 5;
|
|
32090
|
-
if (stopHookAttempts < MAX_STOP_HOOK_ATTEMPTS) {
|
|
32091
|
-
yield* await queryCore(
|
|
32092
|
-
[...messages, assistantMessage],
|
|
32093
|
-
systemPrompt,
|
|
32094
|
-
context,
|
|
32095
|
-
canUseTool,
|
|
32096
|
-
toolUseContext,
|
|
32097
|
-
getBinaryFeedbackResponse,
|
|
32098
|
-
{
|
|
32099
|
-
stopHookActive: true,
|
|
32100
|
-
stopHookAttempts: stopHookAttempts + 1,
|
|
32101
|
-
startupEmitted: true
|
|
32102
|
-
}
|
|
32103
|
-
);
|
|
32104
|
-
return;
|
|
32105
|
-
}
|
|
32296
|
+
return;
|
|
32106
32297
|
}
|
|
32107
32298
|
if (!parentUserMessage?.uuid) {
|
|
32108
32299
|
sessionContext?.setIdle();
|
|
@@ -32161,7 +32352,7 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
32161
32352
|
const toolMessagesForNextTurn = [];
|
|
32162
32353
|
for await (const message of toolQueue.getRemainingResults()) {
|
|
32163
32354
|
yield message;
|
|
32164
|
-
if (message
|
|
32355
|
+
if (isToolQueueNextTurnMessage(message)) {
|
|
32165
32356
|
toolMessagesForNextTurn.push(message);
|
|
32166
32357
|
}
|
|
32167
32358
|
}
|
|
@@ -32171,22 +32362,18 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
32171
32362
|
yield createAssistantMessage(INTERRUPT_MESSAGE_FOR_TOOL_USE);
|
|
32172
32363
|
return;
|
|
32173
32364
|
}
|
|
32174
|
-
|
|
32175
|
-
|
|
32176
|
-
|
|
32177
|
-
|
|
32178
|
-
|
|
32179
|
-
|
|
32180
|
-
|
|
32181
|
-
|
|
32182
|
-
{
|
|
32183
|
-
|
|
32184
|
-
|
|
32185
|
-
|
|
32186
|
-
);
|
|
32187
|
-
} catch (error) {
|
|
32188
|
-
throw error;
|
|
32189
|
-
}
|
|
32365
|
+
yield* await queryCore(
|
|
32366
|
+
[...messages, assistantMessage, ...toolMessagesForNextTurn],
|
|
32367
|
+
systemPrompt,
|
|
32368
|
+
context,
|
|
32369
|
+
canUseTool,
|
|
32370
|
+
toolUseContext,
|
|
32371
|
+
getBinaryFeedbackResponse,
|
|
32372
|
+
{
|
|
32373
|
+
...hookState ?? {},
|
|
32374
|
+
startupEmitted: true
|
|
32375
|
+
}
|
|
32376
|
+
);
|
|
32190
32377
|
} catch (error) {
|
|
32191
32378
|
sessionContext?.setErrored();
|
|
32192
32379
|
throw error;
|
|
@@ -32244,14 +32431,10 @@ async function* runToolUse(toolUse, siblingToolUseIDs, assistantMessage, canUseT
|
|
|
32244
32431
|
toolUseID: toolUse.id,
|
|
32245
32432
|
requestId: currentRequest?.id
|
|
32246
32433
|
});
|
|
32247
|
-
yield
|
|
32248
|
-
|
|
32249
|
-
|
|
32250
|
-
|
|
32251
|
-
errorCode: "TOOL_NOT_FOUND",
|
|
32252
|
-
errorClass: "soft"
|
|
32253
|
-
})
|
|
32254
|
-
]);
|
|
32434
|
+
yield createToolNotFoundErrorMessage({
|
|
32435
|
+
toolUseId: toolUse.id,
|
|
32436
|
+
toolName
|
|
32437
|
+
});
|
|
32255
32438
|
sessionContext?.finishTool(toolUse.id);
|
|
32256
32439
|
return;
|
|
32257
32440
|
}
|
|
@@ -32263,215 +32446,22 @@ async function* runToolUse(toolUse, siblingToolUseIDs, assistantMessage, canUseT
|
|
|
32263
32446
|
requestId: currentRequest?.id
|
|
32264
32447
|
});
|
|
32265
32448
|
try {
|
|
32266
|
-
for await (const message of checkPermissionsAndCallTool(
|
|
32449
|
+
for await (const message of checkPermissionsAndCallTool({
|
|
32267
32450
|
tool,
|
|
32268
|
-
toolUse.id,
|
|
32451
|
+
toolUseID: toolUse.id,
|
|
32269
32452
|
siblingToolUseIDs,
|
|
32270
|
-
toolInput,
|
|
32271
|
-
toolUseContext,
|
|
32453
|
+
input: toolInput,
|
|
32454
|
+
context: toolUseContext,
|
|
32272
32455
|
canUseTool,
|
|
32273
32456
|
assistantMessage,
|
|
32274
32457
|
shouldSkipPermissionCheck
|
|
32275
|
-
)) {
|
|
32458
|
+
})) {
|
|
32276
32459
|
yield message;
|
|
32277
32460
|
}
|
|
32278
|
-
} catch (e) {
|
|
32279
|
-
logError(e);
|
|
32280
|
-
const errorMessage = createUserMessageFromBlocks([
|
|
32281
|
-
createToolExecutionErrorBlock({
|
|
32282
|
-
toolUseId: toolUse.id,
|
|
32283
|
-
error: e,
|
|
32284
|
-
mode: "summary"
|
|
32285
|
-
})
|
|
32286
|
-
]);
|
|
32287
|
-
yield errorMessage;
|
|
32288
32461
|
} finally {
|
|
32289
32462
|
sessionContext?.finishTool(toolUse.id);
|
|
32290
32463
|
}
|
|
32291
32464
|
}
|
|
32292
|
-
async function* checkPermissionsAndCallTool(tool, toolUseID, siblingToolUseIDs, input, context, canUseTool, assistantMessage, shouldSkipPermissionCheck) {
|
|
32293
|
-
const preprocessedInput = preprocessToolInput(tool, input);
|
|
32294
|
-
const isValidInput = tool.inputSchema.safeParse(preprocessedInput);
|
|
32295
|
-
if (!isValidInput.success) {
|
|
32296
|
-
const errorMessage = resolveInitialInputValidationMessage({
|
|
32297
|
-
toolName: tool.name,
|
|
32298
|
-
preprocessedInput,
|
|
32299
|
-
validationMessage: isValidInput.error.message
|
|
32300
|
-
});
|
|
32301
|
-
yield createUserMessageFromBlocks([
|
|
32302
|
-
createInputValidationErrorBlock({
|
|
32303
|
-
toolUseId: toolUseID,
|
|
32304
|
-
content: errorMessage
|
|
32305
|
-
})
|
|
32306
|
-
]);
|
|
32307
|
-
return;
|
|
32308
|
-
}
|
|
32309
|
-
let normalizedInput = normalizeToolInput(tool, isValidInput.data);
|
|
32310
|
-
const isValidCall = await tool.validateInput?.(
|
|
32311
|
-
normalizedInput,
|
|
32312
|
-
context
|
|
32313
|
-
);
|
|
32314
|
-
if (isValidCall?.result === false) {
|
|
32315
|
-
yield createUserMessageFromBlocks([
|
|
32316
|
-
createInputValidationErrorBlock({
|
|
32317
|
-
toolUseId: toolUseID,
|
|
32318
|
-
content: isValidCall.message
|
|
32319
|
-
})
|
|
32320
|
-
]);
|
|
32321
|
-
return;
|
|
32322
|
-
}
|
|
32323
|
-
const hookOutcome = await runPreToolUseHooks({
|
|
32324
|
-
toolName: tool.name,
|
|
32325
|
-
toolInput: normalizedInput,
|
|
32326
|
-
toolUseId: toolUseID,
|
|
32327
|
-
...buildToolHookBaseArgs(context, toolUseID)
|
|
32328
|
-
});
|
|
32329
|
-
if (hookOutcome.kind === "block") {
|
|
32330
|
-
yield createUserMessageFromBlocks([
|
|
32331
|
-
createHookBlockedErrorBlock({
|
|
32332
|
-
toolUseId: toolUseID,
|
|
32333
|
-
content: hookOutcome.message
|
|
32334
|
-
})
|
|
32335
|
-
]);
|
|
32336
|
-
return;
|
|
32337
|
-
}
|
|
32338
|
-
const preWarningDispatchItems = buildWarningDispatchItems({
|
|
32339
|
-
warnings: hookOutcome.warnings,
|
|
32340
|
-
defaultTools: context.options?.tools ?? []
|
|
32341
|
-
});
|
|
32342
|
-
for (const dispatchItem of preWarningDispatchItems) {
|
|
32343
|
-
yield createProgressMessage(
|
|
32344
|
-
toolUseID,
|
|
32345
|
-
siblingToolUseIDs,
|
|
32346
|
-
createAssistantMessage(dispatchItem.warningText),
|
|
32347
|
-
[],
|
|
32348
|
-
dispatchItem.tools,
|
|
32349
|
-
{ progressState: "running" }
|
|
32350
|
-
);
|
|
32351
|
-
}
|
|
32352
|
-
applyHookOutcomeSideEffects(context, hookOutcome);
|
|
32353
|
-
const updatedInputResult = await resolveHookUpdatedInput({
|
|
32354
|
-
tool,
|
|
32355
|
-
normalizedInput,
|
|
32356
|
-
updatedInput: hookOutcome.updatedInput,
|
|
32357
|
-
context
|
|
32358
|
-
});
|
|
32359
|
-
if (updatedInputResult.kind === "invalid") {
|
|
32360
|
-
yield createUserMessageFromBlocks([
|
|
32361
|
-
createInputValidationErrorBlock({
|
|
32362
|
-
toolUseId: toolUseID,
|
|
32363
|
-
content: updatedInputResult.message
|
|
32364
|
-
})
|
|
32365
|
-
]);
|
|
32366
|
-
return;
|
|
32367
|
-
}
|
|
32368
|
-
if (updatedInputResult.kind === "updated") {
|
|
32369
|
-
normalizedInput = normalizeToolInput(tool, updatedInputResult.normalizedInput);
|
|
32370
|
-
}
|
|
32371
|
-
const hookPermissionDecision = hookOutcome.kind === "allow" ? hookOutcome.permissionDecision : void 0;
|
|
32372
|
-
const { permissionResult } = await resolvePermissionCheckOutcome({
|
|
32373
|
-
context,
|
|
32374
|
-
hookPermissionDecision,
|
|
32375
|
-
shouldSkipPermissionCheck,
|
|
32376
|
-
canUseTool,
|
|
32377
|
-
tool,
|
|
32378
|
-
normalizedInput,
|
|
32379
|
-
toolUseId: toolUseID,
|
|
32380
|
-
assistantMessage
|
|
32381
|
-
});
|
|
32382
|
-
if (permissionResult.result === false) {
|
|
32383
|
-
yield createUserMessageFromBlocks([
|
|
32384
|
-
createPermissionDeniedErrorBlock({
|
|
32385
|
-
toolUseId: toolUseID,
|
|
32386
|
-
content: permissionResult.message
|
|
32387
|
-
})
|
|
32388
|
-
]);
|
|
32389
|
-
return;
|
|
32390
|
-
}
|
|
32391
|
-
try {
|
|
32392
|
-
const generator = tool.call(normalizedInput, {
|
|
32393
|
-
...context,
|
|
32394
|
-
toolUseId: toolUseID
|
|
32395
|
-
});
|
|
32396
|
-
for await (const result of generator) {
|
|
32397
|
-
switch (result.type) {
|
|
32398
|
-
case "result":
|
|
32399
|
-
{
|
|
32400
|
-
const content = resolveToolResultAssistantContent({
|
|
32401
|
-
resultForAssistant: result.resultForAssistant,
|
|
32402
|
-
resultData: result.data,
|
|
32403
|
-
renderResultForAssistant: (data) => tool.renderResultForAssistant(data),
|
|
32404
|
-
permissionMode: context.options?.toolPermissionContext?.mode
|
|
32405
|
-
});
|
|
32406
|
-
const postOutcome = await runPostToolUseHooks({
|
|
32407
|
-
toolName: tool.name,
|
|
32408
|
-
toolInput: normalizedInput,
|
|
32409
|
-
toolResult: result.data,
|
|
32410
|
-
toolUseId: toolUseID,
|
|
32411
|
-
...buildToolHookBaseArgs(context, toolUseID)
|
|
32412
|
-
});
|
|
32413
|
-
applyHookOutcomeSideEffects(context, postOutcome);
|
|
32414
|
-
const dispatchItems = buildResultDispatchItems({
|
|
32415
|
-
toolUseId: toolUseID,
|
|
32416
|
-
content,
|
|
32417
|
-
resultData: result.data,
|
|
32418
|
-
newMessages: result.newMessages,
|
|
32419
|
-
contextModifier: result.contextModifier,
|
|
32420
|
-
defaultTools: context.options?.tools ?? [],
|
|
32421
|
-
postWarnings: postOutcome.warnings
|
|
32422
|
-
});
|
|
32423
|
-
for (const dispatchItem of dispatchItems) {
|
|
32424
|
-
if (dispatchItem.kind === "warning_progress") {
|
|
32425
|
-
yield createProgressMessage(
|
|
32426
|
-
toolUseID,
|
|
32427
|
-
siblingToolUseIDs,
|
|
32428
|
-
createAssistantMessage(dispatchItem.warningText),
|
|
32429
|
-
[],
|
|
32430
|
-
dispatchItem.tools,
|
|
32431
|
-
{ progressState: "running" }
|
|
32432
|
-
);
|
|
32433
|
-
continue;
|
|
32434
|
-
}
|
|
32435
|
-
if (dispatchItem.kind === "user_message") {
|
|
32436
|
-
yield createUserMessageFromBlocks(
|
|
32437
|
-
dispatchItem.blocks,
|
|
32438
|
-
dispatchItem.toolUseResult
|
|
32439
|
-
);
|
|
32440
|
-
continue;
|
|
32441
|
-
}
|
|
32442
|
-
yield dispatchItem.message;
|
|
32443
|
-
}
|
|
32444
|
-
}
|
|
32445
|
-
return;
|
|
32446
|
-
case "progress":
|
|
32447
|
-
const progressPayload = buildRunningProgressPayload({
|
|
32448
|
-
content: result.content,
|
|
32449
|
-
normalizedMessages: result.normalizedMessages,
|
|
32450
|
-
tools: result.tools,
|
|
32451
|
-
defaultTools: context.options?.tools ?? []
|
|
32452
|
-
});
|
|
32453
|
-
yield createProgressMessage(
|
|
32454
|
-
toolUseID,
|
|
32455
|
-
siblingToolUseIDs,
|
|
32456
|
-
progressPayload.content,
|
|
32457
|
-
progressPayload.normalizedMessages,
|
|
32458
|
-
progressPayload.tools,
|
|
32459
|
-
{ progressState: "running" }
|
|
32460
|
-
);
|
|
32461
|
-
break;
|
|
32462
|
-
}
|
|
32463
|
-
}
|
|
32464
|
-
} catch (error) {
|
|
32465
|
-
logError(error);
|
|
32466
|
-
yield createUserMessageFromBlocks([
|
|
32467
|
-
createToolExecutionErrorBlock({
|
|
32468
|
-
toolUseId: toolUseID,
|
|
32469
|
-
error,
|
|
32470
|
-
mode: "full"
|
|
32471
|
-
})
|
|
32472
|
-
]);
|
|
32473
|
-
}
|
|
32474
|
-
}
|
|
32475
32465
|
|
|
32476
32466
|
// src/ui/components/binary-feedback/BinaryFeedback.tsx
|
|
32477
32467
|
import { default as React96, useCallback as useCallback15 } from "react";
|
|
@@ -33647,7 +33637,7 @@ import { homedir as homedir8 } from "os";
|
|
|
33647
33637
|
// src/commands/agents/generation.ts
|
|
33648
33638
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
33649
33639
|
async function generateAgentWithClaude(prompt) {
|
|
33650
|
-
const { queryModel } = await import("./llm-
|
|
33640
|
+
const { queryModel } = await import("./llm-MASKGBQQ.js");
|
|
33651
33641
|
const systemPrompt = `You are an expert at creating AI agent configurations. Based on the user's description, generate a specialized agent configuration.
|
|
33652
33642
|
|
|
33653
33643
|
Return your response as a JSON object with exactly these fields:
|