@databricks/appkit 0.47.1 → 0.49.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 (78) hide show
  1. package/CLAUDE.md +11 -1
  2. package/dist/agents/databricks.d.ts +24 -7
  3. package/dist/agents/databricks.d.ts.map +1 -1
  4. package/dist/agents/databricks.js +25 -0
  5. package/dist/agents/databricks.js.map +1 -1
  6. package/dist/agents/supervisor-api.d.ts +362 -0
  7. package/dist/agents/supervisor-api.d.ts.map +1 -0
  8. package/dist/agents/supervisor-api.js +498 -0
  9. package/dist/agents/supervisor-api.js.map +1 -0
  10. package/dist/appkit/package.js +1 -1
  11. package/dist/beta.d.ts +2 -1
  12. package/dist/beta.js +2 -1
  13. package/dist/cli/commands/lint.js +6 -0
  14. package/dist/cli/commands/lint.js.map +1 -1
  15. package/dist/connectors/serving/client.d.ts +24 -0
  16. package/dist/connectors/serving/client.d.ts.map +1 -0
  17. package/dist/connectors/serving/client.js +34 -14
  18. package/dist/connectors/serving/client.js.map +1 -1
  19. package/dist/core/agent/run-agent.d.ts.map +1 -1
  20. package/dist/core/agent/run-agent.js +51 -2
  21. package/dist/core/agent/run-agent.js.map +1 -1
  22. package/dist/core/agent/types.d.ts +19 -3
  23. package/dist/core/agent/types.d.ts.map +1 -1
  24. package/dist/core/agent/types.js.map +1 -1
  25. package/dist/core/appkit.d.ts.map +1 -1
  26. package/dist/core/appkit.js +39 -1
  27. package/dist/core/appkit.js.map +1 -1
  28. package/dist/index.js +2 -2
  29. package/dist/plugins/agents/agents.d.ts.map +1 -1
  30. package/dist/plugins/agents/agents.js +65 -5
  31. package/dist/plugins/agents/agents.js.map +1 -1
  32. package/dist/plugins/files/plugin.js +2 -2
  33. package/dist/plugins/jobs/plugin.js +2 -2
  34. package/dist/plugins/serving/serving.js +2 -2
  35. package/dist/plugins/ui-variants/choice-sink.js +70 -0
  36. package/dist/plugins/ui-variants/choice-sink.js.map +1 -0
  37. package/dist/plugins/ui-variants/index.js +94 -0
  38. package/dist/plugins/ui-variants/index.js.map +1 -0
  39. package/dist/plugins/ui-variants/manifest.js +17 -0
  40. package/dist/plugins/ui-variants/manifest.js.map +1 -0
  41. package/dist/registry/manifest-loader.d.ts +1 -1
  42. package/dist/schemas/manifest.d.ts +1 -0
  43. package/dist/schemas/manifest.d.ts.map +1 -1
  44. package/dist/schemas/manifest.js +1 -0
  45. package/dist/schemas/manifest.js.map +1 -1
  46. package/dist/shared/src/agent.d.ts +28 -0
  47. package/dist/shared/src/agent.d.ts.map +1 -1
  48. package/dist/shared/src/plugin.d.ts +3 -1
  49. package/dist/shared/src/plugin.d.ts.map +1 -1
  50. package/dist/shared/src/schemas/manifest.d.ts +3 -2
  51. package/dist/shared/src/schemas/manifest.d.ts.map +1 -1
  52. package/dist/stream/index.js +1 -0
  53. package/dist/stream/sse-reader.js +86 -0
  54. package/dist/stream/sse-reader.js.map +1 -0
  55. package/docs/api/appkit/Class.DatabricksAdapter.md +34 -0
  56. package/docs/api/appkit/Class.SupervisorApiAdapter.md +121 -0
  57. package/docs/api/appkit/Function.fromSupervisorApi.md +63 -0
  58. package/docs/api/appkit/Function.isSupervisorTool.md +18 -0
  59. package/docs/api/appkit/Interface.AgentAdapter.md +24 -0
  60. package/docs/api/appkit/Interface.AgentInput.md +13 -0
  61. package/docs/api/appkit/Interface.HostedSupervisorTool.md +21 -0
  62. package/docs/api/appkit/Interface.PluginManifest.md +27 -9
  63. package/docs/api/appkit/Interface.SupervisorApiAdapterOptions.md +38 -0
  64. package/docs/api/appkit/Interface.SupervisorExtension.md +12 -0
  65. package/docs/api/appkit/Interface.WorkspaceClientLike.md +67 -0
  66. package/docs/api/appkit/TypeAlias.AgentTool.md +3 -2
  67. package/docs/api/appkit/TypeAlias.ResolvedToolEntry.md +167 -0
  68. package/docs/api/appkit/TypeAlias.SupervisorTool.md +45 -0
  69. package/docs/api/appkit/Variable.SUPERVISOR_EXTENSION_KEY.md +8 -0
  70. package/docs/api/appkit/Variable.supervisorTools.md +176 -0
  71. package/docs/api/appkit.md +118 -108
  72. package/docs/plugins/agents.md +131 -1
  73. package/docs/plugins/manifest.md +12 -11
  74. package/llms.txt +11 -1
  75. package/package.json +2 -1
  76. package/sbom.cdx.json +1 -1
  77. package/scripts/postinstall.js +0 -1
  78. package/skills/appkit-ui-variants/SKILL.md +183 -0
@@ -0,0 +1,362 @@
1
+ import { AgentAdapter, AgentEvent, AgentInput, AgentRunContext } from "../shared/src/agent.js";
2
+ import "../shared/src/index.js";
3
+ import { ApiClientLike, StreamBody } from "../connectors/serving/client.js";
4
+
5
+ //#region src/agents/supervisor-api.d.ts
6
+ /**
7
+ * Structural shape of a Databricks SDK client used by {@link fromSupervisorApi}.
8
+ * Only what we need: `apiClient.request` for streaming and
9
+ * `config.ensureResolved` to materialise the host/credentials.
10
+ *
11
+ * Exported because {@link SupervisorApiAdapterOptions.workspaceClient} (a
12
+ * public type) references it — callers passing their own client can name
13
+ * the shape they need to satisfy.
14
+ */
15
+ interface WorkspaceClientLike extends ApiClientLike {
16
+ config: {
17
+ ensureResolved(): Promise<void>;
18
+ };
19
+ }
20
+ /**
21
+ * Tools supported by the Databricks AI Gateway Responses API. The shapes match
22
+ * the wire format the endpoint expects, so the adapter passes the array
23
+ * straight into the request body.
24
+ *
25
+ * This is an adapter-internal wire type. Application code authors tools via
26
+ * the {@link supervisorTools} factories, which return tagged
27
+ * {@link HostedSupervisorTool} records — the agents plugin then unwraps
28
+ * the `.spec` when routing through {@link AgentInput.extensions}.
29
+ */
30
+ type SupervisorTool = {
31
+ type: "genie_space";
32
+ genie_space: {
33
+ id: string;
34
+ description: string;
35
+ };
36
+ } | {
37
+ type: "uc_function";
38
+ uc_function: {
39
+ name: string;
40
+ description: string;
41
+ };
42
+ } | {
43
+ type: "knowledge_assistant";
44
+ knowledge_assistant: {
45
+ knowledge_assistant_id: string;
46
+ description: string;
47
+ };
48
+ } | {
49
+ type: "app";
50
+ app: {
51
+ name: string;
52
+ description: string;
53
+ };
54
+ } | {
55
+ type: "uc_connection";
56
+ uc_connection: {
57
+ name: string;
58
+ description: string;
59
+ };
60
+ };
61
+ /**
62
+ * Tagged record returned by every {@link supervisorTools} factory. The
63
+ * `__kind` discriminator lets the agents plugin (and standalone
64
+ * `runAgent`) classify these tools without a structural match against the
65
+ * wire format — keeps the SA wire shape free to evolve and avoids
66
+ * namespace collisions with MCP hosted tools (which use `type: "genie-space"`
67
+ * hyphenated, vs SA's `type: "genie_space"` underscored).
68
+ */
69
+ interface HostedSupervisorTool {
70
+ readonly __kind: "hosted-supervisor";
71
+ readonly spec: SupervisorTool;
72
+ }
73
+ /**
74
+ * Type guard for {@link HostedSupervisorTool}. Used by the agents plugin
75
+ * (`buildToolIndex`) and standalone `runAgent` (`classifyTool`) to route
76
+ * supervisor-hosted tools to the extensions payload rather than the
77
+ * adapter's `tools` array.
78
+ */
79
+ declare function isSupervisorTool(value: unknown): value is HostedSupervisorTool;
80
+ /**
81
+ * Concise factories for declaring Supervisor API tools.
82
+ *
83
+ * Each factory accepts a single named-options object: routing-critical
84
+ * strings (`id`, `name`, `description`) get labels at the call site so
85
+ * "we swapped the args and didn't notice for two weeks" bugs are
86
+ * impossible.
87
+ *
88
+ * `description` is required: SA's protobuf validation rejects `null`/`""`,
89
+ * AND the LLM running on SA reads this string to decide when to route to
90
+ * the tool. Two genie spaces both labelled "Genie space" give the model
91
+ * nothing to discriminate on, so callers always own the routing hint.
92
+ *
93
+ * ⚠ The `description` is read by the LLM at routing time — it is a
94
+ * prompt-injection sink. Do **not** derive it from untrusted input (user
95
+ * messages, request bodies, external systems). Treat it as application
96
+ * configuration. (CWE-1427)
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { createAgent } from "@databricks/appkit";
101
+ * import {
102
+ * agents,
103
+ * DatabricksAdapter,
104
+ * supervisorTools,
105
+ * } from "@databricks/appkit/beta";
106
+ *
107
+ * const assistant = createAgent({
108
+ * instructions: "You are a helpful assistant.",
109
+ * model: DatabricksAdapter.fromSupervisorApi({
110
+ * model: "databricks-claude-sonnet-4",
111
+ * }),
112
+ * tools: () => ({
113
+ * nyc: supervisorTools.genieSpace({
114
+ * id: "01ABCDEF12345678",
115
+ * description: "NYC taxi trip records and zones",
116
+ * }),
117
+ * add: supervisorTools.ucFunction({
118
+ * name: "main.default.add",
119
+ * description: "Adds two integers and returns the sum.",
120
+ * }),
121
+ * }),
122
+ * });
123
+ * ```
124
+ */
125
+ declare const supervisorTools: {
126
+ genieSpace: ({
127
+ id,
128
+ description
129
+ }: {
130
+ id: string;
131
+ description: string;
132
+ }) => HostedSupervisorTool;
133
+ ucFunction: ({
134
+ name,
135
+ description
136
+ }: {
137
+ name: string;
138
+ description: string;
139
+ }) => HostedSupervisorTool;
140
+ knowledgeAssistant: ({
141
+ knowledgeAssistantId,
142
+ description
143
+ }: {
144
+ knowledgeAssistantId: string;
145
+ description: string;
146
+ }) => HostedSupervisorTool;
147
+ app: ({
148
+ name,
149
+ description
150
+ }: {
151
+ name: string;
152
+ description: string;
153
+ }) => HostedSupervisorTool;
154
+ ucConnection: ({
155
+ name,
156
+ description
157
+ }: {
158
+ name: string;
159
+ description: string;
160
+ }) => HostedSupervisorTool;
161
+ };
162
+ /**
163
+ * Namespace key under which the adapter reads its hosted-tool payload
164
+ * from {@link AgentInput.extensions}. Exported so the agents plugin and
165
+ * standalone `runAgent` (the producers) can write under the same key the
166
+ * adapter reads.
167
+ */
168
+ declare const SUPERVISOR_EXTENSION_KEY: "databricks.supervisor";
169
+ /**
170
+ * Shape of the value at `AgentInput.extensions[SUPERVISOR_EXTENSION_KEY]`.
171
+ * The agents plugin / `runAgent` build this from the tool index; advanced
172
+ * callers invoking `adapter.run(...)` directly populate it themselves.
173
+ */
174
+ interface SupervisorExtension {
175
+ hostedTools?: SupervisorTool[];
176
+ }
177
+ interface SupervisorApiAdapterOptions {
178
+ /**
179
+ * Model identifier to pass in the request body
180
+ * (e.g. "databricks-claude-sonnet-4").
181
+ */
182
+ model: string;
183
+ /**
184
+ * A WorkspaceClient (or structural equivalent) used for host resolution
185
+ * and per-request authentication. When omitted, a `WorkspaceClient({})`
186
+ * is created internally using the default SDK credential chain
187
+ * (`DATABRICKS_HOST`, OAuth, PAT, etc.).
188
+ *
189
+ * ⚠ The `workspaceClient` is captured at construction and reused across
190
+ * every request. Passing a per-request OBO (On-Behalf-Of) client here
191
+ * would silently leak the first request's identity into all subsequent
192
+ * requests served by this adapter instance. Use the default credential
193
+ * chain or pass a service-principal client. (CWE-664)
194
+ */
195
+ workspaceClient?: WorkspaceClientLike;
196
+ /**
197
+ * Total wall-clock budget (ms) for a single `run()`. When the SSE stream
198
+ * runs longer than this — e.g. an upstream that stalls without closing —
199
+ * the adapter aborts it and emits a terminal `transport` error rather than
200
+ * hanging the request indefinitely.
201
+ *
202
+ * This is a total-duration cap, not an idle cap. Defaults to 5 minutes,
203
+ * generous enough for multi-tool server-side orchestration.
204
+ */
205
+ timeoutMs?: number;
206
+ }
207
+ interface SupervisorApiAdapterCtorOptions {
208
+ streamBody: StreamBody;
209
+ model: string;
210
+ timeoutMs?: number;
211
+ }
212
+ /**
213
+ * Adapter that calls the Databricks AI Gateway Responses API
214
+ * (`/ai-gateway/mlflow/v1/responses`).
215
+ *
216
+ * Streams SSE events in the OpenAI Responses API wire format and maps them
217
+ * to the AppKit `AgentEvent` protocol. Tool execution is handled
218
+ * server-side, so the adapter ignores the agents-plugin tool index.
219
+ *
220
+ * Authentication is handled via the Databricks SDK credential chain — the
221
+ * same mechanism used by `DatabricksAdapter.fromModelServing`. The transport
222
+ * is injected via {@link SupervisorApiAdapterCtorOptions.streamBody}; the
223
+ * {@link fromSupervisorApi} factory wires it through the SDK's
224
+ * `apiClient.request({ raw: true })`.
225
+ *
226
+ * Set `DEBUG=appkit:agents:supervisor-api` to log the outbound request
227
+ * shape (model, instructions length, input shape, tool count) and to be
228
+ * notified when the recovery path engages (no incremental deltas, text
229
+ * pulled from `response.completed.output[]`). The no-delta warning includes
230
+ * a per-turn event-type histogram and the SA-reported status/error/
231
+ * incomplete_details, so it's already actionable without DEBUG.
232
+ *
233
+ * Tools are not configured on the adapter. Declare them via
234
+ * `createAgent({ tools: () => ({ key: supervisorTools.genieSpace({...}) }) })`
235
+ * (or markdown frontmatter referencing an ambient `supervisorTools.*` entry);
236
+ * the agents plugin / standalone `runAgent` aggregates hosted-supervisor
237
+ * entries and routes them to the adapter via
238
+ * `AgentInput.extensions[SUPERVISOR_EXTENSION_KEY]`. Advanced callers
239
+ * invoking `adapter.run(...)` directly populate that key themselves.
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * import { createApp, createAgent } from "@databricks/appkit";
244
+ * import {
245
+ * agents,
246
+ * DatabricksAdapter,
247
+ * supervisorTools,
248
+ * } from "@databricks/appkit/beta";
249
+ *
250
+ * await createApp({
251
+ * plugins: [
252
+ * agents({
253
+ * agents: {
254
+ * assistant: createAgent({
255
+ * instructions: "You are a helpful assistant.",
256
+ * model: DatabricksAdapter.fromSupervisorApi({
257
+ * model: "databricks-claude-sonnet-4",
258
+ * }),
259
+ * tools: () => ({
260
+ * nyc: supervisorTools.genieSpace({
261
+ * id: "01ABCDEF12345678",
262
+ * description: "NYC taxi trip records and zones",
263
+ * }),
264
+ * }),
265
+ * }),
266
+ * },
267
+ * }),
268
+ * ],
269
+ * });
270
+ * ```
271
+ */
272
+ declare class SupervisorApiAdapter implements AgentAdapter {
273
+ private streamBody;
274
+ private model;
275
+ private timeoutMs;
276
+ /**
277
+ * Capability negotiation: the adapter reads its hosted-tool payload
278
+ * from {@link AgentInput.extensions} under {@link SUPERVISOR_EXTENSION_KEY}.
279
+ * The agents plugin uses this list to warn at registration when the tool
280
+ * index produces extensions the adapter wouldn't consume.
281
+ */
282
+ readonly acceptsExtensions: readonly ["databricks.supervisor"];
283
+ /**
284
+ * Capability negotiation: the adapter does not consume `input.tools`.
285
+ * Tool execution is owned by the Databricks AI Gateway server-side, so
286
+ * any function tools or local sub-agents declared on this agent would
287
+ * be silently dropped — the agents plugin warns at registration when
288
+ * that combination is detected.
289
+ */
290
+ readonly consumesInputTools = false;
291
+ constructor(options: SupervisorApiAdapterCtorOptions);
292
+ run(input: AgentInput, context: AgentRunContext): AsyncGenerator<AgentEvent, void, unknown>;
293
+ private streamResponse;
294
+ /**
295
+ * Splits the agent's message list into a Responses-API payload. System
296
+ * messages are concatenated (in order) into the top-level `instructions`
297
+ * field; user/assistant turns become `input` (as a plain string for the
298
+ * common single-user-turn case, otherwise as `{role,content}[]`). Tool-role
299
+ * messages are skipped — SA owns its own tool history server-side, so
300
+ * re-feeding our tool-result records would only confuse it.
301
+ */
302
+ private buildInput;
303
+ }
304
+ /**
305
+ * Creates an {@link AgentAdapter} backed by the Databricks AI Gateway
306
+ * Responses API (`/ai-gateway/mlflow/v1/responses`).
307
+ *
308
+ * Uses the SDK's default credential chain for auth (reads DATABRICKS_HOST,
309
+ * DATABRICKS_TOKEN, OAuth config, etc.). Tools are declared on the agent
310
+ * (via `createAgent({ tools })`), not on this factory.
311
+ *
312
+ * Application code should prefer the
313
+ * {@link DatabricksAdapter.fromSupervisorApi} static — it delegates here
314
+ * and keeps a single `DatabricksAdapter.from*` autocomplete root for all
315
+ * Databricks-backed adapters. This free function is the implementation
316
+ * behind the static and remains exported for callers that want to import
317
+ * it directly without pulling in {@link DatabricksAdapter}.
318
+ *
319
+ * @example
320
+ * ```ts
321
+ * import { createApp, createAgent } from "@databricks/appkit";
322
+ * import {
323
+ * agents,
324
+ * DatabricksAdapter,
325
+ * supervisorTools,
326
+ * } from "@databricks/appkit/beta";
327
+ *
328
+ * await createApp({
329
+ * plugins: [
330
+ * agents({
331
+ * agents: {
332
+ * assistant: createAgent({
333
+ * instructions: "You are a helpful assistant.",
334
+ * model: DatabricksAdapter.fromSupervisorApi({
335
+ * model: "databricks-claude-sonnet-4",
336
+ * }),
337
+ * tools: () => ({
338
+ * nyc: supervisorTools.genieSpace({
339
+ * id: "01ABCDEF12345678",
340
+ * description: "NYC taxi trip records and zones",
341
+ * }),
342
+ * }),
343
+ * }),
344
+ * },
345
+ * }),
346
+ * ],
347
+ * });
348
+ * ```
349
+ *
350
+ * @remarks
351
+ * ⚠ When passing your own `workspaceClient`, see the warning on
352
+ * {@link SupervisorApiAdapterOptions.workspaceClient} — the client is
353
+ * captured once and reused, so per-request OBO clients would leak
354
+ * identity across requests.
355
+ *
356
+ * @see {@link DatabricksAdapter.fromSupervisorApi} — the recommended
357
+ * application-facing entry point.
358
+ */
359
+ declare function fromSupervisorApi(options: SupervisorApiAdapterOptions): Promise<AgentAdapter>;
360
+ //#endregion
361
+ export { HostedSupervisorTool, SUPERVISOR_EXTENSION_KEY, SupervisorApiAdapter, SupervisorApiAdapterOptions, SupervisorExtension, SupervisorTool, WorkspaceClientLike, fromSupervisorApi, isSupervisorTool, supervisorTools };
362
+ //# sourceMappingURL=supervisor-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supervisor-api.d.ts","names":[],"sources":["../../src/agents/supervisor-api.ts"],"mappings":";;;;;;;;AAiGA;;;;;;UAAiB,mBAAA,SAA4B,aAAA;EAC3C,MAAA;IAAU,cAAA,IAAkB,OAAA;EAAA;AAAA;;;;;;;;;;;KAiBlB,cAAA;EACN,IAAA;EAAqB,WAAA;IAAe,EAAA;IAAY,WAAA;EAAA;AAAA;EAChD,IAAA;EAAqB,WAAA;IAAe,IAAA;IAAc,WAAA;EAAA;AAAA;EAElD,IAAA;EACA,mBAAA;IACE,sBAAA;IACA,WAAA;EAAA;AAAA;EAGF,IAAA;EAAa,GAAA;IAAO,IAAA;IAAc,WAAA;EAAA;AAAA;EAElC,IAAA;EACA,aAAA;IAAiB,IAAA;IAAc,WAAA;EAAA;AAAA;;;AA6ErC;;;;;;UAlEiB,oBAAA;EAAA,SACN,MAAA;EAAA,SACA,IAAA,EAAM,cAAA;AAAA;;;;;;;iBASD,gBAAA,CACd,KAAA,YACC,KAAA,IAAS,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqDC,eAAA;;;;;IAKT,EAAA;IACA,WAAA;EAAA,MACE,oBAAA;;;;;IAQF,IAAA;IACA,WAAA;EAAA,MACE,oBAAA;;;;;IAQF,oBAAA;IACA,WAAA;EAAA,MACE,oBAAA;;;;;IAcF,IAAA;IACA,WAAA;EAAA,MACE,oBAAA;;;;;IAQF,IAAA;IACA,WAAA;EAAA,MACE,oBAAA;AAAA;;;;;;;cAgBO,wBAAA;;AAyHb;;;;UAlHiB,mBAAA;EACf,WAAA,GAAc,cAAA;AAAA;AAAA,UAgBC,2BAAA;EAiG4B;;;;EA5F3C,KAAA;EA8FQ;;;;;;;;;;;;EAjFR,eAAA,GAAkB,mBAAA;EA8GA;;;;;AAgcpB;;;;EApiBE,SAAA;AAAA;AAAA,UAGQ,+BAAA;EACR,UAAA,EAAY,UAAA;EACZ,KAAA;EACA,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+DW,oBAAA,YAAgC,YAAA;EAAA,QACnC,UAAA;EAAA,QACA,KAAA;EAAA,QACA,SAAA;;;;;;;WAQC,iBAAA;;;;;;;;WASA,kBAAA;cAEG,OAAA,EAAS,+BAAA;EAMd,GAAA,CACL,KAAA,EAAO,UAAA,EACP,OAAA,EAAS,eAAA,GACR,cAAA,CAAe,UAAA;EAAA,QAiBH,cAAA;;;;;;;;;UA+NP,UAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgNY,iBAAA,CACpB,OAAA,EAAS,2BAAA,GACR,OAAA,CAAQ,YAAA"}