veryfront 0.1.1044 → 0.1.1046

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/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.1044",
3
+ "version": "0.1.1046",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "minimumDependencyAge": {
@@ -1 +1 @@
1
- {"version":3,"file":"agent-stream.handler.d.ts","sourceRoot":"","sources":["../../../../../src/src/server/handlers/request/agent-stream.handler.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,wCAAwC,CAAC;AAQhD,OAAO,EACL,4BAA4B,EAE7B,MAAM,2CAA2C,CAAC;AAyBnD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAmB,aAAa,EAAE,MAAM,aAAa,CAAC;AAcnG,MAAM,WAAW,sBACf,SAAQ,yBAAyB,EAAE,+BAA+B;IAClE,4BAA4B,CAAC,EAAE,OAAO,4BAA4B,CAAC;IACnE,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,+BAA+B,CAAC,YAAY,CAAC,CAAC;CACpF;AAwgBD,qBAAa,kBAAmB,SAAQ,WAAW;IASrC,OAAO,CAAC,QAAQ,CAAC,IAAI;IARjC,QAAQ,EAAE,eAAe,CAMvB;gBAE2B,IAAI,GAAE,sBAAoC;IAIvE,OAAO,CAAC,sBAAsB;IAwBxB,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CA4LxE"}
1
+ {"version":3,"file":"agent-stream.handler.d.ts","sourceRoot":"","sources":["../../../../../src/src/server/handlers/request/agent-stream.handler.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,wCAAwC,CAAC;AAQhD,OAAO,EACL,4BAA4B,EAE7B,MAAM,2CAA2C,CAAC;AAyBnD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAmB,aAAa,EAAE,MAAM,aAAa,CAAC;AAcnG,MAAM,WAAW,sBACf,SAAQ,yBAAyB,EAAE,+BAA+B;IAClE,4BAA4B,CAAC,EAAE,OAAO,4BAA4B,CAAC;IACnE,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,+BAA+B,CAAC,YAAY,CAAC,CAAC;CACpF;AAwgBD,qBAAa,kBAAmB,SAAQ,WAAW;IASrC,OAAO,CAAC,QAAQ,CAAC,IAAI;IARjC,QAAQ,EAAE,eAAe,CAMvB;gBAE2B,IAAI,GAAE,sBAAoC;IAIvE,OAAO,CAAC,sBAAsB;IAwBxB,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CAqMxE"}
@@ -423,145 +423,150 @@ export class AgentStreamHandler extends BaseHandler {
423
423
  if (isServerShuttingDown()) {
424
424
  return this.respond(buildRuntimeShuttingDownResponse(this.createResponseBuilder(ctx)));
425
425
  }
426
- return this.withProxyContext(ctx, async () => {
427
- const builder = this.createResponseBuilder(ctx)
428
- .withCORS(req, ctx.securityConfig?.cors)
429
- .withSecurity(ctx.securityConfig ?? undefined, req);
430
- try {
431
- const pathRunId = getPathRunId(new URL(req.url).pathname);
432
- const rawBody = await readInternalAgentRequestBody(req, INTERNAL_AGENT_STREAM_MAX_BODY_BYTES);
433
- const payload = parseAgentStreamPayload(JSON.parse(rawBody));
434
- if (!pathRunId || pathRunId !== payload.runId) {
435
- return this.respond(builder.json({ error: "CONTROL_PLANE_RUN_ID_MISMATCH" }, 400));
426
+ const builder = this.createResponseBuilder(ctx)
427
+ .withCORS(req, ctx.securityConfig?.cors)
428
+ .withSecurity(ctx.securityConfig ?? undefined, req);
429
+ try {
430
+ const pathRunId = getPathRunId(new URL(req.url).pathname);
431
+ const rawBody = await readInternalAgentRequestBody(req, INTERNAL_AGENT_STREAM_MAX_BODY_BYTES);
432
+ const payload = parseAgentStreamPayload(JSON.parse(rawBody));
433
+ if (!pathRunId || pathRunId !== payload.runId) {
434
+ return this.respond(builder.json({ error: "CONTROL_PLANE_RUN_ID_MISMATCH" }, 400));
435
+ }
436
+ await verifyControlPlaneRequest(req, ctx, rawBody, {
437
+ expectedSubject: payload.runId,
438
+ expectedSurface: "studio",
439
+ });
440
+ const apiAuthToken = payload.credentials?.authToken || ctx.proxyToken ||
441
+ getHostEnv("VERYFRONT_API_TOKEN") || "";
442
+ const requestScopedContext = {
443
+ ...ctx,
444
+ proxyToken: apiAuthToken || undefined,
445
+ requestContext: ctx.requestContext
446
+ ? { ...ctx.requestContext, token: apiAuthToken }
447
+ : ctx.requestContext,
448
+ };
449
+ logger.info("Accepted internal agent stream request", {
450
+ runId: payload.runId,
451
+ threadId: payload.threadId,
452
+ agentId: payload.agentId,
453
+ projectId: requestScopedContext.projectId,
454
+ projectSlug: requestScopedContext.projectSlug,
455
+ messageCount: payload.messages.length,
456
+ toolCount: payload.tools.length,
457
+ hasAgentSource: Boolean(payload.agentSource),
458
+ hasAgentConfig: Boolean(payload.agentConfig),
459
+ });
460
+ return await this.withProxyContext(requestScopedContext, () => this.withAgentSourceContext(requestScopedContext, payload.agentSource, async () => {
461
+ await this.deps.ensureProjectDiscovery(requestScopedContext);
462
+ const agent = this.deps.getAgent(payload.agentId);
463
+ if (!agent) {
464
+ logger.warn("Internal agent stream request referenced unknown agent", {
465
+ runId: payload.runId,
466
+ agentId: payload.agentId,
467
+ projectId: requestScopedContext.projectId,
468
+ projectSlug: requestScopedContext.projectSlug,
469
+ });
470
+ return this.respond(builder.json({ error: "Agent not found" }, 404));
436
471
  }
437
- await verifyControlPlaneRequest(req, ctx, rawBody, {
438
- expectedSubject: payload.runId,
439
- expectedSurface: "studio",
472
+ // veryfront-api is the trusted control-plane caller; it resolves
473
+ // authorization before attaching request-scoped project-agent config.
474
+ const runtimeBaseAgent = payload.agentConfig
475
+ ? createRuntimeAgentFromMarkdownDefinition(payload.agentConfig)
476
+ : agent;
477
+ const runtimeInput = sanitizeRuntimeRunAgentInput(toRuntimeRunAgentInput(payload));
478
+ const localTools = this.deps.getLocalTools?.(runtimeBaseAgent.id);
479
+ const platformRuntimeAgent = await withVeryfrontPlatformRemoteTools({
480
+ agent: runtimeBaseAgent,
481
+ token: apiAuthToken || null,
482
+ projectId: requestScopedContext.projectId ?? null,
483
+ availableToolNames: runtimeInput.tools.map((tool) => tool.name),
440
484
  });
441
- logger.info("Accepted internal agent stream request", {
442
- runId: payload.runId,
443
- threadId: payload.threadId,
444
- agentId: payload.agentId,
445
- projectId: ctx.projectId,
446
- projectSlug: ctx.projectSlug,
447
- messageCount: payload.messages.length,
448
- toolCount: payload.tools.length,
449
- hasAgentSource: Boolean(payload.agentSource),
450
- hasAgentConfig: Boolean(payload.agentConfig),
485
+ const runtimeAgent = withVeryfrontStudioRemoteTools({
486
+ agent: platformRuntimeAgent,
487
+ token: apiAuthToken || null,
488
+ projectId: requestScopedContext.projectId ?? null,
489
+ forwardedProps: runtimeInput.forwardedProps,
490
+ availableToolNames: runtimeInput.tools.map((tool) => tool.name),
491
+ conversationId: runtimeInput.threadId,
451
492
  });
452
- return await this.withAgentSourceContext(ctx, payload.agentSource, async () => {
453
- await this.deps.ensureProjectDiscovery(ctx);
454
- const agent = this.deps.getAgent(payload.agentId);
455
- if (!agent) {
456
- logger.warn("Internal agent stream request referenced unknown agent", {
493
+ // Load project env vars so source-defined MCP tool headers resolve
494
+ // via _getProjectEnv(). Control-plane requests don't go through the proxy and
495
+ // therefore don't carry x-environment-id, so we discover the production env ID
496
+ // from the API (one fetch per project per server lifetime, then cached).
497
+ let envVarsForAgent = {};
498
+ if (requestScopedContext.projectSlug && apiAuthToken) {
499
+ const environmentId = requestScopedContext.environmentId ??
500
+ await _resolveProductionEnvironmentId(requestScopedContext.projectSlug, apiAuthToken);
501
+ if (environmentId) {
502
+ envVarsForAgent = await _agentEnvVarCache.get(environmentId, apiAuthToken, requestScopedContext.projectSlug);
503
+ logger.debug("Agent stream env vars loaded", {
457
504
  runId: payload.runId,
458
- agentId: payload.agentId,
459
- projectId: ctx.projectId,
460
- projectSlug: ctx.projectSlug,
505
+ projectSlug: requestScopedContext.projectSlug,
506
+ environmentId,
507
+ count: Object.keys(envVarsForAgent).length,
461
508
  });
462
- return this.respond(builder.json({ error: "Agent not found" }, 404));
463
509
  }
464
- // veryfront-api is the trusted control-plane caller; it resolves
465
- // authorization before attaching request-scoped project-agent config.
466
- const runtimeBaseAgent = payload.agentConfig
467
- ? createRuntimeAgentFromMarkdownDefinition(payload.agentConfig)
468
- : agent;
469
- const runtimeInput = sanitizeRuntimeRunAgentInput(toRuntimeRunAgentInput(payload));
470
- const localTools = this.deps.getLocalTools?.(runtimeBaseAgent.id);
471
- const apiAuthToken = payload.credentials?.authToken || ctx.proxyToken ||
472
- getHostEnv("VERYFRONT_API_TOKEN") || "";
473
- const platformRuntimeAgent = await withVeryfrontPlatformRemoteTools({
474
- agent: runtimeBaseAgent,
475
- token: apiAuthToken || null,
476
- projectId: ctx.projectId ?? null,
477
- availableToolNames: runtimeInput.tools.map((tool) => tool.name),
478
- });
479
- const runtimeAgent = withVeryfrontStudioRemoteTools({
480
- agent: platformRuntimeAgent,
481
- token: apiAuthToken || null,
482
- projectId: ctx.projectId ?? null,
483
- forwardedProps: runtimeInput.forwardedProps,
484
- availableToolNames: runtimeInput.tools.map((tool) => tool.name),
485
- conversationId: runtimeInput.threadId,
486
- });
487
- // Load project env vars so source-defined MCP tool headers resolve
488
- // via _getProjectEnv(). Control-plane requests don't go through the proxy and
489
- // therefore don't carry x-environment-id, so we discover the production env ID
490
- // from the API (one fetch per project per server lifetime, then cached).
491
- let envVarsForAgent = {};
492
- if (ctx.projectSlug && apiAuthToken) {
493
- const environmentId = ctx.environmentId ??
494
- await _resolveProductionEnvironmentId(ctx.projectSlug, apiAuthToken);
495
- if (environmentId) {
496
- envVarsForAgent = await _agentEnvVarCache.get(environmentId, apiAuthToken, ctx.projectSlug);
497
- logger.debug("Agent stream env vars loaded", {
498
- runId: payload.runId,
499
- projectSlug: ctx.projectSlug,
500
- environmentId,
501
- count: Object.keys(envVarsForAgent).length,
502
- });
503
- }
504
- }
505
- const runAgentStream = () => createRuntimeAgentStreamResponse(runtimeInput, runtimeAgent, {
506
- ...this.deps,
507
- localTools,
508
- projectAgentSandbox: {
509
- apiUrl: resolveVeryfrontApiBaseUrlFromHostEnv(),
510
- authToken: apiAuthToken || undefined,
511
- projectId: ctx.projectId ?? null,
512
- },
513
- });
514
- const shouldIsolateEnv = apiAuthToken.length > 0;
515
- const response = shouldIsolateEnv
516
- ? await runWithProjectEnv(buildAgentStreamEnv({
517
- envVars: envVarsForAgent,
518
- proxyToken: apiAuthToken,
519
- projectSlug: ctx.projectSlug,
520
- }), runAgentStream)
521
- : await runAgentStream();
522
- logger.info("Internal agent stream response created", {
523
- runId: payload.runId,
524
- threadId: payload.threadId,
525
- agentId: payload.agentId,
526
- projectId: ctx.projectId,
527
- projectSlug: ctx.projectSlug,
528
- });
529
- const runtimeOwnerInvokeUrl = await this.deps.resolveRuntimeOwnerInvokeUrl?.(req) ??
530
- null;
531
- const responseWithOwner = runtimeOwnerInvokeUrl
532
- ? setResponseHeader(response, RUNTIME_OWNER_INVOKE_URL_HEADER, runtimeOwnerInvokeUrl)
533
- : response;
534
- return this.respond(applyBuilderHeaders(responseWithOwner, builder.headers));
535
- });
536
- }
537
- catch (error) {
538
- if (error instanceof InternalAgentRequestBodyTooLargeError) {
539
- return this.respond(builder.json({ error: error.message }, error.status));
540
- }
541
- if (error instanceof ControlPlaneRequestError) {
542
- return this.respond(builder.json({ error: error.message }, error.status));
543
- }
544
- if (error instanceof SyntaxError) {
545
- return this.respond(builder.json({ error: "Invalid internal agent stream request" }, 400));
546
- }
547
- if (error instanceof AgentRunAlreadyExistsError) {
548
- return this.respond(builder.json({ error: error.message }, 409));
549
- }
550
- if (error instanceof Error && error.name === "ZodError") {
551
- return this.respond(builder.json({ error: "Invalid internal agent stream request" }, 400));
552
510
  }
553
- this.logWarn("Internal agent stream request failed", {
554
- error: error instanceof Error ? error.message : String(error),
555
- projectId: ctx.projectId,
556
- projectSlug: ctx.projectSlug,
511
+ const runAgentStream = () => createRuntimeAgentStreamResponse(runtimeInput, runtimeAgent, {
512
+ ...this.deps,
513
+ localTools,
514
+ projectAgentSandbox: {
515
+ apiUrl: resolveVeryfrontApiBaseUrlFromHostEnv(),
516
+ authToken: apiAuthToken || undefined,
517
+ projectId: requestScopedContext.projectId ?? null,
518
+ },
557
519
  });
558
- logger.error("Internal agent stream handler failed", {
559
- projectId: ctx.projectId,
560
- projectSlug: ctx.projectSlug,
561
- error: error instanceof Error ? error.message : String(error),
520
+ const shouldIsolateEnv = apiAuthToken.length > 0;
521
+ const response = shouldIsolateEnv
522
+ ? await runWithProjectEnv(buildAgentStreamEnv({
523
+ envVars: envVarsForAgent,
524
+ proxyToken: apiAuthToken,
525
+ projectSlug: requestScopedContext.projectSlug,
526
+ }), runAgentStream)
527
+ : await runAgentStream();
528
+ logger.info("Internal agent stream response created", {
529
+ runId: payload.runId,
530
+ threadId: payload.threadId,
531
+ agentId: payload.agentId,
532
+ projectId: requestScopedContext.projectId,
533
+ projectSlug: requestScopedContext.projectSlug,
562
534
  });
563
- return this.respond(builder.json({ error: "Internal agent stream failed" }, 500));
535
+ const runtimeOwnerInvokeUrl = await this.deps.resolveRuntimeOwnerInvokeUrl?.(req) ??
536
+ null;
537
+ const responseWithOwner = runtimeOwnerInvokeUrl
538
+ ? setResponseHeader(response, RUNTIME_OWNER_INVOKE_URL_HEADER, runtimeOwnerInvokeUrl)
539
+ : response;
540
+ return this.respond(applyBuilderHeaders(responseWithOwner, builder.headers));
541
+ }));
542
+ }
543
+ catch (error) {
544
+ if (error instanceof InternalAgentRequestBodyTooLargeError) {
545
+ return this.respond(builder.json({ error: error.message }, error.status));
564
546
  }
565
- });
547
+ if (error instanceof ControlPlaneRequestError) {
548
+ return this.respond(builder.json({ error: error.message }, error.status));
549
+ }
550
+ if (error instanceof SyntaxError) {
551
+ return this.respond(builder.json({ error: "Invalid internal agent stream request" }, 400));
552
+ }
553
+ if (error instanceof AgentRunAlreadyExistsError) {
554
+ return this.respond(builder.json({ error: error.message }, 409));
555
+ }
556
+ if (error instanceof Error && error.name === "ZodError") {
557
+ return this.respond(builder.json({ error: "Invalid internal agent stream request" }, 400));
558
+ }
559
+ this.logWarn("Internal agent stream request failed", {
560
+ error: error instanceof Error ? error.message : String(error),
561
+ projectId: ctx.projectId,
562
+ projectSlug: ctx.projectSlug,
563
+ });
564
+ logger.error("Internal agent stream handler failed", {
565
+ projectId: ctx.projectId,
566
+ projectSlug: ctx.projectSlug,
567
+ error: error instanceof Error ? error.message : String(error),
568
+ });
569
+ return this.respond(builder.json({ error: "Internal agent stream failed" }, 500));
570
+ }
566
571
  }
567
572
  }
@@ -1,3 +1,3 @@
1
1
  /** Shared version value. */
2
- export declare const VERSION = "0.1.1044";
2
+ export declare const VERSION = "0.1.1046";
3
3
  //# sourceMappingURL=version-constant.d.ts.map
@@ -1,4 +1,4 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
3
  /** Shared version value. */
4
- export const VERSION = "0.1.1044";
4
+ export const VERSION = "0.1.1046";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfront",
3
- "version": "0.1.1044",
3
+ "version": "0.1.1046",
4
4
  "description": "The simplest way to build AI-powered apps",
5
5
  "keywords": [
6
6
  "react",
@@ -330,9 +330,9 @@
330
330
  "@types/react": "19.2.14",
331
331
  "@types/react-dom": "19.2.3",
332
332
  "ws": "8.21.0",
333
- "@veryfront/ext-bundler-esbuild": "0.1.1044",
334
- "@veryfront/ext-content-mdx": "0.1.1044",
335
- "@veryfront/ext-css-tailwind": "0.1.1044"
333
+ "@veryfront/ext-bundler-esbuild": "0.1.1046",
334
+ "@veryfront/ext-content-mdx": "0.1.1046",
335
+ "@veryfront/ext-css-tailwind": "0.1.1046"
336
336
  },
337
337
  "devDependencies": {
338
338
  "@types/node": "20.9.0"