@standardagents/builder 0.20.0 → 0.21.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.
@@ -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 {
@@ -20128,9 +20275,24 @@ function platformLoginUrl(request, env) {
20128
20275
  return url.toString();
20129
20276
  }
20130
20277
 
20278
+ function isUiNavigationPath(pathname) {
20279
+ if (!pathname || pathname === '/') return true;
20280
+ if (pathname.startsWith('/api/')) return false;
20281
+ const lastSegment = pathname.split('/').pop() || '';
20282
+ return !lastSegment.includes('.');
20283
+ }
20284
+
20131
20285
  function isHtmlNavigationRequest(request) {
20132
20286
  if (request.method !== 'GET' && request.method !== 'HEAD') return false;
20133
- return (request.headers.get('Accept') || '').includes('text/html');
20287
+ const accept = (request.headers.get('Accept') || '').toLowerCase();
20288
+ if (accept.includes('text/html')) return true;
20289
+
20290
+ const fetchDest = (request.headers.get('Sec-Fetch-Dest') || '').toLowerCase();
20291
+ if (fetchDest === 'document') return true;
20292
+ if (fetchDest && fetchDest !== 'empty') return false;
20293
+
20294
+ const pathname = new URL(request.url).pathname || '/';
20295
+ return (accept === '' || accept === '*/*') && isUiNavigationPath(pathname);
20134
20296
  }
20135
20297
 
20136
20298
  // CORS headers for API responses
@@ -22909,6 +23071,11 @@ function createEndpointThreadStateBridge(state) {
22909
23071
  unlinkFile: (path20) => state.unlinkFile(normalizeEndpointThreadPath(path20)),
22910
23072
  mkdirFile: (path20) => state.mkdirFile(normalizeEndpointThreadPath(path20)),
22911
23073
  rmdirFile: (path20) => state.rmdirFile(normalizeEndpointThreadPath(path20)),
23074
+ moveFile: (sourcePath, destinationPath) => state.moveFile(
23075
+ normalizeEndpointThreadPath(sourcePath),
23076
+ normalizeEndpointThreadPath(destinationPath)
23077
+ ),
23078
+ renameFile: (path20, newName) => state.renameFile(normalizeEndpointThreadPath(path20), newName),
22912
23079
  getFileStats: () => state.getFileStats(),
22913
23080
  grepFiles: (pattern) => state.grepFiles(pattern),
22914
23081
  findFiles: (pattern) => state.findFiles(pattern),
@@ -27028,6 +27195,43 @@ ${resultContent}${attachmentSummary}`;
27028
27195
  return { success: false, error: error.message };
27029
27196
  }
27030
27197
  }
27198
+ /**
27199
+ * Move or rename a file or directory (RPC method).
27200
+ * Relocates inline files, chunked files, and whole directory subtrees.
27201
+ */
27202
+ async moveFile(sourcePath, destinationPath) {
27203
+ await this.ensureMigrated();
27204
+ try {
27205
+ const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
27206
+ const fs18 = this.getFileStorage();
27207
+ const from = normalizePath2(sourcePath);
27208
+ const record = await fs18.move(sourcePath, destinationPath);
27209
+ this.broadcastEvent("file_deleted", { path: from });
27210
+ this.broadcastEvent("file_created", { path: record.path, file: record });
27211
+ return { success: true, file: record };
27212
+ } catch (error) {
27213
+ console.error("Error in moveFile:", error);
27214
+ return { success: false, error: error.message };
27215
+ }
27216
+ }
27217
+ /**
27218
+ * Rename a file or directory in place (RPC method).
27219
+ */
27220
+ async renameFile(path20, newName) {
27221
+ await this.ensureMigrated();
27222
+ try {
27223
+ const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
27224
+ const fs18 = this.getFileStorage();
27225
+ const from = normalizePath2(path20);
27226
+ const record = await fs18.rename(path20, newName);
27227
+ this.broadcastEvent("file_deleted", { path: from });
27228
+ this.broadcastEvent("file_created", { path: record.path, file: record });
27229
+ return { success: true, file: record };
27230
+ } catch (error) {
27231
+ console.error("Error in renameFile:", error);
27232
+ return { success: false, error: error.message };
27233
+ }
27234
+ }
27031
27235
  /**
27032
27236
  * Get file storage statistics (RPC method)
27033
27237
  */
@@ -30354,6 +30558,6 @@ init_context();
30354
30558
  init_ProviderRegistry();
30355
30559
  init_types2();
30356
30560
 
30357
- 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 };
30561
+ 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 };
30358
30562
  //# sourceMappingURL=index.js.map
30359
30563
  //# sourceMappingURL=index.js.map