nolo-cli 0.1.13 → 0.1.15
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 +9 -2
- package/agent-runtime/hostAdapter.ts +53 -0
- package/agent-runtime/index.ts +28 -0
- package/agent-runtime/localLoop.ts +62 -0
- package/agent-runtime/runtimeDecision.ts +70 -0
- package/agent-runtime/types.ts +87 -0
- package/agentRunCommand.ts +104 -0
- package/agentRuntimeCommands.ts +139 -22
- package/agentRuntimeLocal.ts +7 -0
- package/ai/agent/_executeModel.ts +118 -0
- package/ai/agent/agentSlice.ts +544 -1
- package/ai/agent/appWorkingMemory.ts +126 -0
- package/ai/agent/avatarUtils.ts +24 -0
- package/ai/agent/buildEditingContext.ts +373 -0
- package/ai/agent/buildSystemPrompt.ts +532 -0
- package/ai/agent/cleanAgentMessages.ts +140 -0
- package/ai/agent/cliChatClient.ts +119 -0
- package/ai/agent/contextCompiler.ts +107 -0
- package/ai/agent/contextLayerContract.ts +44 -0
- package/ai/agent/createAgentSchema.ts +234 -0
- package/ai/agent/executeToolCall.ts +58 -0
- package/ai/agent/fetchAgentContexts.ts +42 -0
- package/ai/agent/generatePrompt.ts +3 -0
- package/ai/agent/getFullChatContextKeys.ts +168 -0
- package/ai/agent/hooks/fetchPublicAgents.ts +133 -0
- package/ai/agent/hooks/useAgentConfig.ts +61 -0
- package/ai/agent/hooks/useAgentDialog.ts +35 -0
- package/ai/agent/hooks/useAgentFormValidation.ts +202 -0
- package/ai/agent/hooks/usePublicAgents.ts +473 -0
- package/ai/agent/persistMessageWithFixedId.ts +37 -0
- package/ai/agent/planSlice.ts +259 -0
- package/ai/agent/referenceUtils.ts +229 -0
- package/ai/agent/runAgentBackground.ts +238 -0
- package/ai/agent/runAgentClientLoop.ts +138 -0
- package/ai/agent/runtimeGuidance.ts +97 -0
- package/ai/agent/runtimeServerBase.ts +37 -0
- package/ai/agent/server/fetchPublicAgents.ts +128 -0
- package/ai/agent/startParallelAgentStreams.ts +424 -0
- package/ai/agent/startupProtocol.ts +53 -0
- package/ai/agent/streamAgentChatTurn.ts +1299 -0
- package/ai/agent/streamAgentChatTurnUtils.ts +738 -0
- package/ai/agent/types.ts +71 -0
- package/ai/agent/utils/imageOutput.ts +39 -0
- package/ai/agent/utils/publicImageAgentMode.ts +26 -0
- package/ai/agent/utils/sortUtils.ts +250 -0
- package/ai/agent/web/referencePickerUtils.ts +146 -0
- package/ai/ai.locale.ts +1083 -0
- package/ai/chat/accumulateToolCallChunks.ts +95 -0
- package/ai/chat/fetchUtils.native.ts +276 -0
- package/ai/chat/fetchUtils.ts +153 -0
- package/ai/chat/inlineImageUrlsForCustomProvider.ts +117 -0
- package/ai/chat/parseApiError.ts +64 -0
- package/ai/chat/parseMultilineSSE.ts +95 -0
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +682 -0
- package/ai/chat/sendOpenAICompletionsRequest.ts +712 -0
- package/ai/chat/sendOpenAIResponseRequest.ts +512 -0
- package/ai/chat/shouldUseServerProxy.ts +18 -0
- package/ai/chat/sseClient.native.ts +91 -0
- package/ai/chat/sseClient.ts +67 -0
- package/ai/chat/streamReader.native.ts +31 -0
- package/ai/chat/streamReader.ts +62 -0
- package/ai/chat/updateTotalUsage.ts +72 -0
- package/ai/context/buildReferenceContext.ts +437 -0
- package/ai/context/calculateContextUsage.ts +133 -0
- package/ai/context/retention.ts +165 -0
- package/ai/context/tokenUtils.ts +78 -0
- package/ai/index.ts +1 -1
- package/ai/llm/agentCapabilities.ts +74 -0
- package/ai/llm/calculateGeminiImageTokens.ts +57 -0
- package/ai/llm/deepinfra.ts +28 -0
- package/ai/llm/fireworks.ts +68 -0
- package/ai/llm/generateRequestBody.ts +165 -0
- package/ai/llm/getModelContextWindow.ts +84 -0
- package/ai/llm/getNoloKey.ts +37 -0
- package/ai/llm/getPricing.ts +232 -0
- package/ai/llm/hooks/useModelPricing.ts +75 -0
- package/ai/llm/imagePricing.ts +66 -0
- package/ai/llm/isResponseAPIModel.ts +13 -0
- package/ai/llm/kimi.ts +18 -0
- package/ai/llm/mimo.ts +71 -0
- package/ai/llm/mistral.ts +22 -0
- package/ai/llm/modelAvatar.ts +427 -0
- package/ai/llm/models.ts +45 -0
- package/ai/llm/openrouterModels.ts +141 -0
- package/ai/llm/providers.ts +307 -0
- package/ai/llm/reasoningModels.ts +28 -0
- package/ai/llm/types.ts +59 -0
- package/ai/llm/usageRequestOptions.ts +59 -0
- package/ai/memory/capture.ts +148 -0
- package/ai/memory/consolidate.ts +104 -0
- package/ai/memory/delete.ts +147 -0
- package/ai/memory/overlay.ts +84 -0
- package/ai/memory/query.ts +38 -0
- package/ai/memory/queryShared.ts +160 -0
- package/ai/memory/rank.ts +105 -0
- package/ai/memory/recentRelationshipRecap.ts +247 -0
- package/ai/memory/remember.ts +167 -0
- package/ai/memory/runtime.ts +76 -0
- package/ai/memory/store.ts +20 -0
- package/ai/memory/storeShared.ts +76 -0
- package/ai/memory/types.ts +46 -0
- package/ai/memory/understanding.ts +349 -0
- package/ai/memory/understandingGreeting.ts +264 -0
- package/ai/messages/type.ts +20 -0
- package/ai/policy/personalizationDialog.ts +333 -0
- package/ai/policy/runtimePolicy.ts +440 -0
- package/ai/policy/selfUpdateFields.ts +48 -0
- package/ai/policy/types.ts +64 -0
- package/ai/skills/referenceRuntime.ts +274 -0
- package/ai/skills/skillDiagnostics.ts +251 -0
- package/ai/skills/skillDocBuilder.ts +139 -0
- package/ai/skills/skillDocProtocol.ts +434 -0
- package/ai/skills/skillReferenceSummary.ts +63 -0
- package/ai/skills/skillSummaryMarker.ts +26 -0
- package/ai/token/calculatePrice.ts +546 -0
- package/ai/token/db.ts +98 -0
- package/ai/token/externalToolCost.ts +321 -0
- package/ai/token/hooks/useRecords.ts +65 -0
- package/ai/token/missingUsageEstimate.ts +42 -0
- package/ai/token/modelUsageQuery.ts +252 -0
- package/ai/token/normalizeUsage.ts +84 -0
- package/ai/token/openaiImageGenerationUsage.ts +56 -0
- package/ai/token/prepareTokenUsageData.ts +88 -0
- package/ai/token/query.ts +88 -0
- package/ai/token/queryUserTokens.ts +59 -0
- package/ai/token/resolveBillingTarget.ts +52 -0
- package/ai/token/saveTokenRecord.ts +53 -0
- package/ai/token/serverDialogProjection.ts +78 -0
- package/ai/token/serverTokenWriter.ts +143 -0
- package/ai/token/stats.ts +21 -0
- package/ai/token/tokenThunks.ts +24 -0
- package/ai/token/types.ts +93 -0
- package/ai/tools/agent/agentTools.ts +176 -0
- package/ai/tools/agent/agentUpdateShared.ts +311 -0
- package/ai/tools/agent/callAgentTool.ts +139 -0
- package/ai/tools/agent/createAgentTool.ts +512 -0
- package/ai/tools/agent/createDialogTool.ts +69 -0
- package/ai/tools/agent/createSkillAgentTool.ts +62 -0
- package/ai/tools/agent/parallelBudget.ts +221 -0
- package/ai/tools/agent/presets/appBuilderPreset.ts +147 -0
- package/ai/tools/agent/runLlmTool.ts +96 -0
- package/ai/tools/agent/runStreamingAgentTool.ts +73 -0
- package/ai/tools/agent/skillAgentArgs.ts +106 -0
- package/ai/tools/agent/skillAgentPreset.ts +89 -0
- package/ai/tools/agent/streamParallelAgentsTool.ts +122 -0
- package/ai/tools/agent/updateAgentTool.ts +96 -0
- package/ai/tools/agent/updateSelfTool.ts +113 -0
- package/ai/tools/amazonProductScraperTool.ts +86 -0
- package/ai/tools/apifyActorClient.ts +45 -0
- package/ai/tools/appEditGuard.ts +372 -0
- package/ai/tools/appReadSnapshot.ts +153 -0
- package/ai/tools/appTools.ts +1549 -0
- package/ai/tools/applyEditTool.ts +256 -0
- package/ai/tools/applyLineEditsTool.ts +312 -0
- package/ai/tools/browserTools/click.ts +33 -0
- package/ai/tools/browserTools/closeSession.ts +29 -0
- package/ai/tools/browserTools/common.ts +27 -0
- package/ai/tools/browserTools/openSession.ts +48 -0
- package/ai/tools/browserTools/readContent.ts +38 -0
- package/ai/tools/browserTools/selectOption.ts +46 -0
- package/ai/tools/browserTools/typeText.ts +42 -0
- package/ai/tools/category/createCategoryTool.ts +66 -0
- package/ai/tools/category/queryContentsByCategoryTool.ts +69 -0
- package/ai/tools/category/updateContentCategoryTool.ts +75 -0
- package/ai/tools/cfBrowserTools.ts +319 -0
- package/ai/tools/cfSpeechToTextTool.ts +49 -0
- package/ai/tools/checkEnvTool.ts +65 -0
- package/ai/tools/cloudflareCrawlTool.ts +289 -0
- package/ai/tools/codeSearchTool.ts +111 -0
- package/ai/tools/codeTools.ts +101 -0
- package/ai/tools/createDocTool.ts +132 -0
- package/ai/tools/createPlanTool.ts +999 -0
- package/ai/tools/createSkillDocTool.ts +155 -0
- package/ai/tools/createWorkflowTool.ts +154 -0
- package/ai/tools/deepseekOcrTool.ts +34 -0
- package/ai/tools/delayTool.ts +31 -0
- package/ai/tools/deleteSpacesTool.ts +325 -0
- package/ai/tools/deleteSpacesToolModel.ts +159 -0
- package/ai/tools/devReloadUtils.ts +29 -0
- package/ai/tools/dialogMessageSearch.ts +137 -0
- package/ai/tools/doctorSkillTool.ts +72 -0
- package/ai/tools/ecommerceScraperTool.ts +86 -0
- package/ai/tools/emailTools.ts +549 -0
- package/ai/tools/evalSkillTool.ts +92 -0
- package/ai/tools/exaSearchTool.ts +64 -0
- package/ai/tools/execBashTool.ts +379 -0
- package/ai/tools/executeSqlTool.ts +192 -0
- package/ai/tools/fetchWebpageSupport.ts +309 -0
- package/ai/tools/fetchWebpageTool.ts +84 -0
- package/ai/tools/geminiImagePreviewTool.ts +361 -0
- package/ai/tools/generateDocxTool.ts +215 -0
- package/ai/tools/googleSearchScraperTool.ts +106 -0
- package/ai/tools/importDataTool.ts +133 -0
- package/ai/tools/importSkillTool.ts +162 -0
- package/ai/tools/index.ts +1927 -0
- package/ai/tools/listFilesTool.ts +82 -0
- package/ai/tools/listUserSpacesTool.ts +113 -0
- package/ai/tools/modelUsageTools.ts +199 -0
- package/ai/tools/olmOcrTool.ts +34 -0
- package/ai/tools/openaiImageTool.ts +267 -0
- package/ai/tools/prepareTools.ts +23 -0
- package/ai/tools/readDocTool.ts +84 -0
- package/ai/tools/readFileTool.ts +211 -0
- package/ai/tools/readTool.ts +163 -0
- package/ai/tools/readXPostTool.ts +233 -0
- package/ai/tools/rememberMemoryTool.ts +84 -0
- package/ai/tools/remotionVideoTool.ts +151 -0
- package/ai/tools/searchDialogMessagesTool.ts +222 -0
- package/ai/tools/searchRepoTool.ts +115 -0
- package/ai/tools/searchWorkspaceTool.ts +259 -0
- package/ai/tools/skillFollowup.ts +86 -0
- package/ai/tools/surfWeatherTool.ts +169 -0
- package/ai/tools/table/addTableRowTool.ts +217 -0
- package/ai/tools/table/createTableTool.ts +315 -0
- package/ai/tools/table/rowTools.ts +366 -0
- package/ai/tools/table/schemaTools.ts +244 -0
- package/ai/tools/table/shareTableTool.ts +148 -0
- package/ai/tools/table/toolShared.ts +129 -0
- package/ai/tools/toolApiClient.ts +198 -0
- package/ai/tools/toolNameAliases.ts +57 -0
- package/ai/tools/toolResultError.ts +42 -0
- package/ai/tools/toolRunSlice.ts +303 -0
- package/ai/tools/toolSchemaCompatibility.ts +53 -0
- package/ai/tools/toolVisibility.ts +4 -0
- package/ai/tools/types.ts +20 -0
- package/ai/tools/uiAskChoiceTool.ts +104 -0
- package/ai/tools/updateContentTitleTool.ts +84 -0
- package/ai/tools/updateDocTool.ts +105 -0
- package/ai/tools/updateUserPreferenceProfileTool.ts +145 -0
- package/ai/tools/whisperTool.ts +77 -0
- package/ai/tools/writeFileTool.ts +210 -0
- package/ai/tools/youtubeScraperTool.ts +116 -0
- package/ai/tools/ziweiChartTool.ts +678 -0
- package/ai/types.ts +55 -0
- package/ai/workflow/workflowExecutor.ts +323 -0
- package/ai/workflow/workflowSlice.ts +73 -0
- package/ai/workflow/workflowTypes.ts +106 -0
- package/client/agentRun.test.ts +240 -0
- package/client/agentRun.ts +182 -19
- package/client/compactDialog.test.ts +238 -0
- package/client/localRuntimeAdapter.test.ts +135 -0
- package/client/localRuntimeAdapter.ts +244 -0
- package/client/profileConfig.test.ts +40 -0
- package/client/streamingOutput.test.ts +22 -0
- package/client/streamingOutput.ts +38 -0
- package/commandRegistry.ts +11 -2
- package/connector-experimental/index.ts +5 -0
- package/database/actions/cacheMergedUserData.ts +64 -0
- package/database/actions/common.ts +242 -0
- package/database/actions/deleteFile.ts +40 -0
- package/database/actions/fetchUserData.ts +16 -0
- package/database/actions/fileContent.ts +125 -0
- package/database/actions/patch.ts +155 -0
- package/database/actions/read.ts +337 -0
- package/database/actions/readAndWait.ts +224 -0
- package/database/actions/readRequestManager.ts +120 -0
- package/database/actions/remove.ts +94 -0
- package/database/actions/replication.ts +366 -0
- package/database/actions/upload.ts +174 -0
- package/database/actions/upsert.ts +56 -0
- package/database/actions/write.ts +126 -0
- package/database/client/db.native.ts +73 -0
- package/database/client/db.ts +51 -0
- package/database/client/fetchUserData.ts +61 -0
- package/database/client/handleError.ts +19 -0
- package/database/client/queryRequest.ts +21 -0
- package/database/config.ts +21 -0
- package/database/dbActionThunks.ts +1 -0
- package/database/dbSlice.ts +149 -0
- package/database/email.ts +42 -0
- package/database/fileRing.ts +51 -0
- package/database/fileSharding.ts +70 -0
- package/database/fileStorage.native.ts +92 -0
- package/database/fileStorage.ts +232 -0
- package/database/fileUrl.ts +34 -0
- package/database/hooks/useUserData.ts +489 -0
- package/database/index.ts +1 -0
- package/database/keys.ts +765 -0
- package/database/queryPrefixes.ts +14 -0
- package/database/requests.ts +443 -0
- package/database/runtimeServerContext.ts +35 -0
- package/database/server/MemoryDB.ts +76 -0
- package/database/server/actorAccess.ts +76 -0
- package/database/server/agentDelegation.ts +124 -0
- package/database/server/coreDataOwnership.ts +13 -0
- package/database/server/coreDataProxy.ts +76 -0
- package/database/server/cybotReadonly.ts +18 -0
- package/database/server/dataHandlers.ts +111 -0
- package/database/server/db.ts +118 -0
- package/database/server/dbPath.ts +20 -0
- package/database/server/delete.ts +499 -0
- package/database/server/emailRepository.ts +1480 -0
- package/database/server/ensureDbOpen.ts +12 -0
- package/database/server/fileRead.ts +337 -0
- package/database/server/fileService.ts +436 -0
- package/database/server/handleTransaction.ts +86 -0
- package/database/server/patch.ts +282 -0
- package/database/server/query.ts +138 -0
- package/database/server/read.ts +325 -0
- package/database/server/resourceAccess.ts +211 -0
- package/database/server/routes.ts +110 -0
- package/database/server/spaceMemberAuthority.ts +67 -0
- package/database/server/upload.ts +159 -0
- package/database/server/write.ts +494 -0
- package/database/server/writeAuthority.ts +133 -0
- package/database/sqliteDb.ts +46 -0
- package/database/table/deleteTable.ts +120 -0
- package/database/tenantPlacement.ts +57 -0
- package/database/tombstones.ts +52 -0
- package/database/userDataLoadDecision.ts +17 -0
- package/database/userDataMerge.ts +95 -0
- package/database/userPreferenceRegister.ts +108 -0
- package/database/utils/dbPath.ts +47 -0
- package/database/utils/ulid.native.ts +6 -0
- package/database/utils/ulid.ts +1 -0
- package/index.ts +37 -19
- package/localRuntimeDb.ts +28 -0
- package/package.json +17 -4
- package/runtimeModeArgs.ts +33 -0
- package/tui/readlineWorkspace.ts +1 -0
- package/tui/session.ts +22 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import type { RootState } from "app/store";
|
|
2
|
+
import {
|
|
3
|
+
applyRowFilters,
|
|
4
|
+
formatKnownColumns,
|
|
5
|
+
normalizeRowValues,
|
|
6
|
+
pickRowColumns,
|
|
7
|
+
sortRows,
|
|
8
|
+
type RowFilters,
|
|
9
|
+
} from "render/table/toolValueUtils";
|
|
10
|
+
import { buildNewRow, ensureRowsLoaded, loadTableMetaOrThrow, patchRecord, resolveRowOrThrow, resolveTableIdentity, writeRow } from "./toolShared";
|
|
11
|
+
|
|
12
|
+
const toPreviewJson = (value: unknown, maxLength = 600): string => {
|
|
13
|
+
try {
|
|
14
|
+
const json = JSON.stringify(value, null, 2);
|
|
15
|
+
if (json.length <= maxLength) return json;
|
|
16
|
+
return `${json.slice(0, maxLength)}\n…(已截断)…`;
|
|
17
|
+
} catch {
|
|
18
|
+
return "[无法序列化为 JSON]";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const requireTableIdentity = (args: { tenantId?: string; tableId?: string }, thunkApi: any) => {
|
|
23
|
+
const state = thunkApi.getState() as RootState;
|
|
24
|
+
const { tenantId, tableId } = resolveTableIdentity(args, state);
|
|
25
|
+
if (!tenantId || !tableId) {
|
|
26
|
+
throw new Error("需要显式提供 tenantId 和 tableId,或在已打开的表页面中调用。");
|
|
27
|
+
}
|
|
28
|
+
return { tenantId, tableId };
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const queryTableRowsFunctionSchema = {
|
|
32
|
+
name: "queryTableRows",
|
|
33
|
+
description: "查询指定表中的行,支持简单字段过滤、排序、分页和返回指定列。",
|
|
34
|
+
parameters: {
|
|
35
|
+
type: "object",
|
|
36
|
+
properties: {
|
|
37
|
+
tenantId: { type: "string", description: "租户 ID。聊天场景中必须显式传入。" },
|
|
38
|
+
tableId: { type: "string", description: "表 ID。聊天场景中必须显式传入。" },
|
|
39
|
+
filters: {
|
|
40
|
+
type: "object",
|
|
41
|
+
description: "按列名做精确匹配过滤,例如 {\"status\":\"todo\"}。",
|
|
42
|
+
},
|
|
43
|
+
columns: {
|
|
44
|
+
type: "array",
|
|
45
|
+
items: { type: "string" },
|
|
46
|
+
description: "可选:只返回这些列。",
|
|
47
|
+
},
|
|
48
|
+
limit: { type: "number", description: "最多返回多少行,默认 20,最大 200。" },
|
|
49
|
+
offset: { type: "number", description: "从第几行开始返回,默认 0。" },
|
|
50
|
+
sortBy: { type: "string", description: "排序字段,默认 updatedAt。" },
|
|
51
|
+
sortOrder: {
|
|
52
|
+
type: "string",
|
|
53
|
+
enum: ["asc", "desc"],
|
|
54
|
+
description: "排序方向,默认 desc。",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export async function queryTableRowsFunc(args: any, thunkApi: any) {
|
|
61
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
62
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
63
|
+
const rows = await ensureRowsLoaded(thunkApi, tenantId, tableId);
|
|
64
|
+
const filters = (args?.filters ?? {}) as RowFilters;
|
|
65
|
+
const limit = Math.min(Math.max(Number(args?.limit ?? 20), 1), 200);
|
|
66
|
+
const offset = Math.max(Number(args?.offset ?? 0), 0);
|
|
67
|
+
const sortBy = typeof args?.sortBy === "string" && args.sortBy.trim() ? args.sortBy.trim() : "updatedAt";
|
|
68
|
+
const sortOrder = args?.sortOrder === "asc" ? "asc" : "desc";
|
|
69
|
+
const columns = Array.isArray(args?.columns)
|
|
70
|
+
? args.columns.filter((value: unknown): value is string => typeof value === "string" && value.trim().length > 0)
|
|
71
|
+
: undefined;
|
|
72
|
+
|
|
73
|
+
const filtered = applyRowFilters(rows, filters);
|
|
74
|
+
const sorted = sortRows(filtered, sortBy, sortOrder);
|
|
75
|
+
const page = sorted.slice(offset, offset + limit);
|
|
76
|
+
const items = columns ? page.map((row) => pickRowColumns(row, columns)) : page;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
rawData: {
|
|
80
|
+
tenantId,
|
|
81
|
+
tableId,
|
|
82
|
+
total: filtered.length,
|
|
83
|
+
limit,
|
|
84
|
+
offset,
|
|
85
|
+
items,
|
|
86
|
+
},
|
|
87
|
+
displayData:
|
|
88
|
+
`在表「${tableMeta.displayName || tableId}」中查询到 ${filtered.length} 行,当前返回 ${items.length} 行。\n` +
|
|
89
|
+
`字段:${formatKnownColumns(tableMeta)}\n\n` +
|
|
90
|
+
`${toPreviewJson(items)}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const updateTableRowFunctionSchema = {
|
|
95
|
+
name: "updateTableRow",
|
|
96
|
+
description: "按 rowId 或 dbKey 更新指定表中的一行数据,只修改 changes 中提供的字段。",
|
|
97
|
+
parameters: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
tenantId: { type: "string" },
|
|
101
|
+
tableId: { type: "string" },
|
|
102
|
+
rowId: { type: "string", description: "要更新的行 ID。" },
|
|
103
|
+
dbKey: { type: "string", description: "要更新的行 dbKey。rowId 与 dbKey 二选一即可。" },
|
|
104
|
+
changes: {
|
|
105
|
+
type: "object",
|
|
106
|
+
description: "要修改的字段集合,例如 {\"status\":\"done\"}。",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
required: ["changes"],
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export async function updateTableRowFunc(args: any, thunkApi: any) {
|
|
114
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
115
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
116
|
+
const targetRow = await resolveRowOrThrow(thunkApi, { tenantId, tableId, rowId: args?.rowId, dbKey: args?.dbKey });
|
|
117
|
+
const changes = args?.changes;
|
|
118
|
+
|
|
119
|
+
if (!changes || typeof changes !== "object" || Array.isArray(changes)) {
|
|
120
|
+
throw new Error("updateTableRow.changes 必须是对象。");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const normalized = normalizeRowValues(tableMeta.columns, changes, { mode: "update" });
|
|
124
|
+
if (normalized.errors.length > 0) {
|
|
125
|
+
throw new Error(normalized.errors.join("\n"));
|
|
126
|
+
}
|
|
127
|
+
if (Object.keys(normalized.sanitizedValues).length === 0) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`updateTableRow 没有可更新的有效字段。已知字段:${formatKnownColumns(tableMeta)}`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const updatedAt = new Date().toISOString();
|
|
134
|
+
const updated = await patchRecord(thunkApi, targetRow.dbKey, {
|
|
135
|
+
...normalized.sanitizedValues,
|
|
136
|
+
updatedAt,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const ignoredInfo =
|
|
140
|
+
normalized.ignoredColumns.length > 0
|
|
141
|
+
? `\n\n注意:以下字段已忽略:${normalized.ignoredColumns.join(", ")}`
|
|
142
|
+
: "";
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
rawData: updated,
|
|
146
|
+
displayData:
|
|
147
|
+
`已更新表「${tableMeta.displayName || tableId}」中的行 ${targetRow.rowId}。${ignoredInfo}\n\n` +
|
|
148
|
+
`${toPreviewJson(updated)}`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const deleteTableRowFunctionSchema = {
|
|
153
|
+
name: "deleteTableRow",
|
|
154
|
+
description: "删除指定表中的一行数据(软删除)。",
|
|
155
|
+
parameters: {
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: {
|
|
158
|
+
tenantId: { type: "string" },
|
|
159
|
+
tableId: { type: "string" },
|
|
160
|
+
rowId: { type: "string" },
|
|
161
|
+
dbKey: { type: "string" },
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export async function deleteTableRowFunc(args: any, thunkApi: any) {
|
|
167
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
168
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
169
|
+
const targetRow = await resolveRowOrThrow(thunkApi, { tenantId, tableId, rowId: args?.rowId, dbKey: args?.dbKey });
|
|
170
|
+
const updatedAt = new Date().toISOString();
|
|
171
|
+
const deleted = await patchRecord(thunkApi, targetRow.dbKey, {
|
|
172
|
+
deletedAt: updatedAt,
|
|
173
|
+
updatedAt,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
rawData: deleted,
|
|
178
|
+
displayData: `已从表「${tableMeta.displayName || tableId}」中删除行 ${targetRow.rowId}。`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const addTableRowsFunctionSchema = {
|
|
183
|
+
name: "addTableRows",
|
|
184
|
+
description: "批量向指定表中新增多行数据。",
|
|
185
|
+
parameters: {
|
|
186
|
+
type: "object",
|
|
187
|
+
properties: {
|
|
188
|
+
tenantId: { type: "string" },
|
|
189
|
+
tableId: { type: "string" },
|
|
190
|
+
rows: {
|
|
191
|
+
type: "array",
|
|
192
|
+
items: { type: "object" },
|
|
193
|
+
description: "每一项都是一行数据对象,key 必须是表中的列名。",
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
required: ["rows"],
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export async function addTableRowsFunc(args: any, thunkApi: any) {
|
|
201
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
202
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
203
|
+
const rows = Array.isArray(args?.rows) ? args.rows : [];
|
|
204
|
+
if (rows.length === 0) {
|
|
205
|
+
throw new Error("addTableRows.rows 至少需要包含一行。");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const createdRows: any[] = [];
|
|
209
|
+
const ignoredColumns = new Set<string>();
|
|
210
|
+
for (const row of rows) {
|
|
211
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) {
|
|
212
|
+
throw new Error("addTableRows.rows 中的每一项都必须是对象。");
|
|
213
|
+
}
|
|
214
|
+
const normalized = normalizeRowValues(tableMeta.columns, row, { mode: "create" });
|
|
215
|
+
if (normalized.errors.length > 0) {
|
|
216
|
+
throw new Error(normalized.errors.join("\n"));
|
|
217
|
+
}
|
|
218
|
+
if (Object.keys(normalized.sanitizedValues).length === 0) {
|
|
219
|
+
throw new Error(`存在一行没有任何有效字段。已知字段:${formatKnownColumns(tableMeta)}`);
|
|
220
|
+
}
|
|
221
|
+
normalized.ignoredColumns.forEach((column) => ignoredColumns.add(column));
|
|
222
|
+
const created = buildNewRow(tenantId, tableId, normalized.sanitizedValues);
|
|
223
|
+
await writeRow(thunkApi, created);
|
|
224
|
+
createdRows.push(created);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const ignoredInfo =
|
|
228
|
+
ignoredColumns.size > 0 ? `\n\n注意:以下字段已忽略:${Array.from(ignoredColumns).join(", ")}` : "";
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
rawData: {
|
|
232
|
+
count: createdRows.length,
|
|
233
|
+
items: createdRows,
|
|
234
|
+
},
|
|
235
|
+
displayData:
|
|
236
|
+
`已向表「${tableMeta.displayName || tableId}」批量新增 ${createdRows.length} 行。${ignoredInfo}\n\n` +
|
|
237
|
+
`${toPreviewJson(createdRows.slice(0, 10))}`,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export const updateTableRowsFunctionSchema = {
|
|
242
|
+
name: "updateTableRows",
|
|
243
|
+
description: "批量更新多行数据。每项都需要 rowId 或 dbKey,以及 changes。",
|
|
244
|
+
parameters: {
|
|
245
|
+
type: "object",
|
|
246
|
+
properties: {
|
|
247
|
+
tenantId: { type: "string" },
|
|
248
|
+
tableId: { type: "string" },
|
|
249
|
+
updates: {
|
|
250
|
+
type: "array",
|
|
251
|
+
items: {
|
|
252
|
+
type: "object",
|
|
253
|
+
properties: {
|
|
254
|
+
rowId: { type: "string" },
|
|
255
|
+
dbKey: { type: "string" },
|
|
256
|
+
changes: { type: "object" },
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
required: ["updates"],
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export async function updateTableRowsFunc(args: any, thunkApi: any) {
|
|
266
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
267
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
268
|
+
const updates = Array.isArray(args?.updates) ? args.updates : [];
|
|
269
|
+
if (updates.length === 0) {
|
|
270
|
+
throw new Error("updateTableRows.updates 至少需要包含一项。");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const results: any[] = [];
|
|
274
|
+
const ignoredColumns = new Set<string>();
|
|
275
|
+
for (const item of updates) {
|
|
276
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
277
|
+
throw new Error("updateTableRows.updates 中的每一项都必须是对象。");
|
|
278
|
+
}
|
|
279
|
+
const targetRow = await resolveRowOrThrow(thunkApi, {
|
|
280
|
+
tenantId,
|
|
281
|
+
tableId,
|
|
282
|
+
rowId: item.rowId,
|
|
283
|
+
dbKey: item.dbKey,
|
|
284
|
+
});
|
|
285
|
+
const normalized = normalizeRowValues(tableMeta.columns, item.changes ?? {}, { mode: "update" });
|
|
286
|
+
if (normalized.errors.length > 0) {
|
|
287
|
+
throw new Error(normalized.errors.join("\n"));
|
|
288
|
+
}
|
|
289
|
+
if (Object.keys(normalized.sanitizedValues).length === 0) {
|
|
290
|
+
throw new Error(`行 ${targetRow.rowId} 没有可更新的有效字段。`);
|
|
291
|
+
}
|
|
292
|
+
normalized.ignoredColumns.forEach((column) => ignoredColumns.add(column));
|
|
293
|
+
const updated = await patchRecord(thunkApi, targetRow.dbKey, {
|
|
294
|
+
...normalized.sanitizedValues,
|
|
295
|
+
updatedAt: new Date().toISOString(),
|
|
296
|
+
});
|
|
297
|
+
results.push(updated);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const ignoredInfo =
|
|
301
|
+
ignoredColumns.size > 0 ? `\n\n注意:以下字段已忽略:${Array.from(ignoredColumns).join(", ")}` : "";
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
rawData: {
|
|
305
|
+
count: results.length,
|
|
306
|
+
items: results,
|
|
307
|
+
},
|
|
308
|
+
displayData:
|
|
309
|
+
`已批量更新表「${tableMeta.displayName || tableId}」中的 ${results.length} 行。${ignoredInfo}`,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export const deleteTableRowsFunctionSchema = {
|
|
314
|
+
name: "deleteTableRows",
|
|
315
|
+
description: "批量删除多行数据(软删除)。",
|
|
316
|
+
parameters: {
|
|
317
|
+
type: "object",
|
|
318
|
+
properties: {
|
|
319
|
+
tenantId: { type: "string" },
|
|
320
|
+
tableId: { type: "string" },
|
|
321
|
+
rowIds: {
|
|
322
|
+
type: "array",
|
|
323
|
+
items: { type: "string" },
|
|
324
|
+
description: "要删除的 rowId 列表。",
|
|
325
|
+
},
|
|
326
|
+
dbKeys: {
|
|
327
|
+
type: "array",
|
|
328
|
+
items: { type: "string" },
|
|
329
|
+
description: "要删除的 dbKey 列表。",
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
export async function deleteTableRowsFunc(args: any, thunkApi: any) {
|
|
336
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
337
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
338
|
+
const rowIds = Array.isArray(args?.rowIds) ? args.rowIds : [];
|
|
339
|
+
const dbKeys = Array.isArray(args?.dbKeys) ? args.dbKeys : [];
|
|
340
|
+
const targets = [
|
|
341
|
+
...rowIds.map((rowId: string) => ({ rowId })),
|
|
342
|
+
...dbKeys.map((dbKey: string) => ({ dbKey })),
|
|
343
|
+
];
|
|
344
|
+
|
|
345
|
+
if (targets.length === 0) {
|
|
346
|
+
throw new Error("deleteTableRows 需要至少提供一个 rowId 或 dbKey。");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const results = [];
|
|
350
|
+
for (const target of targets) {
|
|
351
|
+
const row = await resolveRowOrThrow(thunkApi, { tenantId, tableId, rowId: target.rowId, dbKey: target.dbKey });
|
|
352
|
+
const deleted = await patchRecord(thunkApi, row.dbKey, {
|
|
353
|
+
deletedAt: new Date().toISOString(),
|
|
354
|
+
updatedAt: new Date().toISOString(),
|
|
355
|
+
});
|
|
356
|
+
results.push(deleted);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
rawData: {
|
|
361
|
+
count: results.length,
|
|
362
|
+
items: results,
|
|
363
|
+
},
|
|
364
|
+
displayData: `已从表「${tableMeta.displayName || tableId}」中批量删除 ${results.length} 行。`,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { patchRecord, loadTableMetaOrThrow, ensureRowsLoaded, resolveTableIdentity } from "./toolShared";
|
|
2
|
+
import type { RootState } from "app/store";
|
|
3
|
+
import type { TableColumn } from "render/table/types";
|
|
4
|
+
import { ulid } from "database/utils/ulid";
|
|
5
|
+
|
|
6
|
+
const requireTableIdentity = (args: { tenantId?: string; tableId?: string }, thunkApi: any) => {
|
|
7
|
+
const state = thunkApi.getState() as RootState;
|
|
8
|
+
const { tenantId, tableId } = resolveTableIdentity(args, state);
|
|
9
|
+
if (!tenantId || !tableId) {
|
|
10
|
+
throw new Error("需要显式提供 tenantId 和 tableId,或在已打开的表页面中调用。");
|
|
11
|
+
}
|
|
12
|
+
return { tenantId, tableId };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const ensureColumnName = (name: unknown): string => {
|
|
16
|
+
if (typeof name !== "string" || !name.trim()) {
|
|
17
|
+
throw new Error("列名不能为空。");
|
|
18
|
+
}
|
|
19
|
+
return name.trim();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const normalizeOptions = (options: unknown): string[] | undefined => {
|
|
23
|
+
if (!Array.isArray(options)) return undefined;
|
|
24
|
+
const normalized = options
|
|
25
|
+
.map((value) => (typeof value === "string" ? value.trim() : ""))
|
|
26
|
+
.filter(Boolean);
|
|
27
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const addTableColumnFunctionSchema = {
|
|
31
|
+
name: "addTableColumn",
|
|
32
|
+
description: "向指定表中新增一列。",
|
|
33
|
+
parameters: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
tenantId: { type: "string" },
|
|
37
|
+
tableId: { type: "string" },
|
|
38
|
+
name: { type: "string" },
|
|
39
|
+
label: { type: "string" },
|
|
40
|
+
type: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: ["text", "number", "boolean", "date", "datetime", "select", "multi_select"],
|
|
43
|
+
},
|
|
44
|
+
description: { type: "string" },
|
|
45
|
+
required: { type: "boolean" },
|
|
46
|
+
options: { type: "array", items: { type: "string" } },
|
|
47
|
+
},
|
|
48
|
+
required: ["name"],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export async function addTableColumnFunc(args: any, thunkApi: any) {
|
|
53
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
54
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
55
|
+
const name = ensureColumnName(args?.name);
|
|
56
|
+
if (tableMeta.columns.some((column) => column.name === name)) {
|
|
57
|
+
throw new Error(`字段 ${name} 已存在。`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const column: TableColumn = {
|
|
61
|
+
id: ulid(),
|
|
62
|
+
name,
|
|
63
|
+
label: typeof args?.label === "string" && args.label.trim() ? args.label.trim() : name,
|
|
64
|
+
type: typeof args?.type === "string" ? args.type : "text",
|
|
65
|
+
description: typeof args?.description === "string" && args.description.trim() ? args.description.trim() : undefined,
|
|
66
|
+
required: typeof args?.required === "boolean" ? args.required : undefined,
|
|
67
|
+
options: normalizeOptions(args?.options),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const updatedAt = new Date().toISOString();
|
|
71
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
72
|
+
columns: [...tableMeta.columns, column],
|
|
73
|
+
updatedAt,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
rawData: updated,
|
|
78
|
+
displayData: `已向表「${tableMeta.displayName || tableId}」新增字段 ${name}。`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const deleteTableColumnFunctionSchema = {
|
|
83
|
+
name: "deleteTableColumn",
|
|
84
|
+
description: "删除指定表中的某一列,并同步从已有行中移除该字段。",
|
|
85
|
+
parameters: {
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {
|
|
88
|
+
tenantId: { type: "string" },
|
|
89
|
+
tableId: { type: "string" },
|
|
90
|
+
columnName: { type: "string" },
|
|
91
|
+
},
|
|
92
|
+
required: ["columnName"],
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export async function deleteTableColumnFunc(args: any, thunkApi: any) {
|
|
97
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
98
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
99
|
+
const columnName = ensureColumnName(args?.columnName);
|
|
100
|
+
if (!tableMeta.columns.some((column) => column.name === columnName)) {
|
|
101
|
+
throw new Error(`字段 ${columnName} 不存在。`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const rows = await ensureRowsLoaded(thunkApi, tenantId, tableId);
|
|
105
|
+
const updatedAt = new Date().toISOString();
|
|
106
|
+
for (const row of rows) {
|
|
107
|
+
if (Object.prototype.hasOwnProperty.call(row, columnName)) {
|
|
108
|
+
await patchRecord(thunkApi, row.dbKey, {
|
|
109
|
+
[columnName]: null,
|
|
110
|
+
updatedAt,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
116
|
+
columns: tableMeta.columns.filter((column) => column.name !== columnName),
|
|
117
|
+
updatedAt,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
rawData: updated,
|
|
122
|
+
displayData: `已从表「${tableMeta.displayName || tableId}」删除字段 ${columnName}。`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const renameTableColumnFunctionSchema = {
|
|
127
|
+
name: "renameTableColumn",
|
|
128
|
+
description: "修改表字段的 machine name,并同步迁移所有已有行的数据 key。",
|
|
129
|
+
parameters: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {
|
|
132
|
+
tenantId: { type: "string" },
|
|
133
|
+
tableId: { type: "string" },
|
|
134
|
+
oldName: { type: "string" },
|
|
135
|
+
newName: { type: "string" },
|
|
136
|
+
},
|
|
137
|
+
required: ["oldName", "newName"],
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export async function renameTableColumnFunc(args: any, thunkApi: any) {
|
|
142
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
143
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
144
|
+
const oldName = ensureColumnName(args?.oldName);
|
|
145
|
+
const newName = ensureColumnName(args?.newName);
|
|
146
|
+
|
|
147
|
+
if (!tableMeta.columns.some((column) => column.name === oldName)) {
|
|
148
|
+
throw new Error(`字段 ${oldName} 不存在。`);
|
|
149
|
+
}
|
|
150
|
+
if (tableMeta.columns.some((column) => column.name === newName)) {
|
|
151
|
+
throw new Error(`字段 ${newName} 已存在。`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const rows = await ensureRowsLoaded(thunkApi, tenantId, tableId);
|
|
155
|
+
const updatedAt = new Date().toISOString();
|
|
156
|
+
for (const row of rows) {
|
|
157
|
+
if (Object.prototype.hasOwnProperty.call(row, oldName)) {
|
|
158
|
+
await patchRecord(thunkApi, row.dbKey, {
|
|
159
|
+
[newName]: row[oldName],
|
|
160
|
+
[oldName]: null,
|
|
161
|
+
updatedAt,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
167
|
+
columns: tableMeta.columns.map((column) =>
|
|
168
|
+
column.name === oldName ? { ...column, name: newName } : column
|
|
169
|
+
),
|
|
170
|
+
updatedAt,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
rawData: updated,
|
|
175
|
+
displayData: `已将表「${tableMeta.displayName || tableId}」中的字段 ${oldName} 重命名为 ${newName}。`,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export const renameTableColumnLabelFunctionSchema = {
|
|
180
|
+
name: "renameTableColumnLabel",
|
|
181
|
+
description: "修改表字段的显示名,不改变行数据里的 key。",
|
|
182
|
+
parameters: {
|
|
183
|
+
type: "object",
|
|
184
|
+
properties: {
|
|
185
|
+
tenantId: { type: "string" },
|
|
186
|
+
tableId: { type: "string" },
|
|
187
|
+
columnName: { type: "string" },
|
|
188
|
+
newLabel: { type: "string" },
|
|
189
|
+
},
|
|
190
|
+
required: ["columnName", "newLabel"],
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export async function renameTableColumnLabelFunc(args: any, thunkApi: any) {
|
|
195
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
196
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
197
|
+
const columnName = ensureColumnName(args?.columnName);
|
|
198
|
+
const newLabel = ensureColumnName(args?.newLabel);
|
|
199
|
+
|
|
200
|
+
if (!tableMeta.columns.some((column) => column.name === columnName)) {
|
|
201
|
+
throw new Error(`字段 ${columnName} 不存在。`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
205
|
+
columns: tableMeta.columns.map((column) =>
|
|
206
|
+
column.name === columnName ? { ...column, label: newLabel } : column
|
|
207
|
+
),
|
|
208
|
+
updatedAt: new Date().toISOString(),
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
rawData: updated,
|
|
213
|
+
displayData: `已将字段 ${columnName} 的显示名更新为 ${newLabel}。`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export const renameTableFunctionSchema = {
|
|
218
|
+
name: "renameTable",
|
|
219
|
+
description: "更新表的显示名称。",
|
|
220
|
+
parameters: {
|
|
221
|
+
type: "object",
|
|
222
|
+
properties: {
|
|
223
|
+
tenantId: { type: "string" },
|
|
224
|
+
tableId: { type: "string" },
|
|
225
|
+
newName: { type: "string" },
|
|
226
|
+
},
|
|
227
|
+
required: ["newName"],
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export async function renameTableFunc(args: any, thunkApi: any) {
|
|
232
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
233
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
234
|
+
const newName = ensureColumnName(args?.newName);
|
|
235
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
236
|
+
displayName: newName,
|
|
237
|
+
updatedAt: new Date().toISOString(),
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
rawData: updated,
|
|
242
|
+
displayData: `已将表名更新为「${newName}」。`,
|
|
243
|
+
};
|
|
244
|
+
}
|