nolo-cli 0.8.0-alpha.11 → 0.8.0-alpha.13
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-GPU2276G.js → _executeModel-EBU7YBDV.js} +26 -22
- package/{action-PAXRPJJF.js → action-SQGI5JY5.js} +5 -4
- package/{addContentAction-CZVWF3QZ.js → addContentAction-ZX2PUS3X.js} +4 -3
- package/{addDialogAgentAction-CCIDTPHC.js → addDialogAgentAction-ULADQX2Q.js} +3 -2
- package/{agentDeleteCommand-4ZZFM6AT.js → agentDeleteCommand-GNVYHOGZ.js} +11 -8
- package/{agentEmailCommands-C4FIVQYV.js → agentEmailCommands-IC52LATA.js} +29 -25
- package/{agentListCommands-VQAKVNEX.js → agentListCommands-FM4OWXYT.js} +12 -9
- package/{agentMachineCommands-ONFDXZUQ.js → agentMachineCommands-SFWC6KN4.js} +11 -8
- package/{agentRecordCommands-QANUGHLK.js → agentRecordCommands-VLMLWLCM.js} +29 -25
- package/{agentRunCommand-A3OSRB5Q.js → agentRunCommand-D2PVHUGR.js} +30 -25
- package/{agentRuntimeLocal-62ZB2ODP.js → agentRuntimeLocal-XL5PLRJV.js} +16 -12
- package/{agentSlice-GCGLVR2N.js → agentSlice-IIC7AISR.js} +5 -4
- package/{chunk-YOUZDXU7.js → chunk-3N55DSXH.js} +21 -17
- package/chunk-4ZDM73SD.js +34 -0
- package/{chunk-TDIQFT2F.js → chunk-5CS33IBL.js} +1 -1
- package/{chunk-IYQV26RA.js → chunk-6A3LI5TZ.js} +2 -2
- package/{chunk-VEJLAVTC.js → chunk-6CBN7GGH.js} +2 -2
- package/{chunk-BSTNFPHD.js → chunk-6XKX2N2E.js} +1 -1
- package/{chunk-7OC5VCLW.js → chunk-7EPLXPTM.js} +4 -4
- package/{chunk-GCMRDRCQ.js → chunk-7IPLJUYC.js} +1 -1
- package/{chunk-53DNV5AT.js → chunk-7U4TQSWU.js} +3 -3
- package/{chunk-GGUO4FKF.js → chunk-7XN726FS.js} +41 -19
- package/{chunk-I3D64LRJ.js → chunk-BKPVTIEK.js} +4 -4
- package/{chunk-7YLKNMOM.js → chunk-DAB7DRXD.js} +6 -6
- package/{chunk-LM25IZBJ.js → chunk-DG7AAAR3.js} +1 -1
- package/{chunk-F6QQI5YI.js → chunk-DGFWICQJ.js} +1 -1
- package/chunk-DSNONPGW.js +386 -0
- package/{chunk-LAWBMYBC.js → chunk-FE2TZO7Z.js} +2 -2
- package/{chunk-R2HXWML7.js → chunk-HLM6MG7F.js} +19 -20
- package/chunk-I42VC5KR.js +15 -0
- package/{chunk-J5KV47ZW.js → chunk-IBJC3GOP.js} +2 -2
- package/chunk-JEXVIMYZ.js +55 -0
- package/{chunk-6B7G54GE.js → chunk-KH4OXCBK.js} +5 -5
- package/{chunk-SYOF5TAS.js → chunk-MXLQWBVM.js} +36 -95
- package/chunk-OPZYGHUC.js +89 -0
- package/{chunk-J4576WMJ.js → chunk-PCWC3JTN.js} +1 -1
- package/{chunk-HEIIIZBX.js → chunk-Q2YZULBH.js} +1 -1
- package/{chunk-KB7YFGL6.js → chunk-Q3K5K4KS.js} +1 -1
- package/{chunk-IAXBCTTE.js → chunk-QO4YO77G.js} +2 -2
- package/{chunk-GGXABIPP.js → chunk-RJKDVL4L.js} +2 -2
- package/{chunk-CJH2VTEU.js → chunk-RLCFUU46.js} +3 -3
- package/{chunk-2UZXR7WO.js → chunk-SACYB45H.js} +19 -378
- package/{chunk-PN7AFLOK.js → chunk-SH2CFQOH.js} +3 -13
- package/{chunk-XBIUN5CR.js → chunk-TWPGVS2U.js} +2 -2
- package/{chunk-G5H7RNFL.js → chunk-V2AISYMA.js} +2 -2
- package/{chunk-TZNCFAUP.js → chunk-XOH46MRF.js} +8 -15
- package/{chunk-CQAHS7YO.js → chunk-YDESHYQC.js} +56 -12
- package/{chunk-AUGHVUFE.js → chunk-YYUCRDOK.js} +1 -1
- package/{chunk-H2RMRZJE.js → chunk-ZDXZSXYQ.js} +1 -1
- package/{chunk-NXZGF7F7.js → chunk-ZQ2UM4KG.js} +1 -1
- package/{chunk-QR5IPGT3.js → chunk-ZRS4MX3R.js} +170 -176
- package/{createAgentAutomationAction-537X433B.js → createAgentAutomationAction-GNRYFKTT.js} +12 -10
- package/{createDialogAction-YUD4RKBS.js → createDialogAction-Q4ISCARO.js} +15 -13
- package/{createPageAction-KJMFHL4C.js → createPageAction-7YCAZPK3.js} +13 -11
- package/{dbSlice-C4UJLRZP.js → dbSlice-TO2TSMWM.js} +3 -2
- package/{dialogCommands-H74KJKHC.js → dialogCommands-DWSE4PMW.js} +13 -10
- package/{dialogSlice-ETSD4YWS.js → dialogSlice-5KZA46HM.js} +12 -10
- package/{docCreateCommands-ADUSU34K.js → docCreateCommands-UFJL5PUM.js} +12 -9
- package/{docDeleteCommands-ZXV3S5OS.js → docDeleteCommands-XHEIBAB2.js} +13 -10
- package/{docReadCommands-YYYI6LT7.js → docReadCommands-PEDIC2CW.js} +12 -9
- package/{docStore-ZBF5DDKR.js → docStore-M7K7QFVS.js} +13 -11
- package/{docUpdateCommands-7MGJ3BYA.js → docUpdateCommands-WBRODQ7P.js} +12 -9
- package/{fetchMessages-JOCYIFKL.js → fetchMessages-U6ZHN56A.js} +3 -2
- package/{handleSendMessageAction-MGKI62Y6.js → handleSendMessageAction-SEV4YIPL.js} +12 -10
- package/index.js +40 -36
- package/{localDialogRead-D3BELSTF.js → localDialogRead-Z5UTAJPU.js} +1 -1
- package/{machineCommands-RMTMN7VQ.js → machineCommands-T4DN3MOU.js} +28 -24
- package/{machineWsRunDispatch-UIP355FN.js → machineWsRunDispatch-QRIIT2AK.js} +28 -24
- package/package.json +1 -1
- package/{readlineWorkspace-CRNQRZ6D.js → readlineWorkspace-DXOTOVHL.js} +163 -31
- package/{removeDialogAgentAction-CXLST3N6.js → removeDialogAgentAction-3MUQGFZX.js} +5 -4
- package/{runAgentClientLoop-2S334SGA.js → runAgentClientLoop-UEQEP3XG.js} +21 -19
- package/{setDialogExtraReferencesAction-LP6VYGU7.js → setDialogExtraReferencesAction-MXHX2HPK.js} +3 -2
- package/{setPrimaryDialogAgentAction-D3GGH23T.js → setPrimaryDialogAgentAction-7DLDZHDT.js} +5 -4
- package/{settingSlice-J4I3Z5H7.js → settingSlice-PNLASZGI.js} +4 -3
- package/{spaceCommands-NDEWMFZJ.js → spaceCommands-ORSFAWEY.js} +11 -8
- package/{spaceSlice-RLB6RTHO.js → spaceSlice-HOMW64JA.js} +12 -10
- package/{streamAgentChatTurn-Y2TTYPBD.js → streamAgentChatTurn-REWDBIL3.js} +28 -26
- package/{tools-YZYLY2ZQ.js → tools-L4UQS5VW.js} +19 -17
- package/tuiSummaryLlmCaller-JSI4GL6W.js +78 -0
- package/{understanding-HCSFPE7R.js → understanding-YH4X3XU6.js} +3 -2
- package/{updateDialogTitleAction-LQV6QLBW.js → updateDialogTitleAction-CKLNP73H.js} +14 -11
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
createFileCredentialBroker,
|
|
4
4
|
migrateAgentSecrets,
|
|
5
5
|
normalizeAgentRuntimeToolPolicy
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5CS33IBL.js";
|
|
7
7
|
import {
|
|
8
8
|
patch,
|
|
9
9
|
remove,
|
|
10
10
|
write
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-V2AISYMA.js";
|
|
12
12
|
import {
|
|
13
13
|
asRecordOrEmpty
|
|
14
14
|
} from "./chunk-KX6YBIHG.js";
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
createAgentKey,
|
|
17
17
|
require_index_umd,
|
|
18
18
|
toTrimmedString
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-SH2CFQOH.js";
|
|
20
20
|
import {
|
|
21
21
|
asyncThunkCreator,
|
|
22
22
|
buildCreateSlice,
|
|
@@ -289,7 +289,7 @@ var slice = createSliceWithThunks({
|
|
|
289
289
|
const overrides = {};
|
|
290
290
|
if (args.systemPromptOverride !== void 0) overrides.prompt = args.systemPromptOverride;
|
|
291
291
|
if (args.toolsOverride !== void 0) overrides.tools = args.toolsOverride;
|
|
292
|
-
const { _executeModel } = await import("./_executeModel-
|
|
292
|
+
const { _executeModel } = await import("./_executeModel-EBU7YBDV.js");
|
|
293
293
|
return _executeModel(
|
|
294
294
|
{
|
|
295
295
|
isStreaming: args.isStreaming ?? false,
|
|
@@ -310,7 +310,7 @@ var slice = createSliceWithThunks({
|
|
|
310
310
|
* - 循环直到无工具调用或触发其他运行时停止条件
|
|
311
311
|
*/
|
|
312
312
|
runAgent: create.asyncThunk(async (args, thunkApi) => {
|
|
313
|
-
const { runAgentClientLoop } = await import("./runAgentClientLoop-
|
|
313
|
+
const { runAgentClientLoop } = await import("./runAgentClientLoop-UEQEP3XG.js");
|
|
314
314
|
const { content: loopContent, toolCallCount } = await runAgentClientLoop(
|
|
315
315
|
{
|
|
316
316
|
agentKey: args.agentKey,
|
|
@@ -326,7 +326,7 @@ var slice = createSliceWithThunks({
|
|
|
326
326
|
* 聊天轮次流式 Agent 调用
|
|
327
327
|
*/
|
|
328
328
|
streamAgentChatTurn: create.asyncThunk(async (args, thunkApi) => {
|
|
329
|
-
const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-
|
|
329
|
+
const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-REWDBIL3.js");
|
|
330
330
|
return streamAgentChatTurnHandler(args, thunkApi);
|
|
331
331
|
}),
|
|
332
332
|
/**
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractThinkContent,
|
|
3
|
+
flushThinkParser,
|
|
4
|
+
processThinkChunk
|
|
5
|
+
} from "./chunk-OPZYGHUC.js";
|
|
6
|
+
import {
|
|
7
|
+
buildProviderExecutionPlan,
|
|
8
|
+
canUsePlatformChatProvider,
|
|
9
|
+
convertMessagesToResponsesInput,
|
|
10
|
+
extractTextFromResponseOutput,
|
|
11
|
+
extractToolCallsFromResponseOutput,
|
|
12
|
+
hasDirectOpenAiCompatibleProvider,
|
|
13
|
+
resolveAgentRuntimeLocation,
|
|
14
|
+
resolvePlatformAuthToken,
|
|
15
|
+
resolvePlatformServerUrl,
|
|
16
|
+
resolveProviderTransportDecision,
|
|
17
|
+
toResponsesTools
|
|
18
|
+
} from "./chunk-XDVAYP26.js";
|
|
19
|
+
|
|
20
|
+
// packages/agent-runtime/openAiCompatibleMessages.ts
|
|
21
|
+
function toOpenAiCompatibleMessages(messages) {
|
|
22
|
+
return messages.map((message) => ({
|
|
23
|
+
role: message.role,
|
|
24
|
+
content: message.content ?? "",
|
|
25
|
+
...message.tool_call_id ? { tool_call_id: message.tool_call_id } : {},
|
|
26
|
+
...Array.isArray(message.tool_calls) ? { tool_calls: message.tool_calls } : {},
|
|
27
|
+
...message.reasoning_content ? { reasoning_content: message.reasoning_content } : {}
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// packages/agent-runtime/toolCallAccumulator.ts
|
|
32
|
+
function accumulateToolCallDelta(accumulated, deltas) {
|
|
33
|
+
for (const delta of deltas) {
|
|
34
|
+
const index = typeof delta.index === "number" ? delta.index : 0;
|
|
35
|
+
const current = accumulated[index] ?? {
|
|
36
|
+
id: "",
|
|
37
|
+
type: "function",
|
|
38
|
+
function: { name: "", arguments: "" }
|
|
39
|
+
};
|
|
40
|
+
if (typeof delta.id === "string" && delta.id) current.id = delta.id;
|
|
41
|
+
const fn = delta.function;
|
|
42
|
+
if (fn && typeof fn === "object") {
|
|
43
|
+
const functionDelta = fn;
|
|
44
|
+
if (typeof functionDelta.name === "string" && functionDelta.name) {
|
|
45
|
+
current.function.name += functionDelta.name;
|
|
46
|
+
}
|
|
47
|
+
if (typeof functionDelta.arguments === "string" && functionDelta.arguments) {
|
|
48
|
+
current.function.arguments += functionDelta.arguments;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
accumulated[index] = current;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function finalizeAccumulatedToolCalls(accumulated) {
|
|
55
|
+
return Object.keys(accumulated).map((key) => accumulated[Number(key)]).filter((call) => call?.function?.name);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// packages/agent-runtime/processChatCompletionDelta.ts
|
|
59
|
+
function extractChatCompletionStreamError(parsed) {
|
|
60
|
+
const raw = parsed?.error;
|
|
61
|
+
if (!raw) return null;
|
|
62
|
+
if (typeof raw === "string") {
|
|
63
|
+
return raw.trim() ? { message: raw.trim() } : null;
|
|
64
|
+
}
|
|
65
|
+
if (typeof raw !== "object") return null;
|
|
66
|
+
const message = typeof raw.msg === "string" && raw.msg.trim() ? raw.msg.trim() : typeof raw.message === "string" && raw.message.trim() ? raw.message.trim() : "";
|
|
67
|
+
const code = typeof raw.code === "string" && raw.code.trim() ? raw.code.trim() : typeof raw.type === "string" && raw.type.trim() ? raw.type.trim() : void 0;
|
|
68
|
+
if (!message && !code) return null;
|
|
69
|
+
return {
|
|
70
|
+
message: message || "upstream stream error",
|
|
71
|
+
...code ? { code } : {}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function throwIfChatCompletionStreamFailed(state) {
|
|
75
|
+
const failure = state.streamError;
|
|
76
|
+
if (!failure) return;
|
|
77
|
+
const error = new Error(
|
|
78
|
+
failure.code ? `${failure.message} (${failure.code})` : failure.message
|
|
79
|
+
);
|
|
80
|
+
if (failure.code) error.code = failure.code;
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
function applyChatCompletionDelta(parsed, state) {
|
|
84
|
+
const streamError = extractChatCompletionStreamError(parsed);
|
|
85
|
+
if (streamError && !state.streamError) {
|
|
86
|
+
state.streamError = streamError;
|
|
87
|
+
}
|
|
88
|
+
if (parsed?.usage && typeof parsed.usage === "object") {
|
|
89
|
+
state.usage = parsed.usage;
|
|
90
|
+
}
|
|
91
|
+
const rawFinishReason = parsed?.choices?.[0]?.finish_reason;
|
|
92
|
+
if (typeof rawFinishReason === "string" && rawFinishReason.length > 0) {
|
|
93
|
+
state.finishReason = rawFinishReason;
|
|
94
|
+
}
|
|
95
|
+
const delta = parsed?.choices?.[0]?.delta;
|
|
96
|
+
if (!delta || typeof delta !== "object") return false;
|
|
97
|
+
const reasoningChunk = typeof delta.reasoning_content === "string" ? delta.reasoning_content : typeof delta.reasoning === "string" ? delta.reasoning : "";
|
|
98
|
+
if (reasoningChunk) {
|
|
99
|
+
state.reasoning += reasoningChunk;
|
|
100
|
+
state.onReasoningDelta?.(reasoningChunk);
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(delta.tool_calls) && delta.tool_calls.length > 0) {
|
|
103
|
+
accumulateToolCallDelta(state.accumulatedToolCalls, delta.tool_calls);
|
|
104
|
+
}
|
|
105
|
+
const textChunk = typeof delta.content === "string" ? delta.content : "";
|
|
106
|
+
if (textChunk) {
|
|
107
|
+
const parsedChunk = processThinkChunk(textChunk, state.thinkState);
|
|
108
|
+
state.thinkState = parsedChunk.state;
|
|
109
|
+
if (parsedChunk.content) {
|
|
110
|
+
state.content += parsedChunk.content;
|
|
111
|
+
state.onTextDelta?.(parsedChunk.content);
|
|
112
|
+
}
|
|
113
|
+
if (parsedChunk.reasoning) {
|
|
114
|
+
state.reasoning += parsedChunk.reasoning;
|
|
115
|
+
state.onReasoningDelta?.(parsedChunk.reasoning);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
function flushChatCompletionStream(state) {
|
|
121
|
+
const flushed = flushThinkParser(state.thinkState);
|
|
122
|
+
state.thinkState = flushed.state;
|
|
123
|
+
if (flushed.content) {
|
|
124
|
+
state.content += flushed.content;
|
|
125
|
+
state.onTextDelta?.(flushed.content);
|
|
126
|
+
}
|
|
127
|
+
if (flushed.reasoning) {
|
|
128
|
+
state.reasoning += flushed.reasoning;
|
|
129
|
+
state.onReasoningDelta?.(flushed.reasoning);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// packages/agent-runtime/sseFrames.ts
|
|
134
|
+
async function* readSseFrames(response) {
|
|
135
|
+
const reader = response.body?.getReader();
|
|
136
|
+
if (!reader) {
|
|
137
|
+
throw new Error("SSE response did not include a readable body.");
|
|
138
|
+
}
|
|
139
|
+
const decoder = new TextDecoder();
|
|
140
|
+
let buffer = "";
|
|
141
|
+
while (true) {
|
|
142
|
+
const { done, value } = await reader.read();
|
|
143
|
+
if (done) break;
|
|
144
|
+
buffer += decoder.decode(value, { stream: true });
|
|
145
|
+
let boundary = buffer.indexOf("\n\n");
|
|
146
|
+
while (boundary !== -1) {
|
|
147
|
+
yield buffer.slice(0, boundary);
|
|
148
|
+
buffer = buffer.slice(boundary + 2);
|
|
149
|
+
boundary = buffer.indexOf("\n\n");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (buffer.trim()) yield buffer;
|
|
153
|
+
}
|
|
154
|
+
async function readSseDataValues(response, parse) {
|
|
155
|
+
const reader = response.body?.getReader();
|
|
156
|
+
if (!reader) return [];
|
|
157
|
+
const decoder = new TextDecoder();
|
|
158
|
+
const values = [];
|
|
159
|
+
let buffer = "";
|
|
160
|
+
while (true) {
|
|
161
|
+
const { done, value } = await reader.read();
|
|
162
|
+
if (done) break;
|
|
163
|
+
buffer += decoder.decode(value, { stream: true });
|
|
164
|
+
const lines = buffer.split("\n");
|
|
165
|
+
buffer = lines.pop() ?? "";
|
|
166
|
+
for (const line of lines) {
|
|
167
|
+
const parsed = parse(line);
|
|
168
|
+
if (parsed) values.push(parsed);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (buffer.trim()) {
|
|
172
|
+
const parsed = parse(buffer);
|
|
173
|
+
if (parsed) values.push(parsed);
|
|
174
|
+
}
|
|
175
|
+
return values;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// packages/agent-runtime/platformChatProvider.ts
|
|
179
|
+
var CHAT_PROXY_PATH = "/api/v1/chat";
|
|
180
|
+
function shouldDisableThinking(providerConfig) {
|
|
181
|
+
return providerConfig.provider.toLowerCase() === "mimo" || /xiaomimimo\.com/i.test(providerConfig.endpoint);
|
|
182
|
+
}
|
|
183
|
+
function isResponsesEndpoint(endpoint) {
|
|
184
|
+
return /\/responses$/i.test(endpoint.trim());
|
|
185
|
+
}
|
|
186
|
+
function toResponsesRequestOptions(options) {
|
|
187
|
+
const next = { ...options };
|
|
188
|
+
const reasoningEffort = next.reasoning_effort;
|
|
189
|
+
if (typeof reasoningEffort === "string" && reasoningEffort) {
|
|
190
|
+
next.reasoning = { effort: reasoningEffort };
|
|
191
|
+
delete next.reasoning_effort;
|
|
192
|
+
}
|
|
193
|
+
if (next.max_tokens !== void 0) {
|
|
194
|
+
next.max_output_tokens = next.max_tokens;
|
|
195
|
+
delete next.max_tokens;
|
|
196
|
+
}
|
|
197
|
+
return next;
|
|
198
|
+
}
|
|
199
|
+
async function resolvePlatformChatProviderConfig(args) {
|
|
200
|
+
const plan = await buildProviderExecutionPlan({
|
|
201
|
+
agentConfig: args.agentConfig,
|
|
202
|
+
env: args.env,
|
|
203
|
+
runtimeKind: "local",
|
|
204
|
+
...args.apiKeyRefResolver ? { apiKeyRefResolver: args.apiKeyRefResolver } : {},
|
|
205
|
+
...args.credentialBroker ? { credentialBroker: args.credentialBroker } : {},
|
|
206
|
+
...args.syncFetcher ? { syncFetcher: args.syncFetcher } : {}
|
|
207
|
+
});
|
|
208
|
+
if (plan.mode === "cli") {
|
|
209
|
+
throw new Error("Platform chat provider does not support cli agents.");
|
|
210
|
+
}
|
|
211
|
+
if (plan.transport === "direct") {
|
|
212
|
+
return {
|
|
213
|
+
serverUrl: resolvePlatformServerUrl(args.env),
|
|
214
|
+
authToken: resolvePlatformAuthToken(args.env),
|
|
215
|
+
agentKey: args.agentConfig.key,
|
|
216
|
+
model: plan.model,
|
|
217
|
+
provider: plan.provider,
|
|
218
|
+
endpoint: plan.endpoint,
|
|
219
|
+
requestOptions: plan.requestOptions,
|
|
220
|
+
...plan.apiKey ? { apiKey: plan.apiKey } : {},
|
|
221
|
+
...plan.apiKeyHeader ? { apiKeyHeader: plan.apiKeyHeader } : {},
|
|
222
|
+
...args.agentConfig.apiSource ? { apiSource: args.agentConfig.apiSource } : {}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
serverUrl: plan.serverUrl,
|
|
227
|
+
authToken: plan.authToken,
|
|
228
|
+
agentKey: plan.agentKey,
|
|
229
|
+
model: plan.model,
|
|
230
|
+
provider: plan.provider,
|
|
231
|
+
endpoint: plan.endpoint,
|
|
232
|
+
requestOptions: plan.requestOptions,
|
|
233
|
+
...plan.apiKey ? { apiKey: plan.apiKey } : {},
|
|
234
|
+
...plan.apiKeyHeader ? { apiKeyHeader: plan.apiKeyHeader } : {},
|
|
235
|
+
...plan.apiSource ? { apiSource: plan.apiSource } : {}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function buildPlatformChatCompletionRequest(args) {
|
|
239
|
+
const usesResponsesApi = isResponsesEndpoint(args.providerConfig.endpoint);
|
|
240
|
+
const requestOptions = usesResponsesApi ? toResponsesRequestOptions(args.providerConfig.requestOptions) : args.providerConfig.requestOptions;
|
|
241
|
+
const body = {
|
|
242
|
+
model: args.providerConfig.model,
|
|
243
|
+
...usesResponsesApi ? { input: convertMessagesToResponsesInput(args.messages) } : { messages: toOpenAiCompatibleMessages(args.messages) },
|
|
244
|
+
stream: args.stream ?? false,
|
|
245
|
+
...args.stream ? { stream_options: { include_usage: true } } : {},
|
|
246
|
+
...requestOptions,
|
|
247
|
+
...args.tools && args.tools.length > 0 ? {
|
|
248
|
+
tools: usesResponsesApi ? toResponsesTools(args.tools) : args.tools,
|
|
249
|
+
...usesResponsesApi ? {} : { tool_choice: "auto" }
|
|
250
|
+
} : {},
|
|
251
|
+
...shouldDisableThinking(args.providerConfig) ? { thinking: { type: "disabled" } } : {},
|
|
252
|
+
url: args.providerConfig.endpoint,
|
|
253
|
+
provider: args.providerConfig.provider,
|
|
254
|
+
agentKey: args.providerConfig.agentKey,
|
|
255
|
+
...args.providerConfig.apiSource ? { apiSource: args.providerConfig.apiSource } : {},
|
|
256
|
+
...args.providerConfig.apiKey ? { KEY: args.providerConfig.apiKey } : {},
|
|
257
|
+
...args.providerConfig.apiKeyHeader ? { apiKeyHeader: args.providerConfig.apiKeyHeader } : {}
|
|
258
|
+
};
|
|
259
|
+
return {
|
|
260
|
+
url: `${args.providerConfig.serverUrl}${CHAT_PROXY_PATH}`,
|
|
261
|
+
init: {
|
|
262
|
+
method: "POST",
|
|
263
|
+
headers: {
|
|
264
|
+
"Content-Type": "application/json",
|
|
265
|
+
Authorization: `Bearer ${args.providerConfig.authToken}`
|
|
266
|
+
},
|
|
267
|
+
body: JSON.stringify(body)
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function tryParseJson(raw) {
|
|
272
|
+
try {
|
|
273
|
+
return JSON.parse(raw);
|
|
274
|
+
} catch {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function extractJsonObjects(raw) {
|
|
279
|
+
const objects = [];
|
|
280
|
+
let depth = 0;
|
|
281
|
+
let start = -1;
|
|
282
|
+
let inString = false;
|
|
283
|
+
let escaped = false;
|
|
284
|
+
for (let index = 0; index < raw.length; index += 1) {
|
|
285
|
+
const char = raw[index];
|
|
286
|
+
if (inString) {
|
|
287
|
+
if (escaped) {
|
|
288
|
+
escaped = false;
|
|
289
|
+
} else if (char === "\\") {
|
|
290
|
+
escaped = true;
|
|
291
|
+
} else if (char === '"') {
|
|
292
|
+
inString = false;
|
|
293
|
+
}
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (char === '"') {
|
|
297
|
+
inString = true;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (char === "{") {
|
|
301
|
+
if (depth === 0) start = index;
|
|
302
|
+
depth += 1;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (char !== "}" || depth === 0) continue;
|
|
306
|
+
depth -= 1;
|
|
307
|
+
if (depth === 0 && start >= 0) {
|
|
308
|
+
const parsed = tryParseJson(raw.slice(start, index + 1));
|
|
309
|
+
if (parsed) objects.push(parsed);
|
|
310
|
+
start = -1;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return objects;
|
|
314
|
+
}
|
|
315
|
+
function parsePlatformChatCompletionData(raw) {
|
|
316
|
+
const direct = tryParseJson(raw.trim());
|
|
317
|
+
if (direct) return direct;
|
|
318
|
+
const objects = extractJsonObjects(raw);
|
|
319
|
+
return objects.find((object) => Array.isArray(object?.choices)) ?? objects[0] ?? {};
|
|
320
|
+
}
|
|
321
|
+
function parsePlatformChatCompletionResponse(args) {
|
|
322
|
+
if (isResponsesEndpoint(args.providerConfig.endpoint)) {
|
|
323
|
+
const content2 = extractTextFromResponseOutput(args.data);
|
|
324
|
+
const tool_calls = extractToolCallsFromResponseOutput(args.data);
|
|
325
|
+
return {
|
|
326
|
+
content: content2,
|
|
327
|
+
model: args.providerConfig.model,
|
|
328
|
+
provider: args.providerConfig.provider,
|
|
329
|
+
...tool_calls.length > 0 ? { tool_calls } : {},
|
|
330
|
+
usage: args.data?.usage,
|
|
331
|
+
trace: args.trace
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
const choiceMessage = args.data?.choices?.[0]?.message ?? {};
|
|
335
|
+
const rawContent = String(choiceMessage?.content ?? "");
|
|
336
|
+
const { content, reasoning } = extractThinkContent(rawContent);
|
|
337
|
+
return {
|
|
338
|
+
content,
|
|
339
|
+
model: args.providerConfig.model,
|
|
340
|
+
provider: args.providerConfig.provider,
|
|
341
|
+
...Array.isArray(choiceMessage?.tool_calls) ? { tool_calls: choiceMessage.tool_calls } : {},
|
|
342
|
+
...reasoning ? { reasoning_content: reasoning } : typeof choiceMessage?.reasoning_content === "string" && choiceMessage.reasoning_content ? { reasoning_content: choiceMessage.reasoning_content } : {},
|
|
343
|
+
usage: args.data?.usage,
|
|
344
|
+
trace: args.trace
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function canUsePlatformChatProvider2(env) {
|
|
348
|
+
return canUsePlatformChatProvider(env);
|
|
349
|
+
}
|
|
350
|
+
function hasDirectOpenAiCompatibleProvider2(env) {
|
|
351
|
+
return hasDirectOpenAiCompatibleProvider(env);
|
|
352
|
+
}
|
|
353
|
+
function shouldUsePlatformChatProvider(env, agentConfig) {
|
|
354
|
+
if (!agentConfig) {
|
|
355
|
+
return resolveProviderTransportDecision({
|
|
356
|
+
agentConfig: { key: "default-platform" },
|
|
357
|
+
env,
|
|
358
|
+
runtimeLocation: "local-host"
|
|
359
|
+
}).transport === "proxy";
|
|
360
|
+
}
|
|
361
|
+
return resolveProviderTransportDecision({
|
|
362
|
+
agentConfig,
|
|
363
|
+
env,
|
|
364
|
+
runtimeLocation: resolveAgentRuntimeLocation({
|
|
365
|
+
agentConfig,
|
|
366
|
+
runtimeKind: "local"
|
|
367
|
+
})
|
|
368
|
+
}).transport === "proxy";
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export {
|
|
372
|
+
finalizeAccumulatedToolCalls,
|
|
373
|
+
throwIfChatCompletionStreamFailed,
|
|
374
|
+
applyChatCompletionDelta,
|
|
375
|
+
flushChatCompletionStream,
|
|
376
|
+
toOpenAiCompatibleMessages,
|
|
377
|
+
readSseFrames,
|
|
378
|
+
readSseDataValues,
|
|
379
|
+
resolvePlatformChatProviderConfig,
|
|
380
|
+
buildPlatformChatCompletionRequest,
|
|
381
|
+
parsePlatformChatCompletionData,
|
|
382
|
+
parsePlatformChatCompletionResponse,
|
|
383
|
+
canUsePlatformChatProvider2 as canUsePlatformChatProvider,
|
|
384
|
+
hasDirectOpenAiCompatibleProvider2 as hasDirectOpenAiCompatibleProvider,
|
|
385
|
+
shouldUsePlatformChatProvider
|
|
386
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
i18n_default,
|
|
3
3
|
toolRegistry
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7XN726FS.js";
|
|
5
5
|
import {
|
|
6
6
|
canonicalizeToolNames
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-DG7AAAR3.js";
|
|
8
8
|
import {
|
|
9
9
|
asTrimmedLowercaseString
|
|
10
10
|
} from "./chunk-QSJ3HFEF.js";
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clipHeadAndTail
|
|
3
|
+
} from "./chunk-JEXVIMYZ.js";
|
|
1
4
|
import {
|
|
2
5
|
prepareTools
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FE2TZO7Z.js";
|
|
4
7
|
import {
|
|
5
8
|
getPublicImageAgentMode
|
|
6
9
|
} from "./chunk-VIDPVFP3.js";
|
|
7
10
|
import {
|
|
8
11
|
performFetchRequest
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-XOH46MRF.js";
|
|
10
13
|
import {
|
|
11
14
|
createSSEParser,
|
|
12
15
|
createToolRunId,
|
|
@@ -17,7 +20,7 @@ import {
|
|
|
17
20
|
toolRunSetPending,
|
|
18
21
|
toolRunStarted,
|
|
19
22
|
toolRunSucceeded
|
|
20
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-7XN726FS.js";
|
|
21
24
|
import {
|
|
22
25
|
addToolMessage,
|
|
23
26
|
getModelInfo,
|
|
@@ -25,16 +28,18 @@ import {
|
|
|
25
28
|
messageStreaming,
|
|
26
29
|
selectCurrentSpaceId,
|
|
27
30
|
updateToolMessage
|
|
28
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-ZRS4MX3R.js";
|
|
29
32
|
import {
|
|
30
33
|
streamAgentChatTurn
|
|
31
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-DAB7DRXD.js";
|
|
35
|
+
import {
|
|
36
|
+
EMPTY_ASSISTANT_REPAIR_PROMPT
|
|
37
|
+
} from "./chunk-MXLQWBVM.js";
|
|
32
38
|
import {
|
|
33
|
-
EMPTY_ASSISTANT_REPAIR_PROMPT,
|
|
34
39
|
createThinkParserState,
|
|
35
40
|
flushThinkParser,
|
|
36
41
|
processThinkChunk
|
|
37
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-OPZYGHUC.js";
|
|
38
43
|
import {
|
|
39
44
|
getApiEndpoint
|
|
40
45
|
} from "./chunk-572EKYLF.js";
|
|
@@ -54,15 +59,15 @@ import {
|
|
|
54
59
|
} from "./chunk-HNMXYYJR.js";
|
|
55
60
|
import {
|
|
56
61
|
selectCurrentServer
|
|
57
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-6CBN7GGH.js";
|
|
58
63
|
import {
|
|
59
64
|
write
|
|
60
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-V2AISYMA.js";
|
|
61
66
|
import {
|
|
62
67
|
createDialogMessageKeyAndId,
|
|
63
68
|
dialogMessageKey,
|
|
64
69
|
toTrimmedString
|
|
65
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-SH2CFQOH.js";
|
|
66
71
|
import {
|
|
67
72
|
createAsyncThunk,
|
|
68
73
|
selectIdentityToken
|
|
@@ -81,12 +86,6 @@ import {
|
|
|
81
86
|
} from "./chunk-KUG52IAP.js";
|
|
82
87
|
|
|
83
88
|
// packages/integrations/openai/filterAndCleanMessages.ts
|
|
84
|
-
var TOOL_CONTEXT_MAX_CHARS = 4e3;
|
|
85
|
-
var truncateText = (text, maxChars = TOOL_CONTEXT_MAX_CHARS) => {
|
|
86
|
-
if (text.length <= maxChars) return text;
|
|
87
|
-
return `${text.slice(0, maxChars)}
|
|
88
|
-
\u2026[\u622A\u65AD\uFF0C\u539F\u59CB\u957F\u5EA6 ${text.length} \u5B57\u7B26]`;
|
|
89
|
-
};
|
|
90
89
|
var isValidMessagePart = (part) => {
|
|
91
90
|
if (!part || typeof part !== "object") return false;
|
|
92
91
|
if (part.type === "text") return typeof part.text === "string";
|
|
@@ -99,11 +98,11 @@ var isValidMessagePart = (part) => {
|
|
|
99
98
|
var extractContent = (msg) => {
|
|
100
99
|
if (msg.role === "tool") {
|
|
101
100
|
const llmContext = asTrimmedString(msg.toolPayload?.llmContext);
|
|
102
|
-
if (llmContext) return
|
|
101
|
+
if (llmContext) return clipHeadAndTail(llmContext, { toolCallId: extractToolCallId(msg) ?? void 0 }).content;
|
|
103
102
|
const summary = asTrimmedString(msg.toolPayload?.summary);
|
|
104
|
-
if (summary) return
|
|
105
|
-
if (typeof msg.content === "string") return
|
|
106
|
-
if (msg.content != null) return
|
|
103
|
+
if (summary) return clipHeadAndTail(summary, { toolCallId: extractToolCallId(msg) ?? void 0 }).content;
|
|
104
|
+
if (typeof msg.content === "string") return clipHeadAndTail(msg.content, { toolCallId: extractToolCallId(msg) ?? void 0 }).content;
|
|
105
|
+
if (msg.content != null) return clipHeadAndTail(JSON.stringify(msg.content), { toolCallId: extractToolCallId(msg) ?? void 0 }).content;
|
|
107
106
|
return null;
|
|
108
107
|
}
|
|
109
108
|
if (typeof msg.content === "string") return msg.content;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// packages/core/stringArray.ts
|
|
2
|
+
function asNonEmptyStringArray(value) {
|
|
3
|
+
if (!Array.isArray(value)) return [];
|
|
4
|
+
return value.filter(
|
|
5
|
+
(item) => typeof item === "string" && !!item.trim()
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
function asTrimmedNonEmptyStringArray(value) {
|
|
9
|
+
return asNonEmptyStringArray(value).map((item) => item.trim());
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
asNonEmptyStringArray,
|
|
14
|
+
asTrimmedNonEmptyStringArray
|
|
15
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
clearCliLocalRuntimePreparedAgentCache
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3N55DSXH.js";
|
|
4
4
|
import {
|
|
5
5
|
getReadableCliDb
|
|
6
6
|
} from "./chunk-W4NVOSFF.js";
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
resolveAgentRecordFromHybridStore,
|
|
13
13
|
sanitizeAgentRecordForCliOutput,
|
|
14
14
|
writeAgentRecord
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-RJKDVL4L.js";
|
|
16
16
|
import {
|
|
17
17
|
resolveCliAgentKeyInput
|
|
18
18
|
} from "./chunk-VHBWHNVT.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// packages/core/clipHeadAndTail.ts
|
|
2
|
+
import { writeFileSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
function clipHeadAndTail(rawContent, options = {}) {
|
|
6
|
+
const maxHeadBytes = options.maxHeadBytes ?? 1e3;
|
|
7
|
+
const maxTailBytes = options.maxTailBytes ?? 2500;
|
|
8
|
+
const maxTotalBytes = options.maxTotalBytes ?? 4e3;
|
|
9
|
+
const originalBytes = Buffer.byteLength(rawContent, "utf8");
|
|
10
|
+
if (originalBytes <= maxTotalBytes) {
|
|
11
|
+
return { content: rawContent, clipped: false, originalBytes };
|
|
12
|
+
}
|
|
13
|
+
const buf = Buffer.from(rawContent, "utf8");
|
|
14
|
+
let headEnd = Math.min(maxHeadBytes, buf.length);
|
|
15
|
+
while (headEnd > 0 && (buf[headEnd] & 192) === 128) {
|
|
16
|
+
headEnd--;
|
|
17
|
+
}
|
|
18
|
+
let tailStart = Math.max(0, buf.length - maxTailBytes);
|
|
19
|
+
while (tailStart < buf.length && (buf[tailStart] & 192) === 128) {
|
|
20
|
+
tailStart++;
|
|
21
|
+
}
|
|
22
|
+
if (tailStart < headEnd) {
|
|
23
|
+
tailStart = headEnd;
|
|
24
|
+
}
|
|
25
|
+
const headStr = buf.toString("utf8", 0, headEnd);
|
|
26
|
+
const tailStr = buf.toString("utf8", tailStart, buf.length);
|
|
27
|
+
const elidedBytes = Math.max(0, originalBytes - headEnd - (buf.length - tailStart));
|
|
28
|
+
let logPath = void 0;
|
|
29
|
+
if (options.saveTempLog !== false) {
|
|
30
|
+
try {
|
|
31
|
+
const dir = join(tmpdir(), "nolo-tool-logs");
|
|
32
|
+
mkdirSync(dir, { recursive: true });
|
|
33
|
+
const safeId = (options.toolCallId || `tool-${Date.now()}`).replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
34
|
+
logPath = join(dir, `${safeId}.log`);
|
|
35
|
+
writeFileSync(logPath, rawContent, "utf8");
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const logHint = logPath ? ` Full output saved to ${logPath}` : "";
|
|
40
|
+
const notice = `
|
|
41
|
+
|
|
42
|
+
[... truncated ${elidedBytes} bytes.${logHint}]
|
|
43
|
+
|
|
44
|
+
`;
|
|
45
|
+
return {
|
|
46
|
+
content: `${headStr}${notice}${tailStr}`,
|
|
47
|
+
clipped: true,
|
|
48
|
+
logPath,
|
|
49
|
+
originalBytes
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
clipHeadAndTail
|
|
55
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createCliLocalRuntimeAdapter,
|
|
3
3
|
summarizeEndpoint
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3N55DSXH.js";
|
|
5
5
|
import {
|
|
6
6
|
clipMultilineText
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7XN726FS.js";
|
|
8
8
|
import {
|
|
9
9
|
readPipeText,
|
|
10
10
|
spawnProcess
|
|
@@ -17,10 +17,10 @@ import {
|
|
|
17
17
|
} from "./chunk-OLZBQWZU.js";
|
|
18
18
|
import {
|
|
19
19
|
runLocalAgentTurn
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-MXLQWBVM.js";
|
|
21
21
|
import {
|
|
22
22
|
resolveLocalRuntimeEnvFromPolicy
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-5CS33IBL.js";
|
|
24
24
|
import {
|
|
25
25
|
toErrorMessage
|
|
26
26
|
} from "./chunk-HNMXYYJR.js";
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
} from "./chunk-KX6YBIHG.js";
|
|
30
30
|
import {
|
|
31
31
|
asTrimmedNonEmptyStringArray
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-I42VC5KR.js";
|
|
33
33
|
import {
|
|
34
34
|
asTrimmedString
|
|
35
35
|
} from "./chunk-3EUW3WEO.js";
|