@standardagents/builder 0.11.0-next.730b472 → 0.11.0-next.80cee2e

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
@@ -1,7 +1,7 @@
1
1
  export { AgentPluginOptions, agentbuilder } from './plugin.js';
2
2
  import { DurableObjectStorage } from '@cloudflare/workers-types';
3
3
  import { ZodObject, ZodRawShape } from 'zod';
4
- import { ToolResult as ToolResult$1, HookSignatures, AgentDefinition as AgentDefinition$1, ControllerContext, Controller, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, SubpromptConfig as SubpromptConfig$2, ReasoningConfig, SideConfig as SideConfig$1 } from '@standardagents/spec';
4
+ import { ToolResult as ToolResult$1, HookSignatures, ControllerContext, Controller, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, SubpromptConfig as SubpromptConfig$2, ReasoningConfig, SideConfig as SideConfig$1 } from '@standardagents/spec';
5
5
  export { AgentType, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, PromptInput, PromptTextPart, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, defineAgent, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool } from '@standardagents/spec';
6
6
  import { DurableObject } from 'cloudflare:workers';
7
7
  import 'vite';
@@ -785,6 +785,20 @@ interface LogEntry {
785
785
  created_at: number;
786
786
  request_body: string | null;
787
787
  }
788
+ /**
789
+ * Agent definition returned from loadAgent()
790
+ */
791
+ interface AgentDefinition$1 {
792
+ name: string;
793
+ title?: string;
794
+ type?: string;
795
+ description?: string;
796
+ icon?: string;
797
+ defaultPrompt?: string;
798
+ defaultModel?: string;
799
+ tools?: string[];
800
+ [key: string]: unknown;
801
+ }
788
802
  /**
789
803
  * Response from getThreadMeta()
790
804
  */
package/dist/index.js CHANGED
@@ -1995,7 +1995,7 @@ async function getMessages(flow, limit = 100, offset = 0, order = "asc") {
1995
1995
  parent_id,
1996
1996
  depth
1997
1997
  FROM messages
1998
- ORDER BY created_at ${orderClause}, rowid ${orderClause}
1998
+ ORDER BY created_at ${orderClause}
1999
1999
  LIMIT ? OFFSET ?`,
2000
2000
  limit,
2001
2001
  offset
@@ -5833,14 +5833,14 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
5833
5833
  ${columns.join(", ")}
5834
5834
  FROM messages
5835
5835
  WHERE parent_id IS NULL
5836
- ORDER BY created_at ASC, rowid ASC
5836
+ ORDER BY created_at ASC
5837
5837
  `;
5838
5838
  const cursor = await storage.sql.exec(query);
5839
5839
  rows = cursor.toArray();
5840
5840
  }
5841
5841
  if (state.extraMessages && state.extraMessages.length > 0) {
5842
5842
  rows.push(...state.extraMessages);
5843
- rows.sort((a, b) => a.created_at - b.created_at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
5843
+ rows.sort((a, b) => a.created_at - b.created_at);
5844
5844
  }
5845
5845
  const messages = rows.map((row) => ({
5846
5846
  id: row.id,
@@ -8149,15 +8149,7 @@ function agentbuilder(options = {}) {
8149
8149
  "zod",
8150
8150
  "openai"
8151
8151
  ];
8152
- const currentDir = path3.dirname(fileURLToPath(import.meta.url));
8153
- const isInDist = currentDir.endsWith("dist");
8154
- const builderClientDir = path3.resolve(
8155
- currentDir,
8156
- isInDist ? "./client" : "../dist/client"
8157
- );
8158
8152
  return {
8159
- // Set publicDir to builder's client assets so Cloudflare plugin preserves assets config
8160
- publicDir: fs2.existsSync(builderClientDir) ? builderClientDir : void 0,
8161
8153
  optimizeDeps: {
8162
8154
  // Exclude our packages from pre-bundling - they contain cloudflare:workers imports
8163
8155
  // that cannot be resolved during dependency optimization
@@ -8311,48 +8303,6 @@ function isPublicRoute(routePath) {
8311
8303
  return false;
8312
8304
  }
8313
8305
 
8314
- // CORS headers for API responses
8315
- const CORS_HEADERS = {
8316
- "Access-Control-Allow-Origin": "*",
8317
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
8318
- "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
8319
- "Access-Control-Max-Age": "86400",
8320
- };
8321
-
8322
- // Helper to create headers with CORS
8323
- function corsHeaders(contentType) {
8324
- return {
8325
- "Content-Type": contentType,
8326
- ...CORS_HEADERS,
8327
- };
8328
- }
8329
-
8330
- // Helper to add CORS headers to any Response without touching the body
8331
- function addCorsHeaders(response) {
8332
- // Skip WebSocket upgrade responses - they can't be wrapped
8333
- if (response.status === 101) {
8334
- return response;
8335
- }
8336
-
8337
- // Skip if already has CORS headers
8338
- if (response.headers.has("Access-Control-Allow-Origin")) {
8339
- return response;
8340
- }
8341
-
8342
- // Create new headers with CORS added
8343
- const newHeaders = new Headers(response.headers);
8344
- for (const [key, value] of Object.entries(CORS_HEADERS)) {
8345
- newHeaders.set(key, value);
8346
- }
8347
-
8348
- // Return new Response with same body stream (not cloned, just transferred)
8349
- return new Response(response.body, {
8350
- status: response.status,
8351
- statusText: response.statusText,
8352
- headers: newHeaders,
8353
- });
8354
- }
8355
-
8356
8306
  export async function router(request, env) {
8357
8307
  const url = new URL(request.url);
8358
8308
  const pathname = url.pathname;
@@ -8362,14 +8312,6 @@ export async function router(request, env) {
8362
8312
  return null;
8363
8313
  }
8364
8314
 
8365
- // Handle CORS preflight requests
8366
- if (request.method === "OPTIONS") {
8367
- return new Response(null, {
8368
- status: 204,
8369
- headers: CORS_HEADERS,
8370
- });
8371
- }
8372
-
8373
8315
  // Strip mount point prefix for route matching, ensuring we keep the leading slash
8374
8316
  let routePath = pathname.slice(MOUNT_POINT.length) || "/";
8375
8317
  if (!routePath.startsWith('/')) {
@@ -8404,7 +8346,7 @@ ${threadRouteCode}
8404
8346
 
8405
8347
  // If requireAuth returns a Response, it's an error (401)
8406
8348
  if (authResult instanceof Response) {
8407
- return addCorsHeaders(authResult);
8349
+ return authResult;
8408
8350
  }
8409
8351
 
8410
8352
  authContext = authResult;
@@ -8423,17 +8365,16 @@ ${threadRouteCode}
8423
8365
  const result = await controller(context);
8424
8366
 
8425
8367
  if (result instanceof Response) {
8426
- return addCorsHeaders(result);
8368
+ return result;
8427
8369
  }
8428
8370
  if (typeof result === "string") {
8429
8371
  return new Response(result, {
8430
- headers: corsHeaders("text/plain"),
8372
+ headers: {
8373
+ "Content-Type": "text/plain",
8374
+ },
8431
8375
  });
8432
8376
  }
8433
- // JSON responses get CORS headers
8434
- return new Response(JSON.stringify(result), {
8435
- headers: corsHeaders("application/json"),
8436
- });
8377
+ return Response.json(result);
8437
8378
  }
8438
8379
 
8439
8380
  // Serve UI for all other routes (SPA fallback)
@@ -8741,8 +8682,7 @@ import { DurableAgentBuilder as _BaseDurableAgentBuilder } from '@standardagents
8741
8682
 
8742
8683
  // Import sip WASM module and initializer
8743
8684
  // Static import allows workerd to pre-compile the WASM at bundle time
8744
- // WASM is bundled in builder's dist to avoid transitive dependency resolution issues
8745
- import _sipWasm from '@standardagents/builder/dist/sip.wasm';
8685
+ import _sipWasm from '@standardagents/sip/dist/sip.wasm';
8746
8686
  import { initWithWasmModule as _initSipWasm } from '@standardagents/sip';
8747
8687
 
8748
8688
  // Re-export router from virtual:@standardagents-routes
@@ -9297,13 +9237,6 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
9297
9237
  const items = match[1].match(/['"]([^'"]+)['"]/g);
9298
9238
  return items ? items.map((s) => s.replace(/['"]/g, "")) : [];
9299
9239
  };
9300
- const getSidePrompt = (c, side) => {
9301
- const sideRegex = new RegExp(`${side}:\\s*\\{([^}]+)\\}`, "s");
9302
- const sideMatch = c.match(sideRegex);
9303
- if (!sideMatch) return null;
9304
- const promptMatch = sideMatch[1].match(/prompt:\s*['"]([^'"]+)['"]/);
9305
- return promptMatch ? promptMatch[1] : null;
9306
- };
9307
9240
  const name = getName(content);
9308
9241
  if (!name) return null;
9309
9242
  return {
@@ -9314,8 +9247,6 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
9314
9247
  default_prompt: getDefaultPrompt(content) || "",
9315
9248
  default_model: getDefaultModel(content) || "",
9316
9249
  tools: getTools(content),
9317
- side_a_agent_prompt: getSidePrompt(content, "sideA"),
9318
- side_b_agent_prompt: getSidePrompt(content, "sideB"),
9319
9250
  created_at: Math.floor(Date.now() / 1e3)
9320
9251
  };
9321
9252
  } catch (error) {
@@ -9632,12 +9563,6 @@ function base64ToBuffer(base64) {
9632
9563
  }
9633
9564
 
9634
9565
  // src/middleware/auth.ts
9635
- var CORS_HEADERS = {
9636
- "Access-Control-Allow-Origin": "*",
9637
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
9638
- "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
9639
- "Access-Control-Max-Age": "86400"
9640
- };
9641
9566
  function extractBearerToken(request) {
9642
9567
  const authHeader = request.headers.get("Authorization");
9643
9568
  if (authHeader && authHeader.startsWith("Bearer ")) {
@@ -9726,7 +9651,7 @@ async function requireAuth(request, env) {
9726
9651
  if (!authContext) {
9727
9652
  return new Response(JSON.stringify({ error: "Unauthorized" }), {
9728
9653
  status: 401,
9729
- headers: { "Content-Type": "application/json", ...CORS_HEADERS }
9654
+ headers: { "Content-Type": "application/json" }
9730
9655
  });
9731
9656
  }
9732
9657
  return authContext;
@@ -9741,7 +9666,7 @@ async function requireAdmin(request, env) {
9741
9666
  JSON.stringify({ error: "Forbidden: Admin access required" }),
9742
9667
  {
9743
9668
  status: 403,
9744
- headers: { "Content-Type": "application/json", ...CORS_HEADERS }
9669
+ headers: { "Content-Type": "application/json" }
9745
9670
  }
9746
9671
  );
9747
9672
  }
@@ -11137,7 +11062,7 @@ var DurableThread = class extends DurableObject {
11137
11062
  SELECT id, role, content, name, tool_calls, tool_call_id, tool_status, log_id, created_at, silent, parent_id, depth, status, reasoning_content, reasoning_details, attachments
11138
11063
  FROM messages
11139
11064
  ${whereClause}
11140
- ORDER BY created_at ${order === "ASC" ? "ASC" : "DESC"}, rowid ${order === "ASC" ? "ASC" : "DESC"}
11065
+ ORDER BY created_at ${order === "ASC" ? "ASC" : "DESC"}
11141
11066
  LIMIT ? OFFSET ?
11142
11067
  `,
11143
11068
  limit,
@@ -13693,7 +13618,7 @@ var FlowStateSdk = class _FlowStateSdk {
13693
13618
  parent_id,
13694
13619
  depth
13695
13620
  FROM messages
13696
- ORDER BY created_at ${orderClause}, rowid ${orderClause}
13621
+ ORDER BY created_at ${orderClause}
13697
13622
  LIMIT ? OFFSET ?`,
13698
13623
  limit,
13699
13624
  offset