@standardagents/builder 0.10.0 → 0.10.1-dev.b8746e9

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.
@@ -848,12 +848,23 @@ var index_post_default3 = defineController(async ({ req, env }) => {
848
848
  });
849
849
 
850
850
  // src/api/threads/index.ts
851
+ function resolveIconUrl(icon, origin) {
852
+ if (!icon) return void 0;
853
+ if (icon.startsWith("http://") || icon.startsWith("https://")) {
854
+ return icon;
855
+ }
856
+ if (icon.startsWith("/")) {
857
+ return `${origin}${icon}`;
858
+ }
859
+ return icon;
860
+ }
851
861
  var threads_default = defineController(async ({ req, env }) => {
852
862
  if (req.method !== "GET") {
853
863
  return new Response("Method Not Allowed", { status: 405 });
854
864
  }
855
865
  try {
856
866
  const url = new URL(req.url);
867
+ const origin = url.origin;
857
868
  const limit = parseInt(url.searchParams.get("limit") || "50", 10);
858
869
  const offset = parseInt(url.searchParams.get("offset") || "0", 10);
859
870
  const agentName = url.searchParams.get("agent_id");
@@ -872,11 +883,14 @@ var threads_default = defineController(async ({ req, env }) => {
872
883
  try {
873
884
  const agentDef = await agentBuilder.loadAgent(thread.agent_name);
874
885
  agentDetails = {
875
- title: agentDef.title,
876
- type: agentDef.type || "ai_human"
886
+ name: thread.agent_name,
887
+ title: agentDef.title || thread.agent_name,
888
+ type: agentDef.type || "ai_human",
889
+ description: agentDef.description,
890
+ icon: resolveIconUrl(agentDef.icon, origin)
877
891
  };
878
892
  } catch {
879
- agentDetails = { title: thread.agent_name, type: "unknown" };
893
+ agentDetails = { name: thread.agent_name, title: thread.agent_name, type: "unknown" };
880
894
  }
881
895
  return {
882
896
  id: thread.id,
@@ -1447,6 +1461,16 @@ var id_patch_default = defineController(async ({ req, env, params }) => {
1447
1461
  });
1448
1462
 
1449
1463
  // src/api/threads/[id].ts
1464
+ function resolveIconUrl2(icon, origin) {
1465
+ if (!icon) return void 0;
1466
+ if (icon.startsWith("http://") || icon.startsWith("https://")) {
1467
+ return icon;
1468
+ }
1469
+ if (icon.startsWith("/")) {
1470
+ return `${origin}${icon}`;
1471
+ }
1472
+ return icon;
1473
+ }
1450
1474
  var id_default = defineController(async ({ req, params, env }) => {
1451
1475
  const threadId = params.id;
1452
1476
  if (!threadId) {
@@ -1462,6 +1486,10 @@ var id_default = defineController(async ({ req, params, env }) => {
1462
1486
  { status: 404 }
1463
1487
  );
1464
1488
  }
1489
+ if (doData.agent?.icon) {
1490
+ const origin = new URL(req.url).origin;
1491
+ doData.agent.icon = resolveIconUrl2(doData.agent.icon, origin);
1492
+ }
1465
1493
  return Response.json(doData);
1466
1494
  } catch (error) {
1467
1495
  console.error(`Error fetching thread ${threadId}:`, error);
@@ -2077,15 +2105,19 @@ var logs_get_default = defineController(async ({ req, params, env }) => {
2077
2105
  }
2078
2106
  });
2079
2107
 
2080
- // src/api/threads/[id]/message.post.ts
2081
- var imageProcessingModule = null;
2082
- async function getImageProcessing() {
2083
- if (!imageProcessingModule) {
2084
- imageProcessingModule = await import('@standardagents/builder/image-processing');
2108
+ // src/api/threads/[id]/messages.post.ts
2109
+ function needsProcessing(base64Data, mimeType) {
2110
+ const binarySize = Math.ceil(base64Data.length * 3 / 4);
2111
+ const MAX_SIZE = 2 * 1024 * 1024;
2112
+ if (binarySize > MAX_SIZE) {
2113
+ return true;
2114
+ }
2115
+ if (mimeType !== "image/jpeg" && mimeType !== "image/png") {
2116
+ return true;
2085
2117
  }
2086
- return imageProcessingModule;
2118
+ return false;
2087
2119
  }
2088
- var message_post_default = defineController(async ({ req, params, env }) => {
2120
+ var messages_post_default = defineController(async ({ req, params, env }) => {
2089
2121
  const threadId = params.id;
2090
2122
  if (!threadId) {
2091
2123
  return Response.json({ error: "Thread ID required" }, { status: 400 });
@@ -2122,18 +2154,22 @@ var message_post_default = defineController(async ({ req, params, env }) => {
2122
2154
  let mimeType = attachment.mimeType;
2123
2155
  let width = attachment.width;
2124
2156
  let height = attachment.height;
2125
- const imgProc = await getImageProcessing();
2126
- if (mimeType.startsWith("image/") && imgProc.needsProcessing(fileData, mimeType)) {
2157
+ if (mimeType.startsWith("image/") && needsProcessing(fileData, mimeType)) {
2127
2158
  try {
2128
- const buffer = imgProc.base64ToArrayBuffer(fileData);
2129
- const processed = await imgProc.processImage(buffer, mimeType);
2130
- fileData = imgProc.arrayBufferToBase64(processed.data);
2131
- mimeType = processed.mimeType;
2132
- width = processed.width;
2133
- height = processed.height;
2134
- console.log(
2135
- `[image-processing] Processed ${attachment.name}: ${(buffer.byteLength / 1024 / 1024).toFixed(2)}MB \u2192 ${(processed.data.byteLength / 1024 / 1024).toFixed(2)}MB, ${processed.width}x${processed.height}, ${processed.mimeType}`
2136
- );
2159
+ const originalSize = Math.ceil(fileData.length * 3 / 4);
2160
+ const processed = await stub.processImage(fileData, mimeType);
2161
+ if (processed.success && processed.data) {
2162
+ fileData = processed.data;
2163
+ mimeType = processed.mimeType;
2164
+ width = processed.width;
2165
+ height = processed.height;
2166
+ const newSize = Math.ceil(fileData.length * 3 / 4);
2167
+ console.log(
2168
+ `[image-processing] Processed ${attachment.name}: ${(originalSize / 1024 / 1024).toFixed(2)}MB \u2192 ${(newSize / 1024 / 1024).toFixed(2)}MB, ${processed.width}x${processed.height}, ${processed.mimeType}`
2169
+ );
2170
+ } else {
2171
+ console.error(`[image-processing] Failed to process ${attachment.name}:`, processed.error);
2172
+ }
2137
2173
  } catch (err) {
2138
2174
  console.error(`[image-processing] Failed to process ${attachment.name}:`, err);
2139
2175
  }
@@ -2315,6 +2351,20 @@ var stream_default = defineController(async ({ req, params, env }) => {
2315
2351
  });
2316
2352
 
2317
2353
  // src/api/threads/[id]/fs/[...path].ts
2354
+ function toAttachmentRef(file) {
2355
+ const metadata = file.metadata;
2356
+ return {
2357
+ id: file.path,
2358
+ // Use path as unique ID
2359
+ type: "file",
2360
+ path: file.path,
2361
+ name: file.name,
2362
+ mimeType: file.mimeType,
2363
+ size: file.size,
2364
+ ...metadata?.width && { width: metadata.width },
2365
+ ...metadata?.height && { height: metadata.height }
2366
+ };
2367
+ }
2318
2368
  var path_default = defineController(async ({ req, params, env }) => {
2319
2369
  console.log("[fs] params received:", JSON.stringify(params));
2320
2370
  const threadId = params.id;
@@ -2436,7 +2486,7 @@ async function handlePut(stub, path, req) {
2436
2486
  if (!result2.success) {
2437
2487
  return Response.json({ error: result2.error }, { status: 400 });
2438
2488
  }
2439
- return Response.json({ file: result2.file }, { status: 201 });
2489
+ return Response.json(toAttachmentRef(result2.file), { status: 201 });
2440
2490
  }
2441
2491
  if (body.data) {
2442
2492
  const result2 = await stub.writeFile(path, body.data, body.mimeType || "application/octet-stream", {
@@ -2446,7 +2496,7 @@ async function handlePut(stub, path, req) {
2446
2496
  if (!result2.success) {
2447
2497
  return Response.json({ error: result2.error }, { status: 400 });
2448
2498
  }
2449
- return Response.json({ file: result2.file }, { status: 201 });
2499
+ return Response.json(toAttachmentRef(result2.file), { status: 201 });
2450
2500
  }
2451
2501
  return Response.json({ error: "Invalid request body" }, { status: 400 });
2452
2502
  }
@@ -2462,7 +2512,7 @@ async function handlePut(stub, path, req) {
2462
2512
  if (!result.success) {
2463
2513
  return Response.json({ error: result.error }, { status: 400 });
2464
2514
  }
2465
- return Response.json({ file: result.file }, { status: 201 });
2515
+ return Response.json(toAttachmentRef(result.file), { status: 201 });
2466
2516
  }
2467
2517
  async function handleDelete(stub, path) {
2468
2518
  const statResult = await stub.statFile(path);
@@ -2646,7 +2696,7 @@ var routeHandlers = {
2646
2696
  "GET:/threads/:id/cost": cost_get_default,
2647
2697
  "GET:/threads/:id/fs": fs_default,
2648
2698
  "GET:/threads/:id/logs": logs_get_default,
2649
- "POST:/threads/:id/message": message_post_default,
2699
+ "POST:/threads/:id/messages": messages_post_default,
2650
2700
  "GET:/threads/:id/messages": messages_get_default,
2651
2701
  "POST:/threads/:id/rpc": rpc_post_default,
2652
2702
  "POST:/threads/:id/stop": stop_post_default,