@standardagents/builder 0.27.12 → 0.28.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/dist/built-in-routes.js +273 -21
- package/dist/built-in-routes.js.map +1 -1
- package/dist/{index-DReIS8eP.d.ts → index-BzXyIJPA.d.ts} +163 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +909 -38
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +24 -2
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +127 -5
- package/dist/runtime.js +855 -36
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DurableObjectStorage } from '@cloudflare/workers-types';
|
|
2
2
|
import { ZodObject, ZodRawShape } from 'zod';
|
|
3
3
|
import { N as NamespacedRegistry } from './types-Bpe7IANZ.js';
|
|
4
|
-
import { ToolResult as ToolResult$1, VariableDefinition, HookName, HookSignatures,
|
|
4
|
+
import { ThreadState, ToolResult as ToolResult$1, VariableDefinition, HookName, HookSignatures, HookMessage, HookToolCall, HookToolResult, CodeExecutionOptions, CodeExecutionResult, InjectMessageInput, QueueMessageInput, SubagentRegistryEntry, ProviderUsagePricing, AgentDefinition, SkillMetadata, SkillFileInput, ControllerContext, Controller, ThreadEndpointHandler } from '@standardagents/spec';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Callback function to execute before stream closes
|
|
@@ -76,6 +76,132 @@ declare class StreamManager {
|
|
|
76
76
|
forceClose(): void;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Client-tool forwarding — a BUILDER capability, not a spec surface.
|
|
81
|
+
*
|
|
82
|
+
* The Standard Agent Specification has no "client" concept: agents, prompts,
|
|
83
|
+
* hooks, and tools are defined against spec surfaces only. But tools are
|
|
84
|
+
* arbitrary code and may call anything — including this builder API, which
|
|
85
|
+
* forwards an operation over the thread's `bridge` WebSocket to a connected
|
|
86
|
+
* client (a CLI or machine daemon) for local execution. Products built on
|
|
87
|
+
* AgentBuilder (e.g. Standard Code) import these types and entry points from
|
|
88
|
+
* `@standardagents/builder`.
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* A request forwarded from a server-side tool to a connected client (CLI or
|
|
92
|
+
* machine daemon) for local execution. Used by "forwarded" tools where the
|
|
93
|
+
* agent loop runs remotely but the actual operation (read a file, run a
|
|
94
|
+
* command) must happen on the user's own machine.
|
|
95
|
+
*/
|
|
96
|
+
interface ClientToolRequest {
|
|
97
|
+
/** Logical operation name the client knows how to perform (e.g. `read_file`). */
|
|
98
|
+
tool: string;
|
|
99
|
+
/** Arguments for the operation. */
|
|
100
|
+
args?: Record<string, unknown>;
|
|
101
|
+
/**
|
|
102
|
+
* Human-readable description of what this call will do, shown to the user when
|
|
103
|
+
* the client needs to ask for permission. Presence signals the operation may
|
|
104
|
+
* carry side effects.
|
|
105
|
+
*/
|
|
106
|
+
requestPermission?: string;
|
|
107
|
+
/** Risk level 1 (safe) – 5 (dangerous). Clients slide auto-accept on this. */
|
|
108
|
+
risk?: number;
|
|
109
|
+
/** Milliseconds to wait for the client before failing the call. */
|
|
110
|
+
timeoutMs?: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The result a connected client returns for a {@link ClientToolRequest}.
|
|
114
|
+
*/
|
|
115
|
+
interface ClientToolResponse {
|
|
116
|
+
/** Whether the client successfully performed the operation. */
|
|
117
|
+
ok: boolean;
|
|
118
|
+
/** Text result (e.g. file contents, command output). */
|
|
119
|
+
result?: string;
|
|
120
|
+
/** Error message when `ok` is false (including a user denial). */
|
|
121
|
+
error?: string;
|
|
122
|
+
/** Optional structured payload the tool can inspect. */
|
|
123
|
+
data?: unknown;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A request to open a bidirectional byte stream to the connected client.
|
|
127
|
+
*
|
|
128
|
+
* The client interprets `tool` + `meta` (e.g. `tcp_tunnel` with
|
|
129
|
+
* `{ host, port }` opens a raw TCP socket and shuttles bytes both ways).
|
|
130
|
+
* Payload bytes are opaque to the transport — for a TLS tunnel the client
|
|
131
|
+
* only ever relays ciphertext.
|
|
132
|
+
*/
|
|
133
|
+
interface ClientStreamRequest {
|
|
134
|
+
/** Client stream capability name (e.g. `tcp_tunnel`). */
|
|
135
|
+
tool: string;
|
|
136
|
+
/** Opaque per-stream configuration delivered to the client verbatim. */
|
|
137
|
+
meta?: Record<string, unknown>;
|
|
138
|
+
/** Milliseconds to wait for the client to accept the stream. */
|
|
139
|
+
timeoutMs?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A live bidirectional byte pipe between the thread runtime and the client.
|
|
143
|
+
*
|
|
144
|
+
* `readable` carries bytes FROM the client; `writable` carries bytes TO the
|
|
145
|
+
* client. `close()` tears the stream down on both sides (mapped to the
|
|
146
|
+
* `stream_abort` frame); `done` settles when the client reports the stream
|
|
147
|
+
* finished or failed.
|
|
148
|
+
*/
|
|
149
|
+
interface ClientDuplex {
|
|
150
|
+
readable: ReadableStream<Uint8Array>;
|
|
151
|
+
writable: WritableStream<Uint8Array>;
|
|
152
|
+
/** Abort the stream on both sides. */
|
|
153
|
+
close(error?: string): void;
|
|
154
|
+
/** Settles when the stream fully ends (either side) or errors. */
|
|
155
|
+
done: Promise<{
|
|
156
|
+
ok: boolean;
|
|
157
|
+
error?: string;
|
|
158
|
+
}>;
|
|
159
|
+
}
|
|
160
|
+
type ClientStreamResponse = {
|
|
161
|
+
ok: true;
|
|
162
|
+
duplex: ClientDuplex;
|
|
163
|
+
} | {
|
|
164
|
+
ok: false;
|
|
165
|
+
error: string;
|
|
166
|
+
data?: unknown;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* The builder-only forwarding surface implemented by `ThreadStateImpl`.
|
|
170
|
+
* The spec `ThreadState` deliberately does not declare these members.
|
|
171
|
+
*/
|
|
172
|
+
interface ClientForwarding {
|
|
173
|
+
callClient(request: ClientToolRequest): Promise<ClientToolResponse>;
|
|
174
|
+
callClientStream(request: ClientStreamRequest): Promise<ClientStreamResponse>;
|
|
175
|
+
}
|
|
176
|
+
/** Whether this runtime's ThreadState supports client-tool forwarding. */
|
|
177
|
+
declare function supportsClientForwarding(state: ThreadState): state is ThreadState & ClientForwarding;
|
|
178
|
+
/**
|
|
179
|
+
* Forward a tool operation to the connected client and await its result.
|
|
180
|
+
*
|
|
181
|
+
* Resolves with `{ ok: false, error }` (rather than throwing) when no client
|
|
182
|
+
* is connected, the request times out, or the user denies permission, so
|
|
183
|
+
* forwarded tools can surface a normal tool error to the model.
|
|
184
|
+
*
|
|
185
|
+
* When the executing client is unreachable, the call parks durably on the
|
|
186
|
+
* thread and resumes when a client re-attaches (drain-on-attach) — the caller
|
|
187
|
+
* receives a deferred placeholder result and the turn suspends instead of
|
|
188
|
+
* failing.
|
|
189
|
+
*/
|
|
190
|
+
declare function callClient(state: ThreadState, request: ClientToolRequest): Promise<ClientToolResponse>;
|
|
191
|
+
/**
|
|
192
|
+
* Open a bidirectional byte stream to the connected client (e.g. a raw TCP
|
|
193
|
+
* tunnel for Worker-side TLS termination). Requires a live bridge socket on
|
|
194
|
+
* this thread — streams never park durably.
|
|
195
|
+
*/
|
|
196
|
+
declare function callClientStream(state: ThreadState, request: ClientStreamRequest): Promise<ClientStreamResponse>;
|
|
197
|
+
/** Maximum raw bytes per `stream_data` frame (base64 expands ~4/3 on the wire;
|
|
198
|
+
* Cloudflare caps WebSocket frames at 1 MiB). */
|
|
199
|
+
declare const CLIENT_STREAM_CHUNK_BYTES: number;
|
|
200
|
+
/** Encode a chunk of raw bytes for a `stream_data` frame. */
|
|
201
|
+
declare function encodeStreamChunk(bytes: Uint8Array): string;
|
|
202
|
+
/** Decode a `stream_data` frame payload back into raw bytes. */
|
|
203
|
+
declare function decodeStreamChunk(data: string): Uint8Array;
|
|
204
|
+
|
|
79
205
|
/**
|
|
80
206
|
* Agent configuration from D1 agents table
|
|
81
207
|
*/
|
|
@@ -264,6 +390,14 @@ interface ThreadInstance {
|
|
|
264
390
|
setValue(key: string, value: unknown): Promise<void>;
|
|
265
391
|
emitThreadEvent?(threadId: string, event: string, data: unknown): void | Promise<void>;
|
|
266
392
|
callClientTool?(request: ClientToolRequest): Promise<ClientToolResponse>;
|
|
393
|
+
openClientStream?(request: ClientStreamRequest): Promise<ClientStreamResponse>;
|
|
394
|
+
dispatchClientTool?(request: ClientToolRequest, toolCallId: string, side: "a" | "b"): Promise<{
|
|
395
|
+
dispatched: boolean;
|
|
396
|
+
}>;
|
|
397
|
+
hasBridge?(): Promise<boolean>;
|
|
398
|
+
failPendingMessagesAndBroadcast?(): Promise<number>;
|
|
399
|
+
settleTerminalFailure?(errorMessage: string): Promise<void>;
|
|
400
|
+
notifyClientWaiting?(toolCallId: string, threadId: string, userId: string | null): Promise<void>;
|
|
267
401
|
registerCodeExecutionBridge?(runId: string, bridge: {
|
|
268
402
|
call(functionId: string, encodedArgs: unknown[]): Promise<unknown>;
|
|
269
403
|
}): void;
|
|
@@ -1230,6 +1364,31 @@ interface ThreadWatchdogRpc {
|
|
|
1230
1364
|
}>;
|
|
1231
1365
|
}>;
|
|
1232
1366
|
}
|
|
1367
|
+
/**
|
|
1368
|
+
* RPC methods exposed by the DurableUserHub per-user companion Durable Object.
|
|
1369
|
+
*/
|
|
1370
|
+
interface DurableUserHubRpc {
|
|
1371
|
+
hasClient(): Promise<boolean>;
|
|
1372
|
+
requestWake(threadId: string): Promise<{
|
|
1373
|
+
delivered: boolean;
|
|
1374
|
+
}>;
|
|
1375
|
+
getUserValue(userId: string, key: string): Promise<unknown | null>;
|
|
1376
|
+
setUserValue(userId: string, key: string, value: unknown): Promise<void>;
|
|
1377
|
+
listUserValues(userId: string, options?: {
|
|
1378
|
+
prefix?: string | null;
|
|
1379
|
+
limit?: number;
|
|
1380
|
+
offset?: number;
|
|
1381
|
+
}): Promise<{
|
|
1382
|
+
entries: Array<{
|
|
1383
|
+
key: string;
|
|
1384
|
+
value: unknown;
|
|
1385
|
+
updated_at: number;
|
|
1386
|
+
}>;
|
|
1387
|
+
total: number;
|
|
1388
|
+
limit: number;
|
|
1389
|
+
offset: number;
|
|
1390
|
+
}>;
|
|
1391
|
+
}
|
|
1233
1392
|
/**
|
|
1234
1393
|
* Thread registry entry from DurableAgentBuilder.
|
|
1235
1394
|
*/
|
|
@@ -1454,6 +1613,8 @@ interface ThreadEnv {
|
|
|
1454
1613
|
AGENT_BUILDER: DurableObjectNamespace<DurableAgentBuilderRpc>;
|
|
1455
1614
|
/** Optional: deployments generated before 0.26.0 lack this binding. */
|
|
1456
1615
|
AGENT_BUILDER_WATCHDOG?: DurableObjectNamespace<ThreadWatchdogRpc>;
|
|
1616
|
+
/** Optional: deployments generated before the per-user hub lack this binding. */
|
|
1617
|
+
AGENT_BUILDER_USER_HUB?: DurableObjectNamespace<DurableUserHubRpc>;
|
|
1457
1618
|
[key: string]: unknown;
|
|
1458
1619
|
}
|
|
1459
1620
|
/**
|
|
@@ -1535,4 +1696,4 @@ declare function defineController<Env extends ThreadEnv = ThreadEnv>(controller:
|
|
|
1535
1696
|
*/
|
|
1536
1697
|
declare function createThreadEndpointHandler<Env extends ThreadEnv = ThreadEnv>(handler: ThreadEndpointHandler): BuilderController<Env>;
|
|
1537
1698
|
|
|
1538
|
-
export { type Agent as A, type BuilderController as B, type Env as E, type FlowState as F, type GrepResult as G, type ImageMetadata as I, type LLMResponse as L, type Message as M, type RequestContext as R, type StorageBackend as S, type ToolCall as T, type BuilderControllerContext as a, type ThreadEndpointContext as b, createThreadEndpointHandler as c, defineController as d, type ThreadEnv as e, type BuilderThreadEndpointHandler as f,
|
|
1699
|
+
export { type Agent as A, type BuilderController as B, CLIENT_STREAM_CHUNK_BYTES as C, type ImageContentPart as D, type Env as E, type FlowState as F, type GrepResult as G, type MultimodalContent as H, type ImageMetadata as I, type MessageContent as J, type LLMResponse as L, type Message as M, type RequestContext as R, type StorageBackend as S, type ToolCall as T, type BuilderControllerContext as a, type ThreadEndpointContext as b, createThreadEndpointHandler as c, defineController as d, type ThreadEnv as e, type BuilderThreadEndpointHandler as f, callClient as g, callClientStream as h, encodeStreamChunk as i, decodeStreamChunk as j, type ClientToolRequest as k, type ClientToolResponse as l, type ClientStreamRequest as m, type ClientStreamResponse as n, type ClientDuplex as o, type ClientForwarding as p, type ThreadInstance as q, type ThreadMetadata as r, supportsClientForwarding as s, type ToolResult as t, type FlowResult as u, type TelemetryEvent as v, type FileRecord as w, type AttachmentRef as x, type FileStats as y, type TextContentPart as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModelDefinition, AgentDefinition } from './runtime.js';
|
|
2
|
-
export { AgentBuilderEnv, AuthContext, AuthUser, BroadcastOptions, CodeExecutionBridge, DurableAgentBuilder, DurableThread, FlowStateSdk, FlowStateWithSdk, ImageContextConfig, InjectMessageOptions, LLMProviderInterface, NamespaceResolutionError, PromptContent, PromptDefinition, PromptIncludePart, PromptPart, PromptToolConfig, Provider, ProviderContentPart, ProviderFilePart, ProviderImagePart, ProviderRegistry, ProviderTextPart, SessionToolBinding, SessionToolConfig, SideConfig, SubagentToolConfig, SubpromptConfig, ThreadRegistryEntry, ThreadWatchdog, ThreadWatchdogState, ToolConfig, UpdateThreadParams, User, WatchdogCheckin, WatchdogProbeResult, authenticate, buildImageDescription, cat, createNamespaceContext, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isQualifiedName, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage } from './runtime.js';
|
|
2
|
+
export { AgentBuilderEnv, AuthContext, AuthUser, BroadcastOptions, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, FlowStateWithSdk, HubClientInfo, ImageContextConfig, InjectMessageOptions, LLMProviderInterface, NamespaceResolutionError, PromptContent, PromptDefinition, PromptIncludePart, PromptPart, PromptToolConfig, Provider, ProviderContentPart, ProviderFilePart, ProviderImagePart, ProviderRegistry, ProviderTextPart, SessionToolBinding, SessionToolConfig, SideConfig, SubagentToolConfig, SubpromptConfig, ThreadRegistryEntry, ThreadWatchdog, ThreadWatchdogState, ToolConfig, UpdateThreadParams, User, WatchdogCheckin, WatchdogProbeResult, authenticate, buildImageDescription, cat, createNamespaceContext, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isQualifiedName, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage } from './runtime.js';
|
|
3
3
|
export { AgentPluginOptions, agentbuilder, builder } from './plugin.js';
|
|
4
|
-
export { A as Agent,
|
|
4
|
+
export { A as Agent, x as AttachmentRef, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, o as ClientDuplex, p as ClientForwarding, m as ClientStreamRequest, n as ClientStreamResponse, k as ClientToolRequest, l as ClientToolResponse, B as Controller, a as ControllerContext, E as Env, w as FileRecord, y as FileStats, u as FlowResult, F as FlowState, G as GrepResult, D as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, J as MessageContent, H as MultimodalContent, R as RequestContext, S as StorageBackend, v as TelemetryEvent, z as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, q as ThreadInstance, r as ThreadMetadata, T as ToolCall, t as ToolResult, g as callClient, h as callClientStream, c as createThreadEndpointHandler, j as decodeStreamChunk, d as defineController, i as encodeStreamChunk, s as supportsClientForwarding } from './index-BzXyIJPA.js';
|
|
5
5
|
export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderConfigSlot, ProviderConfigSlots, ProviderConfigValueSource, ProviderDefinition, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ProviderMethodOverrides, ModelCapabilities as ProviderModelCapabilities, ProviderOverride, ProviderOverrideContext, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSyncOverride, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineProvider, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue } from '@standardagents/spec';
|
|
6
6
|
export { C as ConstituentItem, D as DiscoveredPackage, N as NamespacedRegistry, P as PackingAnalysis, a as PackingOptions, b as PackingResult, c as UnpackOptions, d as UnpackResult } from './types-Bpe7IANZ.js';
|
|
7
7
|
export { D as DiscoveryConfig, P as PackageDiscoveryService, d as discoverPackages } from './discovery-DiMJWisl.js';
|