@sparkelf/dsh-dataops-managed 0.3.43 → 0.3.45

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
@@ -3196,6 +3196,59 @@ var AiToolManager = class {
3196
3196
  }
3197
3197
  };
3198
3198
  //#endregion
3199
+ //#region src/scoped-credential.ts
3200
+ /**
3201
+ * Fold a Session id into the credential-ref alphabet.
3202
+ *
3203
+ * Credential references are uppercase underscore tokens, and the MCP bridge derives the same name
3204
+ * from the Session id it is serving. Both sides use this function so they cannot drift.
3205
+ * @param baseRef - the workspace credential reference, for example `DATAOPS_ACCESS_TOKEN`.
3206
+ * @param sessionId - the room Session id.
3207
+ * @returns the scoped reference for that Session.
3208
+ */
3209
+ function scopedCredentialRef(baseRef, sessionId) {
3210
+ return `${baseRef}_S_${sessionId.toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "")}`;
3211
+ }
3212
+ /**
3213
+ * Mint one room's scoped token and store it.
3214
+ *
3215
+ * Failure is reported and swallowed: the room keeps working on the workspace credential, which is
3216
+ * the pre-connector behaviour, so a backend outage degrades authority instead of breaking chat.
3217
+ * @param deps - endpoint, credential store, and logger.
3218
+ * @param baseRef - the workspace credential reference the scoped name derives from.
3219
+ * @param sessionId - the room Session the token is minted for.
3220
+ * @param actorUserId - the DataOps user the room acts for.
3221
+ * @returns the stored reference, or undefined when minting failed.
3222
+ */
3223
+ async function mintScopedCredential(deps, baseRef, sessionId, actorUserId) {
3224
+ const ref = scopedCredentialRef(baseRef, sessionId);
3225
+ try {
3226
+ const result = await deps.request("/api/ai/workspace/scoped-token", {
3227
+ method: "POST",
3228
+ body: JSON.stringify({
3229
+ sessionId,
3230
+ actorUserId
3231
+ })
3232
+ });
3233
+ const token = tokenOf(result.body);
3234
+ if (result.status !== 200 || token === void 0) {
3235
+ deps.warn(`scoped credential for ${sessionId} was not minted (status ${String(result.status)})`);
3236
+ return;
3237
+ }
3238
+ await deps.set(ref, token);
3239
+ return ref;
3240
+ } catch (error) {
3241
+ deps.warn(`scoped credential for ${sessionId} failed to mint`, error);
3242
+ return;
3243
+ }
3244
+ }
3245
+ /** Read the token out of an unknown mint response body. */
3246
+ function tokenOf(body) {
3247
+ if (typeof body !== "object" || body === null) return void 0;
3248
+ const value = body["token"];
3249
+ return typeof value === "string" && value !== "" ? value : void 0;
3250
+ }
3251
+ //#endregion
3199
3252
  //#region src/resource-tab.ts
3200
3253
  /** SSE route the client subscribes to. */
3201
3254
  const OPEN_RESOURCE_EVENTS_PATH = "/integrations/dataops/open-resource/events";
@@ -3739,6 +3792,8 @@ const inject = [
3739
3792
  "approval"
3740
3793
  ];
3741
3794
  const MANAGED_AUTH_PATH = "/integrations/dataops/managed-auth";
3795
+ /** Where the connector mints one room Session's scoped credential. */
3796
+ const SCOPED_TOKEN_PATH = "/integrations/dataops/scoped-token";
3742
3797
  /** This plugin's profile entry id, which owns its Config and sync state. */
3743
3798
  const MANAGED_PLUGIN_ID = "dataops-managed";
3744
3799
  /** Same-origin route the workspace settings pages use to read and change model sharing. */
@@ -4132,6 +4187,43 @@ async function apply(ctx, config) {
4132
4187
  reviewApiRef = reviewApi;
4133
4188
  const resourceTabHub = new OpenResourceHub(ctx.logger);
4134
4189
  ctx.effect(() => () => resourceTabHub.dispose(), "dataops-managed: resource tab SSE clients");
4190
+ /**
4191
+ * Mint the scoped credential one room Session uses.
4192
+ *
4193
+ * The connector calls this after it created (or adopted) the room Session with an actor, passing
4194
+ * the DataOps user the room acts for. The token is stored under the Session-specific ref the MCP
4195
+ * bridge derives from the same Session id; a failed mint answers 502 and leaves the room on the
4196
+ * workspace credential, which is what it would have used anyway.
4197
+ */
4198
+ ctx.effect(() => ctx.webServer.register({
4199
+ kind: "exact",
4200
+ path: SCOPED_TOKEN_PATH,
4201
+ handler: async (request, response) => {
4202
+ if ((request.method ?? "GET").toUpperCase() !== "POST") {
4203
+ response.writeHead(405).end();
4204
+ return;
4205
+ }
4206
+ const body = await readJson(request).catch(() => null);
4207
+ const sessionId = typeof body?.["sessionId"] === "string" ? body["sessionId"] : "";
4208
+ const actorUserId = typeof body?.["actorUserId"] === "string" ? body["actorUserId"] : "";
4209
+ if (sessionId === "" || actorUserId === "") {
4210
+ response.writeHead(400, { "content-type": "application/json; charset=utf-8" });
4211
+ response.end(JSON.stringify({ error: "sessionId and actorUserId are required" }));
4212
+ return;
4213
+ }
4214
+ const ref = await mintScopedCredential({
4215
+ request: (path, init) => reviewApi.request(path, init),
4216
+ set: async (name, value) => {
4217
+ await ctx.credentials.set(credentialRef(name), value);
4218
+ },
4219
+ warn: (message, error) => {
4220
+ ctx.logger.warn(`dataops-managed: ${message}`, error);
4221
+ }
4222
+ }, config.credentialRef ?? "DATAOPS_ACCESS_TOKEN", sessionId, actorUserId);
4223
+ response.writeHead(ref === void 0 ? 502 : 200, { "content-type": "application/json; charset=utf-8" });
4224
+ response.end(JSON.stringify(ref === void 0 ? { error: "scoped token was not minted" } : { ref }));
4225
+ }
4226
+ }), "dataops-managed: scoped credential route");
4135
4227
  ctx.effect(() => ctx.webServer.register({
4136
4228
  kind: "exact",
4137
4229
  path: OPEN_RESOURCE_EVENTS_PATH,
@@ -4280,7 +4372,17 @@ async function apply(ctx, config) {
4280
4372
  response.end();
4281
4373
  return;
4282
4374
  }
4283
- await ctx.credentials.set(accessRef, token);
4375
+ const body = await readJson(request).catch(() => null);
4376
+ const sessionId = typeof body?.["sessionId"] === "string" ? body["sessionId"] : "";
4377
+ if (sessionId === "") await ctx.credentials.set(accessRef, token);
4378
+ else {
4379
+ const scopedRef = credentialRef(scopedCredentialRef(config.credentialRef, sessionId));
4380
+ if ((await ctx.credentials.resolve(scopedRef).catch(() => void 0))?.value !== token) try {
4381
+ await ctx.credentials.set(scopedRef, token);
4382
+ } catch (error) {
4383
+ ctx.logger.warn(`dataops-managed: session credential for ${sessionId} was not stored`, error);
4384
+ }
4385
+ }
4284
4386
  resetAuthState();
4285
4387
  aiTools.refresh(true);
4286
4388
  await ensureMcp();
@@ -5083,4 +5185,4 @@ function writeJson(response, status, body) {
5083
5185
  response.end(payload);
5084
5186
  }
5085
5187
  //#endregion
5086
- export { AUTH_STATE_PATH, Config, DEFAULT_TOOL_CALL_TIMEOUT_MS, DEPARTMENTS_PATH, MANAGED_AUTH_PATH, MANAGED_PLUGIN_ID, MODEL_SYNC_PATH, RBAC_PATH, REVIEW_ACTION_PATH, REVIEW_CONTEXT_PATH, REVIEW_NOTIFICATIONS_PATH, REVIEW_SETTINGS_PATH, SKILL_PLAZA_PATH, TOOL_TIMEOUT_MAX_SECONDS, TOOL_TIMEOUT_MIN_SECONDS, TOOL_TIMEOUT_PATH, WORKSPACE_LIMITS_PATH, WORKSPACE_UPGRADE_PATH, adoptRequestJwt, apply, currentModelSync, currentSettingsSync, currentSkillPlaza, currentWorkspaceLimits, inject, name };
5188
+ export { AUTH_STATE_PATH, Config, DEFAULT_TOOL_CALL_TIMEOUT_MS, DEPARTMENTS_PATH, MANAGED_AUTH_PATH, MANAGED_PLUGIN_ID, MODEL_SYNC_PATH, RBAC_PATH, REVIEW_ACTION_PATH, REVIEW_CONTEXT_PATH, REVIEW_NOTIFICATIONS_PATH, REVIEW_SETTINGS_PATH, SCOPED_TOKEN_PATH, SKILL_PLAZA_PATH, TOOL_TIMEOUT_MAX_SECONDS, TOOL_TIMEOUT_MIN_SECONDS, TOOL_TIMEOUT_PATH, WORKSPACE_LIMITS_PATH, WORKSPACE_UPGRADE_PATH, adoptRequestJwt, apply, currentModelSync, currentSettingsSync, currentSkillPlaza, currentWorkspaceLimits, inject, name };
@@ -1,6 +1,6 @@
1
1
  /** Same-origin model-sync calls from the DataOps settings surface. */
2
2
  /** Route the plugin's Host half serves for model sharing. */
3
- export declare const MODEL_SYNC_PATH = "integrations/dataops/model-sync";
3
+ export declare const MODEL_SYNC_PATH = "/integrations/dataops/model-sync";
4
4
  /** One model this workspace holds, and whether it is offered to other users. */
5
5
  export interface ModelSyncModel {
6
6
  /** Model id as the settings document stores it. */
@@ -7,17 +7,17 @@
7
7
  */
8
8
  import type { ReviewContext, ReviewNotification, RiskReport, ReviewStatus, ResourceVisibility } from './review-types.ts';
9
9
  /** Caller identity and review capability. */
10
- export declare const REVIEW_CONTEXT_PATH = "integrations/dataops/review-context";
10
+ export declare const REVIEW_CONTEXT_PATH = "/integrations/dataops/review-context";
11
11
  /** Notification list and read receipts. */
12
- export declare const NOTIFICATIONS_PATH = "integrations/dataops/review-notifications";
12
+ export declare const NOTIFICATIONS_PATH = "/integrations/dataops/review-notifications";
13
13
  /** AI scan and the human decision. */
14
- export declare const REVIEW_ACTION_PATH = "integrations/dataops/review";
14
+ export declare const REVIEW_ACTION_PATH = "/integrations/dataops/review";
15
15
  /** Role matrix, members, departments, and resource scopes. */
16
- export declare const RBAC_PATH = "integrations/dataops/rbac";
16
+ export declare const RBAC_PATH = "/integrations/dataops/rbac";
17
17
  /** The three plaza-review switches in the DataOps settings panel. */
18
- export declare const REVIEW_SETTINGS_PATH = "integrations/dataops/review-settings";
18
+ export declare const REVIEW_SETTINGS_PATH = "/integrations/dataops/review-settings";
19
19
  /** Department CRUD bridge (task-67). */
20
- export declare const DEPARTMENTS_PATH = "integrations/dataops/departments";
20
+ export declare const DEPARTMENTS_PATH = "/integrations/dataops/departments";
21
21
  /** One permission point in the role matrix. */
22
22
  export interface PermissionPoint {
23
23
  key: string;
@@ -1,7 +1,7 @@
1
1
  /** Same-origin skill plaza calls from the DataOps skill center section. */
2
2
  import type { ReviewStatus, ResourceVisibility } from './review-types.ts';
3
3
  /** Route the plugin's Host half serves for the plaza. */
4
- export declare const SKILL_PLAZA_PATH = "integrations/dataops/skill-plaza";
4
+ export declare const SKILL_PLAZA_PATH = "/integrations/dataops/skill-plaza";
5
5
  /** One plaza entry as the section reads it. */
6
6
  export interface PlazaSkill {
7
7
  id: number;
@@ -1,6 +1,6 @@
1
1
  /** Same-origin tool-call timeout calls from the DataOps settings surface. */
2
2
  /** Route the plugin's Host half serves for the tool-call timeout. */
3
- export declare const TOOL_TIMEOUT_PATH = "integrations/dataops/tool-timeout";
3
+ export declare const TOOL_TIMEOUT_PATH = "/integrations/dataops/tool-timeout";
4
4
  /** The two ends a timeout may take, in seconds, matching what the Host enforces. */
5
5
  export declare const TOOL_TIMEOUT_MIN_SECONDS = 1;
6
6
  export declare const TOOL_TIMEOUT_MAX_SECONDS = 3600;
@@ -1,6 +1,6 @@
1
1
  /** Same-origin workspace-limits calls from the DataOps settings surface. */
2
2
  /** Route the plugin's Host half serves for workspace limits. */
3
- export declare const WORKSPACE_LIMITS_PATH = "integrations/dataops/workspace-limits";
3
+ export declare const WORKSPACE_LIMITS_PATH = "/integrations/dataops/workspace-limits";
4
4
  /** The two byte ceilings, as the panel edits them. */
5
5
  export interface WorkspaceLimits {
6
6
  /** Largest file a sidebar download or agent read may carry. */
@@ -1,6 +1,6 @@
1
1
  /** Same-origin calls for the workspace image upgrade banner. */
2
2
  /** Route the plugin's Host half serves for upgrade detection and start. */
3
- export declare const WORKSPACE_UPGRADE_PATH = "integrations/dataops/workspace-upgrade";
3
+ export declare const WORKSPACE_UPGRADE_PATH = "/integrations/dataops/workspace-upgrade";
4
4
  /** A DSH session that will receive "继续" after the restart. */
5
5
  export interface WorkspaceUpgradeSession {
6
6
  sessionId: string;
@@ -12,6 +12,8 @@ export declare const name = "dataops-managed";
12
12
  /** Host services required by managed JWT and MCP ownership. */
13
13
  export declare const inject: string[];
14
14
  export declare const MANAGED_AUTH_PATH = "/integrations/dataops/managed-auth";
15
+ /** Where the connector mints one room Session's scoped credential. */
16
+ export declare const SCOPED_TOKEN_PATH = "/integrations/dataops/scoped-token";
15
17
  /** This plugin's profile entry id, which owns its Config and sync state. */
16
18
  export declare const MANAGED_PLUGIN_ID = "dataops-managed";
17
19
  /** Same-origin route the workspace settings pages use to read and change model sharing. */
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Scoped credentials for group-chat rooms.
3
+ *
4
+ * A room acts for the member the connector names, so its MCP calls must not ride on the workspace
5
+ * JWT. The connector mints one token per room Session, stores it under a Session-specific
6
+ * credential ref, and the MCP bridge prefers that entry for the room's requests. Minting happens
7
+ * once per room, not per request: the token shares the workspace token's long lifetime, and a
8
+ * revoked token surfaces as a 401 the bridge retries once.
9
+ *
10
+ * @module scoped-credential
11
+ */
12
+ /** The credential reference a room Session's token is stored under. */
13
+ export interface ScopedCredentialDeps {
14
+ /** Calls one DataOps endpoint with the workspace JWT. */
15
+ readonly request: (path: string, init?: RequestInit) => Promise<{
16
+ readonly status: number;
17
+ readonly body: unknown;
18
+ }>;
19
+ /** Stores one credential value. */
20
+ readonly set: (ref: string, value: string) => Promise<void>;
21
+ /** Reports a failed mint without failing the caller. */
22
+ readonly warn: (message: string, error?: unknown) => void;
23
+ }
24
+ /**
25
+ * Fold a Session id into the credential-ref alphabet.
26
+ *
27
+ * Credential references are uppercase underscore tokens, and the MCP bridge derives the same name
28
+ * from the Session id it is serving. Both sides use this function so they cannot drift.
29
+ * @param baseRef - the workspace credential reference, for example `DATAOPS_ACCESS_TOKEN`.
30
+ * @param sessionId - the room Session id.
31
+ * @returns the scoped reference for that Session.
32
+ */
33
+ export declare function scopedCredentialRef(baseRef: string, sessionId: string): string;
34
+ /**
35
+ * Mint one room's scoped token and store it.
36
+ *
37
+ * Failure is reported and swallowed: the room keeps working on the workspace credential, which is
38
+ * the pre-connector behaviour, so a backend outage degrades authority instead of breaking chat.
39
+ * @param deps - endpoint, credential store, and logger.
40
+ * @param baseRef - the workspace credential reference the scoped name derives from.
41
+ * @param sessionId - the room Session the token is minted for.
42
+ * @param actorUserId - the DataOps user the room acts for.
43
+ * @returns the stored reference, or undefined when minting failed.
44
+ */
45
+ export declare function mintScopedCredential(deps: ScopedCredentialDeps, baseRef: string, sessionId: string, actorUserId: string): Promise<string | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-dataops-managed",
3
- "version": "0.3.43",
3
+ "version": "0.3.45",
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",
@@ -46,12 +46,6 @@
46
46
  "README.md",
47
47
  "LICENSE"
48
48
  ],
49
- "scripts": {
50
- "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown",
51
- "bundle": "tsdown",
52
- "prepack": "pnpm run build",
53
- "prepublishOnly": "node ../../scripts/prepublish-guard.mjs"
54
- },
55
49
  "engines": {
56
50
  "node": "^22.19.0 || >=24.0.0"
57
51
  },
@@ -103,5 +97,9 @@
103
97
  "lightningcss": "^1.32.0",
104
98
  "react": "^18.2.0",
105
99
  "tsdown": "^0.22.2"
100
+ },
101
+ "scripts": {
102
+ "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown",
103
+ "bundle": "tsdown"
106
104
  }
107
- }
105
+ }