nolo-cli 0.33.0-alpha.18 → 0.33.0-alpha.19
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/{_executeModel-2N36X5OJ.js → _executeModel-XKWVTZAY.js} +11 -11
- package/{agentDeleteCommand-HWJXSW6W.js → agentDeleteCommand-ZU4H6F6M.js} +2 -2
- package/{agentEmailCommands-W4RJ323L.js → agentEmailCommands-6ULFXW4A.js} +11 -11
- package/{agentListCommands-RTK2KSVM.js → agentListCommands-VN7WCW7Z.js} +2 -2
- package/{agentMachineCommands-PZZH5H5U.js → agentMachineCommands-5PALVQBD.js} +3 -3
- package/{agentRecordCommands-5QROGD2I.js → agentRecordCommands-XEB66KRX.js} +11 -11
- package/{agentRunCommand-KUXEU2C3.js → agentRunCommand-IWXLTYGK.js} +11 -11
- package/{agentRuntimeLocal-W4BEGHEJ.js → agentRuntimeLocal-UWDOE55A.js} +2 -2
- package/{agentSlice-EZJ2W4JB.js → agentSlice-SZRRJ3ZX.js} +1 -1
- package/{appDeleteCommands-XNVZPXTU.js → appDeleteCommands-R63PZAY7.js} +2 -2
- package/{appDeployCommands-4ICNWWHP.js → appDeployCommands-VNRT54YO.js} +2 -2
- package/{appDeployStatusCommands-4KVAKNYQ.js → appDeployStatusCommands-6IPTKLEM.js} +2 -2
- package/{appGetCommands-YH4FTUX5.js → appGetCommands-JPFVMVAI.js} +2 -2
- package/{appListCommands-ZB7CYVNS.js → appListCommands-B3SLTPII.js} +2 -2
- package/{chatQueueReduxAdapter-2ZZZYKI3.js → chatQueueReduxAdapter-IEX32ZVP.js} +2 -2
- package/{chunk-YW4YRQUH.js → chunk-2UDMTJOM.js} +2 -2
- package/{chunk-Z4OGZWYZ.js → chunk-37LDAHQN.js} +3 -3
- package/{chunk-AQBJUKBP.js → chunk-7BNPRRDS.js} +9 -9
- package/{chunk-5ZOD4E7E.js → chunk-FR2AIV4Q.js} +6 -6
- package/{chunk-AWHJWUVD.js → chunk-JL2PUYVS.js} +8 -8
- package/{chunk-DFW73ZMB.js → chunk-LJGEEYGC.js} +1 -1
- package/{chunk-ZOQTWQOA.js → chunk-LLKHGZME.js} +3 -3
- package/{chunk-NXXNT43Y.js → chunk-PU47HKTF.js} +7 -7
- package/{chunk-XV4KDZ5L.js → chunk-REOW4YJX.js} +1 -1
- package/{chunk-QZPRTYLL.js → chunk-RO3AEN3L.js} +2 -2
- package/{chunk-WXOIYS2X.js → chunk-SBPGB6TF.js} +2 -2
- package/{chunk-7VCY56GH.js → chunk-U2FRXKC7.js} +1 -1
- package/{chunk-WAFMSVUX.js → chunk-V44VE7R4.js} +1 -1
- package/{chunk-5AQ5Q6ZE.js → chunk-XS543SNR.js} +3 -3
- package/{chunk-JALRRIVE.js → chunk-XTSVOICC.js} +6 -6
- package/{chunk-ITESDS27.js → chunk-YH3FPBG6.js} +376 -0
- package/{createAgentAutomationAction-GU3N7CWJ.js → createAgentAutomationAction-72NNXELT.js} +3 -3
- package/{createDialogAction-6E3BEQGM.js → createDialogAction-3CJ2GXNO.js} +4 -4
- package/{createPageAction-OBDG5ZXM.js → createPageAction-HZHQGQO6.js} +3 -3
- package/{dialogCommands-6I6TJNOH.js → dialogCommands-2BF4ZSWH.js} +2 -2
- package/{dialogSlice-Y57RVHZZ.js → dialogSlice-5R4O4377.js} +2 -2
- package/{docCreateCommands-KXOH2X2A.js → docCreateCommands-HMZUBFGL.js} +2 -2
- package/{docDeleteCommands-XHLPIXGC.js → docDeleteCommands-DFR7GCOR.js} +2 -2
- package/{docReadCommands-2BKCIAZ5.js → docReadCommands-YM7RDUAZ.js} +2 -2
- package/{docStore-A7I2ZFQB.js → docStore-A4SRW2DJ.js} +4 -4
- package/{docUpdateCommands-2XQJWZHN.js → docUpdateCommands-TTQBD7IU.js} +2 -2
- package/{handleSendMessageAction-HK2OIE4N.js → handleSendMessageAction-CIFBZCI2.js} +2 -2
- package/index.js +40 -40
- package/{machineCommands-HKV467DU.js → machineCommands-QSW4JKR2.js} +11 -11
- package/{machineWsRunDispatch-3R7MOVIQ.js → machineWsRunDispatch-X3ZC7DZJ.js} +11 -11
- package/package.json +1 -1
- package/{readlineWorkspace-ZBBCDHJG.js → readlineWorkspace-P6PZ64PS.js} +11 -11
- package/{runAgentClientLoop-FDNHKKGE.js → runAgentClientLoop-5I2R74NR.js} +8 -8
- package/{spaceCommands-LIBLXFUQ.js → spaceCommands-EZYMMJJH.js} +2 -2
- package/{spaceSlice-36IQZFI6.js → spaceSlice-TL2FR4AF.js} +3 -3
- package/{streamAgentChatTurn-2P5KBPCO.js → streamAgentChatTurn-UDYSE2ES.js} +10 -10
- package/{tools-SOOBK33N.js → tools-KWYWDJ77.js} +6 -6
- package/{updateDialogTitleAction-5ITPS25R.js → updateDialogTitleAction-NQCOEOLF.js} +3 -3
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "./chunk-CWMSB67P.js";
|
|
14
14
|
import {
|
|
15
15
|
runLlm
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-XS543SNR.js";
|
|
17
17
|
import {
|
|
18
18
|
cleanupCliSessionForDialog
|
|
19
19
|
} from "./chunk-FH7VUJN5.js";
|
|
@@ -3520,7 +3520,7 @@ var messageSlice = createSliceWithThunks({
|
|
|
3520
3520
|
runtimeOptions: args.runtimeOptions
|
|
3521
3521
|
});
|
|
3522
3522
|
if (agentKeyToUse) {
|
|
3523
|
-
const { streamAgentChatTurn } = await import("./agentSlice-
|
|
3523
|
+
const { streamAgentChatTurn } = await import("./agentSlice-SZRRJ3ZX.js");
|
|
3524
3524
|
await dispatch(
|
|
3525
3525
|
streamAgentChatTurn({
|
|
3526
3526
|
agentKey: agentKeyToUse,
|
|
@@ -4779,7 +4779,7 @@ var deleteDialogThunk = async (payload, thunkApi) => {
|
|
|
4779
4779
|
}
|
|
4780
4780
|
if (isCurrentDialog) {
|
|
4781
4781
|
await thunkApi.dispatch(resetMsgs());
|
|
4782
|
-
const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-
|
|
4782
|
+
const { clearPendingAttachments: clearPendingAttachments2 } = await import("./dialogSlice-5R4O4377.js");
|
|
4783
4783
|
dispatch(clearPendingAttachments2());
|
|
4784
4784
|
clearWorkflow();
|
|
4785
4785
|
}
|
|
@@ -4788,15 +4788,15 @@ var deleteDialogThunk = async (payload, thunkApi) => {
|
|
|
4788
4788
|
|
|
4789
4789
|
// packages/chat/dialog/dialogSlice.ts
|
|
4790
4790
|
var runCreateDialogAction = async (args, thunkApi) => {
|
|
4791
|
-
const { createDialogAction } = await import("./createDialogAction-
|
|
4791
|
+
const { createDialogAction } = await import("./createDialogAction-3CJ2GXNO.js");
|
|
4792
4792
|
return createDialogAction(args, thunkApi);
|
|
4793
4793
|
};
|
|
4794
4794
|
var runCreateAgentAutomationAction = async (args, thunkApi) => {
|
|
4795
|
-
const { createAgentAutomationAction } = await import("./createAgentAutomationAction-
|
|
4795
|
+
const { createAgentAutomationAction } = await import("./createAgentAutomationAction-72NNXELT.js");
|
|
4796
4796
|
return createAgentAutomationAction(args, thunkApi);
|
|
4797
4797
|
};
|
|
4798
4798
|
var runUpdateDialogTitleAction = async (args, thunkApi) => {
|
|
4799
|
-
const { updateDialogTitleAction } = await import("./updateDialogTitleAction-
|
|
4799
|
+
const { updateDialogTitleAction } = await import("./updateDialogTitleAction-NQCOEOLF.js");
|
|
4800
4800
|
return updateDialogTitleAction(args, thunkApi);
|
|
4801
4801
|
};
|
|
4802
4802
|
var runAddDialogAgentAction = async (args, thunkApi) => {
|
|
@@ -4820,7 +4820,7 @@ var runSetDialogExtraReferencesAction = async (args, thunkApi) => {
|
|
|
4820
4820
|
return setDialogExtraReferencesAction(args, thunkApi);
|
|
4821
4821
|
};
|
|
4822
4822
|
var runHandleSendMessageAction = async (args, thunkApi) => {
|
|
4823
|
-
const { handleSendMessageAction } = await import("./handleSendMessageAction-
|
|
4823
|
+
const { handleSendMessageAction } = await import("./handleSendMessageAction-CIFBZCI2.js");
|
|
4824
4824
|
return handleSendMessageAction(args, thunkApi);
|
|
4825
4825
|
};
|
|
4826
4826
|
function clearDialogState() {
|
|
@@ -4833,7 +4833,7 @@ var createPageAndAddReference = createAsyncThunk(
|
|
|
4833
4833
|
async (payload, { dispatch, getState, rejectWithValue }) => {
|
|
4834
4834
|
const { slateData, jsonData, title, type, fileId, groupId, dialogKey } = payload;
|
|
4835
4835
|
try {
|
|
4836
|
-
const { createDocState } = await import("./docStore-
|
|
4836
|
+
const { createDocState } = await import("./docStore-A4SRW2DJ.js");
|
|
4837
4837
|
const pageKey = await createDocState(
|
|
4838
4838
|
{ slateData, title },
|
|
4839
4839
|
{ dispatch, getState }
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createCliLocalRuntimeAdapter,
|
|
3
3
|
summarizeEndpoint
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XTSVOICC.js";
|
|
5
5
|
import {
|
|
6
6
|
clipMultilineText
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7BNPRRDS.js";
|
|
8
8
|
import {
|
|
9
9
|
runLocalAgentTurn
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-YH3FPBG6.js";
|
|
11
11
|
import {
|
|
12
12
|
resolveLocalRuntimeEnvFromPolicy
|
|
13
13
|
} from "./chunk-RQFO3CAF.js";
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
inlineImageUrlsForCustomProvider,
|
|
9
9
|
prepareTools,
|
|
10
10
|
shouldInlineImageUrlsForAgent
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-LJGEEYGC.js";
|
|
12
12
|
import {
|
|
13
13
|
performFetchRequest
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-37LDAHQN.js";
|
|
15
15
|
import {
|
|
16
16
|
createSSEParser,
|
|
17
17
|
createToolRunId,
|
|
@@ -22,22 +22,22 @@ import {
|
|
|
22
22
|
toolRunSetPending,
|
|
23
23
|
toolRunStarted,
|
|
24
24
|
toolRunSucceeded
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-7BNPRRDS.js";
|
|
26
26
|
import {
|
|
27
27
|
getCurrentSpaceId
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-2UDMTJOM.js";
|
|
29
29
|
import {
|
|
30
30
|
addToolMessage,
|
|
31
31
|
messageStreamEnd,
|
|
32
32
|
messageStreaming,
|
|
33
33
|
updateToolMessage
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-JL2PUYVS.js";
|
|
35
35
|
import {
|
|
36
36
|
streamAgentChatTurn
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-XS543SNR.js";
|
|
38
38
|
import {
|
|
39
39
|
EMPTY_ASSISTANT_REPAIR_PROMPT
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-YH3FPBG6.js";
|
|
41
41
|
import {
|
|
42
42
|
accumulateToolCallDelta,
|
|
43
43
|
createThinkParserState,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
addContentToSpace
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2UDMTJOM.js";
|
|
4
4
|
import {
|
|
5
5
|
prepareAndPersistMessage,
|
|
6
6
|
uiAskChoiceFunc,
|
|
7
7
|
uiAskChoiceFunctionSchema
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-JL2PUYVS.js";
|
|
9
9
|
import {
|
|
10
10
|
require_date_fns
|
|
11
11
|
} from "./chunk-M76ECQRD.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
updateContentTitle
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2UDMTJOM.js";
|
|
4
4
|
import {
|
|
5
5
|
require_date_fns
|
|
6
6
|
} from "./chunk-M76ECQRD.js";
|
|
@@ -367,7 +367,7 @@ async function saveDocState(arg, { dispatch, getState }) {
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
async function createDocState(args, thunkApi) {
|
|
370
|
-
const { createPageAction } = await import("./createPageAction-
|
|
370
|
+
const { createPageAction } = await import("./createPageAction-HZHQGQO6.js");
|
|
371
371
|
return createPageAction(args, thunkApi);
|
|
372
372
|
}
|
|
373
373
|
function subscribe(listener) {
|
|
@@ -304,7 +304,7 @@ var slice = createSliceWithThunks({
|
|
|
304
304
|
const overrides = {};
|
|
305
305
|
if (args.systemPromptOverride !== void 0) overrides.prompt = args.systemPromptOverride;
|
|
306
306
|
if (args.toolsOverride !== void 0) overrides.tools = args.toolsOverride;
|
|
307
|
-
const { _executeModel } = await import("./_executeModel-
|
|
307
|
+
const { _executeModel } = await import("./_executeModel-XKWVTZAY.js");
|
|
308
308
|
return _executeModel(
|
|
309
309
|
{
|
|
310
310
|
isStreaming: args.isStreaming ?? false,
|
|
@@ -325,7 +325,7 @@ var slice = createSliceWithThunks({
|
|
|
325
325
|
* - 循环直到无工具调用或触发其他运行时停止条件
|
|
326
326
|
*/
|
|
327
327
|
runAgent: create.asyncThunk(async (args, thunkApi) => {
|
|
328
|
-
const { runAgentClientLoop } = await import("./runAgentClientLoop-
|
|
328
|
+
const { runAgentClientLoop } = await import("./runAgentClientLoop-5I2R74NR.js");
|
|
329
329
|
const { content: loopContent, toolCallCount } = await runAgentClientLoop(
|
|
330
330
|
{
|
|
331
331
|
agentKey: args.agentKey,
|
|
@@ -341,7 +341,7 @@ var slice = createSliceWithThunks({
|
|
|
341
341
|
* 聊天轮次流式 Agent 调用
|
|
342
342
|
*/
|
|
343
343
|
streamAgentChatTurn: create.asyncThunk(async (args, thunkApi) => {
|
|
344
|
-
const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-
|
|
344
|
+
const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-UDYSE2ES.js");
|
|
345
345
|
return streamAgentChatTurnHandler(args, thunkApi);
|
|
346
346
|
}),
|
|
347
347
|
/**
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
inlineImageUrlsForCustomProvider,
|
|
22
22
|
prepareTools
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-LJGEEYGC.js";
|
|
24
24
|
import {
|
|
25
25
|
getServerProviderSecret
|
|
26
26
|
} from "./chunk-HS7MLR74.js";
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
rememberMemoryFunctionSchema,
|
|
40
40
|
resolveAgentRequiredPackIds,
|
|
41
41
|
setTodoListFunc
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-7BNPRRDS.js";
|
|
43
43
|
import {
|
|
44
44
|
createDrainExhaustedResponse,
|
|
45
45
|
isCoreDrainingBody,
|
|
@@ -55,13 +55,13 @@ import {
|
|
|
55
55
|
prepareTokenUsageData,
|
|
56
56
|
resolveBuiltinPlatformAgentConfig,
|
|
57
57
|
runKeyed
|
|
58
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-JL2PUYVS.js";
|
|
59
59
|
import {
|
|
60
60
|
BUILTIN_TITLE_LLM_CONFIG
|
|
61
61
|
} from "./chunk-RCFIB45Q.js";
|
|
62
62
|
import {
|
|
63
63
|
fetchServerSyncedCredential
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-XS543SNR.js";
|
|
65
65
|
import {
|
|
66
66
|
require_date_fns
|
|
67
67
|
} from "./chunk-M76ECQRD.js";
|
|
@@ -86,7 +86,7 @@ import {
|
|
|
86
86
|
parseSyncServersEnv,
|
|
87
87
|
resolveAgentNextAvailableAt,
|
|
88
88
|
resolveOpenAiCompatibleProviderConfig
|
|
89
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-REOW4YJX.js";
|
|
90
90
|
import {
|
|
91
91
|
buildPlatformChatCompletionRequest,
|
|
92
92
|
canUsePlatformChatProvider,
|
|
@@ -105,7 +105,7 @@ import {
|
|
|
105
105
|
import {
|
|
106
106
|
resolveHistoricalToolContentCap,
|
|
107
107
|
summarizeToolArguments
|
|
108
|
-
} from "./chunk-
|
|
108
|
+
} from "./chunk-YH3FPBG6.js";
|
|
109
109
|
import {
|
|
110
110
|
convertMessagesToResponsesInput,
|
|
111
111
|
toResponsesTools
|
|
@@ -1149,6 +1149,22 @@ ${stderr.trim()}` : "",
|
|
|
1149
1149
|
}
|
|
1150
1150
|
|
|
1151
1151
|
// packages/agent-runtime/capabilities/execShellCapability.ts
|
|
1152
|
+
function buildLocalExecShellContext(args) {
|
|
1153
|
+
return {
|
|
1154
|
+
workspaceRoot: args.workspaceRoot,
|
|
1155
|
+
...args.commandTimeoutMs !== void 0 ? { commandTimeoutMs: args.commandTimeoutMs } : {},
|
|
1156
|
+
...args.commandOutputLimit !== void 0 ? { commandOutputLimit: args.commandOutputLimit } : {},
|
|
1157
|
+
...args.commandPrefix ? { commandPrefix: args.commandPrefix } : {},
|
|
1158
|
+
...args.restrictToWorkspace !== void 0 ? { restrictToWorkspace: args.restrictToWorkspace } : {},
|
|
1159
|
+
...args.abortSignal ? { abortSignal: args.abortSignal } : {},
|
|
1160
|
+
...args.detachMs !== void 0 ? { detachMs: args.detachMs } : {},
|
|
1161
|
+
...args.confirmed !== void 0 ? { confirmed: args.confirmed } : {},
|
|
1162
|
+
...args.enableDestructiveShellGuard !== void 0 ? { enableDestructiveShellGuard: args.enableDestructiveShellGuard } : {},
|
|
1163
|
+
...args.confirmDestructiveAction ? { confirmDestructiveAction: args.confirmDestructiveAction } : {},
|
|
1164
|
+
...args.blockDestructiveWithoutConfirmation !== void 0 ? { blockDestructiveWithoutConfirmation: args.blockDestructiveWithoutConfirmation } : {},
|
|
1165
|
+
...args.onInvoke ? { onInvoke: args.onInvoke } : {}
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1152
1168
|
function buildExecShellToolDefinition(toolName = "execShell") {
|
|
1153
1169
|
return {
|
|
1154
1170
|
type: "function",
|
|
@@ -1344,6 +1360,313 @@ async function evaluateCapabilityPolicy(capability, normalizedInput, ctx) {
|
|
|
1344
1360
|
}
|
|
1345
1361
|
}
|
|
1346
1362
|
|
|
1363
|
+
// packages/agent-runtime/capabilities/agentRunService.ts
|
|
1364
|
+
var activityCounter = 0;
|
|
1365
|
+
function generateActivityId(prefix = "act") {
|
|
1366
|
+
activityCounter = (activityCounter + 1) % 1e6;
|
|
1367
|
+
return `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}-${activityCounter}`;
|
|
1368
|
+
}
|
|
1369
|
+
function combineSignals(signals) {
|
|
1370
|
+
const activeSignals = signals.filter((s) => Boolean(s));
|
|
1371
|
+
if (activeSignals.length === 0) return void 0;
|
|
1372
|
+
if (activeSignals.length === 1) return activeSignals[0];
|
|
1373
|
+
if (typeof AbortSignal.any === "function") {
|
|
1374
|
+
return AbortSignal.any(activeSignals);
|
|
1375
|
+
}
|
|
1376
|
+
const controller = new AbortController();
|
|
1377
|
+
for (const s of activeSignals) {
|
|
1378
|
+
if (s.aborted) {
|
|
1379
|
+
controller.abort(s.reason);
|
|
1380
|
+
return controller.signal;
|
|
1381
|
+
}
|
|
1382
|
+
s.addEventListener("abort", () => controller.abort(s.reason), { once: true });
|
|
1383
|
+
}
|
|
1384
|
+
return controller.signal;
|
|
1385
|
+
}
|
|
1386
|
+
async function executeAgentRunLifecycle(service, input, ctx = {}) {
|
|
1387
|
+
const agentKey = input.agentKey ?? input.agentId;
|
|
1388
|
+
if (!agentKey || typeof agentKey !== "string" || !agentKey.trim()) {
|
|
1389
|
+
throw new Error("agents.run: \u7F3A\u5C11\u6709\u6548\u7684 agentId \u6216 agentKey\u3002");
|
|
1390
|
+
}
|
|
1391
|
+
if (!input.task || typeof input.task !== "string" || !input.task.trim()) {
|
|
1392
|
+
throw new Error("agents.run: \u7F3A\u5C11\u6709\u6548\u7684 task \u6587\u672C\u63CF\u8FF0\u3002");
|
|
1393
|
+
}
|
|
1394
|
+
const effectiveSignal = combineSignals([input.signal, ctx.abortSignal]);
|
|
1395
|
+
if (effectiveSignal?.aborted) {
|
|
1396
|
+
const abortErr = new Error("Agent run was aborted before starting");
|
|
1397
|
+
abortErr.name = "AbortError";
|
|
1398
|
+
throw abortErr;
|
|
1399
|
+
}
|
|
1400
|
+
const activityId = generateActivityId("act-run");
|
|
1401
|
+
const parentActivityId = input.parentActivityId ?? ctx.activityContext?.parentActivityId ?? ctx.parentActivityId;
|
|
1402
|
+
const startedAt = Date.now();
|
|
1403
|
+
const activity = {
|
|
1404
|
+
activityId,
|
|
1405
|
+
...parentActivityId ? { parentActivityId } : {},
|
|
1406
|
+
kind: "agent-run",
|
|
1407
|
+
agentId: agentKey,
|
|
1408
|
+
...input.agentName ? { agentName: input.agentName } : {},
|
|
1409
|
+
task: input.task,
|
|
1410
|
+
status: "starting",
|
|
1411
|
+
startedAt
|
|
1412
|
+
};
|
|
1413
|
+
const emit = async (type) => {
|
|
1414
|
+
if (ctx.onActivity) {
|
|
1415
|
+
try {
|
|
1416
|
+
await ctx.onActivity({
|
|
1417
|
+
type,
|
|
1418
|
+
activity: { ...activity }
|
|
1419
|
+
});
|
|
1420
|
+
} catch {
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
await emit("activity-started");
|
|
1425
|
+
let startResult;
|
|
1426
|
+
try {
|
|
1427
|
+
startResult = await service.start(
|
|
1428
|
+
{
|
|
1429
|
+
agentId: agentKey,
|
|
1430
|
+
agentKey,
|
|
1431
|
+
task: input.task,
|
|
1432
|
+
input: input.input,
|
|
1433
|
+
agentName: input.agentName,
|
|
1434
|
+
ephemeral: input.ephemeral,
|
|
1435
|
+
batchId: input.batchId,
|
|
1436
|
+
parentActivityId,
|
|
1437
|
+
signal: effectiveSignal
|
|
1438
|
+
},
|
|
1439
|
+
ctx
|
|
1440
|
+
);
|
|
1441
|
+
} catch (err) {
|
|
1442
|
+
const errorMsg = err?.message || String(err);
|
|
1443
|
+
const finishedAt2 = Date.now();
|
|
1444
|
+
activity.status = "failed";
|
|
1445
|
+
activity.finishedAt = finishedAt2;
|
|
1446
|
+
activity.durationMs = finishedAt2 - startedAt;
|
|
1447
|
+
activity.error = errorMsg;
|
|
1448
|
+
await emit("activity-finished");
|
|
1449
|
+
throw err;
|
|
1450
|
+
}
|
|
1451
|
+
const runId = startResult.runId;
|
|
1452
|
+
activity.runId = runId;
|
|
1453
|
+
if (startResult.status === "done" || startResult.status === "completed") {
|
|
1454
|
+
const finishedAt2 = Date.now();
|
|
1455
|
+
activity.status = "completed";
|
|
1456
|
+
activity.finishedAt = finishedAt2;
|
|
1457
|
+
activity.durationMs = finishedAt2 - startedAt;
|
|
1458
|
+
activity.result = startResult.content;
|
|
1459
|
+
await emit("activity-finished");
|
|
1460
|
+
return {
|
|
1461
|
+
runId,
|
|
1462
|
+
status: "completed",
|
|
1463
|
+
content: startResult.content ?? "",
|
|
1464
|
+
activityId,
|
|
1465
|
+
durationMs: activity.durationMs
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
if (startResult.status === "failed") {
|
|
1469
|
+
const finishedAt2 = Date.now();
|
|
1470
|
+
activity.status = "failed";
|
|
1471
|
+
activity.finishedAt = finishedAt2;
|
|
1472
|
+
activity.durationMs = finishedAt2 - startedAt;
|
|
1473
|
+
activity.error = "Agent run start failed";
|
|
1474
|
+
await emit("activity-finished");
|
|
1475
|
+
throw new Error(`Agent run ${runId} failed on start.`);
|
|
1476
|
+
}
|
|
1477
|
+
activity.status = "running";
|
|
1478
|
+
await emit("activity-updated");
|
|
1479
|
+
let abortCleanup;
|
|
1480
|
+
if (effectiveSignal && service.cancel) {
|
|
1481
|
+
const onAbort = () => {
|
|
1482
|
+
service.cancel?.({ runId, signal: effectiveSignal }, ctx).catch(() => {
|
|
1483
|
+
});
|
|
1484
|
+
};
|
|
1485
|
+
if (effectiveSignal.aborted) {
|
|
1486
|
+
onAbort();
|
|
1487
|
+
} else {
|
|
1488
|
+
effectiveSignal.addEventListener("abort", onAbort, { once: true });
|
|
1489
|
+
abortCleanup = () => effectiveSignal.removeEventListener("abort", onAbort);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
let waitResult;
|
|
1493
|
+
try {
|
|
1494
|
+
waitResult = await service.wait(
|
|
1495
|
+
{
|
|
1496
|
+
runId,
|
|
1497
|
+
timeoutMs: input.timeoutMs ?? ctx.agentRunTimeoutMs,
|
|
1498
|
+
signal: effectiveSignal
|
|
1499
|
+
},
|
|
1500
|
+
ctx
|
|
1501
|
+
);
|
|
1502
|
+
} catch (err) {
|
|
1503
|
+
abortCleanup?.();
|
|
1504
|
+
const errorMsg = err?.message || String(err);
|
|
1505
|
+
const finishedAt2 = Date.now();
|
|
1506
|
+
activity.status = effectiveSignal?.aborted ? "cancelled" : "failed";
|
|
1507
|
+
activity.finishedAt = finishedAt2;
|
|
1508
|
+
activity.durationMs = finishedAt2 - startedAt;
|
|
1509
|
+
activity.error = errorMsg;
|
|
1510
|
+
await emit("activity-finished");
|
|
1511
|
+
throw err;
|
|
1512
|
+
} finally {
|
|
1513
|
+
abortCleanup?.();
|
|
1514
|
+
}
|
|
1515
|
+
const finishedAt = Date.now();
|
|
1516
|
+
activity.finishedAt = finishedAt;
|
|
1517
|
+
activity.durationMs = finishedAt - startedAt;
|
|
1518
|
+
if (waitResult.status === "done" || waitResult.status === "completed") {
|
|
1519
|
+
activity.status = "completed";
|
|
1520
|
+
activity.result = waitResult.content;
|
|
1521
|
+
await emit("activity-finished");
|
|
1522
|
+
return {
|
|
1523
|
+
runId,
|
|
1524
|
+
status: "completed",
|
|
1525
|
+
content: waitResult.content ?? "",
|
|
1526
|
+
activityId,
|
|
1527
|
+
durationMs: activity.durationMs,
|
|
1528
|
+
raw: waitResult.raw
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
if (waitResult.status === "cancelled" || waitResult.status === "killed" || effectiveSignal?.aborted) {
|
|
1532
|
+
activity.status = "cancelled";
|
|
1533
|
+
await emit("activity-finished");
|
|
1534
|
+
return {
|
|
1535
|
+
runId,
|
|
1536
|
+
status: "cancelled",
|
|
1537
|
+
content: waitResult.content ?? "",
|
|
1538
|
+
activityId,
|
|
1539
|
+
durationMs: activity.durationMs,
|
|
1540
|
+
raw: waitResult.raw
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
if (waitResult.status === "timeout") {
|
|
1544
|
+
activity.status = "failed";
|
|
1545
|
+
activity.error = "Agent run timed out";
|
|
1546
|
+
if (service.cancel) {
|
|
1547
|
+
service.cancel({ runId }, ctx).catch(() => {
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
await emit("activity-finished");
|
|
1551
|
+
return {
|
|
1552
|
+
runId,
|
|
1553
|
+
status: "timeout",
|
|
1554
|
+
content: waitResult.content ?? "",
|
|
1555
|
+
activityId,
|
|
1556
|
+
durationMs: activity.durationMs,
|
|
1557
|
+
error: "Agent run timed out",
|
|
1558
|
+
raw: waitResult.raw
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
activity.status = "failed";
|
|
1562
|
+
activity.error = waitResult.errorMessage ?? `Agent run finished with status "${waitResult.status}"`;
|
|
1563
|
+
await emit("activity-finished");
|
|
1564
|
+
throw new Error(activity.error);
|
|
1565
|
+
}
|
|
1566
|
+
function createToolBridgeAgentRunService(options) {
|
|
1567
|
+
return {
|
|
1568
|
+
start: async (opts) => {
|
|
1569
|
+
const res = await options.startRunner(opts);
|
|
1570
|
+
const raw = res.rawData;
|
|
1571
|
+
if (typeof raw === "string") {
|
|
1572
|
+
return {
|
|
1573
|
+
runId: generateActivityId("sync-run"),
|
|
1574
|
+
status: "done",
|
|
1575
|
+
content: raw
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
return {
|
|
1579
|
+
runId: raw?.runId ?? generateActivityId("run"),
|
|
1580
|
+
status: raw?.status ?? "pending",
|
|
1581
|
+
agentKey: raw?.agentKey,
|
|
1582
|
+
agentName: raw?.agentName,
|
|
1583
|
+
batchId: raw?.batchId,
|
|
1584
|
+
taskPreview: raw?.taskPreview,
|
|
1585
|
+
content: raw?.content
|
|
1586
|
+
};
|
|
1587
|
+
},
|
|
1588
|
+
wait: async (opts) => {
|
|
1589
|
+
const res = await options.waitRunner(opts);
|
|
1590
|
+
const raw = res.rawData;
|
|
1591
|
+
return {
|
|
1592
|
+
runId: raw?.runId ?? opts.runId,
|
|
1593
|
+
status: raw?.status ?? "done",
|
|
1594
|
+
content: typeof raw === "string" ? raw : raw?.content ?? res.displayData,
|
|
1595
|
+
errorMessage: raw?.errorMessage ?? raw?.error,
|
|
1596
|
+
raw
|
|
1597
|
+
};
|
|
1598
|
+
},
|
|
1599
|
+
cancel: options.cancelRunner ? async (opts) => {
|
|
1600
|
+
const res = await options.cancelRunner({ runId: opts.runId });
|
|
1601
|
+
return {
|
|
1602
|
+
runId: res.rawData?.runId ?? opts.runId,
|
|
1603
|
+
status: res.rawData?.status ?? "cancelled",
|
|
1604
|
+
wasActive: res.rawData?.wasActive
|
|
1605
|
+
};
|
|
1606
|
+
} : void 0,
|
|
1607
|
+
inspect: options.inspectRunner ? async (opts) => {
|
|
1608
|
+
const res = await options.inspectRunner({ runId: opts.runId, tailLines: opts.tailLines });
|
|
1609
|
+
return {
|
|
1610
|
+
runId: res.rawData?.runId ?? opts.runId,
|
|
1611
|
+
found: res.rawData?.found ?? true,
|
|
1612
|
+
status: res.rawData?.status,
|
|
1613
|
+
logLines: res.rawData?.logLines
|
|
1614
|
+
};
|
|
1615
|
+
} : void 0
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
var toolCallSeq = 0;
|
|
1619
|
+
function createHostToolAgentRunService(hostExecuteTool) {
|
|
1620
|
+
const execTool = async (name, args, opts) => {
|
|
1621
|
+
const id = `sdk-${Date.now().toString(36)}-${(++toolCallSeq).toString(36)}`;
|
|
1622
|
+
const res = await hostExecuteTool({ id, name, arguments: JSON.stringify(args) }, opts);
|
|
1623
|
+
let rawData = res.content;
|
|
1624
|
+
if (typeof res.content === "string" && res.content.length) {
|
|
1625
|
+
try {
|
|
1626
|
+
rawData = JSON.parse(res.content);
|
|
1627
|
+
} catch {
|
|
1628
|
+
rawData = res.content;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
if (rawData && typeof rawData === "object" && typeof rawData.error === "string") {
|
|
1632
|
+
throw new Error(rawData.error);
|
|
1633
|
+
}
|
|
1634
|
+
return {
|
|
1635
|
+
rawData,
|
|
1636
|
+
displayData: typeof res.metadata?.displayData === "string" ? res.metadata.displayData : String(res.content ?? "")
|
|
1637
|
+
};
|
|
1638
|
+
};
|
|
1639
|
+
return createToolBridgeAgentRunService({
|
|
1640
|
+
startRunner: async (opts) => execTool("startAgentRun", {
|
|
1641
|
+
agentKey: opts.agentKey ?? opts.agentId,
|
|
1642
|
+
task: opts.task,
|
|
1643
|
+
input: opts.input,
|
|
1644
|
+
agentName: opts.agentName,
|
|
1645
|
+
ephemeral: opts.ephemeral,
|
|
1646
|
+
batchId: opts.batchId,
|
|
1647
|
+
parentDialogId: opts.parentDialogId,
|
|
1648
|
+
wait: false
|
|
1649
|
+
}),
|
|
1650
|
+
waitRunner: async (opts) => execTool(
|
|
1651
|
+
"controlAgentRun",
|
|
1652
|
+
{
|
|
1653
|
+
action: "wait",
|
|
1654
|
+
runId: opts.runId,
|
|
1655
|
+
timeoutMs: opts.timeoutMs
|
|
1656
|
+
},
|
|
1657
|
+
// Forward the per-run abort signal so the host wait loop can be
|
|
1658
|
+
// cancelled (CLI controlAgentRun wait reads opts.abortSignal).
|
|
1659
|
+
{ abortSignal: opts.signal }
|
|
1660
|
+
),
|
|
1661
|
+
cancelRunner: async ({ runId }) => execTool("controlAgentRun", { action: "stop", runId }),
|
|
1662
|
+
inspectRunner: async ({ runId, tailLines }) => execTool("controlAgentRun", {
|
|
1663
|
+
action: "status",
|
|
1664
|
+
runId,
|
|
1665
|
+
tailLines: tailLines ?? 0
|
|
1666
|
+
})
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1347
1670
|
// packages/agent-runtime/capabilities/capabilitySdk.ts
|
|
1348
1671
|
var BUILTIN_CAPABILITIES = [
|
|
1349
1672
|
execShellCapability
|
|
@@ -1360,6 +1683,31 @@ async function invokeCapability(capabilityOrName, input, ctx = {}) {
|
|
|
1360
1683
|
}
|
|
1361
1684
|
return capability.invoke(ctx, normalizedInput);
|
|
1362
1685
|
}
|
|
1686
|
+
function createCapabilitySdk(args) {
|
|
1687
|
+
const registry2 = /* @__PURE__ */ new Map();
|
|
1688
|
+
for (const cap of args.capabilities ?? BUILTIN_CAPABILITIES) {
|
|
1689
|
+
registry2.set(cap.name, cap);
|
|
1690
|
+
}
|
|
1691
|
+
const invoke = async (name, input) => {
|
|
1692
|
+
const capability = registry2.get(name);
|
|
1693
|
+
if (!capability) {
|
|
1694
|
+
throw new Error(`Capability "${name}" not found.`);
|
|
1695
|
+
}
|
|
1696
|
+
return invokeCapability(capability, input, args.context);
|
|
1697
|
+
};
|
|
1698
|
+
return {
|
|
1699
|
+
execShell: (input) => invoke("execShell", input),
|
|
1700
|
+
agents: {
|
|
1701
|
+
run: async (input) => {
|
|
1702
|
+
if (!args.context.agentRunService) {
|
|
1703
|
+
throw new Error("CapabilityExecutionContext missing agentRunService for agents.run()");
|
|
1704
|
+
}
|
|
1705
|
+
return executeAgentRunLifecycle(args.context.agentRunService, input, args.context);
|
|
1706
|
+
}
|
|
1707
|
+
},
|
|
1708
|
+
invoke
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1363
1711
|
|
|
1364
1712
|
// packages/agent-runtime/toolCallPairing.ts
|
|
1365
1713
|
function readToolCallId(message) {
|
|
@@ -2338,6 +2686,18 @@ function applyPersistedTurnInput(messages, persistedInput, persistedInputReferen
|
|
|
2338
2686
|
};
|
|
2339
2687
|
});
|
|
2340
2688
|
}
|
|
2689
|
+
function createLocalCapabilitySdk(adapter, execShellContext) {
|
|
2690
|
+
return createCapabilitySdk({
|
|
2691
|
+
context: {
|
|
2692
|
+
agentRunService: createHostToolAgentRunService(adapter.executeTool),
|
|
2693
|
+
// Inject the SAME local execution context the host uses for execShell,
|
|
2694
|
+
// so PTC tools.execShell() is no more permissive than normal local tool
|
|
2695
|
+
// calling. Caller supplies the real values (workspaceRoot, restrictToWorkspace,
|
|
2696
|
+
// timeout/output limits, destructive-shell guard semantics, abortSignal).
|
|
2697
|
+
...execShellContext
|
|
2698
|
+
}
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2341
2701
|
async function runLocalAgentTurn(input) {
|
|
2342
2702
|
const agentConfig = await input.adapter.loadAgentConfig(input.agentRef);
|
|
2343
2703
|
if (!agentConfig) {
|
|
@@ -2348,6 +2708,22 @@ async function runLocalAgentTurn(input) {
|
|
|
2348
2708
|
error.agentRef = input.agentRef;
|
|
2349
2709
|
throw error;
|
|
2350
2710
|
}
|
|
2711
|
+
const execShellContext = buildLocalExecShellContext({
|
|
2712
|
+
workspaceRoot: typeof input.runtimeContext?.workspaceRoot === "string" ? input.runtimeContext.workspaceRoot : typeof input.runtimeContext?.cwd === "string" ? input.runtimeContext.cwd : process.cwd(),
|
|
2713
|
+
...typeof input.runtimeContext?.restrictToWorkspace === "boolean" ? { restrictToWorkspace: input.runtimeContext.restrictToWorkspace } : typeof input.runtimeContext?.restrictShellToWorkspace === "boolean" ? { restrictToWorkspace: input.runtimeContext.restrictShellToWorkspace } : {},
|
|
2714
|
+
...typeof input.runtimeContext?.commandTimeoutMs === "number" ? { commandTimeoutMs: input.runtimeContext.commandTimeoutMs } : {},
|
|
2715
|
+
...typeof input.runtimeContext?.commandOutputLimit === "number" ? { commandOutputLimit: input.runtimeContext.commandOutputLimit } : {},
|
|
2716
|
+
...Array.isArray(input.runtimeContext?.commandPrefix) ? { commandPrefix: input.runtimeContext.commandPrefix } : {},
|
|
2717
|
+
...input.abortSignal ? { abortSignal: input.abortSignal } : {},
|
|
2718
|
+
...typeof input.runtimeContext?.detachMs === "number" ? { detachMs: input.runtimeContext.detachMs } : {},
|
|
2719
|
+
...typeof input.runtimeContext?.enableDestructiveShellGuard === "boolean" ? { enableDestructiveShellGuard: input.runtimeContext.enableDestructiveShellGuard } : {},
|
|
2720
|
+
...typeof input.runtimeContext?.confirmDestructiveAction === "function" ? { confirmDestructiveAction: input.runtimeContext.confirmDestructiveAction } : {},
|
|
2721
|
+
...typeof input.runtimeContext?.blockDestructiveWithoutConfirmation === "boolean" ? { blockDestructiveWithoutConfirmation: input.runtimeContext.blockDestructiveWithoutConfirmation } : {}
|
|
2722
|
+
});
|
|
2723
|
+
const tools = createLocalCapabilitySdk(input.adapter, execShellContext);
|
|
2724
|
+
if (input.__testProgram) {
|
|
2725
|
+
await input.__testProgram(tools);
|
|
2726
|
+
}
|
|
2351
2727
|
const rawBillingConfig = agentConfig.rawRecord ?? {};
|
|
2352
2728
|
const billingConfig = {
|
|
2353
2729
|
model: agentConfig.model || "unknown",
|