@sparkelf/dsh-dataops-managed 0.3.31 → 0.3.33

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/lib/index.js CHANGED
@@ -3703,6 +3703,47 @@ const COLLECT_SKILL = {
3703
3703
  rank: BUNDLED_SKILL_RANK,
3704
3704
  locator: COLLECT_SKILL_FILE
3705
3705
  };
3706
+ /** Connector authoring skill: only superadmins hold `data:connector:authoring`. */
3707
+ const CONNECTOR_SKILL_NAME = "api-connector-authoring";
3708
+ const CONNECTOR_SKILL_FILE = new URL("../skills/api-connector-authoring/SKILL.md", import.meta.url);
3709
+ const CONNECTOR_SKILL_ROOT = fileURLToPath(new URL("../", import.meta.url));
3710
+ /** 该技能的门禁:只有持有 `data:connector:authoring` 的超管能看到(只对超管授权)。 */
3711
+ const CONNECTOR_SKILL_PERMISSION = "data:connector:authoring";
3712
+ const CONNECTOR_SKILL = {
3713
+ name: CONNECTOR_SKILL_NAME,
3714
+ metadata: { permissions: [CONNECTOR_SKILL_PERMISSION] },
3715
+ description: "从接口文档(OpenAPI / Swagger / 接口说明)创建 API Connector 并导入为接口资源时使用。包含文档解析、导入粒度判断、资源命名与目录治理、GenUI 预览和用户确认后才导入的流程。",
3716
+ invocation: {
3717
+ modelInvocable: true,
3718
+ userInvocable: true
3719
+ },
3720
+ provider: CONNECTOR_SKILL_NAME,
3721
+ source: "bundled",
3722
+ resourceBase: {
3723
+ kind: "directory",
3724
+ path: CONNECTOR_SKILL_ROOT
3725
+ },
3726
+ rank: BUNDLED_SKILL_RANK,
3727
+ locator: CONNECTOR_SKILL_FILE
3728
+ };
3729
+ /**
3730
+ * 当前 DataOps 身份是否允许看到连接器作者技能。
3731
+ *
3732
+ * 核心层对 provider 的列表是 fail-open 的:不认识的技能一律展示。所以门禁必须在这里做——
3733
+ * 没有权限时返回空列表,`get` 也拒绝,避免只靠 SKILL.md 里的 frontmatter 声明。
3734
+ */
3735
+ let connectorSkillAllowed = () => false;
3736
+ const connectorSkillProvider = {
3737
+ name: CONNECTOR_SKILL_NAME,
3738
+ list: () => Promise.resolve(connectorSkillAllowed() ? [CONNECTOR_SKILL] : []),
3739
+ async get() {
3740
+ if (!connectorSkillAllowed()) throw new Error("connector skill is not available for this account");
3741
+ return {
3742
+ ...CONNECTOR_SKILL,
3743
+ content: await readFile(CONNECTOR_SKILL_FILE, "utf8")
3744
+ };
3745
+ }
3746
+ };
3706
3747
  /** Serve the collection skill to the catalog. */
3707
3748
  const collectSkillProvider = {
3708
3749
  name: COLLECT_SKILL_NAME,
@@ -3726,6 +3767,7 @@ async function apply(ctx, config) {
3726
3767
  let mcpFiber;
3727
3768
  ctx.skills.registerProvider(() => querySkillProvider);
3728
3769
  ctx.skills.registerProvider(() => collectSkillProvider);
3770
+ ctx.skills.registerProvider(() => connectorSkillProvider);
3729
3771
  const ensureMcp = async () => {
3730
3772
  if (mcpFiber !== void 0 && mcpFiber.uid !== null) return;
3731
3773
  const fiber = ctx.plugin(McpClient, {
@@ -3855,16 +3897,54 @@ async function apply(ctx, config) {
3855
3897
  ctx.effect(() => ctx.webServer.register({
3856
3898
  kind: "exact",
3857
3899
  path: RESOURCE_TAB_CONFIG_PATH,
3858
- handler: (request, response) => {
3900
+ handler: async (request, response) => {
3859
3901
  const payload = resolveResourceTabConfig(request, config.webBaseUrl);
3902
+ let token;
3903
+ try {
3904
+ token = (await ctx.credentials.resolve(accessRef))?.value;
3905
+ } catch {
3906
+ token = void 0;
3907
+ }
3860
3908
  response.writeHead(200, {
3861
3909
  "content-type": "application/json; charset=utf-8",
3862
3910
  "cache-control": "no-store"
3863
3911
  });
3864
- response.end(JSON.stringify(payload));
3912
+ response.end(JSON.stringify(token === void 0 ? payload : {
3913
+ ...payload,
3914
+ token
3915
+ }));
3865
3916
  }
3866
3917
  }), "dataops-managed: resource tab config route");
3867
3918
  /**
3919
+ * Same-origin resource reads for the tab's native fallback.
3920
+ *
3921
+ * A DSH page served from its own origin (for example the workspace port) cannot open the
3922
+ * portal's `/embed/resources` iframe with a session: that document is cross-origin and its
3923
+ * sessionStorage token is unreachable. The tab then renders the list in React and reads the
3924
+ * same DataOps resources through this route, where the Host still owns the JWT.
3925
+ */
3926
+ ctx.effect(() => ctx.webServer.register({
3927
+ kind: "prefix",
3928
+ path: "/integrations/dataops/resources",
3929
+ handler: async (request, response) => {
3930
+ const method = (request.method ?? "GET").toUpperCase();
3931
+ const url = new URL(request.url ?? "/", "http://dsh.internal");
3932
+ const rest = url.pathname.slice(31).replace(/^\/+/u, "").replace(/\/+$/u, "");
3933
+ const preferenceWrite = /^\d+\/(?:favorite|pin)$/u.test(rest);
3934
+ if (method !== "GET" && !(preferenceWrite && (method === "PUT" || method === "DELETE"))) {
3935
+ response.writeHead(405, {
3936
+ allow: "GET, PUT, DELETE",
3937
+ "content-length": "0"
3938
+ });
3939
+ response.end();
3940
+ return;
3941
+ }
3942
+ const target = rest === "" ? "/api/resources" + (url.search || "") : "/api/resources/" + encodeURIComponent(rest) + (url.search || "");
3943
+ const result = await reviewApi.request(target, { method });
3944
+ writeJson(response, result.status, result.body);
3945
+ }
3946
+ }), "dataops-managed: resource list bridge");
3947
+ /**
3868
3948
  * The managed tool list follows the workspace's DataOps scope.
3869
3949
  *
3870
3950
  * `AiToolManager` registers only the skill/review tools the current principal can use and
@@ -3874,6 +3954,11 @@ async function apply(ctx, config) {
3874
3954
  * route's answer, because a role edit does not change the JWT but does change the scope.
3875
3955
  */
3876
3956
  const aiTools = new AiToolManager(ctx, reviewApi, resourceTabHub);
3957
+ connectorSkillAllowed = () => {
3958
+ const scope = aiTools.currentScope();
3959
+ if (scope === void 0) return false;
3960
+ return (scope.permissions ?? scope.permissionKeys ?? []).includes(CONNECTOR_SKILL_PERMISSION);
3961
+ };
3877
3962
  ctx.effect(() => () => aiTools.dispose(), "dataops-managed: skill and review tool disclosure");
3878
3963
  ctx.effect(() => ctx.on("credentials/reference-updated", (ref) => {
3879
3964
  if (String(ref) !== config.credentialRef) return;
@@ -4595,9 +4680,22 @@ async function apply(ctx, config) {
4595
4680
  kind: "exact",
4596
4681
  path: AUTH_STATE_PATH,
4597
4682
  handler: async (request, response) => {
4683
+ if (request.method === "POST") {
4684
+ const body = await readJson(request).catch(() => null);
4685
+ if (body?.state === "expired") noteExpired();
4686
+ else if (body?.state === "valid") noteAccepted();
4687
+ else {
4688
+ response.writeHead(400, { "content-length": "0" });
4689
+ response.end();
4690
+ return;
4691
+ }
4692
+ response.writeHead(204, { "cache-control": "no-store" });
4693
+ response.end();
4694
+ return;
4695
+ }
4598
4696
  if (request.method !== "GET") {
4599
4697
  response.writeHead(405, {
4600
- allow: "GET",
4698
+ allow: "GET, POST",
4601
4699
  "content-length": "0"
4602
4700
  });
4603
4701
  response.end();
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The tab's own data-catalog tree (168px).
3
+ *
4
+ * 全部 / 收藏 / 置顶 stay as they were. The catalog section mirrors the portal's folder tree:
5
+ * multi-root (数据中台 / 交投), expandable folders, counts and a recursive filter. Data comes
6
+ * from GET /resources/folder-tree through the Host bridge; the right-hand portal iframe only
7
+ * receives the resulting resource ids, so the portal page itself never renders its own sidebar
8
+ * in embed mode.
9
+ *
10
+ * @module client/ResourceCatalogSidebar
11
+ */
12
+ export interface ResourceFilter {
13
+ scope: 'all' | 'favorites' | 'pinned' | 'catalogNode';
14
+ nodeId?: number;
15
+ ids?: number[];
16
+ }
17
+ export declare function ResourceCatalogSidebar({ onFilter }: {
18
+ onFilter: (filter: ResourceFilter) => void;
19
+ }): import("react").JSX.Element;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Native resource page for the cross-origin right-sidebar tab.
3
+ *
4
+ * The card, badge and button geometry mirrors the portal's `/embed/resources` page
5
+ * (`DataOpsResourcesEmbedPage.vue`) so the tab keeps the product's existing look; only the
6
+ * data path changes (Host bridge instead of a portal iframe). The left column is the data
7
+ * catalog the product asks for: 全部 / 收藏 / 置顶 plus one row per catalog.
8
+ *
9
+ * @module client/ResourceListPanel
10
+ */
11
+ /** One resource row as `/api/resources` returns it. */
12
+ interface ResourceRow {
13
+ id: number;
14
+ urn?: string;
15
+ resourceType?: string;
16
+ chineseName?: string;
17
+ sourceSystem?: string;
18
+ sourceTable?: string;
19
+ sourceDept?: string;
20
+ rowCount?: number | null;
21
+ columnCount?: number;
22
+ accessLevel?: string;
23
+ aiVisible?: boolean;
24
+ catalog?: string;
25
+ remark?: string;
26
+ tags?: string[];
27
+ columns?: Array<{
28
+ name?: string;
29
+ chineseName?: string;
30
+ dataType?: string;
31
+ type?: string;
32
+ }>;
33
+ }
34
+ /** Card grid + data catalog sidebar. */
35
+ export declare function ResourceListPanel({ initialResourceId, portalBaseUrl, onInsertReference, }: {
36
+ initialResourceId?: number;
37
+ portalBaseUrl: string;
38
+ onInsertReference?: (resource: ResourceRow) => void;
39
+ }): import("react").JSX.Element;
40
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 「数据资源」tab 的图标。
3
+ *
4
+ * 以**组件函数**形式提供:sidebar 的 tab 图标契约是
5
+ * `typeof descriptor.icon === 'function' ? descriptor.icon(14) : descriptor.icon`,
6
+ * 传函数可以让 sidebar 自己决定尺寸。用 JSX 而不是 createElement,是为了和同仓
7
+ * 其它插件走同一套 React 运行时(跨运行时创建的元素不会被渲染)。
8
+ */
9
+ export declare function ResourceTabIcon({ size }: {
10
+ size?: number;
11
+ }): React.ReactElement;
@@ -103,6 +103,8 @@ export declare const en: {
103
103
  readonly permWaiting: "The permission-centre API is waiting for the backend (task-37).";
104
104
  readonly permResourceSkill: "Skill";
105
105
  readonly permResourceWorkflow: "Workflow";
106
+ readonly permResourceBuiltin: "Built-in skill";
107
+ readonly permUnshared: "Not shared";
106
108
  readonly permResourceKb: "Knowledge base";
107
109
  readonly permType: "Type";
108
110
  readonly permName: "Name";
@@ -69,16 +69,18 @@ export interface DepartmentRow {
69
69
  enabled?: boolean;
70
70
  updatedAt?: string;
71
71
  }
72
- /** One skill/workflow resource and its visibility scope. */
72
+ /** A resource scope value; `unshared` only applies to a platform built-in skill. */
73
+ export type ResourceScopeVisibility = ResourceVisibility | 'unshared';
74
+ /** One plaza skill/workflow or platform built-in skill and its visibility scope. */
73
75
  export interface ResourceScopeRow {
74
- kind: 'skill' | 'workflow';
76
+ kind: 'skill' | 'workflow' | 'builtin';
75
77
  id: string | number;
76
78
  name: string;
77
- ownerId?: string;
78
- ownerName?: string;
79
+ ownerId?: string | null;
80
+ ownerName?: string | null;
79
81
  departmentCode?: string | null;
80
- visibility: ResourceVisibility;
81
- reviewStatus?: ReviewStatus;
82
+ visibility: ResourceScopeVisibility;
83
+ reviewStatus?: ReviewStatus | 'unshared';
82
84
  updatedAt?: string;
83
85
  }
84
86
  /** Everything the permission centre renders in one read. */
@@ -77,6 +77,26 @@ export interface ReviewableSummary {
77
77
  export declare function normalizeReviewStatus(value: unknown): ReviewStatus;
78
78
  /** Treat a missing visibility as global: a shared row with no scope was visible to everyone. */
79
79
  export declare function normalizeVisibility(value: unknown): ResourceVisibility;
80
+ /** The resource-scope facts the permission centre needs to decide button availability. */
81
+ export interface ResourceScopeSubject {
82
+ kind: 'skill' | 'workflow' | 'builtin';
83
+ visibility: 'global' | 'department' | 'private' | 'unshared';
84
+ departmentCode?: string | null;
85
+ }
86
+ /**
87
+ * Whether this actor may edit one resource-scope row.
88
+ *
89
+ * Mirrors the backend policy: built-in skills are super-administrator only, global skills
90
+ * belong to administrators, and a department administrator edits department rows in their
91
+ * subtree (the list itself is already narrowed to that subtree).
92
+ * @param subject - the row's kind and current scope.
93
+ * @param actorRole - the caller's portal role.
94
+ * @returns the decision and, when denied, the reason shown on the disabled control.
95
+ */
96
+ export declare function canEditResourceScopeRow(subject: ResourceScopeSubject, actorRole: PortalRole): {
97
+ allowed: boolean;
98
+ reason?: string;
99
+ };
80
100
  /** Whether the caller may see and act on the review queue. */
81
101
  export declare function canReview(context: ReviewContext | null | undefined): boolean;
82
102
  /** Whether the caller may open the permission centre's write controls. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-dataops-managed",
3
- "version": "0.3.31",
3
+ "version": "0.3.33",
4
4
  "description": "DataOps JWT intake and credential-backed MCP tools for managed DeepSeek Harness workspaces.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",