@standardagents/builder 0.11.0-next.174a940 → 0.11.0-next.22e39d0
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/built-in-routes.js.map +1 -1
- package/dist/client/assets/index.css +1 -1
- package/dist/client/index.js +2 -2
- package/dist/index.js +47 -9
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +47 -9
- package/dist/plugin.js.map +1 -1
- package/dist/sip.wasm +0 -0
- package/package.json +8 -6
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { sip } from '@standardagents/sip';
|
|
|
2
2
|
import fs2 from 'fs';
|
|
3
3
|
import path3 from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import { createRequire } from 'module';
|
|
6
5
|
export { defineAgent, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool } from '@standardagents/spec';
|
|
7
6
|
import { DurableObject } from 'cloudflare:workers';
|
|
8
7
|
|
|
@@ -7698,7 +7697,6 @@ function validateAgentData(data) {
|
|
|
7698
7697
|
}
|
|
7699
7698
|
|
|
7700
7699
|
// src/plugin.ts
|
|
7701
|
-
createRequire(import.meta.url);
|
|
7702
7700
|
var VIRTUAL_TOOLS_ID = "virtual:@standardagents-tools";
|
|
7703
7701
|
var RESOLVED_VIRTUAL_TOOLS_ID = "\0" + VIRTUAL_TOOLS_ID;
|
|
7704
7702
|
var VIRTUAL_ROUTES_ID = "virtual:@standardagents-routes";
|
|
@@ -8151,7 +8149,15 @@ function agentbuilder(options = {}) {
|
|
|
8151
8149
|
"zod",
|
|
8152
8150
|
"openai"
|
|
8153
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
|
+
);
|
|
8154
8158
|
return {
|
|
8159
|
+
// Set publicDir to builder's client assets so Cloudflare plugin preserves assets config
|
|
8160
|
+
publicDir: fs2.existsSync(builderClientDir) ? builderClientDir : void 0,
|
|
8155
8161
|
optimizeDeps: {
|
|
8156
8162
|
// Exclude our packages from pre-bundling - they contain cloudflare:workers imports
|
|
8157
8163
|
// that cannot be resolved during dependency optimization
|
|
@@ -8305,6 +8311,22 @@ function isPublicRoute(routePath) {
|
|
|
8305
8311
|
return false;
|
|
8306
8312
|
}
|
|
8307
8313
|
|
|
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
|
+
|
|
8308
8330
|
export async function router(request, env) {
|
|
8309
8331
|
const url = new URL(request.url);
|
|
8310
8332
|
const pathname = url.pathname;
|
|
@@ -8314,6 +8336,14 @@ export async function router(request, env) {
|
|
|
8314
8336
|
return null;
|
|
8315
8337
|
}
|
|
8316
8338
|
|
|
8339
|
+
// Handle CORS preflight requests
|
|
8340
|
+
if (request.method === "OPTIONS") {
|
|
8341
|
+
return new Response(null, {
|
|
8342
|
+
status: 204,
|
|
8343
|
+
headers: CORS_HEADERS,
|
|
8344
|
+
});
|
|
8345
|
+
}
|
|
8346
|
+
|
|
8317
8347
|
// Strip mount point prefix for route matching, ensuring we keep the leading slash
|
|
8318
8348
|
let routePath = pathname.slice(MOUNT_POINT.length) || "/";
|
|
8319
8349
|
if (!routePath.startsWith('/')) {
|
|
@@ -8367,16 +8397,21 @@ ${threadRouteCode}
|
|
|
8367
8397
|
const result = await controller(context);
|
|
8368
8398
|
|
|
8369
8399
|
if (result instanceof Response) {
|
|
8400
|
+
// Return Response objects as-is - CORS headers can't be safely added
|
|
8401
|
+
// to Response objects in the workerd environment without issues.
|
|
8402
|
+
// Controllers that return streaming/binary responses should add
|
|
8403
|
+
// CORS headers themselves if needed.
|
|
8370
8404
|
return result;
|
|
8371
8405
|
}
|
|
8372
8406
|
if (typeof result === "string") {
|
|
8373
8407
|
return new Response(result, {
|
|
8374
|
-
headers:
|
|
8375
|
-
"Content-Type": "text/plain",
|
|
8376
|
-
},
|
|
8408
|
+
headers: corsHeaders("text/plain"),
|
|
8377
8409
|
});
|
|
8378
8410
|
}
|
|
8379
|
-
|
|
8411
|
+
// JSON responses get CORS headers
|
|
8412
|
+
return new Response(JSON.stringify(result), {
|
|
8413
|
+
headers: corsHeaders("application/json"),
|
|
8414
|
+
});
|
|
8380
8415
|
}
|
|
8381
8416
|
|
|
8382
8417
|
// Serve UI for all other routes (SPA fallback)
|
|
@@ -8391,13 +8426,15 @@ async function serveUI(pathname, env) {
|
|
|
8391
8426
|
// Create a proper request for the asset path
|
|
8392
8427
|
// Use a dummy origin since we only care about the path
|
|
8393
8428
|
// Re-add mount point since pathname was stripped by router
|
|
8394
|
-
|
|
8429
|
+
// Handle root mountPoint "/" specially to avoid double slashes
|
|
8430
|
+
const mountPrefix = MOUNT_POINT === "/" ? "" : MOUNT_POINT;
|
|
8431
|
+
const assetUrl = \`http://localhost\${mountPrefix}\${pathname}\`;
|
|
8395
8432
|
let response = await env.ASSETS.fetch(assetUrl);
|
|
8396
8433
|
|
|
8397
8434
|
// If not found, fall back to index.html for SPA routing
|
|
8398
8435
|
const isIndexHtml = response.status === 404 || pathname === "/" || !pathname.includes(".");
|
|
8399
8436
|
if (isIndexHtml) {
|
|
8400
|
-
response = await env.ASSETS.fetch(\`http://localhost\${
|
|
8437
|
+
response = await env.ASSETS.fetch(\`http://localhost\${mountPrefix}/index.html\`);
|
|
8401
8438
|
|
|
8402
8439
|
// Transform HTML to use configured mount point
|
|
8403
8440
|
if (response.status === 200) {
|
|
@@ -8682,7 +8719,8 @@ import { DurableAgentBuilder as _BaseDurableAgentBuilder } from '@standardagents
|
|
|
8682
8719
|
|
|
8683
8720
|
// Import sip WASM module and initializer
|
|
8684
8721
|
// Static import allows workerd to pre-compile the WASM at bundle time
|
|
8685
|
-
|
|
8722
|
+
// WASM is bundled in builder's dist to avoid transitive dependency resolution issues
|
|
8723
|
+
import _sipWasm from '@standardagents/builder/dist/sip.wasm';
|
|
8686
8724
|
import { initWithWasmModule as _initSipWasm } from '@standardagents/sip';
|
|
8687
8725
|
|
|
8688
8726
|
// Re-export router from virtual:@standardagents-routes
|