@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,454 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: datagrok-df-and-columns
|
|
3
|
+
description: Find, describe, add, remove, rename, clone, or set metadata on columns of a Datagrok DataFrame via the datagrok_exec tool. Use whenever the user asks to locate "the X column", list the table's numeric / categorical / date columns, summarize a column, add a typed/empty/values-filled/virtual column, set semantic type / units / format / friendly name, apply linear or categorical or conditional color coding, drop or rename columns, copy a DataFrame, compute a statistic of a column (mean, median, count), or group rows into a new summary table of counts and per-group aggregates (groupBy). Covers everything in DataFrame.columns and Column.meta — but not row filtering/selection (datagrok-filtering, datagrok-selection) and not formula-only columns (datagrok-calc-column).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# datagrok-df-and-columns
|
|
7
|
+
|
|
8
|
+
Use the `DG.DataFrame` / `DG.Column` js-api via the `datagrok_exec` tool.
|
|
9
|
+
Globals available in the code: `grok`, `ui`, `DG`, `view`, `t` (the current
|
|
10
|
+
`DG.DataFrame`, when `view.type === 'TableView'`).
|
|
11
|
+
|
|
12
|
+
**Changing a table that is open in a view** must leave an undo step (see `datagrok-undo`). Use the tool when
|
|
13
|
+
it covers the change, otherwise make the change in a script inside the matching `undoable` helper, as every
|
|
14
|
+
example below does:
|
|
15
|
+
|
|
16
|
+
| Change | Tool | In a script |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| add a column | `table_add_column` (per-row value or formula) | add it, then `undoable.columnAdded(col)` |
|
|
19
|
+
| overwrite values | `table_set_values` | `await undoable.changeValues(col, () => ...)` |
|
|
20
|
+
| rename, format, units, semType, default color coding | `table_edit_column` | `await undoable.editColumn(col, () => ...)` |
|
|
21
|
+
| custom colors, description, friendly name, other tags | — | `await undoable.editColumn(col, () => ...)` |
|
|
22
|
+
| remove columns | `table_remove_columns` | `undoable.removeColumns(t, names)` |
|
|
23
|
+
|
|
24
|
+
A table the script built itself and has not opened needs none of this: change it directly.
|
|
25
|
+
|
|
26
|
+
For **formula-driven** columns (recompute on source change), use
|
|
27
|
+
`datagrok-calc-column`. Row filtering / selection lives in `datagrok-filtering`
|
|
28
|
+
and `datagrok-selection`.
|
|
29
|
+
|
|
30
|
+
## Quick reference
|
|
31
|
+
|
|
32
|
+
| Need | Call |
|
|
33
|
+
|----------------------------------------------|-----------------------------------------------------------------|
|
|
34
|
+
| Get column by name (must exist) | `t.getCol(name)` — throws on missing |
|
|
35
|
+
| Get column by name (may be absent) | `t.col(name)` — returns `null` |
|
|
36
|
+
| First column with a given semType | `t.columns.bySemType(DG.SEMTYPE.MOLECULE)` |
|
|
37
|
+
| Every column with a given semType | `t.columns.bySemTypeAll(DG.SEMTYPE.MOLECULE)` |
|
|
38
|
+
| All numeric / categorical / dateTime columns | iterables, not arrays: `Array.from(t.columns.numerical, (c) => c.name)` / `.categorical` / `.dateTime` |
|
|
39
|
+
| All names | `t.columns.names()` |
|
|
40
|
+
| Add typed empty column | `t.columns.addNewFloat(name)` (and `addNewInt/String/Bool/...`) |
|
|
41
|
+
| Add column from values | `t.columns.add(DG.Column.fromList(type, name, values))` |
|
|
42
|
+
| Virtual column (compute-on-demand) | `t.columns.addNewVirtual(name, i => ..., type)` |
|
|
43
|
+
| Collision-free name | `t.columns.getUnusedName(name)` |
|
|
44
|
+
| Remove columns of the open table (undoable) | tool `table_remove_columns` |
|
|
45
|
+
| Rename | tool `table_edit_column`; in a script `col.name = 'new'` inside `undoable.editColumn` |
|
|
46
|
+
| Clone DataFrame (full) | `t.clone()` |
|
|
47
|
+
| Clone filtered rows | `t.clone(t.filter)` |
|
|
48
|
+
| Clone column subset | `t.clone(null, ['a', 'b'])` |
|
|
49
|
+
| Check if value is missing | `col.isNone(i)` |
|
|
50
|
+
| Stats (cached on column) | `col.stats.{min,max,avg,stdev,med,q1,q2,q3,sum,valueCount,missingValueCount,uniqueCount}` — they skip missing values; `col.getRawData()` does not (a missing number is a placeholder value there), so never compute a statistic from it without `col.isNone(i)` |
|
|
51
|
+
| Per-group counts and aggregates (new table) | `t.groupBy(['RACE']).count('count').avg('AGE').med('WEIGHT').aggregate()` (also `.sum/.min/.max/.stdev/.uniqueCount`; `.where(...)` before `aggregate` limits the rows); open it with `grok.shell.addTableView(df)` |
|
|
52
|
+
| Set semType | `col.semType = DG.SEMTYPE.MOLECULE` |
|
|
53
|
+
| Set friendly name / units / format / desc | `col.meta.friendlyName / .units / .format / .description = ...` |
|
|
54
|
+
| Linear color coding (numeric) | `col.meta.colors.setLinear()` (default scheme) or `setLinear(range, opts?)` |
|
|
55
|
+
| Categorical color coding | `col.meta.colors.setCategorical()` (default palette) or `setCategorical(map, opts?)` |
|
|
56
|
+
| Conditional color coding | `col.meta.colors.setConditional()` (auto bins) or `setConditional(rules)` |
|
|
57
|
+
| Disable color coding | `col.meta.colors.setDisabled()` |
|
|
58
|
+
|
|
59
|
+
## Finding the right column
|
|
60
|
+
|
|
61
|
+
| User said... | Right call |
|
|
62
|
+
|---------------------------------------------|---------------------------------------------------------|
|
|
63
|
+
| "column named X" (must exist) | `t.getCol('X')` — throws if missing |
|
|
64
|
+
| "column named X" (may be absent) | `t.col('X')` — returns `null` if missing |
|
|
65
|
+
| "the molecule column" | `t.columns.bySemType(DG.SEMTYPE.MOLECULE)` |
|
|
66
|
+
| "every molecule column" | `t.columns.bySemTypeAll(DG.SEMTYPE.MOLECULE)` |
|
|
67
|
+
| "all numeric columns" | `for (const c of t.columns.numerical)` (no `.map`: not an array) |
|
|
68
|
+
| "an IC50 column" | `t.columns.bySemType(DG.SEMTYPE.IC50)` |
|
|
69
|
+
| "columns tagged `quality=Molecule`" | `t.columns.byTags({quality: 'Molecule'})` |
|
|
70
|
+
| "any of these columns: X, Y, Z (first hit)" | `t.columns.firstWhere(c => names.includes(c.name))` |
|
|
71
|
+
| "does the DF have a column named X?" | `t.columns.contains('X')` (case-insensitive) |
|
|
72
|
+
|
|
73
|
+
`t.col` and `t.columns.byName` are case-insensitive. Always pass the semType
|
|
74
|
+
*constant* (`DG.SEMTYPE.MOLECULE`), never the string literal `'Molecule'`.
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// Find the molecule column. bySemType returns the first match or null.
|
|
78
|
+
const molCol = t.columns.bySemType(DG.SEMTYPE.MOLECULE);
|
|
79
|
+
return ui.divText(molCol ? `Molecule column: ${molCol.name}` : 'No molecule column');
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
// User said "mw" but the DF has "Molecular Weight" — try exact first, then
|
|
84
|
+
// fall back to a name substring match.
|
|
85
|
+
const wanted = 'mw';
|
|
86
|
+
let col = t.col(wanted);
|
|
87
|
+
if (!col) {
|
|
88
|
+
const lc = wanted.toLowerCase();
|
|
89
|
+
col = t.columns.firstWhere((c) => c.name.toLowerCase().includes(lc));
|
|
90
|
+
}
|
|
91
|
+
return ui.divText(col ? col.name : 'no match');
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Describing a column
|
|
95
|
+
|
|
96
|
+
`col.stats` is cached per column — repeated access is cheap.
|
|
97
|
+
|
|
98
|
+
| Need | Use |
|
|
99
|
+
|-----------------------------------|------------------------------------------|
|
|
100
|
+
| total row count | `col.length` |
|
|
101
|
+
| non-null value count | `col.stats.valueCount` |
|
|
102
|
+
| missing-value count | `col.stats.missingValueCount` |
|
|
103
|
+
| distinct value count | `col.stats.uniqueCount` |
|
|
104
|
+
| min / max / avg / stdev | `col.stats.{min,max,avg,stdev}` |
|
|
105
|
+
| median / quartiles | `col.stats.{med,q1,q2,q3}` |
|
|
106
|
+
| sum | `col.stats.sum` |
|
|
107
|
+
| pairwise correlation | `col.stats.corr(other)` |
|
|
108
|
+
| sorted distinct strings | `col.categories` |
|
|
109
|
+
| typed-array raw view | `col.getRawData()` |
|
|
110
|
+
| value iterator (generator) | `col.values()` |
|
|
111
|
+
|
|
112
|
+
Do **not** compute these by hand:
|
|
113
|
+
|
|
114
|
+
- Total rows: `col.length`, not `col.toList().length` (allocates).
|
|
115
|
+
- Non-null count: `col.stats.valueCount`.
|
|
116
|
+
- Distinct count: `col.stats.uniqueCount`, not `new Set(col.toList()).size`.
|
|
117
|
+
- For string columns, `col.categories.length === col.stats.uniqueCount`.
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
// Build a key-value summary of one numeric column.
|
|
121
|
+
const col = t.getCol('age');
|
|
122
|
+
const s = col.stats;
|
|
123
|
+
return ui.tableFromMap({
|
|
124
|
+
name: col.name,
|
|
125
|
+
type: col.type,
|
|
126
|
+
semType: col.semType ?? '(none)',
|
|
127
|
+
length: col.length,
|
|
128
|
+
missing: s.missingValueCount,
|
|
129
|
+
unique: s.uniqueCount,
|
|
130
|
+
min: s.min, max: s.max, avg: s.avg, stdev: s.stdev,
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
// Summarize every numeric column. t.columns.numerical is Iterable<Column>
|
|
136
|
+
// (not an Array) — convert via Array.from to get .map etc.
|
|
137
|
+
const rows = Array.from(t.columns.numerical, (c) => ({
|
|
138
|
+
name: c.name, min: c.stats.min, max: c.stats.max, avg: c.stats.avg,
|
|
139
|
+
}));
|
|
140
|
+
return DG.Viewer.grid(DG.DataFrame.fromObjects(rows)).root;
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Top-N categories
|
|
144
|
+
|
|
145
|
+
No built-in top-N for a string column. Tally into a `Map<string, number>`:
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
const col = t.getCol('class');
|
|
149
|
+
const counts = new Map();
|
|
150
|
+
for (let i = 0; i < col.length; i++) {
|
|
151
|
+
const v = col.get(i);
|
|
152
|
+
if (v === null || v === undefined) continue;
|
|
153
|
+
counts.set(v, (counts.get(v) ?? 0) + 1);
|
|
154
|
+
}
|
|
155
|
+
const top = Array.from(counts.entries())
|
|
156
|
+
.sort((a, b) => b[1] - a[1])
|
|
157
|
+
.slice(0, 5);
|
|
158
|
+
return ui.tableFromMap(Object.fromEntries(top));
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
If you only need distinct values (no counts), `col.categories` is already
|
|
162
|
+
sorted alphabetically.
|
|
163
|
+
|
|
164
|
+
## Cloning DataFrames
|
|
165
|
+
|
|
166
|
+
`t.copy()` does **not** exist. Use
|
|
167
|
+
`t.clone(rowMask?, columnIds?, saveSelection?, saveTags?)`:
|
|
168
|
+
|
|
169
|
+
| Need | Call |
|
|
170
|
+
|-------------------------------------|-----------------------------------------------|
|
|
171
|
+
| Full copy | `t.clone()` |
|
|
172
|
+
| Filtered rows only | `t.clone(t.filter)` |
|
|
173
|
+
| Selected rows only | `t.clone(t.selection)` |
|
|
174
|
+
| Column subset (all rows) | `t.clone(null, ['a', 'b'])` |
|
|
175
|
+
| Filtered rows + column subset | `t.clone(t.filter, ['a', 'b'])` |
|
|
176
|
+
| Preserve selection bits | `t.clone(t.filter, null, true)` |
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
// Just SMILES and activity, filtered rows only.
|
|
180
|
+
const small = t.clone(t.filter, ['smiles', 'activity']);
|
|
181
|
+
return DG.Viewer.grid(small).root;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`col.clone(mask?)` clones a single column, but the cloned column is **not
|
|
185
|
+
attached to any DataFrame**. Call `df.columns.add(clonedCol)` to attach it.
|
|
186
|
+
|
|
187
|
+
## Adding columns
|
|
188
|
+
|
|
189
|
+
| You have... | Right call |
|
|
190
|
+
|------------------------------------------|-----------------------------------------------------------------|
|
|
191
|
+
| Nothing — want empty typed column | `t.columns.addNewFloat(name)` (and `addNewInt/String/Bool/...`) |
|
|
192
|
+
| Generic typed empty column | `t.columns.addNew(name, DG.COLUMN_TYPE.FLOAT)` |
|
|
193
|
+
| An array of values | `t.columns.add(DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, name, values))` |
|
|
194
|
+
| A function of row index | `t.columns.addNewFloat(name).init(i => ...)` |
|
|
195
|
+
| A formula using other columns | See `datagrok-calc-column` skill |
|
|
196
|
+
| Compute-on-demand (no storage) | `t.columns.addNewVirtual(name, i => ..., DG.TYPE.STRING)` |
|
|
197
|
+
| Want a collision-free name first | `const n = t.columns.getUnusedName(name);` then `addNew*` |
|
|
198
|
+
| Insert at a specific position | `t.columns.insert(col, index)` |
|
|
199
|
+
|
|
200
|
+
> **`DG.COLUMN_TYPE.FLOAT === 'double'`.** Never write the literal `'float'`
|
|
201
|
+
> (no such type) or `'double'` (works but brittle). Use the constant, or the
|
|
202
|
+
> typed shorthand `addNewFloat`.
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
// Typed empty column with metadata applied in the same block.
|
|
206
|
+
const col = t.columns.addNewFloat('Ki');
|
|
207
|
+
col.semType = DG.SEMTYPE.Ki;
|
|
208
|
+
col.meta.units = 'nM';
|
|
209
|
+
col.meta.format = '0.00';
|
|
210
|
+
undoable.columnAdded(col);
|
|
211
|
+
return ui.divText(`Added ${col.name} (${col.type})`);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
// Add a column from an array of values. fromList infers length from the array.
|
|
216
|
+
const values = [1.2, 3.4, null, 5.6];
|
|
217
|
+
const col = DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'score', values);
|
|
218
|
+
t.columns.add(col);
|
|
219
|
+
undoable.columnAdded(col);
|
|
220
|
+
return ui.divText(`Added ${col.name}`);
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
// Virtual column — recomputed on every access, not stored. Type argument is
|
|
225
|
+
// DG.TYPE.* (not DG.COLUMN_TYPE.*) — addNewVirtual takes the broader enum.
|
|
226
|
+
const labels = t.columns.addNewVirtual('Label',
|
|
227
|
+
(i) => `${t.get('compound', i)}@${t.get('target', i)}`,
|
|
228
|
+
DG.TYPE.STRING);
|
|
229
|
+
undoable.columnAdded(labels);
|
|
230
|
+
return ui.divText(`Added virtual column ${labels.name}`);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
```js
|
|
234
|
+
// Avoid name collisions explicitly.
|
|
235
|
+
const name = t.columns.getUnusedName('Ki'); // returns 'Ki' or 'Ki (1)' etc.
|
|
236
|
+
const col = t.columns.addNewFloat(name);
|
|
237
|
+
undoable.columnAdded(col);
|
|
238
|
+
return ui.divText(`Final name: ${col.name}`);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Removing & renaming
|
|
242
|
+
|
|
243
|
+
Columns of an open table are removed with the `table_remove_columns` tool, so that Ctrl+Z brings them back
|
|
244
|
+
(see `datagrok-undo`); inside a script:
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
undoable.removeColumns(t, ['_tmp1', '_tmp2', 'temp3'].filter((name) => t.columns.contains(name)));
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
`t.columns.remove(name)` (string, index, or `Column`) is for a table that is not open in a view.
|
|
251
|
+
|
|
252
|
+
To target **calculated columns**, check `col.meta.formula`:
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
// Drop every calculated column.
|
|
256
|
+
const names = t.columns.toList().filter((c) => c.meta.formula != null).map((c) => c.name);
|
|
257
|
+
undoable.removeColumns(t, names);
|
|
258
|
+
return ui.divText(`Removed: ${names.join(', ') || '(none)'}`);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Rename: the `table_edit_column` tool, or in a script:
|
|
262
|
+
|
|
263
|
+
```js
|
|
264
|
+
const col = t.getCol('pIC50');
|
|
265
|
+
await undoable.editColumn(col, () => col.name = 'pIC50_old');
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Setting column metadata
|
|
269
|
+
|
|
270
|
+
Use the right accessor — never `setTag` for these.
|
|
271
|
+
|
|
272
|
+
| Where metadata lives | Read | Write |
|
|
273
|
+
|----------------------|-------------------------------|-------------------------------------------------------------|
|
|
274
|
+
| Semantic type | `col.semType` | `col.semType = DG.SEMTYPE.MOLECULE` |
|
|
275
|
+
| Friendly name | `col.meta.friendlyName` | `col.meta.friendlyName = 'Potency'` (or `null` to clear) |
|
|
276
|
+
| Description | `col.meta.description` | `col.meta.description = '...'` |
|
|
277
|
+
| Format | `col.meta.format` | `col.meta.format = '0.00'` |
|
|
278
|
+
| Units | `col.meta.units` | `col.meta.units = 'nM'` |
|
|
279
|
+
| Choices (combo) | `col.meta.choices` | `col.meta.choices = ['A', 'B']` |
|
|
280
|
+
| Color coding | `col.meta.colors.getType()` | `col.meta.colors.setLinear/setCategorical/setConditional/setDisabled` |
|
|
281
|
+
| Arbitrary tags | `col.getTag(k)` | `col.setTag(k, v)`, `col.tags.delete(k)` |
|
|
282
|
+
| Layout-stable id | `col.layoutColumnId` | `col.layoutColumnId = '...'` |
|
|
283
|
+
|
|
284
|
+
Assign `null` to a `col.meta.*` accessor to **clear** the underlying tag.
|
|
285
|
+
|
|
286
|
+
> **Trap.** The semType tag key is `'quality'` in storage. Don't use
|
|
287
|
+
> `col.setTag('semType', ...)` or `col.setTag('quality', ...)`. Use the
|
|
288
|
+
> `col.semType` accessor — it sets the right tag and fires the right event.
|
|
289
|
+
> Friendly name / format / units / description go through `col.meta.*`, not
|
|
290
|
+
> through `setTag`.
|
|
291
|
+
|
|
292
|
+
```js
|
|
293
|
+
// Set several metadata fields at once.
|
|
294
|
+
const col = t.getCol('Ki');
|
|
295
|
+
await undoable.editColumn(col, () => {
|
|
296
|
+
col.semType = DG.SEMTYPE.Ki;
|
|
297
|
+
col.meta.units = 'nM';
|
|
298
|
+
col.meta.format = '0.00';
|
|
299
|
+
col.meta.description = null; // null clears
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
```js
|
|
304
|
+
// Clear all custom (user-facing) metadata. Do NOT call col.tags.clear() —
|
|
305
|
+
// that also nukes system tags like .color-coding-type.
|
|
306
|
+
const col = t.getCol('activity');
|
|
307
|
+
await undoable.editColumn(col, () => {
|
|
308
|
+
col.meta.friendlyName = null;
|
|
309
|
+
col.meta.units = null;
|
|
310
|
+
col.meta.format = null;
|
|
311
|
+
col.meta.description = null;
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## Color coding
|
|
316
|
+
|
|
317
|
+
When the user doesn't name specific colors or rules, call the setter with
|
|
318
|
+
**no arguments** — the platform's default scheme applies. Never invent a
|
|
319
|
+
palette the user didn't ask for.
|
|
320
|
+
|
|
321
|
+
Lives under `col.meta.colors`. The default scheme of each shape is also `table_edit_column {colorCoding}`; a
|
|
322
|
+
script runs the setter inside `undoable.editColumn`. Four shapes:
|
|
323
|
+
|
|
324
|
+
### Linear (numeric only)
|
|
325
|
+
|
|
326
|
+
```js
|
|
327
|
+
// Default: no palette — the platform's standard linear scheme is used.
|
|
328
|
+
const col = t.getCol('weight');
|
|
329
|
+
await undoable.editColumn(col, () => col.meta.colors.setLinear());
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
```js
|
|
333
|
+
// User asked for red → yellow → green, with min/max pinned.
|
|
334
|
+
const col = t.getCol('age');
|
|
335
|
+
await undoable.editColumn(col, () => col.meta.colors.setLinear(
|
|
336
|
+
['#ff0000', '#ffff00', '#00ff00'],
|
|
337
|
+
{min: 19, max: 70},
|
|
338
|
+
));
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Hex strings and ARGB integers both work in `range`. Optional `belowMinColor`
|
|
342
|
+
/ `aboveMaxColor` paint out-of-range values.
|
|
343
|
+
|
|
344
|
+
Linear on a non-numeric column is a logic error — the setter itself does not
|
|
345
|
+
throw; guard with `col.isNumerical` if uncertain.
|
|
346
|
+
|
|
347
|
+
### Categorical
|
|
348
|
+
|
|
349
|
+
```js
|
|
350
|
+
// Default: no map — every category gets a color from the platform palette.
|
|
351
|
+
const col = t.getCol('race');
|
|
352
|
+
await undoable.editColumn(col, () => col.meta.colors.setCategorical());
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
```js
|
|
356
|
+
// User asked for specific colors per category.
|
|
357
|
+
const col = t.getCol('race');
|
|
358
|
+
await undoable.editColumn(col, () => col.meta.colors.setCategorical(
|
|
359
|
+
{'Asian': '#0000FF', 'Black': '#FF0000'},
|
|
360
|
+
{fallbackColor: '#CCCCCC'},
|
|
361
|
+
));
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Conditional (range-based rules)
|
|
365
|
+
|
|
366
|
+
```js
|
|
367
|
+
// Default: no rules — the platform bins the values into 4 ranges automatically.
|
|
368
|
+
const col = t.getCol('height');
|
|
369
|
+
await undoable.editColumn(col, () => col.meta.colors.setConditional());
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
```js
|
|
373
|
+
// User specified the thresholds. '20-170' means "value in the range 20..170".
|
|
374
|
+
// '<100' / '>50' also work.
|
|
375
|
+
const col = t.getCol('height');
|
|
376
|
+
await undoable.editColumn(col, () => col.meta.colors.setConditional({
|
|
377
|
+
'20-170': '#00FF00',
|
|
378
|
+
'170-190': '#220505',
|
|
379
|
+
}));
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Off
|
|
383
|
+
|
|
384
|
+
```js
|
|
385
|
+
const col = t.getCol('activity');
|
|
386
|
+
await undoable.editColumn(col, () => col.meta.colors.setDisabled());
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
> **Trap.** Don't use `col.setTag('.color-coding-type', ...)` to enable /
|
|
390
|
+
> disable coloring. It bypasses rule validation and the companion tag writes
|
|
391
|
+
> that `setLinear` / `setCategorical` / `setConditional` perform, producing
|
|
392
|
+
> broken color coding.
|
|
393
|
+
|
|
394
|
+
## Working with cell values
|
|
395
|
+
|
|
396
|
+
Bulk init: `col.init(scalar | (i) => value)` is the right shape for an
|
|
397
|
+
already-allocated column.
|
|
398
|
+
|
|
399
|
+
```js
|
|
400
|
+
const col = t.columns.addNewInt('rowSquared');
|
|
401
|
+
col.init((i) => i * i);
|
|
402
|
+
undoable.columnAdded(col);
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
For hot paths, mutate values with `notify=false` and call
|
|
406
|
+
`col.fireValuesChanged()` once at the end:
|
|
407
|
+
|
|
408
|
+
```js
|
|
409
|
+
const src = t.getCol('input');
|
|
410
|
+
const dst = t.getCol('output');
|
|
411
|
+
await undoable.changeValues(dst, () => {
|
|
412
|
+
for (let i = 0; i < t.rowCount; i++)
|
|
413
|
+
dst.set(i, src.get(i) * 2, false);
|
|
414
|
+
dst.fireValuesChanged();
|
|
415
|
+
});
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## Constants — cite, never invent
|
|
419
|
+
|
|
420
|
+
| Constant family | Members |
|
|
421
|
+
|-----------------------------|----------------------------------------------------------------------|
|
|
422
|
+
| `DG.COLUMN_TYPE` | `STRING='string'`, `INT='int'`, **`FLOAT='double'`** (!), `BOOL='bool'`, `BYTE_ARRAY='byte_array'`, `DATE_TIME='datetime'`, `BIG_INT='bigint'`, `QNUM='qnum'`, `DATA_FRAME='dataframe'`, `OBJECT='object'` |
|
|
423
|
+
| `DG.SEMTYPE` | `MOLECULE`, `MACROMOLECULE`, `MOLECULE3D`, `IC50`, `EC50`, `Ki`, `CONCENTRATION`, `VOLUME`, `EMAIL`, `URL`, `LATITUDE`, `LONGITUDE`, `IMAGE`, `FILE`, `CHEMICAL_REACTION`, ... |
|
|
424
|
+
| `DG.UNITS.Molecule` | `SMILES`, `MOLBLOCK`, `V3K_MOLBLOCK`, `INCHI` |
|
|
425
|
+
| `DG.COLOR_CODING_TYPE` | `CATEGORICAL`, `CONDITIONAL`, `LINEAR`, `OFF` |
|
|
426
|
+
|
|
427
|
+
## Anti-patterns — and the fix
|
|
428
|
+
|
|
429
|
+
1. **Looping `t.rows` to read / write column data.** Slow and
|
|
430
|
+
notification-heavy. Use `t.getCol(name)` and an index loop with
|
|
431
|
+
`set(..., false)` plus a final `col.fireValuesChanged()`.
|
|
432
|
+
2. **`col.setTag('color-coding-type', ...)` / `col.setTag('.color-coding-type', ...)`.**
|
|
433
|
+
Use `col.meta.colors.setLinear/setCategorical/setConditional/setDisabled`.
|
|
434
|
+
3. **`col.setTag('semType', 'Molecule')`.** Use
|
|
435
|
+
`col.semType = DG.SEMTYPE.MOLECULE`.
|
|
436
|
+
4. **`col.setTag('friendlyName', '...')`, `col.setTag('format', '...')`.**
|
|
437
|
+
Go through `col.meta.friendlyName` / `col.meta.format`.
|
|
438
|
+
5. **`'float'` or `'double'` string literals for column type.** Always
|
|
439
|
+
`DG.COLUMN_TYPE.FLOAT` (or just `addNewFloat`).
|
|
440
|
+
6. **`t.copy()`.** Doesn't exist. Use `t.clone()`.
|
|
441
|
+
7. **`col.toList().length` for row count.** Use `col.length`, or
|
|
442
|
+
`col.stats.valueCount` for non-null count.
|
|
443
|
+
8. **`new Set(col.toList()).size` for unique count.** Use
|
|
444
|
+
`col.stats.uniqueCount`. For string cols, `col.categories.length` also works.
|
|
445
|
+
9. **Mutating `col.getRawData()` and forgetting to fire.** End with
|
|
446
|
+
`col.fireValuesChanged()` — otherwise viewers / grid don't refresh.
|
|
447
|
+
10. **Forgetting `await` on `t.columns.addNewCalculated`.** It's the only
|
|
448
|
+
`addNew*` that returns a `Promise<Column>`. See `datagrok-calc-column`.
|
|
449
|
+
11. **`t.columns.byName(name)` + `if (col == null)` when you want an error.**
|
|
450
|
+
Use `t.getCol(name)` — it throws on missing.
|
|
451
|
+
12. **`col.tags.clear()` to "reset metadata".** Nukes system tags too (color
|
|
452
|
+
coding, choices, etc). Clear specific `col.meta.*` fields with `null`.
|
|
453
|
+
13. **Changing an open table directly** (`t.columns.remove`, `col.name = ...`, `col.init(...)`, a `col.meta.*`
|
|
454
|
+
write outside a helper). Ctrl+Z cannot take it back. Use the `table_*` tool or the `undoable` helper.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: datagrok-entities
|
|
3
|
+
description: Call datagrok_show_entities after any MCP tool result that returns entity data (files, scripts, queries, connections, projects, spaces, groups, users). Always use the tool — never list entities as plain text, markdown links, or bullet lists.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# datagrok-entities
|
|
7
|
+
|
|
8
|
+
When an MCP tool result contains entity data, call `datagrok_show_entities` immediately.
|
|
9
|
+
The tool renders interactive cards the user can click to open the entity — always prefer
|
|
10
|
+
it over prose.
|
|
11
|
+
|
|
12
|
+
## Tool signature
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
datagrok_show_entities(entities: EntityRef[])
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Supported types
|
|
19
|
+
|
|
20
|
+
| type | required | optional |
|
|
21
|
+
|--------------|-----------------------------|-------------------------------|
|
|
22
|
+
| `file` | `connector`, `path`, `name` | `isDirectory` |
|
|
23
|
+
| `script` | `id`, `name` | — |
|
|
24
|
+
| `query` | `id`, `name` | — |
|
|
25
|
+
| `connection` | `id`, `name` | — |
|
|
26
|
+
| `project` | `id`, `name` | — |
|
|
27
|
+
| `space` | `id`, `name` | — |
|
|
28
|
+
| `group` | `id`, `name` | — |
|
|
29
|
+
| `user` | `id`, `name` | — |
|
|
30
|
+
|
|
31
|
+
## Notes
|
|
32
|
+
|
|
33
|
+
- **`#type` passthrough**: MCP results return entities with a `#type` field in PascalCase (e.g. `"FileInfo"`, `"DataQuery"`, `"UserGroup"`). Pass it as-is in the `#type` field — the tool normalizes it to the correct `type` value automatically. You may also pass the normalized `type` string directly if you already know it.
|
|
34
|
+
- Pass `id` and all other identifying values **exactly** from the MCP response — never invent.
|
|
35
|
+
- For files, `connector` is the connection name string (e.g. `"System:DemoFiles"`) and `path` is the file path relative to the connector root.
|
|
36
|
+
- For users, use `friendlyName` as the `name` field — users have no `name` property in the MCP response, only `friendlyName` and `login`.
|
|
37
|
+
- A single call may mix entity types — the renderer handles them.
|
|
38
|
+
- After calling the tool, you may add a short prose summary if useful, but the tool call must come first.
|