nolo-cli 0.8.0-alpha.2 → 0.8.0-alpha.21

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.
Files changed (188) hide show
  1. package/README.md +1 -1
  2. package/_executeModel-42U3VOVZ.js +205 -0
  3. package/action-TLI3V62L.js +28 -0
  4. package/addContentAction-57RSIIMR.js +26 -0
  5. package/addDialogAgentAction-G3VWEA6E.js +68 -0
  6. package/agentDeleteCommand-5DD2IM3J.js +327 -0
  7. package/agentEmailCommands-6FACJBU4.js +628 -0
  8. package/agentListCommands-I6KZYCIG.js +223 -0
  9. package/agentMachineCommands-VKLIGMZA.js +425 -0
  10. package/agentPullCommand-O2MTUAFR.js +122 -0
  11. package/agentRecordCommands-7TZICYDT.js +96 -0
  12. package/agentRunCommand-L4OM23KV.js +114 -0
  13. package/agentRunControl-K4VKNEHF.js +57 -0
  14. package/agentRuntimeLocal-ZYEIPTY4.js +104 -0
  15. package/agentSlice-BX7GXSNO.js +42 -0
  16. package/authCommand-EB5JSOX5.js +581 -0
  17. package/authCommands-XPEHTKSM.js +35 -0
  18. package/chunk-25LCXTML.js +175 -0
  19. package/chunk-2ECQG4YX.js +22296 -0
  20. package/chunk-2FTTDCD4.js +675 -0
  21. package/chunk-2JCXITPK.js +1078 -0
  22. package/chunk-3ASDTTEI.js +1774 -0
  23. package/chunk-3EUW3WEO.js +8 -0
  24. package/chunk-3LY4F7SV.js +9293 -0
  25. package/chunk-4CQLVGRV.js +50 -0
  26. package/chunk-4IJYA27C.js +342 -0
  27. package/chunk-4O3CARJ4.js +231 -0
  28. package/chunk-4QEWT7KD.js +933 -0
  29. package/chunk-4SN6J65J.js +38 -0
  30. package/chunk-4VNS5WPM.js +42 -0
  31. package/chunk-4XENYTF5.js +222 -0
  32. package/chunk-4ZDM73SD.js +34 -0
  33. package/chunk-5CS33IBL.js +301 -0
  34. package/chunk-5EFXE3O7.js +138 -0
  35. package/chunk-5KLGBAAR.js +386 -0
  36. package/chunk-5MIDPSSK.js +206 -0
  37. package/chunk-5MMAK75Q.js +15 -0
  38. package/chunk-63W5N6P3.js +150 -0
  39. package/chunk-6HYVJV7B.js +102 -0
  40. package/chunk-6KHNO3SK.js +1948 -0
  41. package/chunk-6WD3OOJS.js +20 -0
  42. package/chunk-7DAJ4AI4.js +191 -0
  43. package/chunk-7GNGZRLZ.js +1939 -0
  44. package/chunk-7KCUSYT2.js +354 -0
  45. package/chunk-7U44LYTR.js +238 -0
  46. package/chunk-AFON4QUU.js +112 -0
  47. package/chunk-AGFH73SK.js +239 -0
  48. package/chunk-AL2KDGR2.js +27339 -0
  49. package/chunk-AS4PVWA4.js +221 -0
  50. package/chunk-ATNTHIZI.js +13 -0
  51. package/chunk-AVMKZHBC.js +85 -0
  52. package/chunk-AZPCASRE.js +36 -0
  53. package/chunk-BBYVOSU2.js +792 -0
  54. package/chunk-C3RUNRHT.js +51 -0
  55. package/chunk-C4FTUXVF.js +146 -0
  56. package/chunk-CF2WZF4N.js +134 -0
  57. package/chunk-CF7PE763.js +10 -0
  58. package/chunk-CKOJQDKR.js +198 -0
  59. package/chunk-CMKUBIGW.js +1550 -0
  60. package/chunk-CWMSB67P.js +34 -0
  61. package/chunk-DCOA4QSN.js +105 -0
  62. package/chunk-DFFIZ25G.js +30 -0
  63. package/chunk-DSZUWUYB.js +478 -0
  64. package/chunk-DWLEOOGR.js +8 -0
  65. package/chunk-DZ3XJVET.js +231 -0
  66. package/chunk-EHLHSX7R.js +1433 -0
  67. package/chunk-ENOG22KJ.js +939 -0
  68. package/chunk-FSO5B7GH.js +171 -0
  69. package/chunk-FVYY6MCS.js +1447 -0
  70. package/chunk-G3SUCT4W.js +8 -0
  71. package/chunk-GAKEBQD6.js +30 -0
  72. package/chunk-GBRG75BQ.js +86 -0
  73. package/chunk-GU3PEVGZ.js +4723 -0
  74. package/chunk-H33743XH.js +25 -0
  75. package/chunk-HNMXYYJR.js +12 -0
  76. package/chunk-HNW7IJSK.js +71 -0
  77. package/chunk-I42VC5KR.js +15 -0
  78. package/chunk-I6XMPTMR.js +113 -0
  79. package/chunk-IDZTNRP2.js +85 -0
  80. package/chunk-ISNCLGUZ.js +146 -0
  81. package/chunk-IWX4UW2E.js +548 -0
  82. package/chunk-JBTJAPUF.js +35 -0
  83. package/chunk-JEXVIMYZ.js +55 -0
  84. package/chunk-JRKKFRAV.js +537 -0
  85. package/chunk-JZPBVBIY.js +94 -0
  86. package/chunk-KKY4B2Q2.js +21 -0
  87. package/chunk-KQHGZWSV.js +63 -0
  88. package/chunk-KUG52IAP.js +8 -0
  89. package/chunk-KX6YBIHG.js +8 -0
  90. package/chunk-LCBAMY2M.js +60 -0
  91. package/chunk-LM6IYQ3F.js +16 -0
  92. package/chunk-LTRXGFMS.js +83 -0
  93. package/chunk-M76ECQRD.js +13658 -0
  94. package/chunk-MRC4Q34M.js +188 -0
  95. package/chunk-MTU75CZ2.js +91 -0
  96. package/chunk-N54XAP77.js +19 -0
  97. package/chunk-O2ZNTTET.js +3272 -0
  98. package/chunk-O4BU24WZ.js +3212 -0
  99. package/chunk-OLZBQWZU.js +6 -0
  100. package/chunk-OOSFSFMA.js +271 -0
  101. package/chunk-OPZYGHUC.js +89 -0
  102. package/chunk-OWOHNGCN.js +50 -0
  103. package/chunk-P3PKED2I.js +962 -0
  104. package/chunk-QSJ3HFEF.js +8 -0
  105. package/chunk-RCSJFQPB.js +9036 -0
  106. package/chunk-RL776AGR.js +190 -0
  107. package/chunk-ROWQEJRP.js +139 -0
  108. package/chunk-S7Z2HMCN.js +25 -0
  109. package/chunk-SDJDLO5W.js +628 -0
  110. package/chunk-SOTZ6RDN.js +69 -0
  111. package/chunk-TILFE6LV.js +381 -0
  112. package/chunk-U4TRT5V4.js +246 -0
  113. package/chunk-U6VC4MU4.js +8 -0
  114. package/chunk-UAD2WT54.js +64 -0
  115. package/chunk-UB6SN4NJ.js +421 -0
  116. package/chunk-URUUZLPA.js +807 -0
  117. package/chunk-UTLZINAP.js +3066 -0
  118. package/chunk-VC6OZXO5.js +298 -0
  119. package/chunk-VF4K2QE6.js +21 -0
  120. package/chunk-VHBWHNVT.js +59 -0
  121. package/chunk-VIDPVFP3.js +20 -0
  122. package/chunk-VP4WJWKW.js +8882 -0
  123. package/chunk-VUW5FBDB.js +573 -0
  124. package/chunk-VVX233PH.js +482 -0
  125. package/chunk-VX3SXJ3N.js +2052 -0
  126. package/chunk-W4NVOSFF.js +37 -0
  127. package/chunk-WWC7I6TA.js +8 -0
  128. package/chunk-WZSRQNQG.js +2587 -0
  129. package/chunk-XBUBEFNX.js +34 -0
  130. package/chunk-XENYHRUE.js +104 -0
  131. package/chunk-Y5GCAMGP.js +9 -0
  132. package/chunk-YPRZSPF3.js +148 -0
  133. package/chunk-Z4NR32XR.js +50 -0
  134. package/chunk-ZNFJWEN4.js +56 -0
  135. package/cliExecutor-K3F7DMRO.js +36 -0
  136. package/clipboardy-BVE3LVEH.js +12001 -0
  137. package/createAgentAutomationAction-RJF3N2QY.js +866 -0
  138. package/createDialogAction-DRSPS6CE.js +55 -0
  139. package/createPageAction-6B2WMNO3.js +172 -0
  140. package/db-HCJ5PRB5.js +271 -0
  141. package/dbSlice-Q3TM2FJV.js +60 -0
  142. package/deleteFile-OW53A6BX.js +41 -0
  143. package/dialogCommands-4IX4XIZE.js +63 -0
  144. package/dialogSlice-3M7KX2TX.js +148 -0
  145. package/docCreateCommands-SIL3NPGT.js +220 -0
  146. package/docDeleteCommands-7IOMLUS4.js +181 -0
  147. package/docReadCommands-FNFXUA5L.js +134 -0
  148. package/docStore-SV7E34D4.js +98 -0
  149. package/docUpdateCommands-X2HNDVUC.js +318 -0
  150. package/fetchMessages-KTNM7QAR.js +17 -0
  151. package/getPricing-3E6UNPKL.js +30 -0
  152. package/handleSendMessageAction-JYETO5RZ.js +185 -0
  153. package/index.js +188 -112958
  154. package/lib-FYYBQIXS.js +19839 -0
  155. package/localDialogRead-2VRI24F4.js +26 -0
  156. package/localFirstLog-DHNOY2NA.js +19 -0
  157. package/localRuntimeAuthority-TEGCOWX4.js +471 -0
  158. package/localRuntimeDb-LGDF6FQP.js +12 -0
  159. package/machineCommands-RIO3RP5Q.js +781 -0
  160. package/machineInfo-M6KB6HZN.js +10 -0
  161. package/machineWsRunDispatch-W7UYLGB5.js +112 -0
  162. package/memoryCommands-O4MIPIWQ.js +476 -0
  163. package/models-4OPOOLFS.js +9 -0
  164. package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
  165. package/package.json +4 -24
  166. package/read-GW7ZEI23.js +17 -0
  167. package/readDocTool-HUFU6OCT.js +16 -0
  168. package/readlineWorkspace-27JR7WPW.js +5682 -0
  169. package/removeDialogAgentAction-CXKR4NJI.js +73 -0
  170. package/runAgentClientLoop-HZFAPJHS.js +293 -0
  171. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  172. package/setDialogExtraReferencesAction-6RKUSXHX.js +60 -0
  173. package/setPrimaryDialogAgentAction-T3UTBEFG.js +80 -0
  174. package/settingSlice-IVKXJXMG.js +199 -0
  175. package/skillDiscovery-UGSQGX2U.js +16 -0
  176. package/skillSummaryMarker-42HKSXYY.js +9 -0
  177. package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
  178. package/slateUtils-2M7MUTWX.js +19 -0
  179. package/spaceCommands-E7VOF4LO.js +450 -0
  180. package/spaceSlice-TSVROA5U.js +149 -0
  181. package/streamAgentChatTurn-3C5RQZJF.js +4510 -0
  182. package/tableCommands-O7O2LBEG.js +1286 -0
  183. package/toolApiClient-QI3YBNWB.js +26 -0
  184. package/tools-EQDEKR6N.js +87 -0
  185. package/tuiSummaryLlmCaller-RV3THLZF.js +78 -0
  186. package/understanding-3CUQQ6SV.js +271 -0
  187. package/updateCommands-VOSPKXFF.js +31 -0
  188. package/updateDialogTitleAction-3XV7VWSZ.js +188 -0
@@ -0,0 +1,537 @@
1
+ import {
2
+ getModelConfig
3
+ } from "./chunk-BBYVOSU2.js";
4
+ import {
5
+ asTrimmedLowercaseString
6
+ } from "./chunk-QSJ3HFEF.js";
7
+ import {
8
+ asTrimmedString
9
+ } from "./chunk-3EUW3WEO.js";
10
+ import {
11
+ normalizeServerOrigin
12
+ } from "./chunk-CF7PE763.js";
13
+ import {
14
+ asOptionalTrimmedString
15
+ } from "./chunk-G3SUCT4W.js";
16
+ import {
17
+ isRecord
18
+ } from "./chunk-KUG52IAP.js";
19
+
20
+ // packages/agent-runtime/agentConfigOptions.ts
21
+ function pickAgentRuntimeInferenceOptions(agentConfig) {
22
+ return {
23
+ ...agentConfig.temperature !== void 0 ? { temperature: agentConfig.temperature } : {},
24
+ ...agentConfig.top_p !== void 0 ? { top_p: agentConfig.top_p } : {},
25
+ ...agentConfig.frequency_penalty !== void 0 ? { frequency_penalty: agentConfig.frequency_penalty } : {},
26
+ ...agentConfig.presence_penalty !== void 0 ? { presence_penalty: agentConfig.presence_penalty } : {},
27
+ ...agentConfig.max_tokens !== void 0 ? { max_tokens: agentConfig.max_tokens } : {},
28
+ ...agentConfig.reasoning_effort ? { reasoning_effort: agentConfig.reasoning_effort } : {}
29
+ };
30
+ }
31
+
32
+ // packages/agent-runtime/platformProviderEndpoints.ts
33
+ var OPENAI_RESPONSES_ENDPOINT = "https://api.openai.com/v1/responses";
34
+ var PLATFORM_CHAT_COMPLETIONS_ENDPOINTS = {
35
+ deepinfra: "https://api.deepinfra.com/v1/openai/chat/completions",
36
+ deepseek: "https://api.deepseek.com/chat/completions",
37
+ fireworks: "https://api.fireworks.ai/inference/v1/chat/completions",
38
+ google: "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions",
39
+ openai: "https://api.openai.com/v1/chat/completions",
40
+ openrouter: "https://openrouter.ai/api/v1/chat/completions",
41
+ // 千问 AI 平台 OpenAI 兼容模式
42
+ qwen: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
43
+ // Moonshot AI(月之暗面)开放平台 OpenAI 兼容模式(按量计费)
44
+ moonshot: "https://api.moonshot.cn/v1/chat/completions",
45
+ // Open-source default: nolo provider 中转 ollama cloud。
46
+ // 内部多后端组合路由不开源,由内部 provider 路由层接管。
47
+ nolo: "https://ollama.com/v1/chat/completions"
48
+ };
49
+ function isOpenAiResponsesModel(args) {
50
+ if (asTrimmedLowercaseString(args.provider) !== "openai") return false;
51
+ if (args.endpointKey === "responses") return true;
52
+ if (!args.model) return false;
53
+ try {
54
+ return getModelConfig("openai", args.model).endpointKey === "responses";
55
+ } catch {
56
+ return false;
57
+ }
58
+ }
59
+ function resolvePlatformChatCompletionsEndpoint(provider) {
60
+ const key = asTrimmedLowercaseString(provider);
61
+ if (!key) return void 0;
62
+ return PLATFORM_CHAT_COMPLETIONS_ENDPOINTS[key];
63
+ }
64
+
65
+ // packages/agent-runtime/providerResolution.ts
66
+ function resolvePlatformProviderEndpoint(agentConfig) {
67
+ const customProviderUrl = agentConfig.customProviderUrl?.trim();
68
+ if (customProviderUrl) return resolveChatCompletionsEndpoint(customProviderUrl);
69
+ const provider = asTrimmedLowercaseString(
70
+ agentConfig.provider ?? agentConfig.apiSource ?? "openai"
71
+ );
72
+ if (!provider) {
73
+ throw new Error("Platform chat provider requires agentConfig.provider.");
74
+ }
75
+ if (isOpenAiResponsesModel({
76
+ provider,
77
+ model: agentConfig.model,
78
+ endpointKey: agentConfig.endpointKey
79
+ })) {
80
+ return OPENAI_RESPONSES_ENDPOINT;
81
+ }
82
+ const endpoint = resolvePlatformChatCompletionsEndpoint(provider);
83
+ if (!endpoint) {
84
+ throw new Error(`Platform chat provider does not support provider "${provider}".`);
85
+ }
86
+ return endpoint;
87
+ }
88
+ async function resolveCredentialFromBroker(broker, ref) {
89
+ const trimmed = asTrimmedString(ref);
90
+ if (!trimmed) return null;
91
+ try {
92
+ if (!await broker.has(trimmed)) return null;
93
+ const secret = await broker.get(trimmed);
94
+ return asOptionalTrimmedString(secret) ?? null;
95
+ } catch {
96
+ return null;
97
+ }
98
+ }
99
+ function trimTrailingSlash(value) {
100
+ return normalizeServerOrigin(value);
101
+ }
102
+ function resolveChatCompletionsEndpoint(value) {
103
+ const trimmed = trimTrailingSlash(value);
104
+ return trimmed.endsWith("/chat/completions") ? trimmed : `${trimmed}/chat/completions`;
105
+ }
106
+ function resolveOpenAiCompatibleBaseUrl(env) {
107
+ return env.NOLO_LOCAL_OPENAI_BASE_URL || env.OPENAI_BASE_URL || "https://api.openai.com/v1";
108
+ }
109
+ function resolveOpenAiCompatibleApiKey(env) {
110
+ return env.OPENAI_API_KEY || env.NOLO_LOCAL_OPENAI_API_KEY || "";
111
+ }
112
+ function resolvePlatformServerUrl(env) {
113
+ return trimTrailingSlash(env.NOLO_SERVER || env.BASE_URL || "https://nolo.chat");
114
+ }
115
+ function resolvePlatformAuthToken(env) {
116
+ return env.AUTH_TOKEN || env.AUTH || env.BENCHMARK_AUTH_TOKEN || "";
117
+ }
118
+ function canUsePlatformChatProvider(env) {
119
+ return Boolean(resolvePlatformAuthToken(env));
120
+ }
121
+ function hasDirectOpenAiCompatibleProvider(env) {
122
+ return Boolean(
123
+ env.NOLO_LOCAL_OPENAI_API_KEY || env.OPENAI_API_KEY || env.NOLO_LOCAL_OPENAI_BASE_URL || env.OPENAI_BASE_URL || env.OLLAMA_BASE_URL
124
+ );
125
+ }
126
+ function resolveAgentProviderMode(agentConfig) {
127
+ if (agentConfig.apiSource === "cli" || agentConfig.provider === "cli" || agentConfig.cliProvider) {
128
+ return "cli";
129
+ }
130
+ if (agentConfig.apiSource === "custom" || agentConfig.customProviderUrl) {
131
+ return "custom";
132
+ }
133
+ return "platform";
134
+ }
135
+ function resolveAgentRuntimeLocation(args) {
136
+ const runtimeBinding = args.agentConfig.runtimeBinding;
137
+ const machineId = asTrimmedString(runtimeBinding?.machineId);
138
+ if (machineId) return "bound-machine";
139
+ if (args.runtimeKind === "server") return "server";
140
+ return "local-host";
141
+ }
142
+ function resolveProviderTransportDecision(args) {
143
+ const mode = resolveAgentProviderMode(args.agentConfig);
144
+ if (mode === "cli") {
145
+ return { mode, transport: "direct", reason: "cli-provider" };
146
+ }
147
+ if (mode === "custom") {
148
+ if (args.runtimeLocation === "server" && args.agentConfig.useServerProxy === true) {
149
+ return { mode, transport: "proxy", reason: "custom-server-proxy" };
150
+ }
151
+ return { mode, transport: "direct", reason: "custom-provider" };
152
+ }
153
+ if (args.agentConfig.apiSource === "platform" || args.agentConfig.useServerProxy === true) {
154
+ return { mode, transport: "proxy", reason: "platform-agent" };
155
+ }
156
+ if (args.env.NOLO_LOCAL_LLM === "platform") {
157
+ return { mode, transport: "proxy", reason: "forced-platform-env" };
158
+ }
159
+ if (args.env.NOLO_LOCAL_LLM === "direct") {
160
+ return { mode, transport: "direct", reason: "forced-direct-env" };
161
+ }
162
+ if (hasDirectOpenAiCompatibleProvider(args.env)) {
163
+ return { mode, transport: "direct", reason: "direct-provider-env" };
164
+ }
165
+ if (canUsePlatformChatProvider(args.env)) {
166
+ return { mode, transport: "proxy", reason: "platform-proxy-fallback" };
167
+ }
168
+ return { mode, transport: "direct", reason: "direct-provider-env" };
169
+ }
170
+ function resolveProviderAuthHeaderName(args) {
171
+ const explicitHeader = args.apiKeyHeader?.trim();
172
+ if (explicitHeader) return explicitHeader;
173
+ if (/xiaomimimo\.com/i.test(args.endpoint)) return "api-key";
174
+ return "Authorization";
175
+ }
176
+ function buildProviderAuthHeaders(args) {
177
+ if (!args.apiKey) return {};
178
+ const headerName = resolveProviderAuthHeaderName(args);
179
+ return headerName.toLowerCase() === "authorization" ? { Authorization: `Bearer ${args.apiKey}` } : { [headerName]: args.apiKey };
180
+ }
181
+ async function buildProviderExecutionPlan(args) {
182
+ const { agentConfig, env } = args;
183
+ const mode = resolveAgentProviderMode(agentConfig);
184
+ const runtimeLocation = resolveAgentRuntimeLocation({
185
+ agentConfig,
186
+ runtimeKind: args.runtimeKind
187
+ });
188
+ const transportDecision = resolveProviderTransportDecision({
189
+ agentConfig,
190
+ env,
191
+ runtimeLocation
192
+ });
193
+ const model = agentConfig.model || "gpt-4.1-mini";
194
+ const requestOptions = pickAgentRuntimeInferenceOptions(agentConfig);
195
+ if (mode === "cli") {
196
+ return {
197
+ mode,
198
+ transport: "direct",
199
+ cliProvider: agentConfig.cliProvider || agentConfig.provider || "codex",
200
+ model,
201
+ provider: agentConfig.provider || "cli",
202
+ requestOptions
203
+ };
204
+ }
205
+ if (mode === "custom") {
206
+ const endpoint2 = resolveChatCompletionsEndpoint(agentConfig.customProviderUrl || resolveOpenAiCompatibleBaseUrl(env));
207
+ let apiKey2 = "";
208
+ const credentialRef2 = agentConfig.credentialRef?.trim();
209
+ const apiKeyRef = agentConfig.apiKeyRef?.trim();
210
+ if (args.credentialBroker) {
211
+ const brokerRefs = [credentialRef2, apiKeyRef].filter(
212
+ (ref) => Boolean(ref)
213
+ );
214
+ for (const ref of brokerRefs) {
215
+ const fromBroker = await resolveCredentialFromBroker(args.credentialBroker, ref);
216
+ if (fromBroker) {
217
+ apiKey2 = fromBroker;
218
+ break;
219
+ }
220
+ }
221
+ }
222
+ if (!apiKey2 && agentConfig.credentialSynced && args.syncFetcher && credentialRef2) {
223
+ const synced = await args.syncFetcher(credentialRef2);
224
+ const trimmed = asTrimmedString(synced);
225
+ if (trimmed) {
226
+ try {
227
+ await args.credentialBroker?.put(credentialRef2, trimmed);
228
+ } catch {
229
+ }
230
+ apiKey2 = trimmed;
231
+ }
232
+ }
233
+ if (!apiKey2 && apiKeyRef && args.apiKeyRefResolver) {
234
+ const resolved = await args.apiKeyRefResolver(apiKeyRef);
235
+ if (resolved) {
236
+ apiKey2 = resolved;
237
+ } else if (!agentConfig.apiKey?.trim() && !agentConfig.apiKeyFromAgentKey?.trim()) {
238
+ const isApiKeyRef = apiKeyRef.startsWith("api-key:");
239
+ const hint = isApiKeyRef ? agentConfig.credentialSynced ? `Local credential for "${apiKeyRef}" not found. It is synced to your account \u2014 run this agent once on a device that has the key, or re-enter it in agent settings.` : `Local credential for "${apiKeyRef}" not found. Re-enter the API key in agent settings, or enable cross-device sync.` : `OAuth credential for "${apiKeyRef}" not found locally. Run \`nolo auth ${apiKeyRef}\` (and \`--sync-to-server\` for server-side agent runs).`;
240
+ throw new Error(hint);
241
+ }
242
+ }
243
+ if (!apiKey2) {
244
+ apiKey2 = asOptionalTrimmedString(agentConfig.apiKey) ?? asOptionalTrimmedString(agentConfig.apiKeyFromAgentKey) ?? "";
245
+ }
246
+ const apiKeyHeader = resolveProviderAuthHeaderName({
247
+ endpoint: endpoint2,
248
+ apiKeyHeader: agentConfig.apiKeyHeader
249
+ });
250
+ if (transportDecision.transport === "proxy") {
251
+ return {
252
+ mode,
253
+ transport: "proxy",
254
+ model,
255
+ provider: agentConfig.provider || "custom",
256
+ endpoint: endpoint2,
257
+ requestOptions,
258
+ serverUrl: resolvePlatformServerUrl(env),
259
+ authToken: resolvePlatformAuthToken(env),
260
+ agentKey: agentConfig.key,
261
+ ...agentConfig.apiSource ? { apiSource: agentConfig.apiSource } : {},
262
+ ...apiKey2 ? { apiKey: apiKey2 } : {},
263
+ ...apiKeyHeader ? { apiKeyHeader } : {}
264
+ };
265
+ }
266
+ return {
267
+ mode,
268
+ transport: "direct",
269
+ model,
270
+ provider: agentConfig.provider || "custom",
271
+ endpoint: endpoint2,
272
+ requestOptions,
273
+ apiKey: apiKey2,
274
+ ...apiKeyHeader ? { apiKeyHeader } : {}
275
+ };
276
+ }
277
+ const provider = agentConfig.provider || agentConfig.apiSource || "openai";
278
+ const endpoint = transportDecision.transport === "proxy" ? resolvePlatformProviderEndpoint(agentConfig) : resolveChatCompletionsEndpoint(resolveOpenAiCompatibleBaseUrl(env));
279
+ if (transportDecision.transport === "proxy") {
280
+ return {
281
+ mode,
282
+ transport: "proxy",
283
+ model,
284
+ provider,
285
+ endpoint,
286
+ requestOptions,
287
+ serverUrl: resolvePlatformServerUrl(env),
288
+ authToken: resolvePlatformAuthToken(env),
289
+ agentKey: agentConfig.key,
290
+ ...agentConfig.apiSource ? { apiSource: agentConfig.apiSource } : {},
291
+ ...agentConfig.apiKey?.trim() ? { apiKey: agentConfig.apiKey.trim() } : {},
292
+ ...agentConfig.apiKeyHeader?.trim() ? { apiKeyHeader: agentConfig.apiKeyHeader.trim() } : {}
293
+ };
294
+ }
295
+ let apiKey = "";
296
+ const credentialRef = agentConfig.credentialRef?.trim();
297
+ if (args.credentialBroker && credentialRef) {
298
+ const fromBroker = await resolveCredentialFromBroker(args.credentialBroker, credentialRef);
299
+ if (fromBroker) {
300
+ apiKey = fromBroker;
301
+ }
302
+ }
303
+ if (!apiKey && agentConfig.credentialSynced && args.syncFetcher && credentialRef) {
304
+ const synced = await args.syncFetcher(credentialRef);
305
+ const trimmed = asTrimmedString(synced);
306
+ if (trimmed) {
307
+ try {
308
+ await args.credentialBroker?.put(credentialRef, trimmed);
309
+ } catch {
310
+ }
311
+ apiKey = trimmed;
312
+ }
313
+ }
314
+ if (!apiKey) {
315
+ apiKey = resolveOpenAiCompatibleApiKey(env);
316
+ }
317
+ return {
318
+ mode,
319
+ transport: "direct",
320
+ model,
321
+ provider: agentConfig.provider || "openai-compatible",
322
+ endpoint,
323
+ requestOptions,
324
+ apiKey
325
+ };
326
+ }
327
+
328
+ // packages/integrations/openai/responsesHelpers.ts
329
+ var RESPONSES_TOP_LEVEL_SCHEMA_KEYS = ["anyOf", "oneOf", "allOf", "enum", "not"];
330
+ var sanitizeResponsesParameters = (parameters) => {
331
+ if (!isRecord(parameters)) {
332
+ return parameters;
333
+ }
334
+ const next = { ...parameters };
335
+ for (const key of RESPONSES_TOP_LEVEL_SCHEMA_KEYS) {
336
+ delete next[key];
337
+ }
338
+ return next;
339
+ };
340
+ var appendTextPart = (parts, text, role) => {
341
+ if (!text) return;
342
+ const last = parts.at(-1);
343
+ const textType = role === "assistant" ? "output_text" : "input_text";
344
+ if (last?.type === textType) {
345
+ last.text += text;
346
+ return;
347
+ }
348
+ parts.push({ type: textType, text });
349
+ };
350
+ var normalizeMessageParts = (content, role) => {
351
+ if (typeof content === "string") {
352
+ if (!content) return [];
353
+ return [
354
+ {
355
+ type: role === "assistant" ? "output_text" : "input_text",
356
+ text: content
357
+ }
358
+ ];
359
+ }
360
+ const parts = [];
361
+ for (const part of content ?? []) {
362
+ const typedPart = part;
363
+ if (typedPart?.type === "text" && typeof typedPart.text === "string") {
364
+ appendTextPart(parts, typedPart.text, role);
365
+ continue;
366
+ }
367
+ if (typedPart?.type === "image_url" && typeof typedPart.image_url?.url === "string" && typedPart.image_url.url) {
368
+ if (role === "assistant") continue;
369
+ parts.push({
370
+ type: "input_image",
371
+ image_url: typedPart.image_url.url,
372
+ detail: typedPart.image_url.detail
373
+ });
374
+ }
375
+ }
376
+ return parts;
377
+ };
378
+ var normalizeToolOutput = (content) => {
379
+ if (typeof content === "string") return content;
380
+ return JSON.stringify(content ?? "");
381
+ };
382
+ var toResponsesTools = (tools) => {
383
+ if (!Array.isArray(tools) || tools.length === 0) return void 0;
384
+ return tools.map((tool) => {
385
+ const fn = tool?.function;
386
+ if (!fn?.name) return null;
387
+ return {
388
+ type: "function",
389
+ name: fn.name,
390
+ description: fn.description,
391
+ parameters: sanitizeResponsesParameters(fn.parameters),
392
+ strict: fn.strict
393
+ };
394
+ }).filter(Boolean);
395
+ };
396
+ var convertMessagesToResponsesInput = (messages) => {
397
+ const input = [];
398
+ for (const message of messages) {
399
+ if (!message?.role) continue;
400
+ if (message.role === "tool") {
401
+ if (!message.tool_call_id) continue;
402
+ input.push({
403
+ type: "function_call_output",
404
+ call_id: message.tool_call_id,
405
+ output: normalizeToolOutput(message.content)
406
+ });
407
+ continue;
408
+ }
409
+ const role = message.role;
410
+ const contentParts = normalizeMessageParts(message.content, role);
411
+ if (contentParts.length > 0) {
412
+ input.push({
413
+ type: "message",
414
+ role,
415
+ content: contentParts
416
+ });
417
+ }
418
+ if (role === "assistant" && Array.isArray(message.content)) {
419
+ const replayImages = message.content.map((part) => part).filter(
420
+ (part) => part?.type === "image_url" && typeof part.image_url?.url === "string" && Boolean(part.image_url.url)
421
+ ).map((part) => ({
422
+ type: "input_image",
423
+ image_url: part.image_url.url,
424
+ detail: part.image_url.detail
425
+ }));
426
+ if (replayImages.length > 0) {
427
+ input.push({
428
+ type: "message",
429
+ role: "user",
430
+ content: replayImages
431
+ });
432
+ }
433
+ }
434
+ if (role === "assistant" && Array.isArray(message.tool_calls)) {
435
+ for (const toolCall of message.tool_calls) {
436
+ if (!toolCall?.id || !toolCall.function?.name) continue;
437
+ input.push({
438
+ type: "function_call",
439
+ call_id: toolCall.id,
440
+ name: toolCall.function.name,
441
+ arguments: typeof toolCall.function.arguments === "string" ? toolCall.function.arguments : JSON.stringify(toolCall.function.arguments ?? {})
442
+ });
443
+ }
444
+ }
445
+ }
446
+ return input;
447
+ };
448
+ var extractTextFromResponseOutput = (response) => {
449
+ const parts = [];
450
+ for (const item of response?.output ?? []) {
451
+ if (item?.type !== "message") continue;
452
+ for (const content of item.content ?? []) {
453
+ if (content?.type === "output_text" && typeof content.text === "string") {
454
+ parts.push(content.text);
455
+ }
456
+ }
457
+ }
458
+ return parts.join("");
459
+ };
460
+ var toDataUrl = (base64Data, mimeType) => {
461
+ const normalizedMimeType = asOptionalTrimmedString(mimeType) ?? "image/png";
462
+ return `data:${normalizedMimeType};base64,${base64Data}`;
463
+ };
464
+ var extractImagePartsFromResponseOutput = (response) => {
465
+ const images = [];
466
+ for (const item of response?.output ?? []) {
467
+ if (item?.type === "image_generation_call") {
468
+ const result = asOptionalTrimmedString(item.result);
469
+ if (result) {
470
+ const outputFormat = asOptionalTrimmedString(item.output_format);
471
+ images.push({
472
+ type: "image_url",
473
+ image_url: {
474
+ url: toDataUrl(
475
+ result,
476
+ outputFormat ? `image/${outputFormat}` : void 0
477
+ )
478
+ }
479
+ });
480
+ }
481
+ continue;
482
+ }
483
+ if (item?.type !== "message") continue;
484
+ for (const content of item.content ?? []) {
485
+ const result = asOptionalTrimmedString(content?.result);
486
+ if (content?.type === "output_image" && result) {
487
+ images.push({
488
+ type: "image_url",
489
+ image_url: {
490
+ url: toDataUrl(
491
+ result,
492
+ content.mime_type ?? content.mimeType ?? null
493
+ )
494
+ }
495
+ });
496
+ }
497
+ }
498
+ }
499
+ return images;
500
+ };
501
+ var extractToolCallsFromResponseOutput = (response) => {
502
+ const calls = [];
503
+ for (const item of response?.output ?? []) {
504
+ if (item?.type !== "function_call") continue;
505
+ if (!item.call_id || !item.name) continue;
506
+ calls.push({
507
+ id: item.call_id,
508
+ type: "function",
509
+ function: {
510
+ name: item.name,
511
+ arguments: typeof item.arguments === "string" ? item.arguments : JSON.stringify(item.arguments ?? {})
512
+ }
513
+ });
514
+ }
515
+ return calls;
516
+ };
517
+
518
+ export {
519
+ pickAgentRuntimeInferenceOptions,
520
+ OPENAI_RESPONSES_ENDPOINT,
521
+ isOpenAiResponsesModel,
522
+ resolvePlatformChatCompletionsEndpoint,
523
+ trimTrailingSlash,
524
+ resolvePlatformServerUrl,
525
+ resolvePlatformAuthToken,
526
+ canUsePlatformChatProvider,
527
+ hasDirectOpenAiCompatibleProvider,
528
+ resolveAgentRuntimeLocation,
529
+ resolveProviderTransportDecision,
530
+ buildProviderAuthHeaders,
531
+ buildProviderExecutionPlan,
532
+ toResponsesTools,
533
+ convertMessagesToResponsesInput,
534
+ extractTextFromResponseOutput,
535
+ extractImagePartsFromResponseOutput,
536
+ extractToolCallsFromResponseOutput
537
+ };
@@ -0,0 +1,94 @@
1
+ // packages/agent-runtime/oauthTokenStore.ts
2
+ import {
3
+ chmodSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ readFileSync,
7
+ unlinkSync,
8
+ writeFileSync
9
+ } from "node:fs";
10
+ import { homedir } from "node:os";
11
+ import { join } from "node:path";
12
+ var DEFAULT_REFRESH_SKEW_MS = 5 * 60 * 1e3;
13
+ function getCredentialsDir(homeDir = homedir()) {
14
+ return join(homeDir, ".nolo", "credentials");
15
+ }
16
+ function getCredentialPath(provider, homeDir = homedir()) {
17
+ return join(getCredentialsDir(homeDir), `${provider}.json`);
18
+ }
19
+ function ensurePrivateDir(dir) {
20
+ mkdirSync(dir, { recursive: true, mode: 448 });
21
+ try {
22
+ chmodSync(dir, 448);
23
+ } catch {
24
+ }
25
+ }
26
+ function writePrivateFile(path, body) {
27
+ writeFileSync(path, body, { encoding: "utf8", mode: 384 });
28
+ try {
29
+ chmodSync(path, 384);
30
+ } catch {
31
+ }
32
+ }
33
+ function readOAuthCredential(provider, homeDir = homedir()) {
34
+ const path = getCredentialPath(provider, homeDir);
35
+ if (!existsSync(path)) return null;
36
+ const raw = readFileSync(path, "utf8");
37
+ try {
38
+ const parsed = JSON.parse(raw);
39
+ if (!parsed?.provider || !parsed?.accessToken) return null;
40
+ return parsed;
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+ function writeOAuthCredential(provider, credential, homeDir = homedir()) {
46
+ const path = getCredentialPath(provider, homeDir);
47
+ ensurePrivateDir(getCredentialsDir(homeDir));
48
+ writePrivateFile(path, `${JSON.stringify(credential, null, 2)}
49
+ `);
50
+ }
51
+ function removeOAuthCredential(provider, homeDir = homedir()) {
52
+ const path = getCredentialPath(provider, homeDir);
53
+ if (!existsSync(path)) return;
54
+ unlinkSync(path);
55
+ }
56
+ function createOAuthTokenStore(homeDir = homedir()) {
57
+ return {
58
+ read(provider) {
59
+ return readOAuthCredential(provider, homeDir);
60
+ },
61
+ write(provider, credential) {
62
+ writeOAuthCredential(provider, credential, homeDir);
63
+ },
64
+ remove(provider) {
65
+ removeOAuthCredential(provider, homeDir);
66
+ }
67
+ };
68
+ }
69
+ function isTokenExpired(credential, skewMs = DEFAULT_REFRESH_SKEW_MS, now = Date.now()) {
70
+ if (!credential.expiresAt) return false;
71
+ return credential.expiresAt - now <= skewMs;
72
+ }
73
+ async function resolveFreshAccessToken(args) {
74
+ const store = args.store ?? createOAuthTokenStore(args.homeDir);
75
+ const now = args.now ?? Date.now;
76
+ const credential = store.read(args.provider);
77
+ if (!credential) return null;
78
+ if (!args.force && !isTokenExpired(credential, args.skewMs ?? DEFAULT_REFRESH_SKEW_MS, now())) {
79
+ return credential.accessToken;
80
+ }
81
+ if (!credential.refreshToken || !args.refresh) return null;
82
+ const refreshed = await args.refresh(credential);
83
+ store.write(args.provider, refreshed);
84
+ return refreshed.accessToken;
85
+ }
86
+
87
+ export {
88
+ getCredentialsDir,
89
+ readOAuthCredential,
90
+ writeOAuthCredential,
91
+ createOAuthTokenStore,
92
+ isTokenExpired,
93
+ resolveFreshAccessToken
94
+ };
@@ -0,0 +1,21 @@
1
+ // packages/agent-runtime/staleReplayGuard.ts
2
+ var wrapHistoricalSummaryWithReplayGuard = (summary) => {
3
+ const trimmed = summary.trim();
4
+ if (!trimmed) return "";
5
+ return [
6
+ "\u3010\u5386\u53F2\u53C2\u8003\uFF0C\u975E\u6D3B\u6307\u4EE4\u3011\u4EE5\u4E0B\u4E3A\u51BB\u7ED3\u6458\u8981\uFF0C\u5176\u4E2D\u7684\u4EFB\u52A1/skill/ARGUMENTS \u9ED8\u8BA4\u5DF2\u8FC7\u671F\uFF0C\u4E0D\u5F97\u91CD\u65B0\u6267\u884C\u3002",
7
+ trimmed
8
+ ].join("\n");
9
+ };
10
+
11
+ // packages/agent-runtime/memoryUseGuidance.ts
12
+ var MEMORY_USE_GUIDANCE = `--- \u8BB0\u5FC6\u4F7F\u7528\u65B9\u5F0F ---
13
+ - \u8BB0\u5FC6\u662F\u4E2A\u6027\u5316\u589E\u5F3A\u5C42\uFF1B\u5F53\u524D\u8F93\u5165/\u5BF9\u8BDD/\u7CFB\u7EDF\u89C4\u5219/Agent prompt/skill/\u7528\u6237\u5168\u5C40\u504F\u597D\u90FD\u4F18\u5148\u4E8E\u5B83\u3002\u5F53\u524D\u8F93\u5165\u7ED9\u51FA\u65B0\u8BED\u8A00\u3001\u6280\u672F\u6808\u3001\u6570\u503C\u3001\u7EA6\u675F\u6216\u660E\u786E\u8986\u76D6\u65E7\u504F\u597D\u65F6\uFF0C\u91C7\u7528\u5F53\u524D\u8F93\u5165\uFF0C\u4E0D\u8981\u628A\u65E7\u8BB0\u5FC6\u5F53\u66F4\u9AD8\u771F\u503C\u3002
14
+ - \u8BB0\u5FC6\u542B\u7528\u6237\u8EAB\u4EFD/\u79F0\u547C/\u5173\u7CFB/\u957F\u671F\u504F\u597D/\u9879\u76EE\u80CC\u666F\u65F6\uFF0C\u76F8\u5173\u5904\u81EA\u7136\u4F53\u73B0\uFF08\u5F00\u573A\u79F0\u547C\u3001\u4E0A\u4E0B\u6587\u786E\u8BA4\u3001\u56DE\u7B54\u7ED3\u6784\u3001\u53D6\u820D\u6807\u51C6\uFF09\uFF0C\u4E0D\u8981\u6BCF\u53E5\u673A\u68B0\u79F0\u547C\u7528\u6237\u3002
15
+ - \u201C\u4E0A\u6B21/\u7EE7\u7EED/\u8FD9\u4E2A\u9879\u76EE\u201D\u7B49\u6307\u4EE3\u4F18\u5148\u6309\u5F53\u524D dialog/space/project/agent/sourceDialog \u7B49 KV \u8DEF\u5F84\u548C\u65F6\u95F4\u7EBF\u5B9A\u4F4D\uFF0C\u4E0D\u8981\u53EA\u6309\u8BED\u4E49\u76F8\u4F3C\u5EA6\u635E\u4E00\u6761\u3002
16
+ - \u63A8\u65AD\u578B\u8BB0\u5FC6\u53EA\u7528\u4E8E\u628A\u63E1\u8BED\u6C14\u3001\u72B6\u6001\u548C\u672A\u5B8C\u6210\u4E8B\u9879\uFF0C\u4E0D\u8981\u8BF4\u6210\u201C\u4F60\u660E\u786E\u544A\u8BC9\u8FC7\u6211\u201D\u6216\u5F53\u6210\u7528\u6237\u5DF2\u6388\u6743\u4FDD\u5B58\u7684\u4E8B\u5B9E\u3002\u51B2\u7A81\u6216\u573A\u666F\u4E0D\u660E\u65F6\u8BF4\u660E\u4F9D\u636E\u6216\u7B80\u77ED\u786E\u8BA4\uFF0C\u4E0D\u8981\u786C\u5957\u3002`;
17
+
18
+ export {
19
+ wrapHistoricalSummaryWithReplayGuard,
20
+ MEMORY_USE_GUIDANCE
21
+ };