@agenticmail/enterprise 0.5.612 → 0.5.613

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 (27) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/{agent-heartbeat-PHLWJ3HO.js → agent-heartbeat-HFDBZWMO.js} +1 -1
  3. package/dist/{agent-tools-KRMDJOCK.js → agent-tools-5LLIXV6A.js} +17 -6
  4. package/dist/{chunk-NMMTMHTA.js → chunk-GC77MDKW.js} +37 -31
  5. package/dist/{chunk-BUKTZ35L.js → chunk-H3JXMBTG.js} +3 -6
  6. package/dist/{chunk-I2T4HESC.js → chunk-IXAWHXMY.js} +16 -16
  7. package/dist/{chunk-5EMB2S53.js → chunk-MVD2DMAY.js} +2 -2
  8. package/dist/{chunk-TBBVEXBH.js → chunk-QVZIW5HI.js} +14 -0
  9. package/dist/{chunk-REAJCMQE.js → chunk-T26AVIAQ.js} +3 -6
  10. package/dist/chunk-UETRFOSR.js +80 -0
  11. package/dist/{chunk-KQ5EU4IA.js → chunk-VWIDJRD4.js} +49 -32
  12. package/dist/{cli-agent-V7K6HZAG.js → cli-agent-AMA2R4PG.js} +18 -12
  13. package/dist/{cli-serve-T3W5RDO4.js → cli-serve-4NLB4RK2.js} +2 -2
  14. package/dist/cli.js +3 -3
  15. package/dist/{deployer-BKBISKKF.js → deployer-M4YHMATN.js} +2 -1
  16. package/dist/index.js +12 -11
  17. package/dist/meetings-SPK24WE7.js +1 -1
  18. package/dist/{routes-VX5CXX4J.js → routes-5PUCWC4N.js} +4 -3
  19. package/dist/{runtime-RMLNHLAT.js → runtime-GML2LXIN.js} +2 -1
  20. package/dist/{server-64K32C5T.js → server-R5SICPBI.js} +5 -4
  21. package/dist/{setup-7AQLYQBS.js → setup-SLLV37YT.js} +1 -1
  22. package/dist/{telegram-NG7PNNIN.js → telegram-W765VRI5.js} +1 -1
  23. package/dist/{whatsapp-RAQUV6ZL.js → whatsapp-TBOB7TDL.js} +1 -1
  24. package/dist/workspace-P5FCSG2D.js +19 -0
  25. package/package.json +1 -1
  26. /package/dist/{chunk-CC4BHZHO.js → chunk-GAOEALTJ.js} +0 -0
  27. /package/dist/{integrations-4JDIOHQU.js → integrations-UWDEQ7Z4.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,44 @@
2
2
 
3
3
  All notable changes to AgenticMail Enterprise are documented here.
4
4
 
5
+ ## [0.5.613] - 2026-05-25
6
+
7
+ ### Fixed — Agents now always use a PERMANENT workspace, never /tmp
8
+
9
+ Agents were saving files (e.g. email templates) under `/tmp/agents/<id>/media`,
10
+ which the OS wipes on reboot — work silently lost. Now every agent has one
11
+ canonical, permanent, cross-platform (mac/linux/windows) workspace and never
12
+ falls back to /tmp.
13
+
14
+ - New `src/agent-tools/workspace.ts`: `getAgentWorkspaceDir()` /
15
+ `ensureAgentWorkspace()` / `getAgentSubdir()`. Canonical path
16
+ `~/.agenticmail/workspaces/<agentId>/` (override via
17
+ `AGENTICMAIL_WORKSPACE_DIR`), built with `os.homedir()` + `path.join()` so it
18
+ works on every platform.
19
+ - Neat, predictable layout created on init: `media/ files/ templates/ exports/
20
+ projects/ data/ tmp/` (+ a `WORKSPACE.md` describing it).
21
+ - Removed every `/tmp/agents/...` and `os.tmpdir()` fallback in the
22
+ file/media paths: WhatsApp + Telegram inbound media, the messaging-poller,
23
+ the calendar joined-meetings state file, and WhatsApp auth/session creds
24
+ (now per-agent under `<workspace>/whatsapp`, was a shared dir).
25
+ - `createAllTools` now derives + provisions the workspace from `agentId` when a
26
+ caller didn't pass one, so no code path can land in /tmp. Path-sandbox allowed
27
+ dirs are now cross-platform (`os.tmpdir()` + `os.homedir()` instead of
28
+ hardcoded `/tmp`, `/var/tmp`, `/root`).
29
+ - On agent creation the workspace is provisioned and its location is written to
30
+ the agent's long-term memory; the path + layout are documented in the system
31
+ prompt and in generated `AGENTS.md` so the agent never forgets where to work.
32
+
33
+ ## [0.5.612] - 2026-05-25
34
+
35
+ ### Fixed — Packaging: stop shipping `logs/` in the npm tarball
36
+
37
+ `0.5.611` accidentally bundled the working `logs/` directory (cloudflared
38
+ + agent process logs) into the published package — these contained local
39
+ `/Users/...` paths (no credentials). Added `logs/`, `*.log`, and
40
+ `test-*.mjs` to `.npmignore`. `0.5.611` is deprecated; use `0.5.612`.
41
+ This release is otherwise identical to `0.5.611`.
42
+
5
43
  ## [0.5.611] - 2026-05-20
6
44
 
7
45
  ### Fixed — Agents no longer "wake up dumb" after context compaction
@@ -515,7 +515,7 @@ var AgentHeartbeatManager = class {
515
515
  return;
516
516
  }
517
517
  try {
518
- const { guardrails } = await import("./routes-VX5CXX4J.js");
518
+ const { guardrails } = await import("./routes-5PUCWC4N.js");
519
519
  const status = await guardrails.getStatus(ctx.agentId);
520
520
  if (status.paused || status.offDuty) {
521
521
  console.log(`[heartbeat] Skipping action dispatch \u2014 agent is ${status.offDuty ? "off duty" : "paused"}`);
@@ -2,7 +2,7 @@ import {
2
2
  createBrowserTool,
3
3
  createMeetingTools,
4
4
  createMeetingVoiceTools
5
- } from "./chunk-CC4BHZHO.js";
5
+ } from "./chunk-GAOEALTJ.js";
6
6
  import {
7
7
  detectCapabilities,
8
8
  getCapabilitySummary,
@@ -12,11 +12,11 @@ import {
12
12
  import {
13
13
  createTelegramTools,
14
14
  init_telegram
15
- } from "./chunk-REAJCMQE.js";
15
+ } from "./chunk-T26AVIAQ.js";
16
16
  import {
17
17
  createWhatsAppTools,
18
18
  init_whatsapp
19
- } from "./chunk-BUKTZ35L.js";
19
+ } from "./chunk-H3JXMBTG.js";
20
20
  import {
21
21
  MemorySearchIndex,
22
22
  init_text_search
@@ -14581,7 +14581,16 @@ function createVisualMemoryTools(options) {
14581
14581
  // src/agent-tools/index.ts
14582
14582
  init_environment();
14583
14583
  async function createAllTools(options) {
14584
- var defaultAllowedDirs = ["/tmp", "/var/tmp", process.env.HOME || "/root"];
14584
+ if (options && options.agentId && !options.workspaceDir) {
14585
+ try {
14586
+ var { getAgentWorkspaceDir, ensureAgentWorkspace } = await import("./workspace-P5FCSG2D.js");
14587
+ options.workspaceDir = getAgentWorkspaceDir(options.agentId);
14588
+ ensureAgentWorkspace(options.agentId);
14589
+ } catch {
14590
+ }
14591
+ }
14592
+ var _os = await import("os");
14593
+ var defaultAllowedDirs = [_os.tmpdir(), _os.homedir()].filter(Boolean);
14585
14594
  var configuredDirs = options?.security?.pathSandbox?.allowedDirs || [];
14586
14595
  var pathSandbox = options?.workspaceDir && options?.security?.pathSandbox?.enabled !== false ? createPathSandbox(options.workspaceDir, {
14587
14596
  allowedDirs: [...defaultAllowedDirs, ...configuredDirs],
@@ -14795,7 +14804,7 @@ async function createAllTools(options) {
14795
14804
  var integrationTools = [];
14796
14805
  if (options?.vault) {
14797
14806
  try {
14798
- var { createAllIntegrationTools } = await import("./integrations-4JDIOHQU.js");
14807
+ var { createAllIntegrationTools } = await import("./integrations-UWDEQ7Z4.js");
14799
14808
  integrationTools = await createAllIntegrationTools({
14800
14809
  vault: options.vault,
14801
14810
  orgId: options?.orgId,
@@ -14855,7 +14864,8 @@ async function createAllTools(options) {
14855
14864
  }
14856
14865
  } catch {
14857
14866
  }
14858
- const dataDir = options?.workspaceDir ? (await import("path")).resolve(options.workspaceDir, "..") : process.cwd();
14867
+ const _wsRoot = options?.agentId ? (await import("./workspace-P5FCSG2D.js")).getAgentWorkspaceDir(options.agentId) : options?.workspaceDir || process.cwd();
14868
+ const dataDir = (await import("path")).join(_wsRoot, "whatsapp");
14859
14869
  const _rec = _outboundRecorder;
14860
14870
  messagingTools = messagingTools.concat(createWhatsAppTools({
14861
14871
  agentId: options?.agentId || "",
@@ -14866,6 +14876,7 @@ async function createAllTools(options) {
14866
14876
  if (telegramConfig.botToken) {
14867
14877
  messagingTools = messagingTools.concat(createTelegramTools({
14868
14878
  botToken: telegramConfig.botToken,
14879
+ agentId: options?.agentId || "",
14869
14880
  onOutbound: _rec ? (chatId, text) => _rec("telegram", chatId, text) : void 0
14870
14881
  }));
14871
14882
  }
@@ -7,6 +7,12 @@ import {
7
7
  buildPolymarketPrompt,
8
8
  buildRemotonPrompt
9
9
  } from "./chunk-BBM4POWP.js";
10
+ import {
11
+ WORKSPACE_SUBDIRS,
12
+ ensureAgentWorkspace,
13
+ getAgentWorkspaceDir,
14
+ init_workspace
15
+ } from "./chunk-UETRFOSR.js";
10
16
 
11
17
  // src/runtime/index.ts
12
18
  import { nanoid as nanoid3 } from "nanoid";
@@ -436,7 +442,7 @@ function createRuntimeHooks(deps) {
436
442
  var injectedMessages = [...messages];
437
443
  if (deps.knowledgeBaseEnabled !== false) {
438
444
  try {
439
- var { knowledgeBase } = await import("./routes-VX5CXX4J.js");
445
+ var { knowledgeBase } = await import("./routes-5PUCWC4N.js");
440
446
  var kbs = await knowledgeBase.listForAgent(agentId);
441
447
  if (kbs.length > 0) {
442
448
  var contextParts = [];
@@ -469,7 +475,7 @@ ${contextParts.join("\n\n")}`;
469
475
  }
470
476
  if (deps.memoryEnabled !== false) {
471
477
  try {
472
- var { memoryManager } = await import("./routes-VX5CXX4J.js");
478
+ var { memoryManager } = await import("./routes-5PUCWC4N.js");
473
479
  var memories = await memoryManager.queryMemories({
474
480
  agentId,
475
481
  limit: 10,
@@ -490,7 +496,7 @@ ${memories.map(function(m) {
490
496
  }
491
497
  if (deps.policyEnabled !== false) {
492
498
  try {
493
- var { policyEngine } = await import("./routes-VX5CXX4J.js");
499
+ var { policyEngine } = await import("./routes-5PUCWC4N.js");
494
500
  var policies = await policyEngine.getAgentPolicies(agentId, deps.orgId);
495
501
  if (policies.length > 0) {
496
502
  var policyText = policies.map(function(p) {
@@ -515,7 +521,7 @@ ${policyText}`;
515
521
  // ─── Budget Check ──────────────────────────────
516
522
  async checkBudget(agentId, _orgId, _estimatedTokens) {
517
523
  try {
518
- var { lifecycle } = await import("./routes-VX5CXX4J.js");
524
+ var { lifecycle } = await import("./routes-5PUCWC4N.js");
519
525
  var now = Date.now();
520
526
  var cacheKey = `budget_sync_${agentId}`;
521
527
  var lastSync = globalThis[cacheKey] || 0;
@@ -608,7 +614,7 @@ ${policyText}`;
608
614
  // ─── Record LLM Usage ──────────────────────────
609
615
  async recordLLMUsage(agentId, orgId, usage) {
610
616
  try {
611
- var { lifecycle } = await import("./routes-VX5CXX4J.js");
617
+ var { lifecycle } = await import("./routes-5PUCWC4N.js");
612
618
  console.log(`[hooks] recordLLMUsage: agent=${agentId}, input=${usage.inputTokens}, output=${usage.outputTokens}`);
613
619
  await lifecycle.recordLLMUsage(agentId, {
614
620
  inputTokens: usage.inputTokens,
@@ -619,7 +625,7 @@ ${policyText}`;
619
625
  console.log(`[hooks] recordLLMUsage error: ${recordErr.message}`);
620
626
  }
621
627
  try {
622
- var { activity } = await import("./routes-VX5CXX4J.js");
628
+ var { activity } = await import("./routes-5PUCWC4N.js");
623
629
  await activity.record({
624
630
  agentId,
625
631
  orgId,
@@ -667,7 +673,7 @@ ${policyText}`;
667
673
  var cacheKey = `${ctx.agentId}:${ctx.toolName}`;
668
674
  var cached = getCachedPermission(cacheKey);
669
675
  if (cached) return cached;
670
- var { permissionEngine } = await import("./routes-VX5CXX4J.js");
676
+ var { permissionEngine } = await import("./routes-5PUCWC4N.js");
671
677
  var permResult = await permissionEngine.checkPermission(ctx.agentId, ctx.toolName);
672
678
  var result = {
673
679
  allowed: permResult.allowed,
@@ -676,7 +682,7 @@ ${policyText}`;
676
682
  };
677
683
  if (result.allowed && deps.guardrailsEnabled !== false) {
678
684
  try {
679
- var { guardrails } = await import("./routes-VX5CXX4J.js");
685
+ var { guardrails } = await import("./routes-5PUCWC4N.js");
680
686
  var status = await guardrails.getStatus(ctx.agentId);
681
687
  if (status.paused || status.offDuty) {
682
688
  result.allowed = false;
@@ -688,7 +694,7 @@ ${policyText}`;
688
694
  }
689
695
  if (result.allowed && deps.dlpEnabled !== false && ctx.parameters) {
690
696
  try {
691
- var { dlp } = await import("./routes-VX5CXX4J.js");
697
+ var { dlp } = await import("./routes-5PUCWC4N.js");
692
698
  var dlpResult = await dlp.scanParameters({
693
699
  orgId: ctx.orgId,
694
700
  agentId: ctx.agentId,
@@ -708,7 +714,7 @@ ${policyText}`;
708
714
  }
709
715
  if (result.requiresApproval && result.allowed) {
710
716
  try {
711
- var { approvals } = await import("./routes-VX5CXX4J.js");
717
+ var { approvals } = await import("./routes-5PUCWC4N.js");
712
718
  var approval = await approvals.createAndWait({
713
719
  agentId: ctx.agentId,
714
720
  orgId: ctx.orgId,
@@ -738,7 +744,7 @@ ${policyText}`;
738
744
  // ─── After Tool Call ────────────────────────────
739
745
  async afterToolCall(ctx, result) {
740
746
  try {
741
- var { activity } = await import("./routes-VX5CXX4J.js");
747
+ var { activity } = await import("./routes-5PUCWC4N.js");
742
748
  await activity.record({
743
749
  agentId: ctx.agentId,
744
750
  orgId: ctx.orgId,
@@ -755,7 +761,7 @@ ${policyText}`;
755
761
  } catch {
756
762
  }
757
763
  try {
758
- var { lifecycle } = await import("./routes-VX5CXX4J.js");
764
+ var { lifecycle } = await import("./routes-5PUCWC4N.js");
759
765
  await lifecycle.recordToolCall(ctx.agentId, {
760
766
  toolId: ctx.toolName,
761
767
  tokensUsed: 0,
@@ -767,7 +773,7 @@ ${policyText}`;
767
773
  }
768
774
  if (result.success && EXTERNAL_TOOLS.has(ctx.toolName)) {
769
775
  try {
770
- var { journal } = await import("./routes-VX5CXX4J.js");
776
+ var { journal } = await import("./routes-5PUCWC4N.js");
771
777
  await journal.record({
772
778
  orgId: ctx.orgId,
773
779
  agentId: ctx.agentId,
@@ -782,7 +788,7 @@ ${policyText}`;
782
788
  }
783
789
  if (result.success && COMMUNICATION_TOOLS.has(ctx.toolName)) {
784
790
  try {
785
- var { commBus } = await import("./routes-VX5CXX4J.js");
791
+ var { commBus } = await import("./routes-5PUCWC4N.js");
786
792
  await commBus.observeMessage({
787
793
  orgId: ctx.orgId,
788
794
  agentId: ctx.agentId,
@@ -796,7 +802,7 @@ ${policyText}`;
796
802
  // ─── Session Lifecycle ──────────────────────────
797
803
  async onSessionStart(sessionId, agentId, orgId) {
798
804
  try {
799
- var { activity } = await import("./routes-VX5CXX4J.js");
805
+ var { activity } = await import("./routes-5PUCWC4N.js");
800
806
  await activity.record({
801
807
  agentId,
802
808
  orgId,
@@ -809,7 +815,7 @@ ${policyText}`;
809
815
  },
810
816
  async onSessionEnd(sessionId, agentId, orgId) {
811
817
  try {
812
- var { activity } = await import("./routes-VX5CXX4J.js");
818
+ var { activity } = await import("./routes-5PUCWC4N.js");
813
819
  await activity.record({
814
820
  agentId,
815
821
  orgId,
@@ -824,7 +830,7 @@ ${policyText}`;
824
830
  async onCompactionStart(sessionId, agentId, tokenCount, contextWindowSize) {
825
831
  var pct = contextWindowSize > 0 ? Math.round(tokenCount / contextWindowSize * 100) : 0;
826
832
  try {
827
- var { activity } = await import("./routes-VX5CXX4J.js");
833
+ var { activity } = await import("./routes-5PUCWC4N.js");
828
834
  await activity.record({
829
835
  agentId,
830
836
  orgId: deps.orgId,
@@ -851,7 +857,7 @@ ${policyText}`;
851
857
  // ─── Context Compaction ─────────────────────────
852
858
  async onContextCompaction(sessionId, agentId, summary) {
853
859
  try {
854
- var { activity: activityTracker } = await import("./routes-VX5CXX4J.js");
860
+ var { activity: activityTracker } = await import("./routes-5PUCWC4N.js");
855
861
  await activityTracker.record({
856
862
  agentId,
857
863
  orgId: deps.orgId,
@@ -862,7 +868,7 @@ ${policyText}`;
862
868
  } catch {
863
869
  }
864
870
  try {
865
- var { memoryManager } = await import("./routes-VX5CXX4J.js");
871
+ var { memoryManager } = await import("./routes-5PUCWC4N.js");
866
872
  await memoryManager.createMemory({
867
873
  agentId,
868
874
  orgId: deps.orgId,
@@ -2956,7 +2962,7 @@ async function runAgentLoop(config, initialMessages, hooks, options) {
2956
2962
  console.log(`[agent-loop] \u2705 Tool ${toolCall.name} succeeded (${content.length} chars): ${content.slice(0, 300)}`);
2957
2963
  }
2958
2964
  try {
2959
- const { activity } = await import("./routes-VX5CXX4J.js");
2965
+ const { activity } = await import("./routes-5PUCWC4N.js");
2960
2966
  activity.recordToolCallCompact({
2961
2967
  agentId: config.agentId,
2962
2968
  orgId: config.orgId,
@@ -4270,7 +4276,7 @@ function createRequestToolsTool(allTools, activeSets, _context, agentSkills) {
4270
4276
  };
4271
4277
  }
4272
4278
  async function createToolsForContext(options, context, opts) {
4273
- const { createAllTools } = await import("./agent-tools-KRMDJOCK.js");
4279
+ const { createAllTools } = await import("./agent-tools-5LLIXV6A.js");
4274
4280
  if (context === "full") {
4275
4281
  return createAllTools(options);
4276
4282
  }
@@ -4881,9 +4887,7 @@ var FollowUpScheduler = class {
4881
4887
  };
4882
4888
 
4883
4889
  // src/runtime/index.ts
4884
- import { homedir } from "os";
4885
- import { join } from "path";
4886
- import { mkdirSync } from "fs";
4890
+ init_workspace();
4887
4891
  var _remotionPrompt = buildRemotonPrompt();
4888
4892
  var DEFAULT_MODEL = {
4889
4893
  provider: "anthropic",
@@ -4934,9 +4938,9 @@ var AgentRuntime = class {
4934
4938
  /** Build tool options for a given agent, including OAuth email config if available */
4935
4939
  buildToolOptions(agentId, sessionId) {
4936
4940
  const self = this;
4937
- const agentWorkspace = join(homedir(), ".agenticmail", "workspaces", agentId);
4941
+ const agentWorkspace = getAgentWorkspaceDir(agentId);
4938
4942
  try {
4939
- mkdirSync(agentWorkspace, { recursive: true });
4943
+ ensureAgentWorkspace(agentId);
4940
4944
  } catch {
4941
4945
  }
4942
4946
  const base = {
@@ -5781,7 +5785,7 @@ function createAgentRuntime(config) {
5781
5785
  return new AgentRuntime(config);
5782
5786
  }
5783
5787
  function buildDefaultSystemPrompt(agentId, memoryContext, hierarchyContext, agentIdentity, dbConnections, agentConfig) {
5784
- const wsDir = join(homedir(), ".agenticmail", "workspaces", agentId);
5788
+ const wsDir = getAgentWorkspaceDir(agentId);
5785
5789
  var base = `You are an AI agent managed by AgenticMail Enterprise (agent: ${agentId}).
5786
5790
 
5787
5791
  You have access to a comprehensive set of tools for completing tasks. Use them effectively.
@@ -5796,10 +5800,12 @@ Guidelines:
5796
5800
  - For long tasks, work systematically and report progress
5797
5801
 
5798
5802
  ## Your Workspace
5799
- Your dedicated workspace directory is: ${wsDir}
5800
- ALWAYS save files, deliverables, rendered videos, images, and outputs here \u2014 NEVER in /tmp.
5801
- /tmp files are cleaned up by the OS and will be lost. Your workspace persists across sessions.
5802
- Create subdirectories as needed (e.g. videos/, images/, projects/, exports/).
5803
+ Your permanent workspace directory is: ${wsDir}
5804
+ ALWAYS save files, deliverables, rendered videos, images, templates, and outputs here \u2014 NEVER in /tmp.
5805
+ /tmp files are cleaned up by the OS and WILL be lost. Your workspace persists across sessions, restarts, and reboots.
5806
+ Keep it neat \u2014 it already has these subfolders (use them, create more as needed):
5807
+ ${Object.entries(WORKSPACE_SUBDIRS).map(([n, d]) => ` - ${n}/ \u2014 ${d}`).join("\n")}
5808
+ Examples: email/HTML templates \u2192 templates/ ; attachments & images \u2192 media/ ; finished deliverables \u2192 exports/ ; scratch \u2192 tmp/ (inside your workspace, NOT the OS /tmp).
5803
5809
  - ACTIVELY USE YOUR MEMORY: After corrections, lessons, or insights, call memory_reflect to record them
5804
5810
  - Before complex tasks, call memory_context to recall relevant knowledge
5805
5811
  - Your memory persists across conversations \u2014 it's how you grow as an expert
@@ -137,12 +137,9 @@ async function getOrCreateConnection(config) {
137
137
  var buffer = await downloadMediaMessage(msg, "buffer", {});
138
138
  if (buffer && buffer.length > 0) {
139
139
  var { join: join2 } = await import("path");
140
- var { mkdirSync, writeFileSync } = await import("fs");
141
- var mediaDir = join2(config.dataDir || `/tmp/agents/${config.agentId}`, "media");
142
- try {
143
- mkdirSync(mediaDir, { recursive: true });
144
- } catch {
145
- }
140
+ var { writeFileSync } = await import("fs");
141
+ var { getAgentSubdir } = await import("./workspace-P5FCSG2D.js");
142
+ var mediaDir = getAgentSubdir(config.agentId, "media");
146
143
  mediaType = msg.message?.imageMessage ? "photo" : msg.message?.videoMessage ? "video" : msg.message?.audioMessage ? "audio" : msg.message?.documentMessage ? "document" : msg.message?.stickerMessage ? "sticker" : "file";
147
144
  var ext = mediaType === "photo" ? "jpg" : mediaType === "video" ? "mp4" : mediaType === "audio" ? "ogg" : mediaType === "sticker" ? "webp" : mediaMessage.fileName?.split(".").pop() || "bin";
148
145
  var localName = mediaMessage.fileName || `${mediaType}-${Date.now()}.${ext}`;
@@ -11,7 +11,7 @@ import {
11
11
  init_config_bus,
12
12
  init_routes,
13
13
  routes_exports
14
- } from "./chunk-KQ5EU4IA.js";
14
+ } from "./chunk-VWIDJRD4.js";
15
15
  import {
16
16
  init_transport_encryption,
17
17
  transportEncryptionMiddleware
@@ -1658,7 +1658,7 @@ function createAdminRoutes(db) {
1658
1658
  });
1659
1659
  api.get("/whatsapp/qr/:agentId", requireRole("admin"), async (c) => {
1660
1660
  try {
1661
- var { getWhatsAppQR, isWhatsAppConnected } = await import("./whatsapp-RAQUV6ZL.js");
1661
+ var { getWhatsAppQR, isWhatsAppConnected } = await import("./whatsapp-TBOB7TDL.js");
1662
1662
  var agentId = c.req.param("agentId");
1663
1663
  if (isWhatsAppConnected(agentId)) {
1664
1664
  return c.json({ status: "connected" });
@@ -7746,7 +7746,7 @@ function createServer(config) {
7746
7746
  let engineInitialized = false;
7747
7747
  api.all("/engine/*", async (c, _next) => {
7748
7748
  try {
7749
- const { engineRoutes, setEngineDb } = await import("./routes-VX5CXX4J.js");
7749
+ const { engineRoutes, setEngineDb } = await import("./routes-5PUCWC4N.js");
7750
7750
  const { EngineDatabase } = await import("./db-adapter-ARPQPQ6K.js");
7751
7751
  if (!engineInitialized) {
7752
7752
  engineInitialized = true;
@@ -7776,13 +7776,13 @@ function createServer(config) {
7776
7776
  engineInitialized = true;
7777
7777
  if (config.runtime?.enabled) {
7778
7778
  try {
7779
- const { createAgentRuntime } = await import("./runtime-RMLNHLAT.js");
7780
- const { mountRuntimeApp, setRuntime } = await import("./routes-VX5CXX4J.js");
7779
+ const { createAgentRuntime } = await import("./runtime-GML2LXIN.js");
7780
+ const { mountRuntimeApp, setRuntime } = await import("./routes-5PUCWC4N.js");
7781
7781
  let getEmailConfig;
7782
7782
  let onTokenRefresh;
7783
7783
  let agentMemoryMgr;
7784
7784
  try {
7785
- const { lifecycle: lc, memoryManager: mm } = await import("./routes-VX5CXX4J.js");
7785
+ const { lifecycle: lc, memoryManager: mm } = await import("./routes-5PUCWC4N.js");
7786
7786
  agentMemoryMgr = mm;
7787
7787
  if (lc) {
7788
7788
  getEmailConfig = (agentId) => {
@@ -7821,7 +7821,7 @@ function createServer(config) {
7821
7821
  }
7822
7822
  } catch {
7823
7823
  }
7824
- const { vault: vaultRef, permissionEngine: permRef, databaseManager: dbMgr } = await import("./routes-VX5CXX4J.js");
7824
+ const { vault: vaultRef, permissionEngine: permRef, databaseManager: dbMgr } = await import("./routes-5PUCWC4N.js");
7825
7825
  const runtime = createAgentRuntime({
7826
7826
  engineDb,
7827
7827
  adminDb: config.db,
@@ -8071,7 +8071,7 @@ function createServer(config) {
8071
8071
  }
8072
8072
  }
8073
8073
  try {
8074
- const routesMod = await import("./routes-VX5CXX4J.js");
8074
+ const routesMod = await import("./routes-5PUCWC4N.js");
8075
8075
  const kbEngine = routesMod.knowledgeBase;
8076
8076
  kbEngine?.setApiKeys?.(decryptedKeys);
8077
8077
  if (Object.keys(decryptedKeys).length > 0) {
@@ -8089,7 +8089,7 @@ function createServer(config) {
8089
8089
  });
8090
8090
  (async () => {
8091
8091
  try {
8092
- const { engineRoutes, setEngineDb } = await import("./routes-VX5CXX4J.js");
8092
+ const { engineRoutes, setEngineDb } = await import("./routes-5PUCWC4N.js");
8093
8093
  const { EngineDatabase } = await import("./db-adapter-ARPQPQ6K.js");
8094
8094
  if (!engineInitialized) {
8095
8095
  engineInitialized = true;
@@ -8113,13 +8113,13 @@ function createServer(config) {
8113
8113
  await setEngineDb(engineDb, config.db);
8114
8114
  if (config.runtime?.enabled) {
8115
8115
  try {
8116
- const { createAgentRuntime } = await import("./runtime-RMLNHLAT.js");
8117
- const { mountRuntimeApp, setRuntime } = await import("./routes-VX5CXX4J.js");
8116
+ const { createAgentRuntime } = await import("./runtime-GML2LXIN.js");
8117
+ const { mountRuntimeApp, setRuntime } = await import("./routes-5PUCWC4N.js");
8118
8118
  let getEmailConfig;
8119
8119
  let onTokenRefresh;
8120
8120
  let agentMemoryMgr;
8121
8121
  try {
8122
- const { lifecycle: lc, memoryManager: mm } = await import("./routes-VX5CXX4J.js");
8122
+ const { lifecycle: lc, memoryManager: mm } = await import("./routes-5PUCWC4N.js");
8123
8123
  agentMemoryMgr = mm;
8124
8124
  if (lc) {
8125
8125
  getEmailConfig = (agentId) => {
@@ -8158,7 +8158,7 @@ function createServer(config) {
8158
8158
  }
8159
8159
  } catch {
8160
8160
  }
8161
- const { vault: vaultRef2, permissionEngine: permRef2, databaseManager: dbMgr2 } = await import("./routes-VX5CXX4J.js");
8161
+ const { vault: vaultRef2, permissionEngine: permRef2, databaseManager: dbMgr2 } = await import("./routes-5PUCWC4N.js");
8162
8162
  const runtime = createAgentRuntime({
8163
8163
  engineDb,
8164
8164
  adminDb: config.db,
@@ -8170,7 +8170,7 @@ function createServer(config) {
8170
8170
  agentMemoryManager: agentMemoryMgr,
8171
8171
  vault: vaultRef2,
8172
8172
  permissionEngine: permRef2,
8173
- hierarchyManager: (await import("./routes-VX5CXX4J.js")).hierarchyManager ?? void 0,
8173
+ hierarchyManager: (await import("./routes-5PUCWC4N.js")).hierarchyManager ?? void 0,
8174
8174
  databaseManager: dbMgr2
8175
8175
  });
8176
8176
  await runtime.start();
@@ -8184,7 +8184,7 @@ function createServer(config) {
8184
8184
  }
8185
8185
  console.log("[engine] Eagerly initialized");
8186
8186
  try {
8187
- const { lifecycle: lcRef } = await import("./routes-VX5CXX4J.js");
8187
+ const { lifecycle: lcRef } = await import("./routes-5PUCWC4N.js");
8188
8188
  if (lcRef) {
8189
8189
  const agents = Array.from(lcRef.agents?.values?.() || []);
8190
8190
  const hasLocalPm2 = agents.some((a) => {
@@ -8193,7 +8193,7 @@ function createServer(config) {
8193
8193
  return target === "local" && (!pm || pm === "pm2");
8194
8194
  });
8195
8195
  if (hasLocalPm2) {
8196
- const { ensurePm2 } = await import("./deployer-BKBISKKF.js");
8196
+ const { ensurePm2 } = await import("./deployer-M4YHMATN.js");
8197
8197
  const pm2 = await ensurePm2();
8198
8198
  if (pm2.installed) {
8199
8199
  console.log(`[startup] PM2 v${pm2.version} available for local deployments`);
@@ -1234,7 +1234,7 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
1234
1234
  const { deployTarget, company, database, domain, tunnel, cloud } = config;
1235
1235
  if (deployTarget === "cloudflare-tunnel" && tunnel) {
1236
1236
  spinner.start(`Starting local server on port ${tunnel.port}...`);
1237
- const { createServer: createServer2 } = await import("./server-64K32C5T.js");
1237
+ const { createServer: createServer2 } = await import("./server-R5SICPBI.js");
1238
1238
  const server2 = createServer2({ port: tunnel.port, db, jwtSecret });
1239
1239
  const handle2 = await server2.start();
1240
1240
  spinner.succeed("Server running");
@@ -1601,7 +1601,7 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
1601
1601
  return {};
1602
1602
  }
1603
1603
  spinner.start("Starting local server...");
1604
- const { createServer } = await import("./server-64K32C5T.js");
1604
+ const { createServer } = await import("./server-R5SICPBI.js");
1605
1605
  const server = createServer({ port: 3e3, db, jwtSecret });
1606
1606
  const handle = await server.start();
1607
1607
  spinner.succeed("Server running");
@@ -1,3 +1,7 @@
1
+ import {
2
+ WORKSPACE_SUBDIRS,
3
+ init_workspace
4
+ } from "./chunk-UETRFOSR.js";
1
5
  import {
2
6
  __esm
3
7
  } from "./chunk-KFQGP6VL.js";
@@ -7,6 +11,7 @@ var AgentConfigGenerator;
7
11
  var init_agent_config = __esm({
8
12
  "src/engine/agent-config.ts"() {
9
13
  "use strict";
14
+ init_workspace();
10
15
  AgentConfigGenerator = class _AgentConfigGenerator {
11
16
  /**
12
17
  * Generate the complete workspace files for an agent
@@ -329,6 +334,15 @@ _Configure this from the admin dashboard._
329
334
  - Daily notes: memory/YYYY-MM-DD.md
330
335
  - Long-term: MEMORY.md
331
336
 
337
+ ## Files & Workspace
338
+ You have ONE permanent workspace folder. ALWAYS work from it \u2014 NEVER write to /tmp
339
+ (OS temp files get wiped and are lost). It persists across sessions and reboots.
340
+ Location: \`~/.agenticmail/workspaces/<your-agent-id>/\` (also injected into your
341
+ system prompt at runtime, and saved in your memory). Keep it neat:
342
+ ${Object.entries(WORKSPACE_SUBDIRS).map(([n, d]) => `- \`${n}/\` \u2014 ${d}`).join("\n")}
343
+ Email/HTML templates \u2192 \`templates/\` \xB7 attachments & images \u2192 \`media/\` \xB7 finished
344
+ deliverables \u2192 \`exports/\` \xB7 scratch \u2192 \`tmp/\` (inside your workspace, not the OS /tmp).
345
+
332
346
  ## Safety
333
347
  - Don't exfiltrate private data
334
348
  - Don't run destructive commands without asking
@@ -107,12 +107,9 @@ function createTelegramTools(config) {
107
107
  var resp = await fetch(downloadUrl);
108
108
  if (!resp.ok) throw new Error(`Download failed: ${resp.status}`);
109
109
  var { join } = await import("path");
110
- var { mkdirSync, writeFileSync } = await import("fs");
111
- var mediaDir = join("/tmp/agents/media");
112
- try {
113
- mkdirSync(mediaDir, { recursive: true });
114
- } catch {
115
- }
110
+ var { writeFileSync } = await import("fs");
111
+ var { getAgentSubdir } = await import("./workspace-P5FCSG2D.js");
112
+ var mediaDir = getAgentSubdir(config.agentId || "default", "media");
116
113
  var ext = fileData.file_path.split(".").pop() || "bin";
117
114
  var localName = input.fileName || `telegram-${Date.now()}.${ext}`;
118
115
  var localPath = join(mediaDir, localName);
@@ -0,0 +1,80 @@
1
+ import {
2
+ __esm
3
+ } from "./chunk-KFQGP6VL.js";
4
+
5
+ // src/agent-tools/workspace.ts
6
+ import { homedir } from "os";
7
+ import { join } from "path";
8
+ import { mkdirSync, writeFileSync, existsSync } from "fs";
9
+ function getWorkspaceBase() {
10
+ return process.env.AGENTICMAIL_WORKSPACE_DIR || join(homedir(), ".agenticmail", "workspaces");
11
+ }
12
+ function getAgentWorkspaceDir(agentId) {
13
+ return join(getWorkspaceBase(), agentId || "default");
14
+ }
15
+ function getAgentSubdir(agentId, name) {
16
+ const dir = join(getAgentWorkspaceDir(agentId), name);
17
+ try {
18
+ mkdirSync(dir, { recursive: true });
19
+ } catch {
20
+ }
21
+ return dir;
22
+ }
23
+ function ensureAgentWorkspace(agentId, displayName) {
24
+ const root = getAgentWorkspaceDir(agentId);
25
+ try {
26
+ mkdirSync(root, { recursive: true });
27
+ for (const sub of Object.keys(WORKSPACE_SUBDIRS)) {
28
+ mkdirSync(join(root, sub), { recursive: true });
29
+ }
30
+ const md = join(root, "WORKSPACE.md");
31
+ if (!existsSync(md)) writeFileSync(md, renderWorkspaceMarkdown(root, displayName));
32
+ } catch {
33
+ }
34
+ return root;
35
+ }
36
+ function renderWorkspaceMarkdown(root, displayName) {
37
+ const lines = [];
38
+ lines.push(`# WORKSPACE.md \u2014 ${displayName ? displayName + "'s" : "Your"} permanent workspace`);
39
+ lines.push("");
40
+ lines.push(`Your permanent working directory is:
41
+
42
+ ${root}
43
+ `);
44
+ lines.push("ALWAYS work from here. NEVER write to /tmp \u2014 OS temp files are wiped and lost.");
45
+ lines.push("This folder persists across sessions, restarts, and reboots. Keep it tidy.");
46
+ lines.push("");
47
+ lines.push("## Folder layout");
48
+ lines.push("");
49
+ for (const [name, desc] of Object.entries(WORKSPACE_SUBDIRS)) {
50
+ lines.push(`- \`${name}/\` \u2014 ${desc}`);
51
+ }
52
+ lines.push("");
53
+ lines.push("Save email/HTML templates to `templates/`, attachments and images to `media/`,");
54
+ lines.push("finished deliverables to `exports/`, and use `tmp/` (inside the workspace) for scratch.");
55
+ return lines.join("\n") + "\n";
56
+ }
57
+ var WORKSPACE_SUBDIRS;
58
+ var init_workspace = __esm({
59
+ "src/agent-tools/workspace.ts"() {
60
+ WORKSPACE_SUBDIRS = {
61
+ media: "Images, audio, video, and inbound/outbound message attachments",
62
+ files: "Documents and generated deliverables (reports, sheets, etc.)",
63
+ templates: "Reusable email / HTML / document templates",
64
+ exports: "Rendered final outputs (PDF, MP4, ZIP, etc.) ready to send",
65
+ projects: "Multi-file working projects (code, video projects, sites)",
66
+ data: "Local scratch databases and JSON/CSV working data",
67
+ tmp: "Scratch space \u2014 local & ephemeral, but NOT the OS /tmp (still under your workspace)"
68
+ };
69
+ }
70
+ });
71
+
72
+ export {
73
+ WORKSPACE_SUBDIRS,
74
+ getWorkspaceBase,
75
+ getAgentWorkspaceDir,
76
+ getAgentSubdir,
77
+ ensureAgentWorkspace,
78
+ renderWorkspaceMarkdown,
79
+ init_workspace
80
+ };
@@ -1,3 +1,7 @@
1
+ import {
2
+ AgentStatusTracker,
3
+ init_agent_status
4
+ } from "./chunk-FQWJMPKW.js";
1
5
  import {
2
6
  DatabaseConnectionManager,
3
7
  init_connection_manager,
@@ -7,6 +11,12 @@ import {
7
11
  init_agent_tools,
8
12
  init_types
9
13
  } from "./chunk-TK55CSBH.js";
14
+ import {
15
+ AgentConfigGenerator,
16
+ DeploymentEngine,
17
+ init_agent_config,
18
+ init_deployer
19
+ } from "./chunk-QVZIW5HI.js";
10
20
  import {
11
21
  init_messaging_history,
12
22
  storeMessage
@@ -28,10 +38,6 @@ import {
28
38
  TaskQueueManager,
29
39
  init_task_queue
30
40
  } from "./chunk-ET6WZFPS.js";
31
- import {
32
- AgentStatusTracker,
33
- init_agent_status
34
- } from "./chunk-FQWJMPKW.js";
35
41
  import {
36
42
  BUILTIN_SKILLS,
37
43
  PRESET_PROFILES,
@@ -39,12 +45,6 @@ import {
39
45
  SKILL_SUITES,
40
46
  init_skills as init_skills2
41
47
  } from "./chunk-HGBLI5HF.js";
42
- import {
43
- AgentConfigGenerator,
44
- DeploymentEngine,
45
- init_agent_config,
46
- init_deployer
47
- } from "./chunk-TBBVEXBH.js";
48
48
  import {
49
49
  getConfig,
50
50
  init_transport_encryption,
@@ -760,6 +760,25 @@ var init_lifecycle = __esm({
760
760
  this.agents.set(agent.id, agent);
761
761
  await this.persistAgent(agent);
762
762
  this.emitEvent(agent, "created", { createdBy });
763
+ try {
764
+ const { ensureAgentWorkspace, renderWorkspaceMarkdown } = await import("./workspace-P5FCSG2D.js");
765
+ const displayName = config.identity?.displayName || config.displayName || config.name;
766
+ const wsRoot = ensureAgentWorkspace(agent.id, displayName);
767
+ try {
768
+ const { memoryManager: memoryManager2 } = await import("./routes-5PUCWC4N.js");
769
+ await memoryManager2.createMemory({
770
+ agentId: agent.id,
771
+ orgId,
772
+ category: "system_notice",
773
+ title: "My permanent workspace location",
774
+ content: renderWorkspaceMarkdown(wsRoot, displayName),
775
+ source: "system",
776
+ importance: "high"
777
+ });
778
+ } catch {
779
+ }
780
+ } catch {
781
+ }
763
782
  return agent;
764
783
  }
765
784
  /**
@@ -7055,7 +7074,7 @@ function createAgentRoutes(opts) {
7055
7074
  });
7056
7075
  router.post("/system/install-pm2", async (c) => {
7057
7076
  try {
7058
- const { ensurePm2 } = await import("./deployer-BKBISKKF.js");
7077
+ const { ensurePm2 } = await import("./deployer-M4YHMATN.js");
7059
7078
  const result = await ensurePm2();
7060
7079
  if (result.installed) {
7061
7080
  return c.json({ success: true, message: `PM2 ${result.version} installed successfully` });
@@ -7311,7 +7330,7 @@ function createAgentRoutes(opts) {
7311
7330
  }
7312
7331
  const managedAgent = await lifecycle2.createAgent(orgId, config, actor);
7313
7332
  try {
7314
- const { knowledgeBase: kbEngine } = await import("./routes-VX5CXX4J.js");
7333
+ const { knowledgeBase: kbEngine } = await import("./routes-5PUCWC4N.js");
7315
7334
  const allKbs = kbEngine.getAllKnowledgeBases();
7316
7335
  const clientOrgId = managedAgent?.clientOrgId || config?.clientOrgId || null;
7317
7336
  let kbAssigned = 0;
@@ -9256,7 +9275,7 @@ function createAgentRoutes(opts) {
9256
9275
  try {
9257
9276
  const body = await c.req.json().catch(() => ({}));
9258
9277
  const mode = body.mode || "";
9259
- const { createWhatsAppTools } = await import("./whatsapp-RAQUV6ZL.js");
9278
+ const { createWhatsAppTools } = await import("./whatsapp-TBOB7TDL.js");
9260
9279
  const dataDir = process.env.DATA_DIR || "/tmp/agenticmail-data";
9261
9280
  const connId = mode === "business" ? `biz-${agentId}` : agentId;
9262
9281
  const connDir = mode === "business" ? `${dataDir}/agents/${agentId}/whatsapp-business` : `${dataDir}/agents/${agentId}/whatsapp`;
@@ -9273,7 +9292,7 @@ function createAgentRoutes(opts) {
9273
9292
  const agentId = c.req.param("id");
9274
9293
  const mode = c.req.query("mode") || "";
9275
9294
  try {
9276
- const { getConnectionStatus } = await import("./whatsapp-RAQUV6ZL.js");
9295
+ const { getConnectionStatus } = await import("./whatsapp-TBOB7TDL.js");
9277
9296
  const connId = mode === "business" ? `biz-${agentId}` : agentId;
9278
9297
  return c.json(getConnectionStatus(connId));
9279
9298
  } catch {
@@ -9286,7 +9305,7 @@ function createAgentRoutes(opts) {
9286
9305
  const body = await c.req.json().catch(() => ({}));
9287
9306
  const mode = body.mode || "";
9288
9307
  const connId = mode === "business" ? `biz-${agentId}` : agentId;
9289
- const { sendTestMessage } = await import("./whatsapp-RAQUV6ZL.js");
9308
+ const { sendTestMessage } = await import("./whatsapp-TBOB7TDL.js");
9290
9309
  const result = await sendTestMessage(connId, body.to);
9291
9310
  return c.json(result);
9292
9311
  } catch (err) {
@@ -9297,7 +9316,7 @@ function createAgentRoutes(opts) {
9297
9316
  const agentId = c.req.param("id");
9298
9317
  try {
9299
9318
  const body = await c.req.json();
9300
- const { getConnection } = await import("./whatsapp-RAQUV6ZL.js");
9319
+ const { getConnection } = await import("./whatsapp-TBOB7TDL.js");
9301
9320
  const conn = getConnection(agentId);
9302
9321
  if (!conn?.connected) return c.json({ error: "Not connected" }, 503);
9303
9322
  const toJid = (to) => to?.includes("@") ? to : (to || "").replace(/[^0-9]/g, "") + "@s.whatsapp.net";
@@ -9341,7 +9360,7 @@ function createAgentRoutes(opts) {
9341
9360
  try {
9342
9361
  const body = await c.req.json().catch(() => ({}));
9343
9362
  const mode = body.mode || "";
9344
- const { createWhatsAppTools } = await import("./whatsapp-RAQUV6ZL.js");
9363
+ const { createWhatsAppTools } = await import("./whatsapp-TBOB7TDL.js");
9345
9364
  const dataDir = process.env.DATA_DIR || "/tmp/agenticmail-data";
9346
9365
  const connId = mode === "business" ? `biz-${agentId}` : agentId;
9347
9366
  const connDir = mode === "business" ? `${dataDir}/agents/${agentId}/whatsapp-business` : `${dataDir}/agents/${agentId}/whatsapp`;
@@ -24422,15 +24441,16 @@ var init_messaging_poller = __esm({
24422
24441
  port: agents[0].port || 3100
24423
24442
  };
24424
24443
  if (this.config.getCapability("whatsapp")) {
24425
- var dataDir = process.env.DATA_DIR || "/tmp/agenticmail-data";
24444
+ var { getAgentWorkspaceDir } = await import("./workspace-P5FCSG2D.js");
24445
+ var { join: _join } = await import("path");
24426
24446
  var agentEndpoints = [];
24427
24447
  for (var ag of agents) {
24428
24448
  var ep = { id: ag.id, displayName: ag.displayName || ag.name || "Agent", host: ag.host || "localhost", port: ag.port || 3100 };
24429
- agentEndpoints.push({ id: ag.id, dataDir: `${dataDir}/agents/${ag.id}/whatsapp`, endpoint: ep });
24449
+ agentEndpoints.push({ id: ag.id, dataDir: _join(getAgentWorkspaceDir(ag.id), "whatsapp"), endpoint: ep });
24430
24450
  await this.startWhatsApp(ep);
24431
24451
  }
24432
24452
  try {
24433
- var { autoStartConnections } = await import("./whatsapp-RAQUV6ZL.js");
24453
+ var { autoStartConnections } = await import("./whatsapp-TBOB7TDL.js");
24434
24454
  await autoStartConnections(agentEndpoints.map((a) => ({ id: a.id, dataDir: a.dataDir })));
24435
24455
  } catch (err) {
24436
24456
  console.error("[messaging] WhatsApp auto-start failed:", err.message);
@@ -24544,7 +24564,7 @@ var init_messaging_poller = __esm({
24544
24564
  // ─── WhatsApp (event-driven — Baileys WebSocket) ──
24545
24565
  async startWhatsApp(agent) {
24546
24566
  try {
24547
- var { onWhatsAppMessage } = await import("./whatsapp-RAQUV6ZL.js");
24567
+ var { onWhatsAppMessage } = await import("./whatsapp-TBOB7TDL.js");
24548
24568
  var unsub = onWhatsAppMessage(agent.id, (msg) => {
24549
24569
  var waMediaFiles;
24550
24570
  if (msg.mediaPath && msg.mediaType) {
@@ -24570,7 +24590,7 @@ var init_messaging_poller = __esm({
24570
24590
  }
24571
24591
  // ─── Telegram (webhook preferred, polling fallback) ─
24572
24592
  async startTelegram(botToken, agent) {
24573
- var { setTelegramWebhook, deleteTelegramWebhook, getTelegramWebhookInfo } = await import("./telegram-NG7PNNIN.js");
24593
+ var { setTelegramWebhook, deleteTelegramWebhook, getTelegramWebhookInfo } = await import("./telegram-W765VRI5.js");
24574
24594
  var { randomBytes: randomBytes2 } = await import("crypto");
24575
24595
  var webhookSecret = randomBytes2(32).toString("hex");
24576
24596
  if (this.config.publicUrl && this.config.app) {
@@ -24649,7 +24669,7 @@ var init_messaging_poller = __esm({
24649
24669
  offset = await loadOffset();
24650
24670
  while (running && this.running) {
24651
24671
  try {
24652
- var { pollTelegramUpdates } = await import("./telegram-NG7PNNIN.js");
24672
+ var { pollTelegramUpdates } = await import("./telegram-W765VRI5.js");
24653
24673
  var { updates, nextOffset } = await pollTelegramUpdates(botToken, offset, 25);
24654
24674
  if (nextOffset > offset) {
24655
24675
  offset = nextOffset;
@@ -24766,13 +24786,10 @@ ${desc}` : desc;
24766
24786
  var downloadUrl = `https://api.telegram.org/file/bot${botToken}/${filePath}`;
24767
24787
  var response = await fetch(downloadUrl);
24768
24788
  if (!response.ok) return null;
24769
- var { join: join3, dirname: dirname3 } = await import("path");
24770
- var { mkdirSync, writeFileSync } = await import("fs");
24771
- var mediaDir = join3(agent.dataDir || `/tmp/agents/${agent.id}`, "media");
24772
- try {
24773
- mkdirSync(mediaDir, { recursive: true });
24774
- } catch {
24775
- }
24789
+ var { join: join3 } = await import("path");
24790
+ var { writeFileSync } = await import("fs");
24791
+ var { getAgentSubdir } = await import("./workspace-P5FCSG2D.js");
24792
+ var mediaDir = getAgentSubdir(agent.id, "media");
24776
24793
  var ext = filePath.split(".").pop() || (mediaType === "photo" ? "jpg" : "bin");
24777
24794
  var localName = fileName || `${mediaType}-${Date.now()}.${ext}`;
24778
24795
  var localPath = join3(mediaDir, localName);
@@ -25042,7 +25059,7 @@ ${desc}` : desc;
25042
25059
  var typingJson = await typingResp.json();
25043
25060
  console.log(`[messaging] Telegram typing sent to ${chatId}: ${JSON.stringify(typingJson)}`);
25044
25061
  } else if (ctx.source === "whatsapp") {
25045
- var { getConnection } = await import("./whatsapp-RAQUV6ZL.js");
25062
+ var { getConnection } = await import("./whatsapp-TBOB7TDL.js");
25046
25063
  var conn = getConnection(agent.id);
25047
25064
  if (!conn?.connected) return;
25048
25065
  var jid = ctx.senderId.includes("@") ? ctx.senderId : ctx.senderId.replace(/[^0-9]/g, "") + "@s.whatsapp.net";
@@ -25057,7 +25074,7 @@ ${desc}` : desc;
25057
25074
  async sendDirectReply(agent, ctx, text) {
25058
25075
  try {
25059
25076
  if (ctx.source === "whatsapp") {
25060
- var { getConnection } = await import("./whatsapp-RAQUV6ZL.js");
25077
+ var { getConnection } = await import("./whatsapp-TBOB7TDL.js");
25061
25078
  var conn = getConnection(agent.id);
25062
25079
  if (!conn?.connected) return;
25063
25080
  var jid = ctx.senderId.includes("@") ? ctx.senderId : ctx.senderId.replace(/[^0-9]/g, "") + "@s.whatsapp.net";
@@ -2,13 +2,19 @@ import {
2
2
  TaskQueueManager,
3
3
  init_task_queue
4
4
  } from "./chunk-ET6WZFPS.js";
5
+ import {
6
+ getAgentSubdir,
7
+ init_workspace
8
+ } from "./chunk-UETRFOSR.js";
5
9
  import "./chunk-KFQGP6VL.js";
6
10
 
7
11
  // src/cli-agent.ts
12
+ init_workspace();
8
13
  init_task_queue();
9
14
  import { Hono } from "hono";
10
15
  import { serve } from "@hono/node-server";
11
16
  import { existsSync, readFileSync, writeFileSync } from "fs";
17
+ import { join as _joinPath } from "path";
12
18
 
13
19
  // src/engine/task-queue-before-spawn.ts
14
20
  function extractTaskMetadata(task) {
@@ -889,7 +895,7 @@ async function runAgent(_args) {
889
895
  const agent = agentRow[0];
890
896
  console.log(` Agent: ${agent.display_name || agent.name}`);
891
897
  console.log(` State: ${agent.state}`);
892
- const routes = await import("./routes-VX5CXX4J.js");
898
+ const routes = await import("./routes-5PUCWC4N.js");
893
899
  await routes.lifecycle.setDb(engineDb);
894
900
  await routes.lifecycle.loadFromDb();
895
901
  routes.lifecycle.standaloneMode = true;
@@ -957,7 +963,7 @@ async function runAgent(_args) {
957
963
  }
958
964
  Object.assign(dbApiKeys, fresh);
959
965
  try {
960
- const routesMod = await import("./routes-VX5CXX4J.js");
966
+ const routesMod = await import("./routes-5PUCWC4N.js");
961
967
  routesMod.knowledgeBase?.setApiKeys?.(dbApiKeys);
962
968
  } catch {
963
969
  }
@@ -998,10 +1004,10 @@ async function runAgent(_args) {
998
1004
  setInterval(() => {
999
1005
  void _loadProviderKeys();
1000
1006
  }, 3e4).unref();
1001
- const { createAgentRuntime } = await import("./runtime-RMLNHLAT.js");
1007
+ const { createAgentRuntime } = await import("./runtime-GML2LXIN.js");
1002
1008
  let orgIntMgr = null;
1003
1009
  try {
1004
- const { orgIntegrations: oi } = await import("./routes-VX5CXX4J.js");
1010
+ const { orgIntegrations: oi } = await import("./routes-5PUCWC4N.js");
1005
1011
  orgIntMgr = oi;
1006
1012
  } catch {
1007
1013
  }
@@ -1388,7 +1394,7 @@ Please complete this task now.`,
1388
1394
  console.log(`[TaskPoller] Delivered recovery response to Telegram chat ${dc.chatId}`);
1389
1395
  }
1390
1396
  } else if (dc.channel === "whatsapp") {
1391
- const { getOrCreateConnection, toJid } = await import("./whatsapp-RAQUV6ZL.js");
1397
+ const { getOrCreateConnection, toJid } = await import("./whatsapp-TBOB7TDL.js");
1392
1398
  const conn = await getOrCreateConnection(agentId);
1393
1399
  if (conn.connected && conn.sock) {
1394
1400
  await conn.sock.sendMessage(toJid(dc.chatId), { text: lastText.trim() });
@@ -1590,7 +1596,7 @@ Please complete this task now.`,
1590
1596
  }
1591
1597
  if (scope === "all" || scope === "permissions") {
1592
1598
  try {
1593
- const { permissionEngine } = await import("./routes-VX5CXX4J.js");
1599
+ const { permissionEngine } = await import("./routes-5PUCWC4N.js");
1594
1600
  await permissionEngine.setDb(engineDb);
1595
1601
  reloaded.push("permissions");
1596
1602
  } catch {
@@ -1630,7 +1636,7 @@ Please complete this task now.`,
1630
1636
  }
1631
1637
  if (scope === "all" || scope === "guardrails") {
1632
1638
  try {
1633
- const { guardrails } = await import("./routes-VX5CXX4J.js");
1639
+ const { guardrails } = await import("./routes-5PUCWC4N.js");
1634
1640
  await guardrails.loadFromDb?.();
1635
1641
  reloaded.push("guardrails");
1636
1642
  } catch {
@@ -1719,7 +1725,7 @@ Please complete this task now.`,
1719
1725
  });
1720
1726
  }
1721
1727
  } else if (ctx.source === "whatsapp") {
1722
- import("./whatsapp-RAQUV6ZL.js").then(({ getConnection }) => {
1728
+ import("./whatsapp-TBOB7TDL.js").then(({ getConnection }) => {
1723
1729
  const conn = getConnection(AGENT_ID);
1724
1730
  if (!conn?.connected) return;
1725
1731
  const jid = ctx.senderEmail.includes("@") ? ctx.senderEmail : ctx.senderEmail.replace(/[^0-9]/g, "") + "@s.whatsapp.net";
@@ -2089,7 +2095,7 @@ ${ambientContext}` : ""
2089
2095
  if (isMessagingSource) {
2090
2096
  if (ctx.source === "whatsapp") {
2091
2097
  try {
2092
- const { getOrCreateConnection, toJid } = await import("./whatsapp-RAQUV6ZL.js");
2098
+ const { getOrCreateConnection, toJid } = await import("./whatsapp-TBOB7TDL.js");
2093
2099
  const conn = await getOrCreateConnection(AGENT_ID);
2094
2100
  if (conn.connected && conn.sock) {
2095
2101
  await conn.sock.sendMessage(toJid(ctx.senderEmail), { text: _stripMd(lastText) });
@@ -2343,7 +2349,7 @@ ${identity.personality.slice(0, 800)}` : "";
2343
2349
  if (defaultWaChat) waChatIds.add(String(defaultWaChat));
2344
2350
  if (waChatIds.size > 0) {
2345
2351
  try {
2346
- const { getConnection, toJid } = await import("./whatsapp-RAQUV6ZL.js");
2352
+ const { getConnection, toJid } = await import("./whatsapp-TBOB7TDL.js");
2347
2353
  const conn = await getConnection(agentId);
2348
2354
  if (conn?.connected && conn?.sock) {
2349
2355
  for (const chatId of waChatIds) {
@@ -2832,7 +2838,7 @@ Available tools: ${providerType === "imap" ? "email_send (to, subject, body)" :
2832
2838
  console.log("[guardrails] Disabled via autonomy settings");
2833
2839
  }
2834
2840
  try {
2835
- const { AgentHeartbeatManager } = await import("./agent-heartbeat-PHLWJ3HO.js");
2841
+ const { AgentHeartbeatManager } = await import("./agent-heartbeat-HFDBZWMO.js");
2836
2842
  const hbOrgRows = await engineDb.query(`SELECT org_id FROM managed_agents WHERE id = $1`, [AGENT_ID]);
2837
2843
  const hbOrgId = hbOrgRows?.[0]?.org_id || "";
2838
2844
  const hbManagerEmail = config.managerEmail || (config.manager?.type === "external" ? config.manager.email : null);
@@ -2917,7 +2923,7 @@ async function startCalendarPolling(agentId, config, runtime, _engineDb, _memory
2917
2923
  };
2918
2924
  const CALENDAR_POLL_INTERVAL = 5 * 6e4;
2919
2925
  const joinedMeetings = /* @__PURE__ */ new Set();
2920
- const joinedMeetingsFile = `/tmp/agenticmail-joined-meetings-${agentId}.json`;
2926
+ const joinedMeetingsFile = _joinPath(getAgentSubdir(agentId, "data"), "joined-meetings.json");
2921
2927
  try {
2922
2928
  if (existsSync(joinedMeetingsFile)) {
2923
2929
  const data = JSON.parse(readFileSync(joinedMeetingsFile, "utf-8"));
@@ -94,7 +94,7 @@ async function runServe(_args) {
94
94
  process.exit(1);
95
95
  }
96
96
  const { createAdapter, smartDbConfig } = await import("./factory-RUGZPU7W.js");
97
- const { createServer } = await import("./server-64K32C5T.js");
97
+ const { createServer } = await import("./server-R5SICPBI.js");
98
98
  const db = await createAdapter(smartDbConfig(DATABASE_URL));
99
99
  await db.migrate();
100
100
  const server = createServer({
@@ -120,7 +120,7 @@ async function runServe(_args) {
120
120
  });
121
121
  setTimeout(async () => {
122
122
  try {
123
- const routes = await import("./routes-VX5CXX4J.js");
123
+ const routes = await import("./routes-5PUCWC4N.js");
124
124
  setWatcherRuntime(
125
125
  () => routes.getRuntime?.() || null
126
126
  );
package/dist/cli.js CHANGED
@@ -65,14 +65,14 @@ Skill Development:
65
65
  break;
66
66
  case "serve":
67
67
  case "start":
68
- import("./cli-serve-T3W5RDO4.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
68
+ import("./cli-serve-4NLB4RK2.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
69
69
  break;
70
70
  case "agent":
71
- import("./cli-agent-V7K6HZAG.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
71
+ import("./cli-agent-AMA2R4PG.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
72
72
  break;
73
73
  case "setup":
74
74
  default:
75
- import("./setup-7AQLYQBS.js").then((m) => m.runSetupWizard()).catch(fatal);
75
+ import("./setup-SLLV37YT.js").then((m) => m.runSetupWizard()).catch(fatal);
76
76
  break;
77
77
  }
78
78
  function fatal(err) {
@@ -2,7 +2,8 @@ import {
2
2
  DeploymentEngine,
3
3
  ensurePm2,
4
4
  init_deployer
5
- } from "./chunk-TBBVEXBH.js";
5
+ } from "./chunk-QVZIW5HI.js";
6
+ import "./chunk-UETRFOSR.js";
6
7
  import "./chunk-KFQGP6VL.js";
7
8
  init_deployer();
8
9
  export {
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  provision,
15
15
  runSetupWizard
16
- } from "./chunk-5EMB2S53.js";
16
+ } from "./chunk-MVD2DMAY.js";
17
17
  import {
18
18
  AgentRuntime,
19
19
  EmailChannel,
@@ -28,7 +28,7 @@ import {
28
28
  executeTool,
29
29
  runAgentLoop,
30
30
  toolsToDefinitions
31
- } from "./chunk-NMMTMHTA.js";
31
+ } from "./chunk-GC77MDKW.js";
32
32
  import {
33
33
  ValidationError,
34
34
  auditLogger,
@@ -42,7 +42,7 @@ import {
42
42
  requireRole,
43
43
  securityHeaders,
44
44
  validate
45
- } from "./chunk-I2T4HESC.js";
45
+ } from "./chunk-IXAWHXMY.js";
46
46
  import "./chunk-DJBCRQTD.js";
47
47
  import {
48
48
  PROVIDER_REGISTRY,
@@ -83,7 +83,8 @@ import {
83
83
  init_storage_manager,
84
84
  init_tenant,
85
85
  init_workforce
86
- } from "./chunk-KQ5EU4IA.js";
86
+ } from "./chunk-VWIDJRD4.js";
87
+ import "./chunk-FQWJMPKW.js";
87
88
  import "./chunk-K2GKUQSB.js";
88
89
  import "./chunk-TK55CSBH.js";
89
90
  import {
@@ -96,6 +97,12 @@ import {
96
97
  sqliteToMySQL,
97
98
  sqliteToPostgres
98
99
  } from "./chunk-CZPHXLRP.js";
100
+ import {
101
+ AgentConfigGenerator,
102
+ DeploymentEngine,
103
+ init_agent_config,
104
+ init_deployer
105
+ } from "./chunk-QVZIW5HI.js";
99
106
  import "./chunk-Z7NVD3OQ.js";
100
107
  import {
101
108
  AgentMemoryManager,
@@ -105,19 +112,13 @@ import "./chunk-AF3WSNVX.js";
105
112
  import "./chunk-V6QTSKGO.js";
106
113
  import "./chunk-74ZCQKYU.js";
107
114
  import "./chunk-ET6WZFPS.js";
108
- import "./chunk-FQWJMPKW.js";
115
+ import "./chunk-UETRFOSR.js";
109
116
  import {
110
117
  BUILTIN_SKILLS,
111
118
  PRESET_PROFILES,
112
119
  PermissionEngine,
113
120
  init_skills
114
121
  } from "./chunk-HGBLI5HF.js";
115
- import {
116
- AgentConfigGenerator,
117
- DeploymentEngine,
118
- init_agent_config,
119
- init_deployer
120
- } from "./chunk-TBBVEXBH.js";
121
122
  import "./chunk-FLQ5FLHW.js";
122
123
  import "./chunk-GBW6SJPH.js";
123
124
  import "./chunk-X5IZUXDC.js";
@@ -2,7 +2,7 @@ import {
2
2
  createMeetingTools,
3
3
  ensureBrowser,
4
4
  sendChatMessage
5
- } from "./chunk-CC4BHZHO.js";
5
+ } from "./chunk-GAOEALTJ.js";
6
6
  import "./chunk-X5IZUXDC.js";
7
7
  import "./chunk-KFQGP6VL.js";
8
8
  export {
@@ -37,18 +37,19 @@ import {
37
37
  tenants,
38
38
  vault,
39
39
  workforce
40
- } from "./chunk-KQ5EU4IA.js";
40
+ } from "./chunk-VWIDJRD4.js";
41
+ import "./chunk-FQWJMPKW.js";
41
42
  import "./chunk-K2GKUQSB.js";
42
43
  import "./chunk-TK55CSBH.js";
44
+ import "./chunk-QVZIW5HI.js";
43
45
  import "./chunk-Z7NVD3OQ.js";
44
46
  import "./chunk-VSBC4SWO.js";
45
47
  import "./chunk-AF3WSNVX.js";
46
48
  import "./chunk-V6QTSKGO.js";
47
49
  import "./chunk-74ZCQKYU.js";
48
50
  import "./chunk-ET6WZFPS.js";
49
- import "./chunk-FQWJMPKW.js";
51
+ import "./chunk-UETRFOSR.js";
50
52
  import "./chunk-HGBLI5HF.js";
51
- import "./chunk-TBBVEXBH.js";
52
53
  import "./chunk-FLQ5FLHW.js";
53
54
  import "./chunk-WUAWWKTN.js";
54
55
  import "./chunk-YDD5TC5Q.js";
@@ -16,7 +16,7 @@ import {
16
16
  runAgentLoop,
17
17
  toolsToDefinitions,
18
18
  truncateToolResults
19
- } from "./chunk-NMMTMHTA.js";
19
+ } from "./chunk-GC77MDKW.js";
20
20
  import {
21
21
  PROVIDER_REGISTRY,
22
22
  listAllProviders,
@@ -24,6 +24,7 @@ import {
24
24
  resolveProvider
25
25
  } from "./chunk-FP7JCKYO.js";
26
26
  import "./chunk-BBM4POWP.js";
27
+ import "./chunk-UETRFOSR.js";
27
28
  import "./chunk-KFQGP6VL.js";
28
29
  export {
29
30
  AgentRuntime,
@@ -1,20 +1,21 @@
1
1
  import {
2
2
  createServer
3
- } from "./chunk-I2T4HESC.js";
3
+ } from "./chunk-IXAWHXMY.js";
4
4
  import "./chunk-DJBCRQTD.js";
5
5
  import "./chunk-FP7JCKYO.js";
6
- import "./chunk-KQ5EU4IA.js";
6
+ import "./chunk-VWIDJRD4.js";
7
+ import "./chunk-FQWJMPKW.js";
7
8
  import "./chunk-K2GKUQSB.js";
8
9
  import "./chunk-TK55CSBH.js";
10
+ import "./chunk-QVZIW5HI.js";
9
11
  import "./chunk-Z7NVD3OQ.js";
10
12
  import "./chunk-VSBC4SWO.js";
11
13
  import "./chunk-AF3WSNVX.js";
12
14
  import "./chunk-V6QTSKGO.js";
13
15
  import "./chunk-74ZCQKYU.js";
14
16
  import "./chunk-ET6WZFPS.js";
15
- import "./chunk-FQWJMPKW.js";
17
+ import "./chunk-UETRFOSR.js";
16
18
  import "./chunk-HGBLI5HF.js";
17
- import "./chunk-TBBVEXBH.js";
18
19
  import "./chunk-FLQ5FLHW.js";
19
20
  import "./chunk-GBW6SJPH.js";
20
21
  import "./chunk-X5IZUXDC.js";
@@ -6,7 +6,7 @@ import {
6
6
  promptRegistration,
7
7
  provision,
8
8
  runSetupWizard
9
- } from "./chunk-5EMB2S53.js";
9
+ } from "./chunk-MVD2DMAY.js";
10
10
  import "./chunk-UQRQ2JN3.js";
11
11
  import "./chunk-KFQGP6VL.js";
12
12
  export {
@@ -5,7 +5,7 @@ import {
5
5
  init_telegram,
6
6
  pollTelegramUpdates,
7
7
  setTelegramWebhook
8
- } from "./chunk-REAJCMQE.js";
8
+ } from "./chunk-T26AVIAQ.js";
9
9
  import "./chunk-KFQGP6VL.js";
10
10
  init_telegram();
11
11
  export {
@@ -12,7 +12,7 @@ import {
12
12
  onWhatsAppMessage,
13
13
  sendTestMessage,
14
14
  toJid
15
- } from "./chunk-BUKTZ35L.js";
15
+ } from "./chunk-H3JXMBTG.js";
16
16
  import "./chunk-KFQGP6VL.js";
17
17
  init_whatsapp();
18
18
  export {
@@ -0,0 +1,19 @@
1
+ import {
2
+ WORKSPACE_SUBDIRS,
3
+ ensureAgentWorkspace,
4
+ getAgentSubdir,
5
+ getAgentWorkspaceDir,
6
+ getWorkspaceBase,
7
+ init_workspace,
8
+ renderWorkspaceMarkdown
9
+ } from "./chunk-UETRFOSR.js";
10
+ import "./chunk-KFQGP6VL.js";
11
+ init_workspace();
12
+ export {
13
+ WORKSPACE_SUBDIRS,
14
+ ensureAgentWorkspace,
15
+ getAgentSubdir,
16
+ getAgentWorkspaceDir,
17
+ getWorkspaceBase,
18
+ renderWorkspaceMarkdown
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/enterprise",
3
- "version": "0.5.612",
3
+ "version": "0.5.613",
4
4
  "description": "AgenticMail Enterprise — cloud-hosted AI agent identity, email, auth & compliance for organizations",
5
5
  "type": "module",
6
6
  "bin": {
File without changes