@databricks/appkit 0.31.0 → 0.32.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.md +1 -0
- package/NOTICE.md +1 -0
- package/dist/appkit/package.js +1 -1
- package/dist/beta.d.ts +14 -1
- package/dist/beta.js +12 -1
- package/dist/connectors/index.js +3 -0
- package/dist/connectors/mcp/client.d.ts +60 -0
- package/dist/connectors/mcp/client.d.ts.map +1 -0
- package/dist/connectors/mcp/client.js +197 -0
- package/dist/connectors/mcp/client.js.map +1 -0
- package/dist/connectors/mcp/host-policy.d.ts +51 -0
- package/dist/connectors/mcp/host-policy.d.ts.map +1 -0
- package/dist/connectors/mcp/host-policy.js +168 -0
- package/dist/connectors/mcp/host-policy.js.map +1 -0
- package/dist/connectors/mcp/index.d.ts +3 -0
- package/dist/connectors/mcp/index.js +4 -0
- package/dist/connectors/mcp/types.d.ts +16 -0
- package/dist/connectors/mcp/types.d.ts.map +1 -0
- package/dist/context/index.js +1 -1
- package/dist/core/agent/build-toolkit.d.ts +2 -0
- package/dist/core/agent/build-toolkit.js +50 -0
- package/dist/core/agent/build-toolkit.js.map +1 -0
- package/dist/core/agent/consume-adapter-stream.js +33 -0
- package/dist/core/agent/consume-adapter-stream.js.map +1 -0
- package/dist/core/agent/create-agent.d.ts +27 -0
- package/dist/core/agent/create-agent.d.ts.map +1 -0
- package/dist/core/agent/create-agent.js +50 -0
- package/dist/core/agent/create-agent.js.map +1 -0
- package/dist/core/agent/load-agents.d.ts +67 -0
- package/dist/core/agent/load-agents.d.ts.map +1 -0
- package/dist/core/agent/load-agents.js +228 -0
- package/dist/core/agent/load-agents.js.map +1 -0
- package/dist/core/agent/normalize-result.js +39 -0
- package/dist/core/agent/normalize-result.js.map +1 -0
- package/dist/core/agent/run-agent.d.ts +34 -0
- package/dist/core/agent/run-agent.d.ts.map +1 -0
- package/dist/core/agent/run-agent.js +146 -0
- package/dist/core/agent/run-agent.js.map +1 -0
- package/dist/core/agent/system-prompt.js +38 -0
- package/dist/core/agent/system-prompt.js.map +1 -0
- package/dist/core/agent/tools/define-tool.d.ts +54 -0
- package/dist/core/agent/tools/define-tool.d.ts.map +1 -0
- package/dist/core/agent/tools/define-tool.js +50 -0
- package/dist/core/agent/tools/define-tool.js.map +1 -0
- package/dist/core/agent/tools/function-tool.d.ts +27 -0
- package/dist/core/agent/tools/function-tool.d.ts.map +1 -0
- package/dist/core/agent/tools/function-tool.js +21 -0
- package/dist/core/agent/tools/function-tool.js.map +1 -0
- package/dist/core/agent/tools/hosted-tools.d.ts +47 -0
- package/dist/core/agent/tools/hosted-tools.d.ts.map +1 -0
- package/dist/core/agent/tools/hosted-tools.js +67 -0
- package/dist/core/agent/tools/hosted-tools.js.map +1 -0
- package/dist/core/agent/tools/index.d.ts +5 -0
- package/dist/core/agent/tools/index.js +7 -0
- package/dist/core/agent/tools/json-schema.js +24 -0
- package/dist/core/agent/tools/json-schema.js.map +1 -0
- package/dist/core/agent/tools/sql-policy.js +256 -0
- package/dist/core/agent/tools/sql-policy.js.map +1 -0
- package/dist/core/agent/tools/tool.d.ts +34 -0
- package/dist/core/agent/tools/tool.d.ts.map +1 -0
- package/dist/core/agent/tools/tool.js +41 -0
- package/dist/core/agent/tools/tool.js.map +1 -0
- package/dist/core/agent/types.d.ts +214 -0
- package/dist/core/agent/types.d.ts.map +1 -0
- package/dist/core/agent/types.js +12 -0
- package/dist/core/agent/types.js.map +1 -0
- package/dist/core/appkit.d.ts +1 -0
- package/dist/core/appkit.d.ts.map +1 -1
- package/dist/core/appkit.js +31 -4
- package/dist/core/appkit.js.map +1 -1
- package/dist/core/plugin-context.d.ts +133 -0
- package/dist/core/plugin-context.d.ts.map +1 -0
- package/dist/core/plugin-context.js +220 -0
- package/dist/core/plugin-context.js.map +1 -0
- package/dist/index.d.ts +11 -11
- package/dist/internal-telemetry/appkit-log.js +19 -0
- package/dist/internal-telemetry/appkit-log.js.map +1 -0
- package/dist/internal-telemetry/config.js +15 -0
- package/dist/internal-telemetry/config.js.map +1 -0
- package/dist/internal-telemetry/index.js +4 -0
- package/dist/internal-telemetry/reporter.js +132 -0
- package/dist/internal-telemetry/reporter.js.map +1 -0
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/plugin.d.ts +18 -3
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +26 -2
- package/dist/plugin/plugin.js.map +1 -1
- package/dist/plugin/to-plugin.d.ts +15 -4
- package/dist/plugin/to-plugin.d.ts.map +1 -1
- package/dist/plugin/to-plugin.js +14 -4
- package/dist/plugin/to-plugin.js.map +1 -1
- package/dist/plugins/agents/agents.d.ts +4 -0
- package/dist/plugins/agents/agents.js +882 -0
- package/dist/plugins/agents/agents.js.map +1 -0
- package/dist/plugins/agents/defaults.js +13 -0
- package/dist/plugins/agents/defaults.js.map +1 -0
- package/dist/plugins/agents/event-channel.js +64 -0
- package/dist/plugins/agents/event-channel.js.map +1 -0
- package/dist/plugins/agents/event-translator.js +224 -0
- package/dist/plugins/agents/event-translator.js.map +1 -0
- package/dist/plugins/agents/index.d.ts +4 -0
- package/dist/plugins/agents/index.js +6 -0
- package/dist/plugins/agents/manifest.js +27 -0
- package/dist/plugins/agents/manifest.js.map +1 -0
- package/dist/plugins/agents/schemas.js +51 -0
- package/dist/plugins/agents/schemas.js.map +1 -0
- package/dist/plugins/agents/thread-store.js +58 -0
- package/dist/plugins/agents/thread-store.js.map +1 -0
- package/dist/plugins/agents/tool-approval-gate.js +75 -0
- package/dist/plugins/agents/tool-approval-gate.js.map +1 -0
- package/dist/plugins/analytics/analytics.d.ts +17 -2
- package/dist/plugins/analytics/analytics.d.ts.map +1 -1
- package/dist/plugins/analytics/analytics.js +33 -0
- package/dist/plugins/analytics/analytics.js.map +1 -1
- package/dist/plugins/files/plugin.d.ts +22 -3
- package/dist/plugins/files/plugin.d.ts.map +1 -1
- package/dist/plugins/files/plugin.js +102 -2
- package/dist/plugins/files/plugin.js.map +1 -1
- package/dist/plugins/genie/genie.d.ts +15 -2
- package/dist/plugins/genie/genie.d.ts.map +1 -1
- package/dist/plugins/genie/genie.js +45 -0
- package/dist/plugins/genie/genie.js.map +1 -1
- package/dist/plugins/jobs/plugin.d.ts +2 -1
- package/dist/plugins/jobs/plugin.d.ts.map +1 -1
- package/dist/plugins/jobs/plugin.js +1 -1
- package/dist/plugins/lakebase/index.d.ts +2 -2
- package/dist/plugins/lakebase/index.js +1 -1
- package/dist/plugins/lakebase/lakebase.d.ts +33 -4
- package/dist/plugins/lakebase/lakebase.d.ts.map +1 -1
- package/dist/plugins/lakebase/lakebase.js +77 -5
- package/dist/plugins/lakebase/lakebase.js.map +1 -1
- package/dist/plugins/lakebase/types.d.ts +38 -1
- package/dist/plugins/lakebase/types.d.ts.map +1 -1
- package/dist/plugins/server/index.d.ts +12 -1
- package/dist/plugins/server/index.d.ts.map +1 -1
- package/dist/plugins/server/index.js +39 -5
- package/dist/plugins/server/index.js.map +1 -1
- package/dist/plugins/server/types.d.ts +0 -3
- package/dist/plugins/server/types.d.ts.map +1 -1
- package/dist/plugins/serving/serving.d.ts +2 -1
- package/dist/plugins/serving/serving.d.ts.map +1 -1
- package/dist/shared/src/agent.d.ts +63 -1
- package/dist/shared/src/agent.d.ts.map +1 -1
- package/dist/shared/src/index.d.ts +1 -1
- package/dist/shared/src/plugin.d.ts +8 -0
- package/dist/shared/src/plugin.d.ts.map +1 -1
- package/docs/api/appkit/Class.Plugin.md +65 -23
- package/docs/api/appkit/Function.createApp.md +10 -8
- package/docs/privacy.md +41 -0
- package/llms.txt +1 -0
- package/package.json +4 -2
- package/sbom.cdx.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AgentEvent, Message } from "../../shared/src/agent.js";
|
|
2
|
+
import "../../shared/src/index.js";
|
|
3
|
+
import { AgentDefinition } from "./types.js";
|
|
4
|
+
|
|
5
|
+
//#region src/core/agent/run-agent.d.ts
|
|
6
|
+
interface RunAgentInput {
|
|
7
|
+
/** Seed messages for the run. Either a single user string or a full message list. */
|
|
8
|
+
messages: string | Message[];
|
|
9
|
+
/** Abort signal for cancellation. */
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
interface RunAgentResult {
|
|
13
|
+
/** Aggregated text output from all `message_delta` events. */
|
|
14
|
+
text: string;
|
|
15
|
+
/** Every event the adapter yielded, in order. Useful for inspection/tests. */
|
|
16
|
+
events: AgentEvent[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Standalone agent execution without `createApp`. Resolves the adapter, binds
|
|
20
|
+
* inline tools, and drives the adapter's `run()` loop to completion.
|
|
21
|
+
*
|
|
22
|
+
* Limitations vs. running through the agents() plugin:
|
|
23
|
+
* - No OBO: there is no HTTP request, so plugin tools run as the service
|
|
24
|
+
* principal (when they work at all).
|
|
25
|
+
* - Plugin tools (`ToolkitEntry`) are not supported — they require a live
|
|
26
|
+
* `PluginContext` that only exists when registered in a `createApp`
|
|
27
|
+
* instance. This function throws a clear error if encountered.
|
|
28
|
+
* - Sub-agents (`agents: { ... }` on the def) are executed as nested
|
|
29
|
+
* `runAgent` calls with no shared thread state.
|
|
30
|
+
*/
|
|
31
|
+
declare function runAgent(def: AgentDefinition, input: RunAgentInput): Promise<RunAgentResult>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { RunAgentInput, RunAgentResult, runAgent };
|
|
34
|
+
//# sourceMappingURL=run-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-agent.d.ts","names":[],"sources":["../../../src/core/agent/run-agent.ts"],"mappings":";;;;;UAiBiB,aAAA;;EAEf,QAAA,WAAmB,OAAA;EAFJ;EAIf,MAAA,GAAS,WAAA;AAAA;AAAA,UAGM,cAAA;EALf;EAOA,IAAA;EALA;EAOA,MAAA,EAAQ,UAAA;AAAA;;AAJV;;;;;;;;;AAoBA;;;iBAAsB,QAAA,CACpB,GAAA,EAAK,eAAA,EACL,KAAA,EAAO,aAAA,GACN,OAAA,CAAQ,cAAA"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { consumeAdapterStream } from "./consume-adapter-stream.js";
|
|
2
|
+
import { functionToolToDefinition, isFunctionTool } from "./tools/function-tool.js";
|
|
3
|
+
import { isHostedTool } from "./tools/hosted-tools.js";
|
|
4
|
+
import { isToolkitEntry } from "./types.js";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
//#region src/core/agent/run-agent.ts
|
|
8
|
+
/**
|
|
9
|
+
* Standalone agent execution without `createApp`. Resolves the adapter, binds
|
|
10
|
+
* inline tools, and drives the adapter's `run()` loop to completion.
|
|
11
|
+
*
|
|
12
|
+
* Limitations vs. running through the agents() plugin:
|
|
13
|
+
* - No OBO: there is no HTTP request, so plugin tools run as the service
|
|
14
|
+
* principal (when they work at all).
|
|
15
|
+
* - Plugin tools (`ToolkitEntry`) are not supported — they require a live
|
|
16
|
+
* `PluginContext` that only exists when registered in a `createApp`
|
|
17
|
+
* instance. This function throws a clear error if encountered.
|
|
18
|
+
* - Sub-agents (`agents: { ... }` on the def) are executed as nested
|
|
19
|
+
* `runAgent` calls with no shared thread state.
|
|
20
|
+
*/
|
|
21
|
+
async function runAgent(def, input) {
|
|
22
|
+
const adapter = await resolveAdapter(def);
|
|
23
|
+
const messages = normalizeMessages(input.messages, def.instructions);
|
|
24
|
+
const toolIndex = buildStandaloneToolIndex(def);
|
|
25
|
+
const tools = Array.from(toolIndex.values()).map((e) => e.def);
|
|
26
|
+
const signal = input.signal;
|
|
27
|
+
const executeTool = async (name, args) => {
|
|
28
|
+
const entry = toolIndex.get(name);
|
|
29
|
+
if (!entry) throw new Error(`Unknown tool: ${name}`);
|
|
30
|
+
if (entry.kind === "function") return entry.tool.execute(args);
|
|
31
|
+
if (entry.kind === "subagent") {
|
|
32
|
+
const subInput = {
|
|
33
|
+
messages: typeof args === "object" && args !== null && typeof args.input === "string" ? args.input : JSON.stringify(args),
|
|
34
|
+
signal
|
|
35
|
+
};
|
|
36
|
+
return (await runAgent(entry.agentDef, subInput)).text;
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`runAgent: tool "${name}" is a ${entry.kind} tool. Plugin toolkits and MCP tools are only usable via createApp({ plugins: [..., agents(...)] }).`);
|
|
39
|
+
};
|
|
40
|
+
const events = [];
|
|
41
|
+
return {
|
|
42
|
+
text: await consumeAdapterStream(adapter.run({
|
|
43
|
+
messages,
|
|
44
|
+
tools,
|
|
45
|
+
threadId: randomUUID(),
|
|
46
|
+
signal
|
|
47
|
+
}, {
|
|
48
|
+
executeTool,
|
|
49
|
+
signal
|
|
50
|
+
}), {
|
|
51
|
+
signal,
|
|
52
|
+
onEvent: (event) => {
|
|
53
|
+
events.push(event);
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
events
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function resolveAdapter(def) {
|
|
60
|
+
const { model } = def;
|
|
61
|
+
if (!model) {
|
|
62
|
+
const { DatabricksAdapter } = await import("../../agents/databricks.js");
|
|
63
|
+
return DatabricksAdapter.fromModelServing();
|
|
64
|
+
}
|
|
65
|
+
if (typeof model === "string") {
|
|
66
|
+
const { DatabricksAdapter } = await import("../../agents/databricks.js");
|
|
67
|
+
return DatabricksAdapter.fromModelServing(model);
|
|
68
|
+
}
|
|
69
|
+
return await model;
|
|
70
|
+
}
|
|
71
|
+
function normalizeMessages(input, instructions) {
|
|
72
|
+
const systemMessage = {
|
|
73
|
+
id: "system",
|
|
74
|
+
role: "system",
|
|
75
|
+
content: instructions,
|
|
76
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
77
|
+
};
|
|
78
|
+
if (typeof input === "string") return [systemMessage, {
|
|
79
|
+
id: randomUUID(),
|
|
80
|
+
role: "user",
|
|
81
|
+
content: input,
|
|
82
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
83
|
+
}];
|
|
84
|
+
return [systemMessage, ...input];
|
|
85
|
+
}
|
|
86
|
+
function buildStandaloneToolIndex(def) {
|
|
87
|
+
const index = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const [key, tool] of Object.entries(def.tools ?? {})) index.set(key, classifyTool(key, tool));
|
|
89
|
+
for (const [childKey, child] of Object.entries(def.agents ?? {})) {
|
|
90
|
+
const toolName = `agent-${childKey}`;
|
|
91
|
+
index.set(toolName, {
|
|
92
|
+
kind: "subagent",
|
|
93
|
+
agentDef: {
|
|
94
|
+
...child,
|
|
95
|
+
name: child.name ?? childKey
|
|
96
|
+
},
|
|
97
|
+
def: {
|
|
98
|
+
name: toolName,
|
|
99
|
+
description: child.instructions.slice(0, 120) || `Delegate to the ${childKey} sub-agent`,
|
|
100
|
+
parameters: {
|
|
101
|
+
type: "object",
|
|
102
|
+
properties: { input: {
|
|
103
|
+
type: "string",
|
|
104
|
+
description: "Message to send to the sub-agent."
|
|
105
|
+
} },
|
|
106
|
+
required: ["input"]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return index;
|
|
112
|
+
}
|
|
113
|
+
function classifyTool(key, tool) {
|
|
114
|
+
if (isToolkitEntry(tool)) return {
|
|
115
|
+
kind: "toolkit",
|
|
116
|
+
def: {
|
|
117
|
+
...tool.def,
|
|
118
|
+
name: key
|
|
119
|
+
},
|
|
120
|
+
entry: tool
|
|
121
|
+
};
|
|
122
|
+
if (isFunctionTool(tool)) return {
|
|
123
|
+
kind: "function",
|
|
124
|
+
tool,
|
|
125
|
+
def: {
|
|
126
|
+
...functionToolToDefinition(tool),
|
|
127
|
+
name: key
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
if (isHostedTool(tool)) return {
|
|
131
|
+
kind: "hosted",
|
|
132
|
+
def: {
|
|
133
|
+
name: key,
|
|
134
|
+
description: `Hosted tool: ${tool.type}`,
|
|
135
|
+
parameters: {
|
|
136
|
+
type: "object",
|
|
137
|
+
properties: {}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
throw new Error(`runAgent: unrecognized tool shape at key "${key}"`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
export { runAgent };
|
|
146
|
+
//# sourceMappingURL=run-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-agent.js","names":[],"sources":["../../../src/core/agent/run-agent.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type {\n AgentAdapter,\n AgentEvent,\n AgentToolDefinition,\n Message,\n} from \"shared\";\nimport { consumeAdapterStream } from \"./consume-adapter-stream\";\nimport {\n type FunctionTool,\n functionToolToDefinition,\n isFunctionTool,\n} from \"./tools/function-tool\";\nimport { isHostedTool } from \"./tools/hosted-tools\";\nimport type { AgentDefinition, AgentTool, ToolkitEntry } from \"./types\";\nimport { isToolkitEntry } from \"./types\";\n\nexport interface RunAgentInput {\n /** Seed messages for the run. Either a single user string or a full message list. */\n messages: string | Message[];\n /** Abort signal for cancellation. */\n signal?: AbortSignal;\n}\n\nexport interface RunAgentResult {\n /** Aggregated text output from all `message_delta` events. */\n text: string;\n /** Every event the adapter yielded, in order. Useful for inspection/tests. */\n events: AgentEvent[];\n}\n\n/**\n * Standalone agent execution without `createApp`. Resolves the adapter, binds\n * inline tools, and drives the adapter's `run()` loop to completion.\n *\n * Limitations vs. running through the agents() plugin:\n * - No OBO: there is no HTTP request, so plugin tools run as the service\n * principal (when they work at all).\n * - Plugin tools (`ToolkitEntry`) are not supported — they require a live\n * `PluginContext` that only exists when registered in a `createApp`\n * instance. This function throws a clear error if encountered.\n * - Sub-agents (`agents: { ... }` on the def) are executed as nested\n * `runAgent` calls with no shared thread state.\n */\nexport async function runAgent(\n def: AgentDefinition,\n input: RunAgentInput,\n): Promise<RunAgentResult> {\n const adapter = await resolveAdapter(def);\n const messages = normalizeMessages(input.messages, def.instructions);\n const toolIndex = buildStandaloneToolIndex(def);\n const tools = Array.from(toolIndex.values()).map((e) => e.def);\n\n const signal = input.signal;\n\n const executeTool = async (name: string, args: unknown): Promise<unknown> => {\n const entry = toolIndex.get(name);\n if (!entry) throw new Error(`Unknown tool: ${name}`);\n if (entry.kind === \"function\") {\n return entry.tool.execute(args as Record<string, unknown>);\n }\n if (entry.kind === \"subagent\") {\n const subInput: RunAgentInput = {\n messages:\n typeof args === \"object\" &&\n args !== null &&\n typeof (args as { input?: unknown }).input === \"string\"\n ? (args as { input: string }).input\n : JSON.stringify(args),\n signal,\n };\n const res = await runAgent(entry.agentDef, subInput);\n return res.text;\n }\n throw new Error(\n `runAgent: tool \"${name}\" is a ${entry.kind} tool. ` +\n \"Plugin toolkits and MCP tools are only usable via createApp({ plugins: [..., agents(...)] }).\",\n );\n };\n\n const events: AgentEvent[] = [];\n\n const stream = adapter.run(\n {\n messages,\n tools,\n threadId: randomUUID(),\n signal,\n },\n { executeTool, signal },\n );\n\n // Shared accumulation rule (deltas append, `message` replaces). The\n // `events` array is filled via the `onEvent` side effect so callers that\n // inspect the raw stream still get the full record.\n const text = await consumeAdapterStream(stream, {\n signal,\n onEvent: (event) => {\n events.push(event);\n },\n });\n\n return { text, events };\n}\n\nasync function resolveAdapter(def: AgentDefinition): Promise<AgentAdapter> {\n const { model } = def;\n if (!model) {\n const { DatabricksAdapter } = await import(\"../../agents/databricks\");\n return DatabricksAdapter.fromModelServing();\n }\n if (typeof model === \"string\") {\n const { DatabricksAdapter } = await import(\"../../agents/databricks\");\n return DatabricksAdapter.fromModelServing(model);\n }\n return await model;\n}\n\nfunction normalizeMessages(\n input: string | Message[],\n instructions: string,\n): Message[] {\n const systemMessage: Message = {\n id: \"system\",\n role: \"system\",\n content: instructions,\n createdAt: new Date(),\n };\n if (typeof input === \"string\") {\n return [\n systemMessage,\n {\n id: randomUUID(),\n role: \"user\",\n content: input,\n createdAt: new Date(),\n },\n ];\n }\n return [systemMessage, ...input];\n}\n\ntype StandaloneEntry =\n | {\n kind: \"function\";\n def: AgentToolDefinition;\n tool: FunctionTool;\n }\n | {\n kind: \"subagent\";\n def: AgentToolDefinition;\n agentDef: AgentDefinition;\n }\n | {\n kind: \"toolkit\";\n def: AgentToolDefinition;\n entry: ToolkitEntry;\n }\n | {\n kind: \"hosted\";\n def: AgentToolDefinition;\n };\n\nfunction buildStandaloneToolIndex(\n def: AgentDefinition,\n): Map<string, StandaloneEntry> {\n const index = new Map<string, StandaloneEntry>();\n\n for (const [key, tool] of Object.entries(def.tools ?? {})) {\n index.set(key, classifyTool(key, tool));\n }\n\n for (const [childKey, child] of Object.entries(def.agents ?? {})) {\n const toolName = `agent-${childKey}`;\n index.set(toolName, {\n kind: \"subagent\",\n agentDef: { ...child, name: child.name ?? childKey },\n def: {\n name: toolName,\n description:\n child.instructions.slice(0, 120) ||\n `Delegate to the ${childKey} sub-agent`,\n parameters: {\n type: \"object\",\n properties: {\n input: {\n type: \"string\",\n description: \"Message to send to the sub-agent.\",\n },\n },\n required: [\"input\"],\n },\n },\n });\n }\n\n return index;\n}\n\nfunction classifyTool(key: string, tool: AgentTool): StandaloneEntry {\n if (isToolkitEntry(tool)) {\n return { kind: \"toolkit\", def: { ...tool.def, name: key }, entry: tool };\n }\n if (isFunctionTool(tool)) {\n return {\n kind: \"function\",\n tool,\n def: { ...functionToolToDefinition(tool), name: key },\n };\n }\n if (isHostedTool(tool)) {\n return {\n kind: \"hosted\",\n def: {\n name: key,\n description: `Hosted tool: ${tool.type}`,\n parameters: { type: \"object\", properties: {} },\n },\n };\n }\n throw new Error(`runAgent: unrecognized tool shape at key \"${key}\"`);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/core/agent/system-prompt.ts
|
|
2
|
+
/**
|
|
3
|
+
* Default base system prompt: product identity, active AppKit plugins, and
|
|
4
|
+
* tool-agnostic behavior hints.
|
|
5
|
+
*
|
|
6
|
+
* Individual tool definitions and JSON Schemas are still sent through the
|
|
7
|
+
* model's `tools` / function-calling channel — this string is not a second
|
|
8
|
+
* copy of that list. `ctx.toolNames` is available for custom
|
|
9
|
+
* `baseSystemPrompt` callbacks; the default text stays short and does not
|
|
10
|
+
* enumerate tools to avoid drift and token bloat.
|
|
11
|
+
*/
|
|
12
|
+
function buildBaseSystemPrompt(ctx) {
|
|
13
|
+
const { pluginNames } = ctx;
|
|
14
|
+
const lines = ["You are an AI assistant running on Databricks AppKit."];
|
|
15
|
+
if (pluginNames.length > 0) {
|
|
16
|
+
lines.push("");
|
|
17
|
+
lines.push(`Active AppKit plugins: ${pluginNames.join(", ")}`);
|
|
18
|
+
}
|
|
19
|
+
lines.push("");
|
|
20
|
+
lines.push("Guidelines:");
|
|
21
|
+
lines.push("- Be concise: for large or noisy tool output, summarize what matters and how to go deeper instead of pasting everything.");
|
|
22
|
+
lines.push("- Use each tool as defined: pass required arguments and use the syntax, dialect, or path rules the target system expects (see each tool’s description and schema).");
|
|
23
|
+
lines.push("- If a tool call fails, explain the error in plain language and suggest a fix or next step.");
|
|
24
|
+
lines.push("- Respect tool metadata and app policy: read-only vs destructive tools, user/identity context, and any approval or safety flows the app provides.");
|
|
25
|
+
return lines.join("\n");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compose the full system prompt from the base prompt and an optional
|
|
29
|
+
* per-agent user prompt.
|
|
30
|
+
*/
|
|
31
|
+
function composeSystemPrompt(basePrompt, agentPrompt) {
|
|
32
|
+
if (!agentPrompt) return basePrompt;
|
|
33
|
+
return `${basePrompt}\n\n${agentPrompt}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { buildBaseSystemPrompt, composeSystemPrompt };
|
|
38
|
+
//# sourceMappingURL=system-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-prompt.js","names":[],"sources":["../../../src/core/agent/system-prompt.ts"],"sourcesContent":["import type { PromptContext } from \"./types\";\n\n/**\n * Default base system prompt: product identity, active AppKit plugins, and\n * tool-agnostic behavior hints.\n *\n * Individual tool definitions and JSON Schemas are still sent through the\n * model's `tools` / function-calling channel — this string is not a second\n * copy of that list. `ctx.toolNames` is available for custom\n * `baseSystemPrompt` callbacks; the default text stays short and does not\n * enumerate tools to avoid drift and token bloat.\n */\nexport function buildBaseSystemPrompt(ctx: PromptContext): string {\n const { pluginNames } = ctx;\n const lines: string[] = [\n \"You are an AI assistant running on Databricks AppKit.\",\n ];\n\n if (pluginNames.length > 0) {\n lines.push(\"\");\n lines.push(`Active AppKit plugins: ${pluginNames.join(\", \")}`);\n }\n\n lines.push(\"\");\n lines.push(\"Guidelines:\");\n lines.push(\n \"- Be concise: for large or noisy tool output, summarize what matters and how to go deeper instead of pasting everything.\",\n );\n lines.push(\n \"- Use each tool as defined: pass required arguments and use the syntax, dialect, or path rules the target system expects (see each tool’s description and schema).\",\n );\n lines.push(\n \"- If a tool call fails, explain the error in plain language and suggest a fix or next step.\",\n );\n lines.push(\n \"- Respect tool metadata and app policy: read-only vs destructive tools, user/identity context, and any approval or safety flows the app provides.\",\n );\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Compose the full system prompt from the base prompt and an optional\n * per-agent user prompt.\n */\nexport function composeSystemPrompt(\n basePrompt: string,\n agentPrompt?: string,\n): string {\n if (!agentPrompt) return basePrompt;\n return `${basePrompt}\\n\\n${agentPrompt}`;\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,sBAAsB,KAA4B;CAChE,MAAM,EAAE,gBAAgB;CACxB,MAAM,QAAkB,CACtB,wDACD;AAED,KAAI,YAAY,SAAS,GAAG;AAC1B,QAAM,KAAK,GAAG;AACd,QAAM,KAAK,0BAA0B,YAAY,KAAK,KAAK,GAAG;;AAGhE,OAAM,KAAK,GAAG;AACd,OAAM,KAAK,cAAc;AACzB,OAAM,KACJ,2HACD;AACD,OAAM,KACJ,qKACD;AACD,OAAM,KACJ,8FACD;AACD,OAAM,KACJ,oJACD;AAED,QAAO,MAAM,KAAK,KAAK;;;;;;AAOzB,SAAgB,oBACd,YACA,aACQ;AACR,KAAI,CAAC,YAAa,QAAO;AACzB,QAAO,GAAG,WAAW,MAAM"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AgentToolDefinition, ToolAnnotations } from "../../../shared/src/agent.js";
|
|
2
|
+
import "../../../shared/src/index.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/core/agent/tools/define-tool.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Single-tool entry for a plugin's internal tool registry.
|
|
8
|
+
*
|
|
9
|
+
* Plugins collect these into a `Record<string, ToolEntry>` keyed by the tool's
|
|
10
|
+
* public name and dispatch via `executeFromRegistry`.
|
|
11
|
+
*/
|
|
12
|
+
interface ToolEntry<S extends z.ZodType = z.ZodType> {
|
|
13
|
+
description: string;
|
|
14
|
+
schema: S;
|
|
15
|
+
annotations?: ToolAnnotations;
|
|
16
|
+
/**
|
|
17
|
+
* Whether this tool is eligible for auto-inheritance into markdown or
|
|
18
|
+
* code-defined agents that enable `autoInheritTools`. Defaults to `false`
|
|
19
|
+
* (safe-by-default) — plugin authors must explicitly opt a tool in if they
|
|
20
|
+
* consider it safe enough to appear in every agent's tool record without an
|
|
21
|
+
* explicit `tools:` declaration. Destructive or privilege-sensitive tools
|
|
22
|
+
* should leave this unset so that they only reach agents that wire them
|
|
23
|
+
* explicitly (via `tools:`, `toolkits:`, or `fromPlugin({ only: [...] })`).
|
|
24
|
+
*/
|
|
25
|
+
autoInheritable?: boolean;
|
|
26
|
+
handler: (args: z.infer<S>, signal?: AbortSignal) => unknown | Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
type ToolRegistry = Record<string, ToolEntry>;
|
|
29
|
+
/**
|
|
30
|
+
* Defines a single tool entry for a plugin's internal registry.
|
|
31
|
+
*
|
|
32
|
+
* The generic `S` flows from `schema` through to the `handler` callback so
|
|
33
|
+
* `args` is fully typed from the Zod schema. Names are assigned by the
|
|
34
|
+
* registry key, so they are not repeated inside the entry.
|
|
35
|
+
*/
|
|
36
|
+
declare function defineTool<S extends z.ZodType>(config: ToolEntry<S>): ToolEntry<S>;
|
|
37
|
+
/**
|
|
38
|
+
* Validates tool-call arguments against the entry's schema and invokes its
|
|
39
|
+
* handler. On validation failure, returns an LLM-friendly error string
|
|
40
|
+
* (matching the behavior of `tool()`) rather than throwing, so the model
|
|
41
|
+
* can self-correct on its next turn.
|
|
42
|
+
*/
|
|
43
|
+
declare function executeFromRegistry(registry: ToolRegistry, name: string, args: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Produces the `AgentToolDefinition[]` a ToolProvider exposes to the LLM,
|
|
46
|
+
* deriving `parameters` JSON Schema from each entry's Zod schema.
|
|
47
|
+
*
|
|
48
|
+
* Tool names come from registry keys (supports dotted names like
|
|
49
|
+
* `uploads.list` for dynamic plugins).
|
|
50
|
+
*/
|
|
51
|
+
declare function toolsFromRegistry(registry: ToolRegistry): AgentToolDefinition[];
|
|
52
|
+
//#endregion
|
|
53
|
+
export { ToolEntry, ToolRegistry, defineTool, executeFromRegistry, toolsFromRegistry };
|
|
54
|
+
//# sourceMappingURL=define-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-tool.d.ts","names":[],"sources":["../../../../src/core/agent/tools/define-tool.ts"],"mappings":";;;;;;;;AAWA;;;UAAiB,SAAA,WAAoB,CAAA,CAAE,OAAA,GAAU,CAAA,CAAE,OAAA;EACjD,WAAA;EACA,MAAA,EAAQ,CAAA;EACR,WAAA,GAAc,eAAA;EAYE;;;;;;;;;EAFhB,eAAA;EACA,OAAA,GACE,IAAA,EAAM,CAAA,CAAE,KAAA,CAAM,CAAA,GACd,MAAA,GAAS,WAAA,eACI,OAAA;AAAA;AAAA,KAGL,YAAA,GAAe,MAAA,SAAe,SAAA;;;;;;;;iBAS1B,UAAA,WAAqB,CAAA,CAAE,OAAA,CAAA,CACrC,MAAA,EAAQ,SAAA,CAAU,CAAA,IACjB,SAAA,CAAU,CAAA;;;;;;;iBAUS,mBAAA,CACpB,QAAA,EAAU,YAAA,EACV,IAAA,UACA,IAAA,WACA,MAAA,GAAS,WAAA,GACR,OAAA;;;;;AAjBH;;;iBAoCgB,iBAAA,CACd,QAAA,EAAU,YAAA,GACT,mBAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { toToolJSONSchema } from "./json-schema.js";
|
|
2
|
+
import { formatZodError } from "./tool.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/agent/tools/define-tool.ts
|
|
5
|
+
/**
|
|
6
|
+
* Defines a single tool entry for a plugin's internal registry.
|
|
7
|
+
*
|
|
8
|
+
* The generic `S` flows from `schema` through to the `handler` callback so
|
|
9
|
+
* `args` is fully typed from the Zod schema. Names are assigned by the
|
|
10
|
+
* registry key, so they are not repeated inside the entry.
|
|
11
|
+
*/
|
|
12
|
+
function defineTool(config) {
|
|
13
|
+
return config;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates tool-call arguments against the entry's schema and invokes its
|
|
17
|
+
* handler. On validation failure, returns an LLM-friendly error string
|
|
18
|
+
* (matching the behavior of `tool()`) rather than throwing, so the model
|
|
19
|
+
* can self-correct on its next turn.
|
|
20
|
+
*/
|
|
21
|
+
async function executeFromRegistry(registry, name, args, signal) {
|
|
22
|
+
const entry = registry[name];
|
|
23
|
+
if (!entry) throw new Error(`Unknown tool: ${name}`);
|
|
24
|
+
const parsed = entry.schema.safeParse(args);
|
|
25
|
+
if (!parsed.success) return formatZodError(parsed.error, name);
|
|
26
|
+
return entry.handler(parsed.data, signal);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Produces the `AgentToolDefinition[]` a ToolProvider exposes to the LLM,
|
|
30
|
+
* deriving `parameters` JSON Schema from each entry's Zod schema.
|
|
31
|
+
*
|
|
32
|
+
* Tool names come from registry keys (supports dotted names like
|
|
33
|
+
* `uploads.list` for dynamic plugins).
|
|
34
|
+
*/
|
|
35
|
+
function toolsFromRegistry(registry) {
|
|
36
|
+
return Object.entries(registry).map(([name, entry]) => {
|
|
37
|
+
const parameters = toToolJSONSchema(entry.schema);
|
|
38
|
+
const def = {
|
|
39
|
+
name,
|
|
40
|
+
description: entry.description,
|
|
41
|
+
parameters
|
|
42
|
+
};
|
|
43
|
+
if (entry.annotations) def.annotations = entry.annotations;
|
|
44
|
+
return def;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { defineTool, executeFromRegistry, toolsFromRegistry };
|
|
50
|
+
//# sourceMappingURL=define-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-tool.js","names":[],"sources":["../../../../src/core/agent/tools/define-tool.ts"],"sourcesContent":["import type { AgentToolDefinition, ToolAnnotations } from \"shared\";\nimport type { z } from \"zod\";\nimport { toToolJSONSchema } from \"./json-schema\";\nimport { formatZodError } from \"./tool\";\n\n/**\n * Single-tool entry for a plugin's internal tool registry.\n *\n * Plugins collect these into a `Record<string, ToolEntry>` keyed by the tool's\n * public name and dispatch via `executeFromRegistry`.\n */\nexport interface ToolEntry<S extends z.ZodType = z.ZodType> {\n description: string;\n schema: S;\n annotations?: ToolAnnotations;\n /**\n * Whether this tool is eligible for auto-inheritance into markdown or\n * code-defined agents that enable `autoInheritTools`. Defaults to `false`\n * (safe-by-default) — plugin authors must explicitly opt a tool in if they\n * consider it safe enough to appear in every agent's tool record without an\n * explicit `tools:` declaration. Destructive or privilege-sensitive tools\n * should leave this unset so that they only reach agents that wire them\n * explicitly (via `tools:`, `toolkits:`, or `fromPlugin({ only: [...] })`).\n */\n autoInheritable?: boolean;\n handler: (\n args: z.infer<S>,\n signal?: AbortSignal,\n ) => unknown | Promise<unknown>;\n}\n\nexport type ToolRegistry = Record<string, ToolEntry>;\n\n/**\n * Defines a single tool entry for a plugin's internal registry.\n *\n * The generic `S` flows from `schema` through to the `handler` callback so\n * `args` is fully typed from the Zod schema. Names are assigned by the\n * registry key, so they are not repeated inside the entry.\n */\nexport function defineTool<S extends z.ZodType>(\n config: ToolEntry<S>,\n): ToolEntry<S> {\n return config;\n}\n\n/**\n * Validates tool-call arguments against the entry's schema and invokes its\n * handler. On validation failure, returns an LLM-friendly error string\n * (matching the behavior of `tool()`) rather than throwing, so the model\n * can self-correct on its next turn.\n */\nexport async function executeFromRegistry(\n registry: ToolRegistry,\n name: string,\n args: unknown,\n signal?: AbortSignal,\n): Promise<unknown> {\n const entry = registry[name];\n if (!entry) {\n throw new Error(`Unknown tool: ${name}`);\n }\n const parsed = entry.schema.safeParse(args);\n if (!parsed.success) {\n return formatZodError(parsed.error, name);\n }\n return entry.handler(parsed.data, signal);\n}\n\n/**\n * Produces the `AgentToolDefinition[]` a ToolProvider exposes to the LLM,\n * deriving `parameters` JSON Schema from each entry's Zod schema.\n *\n * Tool names come from registry keys (supports dotted names like\n * `uploads.list` for dynamic plugins).\n */\nexport function toolsFromRegistry(\n registry: ToolRegistry,\n): AgentToolDefinition[] {\n return Object.entries(registry).map(([name, entry]) => {\n const parameters = toToolJSONSchema(\n entry.schema,\n ) as unknown as AgentToolDefinition[\"parameters\"];\n const def: AgentToolDefinition = {\n name,\n description: entry.description,\n parameters,\n };\n if (entry.annotations) {\n def.annotations = entry.annotations;\n }\n return def;\n });\n}\n"],"mappings":";;;;;;;;;;;AAwCA,SAAgB,WACd,QACc;AACd,QAAO;;;;;;;;AAST,eAAsB,oBACpB,UACA,MACA,MACA,QACkB;CAClB,MAAM,QAAQ,SAAS;AACvB,KAAI,CAAC,MACH,OAAM,IAAI,MAAM,iBAAiB,OAAO;CAE1C,MAAM,SAAS,MAAM,OAAO,UAAU,KAAK;AAC3C,KAAI,CAAC,OAAO,QACV,QAAO,eAAe,OAAO,OAAO,KAAK;AAE3C,QAAO,MAAM,QAAQ,OAAO,MAAM,OAAO;;;;;;;;;AAU3C,SAAgB,kBACd,UACuB;AACvB,QAAO,OAAO,QAAQ,SAAS,CAAC,KAAK,CAAC,MAAM,WAAW;EACrD,MAAM,aAAa,iBACjB,MAAM,OACP;EACD,MAAM,MAA2B;GAC/B;GACA,aAAa,MAAM;GACnB;GACD;AACD,MAAI,MAAM,YACR,KAAI,cAAc,MAAM;AAE1B,SAAO;GACP"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AgentToolDefinition, ToolAnnotations } from "../../../shared/src/agent.js";
|
|
2
|
+
import "../../../shared/src/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/agent/tools/function-tool.d.ts
|
|
5
|
+
interface FunctionTool {
|
|
6
|
+
type: "function";
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string | null;
|
|
9
|
+
parameters?: Record<string, unknown> | null;
|
|
10
|
+
strict?: boolean | null;
|
|
11
|
+
/**
|
|
12
|
+
* Behavioural hints that drive the agents plugin's approval gate and the
|
|
13
|
+
* client's approval-card styling. Prefer setting `effect` (one of
|
|
14
|
+
* `"read" | "write" | "update" | "destructive"`) — any mutating value
|
|
15
|
+
* forces HITL approval before `execute()` runs. Legacy `destructive: true`
|
|
16
|
+
* is still honoured. Must be preserved through {@link
|
|
17
|
+
* functionToolToDefinition} so the plugin sees them when building agent
|
|
18
|
+
* tool indexes.
|
|
19
|
+
*/
|
|
20
|
+
annotations?: ToolAnnotations;
|
|
21
|
+
execute: (args: Record<string, unknown>) => Promise<string> | string;
|
|
22
|
+
}
|
|
23
|
+
declare function isFunctionTool(value: unknown): value is FunctionTool;
|
|
24
|
+
declare function functionToolToDefinition(tool: FunctionTool): AgentToolDefinition;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { FunctionTool, functionToolToDefinition, isFunctionTool };
|
|
27
|
+
//# sourceMappingURL=function-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-tool.d.ts","names":[],"sources":["../../../../src/core/agent/tools/function-tool.ts"],"mappings":";;;;UAEiB,YAAA;EACf,IAAA;EACA,IAAA;EACA,WAAA;EACA,UAAA,GAAa,MAAA;EACb,MAAA;EADa;;;;;;;;;EAWb,WAAA,GAAc,eAAA;EACd,OAAA,GAAU,IAAA,EAAM,MAAA,sBAA4B,OAAA;AAAA;AAAA,iBAG9B,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,YAAA;AAAA,iBAUzC,wBAAA,CACd,IAAA,EAAM,YAAA,GACL,mBAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/core/agent/tools/function-tool.ts
|
|
2
|
+
function isFunctionTool(value) {
|
|
3
|
+
if (typeof value !== "object" || value === null) return false;
|
|
4
|
+
const obj = value;
|
|
5
|
+
return obj.type === "function" && typeof obj.name === "string" && typeof obj.execute === "function";
|
|
6
|
+
}
|
|
7
|
+
function functionToolToDefinition(tool) {
|
|
8
|
+
return {
|
|
9
|
+
name: tool.name,
|
|
10
|
+
description: tool.description ?? tool.name,
|
|
11
|
+
parameters: tool.parameters ?? {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {}
|
|
14
|
+
},
|
|
15
|
+
...tool.annotations ? { annotations: tool.annotations } : {}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { functionToolToDefinition, isFunctionTool };
|
|
21
|
+
//# sourceMappingURL=function-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-tool.js","names":[],"sources":["../../../../src/core/agent/tools/function-tool.ts"],"sourcesContent":["import type { AgentToolDefinition, ToolAnnotations } from \"shared\";\n\nexport interface FunctionTool {\n type: \"function\";\n name: string;\n description?: string | null;\n parameters?: Record<string, unknown> | null;\n strict?: boolean | null;\n /**\n * Behavioural hints that drive the agents plugin's approval gate and the\n * client's approval-card styling. Prefer setting `effect` (one of\n * `\"read\" | \"write\" | \"update\" | \"destructive\"`) — any mutating value\n * forces HITL approval before `execute()` runs. Legacy `destructive: true`\n * is still honoured. Must be preserved through {@link\n * functionToolToDefinition} so the plugin sees them when building agent\n * tool indexes.\n */\n annotations?: ToolAnnotations;\n execute: (args: Record<string, unknown>) => Promise<string> | string;\n}\n\nexport function isFunctionTool(value: unknown): value is FunctionTool {\n if (typeof value !== \"object\" || value === null) return false;\n const obj = value as Record<string, unknown>;\n return (\n obj.type === \"function\" &&\n typeof obj.name === \"string\" &&\n typeof obj.execute === \"function\"\n );\n}\n\nexport function functionToolToDefinition(\n tool: FunctionTool,\n): AgentToolDefinition {\n return {\n name: tool.name,\n description: tool.description ?? tool.name,\n parameters: (tool.parameters as AgentToolDefinition[\"parameters\"]) ?? {\n type: \"object\",\n properties: {},\n },\n ...(tool.annotations ? { annotations: tool.annotations } : {}),\n };\n}\n"],"mappings":";AAqBA,SAAgB,eAAe,OAAuC;AACpE,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,MAAM;AACZ,QACE,IAAI,SAAS,cACb,OAAO,IAAI,SAAS,YACpB,OAAO,IAAI,YAAY;;AAI3B,SAAgB,yBACd,MACqB;AACrB,QAAO;EACL,MAAM,KAAK;EACX,aAAa,KAAK,eAAe,KAAK;EACtC,YAAa,KAAK,cAAoD;GACpE,MAAM;GACN,YAAY,EAAE;GACf;EACD,GAAI,KAAK,cAAc,EAAE,aAAa,KAAK,aAAa,GAAG,EAAE;EAC9D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { McpEndpointConfig } from "../../../connectors/mcp/types.js";
|
|
2
|
+
import "../../../connectors/mcp/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/agent/tools/hosted-tools.d.ts
|
|
5
|
+
interface GenieTool {
|
|
6
|
+
type: "genie-space";
|
|
7
|
+
genie_space: {
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface VectorSearchIndexTool {
|
|
12
|
+
type: "vector_search_index";
|
|
13
|
+
vector_search_index: {
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
interface CustomMcpServerTool {
|
|
18
|
+
type: "custom_mcp_server";
|
|
19
|
+
custom_mcp_server: {
|
|
20
|
+
app_name: string;
|
|
21
|
+
app_url: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface ExternalMcpServerTool {
|
|
25
|
+
type: "external_mcp_server";
|
|
26
|
+
external_mcp_server: {
|
|
27
|
+
connection_name: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
type HostedTool = GenieTool | VectorSearchIndexTool | CustomMcpServerTool | ExternalMcpServerTool;
|
|
31
|
+
declare function isHostedTool(value: unknown): value is HostedTool;
|
|
32
|
+
declare function resolveHostedTools(tools: HostedTool[]): McpEndpointConfig[];
|
|
33
|
+
/**
|
|
34
|
+
* Factory for declaring a custom MCP server tool.
|
|
35
|
+
*
|
|
36
|
+
* Replaces the verbose `{ type: "custom_mcp_server", custom_mcp_server: { app_name, app_url } }`
|
|
37
|
+
* wrapper with a concise positional call.
|
|
38
|
+
*
|
|
39
|
+
* Example:
|
|
40
|
+
* ```ts
|
|
41
|
+
* mcpServer("my-app", "https://my-app.databricksapps.com/mcp")
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function mcpServer(name: string, url: string): CustomMcpServerTool;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { HostedTool, isHostedTool, mcpServer, resolveHostedTools };
|
|
47
|
+
//# sourceMappingURL=hosted-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-tools.d.ts","names":[],"sources":["../../../../src/core/agent/tools/hosted-tools.ts"],"mappings":";;;;UAEiB,SAAA;EACf,IAAA;EACA,WAAA;IAAe,EAAA;EAAA;AAAA;AAAA,UAGA,qBAAA;EACf,IAAA;EACA,mBAAA;IAAuB,IAAA;EAAA;AAAA;AAAA,UAGR,mBAAA;EACf,IAAA;EACA,iBAAA;IAAqB,QAAA;IAAkB,OAAA;EAAA;AAAA;AAAA,UAGxB,qBAAA;EACf,IAAA;EACA,mBAAA;IAAuB,eAAA;EAAA;AAAA;AAAA,KAGb,UAAA,GACR,SAAA,GACA,qBAAA,GACA,mBAAA,GACA,qBAAA;AAAA,iBASY,YAAA,CAAa,KAAA,YAAiB,KAAA,IAAS,UAAA;AAAA,iBA0CvC,kBAAA,CAAmB,KAAA,EAAO,UAAA,KAAe,iBAAA;;;;AA5DzD;;;;;;;;iBA2EgB,SAAA,CAAU,IAAA,UAAc,GAAA,WAAc,mBAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/core/agent/tools/hosted-tools.ts
|
|
2
|
+
const HOSTED_TOOL_TYPES = new Set([
|
|
3
|
+
"genie-space",
|
|
4
|
+
"vector_search_index",
|
|
5
|
+
"custom_mcp_server",
|
|
6
|
+
"external_mcp_server"
|
|
7
|
+
]);
|
|
8
|
+
function isHostedTool(value) {
|
|
9
|
+
if (typeof value !== "object" || value === null) return false;
|
|
10
|
+
const obj = value;
|
|
11
|
+
return typeof obj.type === "string" && HOSTED_TOOL_TYPES.has(obj.type);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolves HostedTool configs into MCP endpoint configurations
|
|
15
|
+
* that the MCP client can connect to.
|
|
16
|
+
*/
|
|
17
|
+
function resolveHostedTool(tool) {
|
|
18
|
+
switch (tool.type) {
|
|
19
|
+
case "genie-space": return {
|
|
20
|
+
name: `genie-${tool.genie_space.id}`,
|
|
21
|
+
url: `/api/2.0/mcp/genie/${tool.genie_space.id}`
|
|
22
|
+
};
|
|
23
|
+
case "vector_search_index": {
|
|
24
|
+
const parts = tool.vector_search_index.name.split(".");
|
|
25
|
+
if (parts.length !== 3) throw new Error(`vector_search_index name must be 3-part dotted (catalog.schema.index), got: ${tool.vector_search_index.name}`);
|
|
26
|
+
return {
|
|
27
|
+
name: `vs-${parts.join("-")}`,
|
|
28
|
+
url: `/api/2.0/mcp/vector-search/${parts[0]}/${parts[1]}/${parts[2]}`
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
case "custom_mcp_server": return {
|
|
32
|
+
name: tool.custom_mcp_server.app_name,
|
|
33
|
+
url: tool.custom_mcp_server.app_url
|
|
34
|
+
};
|
|
35
|
+
case "external_mcp_server": return {
|
|
36
|
+
name: tool.external_mcp_server.connection_name,
|
|
37
|
+
url: `/api/2.0/mcp/external/${tool.external_mcp_server.connection_name}`
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function resolveHostedTools(tools) {
|
|
42
|
+
return tools.map(resolveHostedTool);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Factory for declaring a custom MCP server tool.
|
|
46
|
+
*
|
|
47
|
+
* Replaces the verbose `{ type: "custom_mcp_server", custom_mcp_server: { app_name, app_url } }`
|
|
48
|
+
* wrapper with a concise positional call.
|
|
49
|
+
*
|
|
50
|
+
* Example:
|
|
51
|
+
* ```ts
|
|
52
|
+
* mcpServer("my-app", "https://my-app.databricksapps.com/mcp")
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
function mcpServer(name, url) {
|
|
56
|
+
return {
|
|
57
|
+
type: "custom_mcp_server",
|
|
58
|
+
custom_mcp_server: {
|
|
59
|
+
app_name: name,
|
|
60
|
+
app_url: url
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { isHostedTool, mcpServer, resolveHostedTools };
|
|
67
|
+
//# sourceMappingURL=hosted-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-tools.js","names":[],"sources":["../../../../src/core/agent/tools/hosted-tools.ts"],"sourcesContent":["import type { McpEndpointConfig } from \"../../../connectors/mcp\";\n\nexport interface GenieTool {\n type: \"genie-space\";\n genie_space: { id: string };\n}\n\nexport interface VectorSearchIndexTool {\n type: \"vector_search_index\";\n vector_search_index: { name: string };\n}\n\nexport interface CustomMcpServerTool {\n type: \"custom_mcp_server\";\n custom_mcp_server: { app_name: string; app_url: string };\n}\n\nexport interface ExternalMcpServerTool {\n type: \"external_mcp_server\";\n external_mcp_server: { connection_name: string };\n}\n\nexport type HostedTool =\n | GenieTool\n | VectorSearchIndexTool\n | CustomMcpServerTool\n | ExternalMcpServerTool;\n\nconst HOSTED_TOOL_TYPES = new Set([\n \"genie-space\",\n \"vector_search_index\",\n \"custom_mcp_server\",\n \"external_mcp_server\",\n]);\n\nexport function isHostedTool(value: unknown): value is HostedTool {\n if (typeof value !== \"object\" || value === null) return false;\n const obj = value as Record<string, unknown>;\n return typeof obj.type === \"string\" && HOSTED_TOOL_TYPES.has(obj.type);\n}\n\n/**\n * Resolves HostedTool configs into MCP endpoint configurations\n * that the MCP client can connect to.\n */\nfunction resolveHostedTool(tool: HostedTool): McpEndpointConfig {\n switch (tool.type) {\n case \"genie-space\":\n return {\n name: `genie-${tool.genie_space.id}`,\n url: `/api/2.0/mcp/genie/${tool.genie_space.id}`,\n };\n case \"vector_search_index\": {\n const parts = tool.vector_search_index.name.split(\".\");\n if (parts.length !== 3) {\n throw new Error(\n `vector_search_index name must be 3-part dotted (catalog.schema.index), got: ${tool.vector_search_index.name}`,\n );\n }\n return {\n name: `vs-${parts.join(\"-\")}`,\n url: `/api/2.0/mcp/vector-search/${parts[0]}/${parts[1]}/${parts[2]}`,\n };\n }\n case \"custom_mcp_server\":\n return {\n name: tool.custom_mcp_server.app_name,\n url: tool.custom_mcp_server.app_url,\n };\n case \"external_mcp_server\":\n return {\n name: tool.external_mcp_server.connection_name,\n url: `/api/2.0/mcp/external/${tool.external_mcp_server.connection_name}`,\n };\n }\n}\n\nexport function resolveHostedTools(tools: HostedTool[]): McpEndpointConfig[] {\n return tools.map(resolveHostedTool);\n}\n\n/**\n * Factory for declaring a custom MCP server tool.\n *\n * Replaces the verbose `{ type: \"custom_mcp_server\", custom_mcp_server: { app_name, app_url } }`\n * wrapper with a concise positional call.\n *\n * Example:\n * ```ts\n * mcpServer(\"my-app\", \"https://my-app.databricksapps.com/mcp\")\n * ```\n */\nexport function mcpServer(name: string, url: string): CustomMcpServerTool {\n return {\n type: \"custom_mcp_server\",\n custom_mcp_server: { app_name: name, app_url: url },\n };\n}\n"],"mappings":";AA4BA,MAAM,oBAAoB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,aAAa,OAAqC;AAChE,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,MAAM;AACZ,QAAO,OAAO,IAAI,SAAS,YAAY,kBAAkB,IAAI,IAAI,KAAK;;;;;;AAOxE,SAAS,kBAAkB,MAAqC;AAC9D,SAAQ,KAAK,MAAb;EACE,KAAK,cACH,QAAO;GACL,MAAM,SAAS,KAAK,YAAY;GAChC,KAAK,sBAAsB,KAAK,YAAY;GAC7C;EACH,KAAK,uBAAuB;GAC1B,MAAM,QAAQ,KAAK,oBAAoB,KAAK,MAAM,IAAI;AACtD,OAAI,MAAM,WAAW,EACnB,OAAM,IAAI,MACR,+EAA+E,KAAK,oBAAoB,OACzG;AAEH,UAAO;IACL,MAAM,MAAM,MAAM,KAAK,IAAI;IAC3B,KAAK,8BAA8B,MAAM,GAAG,GAAG,MAAM,GAAG,GAAG,MAAM;IAClE;;EAEH,KAAK,oBACH,QAAO;GACL,MAAM,KAAK,kBAAkB;GAC7B,KAAK,KAAK,kBAAkB;GAC7B;EACH,KAAK,sBACH,QAAO;GACL,MAAM,KAAK,oBAAoB;GAC/B,KAAK,yBAAyB,KAAK,oBAAoB;GACxD;;;AAIP,SAAgB,mBAAmB,OAA0C;AAC3E,QAAO,MAAM,IAAI,kBAAkB;;;;;;;;;;;;;AAcrC,SAAgB,UAAU,MAAc,KAAkC;AACxE,QAAO;EACL,MAAM;EACN,mBAAmB;GAAE,UAAU;GAAM,SAAS;GAAK;EACpD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AppKitMcpClient } from "../../../connectors/mcp/client.js";
|
|
2
|
+
import { FunctionTool, functionToolToDefinition, isFunctionTool } from "./function-tool.js";
|
|
3
|
+
import { HostedTool, isHostedTool, mcpServer, resolveHostedTools } from "./hosted-tools.js";
|
|
4
|
+
import { ToolEntry, ToolRegistry, defineTool, executeFromRegistry, toolsFromRegistry } from "./define-tool.js";
|
|
5
|
+
import { ToolConfig, tool } from "./tool.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AppKitMcpClient } from "../../../connectors/mcp/client.js";
|
|
2
|
+
import { tool } from "./tool.js";
|
|
3
|
+
import { defineTool, executeFromRegistry, toolsFromRegistry } from "./define-tool.js";
|
|
4
|
+
import { functionToolToDefinition, isFunctionTool } from "./function-tool.js";
|
|
5
|
+
import { isHostedTool, mcpServer, resolveHostedTools } from "./hosted-tools.js";
|
|
6
|
+
|
|
7
|
+
export { };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { toJSONSchema } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/core/agent/tools/json-schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a Zod schema to JSON Schema suitable for an LLM tool-call
|
|
6
|
+
* `parameters` field.
|
|
7
|
+
*
|
|
8
|
+
* Wraps `zod`'s `toJSONSchema()` and strips the top-level `$schema` annotation
|
|
9
|
+
* that Zod v4 emits by default (e.g. `"https://json-schema.org/draft/..."`).
|
|
10
|
+
* The Databricks Mosaic serving endpoint forwards tool schemas to Google's
|
|
11
|
+
* Gemini `function_declarations` format, which rejects any top-level key it
|
|
12
|
+
* doesn't explicitly recognize — including `$schema` — with a 400
|
|
13
|
+
* `Invalid JSON payload received. Unknown name "$schema"` error. Other LLM
|
|
14
|
+
* providers either ignore the field or also trip on it, so stripping here is
|
|
15
|
+
* safe across backends.
|
|
16
|
+
*/
|
|
17
|
+
function toToolJSONSchema(schema) {
|
|
18
|
+
const { $schema: _ignored, ...rest } = toJSONSchema(schema);
|
|
19
|
+
return rest;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { toToolJSONSchema };
|
|
24
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","names":[],"sources":["../../../../src/core/agent/tools/json-schema.ts"],"sourcesContent":["import { toJSONSchema, type z } from \"zod\";\n\n/**\n * Converts a Zod schema to JSON Schema suitable for an LLM tool-call\n * `parameters` field.\n *\n * Wraps `zod`'s `toJSONSchema()` and strips the top-level `$schema` annotation\n * that Zod v4 emits by default (e.g. `\"https://json-schema.org/draft/...\"`).\n * The Databricks Mosaic serving endpoint forwards tool schemas to Google's\n * Gemini `function_declarations` format, which rejects any top-level key it\n * doesn't explicitly recognize — including `$schema` — with a 400\n * `Invalid JSON payload received. Unknown name \"$schema\"` error. Other LLM\n * providers either ignore the field or also trip on it, so stripping here is\n * safe across backends.\n */\nexport function toToolJSONSchema(schema: z.ZodType): Record<string, unknown> {\n const raw = toJSONSchema(schema) as Record<string, unknown>;\n const { $schema: _ignored, ...rest } = raw;\n return rest;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,iBAAiB,QAA4C;CAE3E,MAAM,EAAE,SAAS,UAAU,GAAG,SADlB,aAAa,OAAO;AAEhC,QAAO"}
|