@primusclaw/personal-agent-teams 0.0.0-stage → 0.1.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.
Files changed (128) hide show
  1. package/dist/LICENSE +37 -0
  2. package/dist/index.js +8817 -0
  3. package/dist/main.js +8739 -0
  4. package/dist/types/activity/decorations.d.ts +40 -0
  5. package/dist/types/activity/feedback-loop.d.ts +9 -0
  6. package/dist/types/activity/inbound/actions.d.ts +55 -0
  7. package/dist/types/activity/inbound/identity.d.ts +36 -0
  8. package/dist/types/activity/inbound/index.d.ts +9 -0
  9. package/dist/types/activity/inbound/links.d.ts +30 -0
  10. package/dist/types/activity/inbound/markup.d.ts +39 -0
  11. package/dist/types/activity/inbound/mentions.d.ts +37 -0
  12. package/dist/types/activity/inbound/patterns.d.ts +21 -0
  13. package/dist/types/activity/inbound/quotes-html.d.ts +17 -0
  14. package/dist/types/activity/inbound/quotes.d.ts +32 -0
  15. package/dist/types/activity/inbound/schema.d.ts +44 -0
  16. package/dist/types/activity/inbound/to-event.d.ts +24 -0
  17. package/dist/types/activity/outbound.d.ts +25 -0
  18. package/dist/types/activity/redact-activity.d.ts +16 -0
  19. package/dist/types/activity/reference.d.ts +9 -0
  20. package/dist/types/activity/stream-activity.d.ts +16 -0
  21. package/dist/types/assembly/features-assistant.d.ts +42 -0
  22. package/dist/types/assembly/features-base.d.ts +49 -0
  23. package/dist/types/assembly/features-proactive.d.ts +26 -0
  24. package/dist/types/assembly/features-remote.d.ts +13 -0
  25. package/dist/types/assembly/features-review.d.ts +31 -0
  26. package/dist/types/assembly/features-switches.d.ts +26 -0
  27. package/dist/types/assembly/features-text.d.ts +35 -0
  28. package/dist/types/assembly/features-turns.d.ts +19 -0
  29. package/dist/types/assembly/features-w8.d.ts +18 -0
  30. package/dist/types/assembly/features.d.ts +42 -0
  31. package/dist/types/assembly/http.d.ts +23 -0
  32. package/dist/types/assembly/inbound.d.ts +18 -0
  33. package/dist/types/assembly/outbound.d.ts +40 -0
  34. package/dist/types/assembly/plugins.d.ts +20 -0
  35. package/dist/types/assembly/runner.d.ts +28 -0
  36. package/dist/types/assembly/secrets.d.ts +11 -0
  37. package/dist/types/assembly/timers.d.ts +14 -0
  38. package/dist/types/assembly/worker-services.d.ts +23 -0
  39. package/dist/types/assembly/worker.d.ts +19 -0
  40. package/dist/types/azure/keyvault-config.d.ts +24 -0
  41. package/dist/types/azure/keyvault.d.ts +52 -0
  42. package/dist/types/azure/workload-identity.d.ts +56 -0
  43. package/dist/types/caps.d.ts +13 -0
  44. package/dist/types/cards/cjk.d.ts +9 -0
  45. package/dist/types/cards/json.d.ts +12 -0
  46. package/dist/types/cards/kit.d.ts +115 -0
  47. package/dist/types/cards/view-buttons.d.ts +4 -0
  48. package/dist/types/config/env.d.ts +48 -0
  49. package/dist/types/config/style.d.ts +32 -0
  50. package/dist/types/connector/errors.d.ts +34 -0
  51. package/dist/types/connector/hosts.d.ts +40 -0
  52. package/dist/types/connector/lanes.d.ts +10 -0
  53. package/dist/types/connector/limits.d.ts +23 -0
  54. package/dist/types/connector/outbox.d.ts +97 -0
  55. package/dist/types/connector/py-parse.d.ts +10 -0
  56. package/dist/types/connector/request.d.ts +21 -0
  57. package/dist/types/connector/response.d.ts +9 -0
  58. package/dist/types/connector/retry.d.ts +57 -0
  59. package/dist/types/connector/timer.d.ts +18 -0
  60. package/dist/types/connector/tokens/assertion.d.ts +38 -0
  61. package/dist/types/connector/tokens/cached.d.ts +33 -0
  62. package/dist/types/connector/tokens/federated.d.ts +41 -0
  63. package/dist/types/connector/tokens/http.d.ts +11 -0
  64. package/dist/types/connector/tokens/imds.d.ts +26 -0
  65. package/dist/types/feedback/vote.d.ts +10 -0
  66. package/dist/types/gate/entry-env.d.ts +25 -0
  67. package/dist/types/gate/no-queue.d.ts +22 -0
  68. package/dist/types/gate/routes.d.ts +34 -0
  69. package/dist/types/html/entities.d.ts +2 -0
  70. package/dist/types/html/html5-entities.d.ts +6 -0
  71. package/dist/types/html/lexer.d.ts +18 -0
  72. package/dist/types/inbound/attachments.d.ts +36 -0
  73. package/dist/types/inbound/download.d.ts +34 -0
  74. package/dist/types/inbound/fetcher.d.ts +63 -0
  75. package/dist/types/inbound/names.d.ts +2 -0
  76. package/dist/types/inbound/types.d.ts +24 -0
  77. package/dist/types/index.d.ts +15 -0
  78. package/dist/types/main.d.ts +13 -0
  79. package/dist/types/messenger/acks.d.ts +23 -0
  80. package/dist/types/messenger/conversation.d.ts +59 -0
  81. package/dist/types/messenger/masker.d.ts +20 -0
  82. package/dist/types/messenger/render.d.ts +27 -0
  83. package/dist/types/observability/build-info.d.ts +7 -0
  84. package/dist/types/outbound/log-fields.d.ts +14 -0
  85. package/dist/types/outbound/outbox.d.ts +70 -0
  86. package/dist/types/richtext/blocks.d.ts +7 -0
  87. package/dist/types/richtext/check.d.ts +4 -0
  88. package/dist/types/richtext/constants.d.ts +15 -0
  89. package/dist/types/richtext/escape.d.ts +37 -0
  90. package/dist/types/richtext/index.d.ts +30 -0
  91. package/dist/types/richtext/inline.d.ts +11 -0
  92. package/dist/types/richtext/lines.d.ts +18 -0
  93. package/dist/types/richtext/scan.d.ts +17 -0
  94. package/dist/types/richtext/status.d.ts +9 -0
  95. package/dist/types/richtext/url.d.ts +2 -0
  96. package/dist/types/servicebus/client.d.ts +40 -0
  97. package/dist/types/servicebus/consumer.d.ts +53 -0
  98. package/dist/types/servicebus/outbox.d.ts +22 -0
  99. package/dist/types/stream/busy.d.ts +17 -0
  100. package/dist/types/stream/informative.d.ts +10 -0
  101. package/dist/types/stream/live-stream.d.ts +25 -0
  102. package/dist/types/stream/mutex.d.ts +6 -0
  103. package/dist/types/stream/teams-stream.d.ts +63 -0
  104. package/dist/types/surface.d.ts +46 -0
  105. package/dist/types/views/approval/index.d.ts +33 -0
  106. package/dist/types/views/assistant/index.d.ts +40 -0
  107. package/dist/types/views/commands/index.d.ts +26 -0
  108. package/dist/types/views/feedback/index.d.ts +23 -0
  109. package/dist/types/views/index.d.ts +3 -0
  110. package/dist/types/views/observe/index.d.ts +10 -0
  111. package/dist/types/views/proactive/index.d.ts +31 -0
  112. package/dist/types/views/registry.d.ts +21 -0
  113. package/dist/types/views/remote/agents-card.d.ts +10 -0
  114. package/dist/types/views/remote/elements.d.ts +18 -0
  115. package/dist/types/views/remote/hidden-card.d.ts +4 -0
  116. package/dist/types/views/remote/index.d.ts +12 -0
  117. package/dist/types/views/remote/permission-cards.d.ts +9 -0
  118. package/dist/types/views/remote/sessions-card.d.ts +8 -0
  119. package/dist/types/views/remote/small-cards.d.ts +14 -0
  120. package/dist/types/views/remote/status-card.d.ts +5 -0
  121. package/dist/types/views/remote/window-card.d.ts +5 -0
  122. package/dist/types/views/review/index.d.ts +21 -0
  123. package/dist/types/views/turn/index.d.ts +28 -0
  124. package/dist/types/views/turn/note.d.ts +10 -0
  125. package/dist/types/views/turn/stop.d.ts +8 -0
  126. package/dist/types/worker-api.d.ts +69 -0
  127. package/package.json +39 -4
  128. package/README.md +0 -3
@@ -0,0 +1,37 @@
1
+ /** The characters Python's `\s` (and `str.isspace`) matches, as the body of a regex character class. */
2
+ export declare const PY_SPACE = "\\t\\n\\v\\f\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
3
+ /** Python's `\s` and `\S` as regex source (use with the "u" flag). */
4
+ export declare const S = "[\\t\\n\\v\\f\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]";
5
+ export declare const NS = "[^\\t\\n\\v\\f\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]";
6
+ /** Python's `$` without MULTILINE: the end, or just before a newline that ends the string. */
7
+ export declare const END = "(?=\\n?$)";
8
+ /** `text` with markdown's backslash escapes resolved (`\-` is `-`), the way the converter reads it. */
9
+ export declare function unescapeMarkdown(text: string): string;
10
+ /**
11
+ * The one way text and code reach the output. A seam (tests replace `esc` to prove that the validator fails closed
12
+ * when escaping is broken); production code never changes it.
13
+ */
14
+ export declare const escaping: {
15
+ esc: (text: string) => string;
16
+ };
17
+ /** Python's `html.escape(text, quote=True)`. */
18
+ export declare function escapeAttr(text: string): string;
19
+ /** The code point that starts at `i` ("" past the end). */
20
+ export declare function cpAt(text: string, i: number): string;
21
+ /** The code point that ends just before `i` ("" at the start). */
22
+ export declare function cpBefore(text: string, i: number): string;
23
+ /** `ch.isspace()` for one code point ("" is false). */
24
+ export declare function isSpace(ch: string): boolean;
25
+ /** `ch.isalnum()` for one code point ("" is false); letters and numbers of the Unicode version Node knows. */
26
+ export declare function isAlnum(ch: string): boolean;
27
+ /** The UTF-16 offset `count` code points after offset `i`, at most `text.length`. */
28
+ export declare function advanceCp(text: string, i: number, count: number): number;
29
+ /**
30
+ * Python's `text.strip()`, in linear time: a regex anchored at the end (`\s+$`) retries from every position of a
31
+ * long inner run of blanks, which is quadratic in the line.
32
+ */
33
+ export declare function strip(text: string): string;
34
+ /** Python's `text.lstrip(chars)`. */
35
+ export declare function lstripChars(text: string, chars: string): string;
36
+ /** Python's `text.rstrip(chars)`. */
37
+ export declare function rstripChars(text: string, chars: string): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The agent's markdown answer as the small HTML subset Teams renders in a bot message with textFormat "xml".
3
+ *
4
+ * Measured on Teams desktop (dark theme) and iPhone: <b> <i> <u> <s>, <br>, <span style="color:..."> and
5
+ * <span style="font-size:..px"> render; <h2> renders only as bold; <font> is ignored. <a>, <code> and <pre> are the
6
+ * ordinary HTML for links and code and degrade to their text where a client ignores them. Lists are drawn as lines
7
+ * with a bullet character and <br>, which needs no list tags.
8
+ *
9
+ * The answer is untrusted text. Nothing from it reaches the output except escaped (text and code) or through
10
+ * `safeUrl` (an http/https URL that goes into an attribute after attribute escaping). `checkHtml` then re-reads the
11
+ * finished HTML against an allow-list, so a bug fails closed: `toTeamsHtml` throws and `richTextActivity` sends the
12
+ * original markdown instead.
13
+ */
14
+ import { type Logger } from "@primusclaw/personal-agent";
15
+ import type { JsonObject } from "../cards/json.js";
16
+ export { toTeamsHtml } from "./blocks.js";
17
+ export { checkHtml } from "./check.js";
18
+ export { LABEL_PX, LEAD_PX, MAX_INPUT_CHARS, MAX_LABEL_CHARS, MAX_NEST, MAX_OUTPUT_BYTES, MAX_URL_CHARS, RichTextError, STATUS_COLORS, } from "./constants.js";
19
+ export { unescapeMarkdown } from "./escape.js";
20
+ export { safeUrl } from "./url.js";
21
+ /** The markdown as it is (Python's `text_activity`): what is sent when the rich conversion cannot be. */
22
+ export declare function markdownActivity(markdown: string): JsonObject;
23
+ /**
24
+ * A final answer as an xml-format message (bold labels, colour on status lines, links, code). Anything that goes
25
+ * wrong in the conversion sends the markdown unchanged: the user always gets the answer. Only the error's kind is
26
+ * logged, never the text.
27
+ */
28
+ export declare function richTextActivity(markdown: string, options?: {
29
+ readonly lead?: boolean;
30
+ }, logger?: Logger): JsonObject;
@@ -0,0 +1,11 @@
1
+ export type FragKind = "text" | "bold" | "code" | "link" | "other";
2
+ /** A piece of a line: its HTML, its plain text, and what it is ("text": the html is the escaped plain text). */
3
+ export interface Frag {
4
+ readonly html: string;
5
+ readonly plain: string;
6
+ readonly kind: FragKind;
7
+ }
8
+ export declare function textFrag(plain: string): Frag;
9
+ export declare function joinHtml(frags: readonly Frag[]): string;
10
+ /** The top-level pieces of one line of markdown. Emphasis inside a piece is already rendered into its html. */
11
+ export declare function inlineFrags(text: string, depth?: number, links?: boolean): Frag[];
@@ -0,0 +1,18 @@
1
+ export declare const FENCE: RegExp;
2
+ export declare const HEADING_OPEN: RegExp;
3
+ export declare const RULE: RegExp;
4
+ export declare const BULLET: RegExp;
5
+ export declare const NUMBERED: RegExp;
6
+ export declare const QUOTE: RegExp;
7
+ export declare const TABLE_SEP: RegExp;
8
+ /**
9
+ * The text of an ATX heading line (`# x`, up to six #, an optional closing run of # after a space dropped); else
10
+ * null. Written out rather than as one pattern, because the text and the closing run around it both take spaces.
11
+ */
12
+ export declare function headingText(line: string): string | null;
13
+ /** The text of a line that is one bold span (**x** or __x__), with a trailing colon kept; else null. */
14
+ export declare function boldOnly(line: string): string | null;
15
+ /** The cells of a table row, trimmed; an escaped `\|` stays inside its cell. */
16
+ export declare function cells(line: string): string[];
17
+ /** Whether `line` ends a paragraph: blank, or the start of another block. */
18
+ export declare function startsBlock(line: string): boolean;
@@ -0,0 +1,17 @@
1
+ /** Start of a code span -> [end, content start, content end]. */
2
+ export type CodeSpans = ReadonlyMap<number, readonly [number, number, number]>;
3
+ /**
4
+ * The code spans of `text`: a backtick run closes at the next run of the same length, found left to right, so a lone
5
+ * backtick stays a backtick.
6
+ */
7
+ export declare function codeSpans(text: string): CodeSpans;
8
+ /** How many backtick runs in `text` neither open nor close a code span. */
9
+ export declare function unmatchedTicks(text: string): number;
10
+ /** Where the emphasis opened before `begin` closes (the offset of its closing delimiters), or null. */
11
+ export declare function findCloser(text: string, begin: number, ch: string, size: number, spans: CodeSpans): number | null;
12
+ /** Whether `size` delimiters `ch` at text[i] can open an emphasis. */
13
+ export declare function canOpen(text: string, i: number, ch: string, size: number): boolean;
14
+ /** A bare URL without the punctuation that ends the sentence around it. */
15
+ export declare function trimUrl(raw: string): string;
16
+ /** `[label](destination "title")` at text[i] === "[": [label, destination, end offset] or null. */
17
+ export declare function parseLink(text: string, i: number, spans: CodeSpans): [string, string, number] | null;
@@ -0,0 +1,9 @@
1
+ import { type Frag } from "./inline.js";
2
+ /**
3
+ * A line's html. A line that starts with a status emoji gets the colour on its short label only: the bold text after
4
+ * the emoji, or else the words up to the first colon, comma, dash or full stop (at most MAX_LABEL_CHARS). A long line
5
+ * with no such label stays uncoloured.
6
+ */
7
+ export declare function statusLine(frags: readonly Frag[]): string;
8
+ /** One bold line as a larger bold heading; its colour follows a leading status emoji. */
9
+ export declare function heading(inner: string, px: number): string;
@@ -0,0 +1,2 @@
1
+ /** `url` when it is an absolute http or https URL without whitespace or control characters; else null. */
2
+ export declare function safeUrl(raw: string): string | null;
@@ -0,0 +1,40 @@
1
+ import type { TokenCredential } from "@azure/core-auth";
2
+ export interface BusMessage {
3
+ readonly body: Uint8Array;
4
+ readonly contentType: string;
5
+ }
6
+ export interface BusSender {
7
+ send(message: BusMessage): Promise<void>;
8
+ close(): Promise<void>;
9
+ }
10
+ /** A received message: its raw body, when the broker took it, and the broker's id and delivery count for the log line. */
11
+ export interface Received {
12
+ readonly body: Uint8Array;
13
+ readonly enqueuedAt: Date | undefined;
14
+ /** The message's id as the sender set it (a string or number id; none for any other kind). */
15
+ readonly messageId?: string | undefined;
16
+ /** How many times the broker has delivered it, this time included. */
17
+ readonly deliveryCount?: number | undefined;
18
+ }
19
+ /** A receiver locked on one session: messages in order, settled one by one. */
20
+ export interface SessionReceiver {
21
+ /** At most `count` messages, waiting at most `waitMs` for the first (none: the session has gone quiet). */
22
+ receive(count: number, waitMs: number): Promise<Received[]>;
23
+ complete(message: Received): Promise<void>;
24
+ abandon(message: Received): Promise<void>;
25
+ deadLetter(message: Received, reason: string, description: string): Promise<void>;
26
+ close(): Promise<void>;
27
+ }
28
+ export interface BusClient {
29
+ sender(queue: string): BusSender;
30
+ /** The next session that has messages; rejects (a timeout) when none has any. */
31
+ acceptNextSession(queue: string): Promise<SessionReceiver>;
32
+ close(): Promise<void>;
33
+ }
34
+ /** How the worker reaches a namespace: a SAS connection string, or an Entra identity on the namespace's host name. */
35
+ export type BusConnection = string | {
36
+ readonly namespace: string;
37
+ readonly credential: TokenCredential;
38
+ };
39
+ /** The SDK's client behind `BusClient`. Bodies are sent as one data section of bytes and read back unparsed. */
40
+ export declare function azureBusClient(connection: BusConnection, lockRenewalMs: number): BusClient;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The inbound queue: several receivers, each taking the next conversation session that has messages and handling them in
3
+ * order until the session has been quiet for IDLE_MS. A body that is not a JSON object is dead-lettered at once (it can never
4
+ * succeed); a handler failure abandons the message, so the broker redelivers it and, after its maximum delivery count,
5
+ * dead-letters it. Either way the session moves on: one poison message never blocks a conversation. Every message taken
6
+ * gets one line (`inbound message`): its id, what came of it (completed, abandoned, dead_lettered), how long it waited in
7
+ * the queue and how long it took; never its body.
8
+ */
9
+ import type { Clock, Logger } from "@primusclaw/personal-agent";
10
+ import { type JsonObject } from "../cards/json.js";
11
+ import type { BusClient, Received } from "./client.js";
12
+ /** A session that has had no message for this long is released for the next one. */
13
+ export declare const IDLE_MS = 20000;
14
+ /** After an error of the broker (not the idle timeout), wait this long before trying again. */
15
+ export declare const BACKOFF_MS = 3000;
16
+ /** After finding no session with messages, wait this long before asking again. */
17
+ export declare const NO_SESSION_PAUSE_MS = 1000;
18
+ /** What the handled messages are counted in: how long each waited in the queue and took to handle. */
19
+ export interface InboundStats {
20
+ processed(queueLagMs: number | undefined, handleMs: number, ok: boolean): void;
21
+ }
22
+ /** Whether a broker error is the documented "no session has messages" timeout of acceptNextSession. */
23
+ export declare function isIdleTimeout(error: unknown): boolean;
24
+ /**
25
+ * How long `message` waited in the queue before the worker took it: from the broker's enqueue time to the start of
26
+ * handling (now, less `handleMs`). undefined when the broker gave no enqueue time. A growing lag is the queue backing up.
27
+ */
28
+ export declare function queueLagMs(message: Received, nowEpochMs: number, handleMs?: number): number | undefined;
29
+ export interface ConsumerParts {
30
+ readonly client: BusClient;
31
+ readonly queue: string;
32
+ readonly handle: (activity: JsonObject) => Promise<void>;
33
+ readonly receivers: number;
34
+ readonly clock: Clock;
35
+ readonly stats?: InboundStats;
36
+ readonly logger?: Logger;
37
+ }
38
+ export declare class InboundConsumer {
39
+ private readonly parts;
40
+ private stopped;
41
+ private readonly logger;
42
+ constructor(parts: ConsumerParts);
43
+ /** Run the receivers until `stop`. */
44
+ run(): Promise<void>;
45
+ stop(): void;
46
+ private loop;
47
+ private pause;
48
+ private drain;
49
+ private dispatch;
50
+ private record;
51
+ /** The one line for a message taken: ids, outcome and times only. */
52
+ private logLine;
53
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The outbound queue: envelopes handed to Service Bus, which the relay Function posts to Teams (send, reply and update;
3
+ * it has no delete). A sender that has sat idle for minutes is dropped by the broker without the client noticing (the
4
+ * first send on it fails and the person waits for the SDK to reconnect), so past IDLE_REOPEN_MS it is replaced first.
5
+ */
6
+ import type { Clock, Logger } from "@primusclaw/personal-agent";
7
+ import { type Delivered, type Outbox, type PublishOptions, type TeamsEnvelope } from "../outbound/outbox.js";
8
+ import type { BusClient } from "./client.js";
9
+ export declare const IDLE_REOPEN_MS = 240000;
10
+ export declare class ServiceBusOutbox implements Outbox {
11
+ private readonly client;
12
+ private readonly queue;
13
+ private readonly clock;
14
+ private sender;
15
+ private usedAt;
16
+ private readonly lock;
17
+ private readonly logger;
18
+ constructor(client: BusClient, queue: string, clock: Clock, logger?: Logger);
19
+ publish(envelope: TeamsEnvelope, options?: PublishOptions): Promise<Delivered | undefined>;
20
+ private replaceSender;
21
+ close(): Promise<void>;
22
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Teams allows one open stream per conversation. This remembers, per conversation, until when this process does not open
3
+ * another one there: one is open, or one whose final was refused may still be open on Teams' side until it times out.
4
+ */
5
+ import type { Clock } from "@primusclaw/personal-agent";
6
+ /** Teams closes a stream 10 minutes after its first request. */
7
+ export declare const STREAM_LIMIT_MS: number;
8
+ export declare class BusyConversations {
9
+ private readonly clock;
10
+ private readonly until;
11
+ constructor(clock: Clock);
12
+ isBusy(conversation: string): boolean;
13
+ /** A stream opened at `openedAt` in `conversation`: busy until Teams' limit. Expired entries are dropped. */
14
+ opened(conversation: string, openedAt: number): void;
15
+ /** The stream opened at `openedAt` closed: the conversation is free, unless a newer stream holds it. */
16
+ closed(conversation: string, openedAt: number): void;
17
+ }
@@ -0,0 +1,10 @@
1
+ /** An informative update is at most 1000 characters ... */
2
+ export declare const INFORMATIVE_MAX_CHARS = 1000;
3
+ /** ... and 1 KB. */
4
+ export declare const INFORMATIVE_MAX_BYTES = 1024;
5
+ export declare const STATUS_JOIN = " \u00B7 ";
6
+ /**
7
+ * Status lines as one informative update: whitespace collapsed, the lines joined by " · ", cut to the limits by keeping
8
+ * the END (the newest) after a leading "…", never starting with a combining mark.
9
+ */
10
+ export declare function informativeText(lines: readonly string[]): string;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Core's `LiveStream` on Teams: a `TeamsStream` in reply to the person's message, opened where the reply style has streams
3
+ * on for this kind of chat, there is a message to reply to, and no other stream may still be open in the conversation.
4
+ * Everything Teams does not take comes back as `StreamRefused`; the caller then shows the same thing without a stream.
5
+ */
6
+ import type { Clock, ConversationRef, LiveStream, Logger, OutMessage, Result, StreamRefused } from "@primusclaw/personal-agent";
7
+ import { type JsonObject } from "../cards/json.js";
8
+ import { type Style } from "../config/style.js";
9
+ import type { BusyConversations } from "./busy.js";
10
+ import { type StreamPoster } from "./teams-stream.js";
11
+ export interface StreamContext {
12
+ readonly style: Style;
13
+ readonly clock: Clock;
14
+ readonly busy: BusyConversations;
15
+ readonly logger?: Logger;
16
+ }
17
+ export interface StreamRequest {
18
+ readonly ref: ConversationRef;
19
+ readonly replyTo: string;
20
+ readonly status: string;
21
+ readonly post: StreamPoster;
22
+ readonly render: (message: OutMessage) => JsonObject;
23
+ }
24
+ /** A stream in reply to `request.replyTo`, opened with `request.status`; refused where streams are not used or not taken. */
25
+ export declare function openStream(context: StreamContext, request: StreamRequest): Promise<Result<LiveStream, StreamRefused>>;
@@ -0,0 +1,6 @@
1
+ /** A first-come-first-served lock: what is run under it runs one at a time, in the order it asked. */
2
+ export declare class Mutex {
3
+ private tail;
4
+ /** Run `work` when every earlier `run` has finished (whether it succeeded or not). */
5
+ run<T>(work: () => Promise<T>): Promise<T>;
6
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * One Teams stream in reply to one person's message (Bot Framework REST, "Stream agent messages"): `start`, then any number
3
+ * of `inform` (status) or `emit` (the text so far), then one `final`. Teams' rules are kept here: every request names the
4
+ * stream's id and a sequence number one higher each time, at most one request a second, streamed text only grows, one open
5
+ * stream per conversation. A request Teams did not take throws StreamRefusedError; the stream is then of no further use
6
+ * (`broken`), except that a final can still be tried.
7
+ */
8
+ import type { Clock, Logger } from "@primusclaw/personal-agent";
9
+ import type { JsonObject } from "../cards/json.js";
10
+ import { type StreamKind } from "../activity/stream-activity.js";
11
+ import type { BusyConversations } from "./busy.js";
12
+ /** Teams takes one request a second per stream. */
13
+ export declare const MIN_INTERVAL_MS = 1000;
14
+ /**
15
+ * Sends one request of a stream and returns the id Teams answered with (the stream's id, for the first). Once `signal`
16
+ * aborts, it rejects at once.
17
+ */
18
+ export type StreamPoster = (activity: JsonObject, signal?: AbortSignal) => Promise<string | undefined>;
19
+ export interface StreamParts {
20
+ readonly post: StreamPoster;
21
+ readonly conversation: string;
22
+ readonly replyTo: string;
23
+ readonly clock: Clock;
24
+ readonly busy: BusyConversations;
25
+ readonly logger?: Logger;
26
+ }
27
+ export declare class TeamsStream {
28
+ private readonly parts;
29
+ streamId: string;
30
+ broken: boolean;
31
+ closed: boolean;
32
+ /** The text streamed into the bubble so far ("" : only status so far). */
33
+ streamed: string;
34
+ openedAt: number | undefined;
35
+ private sequence;
36
+ private lastAt;
37
+ private readonly lock;
38
+ private readonly logger;
39
+ constructor(parts: StreamParts);
40
+ /** Updates can be sent: it opened, and neither failed nor closed. */
41
+ get open(): boolean;
42
+ /** A final message can still be tried: it opened and is not closed (a refused update leaves it closable). */
43
+ get closable(): boolean;
44
+ get replyTo(): string;
45
+ /** How long ago it opened, in milliseconds (0 before it opened). */
46
+ age(): number;
47
+ private send;
48
+ /** Whoever sent it gave the update up (the stream was dropped): it takes no more, and nothing went wrong. */
49
+ private dropped;
50
+ private refused;
51
+ /** Open the stream with its first informative update (or, `kind` streaming, its first text). */
52
+ start(text: string, kind?: StreamKind): Promise<void>;
53
+ /** A new informative update (shown only until text is streamed). */
54
+ inform(text: string, signal?: AbortSignal): Promise<void>;
55
+ /** The streamed text so far. What was streamed before must be its start (Teams refuses anything else). */
56
+ emit(text: string, signal?: AbortSignal): Promise<void>;
57
+ /**
58
+ * Close the stream with `activity`, the message that stays in the chat. A final Teams refuses with 400 while it carries
59
+ * the reply style's extras is sent once more without them, so the status does not spin on until Teams' limit.
60
+ */
61
+ final(activity: JsonObject): Promise<void>;
62
+ private finalOnce;
63
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Core's `Surface` on Microsoft Teams: one `TeamsConversation` per conversation reference (masked in a group chat or a
3
+ * channel, where every member sees what is posted), the files a person sent, and the two things only a direct outbox can do:
4
+ * opening the bot's 1:1 chat with someone and reading a group chat's roster.
5
+ */
6
+ import type { Clock, Conversation, ConversationRef, FetchedFile, FileRefused, InboundFile, Logger, Random, Result, RosterMember, Surface, SurfaceCaps } from "@primusclaw/personal-agent";
7
+ import { type OutboundMode } from "./caps.js";
8
+ import type { Style } from "./config/style.js";
9
+ import type { AckRegistry } from "./messenger/acks.js";
10
+ import type { Masker } from "./messenger/masker.js";
11
+ import { type ConnectorMember, type Outbox } from "./outbound/outbox.js";
12
+ import type { Renderers } from "./views/registry.js";
13
+ /** What fetches a person's files (`inbound/fetcher.ts`). */
14
+ export interface FileFetcher {
15
+ fetchFile(file: InboundFile): Promise<Result<FetchedFile, FileRefused>>;
16
+ }
17
+ export interface TeamsSurfaceParts {
18
+ readonly mode: OutboundMode;
19
+ readonly outbox: Outbox;
20
+ readonly acks: AckRegistry;
21
+ readonly clock: Clock;
22
+ readonly random: Random;
23
+ readonly style: Style;
24
+ readonly renderers: Renderers;
25
+ /** How a group chat's messages are masked (core's credential rules). */
26
+ readonly masker: Masker;
27
+ readonly files: FileFetcher;
28
+ readonly ackTimeoutMs?: number;
29
+ readonly logger?: Logger;
30
+ }
31
+ /** A member as the Bot Connector lists it, in core's words ("" for what it does not give). */
32
+ export declare function rosterMember(member: ConnectorMember): RosterMember;
33
+ export declare class TeamsSurface implements Surface {
34
+ private readonly parts;
35
+ readonly caps: SurfaceCaps;
36
+ private readonly busy;
37
+ private readonly logger;
38
+ constructor(parts: TeamsSurfaceParts);
39
+ conversation(ref: ConversationRef): Conversation;
40
+ fetchFile(file: InboundFile): Promise<Result<FetchedFile, FileRefused>>;
41
+ openPersonal(via: ConversationRef, user: {
42
+ readonly channelUserId: string;
43
+ readonly userId: string;
44
+ }): Promise<Conversation | undefined>;
45
+ members(conversation: ConversationRef): Promise<readonly RosterMember[] | undefined>;
46
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Approval and question cards (teams_agent/render.py permission_card, decision_buttons, question_card, answer_button; the body is
3
+ * approval_view.card_body). What a card says is core's `approvalView`; this draws it on the card kit.
4
+ */
5
+ import { type ApprovalAgainModel, type ApprovalCardModel, type ApprovalDecidedModel, type ApprovalExpiredModel, type ApprovalView, type CardQuestion, type QuestionAnsweredModel, type QuestionCardModel } from "@primusclaw/personal-agent";
6
+ import type { CardElement } from "../../cards/json.js";
7
+ import type { TeamsMessage } from "../registry.js";
8
+ /** Approve (the primary button) and Deny: what an approval card's buttons carry. */
9
+ export declare function decisionButtons(tool: string, sessionId: string, toolUseId: string, lang: string): CardElement[];
10
+ /** The body of a permission card: the warning header, the summary or the agent's words, the facts and the folded raw call. */
11
+ export declare function approvalBody(view: ApprovalView): CardElement[];
12
+ declare function approvalCard(model: ApprovalCardModel): import("../../cards/kit.js").CardMessage;
13
+ /** Send: what a question card's button carries; the questions travel with it so the card can be drawn again. */
14
+ export declare function answerButton(sessionId: string, toolUseId: string, questions: readonly CardQuestion[]): CardElement;
15
+ /** The agent asks before it goes on: each question with its options as choices, a box for a free answer, and one Send button. */
16
+ declare function questionCard(model: QuestionCardModel): import("../../cards/kit.js").CardMessage;
17
+ /** What replaces an approval card once it was answered: who answered (you), when, and on what. */
18
+ declare function approvalDecided(model: ApprovalDecidedModel): TeamsMessage;
19
+ /** An approval or a question that ran out, and what the person can still do. */
20
+ declare function approvalExpired(model: ApprovalExpiredModel): TeamsMessage;
21
+ /** What replaces a question card once it was answered: when, and each answer. */
22
+ declare function questionAnswered(model: QuestionAnsweredModel): TeamsMessage;
23
+ /** An approval card put back after a press that did not go through: the note, then Approve and Deny again. */
24
+ declare function approvalAgain(model: ApprovalAgainModel): TeamsMessage;
25
+ export declare const approvalRenderers: {
26
+ approval: typeof approvalCard;
27
+ approvalAgain: typeof approvalAgain;
28
+ approvalDecided: typeof approvalDecided;
29
+ approvalExpired: typeof approvalExpired;
30
+ question: typeof questionCard;
31
+ questionAnswered: typeof questionAnswered;
32
+ };
33
+ export {};
@@ -0,0 +1,40 @@
1
+ /**
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
4
+ * (`assistantCardText`, the work item helpers); this draws it on the card kit. The buttons carry only the id of the card the
5
+ * worker recorded: what a press means is read from the record, never from the click.
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";
8
+ import type { CardElement } from "../../cards/json.js";
9
+ import type { Tone } from "../../cards/kit.js";
10
+ import type { TeamsMessage } from "../registry.js";
11
+ /** One button of a work item's card: accept, stop, retry (a task that failed or was stopped), watch or unwatch. */
12
+ export declare function workButton(op: string, cardId: string, title: string): CardElement;
13
+ /** Accept (only when a result waits, and only that version; the primary button) and Stop; Stop alone is a destructive primary. */
14
+ export declare function workButtons(cardId: string, version: number, canAccept: boolean, lang: string): CardElement[];
15
+ /**
16
+ * What replaces a card the person just pressed: a short note (under a header with `title`, in `tone`, when there is one), and the
17
+ * buttons again when the press has to be repeated.
18
+ */
19
+ export declare function noteCard(value: string, actions?: CardElement[], title?: string, tone?: Tone): TeamsMessage;
20
+ declare function workCard(model: WorkCardModel): TeamsMessage;
21
+ declare function workDone(model: WorkDoneModel): TeamsMessage;
22
+ declare function workNote(model: WorkNoteModel): TeamsMessage;
23
+ /** The board's own buttons: Accept all (the primary button) and a Retry for each task that failed or was stopped. */
24
+ export declare function boardButtons(accept: readonly string[], retry: readonly BoardRetry[], lang: Lang): CardElement[];
25
+ /** The board's part for reviews the person asked of others: a heading with the count, then one line each. */
26
+ export declare function askedSection(asked: readonly ReviewAskedOfOther[], lang: Lang): CardElement[];
27
+ declare function board(model: BoardModel): TeamsMessage;
28
+ /** Run (primary) and Cancel under a command the assistant put to the person: the buttons carry only the card's id. */
29
+ export declare function actionButtons(cardId: string, lang: string): CardElement[];
30
+ declare function actionCard(model: ActionCardModel): TeamsMessage;
31
+ declare function confirmWrite(model: ConfirmWriteModel): TeamsMessage;
32
+ export declare const assistantRenderers: {
33
+ actionCard: typeof actionCard;
34
+ board: typeof board;
35
+ confirmWrite: typeof confirmWrite;
36
+ workCard: typeof workCard;
37
+ workDone: typeof workDone;
38
+ workNote: typeof workNote;
39
+ };
40
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * How Teams shows the cards of connecting and of the chat's own commands: single column, Action.Execute (and an open-link
3
+ * button) only, so they render the same on desktop and on the phone. Byte for byte the Python worker's `render.link_card`,
4
+ * `binding_request_card`, `onboarding_card`, `repo_card` and `session_card` (snapshots `link`, `binding`, `onboarding`,
5
+ * `repo`, `session`).
6
+ */
7
+ import type { BindingCardView, LinkCardView, OnboardingCardView, RepoCardView, SessionCardView } from "@primusclaw/personal-agent";
8
+ import type { CardElement } from "../../cards/json.js";
9
+ import { type CardMessage } from "../../cards/kit.js";
10
+ /** The older connect card's Confirm button (the person says they confirmed). */
11
+ export declare function confirmButton(): CardElement;
12
+ export declare function linkCard(model: LinkCardView): CardMessage;
13
+ export declare function bindingCard(model: BindingCardView): CardMessage;
14
+ export declare function onboardingCard(model: OnboardingCardView): CardMessage;
15
+ /** What a `/repo` card's button carries; it comes back from the client, so the worker reads it again like typed text. */
16
+ export declare function repoButton(repo: string, branch: string, lang: string, title?: string): CardElement;
17
+ export declare function repoCard(model: RepoCardView): CardMessage;
18
+ export declare function showButton(sessionId: string, title?: string): CardElement;
19
+ export declare function sessionCard(model: SessionCardView): CardMessage;
20
+ export declare const COMMAND_RENDERERS: {
21
+ link: typeof linkCard;
22
+ binding: typeof bindingCard;
23
+ onboarding: typeof onboardingCard;
24
+ repo: typeof repoCard;
25
+ session: typeof sessionCard;
26
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * How Teams shows feedback's views: small single-column cards with Action.Execute buttons only, so they render the same
3
+ * on desktop and on the phone. Byte for byte the Python worker's `render.report_card`, `thumbs_card`, `thumb_comment_card`
4
+ * and `feedback.offer_card` (snapshots `report`, `thumbs`, `thumb_comment`, `feedback_offer`).
5
+ */
6
+ import { type FeedbackOfferRetryView, type FeedbackOfferView, type FeedbackReportView } from "@primusclaw/personal-agent";
7
+ import type { CardElement } from "../../cards/json.js";
8
+ import { type CardMessage } from "../../cards/kit.js";
9
+ export declare function reportCard(model: FeedbackReportView): CardMessage;
10
+ export declare function thumbsCard(): CardMessage;
11
+ export declare function thumbCommentCard(): CardMessage;
12
+ /** Yes (primary) and No: what the offer's buttons carry, also when a Yes has to be pressed again. */
13
+ export declare function offerButtons(offerId: string): CardElement[];
14
+ export declare function offerCard(model: FeedbackOfferView): CardMessage;
15
+ /** The offer after a Yes that could not be carried out: the note, under the offer's question, with Yes and No again. */
16
+ export declare function offerRetryCard(model: FeedbackOfferRetryView): CardMessage;
17
+ export declare const FEEDBACK_RENDERERS: {
18
+ thumbs: typeof thumbsCard;
19
+ thumbComment: typeof thumbCommentCard;
20
+ feedbackReport: typeof reportCard;
21
+ feedbackOffer: typeof offerCard;
22
+ feedbackOfferRetry: typeof offerRetryCard;
23
+ };
@@ -0,0 +1,3 @@
1
+ import type { Renderers } from "./registry.js";
2
+ export declare const RENDERERS: Renderers;
3
+ export { renderView, type Renderer, type Renderers, type TeamsMessage } from "./registry.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * How Teams shows a suggestion of an observed group (the Python worker's `observe.suggestion_card`): the group, what was
3
+ * said, what the observer's assistant would have done, and Accept (primary) and Dismiss.
4
+ */
5
+ import { type ObserveSuggestionView } from "@primusclaw/personal-agent";
6
+ import { type CardMessage } from "../../cards/kit.js";
7
+ export declare function suggestionCard(model: ObserveSuggestionView): CardMessage;
8
+ export declare const OBSERVE_RENDERERS: {
9
+ observeSuggestion: typeof suggestionCard;
10
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * What reaches a person unasked (teams_agent/render.py event_card, digest_card, approval_card, item_approval_card,
3
+ * item_question_card, show_button and the open and show actions). What they say is core's (`proactiveText`, the proactive
4
+ * helpers); the approval body and its buttons are the approval cards' own (`../approval`).
5
+ */
6
+ import { type DigestModel, type ItemQuestionModel, type ProactiveApprovalModel, type RunEventModel } from "@primusclaw/personal-agent";
7
+ import type { CardElement } from "../../cards/json.js";
8
+ import type { TeamsMessage } from "../registry.js";
9
+ /** Show here: what a finished or failed run's card carries; the worker checks the clicker owns the session. */
10
+ export declare function showButton(sessionId: string, title?: string): CardElement;
11
+ /** run.completed, run.failed and any other plain notice: a header in the run's colour, its summary, Show here and Open in Claw. */
12
+ declare function runEvent(model: RunEventModel): TeamsMessage;
13
+ /** One card for everything held back: counts first (in the header), then up to five titles, and Show here for the first three. */
14
+ declare function digest(model: DigestModel): TeamsMessage;
15
+ /** approval.requested of a run: what, on what, until when, with Approve and Deny that call Claw as the clicker. */
16
+ declare function proactiveApproval(model: ProactiveApprovalModel): TeamsMessage;
17
+ /**
18
+ * approval.requested of a work item: which task waits, what it would do and why (the approval body, in the person's language),
19
+ * on what (Claw's target, masked), until when, with Approve and Deny, which answer the item's worker session as the clicker.
20
+ */
21
+ declare function itemApproval(model: ProactiveApprovalModel): TeamsMessage;
22
+ /** A work item's question to its person: the question card a turn's own question gets, under a line naming the task. */
23
+ declare function itemQuestion(model: ItemQuestionModel): TeamsMessage;
24
+ export declare const proactiveRenderers: {
25
+ digest: typeof digest;
26
+ itemApproval: typeof itemApproval;
27
+ itemQuestion: typeof itemQuestion;
28
+ proactiveApproval: typeof proactiveApproval;
29
+ runEvent: typeof runEvent;
30
+ };
31
+ export {};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The View -> Teams message framework. Core says WHAT a person sees as a semantic view (`View`: a name and a model, no card
3
+ * JSON); each feature says HOW Teams shows its views in `teams/src/views/<feature>/`, as a partial `Renderers` object, and
4
+ * `views/index.ts` joins them into the one complete `Renderers`. A view name without a renderer does not compile.
5
+ */
6
+ import type { ViewMap } from "@primusclaw/personal-agent";
7
+ import type { JsonObject } from "../cards/json.js";
8
+ /** What a renderer turns a view into: one Teams message activity (a card message, or a text/xml message). */
9
+ export type TeamsMessage = JsonObject & {
10
+ type: string;
11
+ };
12
+ export type Renderer<M> = (model: M) => TeamsMessage;
13
+ /** One renderer per view name core declares. */
14
+ export type Renderers = {
15
+ readonly [K in keyof ViewMap]: Renderer<ViewMap[K]>;
16
+ };
17
+ /** The message Teams shows for `view` (core's `View`: any of them). */
18
+ export declare function renderView<K extends keyof ViewMap>(renderers: Renderers, view: {
19
+ readonly name: K;
20
+ readonly model: ViewMap[K];
21
+ }): TeamsMessage;