@arcticdata/dsh-datarc-assistant 26.39.0 → 26.39.1
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 +45 -10
- package/api-operations.js +404 -0
- package/client.js +452 -87
- package/cordis.patch.yml +4 -4
- package/entry/SKILL.md +34 -0
- package/icon.png +0 -0
- package/index.js +35 -47
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/native-api.mjs +326 -0
- package/native-contracts.js +195 -0
- package/native-execution.js +184 -0
- package/native-runner.mjs +107 -0
- package/native-state.js +67 -0
- package/native-tools.js +241 -0
- package/operations.js +1260 -0
- package/package.json +65 -51
- package/{skills → runtime}/datarc-access-permissions/SKILL.md +30 -30
- package/{skills → runtime}/datarc-access-permissions/references/api.md +31 -31
- package/{skills → runtime}/datarc-access-permissions/references/write-order.md +16 -16
- package/{skills → runtime}/datarc-analysis-report/SKILL.md +125 -125
- package/{skills → runtime}/datarc-analysis-report/agents/openai.yaml +6 -6
- package/{skills → runtime}/datarc-analysis-report/references/analyst-frameworks.md +215 -215
- package/{skills → runtime}/datarc-analysis-report/references/api-contracts.md +478 -478
- package/{skills → runtime}/datarc-analysis-report/references/direct-card-fallback-design.md +66 -66
- package/{skills → runtime}/datarc-analysis-report/references/human-in-the-loop.md +142 -142
- package/{skills → runtime}/datarc-analysis-report/references/loop-personalization-policy.md +138 -138
- package/{skills → runtime}/datarc-analysis-report/references/manifest-example.json +779 -779
- package/{skills → runtime}/datarc-analysis-report/references/narrative-schema.md +160 -160
- package/{skills → runtime}/datarc-analysis-report/references/question-syntax.md +151 -151
- package/{skills → runtime}/datarc-analysis-report/scripts/run_analysis_report.py +2225 -2225
- package/{skills → runtime}/datarc-analysis-report/scripts/run_dataseek_cards.py +1914 -1914
- package/{skills → runtime}/datarc-analysis-report/scripts/test_run_analysis_report.py +5295 -5295
- package/{skills → runtime}/datarc-data-search/SKILL.md +243 -243
- package/{skills → runtime}/datarc-data-search/scripts/calculate.py +116 -116
- package/{skills → runtime}/datarc-data-search/scripts/data-search.mjs +628 -628
- package/{skills/datarc-dataseek-search → runtime/datarc-data-search}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-data-search/scripts/search-result.mjs +211 -211
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/SKILL.md +59 -59
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/artifacts.md +36 -36
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/equivalence.md +30 -30
- package/{skills/datarc-data-search → runtime/datarc-dataseek-batch-evaluation}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/scripts/dataseek-batch-evaluation.mjs +1020 -1020
- package/{skills → runtime}/datarc-dataseek-search/SKILL.md +96 -96
- package/{skills/datarc-dataseek-batch-evaluation → runtime/datarc-dataseek-search}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-search/scripts/dataseek-search.mjs +257 -257
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/SKILL.md +44 -44
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/evals/evals.json +165 -165
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/dataset.md +77 -77
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/input-and-resolution.md +93 -93
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/interventions.md +64 -64
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/knowledge-and-prompts.md +47 -47
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/rollback.md +11 -11
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/verification-and-rollback.md +95 -95
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/scripts/semantic-debugging.mjs +29 -29
- package/{skills → runtime}/datarc-dataseek-testset-generation/SKILL.md +47 -47
- package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/dataseek-testset-generation.mjs +526 -526
- package/{skills → runtime}/datarc-datasource/SKILL.md +97 -97
- package/{skills → runtime}/datarc-oauth/SKILL.md +50 -50
- package/{skills → runtime}/datarc-oauth/scripts/auth.mjs +192 -192
- package/{skills → runtime}/datarc-oauth/scripts/credentials.mjs +237 -237
- package/{skills → runtime}/datarc-report-add-card/SKILL.md +90 -90
- package/{skills → runtime}/datarc-report-add-card/agents/openai.yaml +4 -4
- package/runtime/datarc-report-add-card/scripts/datarc-client.mjs +464 -0
- package/{skills → runtime}/datarc-report-add-card/scripts/report-card.mjs +439 -439
- package/{skills → runtime}/datarc-semantic-alias/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-alias/scripts/alias-plan.mjs +422 -422
- package/{skills → runtime}/datarc-semantic-alias/scripts/alias.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-calibration/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration-plan.mjs +683 -683
- package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-core/SKILL.md +12 -12
- package/{skills → runtime}/datarc-semantic-core/scripts/artifact-journal.mjs +853 -830
- package/{skills → runtime}/datarc-semantic-core/scripts/canonical.mjs +48 -48
- package/{skills → runtime}/datarc-semantic-core/scripts/case-model.mjs +608 -608
- package/{skills → runtime}/datarc-semantic-core/scripts/cli.mjs +180 -180
- package/{skills → runtime}/datarc-semantic-core/scripts/datarc-client.mjs +180 -180
- package/{skills → runtime}/datarc-semantic-core/scripts/interpretation-pairs.mjs +57 -57
- package/{skills → runtime}/datarc-semantic-core/scripts/interventions.mjs +693 -693
- package/{skills → runtime}/datarc-semantic-core/scripts/live-resolution.mjs +305 -305
- package/{skills → runtime}/datarc-semantic-core/scripts/model-scope.mjs +49 -49
- package/{skills → runtime}/datarc-semantic-core/scripts/reproduction.mjs +330 -330
- package/{skills → runtime}/datarc-semantic-core/scripts/semantic-cli.mjs +799 -740
- package/{skills → runtime}/datarc-semantic-core/scripts/shared.mjs +312 -312
- package/{skills → runtime}/datarc-semantic-core/scripts/verification.mjs +1111 -1014
- package/{skills → runtime}/datarc-semantic-dataset/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-plan.mjs +749 -749
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-preflight.mjs +813 -813
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-knowledge/SKILL.md +38 -38
- package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-drafts.md +61 -61
- package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-generation.json +16 -16
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-draft.mjs +347 -347
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-plan.mjs +848 -848
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge.mjs +31 -31
- package/{skills → runtime}/datarc-semantic-prompt/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt-plan.mjs +598 -447
- package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt.mjs +15 -15
- package/{skills → runtime}/datarc-semantic-synonym/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym-plan.mjs +688 -688
- package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym.mjs +11 -11
- package/{skills → runtime}/datarc-viz-analysis-report/SKILL.md +108 -108
- package/{skills → runtime}/datarc-viz-analysis-report/assets/LICENSE-echarts.md +8 -8
- package/{skills → runtime}/datarc-viz-analysis-report/assets/echarts.min.js +45 -45
- package/{skills → runtime}/datarc-viz-analysis-report/references/api-contracts.md +163 -163
- package/{skills → runtime}/datarc-viz-analysis-report/references/derivation-log.md +157 -157
- package/{skills → runtime}/datarc-viz-analysis-report/references/evidence-framework.md +76 -76
- package/{skills → runtime}/datarc-viz-analysis-report/references/html-template.md +92 -92
- package/{skills → runtime}/datarc-viz-analysis-report/references/provenance-format.md +56 -56
- package/{skills → runtime}/datarc-viz-analysis-report/references/question-syntax.md +151 -151
- package/{skills → runtime}/datarc-viz-analysis-report/scripts/render_viz_report.py +1708 -1708
- package/{skills → runtime}/datarc-viz-analysis-report/scripts/test_render_viz_report.py +964 -964
- package/{skills → runtime}/datarc-workspace-configuration/SKILL.md +59 -59
- package/{skills → runtime}/datarc-workspace-configuration/references/artifacts.md +75 -75
- package/{skills → runtime}/datarc-workspace-configuration/references/verification.md +20 -20
- package/{skills → runtime}/datarc-workspace-configuration/scripts/configuration.mjs +722 -662
- package/{skills → runtime}/datarc-workspace-context/SKILL.md +43 -43
- package/{skills → runtime}/datarc-workspace-context/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-context/scripts/datarc-client.mjs +31 -31
- package/{skills → runtime}/datarc-workspace-context/scripts/query-display.mjs +114 -114
- package/{skills → runtime}/datarc-workspace-context/scripts/workspace-context.mjs +58 -58
- package/{skills → runtime}/datarc-workspace-custom-tables/SKILL.md +89 -89
- package/{skills → runtime}/datarc-workspace-custom-tables/scripts/datarc-client.mjs +165 -165
- package/{skills → runtime}/datarc-workspace-custom-tables/scripts/workspace-custom-tables.mjs +601 -601
- package/{skills → runtime}/datarc-workspace-keywords/SKILL.md +197 -197
- package/{skills → runtime}/datarc-workspace-keywords/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-keywords/references/api-fields.md +79 -79
- package/{skills → runtime}/datarc-workspace-keywords/references/derived-measures.md +177 -177
- package/{skills → runtime}/datarc-workspace-keywords/scripts/datarc-client.mjs +145 -145
- package/{skills → runtime}/datarc-workspace-keywords/scripts/workspace-keywords.mjs +2421 -2421
- package/{skills → runtime}/datarc-workspace-membership/SKILL.md +29 -29
- package/{skills → runtime}/datarc-workspace-membership/references/api.md +19 -19
- package/{skills → runtime}/datarc-workspace-modeling/SKILL.md +209 -209
- package/{skills → runtime}/datarc-workspace-modeling/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-modeling/references/join-preview.md +38 -38
- package/{skills → runtime}/datarc-workspace-modeling/references/model-plan.md +300 -300
- package/{skills → runtime}/datarc-workspace-modeling/references/model-tags.md +95 -95
- package/{skills → runtime}/datarc-workspace-modeling/references/modeling-contract.json +29 -29
- package/{skills → runtime}/datarc-workspace-modeling/references/modeling-fixtures.json +2423 -2423
- package/{skills → runtime}/datarc-workspace-modeling/scripts/datarc-client.mjs +137 -137
- package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-model-tags.mjs +238 -238
- package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-modeling.mjs +1261 -1261
- package/skills-provider.js +51 -0
- package/workflow-index.json +434 -0
- package/icon.svg +0 -4
- package/skills/datarc-report-add-card/scripts/datarc-client.mjs +0 -464
- package/skills-index.json +0 -194
package/index.js
CHANGED
|
@@ -1,66 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as entryProvider from './skills-provider.js';
|
|
2
|
+
import * as nativeTools from './native-tools.js';
|
|
3
3
|
|
|
4
|
-
export const inject = ['skills', 'agentPresets'];
|
|
4
|
+
export const inject = ['skills', 'agentPresets', 'tools', 'sessionProjections'];
|
|
5
5
|
|
|
6
|
-
// DSH provides the skill registry and model-facing loader in its standard profiles.
|
|
7
6
|
export async function* apply(ctx) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return entries.map((entry) => ({
|
|
13
|
-
...entry,
|
|
14
|
-
provider: 'datarc-skills',
|
|
15
|
-
source: 'bundled',
|
|
16
|
-
rank: 600,
|
|
17
|
-
locator: entry.name,
|
|
18
|
-
path: fileURLToPath(new URL(`./skills/${entry.name}/SKILL.md`, import.meta.url)),
|
|
19
|
-
resourceBase: {
|
|
20
|
-
kind: 'directory',
|
|
21
|
-
path: fileURLToPath(new URL(`./skills/${entry.name}/`, import.meta.url)),
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
},
|
|
25
|
-
async get(candidate, { signal } = {}) {
|
|
26
|
-
if (!/^datarc-[a-z0-9]+(?:-[a-z0-9]+)*$/.test(candidate.locator) || candidate.locator !== candidate.name) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
const file = new URL(`./skills/${candidate.locator}/SKILL.md`, import.meta.url);
|
|
30
|
-
const text = await readFile(file, { encoding: 'utf8', signal });
|
|
31
|
-
const { locator, rank, ...definition } = candidate;
|
|
32
|
-
return { ...definition, content: text.replace(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/, '') };
|
|
33
|
-
},
|
|
34
|
-
}));
|
|
35
|
-
const oauth = await readFile(new URL('./skills/datarc-oauth/SKILL.md', import.meta.url), 'utf8');
|
|
36
|
-
const oauthPath = fileURLToPath(new URL('./skills/datarc-oauth/', import.meta.url));
|
|
7
|
+
// A single model-invocable entry is available in Standard too. Detailed business
|
|
8
|
+
// instructions are private resources, and operation schemas activate per task.
|
|
9
|
+
await ctx.plugin(entryProvider);
|
|
10
|
+
await ctx.plugin(nativeTools);
|
|
37
11
|
yield await ctx.agentPresets.register({
|
|
38
12
|
id: 'datarc',
|
|
39
13
|
name: '北极九章',
|
|
40
|
-
description:
|
|
14
|
+
description: [
|
|
15
|
+
'北极九章专属数据分析预设:自然语言查数、连续追问、生成系统或 HTML 报告,以及按权限管理模型、成员和语义配置。',
|
|
16
|
+
'从工作台新建分析时自动选用;也可在新会话发送首条消息前手动选择。统一入口由模型自动加载,操作通过原生业务工具执行,无需指定技能或使用斜杠命令。',
|
|
17
|
+
'仅注册一个业务入口,详细流程按需读取;使用原生工具执行器。本地文件与终端仍受 DSH 权限控制,业务操作仍需登录、服务端授权和必要确认。',
|
|
18
|
+
].join('\n\n'),
|
|
41
19
|
plugins: [
|
|
42
20
|
{
|
|
43
21
|
name: '@deepseek-ai/dsh-persona',
|
|
44
22
|
config: {
|
|
45
23
|
prefix: [
|
|
46
|
-
'你是北极九章(datarc
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'认证能力资源目录:' + oauthPath,
|
|
56
|
-
oauth.replace(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/, ''),
|
|
24
|
+
'你是北极九章(datarc)业务数据分析助手。用户只描述业务目标,无需知道技能、工具、预设或命令。',
|
|
25
|
+
'当前会话实际使用北极九章(datarc)专属预设,平台已由该选择确认。未另行指定平台的普通业务问数默认使用北极九章服务及原生工具;首次问数也不重复询问确认数据平台。这不代表服务网址、授权、业务工作区、模型或口径已确认,缺失时仍按流程确认。',
|
|
26
|
+
'用户明确改用其他平台或本地文件时,遵从用户选择,不强行使用北极九章工具。本预设身份来自宿主实际挂载的专属 persona,不从用户文本、前端显示名称或本地工作目录推定预设。',
|
|
27
|
+
'处理北极九章业务任务时,先加载唯一入口 datarc-assistant,再使用 datarc_guide 读取当前任务所需的内部流程。原生业务工具按任务域在下一步骤提供;不要把guide与尚未开放的业务操作放在同一调用批次。',
|
|
28
|
+
'北极九章业务操作必须使用原生 datarc_* 工具,不改用shell手工调用内部脚本或拼接API。终端与文件工具仅用于必要的本地交付和依赖诊断,不绕过权限拒绝或确认。',
|
|
29
|
+
'按用户目标确认业务工作区、模型与口径,复用本会话已确认的上下文。先检查已有授权;缺失时通过原生认证工具引导网页授权,不索要令牌。',
|
|
30
|
+
'写操作先说明目标与影响,遵循计划、预检、真实用户确认及写后回读。不得代答确认、把CLI确认字段当授权、自动重放超时或结果未知的写入。',
|
|
31
|
+
'后台jobId不等于业务完成,使用job_output跟踪到终态;需要取消时使用job_kill并核查服务端状态。输出报告或导出后核验文件,再用present交付。',
|
|
32
|
+
'本地工作文件夹不是业务工作区。使用当前会话实际目录保存配置和交付,不在插件安装目录写入凭据;保护密码、令牌和独立开放API密钥。',
|
|
57
33
|
].join('\n\n'),
|
|
58
34
|
},
|
|
59
35
|
},
|
|
60
|
-
{ name:
|
|
36
|
+
{ name: '@deepseek-ai/dsh-tool-executor-native' },
|
|
37
|
+
{
|
|
38
|
+
name: process.platform === 'win32' ? '@deepseek-ai/dsh-tool-pwsh' : '@deepseek-ai/dsh-tool-bash',
|
|
39
|
+
},
|
|
61
40
|
{ name: '@deepseek-ai/dsh-tool-jobs' },
|
|
62
41
|
{ name: '@deepseek-ai/dsh-tool-fs' },
|
|
63
|
-
{
|
|
42
|
+
{
|
|
43
|
+
name: 'cordis:group',
|
|
44
|
+
group: true,
|
|
45
|
+
isolate: { skills: true },
|
|
46
|
+
config: [
|
|
47
|
+
{ name: '@deepseek-ai/dsh-skill' },
|
|
48
|
+
{ name: '@arcticdata/dsh-datarc-assistant/skills-provider' },
|
|
49
|
+
{ name: '@deepseek-ai/dsh-tool-skill' },
|
|
50
|
+
],
|
|
51
|
+
},
|
|
64
52
|
{ name: '@deepseek-ai/dsh-time-context' },
|
|
65
53
|
{ name: '@deepseek-ai/dsh-tool-ask-user' },
|
|
66
54
|
{ name: '@deepseek-ai/dsh-tool-present' },
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "
|
|
4
|
-
"description": "
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Arctic Data",
|
|
4
|
+
"description": "For DSH >=0.2.2-rc.5 <0.3.0-0. Select a local folder in the workbench, then continue or create an analysis. Examples and drafts are never sent automatically. A local folder is not a business workspace. The single model-invocable datarc-assistant entry loads the original 24 internal workflows; guide activation exposes domain tools on the next model step without slash commands or taking over unrelated BI/local-data tasks. Dedicated sessions use the Native executor without changing the default preset; PTC Standard wrappers are unsupported. Tools run original CLI scripts and fixed HTTP endpoints through the caller's DSH pwsh/bash sandbox, preserving toolSet admission, working directory, dependencies, jobs and cancellation; business execution never bypasses the Host boundary or a refusal. Inputs, outputs, workflow and confirmation timing follow the original skills. The assistant obtains user approval at the original points and does not ask again for each call within an approved scope. No added signed receipts or business state machines are required. Existing semantic CLI planHash, journals and verification remain. Custom calculations run normal Python files with imports, functions and loops, including the original calculate.load_series checks, not an expression DSL. Existing browser authorization and folder credentials are reused without collecting passwords or tokens in chat. Permission OpenAPI actions require an independent key; business source-detail endpoints use administrator login, never the OpenAPI key. Questions and tool results may be sent to the configured model; business requests go to the configured Arctic Data service. DSH and server permissions still apply. Background handles do not prove business acceptance; reconcile uncertain writes before retrying. Disabling does not delete history, credentials, reports or private temporary results, cancel requests or roll back changes. Full service and UI acceptance requires a separately authorized environment."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "北极九章",
|
|
4
|
-
"description": "
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "北极九章",
|
|
4
|
+
"description": "适用DSH >=0.2.2-rc.5 <0.3.0-0。左侧工作台显式选择本地文件夹,继续或新建分析;示例和草稿不自动发送,本地目录不是业务工作区。单一自动入口datarc-assistant按任务读取原24项内部流程,通过guide在下一模型步骤开放对应领域工具,不提供斜杠命令,不接管其他BI或本地数据任务。专属预设使用Native executor,不改变默认预设;PTC标准wrapper不支持此执行路径。工具在调用者DSH pwsh/bash沙箱中运行原CLI和固定API,保留toolSet、目录、依赖、取消和后台任务约束,不在Host直接执行业务或绕过拒绝。流程、确认时点、输入输出及异常处理沿用原skills;由助手展示影响并在原时点取得用户确认,获批范围内不逐调用重复审批,不另加签名回执或业务状态机。原语义CLI的planHash、journal和回读仍保留。自定义加工支持Python文件、正常imports/函数/循环以及原calculate.load_series的数据校验,不替换成表达式DSL。沿用网页授权与目录登录配置,不让用户在聊天提供密码或令牌;权限OpenAPI须独立密钥,业务来源接口使用管理员登录,两者不混用。问题和工具结果可能进入所配置模型,业务请求去已配置的北极九章服务;服务端和DSH权限仍然有效。后台任务句柄不是业务验收,未知写入先回读,不能自动重放。停用不删除历史、凭据、报告或私有临时结果,不自动取消或回滚。完整业务及UI验收需在授权环境另行进行。"
|
|
5
|
+
}
|
|
6
|
+
}
|
package/native-api.mjs
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// HTTP adaptation only. Original skill documents own workflow and confirmation.
|
|
2
|
+
import { mkdtemp, readFile, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { basename, extname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
import { API_DOMAINS } from './api-operations.js';
|
|
7
|
+
|
|
8
|
+
const SECRET_KEYS = new Set([
|
|
9
|
+
'password',
|
|
10
|
+
'pwd',
|
|
11
|
+
'token',
|
|
12
|
+
'imagetoken',
|
|
13
|
+
'accesstoken',
|
|
14
|
+
'refreshtoken',
|
|
15
|
+
'idtoken',
|
|
16
|
+
'datarctoken',
|
|
17
|
+
'datarcopenapikey',
|
|
18
|
+
'apikey',
|
|
19
|
+
'authorization',
|
|
20
|
+
'secret',
|
|
21
|
+
'clientsecret',
|
|
22
|
+
'credentials',
|
|
23
|
+
'databaseurl',
|
|
24
|
+
'connectionurl',
|
|
25
|
+
'qkey',
|
|
26
|
+
'sql',
|
|
27
|
+
]);
|
|
28
|
+
function error(message, code = 'INVALID_REQUEST') {
|
|
29
|
+
return Object.assign(new Error(message), { code });
|
|
30
|
+
}
|
|
31
|
+
function mask(value, secrets = []) {
|
|
32
|
+
if (Array.isArray(value)) return value.map((item) => mask(item, secrets));
|
|
33
|
+
if (value && typeof value === 'object')
|
|
34
|
+
return Object.fromEntries(
|
|
35
|
+
Object.entries(value).map(([key, item]) => [
|
|
36
|
+
key,
|
|
37
|
+
SECRET_KEYS.has(key.toLowerCase().replace(/[-_\s]/g, '')) ? (item ? '***' : item) : mask(item, secrets),
|
|
38
|
+
]),
|
|
39
|
+
);
|
|
40
|
+
if (typeof value !== 'string') return value;
|
|
41
|
+
for (const secret of secrets) if (secret) value = value.split(secret).join('***');
|
|
42
|
+
return value.replace(/\b[a-z][a-z\d+.-]*:\/\/[^\s<>"']*:[^\s<>"']*@[^\s<>"']+/gi, '[含凭据地址已隐藏]');
|
|
43
|
+
}
|
|
44
|
+
function object(value) {
|
|
45
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw error('请求体必须是原接口要求的JSON对象,请修正输入文件。');
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
async function json(c, path) {
|
|
49
|
+
const source = await readFile(resolve(c.cwd, path), 'utf8');
|
|
50
|
+
let value;
|
|
51
|
+
try {
|
|
52
|
+
value = JSON.parse(source);
|
|
53
|
+
} catch {
|
|
54
|
+
throw error('输入文件不是有效JSON,请修正格式后重试;错误预览不会回显其中的连接信息。', 'INVALID_INPUT');
|
|
55
|
+
}
|
|
56
|
+
return object(value);
|
|
57
|
+
}
|
|
58
|
+
async function artifact(c, value, label) {
|
|
59
|
+
const directory = await mkdtemp(join(tmpdir(), 'datarc-' + label + '-'));
|
|
60
|
+
const path = join(directory, 'result.json');
|
|
61
|
+
await writeFile(path, JSON.stringify(value), { flag: 'wx', mode: 0o600 });
|
|
62
|
+
return path;
|
|
63
|
+
}
|
|
64
|
+
async function context(domain, request, options) {
|
|
65
|
+
const cwd = resolve(options.cwd ?? process.cwd());
|
|
66
|
+
const env = { ...(options.env ?? process.env), DATARC_WORKSPACE_DIR: cwd };
|
|
67
|
+
const runtime = options.runtimeRoot ?? fileURLToPath(new URL('./runtime/', import.meta.url));
|
|
68
|
+
const auth = await import(pathToFileURL(join(runtime, 'datarc-oauth/scripts/credentials.mjs')).href);
|
|
69
|
+
const open = domain === 'permissions' && request.operation !== 'source_details';
|
|
70
|
+
const credentials = open
|
|
71
|
+
? {
|
|
72
|
+
endpoint: auth.normalizeEndpoint(env.DATARC_ENDPOINT),
|
|
73
|
+
token: env.DATARC_OPENAPI_KEY,
|
|
74
|
+
}
|
|
75
|
+
: auth.resolveCredentials({
|
|
76
|
+
env,
|
|
77
|
+
configPath: auth.credentialsPath(env, cwd),
|
|
78
|
+
});
|
|
79
|
+
if (!credentials.endpoint || typeof credentials.token !== 'string' || !credentials.token.trim() || /[\r\n]/.test(credentials.token))
|
|
80
|
+
throw error(
|
|
81
|
+
open ? '请在安全环境配置服务地址与独立DATARC_OPENAPI_KEY,并先核对scopes;勿在聊天粘贴密钥。' : '请先按原登录流程取得可用业务凭据。',
|
|
82
|
+
'AUTH_REQUIRED',
|
|
83
|
+
);
|
|
84
|
+
if ((open && credentials.token === env.DATARC_TOKEN) || (!open && credentials.token === env.DATARC_OPENAPI_KEY))
|
|
85
|
+
throw error('业务登录令牌与独立开放密钥不能互相替代,请核对安全配置。', 'AUTH_REQUIRED');
|
|
86
|
+
const secrets = [credentials.token, env.DATARC_TOKEN, env.DATARC_OPENAPI_KEY].filter(Boolean);
|
|
87
|
+
const c = { cwd, env, secrets, options, request: undefined };
|
|
88
|
+
c.request = async (method, path, params = {}) => {
|
|
89
|
+
options.signal?.throwIfAborted();
|
|
90
|
+
if (options.client) return options.client.request(method, path, params);
|
|
91
|
+
const url = new URL(credentials.endpoint + path);
|
|
92
|
+
for (const [key, value] of Object.entries(params.query ?? {}))
|
|
93
|
+
if (value !== undefined) url.searchParams.set(key, typeof value === 'string' ? value : JSON.stringify(value));
|
|
94
|
+
const headers = {
|
|
95
|
+
Authorization: open ? 'Bearer ' + credentials.token : credentials.token,
|
|
96
|
+
};
|
|
97
|
+
if (params.language) headers['Accept-Language'] = params.language;
|
|
98
|
+
let body = params.form;
|
|
99
|
+
if (params.body !== undefined) {
|
|
100
|
+
headers['Content-Type'] = 'application/json';
|
|
101
|
+
body = JSON.stringify(params.body);
|
|
102
|
+
}
|
|
103
|
+
let response;
|
|
104
|
+
try {
|
|
105
|
+
response = await (options.fetch ?? globalThis.fetch)(url, {
|
|
106
|
+
method,
|
|
107
|
+
headers,
|
|
108
|
+
body,
|
|
109
|
+
redirect: 'error',
|
|
110
|
+
signal: options.signal,
|
|
111
|
+
});
|
|
112
|
+
} catch (cause) {
|
|
113
|
+
throw error('请求未确认完成,请核对网络及当前业务状态;写入结果未知时不要重新发送。', 'NETWORK_ERROR');
|
|
114
|
+
}
|
|
115
|
+
if (response.status === 204 && response.ok) return null;
|
|
116
|
+
let envelope;
|
|
117
|
+
try {
|
|
118
|
+
envelope = await response.json();
|
|
119
|
+
} catch {
|
|
120
|
+
throw error('服务未返回有效JSON,请核对服务状态,不重复未知写入。', 'INVALID_RESPONSE');
|
|
121
|
+
}
|
|
122
|
+
if (!response.ok || (open ? envelope.errcode !== 200 : envelope.status !== 'SUCCESS')) {
|
|
123
|
+
const failure = error(
|
|
124
|
+
String(mask(envelope.message ?? envelope.errmsg ?? '接口请求失败,请核对权限、参数和服务状态。', secrets)),
|
|
125
|
+
envelope.data?.code ?? 'API_ERROR',
|
|
126
|
+
);
|
|
127
|
+
failure.httpStatus = response.status;
|
|
128
|
+
failure.businessStatus = open ? envelope.errcode : envelope.status;
|
|
129
|
+
failure.details = mask(envelope.data, secrets);
|
|
130
|
+
throw failure;
|
|
131
|
+
}
|
|
132
|
+
return envelope.data ?? null;
|
|
133
|
+
};
|
|
134
|
+
return c;
|
|
135
|
+
}
|
|
136
|
+
function routePath(route, r) {
|
|
137
|
+
return route.path.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
138
|
+
const value = key === 'subject' ? { member: 'members', group: 'member-groups' }[r.target] : r[key];
|
|
139
|
+
if (value === undefined || value === null || String(value) === '') throw error('缺少路径参数' + key + ',请使用当前工作区已核对的对象。');
|
|
140
|
+
return encodeURIComponent(String(value));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function equalVisible(observed, expected) {
|
|
144
|
+
if (!expected || typeof expected !== 'object') return Object.is(observed, expected);
|
|
145
|
+
if (Array.isArray(expected))
|
|
146
|
+
return Array.isArray(observed) && expected.length === observed.length && expected.every((value, i) => equalVisible(observed[i], value));
|
|
147
|
+
return Object.entries(expected).every(([key, value]) => {
|
|
148
|
+
const normalized = key.toLowerCase().replace(/[-_\s]/g, '');
|
|
149
|
+
return (SECRET_KEYS.has(normalized) && !['databaseurl', 'connectionurl'].includes(normalized)) || equalVisible(observed?.[key], value);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function fieldPreferences(entries) {
|
|
153
|
+
const counts = new Map();
|
|
154
|
+
const visit = (value) => {
|
|
155
|
+
if (!value || typeof value !== 'object') return;
|
|
156
|
+
if (Array.isArray(value)) return value.forEach(visit);
|
|
157
|
+
if (typeof value.prop === 'string') {
|
|
158
|
+
const prop = value.prop.split('=', 1)[0].split('.', 1)[0];
|
|
159
|
+
if (/^[md][1-9]\d*$|^t(?:0|[1-9]\d*)$/.test(prop)) counts.set(prop, (counts.get(prop) ?? 0) + 1);
|
|
160
|
+
}
|
|
161
|
+
for (const [key, child] of Object.entries(value)) if (['tokens', 'units', 'data'].includes(key)) visit(child);
|
|
162
|
+
};
|
|
163
|
+
visit(entries);
|
|
164
|
+
return [...counts].map(([prop, uses]) => ({ prop, uses }));
|
|
165
|
+
}
|
|
166
|
+
async function privateResult(c, type, value) {
|
|
167
|
+
const result_file = await artifact(c, value, type);
|
|
168
|
+
if (type === 'report')
|
|
169
|
+
return {
|
|
170
|
+
report_file: result_file,
|
|
171
|
+
uid: value?.uid,
|
|
172
|
+
name: value?.name,
|
|
173
|
+
reportVersion: value?.reportVersion,
|
|
174
|
+
pinCount: value?.content?.length,
|
|
175
|
+
};
|
|
176
|
+
if (type === 'prompt')
|
|
177
|
+
return {
|
|
178
|
+
prompt_file: result_file,
|
|
179
|
+
promptVersion: value?.promptVersion,
|
|
180
|
+
modelAvailable: value?.modelAvailable,
|
|
181
|
+
variables: value?.variables,
|
|
182
|
+
};
|
|
183
|
+
if (type === 'task')
|
|
184
|
+
return {
|
|
185
|
+
task_file: result_file,
|
|
186
|
+
uid: value?.uid ?? value?.id,
|
|
187
|
+
status: value?.status,
|
|
188
|
+
resultStatus: value?.result?.status,
|
|
189
|
+
};
|
|
190
|
+
if (type === 'interpretation')
|
|
191
|
+
return {
|
|
192
|
+
result_file,
|
|
193
|
+
id: value?.id ?? value?.taskUid,
|
|
194
|
+
status: value?.status,
|
|
195
|
+
code: value?.code,
|
|
196
|
+
};
|
|
197
|
+
return {
|
|
198
|
+
result_file,
|
|
199
|
+
id: value?.id,
|
|
200
|
+
name: value?.name,
|
|
201
|
+
count: Array.isArray(value) ? value.length : undefined,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
async function uploadSop(c, route, r) {
|
|
205
|
+
const path = resolve(c.cwd, r.source_file),
|
|
206
|
+
info = await stat(path);
|
|
207
|
+
if (!info.isFile() || info.size < 1 || info.size >= 50 * 1024 * 1024 || !['.txt', '.md', '.docx', '.pdf'].includes(extname(path).toLowerCase()))
|
|
208
|
+
throw error('请提供原SOP流程允许的非空txt/md/docx/pdf文件,且小于50MB。');
|
|
209
|
+
const bytes = await readFile(path),
|
|
210
|
+
form = new FormData();
|
|
211
|
+
form.append('file', new Blob([bytes]), basename(path));
|
|
212
|
+
const collection = routePath(route, r);
|
|
213
|
+
const converted = await c.request('POST', collection + 'markitdown/', {
|
|
214
|
+
form,
|
|
215
|
+
language: r.language,
|
|
216
|
+
});
|
|
217
|
+
if (!converted || typeof converted.content !== 'string' || !converted.content.trim())
|
|
218
|
+
throw error('文档转换未返回正文,请核对原文件后重试;尚未创建SOP。', 'INVALID_RESPONSE');
|
|
219
|
+
// Scope was displayed and confirmed by the Agent; the original server checks its version.
|
|
220
|
+
return c.request('POST', collection, {
|
|
221
|
+
body: {
|
|
222
|
+
name: basename(path, extname(path)),
|
|
223
|
+
content: converted.content,
|
|
224
|
+
default_scope_version: r.default_scope_version,
|
|
225
|
+
},
|
|
226
|
+
language: r.language,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async function bodyFor(c, domain, definition, r) {
|
|
230
|
+
const kind = definition.route.body;
|
|
231
|
+
if (!kind || kind === 'sop-upload') return undefined;
|
|
232
|
+
let body = await json(c, r.candidate_file ?? r.input_file);
|
|
233
|
+
const remember = (value) => {
|
|
234
|
+
if (!value || typeof value !== 'object') return;
|
|
235
|
+
for (const [key, item] of Object.entries(value)) {
|
|
236
|
+
if (SECRET_KEYS.has(key.toLowerCase().replace(/[-_\s]/g, '')) && typeof item === 'string' && item) c.secrets.push(item);
|
|
237
|
+
else remember(item);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
remember(body);
|
|
241
|
+
if (kind === 'datasource' || kind === 'datasource-test') {
|
|
242
|
+
if (!Number.isSafeInteger(body.adapter) || body.adapter < 1 || body.adapter === 12)
|
|
243
|
+
throw error('请使用原流程确认的数据库adapter;内置数据仓库12不在配置范围。');
|
|
244
|
+
if (kind === 'datasource-test') {
|
|
245
|
+
const key = body.databaseConfig ? 'databaseConfig' : 'databaseUrl';
|
|
246
|
+
if (!body[key]) throw error('候选缺少有效连接信息,请核对数据库配置后验证。');
|
|
247
|
+
body = { adapter: body.adapter, [key]: body[key] };
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (kind === 'member' && body.role !== undefined && ![0, 1].includes(body.role))
|
|
251
|
+
throw error('原成员流程只设置普通用户0或管理员1;负责人转移须使用专门流程。');
|
|
252
|
+
if (kind === 'mapping' && r.csv_file !== undefined)
|
|
253
|
+
body = {
|
|
254
|
+
...body,
|
|
255
|
+
data: await readFile(resolve(c.cwd, r.csv_file), 'utf8'),
|
|
256
|
+
};
|
|
257
|
+
if (kind === 'report-task' && ![8, 11].includes(body.taskType)) throw error('原报告流程只使用taskType8取数和11本地洞察,请核对请求体。');
|
|
258
|
+
return body;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export async function execute(domain, request, options = {}) {
|
|
262
|
+
const definition = API_DOMAINS[domain]?.operations?.[request?.operation];
|
|
263
|
+
if (!definition?.route) throw error('该API动作未公布,请读取当前业务目录使用固定操作。', 'UNKNOWN_OPERATION');
|
|
264
|
+
const c = await context(domain, request, options),
|
|
265
|
+
route = definition.route;
|
|
266
|
+
try {
|
|
267
|
+
if (request.language !== undefined && !['zh-CN', 'en-US'].includes(request.language)) throw error('请沿用原报告流程确定的zh-CN或en-US语言。');
|
|
268
|
+
let value;
|
|
269
|
+
if (route.body === 'sop-upload') value = await uploadSop(c, route, request);
|
|
270
|
+
else {
|
|
271
|
+
const query = Object.fromEntries(
|
|
272
|
+
Object.entries(route.query ?? {})
|
|
273
|
+
.filter(([key]) => request[key] !== undefined)
|
|
274
|
+
.map(([key, target]) => [target, request[key]]),
|
|
275
|
+
);
|
|
276
|
+
if (route.private === 'history') {
|
|
277
|
+
query.offset ??= 0;
|
|
278
|
+
query.limit ??= 20;
|
|
279
|
+
}
|
|
280
|
+
if (domain === 'report' && request.operation === 'history') query.days = 30;
|
|
281
|
+
if (route.filters) query.filters = (await json(c, request.input_file)).filters;
|
|
282
|
+
const body = await bodyFor(c, domain, definition, request);
|
|
283
|
+
value = await c.request(route.method, routePath(route, request), {
|
|
284
|
+
query,
|
|
285
|
+
...(body === undefined ? {} : { body }),
|
|
286
|
+
...((request.language ?? body?.language) ? { language: request.language ?? body.language } : {}),
|
|
287
|
+
});
|
|
288
|
+
if (domain === 'datasource' && request.operation === 'validate' && (value === null || value === '' || value === undefined))
|
|
289
|
+
throw error('连接验证未返回版本,不能进入保存步骤;请核对配置后重新验证。', 'VALIDATION_FAILED');
|
|
290
|
+
}
|
|
291
|
+
if (route.private === 'history' && !Array.isArray(value))
|
|
292
|
+
throw error('历史列表响应不完整,请核对服务版本后重读,不能据此认定没有历史记录。', 'INVALID_RESPONSE');
|
|
293
|
+
if (route.private === 'history')
|
|
294
|
+
return {
|
|
295
|
+
ok: true,
|
|
296
|
+
data: {
|
|
297
|
+
count: Array.isArray(value) ? value.length : 0,
|
|
298
|
+
fieldUsage: fieldPreferences(value),
|
|
299
|
+
hasMore: Array.isArray(value) && value.length === (request.limit ?? 20),
|
|
300
|
+
maxRecommendationWeight: 0.15,
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
if (route.private) return { ok: true, data: await privateResult(c, route.private, value) };
|
|
304
|
+
if (domain === 'datasource' && request.operation === 'verify' && request.candidate_file)
|
|
305
|
+
return {
|
|
306
|
+
ok: true,
|
|
307
|
+
data: {
|
|
308
|
+
current: mask(value, c.secrets),
|
|
309
|
+
matches: equalVisible(value, await json(c, request.candidate_file)),
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
return { ok: true, data: mask(value, c.secrets) };
|
|
313
|
+
} catch (cause) {
|
|
314
|
+
options.signal?.throwIfAborted();
|
|
315
|
+
return {
|
|
316
|
+
ok: false,
|
|
317
|
+
error: {
|
|
318
|
+
code: cause.code ?? 'API_ERROR',
|
|
319
|
+
message: mask(String(cause.message), c.secrets),
|
|
320
|
+
...(cause.httpStatus === undefined ? {} : { httpStatus: cause.httpStatus }),
|
|
321
|
+
...(cause.businessStatus === undefined ? {} : { businessStatus: cause.businessStatus }),
|
|
322
|
+
...(cause.details === undefined ? {} : { details: cause.details }),
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { DOMAINS } from './operations.js';
|
|
2
|
+
import { API_DOMAINS } from './api-operations.js';
|
|
3
|
+
|
|
4
|
+
export const domains = Object.fromEntries(
|
|
5
|
+
[...new Set([...Object.keys(DOMAINS), ...Object.keys(API_DOMAINS)])].map((name) => [
|
|
6
|
+
name,
|
|
7
|
+
{
|
|
8
|
+
...DOMAINS[name],
|
|
9
|
+
...API_DOMAINS[name],
|
|
10
|
+
...(name === 'report'
|
|
11
|
+
? {
|
|
12
|
+
title: DOMAINS[name].title,
|
|
13
|
+
description: DOMAINS[name].description,
|
|
14
|
+
}
|
|
15
|
+
: {}),
|
|
16
|
+
workflows: [...new Set([...(DOMAINS[name]?.workflows ?? []), ...(API_DOMAINS[name]?.workflows ?? [])])],
|
|
17
|
+
operations: {
|
|
18
|
+
...DOMAINS[name]?.operations,
|
|
19
|
+
...API_DOMAINS[name]?.operations,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
]),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export function operationFor(domain, request) {
|
|
26
|
+
if (
|
|
27
|
+
!Object.hasOwn(domains, domain) ||
|
|
28
|
+
!request ||
|
|
29
|
+
typeof request !== 'object' ||
|
|
30
|
+
Array.isArray(request) ||
|
|
31
|
+
typeof request.operation !== 'string' ||
|
|
32
|
+
!Object.hasOwn(domains[domain].operations, request.operation)
|
|
33
|
+
) {
|
|
34
|
+
throw new Error('操作不存在。请先使用 datarc_guide 查看当前业务域公布的操作,再按参数说明重试。');
|
|
35
|
+
}
|
|
36
|
+
const operation = domains[domain].operations[request.operation];
|
|
37
|
+
for (const key of Object.keys(request)) {
|
|
38
|
+
if (key !== 'operation' && !Object.hasOwn(operation.parameters, key))
|
|
39
|
+
throw new Error(`参数 ${key} 不受支持。请按该操作的明确参数重试,不传入命令、凭据或任意接口。`);
|
|
40
|
+
}
|
|
41
|
+
for (const key of operation.required ?? []) {
|
|
42
|
+
if (!Object.hasOwn(request, key)) throw new Error(`缺少 ${key}。请先补齐当前操作的必要信息。`);
|
|
43
|
+
}
|
|
44
|
+
for (const [key, value] of Object.entries(request)) {
|
|
45
|
+
if (key === 'operation') continue;
|
|
46
|
+
validateValue(value, operation.parameters[key], key);
|
|
47
|
+
if (['workspace_id', 'project_id'].includes(key) && (!Number.isSafeInteger(value) || value < 1))
|
|
48
|
+
throw new Error(`${key} 必须是已确认的正整数工作区编号。请先按名称选择并校验工作区。`);
|
|
49
|
+
if (key === 'endpoint') {
|
|
50
|
+
let url;
|
|
51
|
+
try {
|
|
52
|
+
url = new URL(value);
|
|
53
|
+
} catch {
|
|
54
|
+
throw new Error('服务网址无效。请提供北极九章的 HTTP 或 HTTPS 服务入口。');
|
|
55
|
+
}
|
|
56
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search)
|
|
57
|
+
throw new Error('服务入口不能含凭据或查询参数。请提供服务网址,勿在参数中粘贴令牌;网页片段由原登录脚本处理。');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return operation;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function validateValue(value, schema, label) {
|
|
64
|
+
if (schema.oneOf) {
|
|
65
|
+
for (const variant of schema.oneOf) {
|
|
66
|
+
try {
|
|
67
|
+
validateValue(value, variant, label);
|
|
68
|
+
return;
|
|
69
|
+
} catch {}
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`${label} 类型无效,请保留原接口返回的版本类型。`);
|
|
72
|
+
}
|
|
73
|
+
const type = schema.type;
|
|
74
|
+
const valid =
|
|
75
|
+
type === 'array'
|
|
76
|
+
? Array.isArray(value)
|
|
77
|
+
: type === 'object'
|
|
78
|
+
? value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
79
|
+
: type === 'integer'
|
|
80
|
+
? Number.isSafeInteger(value)
|
|
81
|
+
: type === 'number'
|
|
82
|
+
? typeof value === 'number' && Number.isFinite(value)
|
|
83
|
+
: typeof value === type;
|
|
84
|
+
if (!valid || (schema.enum && !schema.enum.includes(value))) throw new Error(`${label} 类型或取值无效。请使用操作说明中的类型和允许值。`);
|
|
85
|
+
if (typeof value === 'string' && (value.includes('\0') || (schema.file && value === '-')))
|
|
86
|
+
throw new Error(`${label} 无效。请使用正常文本或已有本地文件路径,不使用标准输入占位符。`);
|
|
87
|
+
if (
|
|
88
|
+
typeof value === 'number' &&
|
|
89
|
+
((schema.minimum !== undefined && value < schema.minimum) || (schema.maximum !== undefined && value > schema.maximum))
|
|
90
|
+
)
|
|
91
|
+
throw new Error(`${label} 超出范围。请按操作说明调整后重试。`);
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
for (const item of value) validateValue(item, schema.items ?? { type: 'string' }, label);
|
|
94
|
+
}
|
|
95
|
+
if (type === 'object') {
|
|
96
|
+
for (const key of schema.required ?? []) if (!Object.hasOwn(value, key)) throw new Error(`${label}.${key} 缺失。请补齐后重试。`);
|
|
97
|
+
for (const [key, item] of Object.entries(value)) {
|
|
98
|
+
if (!Object.hasOwn(schema.properties ?? {}, key)) throw new Error(`${label}.${key} 不受支持。请使用操作公布的字段。`);
|
|
99
|
+
validateValue(item, schema.properties[key], `${label}.${key}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function publicSchema(parameter) {
|
|
105
|
+
const schema = {};
|
|
106
|
+
for (const key of ['type', 'description', 'enum', 'const', 'minimum', 'maximum']) if (parameter[key] !== undefined) schema[key] = parameter[key];
|
|
107
|
+
if (parameter.oneOf) schema.oneOf = parameter.oneOf.map(publicSchema);
|
|
108
|
+
if (parameter.items) schema.items = publicSchema(parameter.items);
|
|
109
|
+
if (parameter.properties)
|
|
110
|
+
schema.properties = Object.fromEntries(Object.entries(parameter.properties).map(([key, value]) => [key, publicSchema(value)]));
|
|
111
|
+
if (parameter.type === 'object') {
|
|
112
|
+
schema.additionalProperties = false;
|
|
113
|
+
schema.required = parameter.required ?? [];
|
|
114
|
+
}
|
|
115
|
+
return schema;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function requestSchema(domain) {
|
|
119
|
+
return {
|
|
120
|
+
oneOf: Object.entries(domains[domain].operations).map(([name, operation]) => ({
|
|
121
|
+
type: 'object',
|
|
122
|
+
additionalProperties: false,
|
|
123
|
+
description: operation.description ?? name,
|
|
124
|
+
properties: {
|
|
125
|
+
operation: { type: 'string', const: name },
|
|
126
|
+
...Object.fromEntries(Object.entries(operation.parameters).map(([key, value]) => [key, publicSchema(value)])),
|
|
127
|
+
},
|
|
128
|
+
required: ['operation', ...(operation.required ?? [])],
|
|
129
|
+
})),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function commandArguments(operation, request) {
|
|
134
|
+
const args = Array.isArray(operation.command) ? [...operation.command] : operation.command ? [operation.command] : [];
|
|
135
|
+
const positional = Object.entries(operation.parameters)
|
|
136
|
+
.filter(([, value]) => value.position !== undefined)
|
|
137
|
+
.sort((a, b) => a[1].position - b[1].position);
|
|
138
|
+
for (const [key] of positional) if (request[key] !== undefined) args.push(String(request[key]));
|
|
139
|
+
for (const [key, parameter] of Object.entries(operation.parameters)) {
|
|
140
|
+
if (request[key] === undefined || parameter.position !== undefined || !parameter.flag) continue;
|
|
141
|
+
if (parameter.switch) {
|
|
142
|
+
if (request[key]) args.push('--' + parameter.flag);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
for (const value of parameter.repeat ? request[key] : [request[key]]) args.push('--' + parameter.flag, String(value));
|
|
146
|
+
}
|
|
147
|
+
return args;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function isInputFile(key, parameter) {
|
|
151
|
+
return (
|
|
152
|
+
['string', 'array'].includes(parameter.type) &&
|
|
153
|
+
!parameter.switch &&
|
|
154
|
+
(parameter.file === true ||
|
|
155
|
+
(key.endsWith('_file') && key !== 'output_file') ||
|
|
156
|
+
key === 'input_files' ||
|
|
157
|
+
['from_result', 'current', 'base'].includes(key))
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const credentialKeys = new Set([
|
|
162
|
+
'token',
|
|
163
|
+
'accesstoken',
|
|
164
|
+
'refreshtoken',
|
|
165
|
+
'idtoken',
|
|
166
|
+
'datarctoken',
|
|
167
|
+
'apikey',
|
|
168
|
+
'openapikey',
|
|
169
|
+
'datarcopenapikey',
|
|
170
|
+
'authorization',
|
|
171
|
+
'password',
|
|
172
|
+
'passwd',
|
|
173
|
+
'pwd',
|
|
174
|
+
'secret',
|
|
175
|
+
'clientsecret',
|
|
176
|
+
'privatekey',
|
|
177
|
+
'secretkey',
|
|
178
|
+
'accesskey',
|
|
179
|
+
'awsaccesskeyid',
|
|
180
|
+
'awssecretaccesskey',
|
|
181
|
+
'devicecode',
|
|
182
|
+
'imagetoken',
|
|
183
|
+
'databaseurl',
|
|
184
|
+
'connectionurl',
|
|
185
|
+
'connectionstring',
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
export function redact(value, key = '') {
|
|
189
|
+
const normalized = key.replace(/[_-]/g, '').toLowerCase();
|
|
190
|
+
if (credentialKeys.has(normalized)) return '***';
|
|
191
|
+
if (Array.isArray(value)) return value.map((item) => redact(item));
|
|
192
|
+
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, redact(item, name)]));
|
|
193
|
+
if (typeof value === 'string') return value.replace(/(https?:\/\/)[^\s/@]+:[^\s/@]+@/gi, '$1***@');
|
|
194
|
+
return value;
|
|
195
|
+
}
|