@trops/dash-core 0.1.654 → 0.1.655

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.
@@ -76904,11 +76904,21 @@ var PauseController_1 = PauseController$1;
76904
76904
  * v1; SQLite can later slot in behind this exact interface if volume demands.
76905
76905
  */
76906
76906
 
76907
- const VALID_SCOPES = ["workspace", "global"];
76907
+ const VALID_SCOPES = ["workspace", "global", "bot"];
76908
76908
 
76909
- /** Bucket key for a (scope, id) pair. Global collapses all ids to one bucket. */
76909
+ /**
76910
+ * Bucket key for a (scope, id) pair. Global collapses all ids to one bucket;
76911
+ * "workspace" is a team's shared memory (id = the dashboard); "bot" is one
76912
+ * bot's private memory (id = the bot) — used by bots with no dashboard, so
76913
+ * they don't share one bucket.
76914
+ */
76910
76915
  function bucketKey(scope, id) {
76911
- return scope === "global" ? "global" : `workspace:${id || "default"}`;
76916
+ if (scope === "global") return "global";
76917
+ if (scope === "bot") {
76918
+ if (!id) throw new Error("BotMemory: the 'bot' scope needs a bot id");
76919
+ return `bot:${id}`;
76920
+ }
76921
+ return `workspace:${id || "default"}`;
76912
76922
  }
76913
76923
 
76914
76924
  let BotMemory$1 = class BotMemory {
@@ -76969,6 +76979,21 @@ let BotMemory$1 = class BotMemory {
76969
76979
  }
76970
76980
 
76971
76981
  /** @returns {boolean} true if a value was removed. */
76982
+ /**
76983
+ * A bot was deleted: drop its private memory (the "bot" scope). Team and
76984
+ * global memory are shared, so they're never touched.
76985
+ * @returns {boolean} whether there was anything to remove
76986
+ */
76987
+ forgetBot(botId) {
76988
+ if (!botId) return false;
76989
+ const blob = this._read();
76990
+ const key = bucketKey("bot", botId);
76991
+ if (!blob.scopes[key]) return false;
76992
+ delete blob.scopes[key];
76993
+ this._write(blob);
76994
+ return true;
76995
+ }
76996
+
76972
76997
  delete(scope, id, key) {
76973
76998
  const blob = this._read();
76974
76999
  const bucket = blob.scopes[bucketKey(scope, id)];
@@ -77000,7 +77025,7 @@ const SCOPE_PROP = {
77000
77025
  type: "string",
77001
77026
  enum: ["workspace", "global"],
77002
77027
  description:
77003
- "Which memory scope to use: 'workspace' (default, isolated to this bot's workspace) or 'global' (shared across your bots).",
77028
+ "Which memory scope to use: 'workspace' (default — your team's shared memory, or private to you if you're not on a dashboard's team) or 'global' (shared across all your bots).",
77004
77029
  };
77005
77030
 
77006
77031
  const MEMORY_TOOLS$1 = [
@@ -77070,31 +77095,46 @@ function fail$2(text) {
77070
77095
  /**
77071
77096
  * Execute a memory_* tool call in-process.
77072
77097
  * @param {import("./BotMemory").BotMemory} memory
77073
- * @param {{ workspaceId?: string }} ctx the calling bot's scope context
77098
+ * @param {{ workspaceId?: string|number, botId?: string }} ctx the calling bot
77074
77099
  * @param {string} toolName
77075
77100
  * @param {object} args
77076
77101
  * @returns {{ text: string, isError: boolean }}
77077
77102
  */
77078
77103
  function handleMemoryTool$1(memory, ctx, toolName, args = {}) {
77079
- const scope = args && args.scope === "global" ? "global" : "workspace";
77080
- const id = ctx && ctx.workspaceId;
77104
+ // "workspace" is the team's shared memory; a bot with no dashboard gets its
77105
+ // own private bucket instead of sharing one with every other such bot.
77106
+ const ws = ctx && ctx.workspaceId;
77107
+ const onTeam = ws !== null && ws !== undefined && ws !== "";
77108
+ let scope;
77109
+ let id;
77110
+ if (args && args.scope === "global") {
77111
+ scope = "global";
77112
+ id = null;
77113
+ } else if (onTeam) {
77114
+ scope = "workspace";
77115
+ id = String(ws);
77116
+ } else {
77117
+ scope = "bot";
77118
+ id = ctx && ctx.botId;
77119
+ }
77120
+ const label = scope === "bot" ? "private" : scope;
77081
77121
  try {
77082
77122
  switch (toolName) {
77083
77123
  case "memory_set": {
77084
77124
  if (!args || !args.key) return fail$2("memory_set requires a 'key'.");
77085
77125
  const entry = memory.set(scope, id, args.key, args.value);
77086
- return ok$2(`Stored '${args.key}' (${scope}, v${entry.version}).`);
77126
+ return ok$2(`Stored '${args.key}' (${label}, v${entry.version}).`);
77087
77127
  }
77088
77128
  case "memory_get": {
77089
77129
  if (!args || !args.key) return fail$2("memory_get requires a 'key'.");
77090
77130
  const value = memory.get(scope, id, args.key);
77091
77131
  if (value === undefined)
77092
- return ok$2(`No value stored for '${args.key}' (${scope}).`);
77132
+ return ok$2(`No value stored for '${args.key}' (${label}).`);
77093
77133
  return ok$2(typeof value === "string" ? value : JSON.stringify(value));
77094
77134
  }
77095
77135
  case "memory_list": {
77096
77136
  const entries = memory.list(scope, id, args && args.prefix);
77097
- if (!entries.length) return ok$2(`No memory keys stored (${scope}).`);
77137
+ if (!entries.length) return ok$2(`No memory keys stored (${label}).`);
77098
77138
  return ok$2(entries.map((e) => `${e.key} (v${e.version})`).join("\n"));
77099
77139
  }
77100
77140
  case "memory_delete": {
@@ -77102,8 +77142,8 @@ function handleMemoryTool$1(memory, ctx, toolName, args = {}) {
77102
77142
  const removed = memory.delete(scope, id, args.key);
77103
77143
  return ok$2(
77104
77144
  removed
77105
- ? `Deleted '${args.key}' (${scope}).`
77106
- : `No value to delete for '${args.key}' (${scope}).`,
77145
+ ? `Deleted '${args.key}' (${label}).`
77146
+ : `No value to delete for '${args.key}' (${label}).`,
77107
77147
  );
77108
77148
  }
77109
77149
  default:
@@ -78297,6 +78337,9 @@ const botController$1 = {
78297
78337
  if (isLead(bot) && bot.workspaceId) {
78298
78338
  this._store.setTeamSettings(bot.workspaceId, { leadEnabled: false });
78299
78339
  }
78340
+ // Its private memory (bots with no dashboard) goes with it; team and
78341
+ // global memory are shared and stay.
78342
+ this._memory.forgetBot(botId);
78300
78343
  return this._store.delete(botId);
78301
78344
  },
78302
78345
 
@@ -78755,7 +78798,7 @@ const botController$1 = {
78755
78798
  if (serverName === MEMORY_SERVER) {
78756
78799
  return handleMemoryTool(
78757
78800
  this._memory,
78758
- { workspaceId: opts.workspaceId },
78801
+ { workspaceId: opts.workspaceId, botId: opts.botId },
78759
78802
  toolName,
78760
78803
  args,
78761
78804
  );