@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,31 @@
1
+ /**
2
+ * The review delegation (TEAMS_GITHUB_REVIEW_ENABLED), as the Python worker's `main.run` builds `GithubReview` and
3
+ * `Agent.__init__` attaches it: the identity service's GitHub credentials, the device flow `/github` connects with, the
4
+ * public pull request reader, the request reader on the platform's model gateway (TEAMS_REVIEW_INTENT_MODEL), and the chat
5
+ * it runs in (its turns start on the router, its onboarding and connect cards are the router's). What it gives back: the
6
+ * router's GitHub part, its handlers, the handoff the assistant can send back, the follows it takes up again at start, the
7
+ * open review cards it sweeps, and the stopped items it hears of.
8
+ */
9
+ import { GithubReview, ReviewHandoffAction, type Guardrails, type PostWorkCard, type PublicErrors, type Router, type SubscriptionKeeper } from "@primusclaw/personal-agent";
10
+ import type { AssistantParts } from "./features-assistant.js";
11
+ import type { AssemblyBase } from "./features-base.js";
12
+ /** How often open review cards are checked for an item that is over (Python `CARD_SWEEP_SECONDS`, core `CARD_SWEEP_MS`). */
13
+ export declare const REVIEW_CARD_SWEEP_MS = 120000;
14
+ export interface ReviewInputs {
15
+ readonly guard: Pick<Guardrails, "take" | "giveBack">;
16
+ readonly errors: PublicErrors;
17
+ /** The router, once it is built (the service starts its turns there). */
18
+ readonly router: () => Router;
19
+ readonly subs: SubscriptionKeeper | undefined;
20
+ }
21
+ /**
22
+ * A work item's card in the reviewer's chat when a review waits for them (Python `_tell_reviewer_waiting`: `work_card`,
23
+ * then the card is placed so it is ended with its item).
24
+ */
25
+ export declare function workCardPoster(base: Pick<AssemblyBase, "store">): PostWorkCard;
26
+ export interface ReviewParts {
27
+ readonly service: GithubReview;
28
+ readonly handoff: ReviewHandoffAction;
29
+ }
30
+ /** The review service and the handoff the assistant sends back; undefined with TEAMS_GITHUB_REVIEW_ENABLED off. */
31
+ export declare function reviewParts(base: AssemblyBase, inputs: ReviewInputs, assistant: Pick<AssistantParts, "receipts" | "chat">): ReviewParts | undefined;
@@ -0,0 +1,26 @@
1
+ export type Env = Readonly<Record<string, string | undefined>>;
2
+ export interface FeatureSwitches {
3
+ /** BRIEF_ENABLED == "1": `/brief` (it needs Claw's trigger API). */
4
+ readonly brief: boolean;
5
+ /** ASSISTANT_SCHEDULES_ENABLED == "1". */
6
+ readonly schedules: boolean;
7
+ /** ASSISTANT_JOB_WATCH_ENABLED == "1". */
8
+ readonly jobWatch: boolean;
9
+ /** REMOTE_AGENTS_ENABLED == "1". */
10
+ readonly remoteAgents: boolean;
11
+ /** An attached chat hears its agent between turns (`remote_push_wanted`). */
12
+ readonly remotePush: boolean;
13
+ /** REMOTE_WINDOW_DEFAULT: "chat", or "card" for anything else. */
14
+ readonly remoteWindow: "card" | "chat";
15
+ /** PROACTIVE_ENABLED == "1". */
16
+ readonly proactive: boolean;
17
+ /** Where Claw sends this worker's events ("" when proactive messages are off: no subscriptions at all). */
18
+ readonly notifyUrl: string;
19
+ }
20
+ /** NOTIFY_WEBHOOK_URL, required with PROACTIVE_ENABLED and ignored without it (`notify_url_from_env`). */
21
+ export declare function notifyUrlFromEnv(proactive: boolean, raw: string): string;
22
+ /** On unless REMOTE_PUSH_ENABLED says off, and only with PROACTIVE_ENABLED (`remote_push_wanted`). */
23
+ export declare function remotePushWanted(proactive: boolean, raw: string): boolean;
24
+ /** "chat" when REMOTE_WINDOW_DEFAULT says so, else "card" (`remote_window_default`). */
25
+ export declare function remoteWindowDefault(raw: string): "card" | "chat";
26
+ export declare function featureSwitches(env: Env): FeatureSwitches;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The router's small readers, built from core's pure functions: what a message carries besides its words (quotes, links,
3
+ * files Teams gave no way to fetch), the per-person limits, the channel context a message to the assistant carries, the
4
+ * note card a settled click ends as, `/whoami`'s connection lines, and fetching a message's files through the surface.
5
+ */
6
+ import type { PendingEntry, ChannelContextBuilder, Clock, ConnectionsText, FetchedFile, InboundFile, KnownMember, Integrations, MessageFiles, MessageText, NoteFactory, RouterLimits, Surface, UserLimits } from "@primusclaw/personal-agent";
7
+ /** The router's reading of quotes, links and unreadable files (Python `activity.quote_block`, `with_links`, `with_quote`). */
8
+ export declare const messageText: MessageText;
9
+ /** TEAMS_USER_*: messages per window, tasks at once (Python `limits.UserLimits` and `MessageRateLimiter`). */
10
+ export declare function routerLimits(limits: UserLimits, clock: Clock): RouterLimits;
11
+ /** Python `understanding.channel_context` as `Agent._understood` builds it (the people named, the chat's actions). */
12
+ export declare function channelContextBuilder(store: ContextStore,
13
+ /** What waits for the person's answer (the review service's held confirmations; none without it). */
14
+ pending?: (userId: string) => readonly PendingEntry[]): ChannelContextBuilder;
15
+ interface ContextStore {
16
+ readonly members: {
17
+ knownMembers(): readonly KnownMember[];
18
+ userForChannelId(channelUserId: string): string | null;
19
+ };
20
+ readonly links: {
21
+ clawUserIdOf(userId: string): string | null;
22
+ };
23
+ }
24
+ /** The note card a settled click ends as (Python `render.note_card`). */
25
+ export declare const noteFactory: NoteFactory;
26
+ /** `/whoami`'s lines after its first (the review service's `connectionsText`, with the deployment's integration lines). */
27
+ export declare function whoamiConnections(integrations: Integrations): ConnectionsText;
28
+ /** A message's files through the surface, each once (Python `FileFetcher.fetch_all`): fetched, and why not for the rest. */
29
+ export declare function fetchAll(surface: Pick<Surface, "fetchFile">, files: readonly InboundFile[]): Promise<{
30
+ fetched: FetchedFile[];
31
+ failed: [string, string][];
32
+ }>;
33
+ /** The assistant's side of a message's files (W5 `MessageFiles`). */
34
+ export declare function messageFiles(surface: Pick<Surface, "fetchFile">): MessageFiles;
35
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The turns the router starts (W4b's turn engine), the Stop cards of turns a phone starts, and the approval and question cards
3
+ * those turns show (`Agent._start_turn`'s `on_approval*`, `Agent._decide`).
4
+ */
5
+ import type { ClickHandler, Guardrails, Integrations, PublicErrors, TurnRunner } from "@primusclaw/personal-agent";
6
+ import { turn } from "@primusclaw/personal-agent";
7
+ import { type Style } from "../config/style.js";
8
+ import type { AssemblyBase, RouterHooks } from "./features-base.js";
9
+ export interface TurnInputs {
10
+ readonly style: Style;
11
+ readonly errors: PublicErrors;
12
+ readonly integrations: Integrations;
13
+ }
14
+ /** The router's turn runner: one engine per run, its approval records bound to the person the turn is for. */
15
+ export declare function turnRunner(base: AssemblyBase, inputs: TurnInputs): TurnRunner;
16
+ /** The Stop cards of turns a phone starts (`StopButtons`). */
17
+ export declare function stopCards(base: AssemblyBase): turn.StopButtons;
18
+ /** The buttons of approval and question cards (`Agent._decide`), the person's allowance taken per approval given. */
19
+ export declare function approvalClicks(base: AssemblyBase, guard: Guardrails, hooks: RouterHooks): ClickHandler;
@@ -0,0 +1,18 @@
1
+ import type { JsonObject, OutMessage } from "@primusclaw/personal-agent";
2
+ import { DailyBrief, FeedbackFlow, FeedbackService, FeedbackThumbs, Observer } from "@primusclaw/personal-agent";
3
+ import type { AssemblyBase } from "./features-base.js";
4
+ /** The brief Claw put together, as a message (Python `render.brief_markdown`). */
5
+ export declare function briefMarkdown(brief: JsonObject): string;
6
+ export interface W8Parts {
7
+ readonly service: FeedbackService;
8
+ readonly flow: FeedbackFlow;
9
+ readonly thumbs: FeedbackThumbs;
10
+ readonly observer: Observer;
11
+ readonly brief: DailyBrief;
12
+ /** The Report a problem card under a message of the person's that went wrong. */
13
+ reportView(userId: string, scope: string): OutMessage;
14
+ }
15
+ export declare function w8Parts(base: AssemblyBase, options: {
16
+ readonly briefEnabled: boolean;
17
+ readonly assistantOn: (userId: string) => boolean;
18
+ }): W8Parts;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The features behind the router, built and wired as the Python worker's `main.build_agent`, `Agent.__init__` and
3
+ * `main.build_worker_app` wire them: the router with every feature it hands messages to, what carries Claw's events into the
4
+ * chat (`/claw-events`), the background loops of `main.run`, what runs once at start, and what the release gate's test entry
5
+ * reads. The review service (TEAMS_GITHUB_REVIEW_ENABLED) is built in `features-review.ts`.
6
+ */
7
+ import type { JsonObject, GithubReview } from "@primusclaw/personal-agent";
8
+ import { Router } from "@primusclaw/personal-agent";
9
+ import type { GateSubscriptions } from "../gate/routes.js";
10
+ import type { AssemblyBase } from "./features-base.js";
11
+ export type { AssemblyBase } from "./features-base.js";
12
+ /** The background loops' period (Python `main.SWEEP_SECONDS`). */
13
+ export declare const SWEEP_MS = 60000;
14
+ /** Claw's event type that asks the chat to carry out a command (Python `claw.ASSISTANT_ACTION`). */
15
+ export declare const ASSISTANT_ACTION = "assistant.action";
16
+ export interface FeatureTimer {
17
+ readonly name: string;
18
+ readonly everyMs: number;
19
+ readonly runAtStart: boolean;
20
+ run(): Promise<void>;
21
+ }
22
+ export interface Features {
23
+ readonly router: Router;
24
+ /** `/claw-events`: an `assistant.action` is carried out as the person (`Agent.run_action`), anything else is shown. */
25
+ readonly deliverEvent: (userId: string, reference: JsonObject, event: JsonObject) => Promise<string>;
26
+ /** The loops of `main.run`: name, period, whether the first run is at start, one run. */
27
+ readonly timers: readonly FeatureTimer[];
28
+ /** Once the worker runs: chats attached to a remote agent are followed again (`Agent.resume_remote`). */
29
+ start(): Promise<void>;
30
+ /** The worker stops: the assistant's open receipts are dropped, so their close timers do not keep the process up. */
31
+ stop(): void;
32
+ /** The review service (TEAMS_GITHUB_REVIEW_ENABLED; undefined off), for the gate's review scenarios and the tests. */
33
+ readonly review: GithubReview | undefined;
34
+ /** What the release gate's test entry reads: the subscriptions, and the Claw sessions this worker made. */
35
+ readonly gate: {
36
+ readonly subscriptions: GateSubscriptions | undefined;
37
+ readonly madeSessions: () => readonly string[];
38
+ };
39
+ }
40
+ /** The route the Python worker serves for TEAMS_ON_BEHALF_USERS (link_api.py); a deployment's plugin adds it here. */
41
+ export declare const ON_BEHALF_PATH = "/primus-claw-agent/on-behalf";
42
+ export declare function buildFeatures(given: AssemblyBase): Features;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The worker's HTTP endpoints as it runs them (the Python worker's `build_worker_app`): `/healthz`, the console's
3
+ * `/primus-claw-agent/link`, `/claw-events/<route>` when proactive messages are on, the routes a deployment adds, and in the
4
+ * release gate's test entry its `/gate/v1/*`. `/metrics` is served on a port of its own.
5
+ */
6
+ import type { ClawPort, Clock, JsonObject, Logger, MetricsPort, Plugins } from "@primusclaw/personal-agent";
7
+ import { type HttpRoute, type SqliteStore } from "@primusclaw/personal-agent-runtime";
8
+ export interface WorkerRoutesParts {
9
+ readonly store: SqliteStore;
10
+ readonly claw: ClawPort;
11
+ readonly clock: Clock;
12
+ readonly metrics: MetricsPort;
13
+ readonly logger: Logger;
14
+ readonly plugins: Plugins;
15
+ /** PROACTIVE_ENABLED: Claw's notifications are taken at /claw-events. */
16
+ readonly proactive: boolean;
17
+ /** TEAMS_CLAW_EVENTS_GONE. */
18
+ readonly gone: boolean;
19
+ readonly deliverEvent: (userId: string, reference: JsonObject, event: JsonObject) => Promise<string>;
20
+ }
21
+ export declare function workerRoutes(parts: WorkerRoutesParts): HttpRoute[];
22
+ /** `/metrics` on its own port: the Prometheus text. */
23
+ export declare function metricsRoutes(render: () => string): HttpRoute[];
@@ -0,0 +1,18 @@
1
+ /**
2
+ * One inbound queue message (or a body the gate's test entry posted), as the Python worker's `Agent.handle` took it: a
3
+ * `primusclaw.delivered` ack from the relay settles the post that waits for it; a message or an invoke becomes core's
4
+ * event and goes to the router; anything else is not for the worker. An activity that cannot be read is logged by its kind
5
+ * of failure and dropped (a redelivery cannot make it readable).
6
+ */
7
+ import type { InboundEvent, Logger } from "@primusclaw/personal-agent";
8
+ import type { JsonObject } from "../cards/json.js";
9
+ import type { AckRegistry } from "../messenger/acks.js";
10
+ export declare const DELIVERED = "primusclaw.delivered";
11
+ export interface InboundParts {
12
+ readonly acks: AckRegistry;
13
+ readonly route: (event: InboundEvent) => Promise<void>;
14
+ readonly botName: string;
15
+ readonly logger?: Logger;
16
+ }
17
+ /** The handler of one inbound body. */
18
+ export declare function inboundHandler(parts: InboundParts): (body: JsonObject) => Promise<void>;
@@ -0,0 +1,40 @@
1
+ import type { Clock, Logger } from "@primusclaw/personal-agent";
2
+ import { FederatedCredential } from "../azure/workload-identity.js";
3
+ import type { TeamsSettings } from "../config/env.js";
4
+ import { type ServiceUrlPolicy } from "../connector/hosts.js";
5
+ import type { TokenSource } from "../connector/tokens/cached.js";
6
+ import type { GateEntry } from "../gate/entry-env.js";
7
+ import type { Outbox } from "../outbound/outbox.js";
8
+ import { type BusClient, type BusConnection } from "../servicebus/client.js";
9
+ /** The longest a session's lock is renewed for while one conversation's messages are handled. */
10
+ export declare const LOCK_RENEWAL_MS: number;
11
+ export interface AssemblyDeps {
12
+ readonly clock: Clock;
13
+ readonly logger?: Logger;
14
+ readonly fetch?: typeof fetch;
15
+ /** Reads a key file (default: the file system). */
16
+ readonly readFile?: (path: string) => Buffer;
17
+ }
18
+ export declare class StartupError extends Error {
19
+ name: string;
20
+ }
21
+ /** The bot's token in direct mode (BOT_TOKEN_SOURCE). A federated key that cannot be read stops the worker here, at start. */
22
+ export declare function botTokenSource(settings: TeamsSettings, deps: AssemblyDeps): TokenSource;
23
+ /** The worker identity's credential (one for both queues and the vault), when the settings name the identity. */
24
+ export declare function workerCredential(settings: TeamsSettings, deps: AssemblyDeps): FederatedCredential | undefined;
25
+ /** (inbound, outbound): the worker identity on the namespace when SERVICEBUS_NAMESPACE is set, else the connection strings. */
26
+ export declare function busConnections(settings: TeamsSettings, credential: FederatedCredential | undefined): readonly [BusConnection, BusConnection];
27
+ export interface Outbound {
28
+ readonly outbox: Outbox;
29
+ /** The bot's token, which also fetches a pasted image (direct mode and the gate only). */
30
+ readonly tokens: TokenSource | undefined;
31
+ /** Where the bot's token may go. */
32
+ readonly policy: ServiceUrlPolicy;
33
+ close(): Promise<void>;
34
+ }
35
+ /** The release gate's test entry: the recording connector and nothing else (Microsoft's hosts included). */
36
+ export declare function gateOutbound(gate: GateEntry, deps: AssemblyDeps): Outbound;
37
+ /** The queue by default; in direct mode the Bot Connector with the queue behind it as the fallback. */
38
+ export declare function productionOutbound(settings: TeamsSettings, outbound: BusClient, deps: AssemblyDeps): Outbound;
39
+ /** The SDK clients of the two queues. */
40
+ export declare function busClients(connections: readonly [BusConnection, BusConnection]): readonly [BusClient, BusClient];
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The platform services the Python worker always talks to, in place of the neutral plugins a deployment did not replace:
3
+ * whose key it is from SaFE's `/users/self` (the Python `safe.user_id_of` / `safe.whoami`, used by the subscriptions,
4
+ * `/whoami` and a report), a key deleted at SaFE when it is given up (`safe.revoke_own_key`: /unlink, and pending keys
5
+ * nobody redeemed), and the GitHub issues a report is filed as (`FeedbackService`'s GitHub sink, when FEEDBACK_REPO
6
+ * and a credential are set). A plugin a deployment did replace is kept.
7
+ */
8
+ import { type Logger, type Plugins, type SecretName, type Settings } from "@primusclaw/personal-agent";
9
+ import type { WorkerEnv } from "../worker-api.js";
10
+ export interface PlatformDeps {
11
+ readonly env: WorkerEnv;
12
+ readonly settings: Settings;
13
+ readonly secrets: ReadonlyMap<SecretName, string>;
14
+ readonly fetch: typeof fetch;
15
+ /** Seconds since the epoch. */
16
+ readonly now: () => number;
17
+ readonly logger: Logger;
18
+ }
19
+ /** `plugins` with the identity lookup and the feedback sink the Python worker builds in `main.run` where they are neutral. */
20
+ export declare function platformPlugins(plugins: Plugins, deps: PlatformDeps): Plugins;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A built worker's run: its HTTP endpoints and /metrics listening, the features started, the timers running, then the
3
+ * inbound consumer (or, with no queue, waiting) until it is stopped; everything closed on the way out.
4
+ */
5
+ import type { Clock, Logger } from "@primusclaw/personal-agent";
6
+ import { type buildServer } from "@primusclaw/personal-agent-runtime";
7
+ /** The HTTP server the runtime builds (the teams package does not depend on its framework). */
8
+ type Server = ReturnType<typeof buildServer>;
9
+ import type { InboundConsumer } from "../servicebus/consumer.js";
10
+ import type { Worker } from "../worker-api.js";
11
+ import { type Timer } from "./timers.js";
12
+ export interface RunnerParts {
13
+ readonly app: Server;
14
+ readonly metricsApp: Server;
15
+ readonly host: string;
16
+ readonly port: number;
17
+ readonly metricsPort: number;
18
+ readonly consumer: InboundConsumer | undefined;
19
+ readonly start: () => Promise<void>;
20
+ readonly timers: readonly Timer[];
21
+ readonly clock: Clock;
22
+ readonly logger: Logger;
23
+ readonly close: () => Promise<void>;
24
+ }
25
+ /** Run every close in turn, each even when one before it failed; a failure is logged by its kind. */
26
+ export declare function closeAll(logger: Logger, closes: readonly (() => unknown)[]): Promise<void>;
27
+ export declare function runner(parts: RunnerParts): Worker;
28
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The worker's secrets, from where SECRETS_SOURCE says: the environment (W2's EnvSecretSource) or Azure Key Vault as the
3
+ * worker's own identity. Read once at start; one that cannot be read stops the worker before it opens the store.
4
+ */
5
+ import type { Clock, Logger, SecretName } from "@primusclaw/personal-agent";
6
+ import type { WorkerEnv } from "../worker-api.js";
7
+ export declare function loadSecrets(env: WorkerEnv, deps: {
8
+ readonly clock: Clock;
9
+ readonly logger: Logger;
10
+ readonly fetch?: typeof fetch;
11
+ }): Promise<ReadonlyMap<SecretName, string>>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The worker's background loops (the Python worker's sweep, release, resend, retry and mend tasks): each runs every
3
+ * `everyMs` (first at start when `runAtStart`) until the worker stops; a run that fails is logged by its kind and the loop
4
+ * goes on.
5
+ */
6
+ import type { Clock, Logger } from "@primusclaw/personal-agent";
7
+ export interface Timer {
8
+ readonly name: string;
9
+ readonly everyMs: number;
10
+ readonly runAtStart: boolean;
11
+ run(): Promise<void>;
12
+ }
13
+ /** Run every timer until `signal` aborts; resolves when all have stopped. */
14
+ export declare function startTimers(timers: readonly Timer[], clock: Clock, logger: Logger, signal: AbortSignal): Promise<void>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The worker's services a deployment's plugins are built with (`WorkerServices`): the store's reads, a post into a chat,
3
+ * and a message handled as the person's own (the Python worker's `Agent.on_behalf`: `activity_of_reference` with the text,
4
+ * handled in a task of its own with provenance "on_behalf"). The router is bound once it is built.
5
+ */
6
+ import { type Logger, type Router, type SecurityLog, type Surface } from "@primusclaw/personal-agent";
7
+ import type { SqliteStore } from "@primusclaw/personal-agent-runtime";
8
+ import type { WorkerServices } from "../worker-api.js";
9
+ export interface ServicesParts {
10
+ readonly store: SqliteStore;
11
+ readonly surface: Surface;
12
+ readonly securityLog: SecurityLog;
13
+ readonly logger: Logger;
14
+ readonly botName: string;
15
+ }
16
+ /** The services, the router they wait for, and the background tasks to wait for when the worker stops. */
17
+ export interface BoundServices {
18
+ readonly services: WorkerServices;
19
+ bind(router: Router): void;
20
+ /** Resolves when every task spawned so far has ended. */
21
+ idle(): Promise<void>;
22
+ }
23
+ export declare function workerServices(parts: ServicesParts): BoundServices;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The worker process (`BuildWorker`, the Python worker's `main.run`): secrets, settings, the store, the Claw client, how it
3
+ * reaches Teams, the features behind the router, the HTTP endpoints and /metrics, the inbound queue's consumer (or, in the
4
+ * release gate's test entry, its routes on the loopback instead), and the features' timers. Nothing runs until `run`.
5
+ */
6
+ import { InboundStats, type MetricsPort, type IntegrationRegistry, type Integrations } from "@primusclaw/personal-agent";
7
+ import { PrometheusMetrics } from "@primusclaw/personal-agent-runtime";
8
+ import type { BuildWorker } from "../worker-api.js";
9
+ /**
10
+ * The metrics, with the inbound path also counted for its `inbound_stats` line (Python `InboundStats(metrics=...)`: one line
11
+ * a minute of what was handled, how long it waited and took, what failed and what a limit refused).
12
+ */
13
+ export declare function withInboundStats(prometheus: PrometheusMetrics, stats: InboundStats): MetricsPort;
14
+ /**
15
+ * `integrations` with what `register` adds to them (`WorkerOptions.registerIntegrations`): a registry that starts with
16
+ * every server and line already there, in their order, then takes the deployment's. Without `register`, `integrations`.
17
+ */
18
+ export declare function withRegistered(integrations: Integrations, register: ((registry: IntegrationRegistry) => void) | undefined): Integrations;
19
+ export declare const buildWorker: BuildWorker;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * What SECRETS_SOURCE=keyvault reads and from where: the vault's address (KEYVAULT_URL, checked), the secrets this
3
+ * configuration needs (`wanted`), the vault entry each one is stored under (`VAULT_NAMES`), and the environment
4
+ * setting each one replaces (`ENV_NAMES`, named in a warning when it is set anyway).
5
+ */
6
+ import { type SecretName } from "@primusclaw/personal-agent";
7
+ export type Env = Readonly<Record<string, string | undefined>>;
8
+ export declare const KEYVAULT_SCOPE = "https://vault.azure.net/.default";
9
+ export declare const KEYVAULT_API_VERSION = "7.4";
10
+ /** The setting a secret replaces -> the name of the secret in the vault. */
11
+ export declare const VAULT_NAMES: Readonly<Record<SecretName, string>>;
12
+ /** What the environment holds for each secret with SECRETS_SOURCE=env (the GitHub App key is a mounted file). */
13
+ export declare const ENV_NAMES: Readonly<Record<SecretName, string>>;
14
+ /**
15
+ * The secrets this configuration needs: the encryption keys always, the exchange's client secret when the exchange is
16
+ * on, the GitHub App key when the feedback App is configured (FEEDBACK_GITHUB_APP_ID and FEEDBACK_GITHUB_INSTALLATION_ID).
17
+ */
18
+ export declare function wanted(env: Env): SecretName[];
19
+ /** The environment settings `names` replace that are set anyway: with keyvault they are ignored. */
20
+ export declare function shadowedSettings(env: Env, names: readonly SecretName[]): string[];
21
+ /** The vault's host name, from a URL `vaultUrl` accepted. */
22
+ export declare function vaultHost(url: string): string;
23
+ /** KEYVAULT_URL without a trailing slash: https, a <name>.vault.azure.net host, nothing after the host. */
24
+ export declare function vaultUrl(env: Env): string;
@@ -0,0 +1,52 @@
1
+ import { type Clock, type Logger, type SecretName, type SecretSource } from "@primusclaw/personal-agent";
2
+ import { type Env } from "./keyvault-config.js";
3
+ /** Tries per secret (and for the token) on a transient failure, with waits of 2, 4, 8 and 16 s between them. */
4
+ export declare const ATTEMPTS = 5;
5
+ export declare const BACKOFF_MS = 2000;
6
+ export declare const KEYVAULT_TIMEOUT_MS = 10000;
7
+ /** Everything one load does together; past it the worker stops with a clear line (the startup probe allows two minutes). */
8
+ export declare const LOAD_DEADLINE_MS = 90000;
9
+ /** The token the vault is read with: `FederatedCredential` has this shape. */
10
+ export interface VaultCredential {
11
+ readonly clientId: string;
12
+ /** Throws TokenError (with `transient`) when Entra ID gives no token. */
13
+ token(scope: string, signal?: AbortSignal): Promise<string>;
14
+ }
15
+ export type Sleep = (ms: number, signal?: AbortSignal) => Promise<void>;
16
+ export interface KeyVaultOptions {
17
+ readonly clock: Clock;
18
+ readonly fetch?: typeof fetch;
19
+ readonly logger?: Logger;
20
+ /** The environment, only to name the settings the vault replaces that are set anyway. */
21
+ readonly env?: Env;
22
+ /** The wait between tries; default the clock's. */
23
+ readonly sleep?: Sleep;
24
+ readonly deadlineMs?: number;
25
+ }
26
+ /** " (Forbidden: AccessDenied)": Key Vault's error code and inner code, which carry nothing secret; never its message. */
27
+ export declare function vaultErrorCode(text: string): string;
28
+ export declare class KeyVaultSecretSource implements SecretSource {
29
+ readonly url: string;
30
+ private readonly credential;
31
+ private readonly options;
32
+ readonly name = "keyvault";
33
+ private readonly fetch;
34
+ private readonly logger;
35
+ private readonly sleep;
36
+ /** `url`: a vault address `vaultUrl` accepted. */
37
+ constructor(url: string, credential: VaultCredential, options: KeyVaultOptions);
38
+ load(names: readonly SecretName[]): Promise<ReadonlyMap<SecretName, string>>;
39
+ private readAll;
40
+ private token;
41
+ private read;
42
+ private readOnce;
43
+ }
44
+ export interface KeyVaultEnvOptions extends Omit<KeyVaultOptions, "env"> {
45
+ /** The Entra ID token endpoint; default the tenant's. */
46
+ readonly tokenUrl?: string;
47
+ }
48
+ /**
49
+ * The Key Vault source for SECRETS_SOURCE=keyvault: KEYVAULT_URL checked, the worker identity from the environment and
50
+ * its key read now. Throws SecretsUnavailable naming the setting when one of them cannot work.
51
+ */
52
+ export declare function keyVaultSourceFromEnv(env: Env, options: KeyVaultEnvOptions): KeyVaultSecretSource;
@@ -0,0 +1,56 @@
1
+ import { type Clock, type Logger } from "@primusclaw/personal-agent";
2
+ /** An Azure SDK access token: the bearer token and when it expires (milliseconds since the epoch). */
3
+ export interface AccessToken {
4
+ readonly token: string;
5
+ readonly expiresOnTimestamp: number;
6
+ }
7
+ /** The part of an Azure SDK `TokenCredential` this worker implements. */
8
+ export interface TokenCredential {
9
+ getToken(scopes: string | string[], options?: {
10
+ abortSignal?: AbortSignal;
11
+ }): Promise<AccessToken | null>;
12
+ }
13
+ /** The worker identity is missing a setting or its key cannot be used: the worker does not start. */
14
+ export declare class WorkerIdentityError extends Error {
15
+ name: string;
16
+ }
17
+ /** Entra ID gave no token for the worker identity (what an Azure SDK credential reports as an authentication error). */
18
+ export declare class CredentialAuthenticationError extends Error {
19
+ name: string;
20
+ }
21
+ export interface WorkerIdentity {
22
+ readonly clientId: string;
23
+ readonly tenantId: string;
24
+ /** The https issuer registered in the federated credential, without a trailing slash. */
25
+ readonly issuer: string;
26
+ readonly subject: string;
27
+ readonly keyFile: string;
28
+ }
29
+ /** The identity from the environment; `why` (the setting that needs it) is named when something is missing. */
30
+ export declare function workerIdentityFromEnv(env: Readonly<Record<string, string | undefined>>, why: string): WorkerIdentity;
31
+ /** The signing key's PEM. A key that cannot be read or is not an RSA key stops the worker at start. */
32
+ export declare function readWorkerKey(identity: WorkerIdentity, read?: (path: string) => Buffer): Buffer;
33
+ export interface CredentialOptions {
34
+ readonly clock: Clock;
35
+ readonly fetch?: typeof fetch;
36
+ readonly logger?: Logger;
37
+ /** The token endpoint; default Entra ID's for the tenant. */
38
+ readonly url?: string;
39
+ }
40
+ /** A token credential for the worker identity: one cached token per scope, each from Entra ID for a fresh assertion. */
41
+ export declare class FederatedCredential implements TokenCredential {
42
+ private readonly identity;
43
+ private readonly keyPem;
44
+ private readonly options;
45
+ private readonly providers;
46
+ /** Throws AssertionKeyError now, rather than at the first token, when the key cannot sign. */
47
+ constructor(identity: WorkerIdentity, keyPem: string | Uint8Array, options: CredentialOptions);
48
+ get clientId(): string;
49
+ private provider;
50
+ /** The bearer token for `scope`; throws TokenError (with `transient`) when Entra ID gives none. */
51
+ token(scope: string, signal?: AbortSignal): Promise<string>;
52
+ getToken(scopes: string | string[], options?: {
53
+ abortSignal?: AbortSignal;
54
+ }): Promise<AccessToken>;
55
+ close(): Promise<void>;
56
+ }
@@ -0,0 +1,13 @@
1
+ import type { SurfaceCaps } from "@primusclaw/personal-agent";
2
+ /**
3
+ * How the worker reaches Teams (OUTBOUND_MODE): `direct` posts to the Bot Connector itself; `queue` hands envelopes to
4
+ * the outbound queue, which a relay Function posts (send, reply and update only, and the new message's id comes back
5
+ * as a late ack, if at all).
6
+ */
7
+ export type OutboundMode = "direct" | "queue";
8
+ /**
9
+ * What Teams can do in each mode. A stream needs each request answered with the stream's id at once (direct only); a
10
+ * delete is not in the relay's contract (direct only). Cards, citations and suggested replies are in the activity
11
+ * itself and go either way.
12
+ */
13
+ export declare function teamsCaps(mode: OutboundMode): SurfaceCaps;
@@ -0,0 +1,9 @@
1
+ /** The CJK ranges the card kit treats as Chinese (CJK ideographs, compatibility ideographs, CJK punctuation, full-width forms). */
2
+ export declare const CJK = "[\\u3400-\\u9fff\\uf900-\\ufaff\\u3000-\\u303f\\uff00-\\uffef]";
3
+ export declare function hasCjk(text: unknown): boolean;
4
+ /** `text` with the half-width punctuation next to Chinese made full-width. Text without Chinese is returned as is. */
5
+ export declare function zh(text: unknown): string;
6
+ /** `text` on one line, at most `limit` characters (code points), an ellipsis marking a cut. */
7
+ export declare function clip(text: unknown, limit: number): string;
8
+ /** A word joiner between Chinese characters, so a FactSet's name column does not break "作者" one character to a line. */
9
+ export declare function unbroken(name: string): string;
@@ -0,0 +1,12 @@
1
+ /** JSON values as they go on the wire: what a card, an activity or an envelope is made of. */
2
+ export type Json = string | number | boolean | null | Json[] | JsonObject;
3
+ export interface JsonObject {
4
+ [key: string]: Json;
5
+ }
6
+ /** One element of an Adaptive Card (a TextBlock, a Container, an Action...): a JSON object with a `type`. */
7
+ export interface CardElement extends JsonObject {
8
+ type: string;
9
+ }
10
+ export declare function isObject(value: unknown): value is JsonObject;
11
+ /** Every JSON object in `node`, depth first, `node` itself first. */
12
+ export declare function walk(node: unknown): Generator<JsonObject>;