@standardagents/builder 0.37.8 → 0.38.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/runtime.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as AuthContext, e as ThreadEnv, v as Agent, x as ThreadMetadata, y as ToolResult, M as Message, n as ClientToolRequest, o as ClientToolResponse, p as ClientStreamRequest, q as ClientStreamResponse, G as FileRecord, F as FlowState, K as FileStats, J as GrepResult, H as AttachmentRef, Q as MessageContent, E as Env, w as ThreadInstance } from './index-Lfan8QMN.js';
2
- export { A as AuthUser, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, t as ClientDuplex, u as ClientForwarding, B as Controller, a as ControllerContext, z as FlowResult, O as ImageContentPart, I as ImageMetadata, L as LLMResponse, P as MultimodalContent, R as RequestContext, S as StorageBackend, D as TelemetryEvent, N as TextContentPart, b as ThreadEndpointContext, T as ToolCall, g as authenticate, j as callClient, k as callClientStream, c as createThreadEndpointHandler, m as decodeStreamChunk, d as defineController, l as encodeStreamChunk, h as requireAdmin, r as requireAuth, s as supportsClientForwarding } from './index-Lfan8QMN.js';
1
+ import { j as AuthContext, e as ThreadEnv, w as Agent, y as ThreadMetadata, z as ToolResult, M as Message, o as ClientToolRequest, p as ClientToolResponse, q as ClientStreamRequest, t as ClientStreamResponse, H as FileRecord, F as FlowState, N as FileStats, K as GrepResult, J as AttachmentRef, U as MessageContent, G as Env, x as ThreadInstance } from './index-BBu-Osn5.js';
2
+ export { A as AuthUser, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, u as ClientDuplex, v as ClientForwarding, B as Controller, a as ControllerContext, D as FlowResult, P as ImageContentPart, I as ImageMetadata, L as LLMResponse, Q as MultimodalContent, R as RequestContext, S as StorageBackend, E as TelemetryEvent, O as TextContentPart, b as ThreadEndpointContext, T as ToolCall, g as authenticate, k as callClient, l as callClientStream, c as createThreadEndpointHandler, n as decodeStreamChunk, d as defineController, m as encodeStreamChunk, i as endpointCallerFromAuth, h as requireAdmin, r as requireAuth, s as supportsClientForwarding } from './index-BBu-Osn5.js';
3
3
  import { CodeExecutionOptions, CodeExecutionResult, SubagentRegistryEntry, InjectMessageInput, QueueMessageInput, CredentialGrant, SkillMetadata, SkillFileInput, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, PromptEnvPart, VariableDefinition, SubpromptConfig as SubpromptConfig$1, PromptToolConfig as PromptToolConfig$1, SubagentToolConfig as SubagentToolConfig$1, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart, ThreadState, NamespaceContext, DefinitionLoader } from '@standardagents/spec';
4
4
  export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, 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, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel } from '@standardagents/spec';
5
5
  import { DurableObject, WorkerEntrypoint } from 'cloudflare:workers';
@@ -116,6 +116,7 @@ declare function canAccessThread(auth: AuthContext, thread: {
116
116
  user_id: string | null;
117
117
  }): boolean;
118
118
 
119
+ /** Central API exposure policy shared by the generated Worker router and tests. */
119
120
  declare function isHostedInstance(env: Record<string, unknown> | undefined): boolean;
120
121
  /**
121
122
  * Local-only conveniences are enabled by the request destination, not merely
package/dist/runtime.js CHANGED
@@ -14703,54 +14703,6 @@ var init_image_processing = __esm({
14703
14703
 
14704
14704
  // src/router/index.ts
14705
14705
  init_ThreadStateImpl();
14706
- function defineController2(controller) {
14707
- return controller;
14708
- }
14709
- function createThreadEndpointHandler(handler) {
14710
- return (async ({ req, params, env }) => {
14711
- const threadId = params.threadId ?? params.id;
14712
- if (!threadId) {
14713
- return Response.json({ error: "Thread ID required" }, { status: 400 });
14714
- }
14715
- try {
14716
- const agentBuilderId = env.AGENT_BUILDER.idFromName("singleton");
14717
- const agentBuilder = env.AGENT_BUILDER.get(agentBuilderId);
14718
- const metadata = await agentBuilder.getThread(threadId);
14719
- if (!metadata) {
14720
- return Response.json(
14721
- { error: `Thread not found: ${threadId}` },
14722
- { status: 404 }
14723
- );
14724
- }
14725
- const meta = metadata;
14726
- if (!meta.agent_id && meta.agent_name) {
14727
- meta.agent_id = meta.agent_name;
14728
- }
14729
- const durableId = env.AGENT_BUILDER_THREAD.idFromName(threadId);
14730
- const stub = env.AGENT_BUILDER_THREAD.get(durableId);
14731
- const instance = stub;
14732
- const threadState = ThreadStateImpl.fromThreadInstance(instance, metadata, {
14733
- env
14734
- });
14735
- const endpointParams = {};
14736
- for (const [key, value] of Object.entries(params)) {
14737
- if (key === "threadId" || key === "id" && !params.threadId) {
14738
- continue;
14739
- }
14740
- endpointParams[key === "_" ? "*" : key] = value;
14741
- }
14742
- const response = await handler(req, threadState, endpointParams);
14743
- await threadState.flushPendingEventDeliveries();
14744
- return response;
14745
- } catch (error) {
14746
- console.error(`Error in thread endpoint for ${threadId}:`, error);
14747
- return Response.json(
14748
- { error: error.message || "Internal server error" },
14749
- { status: 500 }
14750
- );
14751
- }
14752
- });
14753
- }
14754
14706
 
14755
14707
  // src/utils/auth.ts
14756
14708
  async function hashToken(token) {
@@ -14841,6 +14793,19 @@ var CORS_HEADERS = {
14841
14793
  "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
14842
14794
  "Access-Control-Max-Age": "86400"
14843
14795
  };
14796
+ function endpointCallerFromAuth(auth) {
14797
+ if (!auth) return null;
14798
+ const { id, username, role, permissions, email, display_name, avatar_url } = auth.user;
14799
+ return {
14800
+ id,
14801
+ username,
14802
+ role,
14803
+ permissions: permissions ?? null,
14804
+ email: email ?? null,
14805
+ display_name: display_name ?? null,
14806
+ avatar_url: avatar_url ?? null
14807
+ };
14808
+ }
14844
14809
  function parsePermissions(value) {
14845
14810
  if (Array.isArray(value)) return value.filter((p) => typeof p === "string");
14846
14811
  if (typeof value === "string" && value.trim()) {
@@ -14975,6 +14940,61 @@ async function requireAdmin(request, env) {
14975
14940
  }
14976
14941
  return result;
14977
14942
  }
14943
+ function defineController2(controller) {
14944
+ return controller;
14945
+ }
14946
+ function createThreadEndpointHandler(handler) {
14947
+ return (async (context) => {
14948
+ const { req, params, env } = context;
14949
+ const threadId = params.threadId ?? params.id;
14950
+ if (!threadId) {
14951
+ return Response.json({ error: "Thread ID required" }, { status: 400 });
14952
+ }
14953
+ const endpointAuth = {
14954
+ caller: endpointCallerFromAuth(context.auth),
14955
+ threadAccess: Boolean(
14956
+ context.threadAccess && context.threadAccess.threadId === threadId
14957
+ )
14958
+ };
14959
+ try {
14960
+ const agentBuilderId = env.AGENT_BUILDER.idFromName("singleton");
14961
+ const agentBuilder = env.AGENT_BUILDER.get(agentBuilderId);
14962
+ const metadata = await agentBuilder.getThread(threadId);
14963
+ if (!metadata) {
14964
+ return Response.json(
14965
+ { error: `Thread not found: ${threadId}` },
14966
+ { status: 404 }
14967
+ );
14968
+ }
14969
+ const meta = metadata;
14970
+ if (!meta.agent_id && meta.agent_name) {
14971
+ meta.agent_id = meta.agent_name;
14972
+ }
14973
+ const durableId = env.AGENT_BUILDER_THREAD.idFromName(threadId);
14974
+ const stub = env.AGENT_BUILDER_THREAD.get(durableId);
14975
+ const instance = stub;
14976
+ const threadState = ThreadStateImpl.fromThreadInstance(instance, metadata, {
14977
+ env
14978
+ });
14979
+ const endpointParams = {};
14980
+ for (const [key, value] of Object.entries(params)) {
14981
+ if (key === "threadId" || key === "id" && !params.threadId) {
14982
+ continue;
14983
+ }
14984
+ endpointParams[key === "_" ? "*" : key] = value;
14985
+ }
14986
+ const response = await handler(req, threadState, endpointParams, endpointAuth);
14987
+ await threadState.flushPendingEventDeliveries();
14988
+ return response;
14989
+ } catch (error) {
14990
+ console.error(`Error in thread endpoint for ${threadId}:`, error);
14991
+ return Response.json(
14992
+ { error: error.message || "Internal server error" },
14993
+ { status: 500 }
14994
+ );
14995
+ }
14996
+ });
14997
+ }
14978
14998
 
14979
14999
  // src/utils/permissions.ts
14980
15000
  function canAccessThread(auth, thread) {
@@ -15007,10 +15027,6 @@ var PUBLIC_ROUTES = /* @__PURE__ */ new Set([
15007
15027
  function isProviderIconRoute(routePath) {
15008
15028
  return /^\/api\/providers\/[^/]+\/icon$/.test(routePath);
15009
15029
  }
15010
- function isPublicThreadFileRoute(routePath, method) {
15011
- if (method !== "GET" && method !== "HEAD") return false;
15012
- return /^\/api\/threads\/[^/]+\/public\/.+/.test(routePath);
15013
- }
15014
15030
  function isHostedInstance(env) {
15015
15031
  const value = env?.STANDARD_AGENTS_HOSTED;
15016
15032
  if (typeof value === "string") {
@@ -15037,9 +15053,6 @@ function isPublicApiRoute(routePath, request, env) {
15037
15053
  if (isProviderIconRoute(routePath)) {
15038
15054
  return true;
15039
15055
  }
15040
- if (isPublicThreadFileRoute(routePath, request.method.toUpperCase())) {
15041
- return true;
15042
- }
15043
15056
  if (!isTrustedLocalDevelopmentRequest(request, env)) return false;
15044
15057
  return routePath === "/api/threads" || routePath.startsWith("/api/threads/") || routePath === "/api/platform" || routePath.startsWith("/api/platform/") || routePath === "/api/platform-session" || routePath.startsWith("/api/platform-session/") || routePath === "/api/platform-auth" || routePath.startsWith("/api/platform-auth/");
15045
15058
  }
@@ -29034,6 +29047,6 @@ init_context();
29034
29047
  init_ProviderRegistry();
29035
29048
  init_types2();
29036
29049
 
29037
- export { CLIENT_STREAM_CHUNK_BYTES, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, NamespaceResolutionError, ProviderRegistry, ThreadWatchdog, authenticate, buildImageDescription, callClient, callClientStream, canAccessThread, cat, createNamespaceContext, createThreadEndpointHandler, decodeStreamChunk, defineController2 as defineController, emitThreadEvent, encodeStreamChunk, enhanceFlowState, exists, find, forceTurn, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isAdminOnlyApiRoute, isHostedInstance, isPublicApiRoute, isQualifiedName, isTrustedLocalDevelopmentRequest, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, supportsClientForwarding, tail, unlink, updateThread, writeFile, writeImage };
29050
+ export { CLIENT_STREAM_CHUNK_BYTES, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, NamespaceResolutionError, ProviderRegistry, ThreadWatchdog, authenticate, buildImageDescription, callClient, callClientStream, canAccessThread, cat, createNamespaceContext, createThreadEndpointHandler, decodeStreamChunk, defineController2 as defineController, emitThreadEvent, encodeStreamChunk, endpointCallerFromAuth, enhanceFlowState, exists, find, forceTurn, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isAdminOnlyApiRoute, isHostedInstance, isPublicApiRoute, isQualifiedName, isTrustedLocalDevelopmentRequest, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, supportsClientForwarding, tail, unlink, updateThread, writeFile, writeImage };
29038
29051
  //# sourceMappingURL=runtime.js.map
29039
29052
  //# sourceMappingURL=runtime.js.map