@primusclaw/personal-agent-teams 0.14.0 → 0.15.1

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.
package/dist/index.js CHANGED
@@ -3216,6 +3216,25 @@ function statusCard(view) {
3216
3216
  return message([...lead, top, ...lines], view.buttons.map(remoteAction), view.buttonsMax);
3217
3217
  }
3218
3218
 
3219
+ // packages/teams/src/views/remote/terminal-end-card.ts
3220
+ function commandAction(button) {
3221
+ return { type: "Action.Submit", title: button.title, data: { msteams: { type: "imBack", value: button.command } } };
3222
+ }
3223
+ function terminalEndCard(view) {
3224
+ const body = [
3225
+ header(view.title, {
3226
+ tone: view.failed ? "attention" : "good",
3227
+ emoji: view.failed ? "failed" : "good",
3228
+ subtitle: view.where
3229
+ })
3230
+ ];
3231
+ for (const line2 of view.earlier) body.push(block(line2, { spacing: "Small", weight: "Bolder" }));
3232
+ if (view.summary) body.push(block(view.summary, { spacing: "Small" }));
3233
+ if (view.full) body.push(...fold("end-full", [block(view.full, { spacing: "Small" })], view.fullLabel));
3234
+ if (view.rest) body.push(note(view.rest));
3235
+ return message(body, view.buttons.map(commandAction));
3236
+ }
3237
+
3219
3238
  // packages/teams/src/views/remote/window-card.ts
3220
3239
  import { pyStrip as pyStrip3 } from "@primusclaw/personal-agent";
3221
3240
  var WINDOW_BUTTONS_MAX = 4;
@@ -3305,6 +3324,7 @@ var REMOTE_RENDERERS = {
3305
3324
  remotePermission: permissionCard,
3306
3325
  remoteAsk: remoteAskCard,
3307
3326
  terminalAsk: terminalAskCard,
3327
+ terminalEnd: terminalEndCard,
3308
3328
  remoteDecided: decidedCard,
3309
3329
  remoteDisconnect: disconnectCard,
3310
3330
  remoteTakeover: takeoverCard,
@@ -4993,6 +5013,23 @@ function toBotPattern(botName) {
4993
5013
  function addressedToBot(activity, botName = DEFAULT_BOT_NAME) {
4994
5014
  return toBotPattern(botName).test(written(activity));
4995
5015
  }
5016
+ var typedName = /* @__PURE__ */ new Map();
5017
+ function typedNamePattern(botName) {
5018
+ let pattern = typedName.get(botName);
5019
+ if (pattern === void 0) {
5020
+ pattern = new RegExp(
5021
+ `^${SPACE}*@?${caseless(botName)}(?![\\p{L}\\p{N}_-])${SPACE}+(?=/\\p{L}[\\p{L}\\p{N}_-]*(?:${SPACE}|$))`,
5022
+ "u"
5023
+ );
5024
+ typedName.set(botName, pattern);
5025
+ }
5026
+ return pattern;
5027
+ }
5028
+ function withoutTypedBotName(text4, botName) {
5029
+ const named = typedNamePattern(botName).exec(text4);
5030
+ if (named === null) return { text: text4, removed: 0 };
5031
+ return { text: text4.slice(named[0].length), removed: cpLength7(named[0]) };
5032
+ }
4996
5033
  function messageText(activity) {
4997
5034
  let text4 = written(activity);
4998
5035
  const botId = botIdOf(activity);
@@ -5109,15 +5146,23 @@ function messageOf(activity, sender, options) {
5109
5146
  logPlaceholderQuotes(activity, found, logger);
5110
5147
  logUnreadKinds(activity, logger);
5111
5148
  const bot = partOf(activity, "recipient");
5149
+ const botName = options.botName ?? DEFAULT_BOT_NAME;
5150
+ const said = withoutTypedBotName(
5151
+ forwarded.forwards.length && !forwardsInText(activity) ? ownWords(messageText(activity), forwarded.forwards, /<attachment\b/iu.test(pyStr14(activity.text))) : messageText(activity),
5152
+ botName
5153
+ );
5112
5154
  return {
5113
5155
  type: "message",
5114
5156
  ...base(activity, sender),
5115
- text: forwarded.forwards.length && !forwardsInText(activity) ? ownWords(messageText(activity), forwarded.forwards, /<attachment\b/iu.test(pyStr14(activity.text))) : messageText(activity),
5157
+ text: said.text,
5116
5158
  mentioned: isMentioned(activity),
5117
5159
  targeted: isTargeted(activity),
5118
- namesBotFirst: addressedToBot(activity, options.botName ?? DEFAULT_BOT_NAME),
5160
+ // (a name taken off the text, with its @ or without, is the person naming the bot: an attached chat keeps those words for the bot, so
5161
+ // "<name> /clear" is not sent bare as "/clear" to the agent while "@<name> /clear" stays with the bot)
5162
+ namesBotFirst: said.removed > 0 || addressedToBot(activity, botName),
5119
5163
  conversationName: personal ? "" : pyStr14(partOf(activity, "conversation")["name"]),
5120
- mentions: mentionsOf(activity),
5164
+ // (the offsets are in the text: where the name typed ahead stood is not there any more)
5165
+ mentions: mentionsOf(activity).filter((m) => m.offset >= said.removed).map((m) => ({ ...m, offset: m.offset - said.removed })),
5121
5166
  links: inboundLinksOf(activity),
5122
5167
  quotes: found.map((q) => ({
5123
5168
  author: q.sender,
package/dist/main.js CHANGED
@@ -1208,6 +1208,23 @@ function toBotPattern(botName) {
1208
1208
  function addressedToBot(activity, botName = DEFAULT_BOT_NAME) {
1209
1209
  return toBotPattern(botName).test(written(activity));
1210
1210
  }
1211
+ var typedName = /* @__PURE__ */ new Map();
1212
+ function typedNamePattern(botName) {
1213
+ let pattern = typedName.get(botName);
1214
+ if (pattern === void 0) {
1215
+ pattern = new RegExp(
1216
+ `^${SPACE}*@?${caseless(botName)}(?![\\p{L}\\p{N}_-])${SPACE}+(?=/\\p{L}[\\p{L}\\p{N}_-]*(?:${SPACE}|$))`,
1217
+ "u"
1218
+ );
1219
+ typedName.set(botName, pattern);
1220
+ }
1221
+ return pattern;
1222
+ }
1223
+ function withoutTypedBotName(text4, botName) {
1224
+ const named = typedNamePattern(botName).exec(text4);
1225
+ if (named === null) return { text: text4, removed: 0 };
1226
+ return { text: text4.slice(named[0].length), removed: cpLength2(named[0]) };
1227
+ }
1211
1228
  function messageText(activity) {
1212
1229
  let text4 = written(activity);
1213
1230
  const botId = botIdOf(activity);
@@ -1324,15 +1341,23 @@ function messageOf(activity, sender, options) {
1324
1341
  logPlaceholderQuotes(activity, found, logger);
1325
1342
  logUnreadKinds(activity, logger);
1326
1343
  const bot = partOf(activity, "recipient");
1344
+ const botName = options.botName ?? DEFAULT_BOT_NAME;
1345
+ const said = withoutTypedBotName(
1346
+ forwarded.forwards.length && !forwardsInText(activity) ? ownWords(messageText(activity), forwarded.forwards, /<attachment\b/iu.test(pyStr11(activity.text))) : messageText(activity),
1347
+ botName
1348
+ );
1327
1349
  return {
1328
1350
  type: "message",
1329
1351
  ...base(activity, sender),
1330
- text: forwarded.forwards.length && !forwardsInText(activity) ? ownWords(messageText(activity), forwarded.forwards, /<attachment\b/iu.test(pyStr11(activity.text))) : messageText(activity),
1352
+ text: said.text,
1331
1353
  mentioned: isMentioned(activity),
1332
1354
  targeted: isTargeted(activity),
1333
- namesBotFirst: addressedToBot(activity, options.botName ?? DEFAULT_BOT_NAME),
1355
+ // (a name taken off the text, with its @ or without, is the person naming the bot: an attached chat keeps those words for the bot, so
1356
+ // "<name> /clear" is not sent bare as "/clear" to the agent while "@<name> /clear" stays with the bot)
1357
+ namesBotFirst: said.removed > 0 || addressedToBot(activity, botName),
1334
1358
  conversationName: personal ? "" : pyStr11(partOf(activity, "conversation")["name"]),
1335
- mentions: mentionsOf(activity),
1359
+ // (the offsets are in the text: where the name typed ahead stood is not there any more)
1360
+ mentions: mentionsOf(activity).filter((m) => m.offset >= said.removed).map((m) => ({ ...m, offset: m.offset - said.removed })),
1336
1361
  links: inboundLinksOf(activity),
1337
1362
  quotes: found.map((q) => ({
1338
1363
  author: q.sender,
@@ -6275,6 +6300,25 @@ function statusCard(view) {
6275
6300
  return message([...lead, top, ...lines], view.buttons.map(remoteAction2), view.buttonsMax);
6276
6301
  }
6277
6302
 
6303
+ // packages/teams/src/views/remote/terminal-end-card.ts
6304
+ function commandAction(button) {
6305
+ return { type: "Action.Submit", title: button.title, data: { msteams: { type: "imBack", value: button.command } } };
6306
+ }
6307
+ function terminalEndCard(view) {
6308
+ const body = [
6309
+ header(view.title, {
6310
+ tone: view.failed ? "attention" : "good",
6311
+ emoji: view.failed ? "failed" : "good",
6312
+ subtitle: view.where
6313
+ })
6314
+ ];
6315
+ for (const line2 of view.earlier) body.push(block(line2, { spacing: "Small", weight: "Bolder" }));
6316
+ if (view.summary) body.push(block(view.summary, { spacing: "Small" }));
6317
+ if (view.full) body.push(...fold("end-full", [block(view.full, { spacing: "Small" })], view.fullLabel));
6318
+ if (view.rest) body.push(note(view.rest));
6319
+ return message(body, view.buttons.map(commandAction));
6320
+ }
6321
+
6278
6322
  // packages/teams/src/views/remote/window-card.ts
6279
6323
  import { pyStrip as pyStrip14 } from "@primusclaw/personal-agent";
6280
6324
  var WINDOW_BUTTONS_MAX = 4;
@@ -6364,6 +6408,7 @@ var REMOTE_RENDERERS = {
6364
6408
  remotePermission: permissionCard,
6365
6409
  remoteAsk: remoteAskCard,
6366
6410
  terminalAsk: terminalAskCard,
6411
+ terminalEnd: terminalEndCard,
6367
6412
  remoteDecided: decidedCard,
6368
6413
  remoteDisconnect: disconnectCard,
6369
6414
  remoteTakeover: takeoverCard,
@@ -22,6 +22,18 @@ export declare function isTargeted(activity: Activity): boolean;
22
22
  * the person says these words are for the bot and not for the session.
23
23
  */
24
24
  export declare function addressedToBot(activity: Activity, botName?: string): boolean;
25
+ /**
26
+ * `text` without the bot's name typed as words ahead of a command (`@<name> /approvals`, `<name> /approvals`), and how many code points
27
+ * that took off its start. A mention a person picks is an entity, which `messageText` drops; one Teams on a phone sends as plain words
28
+ * (2026-11-26 03:24: "@<name> /approvals") has none, so it stayed in the text and `/approvals` was read as a sentence, not as the
29
+ * command. Only the name first and a command word after it: any other words, the name alone, a word that merely starts with the name
30
+ * and a path (`/tmp/app.log`) stay as they were typed, so no ordinary chat becomes a command. A name taken off here, with its @ or without,
31
+ * is the person naming the bot, so the caller also reads the message as naming the bot first (`addressedToBot` reads only the @ form).
32
+ */
33
+ export declare function withoutTypedBotName(text: string, botName: string): {
34
+ readonly text: string;
35
+ readonly removed: number;
36
+ };
25
37
  /**
26
38
  * The person's text without the bot's @mention markup and without what Teams adds for a quote: the words the commands
27
39
  * are read from. With no recipient id every mention is removed (the 1:1 behaviour); in a group chat a mention of
@@ -6,7 +6,8 @@ export { connectBlocks, sessionsCard } from "./sessions-card.js";
6
6
  export { disconnectButtons, disconnectCard, machineChoiceCard, modeCard, takeoverCard } from "./small-cards.js";
7
7
  export { hiddenCard } from "./hidden-card.js";
8
8
  export { statusCard } from "./status-card.js";
9
+ export { commandAction, terminalEndCard } from "./terminal-end-card.js";
9
10
  export { windowCard } from "./window-card.js";
10
- type RemoteRenderers = Pick<Renderers, "remoteAgents" | "remoteSessions" | "remoteStatus" | "remotePermission" | "remoteAsk" | "terminalAsk" | "remoteDecided" | "remoteDisconnect" | "remoteTakeover" | "remoteMachineChoice" | "remoteMode" | "remoteWindow" | "remoteHidden">;
11
+ type RemoteRenderers = Pick<Renderers, "remoteAgents" | "remoteSessions" | "remoteStatus" | "remotePermission" | "remoteAsk" | "terminalAsk" | "terminalEnd" | "remoteDecided" | "remoteDisconnect" | "remoteTakeover" | "remoteMachineChoice" | "remoteMode" | "remoteWindow" | "remoteHidden">;
11
12
  /** The remote-agent renderers. */
12
13
  export declare const REMOTE_RENDERERS: RemoteRenderers;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The card of a turn that ended in a terminal while nobody was at it: the conversation's name and status as the title, the tool, machine,
3
+ * folder and item number in one small line under it, an earlier turn that asked the person something or failed (when one did), what the
4
+ * agent did, its whole last answer folded behind "Show all", and buttons
5
+ * that send the commands for it as the person's own message (an imBack: the command is handled exactly as if typed).
6
+ */
7
+ import type { remoteView } from "@primusclaw/personal-agent";
8
+ import type { CardElement } from "../../cards/json.js";
9
+ import { type CardMessage } from "../../cards/kit.js";
10
+ /** A button that sends `command` into the chat as the person's own message. */
11
+ export declare function commandAction(button: remoteView.CommandButton): CardElement;
12
+ export declare function terminalEndCard(view: remoteView.TerminalEndView): CardMessage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent-teams",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "description": "The personal agent on Microsoft Teams: activities, Adaptive Cards, streams, Bot Connector, inbound queue, and the worker's Teams surface.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,8 +35,8 @@
35
35
  "dependencies": {
36
36
  "@azure/core-auth": "^1.11.0",
37
37
  "@azure/service-bus": "^7.10.0",
38
- "@primusclaw/personal-agent": "0.14.0",
39
- "@primusclaw/personal-agent-runtime": "0.14.0",
38
+ "@primusclaw/personal-agent": "0.15.1",
39
+ "@primusclaw/personal-agent-runtime": "0.15.1",
40
40
  "zod": "^4.6.7"
41
41
  },
42
42
  "devDependencies": {