@standardagents/builder 0.11.2 → 0.11.4

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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { AgentPluginOptions, agentbuilder } from './plugin.js';
2
2
  import { DurableObjectStorage } from '@cloudflare/workers-types';
3
3
  import { ZodObject, ZodRawShape } from 'zod';
4
- import { ToolResult as ToolResult$1, HookSignatures, AgentDefinition as AgentDefinition$1, ControllerContext, Controller, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, SubpromptConfig as SubpromptConfig$2, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart } from '@standardagents/spec';
4
+ import { ToolResult as ToolResult$1, HookSignatures, AgentDefinition as AgentDefinition$1, ControllerContext, Controller, ThreadEndpointHandler, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, SubpromptConfig as SubpromptConfig$2, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart } from '@standardagents/spec';
5
5
  export { AgentType, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ModelCapabilities as ProviderModelCapabilities, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, defineAgent, defineHook, defineModel, definePrompt, defineTool, mapReasoningLevel } from '@standardagents/spec';
6
6
  import { DurableObject } from 'cloudflare:workers';
7
7
  import 'vite';
@@ -1006,6 +1006,7 @@ interface BuilderControllerContext<Env extends ThreadEnv = ThreadEnv> extends Om
1006
1006
  type BuilderController<Env extends ThreadEnv = ThreadEnv> = (context: BuilderControllerContext<Env>) => ReturnType<Controller>;
1007
1007
  /**
1008
1008
  * Thread endpoint context with access to thread instance and metadata.
1009
+ * @deprecated Use ThreadState instead
1009
1010
  */
1010
1011
  interface ThreadEndpointContext {
1011
1012
  req: Request;
@@ -1017,46 +1018,14 @@ interface ThreadEndpointContext {
1017
1018
  /**
1018
1019
  * Handler function for builder thread endpoints.
1019
1020
  *
1020
- * Unlike the spec's ThreadEndpointHandler which receives ThreadState,
1021
- * the builder's handler receives direct access to the Durable Object
1022
- * instance and thread metadata. This allows for lower-level operations
1023
- * like calling RPC methods directly on the instance.
1024
- */
1025
- type BuilderThreadEndpointHandler = (req: Request, context: {
1026
- instance: ThreadInstance;
1027
- metadata: ThreadMetadata;
1028
- }) => Response | Promise<Response>;
1029
- /**
1030
- * Define a thread-specific endpoint with access to the Durable Object instance.
1031
- *
1032
- * This is the builder's version of defineThreadEndpoint. It provides direct
1033
- * access to the thread's Durable Object instance and metadata, allowing
1034
- * for lower-level operations like calling RPC methods directly.
1021
+ * Receives the request and a ThreadState object per the Standard Agents spec.
1022
+ * The ThreadState provides access to thread identity, messages, logs,
1023
+ * resource loading, tool invocation, and more.
1035
1024
  *
1036
- * @param handler - Function that receives the request and thread context
1037
- * @returns A Controller that can be used with the router
1038
- *
1039
- * @example
1040
- * ```typescript
1041
- * import { defineThreadEndpoint } from '@standardagents/builder';
1042
- *
1043
- * export default defineThreadEndpoint(async (req, { instance, metadata }) => {
1044
- * // Access thread metadata
1045
- * console.log('Thread ID:', metadata.id);
1046
- * console.log('Agent ID:', metadata.agent_id);
1047
- *
1048
- * // Call RPC methods on the Durable Object instance
1049
- * const messagesResult = await instance.getMessages();
1050
- * const logs = await instance.getLogs();
1051
- *
1052
- * return Response.json({
1053
- * messageCount: messagesResult.messages.length,
1054
- * logCount: logs.length,
1055
- * });
1056
- * });
1057
- * ```
1025
+ * Note: `state.execution` is always null in endpoints since the thread
1026
+ * is not actively executing.
1058
1027
  */
1059
- declare function defineThreadEndpoint(handler: BuilderThreadEndpointHandler): BuilderController;
1028
+ type BuilderThreadEndpointHandler = ThreadEndpointHandler;
1060
1029
 
1061
1030
  /**
1062
1031
  * Define a controller with typed Cloudflare environment bindings.
@@ -1075,6 +1044,25 @@ declare function defineThreadEndpoint(handler: BuilderThreadEndpointHandler): Bu
1075
1044
  * ```
1076
1045
  */
1077
1046
  declare function defineController<Env extends ThreadEnv = ThreadEnv>(controller: BuilderController<Env>): BuilderController<Env>;
1047
+ /**
1048
+ * Runtime implementation for defineThreadEndpoint.
1049
+ *
1050
+ * This wraps the spec's defineThreadEndpoint to provide the actual
1051
+ * thread lookup and ThreadState creation at runtime.
1052
+ *
1053
+ * @param handler - Function that receives the request and ThreadState
1054
+ * @returns A Controller that can be used with the router
1055
+ *
1056
+ * @example
1057
+ * // agentbuilder/api/threads/[id]/status.get.ts
1058
+ * import { defineThreadEndpoint } from '@standardagents/spec';
1059
+ *
1060
+ * export default defineThreadEndpoint(async (req, state) => {
1061
+ * const { messages } = await state.getMessages({ limit: 1 });
1062
+ * return Response.json({ status: "ok", messageCount: messages.length });
1063
+ * });
1064
+ */
1065
+ declare function createThreadEndpointHandler<Env extends ThreadEnv = ThreadEnv>(handler: ThreadEndpointHandler): BuilderController<Env>;
1078
1066
 
1079
1067
  /**
1080
1068
  * Authentication middleware for protecting API routes
@@ -3654,4 +3642,4 @@ type ProviderImagePart = ImagePart;
3654
3642
  /** @public Alias for FilePart */
3655
3643
  type ProviderFilePart = FilePart;
3656
3644
 
3657
- export { type Agent, type AgentBuilderEnv, type AgentDefinition, type AttachmentRef, type AuthContext, type AuthUser, type BroadcastOptions, type BuilderThreadEndpointHandler, type BuilderController as Controller, type BuilderControllerContext as ControllerContext, DurableAgentBuilder, DurableThread, type Env, type FileRecord, type FileStats, type FlowResult, type FlowState, FlowStateSdk, type FlowStateWithSdk, GitHubApiError, GitHubClient, type GitHubCommitResult, type GitHubConfig, type GitHubFileChange, type GrepResult, type ImageContentPart, type ImageContextConfig, type ImageMetadata, type InjectMessageOptions$1 as InjectMessageOptions, type Provider as LLMProviderInterface, type LLMResponse, type Message, type MessageContent, type ModelDefinition, type MultimodalContent, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptPart, type Provider$1 as Provider, type ProviderContentPart, type ProviderFilePart, type ProviderImagePart, type ProviderTextPart, type RequestContext, type SideConfig, type StorageBackend, type SubpromptConfig, type TelemetryEvent, type TextContentPart, type ThreadEndpointContext, type ThreadEnv, type ThreadInstance, type ThreadMetadata, type ThreadRegistryEntry, type ToolCall, type ToolConfig, type ToolResult, type UpdateThreadParams, type User, authenticate, buildImageDescription, cat, defineController, defineThreadEndpoint, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getThumbnail, getUnsummarizedImageAttachments, grep, hasImageAttachments, head, injectMessage, linkFile, mkdir, optimizeImageContext, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };
3645
+ export { type Agent, type AgentBuilderEnv, type AgentDefinition, type AttachmentRef, type AuthContext, type AuthUser, type BroadcastOptions, type BuilderThreadEndpointHandler, type BuilderController as Controller, type BuilderControllerContext as ControllerContext, DurableAgentBuilder, DurableThread, type Env, type FileRecord, type FileStats, type FlowResult, type FlowState, FlowStateSdk, type FlowStateWithSdk, GitHubApiError, GitHubClient, type GitHubCommitResult, type GitHubConfig, type GitHubFileChange, type GrepResult, type ImageContentPart, type ImageContextConfig, type ImageMetadata, type InjectMessageOptions$1 as InjectMessageOptions, type Provider as LLMProviderInterface, type LLMResponse, type Message, type MessageContent, type ModelDefinition, type MultimodalContent, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptPart, type Provider$1 as Provider, type ProviderContentPart, type ProviderFilePart, type ProviderImagePart, type ProviderTextPart, type RequestContext, type SideConfig, type StorageBackend, type SubpromptConfig, type TelemetryEvent, type TextContentPart, type ThreadEndpointContext, type ThreadEnv, type ThreadInstance, type ThreadMetadata, type ThreadRegistryEntry, type ToolCall, type ToolConfig, type ToolResult, type UpdateThreadParams, type User, authenticate, buildImageDescription, cat, createThreadEndpointHandler, defineController, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getThumbnail, getUnsummarizedImageAttachments, grep, hasImageAttachments, head, injectMessage, linkFile, mkdir, optimizeImageContext, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };