@databricks/appkit 0.32.0 → 0.33.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 +53 -1
- package/NOTICE.md +1 -0
- package/dist/agents/databricks.d.ts.map +1 -1
- package/dist/agents/databricks.js +8 -3
- package/dist/agents/databricks.js.map +1 -1
- package/dist/appkit/package.js +1 -1
- package/dist/beta.d.ts +5 -3
- package/dist/beta.js +3 -1
- package/dist/connectors/mcp/client.d.ts +27 -2
- package/dist/connectors/mcp/client.d.ts.map +1 -1
- package/dist/connectors/mcp/client.js +117 -18
- package/dist/connectors/mcp/client.js.map +1 -1
- package/dist/connectors/mcp/index.d.ts +1 -1
- package/dist/connectors/mcp/types.d.ts +1 -1
- package/dist/core/agent/build-toolkit.js +3 -8
- package/dist/core/agent/build-toolkit.js.map +1 -1
- package/dist/core/agent/load-agents.d.ts +6 -1
- package/dist/core/agent/load-agents.d.ts.map +1 -1
- package/dist/core/agent/load-agents.js +67 -27
- package/dist/core/agent/load-agents.js.map +1 -1
- package/dist/core/agent/plugins-map.js +44 -0
- package/dist/core/agent/plugins-map.js.map +1 -0
- package/dist/core/agent/run-agent.d.ts +31 -7
- package/dist/core/agent/run-agent.d.ts.map +1 -1
- package/dist/core/agent/run-agent.js +138 -27
- package/dist/core/agent/run-agent.js.map +1 -1
- package/dist/core/agent/toolkit-options.js +28 -0
- package/dist/core/agent/toolkit-options.js.map +1 -0
- package/dist/core/agent/toolkit-resolver.js +44 -0
- package/dist/core/agent/toolkit-resolver.js.map +1 -0
- package/dist/core/agent/tools/define-tool.d.ts +14 -2
- package/dist/core/agent/tools/define-tool.d.ts.map +1 -1
- package/dist/core/agent/tools/define-tool.js +1 -1
- package/dist/core/agent/tools/define-tool.js.map +1 -1
- package/dist/core/agent/tools/function-tool.d.ts +13 -2
- package/dist/core/agent/tools/function-tool.d.ts.map +1 -1
- package/dist/core/agent/tools/function-tool.js +4 -3
- package/dist/core/agent/tools/function-tool.js.map +1 -1
- package/dist/core/agent/tools/index.d.ts +1 -1
- package/dist/core/agent/tools/tool.d.ts +32 -3
- package/dist/core/agent/tools/tool.d.ts.map +1 -1
- package/dist/core/agent/tools/tool.js +4 -3
- package/dist/core/agent/tools/tool.js.map +1 -1
- package/dist/core/agent/types.d.ts +95 -10
- package/dist/core/agent/types.d.ts.map +1 -1
- package/dist/core/agent/types.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/to-plugin.d.ts +3 -13
- package/dist/plugin/to-plugin.d.ts.map +1 -1
- package/dist/plugin/to-plugin.js +1 -8
- package/dist/plugin/to-plugin.js.map +1 -1
- package/dist/plugins/agents/agents.d.ts +184 -2
- package/dist/plugins/agents/agents.d.ts.map +1 -0
- package/dist/plugins/agents/agents.js +169 -72
- package/dist/plugins/agents/agents.js.map +1 -1
- package/dist/plugins/agents/index.d.ts +2 -2
- package/dist/plugins/agents/index.js +1 -1
- package/dist/plugins/agents/manifest.js +4 -5
- package/dist/plugins/agents/tool-approval-gate.js.map +1 -1
- package/dist/plugins/analytics/analytics.d.ts +3 -4
- package/dist/plugins/analytics/analytics.d.ts.map +1 -1
- package/dist/plugins/analytics/analytics.js +8 -6
- package/dist/plugins/analytics/analytics.js.map +1 -1
- package/dist/plugins/analytics/index.js +1 -0
- package/dist/plugins/analytics/types.js +15 -0
- package/dist/plugins/analytics/types.js.map +1 -0
- package/dist/plugins/beta-exports.generated.d.ts +2 -0
- package/dist/plugins/beta-exports.generated.js +4 -0
- package/dist/plugins/files/plugin.d.ts +1 -2
- package/dist/plugins/files/plugin.d.ts.map +1 -1
- package/dist/plugins/files/plugin.js +30 -12
- package/dist/plugins/files/plugin.js.map +1 -1
- package/dist/plugins/genie/genie.d.ts +5 -4
- package/dist/plugins/genie/genie.d.ts.map +1 -1
- package/dist/plugins/genie/genie.js +22 -8
- package/dist/plugins/genie/genie.js.map +1 -1
- package/dist/plugins/genie/types.d.ts +10 -2
- package/dist/plugins/genie/types.d.ts.map +1 -1
- package/dist/plugins/jobs/plugin.d.ts +1 -2
- package/dist/plugins/jobs/plugin.d.ts.map +1 -1
- package/dist/plugins/lakebase/lakebase.d.ts +1 -2
- package/dist/plugins/lakebase/lakebase.d.ts.map +1 -1
- package/dist/plugins/lakebase/lakebase.js +3 -3
- package/dist/plugins/lakebase/lakebase.js.map +1 -1
- package/dist/plugins/lakebase/types.d.ts +5 -4
- package/dist/plugins/lakebase/types.d.ts.map +1 -1
- package/dist/plugins/server/index.d.ts +3 -2
- package/dist/plugins/server/index.d.ts.map +1 -1
- package/dist/plugins/server/index.js +8 -5
- package/dist/plugins/server/index.js.map +1 -1
- package/dist/plugins/server/types.d.ts +11 -0
- package/dist/plugins/server/types.d.ts.map +1 -1
- package/dist/plugins/serving/serving.d.ts +1 -2
- package/dist/plugins/serving/serving.d.ts.map +1 -1
- package/dist/shared/src/agent.d.ts +16 -4
- package/dist/shared/src/agent.d.ts.map +1 -1
- package/docs/api/appkit/Class.AppKitMcpClient.md +157 -0
- package/docs/api/appkit/Class.DatabricksAdapter.md +151 -0
- package/docs/api/appkit/Function.agentIdFromMarkdownPath.md +18 -0
- package/docs/api/appkit/Function.createAgent.md +33 -0
- package/docs/api/appkit/Function.defineTool.md +26 -0
- package/docs/api/appkit/Function.executeFromRegistry.md +25 -0
- package/docs/api/appkit/Function.functionToolToDefinition.md +16 -0
- package/docs/api/appkit/Function.isFunctionTool.md +16 -0
- package/docs/api/appkit/Function.isHostedTool.md +16 -0
- package/docs/api/appkit/Function.isToolkitEntry.md +18 -0
- package/docs/api/appkit/Function.loadAgentFromFile.md +21 -0
- package/docs/api/appkit/Function.loadAgentsFromDir.md +26 -0
- package/docs/api/appkit/Function.mcpServer.md +28 -0
- package/docs/api/appkit/Function.parseTextToolCalls.md +26 -0
- package/docs/api/appkit/Function.resolveHostedTools.md +16 -0
- package/docs/api/appkit/Function.runAgent.md +26 -0
- package/docs/api/appkit/Function.tool.md +28 -0
- package/docs/api/appkit/Function.toolsFromRegistry.md +20 -0
- package/docs/api/appkit/Interface.AgentAdapter.md +21 -0
- package/docs/api/appkit/Interface.AgentDefinition.md +112 -0
- package/docs/api/appkit/Interface.AgentInput.md +37 -0
- package/docs/api/appkit/Interface.AgentRunContext.md +32 -0
- package/docs/api/appkit/Interface.AgentToolDefinition.md +37 -0
- package/docs/api/appkit/Interface.AgentsPluginConfig.md +241 -0
- package/docs/api/appkit/Interface.AutoInheritToolsConfig.md +27 -0
- package/docs/api/appkit/Interface.BasePluginConfig.md +1 -0
- package/docs/api/appkit/Interface.FunctionTool.md +80 -0
- package/docs/api/appkit/Interface.McpConnectAllResult.md +38 -0
- package/docs/api/appkit/Interface.Message.md +55 -0
- package/docs/api/appkit/Interface.PluginToolkitProvider.md +22 -0
- package/docs/api/appkit/Interface.PromptContext.md +30 -0
- package/docs/api/appkit/Interface.RegisteredAgent.md +75 -0
- package/docs/api/appkit/Interface.RunAgentInput.md +34 -0
- package/docs/api/appkit/Interface.RunAgentResult.md +23 -0
- package/docs/api/appkit/Interface.Thread.md +46 -0
- package/docs/api/appkit/Interface.ThreadStore.md +103 -0
- package/docs/api/appkit/Interface.ToolAnnotations.md +56 -0
- package/docs/api/appkit/Interface.ToolConfig.md +72 -0
- package/docs/api/appkit/Interface.ToolEntry.md +73 -0
- package/docs/api/appkit/Interface.ToolProvider.md +38 -0
- package/docs/api/appkit/Interface.ToolkitEntry.md +59 -0
- package/docs/api/appkit/Interface.ToolkitOptions.md +45 -0
- package/docs/api/appkit/TypeAlias.AgentEvent.md +299 -0
- package/docs/api/appkit/TypeAlias.AgentTool.md +11 -0
- package/docs/api/appkit/TypeAlias.AgentTools.md +8 -0
- package/docs/api/appkit/TypeAlias.AgentToolsFn.md +20 -0
- package/docs/api/appkit/TypeAlias.BaseSystemPromptOption.md +9 -0
- package/docs/api/appkit/TypeAlias.HostedTool.md +10 -0
- package/docs/api/appkit/TypeAlias.Plugins.md +26 -0
- package/docs/api/appkit/TypeAlias.ResolvedToolEntry.md +29 -0
- package/docs/api/appkit/TypeAlias.ToolRegistry.md +6 -0
- package/docs/api/appkit/Variable.agents.md +19 -0
- package/docs/api/appkit.md +113 -62
- package/docs/plugins/agents.md +441 -0
- package/llms.txt +53 -1
- package/package.json +1 -1
- package/sbom.cdx.json +1 -1
|
@@ -1 +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
|
|
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 /**\n * Optional. When this tool is placed in a keyed record\n * (`tools: { my_tool: ... }` or the function form), the agents plugin\n * overrides this with the record key at index-build time. Only set it\n * explicitly when constructing a `FunctionTool` outside any\n * keyed-record context.\n */\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 /**\n * Returns any shape; downstream `normalizeToolResult` serializes to a\n * string before handing the value to the LLM.\n */\n execute: (args: Record<string, unknown>) => unknown | Promise<unknown>;\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 // `name` is intentionally not required: the agents plugin overrides it\n // with the record key (`tools: { my_tool: tool({...}) }` -> \"my_tool\")\n // so requiring it on the FunctionTool shape rejects perfectly-valid\n // `tool({ description, schema, execute })` calls that omit the name.\n return obj.type === \"function\" && typeof obj.execute === \"function\";\n}\n\nexport function functionToolToDefinition(\n tool: FunctionTool,\n): AgentToolDefinition {\n // `name` is guaranteed to be overridden downstream by the record key\n // when the tool is registered through `AgentDefinition.tools`. Falling\n // back to an empty string here keeps the type honest without\n // surfacing a sentinel that could leak into a non-record context.\n const name = tool.name ?? \"\";\n return {\n name,\n description: tool.description ?? name,\n parameters: (tool.parameters as AgentToolDefinition[\"parameters\"]) ?? {\n type: \"object\",\n properties: {},\n },\n ...(tool.annotations ? { annotations: tool.annotations } : {}),\n };\n}\n"],"mappings":";AAgCA,SAAgB,eAAe,OAAuC;AACpE,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,MAAM;AAKZ,QAAO,IAAI,SAAS,cAAc,OAAO,IAAI,YAAY;;AAG3D,SAAgB,yBACd,MACqB;CAKrB,MAAM,OAAO,KAAK,QAAQ;AAC1B,QAAO;EACL;EACA,aAAa,KAAK,eAAe;EACjC,YAAa,KAAK,cAAoD;GACpE,MAAM;GACN,YAAY,EAAE;GACf;EACD,GAAI,KAAK,cAAc,EAAE,aAAa,KAAK,aAAa,GAAG,EAAE;EAC9D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppKitMcpClient } from "../../../connectors/mcp/client.js";
|
|
1
|
+
import { AppKitMcpClient, McpConnectAllResult } from "../../../connectors/mcp/client.js";
|
|
2
2
|
import { FunctionTool, functionToolToDefinition, isFunctionTool } from "./function-tool.js";
|
|
3
3
|
import { HostedTool, isHostedTool, mcpServer, resolveHostedTools } from "./hosted-tools.js";
|
|
4
4
|
import { ToolEntry, ToolRegistry, defineTool, executeFromRegistry, toolsFromRegistry } from "./define-tool.js";
|
|
@@ -5,8 +5,29 @@ import { z } from "zod";
|
|
|
5
5
|
|
|
6
6
|
//#region src/core/agent/tools/tool.d.ts
|
|
7
7
|
interface ToolConfig<S extends z.ZodType> {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Optional. When the tool is placed in a keyed record (the standard
|
|
10
|
+
* `tools: { my_tool: tool({...}) }` form, or the function form
|
|
11
|
+
* `tools(plugins) => ({ my_tool: tool({...}) })`), the agents plugin
|
|
12
|
+
* overrides the tool's LLM-visible name with the record key. Set
|
|
13
|
+
* `name` explicitly only if you're constructing a `FunctionTool`
|
|
14
|
+
* outside any keyed-record context — otherwise the record key wins.
|
|
15
|
+
*/
|
|
16
|
+
name?: string;
|
|
17
|
+
/**
|
|
18
|
+
* What the tool does, what it expects, and when the LLM should call it.
|
|
19
|
+
* The model reads this verbatim when deciding whether to invoke the tool,
|
|
20
|
+
* so write it for an LLM, not for a human reader of your code: spell out
|
|
21
|
+
* the inputs, the return shape, and any pre-conditions or side effects.
|
|
22
|
+
*
|
|
23
|
+
* Required. Earlier versions silently fell back to the tool's name when
|
|
24
|
+
* omitted, which surfaced cryptic identifiers like `"get_weather"` as the
|
|
25
|
+
* description — the model then had no signal about expected use and
|
|
26
|
+
* either skipped the tool or called it speculatively. Making this
|
|
27
|
+
* mandatory at the type level forces a real description at authoring
|
|
28
|
+
* time instead of debugging a confused agent later.
|
|
29
|
+
*/
|
|
30
|
+
description: string;
|
|
10
31
|
schema: S;
|
|
11
32
|
/**
|
|
12
33
|
* Behavioural hints forwarded to the resolved tool definition. Prefer
|
|
@@ -17,7 +38,15 @@ interface ToolConfig<S extends z.ZodType> {
|
|
|
17
38
|
* added this field.
|
|
18
39
|
*/
|
|
19
40
|
annotations?: ToolAnnotations;
|
|
20
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Returning a non-string value is fine: the agent runtime serializes
|
|
43
|
+
* the result via `normalizeToolResult` before handing it to the LLM
|
|
44
|
+
* (strings pass through; `null` becomes `"null"`; everything else gets
|
|
45
|
+
* `JSON.stringify`'d; `undefined` becomes `""`). Return whatever shape
|
|
46
|
+
* is most natural for your tool — typically an object — and let the
|
|
47
|
+
* runtime handle the wire format.
|
|
48
|
+
*/
|
|
49
|
+
execute: (args: z.infer<S>) => unknown | Promise<unknown>;
|
|
21
50
|
}
|
|
22
51
|
/**
|
|
23
52
|
* Factory for defining function tools with Zod schemas.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","names":[],"sources":["../../../../src/core/agent/tools/tool.ts"],"mappings":";;;;;;UAKiB,UAAA,WAAqB,CAAA,CAAE,OAAA
|
|
1
|
+
{"version":3,"file":"tool.d.ts","names":[],"sources":["../../../../src/core/agent/tools/tool.ts"],"mappings":";;;;;;UAKiB,UAAA,WAAqB,CAAA,CAAE,OAAA;;;AAAxC;;;;;;EASE,IAAA;EAiCkB;;;;;;;;;;;;;EAnBlB,WAAA;EACA,MAAA,EAAQ,CAAA;EAkBU;;;;;;AAYpB;;EArBE,WAAA,GAAc,eAAA;EAqBiB;;;;;;;;EAZ/B,OAAA,GAAU,IAAA,EAAM,CAAA,CAAE,KAAA,CAAM,CAAA,gBAAiB,OAAA;AAAA;;;;;;;;;;iBAY3B,IAAA,WAAe,CAAA,CAAE,OAAA,CAAA,CAAS,MAAA,EAAQ,UAAA,CAAW,CAAA,IAAK,YAAA"}
|
|
@@ -12,15 +12,16 @@ import { toToolJSONSchema } from "./json-schema.js";
|
|
|
12
12
|
*/
|
|
13
13
|
function tool(config) {
|
|
14
14
|
const parameters = toToolJSONSchema(config.schema);
|
|
15
|
+
const labelForErrors = config.name ?? "tool";
|
|
15
16
|
return {
|
|
16
17
|
type: "function",
|
|
17
|
-
name: config.name,
|
|
18
|
-
description: config.description
|
|
18
|
+
...config.name !== void 0 ? { name: config.name } : {},
|
|
19
|
+
description: config.description,
|
|
19
20
|
parameters,
|
|
20
21
|
...config.annotations ? { annotations: config.annotations } : {},
|
|
21
22
|
execute: async (args) => {
|
|
22
23
|
const parsed = config.schema.safeParse(args);
|
|
23
|
-
if (!parsed.success) return formatZodError(parsed.error,
|
|
24
|
+
if (!parsed.success) return formatZodError(parsed.error, labelForErrors);
|
|
24
25
|
return config.execute(parsed.data);
|
|
25
26
|
}
|
|
26
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","names":[],"sources":["../../../../src/core/agent/tools/tool.ts"],"sourcesContent":["import type { ToolAnnotations } from \"shared\";\nimport type { z } from \"zod\";\nimport type { FunctionTool } from \"./function-tool\";\nimport { toToolJSONSchema } from \"./json-schema\";\n\nexport interface ToolConfig<S extends z.ZodType> {\n
|
|
1
|
+
{"version":3,"file":"tool.js","names":[],"sources":["../../../../src/core/agent/tools/tool.ts"],"sourcesContent":["import type { ToolAnnotations } from \"shared\";\nimport type { z } from \"zod\";\nimport type { FunctionTool } from \"./function-tool\";\nimport { toToolJSONSchema } from \"./json-schema\";\n\nexport interface ToolConfig<S extends z.ZodType> {\n /**\n * Optional. When the tool is placed in a keyed record (the standard\n * `tools: { my_tool: tool({...}) }` form, or the function form\n * `tools(plugins) => ({ my_tool: tool({...}) })`), the agents plugin\n * overrides the tool's LLM-visible name with the record key. Set\n * `name` explicitly only if you're constructing a `FunctionTool`\n * outside any keyed-record context — otherwise the record key wins.\n */\n name?: string;\n /**\n * What the tool does, what it expects, and when the LLM should call it.\n * The model reads this verbatim when deciding whether to invoke the tool,\n * so write it for an LLM, not for a human reader of your code: spell out\n * the inputs, the return shape, and any pre-conditions or side effects.\n *\n * Required. Earlier versions silently fell back to the tool's name when\n * omitted, which surfaced cryptic identifiers like `\"get_weather\"` as the\n * description — the model then had no signal about expected use and\n * either skipped the tool or called it speculatively. Making this\n * mandatory at the type level forces a real description at authoring\n * time instead of debugging a confused agent later.\n */\n description: string;\n schema: S;\n /**\n * Behavioural hints forwarded to the resolved tool definition. Prefer\n * `effect` (`\"read\" | \"write\" | \"update\" | \"destructive\"`) — any mutating\n * value forces the agents-plugin approval gate before `execute()` runs\n * and the client's approval card will colour itself accordingly. Legacy\n * `destructive: true` still gates. Dropped silently before the fix that\n * added this field.\n */\n annotations?: ToolAnnotations;\n /**\n * Returning a non-string value is fine: the agent runtime serializes\n * the result via `normalizeToolResult` before handing it to the LLM\n * (strings pass through; `null` becomes `\"null\"`; everything else gets\n * `JSON.stringify`'d; `undefined` becomes `\"\"`). Return whatever shape\n * is most natural for your tool — typically an object — and let the\n * runtime handle the wire format.\n */\n execute: (args: z.infer<S>) => unknown | Promise<unknown>;\n}\n\n/**\n * Factory for defining function tools with Zod schemas.\n *\n * - Generates JSON Schema (for the LLM) from the Zod schema via `z.toJSONSchema()`.\n * - Infers the `execute` argument type from the schema.\n * - Validates tool call arguments at runtime. On validation failure, returns\n * a formatted error string to the LLM instead of throwing, so the model\n * can self-correct on its next turn.\n */\nexport function tool<S extends z.ZodType>(config: ToolConfig<S>): FunctionTool {\n const parameters = toToolJSONSchema(config.schema);\n\n // `name` is only used for the zod-validation error message and the\n // FunctionTool's `name` field; the agents plugin overrides the latter\n // with the record key (`tools: { my_tool: ... }` -> \"my_tool\") at\n // index-build time. Fall back to a generic label so errors are still\n // legible when `name` is omitted.\n const labelForErrors = config.name ?? \"tool\";\n\n return {\n type: \"function\",\n ...(config.name !== undefined ? { name: config.name } : {}),\n description: config.description,\n parameters,\n ...(config.annotations ? { annotations: config.annotations } : {}),\n execute: async (args: Record<string, unknown>) => {\n const parsed = config.schema.safeParse(args);\n if (!parsed.success) {\n return formatZodError(parsed.error, labelForErrors);\n }\n return config.execute(parsed.data as z.infer<S>);\n },\n };\n}\n\n/**\n * Formats a Zod validation error into an LLM-friendly string.\n *\n * Example: `Invalid arguments for get_weather: city: Invalid input: expected string, received undefined`\n */\nexport function formatZodError(error: z.ZodError, toolName: string): string {\n const parts = error.issues.map((issue) => {\n const field = issue.path.length > 0 ? issue.path.join(\".\") : \"(root)\";\n return `${field}: ${issue.message}`;\n });\n return `Invalid arguments for ${toolName}: ${parts.join(\"; \")}`;\n}\n"],"mappings":";;;;;;;;;;;;AA2DA,SAAgB,KAA0B,QAAqC;CAC7E,MAAM,aAAa,iBAAiB,OAAO,OAAO;CAOlD,MAAM,iBAAiB,OAAO,QAAQ;AAEtC,QAAO;EACL,MAAM;EACN,GAAI,OAAO,SAAS,SAAY,EAAE,MAAM,OAAO,MAAM,GAAG,EAAE;EAC1D,aAAa,OAAO;EACpB;EACA,GAAI,OAAO,cAAc,EAAE,aAAa,OAAO,aAAa,GAAG,EAAE;EACjE,SAAS,OAAO,SAAkC;GAChD,MAAM,SAAS,OAAO,OAAO,UAAU,KAAK;AAC5C,OAAI,CAAC,OAAO,QACV,QAAO,eAAe,OAAO,OAAO,eAAe;AAErD,UAAO,OAAO,QAAQ,OAAO,KAAmB;;EAEnD;;;;;;;AAQH,SAAgB,eAAe,OAAmB,UAA0B;AAK1E,QAAO,yBAAyB,SAAS,IAJ3B,MAAM,OAAO,KAAK,UAAU;AAExC,SAAO,GADO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,IAAI,GAAG,SAC7C,IAAI,MAAM;GAC1B,CACiD,KAAK,KAAK"}
|
|
@@ -43,6 +43,41 @@ interface ToolkitOptions {
|
|
|
43
43
|
/** Remap specific local names to different keys (applied after prefix). */
|
|
44
44
|
rename?: Record<string, string>;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Minimum shape every entry in the {@link Plugins} map must expose. Core
|
|
48
|
+
* plugins (analytics, files, genie, lakebase) implement this directly via
|
|
49
|
+
* their `.toolkit()` method. The agents plugin and standalone `runAgent`
|
|
50
|
+
* synthesize this shape for any registered plugin that doesn't implement
|
|
51
|
+
* `.toolkit()` directly (falling back to `getAgentTools()` walking).
|
|
52
|
+
*/
|
|
53
|
+
interface PluginToolkitProvider {
|
|
54
|
+
toolkit(opts?: ToolkitOptions): Record<string, ToolkitEntry>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Plugin map passed to the function form of {@link AgentDefinition.tools}.
|
|
58
|
+
* Each entry exposes a `.toolkit(opts?)` method that returns a record of
|
|
59
|
+
* {@link ToolkitEntry} markers ready to be spread into a tool record.
|
|
60
|
+
*
|
|
61
|
+
* AppKit does not statically know which plugins the surrounding
|
|
62
|
+
* `createApp` will register, so this is a plain string-keyed record.
|
|
63
|
+
* Refer to plugins by the name used in `createApp({ plugins: [...] })`;
|
|
64
|
+
* unknown names resolve to `undefined` at runtime.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const support = createAgent({
|
|
69
|
+
* instructions: "...",
|
|
70
|
+
* tools(plugins) {
|
|
71
|
+
* return {
|
|
72
|
+
* get_weather: tool({ ... }),
|
|
73
|
+
* ...plugins.analytics.toolkit(),
|
|
74
|
+
* ...plugins.files.toolkit({ only: ["uploads.read"] }),
|
|
75
|
+
* };
|
|
76
|
+
* },
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
type Plugins = Record<string, PluginToolkitProvider>;
|
|
46
81
|
/**
|
|
47
82
|
* Context passed to `baseSystemPrompt` callbacks.
|
|
48
83
|
*/
|
|
@@ -52,8 +87,40 @@ interface PromptContext {
|
|
|
52
87
|
toolNames: string[];
|
|
53
88
|
}
|
|
54
89
|
type BaseSystemPromptOption = false | string | ((ctx: PromptContext) => string);
|
|
90
|
+
/**
|
|
91
|
+
* Per-agent tool record. String keys map to inline tools, toolkit entries,
|
|
92
|
+
* hosted tools, etc.
|
|
93
|
+
*/
|
|
94
|
+
type AgentTools = Record<string, AgentTool>;
|
|
95
|
+
/**
|
|
96
|
+
* Function form of `AgentDefinition.tools`. Receives the typed
|
|
97
|
+
* {@link Plugins} map and returns a tool record. Invoked exactly once at
|
|
98
|
+
* setup (or once per `runAgent` call in standalone mode); the result is
|
|
99
|
+
* cached as the agent's resolved tool record.
|
|
100
|
+
*
|
|
101
|
+
* Use the function form when an agent needs tools from registered plugins.
|
|
102
|
+
* The bare object form is fine when an agent only uses inline tools.
|
|
103
|
+
*/
|
|
104
|
+
type AgentToolsFn = (plugins: Plugins) => AgentTools;
|
|
55
105
|
interface AgentDefinition {
|
|
56
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Stable identifier for the agent. **Optional and informational** —
|
|
108
|
+
* when the definition is registered via `agents: { foo: def }` (code) or
|
|
109
|
+
* lives at `config/agents/<id>/agent.md` (markdown), the **registry key
|
|
110
|
+
* always wins** and `name` is ignored. The agent will be reachable as
|
|
111
|
+
* `foo` (or `<id>`) regardless of what this field contains.
|
|
112
|
+
*
|
|
113
|
+
* Set `name` when:
|
|
114
|
+
* - Running standalone via `runAgent({ agent: def })`, where there is
|
|
115
|
+
* no enclosing key. The runtime uses it for the agent's slot in
|
|
116
|
+
* error messages and OTel spans.
|
|
117
|
+
* - Building a definition that may be passed to either form and you
|
|
118
|
+
* want a consistent fallback label.
|
|
119
|
+
*
|
|
120
|
+
* Setting `name` to a value that differs from the registry key is
|
|
121
|
+
* harmless but confusing — prefer keeping them aligned or omitting `name`
|
|
122
|
+
* entirely.
|
|
123
|
+
*/
|
|
57
124
|
name?: string;
|
|
58
125
|
/** System prompt body. For markdown-loaded agents this is the file body. */
|
|
59
126
|
instructions: string;
|
|
@@ -63,8 +130,18 @@ interface AgentDefinition {
|
|
|
63
130
|
* falls back to the plugin's `defaultModel`.
|
|
64
131
|
*/
|
|
65
132
|
model?: AgentAdapter | Promise<AgentAdapter> | string;
|
|
66
|
-
/**
|
|
67
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Per-agent tool record. Key is the LLM-visible tool-call name.
|
|
135
|
+
*
|
|
136
|
+
* Accepts either a plain record (for agents that only use inline tools)
|
|
137
|
+
* or a function `(plugins) => Record<string, AgentTool>` that receives
|
|
138
|
+
* the typed {@link Plugins} map and returns a tool record (for agents
|
|
139
|
+
* that pull tools from registered plugins).
|
|
140
|
+
*
|
|
141
|
+
* The function is invoked once at agent setup; the result is cached.
|
|
142
|
+
* Don't put per-request logic in there.
|
|
143
|
+
*/
|
|
144
|
+
tools?: AgentTools | AgentToolsFn;
|
|
68
145
|
/** Sub-agents, exposed as `agent-<key>` tools on this agent. */
|
|
69
146
|
agents?: Record<string, AgentDefinition>;
|
|
70
147
|
/** Override the plugin's baseSystemPrompt for this agent only. */
|
|
@@ -86,7 +163,8 @@ interface AgentDefinition {
|
|
|
86
163
|
* with no explicit `tools:` declaration receive every registered ToolProvider
|
|
87
164
|
* plugin tool whose author marked `autoInheritable: true`. Tools without that
|
|
88
165
|
* flag — destructive, state-mutating, or privilege-sensitive — never spread
|
|
89
|
-
* automatically and must be wired via `tools
|
|
166
|
+
* automatically and must be wired via `tools:` (object or function form in
|
|
167
|
+
* code, `plugin:NAME` entries in markdown frontmatter).
|
|
90
168
|
*
|
|
91
169
|
* Defaults are `false` for both origins (safe-by-default): developers must
|
|
92
170
|
* consciously opt an origin in to any auto-inherit behaviour.
|
|
@@ -122,14 +200,21 @@ interface AgentsPluginConfig extends BasePluginConfig {
|
|
|
122
200
|
*/
|
|
123
201
|
mcp?: McpHostPolicyConfig;
|
|
124
202
|
/**
|
|
125
|
-
* Human-in-the-loop approval gate for
|
|
203
|
+
* Human-in-the-loop approval gate for mutating tool calls. When enabled
|
|
126
204
|
* (the default), the agents plugin emits an `appkit.approval_pending` SSE
|
|
127
|
-
* event before executing any tool
|
|
128
|
-
*
|
|
129
|
-
*
|
|
205
|
+
* event before executing any tool whose annotation flags it as mutating —
|
|
206
|
+
* `effect: "write" | "update" | "destructive"` (preferred) or the legacy
|
|
207
|
+
* `destructive: true` boolean — and waits for a `POST /chat/approve`
|
|
208
|
+
* decision from the same user who initiated the stream. A missing decision
|
|
209
|
+
* after `timeoutMs` auto-denies the call.
|
|
130
210
|
*/
|
|
131
211
|
approval?: {
|
|
132
|
-
/**
|
|
212
|
+
/**
|
|
213
|
+
* Require human approval for tools that mutate state. Triggered by
|
|
214
|
+
* `effect: "write" | "update" | "destructive"` (preferred) or the legacy
|
|
215
|
+
* `destructive: true` boolean. Default: `true`.
|
|
216
|
+
*/
|
|
217
|
+
requireForDestructive?: boolean; /** Milliseconds to wait before auto-denying. Default: 60_000. */
|
|
133
218
|
timeoutMs?: number;
|
|
134
219
|
};
|
|
135
220
|
/**
|
|
@@ -210,5 +295,5 @@ interface RegisteredAgent {
|
|
|
210
295
|
*/
|
|
211
296
|
declare function isToolkitEntry(value: unknown): value is ToolkitEntry;
|
|
212
297
|
//#endregion
|
|
213
|
-
export { AgentDefinition, AgentTool, AgentsPluginConfig, AutoInheritToolsConfig, BaseSystemPromptOption, PromptContext, RegisteredAgent, ResolvedToolEntry, ToolkitEntry, ToolkitOptions, isToolkitEntry };
|
|
298
|
+
export { AgentDefinition, AgentTool, AgentTools, AgentToolsFn, AgentsPluginConfig, AutoInheritToolsConfig, BaseSystemPromptOption, PluginToolkitProvider, Plugins, PromptContext, RegisteredAgent, ResolvedToolEntry, ToolkitEntry, ToolkitOptions, isToolkitEntry };
|
|
214
299
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/core/agent/types.ts"],"mappings":";;;;;;;;;;;;;;AAiBA;UAAiB,YAAA;EAAA,SACN,YAAA;EACT,UAAA;EACA,SAAA;EACA,GAAA,EAAK,mBAAA;EACL,WAAA,GAAc,eAAA;EADd;;;;;;EAQA,eAAA;AAAA;;;;;;KAQU,SAAA,GAAY,YAAA,GAAe,UAAA,GAAa,YAAA;AAAA,UAEnC,cAAA;EAFO;EAItB,MAAA;EAJkD;EAMlD,IAAA;EAN8D;EAQ9D,MAAA;EAN6B;EAQ7B,MAAA,GAAS,MAAA;AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/core/agent/types.ts"],"mappings":";;;;;;;;;;;;;;AAiBA;UAAiB,YAAA;EAAA,SACN,YAAA;EACT,UAAA;EACA,SAAA;EACA,GAAA,EAAK,mBAAA;EACL,WAAA,GAAc,eAAA;EADd;;;;;;EAQA,eAAA;AAAA;;;;;;KAQU,SAAA,GAAY,YAAA,GAAe,UAAA,GAAa,YAAA;AAAA,UAEnC,cAAA;EAFO;EAItB,MAAA;EAJkD;EAMlD,IAAA;EAN8D;EAQ9D,MAAA;EAN6B;EAQ7B,MAAA,GAAS,MAAA;AAAA;;;;;;;;UAUM,qBAAA;EACf,OAAA,CAAQ,IAAA,GAAO,cAAA,GAAiB,MAAA,SAAe,YAAA;AAAA;;;;;;;;;;;;;AA2BjD;;;;;AAKA;;;;;;;KALY,OAAA,GAAU,MAAA,SAAe,qBAAA;;AAWrC;;UANiB,aAAA;EACf,SAAA;EACA,WAAA;EACA,SAAA;AAAA;AAAA,KAGU,sBAAA,sBAGN,GAAA,EAAK,aAAA;;;AAiBX;;KAXY,UAAA,GAAa,MAAA,SAAe,SAAA;;;;;;;AAaxC;;;KAFY,YAAA,IAAgB,OAAA,EAAS,OAAA,KAAY,UAAA;AAAA,UAEhC,eAAA;EA2BQ;;;;;;;;;;;;;;;;;;EARvB,IAAA;EAsBwB;EApBxB,YAAA;EAsBmB;;;;;EAhBnB,KAAA,GAAQ,YAAA,GAAe,OAAA,CAAQ,YAAA;EAyChB;;;;;AAOjB;;;;;;EApCE,KAAA,GAAQ,UAAA,GAAa,YAAA;EA4CS;EA1C9B,MAAA,GAAS,MAAA,SAAe,eAAA;EA4ChB;EA1CR,gBAAA,GAAmB,sBAAA;EACnB,QAAA;EACA,SAAA;EAqDM;;;;;;;;EA5CN,SAAA;AAAA;;;;;;;;;;;;UAce,sBAAA;EAuBI;EArBnB,IAAA;EA4BM;EA1BN,IAAA;AAAA;AAAA,UAGe,kBAAA,SAA2B,gBAAA;EAmD1C;EAjDA,GAAA;EA6DE;EA3DF,MAAA,GAAS,MAAA,SAAe,eAAA;EA8EtB;EA5EF,YAAA;EA4EmB;EA1EnB,YAAA,GAAe,YAAA,GAAe,OAAA,CAAQ,YAAA;EA+EX;EA7E3B,KAAA,GAAQ,MAAA,SAAe,SAAA;EAkFd;EAhFT,gBAAA,aAA6B,sBAAA;EAqFpB;EAnFT,WAAA,GAAc,WAAA;EA6FL;EA3FT,gBAAA,GAAmB,sBAAA;EA2FS;;;;;;EApF5B,GAAA,GAAM,mBAAA;EAyEF;;;;;;;;;EA/DJ,QAAA;IA0EI;;;;AAGN;IAvEI,qBAAA,YAuE4B;IArE5B,SAAA;EAAA;EAyES;;;;;;;;EA/DX,MAAA;IA+DW;;;;;IAzDT,2BAAA;IA8DF;;;AAOF;;IA/DI,YAAA;IA+DiE;;;;;IAzDjE,gBAAA;;;;;;;;;;;;;IAaA,iBAAA;EAAA;AAAA;;KAKQ,iBAAA;EAEN,MAAA;EACA,UAAA;EACA,SAAA;EACA,GAAA,EAAK,mBAAA;AAAA;EAGL,MAAA;EACA,YAAA,EAAc,YAAA;EACd,GAAA,EAAK,mBAAA;AAAA;EAGL,MAAA;EACA,WAAA;EACA,GAAA,EAAK,mBAAA;AAAA;EAGL,MAAA;EACA,SAAA;EACA,GAAA,EAAK,mBAAA;AAAA;AAAA,UAGM,eAAA;EACf,IAAA;EACA,YAAA;EACA,OAAA,EAAS,YAAA;EACT,SAAA,EAAW,GAAA,SAAY,iBAAA;EACvB,gBAAA,GAAmB,sBAAA;EACnB,QAAA;EACA,SAAA;;EAEA,SAAA;AAAA;;;;;iBAOc,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,YAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/core/agent/types.ts"],"sourcesContent":["import type {\n AgentAdapter,\n AgentToolDefinition,\n BasePluginConfig,\n ThreadStore,\n ToolAnnotations,\n} from \"shared\";\nimport type { McpHostPolicyConfig } from \"../../connectors/mcp\";\nimport type { FunctionTool } from \"./tools/function-tool\";\nimport type { HostedTool } from \"./tools/hosted-tools\";\n\n/**\n * A tool reference produced by a plugin's `.toolkit()` call. The agents plugin\n * recognizes the `__toolkitRef` brand and dispatches tool invocations through\n * `PluginContext.executeTool(req, pluginName, localName, ...)`, preserving\n * OBO (asUser) and telemetry spans.\n */\nexport interface ToolkitEntry {\n readonly __toolkitRef: true;\n pluginName: string;\n localName: string;\n def: AgentToolDefinition;\n annotations?: ToolAnnotations;\n /**\n * Whether this tool is eligible for `autoInheritTools` spreading. Mirrors\n * {@link ToolEntry.autoInheritable} from the source registry so the agents\n * plugin can filter auto-inherited tools without re-walking the provider's\n * internal registry.\n */\n autoInheritable?: boolean;\n}\n\n/**\n * Any tool an agent can invoke: inline function tools (`tool()`), hosted MCP\n * tools (`mcpServer()` / raw hosted), or toolkit references from plugins\n * (`analytics().toolkit()`).\n */\nexport type AgentTool = FunctionTool | HostedTool | ToolkitEntry;\n\nexport interface ToolkitOptions {\n /** Key prefix to prepend to each tool's local name. Defaults to `${pluginName}.`. */\n prefix?: string;\n /** Only include tools whose local name matches one of these. */\n only?: string[];\n /** Exclude tools whose local name matches one of these. */\n except?: string[];\n /** Remap specific local names to different keys (applied after prefix). */\n rename?: Record<string, string>;\n}\n\n/**\n * Context passed to `baseSystemPrompt` callbacks.\n */\nexport interface PromptContext {\n agentName: string;\n pluginNames: string[];\n toolNames: string[];\n}\n\nexport type BaseSystemPromptOption =\n | false\n | string\n | ((ctx: PromptContext) => string);\n\nexport interface AgentDefinition {\n /** Filled in from the enclosing key when used in `agents: { foo: def }`. */\n name?: string;\n /** System prompt body. For markdown-loaded agents this is the file body. */\n instructions: string;\n /**\n * Model adapter (or endpoint-name string sugar for\n * `DatabricksAdapter.fromServingEndpoint({ endpointName })`). Optional —\n * falls back to the plugin's `defaultModel`.\n */\n model?: AgentAdapter | Promise<AgentAdapter> | string;\n /** Per-agent tool record. Key is the LLM-visible tool-call name. */\n tools?: Record<string, AgentTool>;\n /** Sub-agents, exposed as `agent-<key>` tools on this agent. */\n agents?: Record<string, AgentDefinition>;\n /** Override the plugin's baseSystemPrompt for this agent only. */\n baseSystemPrompt?: BaseSystemPromptOption;\n maxSteps?: number;\n maxTokens?: number;\n /**\n * When true, the thread used for a chat request against this agent is\n * deleted from `ThreadStore` after the stream completes (success or\n * failure). Use for stateless one-shot agents — e.g. autocomplete, where\n * each request is independent and retaining history would both poison\n * future calls and accumulate unbounded state in the default\n * `InMemoryThreadStore`. Defaults to `false`.\n */\n ephemeral?: boolean;\n}\n\n/**\n * Auto-inherit configuration. When enabled for a given agent origin, agents\n * with no explicit `tools:` declaration receive every registered ToolProvider\n * plugin tool whose author marked `autoInheritable: true`. Tools without that\n * flag — destructive, state-mutating, or privilege-sensitive — never spread\n * automatically and must be wired via `tools:`, `toolkits:`, or `fromPlugin`.\n *\n * Defaults are `false` for both origins (safe-by-default): developers must\n * consciously opt an origin in to any auto-inherit behaviour.\n */\nexport interface AutoInheritToolsConfig {\n /** Default for agents loaded from markdown files. Default: `false`. */\n file?: boolean;\n /** Default for code-defined agents (via `agents: { foo: createAgent(...) }`). Default: `false`. */\n code?: boolean;\n}\n\nexport interface AgentsPluginConfig extends BasePluginConfig {\n /** Directory of agent packages (`<id>/agent.md` each). Default `./config/agents`. Set to `false` to disable. */\n dir?: string | false;\n /** Code-defined agents, merged with file-loaded ones (code wins on key collision). */\n agents?: Record<string, AgentDefinition>;\n /** Agent used when clients don't specify one. Defaults to the first-registered agent or the file with `default: true` frontmatter. */\n defaultAgent?: string;\n /** Default model for agents that don't specify their own (in code or frontmatter). */\n defaultModel?: AgentAdapter | Promise<AgentAdapter> | string;\n /** Ambient tool library. Keys may be referenced by markdown frontmatter via `tools: [key1, key2]`. */\n tools?: Record<string, AgentTool>;\n /** Whether to auto-inherit every ToolProvider plugin's toolkit. Accepts a boolean shorthand. */\n autoInheritTools?: boolean | AutoInheritToolsConfig;\n /** Persistent thread store. Default: in-memory. */\n threadStore?: ThreadStore;\n /** Customize or disable the AppKit base system prompt. */\n baseSystemPrompt?: BaseSystemPromptOption;\n /**\n * MCP server host policy. By default only same-origin Databricks workspace\n * URLs may be used as MCP endpoints; custom hosts must be explicitly\n * allowlisted here. Workspace credentials (SP / OBO) are never forwarded\n * to non-workspace hosts.\n */\n mcp?: McpHostPolicyConfig;\n /**\n * Human-in-the-loop approval gate for destructive tool calls. When enabled\n * (the default), the agents plugin emits an `appkit.approval_pending` SSE\n * event before executing any tool annotated `destructive: true` and waits\n * for a `POST /chat/approve` decision from the same user who initiated the\n * stream. A missing decision after `timeoutMs` auto-denies the call.\n */\n approval?: {\n /** Require human approval for tools annotated `destructive: true`. Default: `true`. */\n requireForDestructive?: boolean;\n /** Milliseconds to wait before auto-denying. Default: 60_000. */\n timeoutMs?: number;\n };\n /**\n * Runtime resource limits applied during agent execution. Defaults are\n * tuned to protect a single-instance deployment from a misbehaving user or\n * a runaway prompt injection; tighten or relax as appropriate for the\n * deployment's scale and trust model. Request-body caps (chat message\n * size, invocations input size / length) are enforced statically by the\n * Zod schemas and are not configurable here.\n */\n limits?: {\n /**\n * Max concurrent chat streams a single user may have open. Subsequent\n * `POST /chat` requests from that user while at-limit are rejected with\n * HTTP 429. Default: `5`.\n */\n maxConcurrentStreamsPerUser?: number;\n /**\n * Max tool invocations per agent run (across the full tool-call graph,\n * including sub-agent invocations). A run that exceeds the budget is\n * aborted with a terminal error event. Default: `50`.\n */\n maxToolCalls?: number;\n /**\n * Max sub-agent recursion depth. Protects against a prompt-injected\n * agent that delegates to a sub-agent which in turn delegates back to\n * itself (directly or transitively). Default: `3`.\n */\n maxSubAgentDepth?: number;\n /**\n * Per-call timeout for tools dispatched through `PluginContext`\n * (toolkit-routed tools — analytics SQL warehouse queries, Genie\n * messages, Lakebase queries). Independent of `maxToolCalls`: the\n * budget caps how many tools fire per run, this caps how long any\n * single tool call may run. The signal handed to plugin tool\n * implementations combines this timeout with the parent stream's\n * abort signal via `AbortSignal.any`. Function and MCP tools have\n * their own timeouts in their respective adapters and ignore this\n * setting. Default: `300_000` (5 minutes) — generous enough for cold\n * SQL Warehouse round-trips and long Genie conversations.\n */\n toolCallTimeoutMs?: number;\n };\n}\n\n/** Internal tool-index entry after a tool record has been resolved to a dispatchable form. */\nexport type ResolvedToolEntry =\n | {\n source: \"toolkit\";\n pluginName: string;\n localName: string;\n def: AgentToolDefinition;\n }\n | {\n source: \"function\";\n functionTool: FunctionTool;\n def: AgentToolDefinition;\n }\n | {\n source: \"mcp\";\n mcpToolName: string;\n def: AgentToolDefinition;\n }\n | {\n source: \"subagent\";\n agentName: string;\n def: AgentToolDefinition;\n };\n\nexport interface RegisteredAgent {\n name: string;\n instructions: string;\n adapter: AgentAdapter;\n toolIndex: Map<string, ResolvedToolEntry>;\n baseSystemPrompt?: BaseSystemPromptOption;\n maxSteps?: number;\n maxTokens?: number;\n /** Mirrors `AgentDefinition.ephemeral` — skip thread persistence. */\n ephemeral?: boolean;\n}\n\n/**\n * Type guard for `ToolkitEntry` — used by the agents plugin to differentiate\n * toolkit references from inline tools in a mixed `tools` record.\n */\nexport function isToolkitEntry(value: unknown): value is ToolkitEntry {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { __toolkitRef?: unknown }).__toolkitRef === true\n );\n}\n"],"mappings":";;;;;AAuOA,SAAgB,eAAe,OAAuC;AACpE,QACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/core/agent/types.ts"],"sourcesContent":["import type {\n AgentAdapter,\n AgentToolDefinition,\n BasePluginConfig,\n ThreadStore,\n ToolAnnotations,\n} from \"shared\";\nimport type { McpHostPolicyConfig } from \"../../connectors/mcp\";\nimport type { FunctionTool } from \"./tools/function-tool\";\nimport type { HostedTool } from \"./tools/hosted-tools\";\n\n/**\n * A tool reference produced by a plugin's `.toolkit()` call. The agents plugin\n * recognizes the `__toolkitRef` brand and dispatches tool invocations through\n * `PluginContext.executeTool(req, pluginName, localName, ...)`, preserving\n * OBO (asUser) and telemetry spans.\n */\nexport interface ToolkitEntry {\n readonly __toolkitRef: true;\n pluginName: string;\n localName: string;\n def: AgentToolDefinition;\n annotations?: ToolAnnotations;\n /**\n * Whether this tool is eligible for `autoInheritTools` spreading. Mirrors\n * {@link ToolEntry.autoInheritable} from the source registry so the agents\n * plugin can filter auto-inherited tools without re-walking the provider's\n * internal registry.\n */\n autoInheritable?: boolean;\n}\n\n/**\n * Any tool an agent can invoke: inline function tools (`tool()`), hosted MCP\n * tools (`mcpServer()` / raw hosted), or toolkit references from plugins\n * (`analytics().toolkit()`).\n */\nexport type AgentTool = FunctionTool | HostedTool | ToolkitEntry;\n\nexport interface ToolkitOptions {\n /** Key prefix to prepend to each tool's local name. Defaults to `${pluginName}.`. */\n prefix?: string;\n /** Only include tools whose local name matches one of these. */\n only?: string[];\n /** Exclude tools whose local name matches one of these. */\n except?: string[];\n /** Remap specific local names to different keys (applied after prefix). */\n rename?: Record<string, string>;\n}\n\n/**\n * Minimum shape every entry in the {@link Plugins} map must expose. Core\n * plugins (analytics, files, genie, lakebase) implement this directly via\n * their `.toolkit()` method. The agents plugin and standalone `runAgent`\n * synthesize this shape for any registered plugin that doesn't implement\n * `.toolkit()` directly (falling back to `getAgentTools()` walking).\n */\nexport interface PluginToolkitProvider {\n toolkit(opts?: ToolkitOptions): Record<string, ToolkitEntry>;\n}\n\n/**\n * Plugin map passed to the function form of {@link AgentDefinition.tools}.\n * Each entry exposes a `.toolkit(opts?)` method that returns a record of\n * {@link ToolkitEntry} markers ready to be spread into a tool record.\n *\n * AppKit does not statically know which plugins the surrounding\n * `createApp` will register, so this is a plain string-keyed record.\n * Refer to plugins by the name used in `createApp({ plugins: [...] })`;\n * unknown names resolve to `undefined` at runtime.\n *\n * @example\n * ```ts\n * const support = createAgent({\n * instructions: \"...\",\n * tools(plugins) {\n * return {\n * get_weather: tool({ ... }),\n * ...plugins.analytics.toolkit(),\n * ...plugins.files.toolkit({ only: [\"uploads.read\"] }),\n * };\n * },\n * });\n * ```\n */\nexport type Plugins = Record<string, PluginToolkitProvider>;\n\n/**\n * Context passed to `baseSystemPrompt` callbacks.\n */\nexport interface PromptContext {\n agentName: string;\n pluginNames: string[];\n toolNames: string[];\n}\n\nexport type BaseSystemPromptOption =\n | false\n | string\n | ((ctx: PromptContext) => string);\n\n/**\n * Per-agent tool record. String keys map to inline tools, toolkit entries,\n * hosted tools, etc.\n */\nexport type AgentTools = Record<string, AgentTool>;\n\n/**\n * Function form of `AgentDefinition.tools`. Receives the typed\n * {@link Plugins} map and returns a tool record. Invoked exactly once at\n * setup (or once per `runAgent` call in standalone mode); the result is\n * cached as the agent's resolved tool record.\n *\n * Use the function form when an agent needs tools from registered plugins.\n * The bare object form is fine when an agent only uses inline tools.\n */\nexport type AgentToolsFn = (plugins: Plugins) => AgentTools;\n\nexport interface AgentDefinition {\n /**\n * Stable identifier for the agent. **Optional and informational** —\n * when the definition is registered via `agents: { foo: def }` (code) or\n * lives at `config/agents/<id>/agent.md` (markdown), the **registry key\n * always wins** and `name` is ignored. The agent will be reachable as\n * `foo` (or `<id>`) regardless of what this field contains.\n *\n * Set `name` when:\n * - Running standalone via `runAgent({ agent: def })`, where there is\n * no enclosing key. The runtime uses it for the agent's slot in\n * error messages and OTel spans.\n * - Building a definition that may be passed to either form and you\n * want a consistent fallback label.\n *\n * Setting `name` to a value that differs from the registry key is\n * harmless but confusing — prefer keeping them aligned or omitting `name`\n * entirely.\n */\n name?: string;\n /** System prompt body. For markdown-loaded agents this is the file body. */\n instructions: string;\n /**\n * Model adapter (or endpoint-name string sugar for\n * `DatabricksAdapter.fromServingEndpoint({ endpointName })`). Optional —\n * falls back to the plugin's `defaultModel`.\n */\n model?: AgentAdapter | Promise<AgentAdapter> | string;\n /**\n * Per-agent tool record. Key is the LLM-visible tool-call name.\n *\n * Accepts either a plain record (for agents that only use inline tools)\n * or a function `(plugins) => Record<string, AgentTool>` that receives\n * the typed {@link Plugins} map and returns a tool record (for agents\n * that pull tools from registered plugins).\n *\n * The function is invoked once at agent setup; the result is cached.\n * Don't put per-request logic in there.\n */\n tools?: AgentTools | AgentToolsFn;\n /** Sub-agents, exposed as `agent-<key>` tools on this agent. */\n agents?: Record<string, AgentDefinition>;\n /** Override the plugin's baseSystemPrompt for this agent only. */\n baseSystemPrompt?: BaseSystemPromptOption;\n maxSteps?: number;\n maxTokens?: number;\n /**\n * When true, the thread used for a chat request against this agent is\n * deleted from `ThreadStore` after the stream completes (success or\n * failure). Use for stateless one-shot agents — e.g. autocomplete, where\n * each request is independent and retaining history would both poison\n * future calls and accumulate unbounded state in the default\n * `InMemoryThreadStore`. Defaults to `false`.\n */\n ephemeral?: boolean;\n}\n\n/**\n * Auto-inherit configuration. When enabled for a given agent origin, agents\n * with no explicit `tools:` declaration receive every registered ToolProvider\n * plugin tool whose author marked `autoInheritable: true`. Tools without that\n * flag — destructive, state-mutating, or privilege-sensitive — never spread\n * automatically and must be wired via `tools:` (object or function form in\n * code, `plugin:NAME` entries in markdown frontmatter).\n *\n * Defaults are `false` for both origins (safe-by-default): developers must\n * consciously opt an origin in to any auto-inherit behaviour.\n */\nexport interface AutoInheritToolsConfig {\n /** Default for agents loaded from markdown files. Default: `false`. */\n file?: boolean;\n /** Default for code-defined agents (via `agents: { foo: createAgent(...) }`). Default: `false`. */\n code?: boolean;\n}\n\nexport interface AgentsPluginConfig extends BasePluginConfig {\n /** Directory of agent packages (`<id>/agent.md` each). Default `./config/agents`. Set to `false` to disable. */\n dir?: string | false;\n /** Code-defined agents, merged with file-loaded ones (code wins on key collision). */\n agents?: Record<string, AgentDefinition>;\n /** Agent used when clients don't specify one. Defaults to the first-registered agent or the file with `default: true` frontmatter. */\n defaultAgent?: string;\n /** Default model for agents that don't specify their own (in code or frontmatter). */\n defaultModel?: AgentAdapter | Promise<AgentAdapter> | string;\n /** Ambient tool library. Keys may be referenced by markdown frontmatter via `tools: [key1, key2]`. */\n tools?: Record<string, AgentTool>;\n /** Whether to auto-inherit every ToolProvider plugin's toolkit. Accepts a boolean shorthand. */\n autoInheritTools?: boolean | AutoInheritToolsConfig;\n /** Persistent thread store. Default: in-memory. */\n threadStore?: ThreadStore;\n /** Customize or disable the AppKit base system prompt. */\n baseSystemPrompt?: BaseSystemPromptOption;\n /**\n * MCP server host policy. By default only same-origin Databricks workspace\n * URLs may be used as MCP endpoints; custom hosts must be explicitly\n * allowlisted here. Workspace credentials (SP / OBO) are never forwarded\n * to non-workspace hosts.\n */\n mcp?: McpHostPolicyConfig;\n /**\n * Human-in-the-loop approval gate for mutating tool calls. When enabled\n * (the default), the agents plugin emits an `appkit.approval_pending` SSE\n * event before executing any tool whose annotation flags it as mutating —\n * `effect: \"write\" | \"update\" | \"destructive\"` (preferred) or the legacy\n * `destructive: true` boolean — and waits for a `POST /chat/approve`\n * decision from the same user who initiated the stream. A missing decision\n * after `timeoutMs` auto-denies the call.\n */\n approval?: {\n /**\n * Require human approval for tools that mutate state. Triggered by\n * `effect: \"write\" | \"update\" | \"destructive\"` (preferred) or the legacy\n * `destructive: true` boolean. Default: `true`.\n */\n requireForDestructive?: boolean;\n /** Milliseconds to wait before auto-denying. Default: 60_000. */\n timeoutMs?: number;\n };\n /**\n * Runtime resource limits applied during agent execution. Defaults are\n * tuned to protect a single-instance deployment from a misbehaving user or\n * a runaway prompt injection; tighten or relax as appropriate for the\n * deployment's scale and trust model. Request-body caps (chat message\n * size, invocations input size / length) are enforced statically by the\n * Zod schemas and are not configurable here.\n */\n limits?: {\n /**\n * Max concurrent chat streams a single user may have open. Subsequent\n * `POST /chat` requests from that user while at-limit are rejected with\n * HTTP 429. Default: `5`.\n */\n maxConcurrentStreamsPerUser?: number;\n /**\n * Max tool invocations per agent run (across the full tool-call graph,\n * including sub-agent invocations). A run that exceeds the budget is\n * aborted with a terminal error event. Default: `50`.\n */\n maxToolCalls?: number;\n /**\n * Max sub-agent recursion depth. Protects against a prompt-injected\n * agent that delegates to a sub-agent which in turn delegates back to\n * itself (directly or transitively). Default: `3`.\n */\n maxSubAgentDepth?: number;\n /**\n * Per-call timeout for tools dispatched through `PluginContext`\n * (toolkit-routed tools — analytics SQL warehouse queries, Genie\n * messages, Lakebase queries). Independent of `maxToolCalls`: the\n * budget caps how many tools fire per run, this caps how long any\n * single tool call may run. The signal handed to plugin tool\n * implementations combines this timeout with the parent stream's\n * abort signal via `AbortSignal.any`. Function and MCP tools have\n * their own timeouts in their respective adapters and ignore this\n * setting. Default: `300_000` (5 minutes) — generous enough for cold\n * SQL Warehouse round-trips and long Genie conversations.\n */\n toolCallTimeoutMs?: number;\n };\n}\n\n/** Internal tool-index entry after a tool record has been resolved to a dispatchable form. */\nexport type ResolvedToolEntry =\n | {\n source: \"toolkit\";\n pluginName: string;\n localName: string;\n def: AgentToolDefinition;\n }\n | {\n source: \"function\";\n functionTool: FunctionTool;\n def: AgentToolDefinition;\n }\n | {\n source: \"mcp\";\n mcpToolName: string;\n def: AgentToolDefinition;\n }\n | {\n source: \"subagent\";\n agentName: string;\n def: AgentToolDefinition;\n };\n\nexport interface RegisteredAgent {\n name: string;\n instructions: string;\n adapter: AgentAdapter;\n toolIndex: Map<string, ResolvedToolEntry>;\n baseSystemPrompt?: BaseSystemPromptOption;\n maxSteps?: number;\n maxTokens?: number;\n /** Mirrors `AgentDefinition.ephemeral` — skip thread persistence. */\n ephemeral?: boolean;\n}\n\n/**\n * Type guard for `ToolkitEntry` — used by the agents plugin to differentiate\n * toolkit references from inline tools in a mixed `tools` record.\n */\nexport function isToolkitEntry(value: unknown): value is ToolkitEntry {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { __toolkitRef?: unknown }).__toolkitRef === true\n );\n}\n"],"mappings":";;;;;AA+TA,SAAgB,eAAe,OAAuC;AACpE,QACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB"}
|
package/dist/plugin/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { ToPlugin } from "../shared/src/plugin.js";
|
|
|
2
2
|
import "../shared/src/index.js";
|
|
3
3
|
import { ExecutionResult } from "./execution-result.js";
|
|
4
4
|
import { Plugin } from "./plugin.js";
|
|
5
|
-
import {
|
|
5
|
+
import { toPlugin } from "./to-plugin.js";
|
|
@@ -2,24 +2,14 @@ import { PluginConstructor, ToPlugin } from "../shared/src/plugin.js";
|
|
|
2
2
|
import "../shared/src/index.js";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin/to-plugin.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Factory function produced by {@link toPlugin}. Carries a static
|
|
7
|
-
* `pluginName` field so tooling (e.g. `fromPlugin`) can identify which
|
|
8
|
-
* plugin a factory references without constructing an instance.
|
|
9
|
-
*/
|
|
10
|
-
type NamedPluginFactory<Name extends string = string> = {
|
|
11
|
-
readonly pluginName: Name;
|
|
12
|
-
};
|
|
13
5
|
/**
|
|
14
6
|
* Wraps a plugin class so it can be passed to `createApp` with optional
|
|
15
7
|
* config. Infers the config type from the constructor and the plugin name
|
|
16
|
-
* from the static `manifest.name` property
|
|
17
|
-
* the returned factory function so `fromPlugin` can identify the plugin
|
|
18
|
-
* without needing to construct it.
|
|
8
|
+
* from the static `manifest.name` property.
|
|
19
9
|
*
|
|
20
10
|
* @internal
|
|
21
11
|
*/
|
|
22
|
-
declare function toPlugin<T extends PluginConstructor>(plugin: T): ToPlugin<T, ConstructorParameters<T>[0], T["manifest"]["name"]
|
|
12
|
+
declare function toPlugin<T extends PluginConstructor>(plugin: T): ToPlugin<T, ConstructorParameters<T>[0], T["manifest"]["name"]>;
|
|
23
13
|
//#endregion
|
|
24
|
-
export {
|
|
14
|
+
export { toPlugin };
|
|
25
15
|
//# sourceMappingURL=to-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-plugin.d.ts","names":[],"sources":["../../src/plugin/to-plugin.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"to-plugin.d.ts","names":[],"sources":["../../src/plugin/to-plugin.ts"],"mappings":";;;;;;;AASA;;;;iBAAgB,QAAA,WAAmB,iBAAA,CAAA,CACjC,MAAA,EAAQ,CAAA,GACP,QAAA,CAAS,CAAA,EAAG,qBAAA,CAAsB,CAAA,MAAO,CAAA"}
|
package/dist/plugin/to-plugin.js
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Wraps a plugin class so it can be passed to `createApp` with optional
|
|
4
4
|
* config. Infers the config type from the constructor and the plugin name
|
|
5
|
-
* from the static `manifest.name` property
|
|
6
|
-
* the returned factory function so `fromPlugin` can identify the plugin
|
|
7
|
-
* without needing to construct it.
|
|
5
|
+
* from the static `manifest.name` property.
|
|
8
6
|
*
|
|
9
7
|
* @internal
|
|
10
8
|
*/
|
|
@@ -15,11 +13,6 @@ function toPlugin(plugin) {
|
|
|
15
13
|
config,
|
|
16
14
|
name: pluginName
|
|
17
15
|
});
|
|
18
|
-
Object.defineProperty(factory, "pluginName", {
|
|
19
|
-
value: pluginName,
|
|
20
|
-
writable: false,
|
|
21
|
-
enumerable: true
|
|
22
|
-
});
|
|
23
16
|
return factory;
|
|
24
17
|
}
|
|
25
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-plugin.js","names":[],"sources":["../../src/plugin/to-plugin.ts"],"sourcesContent":["import type { PluginConstructor, PluginData, ToPlugin } from \"shared\";\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"to-plugin.js","names":[],"sources":["../../src/plugin/to-plugin.ts"],"sourcesContent":["import type { PluginConstructor, PluginData, ToPlugin } from \"shared\";\n\n/**\n * Wraps a plugin class so it can be passed to `createApp` with optional\n * config. Infers the config type from the constructor and the plugin name\n * from the static `manifest.name` property.\n *\n * @internal\n */\nexport function toPlugin<T extends PluginConstructor>(\n plugin: T,\n): ToPlugin<T, ConstructorParameters<T>[0], T[\"manifest\"][\"name\"]> {\n type Config = ConstructorParameters<T>[0];\n type Name = T[\"manifest\"][\"name\"];\n const pluginName = plugin.manifest.name as Name;\n const factory = (\n config: Config = {} as Config,\n ): PluginData<T, Config, Name> => ({\n plugin: plugin as T,\n config: config as Config,\n name: pluginName,\n });\n return factory as ToPlugin<T, Config, Name>;\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,SACd,QACiE;CAGjE,MAAM,aAAa,OAAO,SAAS;CACnC,MAAM,WACJ,SAAiB,EAAE,MACc;EACzB;EACA;EACR,MAAM;EACP;AACD,QAAO"}
|
|
@@ -1,4 +1,186 @@
|
|
|
1
|
+
import { AgentToolDefinition, Thread, ToolProvider } from "../../shared/src/agent.js";
|
|
2
|
+
import { IAppRouter, PluginPhase, ToPlugin } from "../../shared/src/plugin.js";
|
|
1
3
|
import "../../shared/src/index.js";
|
|
2
|
-
import "../../core/agent/types.js";
|
|
4
|
+
import { AgentDefinition, AgentsPluginConfig, RegisteredAgent } from "../../core/agent/types.js";
|
|
5
|
+
import { Plugin } from "../../plugin/plugin.js";
|
|
3
6
|
import "../../plugin/index.js";
|
|
4
|
-
import "../../registry/
|
|
7
|
+
import { PluginManifest } from "../../registry/types.js";
|
|
8
|
+
import "../../registry/index.js";
|
|
9
|
+
|
|
10
|
+
//#region src/plugins/agents/agents.d.ts
|
|
11
|
+
declare class AgentsPlugin extends Plugin implements ToolProvider {
|
|
12
|
+
static manifest: PluginManifest;
|
|
13
|
+
static phase: PluginPhase;
|
|
14
|
+
protected config: AgentsPluginConfig;
|
|
15
|
+
private agents;
|
|
16
|
+
private defaultAgentName;
|
|
17
|
+
private activeStreams;
|
|
18
|
+
/**
|
|
19
|
+
* Per-user stream count, kept in sync with `activeStreams` so the
|
|
20
|
+
* concurrent-stream rate limit check is O(1) instead of O(n) over every
|
|
21
|
+
* active stream on every request. Mutated only via {@link trackStream}
|
|
22
|
+
* and {@link untrackStream}.
|
|
23
|
+
*/
|
|
24
|
+
private userStreamCounts;
|
|
25
|
+
private mcpClient;
|
|
26
|
+
private threadStore;
|
|
27
|
+
private approvalGate;
|
|
28
|
+
constructor(config: AgentsPluginConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Effective approval policy with defaults applied. Memoised so the
|
|
31
|
+
* `timeoutMs` validation warning fires at most once per plugin instance —
|
|
32
|
+
* `resolvedApprovalPolicy` gets hit on every chat stream and a noisy
|
|
33
|
+
* misconfig would otherwise spam the logs.
|
|
34
|
+
*
|
|
35
|
+
* `timeoutMs` is clamped to a 1s floor so a misconfigured value (`0`,
|
|
36
|
+
* negative, or `NaN`) can't degrade into immediate auto-denial of every
|
|
37
|
+
* mutating tool call.
|
|
38
|
+
*/
|
|
39
|
+
private cachedApprovalPolicy;
|
|
40
|
+
private get resolvedApprovalPolicy();
|
|
41
|
+
/** Effective DoS limits with defaults applied. */
|
|
42
|
+
private get resolvedLimits();
|
|
43
|
+
/** Count active streams owned by a given user. O(1). */
|
|
44
|
+
private countUserStreams;
|
|
45
|
+
/**
|
|
46
|
+
* Register a stream for `userId` and bump the per-user counter. Paired
|
|
47
|
+
* with {@link untrackStream}; the two helpers are the only writers to
|
|
48
|
+
* `activeStreams` + `userStreamCounts`, so the counter cannot drift from
|
|
49
|
+
* the map.
|
|
50
|
+
*/
|
|
51
|
+
private trackStream;
|
|
52
|
+
/**
|
|
53
|
+
* Remove a stream from the active map and decrement the per-user
|
|
54
|
+
* counter. Idempotent — calling twice for the same `requestId` is a
|
|
55
|
+
* no-op (the second call sees no entry and returns early).
|
|
56
|
+
*/
|
|
57
|
+
private untrackStream;
|
|
58
|
+
setup(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Reload agents from the configured directory, preserving code-defined
|
|
61
|
+
* agents. Builds a fresh registry first and only swaps on success — if
|
|
62
|
+
* `loadAgents` throws (malformed markdown, missing tool reference) the
|
|
63
|
+
* existing live registry stays in place and serving requests keep working.
|
|
64
|
+
*/
|
|
65
|
+
reload(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Builds the agent registry into a fresh `Map` without touching live state.
|
|
68
|
+
* Called by both `setup` and `reload`; the latter only swaps the live
|
|
69
|
+
* registry once this resolves successfully (atomic reload).
|
|
70
|
+
*/
|
|
71
|
+
private buildAgentRegistry;
|
|
72
|
+
private resolvedAgentsDir;
|
|
73
|
+
private loadFileDefinitions;
|
|
74
|
+
/**
|
|
75
|
+
* Builds the map of plugin-name → toolkit that the markdown loader consults
|
|
76
|
+
* when resolving `plugin:NAME` entries in the unified `tools:` frontmatter
|
|
77
|
+
* list (and, equivalently, that the code form passes as the `plugins`
|
|
78
|
+
* argument to `tools(plugins) => Record<...>`).
|
|
79
|
+
*/
|
|
80
|
+
private pluginProviderIndex;
|
|
81
|
+
private buildRegisteredAgent;
|
|
82
|
+
private resolveAdapter;
|
|
83
|
+
/**
|
|
84
|
+
* Resolves an agent's tool record into a per-agent dispatch index. Connects
|
|
85
|
+
* hosted tools via MCP client. Applies `autoInheritTools` defaults when the
|
|
86
|
+
* definition has no declared tools/agents.
|
|
87
|
+
*/
|
|
88
|
+
private buildToolIndex;
|
|
89
|
+
/**
|
|
90
|
+
* Resolves an `AgentDefinition.tools` field to a plain tool record. The
|
|
91
|
+
* function form is invoked exactly once at agent setup with the typed
|
|
92
|
+
* {@link Plugins} map; the result replaces the function reference for the
|
|
93
|
+
* remainder of the registered agent's lifetime.
|
|
94
|
+
*
|
|
95
|
+
* Plain object form is returned as-is; an undefined `tools` returns an
|
|
96
|
+
* empty record. The function form is wrapped in a try/catch so a thrown
|
|
97
|
+
* callback fails registration with a useful message instead of leaking
|
|
98
|
+
* the raw stack.
|
|
99
|
+
*/
|
|
100
|
+
private resolveDefTools;
|
|
101
|
+
/**
|
|
102
|
+
* Builds the typed {@link Plugins} map passed to the function form of
|
|
103
|
+
* `AgentDefinition.tools`. Each entry exposes the plugin instance directly
|
|
104
|
+
* (so user code can call typed instance methods including `.toolkit()`);
|
|
105
|
+
* plugins missing `.toolkit()` get a synthesized fallback that walks
|
|
106
|
+
* `getAgentTools()` via `resolveToolkitFromProvider`.
|
|
107
|
+
*
|
|
108
|
+
* Wrapped in {@link createPluginsProxy} so that accessing an unknown
|
|
109
|
+
* plugin name throws a named "not registered, Available: ..." error
|
|
110
|
+
* instead of bubbling up a generic `Cannot read properties of undefined`
|
|
111
|
+
* from the agent's `tools(plugins)` callback.
|
|
112
|
+
*/
|
|
113
|
+
private buildPluginsMap;
|
|
114
|
+
private applyAutoInherit;
|
|
115
|
+
private connectHostedTools;
|
|
116
|
+
getAgentTools(): AgentToolDefinition[];
|
|
117
|
+
executeAgentTool(): Promise<unknown>;
|
|
118
|
+
private mountInvocationsRoute;
|
|
119
|
+
injectRoutes(router: IAppRouter): void;
|
|
120
|
+
clientConfig(): Record<string, unknown>;
|
|
121
|
+
private _handleChat;
|
|
122
|
+
private _handleInvocations;
|
|
123
|
+
private _streamAgent;
|
|
124
|
+
/**
|
|
125
|
+
* Dispatch a single tool call from either the top-level adapter or a
|
|
126
|
+
* sub-agent. Centralising this in one method is what makes the budget
|
|
127
|
+
* counter, approval gate, and abort signal observe sub-agent activity:
|
|
128
|
+
* `runSubAgent` reuses the same `runState` and so increments the same
|
|
129
|
+
* counter and emits approval events through the same channel.
|
|
130
|
+
*
|
|
131
|
+
* `depth` is the current sub-agent recursion depth (0 at the top level).
|
|
132
|
+
* It is forwarded to `runSubAgent` when the dispatched entry is itself a
|
|
133
|
+
* sub-agent, so depth limits remain enforced.
|
|
134
|
+
*/
|
|
135
|
+
private dispatchToolCall;
|
|
136
|
+
/**
|
|
137
|
+
* Runs a sub-agent in response to an `agent-<key>` tool call. Returns the
|
|
138
|
+
* concatenated text output to hand back to the parent adapter as the tool
|
|
139
|
+
* result.
|
|
140
|
+
*
|
|
141
|
+
* `depth` starts at 1 for a top-level sub-agent invocation (i.e. the
|
|
142
|
+
* outer `_streamAgent` calls `runSubAgent(..., 1)`) and increments on
|
|
143
|
+
* each nested `runSubAgent` call. Depths exceeding
|
|
144
|
+
* `limits.maxSubAgentDepth` are rejected before any adapter work.
|
|
145
|
+
*
|
|
146
|
+
* Sub-agent tool calls run through `dispatchToolCall` with the same
|
|
147
|
+
* `runState` as the parent — the budget counter and approval gate are
|
|
148
|
+
* therefore enforced for every nested call, not only at the top level.
|
|
149
|
+
*/
|
|
150
|
+
private runSubAgent;
|
|
151
|
+
private _handleCancel;
|
|
152
|
+
private _handleApprove;
|
|
153
|
+
private _handleListThreads;
|
|
154
|
+
private _handleGetThread;
|
|
155
|
+
private _handleDeleteThread;
|
|
156
|
+
private resolveAgent;
|
|
157
|
+
private printRegistry;
|
|
158
|
+
shutdown(): Promise<void>;
|
|
159
|
+
exports(): {
|
|
160
|
+
register: (name: string, def: AgentDefinition) => Promise<void>;
|
|
161
|
+
list: () => string[];
|
|
162
|
+
get: (name: string) => RegisteredAgent | null;
|
|
163
|
+
reload: () => Promise<void>;
|
|
164
|
+
getDefault: () => string | null;
|
|
165
|
+
getThreads: (userId: string) => Promise<Thread[]>;
|
|
166
|
+
};
|
|
167
|
+
private registerCodeAgent;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Plugin factory for the agents plugin. Reads `config/agents/*.md` by default,
|
|
171
|
+
* resolves toolkits/tools from registered plugins, exposes `appkit.agents.*`
|
|
172
|
+
* runtime API and mounts `/invocations`.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { agents, analytics, createApp, server } from "@databricks/appkit";
|
|
177
|
+
*
|
|
178
|
+
* await createApp({
|
|
179
|
+
* plugins: [server(), analytics(), agents()],
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare const agents: ToPlugin<typeof AgentsPlugin, AgentsPluginConfig, string>;
|
|
184
|
+
//#endregion
|
|
185
|
+
export { AgentsPlugin, agents };
|
|
186
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","names":[],"sources":["../../../src/plugins/agents/agents.ts"],"mappings":";;;;;;;;;;cAkIa,YAAA,SAAqB,MAAA,YAAkB,YAAA;EAAA,OAC3C,QAAA,EAAuB,cAAA;EAAA,OACvB,KAAA,EAAO,WAAA;EAAA,UAEI,MAAA,EAAQ,kBAAA;EAAA,QAElB,MAAA;EAAA,QACA,gBAAA;EAAA,QACA,aAAA;EARgB;;;;;;EAAA,QAkBhB,gBAAA;EAAA,QACA,SAAA;EAAA,QACA,WAAA;EAAA,QACA,YAAA;cAEI,MAAA,EAAQ,kBAAA;EAgqBJ;;;;;;;;;;EAAA,QAjoBR,oBAAA;EAAA,YAKI,sBAAA,CAAA;EA3DoB;EAAA,YAqFpB,cAAA,CAAA;EApFL;EAAA,QAuGC,gBAAA;EAtGD;;;;;;EAAA,QAgHC,WAAA;EAhGA;;;;;EAAA,QAiHA,aAAA;EAYF,KAAA,CAAA,GAAK,OAAA;EAzFH;;;;;;EAuGF,MAAA,CAAA,GAAU,OAAA;EAdL;;;;;EAAA,QAwCG,kBAAA;EAAA,QAmEN,iBAAA;EAAA,QAMM,mBAAA;EAiEA;;;;;;EAAA,QAvCN,mBAAA;EAAA,QAmBM,oBAAA;EAAA,QAoBA,cAAA;EAmTY;;;;;EAAA,QA7QZ,cAAA;EAgVE;;;;;;;;;;;EAAA,QAhPR,eAAA;EA01BA;;;;;;;;;;;;EAAA,QA9zBA,eAAA;EAAA,QAkBM,gBAAA;EAAA,QA0DA,kBAAA;EAiEd,aAAA,CAAA,GAAiB,mBAAA;EAIX,gBAAA,CAAA,GAAoB,OAAA;EAAA,QAMlB,qBAAA;EAWR,YAAA,CAAa,MAAA,EAAQ,UAAA;EAkDrB,YAAA,CAAA,GAAgB,MAAA;EAAA,QAOF,WAAA;EAAA,QAkEA,kBAAA;EAAA,QAqEA,YAAA;EA8jBH;;;;;;;;;;;EAAA,QArZG,gBAAA;EAqZG;;;;;;;;;;;;;;EAAA,QAxSH,WAAA;EAAA,QA2FA,aAAA;EAAA,QA2BA,cAAA;EAAA,QAuCA,kBAAA;EAAA,QASA,gBAAA;EAAA,QAUA,mBAAA;EAAA,QAaN,YAAA;EAAA,QASA,aAAA;EAgBF,QAAA,CAAA,GAAY,OAAA;EAQlB,OAAA,CAAA;6BAE2B,GAAA,EAAO,eAAA,KAAe,OAAA;;2BAG3B,eAAA;;;oCAGS,OAAA,CAAA,MAAA;EAAA;EAAA,QAIjB,iBAAA;AAAA;;;;;;;;;;;;;;;cA8DH,MAAA,EAAM,QAAA,QAAA,YAAA,EAAA,kBAAA"}
|