@standardagents/builder 0.11.0-next.41deba4 → 0.11.0-next.5d2e71b
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 +5714 -48
- 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.d.ts +15 -0
- package/dist/index.js +98 -14
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +56 -9
- package/dist/plugin.js.map +1 -1
- package/dist/sip.wasm +0 -0
- package/package.json +8 -6
package/dist/plugin.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import fs2 from 'fs';
|
|
2
2
|
import path3 from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
|
-
import { createRequire } from 'module';
|
|
5
4
|
|
|
6
5
|
// src/plugin.ts
|
|
7
6
|
var TSCONFIG_CONTENT = `{
|
|
@@ -1617,7 +1616,6 @@ function validateAgentData(data) {
|
|
|
1617
1616
|
}
|
|
1618
1617
|
|
|
1619
1618
|
// src/plugin.ts
|
|
1620
|
-
createRequire(import.meta.url);
|
|
1621
1619
|
var VIRTUAL_TOOLS_ID = "virtual:@standardagents-tools";
|
|
1622
1620
|
var RESOLVED_VIRTUAL_TOOLS_ID = "\0" + VIRTUAL_TOOLS_ID;
|
|
1623
1621
|
var VIRTUAL_ROUTES_ID = "virtual:@standardagents-routes";
|
|
@@ -2070,7 +2068,15 @@ function agentbuilder(options = {}) {
|
|
|
2070
2068
|
"zod",
|
|
2071
2069
|
"openai"
|
|
2072
2070
|
];
|
|
2071
|
+
const currentDir = path3.dirname(fileURLToPath(import.meta.url));
|
|
2072
|
+
const isInDist = currentDir.endsWith("dist");
|
|
2073
|
+
const builderClientDir = path3.resolve(
|
|
2074
|
+
currentDir,
|
|
2075
|
+
isInDist ? "./client" : "../dist/client"
|
|
2076
|
+
);
|
|
2073
2077
|
return {
|
|
2078
|
+
// Set publicDir to builder's client assets so Cloudflare plugin preserves assets config
|
|
2079
|
+
publicDir: fs2.existsSync(builderClientDir) ? builderClientDir : void 0,
|
|
2074
2080
|
optimizeDeps: {
|
|
2075
2081
|
// Exclude our packages from pre-bundling - they contain cloudflare:workers imports
|
|
2076
2082
|
// that cannot be resolved during dependency optimization
|
|
@@ -2224,6 +2230,22 @@ function isPublicRoute(routePath) {
|
|
|
2224
2230
|
return false;
|
|
2225
2231
|
}
|
|
2226
2232
|
|
|
2233
|
+
// CORS headers for API responses
|
|
2234
|
+
const CORS_HEADERS = {
|
|
2235
|
+
"Access-Control-Allow-Origin": "*",
|
|
2236
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
2237
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
|
|
2238
|
+
"Access-Control-Max-Age": "86400",
|
|
2239
|
+
};
|
|
2240
|
+
|
|
2241
|
+
// Helper to create headers with CORS
|
|
2242
|
+
function corsHeaders(contentType) {
|
|
2243
|
+
return {
|
|
2244
|
+
"Content-Type": contentType,
|
|
2245
|
+
...CORS_HEADERS,
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2227
2249
|
export async function router(request, env) {
|
|
2228
2250
|
const url = new URL(request.url);
|
|
2229
2251
|
const pathname = url.pathname;
|
|
@@ -2233,6 +2255,14 @@ export async function router(request, env) {
|
|
|
2233
2255
|
return null;
|
|
2234
2256
|
}
|
|
2235
2257
|
|
|
2258
|
+
// Handle CORS preflight requests
|
|
2259
|
+
if (request.method === "OPTIONS") {
|
|
2260
|
+
return new Response(null, {
|
|
2261
|
+
status: 204,
|
|
2262
|
+
headers: CORS_HEADERS,
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2236
2266
|
// Strip mount point prefix for route matching, ensuring we keep the leading slash
|
|
2237
2267
|
let routePath = pathname.slice(MOUNT_POINT.length) || "/";
|
|
2238
2268
|
if (!routePath.startsWith('/')) {
|
|
@@ -2286,16 +2316,21 @@ ${threadRouteCode}
|
|
|
2286
2316
|
const result = await controller(context);
|
|
2287
2317
|
|
|
2288
2318
|
if (result instanceof Response) {
|
|
2319
|
+
// Return Response objects as-is - CORS headers can't be safely added
|
|
2320
|
+
// to Response objects in the workerd environment without issues.
|
|
2321
|
+
// Controllers that return streaming/binary responses should add
|
|
2322
|
+
// CORS headers themselves if needed.
|
|
2289
2323
|
return result;
|
|
2290
2324
|
}
|
|
2291
2325
|
if (typeof result === "string") {
|
|
2292
2326
|
return new Response(result, {
|
|
2293
|
-
headers:
|
|
2294
|
-
"Content-Type": "text/plain",
|
|
2295
|
-
},
|
|
2327
|
+
headers: corsHeaders("text/plain"),
|
|
2296
2328
|
});
|
|
2297
2329
|
}
|
|
2298
|
-
|
|
2330
|
+
// JSON responses get CORS headers
|
|
2331
|
+
return new Response(JSON.stringify(result), {
|
|
2332
|
+
headers: corsHeaders("application/json"),
|
|
2333
|
+
});
|
|
2299
2334
|
}
|
|
2300
2335
|
|
|
2301
2336
|
// Serve UI for all other routes (SPA fallback)
|
|
@@ -2310,13 +2345,15 @@ async function serveUI(pathname, env) {
|
|
|
2310
2345
|
// Create a proper request for the asset path
|
|
2311
2346
|
// Use a dummy origin since we only care about the path
|
|
2312
2347
|
// Re-add mount point since pathname was stripped by router
|
|
2313
|
-
|
|
2348
|
+
// Handle root mountPoint "/" specially to avoid double slashes
|
|
2349
|
+
const mountPrefix = MOUNT_POINT === "/" ? "" : MOUNT_POINT;
|
|
2350
|
+
const assetUrl = \`http://localhost\${mountPrefix}\${pathname}\`;
|
|
2314
2351
|
let response = await env.ASSETS.fetch(assetUrl);
|
|
2315
2352
|
|
|
2316
2353
|
// If not found, fall back to index.html for SPA routing
|
|
2317
2354
|
const isIndexHtml = response.status === 404 || pathname === "/" || !pathname.includes(".");
|
|
2318
2355
|
if (isIndexHtml) {
|
|
2319
|
-
response = await env.ASSETS.fetch(\`http://localhost\${
|
|
2356
|
+
response = await env.ASSETS.fetch(\`http://localhost\${mountPrefix}/index.html\`);
|
|
2320
2357
|
|
|
2321
2358
|
// Transform HTML to use configured mount point
|
|
2322
2359
|
if (response.status === 200) {
|
|
@@ -2601,7 +2638,8 @@ import { DurableAgentBuilder as _BaseDurableAgentBuilder } from '@standardagents
|
|
|
2601
2638
|
|
|
2602
2639
|
// Import sip WASM module and initializer
|
|
2603
2640
|
// Static import allows workerd to pre-compile the WASM at bundle time
|
|
2604
|
-
|
|
2641
|
+
// WASM is bundled in builder's dist to avoid transitive dependency resolution issues
|
|
2642
|
+
import _sipWasm from '@standardagents/builder/dist/sip.wasm';
|
|
2605
2643
|
import { initWithWasmModule as _initSipWasm } from '@standardagents/sip';
|
|
2606
2644
|
|
|
2607
2645
|
// Re-export router from virtual:@standardagents-routes
|
|
@@ -3156,6 +3194,13 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
3156
3194
|
const items = match[1].match(/['"]([^'"]+)['"]/g);
|
|
3157
3195
|
return items ? items.map((s) => s.replace(/['"]/g, "")) : [];
|
|
3158
3196
|
};
|
|
3197
|
+
const getSidePrompt = (c, side) => {
|
|
3198
|
+
const sideRegex = new RegExp(`${side}:\\s*\\{([^}]+)\\}`, "s");
|
|
3199
|
+
const sideMatch = c.match(sideRegex);
|
|
3200
|
+
if (!sideMatch) return null;
|
|
3201
|
+
const promptMatch = sideMatch[1].match(/prompt:\s*['"]([^'"]+)['"]/);
|
|
3202
|
+
return promptMatch ? promptMatch[1] : null;
|
|
3203
|
+
};
|
|
3159
3204
|
const name = getName(content);
|
|
3160
3205
|
if (!name) return null;
|
|
3161
3206
|
return {
|
|
@@ -3166,6 +3211,8 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
3166
3211
|
default_prompt: getDefaultPrompt(content) || "",
|
|
3167
3212
|
default_model: getDefaultModel(content) || "",
|
|
3168
3213
|
tools: getTools(content),
|
|
3214
|
+
side_a_agent_prompt: getSidePrompt(content, "sideA"),
|
|
3215
|
+
side_b_agent_prompt: getSidePrompt(content, "sideB"),
|
|
3169
3216
|
created_at: Math.floor(Date.now() / 1e3)
|
|
3170
3217
|
};
|
|
3171
3218
|
} catch (error) {
|