@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
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import {JSONSchema7} from 'ai';
|
|
2
|
-
import * as DG from 'datagrok-api/dg';
|
|
3
|
-
|
|
4
|
-
export interface FuncParam {
|
|
5
|
-
type: string;
|
|
6
|
-
description: string;
|
|
7
|
-
default?: any;
|
|
8
|
-
optional?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type ChatGptFuncParams = Record<string, FuncParam>;
|
|
12
|
-
|
|
13
|
-
export interface FunctionInput {
|
|
14
|
-
type: string;
|
|
15
|
-
properties: ChatGptFuncParams;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface FunctionOutput {
|
|
19
|
-
name: string;
|
|
20
|
-
type: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface FunctionMeta {
|
|
24
|
-
name: string;
|
|
25
|
-
description: string;
|
|
26
|
-
inputs: FunctionInput;
|
|
27
|
-
outputs: FunctionOutput[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface Step {
|
|
31
|
-
action: 'call_function';
|
|
32
|
-
function: string;
|
|
33
|
-
inputs: Record<string, any>;
|
|
34
|
-
outputs: string[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface Plan {
|
|
38
|
-
goal: string;
|
|
39
|
-
analysis: string[];
|
|
40
|
-
steps: Step[];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface PackageInfo {
|
|
44
|
-
name: string;
|
|
45
|
-
description: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface StepExecutionOutput<T = any> {
|
|
49
|
-
value: T;
|
|
50
|
-
meta?: DG.Property;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type ExecutionContext = Record<string, StepExecutionOutput>;
|
|
54
|
-
|
|
55
|
-
export interface ExecutePlanResult {
|
|
56
|
-
context: ExecutionContext;
|
|
57
|
-
finalResult: StepExecutionOutput | null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface PackageSelection {
|
|
61
|
-
selected_packages: {
|
|
62
|
-
name: string;
|
|
63
|
-
reason: string;
|
|
64
|
-
}[];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type JsonSchema = JSONSchema7;
|
|
68
|
-
|
|
69
|
-
/* Schemas defined to enable structured output handling */
|
|
70
|
-
export const PackageSelectionSchema: JsonSchema = {
|
|
71
|
-
type: 'object',
|
|
72
|
-
properties: {
|
|
73
|
-
selected_packages: {
|
|
74
|
-
type: 'array',
|
|
75
|
-
items: {
|
|
76
|
-
type: 'object',
|
|
77
|
-
properties: {
|
|
78
|
-
name: {
|
|
79
|
-
type: 'string',
|
|
80
|
-
description: 'The name of the package to use.',
|
|
81
|
-
},
|
|
82
|
-
reason: {
|
|
83
|
-
type: 'string',
|
|
84
|
-
description: 'The reason why this package is relevant to the user\'s goal.',
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
required: ['name', 'reason'],
|
|
88
|
-
additionalProperties: false,
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
required: ['selected_packages'],
|
|
93
|
-
additionalProperties: false,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const PlanSchema: JsonSchema = {
|
|
97
|
-
type: 'object',
|
|
98
|
-
properties: {
|
|
99
|
-
goal: {
|
|
100
|
-
type: 'string',
|
|
101
|
-
description: 'The user goal restated clearly in your own words.'
|
|
102
|
-
},
|
|
103
|
-
analysis: {
|
|
104
|
-
type: 'array',
|
|
105
|
-
description: 'Reasoning explaining why the selected steps will achieve the goal.',
|
|
106
|
-
items: {
|
|
107
|
-
type: 'string',
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
steps: {
|
|
111
|
-
type: 'array',
|
|
112
|
-
description: 'An ordered list of steps to perform, using available functions.',
|
|
113
|
-
items: {
|
|
114
|
-
type: 'object',
|
|
115
|
-
properties: {
|
|
116
|
-
action: {
|
|
117
|
-
type: 'string',
|
|
118
|
-
description: 'The type of action to perform in this step. Currently only "call_function" is supported.',
|
|
119
|
-
enum: ['call_function']
|
|
120
|
-
},
|
|
121
|
-
function: {
|
|
122
|
-
type: 'string',
|
|
123
|
-
description: 'The exact name of the function to call in this step.'
|
|
124
|
-
},
|
|
125
|
-
inputs: {
|
|
126
|
-
type: 'object',
|
|
127
|
-
description: 'Function inputs as a dictionary of key-value pairs.',
|
|
128
|
-
properties: {},
|
|
129
|
-
required: [],
|
|
130
|
-
patternProperties: {
|
|
131
|
-
'.*': {},
|
|
132
|
-
},
|
|
133
|
-
additionalProperties: false,
|
|
134
|
-
},
|
|
135
|
-
outputs: {
|
|
136
|
-
type: 'array',
|
|
137
|
-
description: 'List of names for the outputs this step will produce.',
|
|
138
|
-
items: {
|
|
139
|
-
type: 'string',
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
additionalProperties: false,
|
|
144
|
-
required: ['action', 'function', 'inputs', 'outputs']
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
additionalProperties: false,
|
|
149
|
-
required: ['goal', 'analysis', 'steps'],
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
export enum LLMApiNames {
|
|
153
|
-
OpenAIChatCompletions = 'OpenAI Chat Completions',
|
|
154
|
-
OpenAIResponses = 'OpenAI Responses',
|
|
155
|
-
AntropicMessages = 'Antropic Messages',
|
|
156
|
-
AmazonBedrock = 'Amazon Bedrock',
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export type LLMApiName = `${LLMApiNames}`;
|
|
160
|
-
// export type LLMApiName = 'OpenAI Chat Completions' | 'OpenAI Responses' | 'Antropic Messages'
|
|
161
|
-
|
|
162
|
-
export type PackageSettings = {
|
|
163
|
-
vectorStoreId?: string;
|
|
164
|
-
defaultFastModel?: string;
|
|
165
|
-
defaultDeepResearchModel?: string;
|
|
166
|
-
defaultCodingModel?: string;
|
|
167
|
-
APIName: LLMApiName;
|
|
168
|
-
region?: string;
|
|
169
|
-
apiVersion?: string;
|
|
170
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {ModelType, LLMClient} from '../llm-utils/LLM-client';
|
|
2
|
-
import {JsonSchema} from './interfaces';
|
|
3
|
-
export interface PromptEngine {
|
|
4
|
-
generate(prompt: string, system: string, schema?: JsonSchema): Promise<string>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export class ChatGPTPromptEngine implements PromptEngine {
|
|
8
|
-
private static instance: ChatGPTPromptEngine | null = null;
|
|
9
|
-
|
|
10
|
-
private constructor(
|
|
11
|
-
private model = ModelType['Deep Research'],
|
|
12
|
-
private temperature = 0.0
|
|
13
|
-
) {}
|
|
14
|
-
|
|
15
|
-
public static getInstance(model?: string, temperature?: number): ChatGPTPromptEngine {
|
|
16
|
-
return ChatGPTPromptEngine.instance ??= new ChatGPTPromptEngine(model, temperature);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async generate(prompt: string, system: string, schema?: JsonSchema): Promise<string> {
|
|
20
|
-
const res = LLMClient.getInstance();
|
|
21
|
-
return await res.generalPromptCached(this.model, system, prompt, schema);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class GeminiPromptEngine implements PromptEngine {
|
|
26
|
-
private static instance: GeminiPromptEngine | null = null;
|
|
27
|
-
private session: LanguageModel | null = null;
|
|
28
|
-
|
|
29
|
-
private constructor(
|
|
30
|
-
private readonly monitor?: CreateMonitorCallback,
|
|
31
|
-
) {}
|
|
32
|
-
|
|
33
|
-
public static getInstance(monitor?: CreateMonitorCallback): GeminiPromptEngine {
|
|
34
|
-
return GeminiPromptEngine.instance ??= new GeminiPromptEngine(monitor);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private async initSession(system: string) {
|
|
38
|
-
if (!this.session) {
|
|
39
|
-
this.session = await LanguageModel.create({
|
|
40
|
-
monitor: this.monitor,
|
|
41
|
-
initialPrompts: [{role: 'system', content: system}],
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async generate(prompt: string, system: string, schema?: JsonSchema): Promise<string> {
|
|
47
|
-
await this.initSession(system);
|
|
48
|
-
return this.session!.prompt(prompt, {
|
|
49
|
-
responseConstraint: (schema as Record<string, unknown>) ?? undefined,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import * as ui from 'datagrok-api/ui';
|
|
2
|
-
import * as DG from 'datagrok-api/dg';
|
|
3
|
-
import * as grok from 'datagrok-api/grok';
|
|
4
|
-
|
|
5
|
-
//@ts-ignore
|
|
6
|
-
import '../../css/ai.css';
|
|
7
|
-
import {Plan, Step} from './interfaces';
|
|
8
|
-
|
|
9
|
-
function renderHelm(value: string): HTMLElement {
|
|
10
|
-
return ui.wait(async () => {
|
|
11
|
-
//@ts-ignore
|
|
12
|
-
const helmInput = await ui.input.helmAsync('helm', {
|
|
13
|
-
editable: false,
|
|
14
|
-
});
|
|
15
|
-
helmInput.setStringValue(value);
|
|
16
|
-
await DG.delay(200); // wait for proper sizing
|
|
17
|
-
helmInput.getInput().addEventListener('click', () => {
|
|
18
|
-
grok.shell.o = helmInput.getValue();
|
|
19
|
-
});
|
|
20
|
-
helmInput.getInput().addEventListener('dblclick', () => {
|
|
21
|
-
helmInput.showEditorDialog();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
helmInput.getInput().style.width = '100%';
|
|
25
|
-
helmInput.getInput().style.setProperty('height', '300px', 'important');
|
|
26
|
-
return helmInput.getInput();
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export class AssistantRenderer {
|
|
32
|
-
static renderPlan(plan: Plan): HTMLElement {
|
|
33
|
-
const container = ui.divV([], 'ai-execute-plan');
|
|
34
|
-
if (!plan?.steps?.length) {
|
|
35
|
-
container.append(ui.divText('No steps generated.'));
|
|
36
|
-
return container;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const analysis = ui.divV(
|
|
40
|
-
(plan.analysis ?? []).map((line: string) => ui.divText(line))
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const stepsAccordion = ui.accordion();
|
|
44
|
-
plan.steps.map((s: Step, i: number) =>
|
|
45
|
-
stepsAccordion.addPane(
|
|
46
|
-
`Step ${i + 1}: ${s.function}`,
|
|
47
|
-
() => {
|
|
48
|
-
return ui.divV([
|
|
49
|
-
ui.divText(`Action: ${s.action}`),
|
|
50
|
-
ui.divText(`Inputs: ${JSON.stringify(s.inputs, null, 2)}`),
|
|
51
|
-
ui.divText(`Outputs: ${JSON.stringify(s.outputs)}`),
|
|
52
|
-
]);
|
|
53
|
-
},
|
|
54
|
-
false
|
|
55
|
-
)
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
container.append(ui.h2('Plan'), analysis, stepsAccordion.root);
|
|
59
|
-
return container;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static renderResult(result: any): HTMLElement {
|
|
63
|
-
const val = result?.finalResult?.value ?? result?.finalResult ?? result;
|
|
64
|
-
const meta = result?.finalResult?.meta;
|
|
65
|
-
const container = ui.div([ui.h2('Result')], 'ai-execute-result');
|
|
66
|
-
|
|
67
|
-
if (meta?.propertyType === 'graphics')
|
|
68
|
-
container.append(renderGraphics(val));
|
|
69
|
-
else if (meta?.propertyType === 'widget')
|
|
70
|
-
container.append(val.root);
|
|
71
|
-
else if (typeof val === 'string' && meta?.semType === DG.SEMTYPE.MOLECULE)
|
|
72
|
-
container.append(grok.chem.drawMolecule(val, 200, 300));
|
|
73
|
-
else if (typeof val === 'string' && meta?.semType === DG.SEMTYPE.MACROMOLECULE &&
|
|
74
|
-
(meta?.units?.toLowerCase() === 'helm' || meta?.options?.units?.toLowerCase() === 'helm')
|
|
75
|
-
)
|
|
76
|
-
container.append(renderHelm(val));
|
|
77
|
-
else if (meta?.propertyType === 'dataframe') {
|
|
78
|
-
container.append(ui.button('Add to Workspace', () => grok.shell.addTableView(val),
|
|
79
|
-
'Add resulting data frame to workspace'));
|
|
80
|
-
const grid = val.plot.grid().root;
|
|
81
|
-
grid.style.width = '100%';
|
|
82
|
-
container.append(grid);
|
|
83
|
-
} else
|
|
84
|
-
container.append(ui.divText(String(val)));
|
|
85
|
-
|
|
86
|
-
return container;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function renderGraphics(intermediateResult: HTMLElement): HTMLElement {
|
|
91
|
-
if (!intermediateResult?.style?.backgroundImage)
|
|
92
|
-
return ui.divText('No graphics available.');
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const backgroundImageUrl = intermediateResult.style.backgroundImage;
|
|
96
|
-
let base64Data = backgroundImageUrl.split('data:image/png;base64,')[1];
|
|
97
|
-
base64Data = base64Data.slice(0, -2);
|
|
98
|
-
return ui.image(`data:image/png;base64,${base64Data}`, 200, 300);
|
|
99
|
-
} catch (err) {
|
|
100
|
-
console.error('Failed to render graphics output:', err);
|
|
101
|
-
return ui.divText('Failed to render graphics.');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {geminiDownloadMonitor} from '../llm-utils/query-matching';
|
|
2
|
-
|
|
3
|
-
export async function isHelpRequest(post: string): Promise<boolean> {
|
|
4
|
-
const schema = {
|
|
5
|
-
'type': 'boolean'
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const systemPrompt = `You are a helpful LLM that inspects user input and returns true
|
|
9
|
-
when the input is likely a question concerning the functionality of the data analytics application.
|
|
10
|
-
Return false for anything else (random strings, identifiers, numbers, commands, requests)`;
|
|
11
|
-
|
|
12
|
-
const session = await LanguageModel.create({
|
|
13
|
-
monitor: geminiDownloadMonitor,
|
|
14
|
-
initialPrompts: [
|
|
15
|
-
{role: 'system', content: systemPrompt}
|
|
16
|
-
]
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const result = await session.prompt(post,
|
|
20
|
-
{
|
|
21
|
-
responseConstraint: schema,
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
return JSON.parse(result);
|
|
26
|
-
}
|
package/src/viewers-ai.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import * as grok from 'datagrok-api/grok';
|
|
2
|
-
import * as ui from 'datagrok-api/ui';
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
import {getCurrentViewersString, getDataFrameDescription, getViewerDescriptionsString} from './utils';
|
|
5
|
-
import {ModelType, LLMClient} from './llm-utils/LLM-client';
|
|
6
|
-
|
|
7
|
-
type IViewerResponse = {
|
|
8
|
-
viewerType: string;
|
|
9
|
-
properties: {[index: string]: any};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Examples of queries:
|
|
14
|
-
* - plot width by height
|
|
15
|
-
* - show me age distribution
|
|
16
|
-
* - age distribution by disease
|
|
17
|
-
* - plot age, height, and weight on the 3d scatter plot
|
|
18
|
-
* - Plot width by height in a trellis plot split by race
|
|
19
|
-
* - Plot weight by height for selected rows only
|
|
20
|
-
* - form with all columns starting with "s"
|
|
21
|
-
* */
|
|
22
|
-
export async function askAiTableView(view: DG.TableView, question: string) {
|
|
23
|
-
const prompt = getPrompt(view, question);
|
|
24
|
-
//console.log(prompt);
|
|
25
|
-
// TODO: substitute with the OpenAI client call
|
|
26
|
-
const res = LLMClient.getInstance();
|
|
27
|
-
const answer = await res.generalPromptCached(ModelType.Fast, '', prompt);
|
|
28
|
-
//console.log(answer);
|
|
29
|
-
//grok.shell.info(answer);
|
|
30
|
-
|
|
31
|
-
const response: IViewerResponse = JSON.parse(answer);
|
|
32
|
-
if (DG.Viewer.CORE_VIEWER_TYPES.includes(response.viewerType))
|
|
33
|
-
view.addViewer(response.viewerType, response.properties);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function askAiTableViewDialog(view: DG.TableView) {
|
|
37
|
-
const input = ui.input.textArea('Question', {value: 'Plot width by height'});
|
|
38
|
-
|
|
39
|
-
ui.dialog('Ask AI')
|
|
40
|
-
.addInput('Question', input)
|
|
41
|
-
.onOK(async () => {
|
|
42
|
-
askAiTableView(view, input.value);
|
|
43
|
-
})
|
|
44
|
-
.show();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const getPrompt = (view: DG.TableView, question: string) => {
|
|
48
|
-
return `
|
|
49
|
-
Below is the structure of the dataframe a user is working with, and the interfaces for Datagrok visualizations.
|
|
50
|
-
Your task is to identify which visualization to use, and which properties to set for what the user asks.
|
|
51
|
-
For column name properties, you can only use names from the dataframe.
|
|
52
|
-
Give the answer in the JSON format that can be directly parsed (no annotations or anything like that)
|
|
53
|
-
with the "viewerType" identifying viewer type, and
|
|
54
|
-
"properties" containing properties, like in this example:
|
|
55
|
-
{"viewerType": "Histogram", "properties": {"valueColumnName": "Age", "markerSize": 15}}
|
|
56
|
-
|
|
57
|
-
${getCurrentViewersString(view)}
|
|
58
|
-
|
|
59
|
-
User question: ${question}
|
|
60
|
-
|
|
61
|
-
DataFrame structure:
|
|
62
|
-
${JSON.stringify(getDataFrameDescription(view.dataFrame))}
|
|
63
|
-
|
|
64
|
-
Viewers:
|
|
65
|
-
${getViewerDescriptionsString()}`;
|
|
66
|
-
};
|
|
67
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|