@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.
Files changed (203) hide show
  1. package/.claude/skills/deploy-grokky/SKILL.md +193 -0
  2. package/.grokignore +2 -0
  3. package/.turbo/turbo-build.log +24 -0
  4. package/.vscode/settings.json +16 -0
  5. package/CHANGELOG.md +151 -8
  6. package/CLAUDE.md +284 -0
  7. package/CREDITS.md +173 -0
  8. package/LICENSE.md +16 -0
  9. package/README.md +24 -0
  10. package/bdd/bdd.config.json +1 -0
  11. package/bdd/bindings/elements.ts +9 -0
  12. package/bdd/bindings/steps.ts +787 -0
  13. package/bdd/features/ai-panel/platform-work.feature +63 -0
  14. package/bdd/features/ai-panel/session.feature +69 -0
  15. package/bdd/features/ai-panel/table-work.feature +99 -0
  16. package/bdd/generated/ai-panel/platform-work.test.ts +103 -0
  17. package/bdd/generated/ai-panel/session.test.ts +100 -0
  18. package/bdd/generated/ai-panel/table-work.test.ts +150 -0
  19. package/bdd/package.json +1 -0
  20. package/bdd/tsconfig.json +13 -0
  21. package/css/ai.css +637 -49
  22. package/dist/package-test.js +4 -1707
  23. package/dist/package-test.js.map +1 -1
  24. package/dist/package.js +742 -92317
  25. package/dist/package.js.map +1 -1
  26. package/dockerfiles/claude-runtime/.dockerignore +1 -0
  27. package/{.eslintrc.json → dockerfiles/claude-runtime/.eslintrc.json} +7 -16
  28. package/dockerfiles/claude-runtime/Dockerfile +73 -13
  29. package/dockerfiles/claude-runtime/agent/grokky_agent/__init__.py +0 -0
  30. package/dockerfiles/claude-runtime/agent/grokky_agent/__main__.py +80 -0
  31. package/dockerfiles/claude-runtime/agent/grokky_agent/browser_tools.py +180 -0
  32. package/dockerfiles/claude-runtime/agent/grokky_agent/config.py +26 -0
  33. package/dockerfiles/claude-runtime/agent/grokky_agent/formats.py +155 -0
  34. package/dockerfiles/claude-runtime/agent/grokky_agent/guard.py +87 -0
  35. package/dockerfiles/claude-runtime/agent/grokky_agent/hermes.py +212 -0
  36. package/dockerfiles/claude-runtime/agent/grokky_agent/hermes.yaml +45 -0
  37. package/dockerfiles/claude-runtime/agent/grokky_agent/hermes_plugin/__init__.py +8 -0
  38. package/dockerfiles/claude-runtime/agent/grokky_agent/hermes_plugin/plugin.yaml +3 -0
  39. package/dockerfiles/claude-runtime/agent/grokky_agent/protocol.py +174 -0
  40. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/__init__.py +21 -0
  41. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/anthropic.py +21 -0
  42. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/azure.py +46 -0
  43. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/base.py +127 -0
  44. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/bedrock.py +46 -0
  45. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/custom.py +40 -0
  46. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/databricks.py +54 -0
  47. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/openai_platform.py +41 -0
  48. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/openrouter.py +46 -0
  49. package/dockerfiles/claude-runtime/agent/grokky_agent/session.py +471 -0
  50. package/dockerfiles/claude-runtime/agent/grokky_agent/skills.py +44 -0
  51. package/dockerfiles/claude-runtime/agent/grokky_agent/structured.py +40 -0
  52. package/dockerfiles/claude-runtime/container.json +2 -2
  53. package/dockerfiles/claude-runtime/entrypoint.sh +20 -0
  54. package/dockerfiles/claude-runtime/package-lock.json +1721 -306
  55. package/dockerfiles/claude-runtime/package.json +20 -5
  56. package/dockerfiles/claude-runtime/plugin/.claude-plugin/plugin.json +5 -0
  57. package/dockerfiles/claude-runtime/plugin/skills/datagrok-calc-column/SKILL.md +92 -0
  58. package/dockerfiles/claude-runtime/plugin/skills/datagrok-chem-data/SKILL.md +250 -0
  59. package/dockerfiles/claude-runtime/plugin/skills/datagrok-chem-toolkit/SKILL.md +395 -0
  60. package/dockerfiles/claude-runtime/plugin/skills/datagrok-df-and-columns/SKILL.md +454 -0
  61. package/dockerfiles/claude-runtime/plugin/skills/datagrok-entities/SKILL.md +38 -0
  62. package/dockerfiles/claude-runtime/plugin/skills/datagrok-exec/SKILL.md +209 -0
  63. package/dockerfiles/claude-runtime/plugin/skills/datagrok-filtering/SKILL.md +185 -0
  64. package/dockerfiles/claude-runtime/plugin/skills/datagrok-grid-customization/SKILL.md +270 -0
  65. package/dockerfiles/claude-runtime/plugin/skills/datagrok-projects/SKILL.md +100 -0
  66. package/dockerfiles/claude-runtime/plugin/skills/datagrok-selection/SKILL.md +344 -0
  67. package/dockerfiles/claude-runtime/plugin/skills/datagrok-undo/SKILL.md +78 -0
  68. package/dockerfiles/claude-runtime/plugin/skills/datagrok-viewers/SKILL.md +303 -0
  69. package/dockerfiles/claude-runtime/pyproject.toml +18 -0
  70. package/dockerfiles/claude-runtime/src/agent/pool.ts +411 -0
  71. package/dockerfiles/claude-runtime/src/agent/turn.ts +153 -0
  72. package/dockerfiles/claude-runtime/src/constants.ts +20 -0
  73. package/dockerfiles/claude-runtime/src/credentials.ts +45 -0
  74. package/dockerfiles/claude-runtime/src/grounding.ts +104 -0
  75. package/dockerfiles/claude-runtime/src/help-index.ts +118 -0
  76. package/dockerfiles/claude-runtime/src/privileges.ts +8 -0
  77. package/dockerfiles/claude-runtime/src/prompts.ts +211 -0
  78. package/dockerfiles/claude-runtime/src/server.ts +134 -234
  79. package/dockerfiles/claude-runtime/src/session.ts +328 -0
  80. package/dockerfiles/claude-runtime/src/shared-api-client.ts +112 -0
  81. package/dockerfiles/claude-runtime/src/stream-filter.ts +80 -0
  82. package/dockerfiles/claude-runtime/src/sync/home-files.ts +80 -0
  83. package/dockerfiles/claude-runtime/src/sync/orchestrator.ts +214 -0
  84. package/dockerfiles/claude-runtime/src/sync/packages.ts +145 -0
  85. package/dockerfiles/claude-runtime/src/sync/shared-connections.ts +87 -0
  86. package/dockerfiles/claude-runtime/src/sync/workspace.ts +68 -0
  87. package/dockerfiles/claude-runtime/src/tasks.ts +124 -0
  88. package/dockerfiles/claude-runtime/src/tool-summary.ts +66 -0
  89. package/dockerfiles/claude-runtime/src/types.ts +142 -23
  90. package/dockerfiles/claude-runtime/src/user/installed-packages.ts +17 -0
  91. package/dockerfiles/claude-runtime/src/user/staged-workspace.ts +80 -0
  92. package/dockerfiles/claude-runtime/src/user/user-dir.ts +108 -0
  93. package/dockerfiles/claude-runtime/src/verify.ts +136 -0
  94. package/dockerfiles/claude-runtime/src/watchdog.ts +115 -0
  95. package/dockerfiles/claude-runtime/test/credentials.test.js +43 -0
  96. package/dockerfiles/claude-runtime/test/grounding.test.js +191 -0
  97. package/dockerfiles/claude-runtime/test/help-index.test.js +115 -0
  98. package/dockerfiles/claude-runtime/test/plugin-skills.test.js +57 -0
  99. package/dockerfiles/claude-runtime/test/prompts.test.js +62 -0
  100. package/dockerfiles/claude-runtime/test/reaper.test.js +60 -0
  101. package/dockerfiles/claude-runtime/test/stream-filter.test.js +132 -0
  102. package/dockerfiles/claude-runtime/test/tasks.test.js +74 -0
  103. package/dockerfiles/claude-runtime/test/user-dir.test.js +71 -0
  104. package/dockerfiles/claude-runtime/test/verify.test.js +187 -0
  105. package/dockerfiles/claude-runtime/test/watchdog.test.js +43 -0
  106. package/dockerfiles/mcp-server/.eslintrc.json +39 -0
  107. package/dockerfiles/mcp-server/Dockerfile +10 -2
  108. package/dockerfiles/mcp-server/package-lock.json +1743 -98
  109. package/dockerfiles/mcp-server/package.json +27 -5
  110. package/dockerfiles/mcp-server/src/api-client.ts +123 -66
  111. package/dockerfiles/mcp-server/src/format.ts +51 -0
  112. package/dockerfiles/mcp-server/src/index.ts +44 -113
  113. package/dockerfiles/mcp-server/src/ops.ts +325 -0
  114. package/dockerfiles/mcp-server/src/shared-api-client.ts +81 -0
  115. package/dockerfiles/mcp-server/test/format.test.js +62 -0
  116. package/dockerfiles/mcp-server/test/ops.test.js +84 -0
  117. package/dockerfiles/mcp-server/test/shared-api-client.test.js +35 -0
  118. package/dockerfiles/queue/Dockerfile +2 -0
  119. package/dockerfiles/queue/container.json +7 -0
  120. package/docs/AUDIT-2026-08-03.md +1064 -0
  121. package/docs/BENCHMARK.md +292 -0
  122. package/docs/CLAUDE_CODE_FLOW.md +746 -0
  123. package/docs/EXAMPLES.md +82 -0
  124. package/docs/FEATURES.md +71 -0
  125. package/docs/IMPLEMENTATION.md +128 -0
  126. package/docs/LATENCY.md +170 -0
  127. package/docs/VISION.md +36 -0
  128. package/files/benchmark/suite.yaml +404 -0
  129. package/files/scripts/process-cro-results.md +14 -0
  130. package/files/suggestions.yaml +344 -0
  131. package/package.json +39 -97
  132. package/src/ai/ai-window.ts +157 -0
  133. package/src/ai/benchmark/benchmark.ts +737 -0
  134. package/src/ai/db-view-functions.ts +56 -0
  135. package/src/ai/engine.ts +98 -0
  136. package/src/ai/gemma-engine.ts +81 -0
  137. package/src/ai/panel.ts +1385 -0
  138. package/src/ai/prompt-suggestions.ts +209 -0
  139. package/src/ai/search/combined-search.ts +244 -0
  140. package/src/{llm-utils → ai/search}/query-matching.ts +46 -167
  141. package/src/{llm-utils → ai}/storage.ts +0 -1
  142. package/src/ai/table-tools.ts +145 -0
  143. package/src/ai/ui.ts +720 -0
  144. package/src/ai/usage-limiter.ts +105 -0
  145. package/src/ai/view-tools.ts +352 -0
  146. package/src/claude/ai-feature.ts +16 -0
  147. package/src/claude/exec-blocks.ts +176 -0
  148. package/src/claude/queue-task.ts +84 -0
  149. package/src/claude/runtime-client.ts +310 -0
  150. package/src/claude/turn-log.ts +114 -0
  151. package/src/claude/undoable.ts +105 -0
  152. package/src/{llm-utils → db}/db-index-tools.ts +24 -32
  153. package/src/db/sql-tools.ts +336 -0
  154. package/src/depr/LLM-client.ts +251 -0
  155. package/src/depr/ai-panel.ts +174 -0
  156. package/src/depr/chatgpt-assistant.ts +257 -0
  157. package/src/depr/creds.ts +30 -0
  158. package/src/depr/deepwikiclient.ts +118 -0
  159. package/src/depr/indexes/dg-repository-index.ts +266 -0
  160. package/src/depr/interfaces.ts +170 -0
  161. package/src/depr/is-help-request.ts +39 -0
  162. package/src/depr/prompt-engine.ts +52 -0
  163. package/src/depr/rendering-tools.ts +103 -0
  164. package/src/depr/script-tools.ts +785 -0
  165. package/src/depr/tableview-tools.ts +746 -0
  166. package/src/depr/viewers-ai.ts +67 -0
  167. package/src/package-api.ts +87 -28
  168. package/src/package-test.ts +1 -0
  169. package/src/package.g.ts +98 -48
  170. package/src/package.ts +211 -157
  171. package/src/polyfills.ts +12 -0
  172. package/src/utils.ts +128 -0
  173. package/tsconfig.json +8 -70
  174. package/webpack.config.js +3 -49
  175. package/.eslintignore +0 -2
  176. package/src/ai-panel.ts +0 -174
  177. package/src/claude-code/claude-panel.ts +0 -34
  178. package/src/claude-code/claude-runtime-client.ts +0 -148
  179. package/src/llm-utils/LLM-client.ts +0 -251
  180. package/src/llm-utils/combined-search.ts +0 -162
  181. package/src/llm-utils/creds.ts +0 -30
  182. package/src/llm-utils/deepwikiclient.ts +0 -118
  183. package/src/llm-utils/indexes/dg-repository-index.ts +0 -266
  184. package/src/llm-utils/panel.ts +0 -866
  185. package/src/llm-utils/script-tools.ts +0 -784
  186. package/src/llm-utils/sql-tools.ts +0 -840
  187. package/src/llm-utils/tableview-tools.ts +0 -704
  188. package/src/llm-utils/ui.ts +0 -315
  189. package/src/prompt-engine/chatgpt-assistant.ts +0 -257
  190. package/src/prompt-engine/interfaces.ts +0 -170
  191. package/src/prompt-engine/prompt-engine.ts +0 -52
  192. package/src/prompt-engine/rendering-tools.ts +0 -103
  193. package/src/prompts/is-help-request.ts +0 -26
  194. package/src/viewers-ai.ts +0 -67
  195. /package/src/{llm-utils → db}/indexes/biologics-index.ts +0 -0
  196. /package/src/{llm-utils → db}/indexes/chembl-index.ts +0 -0
  197. /package/src/{llm-utils → db}/query-meta-utils.ts +0 -0
  198. /package/src/{llm-utils/depr → depr}/AI-API-providers/openai-chat-completions-provider.ts +0 -0
  199. /package/src/{llm-utils/depr → depr}/AI-API-providers/openai-responses-provider.ts +0 -0
  200. /package/src/{llm-utils/depr → depr}/AI-API-providers/types.ts +0 -0
  201. /package/src/{llm-utils/depr → depr}/depr.ts +0 -0
  202. /package/src/{llm-utils/depr → depr}/embeddings.ts +0 -0
  203. /package/src/{llm-utils/depr → depr}/sql-utils.ts +0 -0
@@ -0,0 +1,127 @@
1
+ import re
2
+ from abc import ABC, abstractmethod
3
+ from typing import ClassVar, NamedTuple
4
+ from urllib.parse import urlsplit, urlunsplit
5
+
6
+ from .. import hermes
7
+ from ..formats import FORMATS, ApiFormat, ApiMode
8
+ from ..hermes import Connection, Usage
9
+ from ..protocol import JsonObject
10
+
11
+ Credentials = dict[str, str]
12
+
13
+ # Claude speaks Anthropic's Messages API everywhere; GPT calls tools reliably only through OpenAI's Responses API.
14
+ CLAUDE = re.compile(r'claude', re.IGNORECASE)
15
+ LOCAL_HOST = r'(127\.0\.0\.1|localhost|\[::1\]|host\.docker\.internal)'
16
+ # Hermes sends any other sk-ant-* key, a JWT or a cc- token to api.anthropic.com as a Claude subscription login under
17
+ # Claude Code's identity (agent/anthropic_credentials.py _is_oauth_token), which Anthropic allows only in its own apps.
18
+ SUBSCRIPTION_TOKEN = re.compile(r'^(sk-ant-(?!api|usr|svc|admin)|eyJ|cc-)')
19
+
20
+
21
+ class ProviderError(ValueError):
22
+ """The Grokky credentials cannot be used with this provider."""
23
+
24
+
25
+ class Route(NamedTuple):
26
+ """Where a provider serves a wire format, and whether the key goes out as a Bearer token. On the Anthropic
27
+ Messages format Hermes sends a string key as x-api-key and a callable's as Bearer (hermes.send_keys_by_type);
28
+ the OpenAI formats always send Bearer."""
29
+ url: str
30
+ bearer: bool = False
31
+
32
+
33
+ class Provider(ABC):
34
+ """A model API the agent runs on: the Grokky credentials it takes, the wire formats it serves and where, and
35
+ the one model every turn runs on, named by the `model` credential as the provider names it."""
36
+
37
+ name: ClassVar[str]
38
+ # What the apiKey credential must be, for the message when it is missing.
39
+ key_kind: ClassVar[str]
40
+ # A model as this provider names it, for the message when the model credential is missing.
41
+ model_example: ClassVar[str]
42
+ # The price list Hermes keeps for this provider (agent/usage_pricing.py). Without one, or for a model the list
43
+ # lacks, a turn's cost is unknown and only its call limit bounds it.
44
+ billing: ClassVar[str | None] = None
45
+
46
+ def __init__(self, credentials: Credentials) -> None:
47
+ self.test_upstream = credentials.get('TEST_UPSTREAM')
48
+ self.model = self._model(credentials)
49
+ routes = self.routes(credentials)
50
+ mode = next(iter(routes)) if len(routes) == 1 else self.mode()
51
+ self.format: ApiFormat = FORMATS[mode]
52
+ self.route = routes[mode]
53
+ key = credentials.get('apiKey')
54
+ if not key:
55
+ raise ProviderError(f'The apiKey Grokky credential is not set: set {self.key_kind}')
56
+ if re.search(r'[^\x21-\x7e]', key):
57
+ raise ProviderError('The apiKey Grokky credential contains whitespace or control characters')
58
+ self.check_key(key)
59
+ self.key = key
60
+
61
+ def mode(self) -> ApiMode:
62
+ """The format of the model on a provider that serves several."""
63
+ return 'anthropic_messages' if CLAUDE.search(self.model) else 'codex_responses'
64
+
65
+ @abstractmethod
66
+ def routes(self, credentials: Credentials) -> dict[ApiMode, Route]:
67
+ """The wire formats this provider serves, each with where; with two, a Claude model is called in Anthropic's
68
+ Messages format and any other in OpenAI's Responses one."""
69
+
70
+ def check_key(self, key: str) -> None:
71
+ """Refuses a key of the wrong kind before a call is made."""
72
+ return None
73
+
74
+ def connection(self) -> Connection:
75
+ """How Hermes reaches the model: always an explicit Hermes provider id, never `auto` or empty, with which
76
+ Hermes would pick a provider and a credential itself."""
77
+ key = self.key
78
+ bearer = self.route.bearer and self.format.mode == 'anthropic_messages'
79
+ return {'provider': 'custom', 'api_mode': self.format.mode, 'base_url': self.route.url,
80
+ 'api_key': (lambda: key) if bearer else key}
81
+
82
+ def patch_request(self, api_mode: str, request: JsonObject, system_prompt: str,
83
+ output_schema: JsonObject | None) -> JsonObject:
84
+ """The outgoing request with the turn's system prompt, if any, and output format."""
85
+ out = FORMATS[api_mode].patch(request, system_prompt, output_schema)
86
+ # Hermes renames Claude on the Messages format (anthropic/claude-sonnet-5.5 → claude-sonnet-5-5); the
87
+ # provider routes by its own name.
88
+ if api_mode == 'anthropic_messages':
89
+ out['model'] = self.model
90
+ return out
91
+
92
+ def cost(self, usage: Usage) -> float | None:
93
+ """USD for one call, or None when Hermes has no price for the model."""
94
+ return hermes.usage_cost(self.model, usage, self.billing, self.route.url) if self.billing else None
95
+
96
+ def error_hint(self, status: int | None) -> str:
97
+ """Added to a failed call's message, e.g. what to check for a rejected key."""
98
+ return ''
99
+
100
+ def endpoint(self, url: str) -> str:
101
+ """The URL, or with TEST_UPSTREAM set, the URL with its scheme, host and port replaced: the path stays, so a
102
+ test stub sees each route's real path. The override may name only a local host, or this URL's own host over
103
+ https for a stub answering under that name."""
104
+ if not self.test_upstream:
105
+ return url
106
+ real = urlsplit(url)
107
+ if not re.fullmatch(rf'(https?://{LOCAL_HOST}|https://{re.escape(real.hostname or "")})(:\d+)?/?',
108
+ self.test_upstream):
109
+ raise ProviderError("TEST_UPSTREAM may only name a local test host, or the provider's own host over https")
110
+ upstream = urlsplit(self.test_upstream)
111
+ return urlunsplit(real._replace(scheme=upstream.scheme, netloc=upstream.netloc))
112
+
113
+ @staticmethod
114
+ def refuse_subscription_token(key: str, url: str) -> None:
115
+ """Refuses a Claude subscription token bound for api.anthropic.com; other hosts take JWTs (Entra ID, OAuth)."""
116
+ if urlsplit(url).hostname == 'api.anthropic.com' and SUBSCRIPTION_TOKEN.match(key.strip()):
117
+ raise ProviderError('The apiKey Grokky credential is a Claude subscription token: '
118
+ 'set an Anthropic Console API key')
119
+
120
+ def _model(self, credentials: Credentials) -> str:
121
+ model = (credentials.get('model') or '').strip()
122
+ if not model:
123
+ raise ProviderError(f'The model Grokky credential is not set: name the model as {self.name} names '
124
+ f'it, such as {self.model_example}')
125
+ if re.search(r'\s', model):
126
+ raise ProviderError('The model Grokky credential contains whitespace')
127
+ return model
@@ -0,0 +1,46 @@
1
+ import re
2
+
3
+ from ..formats import ApiMode
4
+ from ..hermes import Connection
5
+ from .base import CLAUDE, Credentials, Provider, ProviderError, Route
6
+
7
+ # The AWS commercial regions: GovCloud has no global inference profiles, and China has a domain of its own.
8
+ REGION = re.compile(r'(af|ap|ca|eu|il|me|mx|sa|us)-[a-z]+-\d{1,2}')
9
+
10
+
11
+ class BedrockProvider(Provider):
12
+ """Models on Amazon Bedrock's bedrock-runtime endpoint with an Amazon Bedrock API key: Claude on the Messages API
13
+ (the key as x-api-key), GPT on the Responses API (as Bearer), and every other model (Qwen, Kimi, ...) on the
14
+ Converse API. A model is named by its inference profile,
15
+ such as global.anthropic.claude-sonnet-5-5: a global profile reaches the model from every commercial region at the
16
+ vendor's own price, a geographic one costs 10% more
17
+ (https://docs.aws.amazon.com/bedrock/latest/userguide/models-endpoint-availability.html)."""
18
+
19
+ name = 'Bedrock'
20
+ key_kind = 'an Amazon Bedrock API key'
21
+ model_example = 'global.anthropic.claude-sonnet-5-5'
22
+
23
+ def routes(self, credentials: Credentials) -> dict[ApiMode, Route]:
24
+ region = credentials.get('region') or ''
25
+ if not REGION.fullmatch(region):
26
+ raise ProviderError('The region Grokky credential must name the AWS commercial region the Bedrock API '
27
+ 'key was created in, such as us-east-1')
28
+ host = f'https://bedrock-runtime.{region}.amazonaws.com'
29
+ return {'anthropic_messages': Route(self.endpoint(host + '/anthropic')),
30
+ 'codex_responses': Route(self.endpoint(host + '/openai/v1')),
31
+ 'bedrock_converse': Route(self.endpoint(host))}
32
+
33
+ def mode(self) -> ApiMode:
34
+ if CLAUDE.search(self.model):
35
+ return 'anthropic_messages'
36
+ return 'codex_responses' if re.match(r'([a-z]+\.)?openai\.', self.model) else 'bedrock_converse'
37
+
38
+ def connection(self) -> Connection:
39
+ if self.format.mode != 'bedrock_converse':
40
+ return super().connection()
41
+ # Hermes' own Bedrock provider; hermes.use_bedrock_key gives its boto3 clients the key.
42
+ return {'provider': 'bedrock', 'api_mode': 'bedrock_converse', 'base_url': self.route.url, 'api_key': 'aws-sdk'}
43
+
44
+ def error_hint(self, status: int | None) -> str:
45
+ return (' (check the apiKey and region Grokky credentials: a Bedrock API key works only in the region it '
46
+ 'was created in, and only for the models its IAM user may invoke)') if status in (401, 403) else ''
@@ -0,0 +1,40 @@
1
+ import re
2
+
3
+ from ..formats import BY_CREDENTIAL, ApiMode
4
+ from .base import Credentials, Provider, ProviderError, Route
5
+
6
+ # The model clients append their route to the path and cannot carry user info, a query or a fragment. A host with a
7
+ # trailing dot or outside ASCII is refused: Hermes drops the dot, and IDNA may map a fullwidth letter onto its ASCII
8
+ # one, either of which can turn another host into api.anthropic.com. Only https: over plain http, to a local host too,
9
+ # a tool of any session could listen on that port and take the key and the conversations.
10
+ BASE_URL = re.compile(r'https://[\w-]+(\.[\w-]+)*(:\d+)?(/[^?#\s]*)?', re.ASCII)
11
+ # What to check after a failed call, by its HTTP status; without one nothing answered as the API (a connection error,
12
+ # a login page instead of an event stream).
13
+ HINTS: dict[int | None, str] = {
14
+ None: 'the baseUrl Grokky credential',
15
+ 401: 'the apiKey Grokky credential: a key the endpoint takes as a Bearer token',
16
+ 404: 'the baseUrl, apiFormat and model Grokky credentials'}
17
+
18
+
19
+ class CustomProvider(Provider):
20
+ """The customer's own gateway or self-hosted service at `baseUrl`, called in the `apiFormat` the admin names, with
21
+ the key as a Bearer token."""
22
+
23
+ name = 'Custom'
24
+ key_kind = 'the key the endpoint takes as a Bearer token'
25
+ model_example = 'claude-sonnet-5-5'
26
+
27
+ def routes(self, credentials: Credentials) -> dict[ApiMode, Route]:
28
+ api_format = BY_CREDENTIAL.get(credentials.get('apiFormat') or '')
29
+ if api_format is None:
30
+ raise ProviderError(f'The apiFormat Grokky credential must be one of {", ".join(BY_CREDENTIAL)}')
31
+ url = credentials.get('baseUrl') or ''
32
+ if not BASE_URL.fullmatch(url):
33
+ raise ProviderError("The baseUrl Grokky credential must be the endpoint's https URL, without user "
34
+ 'info, a query or a fragment')
35
+ route = Route(self.endpoint(url), bearer=True)
36
+ self.refuse_subscription_token(credentials.get('apiKey') or '', route.url)
37
+ return {api_format.mode: route}
38
+
39
+ def error_hint(self, status: int | None) -> str:
40
+ return f' (check {HINTS[status]})' if status in HINTS else ''
@@ -0,0 +1,54 @@
1
+ import re
2
+
3
+ from ..formats import ApiMode
4
+ from ..protocol import JsonObject
5
+ from .base import Credentials, Provider, ProviderError, Route
6
+
7
+ # A workspace's own URL on AWS, Azure or Google Cloud:
8
+ # https://docs.databricks.com/aws/en/workspace/workspace-details (and its Azure and Google Cloud versions)
9
+ WORKSPACE = re.compile(r'https://([a-z0-9][a-z0-9-]*\.cloud\.databricks\.com|adb-\d+\.\d+\.azuredatabricks\.net|'
10
+ r'\d+\.\d+\.gcp\.databricks\.com)/?')
11
+ # A Unity Catalog model service: <catalog>.<schema>.<name>.
12
+ SERVICE = re.compile(r'[\w-]+\.[\w-]+\.[\w-]+')
13
+
14
+
15
+ class DatabricksProvider(Provider):
16
+ """Claude and GPT through a Databricks workspace's AI Gateway, with a Databricks token as Bearer on both routes
17
+ (https://docs.databricks.com/aws/en/machine-learning/model-serving/query-anthropic-messages,
18
+ …/query-openai-responses). A model is named as the gateway serves it, such as system.ai.claude-sonnet-5-5; with
19
+ the `service` credential, a model service of the workspace's own (an external provider's model) is named in the
20
+ Databricks-Model-Provider-Service header, and `model` is the provider's model id the service allows."""
21
+
22
+ name = 'Databricks'
23
+ key_kind = 'a Databricks personal access token'
24
+ model_example = 'system.ai.claude-sonnet-5-5'
25
+
26
+ def routes(self, credentials: Credentials) -> dict[ApiMode, Route]:
27
+ workspace = credentials.get('baseUrl') or ''
28
+ if not WORKSPACE.fullmatch(workspace):
29
+ raise ProviderError('The baseUrl Grokky credential is not a Databricks workspace URL: set '
30
+ 'https://<workspace>.cloud.databricks.com, https://adb-<id>.<n>.azuredatabricks.net '
31
+ 'or https://<id>.<n>.gcp.databricks.com')
32
+ service = (credentials.get('service') or '').strip()
33
+ if service and not SERVICE.fullmatch(service):
34
+ raise ProviderError('The service Grokky credential must name a model service as '
35
+ '<catalog>.<schema>.<name>, such as workspace.default.claude-haiku-5-5-ext')
36
+ self.service = service
37
+ base = workspace.rstrip('/')
38
+ return {'anthropic_messages': Route(self.endpoint(base + '/ai-gateway/anthropic'), bearer=True),
39
+ 'codex_responses': Route(self.endpoint(base + '/ai-gateway/openai/v1'), bearer=True)}
40
+
41
+ def patch_request(self, api_mode: str, request: JsonObject, system_prompt: str,
42
+ output_schema: JsonObject | None) -> JsonObject:
43
+ out = super().patch_request(api_mode, request, system_prompt, output_schema)
44
+ if self.service:
45
+ out['extra_headers'] = {**(out.get('extra_headers') or {}),
46
+ 'Databricks-Model-Provider-Service': self.service}
47
+ return out
48
+
49
+ def error_hint(self, status: int | None) -> str:
50
+ if status in (401, 403):
51
+ return (' (check the apiKey Grokky credential: a token of this workspace whose user or service '
52
+ 'principal may query the model' +
53
+ (', and that model is a model id the service allows)' if self.service else ')'))
54
+ return ' (check the model and service Grokky credentials)' if status == 404 and self.service else ''
@@ -0,0 +1,41 @@
1
+ import re
2
+
3
+ from ..formats import ApiMode
4
+ from .base import Credentials, Provider, ProviderError, Route
5
+
6
+ API = 'https://api.openai.com/v1'
7
+ # A project with data residency is called at its region's host:
8
+ # https://developers.openai.com/api/docs/guides/your-data
9
+ REGIONS = ('us', 'eu', 'ae', 'au', 'ca', 'jp', 'in', 'sg', 'kr', 'gb')
10
+ BASE_URL = re.compile(rf'https://((?:{"|".join(REGIONS)})\.)?api\.openai\.com(?:/v1)?/?')
11
+
12
+
13
+ class OpenAIProvider(Provider):
14
+ """GPT on the OpenAI Responses API with a project's API key."""
15
+
16
+ name = 'OpenAI'
17
+ key_kind = 'an API key of an OpenAI project'
18
+ model_example = 'gpt-6.1-sol'
19
+ billing = 'openai'
20
+
21
+ def routes(self, credentials: Credentials) -> dict[ApiMode, Route]:
22
+ base_url = (credentials.get('baseUrl') or '').strip()
23
+ m = BASE_URL.fullmatch(base_url) if base_url else None
24
+ if base_url and not m:
25
+ raise ProviderError('The baseUrl Grokky credential is not an OpenAI API address: set '
26
+ f'https://<region>.api.openai.com, region one of {", ".join(REGIONS)}, for a project '
27
+ 'with data residency, or leave it empty')
28
+ return {'codex_responses': Route(self.endpoint(f'https://{m[1] or ""}api.openai.com/v1' if m else API))}
29
+
30
+ def check_key(self, key: str) -> None:
31
+ # A ChatGPT or Codex login and a workload identity federation token are JWTs.
32
+ if key.startswith('eyJ'):
33
+ raise ProviderError('The apiKey Grokky credential is a token, such as a ChatGPT or Codex login: '
34
+ 'set an API key of an OpenAI project')
35
+ if key.startswith('sk-admin-'):
36
+ raise ProviderError('The apiKey Grokky credential is an OpenAI Admin API key, which works only on the '
37
+ 'administration endpoints: set an API key of a project')
38
+
39
+ def error_hint(self, status: int | None) -> str:
40
+ return (' (check the apiKey Grokky credential, an API key of an OpenAI project, and for a project with '
41
+ 'data residency the baseUrl one)') if status == 401 else ''
@@ -0,0 +1,46 @@
1
+ from ..formats import ApiMode
2
+ from ..protocol import JsonObject
3
+ from .base import CLAUDE, Credentials, Provider, ProviderError, Route
4
+
5
+ API = 'https://openrouter.ai/api'
6
+ # Replaces Hermes' own app attribution (https://openrouter.ai/docs/app-attribution); an empty category list drops the
7
+ # categories Hermes files its calls under.
8
+ ATTRIBUTION = {'HTTP-Referer': 'https://datagrok.ai', 'X-Title': 'Datagrok', 'X-OpenRouter-Categories': ''}
9
+
10
+
11
+ class OpenRouterProvider(Provider):
12
+ """Claude on OpenRouter's Anthropic Messages API, OpenAI's models on its Responses API and every other model on
13
+ its Chat Completions API, with an OpenRouter API key, Bearer as OpenRouter documents it. Gemini, Qwen and Kimi
14
+ return no tool calls through the Responses API."""
15
+
16
+ name = 'OpenRouter'
17
+ key_kind = 'an OpenRouter API key'
18
+ model_example = 'anthropic/claude-sonnet-5.5'
19
+ billing = 'openrouter'
20
+
21
+ def routes(self, credentials: Credentials) -> dict[ApiMode, Route]:
22
+ return {'anthropic_messages': Route(self.endpoint(API), bearer=True),
23
+ 'codex_responses': Route(self.endpoint(f'{API}/v1')),
24
+ 'chat_completions': Route(self.endpoint(f'{API}/v1'))}
25
+
26
+ def mode(self) -> ApiMode:
27
+ if CLAUDE.search(self.model):
28
+ return 'anthropic_messages'
29
+ return 'codex_responses' if self.model.startswith('openai/') else 'chat_completions'
30
+
31
+ def check_key(self, key: str) -> None:
32
+ if not key.startswith('sk-or-'):
33
+ raise ProviderError('The apiKey Grokky credential is not an OpenRouter API key (sk-or-…)')
34
+
35
+ def patch_request(self, api_mode: str, request: JsonObject, system_prompt: str,
36
+ output_schema: JsonObject | None) -> JsonObject:
37
+ out = super().patch_request(api_mode, request, system_prompt, output_schema)
38
+ out['extra_headers'] = {**(out.get('extra_headers') or {}), **ATTRIBUTION}
39
+ # Some hosts of every Claude model lack structured output; GPT's lack it only where they lack
40
+ # response_format, which OpenRouter already routes around.
41
+ if api_mode == 'anthropic_messages' and output_schema is not None:
42
+ out['extra_body'] = {**(out.get('extra_body') or {}), 'provider': {'require_parameters': True}}
43
+ return out
44
+
45
+ def error_hint(self, status: int | None) -> str:
46
+ return ' (check the apiKey Grokky credential: an OpenRouter API key)' if status == 401 else ''