nolo-cli 0.6.1 → 0.8.0-alpha.10

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-CPDNUUQV.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-OSUMJMZM.js +323 -0
  6. package/agentEmailCommands-OQTJIPQU.js +621 -0
  7. package/agentListCommands-FATQEUYT.js +219 -0
  8. package/agentMachineCommands-6LZWF4GL.js +421 -0
  9. package/agentPullCommand-O2MTUAFR.js +122 -0
  10. package/agentRecordCommands-TIHFU65Z.js +89 -0
  11. package/agentRunCommand-R64Y3HCH.js +102 -0
  12. package/agentRunControl-K4VKNEHF.js +57 -0
  13. package/agentRuntimeLocal-6PIWAHLQ.js +99 -0
  14. package/agentSlice-TP4VARJF.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-2TPUKEU7.js +1078 -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-572EKYLF.js +792 -0
  29. package/chunk-5MIDPSSK.js +206 -0
  30. package/chunk-5MMAK75Q.js +15 -0
  31. package/chunk-5VV37AT4.js +222 -0
  32. package/chunk-63W5N6P3.js +150 -0
  33. package/chunk-6A5EF6IR.js +929 -0
  34. package/chunk-6HYVJV7B.js +102 -0
  35. package/chunk-6P2WX5IA.js +3631 -0
  36. package/chunk-6WD3OOJS.js +20 -0
  37. package/chunk-ATNTHIZI.js +13 -0
  38. package/chunk-AUGHVUFE.js +69 -0
  39. package/chunk-AVMKZHBC.js +85 -0
  40. package/chunk-AZPCASRE.js +36 -0
  41. package/chunk-BNMT7YY5.js +34 -0
  42. package/chunk-BR2WP3DF.js +548 -0
  43. package/chunk-BSTNFPHD.js +231 -0
  44. package/chunk-BU4OPIXC.js +171 -0
  45. package/chunk-CF2WZF4N.js +134 -0
  46. package/chunk-CF7PE763.js +10 -0
  47. package/chunk-CKOJQDKR.js +198 -0
  48. package/chunk-CM54RSSA.js +206 -0
  49. package/chunk-CWMSB67P.js +34 -0
  50. package/chunk-DA2OEKS6.js +27 -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-FQZWM5YX.js +628 -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-H2RMRZJE.js +113 -0
  63. package/chunk-H33743XH.js +25 -0
  64. package/chunk-HD63YREL.js +19 -0
  65. package/chunk-HEIIIZBX.js +104 -0
  66. package/chunk-HNMXYYJR.js +12 -0
  67. package/chunk-HOMYP7GZ.js +2152 -0
  68. package/chunk-HZFOMJRA.js +4300 -0
  69. package/chunk-IAXBCTTE.js +175 -0
  70. package/chunk-IDZTNRP2.js +85 -0
  71. package/chunk-IHHA5Y2S.js +9013 -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-JBTJAPUF.js +35 -0
  76. package/chunk-JZPBVBIY.js +94 -0
  77. package/chunk-KQHGZWSV.js +63 -0
  78. package/chunk-KUG52IAP.js +8 -0
  79. package/chunk-KX6YBIHG.js +8 -0
  80. package/chunk-LCBAMY2M.js +60 -0
  81. package/chunk-LM25IZBJ.js +902 -0
  82. package/chunk-LM6IYQ3F.js +16 -0
  83. package/chunk-M76ECQRD.js +13658 -0
  84. package/chunk-MRC4Q34M.js +188 -0
  85. package/chunk-NEMRK4EK.js +944 -0
  86. package/chunk-NXZGF7F7.js +2878 -0
  87. package/chunk-OF5H3QWS.js +300 -0
  88. package/chunk-OLZBQWZU.js +6 -0
  89. package/chunk-OOYVBFM7.js +191 -0
  90. package/chunk-OWOHNGCN.js +50 -0
  91. package/chunk-PN7AFLOK.js +3401 -0
  92. package/chunk-POCFIDGQ.js +562 -0
  93. package/chunk-Q6WACBKB.js +1949 -0
  94. package/chunk-QFV2OAIM.js +421 -0
  95. package/chunk-QJ6V2NIN.js +1447 -0
  96. package/chunk-QSJ3HFEF.js +8 -0
  97. package/chunk-QUWDTOUP.js +190 -0
  98. package/chunk-QYXLLLGL.js +4519 -0
  99. package/chunk-ROWQEJRP.js +139 -0
  100. package/chunk-S7Z2HMCN.js +25 -0
  101. package/chunk-TDIQFT2F.js +301 -0
  102. package/chunk-TILFE6LV.js +381 -0
  103. package/chunk-TKOUBWBO.js +24674 -0
  104. package/chunk-TYH5JE6N.js +27158 -0
  105. package/chunk-U4TRT5V4.js +246 -0
  106. package/chunk-U6VC4MU4.js +8 -0
  107. package/chunk-UAD2WT54.js +64 -0
  108. package/chunk-USZMK5UT.js +105 -0
  109. package/chunk-VEJLAVTC.js +2052 -0
  110. package/chunk-VF4K2QE6.js +21 -0
  111. package/chunk-VHBWHNVT.js +59 -0
  112. package/chunk-VIDPVFP3.js +20 -0
  113. package/chunk-VP4WJWKW.js +8882 -0
  114. package/chunk-VQ2AJRGD.js +148 -0
  115. package/chunk-W4NVOSFF.js +37 -0
  116. package/chunk-WWC7I6TA.js +8 -0
  117. package/chunk-X7W4TNB4.js +1550 -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-YWPXYBY7.js +360 -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-KLKS2HGU.js +864 -0
  127. package/createDialogAction-Z33JMBF5.js +52 -0
  128. package/createPageAction-AQVNOAAI.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-W5PD6MZU.js +59 -0
  133. package/dialogSlice-RBJYVSAR.js +146 -0
  134. package/docCreateCommands-MM34S4Z3.js +215 -0
  135. package/docDeleteCommands-JJTU722V.js +176 -0
  136. package/docReadCommands-GLYDMCTU.js +129 -0
  137. package/docStore-5TYME4DO.js +96 -0
  138. package/docUpdateCommands-ZCGQ7URR.js +313 -0
  139. package/fetchMessages-JOCYIFKL.js +16 -0
  140. package/getPricing-PWPJ6MNV.js +30 -0
  141. package/handleSendMessageAction-KA2MRW6E.js +183 -0
  142. package/index.js +184 -112254
  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-ZB5WUSPF.js +774 -0
  149. package/machineInfo-M6KB6HZN.js +10 -0
  150. package/machineWsRunDispatch-GWCAPPCM.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-FEDY44AA.js +5357 -0
  158. package/removeDialogAgentAction-CXLST3N6.js +72 -0
  159. package/runAgentClientLoop-W4NKE64V.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-LC4FDAKE.js +450 -0
  168. package/spaceSlice-32XOGBEF.js +145 -0
  169. package/streamAgentChatTurn-YQW32AQH.js +4503 -0
  170. package/tableCommands-GOFP7QKA.js +1286 -0
  171. package/toolApiClient-QI3YBNWB.js +26 -0
  172. package/tools-XGTFRYD7.js +83 -0
  173. package/understanding-HCSFPE7R.js +318 -0
  174. package/updateCommands-VOSPKXFF.js +31 -0
  175. package/updateDialogTitleAction-4LHQDNHQ.js +185 -0
@@ -0,0 +1,198 @@
1
+ import {
2
+ loadProfileConfig
3
+ } from "./chunk-ROWQEJRP.js";
4
+ import {
5
+ resolveDefaultSpawn
6
+ } from "./chunk-IDZTNRP2.js";
7
+ import {
8
+ isCompiledBinary
9
+ } from "./chunk-ISNCLGUZ.js";
10
+ import {
11
+ DEFAULT_NOLO_SERVER_URL
12
+ } from "./chunk-OLZBQWZU.js";
13
+ import {
14
+ normalizeServerOrigin
15
+ } from "./chunk-CF7PE763.js";
16
+
17
+ // packages/cli/updateCommands.ts
18
+ import { existsSync, readFileSync } from "node:fs";
19
+ import { dirname, join } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+ function resolvePackageJsonPath() {
22
+ if (isCompiledBinary()) {
23
+ const execDir = dirname(process.execPath);
24
+ const candidate2 = join(execDir, "package.json");
25
+ if (existsSync(candidate2)) return candidate2;
26
+ return null;
27
+ }
28
+ const CLI_DIR = dirname(fileURLToPath(import.meta.url));
29
+ const candidate = join(CLI_DIR, "package.json");
30
+ return existsSync(candidate) ? candidate : null;
31
+ }
32
+ var PACKAGE_JSON_PATH = resolvePackageJsonPath();
33
+ function getCliInstallChannel(serverUrl) {
34
+ const normalized = normalizeServerOrigin(serverUrl);
35
+ if (!normalized) {
36
+ return "latest";
37
+ }
38
+ try {
39
+ const hostname = new URL(normalized).hostname.toLowerCase();
40
+ if (hostname === "us.nolo.chat" || hostname.endsWith(".us.nolo.chat")) {
41
+ return "alpha";
42
+ }
43
+ } catch {
44
+ if (/us\.nolo\.chat/i.test(normalized)) {
45
+ return "alpha";
46
+ }
47
+ }
48
+ return "latest";
49
+ }
50
+ function renderProgressBar(percent, width = 30) {
51
+ const pct = Math.max(0, Math.min(100, percent));
52
+ const filledLen = Math.round(width * pct / 100);
53
+ const emptyLen = width - filledLen;
54
+ const bar = "#".repeat(filledLen) + " ".repeat(emptyLen);
55
+ const pctText = pct.toFixed(1).padStart(5, " ");
56
+ return `[${bar}] ${pctText}%`;
57
+ }
58
+ function buildNpmSelfUpdateCommand(channel = "latest") {
59
+ return ["npm", "install", "-g", `nolo-cli@${channel}`, "--force", "--progress"];
60
+ }
61
+ function readPackageInfo() {
62
+ if (PACKAGE_JSON_PATH) {
63
+ try {
64
+ const raw = readFileSync(PACKAGE_JSON_PATH, "utf8");
65
+ const parsed = JSON.parse(raw);
66
+ return {
67
+ name: parsed.name || "nolo-cli",
68
+ version: parsed.version || "0.0.0"
69
+ };
70
+ } catch {
71
+ }
72
+ }
73
+ return {
74
+ name: process.env.NOLO_CLI_PACKAGE_NAME || "nolo-cli",
75
+ version: process.env.NOLO_CLI_VERSION || "0.0.0"
76
+ };
77
+ }
78
+ function buildCliVersionText(info) {
79
+ return `${info.name} ${info.version}`;
80
+ }
81
+ function buildSelfUpdateCommand(serverUrl) {
82
+ return buildNpmSelfUpdateCommand(getCliInstallChannel(serverUrl));
83
+ }
84
+ function resolveSelfUpdateServerUrl(env = process.env, override) {
85
+ if (override?.trim()) {
86
+ return normalizeServerOrigin(override);
87
+ }
88
+ const fromEnv = env.NOLO_SERVER || env.BASE_URL;
89
+ if (typeof fromEnv === "string" && fromEnv.trim()) {
90
+ return normalizeServerOrigin(fromEnv);
91
+ }
92
+ const profile = loadProfileConfig();
93
+ const profileUrl = profile?.profiles?.[profile.currentProfile]?.serverUrl;
94
+ if (profileUrl?.trim()) {
95
+ return normalizeServerOrigin(profileUrl);
96
+ }
97
+ return DEFAULT_NOLO_SERVER_URL;
98
+ }
99
+ function buildCliDoctorText(info) {
100
+ return [
101
+ "Nolo CLI doctor",
102
+ "---------------",
103
+ `version ${info.packageName} ${info.version}`,
104
+ `install ${info.installKind}`,
105
+ `channel ${info.updateChannel}`,
106
+ `entry ${info.entrypoint}`,
107
+ `server ${info.serverUrl}`,
108
+ `profile ${info.profileName}`,
109
+ `update nolo update`,
110
+ "",
111
+ "If direct `nolo` differs from repo-local `bun ./packages/cli/index.ts`,",
112
+ "the global install is older than this checkout.",
113
+ "",
114
+ `Manual update: ${buildNpmSelfUpdateCommand(info.updateChannel).join(" ")}`
115
+ ].join("\n");
116
+ }
117
+ function isRunSelfUpdateOptions(value) {
118
+ return typeof value === "object" && value !== null && ("output" in value || "spawn" in value || "entrypointPath" in value || "serverUrl" in value || "env" in value);
119
+ }
120
+ async function forwardSpawnOutput(stream, output) {
121
+ if (!stream) {
122
+ return;
123
+ }
124
+ for await (const chunk of stream) {
125
+ output.write(normalizeSpawnChunk(chunk));
126
+ }
127
+ }
128
+ function normalizeSpawnChunk(chunk) {
129
+ if (typeof chunk === "string" || chunk instanceof Uint8Array) {
130
+ return chunk;
131
+ }
132
+ if (chunk instanceof ArrayBuffer) {
133
+ return new Uint8Array(chunk);
134
+ }
135
+ return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
136
+ }
137
+ async function runSelfUpdate(outputOrOptions) {
138
+ const options = outputOrOptions === void 0 ? {} : isRunSelfUpdateOptions(outputOrOptions) ? outputOrOptions : { output: outputOrOptions };
139
+ const output = options.output ?? process.stdout;
140
+ const spawn = options.spawn ?? resolveDefaultSpawn();
141
+ const env = options.env ?? process.env;
142
+ const serverUrl = resolveSelfUpdateServerUrl(env, options.serverUrl);
143
+ const channel = getCliInstallChannel(serverUrl);
144
+ const command = buildNpmSelfUpdateCommand(channel);
145
+ output.write(`
146
+ Nolo Agent CLI Installer & Updater
147
+ `);
148
+ output.write(`-----------------------------------------
149
+ `);
150
+ output.write(`\u2713 Target channel: ${channel} (nolo-cli@${channel})
151
+ `);
152
+ output.write(`\u25B8 Downloading and installing package via npm...
153
+ `);
154
+ const useCustomSink = options.output !== void 0;
155
+ const proc = spawn({
156
+ cmd: command,
157
+ stdin: "inherit",
158
+ stdout: useCustomSink ? "pipe" : "inherit",
159
+ stderr: useCustomSink ? "pipe" : "inherit",
160
+ env
161
+ });
162
+ if (!useCustomSink) {
163
+ const exitCode2 = await proc.exited;
164
+ if (exitCode2 === 0) {
165
+ output.write(` ${renderProgressBar(100)}
166
+ `);
167
+ output.write(`\u2713 Update completed successfully!
168
+
169
+ `);
170
+ }
171
+ return exitCode2;
172
+ }
173
+ const [exitCode] = await Promise.all([
174
+ proc.exited,
175
+ forwardSpawnOutput(proc.stdout, output),
176
+ forwardSpawnOutput(proc.stderr, output)
177
+ ]);
178
+ if (exitCode === 0) {
179
+ output.write(` ${renderProgressBar(100)}
180
+ `);
181
+ output.write(`\u2713 Update completed successfully!
182
+
183
+ `);
184
+ }
185
+ return exitCode;
186
+ }
187
+
188
+ export {
189
+ getCliInstallChannel,
190
+ renderProgressBar,
191
+ buildNpmSelfUpdateCommand,
192
+ readPackageInfo,
193
+ buildCliVersionText,
194
+ buildSelfUpdateCommand,
195
+ resolveSelfUpdateServerUrl,
196
+ buildCliDoctorText,
197
+ runSelfUpdate
198
+ };
@@ -0,0 +1,206 @@
1
+ // packages/agent-runtime/modelLayerOverride.ts
2
+ var MODEL_LAYER_KEYS = [
3
+ "provider",
4
+ "model",
5
+ "apiSource",
6
+ "cliProvider",
7
+ "useServerProxy",
8
+ "apiKey",
9
+ "apiKeyRef",
10
+ "apiKeyHeader",
11
+ "customProviderUrl",
12
+ "credentialRef",
13
+ "credentialSynced",
14
+ "temperature",
15
+ "top_p",
16
+ "frequency_penalty",
17
+ "presence_penalty",
18
+ "max_tokens",
19
+ "reasoning_effort",
20
+ "enableThinking",
21
+ "thinkingBudget"
22
+ ];
23
+ function mergeReferences(base, extra) {
24
+ const safeBase = Array.isArray(base) ? base : [];
25
+ const safeExtra = Array.isArray(extra) ? extra : [];
26
+ const seen = /* @__PURE__ */ new Set();
27
+ const merged = [];
28
+ for (const item of [...safeBase, ...safeExtra]) {
29
+ const key = item?.dbKey;
30
+ if (key && seen.has(key)) continue;
31
+ if (key) seen.add(key);
32
+ if (item) merged.push(item);
33
+ }
34
+ return merged;
35
+ }
36
+ var asNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
37
+ function buildModelLayerOverride(agent) {
38
+ if (!agent || !asNonEmptyString(agent.provider) || !asNonEmptyString(agent.model)) {
39
+ return null;
40
+ }
41
+ const override = {
42
+ provider: agent.provider,
43
+ model: agent.model
44
+ };
45
+ for (const key of MODEL_LAYER_KEYS) {
46
+ if (key === "provider" || key === "model") continue;
47
+ const value = agent[key];
48
+ if (value !== void 0) {
49
+ override[key] = value;
50
+ }
51
+ }
52
+ if (Array.isArray(agent.references) && agent.references.length > 0) {
53
+ override.references = agent.references;
54
+ }
55
+ return override;
56
+ }
57
+ function applyModelLayerOverride(base, override) {
58
+ const next = { ...base };
59
+ for (const key of MODEL_LAYER_KEYS) {
60
+ delete next[key];
61
+ }
62
+ for (const key of MODEL_LAYER_KEYS) {
63
+ const value = override[key];
64
+ if (value !== void 0) {
65
+ next[key] = value;
66
+ }
67
+ }
68
+ const merged = mergeReferences(
69
+ base.references,
70
+ override.references
71
+ );
72
+ if (merged.length > 0) {
73
+ next.references = merged;
74
+ } else {
75
+ delete next.references;
76
+ }
77
+ return next;
78
+ }
79
+
80
+ // packages/agent-runtime/turnContext.ts
81
+ var DEFAULT_RECENT_CONTENT_LIMIT = 10;
82
+ var asTrimmed = (value) => typeof value === "string" ? value.trim() : "";
83
+ var asFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : 0;
84
+ var spaceRecordKey = (spaceId) => spaceId.startsWith("space-") ? spaceId : `space-${spaceId}`;
85
+ var makeLayer = (id, content, cacheScope = "turn") => ({ id, owner: "runtime", cacheScope, content });
86
+ var renderSpaceStructure = (spaceRecord, recentLimit) => {
87
+ const categories = spaceRecord.categories ?? {};
88
+ const validCategories = Object.entries(categories).filter((entry) => entry[1] !== null).sort(
89
+ (a, b) => asFiniteNumber(a[1].order) - asFiniteNumber(b[1].order)
90
+ );
91
+ const categoryNameById = /* @__PURE__ */ new Map();
92
+ let struct = "Directory Structure (Categories):\n";
93
+ if (validCategories.length === 0) struct += "(No categories defined)\n";
94
+ validCategories.forEach(([id, category]) => {
95
+ const name = asTrimmed(category.name) || id;
96
+ categoryNameById.set(id, name);
97
+ struct += `- ${name} (ID: ${id})
98
+ `;
99
+ });
100
+ const contents = spaceRecord.contents ?? {};
101
+ const recentContents = recentLimit > 0 ? Object.values(contents).filter((content) => content !== null).sort(
102
+ (a, b) => asFiniteNumber(b.updatedAt) - asFiniteNumber(a.updatedAt)
103
+ ).slice(0, recentLimit) : [];
104
+ if (recentContents.length > 0) {
105
+ struct += `
106
+ Recent Contents (Top ${recentLimit}):
107
+ `;
108
+ recentContents.forEach((content) => {
109
+ const categoryId = asTrimmed(content.categoryId);
110
+ const categoryName = categoryId ? categoryNameById.get(categoryId) || "Unknown" : "Uncategorized";
111
+ struct += `- [${asTrimmed(content.type) || "content"}] ${asTrimmed(content.title)} (Category: ${categoryName}, dbKey: ${asTrimmed(content.contentKey)})
112
+ `;
113
+ });
114
+ }
115
+ return struct;
116
+ };
117
+ var buildSpaceContextLayer = async (args) => {
118
+ const spaceId = asTrimmed(args.spaceId);
119
+ if (!spaceId) return null;
120
+ const recentLimit = args.recentContentLimit ?? DEFAULT_RECENT_CONTENT_LIMIT;
121
+ let spaceRecord = null;
122
+ let readError = null;
123
+ try {
124
+ spaceRecord = await args.source.readRecord(spaceRecordKey(spaceId));
125
+ } catch (error) {
126
+ readError = error instanceof Error ? error.message : String(error);
127
+ }
128
+ if (!spaceRecord) {
129
+ return makeLayer(
130
+ "space-context",
131
+ [
132
+ "--- \u5F53\u524D\u7A7A\u95F4\uFF08Space\uFF09---",
133
+ `\u672C\u5BF9\u8BDD\u8BB0\u5F55\u58F0\u660E\u5C5E\u4E8E Space ${spaceId}\uFF0C\u4F46\u5F53\u524D\u65E0\u6CD5\u8BFB\u53D6\u8BE5 Space \u7684\u6570\u636E${readError ? `\uFF08${readError}\uFF09` : "\uFF08\u8BB0\u5F55\u4E0D\u5B58\u5728\u6216\u4E0D\u53EF\u8FBE\uFF09"}\u3002`,
134
+ "\u5982\u88AB\u95EE\u53CA\uFF0C\u8BF7\u5982\u5B9E\u8BF4\u660E\u300C\u5BF9\u8BDD\u5C5E\u4E8E\u8BE5 Space \u4F46\u6682\u65F6\u8BFB\u4E0D\u5230\u7A7A\u95F4\u8BE6\u60C5\u300D\uFF0C\u4E0D\u8981\u58F0\u79F0\u5BF9\u8BDD\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u7A7A\u95F4\u3002"
135
+ ].join("\n")
136
+ );
137
+ }
138
+ const name = asTrimmed(spaceRecord.name);
139
+ const description = asTrimmed(spaceRecord.description);
140
+ const structure = renderSpaceStructure(spaceRecord, recentLimit);
141
+ return makeLayer(
142
+ "space-context",
143
+ [
144
+ "--- \u5F53\u524D\u7A7A\u95F4\uFF08Space\uFF09---",
145
+ "\u672C\u5BF9\u8BDD\u5C5E\u4E8E\u4EE5\u4E0B Space\uFF1A",
146
+ `Space Title: ${name || spaceId}`,
147
+ `Space ID: ${spaceId}`,
148
+ `Description: ${description || "N/A"}`,
149
+ "",
150
+ structure.trimEnd()
151
+ ].join("\n")
152
+ );
153
+ };
154
+ var buildSkillDiscoveryLayer = (skills, boundFolder) => {
155
+ if (skills.length === 0) return null;
156
+ const lines = [
157
+ "--- \u53EF\u7528\u6280\u80FD\uFF08Skills\uFF09---",
158
+ `\u5DE5\u4F5C\u533A ${boundFolder} \u4E2D\u53D1\u73B0\u4E86 ${skills.length} \u4E2A\u6280\u80FD\uFF08SKILL.md\uFF09\uFF1A`,
159
+ "\u6A21\u578B\u53EF\u6309\u9700\u7528 readFile \u8BFB\u53D6\u4EE5\u4E0B\u6587\u4EF6\u83B7\u53D6\u8BE6\u7EC6\u6307\u4EE4\uFF1A",
160
+ "",
161
+ ...skills.map(
162
+ (s) => `- ${s.name}: ${s.description}
163
+ path: ${s.relativePath}`
164
+ )
165
+ ];
166
+ return makeLayer("skill-discovery", lines.join("\n"));
167
+ };
168
+ var buildLinkedSpacesSection = async (args) => {
169
+ const ids = (args.linkedSpaceIds ?? []).filter(
170
+ (id) => typeof id === "string" && id.trim() !== ""
171
+ );
172
+ if (ids.length === 0) return null;
173
+ const lines = [];
174
+ for (const rawId of ids) {
175
+ const spaceId = asTrimmed(rawId);
176
+ let spaceData = null;
177
+ try {
178
+ spaceData = await args.source.readRecord(spaceRecordKey(spaceId));
179
+ } catch {
180
+ spaceData = null;
181
+ }
182
+ if (spaceData) {
183
+ const name = asTrimmed(spaceData.name) || spaceId;
184
+ const desc = asTrimmed(spaceData.description);
185
+ lines.push(`- ${name} (ID: ${spaceId})${desc ? `: ${desc}` : ""}`);
186
+ } else {
187
+ lines.push(`- [\u65E0\u6CD5\u8BBF\u95EE] ${spaceId}`);
188
+ }
189
+ }
190
+ if (lines.length === 0) return null;
191
+ return [
192
+ "--- \u5173\u8054\u7A7A\u95F4 (Linked Spaces) ---",
193
+ "\u4EE5\u4E0B\u662F Agent \u53EF\u8BBF\u95EE\u7684\u5176\u4ED6\u5DE5\u4F5C\u7A7A\u95F4\uFF08\u7C97\u7565\u4E0A\u4E0B\u6587\uFF09\uFF1A",
194
+ lines.join("\n"),
195
+ "",
196
+ "\u63D0\u793A\uFF1A\u5982\u9700\u67E5\u8BE2\u8FD9\u4E9B\u7A7A\u95F4\u7684\u8BE6\u7EC6\u5185\u5BB9\uFF0C\u53EF\u4F7F\u7528 read \u5DE5\u5177\u914D\u5408\u5BF9\u5E94\u7684 dbKey\u3002"
197
+ ].join("\n");
198
+ };
199
+
200
+ export {
201
+ buildModelLayerOverride,
202
+ applyModelLayerOverride,
203
+ buildSpaceContextLayer,
204
+ buildSkillDiscoveryLayer,
205
+ buildLinkedSpacesSection
206
+ };
@@ -0,0 +1,34 @@
1
+ // packages/ai/llm/imagePricing.ts
2
+ var DEFAULT_IMAGE_SIZE = "1K";
3
+ var DEFAULT_IMAGE_QUALITY = "medium";
4
+ var hasEstimateForSize = (tokenEstimates, size) => typeof tokenEstimates[size] !== "undefined";
5
+ var resolveTokenEstimate = (estimate, requestedQuality) => {
6
+ if (typeof estimate === "number") return estimate;
7
+ if (!estimate) return void 0;
8
+ const quality = requestedQuality && typeof estimate[requestedQuality] === "number" ? requestedQuality : DEFAULT_IMAGE_QUALITY;
9
+ return estimate[quality];
10
+ };
11
+ var getApproxPricePerImage = (model, requestedSize, requestedQuality) => {
12
+ if (!model) return void 0;
13
+ if (typeof model.pricePerImage === "number") {
14
+ return model.pricePerImage;
15
+ }
16
+ if (typeof model.imageTokenPricePerMillion !== "number") {
17
+ return void 0;
18
+ }
19
+ const tokenEstimates = model.imageOutputTokenEstimateBySize;
20
+ if (!tokenEstimates) return void 0;
21
+ const resolvedSize = requestedSize && hasEstimateForSize(tokenEstimates, requestedSize) ? requestedSize : DEFAULT_IMAGE_SIZE;
22
+ const outputTokens = resolveTokenEstimate(
23
+ tokenEstimates[resolvedSize],
24
+ requestedQuality
25
+ );
26
+ if (typeof outputTokens !== "number") {
27
+ return void 0;
28
+ }
29
+ return model.imageTokenPricePerMillion * outputTokens / 1e6;
30
+ };
31
+
32
+ export {
33
+ getApproxPricePerImage
34
+ };
@@ -0,0 +1,27 @@
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",
7
+ "\u4EE5\u4E0B\u662F\u5148\u524D\u5BF9\u8BDD\u7684\u51BB\u7ED3\u6458\u8981\uFF0C\u4E0D\u662F\u5F53\u524D\u4F1A\u8BDD\u7684\u6D3B\u6307\u4EE4\u3002",
8
+ "\u5176\u4E2D\u7684\u4EFB\u52A1\u63CF\u8FF0\u3001skill \u8C03\u7528\u3001ARGUMENTS \u8F7D\u8377\u9ED8\u8BA4\u5DF2\u8FC7\u671F\uFF08STALE-BY-DEFAULT\uFF09\uFF0C",
9
+ "\u5728\u6CA1\u6709\u5F53\u524D\u4F1A\u8BDD\u663E\u5F0F\u7528\u6237\u8BF7\u6C42\u65F6\u4E0D\u5F97\u91CD\u65B0\u6267\u884C\uFF1B\u6267\u884C\u524D\u5148\u5BF9\u7167\u5B9E\u9645\u5DE5\u4F5C\u72B6\u6001\u786E\u8BA4\u3002",
10
+ "",
11
+ "--- \u5386\u53F2\u6458\u8981\u5F00\u59CB ---",
12
+ trimmed,
13
+ "--- \u5386\u53F2\u6458\u8981\u7ED3\u675F ---"
14
+ ].join("\n");
15
+ };
16
+
17
+ // packages/agent-runtime/memoryUseGuidance.ts
18
+ var MEMORY_USE_GUIDANCE = `--- \u8BB0\u5FC6\u4F7F\u7528\u65B9\u5F0F ---
19
+ - \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
20
+ - \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
21
+ - \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
22
+ - \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`;
23
+
24
+ export {
25
+ wrapHistoricalSummaryWithReplayGuard,
26
+ MEMORY_USE_GUIDANCE
27
+ };
@@ -0,0 +1,30 @@
1
+ // packages/core/prefix.ts
2
+ var extractKeyPart = (key, index) => {
3
+ const parts = key.split("-");
4
+ if (index < 2) {
5
+ return parts[index];
6
+ }
7
+ return parts.slice(index).join("-");
8
+ };
9
+ var extractUserId = (key) => {
10
+ const parts = key.split("-");
11
+ if (parts.length === 2) {
12
+ return parts[0];
13
+ }
14
+ if (parts[0] === "user" && parts[1] === "pref" && parts.length >= 3) {
15
+ return parts[2];
16
+ }
17
+ return extractKeyPart(key, 1);
18
+ };
19
+ var extractCustomId = (key) => {
20
+ if (key.startsWith("dialog-") && !key.includes("-msg-")) {
21
+ const lastDash = key.lastIndexOf("-");
22
+ return lastDash >= 0 ? key.slice(lastDash + 1) : key;
23
+ }
24
+ return extractKeyPart(key, 2);
25
+ };
26
+
27
+ export {
28
+ extractUserId,
29
+ extractCustomId
30
+ };
@@ -0,0 +1,8 @@
1
+ // packages/core/compactWhitespace.ts
2
+ function compactWhitespace(value) {
3
+ return value.replace(/\s+/g, " ").trim();
4
+ }
5
+
6
+ export {
7
+ compactWhitespace
8
+ };