@base44-preview/cli 0.3.1-pr.696.d3cf031 → 0.3.1-pr.697.d8b6e5d

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/cli/index.js CHANGED
@@ -252877,6 +252877,7 @@ async function createVersion(artifacts, options = {}) {
252877
252877
  actors: artifacts.actors.map(declaredActor),
252878
252878
  entities: artifacts.entities,
252879
252879
  agents: artifacts.agents,
252880
+ mcp_config: artifacts.mcpConfig,
252880
252881
  source_commit: options.sourceCommit
252881
252882
  }, "declaring a version")).json(), "declare");
252882
252883
  const declaredFiles = [
@@ -256813,24 +256814,6 @@ var Actor = class _Actor extends Server {
256813
256814
  }
256814
256815
  handleWake(_key) {
256815
256816
  }
256816
- // Optional: the platform posted an event into this room. Delivery is
256817
- // at-least-once; a repeat of an event_id this instance already took is dropped
256818
- // here, so a room that must be exact across evictions dedups on event_id too.
256819
- handlePlatformEvent(_event) {
256820
- }
256821
- takenPlatformEvents = [];
256822
- static REMEMBERED_PLATFORM_EVENTS = 64;
256823
- // Called by the generated wrapper for a verified POST .../events; never user-facing.
256824
- async _b44PlatformEvent(request) {
256825
- const event = await request.json();
256826
- if (!this.takenPlatformEvents.includes(event.event_id)) {
256827
- await this.handlePlatformEvent(event);
256828
- this.takenPlatformEvents.push(event.event_id);
256829
- if (this.takenPlatformEvents.length > _Actor.REMEMBERED_PLATFORM_EVENTS) this.takenPlatformEvents.shift();
256830
- await this.maintainTicker();
256831
- }
256832
- return new Response(null, { status: 204 });
256833
- }
256834
256817
  async schedule(key, at) {
256835
256818
  const when = typeof at === "number" ? at : at.getTime();
256836
256819
  await this.mutateSchedules((m) => {
@@ -259070,12 +259053,8 @@ function buildActorAuth() {
259070
259053
  return `// Auto-generated by the base44 bundler. Do not edit.
259071
259054
  const TOKEN_HEADER = "X-Base44-Actor-Token";
259072
259055
  const IDENTITY_HEADER = "X-Base44-Actor-Identity";
259073
- const EVENT_TOKEN_HEADER = "X-Base44-Actor-Event-Token";
259074
259056
  const CLOCK_SKEW_SECONDS = 30;
259075
259057
  const TOKEN_TTL_SECONDS = 300;
259076
- const EVENT_TOKEN_TTL_SECONDS = 60;
259077
- const EVENT_MAX_BYTES = 64 * 1024;
259078
- const EVENT_TYPE_PREFIX = "__";
259079
259058
 
259080
259059
  const decodeSegment = (segment) => {
259081
259060
  const normalized = segment.replace(/-/g, "+").replace(/_/g, "/");
@@ -259091,37 +259070,6 @@ const unauthorized = () => ({
259091
259070
  ok: false,
259092
259071
  response: new Response("Unauthorized", { status: 401 }),
259093
259072
  });
259094
- const refused = (status, text) => ({ ok: false, response: new Response(text, { status }) });
259095
-
259096
- // The claims of an EdDSA JWT whose signature the actor's public key verifies, else null.
259097
- const verifiedClaims = async (token, publicKey) => {
259098
- if (typeof token !== "string" || token.length > 4096) return null;
259099
- const parts = token.split(".");
259100
- if (parts.length !== 3) return null;
259101
- const header = decodeJsonSegment(parts[0]);
259102
- if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) return null;
259103
- const key = await crypto.subtle.importKey(
259104
- "raw",
259105
- decodeSegment(publicKey),
259106
- { name: "Ed25519" },
259107
- false,
259108
- ["verify"],
259109
- );
259110
- const validSignature = await crypto.subtle.verify(
259111
- { name: "Ed25519" },
259112
- key,
259113
- decodeSegment(parts[2]),
259114
- new TextEncoder().encode(parts[0] + "." + parts[1]),
259115
- );
259116
- return validSignature ? decodeJsonSegment(parts[1]) : null;
259117
- };
259118
-
259119
- const validTimes = (claims, now, ttlSeconds) =>
259120
- [claims.iat, claims.nbf, claims.exp].every(Number.isInteger) &&
259121
- claims.iat <= now + CLOCK_SKEW_SECONDS &&
259122
- claims.nbf <= now + CLOCK_SKEW_SECONDS &&
259123
- claims.exp >= now - CLOCK_SKEW_SECONDS &&
259124
- claims.exp > claims.iat && claims.exp - claims.iat <= ttlSeconds;
259125
259073
 
259126
259074
  const validPrincipal = (principal) => {
259127
259075
  if (principal === null || typeof principal !== "object" || Array.isArray(principal)) return false;
@@ -259140,21 +259088,46 @@ export async function verifyActorConnection(request, env, actorName, room) {
259140
259088
  const token = request.headers.get(TOKEN_HEADER) ?? new URL(request.url).searchParams.get("token");
259141
259089
  if (
259142
259090
  typeof publicKey !== "string" || !publicKey ||
259143
- typeof scriptId !== "string" || !scriptId
259091
+ typeof scriptId !== "string" || !scriptId ||
259092
+ typeof token !== "string" || token.length > 4096
259144
259093
  ) return unauthorized();
259145
259094
 
259095
+ const parts = token.split(".");
259096
+ if (parts.length !== 3) return unauthorized();
259146
259097
  try {
259147
- const claims = await verifiedClaims(token, publicKey);
259148
- if (!claims) return unauthorized();
259098
+ const header = decodeJsonSegment(parts[0]);
259099
+ const claims = decodeJsonSegment(parts[1]);
259100
+ if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) {
259101
+ return unauthorized();
259102
+ }
259103
+ const key = await crypto.subtle.importKey(
259104
+ "raw",
259105
+ decodeSegment(publicKey),
259106
+ { name: "Ed25519" },
259107
+ false,
259108
+ ["verify"],
259109
+ );
259110
+ const validSignature = await crypto.subtle.verify(
259111
+ { name: "Ed25519" },
259112
+ key,
259113
+ decodeSegment(parts[2]),
259114
+ new TextEncoder().encode(parts[0] + "." + parts[1]),
259115
+ );
259116
+ if (!validSignature) return unauthorized();
259149
259117
 
259150
259118
  const now = Math.floor(Date.now() / 1000);
259119
+ const times = [claims.iat, claims.nbf, claims.exp];
259120
+ if (!times.every(Number.isInteger)) return unauthorized();
259151
259121
  if (
259152
259122
  claims.iss !== "base44" ||
259153
259123
  claims.aud !== "base44-actor-connect" ||
259154
259124
  claims.purpose !== "actor-connect" ||
259155
259125
  claims.v !== 1 ||
259156
259126
  typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259157
- !validTimes(claims, now, TOKEN_TTL_SECONDS) ||
259127
+ claims.iat > now + CLOCK_SKEW_SECONDS ||
259128
+ claims.nbf > now + CLOCK_SKEW_SECONDS ||
259129
+ claims.exp < now - CLOCK_SKEW_SECONDS ||
259130
+ claims.exp <= claims.iat || claims.exp - claims.iat > TOKEN_TTL_SECONDS ||
259158
259131
  claims.app_id !== env.BASE44_APP_ID ||
259159
259132
  claims.actor_name !== actorName ||
259160
259133
  claims.actor_script_id !== scriptId ||
@@ -259184,75 +259157,6 @@ export function authorizedActorRequest(request, identity, actorName, room, runti
259184
259157
  headers.set("base44-functions-version", runtimeMode === "prod" ? "prod" : "preview");
259185
259158
  return new Request(new Request(url.toString(), request), { headers });
259186
259159
  }
259187
-
259188
- // A platform event the backend posts into one room. Same key as connection
259189
- // tokens, its own audience and purpose: neither token is accepted as the other.
259190
- // 401 is a token this key did not mint or that has lapsed; 403 is a good token
259191
- // for another app, actor, script or room.
259192
- export async function verifyActorEvent(request, env, actorName, room) {
259193
- const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
259194
- const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
259195
- if (
259196
- typeof publicKey !== "string" || !publicKey ||
259197
- typeof scriptId !== "string" || !scriptId
259198
- ) return unauthorized();
259199
- try {
259200
- const claims = await verifiedClaims(request.headers.get(EVENT_TOKEN_HEADER), publicKey);
259201
- if (!claims) return unauthorized();
259202
- const now = Math.floor(Date.now() / 1000);
259203
- if (
259204
- claims.iss !== "base44" ||
259205
- claims.aud !== "base44-actor-event" ||
259206
- claims.purpose !== "actor-platform-event" ||
259207
- claims.v !== 1 ||
259208
- typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259209
- !validTimes(claims, now, EVENT_TOKEN_TTL_SECONDS) ||
259210
- typeof claims.event_id !== "string" || !claims.event_id || claims.event_id.length > 256
259211
- ) return unauthorized();
259212
- if (
259213
- claims.app_id !== env.BASE44_APP_ID ||
259214
- claims.actor_name !== actorName ||
259215
- claims.actor_script_id !== scriptId ||
259216
- claims.room !== room
259217
- ) return refused(403, "Forbidden");
259218
- return { ok: true, eventId: claims.event_id };
259219
- } catch {
259220
- return unauthorized();
259221
- }
259222
- }
259223
-
259224
- // The JSON body of a verified event: one object in the platform's "__" type
259225
- // namespace whose event_id is the one the token was minted for.
259226
- export async function readPlatformEvent(request, eventId) {
259227
- let text;
259228
- try { text = await request.text(); } catch { return refused(400, "Unreadable event"); }
259229
- if (new TextEncoder().encode(text).length > EVENT_MAX_BYTES) return refused(413, "Event too large");
259230
- let event;
259231
- try { event = JSON.parse(text); } catch { return refused(400, "Invalid event"); }
259232
- if (
259233
- event === null || typeof event !== "object" || Array.isArray(event) ||
259234
- typeof event.type !== "string" || !event.type.startsWith(EVENT_TYPE_PREFIX) || event.type.length > 128 ||
259235
- event.event_id !== eventId
259236
- ) return refused(400, "Invalid event");
259237
- return { ok: true, event };
259238
- }
259239
-
259240
- // Into the room as POST /parties/<actor>/<room>/events: a path no client route
259241
- // forwards (the legacy route is exactly four segments, the direct route rewrites
259242
- // the path), so the Durable Object can trust the shape alone.
259243
- export function platformEventRequest(request, env, actorName, room, event) {
259244
- const url = new URL(request.url);
259245
- url.search = "";
259246
- url.pathname = "/parties/" + encodeURIComponent(actorName) + "/" + encodeURIComponent(room) + "/events";
259247
- return new Request(url.toString(), {
259248
- method: "POST",
259249
- headers: {
259250
- "Content-Type": "application/json",
259251
- "base44-functions-version": env.BASE44_FUNCTIONS_VERSION === "prod" ? "prod" : "preview",
259252
- },
259253
- body: JSON.stringify(event),
259254
- });
259255
- }
259256
259160
  `;
259257
259161
  }
259258
259162
  function buildPrelude() {
@@ -259273,13 +259177,7 @@ function buildEntryWrapper(doClassName, userEntry) {
259273
259177
  import "./${ACTOR_PRELUDE_FILENAME}";
259274
259178
  import Base44UserActor from ${JSON.stringify(userImport)};
259275
259179
  import { runWithWorkerEnvironment as _b44Run } from ${JSON.stringify(RUNTIME_CONTEXT_SPECIFIER)};
259276
- import {
259277
- authorizedActorRequest as _b44AuthorizedActorRequest,
259278
- platformEventRequest as _b44PlatformEventRequest,
259279
- readPlatformEvent as _b44ReadPlatformEvent,
259280
- verifyActorConnection as _b44VerifyActorConnection,
259281
- verifyActorEvent as _b44VerifyActorEvent,
259282
- } from "./${ACTOR_AUTH_FILENAME}";
259180
+ import { authorizedActorRequest as _b44AuthorizedActorRequest, verifyActorConnection as _b44VerifyActorConnection } from "./${ACTOR_AUTH_FILENAME}";
259283
259181
 
259284
259182
  const _b44ActorState = new WeakMap();
259285
259183
  const _b44RunWithActorEnvironment = (ctx, env, runtimeEnv, callback) => _b44Run({
@@ -259309,11 +259207,6 @@ const _b44RunActor = (actor, request, callback) => {
259309
259207
  state.runtimeEnv = runtimeEnv;
259310
259208
  return _b44RunWithActorEnvironment(state.ctx, state.env, runtimeEnv, callback);
259311
259209
  };
259312
- const _b44IsPlatformEvent = (request) => {
259313
- if (request.method !== "POST") return false;
259314
- const parts = new URL(request.url).pathname.split("/");
259315
- return parts.length === 5 && parts[1] === "parties" && parts[4] === "events";
259316
- };
259317
259210
 
259318
259211
  export class ${doClassName} extends Base44UserActor {
259319
259212
  // Read by the shim's service-token exchange: the assertion's actor_name claim
@@ -259326,11 +259219,6 @@ export class ${doClassName} extends Base44UserActor {
259326
259219
  }
259327
259220
 
259328
259221
  fetch(request) {
259329
- // Ahead of the user's own fetch override: a platform event is the wrapper's,
259330
- // never a request the room handles itself.
259331
- if (_b44IsPlatformEvent(request)) {
259332
- return _b44RunActor(this, request, () => this._b44PlatformEvent(request));
259333
- }
259334
259222
  return _b44RunActor(this, request, () => super.fetch(request));
259335
259223
  }
259336
259224
 
@@ -259364,22 +259252,15 @@ export default {
259364
259252
  const parts = url.pathname.split("/");
259365
259253
  const direct = parts[1] === "rooms" && parts.length === 3;
259366
259254
  const legacy = parts[1] === "parties" && parts.length === 4;
259367
- const event = request.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "events";
259368
- if (direct || legacy || event) {
259255
+ if (direct || legacy) {
259369
259256
  // Decode the room: the token was verified against the decoded instance id,
259370
259257
  // so an escaped room must map to the same Durable Object.
259371
- const namespace = legacy ? parts[2] : "${doClassName}";
259372
- const encodedRoom = legacy ? parts[3] : parts[2];
259258
+ const namespace = direct ? "${doClassName}" : parts[2];
259259
+ const encodedRoom = direct ? parts[2] : parts[3];
259373
259260
  let room;
259374
259261
  try { room = decodeURIComponent(encodedRoom); } catch { return new Response("Invalid room", { status: 400 }); }
259375
259262
  let actorRequest = request;
259376
- if (event) {
259377
- const verification = await _b44VerifyActorEvent(request, env, "${doClassName}", room);
259378
- if (!verification.ok) return verification.response;
259379
- const platformEvent = await _b44ReadPlatformEvent(request, verification.eventId);
259380
- if (!platformEvent.ok) return platformEvent.response;
259381
- actorRequest = _b44PlatformEventRequest(request, env, "${doClassName}", room, platformEvent.event);
259382
- } else if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259263
+ if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259383
259264
  const verification = await _b44VerifyActorConnection(request, env, "${doClassName}", room);
259384
259265
  if (!verification.ok) return verification.response;
259385
259266
  actorRequest = _b44AuthorizedActorRequest(
@@ -264672,12 +264553,17 @@ async function readRawResources(dir) {
264672
264553
  }
264673
264554
  return payloads;
264674
264555
  }
264556
+ async function readMcpConfig(configDir) {
264557
+ const path = join30(configDir, "mcp", "config.json");
264558
+ return await pathExists(path) ? await readTextFile(path) : "";
264559
+ }
264675
264560
  async function collectResources(configDir, dirs) {
264676
- const [entities, agents] = await Promise.all([
264561
+ const [entities, agents, mcpConfig] = await Promise.all([
264677
264562
  readRawResources(join30(configDir, dirs.entitiesDir)),
264678
- readRawResources(join30(configDir, dirs.agentsDir))
264563
+ readRawResources(join30(configDir, dirs.agentsDir)),
264564
+ readMcpConfig(configDir)
264679
264565
  ]);
264680
- return { entities, agents };
264566
+ return { entities, agents, mcpConfig };
264681
264567
  }
264682
264568
  async function collectArtifacts(target) {
264683
264569
  const built = await resolveFullStackBuild(target.root);
@@ -275196,4 +275082,4 @@ export {
275196
275082
  runCLI
275197
275083
  };
275198
275084
 
275199
- //# debugId=0543661A2E4EC46564756E2164756E21
275085
+ //# debugId=8C1B105F76867A6564756E2164756E21