@standardagents/builder 0.20.1 → 0.21.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.
@@ -286,6 +286,16 @@ interface ThreadInstance {
286
286
  unlinkFile(path: string): Promise<void>;
287
287
  mkdirFile(path: string): Promise<any>;
288
288
  rmdirFile(path: string): Promise<void>;
289
+ moveFile(sourcePath: string, destinationPath: string): Promise<{
290
+ success: boolean;
291
+ file?: any;
292
+ error?: string;
293
+ }>;
294
+ renameFile(path: string, newName: string): Promise<{
295
+ success: boolean;
296
+ file?: any;
297
+ error?: string;
298
+ }>;
289
299
  getFileStats(): Promise<any>;
290
300
  grepFiles(pattern: string): Promise<any[]>;
291
301
  findFiles(pattern: string): Promise<any>;
@@ -840,10 +850,12 @@ interface Env extends ThreadEnv {
840
850
  CLOUDFLARE_API_TOKEN?: string;
841
851
  CLOUDFLARE_ACCOUNT_ID?: string;
842
852
  CEREBRAS_API_KEY?: string;
853
+ GROQ_API_KEY?: string;
843
854
  OPENAI_API_KEY?: string;
844
855
  ANTHROPIC_API_KEY?: string;
845
856
  OPENROUTER_API_KEY?: string;
846
857
  GOOGLE_API_KEY?: string;
858
+ XAI_API_KEY?: string;
847
859
  UI_DEV_SERVER?: string;
848
860
  ASSETS?: {
849
861
  fetch(request: Request | string): Promise<Response>;
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, ToolConfig, UpdateThreadParams, User, 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, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, 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, FlowStateSdk, FlowStateWithSdk, ImageContextConfig, InjectMessageOptions, LLMProviderInterface, NamespaceResolutionError, PromptContent, PromptDefinition, PromptIncludePart, PromptPart, PromptToolConfig, Provider, ProviderContentPart, ProviderFilePart, ProviderImagePart, ProviderRegistry, ProviderTextPart, SessionToolBinding, SessionToolConfig, SideConfig, SubagentToolConfig, SubpromptConfig, ThreadRegistryEntry, ToolConfig, UpdateThreadParams, User, 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, m as AttachmentRef, f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, E as Env, l as FileRecord, n as FileStats, j as FlowResult, F as FlowState, G as GrepResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, r as MessageContent, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, g as ThreadInstance, h as ThreadMetadata, T as ToolCall, i as ToolResult, c as createThreadEndpointHandler, d as defineController } from './index-Bug9ATQX.js';
4
+ export { A as Agent, m as AttachmentRef, f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, E as Env, l as FileRecord, n as FileStats, j as FlowResult, F as FlowState, G as GrepResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, r as MessageContent, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, g as ThreadInstance, h as ThreadMetadata, T as ToolCall, i as ToolResult, c as createThreadEndpointHandler, d as defineController } from './index-CpuS9hHJ.js';
5
5
  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';
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';
package/dist/index.js CHANGED
@@ -2513,7 +2513,9 @@ __export(files_exports, {
2513
2513
  dirname: () => dirname3,
2514
2514
  isTextMimeType: () => isTextMimeType,
2515
2515
  normalizePath: () => normalizePath,
2516
- rowToFileRecord: () => rowToFileRecord
2516
+ resolveRenameDestination: () => resolveRenameDestination,
2517
+ rowToFileRecord: () => rowToFileRecord,
2518
+ validateMovePaths: () => validateMovePaths
2517
2519
  });
2518
2520
  function isTextMimeType(mimeType) {
2519
2521
  if (mimeType.startsWith("text/")) return true;
@@ -2546,6 +2548,33 @@ function dirname3(path20) {
2546
2548
  if (lastSlash <= 0) return "/";
2547
2549
  return normalized.slice(0, lastSlash);
2548
2550
  }
2551
+ function validateMovePaths(source, destination, isDirectory) {
2552
+ if (source === "/") {
2553
+ throw new Error("Cannot move the root directory");
2554
+ }
2555
+ if (destination === "/") {
2556
+ throw new Error("Cannot move over the root directory");
2557
+ }
2558
+ if (isDirectory && destination.startsWith(source + "/")) {
2559
+ throw new Error(
2560
+ "Cannot move a directory into itself or one of its descendants"
2561
+ );
2562
+ }
2563
+ }
2564
+ function resolveRenameDestination(path20, newName) {
2565
+ if (typeof newName !== "string" || newName.length === 0) {
2566
+ throw new Error("New name must be a non-empty string");
2567
+ }
2568
+ if (newName.includes("/")) {
2569
+ throw new Error("New name must not contain path separators");
2570
+ }
2571
+ if (newName === "." || newName === "..") {
2572
+ throw new Error("New name must not be '.' or '..'");
2573
+ }
2574
+ const normalized = normalizePath(path20);
2575
+ const parent = dirname3(normalized);
2576
+ return parent === "/" ? `/${newName}` : `${parent}/${newName}`;
2577
+ }
2549
2578
  function rowToFileRecord(row) {
2550
2579
  return {
2551
2580
  path: row.path,
@@ -3022,6 +3051,94 @@ var init_files = __esm({
3022
3051
  normalizedPath
3023
3052
  );
3024
3053
  }
3054
+ /**
3055
+ * Move (or rename) a file or directory from one path to another.
3056
+ *
3057
+ * Works for inline files, chunked files, and directories. Moving a
3058
+ * directory relocates the directory marker and every descendant entry,
3059
+ * preserving their relative layout. The destination must not already
3060
+ * exist, and a directory cannot be moved into itself or one of its own
3061
+ * descendants.
3062
+ *
3063
+ * Implementation note: the `file_chunks` table has a foreign key on
3064
+ * `files(path)` with `ON DELETE CASCADE`, and there is no `ON UPDATE`
3065
+ * action. To keep referential integrity intact (foreign key enforcement
3066
+ * is on in Durable Object SQLite), we copy the affected rows to their new
3067
+ * paths first, then delete the originals — the cascade removes the old
3068
+ * chunks, while the freshly copied chunks already point at the new file
3069
+ * rows. This never leaves an orphaned chunk mid-operation.
3070
+ */
3071
+ async move(sourcePath, destinationPath) {
3072
+ const source = normalizePath(sourcePath);
3073
+ const destination = normalizePath(destinationPath);
3074
+ if (source === destination) {
3075
+ const existing = await this.stat(source);
3076
+ if (!existing) {
3077
+ throw new Error(`Source path does not exist: ${source}`);
3078
+ }
3079
+ return existing;
3080
+ }
3081
+ const record = await this.stat(source);
3082
+ if (!record) {
3083
+ throw new Error(`Source path does not exist: ${source}`);
3084
+ }
3085
+ validateMovePaths(source, destination, record.isDirectory);
3086
+ const destPrefix = destination + "/";
3087
+ const collision = await this.sql.exec(
3088
+ `SELECT COUNT(*) as count FROM files WHERE path = ? OR path LIKE ? || '%'`,
3089
+ destination,
3090
+ destPrefix
3091
+ );
3092
+ if (collision.one().count > 0) {
3093
+ throw new Error(`Destination already exists: ${destination}`);
3094
+ }
3095
+ const sourcePrefix = source + "/";
3096
+ const sourceLen = source.length;
3097
+ const destName = basename2(destination);
3098
+ await this.sql.exec(
3099
+ `INSERT INTO files (path, name, mime_type, storage, location, data, content, size, metadata, thumbnail, is_directory, created_at, width, height, is_chunked, chunk_count)
3100
+ SELECT ? || SUBSTR(path, ? + 1), name, mime_type, storage, location, data, content, size, metadata, thumbnail, is_directory, created_at, width, height, is_chunked, chunk_count
3101
+ FROM files
3102
+ WHERE path = ? OR path LIKE ? || '%'`,
3103
+ destination,
3104
+ sourceLen,
3105
+ source,
3106
+ sourcePrefix
3107
+ );
3108
+ await this.sql.exec(
3109
+ `INSERT INTO file_chunks (file_path, chunk_index, data)
3110
+ SELECT ? || SUBSTR(file_path, ? + 1), chunk_index, data
3111
+ FROM file_chunks
3112
+ WHERE file_path = ? OR file_path LIKE ? || '%'`,
3113
+ destination,
3114
+ sourceLen,
3115
+ source,
3116
+ sourcePrefix
3117
+ );
3118
+ await this.sql.exec(
3119
+ `DELETE FROM files WHERE path = ? OR path LIKE ? || '%'`,
3120
+ source,
3121
+ sourcePrefix
3122
+ );
3123
+ await this.sql.exec(
3124
+ `UPDATE files SET name = ? WHERE path = ?`,
3125
+ destName,
3126
+ destination
3127
+ );
3128
+ const moved = await this.stat(destination);
3129
+ if (!moved) {
3130
+ throw new Error(`Failed to move ${source} to ${destination}`);
3131
+ }
3132
+ return moved;
3133
+ }
3134
+ /**
3135
+ * Rename a file or directory in place, keeping it in the same parent
3136
+ * directory. `newName` must be a bare file name with no path separators.
3137
+ */
3138
+ async rename(path20, newName) {
3139
+ const destination = resolveRenameDestination(path20, newName);
3140
+ return this.move(normalizePath(path20), destination);
3141
+ }
3025
3142
  /**
3026
3143
  * Get storage statistics
3027
3144
  */
@@ -9864,6 +9981,22 @@ async function rmdir(flow, path20) {
9864
9981
  throw new Error(result.error || "Failed to remove directory");
9865
9982
  }
9866
9983
  }
9984
+ async function move(flow, sourcePath, destinationPath) {
9985
+ const instance = flow.thread.instance;
9986
+ const result = await instance.moveFile(sourcePath, destinationPath);
9987
+ if (!result.success) {
9988
+ throw new Error(result.error || "Failed to move file");
9989
+ }
9990
+ return result.file;
9991
+ }
9992
+ async function rename(flow, path20, newName) {
9993
+ const instance = flow.thread.instance;
9994
+ const result = await instance.renameFile(path20, newName);
9995
+ if (!result.success) {
9996
+ throw new Error(result.error || "Failed to rename file");
9997
+ }
9998
+ return result.file;
9999
+ }
9867
10000
  async function getFileStats(flow) {
9868
10001
  const instance = flow.thread.instance;
9869
10002
  const result = await instance.getFileStats();
@@ -12489,6 +12622,20 @@ var init_ThreadStateImpl = __esm({
12489
12622
  async rmdirFile(path20) {
12490
12623
  await this._threadInstance.rmdirFile(path20);
12491
12624
  }
12625
+ async moveFile(sourcePath, destinationPath) {
12626
+ const result = await this._threadInstance.moveFile(sourcePath, destinationPath);
12627
+ if (!result.success || !result.file) {
12628
+ throw new Error(result.error || "Failed to move file");
12629
+ }
12630
+ return this._mapFileRecord(result.file);
12631
+ }
12632
+ async renameFile(path20, newName) {
12633
+ const result = await this._threadInstance.renameFile(path20, newName);
12634
+ if (!result.success || !result.file) {
12635
+ throw new Error(result.error || "Failed to rename file");
12636
+ }
12637
+ return this._mapFileRecord(result.file);
12638
+ }
12492
12639
  async getFileStats() {
12493
12640
  const stats = await this._threadInstance.getFileStats();
12494
12641
  return {
@@ -20021,6 +20168,7 @@ const PUBLIC_ROUTES = [
20021
20168
  '/api/auth/bootstrap',
20022
20169
  '/api/auth/login',
20023
20170
  '/api/auth/config',
20171
+ '/api/auth/platform-cleanup',
20024
20172
  '/api/auth/platform-replica',
20025
20173
  '/api/auth/sa/start', // Login with Standard Agents (OAuth) \u2014 unauthenticated entry
20026
20174
  '/api/auth/sa/callback', // OAuth callback (sets the session cookie)
@@ -22924,6 +23072,11 @@ function createEndpointThreadStateBridge(state) {
22924
23072
  unlinkFile: (path20) => state.unlinkFile(normalizeEndpointThreadPath(path20)),
22925
23073
  mkdirFile: (path20) => state.mkdirFile(normalizeEndpointThreadPath(path20)),
22926
23074
  rmdirFile: (path20) => state.rmdirFile(normalizeEndpointThreadPath(path20)),
23075
+ moveFile: (sourcePath, destinationPath) => state.moveFile(
23076
+ normalizeEndpointThreadPath(sourcePath),
23077
+ normalizeEndpointThreadPath(destinationPath)
23078
+ ),
23079
+ renameFile: (path20, newName) => state.renameFile(normalizeEndpointThreadPath(path20), newName),
22927
23080
  getFileStats: () => state.getFileStats(),
22928
23081
  grepFiles: (pattern) => state.grepFiles(pattern),
22929
23082
  findFiles: (pattern) => state.findFiles(pattern),
@@ -27043,6 +27196,43 @@ ${resultContent}${attachmentSummary}`;
27043
27196
  return { success: false, error: error.message };
27044
27197
  }
27045
27198
  }
27199
+ /**
27200
+ * Move or rename a file or directory (RPC method).
27201
+ * Relocates inline files, chunked files, and whole directory subtrees.
27202
+ */
27203
+ async moveFile(sourcePath, destinationPath) {
27204
+ await this.ensureMigrated();
27205
+ try {
27206
+ const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
27207
+ const fs18 = this.getFileStorage();
27208
+ const from = normalizePath2(sourcePath);
27209
+ const record = await fs18.move(sourcePath, destinationPath);
27210
+ this.broadcastEvent("file_deleted", { path: from });
27211
+ this.broadcastEvent("file_created", { path: record.path, file: record });
27212
+ return { success: true, file: record };
27213
+ } catch (error) {
27214
+ console.error("Error in moveFile:", error);
27215
+ return { success: false, error: error.message };
27216
+ }
27217
+ }
27218
+ /**
27219
+ * Rename a file or directory in place (RPC method).
27220
+ */
27221
+ async renameFile(path20, newName) {
27222
+ await this.ensureMigrated();
27223
+ try {
27224
+ const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
27225
+ const fs18 = this.getFileStorage();
27226
+ const from = normalizePath2(path20);
27227
+ const record = await fs18.rename(path20, newName);
27228
+ this.broadcastEvent("file_deleted", { path: from });
27229
+ this.broadcastEvent("file_created", { path: record.path, file: record });
27230
+ return { success: true, file: record };
27231
+ } catch (error) {
27232
+ console.error("Error in renameFile:", error);
27233
+ return { success: false, error: error.message };
27234
+ }
27235
+ }
27046
27236
  /**
27047
27237
  * Get file storage statistics (RPC method)
27048
27238
  */
@@ -28390,6 +28580,24 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
28390
28580
  this.broadcastEvent({ type: "thread_deleted", threadId: id });
28391
28581
  return true;
28392
28582
  }
28583
+ /**
28584
+ * Delete all singleton AgentBuilder storage for platform-owned teardown.
28585
+ * Used when the hosting platform expires a preview branch deployment after
28586
+ * all thread Durable Objects have already been wiped.
28587
+ */
28588
+ async deleteAllStorage() {
28589
+ for (const ws of Array.from(this.eventSockets)) {
28590
+ try {
28591
+ ws.close(1e3, "Instance deleted");
28592
+ } catch {
28593
+ }
28594
+ }
28595
+ this.eventSockets.clear();
28596
+ await this.ctx.storage.deleteAlarm();
28597
+ await this.ctx.storage.deleteAll();
28598
+ this.migratedToVersion = null;
28599
+ return { success: true, message: "AgentBuilder storage completely deleted" };
28600
+ }
28393
28601
  /**
28394
28602
  * Get a thread tree (root + all descendants) in child-first order.
28395
28603
  *
@@ -30369,6 +30577,6 @@ init_context();
30369
30577
  init_ProviderRegistry();
30370
30578
  init_types2();
30371
30579
 
30372
- export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, FlowStateSdk, NamespaceResolutionError, PackageDiscoveryService, ProviderRegistry, agentbuilder, authenticate, buildImageDescription, builder, cat, createNamespaceContext, createThreadEndpointHandler, defineController2 as defineController, discoverPackages, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isQualifiedName, linkFile, mkdir, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };
30580
+ export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, FlowStateSdk, NamespaceResolutionError, PackageDiscoveryService, ProviderRegistry, agentbuilder, authenticate, buildImageDescription, builder, cat, createNamespaceContext, createThreadEndpointHandler, defineController2 as defineController, discoverPackages, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, 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 };
30373
30581
  //# sourceMappingURL=index.js.map
30374
30582
  //# sourceMappingURL=index.js.map