nolo-cli 0.7.0 → 0.8.0-alpha.11

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 (175) hide show
  1. package/_executeModel-GPU2276G.js +198 -0
  2. package/action-PAXRPJJF.js +27 -0
  3. package/addContentAction-CZVWF3QZ.js +25 -0
  4. package/addDialogAgentAction-CCIDTPHC.js +67 -0
  5. package/agentDeleteCommand-4ZZFM6AT.js +323 -0
  6. package/agentEmailCommands-C4FIVQYV.js +621 -0
  7. package/agentListCommands-VQAKVNEX.js +219 -0
  8. package/agentMachineCommands-ONFDXZUQ.js +421 -0
  9. package/agentPullCommand-O2MTUAFR.js +122 -0
  10. package/agentRecordCommands-QANUGHLK.js +89 -0
  11. package/agentRunCommand-A3OSRB5Q.js +102 -0
  12. package/agentRunControl-K4VKNEHF.js +57 -0
  13. package/agentRuntimeLocal-62ZB2ODP.js +99 -0
  14. package/agentSlice-GCGLVR2N.js +41 -0
  15. package/authCommand-WXMD3IPR.js +574 -0
  16. package/authCommands-X74AFDTC.js +26 -0
  17. package/chunk-2EISRLRC.js +238 -0
  18. package/chunk-2FTTDCD4.js +675 -0
  19. package/chunk-2MALU52L.js +51 -0
  20. package/chunk-2UZXR7WO.js +3631 -0
  21. package/chunk-3ASDTTEI.js +1774 -0
  22. package/chunk-3EUW3WEO.js +8 -0
  23. package/chunk-3LY4F7SV.js +9293 -0
  24. package/chunk-4CQLVGRV.js +50 -0
  25. package/chunk-4IJYA27C.js +342 -0
  26. package/chunk-4SN6J65J.js +38 -0
  27. package/chunk-4VNS5WPM.js +42 -0
  28. package/chunk-53DNV5AT.js +421 -0
  29. package/chunk-572EKYLF.js +792 -0
  30. package/chunk-5MIDPSSK.js +206 -0
  31. package/chunk-5MMAK75Q.js +15 -0
  32. package/chunk-63W5N6P3.js +150 -0
  33. package/chunk-6B7G54GE.js +1078 -0
  34. package/chunk-6HYVJV7B.js +102 -0
  35. package/chunk-6WD3OOJS.js +20 -0
  36. package/chunk-7OC5VCLW.js +929 -0
  37. package/chunk-7YLKNMOM.js +562 -0
  38. package/chunk-ATNTHIZI.js +13 -0
  39. package/chunk-AUGHVUFE.js +69 -0
  40. package/chunk-AVMKZHBC.js +85 -0
  41. package/chunk-AZPCASRE.js +36 -0
  42. package/chunk-BR2WP3DF.js +548 -0
  43. package/chunk-BSTNFPHD.js +231 -0
  44. package/chunk-CF2WZF4N.js +134 -0
  45. package/chunk-CF7PE763.js +10 -0
  46. package/chunk-CJH2VTEU.js +360 -0
  47. package/chunk-CKOJQDKR.js +198 -0
  48. package/chunk-CM54RSSA.js +206 -0
  49. package/chunk-CQAHS7YO.js +4300 -0
  50. package/chunk-CWMSB67P.js +34 -0
  51. package/chunk-DFFIZ25G.js +30 -0
  52. package/chunk-DWLEOOGR.js +8 -0
  53. package/chunk-DZ3XJVET.js +231 -0
  54. package/chunk-EHLHSX7R.js +1433 -0
  55. package/chunk-ELRRLDWI.js +478 -0
  56. package/chunk-EYEEHCU4.js +3066 -0
  57. package/chunk-F6QQI5YI.js +19 -0
  58. package/chunk-G3SUCT4W.js +8 -0
  59. package/chunk-G5H7RNFL.js +807 -0
  60. package/chunk-GAKEBQD6.js +30 -0
  61. package/chunk-GBRG75BQ.js +86 -0
  62. package/chunk-GCMRDRCQ.js +190 -0
  63. package/chunk-GGUO4FKF.js +27158 -0
  64. package/chunk-GGXABIPP.js +628 -0
  65. package/chunk-H2RMRZJE.js +113 -0
  66. package/chunk-H33743XH.js +25 -0
  67. package/chunk-HEIIIZBX.js +104 -0
  68. package/chunk-HNMXYYJR.js +12 -0
  69. package/chunk-I3D64LRJ.js +1447 -0
  70. package/chunk-IAXBCTTE.js +175 -0
  71. package/chunk-IDZTNRP2.js +85 -0
  72. package/chunk-ISNCLGUZ.js +146 -0
  73. package/chunk-IYQV26RA.js +138 -0
  74. package/chunk-J4576WMJ.js +91 -0
  75. package/chunk-J5KV47ZW.js +222 -0
  76. package/chunk-JBTJAPUF.js +35 -0
  77. package/chunk-JZPBVBIY.js +94 -0
  78. package/chunk-KB7YFGL6.js +34 -0
  79. package/chunk-KKY4B2Q2.js +21 -0
  80. package/chunk-KQHGZWSV.js +63 -0
  81. package/chunk-KUG52IAP.js +8 -0
  82. package/chunk-KX6YBIHG.js +8 -0
  83. package/chunk-LAWBMYBC.js +171 -0
  84. package/chunk-LCBAMY2M.js +60 -0
  85. package/chunk-LM25IZBJ.js +902 -0
  86. package/chunk-LM6IYQ3F.js +16 -0
  87. package/chunk-M76ECQRD.js +13658 -0
  88. package/chunk-MRC4Q34M.js +188 -0
  89. package/chunk-NXZGF7F7.js +2878 -0
  90. package/chunk-OF5H3QWS.js +300 -0
  91. package/chunk-OLZBQWZU.js +6 -0
  92. package/chunk-OWOHNGCN.js +50 -0
  93. package/chunk-PN7AFLOK.js +3401 -0
  94. package/chunk-QR5IPGT3.js +24674 -0
  95. package/chunk-QSJ3HFEF.js +8 -0
  96. package/chunk-QYXLLLGL.js +4519 -0
  97. package/chunk-R2HXWML7.js +1949 -0
  98. package/chunk-ROWQEJRP.js +139 -0
  99. package/chunk-S7Z2HMCN.js +25 -0
  100. package/chunk-SYOF5TAS.js +962 -0
  101. package/chunk-TDIQFT2F.js +301 -0
  102. package/chunk-TILFE6LV.js +381 -0
  103. package/chunk-TZNCFAUP.js +2157 -0
  104. package/chunk-U4TRT5V4.js +246 -0
  105. package/chunk-U6VC4MU4.js +8 -0
  106. package/chunk-UAD2WT54.js +64 -0
  107. package/chunk-USZMK5UT.js +105 -0
  108. package/chunk-VEJLAVTC.js +2052 -0
  109. package/chunk-VF4K2QE6.js +21 -0
  110. package/chunk-VHBWHNVT.js +59 -0
  111. package/chunk-VIDPVFP3.js +20 -0
  112. package/chunk-VP4WJWKW.js +8882 -0
  113. package/chunk-VQ2AJRGD.js +148 -0
  114. package/chunk-W4NVOSFF.js +37 -0
  115. package/chunk-WWC7I6TA.js +8 -0
  116. package/chunk-X7W4TNB4.js +1550 -0
  117. package/chunk-XBIUN5CR.js +191 -0
  118. package/chunk-XDVAYP26.js +537 -0
  119. package/chunk-XKIMRZO2.js +221 -0
  120. package/chunk-Y5GCAMGP.js +9 -0
  121. package/chunk-YOUZDXU7.js +9013 -0
  122. package/chunk-Z4NR32XR.js +50 -0
  123. package/chunk-ZNFJWEN4.js +56 -0
  124. package/cliExecutor-DNE7TCC4.js +36 -0
  125. package/clipboardy-BVE3LVEH.js +12001 -0
  126. package/createAgentAutomationAction-537X433B.js +864 -0
  127. package/createDialogAction-YUD4RKBS.js +52 -0
  128. package/createPageAction-KJMFHL4C.js +169 -0
  129. package/db-HCJ5PRB5.js +271 -0
  130. package/dbSlice-C4UJLRZP.js +59 -0
  131. package/deleteFile-4SKGPHOZ.js +41 -0
  132. package/dialogCommands-H74KJKHC.js +59 -0
  133. package/dialogSlice-ETSD4YWS.js +146 -0
  134. package/docCreateCommands-ADUSU34K.js +215 -0
  135. package/docDeleteCommands-ZXV3S5OS.js +176 -0
  136. package/docReadCommands-YYYI6LT7.js +129 -0
  137. package/docStore-ZBF5DDKR.js +96 -0
  138. package/docUpdateCommands-7MGJ3BYA.js +313 -0
  139. package/fetchMessages-JOCYIFKL.js +16 -0
  140. package/getPricing-PWPJ6MNV.js +30 -0
  141. package/handleSendMessageAction-MGKI62Y6.js +183 -0
  142. package/index.js +184 -112288
  143. package/lib-FYYBQIXS.js +19839 -0
  144. package/localDialogRead-D3BELSTF.js +26 -0
  145. package/localFirstLog-DHNOY2NA.js +19 -0
  146. package/localRuntimeAuthority-TEGCOWX4.js +471 -0
  147. package/localRuntimeDb-LGDF6FQP.js +12 -0
  148. package/machineCommands-RMTMN7VQ.js +774 -0
  149. package/machineInfo-M6KB6HZN.js +10 -0
  150. package/machineWsRunDispatch-UIP355FN.js +105 -0
  151. package/memoryCommands-O4MIPIWQ.js +476 -0
  152. package/models-XLEOET3E.js +9 -0
  153. package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
  154. package/package.json +3 -25
  155. package/read-RIJCIVKX.js +17 -0
  156. package/readDocTool-GZD2N3LO.js +16 -0
  157. package/readlineWorkspace-CRNQRZ6D.js +5374 -0
  158. package/removeDialogAgentAction-CXLST3N6.js +72 -0
  159. package/runAgentClientLoop-2S334SGA.js +288 -0
  160. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  161. package/setDialogExtraReferencesAction-LP6VYGU7.js +59 -0
  162. package/setPrimaryDialogAgentAction-D3GGH23T.js +79 -0
  163. package/settingSlice-J4I3Z5H7.js +198 -0
  164. package/skillSummaryMarker-42HKSXYY.js +9 -0
  165. package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
  166. package/slateUtils-2M7MUTWX.js +19 -0
  167. package/spaceCommands-NDEWMFZJ.js +450 -0
  168. package/spaceSlice-RLB6RTHO.js +145 -0
  169. package/streamAgentChatTurn-Y2TTYPBD.js +4503 -0
  170. package/tableCommands-GOFP7QKA.js +1286 -0
  171. package/toolApiClient-QI3YBNWB.js +26 -0
  172. package/tools-YZYLY2ZQ.js +83 -0
  173. package/understanding-HCSFPE7R.js +318 -0
  174. package/updateCommands-VOSPKXFF.js +31 -0
  175. package/updateDialogTitleAction-LQV6QLBW.js +185 -0
@@ -0,0 +1,222 @@
1
+ import {
2
+ clearCliLocalRuntimePreparedAgentCache
3
+ } from "./chunk-YOUZDXU7.js";
4
+ import {
5
+ getReadableCliDb
6
+ } from "./chunk-W4NVOSFF.js";
7
+ import {
8
+ buildCreatedAgentRecord,
9
+ buildUpdatedAgentRecord,
10
+ normalizeAgentRecordForOutput,
11
+ parseAgentUpdateArgs,
12
+ resolveAgentRecordFromHybridStore,
13
+ sanitizeAgentRecordForCliOutput,
14
+ writeAgentRecord
15
+ } from "./chunk-GGXABIPP.js";
16
+ import {
17
+ resolveCliAgentKeyInput
18
+ } from "./chunk-VHBWHNVT.js";
19
+ import {
20
+ parseUserIdFromAuthToken,
21
+ resolveAuthToken
22
+ } from "./chunk-ISNCLGUZ.js";
23
+ import {
24
+ toErrorMessage
25
+ } from "./chunk-HNMXYYJR.js";
26
+
27
+ // packages/cli/agentRecordCommands.ts
28
+ async function runAgentReadCommand(args, deps = {}) {
29
+ const env = deps.env ?? process.env;
30
+ const output = deps.output ?? process.stdout;
31
+ const agentInput = args[0]?.trim();
32
+ if (!agentInput || agentInput === "--help" || agentInput === "-h") {
33
+ output.write("Usage: nolo agent read <agent>\n");
34
+ return agentInput ? 0 : 1;
35
+ }
36
+ const authToken = resolveAuthToken(args, env);
37
+ if (!authToken) {
38
+ output.write("[nolo] agent read requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n");
39
+ return 1;
40
+ }
41
+ const agentKey = resolveCliAgentKeyInput(agentInput);
42
+ const db = deps.db ?? await getReadableCliDb(output);
43
+ const fetchImpl = deps.fetchImpl ?? fetch;
44
+ const fallbackFetchImpl = deps.fallbackFetchImpl;
45
+ try {
46
+ const result = await resolveAgentRecordFromHybridStore({
47
+ agentInput,
48
+ cliArgs: args,
49
+ env,
50
+ db,
51
+ fetchImpl,
52
+ fallbackFetchImpl
53
+ });
54
+ if (!result) {
55
+ throw new Error(`agent not found: ${agentKey}`);
56
+ }
57
+ output.write(JSON.stringify({
58
+ ...normalizeAgentRecordForOutput(result.agentKey, authToken, result.record),
59
+ source: result.source
60
+ }, null, 2));
61
+ output.write("\n");
62
+ return 0;
63
+ } catch (error) {
64
+ output.write(
65
+ `[nolo] agent read failed: ${toErrorMessage(error)}
66
+ `
67
+ );
68
+ return 1;
69
+ }
70
+ }
71
+ async function runAgentUpdateCommand(args, deps = {}) {
72
+ const env = deps.env ?? process.env;
73
+ const output = deps.output ?? process.stdout;
74
+ let parsed;
75
+ try {
76
+ parsed = parseAgentUpdateArgs(args);
77
+ } catch (error) {
78
+ output.write(`[nolo] agent update failed: ${toErrorMessage(error)}
79
+ `);
80
+ return 1;
81
+ }
82
+ if (!parsed) {
83
+ output.write(
84
+ "Usage: nolo agent update <agent> [--model <id>] [--cli-provider <provider>] [--api-source <source>] [--max-concurrent <n>] [--expires-at <iso>] [--prompt <text> | --prompt-file <path> | --prompt-doc <pageKey>] [--tools <json>] [--copy-provider-from <agent>] [--field key=value]\n".replace("[--field key=value]", `[--handle <name>] [--field key=value] (e.g. --field disabledTools='["exa_search"]' to disable default tools)`)
85
+ );
86
+ return args[0] ? 0 : 1;
87
+ }
88
+ const authToken = resolveAuthToken(args, env);
89
+ if (!authToken) {
90
+ output.write("[nolo] agent update requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n");
91
+ return 1;
92
+ }
93
+ const userId = parseUserIdFromAuthToken(authToken);
94
+ if (!userId) {
95
+ output.write("[nolo] agent update could not read userId from AUTH_TOKEN.\n");
96
+ return 1;
97
+ }
98
+ const db = deps.db ?? await getReadableCliDb(output);
99
+ const fetchImpl = deps.fetchImpl ?? fetch;
100
+ const fallbackFetchImpl = deps.fallbackFetchImpl;
101
+ try {
102
+ const built = await buildUpdatedAgentRecord({
103
+ cliArgs: args,
104
+ parsed,
105
+ env,
106
+ db,
107
+ fetchImpl,
108
+ fallbackFetchImpl,
109
+ authToken
110
+ });
111
+ await writeAgentRecord({
112
+ agentKey: built.agentKey,
113
+ authToken,
114
+ fallbackFetchImpl,
115
+ fetchImpl,
116
+ serverUrl: built.serverUrl,
117
+ userId,
118
+ record: built.nextRecord
119
+ });
120
+ await db.put(built.agentKey, {
121
+ ...built.nextRecord,
122
+ dbKey: built.agentKey,
123
+ key: built.nextRecord?.key || built.agentKey,
124
+ serverOrigin: built.serverUrl
125
+ });
126
+ clearCliLocalRuntimePreparedAgentCache();
127
+ output.write(JSON.stringify({
128
+ ok: true,
129
+ agentKey: built.agentKey,
130
+ baseUrl: built.serverUrl,
131
+ updates: sanitizeAgentRecordForCliOutput(built.updates),
132
+ record: sanitizeAgentRecordForCliOutput(built.nextRecord)
133
+ }, null, 2));
134
+ output.write("\n");
135
+ return 0;
136
+ } catch (error) {
137
+ output.write(
138
+ `[nolo] agent update failed: ${toErrorMessage(error)}
139
+ `
140
+ );
141
+ return 1;
142
+ }
143
+ }
144
+ async function runAgentCreateCommand(args, deps = {}) {
145
+ const env = deps.env ?? process.env;
146
+ const output = deps.output ?? process.stdout;
147
+ let parsed;
148
+ try {
149
+ parsed = parseAgentUpdateArgs(args);
150
+ } catch (error) {
151
+ output.write(`[nolo] agent create failed: ${toErrorMessage(error)}
152
+ `);
153
+ return 1;
154
+ }
155
+ if (!parsed) {
156
+ output.write(
157
+ "Usage: nolo agent create <agent> [--model <id>] [--cli-provider <provider>] [--api-source <source>] [--max-concurrent <n>] [--expires-at <iso>] [--prompt <text> | --prompt-file <path> | --prompt-doc <pageKey>] [--tools <json>] [--copy-provider-from <agent>] [--name <name>] [--custom-provider-url <url>] [--provider-api-key <key>] [--field key=value]\n".replace("[--field key=value]", "[--handle <name>] [--field key=value]")
158
+ );
159
+ return args[0] ? 0 : 1;
160
+ }
161
+ const authToken = resolveAuthToken(args, env);
162
+ if (!authToken) {
163
+ output.write("[nolo] agent create requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n");
164
+ return 1;
165
+ }
166
+ const userId = parseUserIdFromAuthToken(authToken);
167
+ if (!userId) {
168
+ output.write("[nolo] agent create could not read userId from AUTH_TOKEN.\n");
169
+ return 1;
170
+ }
171
+ const db = deps.db ?? await getReadableCliDb(output);
172
+ const fetchImpl = deps.fetchImpl ?? fetch;
173
+ const fallbackFetchImpl = deps.fallbackFetchImpl;
174
+ try {
175
+ const built = await buildCreatedAgentRecord({
176
+ cliArgs: args,
177
+ parsed,
178
+ env,
179
+ db,
180
+ fetchImpl,
181
+ fallbackFetchImpl,
182
+ authToken
183
+ });
184
+ await writeAgentRecord({
185
+ agentKey: built.agentKey,
186
+ authToken,
187
+ fallbackFetchImpl,
188
+ fetchImpl,
189
+ serverUrl: built.serverUrl,
190
+ userId,
191
+ record: built.nextRecord
192
+ });
193
+ await db.put(built.agentKey, {
194
+ ...built.nextRecord,
195
+ dbKey: built.agentKey,
196
+ key: built.nextRecord?.key || built.agentKey,
197
+ serverOrigin: built.serverUrl
198
+ });
199
+ clearCliLocalRuntimePreparedAgentCache();
200
+ output.write(JSON.stringify({
201
+ ok: true,
202
+ agentKey: built.agentKey,
203
+ baseUrl: built.serverUrl,
204
+ updates: sanitizeAgentRecordForCliOutput(built.updates),
205
+ record: sanitizeAgentRecordForCliOutput(built.nextRecord)
206
+ }, null, 2));
207
+ output.write("\n");
208
+ return 0;
209
+ } catch (error) {
210
+ output.write(
211
+ `[nolo] agent create failed: ${toErrorMessage(error)}
212
+ `
213
+ );
214
+ return 1;
215
+ }
216
+ }
217
+
218
+ export {
219
+ runAgentReadCommand,
220
+ runAgentUpdateCommand,
221
+ runAgentCreateCommand
222
+ };
@@ -0,0 +1,35 @@
1
+ // packages/connector-experimental/codexBinary.ts
2
+ import { copyFileSync, existsSync, mkdirSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { dirname, join } from "node:path";
5
+ var WINDOWS_APPS_CODEX_PATTERN = /\\WindowsApps\\OpenAI\.Codex_[^\\]+\\app\\resources$/i;
6
+ function pathEntries(env) {
7
+ return (env.PATH ?? process.env.PATH ?? "").split(process.platform === "win32" ? ";" : ":");
8
+ }
9
+ function findWindowsAppsCodex(env) {
10
+ if (process.platform !== "win32") return "";
11
+ for (const entry of pathEntries(env)) {
12
+ if (!WINDOWS_APPS_CODEX_PATTERN.test(entry)) continue;
13
+ const candidate = join(entry, "codex.exe");
14
+ if (existsSync(candidate)) return candidate;
15
+ }
16
+ return "";
17
+ }
18
+ function copyCodexToUserBin(source, env) {
19
+ const target = env.NOLO_CODEX_SHIM_PATH ?? join(homedir(), ".nolo", "bin", "codex.exe");
20
+ if (existsSync(target)) return target;
21
+ mkdirSync(dirname(target), { recursive: true });
22
+ copyFileSync(source, target);
23
+ return target;
24
+ }
25
+ function resolveLaunchableCodexCommand(env = process.env) {
26
+ const explicit = env.NOLO_CODEX_BIN?.trim();
27
+ if (explicit) return explicit;
28
+ const windowsAppsCodex = findWindowsAppsCodex(env);
29
+ if (windowsAppsCodex) return copyCodexToUserBin(windowsAppsCodex, env);
30
+ return "codex";
31
+ }
32
+
33
+ export {
34
+ resolveLaunchableCodexCommand
35
+ };
@@ -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,34 @@
1
+ import {
2
+ fetchReferenceContents,
3
+ resolveReferenceAssets
4
+ } from "./chunk-TZNCFAUP.js";
5
+
6
+ // packages/ai/agent/fetchAgentContexts.ts
7
+ async function fetchAgentContexts(references, dispatch) {
8
+ if (!Array.isArray(references)) {
9
+ return { botInstructionsContext: "", botKnowledgeContext: "" };
10
+ }
11
+ const { references: normalizedRefs, contentByKey } = await resolveReferenceAssets(references, dispatch);
12
+ const instructionKeys = /* @__PURE__ */ new Set();
13
+ const knowledgeKeys = /* @__PURE__ */ new Set();
14
+ normalizedRefs.forEach((ref) => {
15
+ if (!ref.dbKey) return;
16
+ ref.type === "instruction" ? instructionKeys.add(ref.dbKey) : knowledgeKeys.add(ref.dbKey);
17
+ });
18
+ const [instructionsMap, knowledgeMap] = await Promise.all([
19
+ fetchReferenceContents(Array.from(instructionKeys), dispatch, {
20
+ preloaded: contentByKey
21
+ }),
22
+ fetchReferenceContents(Array.from(knowledgeKeys), dispatch, {
23
+ preloaded: contentByKey
24
+ })
25
+ ]);
26
+ return {
27
+ botInstructionsContext: Array.from(instructionsMap.values()).join(""),
28
+ botKnowledgeContext: Array.from(knowledgeMap.values()).join("")
29
+ };
30
+ }
31
+
32
+ export {
33
+ fetchAgentContexts
34
+ };
@@ -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
+ };
@@ -0,0 +1,63 @@
1
+ import {
2
+ getRecordTimestamp,
3
+ isTombstoneRecord,
4
+ shouldReplaceWithNextRecord
5
+ } from "./chunk-GBRG75BQ.js";
6
+
7
+ // packages/database/userDataMerge.ts
8
+ var getUserDataItemTimestamp = (dataItem) => getRecordTimestamp(dataItem);
9
+ var getItemKey = (item) => {
10
+ const candidates = [
11
+ typeof item.contentKey === "string" ? item.contentKey : void 0,
12
+ typeof item.dbKey === "string" ? item.dbKey : void 0,
13
+ typeof item.appKey === "string" ? item.appKey : void 0,
14
+ typeof item.appId === "string" ? item.appId : void 0,
15
+ item.id
16
+ ];
17
+ for (const candidate of candidates) {
18
+ if (typeof candidate === "string" && candidate.trim().length > 0) {
19
+ return candidate;
20
+ }
21
+ }
22
+ return null;
23
+ };
24
+ var mergeAndDedupUserData = (localData, remoteResults, options = {}) => {
25
+ const uniqueMap = /* @__PURE__ */ new Map();
26
+ const mergeRecordMetadata = (currentItem, nextItem) => {
27
+ if (typeof currentItem.serverOrigin !== "string" && typeof nextItem.serverOrigin === "string" && nextItem.serverOrigin.trim().length > 0) {
28
+ return {
29
+ ...currentItem,
30
+ serverOrigin: nextItem.serverOrigin
31
+ };
32
+ }
33
+ return currentItem;
34
+ };
35
+ const addToMap = (item) => {
36
+ const itemKey = getItemKey(item);
37
+ if (!itemKey) return;
38
+ const existing = uniqueMap.get(itemKey);
39
+ if (!existing) {
40
+ uniqueMap.set(itemKey, item);
41
+ return;
42
+ }
43
+ if (shouldReplaceWithNextRecord(item, existing)) {
44
+ uniqueMap.set(itemKey, item);
45
+ return;
46
+ }
47
+ uniqueMap.set(itemKey, mergeRecordMetadata(existing, item));
48
+ };
49
+ localData.forEach(addToMap);
50
+ remoteResults.forEach((result) => {
51
+ const items = result?.data?.data;
52
+ if (Array.isArray(items)) {
53
+ items.forEach(addToMap);
54
+ }
55
+ });
56
+ const merged = Array.from(uniqueMap.values());
57
+ return options.includeDeleted ? merged : merged.filter((item) => !isTombstoneRecord(item));
58
+ };
59
+
60
+ export {
61
+ getUserDataItemTimestamp,
62
+ mergeAndDedupUserData
63
+ };
@@ -0,0 +1,8 @@
1
+ // packages/core/isRecord.ts
2
+ function isRecord(value) {
3
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4
+ }
5
+
6
+ export {
7
+ isRecord
8
+ };
@@ -0,0 +1,8 @@
1
+ // packages/core/recordOrEmpty.ts
2
+ function asRecordOrEmpty(value) {
3
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
4
+ }
5
+
6
+ export {
7
+ asRecordOrEmpty
8
+ };
@@ -0,0 +1,171 @@
1
+ import {
2
+ i18n_default,
3
+ toolRegistry
4
+ } from "./chunk-GGUO4FKF.js";
5
+ import {
6
+ canonicalizeToolNames
7
+ } from "./chunk-LM25IZBJ.js";
8
+ import {
9
+ asTrimmedLowercaseString
10
+ } from "./chunk-QSJ3HFEF.js";
11
+ import {
12
+ isRecord
13
+ } from "./chunk-KUG52IAP.js";
14
+
15
+ // packages/ai/tools/toolSchemaCompatibility.ts
16
+ var COMPOSITION_KEYS = ["anyOf", "oneOf", "allOf"];
17
+ var LIMITED_JSON_SCHEMA_PROVIDERS = /* @__PURE__ */ new Set([
18
+ "fireworks"
19
+ ]);
20
+ var sanitizeSchemaNode = (value) => {
21
+ if (Array.isArray(value)) {
22
+ return value.map((item) => sanitizeSchemaNode(item));
23
+ }
24
+ if (!isRecord(value)) {
25
+ return value;
26
+ }
27
+ const next = {};
28
+ for (const [key, child] of Object.entries(value)) {
29
+ if (COMPOSITION_KEYS.includes(key)) {
30
+ continue;
31
+ }
32
+ next[key] = sanitizeSchemaNode(child);
33
+ }
34
+ return next;
35
+ };
36
+ var shouldSanitizeProviderSchema = (provider) => LIMITED_JSON_SCHEMA_PROVIDERS.has(asTrimmedLowercaseString(provider));
37
+ var sanitizeToolForProvider = (tool, provider) => {
38
+ if (!shouldSanitizeProviderSchema(provider)) {
39
+ return tool;
40
+ }
41
+ const parameters = tool?.function?.parameters;
42
+ if (!isRecord(parameters)) {
43
+ return tool;
44
+ }
45
+ return {
46
+ ...tool,
47
+ function: {
48
+ ...tool.function,
49
+ parameters: sanitizeSchemaNode(parameters)
50
+ }
51
+ };
52
+ };
53
+
54
+ // packages/ai/tools/prepareTools.ts
55
+ var translatedFunctionCache = /* @__PURE__ */ new Map();
56
+ var prepareToolsResultCache = /* @__PURE__ */ new Map();
57
+ var PREPARE_TOOLS_CACHE_LIMIT = 128;
58
+ function getTranslation(keys, defaultVal) {
59
+ for (const key of keys) {
60
+ if (i18n_default.exists(key)) {
61
+ return i18n_default.t(key);
62
+ }
63
+ const aiKey = key.startsWith("ai:") ? key : `ai:${key}`;
64
+ if (i18n_default.exists(aiKey)) {
65
+ return i18n_default.t(aiKey);
66
+ }
67
+ }
68
+ return defaultVal;
69
+ }
70
+ function translateSchema(schema) {
71
+ if (!schema || typeof schema !== "object") return schema;
72
+ const nextSchema = JSON.parse(JSON.stringify(schema));
73
+ const toolName = nextSchema.name;
74
+ if (!toolName) return nextSchema;
75
+ const walk = (node, path) => {
76
+ if (!node || typeof node !== "object") return;
77
+ if (typeof node.description === "string") {
78
+ const keysToTry = [
79
+ `${path}.description`,
80
+ `${path}.desc`,
81
+ path,
82
+ node.description
83
+ ];
84
+ node.description = getTranslation(keysToTry, node.description);
85
+ }
86
+ if (node.parameters && typeof node.parameters === "object") {
87
+ walk(node.parameters, path);
88
+ }
89
+ if (node.properties && typeof node.properties === "object") {
90
+ for (const [key, child] of Object.entries(node.properties)) {
91
+ const nextPath = path.endsWith(".params") ? `${path}.${key}` : `${path}.params.${key}`;
92
+ walk(child, nextPath);
93
+ }
94
+ }
95
+ if (node.items && typeof node.items === "object") {
96
+ walk(node.items, path);
97
+ }
98
+ const compositions = ["anyOf", "oneOf", "allOf"];
99
+ for (const comp of compositions) {
100
+ if (Array.isArray(node[comp])) {
101
+ node[comp].forEach((child, idx) => {
102
+ const suffix = child.type === "string" ? "stringDesc" : child.type === "object" ? "objectDesc" : `${idx}`;
103
+ walk(child, `${path}.${suffix}`);
104
+ });
105
+ }
106
+ }
107
+ };
108
+ walk(nextSchema, `tools.${toolName}`);
109
+ return nextSchema;
110
+ }
111
+ function currentI18nLanguage() {
112
+ return typeof i18n_default.language === "string" ? i18n_default.language : "";
113
+ }
114
+ function translateSchemaCached(schema) {
115
+ if (!schema || typeof schema !== "object") return schema;
116
+ const toolName = typeof schema.name === "string" ? schema.name : "";
117
+ if (!toolName) return translateSchema(schema);
118
+ const cacheKey = `${currentI18nLanguage()}\0${toolName}`;
119
+ const hit = translatedFunctionCache.get(cacheKey);
120
+ if (hit) return hit;
121
+ const translated = translateSchema(schema);
122
+ translatedFunctionCache.set(cacheKey, translated);
123
+ return translated;
124
+ }
125
+ function buildPrepareToolsCacheKey(toolNames, disabledToolNames, provider) {
126
+ return [
127
+ currentI18nLanguage(),
128
+ provider ?? "",
129
+ disabledToolNames.join(""),
130
+ toolNames.join("")
131
+ ].join("\0");
132
+ }
133
+ function rememberPrepareToolsResult(key, value) {
134
+ if (prepareToolsResultCache.size >= PREPARE_TOOLS_CACHE_LIMIT) {
135
+ const oldest = prepareToolsResultCache.keys().next().value;
136
+ if (oldest !== void 0) {
137
+ prepareToolsResultCache.delete(oldest);
138
+ }
139
+ }
140
+ prepareToolsResultCache.set(key, value);
141
+ }
142
+ var prepareTools = (toolNames, options) => {
143
+ const disabledList = canonicalizeToolNames(options?.disabledToolNames ?? []);
144
+ const disabledToolNames = new Set(disabledList);
145
+ const canonicalNames = canonicalizeToolNames(toolNames).filter(
146
+ (toolName) => !disabledToolNames.has(toolName)
147
+ );
148
+ const cacheKey = buildPrepareToolsCacheKey(
149
+ canonicalNames,
150
+ disabledList,
151
+ options?.provider
152
+ );
153
+ const cached = prepareToolsResultCache.get(cacheKey);
154
+ if (cached) {
155
+ return cached.slice();
156
+ }
157
+ const prepared = canonicalNames.map((toolName) => {
158
+ const regTool = toolRegistry[toolName];
159
+ if (!regTool) return regTool;
160
+ return {
161
+ ...regTool,
162
+ function: translateSchemaCached(regTool.function)
163
+ };
164
+ }).map((tool) => sanitizeToolForProvider(tool, options?.provider)).filter(Boolean);
165
+ rememberPrepareToolsResult(cacheKey, prepared);
166
+ return prepared.slice();
167
+ };
168
+
169
+ export {
170
+ prepareTools
171
+ };