@base44-preview/cli 0.3.2-pr.698.ea0a371 → 0.3.2-pr.699.00cdc4d

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
@@ -237180,7 +237180,7 @@ var SKILL_NAME_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
237180
237180
  var AgentSkillSchema = object({
237181
237181
  name: string2().trim().min(1).max(64).regex(SKILL_NAME_REGEX, "Skill name must be lowercase-hyphenated (a-z, 0-9, -)"),
237182
237182
  description: string2().trim().min(1, "Description is required").max(1024),
237183
- body: string2().trim().min(1, "Body is required").max(50000)
237183
+ body: string2().trim().min(1, "Body is required").max(15000)
237184
237184
  });
237185
237185
  var AgentSkillApiResponseSchema = object({
237186
237186
  name: string2(),
@@ -247073,7 +247073,6 @@ async function resolveBuildTarget(projectRoot, overrides = {}) {
247073
247073
  outputDir: resolve6(root, overrides.outputDir ?? site.outputDirectory ?? DEFAULT_SITE.outputDirectory),
247074
247074
  entitiesDir: project?.entitiesDir ?? "entities",
247075
247075
  agentsDir: project?.agentsDir ?? "agents",
247076
- agentSkillsDir: project?.agentSkillsDir ?? "agent-skills",
247077
247076
  functionsDir: project?.functionsDir ?? "functions",
247078
247077
  actorsDir: project?.actorsDir ?? "actors"
247079
247078
  };
@@ -252879,7 +252878,6 @@ async function createVersion(artifacts, options = {}) {
252879
252878
  entities: artifacts.entities,
252880
252879
  agents: artifacts.agents,
252881
252880
  mcp_config: artifacts.mcpConfig,
252882
- agent_skills: artifacts.agentSkills,
252883
252881
  source_commit: options.sourceCommit
252884
252882
  }, "declaring a version")).json(), "declare");
252885
252883
  const declaredFiles = [
@@ -255440,7 +255438,6 @@ var deno2 = Object.freeze({
255440
255438
  });
255441
255439
  globalThis.Deno = deno2;
255442
255440
  globalThis.Buffer = Buffer2;
255443
- if (typeof process !== "undefined") process.version = "v22.23.4";
255444
255441
  try {
255445
255442
  new AsyncLocalStorage().enterWith(void 0);
255446
255443
  } catch {
@@ -256406,7 +256403,7 @@ Did you try connecting directly to this Durable Object? Try using getServerByNam
256406
256403
  };
256407
256404
 
256408
256405
  // src/shim/actor.ts
256409
- import { createClient } from "npm:@base44/sdk@0.8.41";
256406
+ import { createClient } from "npm:@base44/sdk@0.8.54";
256410
256407
 
256411
256408
  // src/shim/tick-loop.ts
256412
256409
  var TickLoop = class {
@@ -256816,6 +256813,36 @@ var Actor = class _Actor extends Server {
256816
256813
  }
256817
256814
  handleWake(_key) {
256818
256815
  }
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
+ platformEventsInFlight = /* @__PURE__ */ new Map();
256823
+ static REMEMBERED_PLATFORM_EVENTS = 64;
256824
+ // Called by the generated wrapper for a verified POST .../events; never user-facing.
256825
+ async _b44PlatformEvent(request) {
256826
+ const room = request.headers.get("x-partykit-room");
256827
+ if (room) await this.setName(room);
256828
+ const event = await request.json();
256829
+ const eventId = event.event_id;
256830
+ if (!this.takenPlatformEvents.includes(eventId)) {
256831
+ let delivery = this.platformEventsInFlight.get(eventId);
256832
+ if (!delivery) {
256833
+ delivery = this.takePlatformEvent(event).finally(() => this.platformEventsInFlight.delete(eventId));
256834
+ this.platformEventsInFlight.set(eventId, delivery);
256835
+ }
256836
+ await delivery;
256837
+ }
256838
+ return new Response(null, { status: 204 });
256839
+ }
256840
+ async takePlatformEvent(event) {
256841
+ await this.handlePlatformEvent(event);
256842
+ this.takenPlatformEvents.push(event.event_id);
256843
+ if (this.takenPlatformEvents.length > _Actor.REMEMBERED_PLATFORM_EVENTS) this.takenPlatformEvents.shift();
256844
+ await this.maintainTicker();
256845
+ }
256819
256846
  async schedule(key, at) {
256820
256847
  const when = typeof at === "number" ? at : at.getTime();
256821
256848
  await this.mutateSchedules((m) => {
@@ -258556,7 +258583,7 @@ var TELEMETRY_PATCH = [
258556
258583
  var TELEMETRY_STORE_FIELDS = "reqId: crypto.randomUUID(), respondedAt: null, inflight: new Map(), inflightTotal: 0, hadRejection: false, hadNonOk: false, logBudget: 5";
258557
258584
 
258558
258585
  // ../functions-compiler/src/version.ts
258559
- var COMPILER_VERSION = "0.2.0";
258586
+ var COMPILER_VERSION = "0.3.0";
258560
258587
 
258561
258588
  // ../functions-compiler/src/worker-entry.ts
258562
258589
  function denoShimSource() {
@@ -259055,8 +259082,12 @@ function buildActorAuth() {
259055
259082
  return `// Auto-generated by the base44 bundler. Do not edit.
259056
259083
  const TOKEN_HEADER = "X-Base44-Actor-Token";
259057
259084
  const IDENTITY_HEADER = "X-Base44-Actor-Identity";
259085
+ const EVENT_TOKEN_HEADER = "X-Base44-Actor-Event-Token";
259058
259086
  const CLOCK_SKEW_SECONDS = 30;
259059
259087
  const TOKEN_TTL_SECONDS = 300;
259088
+ const EVENT_TOKEN_TTL_SECONDS = 60;
259089
+ const EVENT_MAX_BYTES = 64 * 1024;
259090
+ const EVENT_TYPE_PREFIX = "__";
259060
259091
 
259061
259092
  const decodeSegment = (segment) => {
259062
259093
  const normalized = segment.replace(/-/g, "+").replace(/_/g, "/");
@@ -259072,6 +259103,37 @@ const unauthorized = () => ({
259072
259103
  ok: false,
259073
259104
  response: new Response("Unauthorized", { status: 401 }),
259074
259105
  });
259106
+ const refused = (status, text) => ({ ok: false, response: new Response(text, { status }) });
259107
+
259108
+ // The claims of an EdDSA JWT whose signature the actor's public key verifies, else null.
259109
+ const verifiedClaims = async (token, publicKey) => {
259110
+ if (typeof token !== "string" || token.length > 4096) return null;
259111
+ const parts = token.split(".");
259112
+ if (parts.length !== 3) return null;
259113
+ const header = decodeJsonSegment(parts[0]);
259114
+ if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) return null;
259115
+ const key = await crypto.subtle.importKey(
259116
+ "raw",
259117
+ decodeSegment(publicKey),
259118
+ { name: "Ed25519" },
259119
+ false,
259120
+ ["verify"],
259121
+ );
259122
+ const validSignature = await crypto.subtle.verify(
259123
+ { name: "Ed25519" },
259124
+ key,
259125
+ decodeSegment(parts[2]),
259126
+ new TextEncoder().encode(parts[0] + "." + parts[1]),
259127
+ );
259128
+ return validSignature ? decodeJsonSegment(parts[1]) : null;
259129
+ };
259130
+
259131
+ const validTimes = (claims, now, ttlSeconds) =>
259132
+ [claims.iat, claims.nbf, claims.exp].every(Number.isInteger) &&
259133
+ claims.iat <= now + CLOCK_SKEW_SECONDS &&
259134
+ claims.nbf <= now + CLOCK_SKEW_SECONDS &&
259135
+ claims.exp >= now - CLOCK_SKEW_SECONDS &&
259136
+ claims.exp > claims.iat && claims.exp - claims.iat <= ttlSeconds;
259075
259137
 
259076
259138
  const validPrincipal = (principal) => {
259077
259139
  if (principal === null || typeof principal !== "object" || Array.isArray(principal)) return false;
@@ -259090,46 +259152,21 @@ export async function verifyActorConnection(request, env, actorName, room) {
259090
259152
  const token = request.headers.get(TOKEN_HEADER) ?? new URL(request.url).searchParams.get("token");
259091
259153
  if (
259092
259154
  typeof publicKey !== "string" || !publicKey ||
259093
- typeof scriptId !== "string" || !scriptId ||
259094
- typeof token !== "string" || token.length > 4096
259155
+ typeof scriptId !== "string" || !scriptId
259095
259156
  ) return unauthorized();
259096
259157
 
259097
- const parts = token.split(".");
259098
- if (parts.length !== 3) return unauthorized();
259099
259158
  try {
259100
- const header = decodeJsonSegment(parts[0]);
259101
- const claims = decodeJsonSegment(parts[1]);
259102
- if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) {
259103
- return unauthorized();
259104
- }
259105
- const key = await crypto.subtle.importKey(
259106
- "raw",
259107
- decodeSegment(publicKey),
259108
- { name: "Ed25519" },
259109
- false,
259110
- ["verify"],
259111
- );
259112
- const validSignature = await crypto.subtle.verify(
259113
- { name: "Ed25519" },
259114
- key,
259115
- decodeSegment(parts[2]),
259116
- new TextEncoder().encode(parts[0] + "." + parts[1]),
259117
- );
259118
- if (!validSignature) return unauthorized();
259159
+ const claims = await verifiedClaims(token, publicKey);
259160
+ if (!claims) return unauthorized();
259119
259161
 
259120
259162
  const now = Math.floor(Date.now() / 1000);
259121
- const times = [claims.iat, claims.nbf, claims.exp];
259122
- if (!times.every(Number.isInteger)) return unauthorized();
259123
259163
  if (
259124
259164
  claims.iss !== "base44" ||
259125
259165
  claims.aud !== "base44-actor-connect" ||
259126
259166
  claims.purpose !== "actor-connect" ||
259127
259167
  claims.v !== 1 ||
259128
259168
  typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259129
- claims.iat > now + CLOCK_SKEW_SECONDS ||
259130
- claims.nbf > now + CLOCK_SKEW_SECONDS ||
259131
- claims.exp < now - CLOCK_SKEW_SECONDS ||
259132
- claims.exp <= claims.iat || claims.exp - claims.iat > TOKEN_TTL_SECONDS ||
259169
+ !validTimes(claims, now, TOKEN_TTL_SECONDS) ||
259133
259170
  claims.app_id !== env.BASE44_APP_ID ||
259134
259171
  claims.actor_name !== actorName ||
259135
259172
  claims.actor_script_id !== scriptId ||
@@ -259159,6 +259196,75 @@ export function authorizedActorRequest(request, identity, actorName, room, runti
259159
259196
  headers.set("base44-functions-version", runtimeMode === "prod" ? "prod" : "preview");
259160
259197
  return new Request(new Request(url.toString(), request), { headers });
259161
259198
  }
259199
+
259200
+ // A platform event the backend posts into one room. Same key as connection
259201
+ // tokens, its own audience and purpose: neither token is accepted as the other.
259202
+ // 401 is a token this key did not mint or that has lapsed; 403 is a good token
259203
+ // for another app, actor, script or room.
259204
+ export async function verifyActorEvent(request, env, actorName, room) {
259205
+ const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
259206
+ const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
259207
+ if (
259208
+ typeof publicKey !== "string" || !publicKey ||
259209
+ typeof scriptId !== "string" || !scriptId
259210
+ ) return unauthorized();
259211
+ try {
259212
+ const claims = await verifiedClaims(request.headers.get(EVENT_TOKEN_HEADER), publicKey);
259213
+ if (!claims) return unauthorized();
259214
+ const now = Math.floor(Date.now() / 1000);
259215
+ if (
259216
+ claims.iss !== "base44" ||
259217
+ claims.aud !== "base44-actor-event" ||
259218
+ claims.purpose !== "actor-platform-event" ||
259219
+ claims.v !== 1 ||
259220
+ typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259221
+ !validTimes(claims, now, EVENT_TOKEN_TTL_SECONDS) ||
259222
+ typeof claims.event_id !== "string" || !claims.event_id || claims.event_id.length > 256
259223
+ ) return unauthorized();
259224
+ if (
259225
+ claims.app_id !== env.BASE44_APP_ID ||
259226
+ claims.actor_name !== actorName ||
259227
+ claims.actor_script_id !== scriptId ||
259228
+ claims.room !== room
259229
+ ) return refused(403, "Forbidden");
259230
+ return { ok: true, eventId: claims.event_id };
259231
+ } catch {
259232
+ return unauthorized();
259233
+ }
259234
+ }
259235
+
259236
+ // The JSON body of a verified event: one object in the platform's "__" type
259237
+ // namespace whose event_id is the one the token was minted for.
259238
+ export async function readPlatformEvent(request, eventId) {
259239
+ let text;
259240
+ try { text = await request.text(); } catch { return refused(400, "Unreadable event"); }
259241
+ if (new TextEncoder().encode(text).length > EVENT_MAX_BYTES) return refused(413, "Event too large");
259242
+ let event;
259243
+ try { event = JSON.parse(text); } catch { return refused(400, "Invalid event"); }
259244
+ if (
259245
+ event === null || typeof event !== "object" || Array.isArray(event) ||
259246
+ typeof event.type !== "string" || !event.type.startsWith(EVENT_TYPE_PREFIX) || event.type.length > 128 ||
259247
+ event.event_id !== eventId
259248
+ ) return refused(400, "Invalid event");
259249
+ return { ok: true, event };
259250
+ }
259251
+
259252
+ // Into the room as POST /parties/<actor>/<room>/events: a path no client route
259253
+ // forwards (the legacy route is exactly four segments, the direct route rewrites
259254
+ // the path), so the Durable Object can trust the shape alone.
259255
+ export function platformEventRequest(request, env, actorName, room, event) {
259256
+ const url = new URL(request.url);
259257
+ url.search = "";
259258
+ url.pathname = "/parties/" + encodeURIComponent(actorName) + "/" + encodeURIComponent(room) + "/events";
259259
+ return new Request(url.toString(), {
259260
+ method: "POST",
259261
+ headers: {
259262
+ "Content-Type": "application/json",
259263
+ "base44-functions-version": env.BASE44_FUNCTIONS_VERSION === "prod" ? "prod" : "preview",
259264
+ },
259265
+ body: JSON.stringify(event),
259266
+ });
259267
+ }
259162
259268
  `;
259163
259269
  }
259164
259270
  function buildPrelude() {
@@ -259179,7 +259285,13 @@ function buildEntryWrapper(doClassName, userEntry) {
259179
259285
  import "./${ACTOR_PRELUDE_FILENAME}";
259180
259286
  import Base44UserActor from ${JSON.stringify(userImport)};
259181
259287
  import { runWithWorkerEnvironment as _b44Run } from ${JSON.stringify(RUNTIME_CONTEXT_SPECIFIER)};
259182
- import { authorizedActorRequest as _b44AuthorizedActorRequest, verifyActorConnection as _b44VerifyActorConnection } from "./${ACTOR_AUTH_FILENAME}";
259288
+ import {
259289
+ authorizedActorRequest as _b44AuthorizedActorRequest,
259290
+ platformEventRequest as _b44PlatformEventRequest,
259291
+ readPlatformEvent as _b44ReadPlatformEvent,
259292
+ verifyActorConnection as _b44VerifyActorConnection,
259293
+ verifyActorEvent as _b44VerifyActorEvent,
259294
+ } from "./${ACTOR_AUTH_FILENAME}";
259183
259295
 
259184
259296
  const _b44ActorState = new WeakMap();
259185
259297
  const _b44RunWithActorEnvironment = (ctx, env, runtimeEnv, callback) => _b44Run({
@@ -259209,6 +259321,11 @@ const _b44RunActor = (actor, request, callback) => {
259209
259321
  state.runtimeEnv = runtimeEnv;
259210
259322
  return _b44RunWithActorEnvironment(state.ctx, state.env, runtimeEnv, callback);
259211
259323
  };
259324
+ const _b44IsPlatformEvent = (request) => {
259325
+ if (request.method !== "POST") return false;
259326
+ const parts = new URL(request.url).pathname.split("/");
259327
+ return parts.length === 5 && parts[1] === "parties" && parts[4] === "events";
259328
+ };
259212
259329
 
259213
259330
  export class ${doClassName} extends Base44UserActor {
259214
259331
  // Read by the shim's service-token exchange: the assertion's actor_name claim
@@ -259221,6 +259338,11 @@ export class ${doClassName} extends Base44UserActor {
259221
259338
  }
259222
259339
 
259223
259340
  fetch(request) {
259341
+ // Ahead of the user's own fetch override: a platform event is the wrapper's,
259342
+ // never a request the room handles itself.
259343
+ if (_b44IsPlatformEvent(request)) {
259344
+ return _b44RunActor(this, request, () => this._b44PlatformEvent(request));
259345
+ }
259224
259346
  return _b44RunActor(this, request, () => super.fetch(request));
259225
259347
  }
259226
259348
 
@@ -259254,15 +259376,22 @@ export default {
259254
259376
  const parts = url.pathname.split("/");
259255
259377
  const direct = parts[1] === "rooms" && parts.length === 3;
259256
259378
  const legacy = parts[1] === "parties" && parts.length === 4;
259257
- if (direct || legacy) {
259379
+ const event = request.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "events";
259380
+ if (direct || legacy || event) {
259258
259381
  // Decode the room: the token was verified against the decoded instance id,
259259
259382
  // so an escaped room must map to the same Durable Object.
259260
- const namespace = direct ? "${doClassName}" : parts[2];
259261
- const encodedRoom = direct ? parts[2] : parts[3];
259383
+ const namespace = legacy ? parts[2] : "${doClassName}";
259384
+ const encodedRoom = legacy ? parts[3] : parts[2];
259262
259385
  let room;
259263
259386
  try { room = decodeURIComponent(encodedRoom); } catch { return new Response("Invalid room", { status: 400 }); }
259264
259387
  let actorRequest = request;
259265
- if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259388
+ if (event) {
259389
+ const verification = await _b44VerifyActorEvent(request, env, "${doClassName}", room);
259390
+ if (!verification.ok) return verification.response;
259391
+ const platformEvent = await _b44ReadPlatformEvent(request, verification.eventId);
259392
+ if (!platformEvent.ok) return platformEvent.response;
259393
+ actorRequest = _b44PlatformEventRequest(request, env, "${doClassName}", room, platformEvent.event);
259394
+ } else if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259266
259395
  const verification = await _b44VerifyActorConnection(request, env, "${doClassName}", room);
259267
259396
  if (!verification.ok) return verification.response;
259268
259397
  actorRequest = _b44AuthorizedActorRequest(
@@ -264559,29 +264688,13 @@ async function readMcpConfig(configDir) {
264559
264688
  const path = join30(configDir, "mcp", "config.json");
264560
264689
  return await pathExists(path) ? await readTextFile(path) : "";
264561
264690
  }
264562
- async function readAgentSkillFiles(dir) {
264563
- if (!await pathExists(dir)) {
264564
- return {};
264565
- }
264566
- const files = await globby("*.md", {
264567
- cwd: dir,
264568
- onlyFiles: true,
264569
- followSymbolicLinks: false
264570
- });
264571
- const skills = {};
264572
- for (const file of files.sort()) {
264573
- skills[file.replace(/\.md$/, "")] = await readTextFile(join30(dir, file));
264574
- }
264575
- return skills;
264576
- }
264577
264691
  async function collectResources(configDir, dirs) {
264578
- const [entities, agents, mcpConfig, agentSkills] = await Promise.all([
264692
+ const [entities, agents, mcpConfig] = await Promise.all([
264579
264693
  readRawResources(join30(configDir, dirs.entitiesDir)),
264580
264694
  readRawResources(join30(configDir, dirs.agentsDir)),
264581
- readMcpConfig(configDir),
264582
- readAgentSkillFiles(join30(configDir, dirs.agentSkillsDir))
264695
+ readMcpConfig(configDir)
264583
264696
  ]);
264584
- return { entities, agents, mcpConfig, agentSkills };
264697
+ return { entities, agents, mcpConfig };
264585
264698
  }
264586
264699
  async function collectArtifacts(target) {
264587
264700
  const built = await resolveFullStackBuild(target.root);
@@ -275100,4 +275213,4 @@ export {
275100
275213
  runCLI
275101
275214
  };
275102
275215
 
275103
- //# debugId=2490C9565A93147064756E2164756E21
275216
+ //# debugId=CB629F837A2727B764756E2164756E21