nolo-cli 0.1.9 → 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.
- package/README.md +0 -32
- package/agentRuntimeCommands.ts +3 -3
- package/commandRegistry.ts +2 -2
- package/machineCommands.ts +31 -6
- package/package.json +6 -8
- package/ai/agent/_executeModel.ts +0 -118
- package/ai/agent/agentSlice.ts +0 -525
- package/ai/agent/appWorkingMemory.ts +0 -126
- package/ai/agent/avatarUtils.ts +0 -24
- package/ai/agent/buildEditingContext.ts +0 -373
- package/ai/agent/buildSystemPrompt.ts +0 -532
- package/ai/agent/cleanAgentMessages.ts +0 -140
- package/ai/agent/cliChatClient.ts +0 -119
- package/ai/agent/cliExecutor.ts +0 -733
- package/ai/agent/cliPrompt.ts +0 -10
- package/ai/agent/contextCompiler.ts +0 -107
- package/ai/agent/contextLayerContract.ts +0 -44
- package/ai/agent/createAgentSchema.ts +0 -234
- package/ai/agent/executeToolCall.ts +0 -58
- package/ai/agent/fetchAgentContexts.ts +0 -42
- package/ai/agent/generatePrompt.ts +0 -3
- package/ai/agent/getFullChatContextKeys.ts +0 -168
- package/ai/agent/hooks/fetchPublicAgents.ts +0 -133
- package/ai/agent/hooks/useAgentConfig.ts +0 -61
- package/ai/agent/hooks/useAgentDialog.ts +0 -35
- package/ai/agent/hooks/useAgentFormValidation.ts +0 -202
- package/ai/agent/hooks/usePublicAgents.ts +0 -473
- package/ai/agent/machineRunPermissions.ts +0 -95
- package/ai/agent/persistMessageWithFixedId.ts +0 -37
- package/ai/agent/planSlice.ts +0 -259
- package/ai/agent/referenceUtils.ts +0 -229
- package/ai/agent/runAgentBackground.ts +0 -238
- package/ai/agent/runAgentClientLoop.ts +0 -138
- package/ai/agent/runtimeGuidance.ts +0 -97
- package/ai/agent/runtimeServerBase.ts +0 -37
- package/ai/agent/server/fetchPublicAgents.ts +0 -128
- package/ai/agent/startParallelAgentStreams.ts +0 -424
- package/ai/agent/startupProtocol.ts +0 -53
- package/ai/agent/streamAgentChatTurn.ts +0 -1278
- package/ai/agent/streamAgentChatTurnUtils.ts +0 -738
- package/ai/agent/types.ts +0 -71
- package/ai/agent/utils/imageOutput.ts +0 -33
- package/ai/agent/utils/sortUtils.ts +0 -250
- package/ai/agent/web/referencePickerUtils.ts +0 -146
- package/ai/ai.locale.ts +0 -1075
- package/ai/chat/accumulateToolCallChunks.ts +0 -95
- package/ai/chat/fetchUtils.native.ts +0 -276
- package/ai/chat/fetchUtils.ts +0 -153
- package/ai/chat/parseApiError.ts +0 -64
- package/ai/chat/parseMultilineSSE.ts +0 -95
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +0 -682
- package/ai/chat/sendOpenAICompletionsRequest.ts +0 -703
- package/ai/chat/sendOpenAIResponseRequest.ts +0 -491
- package/ai/chat/shouldUseServerProxy.ts +0 -18
- package/ai/chat/sseClient.native.ts +0 -91
- package/ai/chat/sseClient.ts +0 -67
- package/ai/chat/streamReader.native.ts +0 -31
- package/ai/chat/streamReader.ts +0 -62
- package/ai/chat/updateTotalUsage.ts +0 -72
- package/ai/context/buildReferenceContext.ts +0 -437
- package/ai/context/calculateContextUsage.ts +0 -133
- package/ai/context/retention.ts +0 -165
- package/ai/context/tokenUtils.ts +0 -78
- package/ai/index.ts +0 -1
- package/ai/llm/calculateGeminiImageTokens.ts +0 -57
- package/ai/llm/deepinfra.ts +0 -28
- package/ai/llm/fireworks.ts +0 -50
- package/ai/llm/generateRequestBody.ts +0 -165
- package/ai/llm/getModelContextWindow.ts +0 -84
- package/ai/llm/getNoloKey.ts +0 -31
- package/ai/llm/getPricing.ts +0 -199
- package/ai/llm/hooks/useModelPricing.ts +0 -75
- package/ai/llm/imagePricing.ts +0 -40
- package/ai/llm/isResponseAPIModel.ts +0 -13
- package/ai/llm/mimo.ts +0 -71
- package/ai/llm/mistral.ts +0 -22
- package/ai/llm/modelAvatar.ts +0 -427
- package/ai/llm/models.ts +0 -45
- package/ai/llm/openrouterModels.ts +0 -269
- package/ai/llm/providers.ts +0 -306
- package/ai/llm/reasoningModels.ts +0 -28
- package/ai/llm/types.ts +0 -59
- package/ai/llm/usageRequestOptions.ts +0 -59
- package/ai/memory/capture.ts +0 -148
- package/ai/memory/consolidate.ts +0 -104
- package/ai/memory/delete.ts +0 -147
- package/ai/memory/overlay.ts +0 -84
- package/ai/memory/query.ts +0 -38
- package/ai/memory/queryShared.ts +0 -160
- package/ai/memory/rank.ts +0 -105
- package/ai/memory/recentRelationshipRecap.ts +0 -249
- package/ai/memory/remember.ts +0 -167
- package/ai/memory/runtime.ts +0 -76
- package/ai/memory/store.ts +0 -20
- package/ai/memory/storeShared.ts +0 -76
- package/ai/memory/types.ts +0 -46
- package/ai/memory/understanding.ts +0 -349
- package/ai/memory/understandingGreeting.ts +0 -264
- package/ai/messages/type.ts +0 -20
- package/ai/policy/personalizationDialog.ts +0 -333
- package/ai/policy/runtimePolicy.ts +0 -440
- package/ai/policy/selfUpdateFields.ts +0 -48
- package/ai/policy/types.ts +0 -64
- package/ai/skills/referenceRuntime.ts +0 -274
- package/ai/skills/skillDiagnostics.ts +0 -251
- package/ai/skills/skillDocBuilder.ts +0 -139
- package/ai/skills/skillDocProtocol.ts +0 -434
- package/ai/skills/skillReferenceSummary.ts +0 -63
- package/ai/skills/skillSummaryMarker.ts +0 -26
- package/ai/token/calculatePrice.ts +0 -544
- package/ai/token/db.ts +0 -98
- package/ai/token/externalToolCost.ts +0 -330
- package/ai/token/hooks/useRecords.ts +0 -65
- package/ai/token/missingUsageEstimate.ts +0 -42
- package/ai/token/modelUsageQuery.ts +0 -252
- package/ai/token/normalizeUsage.ts +0 -84
- package/ai/token/openaiImageGenerationUsage.ts +0 -56
- package/ai/token/prepareTokenUsageData.ts +0 -88
- package/ai/token/query.ts +0 -88
- package/ai/token/queryUserTokens.ts +0 -59
- package/ai/token/resolveBillingTarget.ts +0 -52
- package/ai/token/saveTokenRecord.ts +0 -53
- package/ai/token/serverDialogProjection.ts +0 -78
- package/ai/token/serverTokenWriter.ts +0 -143
- package/ai/token/stats.ts +0 -21
- package/ai/token/tokenThunks.ts +0 -24
- package/ai/token/types.ts +0 -93
- package/ai/tools/agent/agentTools.ts +0 -176
- package/ai/tools/agent/agentUpdateShared.ts +0 -311
- package/ai/tools/agent/callAgentTool.ts +0 -139
- package/ai/tools/agent/createAgentTool.ts +0 -512
- package/ai/tools/agent/createDialogTool.ts +0 -69
- package/ai/tools/agent/createSkillAgentTool.ts +0 -62
- package/ai/tools/agent/parallelBudget.ts +0 -221
- package/ai/tools/agent/presets/appBuilderPreset.ts +0 -145
- package/ai/tools/agent/runLlmTool.ts +0 -96
- package/ai/tools/agent/runStreamingAgentTool.ts +0 -73
- package/ai/tools/agent/skillAgentArgs.ts +0 -106
- package/ai/tools/agent/skillAgentPreset.ts +0 -89
- package/ai/tools/agent/streamParallelAgentsTool.ts +0 -122
- package/ai/tools/agent/updateAgentTool.ts +0 -96
- package/ai/tools/agent/updateSelfTool.ts +0 -113
- package/ai/tools/amazonProductScraperTool.ts +0 -86
- package/ai/tools/apifyActorClient.ts +0 -45
- package/ai/tools/appEditGuard.ts +0 -372
- package/ai/tools/appReadSnapshot.ts +0 -153
- package/ai/tools/appTools.ts +0 -1549
- package/ai/tools/applyEditTool.ts +0 -256
- package/ai/tools/applyLineEditsTool.ts +0 -312
- package/ai/tools/browserTools/click.ts +0 -33
- package/ai/tools/browserTools/closeSession.ts +0 -29
- package/ai/tools/browserTools/common.ts +0 -27
- package/ai/tools/browserTools/openSession.ts +0 -48
- package/ai/tools/browserTools/readContent.ts +0 -38
- package/ai/tools/browserTools/selectOption.ts +0 -46
- package/ai/tools/browserTools/typeText.ts +0 -42
- package/ai/tools/category/createCategoryTool.ts +0 -66
- package/ai/tools/category/queryContentsByCategoryTool.ts +0 -69
- package/ai/tools/category/updateContentCategoryTool.ts +0 -75
- package/ai/tools/cfBrowserTools.ts +0 -319
- package/ai/tools/cfSpeechToTextTool.ts +0 -49
- package/ai/tools/checkEnvTool.ts +0 -65
- package/ai/tools/cloudflareCrawlTool.ts +0 -289
- package/ai/tools/codeSearchTool.ts +0 -111
- package/ai/tools/codeTools.ts +0 -101
- package/ai/tools/createDocTool.ts +0 -132
- package/ai/tools/createPlanTool.ts +0 -999
- package/ai/tools/createSkillDocTool.ts +0 -155
- package/ai/tools/createWorkflowTool.ts +0 -154
- package/ai/tools/deepseekOcrTool.ts +0 -34
- package/ai/tools/delayTool.ts +0 -31
- package/ai/tools/deleteSpacesTool.ts +0 -325
- package/ai/tools/deleteSpacesToolModel.ts +0 -159
- package/ai/tools/devReloadUtils.ts +0 -29
- package/ai/tools/dialogMessageSearch.ts +0 -137
- package/ai/tools/doctorSkillTool.ts +0 -72
- package/ai/tools/ecommerceScraperTool.ts +0 -86
- package/ai/tools/emailTools.ts +0 -549
- package/ai/tools/evalSkillTool.ts +0 -92
- package/ai/tools/exaSearchTool.ts +0 -64
- package/ai/tools/execBashTool.ts +0 -379
- package/ai/tools/executeSqlTool.ts +0 -192
- package/ai/tools/fetchWebpageSupport.ts +0 -309
- package/ai/tools/fetchWebpageTool.ts +0 -84
- package/ai/tools/geminiImagePreviewTool.ts +0 -361
- package/ai/tools/generateDocxTool.ts +0 -215
- package/ai/tools/googleSearchScraperTool.ts +0 -106
- package/ai/tools/importDataTool.ts +0 -133
- package/ai/tools/importSkillTool.ts +0 -162
- package/ai/tools/index.ts +0 -1858
- package/ai/tools/listFilesTool.ts +0 -82
- package/ai/tools/listUserSpacesTool.ts +0 -113
- package/ai/tools/modelUsageTools.ts +0 -142
- package/ai/tools/olmOcrTool.ts +0 -34
- package/ai/tools/openaiImageTool.ts +0 -218
- package/ai/tools/paddleOcrTool.ts +0 -34
- package/ai/tools/prepareTools.ts +0 -23
- package/ai/tools/readDocTool.ts +0 -84
- package/ai/tools/readFileTool.ts +0 -211
- package/ai/tools/readTool.ts +0 -163
- package/ai/tools/readXPostTool.ts +0 -233
- package/ai/tools/rememberMemoryTool.ts +0 -84
- package/ai/tools/remotionVideoTool.ts +0 -151
- package/ai/tools/searchDialogMessagesTool.ts +0 -222
- package/ai/tools/searchRepoTool.ts +0 -115
- package/ai/tools/searchWorkspaceTool.ts +0 -259
- package/ai/tools/skillFollowup.ts +0 -86
- package/ai/tools/surfWeatherTool.ts +0 -169
- package/ai/tools/table/addTableRowTool.ts +0 -217
- package/ai/tools/table/createTableTool.ts +0 -315
- package/ai/tools/table/rowTools.ts +0 -366
- package/ai/tools/table/schemaTools.ts +0 -244
- package/ai/tools/table/shareTableTool.ts +0 -148
- package/ai/tools/table/toolShared.ts +0 -129
- package/ai/tools/toolApiClient.ts +0 -198
- package/ai/tools/toolNameAliases.ts +0 -57
- package/ai/tools/toolResultError.ts +0 -42
- package/ai/tools/toolRunSlice.ts +0 -303
- package/ai/tools/toolSchemaCompatibility.ts +0 -53
- package/ai/tools/toolVisibility.ts +0 -4
- package/ai/tools/types.ts +0 -20
- package/ai/tools/uiAskChoiceTool.ts +0 -104
- package/ai/tools/updateContentTitleTool.ts +0 -84
- package/ai/tools/updateDocTool.ts +0 -105
- package/ai/tools/updateUserPreferenceProfileTool.ts +0 -145
- package/ai/tools/whisperTool.ts +0 -77
- package/ai/tools/writeFileTool.ts +0 -210
- package/ai/tools/youtubeScraperTool.ts +0 -116
- package/ai/tools/ziweiChartTool.ts +0 -678
- package/ai/types.ts +0 -55
- package/ai/workflow/workflowExecutor.ts +0 -323
- package/ai/workflow/workflowSlice.ts +0 -73
- package/ai/workflow/workflowTypes.ts +0 -106
- package/client/compactDialog.ts +0 -222
- package/connector-experimental/capabilities.ts +0 -73
- package/connector-experimental/codexBinary.ts +0 -41
- package/connector-experimental/heartbeatLoop.ts +0 -22
- package/connector-experimental/index.ts +0 -5
- package/connector-experimental/machineInfo.ts +0 -46
- package/connector-experimental/protocol.ts +0 -54
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
// 文件: ai/tools/table/addTableRowTool.ts
|
|
2
|
-
|
|
3
|
-
import type { RootState } from "app/store";
|
|
4
|
-
import { addRow } from "render/table/tableSlice";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* [Schema] addTableRow:在当前已打开的表中新增一行数据
|
|
8
|
-
*
|
|
9
|
-
* 设计要点:
|
|
10
|
-
* - 默认情况下,从当前 Redux 状态里的 tableSlice.currentTable 推断 tenantId / tableId
|
|
11
|
-
* - LLM 主要只需要关心 values(列名 -> 值)
|
|
12
|
-
* - 如果没有当前表,又没显式传 tenantId / tableId,则报错
|
|
13
|
-
*/
|
|
14
|
-
export const addTableRowFunctionSchema = {
|
|
15
|
-
name: "addTableRow",
|
|
16
|
-
description:
|
|
17
|
-
[
|
|
18
|
-
"在指定表中新增一行数据。",
|
|
19
|
-
"【重要】如果你是在对话(chat)中调用此函数(而非在表格页面的「页面助手」中),",
|
|
20
|
-
"则必须显式传入 tenantId 和 tableId。这两个值可从 createTable 的返回结果中获取。",
|
|
21
|
-
"如果你刚刚调用了 createTable,请务必将其返回的 tenantId 和 tableId 传入此函数。",
|
|
22
|
-
"只有在表格页面打开「页面助手」时,tenantId 和 tableId 才可以省略(会自动推断)。",
|
|
23
|
-
"【重要】表格字段必须放在 values 对象里,不要把 content、status 这类列名直接放在顶层。",
|
|
24
|
-
'完整示例:{"tenantId":"u1","tableId":"t1","values":{"content":"希望支持支付宝支付","status":"待处理"}}。',
|
|
25
|
-
].join("\n"),
|
|
26
|
-
parameters: {
|
|
27
|
-
type: "object",
|
|
28
|
-
properties: {
|
|
29
|
-
values: {
|
|
30
|
-
type: "object",
|
|
31
|
-
description:
|
|
32
|
-
[
|
|
33
|
-
"要写入新行的数据。key 必须是目标表已有的列名,多余字段会被忽略。",
|
|
34
|
-
'请根据用户的自然语言描述,为每个相关字段填上合理的值,而不是传入空对象 {}。',
|
|
35
|
-
'字段必须包在 values 中。示例:{"values": {"name": "张三", "desc": "测试任务", "date": "2025-01-01"}}。',
|
|
36
|
-
].join("\n"),
|
|
37
|
-
additionalProperties: {
|
|
38
|
-
description:
|
|
39
|
-
"单个字段的值;可以是字符串、数字、布尔值、null、对象或数组。",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
tenantId: {
|
|
43
|
-
type: "string",
|
|
44
|
-
description:
|
|
45
|
-
"租户 ID。在对话(chat)中调用时必须显式传入,从 createTable 的返回结果获取。",
|
|
46
|
-
},
|
|
47
|
-
tableId: {
|
|
48
|
-
type: "string",
|
|
49
|
-
description:
|
|
50
|
-
"表 ID。在对话(chat)中调用时必须显式传入,从 createTable 的返回结果获取。",
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
required: ["values"],
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type AddTableRowArgs = {
|
|
58
|
-
values?: Record<string, any>;
|
|
59
|
-
tenantId?: string;
|
|
60
|
-
tableId?: string;
|
|
61
|
-
} & Record<string, any>;
|
|
62
|
-
|
|
63
|
-
type AddTableRowResult = {
|
|
64
|
-
rawData: any;
|
|
65
|
-
displayData: string;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const toPreviewJson = (value: unknown, maxLength = 400): string => {
|
|
69
|
-
try {
|
|
70
|
-
const json = JSON.stringify(value, null, 2);
|
|
71
|
-
if (json.length <= maxLength) return json;
|
|
72
|
-
return `${json.slice(0, maxLength)}\n…(已截断)…`;
|
|
73
|
-
} catch {
|
|
74
|
-
return "[无法序列化为 JSON]";
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const RESERVED_ARG_KEYS = new Set(["tenantId", "tableId", "values"]);
|
|
79
|
-
|
|
80
|
-
const extractLegacyValues = (args: AddTableRowArgs | undefined): Record<string, any> => {
|
|
81
|
-
if (!args || typeof args !== "object" || Array.isArray(args)) {
|
|
82
|
-
return {};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return Object.fromEntries(
|
|
86
|
-
Object.entries(args).filter(
|
|
87
|
-
([key, value]) => !RESERVED_ARG_KEYS.has(key) && value !== undefined
|
|
88
|
-
)
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* [Executor] 在当前表中新增一行
|
|
94
|
-
*
|
|
95
|
-
* - 优先从 args.tenantId / args.tableId 取值
|
|
96
|
-
* - 否则使用 state.table.currentTable 的 tenantId / tableId
|
|
97
|
-
* - 如果当前表元数据可用,会自动过滤掉不存在的列名,并在 displayData 提示
|
|
98
|
-
*/
|
|
99
|
-
export async function addTableRowFunc(
|
|
100
|
-
args: AddTableRowArgs,
|
|
101
|
-
thunkApi: any
|
|
102
|
-
): Promise<AddTableRowResult> {
|
|
103
|
-
const state = thunkApi.getState() as RootState;
|
|
104
|
-
const tableState = state.table as RootState["table"];
|
|
105
|
-
|
|
106
|
-
const currentTable = tableState.currentTable;
|
|
107
|
-
|
|
108
|
-
const tenantId = args?.tenantId ?? currentTable?.tenantId;
|
|
109
|
-
const tableId = args?.tableId ?? currentTable?.tableId;
|
|
110
|
-
const normalizedValues =
|
|
111
|
-
args?.values !== undefined ? args.values : extractLegacyValues(args);
|
|
112
|
-
const values = (normalizedValues ?? {}) as Record<string, any>;
|
|
113
|
-
|
|
114
|
-
if (!tenantId || !tableId) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
"addTableRow 只能在已打开某张表的页面中调用,或显式提供 tenantId 和 tableId。"
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!values || typeof values !== "object" || Array.isArray(values)) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
'addTableRow.values 必须是一个对象(列名到值的映射,例如 { "name": "张三", "desc": "测试任务" })。'
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// 兜底:禁止传空对象 {},要求至少提供一个字段
|
|
127
|
-
if (Object.keys(values).length === 0) {
|
|
128
|
-
const knownCols = currentTable
|
|
129
|
-
? currentTable.columns.map((c) => c.name).join(", ") || "(无列定义)"
|
|
130
|
-
: "(当前表字段未知)";
|
|
131
|
-
|
|
132
|
-
throw new Error(
|
|
133
|
-
`addTableRow.values 不能为空:你需要至少为一个字段提供值。\n` +
|
|
134
|
-
`请根据用户的输入,从以下字段中选择并填充值:${knownCols}`
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
let sanitizedValues: Record<string, any> = values;
|
|
139
|
-
let ignoredColumns: string[] = [];
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
currentTable &&
|
|
143
|
-
currentTable.tenantId === tenantId &&
|
|
144
|
-
currentTable.tableId === tableId
|
|
145
|
-
) {
|
|
146
|
-
const allowedColumns = new Set(currentTable.columns.map((c) => c.name));
|
|
147
|
-
|
|
148
|
-
sanitizedValues = {};
|
|
149
|
-
ignoredColumns = [];
|
|
150
|
-
|
|
151
|
-
for (const [key, val] of Object.entries(values)) {
|
|
152
|
-
if (allowedColumns.has(key)) {
|
|
153
|
-
sanitizedValues[key] = val;
|
|
154
|
-
} else {
|
|
155
|
-
ignoredColumns.push(key);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
Object.keys(sanitizedValues).length === 0 &&
|
|
161
|
-
Object.keys(values).length > 0
|
|
162
|
-
) {
|
|
163
|
-
const knownCols =
|
|
164
|
-
currentTable.columns.map((c) => c.name).join(", ") || "(无列定义)";
|
|
165
|
-
|
|
166
|
-
throw new Error(
|
|
167
|
-
`addTableRow 失败:提供的字段名都不在当前表中。\n` +
|
|
168
|
-
`已知字段: ${knownCols}\n` +
|
|
169
|
-
`请仅使用这些字段名作为 key。`
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
try {
|
|
175
|
-
const actionResult = await thunkApi.dispatch(
|
|
176
|
-
addRow({ tenantId, tableId, values: sanitizedValues })
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
if (!addRow.fulfilled.match(actionResult)) {
|
|
180
|
-
const msg =
|
|
181
|
-
(actionResult.payload as string) ||
|
|
182
|
-
actionResult.error?.message ||
|
|
183
|
-
"新增表行失败";
|
|
184
|
-
throw new Error(msg);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const createdRow = actionResult.payload as any;
|
|
188
|
-
|
|
189
|
-
const tableLabel =
|
|
190
|
-
currentTable?.displayName ||
|
|
191
|
-
currentTable?.tableId ||
|
|
192
|
-
tableId ||
|
|
193
|
-
"当前表";
|
|
194
|
-
|
|
195
|
-
const ignoredInfo =
|
|
196
|
-
ignoredColumns.length > 0
|
|
197
|
-
? `\n\n注意:以下字段在当前表中不存在,已被忽略:${ignoredColumns.join(
|
|
198
|
-
", "
|
|
199
|
-
)}`
|
|
200
|
-
: "";
|
|
201
|
-
|
|
202
|
-
return {
|
|
203
|
-
rawData: {
|
|
204
|
-
...createdRow,
|
|
205
|
-
values: sanitizedValues,
|
|
206
|
-
},
|
|
207
|
-
displayData:
|
|
208
|
-
`已在表「${tableLabel}」中新增一行数据。\n` +
|
|
209
|
-
`rowId: ${createdRow.rowId ?? "(无 rowId 字段)"}\n\n` +
|
|
210
|
-
`数据预览:\n${toPreviewJson(createdRow)}${ignoredInfo}`,
|
|
211
|
-
};
|
|
212
|
-
} catch (error: any) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
`addTableRow 调用失败:${error?.message ?? "未知错误"}`
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
// 文件: ai/tools/table/createTableTool.ts
|
|
2
|
-
|
|
3
|
-
import { createTable } from "render/table/tableSlice";
|
|
4
|
-
import { SEPARATOR } from "database/keys";
|
|
5
|
-
|
|
6
|
-
type ColumnType =
|
|
7
|
-
| "text"
|
|
8
|
-
| "number"
|
|
9
|
-
| "boolean"
|
|
10
|
-
| "date"
|
|
11
|
-
| "datetime"
|
|
12
|
-
| "select"
|
|
13
|
-
| "multi_select";
|
|
14
|
-
|
|
15
|
-
interface ToolTableColumnInput {
|
|
16
|
-
name: string;
|
|
17
|
-
label?: string;
|
|
18
|
-
type?: ColumnType;
|
|
19
|
-
description?: string;
|
|
20
|
-
required?: boolean;
|
|
21
|
-
options?: string[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type CreateTableToolArgs = {
|
|
25
|
-
spaceId?: string;
|
|
26
|
-
title?: string;
|
|
27
|
-
description?: string;
|
|
28
|
-
tags?: string[];
|
|
29
|
-
categoryId?: string;
|
|
30
|
-
columns: ToolTableColumnInput[];
|
|
31
|
-
withDefaultRows?: boolean;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type CreateTableResult = {
|
|
35
|
-
rawData: any;
|
|
36
|
-
displayData: string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 解析 meta dbKey,得到 tenantId / tableId
|
|
41
|
-
* 约定:meta-{tenantId}-{tableId}
|
|
42
|
-
*/
|
|
43
|
-
const parseMetaKey = (dbKey: string): { tenantId: string; tableId: string } => {
|
|
44
|
-
const parts = dbKey.split(SEPARATOR);
|
|
45
|
-
if (parts[0] !== "meta" || parts.length < 3) {
|
|
46
|
-
return { tenantId: "", tableId: "" };
|
|
47
|
-
}
|
|
48
|
-
const tenantId = parts[1];
|
|
49
|
-
const tableId = parts.slice(2).join(SEPARATOR);
|
|
50
|
-
return { tenantId, tableId };
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const toPreviewJson = (value: unknown, maxLength = 400): string => {
|
|
54
|
-
try {
|
|
55
|
-
const json = JSON.stringify(value, null, 2);
|
|
56
|
-
if (json.length <= maxLength) return json;
|
|
57
|
-
return `${json.slice(0, maxLength)}\n…(已截断)…`;
|
|
58
|
-
} catch {
|
|
59
|
-
return "[无法序列化为 JSON]";
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* [Schema] createTable:为当前用户创建一张新表
|
|
65
|
-
*/
|
|
66
|
-
export const createTableFunctionSchema = {
|
|
67
|
-
name: "createTable",
|
|
68
|
-
description: [
|
|
69
|
-
"在当前用户(租户)下创建一张新的结构化数据表。",
|
|
70
|
-
"根据用户的描述,设计表的标题(title)、用途说明(description)以及字段列表(columns)。",
|
|
71
|
-
"字段名建议使用简洁的英文或拼音(如 name, desc, status, dueDate),避免空格和特殊符号。",
|
|
72
|
-
].join("\n"),
|
|
73
|
-
parameters: {
|
|
74
|
-
type: "object",
|
|
75
|
-
properties: {
|
|
76
|
-
spaceId: {
|
|
77
|
-
type: "string",
|
|
78
|
-
description:
|
|
79
|
-
"可选:指定要创建到的 Space ID。不传则使用当前 Space。",
|
|
80
|
-
},
|
|
81
|
-
title: {
|
|
82
|
-
type: "string",
|
|
83
|
-
description:
|
|
84
|
-
"表的显示名称,可以使用中文,例如「任务清单」「客户管理」。",
|
|
85
|
-
},
|
|
86
|
-
description: {
|
|
87
|
-
type: "string",
|
|
88
|
-
description:
|
|
89
|
-
"表用途说明(给人和 AI 看):建议描述每一行代表什么,以及这张表大致用来干什么。",
|
|
90
|
-
},
|
|
91
|
-
tags: {
|
|
92
|
-
type: "array",
|
|
93
|
-
items: { type: "string" },
|
|
94
|
-
description:
|
|
95
|
-
"可选:表示该表的关键词标签列表,例如 [\"记账\",\"交易\",\"预算\"]。主要供 AI 选表使用,用户无需手动维护。",
|
|
96
|
-
},
|
|
97
|
-
categoryId: {
|
|
98
|
-
type: "string",
|
|
99
|
-
description: "可选:Space 内分类 ID。",
|
|
100
|
-
},
|
|
101
|
-
columns: {
|
|
102
|
-
type: "array",
|
|
103
|
-
description: [
|
|
104
|
-
"要创建的字段列表,至少包含 1 个字段。",
|
|
105
|
-
"字段顺序会按数组顺序保存。",
|
|
106
|
-
"",
|
|
107
|
-
"每个字段对象支持:",
|
|
108
|
-
"- name: 字段 machine 名(英文/拼音,无空格),必填;",
|
|
109
|
-
"- label: 字段显示名,可中文;",
|
|
110
|
-
"- type: 字段类型,默认 text,可选:text/number/boolean/date/datetime/select/multi_select;",
|
|
111
|
-
"- description: 字段含义说明,给人和 AI 看;",
|
|
112
|
-
"- required: 是否必填;",
|
|
113
|
-
"- options: 对于 select/multi_select 的可选值列表。",
|
|
114
|
-
].join("\n"),
|
|
115
|
-
minItems: 1,
|
|
116
|
-
items: {
|
|
117
|
-
type: "object",
|
|
118
|
-
properties: {
|
|
119
|
-
name: {
|
|
120
|
-
type: "string",
|
|
121
|
-
description:
|
|
122
|
-
"字段名(machine name),例如 name、desc、status、dueDate。必须是单个标识符,不要包含空格。",
|
|
123
|
-
},
|
|
124
|
-
label: {
|
|
125
|
-
type: "string",
|
|
126
|
-
description:
|
|
127
|
-
"字段显示名,可中文,例如「订单金额」「备注」。不填时前端会回退为 name。",
|
|
128
|
-
},
|
|
129
|
-
type: {
|
|
130
|
-
type: "string",
|
|
131
|
-
enum: [
|
|
132
|
-
"text",
|
|
133
|
-
"number",
|
|
134
|
-
"boolean",
|
|
135
|
-
"date",
|
|
136
|
-
"datetime",
|
|
137
|
-
"select",
|
|
138
|
-
"multi_select",
|
|
139
|
-
],
|
|
140
|
-
description:
|
|
141
|
-
"字段类型,默认 text。选择类字段请使用 select 或 multi_select。",
|
|
142
|
-
},
|
|
143
|
-
description: {
|
|
144
|
-
type: "string",
|
|
145
|
-
description:
|
|
146
|
-
"字段含义说明,既给用户也给 AI 看,例如「订单金额(单位人民币)」。",
|
|
147
|
-
},
|
|
148
|
-
required: {
|
|
149
|
-
type: "boolean",
|
|
150
|
-
description: "是否为必填字段。",
|
|
151
|
-
},
|
|
152
|
-
options: {
|
|
153
|
-
type: "array",
|
|
154
|
-
items: { type: "string" },
|
|
155
|
-
description:
|
|
156
|
-
"当 type 为 select 或 multi_select 时可用,表示允许的取值列表,例如 [\"created\",\"paid\",\"done\"]。",
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
required: ["name"],
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
withDefaultRows: {
|
|
163
|
-
type: "boolean",
|
|
164
|
-
description:
|
|
165
|
-
"是否自动创建两行示例数据。默认 false(AI 创建的表通常不需要示例行)。",
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
required: ["columns"],
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* [Executor] 创建一张新表(调用 tableSlice.createTable thunk)
|
|
174
|
-
*/
|
|
175
|
-
export async function createTableFunc(
|
|
176
|
-
args: CreateTableToolArgs,
|
|
177
|
-
thunkApi: any
|
|
178
|
-
): Promise<CreateTableResult> {
|
|
179
|
-
const spaceId =
|
|
180
|
-
typeof args?.spaceId === "string" && args.spaceId.trim()
|
|
181
|
-
? args.spaceId.trim()
|
|
182
|
-
: undefined;
|
|
183
|
-
const title =
|
|
184
|
-
typeof args?.title === "string" && args.title.trim()
|
|
185
|
-
? args.title.trim()
|
|
186
|
-
: undefined;
|
|
187
|
-
const description =
|
|
188
|
-
typeof args?.description === "string" && args.description.trim()
|
|
189
|
-
? args.description.trim()
|
|
190
|
-
: undefined;
|
|
191
|
-
const tags =
|
|
192
|
-
Array.isArray(args?.tags) && args.tags.length
|
|
193
|
-
? args.tags
|
|
194
|
-
.map((t) => (typeof t === "string" ? t.trim() : ""))
|
|
195
|
-
.filter(Boolean)
|
|
196
|
-
: undefined;
|
|
197
|
-
const categoryId =
|
|
198
|
-
typeof args?.categoryId === "string" && args.categoryId.trim()
|
|
199
|
-
? args.categoryId.trim()
|
|
200
|
-
: undefined;
|
|
201
|
-
const withDefaultRows =
|
|
202
|
-
typeof args?.withDefaultRows === "boolean" ? args.withDefaultRows : false;
|
|
203
|
-
|
|
204
|
-
const columnsInput = Array.isArray(args?.columns) ? args.columns : [];
|
|
205
|
-
|
|
206
|
-
if (columnsInput.length === 0) {
|
|
207
|
-
throw new Error(
|
|
208
|
-
"createTable.columns 至少需要包含一个字段,请根据用户需求设计字段。"
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// 1. 清洗字段:去空白、去重
|
|
213
|
-
const seen = new Set<string>();
|
|
214
|
-
const sanitizedColumns: ToolTableColumnInput[] = [];
|
|
215
|
-
|
|
216
|
-
for (const col of columnsInput) {
|
|
217
|
-
if (!col || typeof col.name !== "string") continue;
|
|
218
|
-
const name = col.name.trim();
|
|
219
|
-
if (!name) continue;
|
|
220
|
-
if (seen.has(name)) continue;
|
|
221
|
-
seen.add(name);
|
|
222
|
-
|
|
223
|
-
const sanitized: ToolTableColumnInput = { name };
|
|
224
|
-
|
|
225
|
-
if (typeof col.label === "string" && col.label.trim()) {
|
|
226
|
-
sanitized.label = col.label.trim();
|
|
227
|
-
}
|
|
228
|
-
if (typeof col.type === "string") {
|
|
229
|
-
sanitized.type = col.type as ColumnType;
|
|
230
|
-
}
|
|
231
|
-
if (typeof col.description === "string" && col.description.trim()) {
|
|
232
|
-
sanitized.description = col.description.trim();
|
|
233
|
-
}
|
|
234
|
-
if (typeof col.required === "boolean") {
|
|
235
|
-
sanitized.required = col.required;
|
|
236
|
-
}
|
|
237
|
-
if (Array.isArray(col.options)) {
|
|
238
|
-
const opts = col.options
|
|
239
|
-
.map((opt) => (typeof opt === "string" ? opt.trim() : ""))
|
|
240
|
-
.filter(Boolean);
|
|
241
|
-
if (opts.length) sanitized.options = opts;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
sanitizedColumns.push(sanitized);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (sanitizedColumns.length === 0) {
|
|
248
|
-
throw new Error(
|
|
249
|
-
"createTable.columns 中没有任何有效的字段名,请为至少一个字段提供非空的 name。"
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// 2. 构造 CreateTableArgs(与 render/table/createTableAction.ts 对齐)
|
|
254
|
-
const createArgs: any = {
|
|
255
|
-
spaceId,
|
|
256
|
-
title,
|
|
257
|
-
description,
|
|
258
|
-
tags,
|
|
259
|
-
categoryId,
|
|
260
|
-
columns: sanitizedColumns,
|
|
261
|
-
withDefaultRows,
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
const actionResult = await thunkApi.dispatch(createTable(createArgs));
|
|
266
|
-
|
|
267
|
-
if (!createTable.fulfilled.match(actionResult)) {
|
|
268
|
-
const msg =
|
|
269
|
-
(actionResult.payload as string) ||
|
|
270
|
-
actionResult.error?.message ||
|
|
271
|
-
"创建表失败";
|
|
272
|
-
throw new Error(msg);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// createTableAction 返回的是 dbKey(string)
|
|
276
|
-
const dbKey = actionResult.payload as string;
|
|
277
|
-
|
|
278
|
-
// 解析出 tenantId / tableId
|
|
279
|
-
const { tenantId, tableId } = parseMetaKey(dbKey);
|
|
280
|
-
|
|
281
|
-
const finalTitle = title || "新建表格";
|
|
282
|
-
const colNamesForDisplay = sanitizedColumns.map((c) => c.name).join(", ");
|
|
283
|
-
|
|
284
|
-
// 给聊天前端的结构化数据,供 Tool 卡片渲染
|
|
285
|
-
const tableMetaForUi = {
|
|
286
|
-
dbKey, // meta-{tenantId}-{tableId}
|
|
287
|
-
tenantId,
|
|
288
|
-
tableId,
|
|
289
|
-
displayName: finalTitle,
|
|
290
|
-
description,
|
|
291
|
-
tags,
|
|
292
|
-
columns: sanitizedColumns, // [{ name, label?, type?, description?, required?, options? }]
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
return {
|
|
296
|
-
rawData: tableMetaForUi,
|
|
297
|
-
displayData:
|
|
298
|
-
`已创建新表「${finalTitle}」(tableId: ${tableId})。\n` +
|
|
299
|
-
`字段列表:${colNamesForDisplay}\n\n` +
|
|
300
|
-
`接下来调用 addTableRow 时,请传入完整结构:\n` +
|
|
301
|
-
`{\n` +
|
|
302
|
-
` "tenantId": "${tenantId}",\n` +
|
|
303
|
-
` "tableId": "${tableId}",\n` +
|
|
304
|
-
` "values": {\n` +
|
|
305
|
-
` "列名": "字段值"\n` +
|
|
306
|
-
` }\n` +
|
|
307
|
-
`}\n\n` +
|
|
308
|
-
`服务器返回 dbKey:\n${toPreviewJson(dbKey)}`,
|
|
309
|
-
};
|
|
310
|
-
} catch (error: any) {
|
|
311
|
-
throw new Error(
|
|
312
|
-
`createTable 调用失败:${error?.message ?? "未知错误"}`
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
}
|