@datagrok/grokky 1.0.4 → 1.1.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/.claude/skills/deploy-grokky/SKILL.md +193 -0
- package/.grokignore +2 -0
- package/.turbo/turbo-build.log +24 -0
- package/.vscode/settings.json +16 -0
- package/CHANGELOG.md +151 -8
- package/CLAUDE.md +284 -0
- package/CREDITS.md +173 -0
- package/LICENSE.md +16 -0
- package/README.md +24 -0
- package/bdd/bdd.config.json +1 -0
- package/bdd/bindings/elements.ts +9 -0
- package/bdd/bindings/steps.ts +787 -0
- package/bdd/features/ai-panel/platform-work.feature +63 -0
- package/bdd/features/ai-panel/session.feature +69 -0
- package/bdd/features/ai-panel/table-work.feature +99 -0
- package/bdd/generated/ai-panel/platform-work.test.ts +103 -0
- package/bdd/generated/ai-panel/session.test.ts +100 -0
- package/bdd/generated/ai-panel/table-work.test.ts +150 -0
- package/bdd/package.json +1 -0
- package/bdd/tsconfig.json +13 -0
- package/css/ai.css +637 -49
- package/dist/package-test.js +4 -1707
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +742 -92317
- package/dist/package.js.map +1 -1
- package/dockerfiles/claude-runtime/.dockerignore +1 -0
- package/{.eslintrc.json → dockerfiles/claude-runtime/.eslintrc.json} +7 -16
- package/dockerfiles/claude-runtime/Dockerfile +73 -13
- package/dockerfiles/claude-runtime/agent/grokky_agent/__init__.py +0 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/__main__.py +80 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/browser_tools.py +180 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/config.py +26 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/formats.py +155 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/guard.py +87 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/hermes.py +212 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/hermes.yaml +45 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/hermes_plugin/__init__.py +8 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/hermes_plugin/plugin.yaml +3 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/protocol.py +174 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/__init__.py +21 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/anthropic.py +21 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/azure.py +46 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/base.py +127 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/bedrock.py +46 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/custom.py +40 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/databricks.py +54 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/openai_platform.py +41 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/openrouter.py +46 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/session.py +471 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/skills.py +44 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/structured.py +40 -0
- package/dockerfiles/claude-runtime/container.json +2 -2
- package/dockerfiles/claude-runtime/entrypoint.sh +20 -0
- package/dockerfiles/claude-runtime/package-lock.json +1721 -306
- package/dockerfiles/claude-runtime/package.json +20 -5
- package/dockerfiles/claude-runtime/plugin/.claude-plugin/plugin.json +5 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-calc-column/SKILL.md +92 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-chem-data/SKILL.md +250 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-chem-toolkit/SKILL.md +395 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-df-and-columns/SKILL.md +454 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-entities/SKILL.md +38 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-exec/SKILL.md +209 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-filtering/SKILL.md +185 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-grid-customization/SKILL.md +270 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-projects/SKILL.md +100 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-selection/SKILL.md +344 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-undo/SKILL.md +78 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-viewers/SKILL.md +303 -0
- package/dockerfiles/claude-runtime/pyproject.toml +18 -0
- package/dockerfiles/claude-runtime/src/agent/pool.ts +411 -0
- package/dockerfiles/claude-runtime/src/agent/turn.ts +153 -0
- package/dockerfiles/claude-runtime/src/constants.ts +20 -0
- package/dockerfiles/claude-runtime/src/credentials.ts +45 -0
- package/dockerfiles/claude-runtime/src/grounding.ts +104 -0
- package/dockerfiles/claude-runtime/src/help-index.ts +118 -0
- package/dockerfiles/claude-runtime/src/privileges.ts +8 -0
- package/dockerfiles/claude-runtime/src/prompts.ts +211 -0
- package/dockerfiles/claude-runtime/src/server.ts +134 -234
- package/dockerfiles/claude-runtime/src/session.ts +328 -0
- package/dockerfiles/claude-runtime/src/shared-api-client.ts +112 -0
- package/dockerfiles/claude-runtime/src/stream-filter.ts +80 -0
- package/dockerfiles/claude-runtime/src/sync/home-files.ts +80 -0
- package/dockerfiles/claude-runtime/src/sync/orchestrator.ts +214 -0
- package/dockerfiles/claude-runtime/src/sync/packages.ts +145 -0
- package/dockerfiles/claude-runtime/src/sync/shared-connections.ts +87 -0
- package/dockerfiles/claude-runtime/src/sync/workspace.ts +68 -0
- package/dockerfiles/claude-runtime/src/tasks.ts +124 -0
- package/dockerfiles/claude-runtime/src/tool-summary.ts +66 -0
- package/dockerfiles/claude-runtime/src/types.ts +142 -23
- package/dockerfiles/claude-runtime/src/user/installed-packages.ts +17 -0
- package/dockerfiles/claude-runtime/src/user/staged-workspace.ts +80 -0
- package/dockerfiles/claude-runtime/src/user/user-dir.ts +108 -0
- package/dockerfiles/claude-runtime/src/verify.ts +136 -0
- package/dockerfiles/claude-runtime/src/watchdog.ts +115 -0
- package/dockerfiles/claude-runtime/test/credentials.test.js +43 -0
- package/dockerfiles/claude-runtime/test/grounding.test.js +191 -0
- package/dockerfiles/claude-runtime/test/help-index.test.js +115 -0
- package/dockerfiles/claude-runtime/test/plugin-skills.test.js +57 -0
- package/dockerfiles/claude-runtime/test/prompts.test.js +62 -0
- package/dockerfiles/claude-runtime/test/reaper.test.js +60 -0
- package/dockerfiles/claude-runtime/test/stream-filter.test.js +132 -0
- package/dockerfiles/claude-runtime/test/tasks.test.js +74 -0
- package/dockerfiles/claude-runtime/test/user-dir.test.js +71 -0
- package/dockerfiles/claude-runtime/test/verify.test.js +187 -0
- package/dockerfiles/claude-runtime/test/watchdog.test.js +43 -0
- package/dockerfiles/mcp-server/.eslintrc.json +39 -0
- package/dockerfiles/mcp-server/Dockerfile +10 -2
- package/dockerfiles/mcp-server/package-lock.json +1743 -98
- package/dockerfiles/mcp-server/package.json +27 -5
- package/dockerfiles/mcp-server/src/api-client.ts +123 -66
- package/dockerfiles/mcp-server/src/format.ts +51 -0
- package/dockerfiles/mcp-server/src/index.ts +44 -113
- package/dockerfiles/mcp-server/src/ops.ts +325 -0
- package/dockerfiles/mcp-server/src/shared-api-client.ts +81 -0
- package/dockerfiles/mcp-server/test/format.test.js +62 -0
- package/dockerfiles/mcp-server/test/ops.test.js +84 -0
- package/dockerfiles/mcp-server/test/shared-api-client.test.js +35 -0
- package/dockerfiles/queue/Dockerfile +2 -0
- package/dockerfiles/queue/container.json +7 -0
- package/docs/AUDIT-2026-08-03.md +1064 -0
- package/docs/BENCHMARK.md +292 -0
- package/docs/CLAUDE_CODE_FLOW.md +746 -0
- package/docs/EXAMPLES.md +82 -0
- package/docs/FEATURES.md +71 -0
- package/docs/IMPLEMENTATION.md +128 -0
- package/docs/LATENCY.md +170 -0
- package/docs/VISION.md +36 -0
- package/files/benchmark/suite.yaml +404 -0
- package/files/scripts/process-cro-results.md +14 -0
- package/files/suggestions.yaml +344 -0
- package/package.json +39 -97
- package/src/ai/ai-window.ts +157 -0
- package/src/ai/benchmark/benchmark.ts +737 -0
- package/src/ai/db-view-functions.ts +56 -0
- package/src/ai/engine.ts +98 -0
- package/src/ai/gemma-engine.ts +81 -0
- package/src/ai/panel.ts +1385 -0
- package/src/ai/prompt-suggestions.ts +209 -0
- package/src/ai/search/combined-search.ts +244 -0
- package/src/{llm-utils → ai/search}/query-matching.ts +46 -167
- package/src/{llm-utils → ai}/storage.ts +0 -1
- package/src/ai/table-tools.ts +145 -0
- package/src/ai/ui.ts +720 -0
- package/src/ai/usage-limiter.ts +105 -0
- package/src/ai/view-tools.ts +352 -0
- package/src/claude/ai-feature.ts +16 -0
- package/src/claude/exec-blocks.ts +176 -0
- package/src/claude/queue-task.ts +84 -0
- package/src/claude/runtime-client.ts +310 -0
- package/src/claude/turn-log.ts +114 -0
- package/src/claude/undoable.ts +105 -0
- package/src/{llm-utils → db}/db-index-tools.ts +24 -32
- package/src/db/sql-tools.ts +336 -0
- package/src/depr/LLM-client.ts +251 -0
- package/src/depr/ai-panel.ts +174 -0
- package/src/depr/chatgpt-assistant.ts +257 -0
- package/src/depr/creds.ts +30 -0
- package/src/depr/deepwikiclient.ts +118 -0
- package/src/depr/indexes/dg-repository-index.ts +266 -0
- package/src/depr/interfaces.ts +170 -0
- package/src/depr/is-help-request.ts +39 -0
- package/src/depr/prompt-engine.ts +52 -0
- package/src/depr/rendering-tools.ts +103 -0
- package/src/depr/script-tools.ts +785 -0
- package/src/depr/tableview-tools.ts +746 -0
- package/src/depr/viewers-ai.ts +67 -0
- package/src/package-api.ts +87 -28
- package/src/package-test.ts +1 -0
- package/src/package.g.ts +98 -48
- package/src/package.ts +211 -157
- package/src/polyfills.ts +12 -0
- package/src/utils.ts +128 -0
- package/tsconfig.json +8 -70
- package/webpack.config.js +3 -49
- package/.eslintignore +0 -2
- package/src/ai-panel.ts +0 -174
- package/src/claude-code/claude-panel.ts +0 -34
- package/src/claude-code/claude-runtime-client.ts +0 -148
- package/src/llm-utils/LLM-client.ts +0 -251
- package/src/llm-utils/combined-search.ts +0 -162
- package/src/llm-utils/creds.ts +0 -30
- package/src/llm-utils/deepwikiclient.ts +0 -118
- package/src/llm-utils/indexes/dg-repository-index.ts +0 -266
- package/src/llm-utils/panel.ts +0 -866
- package/src/llm-utils/script-tools.ts +0 -784
- package/src/llm-utils/sql-tools.ts +0 -840
- package/src/llm-utils/tableview-tools.ts +0 -704
- package/src/llm-utils/ui.ts +0 -315
- package/src/prompt-engine/chatgpt-assistant.ts +0 -257
- package/src/prompt-engine/interfaces.ts +0 -170
- package/src/prompt-engine/prompt-engine.ts +0 -52
- package/src/prompt-engine/rendering-tools.ts +0 -103
- package/src/prompts/is-help-request.ts +0 -26
- package/src/viewers-ai.ts +0 -67
- /package/src/{llm-utils → db}/indexes/biologics-index.ts +0 -0
- /package/src/{llm-utils → db}/indexes/chembl-index.ts +0 -0
- /package/src/{llm-utils → db}/query-meta-utils.ts +0 -0
- /package/src/{llm-utils/depr → depr}/AI-API-providers/openai-chat-completions-provider.ts +0 -0
- /package/src/{llm-utils/depr → depr}/AI-API-providers/openai-responses-provider.ts +0 -0
- /package/src/{llm-utils/depr → depr}/AI-API-providers/types.ts +0 -0
- /package/src/{llm-utils/depr → depr}/depr.ts +0 -0
- /package/src/{llm-utils/depr → depr}/embeddings.ts +0 -0
- /package/src/{llm-utils/depr → depr}/sql-utils.ts +0 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import {createHash, randomUUID} from 'node:crypto';
|
|
2
|
+
import * as api from './api-client.js';
|
|
3
|
+
|
|
4
|
+
// Operation registry backing the domain tools. Previously each of these was its own MCP tool, so
|
|
5
|
+
// all ~32 schemas sat in the model's prompt prefix on every turn (measured: 3,847 tokens/call).
|
|
6
|
+
// Collapsing them behind one tool per domain keeps the same reach at a fraction of the prefix:
|
|
7
|
+
// the tool description carries only the operation NAMES, and a call with no `op` returns the full
|
|
8
|
+
// parameter schema for that domain. See docs/BENCHMARK.md "context diet".
|
|
9
|
+
|
|
10
|
+
export type ParamType = 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
11
|
+
|
|
12
|
+
export interface Param {
|
|
13
|
+
type: ParamType;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
desc: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Op {
|
|
19
|
+
desc: string;
|
|
20
|
+
params?: Record<string, Param>;
|
|
21
|
+
/** File-ish payload: never array-paged, capped at a larger size than list results. */
|
|
22
|
+
raw?: boolean;
|
|
23
|
+
/** Destructive op: returns the dry-run summary shown to the user before `run` is allowed. */
|
|
24
|
+
preview?: (a: Record<string, any>) => Promise<Record<string, unknown>>;
|
|
25
|
+
run: (a: Record<string, any>) => Promise<unknown>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Domain {
|
|
29
|
+
tool: string;
|
|
30
|
+
blurb: string;
|
|
31
|
+
ops: Record<string, Op>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Read-only by operation name, matching the runtime's verify gate (verify.ts). Naming ops so the
|
|
35
|
+
// prefix is meaningful is what lets the gate stay a pure name check after consolidation — the tool
|
|
36
|
+
// name alone can no longer say whether a call mutates anything.
|
|
37
|
+
const READONLY_RE = /^(whoami$|list|get|search|read|download|find)/;
|
|
38
|
+
|
|
39
|
+
export const isReadonlyOp = (op: string): boolean => READONLY_RE.test(op);
|
|
40
|
+
|
|
41
|
+
const str = (desc: string, required = false): Param => ({type: 'string', required, desc});
|
|
42
|
+
const bool = (desc: string): Param => ({type: 'boolean', desc});
|
|
43
|
+
|
|
44
|
+
const CONFIRM = str('Confirm token from the dry-run response. Omit on the first call.');
|
|
45
|
+
|
|
46
|
+
const DRY_RUN_DESC = ' The first call is a dry run: it returns a summary plus a confirm token; ' +
|
|
47
|
+
'repeat the call with `confirm` after the user approves.';
|
|
48
|
+
|
|
49
|
+
const CONFIRM_SALT = randomUUID();
|
|
50
|
+
|
|
51
|
+
export const confirmTokenFor = (tool: string, op: string, args: Record<string, unknown>): string =>
|
|
52
|
+
createHash('sha256').update(`${CONFIRM_SALT}:${tool}.${op}:${JSON.stringify(args, Object.keys(args).sort())}`)
|
|
53
|
+
.digest('hex').slice(0, 8);
|
|
54
|
+
|
|
55
|
+
const FILTER = str('Smart search filter, e.g. name="Chem"');
|
|
56
|
+
const LIMIT = {type: 'number' as const, desc: 'Max items to return (default 50)'};
|
|
57
|
+
const OFFSET = {type: 'number' as const, desc: 'Items to skip, for paging (default 0)'};
|
|
58
|
+
const PAGING = {limit: LIMIT, offset: OFFSET};
|
|
59
|
+
// Every operation shares these; the dry-run note of a destructive op already says what `confirm` is for.
|
|
60
|
+
const SELF_EVIDENT = new Set<Param>([LIMIT, OFFSET, CONFIRM]);
|
|
61
|
+
|
|
62
|
+
export const DOMAINS: Domain[] = [
|
|
63
|
+
{
|
|
64
|
+
tool: 'datagrok_functions',
|
|
65
|
+
blurb: 'Datagrok functions, scripts and data queries — discover, inspect, run, and create them.',
|
|
66
|
+
ops: {
|
|
67
|
+
list: {
|
|
68
|
+
desc: 'List functions matching an optional smart filter.',
|
|
69
|
+
params: {filter: FILTER, ...PAGING},
|
|
70
|
+
run: (a) => api.listFunctions(a.filter),
|
|
71
|
+
},
|
|
72
|
+
get: {
|
|
73
|
+
desc: 'Full details of one function, including its parameter list.',
|
|
74
|
+
params: {id: str('Function ID or name, e.g. "Chem:getMolProperty"', true)},
|
|
75
|
+
run: (a) => api.getFunction(a.id),
|
|
76
|
+
},
|
|
77
|
+
call: {
|
|
78
|
+
desc: 'Execute a function and return its result.',
|
|
79
|
+
params: {
|
|
80
|
+
name: str('Function name, e.g. "Chem:smilesToMw"', true),
|
|
81
|
+
params: {type: 'object', desc: 'Arguments keyed by input name'},
|
|
82
|
+
},
|
|
83
|
+
run: (a) => api.callFunction(a.name, a.params),
|
|
84
|
+
},
|
|
85
|
+
list_scripts: {
|
|
86
|
+
desc: 'List all scripts.',
|
|
87
|
+
params: PAGING,
|
|
88
|
+
run: () => api.listFunctions('source="script"'),
|
|
89
|
+
},
|
|
90
|
+
list_queries: {
|
|
91
|
+
desc: 'List all data queries.',
|
|
92
|
+
params: PAGING,
|
|
93
|
+
run: () => api.listFunctions('source="data-query"'),
|
|
94
|
+
},
|
|
95
|
+
create_script: {
|
|
96
|
+
desc: 'Create a new script.',
|
|
97
|
+
params: {
|
|
98
|
+
script: str('Script source, starting with the header the platform reads: `#name: X`, `#language: python`, ' +
|
|
99
|
+
'one `#input: <type> <name>` per input and one `#output: <type> <name>` per output ' +
|
|
100
|
+
'(types: int, double, string, bool, dataframe, column); the body assigns each output variable', true),
|
|
101
|
+
name: str('Script name'),
|
|
102
|
+
language: str('python | r | julia | nodejs | grok | octave (default python)'),
|
|
103
|
+
},
|
|
104
|
+
run: (a) => api.saveFunction({
|
|
105
|
+
source: 'script', script: a.script,
|
|
106
|
+
name: a.name ?? 'Untitled Script', language: a.language ?? 'python',
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
create_query: {
|
|
110
|
+
desc: 'Create a new data query against a connection.',
|
|
111
|
+
params: {
|
|
112
|
+
connectionId: str('ID of the data connection', true),
|
|
113
|
+
query: str('SQL query text', true),
|
|
114
|
+
name: str('Query name'),
|
|
115
|
+
},
|
|
116
|
+
run: (a) => api.saveFunction({
|
|
117
|
+
source: 'data-query', query: a.query,
|
|
118
|
+
connection: {id: a.connectionId}, name: a.name ?? 'Untitled Query',
|
|
119
|
+
}),
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
tool: 'datagrok_files',
|
|
125
|
+
blurb: 'Files in connector storage (e.g. "System:DemoFiles") — browse, read, write.',
|
|
126
|
+
ops: {
|
|
127
|
+
list: {
|
|
128
|
+
desc: 'List files in a connector directory.',
|
|
129
|
+
params: {
|
|
130
|
+
connector: str('Connector name, e.g. "System:DemoFiles"', true),
|
|
131
|
+
path: str('Directory path within the connector'), ...PAGING,
|
|
132
|
+
},
|
|
133
|
+
run: (a) => api.listFiles(a.connector, a.path),
|
|
134
|
+
},
|
|
135
|
+
download: {
|
|
136
|
+
desc: 'Read a file\'s contents.',
|
|
137
|
+
params: {connector: str('Connector name', true), path: str('File path within the connector', true)},
|
|
138
|
+
raw: true,
|
|
139
|
+
run: (a) => api.downloadFile(a.connector, a.path),
|
|
140
|
+
},
|
|
141
|
+
upload: {
|
|
142
|
+
desc: 'Write content to a file.',
|
|
143
|
+
params: {
|
|
144
|
+
connector: str('Connector name', true), path: str('File path within the connector', true),
|
|
145
|
+
content: str('File content', true),
|
|
146
|
+
},
|
|
147
|
+
run: (a) => api.uploadFile(a.connector, a.path, a.content),
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
tool: 'datagrok_projects',
|
|
153
|
+
blurb: 'Projects — the shareable unit that bundles tables, layouts, queries and connections.',
|
|
154
|
+
ops: {
|
|
155
|
+
list: {desc: 'List projects.', params: {filter: FILTER, ...PAGING}, run: (a) => api.listProjects(a.filter)},
|
|
156
|
+
get: {desc: 'Details of one project.', params: {id: str('Project ID', true)}, run: (a) => api.getProject(a.id)},
|
|
157
|
+
list_recent: {desc: 'List recently accessed projects.', params: PAGING, run: () => api.listRecentProjects()},
|
|
158
|
+
search: {
|
|
159
|
+
desc: 'Find a project by name.',
|
|
160
|
+
params: {name: str('Project name to search for', true), ...PAGING},
|
|
161
|
+
run: (a) => api.searchProject(a.name),
|
|
162
|
+
},
|
|
163
|
+
create: {
|
|
164
|
+
desc: 'Create a new project.',
|
|
165
|
+
params: {name: str('Project name', true), description: str('Project description')},
|
|
166
|
+
run: (a) => api.createProject(a.name, a.description),
|
|
167
|
+
},
|
|
168
|
+
delete: {
|
|
169
|
+
desc: 'Delete a project.' + DRY_RUN_DESC,
|
|
170
|
+
params: {id: str('Project ID', true), confirm: CONFIRM},
|
|
171
|
+
preview: async (a) => {
|
|
172
|
+
const p: any = await api.getProject(a.id);
|
|
173
|
+
return {name: p.friendlyName ?? p.name, owner: p.author?.friendlyName ?? p.author?.login,
|
|
174
|
+
createdOn: p.createdOn};
|
|
175
|
+
},
|
|
176
|
+
run: (a) => api.deleteProject(a.id),
|
|
177
|
+
},
|
|
178
|
+
attach_entity: {
|
|
179
|
+
desc: 'Attach an existing SERVER-SIDE entity (table, layout, script, query, connection) to a ' +
|
|
180
|
+
'project. Pass a real server id — not a client-side stub from t.getTableInfo().id.',
|
|
181
|
+
params: {
|
|
182
|
+
projectId: str('Project ID (UUID)', true),
|
|
183
|
+
entityId: str('Entity ID (UUID) of the server-side entity', true),
|
|
184
|
+
link: bool('true creates a reference; false (default) means the project owns it'),
|
|
185
|
+
},
|
|
186
|
+
run: (a) => api.attachEntityToProject(a.projectId, a.entityId, a.link ?? false),
|
|
187
|
+
},
|
|
188
|
+
share: {
|
|
189
|
+
desc: 'Share a project with user groups. If the entity is not a project, its owning project ' +
|
|
190
|
+
'is shared. Returns per-group success/already-shared/failure.',
|
|
191
|
+
params: {
|
|
192
|
+
projectId: str('Project ID (UUID) or "namespace:name"', true),
|
|
193
|
+
groups: {type: 'array', required: true, desc: 'Group names, e.g. ["clinical-ops"]'},
|
|
194
|
+
access: str('"View" (default) or "Edit"'),
|
|
195
|
+
},
|
|
196
|
+
run: (a) => api.shareProject(a.projectId, a.groups, a.access === 'Edit' ? 'Edit' : 'View'),
|
|
197
|
+
},
|
|
198
|
+
list_shares: {
|
|
199
|
+
desc: 'Groups a project is shared with, by access level.',
|
|
200
|
+
params: {projectId: str('Project ID (UUID)', true)},
|
|
201
|
+
run: (a) => api.listProjectShares(a.projectId),
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
tool: 'datagrok_spaces',
|
|
207
|
+
blurb: 'Spaces — hierarchical containers that group entities and hold their own file storage.',
|
|
208
|
+
ops: {
|
|
209
|
+
list: {desc: 'List root spaces.', params: {filter: FILTER, ...PAGING}, run: (a) => api.listSpaces(a.filter)},
|
|
210
|
+
get: {desc: 'Details of one space.', params: {id: str('Space ID', true)}, run: (a) => api.getSpace(a.id)},
|
|
211
|
+
list_children: {
|
|
212
|
+
desc: 'List a space\'s children — subspaces and contained entities.',
|
|
213
|
+
params: {
|
|
214
|
+
spaceId: str('Space ID', true),
|
|
215
|
+
types: str('Comma-separated entity types, e.g. "Script,DataQuery"'),
|
|
216
|
+
includeLinked: bool('Include linked (non-owned) children'), ...PAGING,
|
|
217
|
+
},
|
|
218
|
+
run: (a) => api.listSpaceChildren(a.spaceId, a.types, a.includeLinked),
|
|
219
|
+
},
|
|
220
|
+
create: {desc: 'Create a root space.', params: {name: str('Space name', true)},
|
|
221
|
+
run: (a) => api.createRootSpace(a.name)},
|
|
222
|
+
delete: {
|
|
223
|
+
desc: 'Delete a space.' + DRY_RUN_DESC,
|
|
224
|
+
params: {id: str('Space ID', true), confirm: CONFIRM},
|
|
225
|
+
preview: async (a) => {
|
|
226
|
+
const s: any = await api.getSpace(a.id);
|
|
227
|
+
const children = await api.listSpaceChildren(a.id);
|
|
228
|
+
return {name: s.friendlyName ?? s.name, owner: s.author?.friendlyName ?? s.author?.login,
|
|
229
|
+
children: children.length};
|
|
230
|
+
},
|
|
231
|
+
run: (a) => api.deleteSpace(a.id),
|
|
232
|
+
},
|
|
233
|
+
create_subspace: {
|
|
234
|
+
desc: 'Create a subspace inside a space.',
|
|
235
|
+
params: {
|
|
236
|
+
spaceId: str('Parent space ID', true), name: str('Subspace name', true),
|
|
237
|
+
link: bool('Create as a link reference instead of an owned child'),
|
|
238
|
+
},
|
|
239
|
+
run: (a) => api.createSubspace(a.spaceId, a.name, a.link),
|
|
240
|
+
},
|
|
241
|
+
add_entity: {
|
|
242
|
+
desc: 'Add an entity (script, query, connection, …) to a space.',
|
|
243
|
+
params: {
|
|
244
|
+
spaceId: str('Space ID', true), entityId: str('Entity ID', true),
|
|
245
|
+
link: bool('Add as a link reference instead of an owned child'),
|
|
246
|
+
},
|
|
247
|
+
run: (a) => api.addEntityToSpace(a.spaceId, a.entityId, a.link),
|
|
248
|
+
},
|
|
249
|
+
remove_entity: {
|
|
250
|
+
desc: 'Remove an entity from a space.',
|
|
251
|
+
params: {spaceId: str('Space ID', true), entityId: str('Entity ID', true)},
|
|
252
|
+
run: (a) => api.removeEntityFromSpace(a.spaceId, a.entityId),
|
|
253
|
+
},
|
|
254
|
+
read_file: {
|
|
255
|
+
desc: 'Read a file from a space\'s storage.',
|
|
256
|
+
params: {spaceId: str('Space ID', true), path: str('File path within the space', true)},
|
|
257
|
+
raw: true,
|
|
258
|
+
run: (a) => api.readSpaceFile(a.spaceId, a.path),
|
|
259
|
+
},
|
|
260
|
+
write_file: {
|
|
261
|
+
desc: 'Write a file into a space\'s storage.',
|
|
262
|
+
params: {
|
|
263
|
+
spaceId: str('Space ID', true), path: str('File path within the space', true),
|
|
264
|
+
content: str('File content', true),
|
|
265
|
+
},
|
|
266
|
+
run: (a) => api.writeSpaceFile(a.spaceId, a.path, a.content),
|
|
267
|
+
},
|
|
268
|
+
delete_file: {
|
|
269
|
+
desc: 'Delete a file from a space\'s storage.' + DRY_RUN_DESC,
|
|
270
|
+
params: {spaceId: str('Space ID', true), path: str('File path within the space', true), confirm: CONFIRM},
|
|
271
|
+
preview: async (a) => {
|
|
272
|
+
const s: any = await api.getSpace(a.spaceId);
|
|
273
|
+
return {space: s.friendlyName ?? s.name, path: a.path};
|
|
274
|
+
},
|
|
275
|
+
run: (a) => api.deleteSpaceFile(a.spaceId, a.path),
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
tool: 'datagrok_platform',
|
|
281
|
+
blurb: 'Who you are, and the instance\'s users, groups and data connections.',
|
|
282
|
+
ops: {
|
|
283
|
+
whoami: {desc: 'The authenticated user.', run: () => api.getCurrentUser()},
|
|
284
|
+
list_users: {desc: 'List users.', params: {filter: FILTER, ...PAGING}, run: (a) => api.listUsers(a.filter)},
|
|
285
|
+
list_groups: {desc: 'List groups.', params: {filter: FILTER, ...PAGING}, run: (a) => api.listGroups(a.filter)},
|
|
286
|
+
list_connections: {
|
|
287
|
+
desc: 'List data connections.',
|
|
288
|
+
params: {filter: FILTER, ...PAGING},
|
|
289
|
+
run: (a) => api.listConnections(a.filter),
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
];
|
|
294
|
+
|
|
295
|
+
/** One-line operation menu for a domain — what goes in the tool description. */
|
|
296
|
+
/** Each operation with its purpose and every parameter's type and meaning, e.g.
|
|
297
|
+
* `get — Full details of one function…; id: string — Function ID or name`: enough to call it right without
|
|
298
|
+
* first listing the domain. */
|
|
299
|
+
export function opMenu(d: Domain): string {
|
|
300
|
+
return Object.entries(d.ops).map(([name, op]) => {
|
|
301
|
+
const params = Object.entries(op.params ?? {}).map(([p, meta]) => {
|
|
302
|
+
const desc = SELF_EVIDENT.has(meta) ? '' : ` — ${meta.desc}`;
|
|
303
|
+
return `\n ${p}${meta.required ? '' : '?'}: ${meta.type}${desc}`;
|
|
304
|
+
}).join('');
|
|
305
|
+
return `- ${name} — ${op.desc}${params}`;
|
|
306
|
+
}).join('\n');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Full schema for a domain, returned when a call omits `op` or names an unknown one. */
|
|
310
|
+
export function catalog(d: Domain): object {
|
|
311
|
+
const operations: Record<string, object> = {};
|
|
312
|
+
for (const [name, op] of Object.entries(d.ops)) {
|
|
313
|
+
const params: Record<string, string> = {};
|
|
314
|
+
for (const [p, meta] of Object.entries(op.params ?? {}))
|
|
315
|
+
params[p] = `${meta.type}${meta.required ? ', required' : ''} — ${meta.desc}`;
|
|
316
|
+
operations[name] = Object.keys(params).length ? {description: op.desc, params} : {description: op.desc};
|
|
317
|
+
}
|
|
318
|
+
return {tool: d.tool, description: d.blurb, operations};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function missingParams(op: Op, args: Record<string, any>): string[] {
|
|
322
|
+
return Object.entries(op.params ?? {})
|
|
323
|
+
.filter(([name, meta]) => meta.required && args[name] === undefined)
|
|
324
|
+
.map(([name]) => name);
|
|
325
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Duplicated in claude-runtime/src/shared-api-client.ts — keep in sync.
|
|
2
|
+
// Can't be shared because each Docker container builds with its own context.
|
|
3
|
+
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
4
|
+
|
|
5
|
+
interface RequestContext {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
apiUrl: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const ctxStore = new AsyncLocalStorage<RequestContext>();
|
|
11
|
+
|
|
12
|
+
function _ctx(): RequestContext {
|
|
13
|
+
const ctx = ctxStore.getStore();
|
|
14
|
+
if (!ctx)
|
|
15
|
+
throw new Error('No request context — missing x-user-api-key / x-datagrok-api-url headers');
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function runWithContext<T>(ctx: RequestContext, fn: () => T): T {
|
|
20
|
+
return ctxStore.run(ctx, fn);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface Connection {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function toGrokPath(name: string): string {
|
|
29
|
+
return name.replace(/:/g, '.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function request<T = unknown>(
|
|
33
|
+
method: string, path: string, body?: unknown, headers?: Record<string, string>,
|
|
34
|
+
): Promise<T> {
|
|
35
|
+
const ctx = _ctx();
|
|
36
|
+
const url = `${ctx.apiUrl}/${path.replace(/^\//, '')}`;
|
|
37
|
+
const res = await fetch(url, {
|
|
38
|
+
method,
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
'Authorization': ctx.apiKey,
|
|
42
|
+
...headers,
|
|
43
|
+
},
|
|
44
|
+
body: body === undefined ? undefined : (typeof body === 'string' ? body : JSON.stringify(body)),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!res.ok) {
|
|
48
|
+
const text = await res.text();
|
|
49
|
+
throw new Error(`HTTP ${res.status}: ${text}`);
|
|
50
|
+
}
|
|
51
|
+
if (res.headers.has('api-error')) {
|
|
52
|
+
const text = await res.text();
|
|
53
|
+
throw new Error(`API error: ${text}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const ct = res.headers.get('content-type') ?? '';
|
|
57
|
+
if (ct.includes('application/json'))
|
|
58
|
+
return res.json();
|
|
59
|
+
return res.text() as T;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function listFiles(connector: string, path?: string): Promise<unknown[]> {
|
|
63
|
+
const searchName = connector.includes(':') ? connector.split(':').pop()! : connector;
|
|
64
|
+
const conns = await request<Connection[]>(
|
|
65
|
+
'GET', `/public/v1/connections?text=${encodeURIComponent(searchName)}`,
|
|
66
|
+
);
|
|
67
|
+
if (!conns.length)
|
|
68
|
+
throw new Error(`Connection "${connector}" not found`);
|
|
69
|
+
const filePath = path ? `${path.replace(/^\//, '')}/` : '';
|
|
70
|
+
return request('GET', `/connectors/connections/${conns[0].id}/files/${filePath}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function downloadFile(connector: string, path: string): Promise<unknown> {
|
|
74
|
+
return request('GET', `/public/v1/files/${toGrokPath(connector)}/${path}`, undefined,
|
|
75
|
+
{'Accept': 'application/octet-stream'});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function uploadFile(connector: string, path: string, content: string): Promise<unknown> {
|
|
79
|
+
return request('POST', `/public/v1/files/${toGrokPath(connector)}/${path}`, content,
|
|
80
|
+
{'Content-Type': 'application/octet-stream'});
|
|
81
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Result shaping. A tool result stays in the transcript and is re-read on every later hop of the
|
|
2
|
+
// turn, so these caps are a per-turn multiplier, not a one-off saving.
|
|
3
|
+
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import assert from 'node:assert';
|
|
6
|
+
import {formatResult, formatError} from '../dist/format.js';
|
|
7
|
+
|
|
8
|
+
const text = (r) => r.content[0].text;
|
|
9
|
+
|
|
10
|
+
test('results are compact JSON, not pretty-printed', () => {
|
|
11
|
+
const out = text(formatResult({a: 1, b: {c: 2}}));
|
|
12
|
+
assert.equal(out, '{"a":1,"b":{"c":2}}');
|
|
13
|
+
assert.ok(!out.includes('\n'), 'pretty-printing spends tokens on whitespace');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('array results are paged with a note pointing at offset/limit', () => {
|
|
17
|
+
const data = Array.from({length: 120}, (_, i) => ({i}));
|
|
18
|
+
const out = JSON.parse(text(formatResult(data, {paged: true, args: {}})));
|
|
19
|
+
assert.equal(out.total, 120);
|
|
20
|
+
assert.equal(out.items.length, 50, 'default page is 50');
|
|
21
|
+
assert.equal(out.showing, '1-50');
|
|
22
|
+
assert.match(out.note, /offset/);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('paging honours offset and limit', () => {
|
|
26
|
+
const data = Array.from({length: 120}, (_, i) => ({i}));
|
|
27
|
+
const out = JSON.parse(text(formatResult(data, {paged: true, args: {offset: 100, limit: 5}})));
|
|
28
|
+
assert.equal(out.items.length, 5);
|
|
29
|
+
assert.equal(out.items[0].i, 100);
|
|
30
|
+
assert.equal(out.showing, '101-105');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('a short array is returned bare — no paging envelope to unwrap', () => {
|
|
34
|
+
const out = JSON.parse(text(formatResult([{a: 1}], {paged: true, args: {}})));
|
|
35
|
+
assert.deepEqual(out, [{a: 1}]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('oversized results are truncated with an actionable hint', () => {
|
|
39
|
+
const out = text(formatResult('x'.repeat(50_000)));
|
|
40
|
+
assert.ok(out.length < 21_000, 'must be capped');
|
|
41
|
+
assert.match(out, /truncated at 20000 chars/);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('file payloads get the larger cap and are never paged', () => {
|
|
45
|
+
const body = Array.from({length: 200}, (_, i) => `line ${i}`);
|
|
46
|
+
const out = text(formatResult(body, {raw: true, paged: false}));
|
|
47
|
+
assert.deepEqual(JSON.parse(out).length, 200, 'file content must not be silently paged away');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('errors come back as a readable result, not a throw', () => {
|
|
51
|
+
const result = formatError('unknown op', {available: ['list', 'get']});
|
|
52
|
+
assert.equal(result.isError, true, 'errors must carry the MCP isError flag');
|
|
53
|
+
const out = JSON.parse(text(result));
|
|
54
|
+
assert.equal(out.error, 'unknown op');
|
|
55
|
+
assert.deepEqual(out.available, ['list', 'get']);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('a huge error message is truncated but stays parseable JSON', () => {
|
|
59
|
+
const out = JSON.parse(text(formatError('boom\n' + 'at frame\n'.repeat(5_000))));
|
|
60
|
+
assert.ok(out.error.length < 2_100, 'must be capped');
|
|
61
|
+
assert.match(out.error, /truncated at 2000 chars/);
|
|
62
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The op registry behind the domain tools. Tests run against the compiled dist/.
|
|
2
|
+
//
|
|
3
|
+
// The important invariant here is the naming convention: the claude-runtime verify gate decides
|
|
4
|
+
// whether a call mutated anything by matching the OP NAME against the same read-verb prefixes
|
|
5
|
+
// (claude-runtime/src/verify.ts READONLY_NAME_RE). The two regexes live in different containers
|
|
6
|
+
// and cannot import each other, so an op named outside the convention silently changes whether
|
|
7
|
+
// the runtime demands verification. These tests are the guard against that drift.
|
|
8
|
+
|
|
9
|
+
import test from 'node:test';
|
|
10
|
+
import assert from 'node:assert';
|
|
11
|
+
import {DOMAINS, catalog, opMenu, missingParams, isReadonlyOp} from '../dist/ops.js';
|
|
12
|
+
|
|
13
|
+
const allOps = () => DOMAINS.flatMap((d) => Object.entries(d.ops).map(([name, op]) => ({d, name, op})));
|
|
14
|
+
|
|
15
|
+
const READ_VERBS = ['whoami', 'list', 'get', 'search', 'read', 'download', 'find'];
|
|
16
|
+
const WRITE_VERBS = ['create', 'delete', 'add', 'remove', 'write', 'upload', 'share', 'attach', 'call', 'update'];
|
|
17
|
+
|
|
18
|
+
test('every op is runnable and documented', () => {
|
|
19
|
+
for (const {d, name, op} of allOps()) {
|
|
20
|
+
assert.equal(typeof op.run, 'function', `${d.tool}.${name} has no run()`);
|
|
21
|
+
assert.ok(op.desc?.length > 10, `${d.tool}.${name} needs a real description`);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('op names follow the read/write verb convention the runtime verify gate depends on', () => {
|
|
26
|
+
for (const {d, name} of allOps()) {
|
|
27
|
+
const verb = [...READ_VERBS, ...WRITE_VERBS].find((v) => name.startsWith(v));
|
|
28
|
+
assert.ok(verb, `${d.tool}.${name} starts with no known verb — the runtime cannot classify it`);
|
|
29
|
+
assert.equal(isReadonlyOp(name), READ_VERBS.some((v) => name.startsWith(v)),
|
|
30
|
+
`${d.tool}.${name} is classified inconsistently with its verb`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('tool names are unique and namespaced', () => {
|
|
35
|
+
const names = DOMAINS.map((d) => d.tool);
|
|
36
|
+
assert.equal(new Set(names).size, names.length, 'duplicate tool name');
|
|
37
|
+
for (const n of names)
|
|
38
|
+
assert.match(n, /^datagrok_[a-z]+$/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('catalog exposes every op with its parameters', () => {
|
|
42
|
+
const spaces = DOMAINS.find((d) => d.tool === 'datagrok_spaces');
|
|
43
|
+
const c = catalog(spaces);
|
|
44
|
+
assert.equal(Object.keys(c.operations).length, Object.keys(spaces.ops).length);
|
|
45
|
+
assert.match(c.operations.create_subspace.params.spaceId, /required/);
|
|
46
|
+
assert.ok(!/required/.test(c.operations.create_subspace.params.link), 'link is optional');
|
|
47
|
+
assert.equal(c.operations.list.description, spaces.ops.list.desc);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('opMenu lists every op name — it is what the model sees in the tool description', () => {
|
|
51
|
+
for (const d of DOMAINS) {
|
|
52
|
+
const menu = opMenu(d);
|
|
53
|
+
for (const name of Object.keys(d.ops))
|
|
54
|
+
assert.ok(menu.includes(name), `${d.tool} menu is missing ${name}`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('missingParams reports only absent required params', () => {
|
|
59
|
+
const spaces = DOMAINS.find((d) => d.tool === 'datagrok_spaces');
|
|
60
|
+
assert.deepEqual(missingParams(spaces.ops.create_subspace, {}), ['spaceId', 'name']);
|
|
61
|
+
assert.deepEqual(missingParams(spaces.ops.create_subspace, {spaceId: 'a'}), ['name']);
|
|
62
|
+
assert.deepEqual(missingParams(spaces.ops.create_subspace, {spaceId: 'a', name: 'b'}), []);
|
|
63
|
+
assert.deepEqual(missingParams(spaces.ops.list, {}), [], 'filter is optional');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('the consolidated surface still covers every operation the split tools had', () => {
|
|
67
|
+
// The 32 tools this replaced, by the domain+op they map onto. A regression here means an
|
|
68
|
+
// operation was dropped in the consolidation rather than renamed.
|
|
69
|
+
const expected = {
|
|
70
|
+
datagrok_functions: ['list', 'get', 'call', 'list_scripts', 'list_queries', 'create_script', 'create_query'],
|
|
71
|
+
datagrok_files: ['list', 'download', 'upload'],
|
|
72
|
+
datagrok_projects: ['list', 'get', 'create', 'delete', 'search', 'list_recent', 'attach_entity',
|
|
73
|
+
'share', 'list_shares'],
|
|
74
|
+
datagrok_spaces: ['list', 'get', 'create', 'delete', 'create_subspace', 'list_children',
|
|
75
|
+
'add_entity', 'remove_entity', 'read_file', 'write_file', 'delete_file'],
|
|
76
|
+
datagrok_platform: ['whoami', 'list_users', 'list_groups', 'list_connections'],
|
|
77
|
+
};
|
|
78
|
+
for (const [tool, ops] of Object.entries(expected)) {
|
|
79
|
+
const d = DOMAINS.find((x) => x.tool === tool);
|
|
80
|
+
assert.ok(d, `missing domain tool ${tool}`);
|
|
81
|
+
for (const op of ops)
|
|
82
|
+
assert.ok(d.ops[op], `${tool} lost operation ${op}`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// request() must send string bodies (file uploads) over the wire untouched while still
|
|
2
|
+
// JSON-encoding object bodies — a stringified upload corrupts every stored file.
|
|
3
|
+
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import assert from 'node:assert';
|
|
6
|
+
import http from 'node:http';
|
|
7
|
+
import {runWithContext, uploadFile, downloadFile, request} from '../dist/shared-api-client.js';
|
|
8
|
+
|
|
9
|
+
const files = new Map();
|
|
10
|
+
const server = http.createServer((req, res) => {
|
|
11
|
+
let body = '';
|
|
12
|
+
req.on('data', (c) => body += c);
|
|
13
|
+
req.on('end', () => {
|
|
14
|
+
if (req.method === 'POST')
|
|
15
|
+
files.set(req.url, body);
|
|
16
|
+
res.setHeader('content-type', 'application/octet-stream');
|
|
17
|
+
res.end(files.get(req.url) ?? '');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
await new Promise((r) => server.listen(0, '127.0.0.1', r));
|
|
21
|
+
server.unref();
|
|
22
|
+
const ctx = {apiKey: 'key', apiUrl: `http://127.0.0.1:${server.address().port}`};
|
|
23
|
+
|
|
24
|
+
test('file upload → download round-trips byte-identically', () => runWithContext(ctx, async () => {
|
|
25
|
+
const content = 'line1\nline2 "quoted" back\\slash\ttab юникод ✓\n{"json": [1, 2, 3]}\n';
|
|
26
|
+
await uploadFile('System:DemoFiles', 'roundtrip.txt', content);
|
|
27
|
+
assert.equal(files.get('/public/v1/files/System.DemoFiles/roundtrip.txt'), content,
|
|
28
|
+
'uploaded body must reach the server as-is, not JSON-encoded');
|
|
29
|
+
assert.equal(await downloadFile('System:DemoFiles', 'roundtrip.txt'), content);
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
test('object bodies are still JSON-encoded', () => runWithContext(ctx, async () => {
|
|
33
|
+
await request('POST', '/public/v1/functions/Sin/call', {x: 0});
|
|
34
|
+
assert.equal(files.get('/public/v1/functions/Sin/call'), '{"x":0}');
|
|
35
|
+
}));
|