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,373 +0,0 @@
1
- // 文件路径: ai/agent/buildEditingContext.ts
2
-
3
- import type { RootState } from "app/store";
4
- import type { AgentRuntimeOptions } from "./types";
5
- import { selectCurrentTable, selectTableRows } from "render/table/tableSlice";
6
- import { selectDoc } from "render/page/docSlice";
7
-
8
- type AppConstraintPack = {
9
- id: string;
10
- title: string;
11
- rules: string[];
12
- };
13
-
14
- const buildAppConstraintPacks = (args: {
15
- framework: string;
16
- fileNames: string[];
17
- externalImports: string[];
18
- }): AppConstraintPack[] => {
19
- const imports = new Set(args.externalImports);
20
- const fileSet = new Set(args.fileNames);
21
- const packs: AppConstraintPack[] = [
22
- {
23
- id: "repair-loop",
24
- title: "预检与定点修复",
25
- rules: [
26
- "每次改完代码后,先调用 appPreflight,只有预检通过后再调用 appDeploy。",
27
- "如果 preflight / deploy 失败,优先根据返回的 issues 做定点修复,然后重新 preflight;不要无关重写整页应用。",
28
- "如果工具结果里带有 repairPlan,默认立即执行 repairPlan 中的局部修复步骤,不要先停下来问用户。",
29
- "如果工具结果明确说明是 HTML / 非 JSON 响应、transport failure 或 retryable=false,停止自动 deploy 重试;这说明当前是平台通道异常,不是代码问题。",
30
- ],
31
- },
32
- {
33
- id: "design-system",
34
- title: "设计系统与小改动约束",
35
- rules: [
36
- "先检查当前应用是否已经有 theme / tokens / designSystem / 共享样式常量;如果已有,优先沿用这套设计系统,不要平行再造一套。",
37
- "如果当前应用还没有设计系统,而用户需求涉及 UI / 样式 / 新页面,优先补一层最小共享 token(colors、typography、spacing、radius、shadow),再让组件消费这些 token。",
38
- "如果当前应用是旧写法:视觉值散落在多个组件的硬编码 style / 常量里,而本次需求只是调字体、颜色、间距、圆角、阴影,默认执行一次最小 token 迁移,再在 token 层完成调整;不要继续把新数字散落写回多个位置。",
39
- "当用户只是想调字体大小、字重、颜色、圆角、阴影、间距等视觉参数时,优先修改 token 或命中的局部组件,不要顺手重写整个页面结构。",
40
- "除非用户明确要求整体改版或重做风格,否则不要连带修改布局、组件树、文案、数据流、路由或未命中的页面。",
41
- "如果只是小改一处,尽量把变更收敛在少数文件,并保持未命中文件的结构与命名稳定。",
42
- ],
43
- },
44
- ];
45
-
46
- if (args.framework === "react-spa" || fileSet.has("main.tsx") || fileSet.has("App.tsx")) {
47
- packs.push({
48
- id: "react-spa-core",
49
- title: "React SPA 形态保持",
50
- rules: [
51
- '继续沿用 framework: "react-spa" + files,不要退回单文件 Worker。',
52
- "保留稳定入口结构,优先维护 main.tsx + App.tsx,再局部修改组件文件。",
53
- ],
54
- });
55
- }
56
-
57
- if (imports.has("react-icons/lu")) {
58
- packs.push({
59
- id: "react-icons-lu",
60
- title: "Lucide 图标安全规则",
61
- rules: [
62
- "只能使用 react-icons/lu 中真实存在的图标名,不要猜测变体名。",
63
- "如果不确定图标名,优先使用 LuCircle、LuCheck、LuX、LuInfo、LuArrowRight 这类基础图标。",
64
- ],
65
- });
66
- }
67
-
68
- if (imports.has("leaflet") || imports.has("react-leaflet")) {
69
- packs.push({
70
- id: "leaflet",
71
- title: "Leaflet 地图约束",
72
- rules: [
73
- "不要手动 import leaflet.css;平台会自动注入 Leaflet 样式。",
74
- "修改地图时优先保留现有坐标、缩放和图层结构,只做必要的交互或视觉调整。",
75
- ],
76
- });
77
- }
78
-
79
- if (imports.has("@xyflow/react")) {
80
- packs.push({
81
- id: "xyflow",
82
- title: "Flow 图编辑约束",
83
- rules: [
84
- "不要新增外部 CSS import;需要样式时直接补最小必要内联样式或组件内 style 标签。",
85
- "优先复用现有节点/边数据结构,避免重写整套 flow 画布。",
86
- ],
87
- });
88
- }
89
-
90
- if (imports.has("echarts") || imports.has("echarts-for-react")) {
91
- packs.push({
92
- id: "echarts",
93
- title: "图表改动约束",
94
- rules: [
95
- "优先局部修改 option 配置、数据映射和组件 props,不要重写整个图表页面。",
96
- "响应式布局优先靠容器尺寸和现有组件结构调整,不要额外引入 CSS 文件。",
97
- ],
98
- });
99
- }
100
-
101
- if (imports.has("docx") || imports.has("xlsx")) {
102
- packs.push({
103
- id: "file-processing",
104
- title: "文档/表格处理约束",
105
- rules: [
106
- "不要把大型数据或模板内容直接内嵌进代码常量;优先保留运行时加载方式。",
107
- "修改导入导出逻辑时,优先沿用现有文件处理链路和数据结构。",
108
- ],
109
- });
110
- }
111
-
112
- return packs;
113
- };
114
-
115
- const formatAppConstraintPacks = (packs: AppConstraintPack[]): string[] => {
116
- if (packs.length === 0) return [];
117
-
118
- return [
119
- "",
120
- "当前激活约束包(按当前应用依赖/形态动态注入):",
121
- ...packs.flatMap((pack) => [
122
- `- ${pack.title}(${pack.id})`,
123
- ...pack.rules.map((rule) => ` - ${rule}`),
124
- ]),
125
- ];
126
- };
127
-
128
- /**
129
- * 根据当前 Redux 状态 + 本次调用的 runtimeOptions,生成「当前编辑对象」的自然语言描述。
130
- *
131
- * 设计目标:
132
- * - 只返回一段 string 或 null,不关心 Prompt 结构。
133
- * - 不涉及任何持久化(DialogConfig / AgentConfig),完全是运行时。
134
- * - 目前重点支持:
135
- * - kind === "table": 当前表格 + 部分行数据
136
- * - kind === "page" | "article": 当前页面/文章的标题(正文后面可以再丰富)
137
- */
138
- export const buildEditingContextSummary = (
139
- state: RootState,
140
- runtimeOptions?: AgentRuntimeOptions
141
- ): string | null => {
142
- const targetKind = runtimeOptions?.editingTarget?.kind;
143
-
144
- // 1) 表格场景:基于当前表 meta + 行数据
145
- if (targetKind === "table") {
146
- const table = selectCurrentTable(state);
147
- const rows = selectTableRows(state);
148
- const metadata = runtimeOptions?.editingTarget?.metadata;
149
- const focusContext =
150
- metadata && typeof metadata === "object" ? metadata.focusContext : null;
151
-
152
-
153
- if (!table) return null;
154
-
155
-
156
- const columns = Array.isArray(table.columns) ? table.columns : [];
157
-
158
-
159
- const columnSummaries = columns.length
160
- ? columns.map((c) => {
161
- const displayName = c.label || c.name;
162
- const type = c.type || "text";
163
- const requiredFlag = c.required ? "必填" : "可选";
164
- const primaryFlag = c.isPrimary ? ",主字段" : "";
165
- const optionsStr =
166
- Array.isArray(c.options) && c.options.length
167
- ? `,可选值:${c.options.join(" | ")}`
168
- : "";
169
- const descStr = c.description ? `。说明:${c.description}` : "";
170
-
171
-
172
- return `- ${c.name}(显示名:${displayName},类型:${type},${requiredFlag}${primaryFlag}${optionsStr}${descStr})`;
173
- })
174
- : ["- (当前表尚未定义字段)"];
175
-
176
-
177
- // 只给出前 20 行作为结构示例,避免 prompt 过长
178
- const sampleRows = Array.isArray(rows) ? rows.slice(0, 20) : [];
179
- const rowsPreview = sampleRows.length
180
- ? JSON.stringify(sampleRows, null, 2)
181
- : "(当前表暂无行数据)";
182
-
183
-
184
- const tableTitle = table.displayName ?? table.tableId ?? "(未命名表)";
185
- const tableDesc = table.description
186
- ? `用途说明:${table.description}`
187
- : "(暂无用途说明)";
188
-
189
-
190
- // ✅ 新增:如果有表级 tags,把它们也告诉 Agent
191
- const tableTagsLine =
192
- Array.isArray(table.tags) && table.tags.length
193
- ? `- 关键词标签: ${table.tags.join(", ")}`
194
- : null;
195
-
196
-
197
- return [
198
- "当前编辑目标:一张数据表(Editing Table)。",
199
- `- 表 ID: ${table.tableId}`,
200
- `- 显示名称: ${tableTitle}`,
201
- `- ${tableDesc}`,
202
- ...(tableTagsLine ? [tableTagsLine] : []),
203
- ...(focusContext &&
204
- typeof focusContext === "object" &&
205
- "columnName" in focusContext
206
- ? [
207
- "",
208
- "当前焦点(Focus Context):",
209
- `- 当前单元格列: ${String((focusContext as any).columnName ?? "(未知列)")}`,
210
- ...((focusContext as any).rowTitle
211
- ? [`- 当前行标题: ${String((focusContext as any).rowTitle)}`]
212
- : []),
213
- ...((focusContext as any).rowIndex !== null &&
214
- (focusContext as any).rowIndex !== undefined
215
- ? [`- 当前行号: ${Number((focusContext as any).rowIndex) + 1}`]
216
- : []),
217
- ...((focusContext as any).cellPreview
218
- ? [`- 当前单元格内容预览: ${String((focusContext as any).cellPreview)}`]
219
- : []),
220
- ]
221
- : []),
222
- "",
223
- "字段定义(Field Schema):",
224
- ...columnSummaries,
225
- "",
226
- "【给 AI 的操作指南 / 非用户原话】",
227
- "当用户希望在当前表中“新增一行 / 新增记录 / 插入一条 / 帮我记一条 xxx”时:",
228
- "1. 必须调用工具 addTableRow(而不是只在回答中口头描述要新增的数据)。",
229
- "2. 调用 addTableRow 时:",
230
- " - 使用参数 values(一个对象),其中每个 key 必须是上面字段名之一(name,而不是 label)。",
231
- ' - 例如:{"values":{"title":"修 Bug #123","status":"todo","note":"高优先级"}}。',
232
- " - 尽量从用户的自然语言中推断并填满所有相关字段;对于必填字段(required=true)尤其要注意。",
233
- ' - 用户没有提到的字段,可以使用空字符串 "" 或 null 作为占位。',
234
- " - 绝不要传入空对象 {} 作为 values。",
235
- "",
236
- "以下是部分示例行(最多 20 行,用于帮助你理解列含义,请避免在回答中完整粘贴整表):",
237
- rowsPreview,
238
- ].join("\n");
239
- }
240
-
241
-
242
-
243
-
244
- // 2) 页面 / 文章场景:先只提供标题信息(正文后面可以在这里丰富)
245
- if (targetKind === "page" || targetKind === "article") {
246
- const page = selectDoc(state);
247
- const metadata = runtimeOptions?.editingTarget?.metadata;
248
- const focusContext =
249
- metadata && typeof metadata === "object" ? metadata.focusContext : null;
250
- if (!page) return null;
251
-
252
- const title = page.title ?? "(未命名页面)";
253
-
254
- return [
255
- "当前编辑目标:一个页面 / 文章(Editing Document)。",
256
- `- 标题: ${title}`,
257
- ...(focusContext &&
258
- typeof focusContext === "object" &&
259
- "anchorPath" in focusContext
260
- ? [
261
- "",
262
- "当前焦点(Focus Context):",
263
- `- 光标是否折叠: ${Boolean((focusContext as any).isCollapsed) ? "是" : "否"}`,
264
- ...((focusContext as any).blockType
265
- ? [`- 当前块类型: ${String((focusContext as any).blockType)}`]
266
- : []),
267
- ...((focusContext as any).selectedText
268
- ? [`- 当前选中文本: ${String((focusContext as any).selectedText)}`]
269
- : []),
270
- ...((focusContext as any).anchorPath?.length
271
- ? [`- 当前锚点路径: ${(focusContext as any).anchorPath.join(" > ")}`]
272
- : []),
273
- ]
274
- : []),
275
- "",
276
- "如果用户要求你对这篇文章进行修改或优化,请在回答中明确指出修改方向。",
277
- "如果存在当前选区或光标上下文,优先围绕该局部位置做定点改写,而不是泛泛重写整篇文档。",
278
- ].join("\n");
279
- }
280
-
281
- if (targetKind === "app") {
282
- const editingTarget = runtimeOptions?.editingTarget;
283
- const metadata = editingTarget?.metadata;
284
- const appId = editingTarget?.key ?? "(未知 appId)";
285
- const title = editingTarget?.title ?? "(未命名应用)";
286
- const framework =
287
- typeof metadata?.framework === "string"
288
- ? metadata.framework
289
- : "worker";
290
- const appUrl =
291
- typeof metadata?.appUrl === "string" ? metadata.appUrl : null;
292
- const fileNames = Array.isArray(metadata?.fileNames)
293
- ? metadata.fileNames.filter((name): name is string => typeof name === "string")
294
- : [];
295
- const externalImports = Array.isArray(metadata?.externalImports)
296
- ? metadata.externalImports.filter(
297
- (name): name is string => typeof name === "string"
298
- )
299
- : [];
300
- const sourceSummary =
301
- typeof editingTarget?.summary === "string" && editingTarget.summary.trim()
302
- ? editingTarget.summary.trim()
303
- : null;
304
- const constraintPacks = buildAppConstraintPacks({
305
- framework,
306
- fileNames,
307
- externalImports,
308
- });
309
-
310
- return [
311
- "当前编辑目标:一个 Web 应用(Editing App)。",
312
- `- 应用 ID: ${appId}`,
313
- `- 名称: ${title}`,
314
- `- 技术形态: ${framework}`,
315
- ...(appUrl ? [`- 当前访问地址: ${appUrl}`] : []),
316
- ...(fileNames.length
317
- ? [`- 当前源码文件: ${fileNames.join(", ")}`]
318
- : ["- 当前源码文件: (未提供多文件清单;可能是单文件源码,也可能只剩部署产物)"]),
319
- ...(externalImports.length
320
- ? [`- 当前依赖白名单命中: ${externalImports.join(", ")}`]
321
- : []),
322
- ...(sourceSummary ? ["", sourceSummary] : []),
323
- "",
324
- "【给 AI 的操作指南 / 非用户原话】",
325
- "1. 用户要求修改当前应用时,先调用 appRead 获取当前代码/文件,再基于现有实现修改。",
326
- "2. 先识别当前应用是否已有 theme / tokens / design system;已有就优先改这层,没有再补一层最小共享 token,再基于 token 调整组件。",
327
- "3. 如果当前应用还是旧写法:视觉值散落在组件硬编码 style 里,而用户只是做字体/颜色/间距等视觉微调,默认先把命中的视觉值抽到最小 token 层,再完成本次修改;除非用户明确要求不要重构。",
328
- `4. 重新部署当前应用时,appDeploy 必须继续传同一个 appId(${appId}),避免创建新应用。`,
329
- framework === "react-spa"
330
- ? '5. 当前应用是 React SPA,修改时继续沿用 framework: "react-spa" + files,不要退回单文件 Worker。'
331
- : "5. 当前应用目前是 Worker 形态;如果需求变成复杂交互或图表,可以评估升级为 React SPA。",
332
- ...(fileNames.length
333
- ? []
334
- : [
335
- "6. 当前没有源码文件清单时,必须先用 appRead 判断读到的是可维护源码还是部署产物 / 打包 bundle。",
336
- "7. 如果 appRead 返回的是 HTML 壳、importmap、压缩 bundle 或明显不是原始源码文件,禁止在未告知用户风险的情况下整站重写;应先说明“当前缺少原始源码快照,继续修改更像整体重建”,等用户确认后再继续。",
337
- ]),
338
- "8. 如果用户只是要调字体大小、配色、圆角、阴影、留白等视觉细节,默认优先改设计 token 或命中的局部组件;对旧写法应用则优先做最小 token 迁移,不要只改散落硬编码。",
339
- "9. 每次修改完成后,先 appPreflight,再 appDeploy;如果失败,按返回 issues 定点修复。",
340
- "10. 回复用户时优先说明做了什么变化、现在应用可以怎么用,而不是直接堆代码。",
341
- ...formatAppConstraintPacks(constraintPacks),
342
- ].join("\n");
343
- }
344
-
345
- if (targetKind === "image" || targetKind === "file") {
346
- const editingTarget = runtimeOptions?.editingTarget;
347
- const metadata = editingTarget?.metadata;
348
- const title = editingTarget?.title ?? "(未命名对象)";
349
- const objectKey = editingTarget?.key ?? "(未知 key)";
350
- const fileId =
351
- typeof metadata?.fileId === "string" ? metadata.fileId : null;
352
- const url = typeof metadata?.url === "string" ? metadata.url : null;
353
- const size =
354
- typeof metadata?.size === "number" ? metadata.size : null;
355
-
356
- return [
357
- `当前编辑目标:一个${targetKind === "image" ? "图片" : "文件"}对象(Editing ${targetKind === "image" ? "Image" : "File"})。`,
358
- `- 对象 key: ${objectKey}`,
359
- `- 标题: ${title}`,
360
- ...(fileId ? [`- fileId: ${fileId}`] : []),
361
- ...(url ? [`- 资源地址: ${url}`] : []),
362
- ...(size !== null ? [`- 文件大小: ${size} bytes`] : []),
363
- "",
364
- "【给 AI 的操作指南 / 非用户原话】",
365
- targetKind === "image"
366
- ? "当前阶段优先帮助用户理解图片内容、提炼重点、命名归类和下一步处理建议。不要假装已经完成复杂图片编辑。"
367
- : "当前阶段优先帮助用户理解文件用途、提取处理思路、给出整理建议和下一步操作建议。不要假装已经完整解析文件内容。",
368
- ].join("\n");
369
- }
370
-
371
- // 其它 kind 以后按需扩展
372
- return null;
373
- };