@standardagents/builder 0.11.0 → 0.11.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/index.d.ts CHANGED
@@ -281,7 +281,8 @@ interface ThreadInstance {
281
281
  loadAgent(name: string): Promise<any>;
282
282
  getPromptNames(): string[];
283
283
  getAgentNames(): string[];
284
- writeFile(path: string, data: ArrayBuffer | string, mimeType: string, options?: Record<string, unknown>): Promise<any>;
284
+ writeFile(path: string, data: string, mimeType: string, options?: Record<string, unknown>): Promise<any>;
285
+ writeTextFile(path: string, content: string, mimeType: string, options?: Record<string, unknown>): Promise<any>;
285
286
  readFile(path: string): Promise<{
286
287
  success: boolean;
287
288
  data?: string;
package/dist/index.js CHANGED
@@ -2212,8 +2212,105 @@ var init_ThreadStateImpl = __esm({
2212
2212
  // File System
2213
2213
  // ─────────────────────────────────────────────────────────────────────────
2214
2214
  async writeFile(path4, data, mimeType, options) {
2215
- const result = await this._threadInstance.writeFile(path4, data, mimeType, options);
2216
- return this._mapFileRecord(result);
2215
+ const isText = this._isTextMimeType(mimeType);
2216
+ if (isText) {
2217
+ let textContent;
2218
+ if (typeof data === "string") {
2219
+ textContent = data;
2220
+ } else {
2221
+ textContent = new TextDecoder().decode(data);
2222
+ }
2223
+ const result = await this._threadInstance.writeTextFile(path4, textContent, mimeType, options);
2224
+ return this._mapFileRecord(result.file);
2225
+ } else {
2226
+ let base64Data;
2227
+ if (typeof data === "string") {
2228
+ const encoder = new TextEncoder();
2229
+ const bytes = encoder.encode(data);
2230
+ let binary = "";
2231
+ for (let i = 0; i < bytes.length; i++) {
2232
+ binary += String.fromCharCode(bytes[i]);
2233
+ }
2234
+ base64Data = btoa(binary);
2235
+ } else {
2236
+ const bytes = new Uint8Array(data);
2237
+ let binary = "";
2238
+ for (let i = 0; i < bytes.length; i++) {
2239
+ binary += String.fromCharCode(bytes[i]);
2240
+ }
2241
+ base64Data = btoa(binary);
2242
+ }
2243
+ const result = await this._threadInstance.writeFile(path4, base64Data, mimeType, options);
2244
+ return this._mapFileRecord(result.file);
2245
+ }
2246
+ }
2247
+ /**
2248
+ * Check if a MIME type should be stored as searchable text.
2249
+ * Matches the logic in FileStorage for consistency.
2250
+ */
2251
+ _isTextMimeType(mimeType) {
2252
+ if (mimeType.startsWith("text/")) return true;
2253
+ const TEXT_APPLICATION_TYPES2 = [
2254
+ // Data formats
2255
+ "application/json",
2256
+ "application/ld+json",
2257
+ "application/json5",
2258
+ "application/jsonl",
2259
+ "application/x-ndjson",
2260
+ "application/xml",
2261
+ "application/xhtml+xml",
2262
+ "application/rss+xml",
2263
+ "application/atom+xml",
2264
+ "application/soap+xml",
2265
+ "application/yaml",
2266
+ "application/x-yaml",
2267
+ "application/toml",
2268
+ "application/x-toml",
2269
+ // Programming languages
2270
+ "application/javascript",
2271
+ "application/x-javascript",
2272
+ "application/ecmascript",
2273
+ "application/typescript",
2274
+ "application/x-typescript",
2275
+ "application/x-python",
2276
+ "application/x-ruby",
2277
+ "application/x-perl",
2278
+ "application/x-php",
2279
+ "application/x-sh",
2280
+ "application/x-bash",
2281
+ "application/x-csh",
2282
+ "application/x-zsh",
2283
+ "application/x-powershell",
2284
+ "application/x-lua",
2285
+ "application/x-tcl",
2286
+ // Query/config languages
2287
+ "application/sql",
2288
+ "application/x-sql",
2289
+ "application/graphql",
2290
+ "application/x-graphql",
2291
+ "application/sparql-query",
2292
+ "application/sparql-results+json",
2293
+ "application/sparql-results+xml",
2294
+ // Markup/templates
2295
+ "application/x-httpd-php",
2296
+ "application/x-latex",
2297
+ "application/x-tex",
2298
+ "application/rtf",
2299
+ "application/xslt+xml",
2300
+ // Web
2301
+ "application/x-www-form-urlencoded",
2302
+ "application/manifest+json",
2303
+ "application/webmanifest+json",
2304
+ "application/x-web-app-manifest+json",
2305
+ // Config files
2306
+ "application/x-ini",
2307
+ "application/x-properties",
2308
+ "application/plist",
2309
+ "application/x-plist"
2310
+ ];
2311
+ return TEXT_APPLICATION_TYPES2.some(
2312
+ (type) => mimeType === type || mimeType.startsWith(type + ";")
2313
+ );
2217
2314
  }
2218
2315
  async readFile(path4) {
2219
2316
  const result = await this._threadInstance.readFile(path4);
@@ -2476,7 +2573,10 @@ __export(files_exports, {
2476
2573
  rowToFileRecord: () => rowToFileRecord
2477
2574
  });
2478
2575
  function isTextMimeType(mimeType) {
2479
- return TEXT_MIME_TYPES.some((prefix) => mimeType.startsWith(prefix));
2576
+ if (mimeType.startsWith("text/")) return true;
2577
+ return TEXT_APPLICATION_TYPES.some(
2578
+ (type) => mimeType === type || mimeType.startsWith(type + ";")
2579
+ );
2480
2580
  }
2481
2581
  function detectStorageBackend(location) {
2482
2582
  if (location.startsWith("s3://")) return "s3";
@@ -2553,17 +2653,67 @@ function inferMimeType(filename) {
2553
2653
  };
2554
2654
  return mimeTypes[ext || ""] || "application/octet-stream";
2555
2655
  }
2556
- var CHUNK_SIZE, TEXT_MIME_TYPES, FileStorage;
2656
+ var CHUNK_SIZE, TEXT_APPLICATION_TYPES, FileStorage;
2557
2657
  var init_files = __esm({
2558
2658
  "src/durable-objects/files.ts"() {
2559
2659
  CHUNK_SIZE = 1.75 * 1024 * 1024;
2560
- TEXT_MIME_TYPES = [
2561
- "text/",
2660
+ TEXT_APPLICATION_TYPES = [
2661
+ // Data formats
2562
2662
  "application/json",
2563
- "application/javascript",
2663
+ "application/ld+json",
2664
+ "application/json5",
2665
+ "application/jsonl",
2666
+ "application/x-ndjson",
2564
2667
  "application/xml",
2668
+ "application/xhtml+xml",
2669
+ "application/rss+xml",
2670
+ "application/atom+xml",
2671
+ "application/soap+xml",
2672
+ "application/yaml",
2565
2673
  "application/x-yaml",
2566
- "application/yaml"
2674
+ "application/toml",
2675
+ "application/x-toml",
2676
+ // Programming languages
2677
+ "application/javascript",
2678
+ "application/x-javascript",
2679
+ "application/ecmascript",
2680
+ "application/typescript",
2681
+ "application/x-typescript",
2682
+ "application/x-python",
2683
+ "application/x-ruby",
2684
+ "application/x-perl",
2685
+ "application/x-php",
2686
+ "application/x-sh",
2687
+ "application/x-bash",
2688
+ "application/x-csh",
2689
+ "application/x-zsh",
2690
+ "application/x-powershell",
2691
+ "application/x-lua",
2692
+ "application/x-tcl",
2693
+ // Query/config languages
2694
+ "application/sql",
2695
+ "application/x-sql",
2696
+ "application/graphql",
2697
+ "application/x-graphql",
2698
+ "application/sparql-query",
2699
+ "application/sparql-results+json",
2700
+ "application/sparql-results+xml",
2701
+ // Markup/templates
2702
+ "application/x-httpd-php",
2703
+ "application/x-latex",
2704
+ "application/x-tex",
2705
+ "application/rtf",
2706
+ "application/xslt+xml",
2707
+ // Web
2708
+ "application/x-www-form-urlencoded",
2709
+ "application/manifest+json",
2710
+ "application/webmanifest+json",
2711
+ "application/x-web-app-manifest+json",
2712
+ // Config files
2713
+ "application/x-ini",
2714
+ "application/x-properties",
2715
+ "application/plist",
2716
+ "application/x-plist"
2567
2717
  ];
2568
2718
  FileStorage = class {
2569
2719
  constructor(sql) {