@sparkelf/dsh-dataops-managed 0.3.54 → 0.4.0
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/client.js +154 -154
- package/lib/client.js.map +1 -1
- package/lib/index.js +592 -113
- package/lib/types/collect-api.d.ts +19 -10
- package/lib/types/tool-scope.d.ts +14 -1
- package/package.json +4 -2
- package/skills/browser/SKILL.md +44 -33
- package/skills/{browser-bridge-companion/SKILL.md → browser/references/bridge.md} +1 -6
- package/skills/browser/references/chrome-install.md +309 -0
- package/skills/browser/references/chrome-install.openai.yaml +4 -0
- package/skills/{browser-headless/SKILL.md → browser/references/headless.md} +1 -6
- package/skills/browser/references/scripts/check_browser_bridge_status.js +33 -0
- package/skills/browser/references/scripts/cleanup_isolated_chrome.ps1 +10 -0
- package/skills/browser/references/scripts/start_isolated_chrome.ps1 +25 -0
- package/skills/browser/references/scripts/start_test_browser_bridge.cjs +245 -0
- package/skills/dataops-collect/SKILL.md +57 -96
- package/skills/dataops-collect/references/append.md +137 -0
- package/skills/dataops-collect/references/execution.md +133 -0
- package/skills/dataops-collect/references/plan-schema.md +142 -0
package/lib/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
|
5
5
|
import * as McpClient from "@sparkelf/dsh-plugin-mcp-credentials";
|
|
6
6
|
import { BUNDLED_SKILL_RANK } from "@deepseek-ai/dsh-skill";
|
|
7
7
|
import z from "@deepseek-ai/schemastery";
|
|
8
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
8
9
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
9
|
-
import { randomUUID } from "node:crypto";
|
|
10
10
|
//#region src/auth-state.ts
|
|
11
11
|
let state = "unknown";
|
|
12
12
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -882,10 +882,21 @@ const AI_TOOL_ACCESS = {
|
|
|
882
882
|
workflow_deployment: { superAdminOnly: true },
|
|
883
883
|
workflow_run_control: { superAdminOnly: true },
|
|
884
884
|
dataops_collect_preview: { permission: "data:resource:manage" },
|
|
885
|
-
|
|
885
|
+
dataops_collect_validate_plan: { permission: "data:resource:manage" },
|
|
886
886
|
dataops_collect_execute: { permission: "data:resource:manage" },
|
|
887
887
|
dataops_collect_resources: { permission: "data:resource:read" },
|
|
888
888
|
dataops_open_resource_tab: {},
|
|
889
|
+
dataops_user_lookup: { permission: "system:user:read" },
|
|
890
|
+
dataops_user_create: {
|
|
891
|
+
capability: "admin.manage",
|
|
892
|
+
adminOnly: true,
|
|
893
|
+
defaultEnabled: true
|
|
894
|
+
},
|
|
895
|
+
dataops_role_assign: {
|
|
896
|
+
capability: "admin.manage",
|
|
897
|
+
adminOnly: true,
|
|
898
|
+
defaultEnabled: true
|
|
899
|
+
},
|
|
889
900
|
dataops_resource_pending_list: {
|
|
890
901
|
capability: "resource.manage",
|
|
891
902
|
adminOnly: true,
|
|
@@ -1338,10 +1349,11 @@ function hasCapability(id) {
|
|
|
1338
1349
|
/**
|
|
1339
1350
|
* DataOps spreadsheet-import transport for the collection skill.
|
|
1340
1351
|
*
|
|
1341
|
-
* The host reads a workspace attachment, uploads it as multipart,
|
|
1342
|
-
* create-table or existing-table plan
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1352
|
+
* The host reads a workspace attachment, uploads it as multipart, and validates the
|
|
1353
|
+
* create-table or existing-table plan the current conversation model wrote. DataOps only
|
|
1354
|
+
* normalizes that plan and returns SQL/mapping summaries; it never selects or calls a shared
|
|
1355
|
+
* model. Execution is the single mutating call and stays behind the user's explicit
|
|
1356
|
+
* confirmation.
|
|
1345
1357
|
*
|
|
1346
1358
|
* @module collect-api
|
|
1347
1359
|
*/
|
|
@@ -1411,12 +1423,19 @@ var CollectApi = class {
|
|
|
1411
1423
|
const body = unwrap$1(result, "import data sources");
|
|
1412
1424
|
return Array.isArray(body.dataSources) ? body.dataSources : [];
|
|
1413
1425
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1426
|
+
/**
|
|
1427
|
+
* Validate and normalize a plan written by the current conversation model.
|
|
1428
|
+
*
|
|
1429
|
+
* Read-only and model-free: the backend runs the same deterministic sanitizers as
|
|
1430
|
+
* `/plan` and `/execute`, then returns the normalized plan, CREATE TABLE SQL or mapping
|
|
1431
|
+
* summary. It never resolves a shared `AiModelConfig` or calls a provider.
|
|
1432
|
+
*/
|
|
1433
|
+
async validatePlan(payload) {
|
|
1434
|
+
const result = await this.reviewApi.request("/api/resources/spreadsheet-import/validate-plan", {
|
|
1416
1435
|
method: "POST",
|
|
1417
1436
|
body: JSON.stringify(payload)
|
|
1418
1437
|
});
|
|
1419
|
-
return unwrap$1(result, "spreadsheet plan");
|
|
1438
|
+
return unwrap$1(result, "spreadsheet plan validation");
|
|
1420
1439
|
}
|
|
1421
1440
|
async execute(payload) {
|
|
1422
1441
|
const result = await this.reviewApi.request("/api/resources/spreadsheet-import/execute", {
|
|
@@ -1751,6 +1770,25 @@ const renderJson = (_args, value) => [{
|
|
|
1751
1770
|
}];
|
|
1752
1771
|
//#endregion
|
|
1753
1772
|
//#region src/tools.ts
|
|
1773
|
+
/**
|
|
1774
|
+
* Model tools for the skill centre, the shared review queues, and the DataOps API reference.
|
|
1775
|
+
*
|
|
1776
|
+
* Registration is disclosure, not authorization. `AiToolManager` computes the workspace's
|
|
1777
|
+
* current DataOps scope once per credential/role sync and registers only the tools that scope
|
|
1778
|
+
* can use; these definitions assume they were registered for a principal that may call them.
|
|
1779
|
+
* Every `execute` therefore validates parameters, asks for user approval where a mutation needs
|
|
1780
|
+
* it, writes its audit line, and lets DataOps answer — no per-call role read, no local permission
|
|
1781
|
+
* tree, and no replacement for the backend's AuthGuard/PermissionGuard.
|
|
1782
|
+
*
|
|
1783
|
+
* The skill plaza is the catalogue. `scope=mine` exposes the caller's pending/rejected rows,
|
|
1784
|
+
* the public list exposes what the caller may install, and the admin list (administrators only)
|
|
1785
|
+
* exposes disabled entries. Installation, sharing and deletion are deliberately three different
|
|
1786
|
+
* actions: uninstall removes only the caller's installation, unshare unpublishes the shared entry
|
|
1787
|
+
* (with an unpublished notification), and delete permanently removes the entry after a second
|
|
1788
|
+
* confirmation, with its own deleted notification and audit trail.
|
|
1789
|
+
*
|
|
1790
|
+
* @module tools
|
|
1791
|
+
*/
|
|
1754
1792
|
/** Parse one plaza response body into rows without trusting its shape. */
|
|
1755
1793
|
function rowsOf(body) {
|
|
1756
1794
|
if (Array.isArray(body)) return body.filter((row) => typeof row === "object" && row !== null);
|
|
@@ -1783,6 +1821,87 @@ const provisioningDepartmentCode = (tool, value) => {
|
|
|
1783
1821
|
return code;
|
|
1784
1822
|
};
|
|
1785
1823
|
/**
|
|
1824
|
+
* Roles a tool-created account receives.
|
|
1825
|
+
*
|
|
1826
|
+
* This is the same minimal set the IM private-chat auto-provision path writes: an ordinary
|
|
1827
|
+
* member, the basic data-security tier, and the admission role that lets the account open its
|
|
1828
|
+
* AI workspace. None of them carries a business capability or a resource grant.
|
|
1829
|
+
*/
|
|
1830
|
+
const PROVISIONED_USER_ROLES = [
|
|
1831
|
+
"应用人员",
|
|
1832
|
+
"初级权限",
|
|
1833
|
+
"AI 工作区成员"
|
|
1834
|
+
];
|
|
1835
|
+
/** The one role this tool set never assigns or removes; super-admin changes stay in the console. */
|
|
1836
|
+
const SUPER_ADMIN_ROLE = "超级管理员";
|
|
1837
|
+
/** The department a provisioned account lands in until an administrator assigns one. */
|
|
1838
|
+
const PROVISIONED_DEPARTMENT = "unassigned";
|
|
1839
|
+
/** Trim one optional string argument; a non-string becomes the empty string. */
|
|
1840
|
+
const textArg = (value) => typeof value === "string" ? value.trim() : "";
|
|
1841
|
+
/** Digits only, used to compare phone numbers written with separators or a country code. */
|
|
1842
|
+
const phoneDigits = (value) => value.replace(/\D+/gu, "");
|
|
1843
|
+
/** Case-insensitive exact match helper for usernames and emails. */
|
|
1844
|
+
const sameText = (left, right) => left.toLowerCase() === right.toLowerCase();
|
|
1845
|
+
/** The comparable form the backend's password policy uses for account tokens. */
|
|
1846
|
+
const comparable = (value) => value.toLowerCase().replace(/[^a-z0-9]/gu, "");
|
|
1847
|
+
/**
|
|
1848
|
+
* Generate an initial password the backend's strong-password policy accepts.
|
|
1849
|
+
*
|
|
1850
|
+
* The value never leaves this function's caller: it is sent to DataOps once, stored as a hash,
|
|
1851
|
+
* and deliberately not returned, logged or audited. A tool-created account therefore cannot be
|
|
1852
|
+
* signed into until an administrator sets a password in the user console, which is the intended
|
|
1853
|
+
* credential hand-off for an AI-driven provisioning action.
|
|
1854
|
+
* @param context - account fields the policy rejects when the password embeds them.
|
|
1855
|
+
*/
|
|
1856
|
+
const generatedInitialPassword = (context) => {
|
|
1857
|
+
const localPart = context.email.includes("@") ? context.email.split("@")[0] ?? "" : context.email;
|
|
1858
|
+
const tokens = [
|
|
1859
|
+
context.username,
|
|
1860
|
+
context.displayName,
|
|
1861
|
+
localPart
|
|
1862
|
+
].map((token) => comparable(token)).filter((token) => token.length >= 3);
|
|
1863
|
+
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
1864
|
+
const candidate = "Aa1!" + randomBytes(32).toString("base64url");
|
|
1865
|
+
const comparableCandidate = comparable(candidate);
|
|
1866
|
+
if (tokens.every((token) => !comparableCandidate.includes(token))) return candidate;
|
|
1867
|
+
}
|
|
1868
|
+
return "Aa1!" + randomBytes(48).toString("hex") + "Zz9!";
|
|
1869
|
+
};
|
|
1870
|
+
/** One user row projected to the fields the lookup contract promises, never password material. */
|
|
1871
|
+
const projectUserRow = (row) => {
|
|
1872
|
+
const department = typeof row.department === "object" && row.department !== null ? row.department : {};
|
|
1873
|
+
const departmentCode = textArg(department.code);
|
|
1874
|
+
const roles = Array.isArray(row.roles) ? row.roles.flatMap((role) => {
|
|
1875
|
+
if (typeof role !== "object" || role === null) return [];
|
|
1876
|
+
const entry = role;
|
|
1877
|
+
const code = textArg(entry.code);
|
|
1878
|
+
if (code === "") return [];
|
|
1879
|
+
return [{
|
|
1880
|
+
code,
|
|
1881
|
+
name: textArg(entry.name) || code
|
|
1882
|
+
}];
|
|
1883
|
+
}) : [];
|
|
1884
|
+
return {
|
|
1885
|
+
id: textArg(row.id),
|
|
1886
|
+
username: textArg(row.username),
|
|
1887
|
+
displayName: textArg(row.displayName),
|
|
1888
|
+
email: textArg(row.email),
|
|
1889
|
+
mobile: textArg(row.phone) || null,
|
|
1890
|
+
enabled: row.enabled === true,
|
|
1891
|
+
departments: departmentCode === "" ? [] : [{
|
|
1892
|
+
code: departmentCode,
|
|
1893
|
+
name: textArg(department.name) || departmentCode
|
|
1894
|
+
}],
|
|
1895
|
+
roles
|
|
1896
|
+
};
|
|
1897
|
+
};
|
|
1898
|
+
/** Read one user row from a DataOps response body without trusting its shape. */
|
|
1899
|
+
const userRowOf = (body) => {
|
|
1900
|
+
if (typeof body !== "object" || body === null) return void 0;
|
|
1901
|
+
const user = body.user;
|
|
1902
|
+
return typeof user === "object" && user !== null && !Array.isArray(user) ? user : void 0;
|
|
1903
|
+
};
|
|
1904
|
+
/**
|
|
1786
1905
|
* Build every managed tool definition.
|
|
1787
1906
|
*
|
|
1788
1907
|
* The definitions are built once; `readScope` is a live getter so a tool that survives a role
|
|
@@ -1920,8 +2039,8 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
1920
2039
|
return parsed;
|
|
1921
2040
|
};
|
|
1922
2041
|
/**
|
|
1923
|
-
* Keep only the fields the DataOps execute
|
|
1924
|
-
* `createSql`/`targetSchema`/`notes` beside `createTable`; if the model passes
|
|
2042
|
+
* Keep only the fields the DataOps execute/validate DTOs accept. The validated plan
|
|
2043
|
+
* carries `createSql`/`targetSchema`/`notes` beside `createTable`; if the model passes
|
|
1925
2044
|
* the whole plan (or rebuilds it after a table-name edit), the backend's
|
|
1926
2045
|
* `forbidNonWhitelisted` pipe rejects the call with a generic 400.
|
|
1927
2046
|
*/
|
|
@@ -1954,6 +2073,24 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
1954
2073
|
columns
|
|
1955
2074
|
};
|
|
1956
2075
|
};
|
|
2076
|
+
/**
|
|
2077
|
+
* Keep only `{sourceKey,targetColumn}` from a model-written mapping list.
|
|
2078
|
+
*
|
|
2079
|
+
* The validated plan carries sourceHeader/targetDataType/confidence beside the pair; the
|
|
2080
|
+
* backend DTO drops them, but rejecting a malformed entry here names the offending index
|
|
2081
|
+
* instead of letting the server answer a generic "no usable mapping".
|
|
2082
|
+
*/
|
|
2083
|
+
const normalizeMappings = (tool, entries) => entries.map((entry, index) => {
|
|
2084
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) throw new Error(tool + ": mappings_json[" + index + "] must be an object");
|
|
2085
|
+
const mapping = entry;
|
|
2086
|
+
const sourceKey = typeof mapping.sourceKey === "string" ? mapping.sourceKey.trim() : "";
|
|
2087
|
+
const targetColumn = typeof mapping.targetColumn === "string" ? mapping.targetColumn.trim() : "";
|
|
2088
|
+
if (!sourceKey || !targetColumn) throw new Error(tool + ": mappings_json[" + index + "] needs sourceKey and targetColumn");
|
|
2089
|
+
return {
|
|
2090
|
+
sourceKey,
|
|
2091
|
+
targetColumn
|
|
2092
|
+
};
|
|
2093
|
+
});
|
|
1957
2094
|
return [
|
|
1958
2095
|
{
|
|
1959
2096
|
name: "skill_list",
|
|
@@ -2585,17 +2722,11 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2585
2722
|
definition: defineTool({
|
|
2586
2723
|
name: "dataops_collect_preview",
|
|
2587
2724
|
description: "Parse one spreadsheet attachment from the workspace and return DataOps's preview plus the importable database destinations. Read-only: it does not create a table and does not write rows. Use this first in the data-collection skill, then ask the user to choose the destination when more than one is returned.",
|
|
2588
|
-
parameters: {
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
},
|
|
2594
|
-
model_id: {
|
|
2595
|
-
type: "number",
|
|
2596
|
-
description: "Optional shared AI model id for the later plan call."
|
|
2597
|
-
}
|
|
2598
|
-
},
|
|
2725
|
+
parameters: { file_path: {
|
|
2726
|
+
type: "string",
|
|
2727
|
+
required: true,
|
|
2728
|
+
description: "Absolute or workspace-relative path to one .xlsx/.xls/.csv/.tsv file."
|
|
2729
|
+
} },
|
|
2599
2730
|
output: {
|
|
2600
2731
|
schema: OPEN_OBJECT_SCHEMA,
|
|
2601
2732
|
render: renderJson
|
|
@@ -2617,10 +2748,10 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2617
2748
|
})
|
|
2618
2749
|
},
|
|
2619
2750
|
{
|
|
2620
|
-
name: "
|
|
2751
|
+
name: "dataops_collect_validate_plan",
|
|
2621
2752
|
definition: defineTool({
|
|
2622
|
-
name: "
|
|
2623
|
-
description: "
|
|
2753
|
+
name: "dataops_collect_validate_plan",
|
|
2754
|
+
description: "Validate and normalize the spreadsheet import plan the current conversation model wrote: a create-table plan or an existing-table field mapping. Read-only and model-free: DataOps checks identifiers, data types, source keys and target columns, then returns the normalized plan, CREATE TABLE SQL or mapping summary. It does not call any AI model and does not create tables or write rows. Call this after generating the plan and before presenting it to the user; use the returned plan for confirmation and execution.",
|
|
2624
2755
|
parameters: {
|
|
2625
2756
|
session_id: {
|
|
2626
2757
|
type: "string",
|
|
@@ -2629,20 +2760,23 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2629
2760
|
},
|
|
2630
2761
|
data_source_urn: {
|
|
2631
2762
|
type: "string",
|
|
2632
|
-
|
|
2633
|
-
description: "Destination URN from the preview result."
|
|
2763
|
+
description: "Destination URN from the preview result. Required when appending to an existing table; omit only when validating a generic create-table plan."
|
|
2634
2764
|
},
|
|
2635
2765
|
target_schema: {
|
|
2636
2766
|
type: "string",
|
|
2637
|
-
description: "Existing-table schema; required
|
|
2767
|
+
description: "Existing-table schema; required together with target_table."
|
|
2638
2768
|
},
|
|
2639
2769
|
target_table: {
|
|
2640
2770
|
type: "string",
|
|
2641
|
-
description: "Existing table name; omit to
|
|
2771
|
+
description: "Existing table name; omit to validate a new create-table plan."
|
|
2642
2772
|
},
|
|
2643
|
-
|
|
2644
|
-
type: "
|
|
2645
|
-
description: "
|
|
2773
|
+
create_plan_json: {
|
|
2774
|
+
type: "string",
|
|
2775
|
+
description: "JSON object for CREATE_TABLE: {tableName,tableChineseName?,tableComment?,columns:[{sourceKey,name,chineseName,dataType,nullable?,comment?}]}."
|
|
2776
|
+
},
|
|
2777
|
+
mappings_json: {
|
|
2778
|
+
type: "string",
|
|
2779
|
+
description: "JSON array for EXISTING_TABLE: [{sourceKey,targetColumn}]."
|
|
2646
2780
|
}
|
|
2647
2781
|
},
|
|
2648
2782
|
output: {
|
|
@@ -2650,21 +2784,36 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2650
2784
|
render: renderJson
|
|
2651
2785
|
},
|
|
2652
2786
|
execute: async (args, exec) => {
|
|
2653
|
-
const
|
|
2787
|
+
const tool = "dataops_collect_validate_plan";
|
|
2788
|
+
const createPlan = normalizeCreatePlan(tool, parseJsonObject(tool, "create_plan_json", args.create_plan_json));
|
|
2789
|
+
const mappings = normalizeMappings(tool, parseJsonArray(tool, "mappings_json", args.mappings_json));
|
|
2790
|
+
if (args.target_table !== void 0 && args.target_table.trim() === "") throw new Error(tool + ": target_table must be a non-empty existing table name");
|
|
2791
|
+
if (args.target_schema !== void 0 && args.target_table === void 0) throw new Error(tool + ": target_schema requires target_table");
|
|
2792
|
+
if (args.target_table !== void 0) {
|
|
2793
|
+
if (!args.target_schema || args.target_schema.trim() === "") throw new Error(tool + ": target_schema is required when target_table is set");
|
|
2794
|
+
if (createPlan !== void 0) throw new Error(tool + ": do not send create_plan_json when target_table is set");
|
|
2795
|
+
if (mappings.length === 0) throw new Error(tool + ": mappings_json is required for EXISTING_TABLE");
|
|
2796
|
+
} else {
|
|
2797
|
+
if (createPlan === void 0) throw new Error(tool + ": create_plan_json is required for CREATE_TABLE");
|
|
2798
|
+
if (mappings.length > 0) throw new Error(tool + ": do not send mappings_json for CREATE_TABLE");
|
|
2799
|
+
}
|
|
2800
|
+
const result = await collectApi.validatePlan({
|
|
2654
2801
|
sessionId: args.session_id,
|
|
2655
|
-
dataSourceUrn: args.data_source_urn,
|
|
2656
|
-
...args.target_table ? { targetTable: {
|
|
2657
|
-
schema: args.target_schema
|
|
2802
|
+
...args.data_source_urn === void 0 || args.data_source_urn.trim() === "" ? {} : { dataSourceUrn: args.data_source_urn },
|
|
2803
|
+
...args.target_schema && args.target_table ? { targetTable: {
|
|
2804
|
+
schema: args.target_schema,
|
|
2658
2805
|
table: args.target_table
|
|
2659
2806
|
} } : {},
|
|
2660
|
-
...
|
|
2807
|
+
...createPlan === void 0 ? {} : { createPlan },
|
|
2808
|
+
...mappings.length === 0 ? {} : { mappings }
|
|
2661
2809
|
});
|
|
2662
|
-
audit(
|
|
2810
|
+
audit(tool, exec, {
|
|
2663
2811
|
sessionId: args.session_id,
|
|
2664
|
-
dataSourceUrn: args.data_source_urn,
|
|
2665
|
-
targetTable: args.target_table ?? null
|
|
2812
|
+
dataSourceUrn: args.data_source_urn ?? null,
|
|
2813
|
+
targetTable: args.target_table ?? createPlan?.tableName ?? null,
|
|
2814
|
+
mode: args.target_table === void 0 ? "CREATE_TABLE" : "EXISTING_TABLE"
|
|
2666
2815
|
});
|
|
2667
|
-
return
|
|
2816
|
+
return result;
|
|
2668
2817
|
}
|
|
2669
2818
|
})
|
|
2670
2819
|
},
|
|
@@ -2672,7 +2821,7 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2672
2821
|
name: "dataops_collect_execute",
|
|
2673
2822
|
definition: defineTool({
|
|
2674
2823
|
name: "dataops_collect_execute",
|
|
2675
|
-
description: "Execute one confirmed spreadsheet import: create a table (or write to an existing table), insert rows, and register the DataOps resource. This is the ONLY collection tool that mutates data. Call it only after the user explicitly
|
|
2824
|
+
description: "Execute one confirmed spreadsheet import: create a table (or write to an existing table), insert rows, and register the DataOps resource. This is the ONLY collection tool that mutates data. Call it only after dataops_collect_validate_plan has normalized the plan and the user explicitly confirmed that plan in natural language (e.g. 确认/开始吧); never call it while the plan is still being edited and never call it with an unvalidated plan.",
|
|
2676
2825
|
parameters: {
|
|
2677
2826
|
session_id: {
|
|
2678
2827
|
type: "string",
|
|
@@ -2687,7 +2836,7 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2687
2836
|
mode: {
|
|
2688
2837
|
type: "string",
|
|
2689
2838
|
required: true,
|
|
2690
|
-
description: "CREATE_TABLE or
|
|
2839
|
+
description: "CREATE_TABLE, EXISTING_TABLE or OVERWRITE_TABLE. OVERWRITE_TABLE truncates the target table first; require explicit user confirmation and confirm_overwrite=true."
|
|
2691
2840
|
},
|
|
2692
2841
|
target_schema: {
|
|
2693
2842
|
type: "string",
|
|
@@ -2699,11 +2848,15 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2699
2848
|
},
|
|
2700
2849
|
create_plan_json: {
|
|
2701
2850
|
type: "string",
|
|
2702
|
-
description: "Only plan.createTable (tableName/tableChineseName/tableComment/columns). Do not send createSql/targetSchema/notes; if the user edits the table name,
|
|
2851
|
+
description: "Only plan.createTable (tableName/tableChineseName/tableComment/columns) from the plan returned by dataops_collect_validate_plan. Do not send createSql/targetSchema/notes; if the user edits the table name, regenerate the plan and call dataops_collect_validate_plan again before executing."
|
|
2703
2852
|
},
|
|
2704
2853
|
mappings_json: {
|
|
2705
2854
|
type: "string",
|
|
2706
|
-
description: "JSON array of {sourceKey,targetColumn} for EXISTING_TABLE."
|
|
2855
|
+
description: "JSON array of {sourceKey,targetColumn} for EXISTING_TABLE/OVERWRITE_TABLE."
|
|
2856
|
+
},
|
|
2857
|
+
confirm_overwrite: {
|
|
2858
|
+
type: "boolean",
|
|
2859
|
+
description: "Required true for OVERWRITE_TABLE after the user explicitly confirms that the target table will be truncated."
|
|
2707
2860
|
},
|
|
2708
2861
|
resource_name: {
|
|
2709
2862
|
type: "string",
|
|
@@ -2718,6 +2871,18 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2718
2871
|
items: { type: "string" },
|
|
2719
2872
|
description: "Optional resource tags."
|
|
2720
2873
|
},
|
|
2874
|
+
business_domain: {
|
|
2875
|
+
type: "string",
|
|
2876
|
+
description: "Business domain inferred by the conversation model from table name/comment/columns/terms, e.g. 财务域. Omit when unknown; DataOps will place it in 未分类."
|
|
2877
|
+
},
|
|
2878
|
+
domain_inference_source: {
|
|
2879
|
+
type: "string",
|
|
2880
|
+
description: "MODEL, USER, RULE or UNKNOWN. Defaults to MODEL when business_domain is provided."
|
|
2881
|
+
},
|
|
2882
|
+
domain_inference_confidence: {
|
|
2883
|
+
type: "string",
|
|
2884
|
+
description: "HIGH, MEDIUM or LOW. LOW is placed in 未分类."
|
|
2885
|
+
},
|
|
2721
2886
|
ai_visible: {
|
|
2722
2887
|
type: "boolean",
|
|
2723
2888
|
description: "Whether AI may retrieve this resource. Defaults to true."
|
|
@@ -2732,7 +2897,8 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2732
2897
|
render: renderJson
|
|
2733
2898
|
},
|
|
2734
2899
|
execute: async (args, exec) => {
|
|
2735
|
-
if (args.mode !== "CREATE_TABLE" && args.mode !== "EXISTING_TABLE") throw new Error("dataops_collect_execute: mode must be CREATE_TABLE or
|
|
2900
|
+
if (args.mode !== "CREATE_TABLE" && args.mode !== "EXISTING_TABLE" && args.mode !== "OVERWRITE_TABLE") throw new Error("dataops_collect_execute: mode must be CREATE_TABLE, EXISTING_TABLE or OVERWRITE_TABLE");
|
|
2901
|
+
if (args.mode === "OVERWRITE_TABLE" && args.confirm_overwrite !== true) throw new Error("dataops_collect_execute: OVERWRITE_TABLE requires confirm_overwrite=true after explicit user confirmation");
|
|
2736
2902
|
const createPlan = normalizeCreatePlan("dataops_collect_execute", parseJsonObject("dataops_collect_execute", "create_plan_json", args.create_plan_json));
|
|
2737
2903
|
const mappings = parseJsonArray("dataops_collect_execute", "mappings_json", args.mappings_json);
|
|
2738
2904
|
if (args.mode === "CREATE_TABLE" && createPlan === void 0) throw new Error("dataops_collect_execute: create_plan_json is required for CREATE_TABLE");
|
|
@@ -2747,9 +2913,13 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2747
2913
|
schema: args.target_schema,
|
|
2748
2914
|
table: args.target_table
|
|
2749
2915
|
} } : {},
|
|
2916
|
+
...args.mode === "OVERWRITE_TABLE" ? { confirmOverwrite: true } : {},
|
|
2750
2917
|
...args.resource_name === void 0 ? {} : { resourceName: args.resource_name },
|
|
2751
2918
|
...args.resource_description === void 0 ? {} : { resourceDescription: args.resource_description },
|
|
2752
2919
|
...args.resource_tags === void 0 ? {} : { resourceTags: args.resource_tags },
|
|
2920
|
+
...args.business_domain === void 0 ? {} : { businessDomain: args.business_domain },
|
|
2921
|
+
...args.domain_inference_source === void 0 ? {} : { domainInferenceSource: args.domain_inference_source },
|
|
2922
|
+
...args.domain_inference_confidence === void 0 ? {} : { domainInferenceConfidence: args.domain_inference_confidence },
|
|
2753
2923
|
...args.ai_visible === void 0 ? {} : { aiVisible: args.ai_visible },
|
|
2754
2924
|
...args.access_level === void 0 ? {} : { accessLevel: args.access_level }
|
|
2755
2925
|
};
|
|
@@ -2759,7 +2929,8 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2759
2929
|
sessionId: args.session_id,
|
|
2760
2930
|
mode: args.mode,
|
|
2761
2931
|
resourceId: resource?.id ?? null,
|
|
2762
|
-
importedRows: result.importedRows ?? null
|
|
2932
|
+
importedRows: result.importedRows ?? null,
|
|
2933
|
+
businessDomain: args.business_domain ?? null
|
|
2763
2934
|
});
|
|
2764
2935
|
return result;
|
|
2765
2936
|
}
|
|
@@ -2838,6 +3009,368 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
|
|
|
2838
3009
|
}
|
|
2839
3010
|
})
|
|
2840
3011
|
},
|
|
3012
|
+
{
|
|
3013
|
+
name: "dataops_user_lookup",
|
|
3014
|
+
definition: defineTool({
|
|
3015
|
+
name: "dataops_user_lookup",
|
|
3016
|
+
description: "Look up DataOps users by username, display name, email, mobile or WeCom userid. Administrator and department-administrator visibility apply; DataOps returns only the users inside the caller's existing data scope. Read-only and never returns password or credential material.",
|
|
3017
|
+
parameters: {
|
|
3018
|
+
username: {
|
|
3019
|
+
type: "string",
|
|
3020
|
+
description: "Exact login name (case-insensitive)."
|
|
3021
|
+
},
|
|
3022
|
+
display_name: {
|
|
3023
|
+
type: "string",
|
|
3024
|
+
description: "Display-name keyword (case-insensitive contains)."
|
|
3025
|
+
},
|
|
3026
|
+
email: {
|
|
3027
|
+
type: "string",
|
|
3028
|
+
description: "Exact email address (case-insensitive)."
|
|
3029
|
+
},
|
|
3030
|
+
mobile: {
|
|
3031
|
+
type: "string",
|
|
3032
|
+
description: "Exact mobile number; separators and a country prefix are tolerated."
|
|
3033
|
+
},
|
|
3034
|
+
wecom_user_id: {
|
|
3035
|
+
type: "string",
|
|
3036
|
+
description: "Exact WeCom address-book userid."
|
|
3037
|
+
},
|
|
3038
|
+
department_code: {
|
|
3039
|
+
type: "string",
|
|
3040
|
+
description: "Restrict to one department code."
|
|
3041
|
+
},
|
|
3042
|
+
enabled_only: {
|
|
3043
|
+
type: "boolean",
|
|
3044
|
+
description: "Return enabled accounts only. Defaults to false."
|
|
3045
|
+
},
|
|
3046
|
+
limit: {
|
|
3047
|
+
type: "number",
|
|
3048
|
+
description: "Maximum rows (default 20, max 50)."
|
|
3049
|
+
}
|
|
3050
|
+
},
|
|
3051
|
+
output: {
|
|
3052
|
+
schema: OPEN_OBJECT_SCHEMA,
|
|
3053
|
+
render: renderJson
|
|
3054
|
+
},
|
|
3055
|
+
execute: async (args) => {
|
|
3056
|
+
const username = textArg(args.username);
|
|
3057
|
+
const displayName = textArg(args.display_name);
|
|
3058
|
+
const email = textArg(args.email);
|
|
3059
|
+
const mobile = textArg(args.mobile);
|
|
3060
|
+
const wecomUserId = textArg(args.wecom_user_id);
|
|
3061
|
+
const departmentCode = textArg(args.department_code);
|
|
3062
|
+
const enabledOnly = args.enabled_only === true;
|
|
3063
|
+
if (username === "" && displayName === "" && email === "" && mobile === "" && wecomUserId === "") throw new Error("dataops_user_lookup: provide at least one of username, display_name, email, mobile or wecom_user_id");
|
|
3064
|
+
const limit = Math.max(1, Math.min(50, Math.round(args.limit ?? 20)));
|
|
3065
|
+
const params = new URLSearchParams();
|
|
3066
|
+
const search = username || displayName || email || mobile;
|
|
3067
|
+
if (search !== "") params.set("search", search);
|
|
3068
|
+
if (wecomUserId !== "") params.set("wecomUserId", wecomUserId);
|
|
3069
|
+
if (departmentCode !== "") params.set("departmentCode", departmentCode);
|
|
3070
|
+
params.set("page", "1");
|
|
3071
|
+
params.set("pageSize", "100");
|
|
3072
|
+
const body = await call("/api/system/users?" + params.toString());
|
|
3073
|
+
const rows = typeof body === "object" && body !== null && Array.isArray(body.items) ? body.items.filter((row) => typeof row === "object" && row !== null) : [];
|
|
3074
|
+
const queryDigits = phoneDigits(mobile);
|
|
3075
|
+
const users = rows.filter((row) => {
|
|
3076
|
+
if (username !== "" && !sameText(textArg(row.username), username)) return false;
|
|
3077
|
+
if (email !== "" && !sameText(textArg(row.email), email)) return false;
|
|
3078
|
+
if (displayName !== "" && !textArg(row.displayName).toLowerCase().includes(displayName.toLowerCase())) return false;
|
|
3079
|
+
if (mobile !== "") {
|
|
3080
|
+
const storedDigits = phoneDigits(textArg(row.phone));
|
|
3081
|
+
if (queryDigits === "" || storedDigits === "") return false;
|
|
3082
|
+
if (storedDigits !== queryDigits && !(queryDigits.length >= 7 && storedDigits.endsWith(queryDigits))) return false;
|
|
3083
|
+
}
|
|
3084
|
+
if (enabledOnly && row.enabled !== true) return false;
|
|
3085
|
+
return true;
|
|
3086
|
+
});
|
|
3087
|
+
return {
|
|
3088
|
+
users: users.slice(0, limit).map(projectUserRow),
|
|
3089
|
+
count: Math.min(users.length, limit),
|
|
3090
|
+
scanned: rows.length,
|
|
3091
|
+
filters: {
|
|
3092
|
+
username: username || null,
|
|
3093
|
+
displayName: displayName || null,
|
|
3094
|
+
email: email || null,
|
|
3095
|
+
mobile: mobile || null,
|
|
3096
|
+
wecomUserId: wecomUserId || null,
|
|
3097
|
+
departmentCode: departmentCode || null,
|
|
3098
|
+
enabledOnly: enabledOnly === true
|
|
3099
|
+
}
|
|
3100
|
+
};
|
|
3101
|
+
}
|
|
3102
|
+
})
|
|
3103
|
+
},
|
|
3104
|
+
{
|
|
3105
|
+
name: "dataops_user_create",
|
|
3106
|
+
definition: defineTool({
|
|
3107
|
+
name: "dataops_user_create",
|
|
3108
|
+
description: "Create an enabled ordinary DataOps account with the same minimal roles as IM auto-provisioning (应用人员/初级权限/AI 工作区成员), in 待分配部门 unless a department is named, and with ZERO data-resource grants. Requires confirm=true and a user approval for the real write; dry_run=true previews without writing. The initial password is random, never returned and never logged — an administrator must set the password in the user console before hand-off. Use dataops_user_lookup first.",
|
|
3109
|
+
parameters: {
|
|
3110
|
+
username: {
|
|
3111
|
+
type: "string",
|
|
3112
|
+
required: true,
|
|
3113
|
+
description: "Login name."
|
|
3114
|
+
},
|
|
3115
|
+
display_name: {
|
|
3116
|
+
type: "string",
|
|
3117
|
+
required: true,
|
|
3118
|
+
description: "Display name."
|
|
3119
|
+
},
|
|
3120
|
+
email: {
|
|
3121
|
+
type: "string",
|
|
3122
|
+
required: true,
|
|
3123
|
+
description: "Email address."
|
|
3124
|
+
},
|
|
3125
|
+
mobile: {
|
|
3126
|
+
type: "string",
|
|
3127
|
+
description: "Optional mobile number."
|
|
3128
|
+
},
|
|
3129
|
+
department_code: {
|
|
3130
|
+
type: "string",
|
|
3131
|
+
description: "Department code. Defaults to unassigned (待分配部门)."
|
|
3132
|
+
},
|
|
3133
|
+
dry_run: {
|
|
3134
|
+
type: "boolean",
|
|
3135
|
+
description: "Preview the account that would be created without writing. Defaults to false."
|
|
3136
|
+
},
|
|
3137
|
+
confirm: {
|
|
3138
|
+
type: "boolean",
|
|
3139
|
+
description: "Must be true for a real create; the tool also asks the user for approval."
|
|
3140
|
+
}
|
|
3141
|
+
},
|
|
3142
|
+
output: {
|
|
3143
|
+
schema: OPEN_OBJECT_SCHEMA,
|
|
3144
|
+
render: renderJson
|
|
3145
|
+
},
|
|
3146
|
+
execute: async (args, exec) => {
|
|
3147
|
+
const username = textArg(args.username);
|
|
3148
|
+
const displayName = textArg(args.display_name);
|
|
3149
|
+
const email = textArg(args.email);
|
|
3150
|
+
if (username === "" || displayName === "" || email === "") throw new Error("dataops_user_create: username, display_name and email are required");
|
|
3151
|
+
const mobile = textArg(args.mobile);
|
|
3152
|
+
const departmentCode = textArg(args.department_code) || PROVISIONED_DEPARTMENT;
|
|
3153
|
+
const roles = [...PROVISIONED_USER_ROLES];
|
|
3154
|
+
const credential = {
|
|
3155
|
+
mode: "admin_reset_required",
|
|
3156
|
+
message: "初始密码由工具随机生成且不回显;请在用户管理页为该账号设置密码后再交付。"
|
|
3157
|
+
};
|
|
3158
|
+
const preview = {
|
|
3159
|
+
username,
|
|
3160
|
+
displayName,
|
|
3161
|
+
email,
|
|
3162
|
+
mobile: mobile || null,
|
|
3163
|
+
departmentCode,
|
|
3164
|
+
enabled: true,
|
|
3165
|
+
roles,
|
|
3166
|
+
directResourceGrants: 0,
|
|
3167
|
+
credential
|
|
3168
|
+
};
|
|
3169
|
+
if (args.dry_run === true) return {
|
|
3170
|
+
dryRun: true,
|
|
3171
|
+
wouldCreate: preview
|
|
3172
|
+
};
|
|
3173
|
+
if (args.confirm !== true) throw new Error("dataops_user_create: confirm must be true for a real create (use dry_run=true to preview)");
|
|
3174
|
+
await approve("dataops_user_create", exec, "Create DataOps user " + username + " with roles " + roles.join(" / ") + " and no resource grants.");
|
|
3175
|
+
const body = await call("/api/system/users", {
|
|
3176
|
+
method: "POST",
|
|
3177
|
+
body: JSON.stringify({
|
|
3178
|
+
username,
|
|
3179
|
+
displayName,
|
|
3180
|
+
email,
|
|
3181
|
+
...mobile === "" ? {} : { phone: mobile },
|
|
3182
|
+
departmentCode,
|
|
3183
|
+
roleCodes: roles,
|
|
3184
|
+
password: generatedInitialPassword({
|
|
3185
|
+
username,
|
|
3186
|
+
displayName,
|
|
3187
|
+
email
|
|
3188
|
+
})
|
|
3189
|
+
})
|
|
3190
|
+
});
|
|
3191
|
+
const row = userRowOf(body);
|
|
3192
|
+
if (row === void 0) throw new Error("dataops_user_create: DataOps created the account but returned no user record");
|
|
3193
|
+
const user = projectUserRow(row);
|
|
3194
|
+
const actorUserId = readScope()?.userId ?? null;
|
|
3195
|
+
audit("dataops_user_create", exec, {
|
|
3196
|
+
actorUserId,
|
|
3197
|
+
userId: user.id,
|
|
3198
|
+
username,
|
|
3199
|
+
roles,
|
|
3200
|
+
departmentCode,
|
|
3201
|
+
directResourceGrants: 0
|
|
3202
|
+
});
|
|
3203
|
+
return {
|
|
3204
|
+
created: true,
|
|
3205
|
+
user,
|
|
3206
|
+
defaultRoles: roles,
|
|
3207
|
+
directResourceGrants: 0,
|
|
3208
|
+
credential
|
|
3209
|
+
};
|
|
3210
|
+
}
|
|
3211
|
+
})
|
|
3212
|
+
},
|
|
3213
|
+
{
|
|
3214
|
+
name: "dataops_role_assign",
|
|
3215
|
+
definition: defineTool({
|
|
3216
|
+
name: "dataops_role_assign",
|
|
3217
|
+
description: "Add or remove roles on one or more DataOps users (role_codes replaces nothing: action=add merges, action=remove subtracts, and the backend keeps all other roles). Administrator only; DataOps enforces role hierarchy and data scope on every write. The 超级管理员 role can never be assigned or removed here. Requires confirm=true and a user approval for real writes; dry_run=true previews. Adds no resource grants.",
|
|
3218
|
+
parameters: {
|
|
3219
|
+
user_ids: {
|
|
3220
|
+
type: "array",
|
|
3221
|
+
required: true,
|
|
3222
|
+
description: "DataOps user ids (UUID strings).",
|
|
3223
|
+
items: { type: "string" }
|
|
3224
|
+
},
|
|
3225
|
+
role_codes: {
|
|
3226
|
+
type: "array",
|
|
3227
|
+
required: true,
|
|
3228
|
+
description: "Role codes to add or remove, for example 应用人员 / 初级权限.",
|
|
3229
|
+
items: { type: "string" }
|
|
3230
|
+
},
|
|
3231
|
+
action: {
|
|
3232
|
+
type: "string",
|
|
3233
|
+
description: "add (default) or remove."
|
|
3234
|
+
},
|
|
3235
|
+
dry_run: {
|
|
3236
|
+
type: "boolean",
|
|
3237
|
+
description: "Preview each user's before/after roles without writing. Defaults to false."
|
|
3238
|
+
},
|
|
3239
|
+
confirm: {
|
|
3240
|
+
type: "boolean",
|
|
3241
|
+
description: "Must be true for a real change; the tool also asks the user for approval."
|
|
3242
|
+
}
|
|
3243
|
+
},
|
|
3244
|
+
output: {
|
|
3245
|
+
schema: OPEN_OBJECT_SCHEMA,
|
|
3246
|
+
render: renderJson
|
|
3247
|
+
},
|
|
3248
|
+
execute: async (args, exec) => {
|
|
3249
|
+
if (!Array.isArray(args.user_ids) || args.user_ids.length === 0) throw new Error("dataops_role_assign: user_ids must be a non-empty array");
|
|
3250
|
+
const userIds = Array.from(new Set(args.user_ids.map(textArg).filter((id) => id !== "")));
|
|
3251
|
+
if (userIds.length === 0) throw new Error("dataops_role_assign: user_ids must contain non-empty DataOps user ids");
|
|
3252
|
+
if (userIds.length > 50) throw new Error("dataops_role_assign: at most 50 users per call");
|
|
3253
|
+
const requestedRoles = Array.from(new Set((args.role_codes ?? []).map(textArg).filter((code) => code !== "")));
|
|
3254
|
+
if (requestedRoles.length === 0) throw new Error("dataops_role_assign: role_codes must be a non-empty array");
|
|
3255
|
+
if (requestedRoles.includes(SUPER_ADMIN_ROLE)) throw new Error("dataops_role_assign: 超级管理员 role cannot be assigned or removed through this tool; use the administrator console");
|
|
3256
|
+
const action = args.action === void 0 ? "add" : textArg(args.action).toLowerCase();
|
|
3257
|
+
if (action !== "add" && action !== "remove") throw new Error("dataops_role_assign: action must be add or remove");
|
|
3258
|
+
const plans = [];
|
|
3259
|
+
for (const userId of userIds) try {
|
|
3260
|
+
const body = await call("/api/system/users/" + encodeURIComponent(userId));
|
|
3261
|
+
const row = userRowOf(body);
|
|
3262
|
+
if (row === void 0) throw new Error("user record missing from the response");
|
|
3263
|
+
const beforeRoles = Array.isArray(row.roles) ? row.roles.flatMap((role) => {
|
|
3264
|
+
if (typeof role !== "object" || role === null) return [];
|
|
3265
|
+
const code = textArg(role.code);
|
|
3266
|
+
return code === "" ? [] : [code];
|
|
3267
|
+
}) : [];
|
|
3268
|
+
if (beforeRoles.includes(SUPER_ADMIN_ROLE)) {
|
|
3269
|
+
plans.push({
|
|
3270
|
+
userId,
|
|
3271
|
+
username: textArg(row.username),
|
|
3272
|
+
ok: false,
|
|
3273
|
+
changed: false,
|
|
3274
|
+
beforeRoles,
|
|
3275
|
+
afterRoles: beforeRoles,
|
|
3276
|
+
error: "target is a 超级管理员; super-admin changes stay in the administrator console"
|
|
3277
|
+
});
|
|
3278
|
+
continue;
|
|
3279
|
+
}
|
|
3280
|
+
const afterRoles = action === "add" ? Array.from(/* @__PURE__ */ new Set([...beforeRoles, ...requestedRoles])) : beforeRoles.filter((code) => !requestedRoles.includes(code));
|
|
3281
|
+
if (afterRoles.length === 0) {
|
|
3282
|
+
plans.push({
|
|
3283
|
+
userId,
|
|
3284
|
+
username: textArg(row.username),
|
|
3285
|
+
ok: false,
|
|
3286
|
+
changed: false,
|
|
3287
|
+
beforeRoles,
|
|
3288
|
+
afterRoles,
|
|
3289
|
+
error: "the change would leave the user without any role"
|
|
3290
|
+
});
|
|
3291
|
+
continue;
|
|
3292
|
+
}
|
|
3293
|
+
const changed = afterRoles.length !== beforeRoles.length || afterRoles.some((code) => !beforeRoles.includes(code));
|
|
3294
|
+
plans.push({
|
|
3295
|
+
userId,
|
|
3296
|
+
username: textArg(row.username),
|
|
3297
|
+
ok: true,
|
|
3298
|
+
changed,
|
|
3299
|
+
beforeRoles,
|
|
3300
|
+
afterRoles,
|
|
3301
|
+
updatedAt: textArg(row.updatedAt)
|
|
3302
|
+
});
|
|
3303
|
+
} catch (error) {
|
|
3304
|
+
plans.push({
|
|
3305
|
+
userId,
|
|
3306
|
+
username: "",
|
|
3307
|
+
ok: false,
|
|
3308
|
+
changed: false,
|
|
3309
|
+
beforeRoles: [],
|
|
3310
|
+
afterRoles: [],
|
|
3311
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3314
|
+
const changedPlans = plans.filter((plan) => plan.ok && plan.changed);
|
|
3315
|
+
const rejectedPlans = plans.filter((plan) => !plan.ok).length;
|
|
3316
|
+
if (args.dry_run === true) return {
|
|
3317
|
+
dryRun: true,
|
|
3318
|
+
action,
|
|
3319
|
+
roleCodes: requestedRoles,
|
|
3320
|
+
results: plans,
|
|
3321
|
+
changed: changedPlans.length,
|
|
3322
|
+
failed: rejectedPlans
|
|
3323
|
+
};
|
|
3324
|
+
if (changedPlans.length === 0) return {
|
|
3325
|
+
action,
|
|
3326
|
+
roleCodes: requestedRoles,
|
|
3327
|
+
results: plans,
|
|
3328
|
+
changed: 0,
|
|
3329
|
+
failed: rejectedPlans
|
|
3330
|
+
};
|
|
3331
|
+
if (args.confirm !== true) throw new Error("dataops_role_assign: confirm must be true for a real change (use dry_run=true to preview)");
|
|
3332
|
+
await approve("dataops_role_assign", exec, (action === "add" ? "Add" : "Remove") + " role(s) " + requestedRoles.join(" / ") + " for " + String(changedPlans.length) + " DataOps user(s).");
|
|
3333
|
+
let failed = rejectedPlans;
|
|
3334
|
+
for (const plan of changedPlans) {
|
|
3335
|
+
if (plan.updatedAt === void 0 || plan.updatedAt === "") {
|
|
3336
|
+
plan.ok = false;
|
|
3337
|
+
plan.error = "user record has no updatedAt optimistic token; re-run the lookup";
|
|
3338
|
+
failed += 1;
|
|
3339
|
+
continue;
|
|
3340
|
+
}
|
|
3341
|
+
try {
|
|
3342
|
+
await call("/api/system/users/" + encodeURIComponent(plan.userId), {
|
|
3343
|
+
method: "PATCH",
|
|
3344
|
+
body: JSON.stringify({
|
|
3345
|
+
updatedAt: plan.updatedAt,
|
|
3346
|
+
roleCodes: plan.afterRoles
|
|
3347
|
+
})
|
|
3348
|
+
});
|
|
3349
|
+
} catch (error) {
|
|
3350
|
+
plan.ok = false;
|
|
3351
|
+
plan.error = error instanceof Error ? error.message : String(error);
|
|
3352
|
+
failed += 1;
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
const actorUserId = readScope()?.userId ?? null;
|
|
3356
|
+
audit("dataops_role_assign", exec, {
|
|
3357
|
+
actorUserId,
|
|
3358
|
+
action,
|
|
3359
|
+
roleCodes: requestedRoles,
|
|
3360
|
+
userIds: changedPlans.map((plan) => plan.userId),
|
|
3361
|
+
changed: changedPlans.filter((plan) => plan.ok).length,
|
|
3362
|
+
failed
|
|
3363
|
+
});
|
|
3364
|
+
return {
|
|
3365
|
+
action,
|
|
3366
|
+
roleCodes: requestedRoles,
|
|
3367
|
+
results: plans,
|
|
3368
|
+
changed: changedPlans.filter((plan) => plan.ok).length,
|
|
3369
|
+
failed
|
|
3370
|
+
};
|
|
3371
|
+
}
|
|
3372
|
+
})
|
|
3373
|
+
},
|
|
2841
3374
|
{
|
|
2842
3375
|
name: "dataops_resource_pending_list",
|
|
2843
3376
|
definition: defineTool({
|
|
@@ -5169,7 +5702,7 @@ const COLLECT_SKILL = {
|
|
|
5169
5702
|
source: "bundled",
|
|
5170
5703
|
resourceBase: {
|
|
5171
5704
|
kind: "directory",
|
|
5172
|
-
path: fileURLToPath(new URL("../", import.meta.url))
|
|
5705
|
+
path: fileURLToPath(new URL("../skills/dataops-collect/", import.meta.url))
|
|
5173
5706
|
},
|
|
5174
5707
|
rank: BUNDLED_SKILL_RANK,
|
|
5175
5708
|
locator: COLLECT_SKILL_FILE
|
|
@@ -5247,12 +5780,18 @@ const prefectScriptSkillProvider = {
|
|
|
5247
5780
|
};
|
|
5248
5781
|
}
|
|
5249
5782
|
};
|
|
5250
|
-
/**
|
|
5251
|
-
|
|
5252
|
-
|
|
5783
|
+
/**
|
|
5784
|
+
* The browser entry skill: one catalog entry that routes headless scraping, the
|
|
5785
|
+
* local companion, and legacy Chrome-install troubleshooting through its
|
|
5786
|
+
* `references/` documents. The old `browser-headless` and
|
|
5787
|
+
* `browser-bridge-companion` entries were merged into it so the skill center
|
|
5788
|
+
* exposes one browser skill instead of three overlapping ones.
|
|
5789
|
+
*/
|
|
5790
|
+
const BROWSER_SKILL_NAME = "browser";
|
|
5791
|
+
const BROWSER_SKILL_FILE = new URL("../skills/browser/SKILL.md", import.meta.url);
|
|
5253
5792
|
const BROWSER_SKILL = {
|
|
5254
5793
|
name: BROWSER_SKILL_NAME,
|
|
5255
|
-
description: "
|
|
5794
|
+
description: "浏览器自动化总入口。抓取网页/大屏/表格、登录后取数、或用用户本地 Chrome/Edge 操作内网系统时使用。默认工作区 Playwright headless;只有用户明确要求本地浏览器、已登录 Chrome 或 Companion 才走 Browser Bridge。包含 headless、Companion 桥接与旧 Chrome 安装排查三套按需参考。",
|
|
5256
5795
|
invocation: {
|
|
5257
5796
|
modelInvocable: true,
|
|
5258
5797
|
userInvocable: true
|
|
@@ -5261,7 +5800,7 @@ const BROWSER_SKILL = {
|
|
|
5261
5800
|
source: "bundled",
|
|
5262
5801
|
resourceBase: {
|
|
5263
5802
|
kind: "directory",
|
|
5264
|
-
path: fileURLToPath(new URL("../", import.meta.url))
|
|
5803
|
+
path: fileURLToPath(new URL("../skills/browser/", import.meta.url))
|
|
5265
5804
|
},
|
|
5266
5805
|
rank: BUNDLED_SKILL_RANK,
|
|
5267
5806
|
locator: BROWSER_SKILL_FILE
|
|
@@ -5276,64 +5815,6 @@ const browserSkillProvider = {
|
|
|
5276
5815
|
};
|
|
5277
5816
|
}
|
|
5278
5817
|
};
|
|
5279
|
-
/** The browser entry skill: chooses headless scraping or the local companion. */
|
|
5280
|
-
const BROWSER_GUIDE_SKILL_NAME = "browser";
|
|
5281
|
-
const BROWSER_GUIDE_SKILL_FILE = new URL("../skills/browser/SKILL.md", import.meta.url);
|
|
5282
|
-
const BROWSER_GUIDE_SKILL = {
|
|
5283
|
-
name: BROWSER_GUIDE_SKILL_NAME,
|
|
5284
|
-
description: "浏览器自动化总入口。默认用工作区 Playwright headless 抓取网页/大屏;只有用户明确要求“本地浏览器/已登录 Chrome/companion”才使用 Browser Bridge。账号密码登录走凭据插件,不强制 Companion。",
|
|
5285
|
-
invocation: {
|
|
5286
|
-
modelInvocable: true,
|
|
5287
|
-
userInvocable: true
|
|
5288
|
-
},
|
|
5289
|
-
provider: BROWSER_GUIDE_SKILL_NAME,
|
|
5290
|
-
source: "bundled",
|
|
5291
|
-
resourceBase: {
|
|
5292
|
-
kind: "directory",
|
|
5293
|
-
path: fileURLToPath(new URL("../", import.meta.url))
|
|
5294
|
-
},
|
|
5295
|
-
rank: BUNDLED_SKILL_RANK,
|
|
5296
|
-
locator: BROWSER_GUIDE_SKILL_FILE
|
|
5297
|
-
};
|
|
5298
|
-
const browserGuideSkillProvider = {
|
|
5299
|
-
name: BROWSER_GUIDE_SKILL_NAME,
|
|
5300
|
-
list: () => Promise.resolve([BROWSER_GUIDE_SKILL]),
|
|
5301
|
-
async get() {
|
|
5302
|
-
return {
|
|
5303
|
-
...BROWSER_GUIDE_SKILL,
|
|
5304
|
-
content: await readFile(BROWSER_GUIDE_SKILL_FILE, "utf8")
|
|
5305
|
-
};
|
|
5306
|
-
}
|
|
5307
|
-
};
|
|
5308
|
-
/** The headless scraping skill the browser entry points at as the default mode. */
|
|
5309
|
-
const BROWSER_HEADLESS_SKILL_NAME = "browser-headless";
|
|
5310
|
-
const BROWSER_HEADLESS_SKILL_FILE = new URL("../skills/browser-headless/SKILL.md", import.meta.url);
|
|
5311
|
-
const BROWSER_HEADLESS_SKILL = {
|
|
5312
|
-
name: BROWSER_HEADLESS_SKILL_NAME,
|
|
5313
|
-
description: "用工作区 Playwright + Chromium 无头抓取网页/大屏数据。默认模式;支持账号密码登录(凭据插件注入)、表格/文本/截图/JSON 输出。需要用户已登录的本地浏览器时改用 browser-bridge-companion。",
|
|
5314
|
-
invocation: {
|
|
5315
|
-
modelInvocable: true,
|
|
5316
|
-
userInvocable: true
|
|
5317
|
-
},
|
|
5318
|
-
provider: BROWSER_HEADLESS_SKILL_NAME,
|
|
5319
|
-
source: "bundled",
|
|
5320
|
-
resourceBase: {
|
|
5321
|
-
kind: "directory",
|
|
5322
|
-
path: fileURLToPath(new URL("../", import.meta.url))
|
|
5323
|
-
},
|
|
5324
|
-
rank: BUNDLED_SKILL_RANK,
|
|
5325
|
-
locator: BROWSER_HEADLESS_SKILL_FILE
|
|
5326
|
-
};
|
|
5327
|
-
const browserHeadlessSkillProvider = {
|
|
5328
|
-
name: BROWSER_HEADLESS_SKILL_NAME,
|
|
5329
|
-
list: () => Promise.resolve([BROWSER_HEADLESS_SKILL]),
|
|
5330
|
-
async get() {
|
|
5331
|
-
return {
|
|
5332
|
-
...BROWSER_HEADLESS_SKILL,
|
|
5333
|
-
content: await readFile(BROWSER_HEADLESS_SKILL_FILE, "utf8")
|
|
5334
|
-
};
|
|
5335
|
-
}
|
|
5336
|
-
};
|
|
5337
5818
|
const PROVISIONING_SKILL_NAME = "skill-provisioning";
|
|
5338
5819
|
const PROVISIONING_SKILL_FILE = new URL("../skills/skill-provisioning/SKILL.md", import.meta.url);
|
|
5339
5820
|
/** 该技能只对持有 `skill:manage` 的身份展示:它驱动的分配工具使用同一能力。 */
|
|
@@ -5402,8 +5883,6 @@ async function apply(ctx, config) {
|
|
|
5402
5883
|
ctx.skills.registerProvider(() => prefectScriptSkillProvider);
|
|
5403
5884
|
ctx.skills.registerProvider(() => provisioningSkillProvider);
|
|
5404
5885
|
ctx.skills.registerProvider(() => browserSkillProvider);
|
|
5405
|
-
ctx.skills.registerProvider(() => browserGuideSkillProvider);
|
|
5406
|
-
ctx.skills.registerProvider(() => browserHeadlessSkillProvider);
|
|
5407
5886
|
const ensureMcp = async () => {
|
|
5408
5887
|
if (mcpFiber !== void 0 && mcpFiber.uid !== null) return;
|
|
5409
5888
|
const fiber = ctx.plugin(McpClient, {
|