nolo-cli 0.1.10 → 0.1.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 (240) hide show
  1. package/README.md +0 -32
  2. package/agentRuntimeCommands.ts +3 -3
  3. package/commandRegistry.ts +2 -2
  4. package/machineCommands.ts +31 -6
  5. package/package.json +6 -22
  6. package/ai/agent/_executeModel.ts +0 -118
  7. package/ai/agent/agentSlice.ts +0 -525
  8. package/ai/agent/appWorkingMemory.ts +0 -126
  9. package/ai/agent/avatarUtils.ts +0 -24
  10. package/ai/agent/buildEditingContext.ts +0 -373
  11. package/ai/agent/buildSystemPrompt.ts +0 -532
  12. package/ai/agent/cleanAgentMessages.ts +0 -140
  13. package/ai/agent/cliChatClient.ts +0 -119
  14. package/ai/agent/cliExecutor.ts +0 -733
  15. package/ai/agent/cliPrompt.ts +0 -10
  16. package/ai/agent/contextCompiler.ts +0 -107
  17. package/ai/agent/contextLayerContract.ts +0 -44
  18. package/ai/agent/createAgentSchema.ts +0 -234
  19. package/ai/agent/executeToolCall.ts +0 -58
  20. package/ai/agent/fetchAgentContexts.ts +0 -42
  21. package/ai/agent/generatePrompt.ts +0 -3
  22. package/ai/agent/getFullChatContextKeys.ts +0 -168
  23. package/ai/agent/hooks/fetchPublicAgents.ts +0 -133
  24. package/ai/agent/hooks/useAgentConfig.ts +0 -61
  25. package/ai/agent/hooks/useAgentDialog.ts +0 -35
  26. package/ai/agent/hooks/useAgentFormValidation.ts +0 -202
  27. package/ai/agent/hooks/usePublicAgents.ts +0 -473
  28. package/ai/agent/machineRunPermissions.ts +0 -95
  29. package/ai/agent/persistMessageWithFixedId.ts +0 -37
  30. package/ai/agent/planSlice.ts +0 -259
  31. package/ai/agent/referenceUtils.ts +0 -229
  32. package/ai/agent/runAgentBackground.ts +0 -238
  33. package/ai/agent/runAgentClientLoop.ts +0 -138
  34. package/ai/agent/runtimeGuidance.ts +0 -97
  35. package/ai/agent/runtimeServerBase.ts +0 -37
  36. package/ai/agent/server/fetchPublicAgents.ts +0 -128
  37. package/ai/agent/startParallelAgentStreams.ts +0 -424
  38. package/ai/agent/startupProtocol.ts +0 -53
  39. package/ai/agent/streamAgentChatTurn.ts +0 -1278
  40. package/ai/agent/streamAgentChatTurnUtils.ts +0 -738
  41. package/ai/agent/types.ts +0 -71
  42. package/ai/agent/utils/imageOutput.ts +0 -33
  43. package/ai/agent/utils/sortUtils.ts +0 -250
  44. package/ai/agent/web/referencePickerUtils.ts +0 -146
  45. package/ai/ai.locale.ts +0 -1079
  46. package/ai/chat/accumulateToolCallChunks.ts +0 -95
  47. package/ai/chat/fetchUtils.native.ts +0 -276
  48. package/ai/chat/fetchUtils.ts +0 -153
  49. package/ai/chat/parseApiError.ts +0 -64
  50. package/ai/chat/parseMultilineSSE.ts +0 -95
  51. package/ai/chat/sendOpenAICompletionsRequest.native.ts +0 -682
  52. package/ai/chat/sendOpenAICompletionsRequest.ts +0 -703
  53. package/ai/chat/sendOpenAIResponseRequest.ts +0 -491
  54. package/ai/chat/shouldUseServerProxy.ts +0 -18
  55. package/ai/chat/sseClient.native.ts +0 -91
  56. package/ai/chat/sseClient.ts +0 -67
  57. package/ai/chat/streamReader.native.ts +0 -31
  58. package/ai/chat/streamReader.ts +0 -62
  59. package/ai/chat/updateTotalUsage.ts +0 -72
  60. package/ai/context/buildReferenceContext.ts +0 -437
  61. package/ai/context/calculateContextUsage.ts +0 -133
  62. package/ai/context/retention.ts +0 -165
  63. package/ai/context/tokenUtils.ts +0 -78
  64. package/ai/index.ts +0 -1
  65. package/ai/llm/calculateGeminiImageTokens.ts +0 -57
  66. package/ai/llm/deepinfra.ts +0 -28
  67. package/ai/llm/fireworks.ts +0 -50
  68. package/ai/llm/generateRequestBody.ts +0 -165
  69. package/ai/llm/getModelContextWindow.ts +0 -84
  70. package/ai/llm/getNoloKey.ts +0 -31
  71. package/ai/llm/getPricing.ts +0 -199
  72. package/ai/llm/hooks/useModelPricing.ts +0 -75
  73. package/ai/llm/imagePricing.ts +0 -40
  74. package/ai/llm/isResponseAPIModel.ts +0 -13
  75. package/ai/llm/mimo.ts +0 -71
  76. package/ai/llm/mistral.ts +0 -22
  77. package/ai/llm/modelAvatar.ts +0 -427
  78. package/ai/llm/models.ts +0 -45
  79. package/ai/llm/openrouterModels.ts +0 -269
  80. package/ai/llm/providers.ts +0 -306
  81. package/ai/llm/reasoningModels.ts +0 -28
  82. package/ai/llm/types.ts +0 -59
  83. package/ai/llm/usageRequestOptions.ts +0 -59
  84. package/ai/memory/capture.ts +0 -148
  85. package/ai/memory/consolidate.ts +0 -104
  86. package/ai/memory/delete.ts +0 -147
  87. package/ai/memory/overlay.ts +0 -84
  88. package/ai/memory/query.ts +0 -38
  89. package/ai/memory/queryShared.ts +0 -160
  90. package/ai/memory/rank.ts +0 -105
  91. package/ai/memory/recentRelationshipRecap.ts +0 -249
  92. package/ai/memory/remember.ts +0 -167
  93. package/ai/memory/runtime.ts +0 -76
  94. package/ai/memory/store.ts +0 -20
  95. package/ai/memory/storeShared.ts +0 -76
  96. package/ai/memory/types.ts +0 -46
  97. package/ai/memory/understanding.ts +0 -349
  98. package/ai/memory/understandingGreeting.ts +0 -264
  99. package/ai/messages/type.ts +0 -20
  100. package/ai/policy/personalizationDialog.ts +0 -333
  101. package/ai/policy/runtimePolicy.ts +0 -440
  102. package/ai/policy/selfUpdateFields.ts +0 -48
  103. package/ai/policy/types.ts +0 -64
  104. package/ai/skills/referenceRuntime.ts +0 -274
  105. package/ai/skills/skillDiagnostics.ts +0 -251
  106. package/ai/skills/skillDocBuilder.ts +0 -139
  107. package/ai/skills/skillDocProtocol.ts +0 -434
  108. package/ai/skills/skillReferenceSummary.ts +0 -63
  109. package/ai/skills/skillSummaryMarker.ts +0 -26
  110. package/ai/token/calculatePrice.ts +0 -544
  111. package/ai/token/db.ts +0 -98
  112. package/ai/token/externalToolCost.ts +0 -330
  113. package/ai/token/hooks/useRecords.ts +0 -65
  114. package/ai/token/missingUsageEstimate.ts +0 -42
  115. package/ai/token/modelUsageQuery.ts +0 -252
  116. package/ai/token/normalizeUsage.ts +0 -84
  117. package/ai/token/openaiImageGenerationUsage.ts +0 -56
  118. package/ai/token/prepareTokenUsageData.ts +0 -88
  119. package/ai/token/query.ts +0 -88
  120. package/ai/token/queryUserTokens.ts +0 -59
  121. package/ai/token/resolveBillingTarget.ts +0 -52
  122. package/ai/token/saveTokenRecord.ts +0 -53
  123. package/ai/token/serverDialogProjection.ts +0 -78
  124. package/ai/token/serverTokenWriter.ts +0 -143
  125. package/ai/token/stats.ts +0 -21
  126. package/ai/token/tokenThunks.ts +0 -24
  127. package/ai/token/types.ts +0 -93
  128. package/ai/tools/agent/agentTools.ts +0 -176
  129. package/ai/tools/agent/agentUpdateShared.ts +0 -311
  130. package/ai/tools/agent/callAgentTool.ts +0 -139
  131. package/ai/tools/agent/createAgentTool.ts +0 -512
  132. package/ai/tools/agent/createDialogTool.ts +0 -69
  133. package/ai/tools/agent/createSkillAgentTool.ts +0 -62
  134. package/ai/tools/agent/parallelBudget.ts +0 -221
  135. package/ai/tools/agent/presets/appBuilderPreset.ts +0 -145
  136. package/ai/tools/agent/runLlmTool.ts +0 -96
  137. package/ai/tools/agent/runStreamingAgentTool.ts +0 -73
  138. package/ai/tools/agent/skillAgentArgs.ts +0 -106
  139. package/ai/tools/agent/skillAgentPreset.ts +0 -89
  140. package/ai/tools/agent/streamParallelAgentsTool.ts +0 -122
  141. package/ai/tools/agent/updateAgentTool.ts +0 -96
  142. package/ai/tools/agent/updateSelfTool.ts +0 -113
  143. package/ai/tools/amazonProductScraperTool.ts +0 -86
  144. package/ai/tools/apifyActorClient.ts +0 -45
  145. package/ai/tools/appEditGuard.ts +0 -372
  146. package/ai/tools/appReadSnapshot.ts +0 -153
  147. package/ai/tools/appTools.ts +0 -1549
  148. package/ai/tools/applyEditTool.ts +0 -256
  149. package/ai/tools/applyLineEditsTool.ts +0 -312
  150. package/ai/tools/browserTools/click.ts +0 -33
  151. package/ai/tools/browserTools/closeSession.ts +0 -29
  152. package/ai/tools/browserTools/common.ts +0 -27
  153. package/ai/tools/browserTools/openSession.ts +0 -48
  154. package/ai/tools/browserTools/readContent.ts +0 -38
  155. package/ai/tools/browserTools/selectOption.ts +0 -46
  156. package/ai/tools/browserTools/typeText.ts +0 -42
  157. package/ai/tools/category/createCategoryTool.ts +0 -66
  158. package/ai/tools/category/queryContentsByCategoryTool.ts +0 -69
  159. package/ai/tools/category/updateContentCategoryTool.ts +0 -75
  160. package/ai/tools/cfBrowserTools.ts +0 -319
  161. package/ai/tools/cfSpeechToTextTool.ts +0 -49
  162. package/ai/tools/checkEnvTool.ts +0 -65
  163. package/ai/tools/cloudflareCrawlTool.ts +0 -289
  164. package/ai/tools/codeSearchTool.ts +0 -111
  165. package/ai/tools/codeTools.ts +0 -101
  166. package/ai/tools/createDocTool.ts +0 -132
  167. package/ai/tools/createPlanTool.ts +0 -999
  168. package/ai/tools/createSkillDocTool.ts +0 -155
  169. package/ai/tools/createWorkflowTool.ts +0 -154
  170. package/ai/tools/deepseekOcrTool.ts +0 -34
  171. package/ai/tools/delayTool.ts +0 -31
  172. package/ai/tools/deleteSpacesTool.ts +0 -325
  173. package/ai/tools/deleteSpacesToolModel.ts +0 -159
  174. package/ai/tools/devReloadUtils.ts +0 -29
  175. package/ai/tools/dialogMessageSearch.ts +0 -137
  176. package/ai/tools/doctorSkillTool.ts +0 -72
  177. package/ai/tools/ecommerceScraperTool.ts +0 -86
  178. package/ai/tools/emailTools.ts +0 -549
  179. package/ai/tools/evalSkillTool.ts +0 -92
  180. package/ai/tools/exaSearchTool.ts +0 -64
  181. package/ai/tools/execBashTool.ts +0 -379
  182. package/ai/tools/executeSqlTool.ts +0 -192
  183. package/ai/tools/fetchWebpageSupport.ts +0 -309
  184. package/ai/tools/fetchWebpageTool.ts +0 -84
  185. package/ai/tools/geminiImagePreviewTool.ts +0 -361
  186. package/ai/tools/generateDocxTool.ts +0 -215
  187. package/ai/tools/googleSearchScraperTool.ts +0 -106
  188. package/ai/tools/importDataTool.ts +0 -133
  189. package/ai/tools/importSkillTool.ts +0 -162
  190. package/ai/tools/index.ts +0 -1858
  191. package/ai/tools/listFilesTool.ts +0 -82
  192. package/ai/tools/listUserSpacesTool.ts +0 -113
  193. package/ai/tools/modelUsageTools.ts +0 -142
  194. package/ai/tools/olmOcrTool.ts +0 -34
  195. package/ai/tools/openaiImageTool.ts +0 -218
  196. package/ai/tools/paddleOcrTool.ts +0 -34
  197. package/ai/tools/prepareTools.ts +0 -23
  198. package/ai/tools/readDocTool.ts +0 -84
  199. package/ai/tools/readFileTool.ts +0 -211
  200. package/ai/tools/readTool.ts +0 -163
  201. package/ai/tools/readXPostTool.ts +0 -233
  202. package/ai/tools/rememberMemoryTool.ts +0 -84
  203. package/ai/tools/remotionVideoTool.ts +0 -151
  204. package/ai/tools/searchDialogMessagesTool.ts +0 -222
  205. package/ai/tools/searchRepoTool.ts +0 -115
  206. package/ai/tools/searchWorkspaceTool.ts +0 -259
  207. package/ai/tools/skillFollowup.ts +0 -86
  208. package/ai/tools/surfWeatherTool.ts +0 -169
  209. package/ai/tools/table/addTableRowTool.ts +0 -217
  210. package/ai/tools/table/createTableTool.ts +0 -315
  211. package/ai/tools/table/rowTools.ts +0 -366
  212. package/ai/tools/table/schemaTools.ts +0 -244
  213. package/ai/tools/table/shareTableTool.ts +0 -148
  214. package/ai/tools/table/toolShared.ts +0 -129
  215. package/ai/tools/toolApiClient.ts +0 -198
  216. package/ai/tools/toolNameAliases.ts +0 -57
  217. package/ai/tools/toolResultError.ts +0 -42
  218. package/ai/tools/toolRunSlice.ts +0 -303
  219. package/ai/tools/toolSchemaCompatibility.ts +0 -53
  220. package/ai/tools/toolVisibility.ts +0 -4
  221. package/ai/tools/types.ts +0 -20
  222. package/ai/tools/uiAskChoiceTool.ts +0 -104
  223. package/ai/tools/updateContentTitleTool.ts +0 -84
  224. package/ai/tools/updateDocTool.ts +0 -105
  225. package/ai/tools/updateUserPreferenceProfileTool.ts +0 -145
  226. package/ai/tools/whisperTool.ts +0 -77
  227. package/ai/tools/writeFileTool.ts +0 -210
  228. package/ai/tools/youtubeScraperTool.ts +0 -116
  229. package/ai/tools/ziweiChartTool.ts +0 -678
  230. package/ai/types.ts +0 -55
  231. package/ai/workflow/workflowExecutor.ts +0 -323
  232. package/ai/workflow/workflowSlice.ts +0 -73
  233. package/ai/workflow/workflowTypes.ts +0 -106
  234. package/client/compactDialog.ts +0 -222
  235. package/connector-experimental/capabilities.ts +0 -73
  236. package/connector-experimental/codexBinary.ts +0 -41
  237. package/connector-experimental/heartbeatLoop.ts +0 -22
  238. package/connector-experimental/index.ts +0 -5
  239. package/connector-experimental/machineInfo.ts +0 -46
  240. package/connector-experimental/protocol.ts +0 -54
@@ -1,440 +0,0 @@
1
- import type { Agent } from "app/types";
2
- import type {
3
- AgentBasePolicy,
4
- DialogPolicyState,
5
- KnowledgeCaptureLevel,
6
- SelfEvolutionMode,
7
- SpaceContextLevel,
8
- TonePreset,
9
- ToneResolutionMode,
10
- UserPreferenceProfile,
11
- } from "./types";
12
- import {
13
- DEFAULT_AGENT_BASE_POLICY,
14
- DEFAULT_USER_PREFERENCE_PROFILE,
15
- } from "./types";
16
-
17
- export type CaptureIntent = "none" | "possible" | "strong";
18
- export type SpaceNeed = "none" | "light" | "deep";
19
- export type KnowledgeCaptureMode = "blocked" | "ask" | "suggest" | "auto";
20
-
21
- export interface ResolvedRuntimePolicy {
22
- tonePreset: TonePreset;
23
- toneResolutionMode: ToneResolutionMode;
24
- knowledgeCapture: {
25
- level: KnowledgeCaptureLevel;
26
- mode: KnowledgeCaptureMode;
27
- explicitRequest: boolean;
28
- maxAutoCreatesPerDialog: number;
29
- currentAutoCreates: number;
30
- captureIntent: CaptureIntent;
31
- };
32
- spaceContext: {
33
- level: SpaceContextLevel;
34
- explicitRequest: boolean;
35
- need: SpaceNeed;
36
- maxReadCallsPerTurn: number;
37
- maxReadCallsPerDialog: number;
38
- currentAutoReads: number;
39
- preloadSummaryCount: number;
40
- preloadBudgetRatio: number;
41
- };
42
- selfEvolutionMode: SelfEvolutionMode;
43
- }
44
-
45
- const clampLevel = <T extends 1 | 2 | 3 | 4>(
46
- value: unknown,
47
- fallback: T,
48
- ): T => {
49
- const n = Number(value);
50
- if (n === 1 || n === 2 || n === 3 || n === 4) {
51
- return n as T;
52
- }
53
- return fallback;
54
- };
55
-
56
- const normalizeTonePreset = (value: unknown, fallback: TonePreset): TonePreset => {
57
- switch (value) {
58
- case "professional":
59
- case "friendly":
60
- case "direct":
61
- case "pragmatic":
62
- case "default":
63
- return value;
64
- default:
65
- return fallback;
66
- }
67
- };
68
-
69
- const normalizeToneResolutionMode = (
70
- value: unknown,
71
- fallback: ToneResolutionMode,
72
- ): ToneResolutionMode => {
73
- switch (value) {
74
- case "agent_first":
75
- case "user_first":
76
- case "blend":
77
- return value;
78
- default:
79
- return fallback;
80
- }
81
- };
82
-
83
- const normalizeSelfEvolutionMode = (
84
- value: unknown,
85
- fallback: SelfEvolutionMode,
86
- ): SelfEvolutionMode => {
87
- switch (value) {
88
- case "none":
89
- case "knowledge_only":
90
- case "prompt_and_refs":
91
- case "full":
92
- return value;
93
- default:
94
- return fallback;
95
- }
96
- };
97
-
98
- export const resolveAgentBasePolicy = (agentConfig?: Agent | any): AgentBasePolicy => {
99
- const raw = agentConfig?.basePolicy ?? {};
100
-
101
- return {
102
- version: 1,
103
- tone: {
104
- preset: normalizeTonePreset(
105
- raw?.tone?.preset,
106
- DEFAULT_AGENT_BASE_POLICY.tone?.preset ?? "default",
107
- ),
108
- resolutionMode: normalizeToneResolutionMode(
109
- raw?.tone?.resolutionMode,
110
- DEFAULT_AGENT_BASE_POLICY.tone?.resolutionMode ?? "blend",
111
- ),
112
- },
113
- knowledgeCaptureMaxLevel: clampLevel(
114
- raw?.knowledgeCaptureMaxLevel,
115
- DEFAULT_AGENT_BASE_POLICY.knowledgeCaptureMaxLevel,
116
- ),
117
- spaceContextMaxLevel: clampLevel(
118
- raw?.spaceContextMaxLevel,
119
- DEFAULT_AGENT_BASE_POLICY.spaceContextMaxLevel,
120
- ),
121
- selfEvolutionMode: normalizeSelfEvolutionMode(
122
- raw?.selfEvolutionMode,
123
- DEFAULT_AGENT_BASE_POLICY.selfEvolutionMode,
124
- ),
125
- };
126
- };
127
-
128
- export const resolveUserPreferenceProfile = (
129
- settingsRecord?: Record<string, any> | null,
130
- ): UserPreferenceProfile => {
131
- const fallbackSpaceLevel =
132
- settingsRecord?.enableReadCurrentSpace === false
133
- ? 1
134
- : DEFAULT_USER_PREFERENCE_PROFILE.spaceContextLevel;
135
-
136
- return {
137
- version: 1,
138
- tone: {
139
- preset: normalizeTonePreset(
140
- settingsRecord?.userTonePreset,
141
- DEFAULT_USER_PREFERENCE_PROFILE.tone?.preset ?? "default",
142
- ),
143
- },
144
- knowledgeCaptureLevel: clampLevel(
145
- settingsRecord?.knowledgeCaptureLevel,
146
- DEFAULT_USER_PREFERENCE_PROFILE.knowledgeCaptureLevel,
147
- ),
148
- spaceContextLevel: clampLevel(
149
- settingsRecord?.spaceContextLevel,
150
- fallbackSpaceLevel,
151
- ),
152
- };
153
- };
154
-
155
- const containsAny = (text: string, patterns: string[]): boolean =>
156
- patterns.some((pattern) => text.includes(pattern));
157
-
158
- export const inferCaptureIntent = (userInput: string): CaptureIntent => {
159
- const normalized = userInput.toLowerCase();
160
-
161
- if (
162
- containsAny(normalized, [
163
- "保存",
164
- "存一下",
165
- "沉淀",
166
- "记住",
167
- "写入文档",
168
- "建文档",
169
- "创建文档",
170
- "导入 skill",
171
- "导入这个 skill",
172
- "确认导入",
173
- "确认导入这个 skill",
174
- "导入这个技能",
175
- "确认导入这个技能",
176
- "创建 skill",
177
- "创建这个 skill",
178
- "skill 文档",
179
- "创建表格",
180
- "建表",
181
- "建个表",
182
- "做个表",
183
- "做一张表",
184
- "整理成表",
185
- "整理成一张表",
186
- "建立一个表",
187
- "建立一张表",
188
- "建立成表",
189
- "建立成一张表",
190
- "创建这个表格",
191
- "确认创建",
192
- "确认创建这张表格",
193
- "create doc",
194
- "import skill",
195
- "confirm import",
196
- "create skill",
197
- "create table",
198
- "save this",
199
- "remember this",
200
- "document this",
201
- ])
202
- ) {
203
- return "strong";
204
- }
205
-
206
- if (
207
- containsAny(normalized, [
208
- "总结",
209
- "方案",
210
- "调研",
211
- "规范",
212
- "会议纪要",
213
- "总结一下",
214
- "research",
215
- "proposal",
216
- "spec",
217
- "summary",
218
- ])
219
- ) {
220
- return "possible";
221
- }
222
-
223
- return "none";
224
- };
225
-
226
- export const inferSpaceNeed = (userInput: string): SpaceNeed => {
227
- const normalized = userInput.toLowerCase();
228
-
229
- if (
230
- containsAny(normalized, [
231
- "当前空间",
232
- "这个空间",
233
- "这些文档",
234
- "根据空间",
235
- "workspace",
236
- "current space",
237
- "these docs",
238
- "based on the docs",
239
- ])
240
- ) {
241
- return "deep";
242
- }
243
-
244
- if (
245
- containsAny(normalized, [
246
- "文档",
247
- "文件",
248
- "页面",
249
- "目录",
250
- "page",
251
- "pages",
252
- "docs",
253
- "files",
254
- "目录结构",
255
- ])
256
- ) {
257
- return "light";
258
- }
259
-
260
- return "none";
261
- };
262
-
263
- const resolveTonePreset = (
264
- agentTone: TonePreset,
265
- userTone: TonePreset,
266
- mode: ToneResolutionMode,
267
- ): TonePreset => {
268
- if (mode === "agent_first") {
269
- return agentTone === "default" ? userTone : agentTone;
270
- }
271
- if (mode === "user_first") {
272
- return userTone === "default" ? agentTone : userTone;
273
- }
274
- if (userTone !== "default") return userTone;
275
- return agentTone;
276
- };
277
-
278
- const maxReadCallsPerTurnByLevel = (
279
- level: SpaceContextLevel,
280
- need: SpaceNeed,
281
- ): number => {
282
- if (need === "deep") {
283
- return { 1: 2, 2: 3, 3: 4, 4: 6 }[level];
284
- }
285
- if (need === "light") {
286
- return { 1: 1, 2: 2, 3: 3, 4: 4 }[level];
287
- }
288
- return { 1: 0, 2: 0, 3: 1, 4: 2 }[level];
289
- };
290
-
291
- const maxReadCallsPerDialogByLevel = (
292
- level: SpaceContextLevel,
293
- need: SpaceNeed,
294
- ): number => {
295
- if (need === "deep") {
296
- return { 1: 3, 2: 4, 3: 6, 4: 8 }[level];
297
- }
298
- if (need === "light") {
299
- return { 1: 2, 2: 3, 3: 4, 4: 6 }[level];
300
- }
301
- return { 1: 0, 2: 0, 3: 2, 4: 4 }[level];
302
- };
303
-
304
- const preloadSummaryCountByLevel = (level: SpaceContextLevel): number =>
305
- ({ 1: 0, 2: 0, 3: 8, 4: 16 }[level]);
306
-
307
- const preloadBudgetRatioByLevel = (level: SpaceContextLevel): number =>
308
- ({ 1: 0, 2: 0.01, 3: 0.04, 4: 0.08 }[level]);
309
-
310
- export const resolveRuntimePolicy = (params: {
311
- agentConfig?: Agent | any;
312
- settingsRecord?: Record<string, any> | null;
313
- userInput: string;
314
- dialogPolicyState?: DialogPolicyState | null;
315
- }): ResolvedRuntimePolicy => {
316
- const { agentConfig, settingsRecord, userInput, dialogPolicyState } = params;
317
-
318
- const agentBasePolicy = resolveAgentBasePolicy(agentConfig);
319
- const userPreferenceProfile = resolveUserPreferenceProfile(settingsRecord);
320
-
321
- const knowledgeLevel = Math.min(
322
- agentBasePolicy.knowledgeCaptureMaxLevel,
323
- userPreferenceProfile.knowledgeCaptureLevel,
324
- ) as KnowledgeCaptureLevel;
325
- const spaceLevel = Math.min(
326
- agentBasePolicy.spaceContextMaxLevel,
327
- userPreferenceProfile.spaceContextLevel,
328
- ) as SpaceContextLevel;
329
-
330
- const captureIntent = inferCaptureIntent(userInput);
331
- const spaceNeed = inferSpaceNeed(userInput);
332
- const explicitCaptureRequest = captureIntent === "strong";
333
- const explicitSpaceRequest = spaceNeed !== "none";
334
-
335
- const currentAutoCreates = Math.max(
336
- 0,
337
- Number(dialogPolicyState?.autoKnowledgeCaptureCount ?? 0),
338
- );
339
- const currentAutoReads = Math.max(
340
- 0,
341
- Number(dialogPolicyState?.autoSpaceReadCount ?? 0),
342
- );
343
-
344
- let knowledgeMode: KnowledgeCaptureMode = "blocked";
345
- if (explicitCaptureRequest) {
346
- knowledgeMode = "auto";
347
- } else if (knowledgeLevel === 2) {
348
- knowledgeMode = "ask";
349
- } else if (knowledgeLevel === 3) {
350
- knowledgeMode = "suggest";
351
- } else if (knowledgeLevel >= 4 && captureIntent !== "none") {
352
- knowledgeMode = "auto";
353
- }
354
-
355
- return {
356
- tonePreset: resolveTonePreset(
357
- agentBasePolicy.tone?.preset ?? "default",
358
- userPreferenceProfile.tone?.preset ?? "default",
359
- agentBasePolicy.tone?.resolutionMode ?? "blend",
360
- ),
361
- toneResolutionMode: agentBasePolicy.tone?.resolutionMode ?? "blend",
362
- knowledgeCapture: {
363
- level: knowledgeLevel,
364
- mode: knowledgeMode,
365
- explicitRequest: explicitCaptureRequest,
366
- maxAutoCreatesPerDialog: explicitCaptureRequest ? 99 : 1,
367
- currentAutoCreates,
368
- captureIntent,
369
- },
370
- spaceContext: {
371
- level: spaceLevel,
372
- explicitRequest: explicitSpaceRequest,
373
- need: spaceNeed,
374
- maxReadCallsPerTurn: maxReadCallsPerTurnByLevel(spaceLevel, spaceNeed),
375
- maxReadCallsPerDialog: maxReadCallsPerDialogByLevel(spaceLevel, spaceNeed),
376
- currentAutoReads,
377
- preloadSummaryCount: preloadSummaryCountByLevel(spaceLevel),
378
- preloadBudgetRatio: preloadBudgetRatioByLevel(spaceLevel),
379
- },
380
- selfEvolutionMode: agentBasePolicy.selfEvolutionMode,
381
- };
382
- };
383
-
384
- export const buildUserPolicyContext = (
385
- policy: ResolvedRuntimePolicy,
386
- ): string => {
387
- const lines = [
388
- `用户语气偏好:${policy.tonePreset}`,
389
- `知识沉淀级别:${policy.knowledgeCapture.level}(当前模式:${policy.knowledgeCapture.mode})`,
390
- `空间上下文级别:${policy.spaceContext.level}(本轮最多自动 read ${policy.spaceContext.maxReadCallsPerTurn} 次)`,
391
- "如果工具返回 policy limit,不要重试同一路径,应改为解释限制、先给答案或向用户确认。",
392
- ];
393
-
394
- if (policy.knowledgeCapture.mode === "ask") {
395
- lines.push("当前用户偏好要求:创建知识文档前先询问用户。");
396
- } else if (policy.knowledgeCapture.mode === "suggest") {
397
- lines.push("当前用户偏好要求:先完成回答,再建议是否沉淀成文档/表格。");
398
- }
399
-
400
- return lines.join("\n");
401
- };
402
-
403
- export const buildStaticUserPolicyContext = (params: {
404
- agentConfig?: Agent | any;
405
- settingsRecord?: Record<string, any> | null;
406
- }): string => {
407
- const agentBasePolicy = resolveAgentBasePolicy(params.agentConfig);
408
- const userPreferenceProfile = resolveUserPreferenceProfile(params.settingsRecord);
409
- const tonePreset = resolveTonePreset(
410
- agentBasePolicy.tone?.preset ?? "default",
411
- userPreferenceProfile.tone?.preset ?? "default",
412
- agentBasePolicy.tone?.resolutionMode ?? "blend",
413
- );
414
-
415
- return [
416
- `用户语气偏好:${tonePreset}`,
417
- `知识沉淀级别:${Math.min(agentBasePolicy.knowledgeCaptureMaxLevel, userPreferenceProfile.knowledgeCaptureLevel)}`,
418
- `空间上下文级别:${Math.min(agentBasePolicy.spaceContextMaxLevel, userPreferenceProfile.spaceContextLevel)}`,
419
- "请尽量保留 agent 自身角色设定,同时按用户偏好调整表达和自动化程度。",
420
- ].join("\n");
421
- };
422
-
423
- export const resolveSpaceContextPreloadPlan = (level: SpaceContextLevel) => ({
424
- preloadSummaryCount: preloadSummaryCountByLevel(level),
425
- preloadBudgetRatio: preloadBudgetRatioByLevel(level),
426
- includeRecentContent: level >= 3,
427
- });
428
-
429
- export const isBudgetedWorkspaceReadKey = (dbKey: string): boolean => {
430
- const normalized = dbKey.toLowerCase();
431
- return (
432
- normalized.startsWith("page-") ||
433
- normalized.startsWith("dialog-") ||
434
- normalized.startsWith("space-") ||
435
- normalized.startsWith("table-") ||
436
- normalized.startsWith("table_row-") ||
437
- normalized.startsWith("row-") ||
438
- normalized.startsWith("meta-")
439
- );
440
- };
@@ -1,48 +0,0 @@
1
- export const AGENT_UPDATE_FIELD_NAMES = [
2
- "name",
3
- "model",
4
- "provider",
5
- "prompt",
6
- "introduction",
7
- "greeting",
8
- "isPublic",
9
- "tags",
10
- "tools",
11
- "references",
12
- "temperature",
13
- "top_p",
14
- "frequency_penalty",
15
- "presence_penalty",
16
- "max_tokens",
17
- "reasoning_effort",
18
- ] as const;
19
-
20
- export type AgentUpdateField = (typeof AGENT_UPDATE_FIELD_NAMES)[number];
21
-
22
- export const DEFAULT_AUTO_APPROVED_SELF_UPDATE_FIELDS: AgentUpdateField[] = [
23
- "greeting",
24
- "introduction",
25
- "tags",
26
- ];
27
-
28
- const VALID_AGENT_UPDATE_FIELDS = new Set<string>(AGENT_UPDATE_FIELD_NAMES);
29
-
30
- export const normalizeAgentUpdateFieldList = (
31
- value: unknown,
32
- fallback: readonly AgentUpdateField[] = DEFAULT_AUTO_APPROVED_SELF_UPDATE_FIELDS,
33
- ): AgentUpdateField[] => {
34
- if (!Array.isArray(value)) {
35
- return [...fallback];
36
- }
37
-
38
- const normalized = Array.from(
39
- new Set(
40
- value.filter(
41
- (item): item is AgentUpdateField =>
42
- typeof item === "string" && VALID_AGENT_UPDATE_FIELDS.has(item),
43
- ),
44
- ),
45
- );
46
-
47
- return normalized;
48
- };
@@ -1,64 +0,0 @@
1
- export type TonePreset =
2
- | "default"
3
- | "professional"
4
- | "friendly"
5
- | "direct"
6
- | "pragmatic";
7
-
8
- export type ToneResolutionMode = "agent_first" | "user_first" | "blend";
9
-
10
- export type KnowledgeCaptureLevel = 1 | 2 | 3 | 4;
11
- export type SpaceContextLevel = 1 | 2 | 3 | 4;
12
-
13
- export type SelfEvolutionMode =
14
- | "none"
15
- | "knowledge_only"
16
- | "prompt_and_refs"
17
- | "full";
18
-
19
- export interface AgentBasePolicy {
20
- version: 1;
21
- tone?: {
22
- preset?: TonePreset;
23
- resolutionMode?: ToneResolutionMode;
24
- };
25
- knowledgeCaptureMaxLevel: KnowledgeCaptureLevel;
26
- spaceContextMaxLevel: SpaceContextLevel;
27
- selfEvolutionMode: SelfEvolutionMode;
28
- }
29
-
30
- export interface UserPreferenceProfile {
31
- version: 1;
32
- tone?: {
33
- preset?: TonePreset;
34
- };
35
- knowledgeCaptureLevel: KnowledgeCaptureLevel;
36
- spaceContextLevel: SpaceContextLevel;
37
- }
38
-
39
- export interface DialogPolicyState {
40
- autoKnowledgeCaptureCount?: number;
41
- autoSpaceReadCount?: number;
42
- updatedAt?: number;
43
- }
44
-
45
- export const DEFAULT_AGENT_BASE_POLICY: AgentBasePolicy = {
46
- version: 1,
47
- tone: {
48
- preset: "default",
49
- resolutionMode: "blend",
50
- },
51
- knowledgeCaptureMaxLevel: 4,
52
- spaceContextMaxLevel: 4,
53
- selfEvolutionMode: "knowledge_only",
54
- };
55
-
56
- export const DEFAULT_USER_PREFERENCE_PROFILE: UserPreferenceProfile = {
57
- version: 1,
58
- tone: {
59
- preset: "default",
60
- },
61
- knowledgeCaptureLevel: 2,
62
- spaceContextLevel: 3,
63
- };
64
-