@standardagents/builder 0.29.0 → 0.29.1

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 { e as ThreadEnv, A as Agent, r as ThreadMetadata, t as ToolResult, M as Message, k as ClientToolRequest, l as ClientToolResponse, m as ClientStreamRequest, n as ClientStreamResponse, w as FileRecord, F as FlowState, y as FileStats, G as GrepResult, x as AttachmentRef, J as MessageContent, E as Env, q as ThreadInstance } from './index-Cp_Zcrhy.js';
2
- export { f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, o as ClientDuplex, p as ClientForwarding, B as Controller, a as ControllerContext, u as FlowResult, D as ImageContentPart, I as ImageMetadata, L as LLMResponse, H as MultimodalContent, R as RequestContext, S as StorageBackend, v as TelemetryEvent, z as TextContentPart, b as ThreadEndpointContext, T as ToolCall, g as callClient, h as callClientStream, c as createThreadEndpointHandler, j as decodeStreamChunk, d as defineController, i as encodeStreamChunk, s as supportsClientForwarding } from './index-Cp_Zcrhy.js';
1
+ import { e as ThreadEnv, A as Agent, r as ThreadMetadata, t as ToolResult, M as Message, k as ClientToolRequest, l as ClientToolResponse, m as ClientStreamRequest, n as ClientStreamResponse, w as FileRecord, F as FlowState, y as FileStats, G as GrepResult, x as AttachmentRef, J as MessageContent, E as Env, q as ThreadInstance } from './index-BNLDsLsL.js';
2
+ export { f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, o as ClientDuplex, p as ClientForwarding, B as Controller, a as ControllerContext, u as FlowResult, D as ImageContentPart, I as ImageMetadata, L as LLMResponse, H as MultimodalContent, R as RequestContext, S as StorageBackend, v as TelemetryEvent, z as TextContentPart, b as ThreadEndpointContext, T as ToolCall, g as callClient, h as callClientStream, c as createThreadEndpointHandler, j as decodeStreamChunk, d as defineController, i as encodeStreamChunk, s as supportsClientForwarding } from './index-BNLDsLsL.js';
3
3
  import { CodeExecutionOptions, CodeExecutionResult, SubagentRegistryEntry, InjectMessageInput, QueueMessageInput, 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';
@@ -1112,6 +1112,18 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
1112
1112
  } | null>;
1113
1113
  /** Default time to wait for the client to accept a stream open. */
1114
1114
  private static readonly CLIENT_STREAM_OPEN_TIMEOUT_MS;
1115
+ /** Poll cadence while waiting for a disconnected owner's bridge to return. */
1116
+ private static readonly OWNER_REATTACH_POLL_MS;
1117
+ /**
1118
+ * The thread HAS an elected execution owner, but its bridge socket is gone
1119
+ * (daemon restart, network blip, DO handoff). Summon the owning machine
1120
+ * through the per-user hub and wait for a bridge to re-attach instead of
1121
+ * failing the stream open instantly — that instant failure is what ended
1122
+ * Sama One turns with "workspace unavailable" whenever a slow tool/approval
1123
+ * outlived the socket. Threads with NO recorded owner (subagent children)
1124
+ * still fail fast so ancestor walk-up routing stays immediate.
1125
+ */
1126
+ private awaitOwnerBridgeSocket;
1115
1127
  /** Open a bidirectional byte stream to the connected owner client. */
1116
1128
  openClientStream(request: ClientStreamRequest): Promise<ClientStreamResponse>;
1117
1129
  private proxyStreams;
@@ -1147,6 +1159,9 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
1147
1159
  * instead of a silent hang.
1148
1160
  */
1149
1161
  notifyClientWaiting(toolCallId: string, threadId: string, userId: string | null): Promise<void>;
1162
+ /** Ask the user's hub to summon the owning machine's daemon to a thread.
1163
+ * Best-effort: wake failure must never fail the caller's own path. */
1164
+ private requestHubWake;
1150
1165
  /**
1151
1166
  * Park TTL expired: if the call is still pending, settle it as a durable,
1152
1167
  * VISIBLE failure — rewrite the waiting placeholder, mark the pending row
package/dist/runtime.js CHANGED
@@ -13583,7 +13583,9 @@ var init_ThreadStateImpl = __esm({
13583
13583
  error: "This thread runtime cannot open client streams. Client streaming requires the DurableThread bridge."
13584
13584
  };
13585
13585
  }
13586
- const local = await instance.openClientStream(request);
13586
+ const wakeUserId = this._metadata.user_id ?? null;
13587
+ const withWake = (threadId) => wakeUserId ? { ...request, wake: { threadId, userId: wakeUserId } } : request;
13588
+ const local = await instance.openClientStream(withWake(this._metadata.id));
13587
13589
  if (local.ok || !this.isNoClient(local)) return local;
13588
13590
  const env = this._threadInstance.env;
13589
13591
  if (!env?.AGENT_BUILDER_THREAD) return local;
@@ -13594,7 +13596,7 @@ var init_ThreadStateImpl = __esm({
13594
13596
  try {
13595
13597
  const stub = env.AGENT_BUILDER_THREAD.get(env.AGENT_BUILDER_THREAD.idFromName(parentId));
13596
13598
  if (typeof stub.proxyStreamOpen === "function") {
13597
- const opened = await stub.proxyStreamOpen(request);
13599
+ const opened = await stub.proxyStreamOpen(withWake(parentId));
13598
13600
  if (opened.ok && opened.id) {
13599
13601
  return { ok: true, duplex: this.buildProxyDuplex(stub, opened.id) };
13600
13602
  }
@@ -20329,10 +20331,40 @@ ${resultContent}${attachmentSummary}`;
20329
20331
  // they are bound to one bridge socket and never park.
20330
20332
  /** Default time to wait for the client to accept a stream open. */
20331
20333
  static CLIENT_STREAM_OPEN_TIMEOUT_MS = 3e4;
20334
+ /** Poll cadence while waiting for a disconnected owner's bridge to return. */
20335
+ static OWNER_REATTACH_POLL_MS = 250;
20336
+ /**
20337
+ * The thread HAS an elected execution owner, but its bridge socket is gone
20338
+ * (daemon restart, network blip, DO handoff). Summon the owning machine
20339
+ * through the per-user hub and wait for a bridge to re-attach instead of
20340
+ * failing the stream open instantly — that instant failure is what ended
20341
+ * Sama One turns with "workspace unavailable" whenever a slow tool/approval
20342
+ * outlived the socket. Threads with NO recorded owner (subagent children)
20343
+ * still fail fast so ancestor walk-up routing stays immediate.
20344
+ */
20345
+ async awaitOwnerBridgeSocket(request) {
20346
+ if (request.wake?.userId) {
20347
+ void this.requestHubWake(request.wake.userId, request.wake.threadId);
20348
+ }
20349
+ const timeoutMs = typeof request.timeoutMs === "number" && request.timeoutMs > 0 ? request.timeoutMs : _DurableThread.CLIENT_STREAM_OPEN_TIMEOUT_MS;
20350
+ const deadline = Date.now() + timeoutMs;
20351
+ while (Date.now() < deadline) {
20352
+ await new Promise(
20353
+ (resolve) => setTimeout(resolve, _DurableThread.OWNER_REATTACH_POLL_MS)
20354
+ );
20355
+ const owner = await this.getExecutionOwner();
20356
+ const socket = this.getOpenBridgeSocket(owner?.client_id ?? null);
20357
+ if (socket) return socket;
20358
+ }
20359
+ return null;
20360
+ }
20332
20361
  /** Open a bidirectional byte stream to the connected owner client. */
20333
20362
  async openClientStream(request) {
20334
20363
  const owner = await this.getExecutionOwner();
20335
- const socket = this.getOpenBridgeSocket(owner?.client_id ?? null);
20364
+ let socket = this.getOpenBridgeSocket(owner?.client_id ?? null);
20365
+ if (!socket && owner) {
20366
+ socket = await this.awaitOwnerBridgeSocket(request);
20367
+ }
20336
20368
  if (!socket) {
20337
20369
  return {
20338
20370
  ok: false,
@@ -20626,6 +20658,11 @@ ${resultContent}${attachmentSummary}`;
20626
20658
  console.error("[DurableThread] Failed to arm park TTL (non-fatal):", error);
20627
20659
  }
20628
20660
  if (!userId) return;
20661
+ await this.requestHubWake(userId, threadId);
20662
+ }
20663
+ /** Ask the user's hub to summon the owning machine's daemon to a thread.
20664
+ * Best-effort: wake failure must never fail the caller's own path. */
20665
+ async requestHubWake(userId, threadId) {
20629
20666
  try {
20630
20667
  const namespace = this.env.AGENT_BUILDER_USER_HUB;
20631
20668
  if (!namespace) return;