@primusclaw/personal-agent-teams 0.4.0 → 0.6.0

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
@@ -1804,7 +1804,8 @@ var TeamsConversation = class {
1804
1804
  return envelope("send", reference(this.ref), this.prepare(activityOf(message2, this.parts.render)));
1805
1805
  }
1806
1806
  async deliver(stored) {
1807
- await this.publish(asEnvelope(stored));
1807
+ const delivered = await this.publish(asEnvelope(stored));
1808
+ return delivered?.activityId || void 0;
1808
1809
  }
1809
1810
  async send(message2) {
1810
1811
  await this.deliver(this.outgoing(message2));
@@ -2182,8 +2183,40 @@ function confirmWrite(model) {
2182
2183
  buttons([button(model.allowLabel || t.confirm, "allow"), button(t.deny, "deny")])
2183
2184
  );
2184
2185
  }
2186
+ function choiceCard(model) {
2187
+ const lang = cardLang(model.lang, model.text, ...model.options);
2188
+ const t = assistantCardText.in(lang);
2189
+ const body = [
2190
+ header(model.multiple ? t.choiceTitleMany : t.choiceTitle, { tone: "accent", emoji: "question" })
2191
+ ];
2192
+ if (model.text) body.push(text(model.text));
2193
+ body.push({
2194
+ type: "Input.ChoiceSet",
2195
+ id: "choice",
2196
+ style: "expanded",
2197
+ isMultiSelect: model.multiple,
2198
+ choices: model.options.map((option, i) => ({ title: clip(option, LABEL_MAX), value: String(i) }))
2199
+ });
2200
+ if (model.note) body.push(text(model.note, { weight: "Bolder" }));
2201
+ body.push(note(t.choiceTyped));
2202
+ const send = execute(t.choiceSend, "primusclaw.assistant_choice", {
2203
+ primusclaw: "assistant_choice",
2204
+ card: model.cardId
2205
+ });
2206
+ return message(body, buttons([send]));
2207
+ }
2208
+ function choiceChosen(model) {
2209
+ const lang = cardLang(model.lang, model.text, ...model.chosen);
2210
+ const t = assistantCardText.in(lang);
2211
+ const answer = model.chosen.join(t.choiceJoin);
2212
+ const body = [header(t.choiceSent({ answer: clip(answer, TITLE_MAX) }), { tone: "good", emoji: "good" })];
2213
+ if (model.text) body.push(text(model.text, { subtle: true }));
2214
+ return message(body);
2215
+ }
2185
2216
  var assistantRenderers = {
2186
2217
  actionCard,
2218
+ choiceCard,
2219
+ choiceChosen,
2187
2220
  board,
2188
2221
  confirmWrite,
2189
2222
  workCard,
@@ -2282,6 +2315,7 @@ function questionCard(model) {
2282
2315
  header(t.questionTitle, { tone: "accent", subtitle: model.note, emoji: "question" }),
2283
2316
  ...model.questions.flatMap((q, i) => questionInputs(q, i, t))
2284
2317
  ];
2318
+ if (model.typedReply === true) body.push(note(model.group ? t.questionReplyGroup : t.questionReply));
2285
2319
  if (model.group) body.push(note(t.questionOnly({ who: model.ownerName || t.questionAsker })));
2286
2320
  return message(body, [answerButton(model.sessionId, model.toolUseId, model.questions)]);
2287
2321
  }
@@ -2302,12 +2336,21 @@ function approvalExpired(model) {
2302
2336
  return message([header(t.expired, { tone: "attention", emoji: "expired" }), text(line2, { subtle: true })]);
2303
2337
  }
2304
2338
  function questionAnswered(model) {
2339
+ if (model.replied !== void 0) return questionReplied(model, model.replied);
2305
2340
  const said = proactiveText.in("en").answered({ at: clockText(model.when, model.zone) });
2306
2341
  return message([
2307
2342
  header(said, { tone: "good", emoji: "good" }),
2308
2343
  ...model.answers.map(([, answer]) => text(clip(answer, ANSWER_SHOWN_MAX)))
2309
2344
  ]);
2310
2345
  }
2346
+ function questionReplied(model, lang) {
2347
+ const t = approvalText.in(lang);
2348
+ const answer = [...new Set(model.answers.map(([, a]) => a))].join(" / ");
2349
+ return message([
2350
+ header(t.questionReplied({ answer: clip(answer, TITLE_MAX) }), { tone: "good", emoji: "good" }),
2351
+ note(t.questionRepliedAt({ at: clockText(model.when, model.zone) }))
2352
+ ]);
2353
+ }
2311
2354
  function approvalAgain(model) {
2312
2355
  return noteCard(
2313
2356
  model.text,
@@ -6011,6 +6054,7 @@ import {
6011
6054
  clientLocaleOf,
6012
6055
  agentActionAllowed,
6013
6056
  AssistantActions,
6057
+ AssistantChoiceClicks,
6014
6058
  AssistantChatService,
6015
6059
  Board,
6016
6060
  commandArgs,
@@ -6286,7 +6330,8 @@ function assistantParts(base2, inputs) {
6286
6330
  });
6287
6331
  const watch = new WatchClicks({ store, claw: claw.workItems, exchange, logger });
6288
6332
  const linked = (userId) => store.links.getKey(userId) !== null;
6289
- const clicks = [new WorkCardClicks(work, watch, exchange, linked, logger), actionClicks(actions)];
6333
+ const choices = new AssistantChoiceClicks({ store, deliver: (message2) => hooks.typed(message2), logger });
6334
+ const clicks = [new WorkCardClicks(work, watch, exchange, linked, logger), actionClicks(actions), choices];
6290
6335
  return { subs, chat: assistant, board: board2, receipts, directChat, actions, clicks };
6291
6336
  }
6292
6337
 
@@ -6340,7 +6385,9 @@ function proactiveParts(base2, style, assistant, errors, router) {
6340
6385
  const deps = {
6341
6386
  store,
6342
6387
  conversationFor: conversationFor(base2),
6343
- deliverStored: (envelope2) => surface.conversation(refOf(envelope2["reference"] ?? {})).deliver(envelope2),
6388
+ deliverStored: async (envelope2) => {
6389
+ await surface.conversation(refOf(envelope2["reference"] ?? {})).deliver(envelope2);
6390
+ },
6344
6391
  messageIds: surface.caps.messageIds,
6345
6392
  say: new SayPlanner({
6346
6393
  store,
@@ -6763,6 +6810,7 @@ function approvalClicks(base2, guard, hooks) {
6763
6810
  // packages/teams/src/assembly/features-w8.ts
6764
6811
  import { createHash as createHash3 } from "node:crypto";
6765
6812
  import {
6813
+ chatCredentialOf,
6766
6814
  DailyBrief,
6767
6815
  FeedbackFlow,
6768
6816
  FeedbackReporting,
@@ -6846,7 +6894,9 @@ function w8Parts(base2, options) {
6846
6894
  reporting,
6847
6895
  sessions: store.sessions,
6848
6896
  claw: { sessions: claw.sessions, assistant: claw.assistant },
6849
- credential,
6897
+ // A vote is cast as the person's chats run: someone bound but never linked has no key, and their turns run on the
6898
+ // exchanged token, so a key-only vote was never recorded for them.
6899
+ credential: chatCredentialOf(store.links, settings2.exchange.forChat ? base2.exchange : void 0),
6850
6900
  assistantOn: options.assistantOn,
6851
6901
  sha256Hex: (text4) => createHash3("sha256").update(text4, "utf8").digest("hex"),
6852
6902
  mask: mask2,
@@ -6948,7 +6998,8 @@ function lateHooks(get3) {
6948
6998
  const router = get3();
6949
6999
  return router.commands.run(text4, router.chat(sender, conversation), key);
6950
7000
  },
6951
- background: (userId) => get3().ctx.credentials.background(userId)
7001
+ background: (userId) => get3().ctx.credentials.background(userId),
7002
+ typed: (message2) => get3().handle(message2)
6952
7003
  };
6953
7004
  }
6954
7005
  function routerDeps(base2, built, errors) {
@@ -7339,6 +7390,7 @@ var workAction = reader("work");
7339
7390
  var observeAction = reader("observe");
7340
7391
  var assistantActionClick = reader("assistant_action");
7341
7392
  var assistantConfirmClick = reader("assistant_confirm");
7393
+ var assistantChoiceClick = reader("assistant_choice");
7342
7394
  var githubConfirmAction = reader("github_confirm");
7343
7395
  var githubModeAction = reader("github_mode");
7344
7396
  var githubConnectAction = reader("github_connect");
package/dist/main.js CHANGED
@@ -3033,7 +3033,8 @@ var TeamsConversation = class {
3033
3033
  return envelope("send", reference(this.ref), this.prepare(activityOf(message2, this.parts.render)));
3034
3034
  }
3035
3035
  async deliver(stored) {
3036
- await this.publish(asEnvelope(stored));
3036
+ const delivered = await this.publish(asEnvelope(stored));
3037
+ return delivered?.activityId || void 0;
3037
3038
  }
3038
3039
  async send(message2) {
3039
3040
  await this.deliver(this.outgoing(message2));
@@ -3651,8 +3652,40 @@ function confirmWrite(model) {
3651
3652
  buttons([button(model.allowLabel || t.confirm, "allow"), button(t.deny, "deny")])
3652
3653
  );
3653
3654
  }
3655
+ function choiceCard(model) {
3656
+ const lang = cardLang(model.lang, model.text, ...model.options);
3657
+ const t = assistantCardText.in(lang);
3658
+ const body = [
3659
+ header(model.multiple ? t.choiceTitleMany : t.choiceTitle, { tone: "accent", emoji: "question" })
3660
+ ];
3661
+ if (model.text) body.push(text2(model.text));
3662
+ body.push({
3663
+ type: "Input.ChoiceSet",
3664
+ id: "choice",
3665
+ style: "expanded",
3666
+ isMultiSelect: model.multiple,
3667
+ choices: model.options.map((option, i) => ({ title: clip(option, LABEL_MAX), value: String(i) }))
3668
+ });
3669
+ if (model.note) body.push(text2(model.note, { weight: "Bolder" }));
3670
+ body.push(note(t.choiceTyped));
3671
+ const send = execute(t.choiceSend, "primusclaw.assistant_choice", {
3672
+ primusclaw: "assistant_choice",
3673
+ card: model.cardId
3674
+ });
3675
+ return message(body, buttons([send]));
3676
+ }
3677
+ function choiceChosen(model) {
3678
+ const lang = cardLang(model.lang, model.text, ...model.chosen);
3679
+ const t = assistantCardText.in(lang);
3680
+ const answer = model.chosen.join(t.choiceJoin);
3681
+ const body = [header(t.choiceSent({ answer: clip(answer, TITLE_MAX) }), { tone: "good", emoji: "good" })];
3682
+ if (model.text) body.push(text2(model.text, { subtle: true }));
3683
+ return message(body);
3684
+ }
3654
3685
  var assistantRenderers = {
3655
3686
  actionCard,
3687
+ choiceCard,
3688
+ choiceChosen,
3656
3689
  board,
3657
3690
  confirmWrite,
3658
3691
  workCard,
@@ -3751,6 +3784,7 @@ function questionCard(model) {
3751
3784
  header(t.questionTitle, { tone: "accent", subtitle: model.note, emoji: "question" }),
3752
3785
  ...model.questions.flatMap((q, i) => questionInputs(q, i, t))
3753
3786
  ];
3787
+ if (model.typedReply === true) body.push(note(model.group ? t.questionReplyGroup : t.questionReply));
3754
3788
  if (model.group) body.push(note(t.questionOnly({ who: model.ownerName || t.questionAsker })));
3755
3789
  return message(body, [answerButton(model.sessionId, model.toolUseId, model.questions)]);
3756
3790
  }
@@ -3771,12 +3805,21 @@ function approvalExpired(model) {
3771
3805
  return message([header(t.expired, { tone: "attention", emoji: "expired" }), text2(line2, { subtle: true })]);
3772
3806
  }
3773
3807
  function questionAnswered(model) {
3808
+ if (model.replied !== void 0) return questionReplied(model, model.replied);
3774
3809
  const said = proactiveText.in("en").answered({ at: clockText(model.when, model.zone) });
3775
3810
  return message([
3776
3811
  header(said, { tone: "good", emoji: "good" }),
3777
3812
  ...model.answers.map(([, answer]) => text2(clip(answer, ANSWER_SHOWN_MAX)))
3778
3813
  ]);
3779
3814
  }
3815
+ function questionReplied(model, lang) {
3816
+ const t = approvalText.in(lang);
3817
+ const answer = [...new Set(model.answers.map(([, a]) => a))].join(" / ");
3818
+ return message([
3819
+ header(t.questionReplied({ answer: clip(answer, TITLE_MAX) }), { tone: "good", emoji: "good" }),
3820
+ note(t.questionRepliedAt({ at: clockText(model.when, model.zone) }))
3821
+ ]);
3822
+ }
3780
3823
  function approvalAgain(model) {
3781
3824
  return noteCard(
3782
3825
  model.text,
@@ -5951,6 +5994,7 @@ import {
5951
5994
  clientLocaleOf,
5952
5995
  agentActionAllowed,
5953
5996
  AssistantActions,
5997
+ AssistantChoiceClicks,
5954
5998
  AssistantChatService,
5955
5999
  Board,
5956
6000
  commandArgs,
@@ -6226,7 +6270,8 @@ function assistantParts(base2, inputs) {
6226
6270
  });
6227
6271
  const watch = new WatchClicks({ store, claw: claw.workItems, exchange, logger });
6228
6272
  const linked = (userId) => store.links.getKey(userId) !== null;
6229
- const clicks = [new WorkCardClicks(work, watch, exchange, linked, logger), actionClicks(actions)];
6273
+ const choices = new AssistantChoiceClicks({ store, deliver: (message2) => hooks.typed(message2), logger });
6274
+ const clicks = [new WorkCardClicks(work, watch, exchange, linked, logger), actionClicks(actions), choices];
6230
6275
  return { subs, chat: assistant, board: board2, receipts, directChat, actions, clicks };
6231
6276
  }
6232
6277
 
@@ -6308,7 +6353,9 @@ function proactiveParts(base2, style, assistant, errors, router) {
6308
6353
  const deps = {
6309
6354
  store,
6310
6355
  conversationFor: conversationFor(base2),
6311
- deliverStored: (envelope2) => surface.conversation(refOf(envelope2["reference"] ?? {})).deliver(envelope2),
6356
+ deliverStored: async (envelope2) => {
6357
+ await surface.conversation(refOf(envelope2["reference"] ?? {})).deliver(envelope2);
6358
+ },
6312
6359
  messageIds: surface.caps.messageIds,
6313
6360
  say: new SayPlanner({
6314
6361
  store,
@@ -6731,6 +6778,7 @@ function approvalClicks(base2, guard, hooks) {
6731
6778
  // packages/teams/src/assembly/features-w8.ts
6732
6779
  import { createHash as createHash3 } from "node:crypto";
6733
6780
  import {
6781
+ chatCredentialOf,
6734
6782
  DailyBrief,
6735
6783
  FeedbackFlow,
6736
6784
  FeedbackReporting,
@@ -6814,7 +6862,9 @@ function w8Parts(base2, options) {
6814
6862
  reporting,
6815
6863
  sessions: store.sessions,
6816
6864
  claw: { sessions: claw.sessions, assistant: claw.assistant },
6817
- credential,
6865
+ // A vote is cast as the person's chats run: someone bound but never linked has no key, and their turns run on the
6866
+ // exchanged token, so a key-only vote was never recorded for them.
6867
+ credential: chatCredentialOf(store.links, settings2.exchange.forChat ? base2.exchange : void 0),
6818
6868
  assistantOn: options.assistantOn,
6819
6869
  sha256Hex: (text4) => createHash3("sha256").update(text4, "utf8").digest("hex"),
6820
6870
  mask: mask2,
@@ -6916,7 +6966,8 @@ function lateHooks(get3) {
6916
6966
  const router = get3();
6917
6967
  return router.commands.run(text4, router.chat(sender, conversation), key);
6918
6968
  },
6919
- background: (userId) => get3().ctx.credentials.background(userId)
6969
+ background: (userId) => get3().ctx.credentials.background(userId),
6970
+ typed: (message2) => get3().handle(message2)
6920
6971
  };
6921
6972
  }
6922
6973
  function routerDeps(base2, built, errors) {
@@ -7307,6 +7358,7 @@ var workAction = reader("work");
7307
7358
  var observeAction = reader("observe");
7308
7359
  var assistantActionClick = reader("assistant_action");
7309
7360
  var assistantConfirmClick = reader("assistant_confirm");
7361
+ var assistantChoiceClick = reader("assistant_choice");
7310
7362
  var githubConfirmAction = reader("github_confirm");
7311
7363
  var githubModeAction = reader("github_mode");
7312
7364
  var githubConnectAction = reader("github_connect");
@@ -40,6 +40,8 @@ export declare const observeAction: Reader;
40
40
  export declare const assistantActionClick: Reader;
41
41
  /** A held write's card (allow or deny). */
42
42
  export declare const assistantConfirmClick: Reader;
43
+ /** Send on a choice the assistant put to the person, with the places of the options picked. */
44
+ export declare const assistantChoiceClick: Reader;
43
45
  /** "Merge" / "Do not merge" on the card a high-risk merge sends to the reviewer. */
44
46
  export declare const githubConfirmAction: Reader;
45
47
  /** One of the two confirmation settings of the review mode card. */
@@ -2,7 +2,7 @@
2
2
  * What the features behind the router are built from (the process's ports and settings), and the hooks into the router a
3
3
  * feature needs once the router exists: the router is built from the features, and some features call back into it.
4
4
  */
5
- import type { ClawPort, Clock, Logger, MetricsPort, Plugins, Random, RequestScope, SecurityLog, Settings, Surface, TokenExchange } from "@primusclaw/personal-agent";
5
+ import type { ClawPort, InboundMessage, Clock, Logger, MetricsPort, Plugins, Random, RequestScope, SecurityLog, Settings, Surface, TokenExchange } from "@primusclaw/personal-agent";
6
6
  import type { ChatLog, SqliteStore } from "@primusclaw/personal-agent-runtime";
7
7
  import type { TeamsSettings } from "../config/env.js";
8
8
  export interface AssemblyBase {
@@ -41,6 +41,8 @@ export interface RouterHooks {
41
41
  runCommand(text: string, sender: SenderOf, conversation: ConversationOf, key: string): Promise<boolean>;
42
42
  /** What reads Claw for a person with nobody to ask (`Agent._background_credential`); undefined: none. */
43
43
  background(userId: string): Promise<string | undefined>;
44
+ /** `message` handled as one the person typed (`Router.handle`): what a choice card's Send sends. */
45
+ typed(message: InboundMessage): Promise<void>;
44
46
  }
45
47
  type SenderOf = Parameters<import("@primusclaw/personal-agent").Router["chat"]>[0];
46
48
  type ConversationOf = Parameters<import("@primusclaw/personal-agent").Router["chat"]>[1];
@@ -42,7 +42,7 @@ export declare class TeamsConversation implements Conversation {
42
42
  private publish;
43
43
  typing(): Promise<void>;
44
44
  outgoing(message: OutMessage): Envelope;
45
- deliver(stored: Envelope): Promise<void>;
45
+ deliver(stored: Envelope): Promise<MessageId | undefined>;
46
46
  send(message: OutMessage): Promise<void>;
47
47
  /**
48
48
  * Send and return Teams' id of the new message; undefined if it never arrives. A direct send returns the id itself; a
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * The assistant's cards (teams_agent/render.py work_button, work_buttons, work_card, work_done_card, note_card, board_buttons,
3
- * board_card, asked_section, action_buttons, action_card, confirm_write_card). What they say is core's
3
+ * board_card, asked_section, action_buttons, action_card, confirm_write_card), and a choice put to the person. What they say is core's
4
4
  * (`assistantCardText`, the work item helpers); this draws it on the card kit. The buttons carry only the id of the card the
5
5
  * worker recorded: what a press means is read from the record, never from the click.
6
6
  */
7
- import { type ActionCardModel, type BoardModel, type BoardRetry, type ConfirmWriteModel, type Lang, type ReviewAskedOfOther, type WorkCardModel, type WorkDoneModel, type WorkNoteModel } from "@primusclaw/personal-agent";
7
+ import { type ActionCardModel, type BoardModel, type BoardRetry, type ChoiceCardModel, type ChoiceChosenModel, type ConfirmWriteModel, type Lang, type ReviewAskedOfOther, type WorkCardModel, type WorkDoneModel, type WorkNoteModel } from "@primusclaw/personal-agent";
8
8
  import type { CardElement } from "../../cards/json.js";
9
9
  import type { Tone } from "../../cards/kit.js";
10
10
  import type { TeamsMessage } from "../registry.js";
@@ -29,8 +29,18 @@ declare function board(model: BoardModel): TeamsMessage;
29
29
  export declare function actionButtons(cardId: string, lang: string): CardElement[];
30
30
  declare function actionCard(model: ActionCardModel): TeamsMessage;
31
31
  declare function confirmWrite(model: ConfirmWriteModel): TeamsMessage;
32
+ /**
33
+ * A choice put to the person: the words (when the card holds them), the options as radio buttons (check boxes when several may be
34
+ * picked), and Send. Send carries the card's id and, as its input, the places of the options picked: what it sends is read from
35
+ * the record. The person may also just reply in the chat.
36
+ */
37
+ declare function choiceCard(model: ChoiceCardModel): TeamsMessage;
38
+ /** What replaces a choice card once sent: what was sent, under the words it answered. */
39
+ declare function choiceChosen(model: ChoiceChosenModel): TeamsMessage;
32
40
  export declare const assistantRenderers: {
33
41
  actionCard: typeof actionCard;
42
+ choiceCard: typeof choiceCard;
43
+ choiceChosen: typeof choiceChosen;
34
44
  board: typeof board;
35
45
  confirmWrite: typeof confirmWrite;
36
46
  workCard: typeof workCard;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent-teams",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "The personal agent on Microsoft Teams: activities, Adaptive Cards, streams, Bot Connector, inbound queue, process assembly.",
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.4.0",
39
- "@primusclaw/personal-agent-runtime": "0.4.0",
38
+ "@primusclaw/personal-agent": "0.6.0",
39
+ "@primusclaw/personal-agent-runtime": "0.6.0",
40
40
  "zod": "^4.6.7"
41
41
  },
42
42
  "devDependencies": {