agentful 0.3.7 → 0.3.8

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 +47 -19
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -3044,7 +3044,7 @@ var VERSION, brand, useColor, wrap, paint, sym, ui;
3044
3044
  var init_branding = __esm({
3045
3045
  "src/branding.ts"() {
3046
3046
  "use strict";
3047
- VERSION = "0.3.7" ? "0.3.7" : null.version;
3047
+ VERSION = "0.3.8" ? "0.3.8" : null.version;
3048
3048
  brand = {
3049
3049
  name: "agentful",
3050
3050
  // the command users type
@@ -8084,28 +8084,47 @@ async function shareCommand(opts) {
8084
8084
  }
8085
8085
 
8086
8086
  // src/commands/pull.ts
8087
- var import_node_fs18 = require("fs");
8088
- var import_node_path21 = require("path");
8087
+ var import_node_fs19 = require("fs");
8088
+ var import_node_path22 = require("path");
8089
8089
  init_branding();
8090
8090
  init_branding();
8091
- function isProbablyBase64Binary(path) {
8092
- return /\.(png|jpe?g|gif|webp|ico|woff2?|ttf|otf|eot|pdf|zip|mp[34]|webm|avif)$/i.test(path);
8091
+
8092
+ // src/lib/pullFiles.ts
8093
+ var import_node_fs18 = require("fs");
8094
+ var import_node_path21 = require("path");
8095
+ var INLINE_BASE64_EXTENSIONS = /\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?|woff2?|ttf|otf|eot|pdf|docx?|xlsx?|pptx?|zip|tar|gz|7z|rar|bz2|mp[34]|m4a|wav|ogg|avi|mov|mkv|flac|webm|exe|dll|so|dylib|bin|wasm)$/i;
8096
+ function inlineContent(value) {
8097
+ return typeof value === "object" && value !== null && "content" in value ? String(value.content) : String(value ?? "");
8093
8098
  }
8094
- function writeEntry(root, rel, value) {
8099
+ function writePulledWorkspaceEntry(root, rel, value) {
8095
8100
  const target = (0, import_node_path21.join)(root, rel);
8096
8101
  (0, import_node_fs18.mkdirSync)((0, import_node_path21.dirname)(target), { recursive: true });
8097
- const content = typeof value === "object" && value !== null && "content" in value ? String(value.content) : String(value ?? "");
8098
- if (isProbablyBase64Binary(rel)) {
8102
+ const content = inlineContent(value);
8103
+ if (INLINE_BASE64_EXTENSIONS.test(rel)) {
8099
8104
  (0, import_node_fs18.writeFileSync)(target, Buffer.from(content, "base64"));
8100
- } else {
8101
- (0, import_node_fs18.writeFileSync)(target, content, "utf8");
8105
+ return;
8102
8106
  }
8107
+ (0, import_node_fs18.writeFileSync)(target, content, "utf8");
8103
8108
  }
8109
+ function writePulledBackendDeclaration(root, declaration) {
8110
+ const target = (0, import_node_path21.join)(root, ".agentful", "backend.json");
8111
+ (0, import_node_fs18.mkdirSync)((0, import_node_path21.dirname)(target), { recursive: true });
8112
+ const {
8113
+ source: _source,
8114
+ received_at: _receivedAt,
8115
+ last_sync: _lastSync,
8116
+ ...portableDeclaration
8117
+ } = declaration;
8118
+ (0, import_node_fs18.writeFileSync)(target, `${JSON.stringify(portableDeclaration, null, 2)}
8119
+ `, "utf8");
8120
+ }
8121
+
8122
+ // src/commands/pull.ts
8104
8123
  async function pullCommand(opts) {
8105
8124
  console.log(banner());
8106
8125
  const auth = await ensureAuth();
8107
8126
  const project = requireProject();
8108
- const nonHidden = (0, import_node_fs18.readdirSync)(process.cwd()).filter((n) => n !== ".agentful" && !n.startsWith("."));
8127
+ const nonHidden = (0, import_node_fs19.readdirSync)(process.cwd()).filter((n) => n !== ".agentful" && !n.startsWith("."));
8109
8128
  if (nonHidden.length > 0 && !opts.force) {
8110
8129
  throw new ApiError(
8111
8130
  0,
@@ -8114,10 +8133,13 @@ async function pullCommand(opts) {
8114
8133
  );
8115
8134
  }
8116
8135
  ui.step("Fetching workspace\u2026");
8117
- const data = await request(
8118
- `${PB_URL}/api/workspaces/${project.userId}/${project.projectId}`,
8119
- { token: auth.pb_token, timeoutMs: 12e4 }
8120
- );
8136
+ const [data, backendState] = await Promise.all([
8137
+ request(
8138
+ `${PB_URL}/api/workspaces/${project.userId}/${project.projectId}`,
8139
+ { token: auth.pb_token, timeoutMs: 12e4 }
8140
+ ),
8141
+ fetchBackendSessionState(auth, project.userId, project.projectId)
8142
+ ]);
8121
8143
  let written = 0;
8122
8144
  if (data.mode === "presigned" && data.urls) {
8123
8145
  for (const [rel, url] of Object.entries(data.urls)) {
@@ -8129,20 +8151,26 @@ async function pullCommand(opts) {
8129
8151
  ui.warn(`Skipped ${rel} (HTTP ${resp.status})`);
8130
8152
  continue;
8131
8153
  }
8132
- const target = (0, import_node_path21.join)(process.cwd(), rel);
8133
- (0, import_node_fs18.mkdirSync)((0, import_node_path21.dirname)(target), { recursive: true });
8134
- (0, import_node_fs18.writeFileSync)(target, Buffer.from(await resp.arrayBuffer()));
8154
+ const target = (0, import_node_path22.join)(process.cwd(), rel);
8155
+ (0, import_node_fs19.mkdirSync)((0, import_node_path22.dirname)(target), { recursive: true });
8156
+ (0, import_node_fs19.writeFileSync)(target, Buffer.from(await resp.arrayBuffer()));
8135
8157
  written++;
8136
8158
  }
8137
8159
  } else if (data.files) {
8138
8160
  for (const [rel, value] of Object.entries(data.files)) {
8139
- writeEntry(process.cwd(), rel, value);
8161
+ writePulledWorkspaceEntry(process.cwd(), rel, value);
8140
8162
  written++;
8141
8163
  }
8142
8164
  } else {
8143
8165
  throw new ApiError(0, "empty_workspace", "The cloud workspace has no files yet.");
8144
8166
  }
8145
8167
  ui.ok(`Pulled ${written} files from the cloud workspace.`);
8168
+ if (backendState?.declaration) {
8169
+ writePulledBackendDeclaration(process.cwd(), backendState.declaration);
8170
+ ui.ok("Restored .agentful/backend.json from the platform declaration.");
8171
+ } else if (backendState === null) {
8172
+ ui.warn("Could not read the platform backend declaration; .agentful/backend.json was not restored.");
8173
+ }
8146
8174
  }
8147
8175
 
8148
8176
  // THIRD-PARTY-LICENSES.txt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentful",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
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",