@openai/agents-core 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +5 -0
- package/dist/agent.js.map +1 -1
- package/dist/agent.mjs +5 -0
- package/dist/agent.mjs.map +1 -1
- package/dist/editor.d.ts +38 -0
- package/dist/editor.js +3 -0
- package/dist/editor.js.map +1 -0
- package/dist/editor.mjs +2 -0
- package/dist/editor.mjs.map +1 -0
- package/dist/extensions/handoffFilters.js +4 -0
- package/dist/extensions/handoffFilters.js.map +1 -1
- package/dist/extensions/handoffFilters.mjs +4 -0
- package/dist/extensions/handoffFilters.mjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/items.d.ts +518 -4
- package/dist/items.js +22 -1
- package/dist/items.js.map +1 -1
- package/dist/items.mjs +22 -1
- package/dist/items.mjs.map +1 -1
- package/dist/metadata.js +2 -2
- package/dist/metadata.mjs +2 -2
- package/dist/model.d.ts +17 -3
- package/dist/run.js +3 -0
- package/dist/run.js.map +1 -1
- package/dist/run.mjs +3 -0
- package/dist/run.mjs.map +1 -1
- package/dist/runContext.js +2 -2
- package/dist/runContext.js.map +1 -1
- package/dist/runContext.mjs +2 -2
- package/dist/runContext.mjs.map +1 -1
- package/dist/runImplementation.d.ts +16 -1
- package/dist/runImplementation.js +262 -4
- package/dist/runImplementation.js.map +1 -1
- package/dist/runImplementation.mjs +260 -4
- package/dist/runImplementation.mjs.map +1 -1
- package/dist/runState.d.ts +2554 -20
- package/dist/runState.js +46 -3
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +46 -3
- package/dist/runState.mjs.map +1 -1
- package/dist/shell.d.ts +36 -0
- package/dist/shell.js +3 -0
- package/dist/shell.js.map +1 -0
- package/dist/shell.mjs +2 -0
- package/dist/shell.mjs.map +1 -0
- package/dist/tool.d.ts +62 -1
- package/dist/tool.js +30 -0
- package/dist/tool.js.map +1 -1
- package/dist/tool.mjs +28 -0
- package/dist/tool.mjs.map +1 -1
- package/dist/types/aliases.d.ts +3 -3
- package/dist/types/protocol.d.ts +2317 -42
- package/dist/types/protocol.js +73 -1
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/protocol.mjs +72 -0
- package/dist/types/protocol.mjs.map +1 -1
- package/dist/utils/applyDiff.d.ts +9 -0
- package/dist/utils/applyDiff.js +275 -0
- package/dist/utils/applyDiff.js.map +1 -0
- package/dist/utils/applyDiff.mjs +272 -0
- package/dist/utils/applyDiff.mjs.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -0
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/serialize.js +12 -0
- package/dist/utils/serialize.js.map +1 -1
- package/dist/utils/serialize.mjs +12 -0
- package/dist/utils/serialize.mjs.map +1 -1
- package/package.json +3 -3
package/dist/runContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runContext.js","sourceRoot":"","sources":["../src/runContext.ts"],"names":[],"mappings":";;;;;;AACA,yDAA8B;AAE9B,sCAAgC;AAOhC;;GAEG;AACH,MAAa,UAAU;IACrB;;OAEG;IACH,OAAO,CAAW;IAElB;;;OAGG;IACH,KAAK,CAAQ;IAEb;;OAEG;IACH,UAAU,CAA8B;IAExC,YAAY,UAAoB,EAAc;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,aAAK,EAAE,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,iBAAiB,CAAC,SAAyC;QACzD,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CA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AQ,EAAE,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM;QAKJ,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SACzD,CAAC;IACJ,CAAC;CACF;AAnKD,gCAmKC"}
|
package/dist/runContext.mjs
CHANGED
|
@@ -75,7 +75,7 @@ export class RunContext {
|
|
|
75
75
|
* @param options - Additional approval behavior options.
|
|
76
76
|
*/
|
|
77
77
|
approveTool(approvalItem, { alwaysApprove = false } = {}) {
|
|
78
|
-
const toolName = approvalItem.rawItem.name;
|
|
78
|
+
const toolName = approvalItem.toolName ?? approvalItem.rawItem.name;
|
|
79
79
|
if (alwaysApprove) {
|
|
80
80
|
this.#approvals.set(toolName, {
|
|
81
81
|
approved: true,
|
|
@@ -102,7 +102,7 @@ export class RunContext {
|
|
|
102
102
|
* @param approvalItem - The tool approval item to reject.
|
|
103
103
|
*/
|
|
104
104
|
rejectTool(approvalItem, { alwaysReject = false } = {}) {
|
|
105
|
-
const toolName = approvalItem.rawItem.name;
|
|
105
|
+
const toolName = approvalItem.toolName ?? approvalItem.rawItem.name;
|
|
106
106
|
if (alwaysReject) {
|
|
107
107
|
this.#approvals.set(toolName, {
|
|
108
108
|
approved: false,
|
package/dist/runContext.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runContext.mjs","sourceRoot":"","sources":["../src/runContext.ts"],"names":[],"mappings":"OACO,MAAM;OAEN,EAAE,KAAK,EAAE;AAOhB;;GAEG;AACH,MAAM,OAAO,UAAU;IACrB;;OAEG;IACH,OAAO,CAAW;IAElB;;;OAGG;IACH,KAAK,CAAQ;IAEb;;OAEG;IACH,UAAU,CAA8B;IAExC,YAAY,UAAoB,EAAc;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAC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C,OAAO,CAAC,MAAM,CAAC,iBAAiB;gBAC/C,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,EAAG,CAAC,CAAC,eAAe;YAC/C,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM;QAKJ,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SACzD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Agent } from './agent';
|
|
2
2
|
import { Handoff } from './handoff';
|
|
3
3
|
import { RunItem, RunToolApprovalItem } from './items';
|
|
4
|
+
import { Logger } from './logger';
|
|
4
5
|
import { ModelResponse } from './model';
|
|
5
|
-
import { ComputerTool, FunctionTool, HostedMCPTool } from './tool';
|
|
6
|
+
import { ComputerTool, FunctionTool, HostedMCPTool, ShellTool, ApplyPatchTool } from './tool';
|
|
6
7
|
import { AgentInputItem, UnknownContext } from './types';
|
|
8
|
+
import { Runner } from './run';
|
|
9
|
+
import { RunContext } from './runContext';
|
|
7
10
|
import { StreamedRunResult } from './result';
|
|
8
11
|
import { z } from 'zod';
|
|
9
12
|
import * as protocol from './types/protocol';
|
|
@@ -20,6 +23,14 @@ type ToolRunComputer = {
|
|
|
20
23
|
toolCall: protocol.ComputerUseCallItem;
|
|
21
24
|
computer: ComputerTool;
|
|
22
25
|
};
|
|
26
|
+
type ToolRunShell = {
|
|
27
|
+
toolCall: protocol.ShellCallItem;
|
|
28
|
+
shell: ShellTool;
|
|
29
|
+
};
|
|
30
|
+
type ToolRunApplyPatch = {
|
|
31
|
+
toolCall: protocol.ApplyPatchCallItem;
|
|
32
|
+
applyPatch: ApplyPatchTool;
|
|
33
|
+
};
|
|
23
34
|
type ToolRunMCPApprovalRequest = {
|
|
24
35
|
requestItem: RunToolApprovalItem;
|
|
25
36
|
mcpTool: HostedMCPTool;
|
|
@@ -29,6 +40,8 @@ export type ProcessedResponse<TContext = UnknownContext> = {
|
|
|
29
40
|
handoffs: ToolRunHandoff[];
|
|
30
41
|
functions: ToolRunFunction<TContext>[];
|
|
31
42
|
computerActions: ToolRunComputer[];
|
|
43
|
+
shellActions: ToolRunShell[];
|
|
44
|
+
applyPatchActions: ToolRunApplyPatch[];
|
|
32
45
|
mcpApprovalRequests: ToolRunMCPApprovalRequest[];
|
|
33
46
|
toolsUsed: string[];
|
|
34
47
|
hasToolsOrApprovalsToRun(): boolean;
|
|
@@ -119,6 +132,8 @@ declare class SingleStepResult {
|
|
|
119
132
|
*/
|
|
120
133
|
get generatedItems(): RunItem[];
|
|
121
134
|
}
|
|
135
|
+
export declare function executeShellActions(agent: Agent<any, any>, actions: ToolRunShell[], runner: Runner, runContext: RunContext, customLogger?: Logger | undefined): Promise<RunItem[]>;
|
|
136
|
+
export declare function executeApplyPatchOperations(agent: Agent<any, any>, actions: ToolRunApplyPatch[], runner: Runner, runContext: RunContext, customLogger?: Logger | undefined): Promise<RunItem[]>;
|
|
122
137
|
export declare function streamStepItemsToRunResult(result: StreamedRunResult<any, any>, items: RunItem[]): void;
|
|
123
138
|
export declare function addStepToRunResult(result: StreamedRunResult<any, any>, step: SingleStepResult, options?: {
|
|
124
139
|
skipItems?: Set<RunItem>;
|
|
@@ -10,6 +10,8 @@ exports.resolveInterruptedTurn = resolveInterruptedTurn;
|
|
|
10
10
|
exports.resolveTurnAfterModelResponse = resolveTurnAfterModelResponse;
|
|
11
11
|
exports.getToolCallOutputItem = getToolCallOutputItem;
|
|
12
12
|
exports.executeFunctionToolCalls = executeFunctionToolCalls;
|
|
13
|
+
exports.executeShellActions = executeShellActions;
|
|
14
|
+
exports.executeApplyPatchOperations = executeApplyPatchOperations;
|
|
13
15
|
exports.executeComputerActions = executeComputerActions;
|
|
14
16
|
exports.executeHandoffCalls = executeHandoffCalls;
|
|
15
17
|
exports.checkForFinalOutputFromTools = checkForFinalOutputFromTools;
|
|
@@ -89,12 +91,16 @@ function processModelResponse(modelResponse, agent, tools, handoffs) {
|
|
|
89
91
|
const runHandoffs = [];
|
|
90
92
|
const runFunctions = [];
|
|
91
93
|
const runComputerActions = [];
|
|
94
|
+
const runShellActions = [];
|
|
95
|
+
const runApplyPatchActions = [];
|
|
92
96
|
const runMCPApprovalRequests = [];
|
|
93
97
|
const toolsUsed = [];
|
|
94
98
|
const handoffMap = new Map(handoffs.map((h) => [h.toolName, h]));
|
|
95
99
|
// Resolve tools upfront so we can look up the concrete handler in O(1) while iterating outputs.
|
|
96
100
|
const functionMap = new Map(tools.filter((t) => t.type === 'function').map((t) => [t.name, t]));
|
|
97
101
|
const computerTool = tools.find((t) => t.type === 'computer');
|
|
102
|
+
const shellTool = tools.find((t) => t.type === 'shell');
|
|
103
|
+
const applyPatchTool = tools.find((t) => t.type === 'apply_patch');
|
|
98
104
|
const mcpToolMap = new Map(tools
|
|
99
105
|
.filter((t) => t.type === 'hosted_tool' && t.providerData?.type === 'mcp')
|
|
100
106
|
.map((t) => t)
|
|
@@ -164,6 +170,40 @@ function processModelResponse(modelResponse, agent, tools, handoffs) {
|
|
|
164
170
|
computer: computerTool,
|
|
165
171
|
});
|
|
166
172
|
}
|
|
173
|
+
else if (output.type === 'shell_call') {
|
|
174
|
+
items.push(new items_1.RunToolCallItem(output, agent));
|
|
175
|
+
toolsUsed.push('shell');
|
|
176
|
+
if (!shellTool) {
|
|
177
|
+
(0, context_1.addErrorToCurrentSpan)({
|
|
178
|
+
message: 'Model produced shell action without a shell tool.',
|
|
179
|
+
data: {
|
|
180
|
+
agent_name: agent.name,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
throw new errors_1.ModelBehaviorError('Model produced shell action without a shell tool.');
|
|
184
|
+
}
|
|
185
|
+
runShellActions.push({
|
|
186
|
+
toolCall: output,
|
|
187
|
+
shell: shellTool,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
else if (output.type === 'apply_patch_call') {
|
|
191
|
+
items.push(new items_1.RunToolCallItem(output, agent));
|
|
192
|
+
toolsUsed.push('apply_patch');
|
|
193
|
+
if (!applyPatchTool) {
|
|
194
|
+
(0, context_1.addErrorToCurrentSpan)({
|
|
195
|
+
message: 'Model produced apply_patch action without an apply_patch tool.',
|
|
196
|
+
data: {
|
|
197
|
+
agent_name: agent.name,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
throw new errors_1.ModelBehaviorError('Model produced apply_patch action without an apply_patch tool.');
|
|
201
|
+
}
|
|
202
|
+
runApplyPatchActions.push({
|
|
203
|
+
toolCall: output,
|
|
204
|
+
applyPatch: applyPatchTool,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
167
207
|
if (output.type !== 'function_call') {
|
|
168
208
|
continue;
|
|
169
209
|
}
|
|
@@ -200,13 +240,17 @@ function processModelResponse(modelResponse, agent, tools, handoffs) {
|
|
|
200
240
|
handoffs: runHandoffs,
|
|
201
241
|
functions: runFunctions,
|
|
202
242
|
computerActions: runComputerActions,
|
|
243
|
+
shellActions: runShellActions,
|
|
244
|
+
applyPatchActions: runApplyPatchActions,
|
|
203
245
|
mcpApprovalRequests: runMCPApprovalRequests,
|
|
204
246
|
toolsUsed: toolsUsed,
|
|
205
247
|
hasToolsOrApprovalsToRun() {
|
|
206
248
|
return (runHandoffs.length > 0 ||
|
|
207
249
|
runFunctions.length > 0 ||
|
|
208
250
|
runMCPApprovalRequests.length > 0 ||
|
|
209
|
-
runComputerActions.length > 0
|
|
251
|
+
runComputerActions.length > 0 ||
|
|
252
|
+
runShellActions.length > 0 ||
|
|
253
|
+
runApplyPatchActions.length > 0);
|
|
210
254
|
},
|
|
211
255
|
};
|
|
212
256
|
}
|
|
@@ -374,10 +418,14 @@ async function resolveInterruptedTurn(agent, originalInput, originalPreStepItems
|
|
|
374
418
|
// Keep track of approvals we still need to surface next turn so HITL flows can resume cleanly.
|
|
375
419
|
for (const run of mcpApprovalRuns) {
|
|
376
420
|
// the approval_request_id "mcpr_123..."
|
|
377
|
-
const
|
|
421
|
+
const rawItem = run.requestItem.rawItem;
|
|
422
|
+
if (rawItem.type !== 'hosted_tool_call') {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
const approvalRequestId = rawItem.id;
|
|
378
426
|
const approved = state._context.isToolApproved({
|
|
379
427
|
// Since this item name must be the same with the one sent from Responses API server
|
|
380
|
-
toolName:
|
|
428
|
+
toolName: rawItem.name,
|
|
381
429
|
callId: approvalRequestId,
|
|
382
430
|
});
|
|
383
431
|
if (typeof approved !== 'undefined') {
|
|
@@ -464,9 +512,11 @@ async function resolveTurnAfterModelResponse(agent, originalInput, originalPreSt
|
|
|
464
512
|
appendIfNew(item);
|
|
465
513
|
}
|
|
466
514
|
// Run function tools and computer actions in parallel; neither depends on the other's side effects.
|
|
467
|
-
const [functionResults, computerResults] = await Promise.all([
|
|
515
|
+
const [functionResults, computerResults, shellResults, applyPatchResults] = await Promise.all([
|
|
468
516
|
executeFunctionToolCalls(agent, processedResponse.functions, runner, state),
|
|
469
517
|
executeComputerActions(agent, processedResponse.computerActions, runner, state._context),
|
|
518
|
+
executeShellActions(agent, processedResponse.shellActions, runner, state._context),
|
|
519
|
+
executeApplyPatchOperations(agent, processedResponse.applyPatchActions, runner, state._context),
|
|
470
520
|
]);
|
|
471
521
|
for (const result of functionResults) {
|
|
472
522
|
appendIfNew(result.runItem);
|
|
@@ -474,6 +524,12 @@ async function resolveTurnAfterModelResponse(agent, originalInput, originalPreSt
|
|
|
474
524
|
for (const item of computerResults) {
|
|
475
525
|
appendIfNew(item);
|
|
476
526
|
}
|
|
527
|
+
for (const item of shellResults) {
|
|
528
|
+
appendIfNew(item);
|
|
529
|
+
}
|
|
530
|
+
for (const item of applyPatchResults) {
|
|
531
|
+
appendIfNew(item);
|
|
532
|
+
}
|
|
477
533
|
// run hosted MCP approval requests
|
|
478
534
|
if (processedResponse.mcpApprovalRequests.length > 0) {
|
|
479
535
|
for (const approvalRequest of processedResponse.mcpApprovalRequests) {
|
|
@@ -537,6 +593,8 @@ async function resolveTurnAfterModelResponse(agent, originalInput, originalPreSt
|
|
|
537
593
|
// We should run the loop again so the model can see the tool results and respond.
|
|
538
594
|
const hadToolCallsOrActions = (processedResponse.functions?.length ?? 0) > 0 ||
|
|
539
595
|
(processedResponse.computerActions?.length ?? 0) > 0 ||
|
|
596
|
+
(processedResponse.shellActions?.length ?? 0) > 0 ||
|
|
597
|
+
(processedResponse.applyPatchActions?.length ?? 0) > 0 ||
|
|
540
598
|
(processedResponse.mcpApprovalRequests?.length ?? 0) > 0 ||
|
|
541
599
|
(processedResponse.handoffs?.length ?? 0) > 0;
|
|
542
600
|
if (hadToolCallsOrActions) {
|
|
@@ -905,6 +963,206 @@ async function _runComputerActionAndScreenshot(computer, toolCall) {
|
|
|
905
963
|
}
|
|
906
964
|
throw new Error('Computer does not implement screenshot()');
|
|
907
965
|
}
|
|
966
|
+
function toErrorMessage(error) {
|
|
967
|
+
if (error instanceof Error) {
|
|
968
|
+
return error.message || error.toString();
|
|
969
|
+
}
|
|
970
|
+
try {
|
|
971
|
+
return JSON.stringify(error);
|
|
972
|
+
}
|
|
973
|
+
catch {
|
|
974
|
+
return String(error);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
async function executeShellActions(agent, actions, runner, runContext, customLogger = undefined) {
|
|
978
|
+
const _logger = customLogger ?? logger_1.default;
|
|
979
|
+
const results = [];
|
|
980
|
+
for (const action of actions) {
|
|
981
|
+
const shellTool = action.shell;
|
|
982
|
+
const toolCall = action.toolCall;
|
|
983
|
+
const approvalItem = new items_1.RunToolApprovalItem(toolCall, agent, shellTool.name);
|
|
984
|
+
const requiresApproval = await shellTool.needsApproval(runContext, toolCall.action, toolCall.callId);
|
|
985
|
+
if (requiresApproval) {
|
|
986
|
+
if (shellTool.onApproval) {
|
|
987
|
+
const decision = await shellTool.onApproval(runContext, approvalItem);
|
|
988
|
+
if (decision.approve === true) {
|
|
989
|
+
runContext.approveTool(approvalItem);
|
|
990
|
+
}
|
|
991
|
+
else if (decision.approve === false) {
|
|
992
|
+
runContext.rejectTool(approvalItem);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
const approval = runContext.isToolApproved({
|
|
996
|
+
toolName: shellTool.name,
|
|
997
|
+
callId: toolCall.callId,
|
|
998
|
+
});
|
|
999
|
+
if (approval === false) {
|
|
1000
|
+
const response = 'Tool execution was not approved.';
|
|
1001
|
+
const rejectionOutput = {
|
|
1002
|
+
stdout: '',
|
|
1003
|
+
stderr: response,
|
|
1004
|
+
outcome: { type: 'exit', exitCode: null },
|
|
1005
|
+
};
|
|
1006
|
+
results.push(new items_1.RunToolCallOutputItem({
|
|
1007
|
+
type: 'shell_call_output',
|
|
1008
|
+
callId: toolCall.callId,
|
|
1009
|
+
output: [rejectionOutput],
|
|
1010
|
+
}, agent, response));
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
if (approval !== true) {
|
|
1014
|
+
results.push(approvalItem);
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
runner.emit('agent_tool_start', runContext, agent, shellTool, {
|
|
1019
|
+
toolCall,
|
|
1020
|
+
});
|
|
1021
|
+
if (typeof agent.emit === 'function') {
|
|
1022
|
+
agent.emit('agent_tool_start', runContext, shellTool, { toolCall });
|
|
1023
|
+
}
|
|
1024
|
+
let shellOutputs;
|
|
1025
|
+
const providerMeta = {};
|
|
1026
|
+
let maxOutputLength;
|
|
1027
|
+
try {
|
|
1028
|
+
const shellResult = await shellTool.shell.run(toolCall.action);
|
|
1029
|
+
shellOutputs = shellResult.output ?? [];
|
|
1030
|
+
if (shellResult.providerData) {
|
|
1031
|
+
Object.assign(providerMeta, shellResult.providerData);
|
|
1032
|
+
}
|
|
1033
|
+
if (typeof shellResult.maxOutputLength === 'number') {
|
|
1034
|
+
maxOutputLength = shellResult.maxOutputLength;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
catch (err) {
|
|
1038
|
+
const errorText = toErrorMessage(err);
|
|
1039
|
+
shellOutputs = [
|
|
1040
|
+
{
|
|
1041
|
+
stdout: '',
|
|
1042
|
+
stderr: errorText,
|
|
1043
|
+
outcome: { type: 'exit', exitCode: null },
|
|
1044
|
+
},
|
|
1045
|
+
];
|
|
1046
|
+
_logger.error('Failed to execute shell action:', err);
|
|
1047
|
+
}
|
|
1048
|
+
shellOutputs = shellOutputs ?? [];
|
|
1049
|
+
runner.emit('agent_tool_end', runContext, agent, shellTool, JSON.stringify(shellOutputs), {
|
|
1050
|
+
toolCall,
|
|
1051
|
+
});
|
|
1052
|
+
if (typeof agent.emit === 'function') {
|
|
1053
|
+
agent.emit('agent_tool_end', runContext, shellTool, JSON.stringify(shellOutputs), {
|
|
1054
|
+
toolCall,
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
const rawItem = {
|
|
1058
|
+
type: 'shell_call_output',
|
|
1059
|
+
callId: toolCall.callId,
|
|
1060
|
+
output: shellOutputs ?? [],
|
|
1061
|
+
};
|
|
1062
|
+
if (typeof maxOutputLength === 'number') {
|
|
1063
|
+
rawItem.maxOutputLength = maxOutputLength;
|
|
1064
|
+
}
|
|
1065
|
+
if (Object.keys(providerMeta).length > 0) {
|
|
1066
|
+
rawItem.providerData = providerMeta;
|
|
1067
|
+
}
|
|
1068
|
+
results.push(new items_1.RunToolCallOutputItem(rawItem, agent, rawItem.output));
|
|
1069
|
+
}
|
|
1070
|
+
return results;
|
|
1071
|
+
}
|
|
1072
|
+
async function executeApplyPatchOperations(agent, actions, runner, runContext, customLogger = undefined) {
|
|
1073
|
+
const _logger = customLogger ?? logger_1.default;
|
|
1074
|
+
const results = [];
|
|
1075
|
+
for (const action of actions) {
|
|
1076
|
+
const applyPatchTool = action.applyPatch;
|
|
1077
|
+
const toolCall = action.toolCall;
|
|
1078
|
+
const approvalItem = new items_1.RunToolApprovalItem(toolCall, agent, applyPatchTool.name);
|
|
1079
|
+
const requiresApproval = await applyPatchTool.needsApproval(runContext, toolCall.operation, toolCall.callId);
|
|
1080
|
+
if (requiresApproval) {
|
|
1081
|
+
if (applyPatchTool.onApproval) {
|
|
1082
|
+
const decision = await applyPatchTool.onApproval(runContext, approvalItem);
|
|
1083
|
+
if (decision.approve === true) {
|
|
1084
|
+
runContext.approveTool(approvalItem);
|
|
1085
|
+
}
|
|
1086
|
+
else if (decision.approve === false) {
|
|
1087
|
+
runContext.rejectTool(approvalItem);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
const approval = runContext.isToolApproved({
|
|
1091
|
+
toolName: applyPatchTool.name,
|
|
1092
|
+
callId: toolCall.callId,
|
|
1093
|
+
});
|
|
1094
|
+
if (approval === false) {
|
|
1095
|
+
const response = 'Tool execution was not approved.';
|
|
1096
|
+
results.push(new items_1.RunToolCallOutputItem({
|
|
1097
|
+
type: 'apply_patch_call_output',
|
|
1098
|
+
callId: toolCall.callId,
|
|
1099
|
+
status: 'failed',
|
|
1100
|
+
output: response,
|
|
1101
|
+
}, agent, response));
|
|
1102
|
+
continue;
|
|
1103
|
+
}
|
|
1104
|
+
if (approval !== true) {
|
|
1105
|
+
results.push(approvalItem);
|
|
1106
|
+
continue;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
runner.emit('agent_tool_start', runContext, agent, applyPatchTool, {
|
|
1110
|
+
toolCall,
|
|
1111
|
+
});
|
|
1112
|
+
if (typeof agent.emit === 'function') {
|
|
1113
|
+
agent.emit('agent_tool_start', runContext, applyPatchTool, {
|
|
1114
|
+
toolCall,
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
let status = 'completed';
|
|
1118
|
+
let output = '';
|
|
1119
|
+
try {
|
|
1120
|
+
let result;
|
|
1121
|
+
switch (toolCall.operation.type) {
|
|
1122
|
+
case 'create_file':
|
|
1123
|
+
result = await applyPatchTool.editor.createFile(toolCall.operation);
|
|
1124
|
+
break;
|
|
1125
|
+
case 'update_file':
|
|
1126
|
+
result = await applyPatchTool.editor.updateFile(toolCall.operation);
|
|
1127
|
+
break;
|
|
1128
|
+
case 'delete_file':
|
|
1129
|
+
result = await applyPatchTool.editor.deleteFile(toolCall.operation);
|
|
1130
|
+
break;
|
|
1131
|
+
default:
|
|
1132
|
+
throw new Error('Unsupported apply_patch operation');
|
|
1133
|
+
}
|
|
1134
|
+
if (result && typeof result.status === 'string') {
|
|
1135
|
+
status = result.status;
|
|
1136
|
+
}
|
|
1137
|
+
if (result && typeof result.output === 'string') {
|
|
1138
|
+
output = result.output;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
catch (err) {
|
|
1142
|
+
status = 'failed';
|
|
1143
|
+
output = toErrorMessage(err);
|
|
1144
|
+
_logger.error('Failed to execute apply_patch operation:', err);
|
|
1145
|
+
}
|
|
1146
|
+
runner.emit('agent_tool_end', runContext, agent, applyPatchTool, output, {
|
|
1147
|
+
toolCall,
|
|
1148
|
+
});
|
|
1149
|
+
if (typeof agent.emit === 'function') {
|
|
1150
|
+
agent.emit('agent_tool_end', runContext, applyPatchTool, output, {
|
|
1151
|
+
toolCall,
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
const rawItem = {
|
|
1155
|
+
type: 'apply_patch_call_output',
|
|
1156
|
+
callId: toolCall.callId,
|
|
1157
|
+
status,
|
|
1158
|
+
};
|
|
1159
|
+
if (output) {
|
|
1160
|
+
rawItem.output = output;
|
|
1161
|
+
}
|
|
1162
|
+
results.push(new items_1.RunToolCallOutputItem(rawItem, agent, output));
|
|
1163
|
+
}
|
|
1164
|
+
return results;
|
|
1165
|
+
}
|
|
908
1166
|
/**
|
|
909
1167
|
* @internal
|
|
910
1168
|
* Executes any computer-use actions emitted by the model and returns the resulting items so the
|