experimental-ash 0.41.0 → 0.43.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/CHANGELOG.md +36 -0
- package/dist/docs/internals/hooks.md +53 -11
- package/dist/docs/public/README.md +8 -8
- package/dist/docs/public/advanced/{auth-and-route-protection.md → auth-and-route-protection.mdx} +11 -0
- package/dist/docs/public/advanced/context-control.md +4 -4
- package/dist/docs/public/advanced/{evals.md → evals.mdx} +11 -1
- package/dist/docs/public/advanced/{hooks.md → hooks.mdx} +37 -46
- package/dist/docs/public/advanced/instrumentation.md +92 -3
- package/dist/docs/public/advanced/project-layout.md +5 -5
- package/dist/docs/public/advanced/runs-and-streaming.md +8 -2
- package/dist/docs/public/advanced/session-context.md +1 -1
- package/dist/docs/public/advanced/typescript-api.md +49 -6
- package/dist/docs/public/advanced/vercel-deployment.md +1 -1
- package/dist/docs/public/agent-ts.md +5 -5
- package/dist/docs/public/channels/{discord.md → discord.mdx} +11 -0
- package/dist/docs/public/channels/index.md +10 -10
- package/dist/docs/public/channels/{slack.md → slack.mdx} +11 -0
- package/dist/docs/public/channels/{teams.md → teams.mdx} +12 -0
- package/dist/docs/public/channels/{telegram.md → telegram.mdx} +11 -0
- package/dist/docs/public/channels/{twilio.md → twilio.mdx} +11 -0
- package/dist/docs/public/{connections.md → connections.mdx} +18 -6
- package/dist/docs/public/frontend/README.md +16 -0
- package/dist/docs/public/frontend/meta.json +3 -0
- package/dist/docs/public/frontend/nextjs.md +192 -0
- package/dist/docs/public/frontend/use-ash-agent.md +332 -0
- package/dist/docs/public/{getting-started.md → getting-started.mdx} +12 -1
- package/dist/docs/public/{human-in-the-loop.md → human-in-the-loop.mdx} +12 -1
- package/dist/docs/public/meta.json +1 -0
- package/dist/docs/public/sandbox.md +1 -1
- package/dist/docs/public/{schedules.md → schedules.mdx} +9 -0
- package/dist/docs/public/skills.md +2 -2
- package/dist/docs/public/{subagents.md → subagents.mdx} +10 -0
- package/dist/docs/public/{tools.md → tools.mdx} +62 -36
- package/dist/src/channel/adapter.d.ts +13 -0
- package/dist/src/channel/instrumentation.d.ts +10 -0
- package/dist/src/channel/instrumentation.js +1 -0
- package/dist/src/channel/send.js +1 -1
- package/dist/src/channel/types.d.ts +16 -0
- package/dist/src/cli/commands/channels.d.ts +2 -1
- package/dist/src/cli/commands/channels.js +1 -1
- package/dist/src/compiler/manifest.d.ts +13 -1
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/compiler/module-map.js +1 -1
- package/dist/src/compiler/normalize-manifest.js +1 -1
- package/dist/src/compiler/normalize-skill.d.ts +15 -2
- package/dist/src/compiler/normalize-skill.js +1 -1
- package/dist/src/compiler/normalize-tool.js +1 -1
- package/dist/src/context/dynamic-skill-lifecycle.d.ts +23 -0
- package/dist/src/context/dynamic-skill-lifecycle.js +1 -0
- package/dist/src/context/dynamic-tool-lifecycle.d.ts +19 -23
- package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
- package/dist/src/context/hook-lifecycle.d.ts +4 -6
- package/dist/src/context/hook-lifecycle.js +1 -1
- package/dist/src/context/keys.d.ts +10 -9
- package/dist/src/context/keys.js +1 -1
- package/dist/src/context/providers/connection.d.ts +9 -0
- package/dist/src/context/providers/connection.js +1 -1
- package/dist/src/context/providers/sandbox.js +1 -1
- package/dist/src/execution/ash-workflow-attributes.d.ts +118 -0
- package/dist/src/execution/ash-workflow-attributes.js +1 -0
- package/dist/src/execution/channel-context.d.ts +5 -0
- package/dist/src/execution/channel-context.js +1 -0
- package/dist/src/execution/create-session-step.d.ts +28 -1
- package/dist/src/execution/create-session-step.js +1 -1
- package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
- package/dist/src/execution/durable-session-store.d.ts +7 -0
- package/dist/src/execution/node-step.d.ts +2 -2
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/sandbox/prewarm.js +1 -1
- package/dist/src/execution/session.d.ts +6 -0
- package/dist/src/execution/session.js +2 -2
- package/dist/src/execution/skills/instructions.d.ts +3 -2
- package/dist/src/execution/subagent-tool.js +1 -1
- package/dist/src/execution/workflow-entry.js +1 -1
- package/dist/src/execution/workflow-steps.js +1 -1
- package/dist/src/harness/attachment-staging.js +1 -1
- package/dist/src/harness/code-mode.d.ts +0 -5
- package/dist/src/harness/code-mode.js +1 -1
- package/dist/src/harness/emission.d.ts +1 -1
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/instrumentation-config.d.ts +1 -1
- package/dist/src/harness/instrumentation-metadata.d.ts +23 -0
- package/dist/src/harness/instrumentation-metadata.js +1 -0
- package/dist/src/harness/otel-integration.d.ts +2 -2
- package/dist/src/harness/otel-integration.js +1 -1
- package/dist/src/harness/step-hooks.js +1 -1
- package/dist/src/harness/tool-loop.js +1 -1
- package/dist/src/harness/turn-tag-state.d.ts +50 -0
- package/dist/src/harness/turn-tag-state.js +1 -0
- package/dist/src/harness/types.d.ts +20 -2
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-definition/schema-backed.d.ts +0 -1
- package/dist/src/internal/authored-definition/schema-backed.js +1 -1
- package/dist/src/internal/instrumentation.d.ts +39 -0
- package/dist/src/internal/instrumentation.js +1 -0
- package/dist/src/internal/workflow/builtins.d.ts +32 -0
- package/dist/src/internal/workflow/builtins.js +1 -1
- package/dist/src/internal/workflow-bundle/dynamic-tool-transform.d.ts +1 -1
- package/dist/src/internal/workflow-bundle/dynamic-tool-transform.js +1 -1
- package/dist/src/internal/workflow-bundle/workflow-core-shim.d.ts +34 -0
- package/dist/src/internal/workflow-bundle/workflow-core-shim.js +1 -1
- package/dist/src/internal/workflow-bundle/workflow-transformer.js +1 -1
- package/dist/src/packages/ash-scaffold/src/channels.js +1 -1
- package/dist/src/packages/ash-scaffold/src/steps/run-add-to-agent.js +2 -2
- package/dist/src/public/channels/slack/attachments.js +1 -1
- package/dist/src/public/channels/slack/index.d.ts +1 -1
- package/dist/src/public/channels/slack/slackChannel.d.ts +6 -0
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/channels/telegram/telegramChannel.js +1 -1
- package/dist/src/public/channels/twilio/index.d.ts +1 -1
- package/dist/src/public/channels/twilio/twilioChannel.d.ts +6 -0
- package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
- package/dist/src/public/definitions/defineChannel.d.ts +12 -2
- package/dist/src/public/definitions/defineChannel.js +1 -1
- package/dist/src/public/definitions/hook.d.ts +3 -11
- package/dist/src/public/definitions/instrumentation.d.ts +88 -2
- package/dist/src/public/definitions/skill.d.ts +5 -0
- package/dist/src/public/definitions/tool.d.ts +25 -66
- package/dist/src/public/definitions/tool.js +1 -1
- package/dist/src/public/instrumentation/index.d.ts +1 -4
- package/dist/src/public/instrumentation/index.js +1 -1
- package/dist/src/public/skills/index.d.ts +2 -0
- package/dist/src/public/skills/index.js +1 -1
- package/dist/src/public/tools/index.d.ts +2 -2
- package/dist/src/public/tools/index.js +1 -1
- package/dist/src/runtime/agent/mock-model-adapter.js +4 -7
- package/dist/src/runtime/agent/mock-model-skill-selection.d.ts +9 -0
- package/dist/src/runtime/agent/mock-model-skill-selection.js +4 -0
- package/dist/src/runtime/attributes/emit.d.ts +73 -0
- package/dist/src/runtime/attributes/emit.js +1 -0
- package/dist/src/runtime/channels/registry.js +1 -1
- package/dist/src/runtime/connections/mcp-client.js +1 -1
- package/dist/src/runtime/framework-tools/code-mode-connection-auth.d.ts +2 -0
- package/dist/src/runtime/framework-tools/connection-search-dynamic.d.ts +34 -0
- package/dist/src/runtime/framework-tools/connection-search-dynamic.js +1 -0
- package/dist/src/runtime/framework-tools/index.d.ts +7 -5
- package/dist/src/runtime/framework-tools/index.js +1 -1
- package/dist/src/runtime/prompt/connections.js +1 -1
- package/dist/src/runtime/resolve-agent-graph.js +1 -1
- package/dist/src/runtime/resolve-agent.js +1 -1
- package/dist/src/runtime/resolve-dynamic-skill.d.ts +8 -0
- package/dist/src/runtime/resolve-dynamic-skill.js +1 -0
- package/dist/src/runtime/resolve-dynamic-tool.js +1 -1
- package/dist/src/runtime/sessions/compiled-agent-cache.js +1 -1
- package/dist/src/runtime/sessions/runtime-context-keys.js +1 -1
- package/dist/src/runtime/types.d.ts +13 -4
- package/dist/src/shared/dynamic-tool-definition.d.ts +57 -80
- package/dist/src/shared/dynamic-tool-definition.js +1 -1
- package/dist/src/shared/guards.d.ts +14 -0
- package/dist/src/shared/guards.js +1 -1
- package/dist/src/shared/skill-definition.d.ts +5 -4
- package/dist/src/shared/tool-definition.d.ts +12 -0
- package/package.json +2 -1
- package/dist/src/runtime/framework-tools/connection-search.d.ts +0 -57
- package/dist/src/runtime/framework-tools/connection-search.js +0 -1
- package/dist/src/runtime/framework-tools/connection-tools.d.ts +0 -55
- package/dist/src/runtime/framework-tools/connection-tools.js +0 -1
|
@@ -35,4 +35,16 @@ export interface InternalToolDefinitionWithExecuteFn<TInput = unknown, TOutput =
|
|
|
35
35
|
export interface PublicToolDefinitionWithExecuteFn<TInput = unknown, TOutput = unknown> extends PublicToolDefinition<TInput> {
|
|
36
36
|
execute: ToolExecuteFn<TInput, TOutput>;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Ash-owned shape for the model-facing tool result produced by
|
|
40
|
+
* `toModelOutput`. Structurally compatible with the AI SDK's
|
|
41
|
+
* `ToolResultOutput` so the harness can forward it without conversion.
|
|
42
|
+
*/
|
|
43
|
+
export type ToolModelOutput = {
|
|
44
|
+
readonly type: "text";
|
|
45
|
+
readonly value: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly type: "json";
|
|
48
|
+
readonly value: unknown;
|
|
49
|
+
};
|
|
38
50
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "experimental-ash",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"bin": {
|
|
5
5
|
"ash": "./bin/ash.js",
|
|
6
6
|
"experimental-ash": "./bin/ash.js"
|
|
@@ -191,6 +191,7 @@
|
|
|
191
191
|
"@vercel/sandbox": "2.0.1",
|
|
192
192
|
"@workflow/core": "5.0.0-beta.10",
|
|
193
193
|
"@workflow/errors": "5.0.0-beta.6",
|
|
194
|
+
"@workflow/world": "5.0.0-beta.5",
|
|
194
195
|
"@workflow/world-local": "5.0.0-beta.11",
|
|
195
196
|
"ai": "7.0.0-canary.159",
|
|
196
197
|
"autoevals": "0.0.132",
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ContextKey } from "#context/key.js";
|
|
2
|
-
import { type AuthorizationSignal } from "#harness/authorization.js";
|
|
3
|
-
import { type ConnectionRegistry, type ConnectionToolMetadata } from "#runtime/connections/types.js";
|
|
4
|
-
import type { ResolvedToolDefinition } from "#runtime/types.js";
|
|
5
|
-
import { type CodeModeConnectionAuthContext } from "#runtime/framework-tools/code-mode-connection-auth.js";
|
|
6
|
-
/**
|
|
7
|
-
* Context key for the per-session connection registry.
|
|
8
|
-
*
|
|
9
|
-
* Created as a derived key (no codec) because the registry holds live
|
|
10
|
-
* client instances that cannot be serialized across step boundaries.
|
|
11
|
-
* The `connectionProvider` reconstructs it each step.
|
|
12
|
-
*/
|
|
13
|
-
export declare const ConnectionRegistryKey: ContextKey<ConnectionRegistry>;
|
|
14
|
-
/**
|
|
15
|
-
* Durable state tracking which connection tools have been discovered
|
|
16
|
-
* via `connection_search`.
|
|
17
|
-
*
|
|
18
|
-
* Maps connection name → tool metadata. Persists across step
|
|
19
|
-
* boundaries so the tool-building code can register discovered tools
|
|
20
|
-
* as first-class AI SDK tools on subsequent steps.
|
|
21
|
-
*/
|
|
22
|
-
export interface DiscoveredConnectionToolsState {
|
|
23
|
-
readonly byConnection: Readonly<Record<string, readonly ConnectionToolMetadata[]>>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Durable context key for discovered connection tools.
|
|
27
|
-
*
|
|
28
|
-
* Written by `connection_search` after fetching tool metadata.
|
|
29
|
-
* Read by `resolveDiscoveredConnectionTools` at the start of each
|
|
30
|
-
* step to inject discovered tools into the ToolSet.
|
|
31
|
-
*/
|
|
32
|
-
export declare const DiscoveredConnectionToolsKey: ContextKey<DiscoveredConnectionToolsState>;
|
|
33
|
-
interface ConnectionSearchInput {
|
|
34
|
-
readonly connection?: string;
|
|
35
|
-
readonly keywords: string;
|
|
36
|
-
readonly limit?: number;
|
|
37
|
-
}
|
|
38
|
-
interface ConnectionSearchResultItem {
|
|
39
|
-
readonly connection: string;
|
|
40
|
-
readonly description: string;
|
|
41
|
-
readonly error?: string;
|
|
42
|
-
readonly inputSchema?: Record<string, unknown>;
|
|
43
|
-
readonly needsAuthorization?: boolean;
|
|
44
|
-
readonly tool?: string;
|
|
45
|
-
readonly qualifiedName?: string;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Framework-provided `connection_search` tool.
|
|
49
|
-
*/
|
|
50
|
-
export declare const CONNECTION_SEARCH_TOOL_DEFINITION: ResolvedToolDefinition;
|
|
51
|
-
export declare function executeConnectionSearch(input: ConnectionSearchInput, meta?: {
|
|
52
|
-
readonly codeMode?: boolean;
|
|
53
|
-
readonly codeModeInterrupt?: CodeModeConnectionAuthContext;
|
|
54
|
-
}): Promise<ConnectionSearchResultItem[] | AuthorizationSignal>;
|
|
55
|
-
export declare function tokenize(text: string): string[];
|
|
56
|
-
export declare function scoreMatch(queryTokens: string[], tool: ConnectionToolMetadata): number;
|
|
57
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createLogger}from"#internal/logging.js";import{loadContext}from"#context/container.js";import{ContextKey}from"#context/key.js";import{loadCodeModeModule}from"#shared/code-mode.js";import{getAuthorizationResult,getHookUrl,requestAuthorization}from"#harness/authorization.js";import{CODE_MODE_CONNECTION_AUTH_INTERRUPT_KIND,isCodeModeToolExecutionOptions,readCodeModeConnectionAuthContext,toCodeModeConnectionAuthArgs}from"#runtime/framework-tools/code-mode-connection-auth.js";import{qualifiedConnectionToolName}from"#runtime/framework-tools/connection-tools.js";import{principalKey,resolveConnectionPrincipal}from"#runtime/connections/principal.js";import{supportsInteractiveAuthorization}from"#runtime/connections/types.js";import{isConnectionAuthorizationFailedError,isConnectionAuthorizationRequiredError}from"#public/connections/errors.js";import{writeCachedToken}from"#runtime/connections/authorization-tokens.js";const logger=createLogger(`framework.connection-search`),ConnectionRegistryKey=new ContextKey(`ash.connectionRegistry`),DiscoveredConnectionToolsKey=new ContextKey(`ash.discoveredConnectionTools`),CONNECTION_SEARCH_TOOL_DEFINITION={description:`Search for tools across your connections. Discovered tools become directly callable by their qualified name (e.g. linear__list_issues) in your next response.`,execute:async(e,t)=>executeConnectionSearch(e,{codeMode:isCodeModeToolExecutionOptions(t),codeModeInterrupt:readCodeModeConnectionAuthContext(t)}),inputSchema:{additionalProperties:!1,properties:{connection:{description:`Optional: limit search to a specific connection name.`,type:`string`},limit:{description:`Max results to return. Default 10.`,type:`number`},keywords:{description:`Search keywords and expanded aliases. Distill intent into keywords; avoid stop words like 'a', 'the', 'in'.`,type:`string`}},required:[`keywords`],type:`object`},logicalPath:`ash:framework/connection-search`,name:`connection_search`,onCompact(){return loadContext().set(DiscoveredConnectionToolsKey,{byConnection:{}}),{}},sourceId:`ash:connection-search-tool`,sourceKind:`module`};async function executeConnectionSearch(e,n){let i=loadContext(),c=i.get(ConnectionRegistryKey);if(c===void 0)return[];await completePendingAuthorizations(c);let l=e.limit??10,u=tokenize(e.keywords),d=[],f=[],p=e.connection!==void 0&&e.connection!==``?c.getConnections().filter(t=>t.connectionName===e.connection):c.getConnections(),m={...i.get(DiscoveredConnectionToolsKey)?.byConnection},h=[];for(let t of p){if(n?.codeModeInterrupt?.resolution.status===`failed`&&n.codeModeInterrupt.payload.connectionName===t.connectionName){let{resolution:e}=n.codeModeInterrupt;f.push({connection:t.connectionName,description:t.description,error:e.reason,needsAuthorization:e.retryable});continue}let i;try{i=await c.getClient(t.connectionName).getToolMetadata()}catch(i){if(isConnectionAuthorizationRequiredError(i)){let i=resolveInteractiveAuth(c,t.connectionName);if(i&&n?.codeMode===!0){let{requestCodeModeInterrupt:n}=await loadCodeModeModule();n({args:toCodeModeConnectionAuthArgs(e),connectionName:t.connectionName,kind:CODE_MODE_CONNECTION_AUTH_INTERRUPT_KIND,toolName:`connection_search`})}if(i){let e=getHookUrl(t.connectionName);if(e){let n=resolveConnectionPrincipal(t.connectionName,i);try{let{challenge:r,state:a}=await i.startAuthorization({callbackUrl:e,connection:{url:t.url??``},principal:n});h.push({name:t.connectionName,challenge:r,hookUrl:e,state:a})}catch(e){logger.warn(`startAuthorization failed`,{connection:t.connectionName,error:e instanceof Error?e:Error(String(e))})}}}f.push({connection:t.connectionName,description:t.description,needsAuthorization:!0});continue}if(isConnectionAuthorizationFailedError(i)){logger.warn(`connection authorization failed`,{connection:t.connectionName,reason:i.reason,retryable:i.retryable,error:i}),f.push({connection:t.connectionName,description:t.description,error:`Authorization failed for ${t.connectionName}: ${i.message}`});continue}let o=i instanceof Error?i.message:`unknown error`;logger.warn(`failed to load connection tools`,{connection:t.connectionName,error:i instanceof Error?i:Error(o)}),f.push({connection:t.connectionName,description:t.description,error:`Failed to load tools for "${t.connectionName}": ${o}`});continue}m[t.connectionName]=i;for(let e of i){let n=scoreMatch(u,e);n>0&&d.push({item:{connection:t.connectionName,description:e.description,inputSchema:e.inputSchema,qualifiedName:qualifiedConnectionToolName(t.connectionName,e.name),tool:e.name},score:n})}}if(i.set(DiscoveredConnectionToolsKey,{byConnection:m}),h.length>0)return requestAuthorization(h);d.sort((e,t)=>t.score-e.score);let g=d.slice(0,l).map(e=>e.item);return g.length>0?[...g,...f]:p.map(e=>f.find(t=>t.connection===e.connectionName)||{connection:e.connectionName,description:e.description})}async function completePendingAuthorizations(e){let n=loadContext();for(let t of e.getConnections()){let r=getAuthorizationResult(t.connectionName);if(!r)continue;let a=resolveInteractiveAuth(e,t.connectionName);if(!a)continue;let o=resolveConnectionPrincipal(t.connectionName,a),s=await a.completeAuthorization({callbackUrl:r.hookUrl,connection:{url:t.url??``},principal:o,request:r.callback,state:r.state});writeCachedToken(n,t.connectionName,principalKey(o),s)}}function tokenize(e){return e.toLowerCase().split(/[\s_\-./]+/).filter(e=>e.length>1)}function scoreMatch(e,t){let n=tokenize(t.name),r=tokenize(t.description),i=0;for(let t of e){for(let e of n)(e.includes(t)||t.includes(e))&&(i+=3);for(let e of r)(e.includes(t)||t.includes(e))&&(i+=1)}return i}function resolveInteractiveAuth(e,t){let n=e.getConnections().find(e=>e.connectionName===t);if(n?.authorization&&supportsInteractiveAuthorization(n.authorization))return n.authorization}export{CONNECTION_SEARCH_TOOL_DEFINITION,ConnectionRegistryKey,DiscoveredConnectionToolsKey,executeConnectionSearch,scoreMatch,tokenize};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { type ToolSet } from "ai";
|
|
2
|
-
import { type ConnectionRegistry } from "#runtime/connections/types.js";
|
|
3
|
-
import type { ResolvedConnectionDefinition } from "#runtime/types.js";
|
|
4
|
-
import { type DiscoveredConnectionToolsState } from "#runtime/framework-tools/connection-search.js";
|
|
5
|
-
/**
|
|
6
|
-
* Builds the qualified tool name for a connection tool.
|
|
7
|
-
*
|
|
8
|
-
* Uses double-underscore as the separator because it is safe in
|
|
9
|
-
* tool-name schemas and unlikely to appear in authored tool names.
|
|
10
|
-
*/
|
|
11
|
-
export declare function qualifiedConnectionToolName(connectionName: string, toolName: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* Builds AI SDK tools for every connection tool that has been
|
|
14
|
-
* discovered via a prior `connection_search` call.
|
|
15
|
-
*/
|
|
16
|
-
export declare function resolveConnectionToolsFromState(registry: ConnectionRegistry, discovered: DiscoveredConnectionToolsState, input: {
|
|
17
|
-
readonly approvedTools?: ReadonlySet<string>;
|
|
18
|
-
readonly authMode?: "code-mode" | "direct";
|
|
19
|
-
readonly codeModeMetadataOnlyConnectionNames?: ReadonlySet<string>;
|
|
20
|
-
readonly existingToolNames?: ReadonlySet<string>;
|
|
21
|
-
}): Promise<ToolSet>;
|
|
22
|
-
/**
|
|
23
|
-
* AI SDK tool-execute function shape. Captured locally so we can wrap
|
|
24
|
-
* the `execute` returned by `@ai-sdk/mcp`'s `toolsFromDefinitions()`
|
|
25
|
-
* without taking a direct dependency on the SDK's internal types.
|
|
26
|
-
*/
|
|
27
|
-
type ToolExecuteFn = (args: unknown, options: unknown) => Promise<unknown>;
|
|
28
|
-
/**
|
|
29
|
-
* Wraps one connection tool's `execute` for nested code-mode execution.
|
|
30
|
-
*
|
|
31
|
-
* Interactive auth pauses the outer `code_mode` tool with a generic
|
|
32
|
-
* interruption instead of writing a top-level placeholder result. The
|
|
33
|
-
* durable workflow completes OAuth, then code mode replays the same
|
|
34
|
-
* sandbox program and re-enters this nested host tool with
|
|
35
|
-
* `options.codeModeInterrupt` populated.
|
|
36
|
-
*/
|
|
37
|
-
export declare function wrapCodeModeConnectionToolExecute(params: {
|
|
38
|
-
readonly connectionDefinition: ResolvedConnectionDefinition | undefined;
|
|
39
|
-
readonly connectionName: string;
|
|
40
|
-
readonly originalExecute: ToolExecuteFn | undefined;
|
|
41
|
-
readonly toolName: string;
|
|
42
|
-
}): ToolExecuteFn | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Wraps one connection tool's `execute` to handle interactive auth.
|
|
45
|
-
* On auth error, starts authorization and returns an
|
|
46
|
-
* `AuthorizationSignal`. On re-execution after callback, completes
|
|
47
|
-
* auth, caches the token, and falls through to normal execute.
|
|
48
|
-
*/
|
|
49
|
-
export declare function wrapConnectionToolExecute(params: {
|
|
50
|
-
readonly connectionDefinition: ResolvedConnectionDefinition | undefined;
|
|
51
|
-
readonly connectionName: string;
|
|
52
|
-
readonly originalExecute: ToolExecuteFn | undefined;
|
|
53
|
-
readonly toolName: string;
|
|
54
|
-
}): ToolExecuteFn | undefined;
|
|
55
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isObject}from"#shared/guards.js";import{loadContext}from"#context/container.js";import{jsonSchema}from"ai";import"#runtime/framework-tools/connection-search.js";import{loadCodeModeModule}from"#shared/code-mode.js";import{getAuthorizationResult,getHookUrl,requestAuthorization}from"#harness/authorization.js";import{CODE_MODE_CONNECTION_AUTH_INTERRUPT_KIND,toCodeModeConnectionAuthArgs}from"#runtime/framework-tools/code-mode-connection-auth.js";import{principalKey,resolveConnectionPrincipal}from"#runtime/connections/principal.js";import{supportsInteractiveAuthorization}from"#runtime/connections/types.js";import{isConnectionAuthorizationRequiredError}from"#public/connections/errors.js";import{writeCachedToken}from"#runtime/connections/authorization-tokens.js";function qualifiedConnectionToolName(e,t){return`${e}__${t}`}async function resolveConnectionToolsFromState(t,n,r){let i={};for(let[a,o]of Object.entries(n.byConnection)){let n=r.authMode===`code-mode`&&r.codeModeMetadataOnlyConnectionNames?.has(a)===!0,s=n?void 0:await t.getClient(a).getTools(),c=t.getConnectionApproval(a);for(let l of o){let o=qualifiedConnectionToolName(a,l.name);if(r.existingToolNames?.has(o))continue;let u=s?.[l.name]??(n?createMetadataOnlyTool(l,o):void 0);if(u===void 0)continue;let d=!n&&c!==void 0?async t=>c({approvedTools:r.approvedTools??new Set,toolInput:isObject(t)?t:void 0,toolName:o}):void 0,f=t.getConnections().find(e=>e.connectionName===a),p=u.execute,m=r.authMode===`code-mode`?wrapCodeModeConnectionToolExecute({connectionDefinition:f,connectionName:a,originalExecute:p,toolName:l.name}):wrapConnectionToolExecute({connectionDefinition:f,connectionName:a,originalExecute:p,toolName:l.name});i[o]={...u,execute:m,needsApproval:d}}}return i}function createMetadataOnlyTool(e,t){return{description:e.description,execute:async()=>{throw Error(`Connection tool "${t}" cannot execute without authorization.`)},inputSchema:jsonSchema(e.inputSchema)}}function wrapCodeModeConnectionToolExecute(e){let{connectionDefinition:n,connectionName:a,originalExecute:o,toolName:m}=e;if(o===void 0)return;let h=n?.authorization&&supportsInteractiveAuthorization(n.authorization)?n.authorization:void 0,g=n?.url??``;return async(e,n)=>{if(h){let e=getAuthorizationResult(a);if(e){let n=loadContext(),r=resolveConnectionPrincipal(a,h),i=await h.completeAuthorization({callbackUrl:e.hookUrl,connection:{url:g},principal:r,request:e.callback,state:e.state});writeCachedToken(n,a,principalKey(r),i)}}try{return await o(e,n)}catch(t){if(!isConnectionAuthorizationRequiredError(t)||!h)throw t;let{requestCodeModeInterrupt:n}=await loadCodeModeModule();n({args:toCodeModeConnectionAuthArgs(e),connectionName:a,kind:CODE_MODE_CONNECTION_AUTH_INTERRUPT_KIND,toolName:m})}}}function wrapConnectionToolExecute(e){let{connectionDefinition:n,connectionName:r,originalExecute:s}=e;if(s===void 0)return;let c=n?.authorization&&supportsInteractiveAuthorization(n.authorization)?n.authorization:void 0,m=n?.url??``;return async(e,n)=>{if(c){let e=getAuthorizationResult(r);if(e){let n=loadContext(),i=resolveConnectionPrincipal(r,c),a=await c.completeAuthorization({callbackUrl:e.hookUrl,connection:{url:m},principal:i,request:e.callback,state:e.state});writeCachedToken(n,r,principalKey(i),a)}}try{return await s(e,n)}catch(e){if(!isConnectionAuthorizationRequiredError(e)||!c)throw e;let t=getHookUrl(r);if(!t)throw e;let n=resolveConnectionPrincipal(r,c),{challenge:i,state:s}=await c.startAuthorization({callbackUrl:t,connection:{url:m},principal:n});return requestAuthorization([{name:r,challenge:i,hookUrl:t,state:s}])}}}export{qualifiedConnectionToolName,resolveConnectionToolsFromState,wrapCodeModeConnectionToolExecute,wrapConnectionToolExecute};
|