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

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-WRUCQIV5.js +205 -0
  3. package/action-R4M4ORGA.js +28 -0
  4. package/addContentAction-UYFFTEWJ.js +26 -0
  5. package/addDialogAgentAction-OT4XZAVP.js +68 -0
  6. package/agentDeleteCommand-5DD2IM3J.js +327 -0
  7. package/agentEmailCommands-IASM2YBQ.js +628 -0
  8. package/agentListCommands-I6KZYCIG.js +223 -0
  9. package/agentMachineCommands-OUP3YQP7.js +425 -0
  10. package/agentPullCommand-O2MTUAFR.js +122 -0
  11. package/agentRecordCommands-QKGE2JTA.js +96 -0
  12. package/agentRunCommand-TVZXUBQ5.js +114 -0
  13. package/agentRunControl-K4VKNEHF.js +57 -0
  14. package/agentRuntimeLocal-ZYEIPTY4.js +104 -0
  15. package/agentSlice-T4PMW7W6.js +42 -0
  16. package/authCommand-EB5JSOX5.js +581 -0
  17. package/authCommands-XPEHTKSM.js +35 -0
  18. package/chunk-2EHX7F5G.js +1948 -0
  19. package/chunk-2FTTDCD4.js +675 -0
  20. package/chunk-3ASDTTEI.js +1774 -0
  21. package/chunk-3EUW3WEO.js +8 -0
  22. package/chunk-3LY4F7SV.js +9293 -0
  23. package/chunk-4CQLVGRV.js +50 -0
  24. package/chunk-4FBRSEV4.js +573 -0
  25. package/chunk-4IJYA27C.js +342 -0
  26. package/chunk-4QEWT7KD.js +933 -0
  27. package/chunk-4SN6J65J.js +38 -0
  28. package/chunk-4VNS5WPM.js +42 -0
  29. package/chunk-4ZDM73SD.js +34 -0
  30. package/chunk-5CS33IBL.js +301 -0
  31. package/chunk-5KLGBAAR.js +386 -0
  32. package/chunk-5MIDPSSK.js +206 -0
  33. package/chunk-5MMAK75Q.js +15 -0
  34. package/chunk-5W3VUFOX.js +34 -0
  35. package/chunk-63W5N6P3.js +150 -0
  36. package/chunk-6HYVJV7B.js +102 -0
  37. package/chunk-6WD3OOJS.js +20 -0
  38. package/chunk-7DAJ4AI4.js +191 -0
  39. package/chunk-7KCUSYT2.js +354 -0
  40. package/chunk-7T5PWAZN.js +171 -0
  41. package/chunk-AFON4QUU.js +112 -0
  42. package/chunk-AGFH73SK.js +239 -0
  43. package/chunk-ATNTHIZI.js +13 -0
  44. package/chunk-AVMKZHBC.js +85 -0
  45. package/chunk-AZPCASRE.js +36 -0
  46. package/chunk-BBYVOSU2.js +792 -0
  47. package/chunk-BCIOM4NZ.js +1078 -0
  48. package/chunk-C3RUNRHT.js +51 -0
  49. package/chunk-C4FTUXVF.js +146 -0
  50. package/chunk-CF2WZF4N.js +134 -0
  51. package/chunk-CF7PE763.js +10 -0
  52. package/chunk-CKOJQDKR.js +198 -0
  53. package/chunk-CMKUBIGW.js +1550 -0
  54. package/chunk-CWMSB67P.js +34 -0
  55. package/chunk-DCOA4QSN.js +105 -0
  56. package/chunk-DFFIZ25G.js +30 -0
  57. package/chunk-DWLEOOGR.js +8 -0
  58. package/chunk-DZ3XJVET.js +231 -0
  59. package/chunk-EHLHSX7R.js +1433 -0
  60. package/chunk-FM5IVZXO.js +4723 -0
  61. package/chunk-FVYY6MCS.js +1447 -0
  62. package/chunk-G3SUCT4W.js +8 -0
  63. package/chunk-GAKEBQD6.js +30 -0
  64. package/chunk-GBRG75BQ.js +86 -0
  65. package/chunk-GLYVN7EQ.js +238 -0
  66. package/chunk-H33743XH.js +25 -0
  67. package/chunk-HNMXYYJR.js +12 -0
  68. package/chunk-HNW7IJSK.js +71 -0
  69. package/chunk-I42VC5KR.js +15 -0
  70. package/chunk-IDZTNRP2.js +85 -0
  71. package/chunk-IHBCLYEE.js +22310 -0
  72. package/chunk-IJGXKGXW.js +421 -0
  73. package/chunk-ISNCLGUZ.js +146 -0
  74. package/chunk-IWX4UW2E.js +548 -0
  75. package/chunk-JBTJAPUF.js +35 -0
  76. package/chunk-JEXVIMYZ.js +55 -0
  77. package/chunk-JRKKFRAV.js +537 -0
  78. package/chunk-JZPBVBIY.js +94 -0
  79. package/chunk-K6BPOQLF.js +2052 -0
  80. package/chunk-K777STIO.js +478 -0
  81. package/chunk-KKY4B2Q2.js +21 -0
  82. package/chunk-KQHGZWSV.js +63 -0
  83. package/chunk-KUG52IAP.js +8 -0
  84. package/chunk-KX6YBIHG.js +8 -0
  85. package/chunk-LCBAMY2M.js +60 -0
  86. package/chunk-LM6IYQ3F.js +16 -0
  87. package/chunk-LTRXGFMS.js +83 -0
  88. package/chunk-M76ECQRD.js +13658 -0
  89. package/chunk-MNJDFJND.js +222 -0
  90. package/chunk-MRC4Q34M.js +188 -0
  91. package/chunk-MTU75CZ2.js +91 -0
  92. package/chunk-N54XAP77.js +19 -0
  93. package/chunk-O2ZNTTET.js +3272 -0
  94. package/chunk-O4BU24WZ.js +3212 -0
  95. package/chunk-OLZBQWZU.js +6 -0
  96. package/chunk-OPZYGHUC.js +89 -0
  97. package/chunk-OWOHNGCN.js +50 -0
  98. package/chunk-P3PKED2I.js +962 -0
  99. package/chunk-PFTAG6DY.js +1939 -0
  100. package/chunk-PMKQGGGM.js +221 -0
  101. package/chunk-PP4S6RTL.js +175 -0
  102. package/chunk-QJ7FZNYN.js +939 -0
  103. package/chunk-QSJ3HFEF.js +8 -0
  104. package/chunk-RGIM3WLT.js +113 -0
  105. package/chunk-RL776AGR.js +190 -0
  106. package/chunk-ROWQEJRP.js +139 -0
  107. package/chunk-S7Z2HMCN.js +25 -0
  108. package/chunk-SDJDLO5W.js +628 -0
  109. package/chunk-SOTZ6RDN.js +69 -0
  110. package/chunk-TILFE6LV.js +381 -0
  111. package/chunk-TIMLUWQA.js +231 -0
  112. package/chunk-TISCADJH.js +807 -0
  113. package/chunk-U4TRT5V4.js +246 -0
  114. package/chunk-U6VC4MU4.js +8 -0
  115. package/chunk-UAD2WT54.js +64 -0
  116. package/chunk-VC6OZXO5.js +298 -0
  117. package/chunk-VF4K2QE6.js +21 -0
  118. package/chunk-VHBWHNVT.js +59 -0
  119. package/chunk-VIDPVFP3.js +20 -0
  120. package/chunk-VP4WJWKW.js +8882 -0
  121. package/chunk-VVX233PH.js +482 -0
  122. package/chunk-W4NVOSFF.js +37 -0
  123. package/chunk-WI4XWASA.js +208 -0
  124. package/chunk-WWC7I6TA.js +8 -0
  125. package/chunk-WZSRQNQG.js +2587 -0
  126. package/chunk-XBROXIGL.js +3066 -0
  127. package/chunk-XENYHRUE.js +104 -0
  128. package/chunk-Y5GCAMGP.js +9 -0
  129. package/chunk-YN4XDB7B.js +9036 -0
  130. package/chunk-YPRZSPF3.js +148 -0
  131. package/chunk-Z4NR32XR.js +50 -0
  132. package/chunk-Z6EKEXJW.js +138 -0
  133. package/chunk-ZDRZMLKO.js +27339 -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-CCABEOM6.js +866 -0
  138. package/createDialogAction-YPKF5ITI.js +55 -0
  139. package/createPageAction-YEZ7EK5F.js +172 -0
  140. package/db-HCJ5PRB5.js +271 -0
  141. package/dbSlice-QPVZHBOE.js +60 -0
  142. package/deleteFile-SV5MS23W.js +41 -0
  143. package/dialogCommands-4IX4XIZE.js +63 -0
  144. package/dialogSlice-OVTO7QGW.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-ZAYLW2HN.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-TZMZ4EP5.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-M4ZJZIMS.js +781 -0
  160. package/machineInfo-M6KB6HZN.js +10 -0
  161. package/machineWsRunDispatch-TPJAUGLP.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 -23
  166. package/read-EBMWX4Z6.js +17 -0
  167. package/readDocTool-2MWHSTQE.js +16 -0
  168. package/readlineWorkspace-OMCIU3WT.js +5682 -0
  169. package/removeDialogAgentAction-SNZ662NP.js +73 -0
  170. package/runAgentClientLoop-H6NGOUAM.js +293 -0
  171. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  172. package/setDialogExtraReferencesAction-XDI2KM2N.js +60 -0
  173. package/setPrimaryDialogAgentAction-PYEC4N4Z.js +80 -0
  174. package/settingSlice-NOWHY2FK.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-QHBPICA2.js +149 -0
  181. package/streamAgentChatTurn-3XTBA2HN.js +4510 -0
  182. package/tableCommands-R5UCM63M.js +1286 -0
  183. package/toolApiClient-QI3YBNWB.js +26 -0
  184. package/tools-GHLZ3XD6.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-XA2OZTLP.js +188 -0
@@ -0,0 +1,354 @@
1
+ import {
2
+ readDbRecord,
3
+ writeAgentRecord
4
+ } from "./chunk-SDJDLO5W.js";
5
+ import {
6
+ buildSkillSummaryMarker
7
+ } from "./chunk-VF4K2QE6.js";
8
+ import {
9
+ buildSkillDocMarkdown
10
+ } from "./chunk-VC6OZXO5.js";
11
+ import {
12
+ createSpaceKey
13
+ } from "./chunk-UAD2WT54.js";
14
+ import {
15
+ parseUserIdFromAuthToken,
16
+ readOption,
17
+ resolveAuthToken,
18
+ resolveServerUrl
19
+ } from "./chunk-ISNCLGUZ.js";
20
+ import {
21
+ asTrimmedLowercaseString
22
+ } from "./chunk-QSJ3HFEF.js";
23
+ import {
24
+ DEFAULT_LOCAL_API_ORIGIN
25
+ } from "./chunk-4SN6J65J.js";
26
+ import {
27
+ NOLO_CLUSTER_SERVERS
28
+ } from "./chunk-LCBAMY2M.js";
29
+ import {
30
+ normalizeServerOrigin
31
+ } from "./chunk-CF7PE763.js";
32
+
33
+ // packages/cli/docPageHelpers.ts
34
+ import { readFileSync } from "node:fs";
35
+ import { ulid } from "ulid";
36
+ function getCliArg(args, flag) {
37
+ const idx = args.indexOf(flag);
38
+ return idx !== -1 ? args[idx + 1] : void 0;
39
+ }
40
+ function readBodyArg(args, fallback = "") {
41
+ const bodyFile = getCliArg(args, "--body-file");
42
+ if (bodyFile !== void 0) {
43
+ return readFileSync(bodyFile, "utf8");
44
+ }
45
+ return getCliArg(args, "--body") ?? fallback;
46
+ }
47
+ function textToSlate(text) {
48
+ return text.split("\n").map((line) => ({
49
+ type: "paragraph",
50
+ children: [{ text: line }]
51
+ }));
52
+ }
53
+ function createPageId() {
54
+ return ulid();
55
+ }
56
+ function buildPageKey(userId, pageId) {
57
+ return `page-${userId}-${pageId}`;
58
+ }
59
+ function buildPageRecord(args) {
60
+ const { dbKey, pageId, title, spaceId, content, existing, meta, slateData } = args;
61
+ const now = Date.now();
62
+ const createdAt = typeof existing?.createdAt === "number" ? existing.createdAt : now;
63
+ const created = typeof existing?.created === "string" ? existing.created : new Date(createdAt).toISOString();
64
+ const nextRecord = {
65
+ ...existing ?? {},
66
+ id: existing?.id ?? pageId,
67
+ dbKey,
68
+ type: "page",
69
+ title,
70
+ spaceId,
71
+ content,
72
+ updatedAt: now,
73
+ createdAt,
74
+ created
75
+ };
76
+ if (meta !== void 0) {
77
+ if (meta === null) {
78
+ delete nextRecord.meta;
79
+ } else {
80
+ nextRecord.meta = meta;
81
+ }
82
+ }
83
+ if (slateData !== void 0) {
84
+ if (slateData === null) {
85
+ delete nextRecord.slateData;
86
+ } else {
87
+ nextRecord.slateData = slateData;
88
+ }
89
+ } else if (!existing?.slateData) {
90
+ nextRecord.slateData = textToSlate(content);
91
+ }
92
+ return nextRecord;
93
+ }
94
+
95
+ // packages/cli/docSkillHelpers.ts
96
+ function normalizeSkillSeed(input) {
97
+ return input.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/g, "-").replace(/^-+|-+$/g, "");
98
+ }
99
+ function deterministicId(prefix, seed) {
100
+ let h = 2166136261;
101
+ for (let i = 0; i < seed.length; i++) {
102
+ h ^= seed.charCodeAt(i);
103
+ h = h * 16777619 >>> 0;
104
+ }
105
+ const suffix = h.toString(36).toUpperCase().padStart(14, "0");
106
+ return (prefix + suffix).slice(0, 26);
107
+ }
108
+ function buildSkillDocId(input) {
109
+ return deterministicId("01SK", normalizeSkillSeed(input) || input);
110
+ }
111
+ function buildSkillPageKey(userId, skillId) {
112
+ return buildPageKey(userId, skillId);
113
+ }
114
+ function buildSkillPageRecord(args) {
115
+ const {
116
+ dbKey,
117
+ skillId,
118
+ title,
119
+ spaceId,
120
+ body,
121
+ skillConfig,
122
+ evalConfig,
123
+ workflowConfig,
124
+ existing
125
+ } = args;
126
+ return {
127
+ ...buildPageRecord({
128
+ dbKey,
129
+ pageId: skillId,
130
+ title,
131
+ spaceId,
132
+ content: buildSkillDocMarkdown({
133
+ body,
134
+ skillConfig,
135
+ evalConfig,
136
+ workflowConfig
137
+ }),
138
+ existing,
139
+ meta: {
140
+ ...existing?.meta ?? {},
141
+ kind: "skill",
142
+ skillConfig,
143
+ ...evalConfig ? { evalConfig } : {},
144
+ ...workflowConfig ? { workflowConfig } : {}
145
+ },
146
+ slateData: null
147
+ })
148
+ };
149
+ }
150
+ function parseJsonArg(raw, fallback) {
151
+ if (raw === void 0) return fallback;
152
+ return JSON.parse(raw);
153
+ }
154
+
155
+ // packages/cli/docSpaceHelpers.ts
156
+ async function ensurePageAttachedToSpace(params) {
157
+ const { baseUrl, userId, authToken, spaceId, contentKey, title, skillSummary } = params;
158
+ const spaceKey = createSpaceKey.space(spaceId);
159
+ const spaceRecord = await readDbRecord({
160
+ dbKey: spaceKey,
161
+ authToken,
162
+ fetchImpl: fetch,
163
+ serverUrl: baseUrl
164
+ });
165
+ const now = Date.now();
166
+ await writeAgentRecord({
167
+ agentKey: spaceKey,
168
+ authToken,
169
+ fetchImpl: fetch,
170
+ serverUrl: baseUrl,
171
+ userId,
172
+ record: {
173
+ ...spaceRecord,
174
+ contents: {
175
+ ...spaceRecord.contents ?? {},
176
+ [contentKey]: {
177
+ ...spaceRecord.contents?.[contentKey] ?? {},
178
+ title,
179
+ type: "page",
180
+ contentKey,
181
+ ...skillSummary !== void 0 ? { skillSummary } : {},
182
+ updatedAt: now,
183
+ createdAt: spaceRecord.contents?.[contentKey]?.createdAt ?? now
184
+ }
185
+ },
186
+ updatedAt: now
187
+ }
188
+ });
189
+ }
190
+ async function removePageFromSpace(params) {
191
+ const { baseUrl, userId, authToken, spaceId, contentKey } = params;
192
+ const spaceKey = createSpaceKey.space(spaceId);
193
+ const spaceRecord = await readDbRecord({
194
+ dbKey: spaceKey,
195
+ authToken,
196
+ fetchImpl: fetch,
197
+ serverUrl: baseUrl
198
+ });
199
+ const nextContents = { ...spaceRecord.contents ?? {} };
200
+ delete nextContents[contentKey];
201
+ await writeAgentRecord({
202
+ agentKey: spaceKey,
203
+ authToken,
204
+ fetchImpl: fetch,
205
+ serverUrl: baseUrl,
206
+ userId,
207
+ record: {
208
+ ...spaceRecord,
209
+ contents: nextContents,
210
+ updatedAt: Date.now()
211
+ }
212
+ });
213
+ }
214
+
215
+ // packages/cli/docCommandShared.ts
216
+ function hasHelpArg(args) {
217
+ return args.includes("--help") || args.includes("-h");
218
+ }
219
+ function hasFlag(args, flag) {
220
+ return args.includes(flag);
221
+ }
222
+ function normalizeBaseUrl(base) {
223
+ return normalizeServerOrigin(base);
224
+ }
225
+ function localBaseFromEnv(env) {
226
+ return normalizeBaseUrl(env.SCRIPT_LOCAL_BASE_URL || DEFAULT_LOCAL_API_ORIGIN);
227
+ }
228
+ function targetToBase(target, env) {
229
+ const normalized = asTrimmedLowercaseString(target);
230
+ if (normalized === "local") return localBaseFromEnv(env);
231
+ if (normalized === "main") return normalizeBaseUrl(NOLO_CLUSTER_SERVERS[0]);
232
+ if (normalized === "us") return normalizeBaseUrl(NOLO_CLUSTER_SERVERS[1]);
233
+ return normalizeBaseUrl(target);
234
+ }
235
+ function parseSyncTargets(raw, env) {
236
+ if (!raw) return void 0;
237
+ return raw.split(",").map((value) => value.trim()).filter(Boolean).filter((value) => value !== "none").map((value) => targetToBase(value, env));
238
+ }
239
+ function isLocalBaseUrl(baseUrl) {
240
+ try {
241
+ const hostname = new URL(baseUrl).hostname;
242
+ return hostname === "localhost" || hostname === "127.0.0.1";
243
+ } catch {
244
+ return false;
245
+ }
246
+ }
247
+ function resolveWriteTargets(args, env) {
248
+ const explicitSync = parseSyncTargets(readOption(args, "--sync"), env);
249
+ const targets = hasFlag(args, "--local-only") ? [localBaseFromEnv(env)] : explicitSync ?? [resolveServerUrl(args, env)];
250
+ const filtered = hasFlag(args, "--no-local") ? targets.filter((target) => !isLocalBaseUrl(target)) : targets;
251
+ return Array.from(new Set(filtered.map(normalizeBaseUrl)));
252
+ }
253
+ function readTitle(args) {
254
+ const valueFlags = /* @__PURE__ */ new Set([
255
+ "--title",
256
+ "--name",
257
+ "--description",
258
+ "--body",
259
+ "--body-file",
260
+ "--space",
261
+ "--id",
262
+ "--key",
263
+ "--kind",
264
+ "--sync",
265
+ "--tools",
266
+ "--required-skills",
267
+ "--recommended-skills",
268
+ "--preferred-agents",
269
+ "--trigger-mode",
270
+ "--budget-tier",
271
+ "--prompt-patch",
272
+ "--token",
273
+ "--server"
274
+ ]);
275
+ return readOption(args, "--title") ?? args.find((value, index) => {
276
+ if (index === 0) return false;
277
+ if (valueFlags.has(args[index - 1])) return false;
278
+ return !value.startsWith("-");
279
+ });
280
+ }
281
+ function resolveDocKind(args, fallback) {
282
+ if (hasFlag(args, "--page") || readOption(args, "--kind") === "page") return "page";
283
+ return fallback;
284
+ }
285
+ function requireTokenUser(args, env, dryRun) {
286
+ const authToken = resolveAuthToken(args, env);
287
+ const userId = parseUserIdFromAuthToken(authToken) || env.USER_ID || "";
288
+ if (!authToken && !dryRun) {
289
+ throw new Error("doc command requires an auth token. Pass --token or set AUTH_TOKEN.");
290
+ }
291
+ if (!userId && !dryRun) {
292
+ throw new Error("auth token does not contain userId. Pass a user-scoped token.");
293
+ }
294
+ return {
295
+ authToken,
296
+ userId: userId || "dry-run"
297
+ };
298
+ }
299
+ async function writePageRecord(args) {
300
+ await writeAgentRecord({
301
+ agentKey: args.dbKey,
302
+ authToken: args.authToken,
303
+ fetchImpl: fetch,
304
+ serverUrl: args.serverUrl,
305
+ userId: args.userId,
306
+ record: args.record
307
+ });
308
+ if (args.spaceId) {
309
+ await ensurePageAttachedToSpace({
310
+ baseUrl: args.serverUrl,
311
+ userId: args.userId,
312
+ authToken: args.authToken,
313
+ spaceId: args.spaceId,
314
+ contentKey: args.dbKey,
315
+ title: args.title,
316
+ skillSummary: args.skillSummary
317
+ });
318
+ }
319
+ }
320
+ async function readPageRecord(args) {
321
+ return readDbRecord({
322
+ dbKey: args.dbKey,
323
+ authToken: args.authToken,
324
+ fetchImpl: fetch,
325
+ serverUrl: args.serverUrl
326
+ });
327
+ }
328
+ function buildSkillSummaryForRecord(record) {
329
+ const meta = record?.meta;
330
+ const skillConfig = meta?.skillConfig;
331
+ if (!skillConfig) return void 0;
332
+ return buildSkillSummaryMarker(meta);
333
+ }
334
+
335
+ export {
336
+ readBodyArg,
337
+ createPageId,
338
+ buildPageKey,
339
+ buildPageRecord,
340
+ buildSkillDocId,
341
+ buildSkillPageKey,
342
+ buildSkillPageRecord,
343
+ parseJsonArg,
344
+ removePageFromSpace,
345
+ hasHelpArg,
346
+ hasFlag,
347
+ resolveWriteTargets,
348
+ readTitle,
349
+ resolveDocKind,
350
+ requireTokenUser,
351
+ writePageRecord,
352
+ readPageRecord,
353
+ buildSkillSummaryForRecord
354
+ };
@@ -0,0 +1,171 @@
1
+ import {
2
+ i18n_default,
3
+ toolRegistry
4
+ } from "./chunk-ZDRZMLKO.js";
5
+ import {
6
+ canonicalizeToolNames
7
+ } from "./chunk-P3PKED2I.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
+ };
@@ -0,0 +1,112 @@
1
+ import {
2
+ buildSkillDiscoveryLayer
3
+ } from "./chunk-C4FTUXVF.js";
4
+ import {
5
+ load
6
+ } from "./chunk-WZSRQNQG.js";
7
+
8
+ // packages/agent-runtime/skillDiscovery.ts
9
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ var SKILL_SCAN_DIRS = [".agents/skills", "docs/skills"];
12
+ var MAX_DISCOVERED_SKILLS = 50;
13
+ function parseSkillFrontmatter(filePath) {
14
+ try {
15
+ const content = readFileSync(filePath, "utf8").slice(0, 2048);
16
+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
17
+ if (!fmMatch) return {};
18
+ const fm = load(fmMatch[1]);
19
+ if (!fm || typeof fm !== "object") return {};
20
+ const name = typeof fm.name === "string" ? fm.name : void 0;
21
+ const rawDesc = fm.description;
22
+ const description = typeof rawDesc === "string" ? rawDesc : rawDesc == null ? void 0 : String(rawDesc);
23
+ const sanitize = (s) => s?.trim().replace(/^["']|["']$/g, "").replace(/[\n\r]+/g, " ").slice(0, 200);
24
+ return { name: sanitize(name), description: sanitize(description) };
25
+ } catch {
26
+ return {};
27
+ }
28
+ }
29
+ function discoverSkills(cwd) {
30
+ const skills = [];
31
+ for (const dir of SKILL_SCAN_DIRS) {
32
+ if (skills.length >= MAX_DISCOVERED_SKILLS) break;
33
+ const absDir = join(cwd, dir);
34
+ if (!existsSync(absDir) || !statSync(absDir).isDirectory()) continue;
35
+ try {
36
+ for (const entry of readdirSync(absDir)) {
37
+ if (skills.length >= MAX_DISCOVERED_SKILLS) break;
38
+ const skillMdPath = join(absDir, entry, "SKILL.md");
39
+ if (existsSync(skillMdPath)) {
40
+ const { name, description } = parseSkillFrontmatter(skillMdPath);
41
+ skills.push({ name: name ?? entry, description: description ?? "", relativePath: join(dir, entry, "SKILL.md") });
42
+ continue;
43
+ }
44
+ if (dir === "docs/skills" && entry.endsWith(".md")) {
45
+ const flatPath = join(absDir, entry);
46
+ const { name, description } = parseSkillFrontmatter(flatPath);
47
+ skills.push({ name: name ?? entry.replace(/\.md$/, ""), description: description ?? "", relativePath: join(dir, entry) });
48
+ }
49
+ }
50
+ } catch {
51
+ }
52
+ }
53
+ return skills;
54
+ }
55
+ function resolveSkillByName(cwd, name) {
56
+ const trimmed = name.trim();
57
+ if (!trimmed || trimmed.includes("/") || trimmed.includes("\\") || trimmed.includes("..")) {
58
+ return null;
59
+ }
60
+ const agentsDir = join(cwd, ".agents", "skills", trimmed);
61
+ const agentsSkillMd = join(agentsDir, "SKILL.md");
62
+ if (existsSync(agentsSkillMd)) return agentsSkillMd;
63
+ const agentsParent = join(cwd, ".agents", "skills");
64
+ if (existsSync(agentsParent) && statSync(agentsParent).isDirectory()) {
65
+ try {
66
+ for (const entry of readdirSync(agentsParent)) {
67
+ const candidate = join(agentsParent, entry, "SKILL.md");
68
+ if (!existsSync(candidate)) continue;
69
+ try {
70
+ const { name: fmName } = parseSkillFrontmatter(candidate);
71
+ if (fmName && fmName === trimmed) return candidate;
72
+ } catch {
73
+ }
74
+ }
75
+ } catch {
76
+ }
77
+ }
78
+ const docsFlat = join(cwd, "docs", "skills", `${trimmed}.md`);
79
+ if (existsSync(docsFlat)) return docsFlat;
80
+ const docsDir = join(cwd, "docs", "skills");
81
+ if (existsSync(docsDir) && statSync(docsDir).isDirectory()) {
82
+ try {
83
+ for (const entry of readdirSync(docsDir)) {
84
+ if (!entry.endsWith(".md")) continue;
85
+ const candidate = join(docsDir, entry);
86
+ try {
87
+ const { name: fmName } = parseSkillFrontmatter(candidate);
88
+ if (fmName && fmName === trimmed) return candidate;
89
+ } catch {
90
+ }
91
+ }
92
+ } catch {
93
+ }
94
+ }
95
+ return null;
96
+ }
97
+ function buildSkillDiscoveryContextBlock(cwd) {
98
+ try {
99
+ const discovered = discoverSkills(cwd);
100
+ const layer = buildSkillDiscoveryLayer(discovered, cwd);
101
+ return layer?.content ?? null;
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+
107
+ export {
108
+ parseSkillFrontmatter,
109
+ discoverSkills,
110
+ resolveSkillByName,
111
+ buildSkillDiscoveryContextBlock
112
+ };