Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
chore: ai editing fixes (#4525)
Wolf Mermelstein20a92f0e69bd
diff --git a/docker-compose.yml b/docker-compose.ymlindex 6c4e853736..a268978512 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -397,7 +397,7 @@ services:- ./rust/sync-service/src:/app/srcenvironment:- INTERNAL_API_SECRET_KEY=${INTERNAL_API_SECRET_KEY}- - DOCUMENT_PERMISSIONS_SECRET=${DOCUMENT_PERMISSION_JWT_SECRET_KEY}+ - DOCUMENT_PERMISSIONS_SECRET=${DOCUMENT_PERMISSION_JWT}networks:services:aliases:diff --git a/js/ai-editing-worker/bun.lock b/js/ai-editing-worker/bun.lockindex 86cdedecae..7566d0b2b2 100644--- a/js/ai-editing-worker/bun.lock+++ b/js/ai-editing-worker/bun.lock@@ -11,9 +11,13 @@"@hono/zod-validator": "^0.8.0","ai": "^6.0.207","ai-fallback": "2",+ "bitf": "^1.0.2","envsafe": "^2.0.3",+ "flat": "^6.0.1","hono": "^4.6.20",+ "p-queue": "^9.3.0","quickjs-emscripten": "^0.31.0",+ "random-js": "^2.1.0","yargs": "^18.0.0","zod": "^4.4.3",},@@ -208,6 +212,8 @@"ansi-styles": ["[email protected]", "", {}, "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg=="],+ "bitf": ["[email protected]", "", {}, "sha512-l3PytekTpJOq4W8QmXQQtDRI29Fp3ds2F9SfK+RTc9rvfDk0RFtFRjTuVSpYOyh0qITJP6walQq9TkxjY7gAFw=="],+"blake3-wasm": ["[email protected]", "", {}, "sha512-F1+K8EbfOZE49dtoPtmxUQrpXaBIl3ICvasLh+nJta0xkz+9kF/7uet9fLnwKqhDrmj6g+6K3Tw9yQPUg2ka5g=="],"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-4N0ig0fEomHt5R0KCFWjovxow98rIoRwKolrYdCcknNwMekCXRnWEUvgu5soYV8QXtVsrUD8B95MBOZGPvr6KQ=="],@@ -228,8 +234,12 @@"escalade": ["[email protected]", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="],+ "eventemitter3": ["[email protected]", "", {}, "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw=="],+"eventsource-parser": ["[email protected]", "", {}, "sha512-kJezFj9YFAMLeORyi7aCLxLbD5/qWMQnoMVlVPyHIll7lgRJCc3JVln9Vgl9nwQi0YkMnhdGTMNn7CkRRAptMg=="],+ "flat": ["[email protected]", "", { "bin": { "flat": "cli.js" } }, "sha512-/3FfIa8mbrg3xE7+wAhWeV+bd7L2Mof+xtZb5dRDKZ+wDvYJK4WDYeIOuOhre5Yv5aQObZrlbRmk3RTSiuQBtw=="],+"fsevents": ["[email protected]", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="],"get-caller-file": ["[email protected]", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="],@@ -244,6 +254,10 @@"miniflare": ["[email protected]", "", { "dependencies": { "@cspotcode/source-map-support": "0.8.1", "sharp": "0.34.5", "undici": "7.28.0", "workerd": "1.20260617.1", "ws": "8.21.0", "youch": "4.1.0-beta.10" }, "bin": { "miniflare": "bootstrap.js" } }, "sha512-Go3/gzStm99QHptsSgU+q1S+xDfLoRgwjJNY80kaTVi0ENhTyqKq+sc4xZiWBSbM7uUcJwmzm8+QFKtcYLJ9nw=="],+ "p-queue": ["[email protected]", "", { "dependencies": { "eventemitter3": "^5.0.4", "p-timeout": "^7.0.0" } }, "sha512-POWdiIPmsUPGwb4FeQ4OBg46aqmcInSWe45CKDsGHiOBiVQM9chqfQTuqhuTzcg2Vz9faTI65at0KkVyVEiCHw=="],++ "p-timeout": ["[email protected]", "", {}, "sha512-AxTM2wDGORHGEkPCt8yqxOTMgpfbEHqF51f/5fJCmwFC3C/zNcGT63SymH2ttOAaiIws2zVg4+izQCjrakcwHg=="],+"path-to-regexp": ["[email protected]", "", {}, "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ=="],"pathe": ["[email protected]", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="],@@ -252,6 +266,8 @@"quickjs-emscripten-core": ["[email protected]", "", { "dependencies": { "@jitl/quickjs-ffi-types": "0.31.0" } }, "sha512-oQz8p0SiKDBc1TC7ZBK2fr0GoSHZKA0jZIeXxsnCyCs4y32FStzCW4d1h6E1sE0uHDMbGITbk2zhNaytaoJwXQ=="],+ "random-js": ["[email protected]", "", {}, "sha512-CRUyWmnzmZBA7RZSVGq0xMqmgCyPPxbiKNLFA5ud7KenojVX2s7Gv+V7eB52beKTPGxWRnVZ7D/tCIgYJJ8vNQ=="],+"semver": ["[email protected]", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA=="],"sharp": ["[email protected]", "", { "dependencies": { "@img/colour": "^1.0.0", "detect-libc": "^2.1.2", "semver": "^7.7.3" }, "optionalDependencies": { "@img/sharp-darwin-arm64": "0.34.5", "@img/sharp-darwin-x64": "0.34.5", "@img/sharp-libvips-darwin-arm64": "1.2.4", "@img/sharp-libvips-darwin-x64": "1.2.4", "@img/sharp-libvips-linux-arm": "1.2.4", "@img/sharp-libvips-linux-arm64": "1.2.4", "@img/sharp-libvips-linux-ppc64": "1.2.4", "@img/sharp-libvips-linux-riscv64": "1.2.4", "@img/sharp-libvips-linux-s390x": "1.2.4", "@img/sharp-libvips-linux-x64": "1.2.4", "@img/sharp-libvips-linuxmusl-arm64": "1.2.4", "@img/sharp-libvips-linuxmusl-x64": "1.2.4", "@img/sharp-linux-arm": "0.34.5", "@img/sharp-linux-arm64": "0.34.5", "@img/sharp-linux-ppc64": "0.34.5", "@img/sharp-linux-riscv64": "0.34.5", "@img/sharp-linux-s390x": "0.34.5", "@img/sharp-linux-x64": "0.34.5", "@img/sharp-linuxmusl-arm64": "0.34.5", "@img/sharp-linuxmusl-x64": "0.34.5", "@img/sharp-wasm32": "0.34.5", "@img/sharp-win32-arm64": "0.34.5", "@img/sharp-win32-ia32": "0.34.5", "@img/sharp-win32-x64": "0.34.5" } }, "sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg=="],diff --git a/js/ai-editing-worker/package.json b/js/ai-editing-worker/package.jsonindex 9cdda0bc3c..6aa00186b1 100644--- a/js/ai-editing-worker/package.json+++ b/js/ai-editing-worker/package.json@@ -18,7 +18,11 @@"hono": "^4.6.20","quickjs-emscripten": "^0.31.0","yargs": "^18.0.0",- "zod": "^4.4.3"+ "zod": "^4.4.3",+ "bitf": "^1.0.2",+ "flat": "^6.0.1",+ "p-queue": "^9.3.0",+ "random-js": "^2.1.0"},"devDependencies": {"@types/node": "^25.9.3",diff --git a/js/ai-editing-worker/scripts/edit.ts b/js/ai-editing-worker/scripts/edit.tsindex dce5c8bee7..ed668212ef 100644--- a/js/ai-editing-worker/scripts/edit.ts+++ b/js/ai-editing-worker/scripts/edit.ts@@ -11,12 +11,14 @@ const {"coding-model": codingModelFlag,debug,out,+ prompt: promptFlag,"prompt-file": promptFile,- _,} = await yargs(hideBin(process.argv))- .usage("$0 [prompt] --ws-url <url>")+ .usage("$0 --prompt <text> --ws-url <url>").help()+ .strict().option("ws-url", { type: "string", demandOption: true, describe: "sync service ws url with token, e.g. wss://…/document/<id>/connect?token=<doc-token>" })+ .option("prompt", { type: "string", describe: "the edit instruction (or use --prompt-file)" }).option("port", { type: "number", default: 8933, describe: "worker port" }).option("worker-url", { type: "string", describe: "full worker base URL (overrides --port)" }).option("supervisor-model", { type: "string", demandOption: true, describe: "provider:model for the supervisor" })@@ -24,16 +26,17 @@ const {.option("coding-model", { type: "string", demandOption: true, describe: "provider:model for the coding agents" }).option("debug", { type: "boolean", default: false, describe: "include the supervisor step trace + replay trace in the response" }).option("out", { type: "string", describe: "write the replay trace JSON to this file (implies --debug)" })- .option("prompt-file", { type: "string", describe: "read the prompt from this file instead of the positional arg" })+ .option("prompt-file", { type: "string", describe: "read the prompt from this file instead of --prompt" })+ .check((argv) => {+ if (!argv.prompt && !argv["prompt-file"]) throw new Error("provide --prompt <text> or --prompt-file <path>");+ if (argv._.length > 0) throw new Error(`unexpected positional args: ${argv._.join(" ")} — everything is a flag (use --prompt)`);+ return true;+ }).parse();const prompt = promptFile? (await Bun.file(promptFile as string).text()).trim()- : (_[0] as string | undefined);-if (!prompt) {- console.error("Usage: bun run scripts/edit.ts [prompt] --ws-url <url> (or pass --prompt-file <path>)");- process.exit(1);-}+ : (promptFlag as string);const parsed = new URL(wsUrl as string);const pathParts = parsed.pathname.split("/");diff --git a/js/ai-editing-worker/wrangler.toml b/js/ai-editing-worker/wrangler.tomlindex 5f4c17ea95..dcd0aab623 100644--- a/js/ai-editing-worker/wrangler.toml+++ b/js/ai-editing-worker/wrangler.toml@@ -1,7 +1,7 @@name = "ai-editing-worker"main = "src/index.ts"compatibility_date = "2025-07-22"-compatibility_flags = ["nodejs_compat", "enable_request_signal"]+compatibility_flags = ["nodejs_compat", "enable_request_signal", "global_fetch_strictly_public"][alias]"loro-crdt" = "loro-crdt/bundler"diff --git a/rust/cloud-storage/ai_tools/src/build_context.rs b/rust/cloud-storage/ai_tools/src/build_context.rsindex 57fa258a2e..fabb7540ed 100644--- a/rust/cloud-storage/ai_tools/src/build_context.rs+++ b/rust/cloud-storage/ai_tools/src/build_context.rs@@ -56,7 +56,7 @@ env_var! {DocumentStorageServiceCloudfrontDistributionUrl,DocumentStorageServiceCloudfrontSignerPublicKeyId,DocumentStorageServiceCloudfrontSignerPrivateKeySecretName,- DocumentPermissionJwtSecretKey,+ DocumentPermissionJwt,}}@@ -262,7 +262,7 @@ pub async fn build_tool_service_context_from_env(lexical_client,sync_client.as_ref().clone(),ReqwestEditingWorkerClient::new(ai_editing_worker_url, Arc::new(reqwest::Client::new())),- env.document_permission_jwt_secret_key.to_string(),+ env.document_permission_jwt.to_string(),);let properties_tool_context =diff --git a/rust/cloud-storage/document_cognition_service/src/config.rs b/rust/cloud-storage/document_cognition_service/src/config.rsindex 8968360ece..6519225bd1 100644--- a/rust/cloud-storage/document_cognition_service/src/config.rs+++ b/rust/cloud-storage/document_cognition_service/src/config.rs@@ -20,7 +20,7 @@ env_vars!(pub struct DocumentStorageServiceCloudfrontSignerPublicKeyId;pub struct DocumentStorageServiceCloudfrontSignerPrivateKey;pub struct McpCredentialsKeySecretName;- pub struct DocumentPermissionJwtSecretKey;+ pub struct DocumentPermissionJwt;);maybe_env_vars!(@@ -70,7 +70,7 @@ pub struct Config {#[macro_config_default(AiEditingWorkerUrl::unwrap_new().to_string())]pub ai_editing_worker_url: String,/// JWT secret for minting document permission tokens for the editing worker.- pub document_permission_jwt_secret_key: DocumentPermissionJwtSecretKey,+ pub document_permission_jwt: DocumentPermissionJwt,}impl Config {@@ -118,9 +118,7 @@ impl Config {),internal_api_key: InternalApiKey::Comptime(""),ai_editing_worker_url: AiEditingWorkerUrl::unwrap_new().to_string(),- document_permission_jwt_secret_key: DocumentPermissionJwtSecretKey::Comptime(- "DOCUMENT_PERMISSION_JWT_SECRET_KEY",- ),+ document_permission_jwt: DocumentPermissionJwt::Comptime("DOCUMENT_PERMISSION_JWT"),}}}diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rsindex 03519798a7..827996c3ec 100644--- a/rust/cloud-storage/document_cognition_service/src/main.rs+++ b/rust/cloud-storage/document_cognition_service/src/main.rs@@ -294,10 +294,7 @@ async fn main() -> anyhow::Result<()> {config.ai_editing_worker_url.clone(),std::sync::Arc::new(reqwest::Client::new()),),- config- .document_permission_jwt_secret_key- .as_ref()- .to_string(),+ config.document_permission_jwt.as_ref().to_string(),);tracing::info!("initialized document tool context");diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/permissions_token/create_permission_token.rs b/rust/cloud-storage/document_storage_service/src/api/documents/permissions_token/create_permission_token.rsindex c3fcec5ed2..92ef88602c 100644--- a/rust/cloud-storage/document_storage_service/src/api/documents/permissions_token/create_permission_token.rs+++ b/rust/cloud-storage/document_storage_service/src/api/documents/permissions_token/create_permission_token.rs@@ -64,7 +64,7 @@ pub async fn handler(user_id,document_id,access_level,- state.config.document_permission_jwt_secret_key.as_ref(),+ state.config.document_permission_jwt.as_ref(),).map_err(|e| {tracing::error!(error=?e, "unable to encode jwt");diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/permissions_token/validate_permissions_token.rs b/rust/cloud-storage/document_storage_service/src/api/documents/permissions_token/validate_permissions_token.rsindex 4a722ffcee..eecd2d64f2 100644--- a/rust/cloud-storage/document_storage_service/src/api/documents/permissions_token/validate_permissions_token.rs+++ b/rust/cloud-storage/document_storage_service/src/api/documents/permissions_token/validate_permissions_token.rs@@ -54,12 +54,7 @@ pub async fn handler(// Attempt to decode the token.let decoded_jwt: DocumentPermissionsToken = match jsonwebtoken::decode::<DocumentPermissionsToken>(&token,- &DecodingKey::from_secret(- config_context- .document_permission_jwt_secret_key- .as_ref()- .as_bytes(),- ),+ &DecodingKey::from_secret(config_context.document_permission_jwt.as_ref().as_bytes()),&validation,) {Ok(decoded) => decoded.claims,diff --git a/rust/cloud-storage/document_storage_service/src/config.rs b/rust/cloud-storage/document_storage_service/src/config.rsindex 7c0e38b168..97f39bcbcf 100644--- a/rust/cloud-storage/document_storage_service/src/config.rs+++ b/rust/cloud-storage/document_storage_service/src/config.rs@@ -38,7 +38,7 @@ env_vars! {pub struct DocumentStorageServicePresignedUrlBrowserCacheExpirySeconds;pub struct DocumentStorageServiceCloudfrontSignerPrivateKey;#[derive(Clone)]- pub struct DocumentPermissionJwtSecretKey;+ pub struct DocumentPermissionJwt;pub struct GithubWebhookSecretKey;pub struct GithubSyncAppPemSecretKey;pub struct CalWebhookSecretKey;@@ -136,7 +136,7 @@ pub struct Config {pub document_storage_service_cloudfront_signer_private_key:LocalOrRemoteSecret<DocumentStorageServiceCloudfrontSignerPrivateKey>,- pub document_permission_jwt_secret_key: LocalOrRemoteSecret<DocumentPermissionJwtSecretKey>,+ pub document_permission_jwt: DocumentPermissionJwt,pub livekit_transcription_agent_name: LivekitTranscriptionAgentName,pub internal_call_secret: InternalCallSecret,diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rsindex 7837429970..e22f32e50d 100644--- a/rust/cloud-storage/document_storage_service/src/main.rs+++ b/rust/cloud-storage/document_storage_service/src/main.rs@@ -727,7 +727,7 @@ async fn main() -> anyhow::Result<()> {markdown_initializer,documents_hex::outbound::document_bytes_upload::ReqwestDocumentBytesUploader::default(),),- document_permission_jwt_secret: config.document_permission_jwt_secret_key.as_ref().to_string(),+ document_permission_jwt_secret: config.document_permission_jwt.as_ref().to_string(),},config: Arc::new(config),channels_state: ChannelsRouterState::from_arc(diff --git a/rust/cloud-storage/mcp_service/src/config.rs b/rust/cloud-storage/mcp_service/src/config.rsindex 50de2d26a0..9b0eb8dfa8 100644--- a/rust/cloud-storage/mcp_service/src/config.rs+++ b/rust/cloud-storage/mcp_service/src/config.rs@@ -49,7 +49,7 @@ env_vars! {/// links to Macro items in MCP responses.pub struct AppBaseUrl;/// JWT secret for minting document permission tokens for the editing worker.- pub struct DocumentPermissionJwtSecretKey;+ pub struct DocumentPermissionJwt;}/// The configuration parameters for the MCP server.@@ -86,7 +86,7 @@ pub struct Config {pub app_base_url: AppBaseUrl,/// The internal api keypub internal_api_key: InternalApiKey,- pub document_permission_jwt_secret_key: DocumentPermissionJwtSecretKey,+ pub document_permission_jwt: DocumentPermissionJwt,}impl Config {diff --git a/rust/cloud-storage/mcp_service/src/context.rs b/rust/cloud-storage/mcp_service/src/context.rsindex 3f07df28c3..eb19effe78 100644--- a/rust/cloud-storage/mcp_service/src/context.rs+++ b/rust/cloud-storage/mcp_service/src/context.rs@@ -233,7 +233,7 @@ async fn build_tool_context(lexical_client_for_tools,sync_service_client.clone(),ReqwestEditingWorkerClient::from_url(ai_editing_worker_url),- config.document_permission_jwt_secret_key.to_string(),+ config.document_permission_jwt.to_string(),);let properties_tool_context = ai_tools::build_properties_tool_context(properties_service);diff --git a/rust/cloud-storage/tools/xtask/src/local/local_env.rs b/rust/cloud-storage/tools/xtask/src/local/local_env.rsindex 64d6cc45df..79d2381778 100644--- a/rust/cloud-storage/tools/xtask/src/local/local_env.rs+++ b/rust/cloud-storage/tools/xtask/src/local/local_env.rs@@ -194,7 +194,10 @@ impl ServiceAuthEnv {ServiceAuthEnv {service_internal: identity::instance_secret("service-internal", name),dss_auth: identity::instance_secret("dss-auth", name),- doc_perm_jwt: identity::instance_secret("doc-perm-jwt", name),+ // Must match sync-service's local DOCUMENT_PERMISSIONS_SECRET+ // ("local") so locally-minted tokens verify. This is ONLY for local+ // dev use obv+ doc_perm_jwt: "local".to_string(),internal_call: identity::instance_secret("internal-call", name),url_signing: identity::instance_secret("url-signing", name),}@@ -222,10 +225,7 @@ impl ServiceAuthEnv {"DOCUMENT_STORAGE_SERVICE_AUTH_KEY".into(),self.dss_auth.clone(),);- env.insert(- "DOCUMENT_PERMISSION_JWT_SECRET_KEY".into(),- self.doc_perm_jwt.clone(),- );+ env.insert("DOCUMENT_PERMISSION_JWT".into(), self.doc_perm_jwt.clone());env.insert("INTERNAL_CALL_SECRET".into(), self.internal_call.clone());env.insert("URL_SIGNING_HMAC".into(), self.url_signing.clone());}