agentful 0.4.20 → 0.4.21

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.
Files changed (2) hide show
  1. package/dist/index.cjs +60 -7
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -3044,7 +3044,7 @@ var VERSION, brand, useColor, wrap, paint, tuiDesign, sym, ui;
3044
3044
  var init_branding = __esm({
3045
3045
  "src/branding.ts"() {
3046
3046
  "use strict";
3047
- VERSION = "0.4.20" ? "0.4.20" : null.version;
3047
+ VERSION = "0.4.21" ? "0.4.21" : null.version;
3048
3048
  brand = {
3049
3049
  name: "agentful",
3050
3050
  // the command users type
@@ -7966,15 +7966,68 @@ async function backendCommand() {
7966
7966
 
7967
7967
  // src/commands/open.ts
7968
7968
  init_branding();
7969
+
7970
+ // src/lib/previewOpen.ts
7971
+ var PREVIEW_PROJECT_ID = /^[a-z0-9]{10,20}$/i;
7972
+ function isPreviewProjectId(projectId) {
7973
+ return typeof projectId === "string" && PREVIEW_PROJECT_ID.test(projectId);
7974
+ }
7975
+ function assertProjectId(projectId) {
7976
+ if (!isPreviewProjectId(projectId)) {
7977
+ throw new ApiError(
7978
+ 0,
7979
+ "invalid_project_id",
7980
+ `"${projectId}" is not a valid project id \u2014 check .agentful/project.json or run \`agentful init\`.`
7981
+ );
7982
+ }
7983
+ }
7984
+ function previewAddress(projectId) {
7985
+ assertProjectId(projectId);
7986
+ return `https://preview-${projectId}.${PREVIEW_DOMAIN}/`;
7987
+ }
7988
+ function appPreviewRoute(projectId) {
7989
+ assertProjectId(projectId);
7990
+ return `${APP_URL}/preview/${projectId}`;
7991
+ }
7992
+ function withPreviewTicket(address, ticket) {
7993
+ const url = new URL(address);
7994
+ url.searchParams.set("ticket", ticket);
7995
+ return url.toString();
7996
+ }
7997
+ async function fetchPreviewTicket(auth, projectId) {
7998
+ assertProjectId(projectId);
7999
+ const body = await request(
8000
+ `${PUBLIC_API_URL}/api/workspaces/${encodeURIComponent(auth.user_id)}/${projectId}/preview-ticket`,
8001
+ { method: "POST", token: auth.pb_token, timeoutMs: 15e3 }
8002
+ );
8003
+ if (typeof body.ticket !== "string" || !body.ticket) {
8004
+ throw new ApiError(0, "preview_ticket_missing", "The workspace API returned no preview ticket.");
8005
+ }
8006
+ return body.ticket;
8007
+ }
8008
+ async function previewOpenTarget(auth, projectId) {
8009
+ const address = previewAddress(projectId);
8010
+ try {
8011
+ const ticket = await fetchPreviewTicket(auth, projectId);
8012
+ return { url: withPreviewTicket(address, ticket), shown: address };
8013
+ } catch (err2) {
8014
+ if (err2 instanceof ApiError && [401, 403, 404].includes(err2.status)) throw err2;
8015
+ const route = appPreviewRoute(projectId);
8016
+ const reason = err2 instanceof Error ? err2.message : String(err2);
8017
+ return { url: route, shown: route, warning: `Could not get a preview ticket (${reason}); opening it through the app instead.` };
8018
+ }
8019
+ }
8020
+
8021
+ // src/commands/open.ts
7969
8022
  async function openCommand() {
7970
8023
  const project = requireProject();
7971
8024
  const auth = await ensureAuth();
7972
- const url = `https://preview-${project.projectId}.${PREVIEW_DOMAIN}/?token=${encodeURIComponent(auth.pb_token)}`;
7973
- const shown = `https://preview-${project.projectId}.${PREVIEW_DOMAIN}/`;
7974
- ui.step(`Opening ${ui.url(shown)}`);
7975
- if (!openInBrowser(url)) {
7976
- ui.info(`Could not launch a browser \u2014 open this URL manually:`);
7977
- ui.info(ui.url(url));
8025
+ const target = await previewOpenTarget(auth, project.projectId);
8026
+ if (target.warning) ui.warn(target.warning);
8027
+ ui.step(`Opening ${ui.url(target.shown)}`);
8028
+ if (!openInBrowser(target.url)) {
8029
+ ui.info("Could not launch a browser \u2014 open this address and sign in to Agentful there if asked:");
8030
+ ui.info(ui.url(appPreviewRoute(project.projectId)));
7978
8031
  }
7979
8032
  }
7980
8033
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentful",
3
- "version": "0.4.20",
3
+ "version": "0.4.21",
4
4
  "description": "Agentful in your terminal — local development with push-to-cloud previews",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://agentful.dev",