@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,251 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import * as grok from 'datagrok-api/grok';
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
import OpenAI from 'openai';
|
|
5
|
-
import * as api from '../package-api';
|
|
6
|
-
import {LLMCredsManager} from './creds';
|
|
7
|
-
import {JsonSchema, LLMApiNames} from '../prompt-engine/interfaces';
|
|
8
|
-
import {_package} from '../package';
|
|
9
|
-
// import {AIProvider, BuiltinToolSpec} from './AI-API-providers/types';
|
|
10
|
-
import * as osdk from '@ai-sdk/openai';
|
|
11
|
-
import * as asdk from '@ai-sdk/anthropic';
|
|
12
|
-
import * as awsSdk from '@ai-sdk/amazon-bedrock';
|
|
13
|
-
import {LanguageModelV3Message, LanguageModelV3} from '@ai-sdk/provider';
|
|
14
|
-
import {findLast} from '../utils';
|
|
15
|
-
|
|
16
|
-
export type ModelOption = 'Fast' | 'Deep Research' | 'Coding';
|
|
17
|
-
export const ModelType: {[type in ModelOption]: string} = {
|
|
18
|
-
Fast: 'gpt-4o-mini',
|
|
19
|
-
'Deep Research': 'gpt-5.2', // hell of a smart model but a bit expensive expensive
|
|
20
|
-
Coding: 'gpt-5.1-codex-max',
|
|
21
|
-
//'Deep Research': 'o4-mini', // good balance between speed, quality and $$$
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export function initModelTypeNames() {
|
|
25
|
-
if (_package.settings.defaultFastModel)
|
|
26
|
-
ModelType.Fast = _package.settings.defaultFastModel;
|
|
27
|
-
if (_package.settings.defaultDeepResearchModel)
|
|
28
|
-
ModelType['Deep Research'] = _package.settings.defaultDeepResearchModel;
|
|
29
|
-
if (_package.settings.defaultCodingModel)
|
|
30
|
-
ModelType.Coding = _package.settings.defaultCodingModel;
|
|
31
|
-
if (grok.ai.config.current?.provider == 'azure' && grok.ai.config.current.modelToDeployment) {
|
|
32
|
-
const cfg: typeof grok.ai.config.current.modelToDeployment = DG.toJs(grok.ai.config.current.modelToDeployment);
|
|
33
|
-
ModelType.Fast = cfg[ModelType.Fast] ?? ModelType.Fast;
|
|
34
|
-
ModelType['Deep Research'] = cfg[ModelType['Deep Research']] ?? ModelType['Deep Research'];
|
|
35
|
-
ModelType.Coding = cfg[ModelType.Coding] ?? ModelType.Coding;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class LLMClient {
|
|
40
|
-
public openai: OpenAI;
|
|
41
|
-
public aiModels!: Record<ModelOption, LanguageModelV3>;
|
|
42
|
-
private constructor(private vectorStoreId: string) {
|
|
43
|
-
if (!grok.ai.config.configured)
|
|
44
|
-
throw new Error('AI is not configured. Please set the API key in the AI settings under Admin section.');
|
|
45
|
-
const apiVersion = _package.settings.apiVersion ?? '';
|
|
46
|
-
const versionChunk = apiVersion ? `/${apiVersion}` : '';
|
|
47
|
-
const fullBaseUrl = `${grok.ai.config.proxyUrl}${versionChunk}`;
|
|
48
|
-
// this is still needed for vector store access
|
|
49
|
-
this.openai = new OpenAI({baseURL: fullBaseUrl, dangerouslyAllowBrowser: true,
|
|
50
|
-
apiKey: 'unused',
|
|
51
|
-
// ...(grok.ai.config.apiMode === 'legacy' ? {apiVersion: grok.ai.config!.apiVersion!} : {}),
|
|
52
|
-
fetch: async (input, init) => {
|
|
53
|
-
let url = typeof input === 'string' ? input : input.toString();
|
|
54
|
-
if (grok.ai.config.current?.provider == 'azure' && grok.ai.config.current.apiMode === 'legacy') {
|
|
55
|
-
if (grok.ai.config.current.apiVersion) {
|
|
56
|
-
const prsed = new URL(url);
|
|
57
|
-
prsed.searchParams.set('api-version', grok.ai.config.current.apiVersion);
|
|
58
|
-
url = prsed.toString();
|
|
59
|
-
}
|
|
60
|
-
if (init?.body && typeof init.body === 'string') {
|
|
61
|
-
const bodyObj = JSON.parse(init.body);
|
|
62
|
-
const modelName = bodyObj['model'];
|
|
63
|
-
if (!modelName)
|
|
64
|
-
throw new Error('Model name is not specified in the request body.');
|
|
65
|
-
const modifiedURL = url.substring(0, fullBaseUrl.length) + '/' + modelName + url.substring(fullBaseUrl.length);
|
|
66
|
-
url = modifiedURL;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const prms = {
|
|
70
|
-
...init,
|
|
71
|
-
// headers: {
|
|
72
|
-
// ...in
|
|
73
|
-
// Authorization: grok.ai.openAiProxyToken,
|
|
74
|
-
// },
|
|
75
|
-
};
|
|
76
|
-
const headers = new Headers(prms.headers);
|
|
77
|
-
headers.set('Authorization', grok.ai.config.proxyToken);
|
|
78
|
-
prms.headers = headers;
|
|
79
|
-
return fetch(url, prms);
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// const constr = _package.settings.APIName === 'openai chat completions' ? osdk.openai.chat : osdk.openai.responses;
|
|
84
|
-
// this.aiModels.Fast = constr(ModelType.Fast);
|
|
85
|
-
const providerConstructor = _package.settings.APIName === LLMApiNames.AntropicMessages ? asdk.createAnthropic :
|
|
86
|
-
_package.settings.APIName === LLMApiNames.AmazonBedrock ? awsSdk.createAmazonBedrock : osdk.createOpenAI;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const provider = providerConstructor({
|
|
90
|
-
baseURL: fullBaseUrl,
|
|
91
|
-
apiKey: grok.ai.config.proxyToken!,
|
|
92
|
-
...(_package.settings.APIName === LLMApiNames.AmazonBedrock ? {region: _package.settings.region} : {}),
|
|
93
|
-
fetch: async (input, init) => {
|
|
94
|
-
let url = typeof input === 'string' ? input : input.toString();
|
|
95
|
-
const currentConfig = grok.ai.config.current;
|
|
96
|
-
if ('apiMode' in currentConfig && currentConfig.apiMode === 'legacy' && currentConfig.apiVersion) {
|
|
97
|
-
const prsed = new URL(url);
|
|
98
|
-
prsed.searchParams.set('api-version', currentConfig.apiVersion);
|
|
99
|
-
url = prsed.toString();
|
|
100
|
-
if (init?.body && typeof init.body === 'string') {
|
|
101
|
-
const bodyObj = JSON.parse(init.body);
|
|
102
|
-
const modelName = bodyObj['model'];
|
|
103
|
-
if (!modelName)
|
|
104
|
-
throw new Error('Model name is not specified in the request body.');
|
|
105
|
-
const modifiedURL = url.substring(0, fullBaseUrl.length) + '/' + modelName + url.substring(fullBaseUrl.length);
|
|
106
|
-
url = modifiedURL;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const prms = {
|
|
110
|
-
...init,
|
|
111
|
-
// headers: {
|
|
112
|
-
// ...in
|
|
113
|
-
// Authorization: grok.ai.openAiProxyToken,
|
|
114
|
-
// },
|
|
115
|
-
};
|
|
116
|
-
const headers = new Headers(prms.headers);
|
|
117
|
-
headers.set('Authorization', grok.ai.config.proxyToken);
|
|
118
|
-
prms.headers = headers;
|
|
119
|
-
return fetch(url, prms);
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const constr = _package.settings.APIName === LLMApiNames.OpenAIChatCompletions ? (provider as osdk.OpenAIProvider).chat :
|
|
124
|
-
(_package.settings.APIName === LLMApiNames.OpenAIResponses ? (provider as osdk.OpenAIProvider).responses :
|
|
125
|
-
((_package.settings.APIName === LLMApiNames.AmazonBedrock ? (provider as awsSdk.AmazonBedrockProvider).languageModel : (provider as asdk.AnthropicProvider).messages)));
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
this.aiModels = {};
|
|
128
|
-
for (const type of Object.keys(ModelType) as ModelOption[])
|
|
129
|
-
this.aiModels[type] = constr(ModelType[type]);
|
|
130
|
-
// this.aiModels.Fast = constr(ModelType.Fast);
|
|
131
|
-
// this.aiModels['Deep Research'] = constr(ModelType['Deep Research']);
|
|
132
|
-
// this.aiModels.Coding = constr(ModelType.Coding);
|
|
133
|
-
// this.aiModels.Fast.doGenerate({prompt: [{role: 'user', content: [{type: 'text', text: 'call the test function with param1 equal to hello'}]}],
|
|
134
|
-
// tools: [{
|
|
135
|
-
// type: 'function', name: 'test', description: 'Make sure to call the test function', inputSchema: {type: 'object', properties: {param1: {type: 'string', description: 'a test param'}}, required: ['param1']}
|
|
136
|
-
// }]})
|
|
137
|
-
// .then((res) => { console.log('OpenAI client initialized', res); });
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private static _instance: LLMClient | null = null;
|
|
141
|
-
static getInstance(): LLMClient {
|
|
142
|
-
LLMClient._instance ??= new LLMClient(LLMCredsManager.getVectorStoreId());
|
|
143
|
-
return LLMClient._instance;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async getHelpAnswer(question: string): Promise<string> {
|
|
147
|
-
if (!this.vectorStoreId)
|
|
148
|
-
throw new Error('Vector Store ID is not set. Please set it in the package settings.');
|
|
149
|
-
const storageIDs = [this.vectorStoreId];
|
|
150
|
-
// const provider = AIProvider.getProvider();
|
|
151
|
-
const systemMsg: LanguageModelV3Message = {
|
|
152
|
-
role: 'system',
|
|
153
|
-
content: `
|
|
154
|
-
You are a helpful assistant with access to documentation for the datagrok platform via file_search tool. Use the available tool to answer questions accurately.
|
|
155
|
-
|
|
156
|
-
VERY IMPORTANT TO REMEMBER!!!: you are a UI side assistant for Datagrok platform users, so when asked about how to do something in Datagrok, Always answer with UI solution first (if any) and then the code (if relevant).
|
|
157
|
-
|
|
158
|
-
Make sure the output is nicely formatted with markdown syntax where applicable.
|
|
159
|
-
|
|
160
|
-
If the question is also related to coding, provide code examples in your answers.
|
|
161
|
-
|
|
162
|
-
MAKE SURE TO ALWAYS USE TOOL to access the repository information! DO NOT MAKE UP ANSWERS BASED ON YOUR TRAINING DATA!
|
|
163
|
-
|
|
164
|
-
Prioritize readme files from help directory, js file samples from apisamples directory, and any other relevant documentation files.
|
|
165
|
-
`
|
|
166
|
-
};
|
|
167
|
-
const userMsg: LanguageModelV3Message = {
|
|
168
|
-
role: 'user',
|
|
169
|
-
content: [{type: 'text', text: `${question}.\n Remember that I am in Datagrok platform environment and the question is related to working in Datagrok platform.`}]
|
|
170
|
-
};
|
|
171
|
-
// const tools: BuiltinToolSpec[] = [{type: 'file_search', vector_store_ids: storageIDs}];
|
|
172
|
-
// const response = await provider.create({
|
|
173
|
-
// model: ModelType.Fast,
|
|
174
|
-
// messages: [systemMsg, userMsg],
|
|
175
|
-
// tools,
|
|
176
|
-
// });
|
|
177
|
-
|
|
178
|
-
const response = await this.aiModels.Fast.doGenerate({
|
|
179
|
-
prompt: [systemMsg, userMsg],
|
|
180
|
-
tools: [{type: 'provider', id: 'openai.file_search', args: {vectorStoreIds: storageIDs}, name: 'file_search'}],
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const output = response.content.length > 0 ? findLast(response.content, (c) => c.type === 'text') : undefined;
|
|
184
|
-
|
|
185
|
-
return output?.text ?? '';
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async generalPromptCached(model: string, systemPrompt: string, prompt: string, schema?: JsonSchema): Promise<string> {
|
|
189
|
-
return await api.funcs.askAIGeneralCached(model, systemPrompt, prompt, schema);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
public createSystemMessage(content: string): LanguageModelV3Message {
|
|
193
|
-
return {
|
|
194
|
-
role: 'system',
|
|
195
|
-
content: content,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
public createToolOutputMessage(callId: string, toolName: string, output: string): LanguageModelV3Message {
|
|
200
|
-
return {
|
|
201
|
-
role: 'tool',
|
|
202
|
-
content: [{type: 'tool-result', toolCallId: callId, toolName: toolName, output: {type: 'text', value: output}}],
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
public createUserMessage(content: string): LanguageModelV3Message {
|
|
207
|
-
return {
|
|
208
|
-
role: 'user',
|
|
209
|
-
content: [{type: 'text', text: content}],
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* @deprecated - use generalPromptCached instead
|
|
215
|
-
* @param model - model name
|
|
216
|
-
* @param systemPrompt - system prompt
|
|
217
|
-
* @param prompt - user prompt
|
|
218
|
-
* @returns string response from OpenAI
|
|
219
|
-
*/
|
|
220
|
-
async generalPrompt(
|
|
221
|
-
model: string,
|
|
222
|
-
systemPrompt: string,
|
|
223
|
-
userPrompt: string,
|
|
224
|
-
schema?: JsonSchema
|
|
225
|
-
): Promise<string> {
|
|
226
|
-
const systemMsg = this.createSystemMessage(systemPrompt);
|
|
227
|
-
const userMsg = this.createUserMessage(userPrompt);
|
|
228
|
-
|
|
229
|
-
const modelProvider = Object.values(this.aiModels).find((m) => m.modelId === model) ?? this.aiModels.Fast;
|
|
230
|
-
const res = await modelProvider.doGenerate({
|
|
231
|
-
prompt: [systemMsg, userMsg],
|
|
232
|
-
responseFormat: {
|
|
233
|
-
...(!schema ? {type: 'text'} : {type: 'json', name: 'ResponseSchema', schema: schema!}),
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
const output = res.content.length > 0 ? findLast(res.content, (c) => c.type === 'text') : undefined;
|
|
238
|
-
const text = output?.text ?? '';
|
|
239
|
-
if (!schema)
|
|
240
|
-
return text;
|
|
241
|
-
try {
|
|
242
|
-
return JSON.stringify(JSON.parse(text));
|
|
243
|
-
} catch {
|
|
244
|
-
return text;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export async function askOpenAIHelp(question: string): Promise<string> {
|
|
250
|
-
return await api.funcs.askDocumentationCached(question);
|
|
251
|
-
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
import * as ui from 'datagrok-api/ui';
|
|
5
|
-
import {ModelType, LLMClient} from './LLM-client';
|
|
6
|
-
/**
|
|
7
|
-
* The idea is to provide single AI search provider which will decide which LLM to use based on user prompt.
|
|
8
|
-
* This class will not care about individual LLM implementations, nor the presence of api keys and other needed things.
|
|
9
|
-
*/
|
|
10
|
-
export class CombinedAISearchAssistant {
|
|
11
|
-
private collectFunctions() {
|
|
12
|
-
// these function should have descriptions, one input of a string prompt and an output of a widget. meta.useWhen must be defined as well
|
|
13
|
-
const functions = DG.Func.find({meta: {role: 'aiSearchProvider'}}).filter((f) => f.inputs.length === 1 && f.inputs[0].type === 'string' &&
|
|
14
|
-
f.description && f.outputs.length === 1 && (f.outputs[0].type as string) === 'widget' && f.options.useWhen);
|
|
15
|
-
|
|
16
|
-
// create a map from names to functions
|
|
17
|
-
const functionMap: {[name: string]: {func: DG.Func, friendlyName: string, inputName: string, order: number}} = {};
|
|
18
|
-
for (const f of functions)
|
|
19
|
-
functionMap[f.name] = {func: f, friendlyName: f.friendlyName ?? f.name, inputName: f.inputs[0].name, order: Number.parseInt(f.options.order ?? '0') ?? 0};
|
|
20
|
-
return functionMap;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
private functions: ReturnType<typeof CombinedAISearchAssistant.prototype.collectFunctions>;
|
|
24
|
-
private constructor() {
|
|
25
|
-
this.functions = this.collectFunctions();
|
|
26
|
-
}
|
|
27
|
-
private static _instance: CombinedAISearchAssistant | null = null;
|
|
28
|
-
public static get instance(): CombinedAISearchAssistant {
|
|
29
|
-
if (this._instance === null)
|
|
30
|
-
this._instance = new CombinedAISearchAssistant();
|
|
31
|
-
return this._instance;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public async getResultWidget(prompt: string): Promise<DG.Widget | null> {
|
|
35
|
-
const functionOrder = await this.getRelevantFunctionOrder(prompt);
|
|
36
|
-
console.log(`Function order for execution: ${functionOrder.join(', ')}`);
|
|
37
|
-
const remainingFunctions = Object.keys(this.functions).filter((fn) => !functionOrder.includes(fn));
|
|
38
|
-
let moreBtn: HTMLButtonElement | null = null;
|
|
39
|
-
// create a lazy tabcontrol with all functions, but the chosen one first
|
|
40
|
-
const tabcontrol = ui.tabControl();
|
|
41
|
-
|
|
42
|
-
const addFunctionTab = (functionName: string, setAsCurrentPane: boolean = false) => {
|
|
43
|
-
const funcInfo = this.functions[functionName];
|
|
44
|
-
const pane = tabcontrol.addPane(funcInfo.friendlyName, () => {
|
|
45
|
-
const wait = ui.wait(async () => {
|
|
46
|
-
const inputParam: {[key: string]: any} = {};
|
|
47
|
-
inputParam[funcInfo.inputName] = prompt;
|
|
48
|
-
const result: DG.Widget | null = await funcInfo.func.apply(inputParam);
|
|
49
|
-
if (result == null)
|
|
50
|
-
return ui.divText('No result generated.');
|
|
51
|
-
result.root.style.width = '100%';
|
|
52
|
-
return result.root;
|
|
53
|
-
});
|
|
54
|
-
return wait;
|
|
55
|
-
});
|
|
56
|
-
if (setAsCurrentPane) tabcontrol.currentPane = pane;
|
|
57
|
-
ui.tooltip.bind(pane.header, funcInfo.func.description);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const handleBtnClick = () => {
|
|
61
|
-
const menu = ui.popupMenu();
|
|
62
|
-
for (const functionName of remainingFunctions) {
|
|
63
|
-
const funcFn = this.functions[functionName].friendlyName;
|
|
64
|
-
menu.item(funcFn, () => {
|
|
65
|
-
// Remove selected function from remaining list
|
|
66
|
-
const index = remainingFunctions.indexOf(functionName);
|
|
67
|
-
if (index !== -1) remainingFunctions.splice(index, 1);
|
|
68
|
-
|
|
69
|
-
if (moreBtn && tabcontrol.header.contains(moreBtn))
|
|
70
|
-
tabcontrol.header.removeChild(moreBtn);
|
|
71
|
-
|
|
72
|
-
addFunctionTab(functionName, true);
|
|
73
|
-
|
|
74
|
-
if (moreBtn && remainingFunctions.length > 0)
|
|
75
|
-
tabcontrol.header.appendChild(moreBtn);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
menu.show();
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
for (const functionName of functionOrder)
|
|
82
|
-
addFunctionTab(functionName);
|
|
83
|
-
|
|
84
|
-
if (remainingFunctions.length) {
|
|
85
|
-
moreBtn = ui.button('...', () => handleBtnClick(), 'Click to see other options');
|
|
86
|
-
tabcontrol.header.appendChild(moreBtn);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
tabcontrol.root.style.width = '100%';
|
|
90
|
-
tabcontrol.root.style.height = 'unset';
|
|
91
|
-
tabcontrol.root.style.minHeight = '300px';
|
|
92
|
-
return DG.Widget.fromRoot(tabcontrol.root);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private lastUiprompt: string = '';
|
|
96
|
-
public resetSearchUI() {
|
|
97
|
-
this.lastUiprompt = '';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public async searchUI(prompt: string) {
|
|
101
|
-
if (this.lastUiprompt === prompt)
|
|
102
|
-
return;
|
|
103
|
-
this.lastUiprompt = prompt;
|
|
104
|
-
// add components to right places in ui
|
|
105
|
-
const searchResultHost = document.getElementsByClassName('power-pack-search-host')[0];
|
|
106
|
-
if (!searchResultHost) {
|
|
107
|
-
console.warn('No search result host found for combined AI search.');
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const spinner = ui.icons.spinner();
|
|
111
|
-
spinner.style.color = 'var(--blue-1)';
|
|
112
|
-
const searchingText = ui.divText('Grokking your question...', {style: {marginLeft: '8px'}});
|
|
113
|
-
const loader = ui.divH([spinner, searchingText], {style: {alignItems: 'center', marginTop: '8px'}});
|
|
114
|
-
const widgetDiv = ui.divV([loader], {style: {marginTop: '8px', marginBottom: '8px', alignItems: 'center', justifyContent: 'center', height: '100px'}});
|
|
115
|
-
searchResultHost.prepend(widgetDiv);
|
|
116
|
-
try {
|
|
117
|
-
const widgetResult = await this.getResultWidget(prompt);
|
|
118
|
-
if (!widgetResult)
|
|
119
|
-
throw new Error('No result widget generated.');
|
|
120
|
-
loader.remove();
|
|
121
|
-
widgetDiv.style.removeProperty('align-items');
|
|
122
|
-
widgetDiv.style.removeProperty('justify-content');
|
|
123
|
-
widgetDiv.style.removeProperty('height');
|
|
124
|
-
widgetDiv.appendChild(widgetResult.root);
|
|
125
|
-
} catch (error: any) {
|
|
126
|
-
console.error('Error during Combined AI search:', error);
|
|
127
|
-
widgetDiv.appendChild(ui.divText(`Error during Combined AI search: ${error.message}`));
|
|
128
|
-
} finally {
|
|
129
|
-
loader.remove();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private async getRelevantFunctionOrder(prompt: string) {
|
|
134
|
-
const fullPrompt = `
|
|
135
|
-
You are an intelligent assistant that helps to choose the best AI tool for a user's search query.
|
|
136
|
-
Given the following available functions and their descriptions along with descriptions of when to use them, reply with JSON array of only relevant functions in correct order and nothing else.
|
|
137
|
-
Make sure to reply WITH ONLY THE JSON PARSABLE ARRAY OF FUNCTION NAMES IN CORRECT ORDER (First being the best choice) and nothing else. no markdown, no backticks, no explanations nothing else.
|
|
138
|
-
Leave out the functions only if they are super irrelevant, otherwise include them but make sure the best function is first in the list.
|
|
139
|
-
Available functions:
|
|
140
|
-
${Object.values(this.functions).map((f) => `Function name: ${f.func.name}
|
|
141
|
-
Description: ${f.func.description}
|
|
142
|
-
Use when: ${f.func.options.useWhen}`).join('\n\n')}
|
|
143
|
-
|
|
144
|
-
User query: ${prompt}
|
|
145
|
-
|
|
146
|
-
`;
|
|
147
|
-
const res = await LLMClient.getInstance().generalPromptCached(
|
|
148
|
-
ModelType.Fast, 'You are a helpful assistant that selects the best function for a user query. reply with JSON array only and nothing else', fullPrompt);
|
|
149
|
-
|
|
150
|
-
let order = Object.keys(this.functions);
|
|
151
|
-
try {
|
|
152
|
-
const parsed = JSON.parse(res) as string[];
|
|
153
|
-
if (Array.isArray(parsed) && parsed.every((s) => typeof s === 'string' && this.functions[s]) && parsed.length > 0)
|
|
154
|
-
order = parsed;
|
|
155
|
-
else
|
|
156
|
-
console.error('Invalid function order response:', res);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.error('Error parsing function order response:', error, res);
|
|
159
|
-
}
|
|
160
|
-
return order;
|
|
161
|
-
}
|
|
162
|
-
}
|
package/src/llm-utils/creds.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as grok from 'datagrok-api/grok';
|
|
2
|
-
import * as DG from 'datagrok-api/dg';
|
|
3
|
-
|
|
4
|
-
const OPENAIVectorStoreName = 'vectorStoreId';
|
|
5
|
-
|
|
6
|
-
export class LLMCredsManager {
|
|
7
|
-
vectorStoreId: string;
|
|
8
|
-
private constructor(vectorStoreId: string) {
|
|
9
|
-
this.vectorStoreId = vectorStoreId;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
private static _instance: LLMCredsManager | null = null;
|
|
13
|
-
// Initialize the singleton instance
|
|
14
|
-
// TODO: in future this will probably move to credentials manager
|
|
15
|
-
static init(pckg: DG.Package): void {
|
|
16
|
-
const hasAIKey = grok.ai.config.configured;
|
|
17
|
-
const vectorStoreId = pckg.settings[OPENAIVectorStoreName];
|
|
18
|
-
LLMCredsManager._instance =
|
|
19
|
-
new LLMCredsManager(hasAIKey ? vectorStoreId ?? '' : '');
|
|
20
|
-
}
|
|
21
|
-
static getInstance(): LLMCredsManager {
|
|
22
|
-
return LLMCredsManager._instance!;
|
|
23
|
-
}
|
|
24
|
-
static getVectorStoreId(): string {
|
|
25
|
-
const res = LLMCredsManager.getInstance().vectorStoreId;
|
|
26
|
-
if (!res || !res.trim())
|
|
27
|
-
return '';
|
|
28
|
-
return res;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import {Client} from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
-
import {SSEClientTransport} from '@modelcontextprotocol/sdk/client/sse';
|
|
4
|
-
|
|
5
|
-
interface DeepWikiClientConfig {
|
|
6
|
-
repository: string;
|
|
7
|
-
openaiApiKey: string;
|
|
8
|
-
openaiModel?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const helpAIName = 'WIKITOR GROKOWSKY';
|
|
12
|
-
|
|
13
|
-
class DeepWikiMCPClient {
|
|
14
|
-
private mcpClient: Client;
|
|
15
|
-
private transport: SSEClientTransport | null = null;
|
|
16
|
-
private readonly askTool = {
|
|
17
|
-
name: 'ask_question',
|
|
18
|
-
description: 'Ask a question about the repository and get an answer based on its documentation.',
|
|
19
|
-
};
|
|
20
|
-
private static _instance: DeepWikiMCPClient | null = null;
|
|
21
|
-
static getInstance(repo?: string): DeepWikiMCPClient {
|
|
22
|
-
DeepWikiMCPClient._instance ??= new DeepWikiMCPClient(repo);
|
|
23
|
-
return DeepWikiMCPClient._instance;
|
|
24
|
-
}
|
|
25
|
-
private constructor(private repoName: string = 'datagrok-ai/public') {
|
|
26
|
-
this.mcpClient = new Client(
|
|
27
|
-
{
|
|
28
|
-
name: 'deepwiki-GROKOWSKY-client',
|
|
29
|
-
version: '1.0.0',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
capabilities: {},
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async connect(): Promise<void> {
|
|
38
|
-
if (this.transport) {
|
|
39
|
-
console.log('Already connected to MCP server');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
console.log('Connecting to DeepWiki MCP server...');
|
|
43
|
-
|
|
44
|
-
// Connect to DeepWiki's free mcp endpoint
|
|
45
|
-
this.transport = new SSEClientTransport(
|
|
46
|
-
new URL('https://mcp.deepwiki.com/mcp')
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
await this.mcpClient.connect(this.transport);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async disconnect(): Promise<void> {
|
|
53
|
-
if (this.transport) {
|
|
54
|
-
await this.transport.close();
|
|
55
|
-
console.log('\n✓ Disconnected from DeepWiki MCP server');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async askDeepWiki(question: string): Promise<string> {
|
|
60
|
-
if (!this.transport)
|
|
61
|
-
throw new Error('Not connected to MCP server. Call connect() first.');
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const q = `You are a helpful assistant with access to documentation for the ${this.repoName} GitHub repository.
|
|
65
|
-
|
|
66
|
-
VERY IMPORTANT TO REMEMER!!!: you are a UI side assistant for Datagrok platform users, so when asked about how to do something in Datagrok, try to answer with UI in mind and also the code.
|
|
67
|
-
|
|
68
|
-
Make sure the output is nicely formatted with markdown syntax where applicable.
|
|
69
|
-
|
|
70
|
-
Do not repeat the question in your answer, and do not include the deepwiki links!!!.
|
|
71
|
-
|
|
72
|
-
user: ${question}
|
|
73
|
-
`;
|
|
74
|
-
// just call the ask tool directly
|
|
75
|
-
const toolArgs = {
|
|
76
|
-
repoName: this.repoName,
|
|
77
|
-
repository: this.repoName,
|
|
78
|
-
question: q,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const result = await this.mcpClient.callTool({
|
|
82
|
-
name: this.askTool.name,
|
|
83
|
-
arguments: toolArgs,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const contentArray = Array.isArray(result.content) ? result.content : [];
|
|
87
|
-
const toolResult = contentArray
|
|
88
|
-
.filter((item: any) => item.type === 'text')
|
|
89
|
-
.map((item: any) => item.text || '')
|
|
90
|
-
.join('\n');
|
|
91
|
-
if (!toolResult || toolResult.length === 0)
|
|
92
|
-
return 'No response generated.';
|
|
93
|
-
|
|
94
|
-
// remove deepwiki links from the answer
|
|
95
|
-
const lines = toolResult.split('\n').filter((line) => !line.includes('deepwiki.com')).join('\n');
|
|
96
|
-
return lines;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Example usage
|
|
101
|
-
export async function askDeepWiki(question: string) {
|
|
102
|
-
const client = DeepWikiMCPClient.getInstance('datagrok-ai/public');
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
await client.connect();
|
|
106
|
-
|
|
107
|
-
const response = await client.askDeepWiki(
|
|
108
|
-
question
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
return response;
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error('Error:', error);
|
|
114
|
-
return `Error: ${error}`;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|