@base44-preview/cli 0.3.2-pr.699.00cdc4d → 0.3.3-pr.700.e2948cc

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
@@ -228845,13 +228845,19 @@ function findEnvDir(cwd) {
228845
228845
  const configDir = dirname3(found.configPath);
228846
228846
  return basename(configDir) === PROJECT_SUBDIR ? dirname3(configDir) : configDir;
228847
228847
  }
228848
+ var accessTokenFromEnvFile = false;
228849
+ function isAccessTokenFromEnvFile() {
228850
+ return accessTokenFromEnvFile;
228851
+ }
228848
228852
  function loadProjectEnvFiles(cwd = process.cwd()) {
228849
228853
  const root = findEnvDir(cwd);
228854
+ const ambientAccessToken = process.env.BASE44_ACCESS_TOKEN ?? process.env[`${STRIPE_ENV_PREFIX}BASE44_ACCESS_TOKEN`];
228850
228855
  import_dotenv.config({
228851
228856
  path: [join(root, ".env.local"), join(root, ".env")],
228852
228857
  quiet: true
228853
228858
  });
228854
228859
  normalizeBase44Env();
228860
+ accessTokenFromEnvFile = ambientAccessToken === undefined && process.env.BASE44_ACCESS_TOKEN !== undefined;
228855
228861
  }
228856
228862
  function normalizeBase44Env() {
228857
228863
  for (const bareKey of BASE44_ENV_KEYS) {
@@ -230864,6 +230870,7 @@ function getTestOverrides() {
230864
230870
  var TOKEN_REFRESH_BUFFER_MS = 60 * 1000;
230865
230871
  var WORKSPACE_API_KEY_PREFIX = "b44k_";
230866
230872
  var refreshPromise = null;
230873
+ var envAccessTokenAuth = null;
230867
230874
  function getWorkspaceApiKeyFromEnv() {
230868
230875
  const key = process.env.BASE44_API_KEY?.trim();
230869
230876
  return key ? key : null;
@@ -230885,7 +230892,20 @@ async function seedAuthFromEnv() {
230885
230892
  const payload = claims !== null && typeof claims === "object" ? claims : null;
230886
230893
  const sub = typeof payload?.sub === "string" ? payload.sub : undefined;
230887
230894
  const exp = typeof payload?.exp === "number" ? payload.exp : undefined;
230888
- if (!refreshToken || !sub || !exp) {
230895
+ if (!sub || !exp) {
230896
+ return;
230897
+ }
230898
+ if (!refreshToken) {
230899
+ if (isAccessTokenFromEnvFile()) {
230900
+ return;
230901
+ }
230902
+ envAccessTokenAuth = {
230903
+ accessToken,
230904
+ refreshToken: "",
230905
+ expiresAt: exp * 1000,
230906
+ email: sub,
230907
+ name: sub
230908
+ };
230889
230909
  return;
230890
230910
  }
230891
230911
  await writeAuth({
@@ -230897,6 +230917,9 @@ async function seedAuthFromEnv() {
230897
230917
  });
230898
230918
  }
230899
230919
  async function readAuth() {
230920
+ if (envAccessTokenAuth) {
230921
+ return envAccessTokenAuth;
230922
+ }
230900
230923
  try {
230901
230924
  const authData = await readJsonFile(getAuthFilePath());
230902
230925
  const result = AuthDataSchema.safeParse(authData);
@@ -230933,6 +230956,9 @@ function isTokenExpired(auth) {
230933
230956
  return Date.now() >= auth.expiresAt - TOKEN_REFRESH_BUFFER_MS;
230934
230957
  }
230935
230958
  async function refreshAndSaveTokens() {
230959
+ if (envAccessTokenAuth) {
230960
+ return null;
230961
+ }
230936
230962
  if (refreshPromise) {
230937
230963
  return refreshPromise;
230938
230964
  }
@@ -237180,7 +237206,7 @@ var SKILL_NAME_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
237180
237206
  var AgentSkillSchema = object({
237181
237207
  name: string2().trim().min(1).max(64).regex(SKILL_NAME_REGEX, "Skill name must be lowercase-hyphenated (a-z, 0-9, -)"),
237182
237208
  description: string2().trim().min(1, "Description is required").max(1024),
237183
- body: string2().trim().min(1, "Body is required").max(15000)
237209
+ body: string2().trim().min(1, "Body is required").max(50000)
237184
237210
  });
237185
237211
  var AgentSkillApiResponseSchema = object({
237186
237212
  name: string2(),
@@ -239420,7 +239446,7 @@ import { join as join13 } from "node:path";
239420
239446
  // package.json
239421
239447
  var package_default = {
239422
239448
  name: "base44",
239423
- version: "0.3.2",
239449
+ version: "0.3.3",
239424
239450
  description: "Base44 CLI - Unified interface for managing Base44 applications",
239425
239451
  type: "module",
239426
239452
  bin: {
@@ -247073,6 +247099,7 @@ async function resolveBuildTarget(projectRoot, overrides = {}) {
247073
247099
  outputDir: resolve6(root, overrides.outputDir ?? site.outputDirectory ?? DEFAULT_SITE.outputDirectory),
247074
247100
  entitiesDir: project?.entitiesDir ?? "entities",
247075
247101
  agentsDir: project?.agentsDir ?? "agents",
247102
+ agentSkillsDir: project?.agentSkillsDir ?? "agent-skills",
247076
247103
  functionsDir: project?.functionsDir ?? "functions",
247077
247104
  actorsDir: project?.actorsDir ?? "actors"
247078
247105
  };
@@ -252878,6 +252905,7 @@ async function createVersion(artifacts, options = {}) {
252878
252905
  entities: artifacts.entities,
252879
252906
  agents: artifacts.agents,
252880
252907
  mcp_config: artifacts.mcpConfig,
252908
+ agent_skills: artifacts.agentSkills,
252881
252909
  source_commit: options.sourceCommit
252882
252910
  }, "declaring a version")).json(), "declare");
252883
252911
  const declaredFiles = [
@@ -255438,6 +255466,7 @@ var deno2 = Object.freeze({
255438
255466
  });
255439
255467
  globalThis.Deno = deno2;
255440
255468
  globalThis.Buffer = Buffer2;
255469
+ if (typeof process !== "undefined") process.version = "v22.23.4";
255441
255470
  try {
255442
255471
  new AsyncLocalStorage().enterWith(void 0);
255443
255472
  } catch {
@@ -256813,35 +256842,41 @@ var Actor = class _Actor extends Server {
256813
256842
  }
256814
256843
  handleWake(_key) {
256815
256844
  }
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) {
256845
+ static parseRequestIdentity(value) {
256846
+ if (value === '{"type":"service"}') return Object.freeze({ type: "service" });
256847
+ return _Actor.parseIdentity(value);
256820
256848
  }
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) {
256849
+ // Called by the generated wrapper for a verified POST .../requests; never user-facing.
256850
+ async _b44ActorRequest(request) {
256826
256851
  const room = request.headers.get("x-partykit-room");
256827
256852
  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();
256853
+ if (typeof this.handleRequest !== "function") {
256854
+ return new Response("This actor does not accept requests", { status: 404 });
256855
+ }
256856
+ const identity = _Actor.parseRequestIdentity(request.headers.get(_Actor.IDENTITY_HEADER));
256857
+ if (!identity) return new Response("Unauthorized", { status: 401 });
256858
+ const forHandler = new Request(
256859
+ \`https://actor.base44/rooms/\${encodeURIComponent(this.name)}/requests\`,
256860
+ {
256861
+ method: "POST",
256862
+ headers: { "Content-Type": request.headers.get("Content-Type") ?? "application/json" },
256863
+ body: await request.arrayBuffer()
256864
+ }
256865
+ );
256866
+ let response;
256867
+ try {
256868
+ response = await this.handleRequest(forHandler, { identity });
256869
+ } catch (err) {
256870
+ console.error("Actor.handleRequest threw:", err);
256871
+ response = new Response("Actor request failed", { status: 500 });
256872
+ }
256844
256873
  await this.maintainTicker();
256874
+ if (response === void 0) return new Response(null, { status: 204 });
256875
+ if (!(response instanceof Response)) {
256876
+ console.error("Actor.handleRequest must return a Response or nothing");
256877
+ return new Response("Actor request failed", { status: 500 });
256878
+ }
256879
+ return response;
256845
256880
  }
256846
256881
  async schedule(key, at) {
256847
256882
  const when = typeof at === "number" ? at : at.getTime();
@@ -259082,12 +259117,11 @@ function buildActorAuth() {
259082
259117
  return `// Auto-generated by the base44 bundler. Do not edit.
259083
259118
  const TOKEN_HEADER = "X-Base44-Actor-Token";
259084
259119
  const IDENTITY_HEADER = "X-Base44-Actor-Identity";
259085
- const EVENT_TOKEN_HEADER = "X-Base44-Actor-Event-Token";
259120
+ const REQUEST_TOKEN_HEADER = "X-Base44-Actor-Request-Token";
259086
259121
  const CLOCK_SKEW_SECONDS = 30;
259087
259122
  const TOKEN_TTL_SECONDS = 300;
259088
- const EVENT_TOKEN_TTL_SECONDS = 60;
259089
- const EVENT_MAX_BYTES = 64 * 1024;
259090
- const EVENT_TYPE_PREFIX = "__";
259123
+ const REQUEST_TOKEN_TTL_SECONDS = 60;
259124
+ const REQUEST_MAX_BYTES = 64 * 1024;
259091
259125
 
259092
259126
  const decodeSegment = (segment) => {
259093
259127
  const normalized = segment.replace(/-/g, "+").replace(/_/g, "/");
@@ -259197,11 +259231,21 @@ export function authorizedActorRequest(request, identity, actorName, room, runti
259197
259231
  return new Request(new Request(url.toString(), request), { headers });
259198
259232
  }
259199
259233
 
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) {
259234
+ const validRequestPrincipal = (principal) =>
259235
+ validPrincipal(principal) ||
259236
+ (principal !== null && typeof principal === "object" && principal.type === "service" && Object.keys(principal).length === 1);
259237
+
259238
+ const sha256 = async (bytes) => {
259239
+ const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
259240
+ return btoa(String.fromCharCode(...digest)).replace(/\\+/g, "-").replace(/\\//g, "_").replace(/=+$/, "");
259241
+ };
259242
+
259243
+ // A request the backend relays into one room for a caller it authenticated. Same
259244
+ // key as connection tokens, its own audience and purpose: neither is accepted as
259245
+ // the other. The token is bound to the body, so a leaked token can't carry another.
259246
+ // 401 is a token this key did not mint or that has lapsed; 403 is a good token for
259247
+ // another app, actor, script, room or runtime.
259248
+ export async function verifyActorRequest(request, env, actorName, room) {
259205
259249
  const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
259206
259250
  const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
259207
259251
  if (
@@ -259209,60 +259253,56 @@ export async function verifyActorEvent(request, env, actorName, room) {
259209
259253
  typeof scriptId !== "string" || !scriptId
259210
259254
  ) return unauthorized();
259211
259255
  try {
259212
- const claims = await verifiedClaims(request.headers.get(EVENT_TOKEN_HEADER), publicKey);
259256
+ const claims = await verifiedClaims(request.headers.get(REQUEST_TOKEN_HEADER), publicKey);
259213
259257
  if (!claims) return unauthorized();
259214
259258
  const now = Math.floor(Date.now() / 1000);
259215
259259
  if (
259216
259260
  claims.iss !== "base44" ||
259217
- claims.aud !== "base44-actor-event" ||
259218
- claims.purpose !== "actor-platform-event" ||
259261
+ claims.aud !== "base44-actor-request" ||
259262
+ claims.purpose !== "actor-request" ||
259219
259263
  claims.v !== 1 ||
259220
259264
  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
259265
+ !validTimes(claims, now, REQUEST_TOKEN_TTL_SECONDS) ||
259266
+ typeof claims.body_sha256 !== "string" ||
259267
+ !validRequestPrincipal(claims.principal)
259223
259268
  ) return unauthorized();
259224
259269
  if (
259225
259270
  claims.app_id !== env.BASE44_APP_ID ||
259226
259271
  claims.actor_name !== actorName ||
259227
259272
  claims.actor_script_id !== scriptId ||
259228
- claims.room !== room
259273
+ claims.room !== room ||
259274
+ claims.runtime_mode !== (env.BASE44_FUNCTIONS_VERSION === "prod" ? "prod" : "preview")
259229
259275
  ) return refused(403, "Forbidden");
259230
- return { ok: true, eventId: claims.event_id };
259276
+
259277
+ const body = new Uint8Array(await request.arrayBuffer());
259278
+ if (body.length > REQUEST_MAX_BYTES) return refused(413, "Request too large");
259279
+ if (await sha256(body) !== claims.body_sha256) return unauthorized();
259280
+ return {
259281
+ ok: true,
259282
+ identity: Object.freeze({ ...claims.principal }),
259283
+ runtimeMode: claims.runtime_mode,
259284
+ body,
259285
+ };
259231
259286
  } catch {
259232
259287
  return unauthorized();
259233
259288
  }
259234
259289
  }
259235
259290
 
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
259291
+ // Into the room as POST /parties/<actor>/<room>/requests: a path no client route
259253
259292
  // 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) {
259293
+ // the path), so the Durable Object can trust the shape and its identity header.
259294
+ export function actorRequestToRoom(request, actorName, room, verified) {
259256
259295
  const url = new URL(request.url);
259257
259296
  url.search = "";
259258
- url.pathname = "/parties/" + encodeURIComponent(actorName) + "/" + encodeURIComponent(room) + "/events";
259297
+ url.pathname = "/parties/" + encodeURIComponent(actorName) + "/" + encodeURIComponent(room) + "/requests";
259259
259298
  return new Request(url.toString(), {
259260
259299
  method: "POST",
259261
259300
  headers: {
259262
- "Content-Type": "application/json",
259263
- "base44-functions-version": env.BASE44_FUNCTIONS_VERSION === "prod" ? "prod" : "preview",
259301
+ "Content-Type": request.headers.get("Content-Type") ?? "application/json",
259302
+ [IDENTITY_HEADER]: JSON.stringify(verified.identity),
259303
+ "base44-functions-version": verified.runtimeMode,
259264
259304
  },
259265
- body: JSON.stringify(event),
259305
+ body: verified.body,
259266
259306
  });
259267
259307
  }
259268
259308
  `;
@@ -259286,11 +259326,10 @@ import "./${ACTOR_PRELUDE_FILENAME}";
259286
259326
  import Base44UserActor from ${JSON.stringify(userImport)};
259287
259327
  import { runWithWorkerEnvironment as _b44Run } from ${JSON.stringify(RUNTIME_CONTEXT_SPECIFIER)};
259288
259328
  import {
259329
+ actorRequestToRoom as _b44ActorRequestToRoom,
259289
259330
  authorizedActorRequest as _b44AuthorizedActorRequest,
259290
- platformEventRequest as _b44PlatformEventRequest,
259291
- readPlatformEvent as _b44ReadPlatformEvent,
259292
259331
  verifyActorConnection as _b44VerifyActorConnection,
259293
- verifyActorEvent as _b44VerifyActorEvent,
259332
+ verifyActorRequest as _b44VerifyActorRequest,
259294
259333
  } from "./${ACTOR_AUTH_FILENAME}";
259295
259334
 
259296
259335
  const _b44ActorState = new WeakMap();
@@ -259321,10 +259360,10 @@ const _b44RunActor = (actor, request, callback) => {
259321
259360
  state.runtimeEnv = runtimeEnv;
259322
259361
  return _b44RunWithActorEnvironment(state.ctx, state.env, runtimeEnv, callback);
259323
259362
  };
259324
- const _b44IsPlatformEvent = (request) => {
259363
+ const _b44IsActorRequest = (request) => {
259325
259364
  if (request.method !== "POST") return false;
259326
259365
  const parts = new URL(request.url).pathname.split("/");
259327
- return parts.length === 5 && parts[1] === "parties" && parts[4] === "events";
259366
+ return parts.length === 5 && parts[1] === "parties" && parts[4] === "requests";
259328
259367
  };
259329
259368
 
259330
259369
  export class ${doClassName} extends Base44UserActor {
@@ -259338,10 +259377,10 @@ export class ${doClassName} extends Base44UserActor {
259338
259377
  }
259339
259378
 
259340
259379
  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));
259380
+ // Ahead of the user's own fetch override: a relayed request reaches the room
259381
+ // only through the shim, which hands handleRequest the verified identity.
259382
+ if (_b44IsActorRequest(request)) {
259383
+ return _b44RunActor(this, request, () => this._b44ActorRequest(request));
259345
259384
  }
259346
259385
  return _b44RunActor(this, request, () => super.fetch(request));
259347
259386
  }
@@ -259376,8 +259415,8 @@ export default {
259376
259415
  const parts = url.pathname.split("/");
259377
259416
  const direct = parts[1] === "rooms" && parts.length === 3;
259378
259417
  const legacy = parts[1] === "parties" && parts.length === 4;
259379
- const event = request.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "events";
259380
- if (direct || legacy || event) {
259418
+ const relayed = request.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "requests";
259419
+ if (direct || legacy || relayed) {
259381
259420
  // Decode the room: the token was verified against the decoded instance id,
259382
259421
  // so an escaped room must map to the same Durable Object.
259383
259422
  const namespace = legacy ? parts[2] : "${doClassName}";
@@ -259385,12 +259424,10 @@ export default {
259385
259424
  let room;
259386
259425
  try { room = decodeURIComponent(encodedRoom); } catch { return new Response("Invalid room", { status: 400 }); }
259387
259426
  let actorRequest = request;
259388
- if (event) {
259389
- const verification = await _b44VerifyActorEvent(request, env, "${doClassName}", room);
259427
+ if (relayed) {
259428
+ const verification = await _b44VerifyActorRequest(request, env, "${doClassName}", room);
259390
259429
  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);
259430
+ actorRequest = _b44ActorRequestToRoom(request, "${doClassName}", room, verification);
259394
259431
  } else if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259395
259432
  const verification = await _b44VerifyActorConnection(request, env, "${doClassName}", room);
259396
259433
  if (!verification.ok) return verification.response;
@@ -264688,13 +264725,29 @@ async function readMcpConfig(configDir) {
264688
264725
  const path = join30(configDir, "mcp", "config.json");
264689
264726
  return await pathExists(path) ? await readTextFile(path) : "";
264690
264727
  }
264728
+ async function readAgentSkillFiles(dir) {
264729
+ if (!await pathExists(dir)) {
264730
+ return {};
264731
+ }
264732
+ const files = await globby("*.md", {
264733
+ cwd: dir,
264734
+ onlyFiles: true,
264735
+ followSymbolicLinks: false
264736
+ });
264737
+ const skills = {};
264738
+ for (const file of files.sort()) {
264739
+ skills[file.replace(/\.md$/, "")] = await readTextFile(join30(dir, file));
264740
+ }
264741
+ return skills;
264742
+ }
264691
264743
  async function collectResources(configDir, dirs) {
264692
- const [entities, agents, mcpConfig] = await Promise.all([
264744
+ const [entities, agents, mcpConfig, agentSkills] = await Promise.all([
264693
264745
  readRawResources(join30(configDir, dirs.entitiesDir)),
264694
264746
  readRawResources(join30(configDir, dirs.agentsDir)),
264695
- readMcpConfig(configDir)
264747
+ readMcpConfig(configDir),
264748
+ readAgentSkillFiles(join30(configDir, dirs.agentSkillsDir))
264696
264749
  ]);
264697
- return { entities, agents, mcpConfig };
264750
+ return { entities, agents, mcpConfig, agentSkills };
264698
264751
  }
264699
264752
  async function collectArtifacts(target) {
264700
264753
  const built = await resolveFullStackBuild(target.root);
@@ -275213,4 +275266,4 @@ export {
275213
275266
  runCLI
275214
275267
  };
275215
275268
 
275216
- //# debugId=CB629F837A2727B764756E2164756E21
275269
+ //# debugId=B98A0F7103A0C01B64756E2164756E21