@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
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: datarc-workspace-context
|
|
3
|
-
description: 北极九章(datarc)工作区名称发现与查询上下文技能。在任何查询、报告或配置任务尚未确定工作区时,先读取可访问工作区名称并让用户选择,内部解析 ID;选定后可读取模型、指标、维度及示例。不修改工作区或执行数据查询。
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Datarc 工作区选择与查询上下文
|
|
7
|
-
|
|
8
|
-
先用 datarc-oauth 从环境变量或用户凭据文件解析认证;令牌不进入命令参数或回复。固定 DATARC_WORKSPACE_DIR 为会话工作区绝对路径,再使用本 Skill 的绝对脚本路径执行,只使用只读接口。依赖本流程的业务技能需同级安装本技能;缺失时提示安装,不把寻找 ID 的任务转交给用户。
|
|
9
|
-
|
|
10
|
-
## 先按名称确定工作区
|
|
11
|
-
|
|
12
|
-
1. 优先采用用户本次指定的目标,其次复用本次对话同一认证上下文中的明确选择;首次选定时调用 workspace 实时校验。普通问数已在当前对话确认过工作区时,沿用其 ID 或该对话的结果引用,新查询仍由服务端检查数据权限;其他任务仍实时校验所选工作区。既无指定目标也无对话选择时先运行 default:有已保存的默认工作区且实时校验成功,直接采用并告知名称,不再次询问;返回 null 才进入名称选择。默认工作区校验失败按错误处理,不静默采用列表首项。服务或令牌改变后默认值不复用。用户主动提供 ID 或链接时可内部解析并校验,随后显示实际名称。
|
|
13
|
-
2. 用户给出名称时调用 workspaces --query。接口是名称/介绍的子串检索,不代表精确匹配;只有检索完成后的唯一精确名称匹配才可直接采用并告知名称。多项、模糊匹配或未给名称时,展示序号、名称和服务端实际返回的简短介绍,让用户回复名称或序号。默认每次展示最多 5 项,可继续翻页或用关键词缩小范围。
|
|
14
|
-
3. 未保存默认工作区时,登录态、历史选择和列表第一项仅为候选;即使仅返回一项,也展示名称请用户选择。选定并校验后,询问“是否将「名称」设为 datarc 默认工作区?下次将自动使用。”用户同意才运行 set-default --workspace-id <真实 ID> --confirm yes;拒绝或未答复则只用于当前任务,不保存。已有默认工作区且用户本次切换到其他工作区时,询问是否更改默认值;拒绝或未回复保留原默认值。相同目标不重复询问。
|
|
15
|
-
4. 同名项使用实际介绍或用户提供的工作区链接辅助区分;仍不能区分时说明情况,让用户补充业务用途或从产品页面复制目标链接。不要猜测或要求用户寻找、填写工作区 ID。
|
|
16
|
-
5. 用户选定后调用 workspace 实时校验,内部固定服务地址、账号上下文和工作区 ID,并把名称用于确认消息。向下游脚本传入 workspace-id/project-id/workspaceId 等原有参数,不能把展示序号当作 ID。不调用 change-project 等写接口;保存默认值只修改当前会话工作区的凭据文件,不改变产品账号的当前工作区。
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
node scripts/workspace-context.mjs default
|
|
20
|
-
node scripts/workspace-context.mjs workspaces --offset 0 --limit 20
|
|
21
|
-
node scripts/workspace-context.mjs workspaces --query "销售" --offset 0 --limit 20
|
|
22
|
-
node scripts/workspace-context.mjs workspace --workspace-id 12
|
|
23
|
-
# 仅在用户明确同意后保存;命令会再次校验可访问性
|
|
24
|
-
node scripts/workspace-context.mjs set-default --workspace-id 12 --confirm yes
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
workspaces 保持返回列表结构;每页最多 100 项。返回满页时按 offset 加 limit 继续读取,直到不足一页,不能把第一页当成全量或据此断定名称唯一。一次定位最多读取 20 页;仍未取完时请用户缩小名称关键词,不自动选择。无关键词时不发送 q,不把完整业务问题当成工作区名。
|
|
28
|
-
|
|
29
|
-
空列表:说明当前账号未找到匹配工作区;有关键词时可改关键词或列出可访问项,无关键词仍为空时请用户检查账号或联系管理员加入工作区。认证失败按 datarc-oauth 处理;无权访问所选工作区时停止并提示核对账号/申请权限,不能自动替换。网络或服务异常时说明失败并提示稍后重试,不能当作“没有工作区”。
|
|
30
|
-
|
|
31
|
-
## 选择后读取上下文
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
node scripts/workspace-context.mjs get --workspace-id 12
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
get 返回 workspace 和 models;未提供 ID 时拒绝请求并提示先按名称选择,不再自动读取列表第一项。输出封装为 {"ok":true,"data":...},失败为 {"ok":false,"error":...} 且非零退出。
|
|
38
|
-
|
|
39
|
-
只使用返回的模型、维度和指标;维度样例不代表完整枚举。实际查询交给数据搜索技能。工作区可访问不等于有数据权限或管理权限:查询继续检查建模就绪及数据权限;配置继续使用业务技能的管理权限、dry-run 和写入确认。尚未配置数据源或模型的工作区也能按名称选择,不用 configReady 作为配置任务的选择门槛。
|
|
40
|
-
|
|
41
|
-
## 共享的卡片展示脚本
|
|
42
|
-
|
|
43
|
-
数据搜索和 DataSeek 会话搜索共用 `scripts/query-display.mjs`。脚本从已有卡片提取业务列名和查询口径,由两个搜索入口调用,无需发起请求。工作区选择仍使用 `scripts/workspace-context.mjs`。
|
|
1
|
+
---
|
|
2
|
+
name: datarc-workspace-context
|
|
3
|
+
description: 北极九章(datarc)工作区名称发现与查询上下文技能。在任何查询、报告或配置任务尚未确定工作区时,先读取可访问工作区名称并让用户选择,内部解析 ID;选定后可读取模型、指标、维度及示例。不修改工作区或执行数据查询。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Datarc 工作区选择与查询上下文
|
|
7
|
+
|
|
8
|
+
先用 datarc-oauth 从环境变量或用户凭据文件解析认证;令牌不进入命令参数或回复。固定 DATARC_WORKSPACE_DIR 为会话工作区绝对路径,再使用本 Skill 的绝对脚本路径执行,只使用只读接口。依赖本流程的业务技能需同级安装本技能;缺失时提示安装,不把寻找 ID 的任务转交给用户。
|
|
9
|
+
|
|
10
|
+
## 先按名称确定工作区
|
|
11
|
+
|
|
12
|
+
1. 优先采用用户本次指定的目标,其次复用本次对话同一认证上下文中的明确选择;首次选定时调用 workspace 实时校验。普通问数已在当前对话确认过工作区时,沿用其 ID 或该对话的结果引用,新查询仍由服务端检查数据权限;其他任务仍实时校验所选工作区。既无指定目标也无对话选择时先运行 default:有已保存的默认工作区且实时校验成功,直接采用并告知名称,不再次询问;返回 null 才进入名称选择。默认工作区校验失败按错误处理,不静默采用列表首项。服务或令牌改变后默认值不复用。用户主动提供 ID 或链接时可内部解析并校验,随后显示实际名称。
|
|
13
|
+
2. 用户给出名称时调用 workspaces --query。接口是名称/介绍的子串检索,不代表精确匹配;只有检索完成后的唯一精确名称匹配才可直接采用并告知名称。多项、模糊匹配或未给名称时,展示序号、名称和服务端实际返回的简短介绍,让用户回复名称或序号。默认每次展示最多 5 项,可继续翻页或用关键词缩小范围。
|
|
14
|
+
3. 未保存默认工作区时,登录态、历史选择和列表第一项仅为候选;即使仅返回一项,也展示名称请用户选择。选定并校验后,询问“是否将「名称」设为 datarc 默认工作区?下次将自动使用。”用户同意才运行 set-default --workspace-id <真实 ID> --confirm yes;拒绝或未答复则只用于当前任务,不保存。已有默认工作区且用户本次切换到其他工作区时,询问是否更改默认值;拒绝或未回复保留原默认值。相同目标不重复询问。
|
|
15
|
+
4. 同名项使用实际介绍或用户提供的工作区链接辅助区分;仍不能区分时说明情况,让用户补充业务用途或从产品页面复制目标链接。不要猜测或要求用户寻找、填写工作区 ID。
|
|
16
|
+
5. 用户选定后调用 workspace 实时校验,内部固定服务地址、账号上下文和工作区 ID,并把名称用于确认消息。向下游脚本传入 workspace-id/project-id/workspaceId 等原有参数,不能把展示序号当作 ID。不调用 change-project 等写接口;保存默认值只修改当前会话工作区的凭据文件,不改变产品账号的当前工作区。
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
node scripts/workspace-context.mjs default
|
|
20
|
+
node scripts/workspace-context.mjs workspaces --offset 0 --limit 20
|
|
21
|
+
node scripts/workspace-context.mjs workspaces --query "销售" --offset 0 --limit 20
|
|
22
|
+
node scripts/workspace-context.mjs workspace --workspace-id 12
|
|
23
|
+
# 仅在用户明确同意后保存;命令会再次校验可访问性
|
|
24
|
+
node scripts/workspace-context.mjs set-default --workspace-id 12 --confirm yes
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
workspaces 保持返回列表结构;每页最多 100 项。返回满页时按 offset 加 limit 继续读取,直到不足一页,不能把第一页当成全量或据此断定名称唯一。一次定位最多读取 20 页;仍未取完时请用户缩小名称关键词,不自动选择。无关键词时不发送 q,不把完整业务问题当成工作区名。
|
|
28
|
+
|
|
29
|
+
空列表:说明当前账号未找到匹配工作区;有关键词时可改关键词或列出可访问项,无关键词仍为空时请用户检查账号或联系管理员加入工作区。认证失败按 datarc-oauth 处理;无权访问所选工作区时停止并提示核对账号/申请权限,不能自动替换。网络或服务异常时说明失败并提示稍后重试,不能当作“没有工作区”。
|
|
30
|
+
|
|
31
|
+
## 选择后读取上下文
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
node scripts/workspace-context.mjs get --workspace-id 12
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
get 返回 workspace 和 models;未提供 ID 时拒绝请求并提示先按名称选择,不再自动读取列表第一项。输出封装为 {"ok":true,"data":...},失败为 {"ok":false,"error":...} 且非零退出。
|
|
38
|
+
|
|
39
|
+
只使用返回的模型、维度和指标;维度样例不代表完整枚举。实际查询交给数据搜索技能。工作区可访问不等于有数据权限或管理权限:查询继续检查建模就绪及数据权限;配置继续使用业务技能的管理权限、dry-run 和写入确认。尚未配置数据源或模型的工作区也能按名称选择,不用 configReady 作为配置任务的选择门槛。
|
|
40
|
+
|
|
41
|
+
## 共享的卡片展示脚本
|
|
42
|
+
|
|
43
|
+
数据搜索和 DataSeek 会话搜索共用 `scripts/query-display.mjs`。脚本从已有卡片提取业务列名和查询口径,由两个搜索入口调用,无需发起请求。工作区选择仍使用 `scripts/workspace-context.mjs`。
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface:
|
|
2
|
-
display_name: "Datarc 工作区上下文"
|
|
3
|
-
short_description: "读取可查询模型、字段及维度示例,补充数据查询上下文"
|
|
4
|
-
default_prompt: "使用 $datarc-workspace-context 获取当前工作区的可查询数据上下文。"
|
|
1
|
+
interface:
|
|
2
|
+
display_name: "Datarc 工作区上下文"
|
|
3
|
+
short_description: "读取可查询模型、字段及维度示例,补充数据查询上下文"
|
|
4
|
+
default_prompt: "使用 $datarc-workspace-context 获取当前工作区的可查询数据上下文。"
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
|
|
2
|
-
export function required(args, key) {
|
|
3
|
-
if (!args[key]) throw new Error(`缺少参数 --${key}`);
|
|
4
|
-
return args[key];
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function createClient(options = {}) {
|
|
8
|
-
const { endpoint, token } = resolveCredentials(options);
|
|
9
|
-
if (!endpoint) throw new Error("未配置 DATARC_ENDPOINT");
|
|
10
|
-
if (!token) throw new Error("未配置 DATARC_TOKEN");
|
|
11
|
-
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
12
|
-
return {
|
|
13
|
-
async request(method, path, { query } = {}) {
|
|
14
|
-
const url = new URL(`${endpoint}${path}`);
|
|
15
|
-
for (const [key, value] of Object.entries(query ?? {})) url.searchParams.set(key, value);
|
|
16
|
-
const response = await fetchImpl(url, { method, headers: { Authorization: token } });
|
|
17
|
-
const payload = await response.json();
|
|
18
|
-
if (!response.ok || payload.status !== "SUCCESS") throw new Error(payload.message ?? `请求失败(HTTP ${response.status})`);
|
|
19
|
-
return payload.data;
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function runCli(main) {
|
|
25
|
-
try {
|
|
26
|
-
process.stdout.write(`${JSON.stringify({ ok: true, data: await main() }, null, 2)}\n`);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
process.stdout.write(`${JSON.stringify({ ok: false, error: { message: error.message } }, null, 2)}\n`);
|
|
29
|
-
process.exitCode = 1;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
|
|
2
|
+
export function required(args, key) {
|
|
3
|
+
if (!args[key]) throw new Error(`缺少参数 --${key}`);
|
|
4
|
+
return args[key];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function createClient(options = {}) {
|
|
8
|
+
const { endpoint, token } = resolveCredentials(options);
|
|
9
|
+
if (!endpoint) throw new Error("未配置 DATARC_ENDPOINT");
|
|
10
|
+
if (!token) throw new Error("未配置 DATARC_TOKEN");
|
|
11
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
12
|
+
return {
|
|
13
|
+
async request(method, path, { query } = {}) {
|
|
14
|
+
const url = new URL(`${endpoint}${path}`);
|
|
15
|
+
for (const [key, value] of Object.entries(query ?? {})) url.searchParams.set(key, value);
|
|
16
|
+
const response = await fetchImpl(url, { method, headers: { Authorization: token } });
|
|
17
|
+
const payload = await response.json();
|
|
18
|
+
if (!response.ok || payload.status !== "SUCCESS") throw new Error(payload.message ?? `请求失败(HTTP ${response.status})`);
|
|
19
|
+
return payload.data;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function runCli(main) {
|
|
25
|
+
try {
|
|
26
|
+
process.stdout.write(`${JSON.stringify({ ok: true, data: await main() }, null, 2)}\n`);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
process.stdout.write(`${JSON.stringify({ ok: false, error: { message: error.message } }, null, 2)}\n`);
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
// Shared by the two search skills through their workspace-context dependency.
|
|
2
|
-
export function queryDisplay(cards) {
|
|
3
|
-
return cards.map((card) => {
|
|
4
|
-
const cardSeries = card.data ?? [];
|
|
5
|
-
const explanations = card.explanations ?? [];
|
|
6
|
-
const series = cardSeries.map(({ columns }) => ({
|
|
7
|
-
columnNames: displayColumnNames(columns),
|
|
8
|
-
}));
|
|
9
|
-
// Follow OpenAPI's field recognition, using only this card's returned columns.
|
|
10
|
-
const returnedMeasures = new Set(
|
|
11
|
-
cardSeries
|
|
12
|
-
.flatMap(({ columns }) => columns ?? [])
|
|
13
|
-
.map(({ _nes }) => _nes ?? "")
|
|
14
|
-
.filter((field) => {
|
|
15
|
-
const prop = baseProp(field);
|
|
16
|
-
return (
|
|
17
|
-
/^m[1-9]\d*$/.test(prop) ||
|
|
18
|
-
(/^d[1-9]\d*$/.test(prop) && field.includes(".$"))
|
|
19
|
-
);
|
|
20
|
-
})
|
|
21
|
-
.map(baseProp),
|
|
22
|
-
);
|
|
23
|
-
const derivedMeasures = displayGroups(
|
|
24
|
-
returnedMeasureGroups(
|
|
25
|
-
explanations.flatMap(({ derive }) => derive ?? []),
|
|
26
|
-
returnedMeasures,
|
|
27
|
-
),
|
|
28
|
-
);
|
|
29
|
-
const scopes = explanations.map((scope) => ({
|
|
30
|
-
model: displayName(scope.model, scope.modelUid) || undefined,
|
|
31
|
-
columnNames: displayColumnNames(scope.columns),
|
|
32
|
-
measures: displayGroups(
|
|
33
|
-
returnedMeasureGroups(scope.measures ?? [], returnedMeasures),
|
|
34
|
-
),
|
|
35
|
-
dimensions: displayGroups(scope.dimensions),
|
|
36
|
-
dateFilters: displayDateFilters(scope.dateFilters),
|
|
37
|
-
filters: displayGroups(scope.filters),
|
|
38
|
-
having: displayGroups(scope.having),
|
|
39
|
-
order: displayGroups((scope.order ?? []).map(({ tokens }) => tokens)),
|
|
40
|
-
limit: displayGroups(scope.limit),
|
|
41
|
-
proportion: [
|
|
42
|
-
...new Set(
|
|
43
|
-
(scope.proportion ?? []).map(({ text }) => text).filter(Boolean),
|
|
44
|
-
),
|
|
45
|
-
],
|
|
46
|
-
}));
|
|
47
|
-
return { series, derivedMeasures, scopes };
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function displayColumnNames(columns) {
|
|
52
|
-
return (columns ?? []).map(({ _n, _nes }) => displayName(_n, _nes) || null);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function displayName(value, identifier) {
|
|
56
|
-
const text = value?.trim();
|
|
57
|
-
return text && text !== identifier ? text : "";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function displayGroups(groups) {
|
|
61
|
-
return uniqueDisplayValues(
|
|
62
|
-
(groups ?? [])
|
|
63
|
-
.map((tokens) =>
|
|
64
|
-
tokens.flatMap((token) => {
|
|
65
|
-
const name = displayName(token.word, token.prop);
|
|
66
|
-
return name ? [token.prefix, name].filter(Boolean) : [];
|
|
67
|
-
}),
|
|
68
|
-
)
|
|
69
|
-
.filter((group) => group.length),
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function displayDateFilters(groups) {
|
|
74
|
-
const filters = [];
|
|
75
|
-
for (const tokens of groups ?? []) {
|
|
76
|
-
let timeDimension;
|
|
77
|
-
let expression = [];
|
|
78
|
-
const ranges = [];
|
|
79
|
-
for (const { word, prop, onlyText, start, end } of tokens) {
|
|
80
|
-
const text = displayName(word, prop);
|
|
81
|
-
if (!onlyText && /^t(?:0|[1-9]\d*)$/.test(prop)) {
|
|
82
|
-
timeDimension = text || undefined;
|
|
83
|
-
} else if (onlyText && ((start && end) || text)) {
|
|
84
|
-
const actualRange = start && end ? { start, end } : { text };
|
|
85
|
-
ranges.push(
|
|
86
|
-
expression.length ? { expression, ...actualRange } : actualRange,
|
|
87
|
-
);
|
|
88
|
-
expression = [];
|
|
89
|
-
} else if (!onlyText && text) {
|
|
90
|
-
expression.push(text);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (expression.length) ranges.push({ expression });
|
|
94
|
-
if (timeDimension || ranges.length) filters.push({ timeDimension, ranges });
|
|
95
|
-
}
|
|
96
|
-
return uniqueDisplayValues(filters);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function uniqueDisplayValues(values) {
|
|
100
|
-
return [
|
|
101
|
-
...new Map(values.map((value) => [JSON.stringify(value), value])).values(),
|
|
102
|
-
];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function returnedMeasureGroups(groups, returnedMeasures) {
|
|
106
|
-
if (!returnedMeasures.size) return groups;
|
|
107
|
-
return groups.filter((tokens) =>
|
|
108
|
-
tokens.some(({ prop }) => returnedMeasures.has(baseProp(prop))),
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function baseProp(prop) {
|
|
113
|
-
return prop?.split(".", 1)[0];
|
|
114
|
-
}
|
|
1
|
+
// Shared by the two search skills through their workspace-context dependency.
|
|
2
|
+
export function queryDisplay(cards) {
|
|
3
|
+
return cards.map((card) => {
|
|
4
|
+
const cardSeries = card.data ?? [];
|
|
5
|
+
const explanations = card.explanations ?? [];
|
|
6
|
+
const series = cardSeries.map(({ columns }) => ({
|
|
7
|
+
columnNames: displayColumnNames(columns),
|
|
8
|
+
}));
|
|
9
|
+
// Follow OpenAPI's field recognition, using only this card's returned columns.
|
|
10
|
+
const returnedMeasures = new Set(
|
|
11
|
+
cardSeries
|
|
12
|
+
.flatMap(({ columns }) => columns ?? [])
|
|
13
|
+
.map(({ _nes }) => _nes ?? "")
|
|
14
|
+
.filter((field) => {
|
|
15
|
+
const prop = baseProp(field);
|
|
16
|
+
return (
|
|
17
|
+
/^m[1-9]\d*$/.test(prop) ||
|
|
18
|
+
(/^d[1-9]\d*$/.test(prop) && field.includes(".$"))
|
|
19
|
+
);
|
|
20
|
+
})
|
|
21
|
+
.map(baseProp),
|
|
22
|
+
);
|
|
23
|
+
const derivedMeasures = displayGroups(
|
|
24
|
+
returnedMeasureGroups(
|
|
25
|
+
explanations.flatMap(({ derive }) => derive ?? []),
|
|
26
|
+
returnedMeasures,
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
const scopes = explanations.map((scope) => ({
|
|
30
|
+
model: displayName(scope.model, scope.modelUid) || undefined,
|
|
31
|
+
columnNames: displayColumnNames(scope.columns),
|
|
32
|
+
measures: displayGroups(
|
|
33
|
+
returnedMeasureGroups(scope.measures ?? [], returnedMeasures),
|
|
34
|
+
),
|
|
35
|
+
dimensions: displayGroups(scope.dimensions),
|
|
36
|
+
dateFilters: displayDateFilters(scope.dateFilters),
|
|
37
|
+
filters: displayGroups(scope.filters),
|
|
38
|
+
having: displayGroups(scope.having),
|
|
39
|
+
order: displayGroups((scope.order ?? []).map(({ tokens }) => tokens)),
|
|
40
|
+
limit: displayGroups(scope.limit),
|
|
41
|
+
proportion: [
|
|
42
|
+
...new Set(
|
|
43
|
+
(scope.proportion ?? []).map(({ text }) => text).filter(Boolean),
|
|
44
|
+
),
|
|
45
|
+
],
|
|
46
|
+
}));
|
|
47
|
+
return { series, derivedMeasures, scopes };
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function displayColumnNames(columns) {
|
|
52
|
+
return (columns ?? []).map(({ _n, _nes }) => displayName(_n, _nes) || null);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function displayName(value, identifier) {
|
|
56
|
+
const text = value?.trim();
|
|
57
|
+
return text && text !== identifier ? text : "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function displayGroups(groups) {
|
|
61
|
+
return uniqueDisplayValues(
|
|
62
|
+
(groups ?? [])
|
|
63
|
+
.map((tokens) =>
|
|
64
|
+
tokens.flatMap((token) => {
|
|
65
|
+
const name = displayName(token.word, token.prop);
|
|
66
|
+
return name ? [token.prefix, name].filter(Boolean) : [];
|
|
67
|
+
}),
|
|
68
|
+
)
|
|
69
|
+
.filter((group) => group.length),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function displayDateFilters(groups) {
|
|
74
|
+
const filters = [];
|
|
75
|
+
for (const tokens of groups ?? []) {
|
|
76
|
+
let timeDimension;
|
|
77
|
+
let expression = [];
|
|
78
|
+
const ranges = [];
|
|
79
|
+
for (const { word, prop, onlyText, start, end } of tokens) {
|
|
80
|
+
const text = displayName(word, prop);
|
|
81
|
+
if (!onlyText && /^t(?:0|[1-9]\d*)$/.test(prop)) {
|
|
82
|
+
timeDimension = text || undefined;
|
|
83
|
+
} else if (onlyText && ((start && end) || text)) {
|
|
84
|
+
const actualRange = start && end ? { start, end } : { text };
|
|
85
|
+
ranges.push(
|
|
86
|
+
expression.length ? { expression, ...actualRange } : actualRange,
|
|
87
|
+
);
|
|
88
|
+
expression = [];
|
|
89
|
+
} else if (!onlyText && text) {
|
|
90
|
+
expression.push(text);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (expression.length) ranges.push({ expression });
|
|
94
|
+
if (timeDimension || ranges.length) filters.push({ timeDimension, ranges });
|
|
95
|
+
}
|
|
96
|
+
return uniqueDisplayValues(filters);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function uniqueDisplayValues(values) {
|
|
100
|
+
return [
|
|
101
|
+
...new Map(values.map((value) => [JSON.stringify(value), value])).values(),
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function returnedMeasureGroups(groups, returnedMeasures) {
|
|
106
|
+
if (!returnedMeasures.size) return groups;
|
|
107
|
+
return groups.filter((tokens) =>
|
|
108
|
+
tokens.some(({ prop }) => returnedMeasures.has(baseProp(prop))),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function baseProp(prop) {
|
|
113
|
+
return prop?.split(".", 1)[0];
|
|
114
|
+
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import { resolveCredentials, saveDefaultWorkspace } from "../../datarc-oauth/scripts/credentials.mjs";
|
|
2
|
-
import { createClient, runCli } from "./datarc-client.mjs";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
-
|
|
5
|
-
export async function execute(argv, options = {}) {
|
|
6
|
-
const [command, ...args] = argv;
|
|
7
|
-
const allowed = command === "workspaces" ? ["query", "offset", "limit"] : command === "set-default" ? ["workspace-id", "confirm"] : ["workspace-id"];
|
|
8
|
-
if (!["workspaces", "workspace", "get", "default", "set-default"].includes(command))
|
|
9
|
-
throw new Error("命令无效;请使用 workspaces 列出名称、workspace 校验所选工作区或 get 读取上下文");
|
|
10
|
-
const params = {};
|
|
11
|
-
for (let i = 0; i < args.length; i += 2) {
|
|
12
|
-
const key = args[i].slice(2);
|
|
13
|
-
if (
|
|
14
|
-
!args[i].startsWith("--") ||
|
|
15
|
-
!allowed.includes(key) ||
|
|
16
|
-
Object.hasOwn(params, key) ||
|
|
17
|
-
args[i + 1] === undefined ||
|
|
18
|
-
args[i + 1].startsWith("--")
|
|
19
|
-
)
|
|
20
|
-
throw new Error("参数缺失、重复或未知;请按技能中的命令示例补齐参数");
|
|
21
|
-
params[key] = args[i + 1];
|
|
22
|
-
}
|
|
23
|
-
if (command === "workspaces") {
|
|
24
|
-
const offset = integer(params.offset ?? "0", 0, Number.MAX_SAFE_INTEGER, "offset");
|
|
25
|
-
const limit = integer(params.limit ?? "20", 1, 100, "limit");
|
|
26
|
-
const client = options.client ?? createClient(options);
|
|
27
|
-
return client.request("GET", "/api/v2/account-projects/", {
|
|
28
|
-
query: { ...(params.query === undefined ? {} : { q: params.query }), offset, limit },
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (command === "default") {
|
|
32
|
-
if (Object.keys(params).length) throw new Error("default 不接受工作区参数;请直接调用 default 或使用 workspace 校验指定目标");
|
|
33
|
-
const saved = resolveCredentials(options).defaultWorkspace;
|
|
34
|
-
if (!saved) return null;
|
|
35
|
-
const client = options.client ?? createClient(options);
|
|
36
|
-
return client.request("GET", "/api/v2/account-projects/" + saved.id + "/");
|
|
37
|
-
}
|
|
38
|
-
if (command === "set-default" && params.confirm !== "yes") throw new Error("尚未确认保存默认工作区;请先取得用户明确同意,再传入 --confirm yes");
|
|
39
|
-
if (!params["workspace-id"]) throw new Error("尚未选择工作区;请先运行 workspaces 读取名称列表,让用户按名称或序号选择,再内部传入 --workspace-id");
|
|
40
|
-
const workspaceId = integer(params["workspace-id"], 1, Number.MAX_SAFE_INTEGER, "workspace-id");
|
|
41
|
-
const client = options.client ?? createClient(options);
|
|
42
|
-
const path = "/api/v2/account-projects/" + workspaceId + "/";
|
|
43
|
-
if (command === "set-default") {
|
|
44
|
-
const workspace = await client.request("GET", path);
|
|
45
|
-
if (Number(workspace?.id) !== workspaceId) throw new Error("工作区响应不匹配;请重新选择并校验工作区");
|
|
46
|
-
saveDefaultWorkspace({ id: workspaceId, name: workspace.name }, options);
|
|
47
|
-
return { id: workspaceId, name: workspace.name, saved: true };
|
|
48
|
-
}
|
|
49
|
-
return command === "workspace" ? client.request("GET", path) : client.request("GET", path + "agent-context/", { query: { format: "json" } });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function integer(value, min, max, name) {
|
|
53
|
-
if (!/^\d+$/.test(value) || !Number.isSafeInteger(Number(value)) || Number(value) < min || Number(value) > max)
|
|
54
|
-
throw new Error(name + " 参数无效;请使用 " + min + " 至 " + max + " 的整数,工作区编号应来自名称列表");
|
|
55
|
-
return Number(value);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) await runCli(() => execute(process.argv.slice(2)));
|
|
1
|
+
import { resolveCredentials, saveDefaultWorkspace } from "../../datarc-oauth/scripts/credentials.mjs";
|
|
2
|
+
import { createClient, runCli } from "./datarc-client.mjs";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
|
|
5
|
+
export async function execute(argv, options = {}) {
|
|
6
|
+
const [command, ...args] = argv;
|
|
7
|
+
const allowed = command === "workspaces" ? ["query", "offset", "limit"] : command === "set-default" ? ["workspace-id", "confirm"] : ["workspace-id"];
|
|
8
|
+
if (!["workspaces", "workspace", "get", "default", "set-default"].includes(command))
|
|
9
|
+
throw new Error("命令无效;请使用 workspaces 列出名称、workspace 校验所选工作区或 get 读取上下文");
|
|
10
|
+
const params = {};
|
|
11
|
+
for (let i = 0; i < args.length; i += 2) {
|
|
12
|
+
const key = args[i].slice(2);
|
|
13
|
+
if (
|
|
14
|
+
!args[i].startsWith("--") ||
|
|
15
|
+
!allowed.includes(key) ||
|
|
16
|
+
Object.hasOwn(params, key) ||
|
|
17
|
+
args[i + 1] === undefined ||
|
|
18
|
+
args[i + 1].startsWith("--")
|
|
19
|
+
)
|
|
20
|
+
throw new Error("参数缺失、重复或未知;请按技能中的命令示例补齐参数");
|
|
21
|
+
params[key] = args[i + 1];
|
|
22
|
+
}
|
|
23
|
+
if (command === "workspaces") {
|
|
24
|
+
const offset = integer(params.offset ?? "0", 0, Number.MAX_SAFE_INTEGER, "offset");
|
|
25
|
+
const limit = integer(params.limit ?? "20", 1, 100, "limit");
|
|
26
|
+
const client = options.client ?? createClient(options);
|
|
27
|
+
return client.request("GET", "/api/v2/account-projects/", {
|
|
28
|
+
query: { ...(params.query === undefined ? {} : { q: params.query }), offset, limit },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (command === "default") {
|
|
32
|
+
if (Object.keys(params).length) throw new Error("default 不接受工作区参数;请直接调用 default 或使用 workspace 校验指定目标");
|
|
33
|
+
const saved = resolveCredentials(options).defaultWorkspace;
|
|
34
|
+
if (!saved) return null;
|
|
35
|
+
const client = options.client ?? createClient(options);
|
|
36
|
+
return client.request("GET", "/api/v2/account-projects/" + saved.id + "/");
|
|
37
|
+
}
|
|
38
|
+
if (command === "set-default" && params.confirm !== "yes") throw new Error("尚未确认保存默认工作区;请先取得用户明确同意,再传入 --confirm yes");
|
|
39
|
+
if (!params["workspace-id"]) throw new Error("尚未选择工作区;请先运行 workspaces 读取名称列表,让用户按名称或序号选择,再内部传入 --workspace-id");
|
|
40
|
+
const workspaceId = integer(params["workspace-id"], 1, Number.MAX_SAFE_INTEGER, "workspace-id");
|
|
41
|
+
const client = options.client ?? createClient(options);
|
|
42
|
+
const path = "/api/v2/account-projects/" + workspaceId + "/";
|
|
43
|
+
if (command === "set-default") {
|
|
44
|
+
const workspace = await client.request("GET", path);
|
|
45
|
+
if (Number(workspace?.id) !== workspaceId) throw new Error("工作区响应不匹配;请重新选择并校验工作区");
|
|
46
|
+
saveDefaultWorkspace({ id: workspaceId, name: workspace.name }, options);
|
|
47
|
+
return { id: workspaceId, name: workspace.name, saved: true };
|
|
48
|
+
}
|
|
49
|
+
return command === "workspace" ? client.request("GET", path) : client.request("GET", path + "agent-context/", { query: { format: "json" } });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function integer(value, min, max, name) {
|
|
53
|
+
if (!/^\d+$/.test(value) || !Number.isSafeInteger(Number(value)) || Number(value) < min || Number(value) > max)
|
|
54
|
+
throw new Error(name + " 参数无效;请使用 " + min + " 至 " + max + " 的整数,工作区编号应来自名称列表");
|
|
55
|
+
return Number(value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) await runCli(() => execute(process.argv.slice(2)));
|