@primusclaw/personal-agent-teams 0.11.0 → 0.13.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 +1055 -487
- package/dist/main.js +1200 -632
- package/dist/types/activity/inbound/forwards.d.ts +48 -0
- package/dist/types/activity/inbound/index.d.ts +1 -0
- package/dist/types/activity/inbound/links.d.ts +2 -2
- package/dist/types/activity/inbound/markup.d.ts +15 -5
- package/dist/types/activity/inbound/quotes-html.d.ts +29 -0
- package/dist/types/assembly/inbound.d.ts +5 -1
- package/dist/types/assembly/outbound.d.ts +15 -1
- package/dist/types/outbound/outbox.d.ts +2 -1
- package/dist/types/probe/probe.d.ts +58 -0
- package/dist/types/servicebus/client.d.ts +15 -4
- package/dist/types/servicebus/consumer.d.ts +68 -2
- package/dist/types/views/assistant/index.d.ts +7 -1
- package/package.json +3 -3
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The messages a person forwarded into the chat, with the images they showed. Teams says a forward in two ways and a
|
|
3
|
+
* client may use either:
|
|
4
|
+
* - a Forward blockquote in the message's HTML (its text when that is HTML, or its `text/html` attachment), one per
|
|
5
|
+
* message forwarded, after the forwarder's own words: `<p>FYI</p><blockquote itemtype="http://schema.skype.com/
|
|
6
|
+
* Forward">...</blockquote>`, with the author (`itemprop="mri"`) and the time (`itemprop="time"`) when Teams marks
|
|
7
|
+
* them, as a Reply blockquote has them;
|
|
8
|
+
* - a `forwardedMessageReference` attachment, whose `content` (a JSON string, or the object) carries the original:
|
|
9
|
+
* `originalMessageId`, `originalMessageContent` (HTML), `originalSentDateTime`, `originalMessageSender`.
|
|
10
|
+
* Both are read; one message said both ways is one message. An image in a forwarded message (`<img>`, Teams' stored
|
|
11
|
+
* image `.../v1/objects/<id>/views/imgo`) is fetched as a pasted image is, from the Bot Connector the activity came
|
|
12
|
+
* through (`<serviceUrl>v3/attachments/<id>/views/original`), unless the message already carries it as an image
|
|
13
|
+
* attachment; an image with no such id is said to be not passed on.
|
|
14
|
+
*/
|
|
15
|
+
import { type InboundFile, type InboundForward, type Logger } from "@primusclaw/personal-agent";
|
|
16
|
+
import { type Activity } from "./schema.js";
|
|
17
|
+
/** The `contentType` of a forward reference (Teams writes it in this case; it is compared without case). */
|
|
18
|
+
export declare const FORWARD_REFERENCE = "forwardedmessagereference";
|
|
19
|
+
/** The forwarded messages for core, and the message's files with the images they showed added. */
|
|
20
|
+
export interface ForwardsAndFiles {
|
|
21
|
+
readonly forwards: InboundForward[];
|
|
22
|
+
readonly files: InboundFile[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `files` (what `inboundFiles` read from the attachments) with each image of a forwarded message added as a pasted
|
|
26
|
+
* image (once, and not when an attachment already carries it), and the forwarded messages with their image markers
|
|
27
|
+
* made words: `[image-<n>]` for file n, `[image not passed on]` for one that has no Teams id to fetch it by.
|
|
28
|
+
*/
|
|
29
|
+
export declare function forwardsOf(activity: Activity, files: readonly InboundFile[], logger?: Logger): ForwardsAndFiles;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the message's own `text` holds its forwards as Forward blockquotes: `written` cuts them out, so what is left
|
|
32
|
+
* is all the person's own words and nothing of it is a copy of a forward (their "LGTM" before a forwarded "LGTM" stays
|
|
33
|
+
* theirs).
|
|
34
|
+
*/
|
|
35
|
+
export declare function forwardsInText(activity: Activity): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* `text` (the person's words) without the forwarded messages' text that Teams also put there: a client that sends the
|
|
38
|
+
* forward as plain text writes the forwarded messages into `text` as well, after the person's words and in their order,
|
|
39
|
+
* and they must not read as the person's own words. Only that shape is cut: every forwarded message's text, in order, at
|
|
40
|
+
* the end of `text` (after a space, or as all of it). A forwarded text the person happens to repeat in their own words
|
|
41
|
+
* ("who said LGTM on this?" with "LGTM" forwarded), or one written anywhere else, stays theirs; `text` is untouched then.
|
|
42
|
+
*/
|
|
43
|
+
export declare function ownWords(text: string, forwards: readonly InboundForward[], keepSome?: boolean): string;
|
|
44
|
+
/**
|
|
45
|
+
* Logs, by shape only (the attachments' and entities' types), a message that carries an attachment of a kind no reader
|
|
46
|
+
* here reads: how a client says something new (a forward in a form not known yet) shows in the log, never what it held.
|
|
47
|
+
*/
|
|
48
|
+
export declare function logUnreadKinds(activity: Activity, logger: Logger): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Reading an inbound Teams activity: its schema, the readers of its parts, and its mapping to core's events. */
|
|
2
2
|
export * from "./actions.js";
|
|
3
|
+
export * from "./forwards.js";
|
|
3
4
|
export * from "./group-changes.js";
|
|
4
5
|
export * from "./identity.js";
|
|
5
6
|
export * from "./links.js";
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* what the words look like on the screen: a link written with other words than its address shows only those words.
|
|
4
4
|
* Teams sends the address beside it: in the message's `text/html` attachment (`<a href>`), in a link preview card
|
|
5
5
|
* (`url`, an `openUrl` action's `value`), or in an entity's `url`. The links of a quote are the quote's (its Reply
|
|
6
|
-
* blockquote is left out here); a file's `downloadUrl` is a credential and is never read; a picture is not a link.
|
|
6
|
+
* blockquote is left out here), and so are a forwarded message's (its Forward blockquote, whose text carries them); a file's `downloadUrl` is a credential and is never read; a picture is not a link.
|
|
7
7
|
*/
|
|
8
8
|
import { type InboundLink } from "@primusclaw/personal-agent";
|
|
9
9
|
import { type Activity } from "./schema.js";
|
|
@@ -23,7 +23,7 @@ export declare function htmlLinks(markup: string): Link[];
|
|
|
23
23
|
export declare function cardLinks(node: unknown, title?: string, depth?: number): Link[];
|
|
24
24
|
/**
|
|
25
25
|
* The hyperlinks the person's own words carry, each address once, in the order found, at most LINK_COUNT: those of
|
|
26
|
-
* the message's HTML (its quote left out), of a link preview's card, and of an entity.
|
|
26
|
+
* the message's HTML (its quote and forwarded messages left out), of a link preview's card, and of an entity.
|
|
27
27
|
*/
|
|
28
28
|
export declare function linksOf(activity: Activity): Link[];
|
|
29
29
|
/** `linksOf` as core's links: the words shown are the title. */
|
|
@@ -19,17 +19,27 @@ export declare function findTags(text: string, names: readonly string[], closing
|
|
|
19
19
|
export declare function replaceTags(text: string, tags: readonly TagMatch[], by: string): string;
|
|
20
20
|
/** The itemtype of a Reply blockquote: the older way Teams marks a quote. */
|
|
21
21
|
export declare const REPLY_ITEMTYPE: RegExp;
|
|
22
|
+
/**
|
|
23
|
+
* The itemtype of a Forward blockquote: a message forwarded into this chat, one blockquote per message forwarded, after
|
|
24
|
+
* the forwarder's own words (`<p>FYI</p><blockquote itemtype="http://schema.skype.com/Forward">...</blockquote>`).
|
|
25
|
+
*/
|
|
26
|
+
export declare const FORWARD_ITEMTYPE: RegExp;
|
|
27
|
+
/** What `cutReplies` / `cutForwards` give: the markup without the blockquotes cut, and each one cut. */
|
|
28
|
+
export interface CutBlockquotes {
|
|
29
|
+
readonly kept: string;
|
|
30
|
+
readonly cut: [attrs: string, inner: string][];
|
|
31
|
+
}
|
|
22
32
|
/**
|
|
23
33
|
* (`markup` without its Reply blockquotes, [the attributes of each, what is inside it]). A blockquote inside a Reply
|
|
24
34
|
* blockquote belongs to it; a blockquote that is not a Reply stays where it is; one never closed runs to the end.
|
|
25
35
|
*/
|
|
26
|
-
export declare function cutReplies(markup: string):
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
36
|
+
export declare function cutReplies(markup: string): CutBlockquotes;
|
|
37
|
+
/** `cutReplies` for Forward blockquotes: each message forwarded, and the forwarder's own words around them. */
|
|
38
|
+
export declare function cutForwards(markup: string): CutBlockquotes;
|
|
30
39
|
/**
|
|
31
40
|
* `text` as the person wrote it: without what Teams puts there for a quote (the `<quoted .../>` placeholder, and the
|
|
32
|
-
* Reply blockquote of a text that is HTML, with the paragraph tags that come with such a text)
|
|
41
|
+
* Reply blockquote of a text that is HTML, with the paragraph tags that come with such a text) or for a forwarded
|
|
42
|
+
* message (its Forward blockquote, or the `<attachment id="..."/>` that stands for it).
|
|
33
43
|
*/
|
|
34
44
|
export declare function written(activity: Activity): string;
|
|
35
45
|
/**
|
|
@@ -11,6 +11,35 @@ export interface Quote {
|
|
|
11
11
|
/** Where it was read from: for a log line, never the text. */
|
|
12
12
|
readonly source: "entity" | "html" | "placeholder";
|
|
13
13
|
}
|
|
14
|
+
/** An image a forwarded message shows (`<img>`), read where it stands in the text. */
|
|
15
|
+
export interface HtmlImage {
|
|
16
|
+
/** The `src` as written (an http(s) address, else ""). */
|
|
17
|
+
readonly src: string;
|
|
18
|
+
/** The `itemid` (Teams' id of an image it stores), "" when none. */
|
|
19
|
+
readonly itemId: string;
|
|
20
|
+
readonly alt: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Where an image stands in a text read with images (`readImages`): a marker the caller replaces once it knows what the
|
|
24
|
+
* image became (a file of the message, or words saying it was not passed on).
|
|
25
|
+
*/
|
|
26
|
+
export declare function imageMarker(index: number): string;
|
|
27
|
+
export declare const IMAGE_MARKER: RegExp;
|
|
28
|
+
/** A forwarded message as its Forward blockquote (or the HTML a forward reference carries) says it. */
|
|
29
|
+
export interface HtmlForward {
|
|
30
|
+
readonly messageId: string;
|
|
31
|
+
readonly senderId: string;
|
|
32
|
+
readonly sender: string;
|
|
33
|
+
readonly time: string;
|
|
34
|
+
/** The text, each image in it an `imageMarker(i)` of `images[i]`. */
|
|
35
|
+
readonly text: string;
|
|
36
|
+
readonly images: readonly HtmlImage[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The message one Forward blockquote holds: read as a Reply blockquote is (an author and a time when Teams marks them,
|
|
40
|
+
* else everything in it is the message), its images kept as markers.
|
|
41
|
+
*/
|
|
42
|
+
export declare function htmlForward(attrs: string, inner: string): HtmlForward;
|
|
14
43
|
/** The quote one Reply blockquote holds (`attrs`: the blockquote's own attributes; `inner`: what is inside it). */
|
|
15
44
|
export declare function htmlQuote(attrs: string, inner: string): Quote;
|
|
16
45
|
/** The Reply blockquotes of an activity: those of its text (when it is HTML), then of its `text/html` attachments. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
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
|
|
3
|
+
* `primusclaw.delivered` ack from the relay settles the post that waits for it; a `primusclaw.probe` is the delivery probe's
|
|
4
|
+
* (`probe/probe.ts`); a message or an invoke becomes core's
|
|
4
5
|
* 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
6
|
* of failure and dropped (a redelivery cannot make it readable).
|
|
6
7
|
*/
|
|
@@ -8,6 +9,7 @@ import type { InboundEvent, Logger } from "@primusclaw/personal-agent";
|
|
|
8
9
|
import { type GroupContextChanges } from "../activity/inbound/index.js";
|
|
9
10
|
import type { JsonObject } from "../cards/json.js";
|
|
10
11
|
import type { AckRegistry } from "../messenger/acks.js";
|
|
12
|
+
import { DeliveryProbe } from "../probe/probe.js";
|
|
11
13
|
export declare const DELIVERED = "primusclaw.delivered";
|
|
12
14
|
export interface InboundParts {
|
|
13
15
|
readonly acks: AckRegistry;
|
|
@@ -16,6 +18,8 @@ export interface InboundParts {
|
|
|
16
18
|
readonly logger?: Logger;
|
|
17
19
|
/** The recent messages kept of group chats: a removal, delete or edit in a group changes them (none: nothing kept). */
|
|
18
20
|
readonly groupContext?: GroupContextChanges;
|
|
21
|
+
/** Answers the delivery probe (`primusclaw.probe`); none: a probe is dropped unanswered. */
|
|
22
|
+
readonly probe?: DeliveryProbe;
|
|
19
23
|
}
|
|
20
24
|
/** The handler of one inbound body. */
|
|
21
25
|
export declare function inboundHandler(parts: InboundParts): (body: JsonObject) => Promise<void>;
|
|
@@ -7,7 +7,19 @@ import type { TokenSource } from "../connector/tokens/cached.js";
|
|
|
7
7
|
import type { GateEntry } from "../gate/entry-env.js";
|
|
8
8
|
import type { Outbox } from "../outbound/outbox.js";
|
|
9
9
|
import { type BusClient, type BusConnection } from "../servicebus/client.js";
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The work a handler does around the turn it follows (TURN_DEADLINE_SECONDS): the Claw calls before the turn is submitted
|
|
12
|
+
* and the replies sent after it ends, with room to spare. Part of the lock renewal, so that work never outlives the lock.
|
|
13
|
+
*/
|
|
14
|
+
export declare const HANDLER_MARGIN_MS: number;
|
|
15
|
+
/**
|
|
16
|
+
* The longest a session's lock is renewed for, from its accept: past the consumer's hold of a session (SESSION_HOLD_MS),
|
|
17
|
+
* the wait for one more message (RECEIVE_DEADLINE_MS), a handler that runs as long as the chat follows a turn
|
|
18
|
+
* (TURN_DEADLINE_SECONDS) plus the work around it (HANDLER_MARGIN_MS), and the settlement after it (SETTLE_DEADLINE_MS),
|
|
19
|
+
* so the lock never lapses while a message is in hand: a lapsed lock makes the broker hand the message to another
|
|
20
|
+
* receiver, and the request runs twice. A closed session releases its lock at once, and a worker that dies loses it
|
|
21
|
+
* after the queue's lock duration: this bound only caps the renewal of a live worker.
|
|
22
|
+
*/
|
|
11
23
|
export declare const LOCK_RENEWAL_MS: number;
|
|
12
24
|
export interface AssemblyDeps {
|
|
13
25
|
readonly clock: Clock;
|
|
@@ -29,6 +41,8 @@ export interface Outbound {
|
|
|
29
41
|
readonly tokens: TokenSource | undefined;
|
|
30
42
|
/** Where the bot's token may go. */
|
|
31
43
|
readonly policy: ServiceUrlPolicy;
|
|
44
|
+
/** The outbound queue itself (the delivery probe's answer always goes through the relay); none for the gate. */
|
|
45
|
+
readonly queue?: Outbox;
|
|
32
46
|
close(): Promise<void>;
|
|
33
47
|
}
|
|
34
48
|
/** The release gate's test entry: the recording connector and nothing else (Microsoft's hosts included). */
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* `{"operation", "reference", "activity", ["activity_id"], ["ack"]}`.
|
|
5
5
|
*/
|
|
6
6
|
import type { JsonObject } from "../cards/json.js";
|
|
7
|
-
|
|
7
|
+
/** `probe`: the delivery probe's answer (`probe/probe.ts`); the relay acks it without posting anything to Teams. */
|
|
8
|
+
export type Operation = "send" | "reply" | "update" | "delete" | "probe";
|
|
8
9
|
/** One outbound envelope. `reference` is the conversation reference (`activity.referenceOf`), `activity` the message. */
|
|
9
10
|
export interface TeamsEnvelope extends JsonObject {
|
|
10
11
|
operation: Operation;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The delivery probe: a synthetic message that takes the path every person's message takes, so a broken or slow path is
|
|
3
|
+
* seen when nobody is writing, not when somebody's message is lost. The ingress puts a `primusclaw.probe` on the inbound
|
|
4
|
+
* queue every few minutes (its timer, PRIMUSCLAW_PROBE_SCHEDULE) under its own session; the worker's consumer takes it
|
|
5
|
+
* like any message and answers it here, the way it answers a person: one envelope on the outbound queue, as it would put a
|
|
6
|
+
* typing indicator there, with an ack. The relay takes that envelope (operation `probe`), posts nothing to Teams, and acks
|
|
7
|
+
* it back on the inbound queue as it acks a posted message.
|
|
8
|
+
*
|
|
9
|
+
* Two times are measured from when the ingress sent the probe: `feedback`, until the worker had queued its answer (when a
|
|
10
|
+
* person's typing indicator is queued), and `reply`, until the relay's ack came back to the worker (the whole round trip
|
|
11
|
+
* through both queues and the relay). Each probe gets one line, `delivery probe`, and the metrics port the outcome. A probe
|
|
12
|
+
* that gets no ack within PROBE_REPLY_TIMEOUT_MS is counted unanswered. Never touches a conversation, a person or Claw.
|
|
13
|
+
*/
|
|
14
|
+
import type { Clock, Logger } from "@primusclaw/personal-agent";
|
|
15
|
+
import type { JsonObject } from "../cards/json.js";
|
|
16
|
+
import type { AckRegistry } from "../messenger/acks.js";
|
|
17
|
+
import type { Outbox } from "../outbound/outbox.js";
|
|
18
|
+
/** The type of a probe on the inbound queue (the ingress's PROBE_TYPE). */
|
|
19
|
+
export declare const PROBE = "primusclaw.probe";
|
|
20
|
+
/** The conversation (and session) a probe and its answer go under; no Teams conversation has this id. */
|
|
21
|
+
export declare const PROBE_CONVERSATION = "primusclaw-probe";
|
|
22
|
+
/** How long a probe's ack is waited for before the probe is counted unanswered. */
|
|
23
|
+
export declare const PROBE_REPLY_TIMEOUT_MS = 120000;
|
|
24
|
+
/** Where a probe's outcome is counted: milliseconds to the answer queued, and to the ack (null: none came in time). */
|
|
25
|
+
export interface ProbeStats {
|
|
26
|
+
probed(feedbackMs: number, replyMs: number | null): void;
|
|
27
|
+
}
|
|
28
|
+
export interface ProbeParts {
|
|
29
|
+
/** The outbound queue (the relay's); none (the release gate's test entry): probes are not answered. */
|
|
30
|
+
readonly outbox: Outbox | undefined;
|
|
31
|
+
readonly acks: AckRegistry;
|
|
32
|
+
readonly clock: Clock;
|
|
33
|
+
readonly stats?: ProbeStats;
|
|
34
|
+
readonly logger?: Logger;
|
|
35
|
+
readonly timeoutMs?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Answers probes; `close` stops waiting for the acks still out (the worker is stopping). */
|
|
38
|
+
export declare class DeliveryProbe {
|
|
39
|
+
private readonly parts;
|
|
40
|
+
private readonly logger;
|
|
41
|
+
private readonly stopping;
|
|
42
|
+
private readonly waiting;
|
|
43
|
+
constructor(parts: ProbeParts);
|
|
44
|
+
/** Whether `body` is a probe (the inbound handler hands it here instead of reading it as an activity). */
|
|
45
|
+
static is(body: JsonObject): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Answer one probe: queue the answer, and wait for its ack in the background (the ack comes on the probe's own session,
|
|
48
|
+
* which the consumer reads only after this returns). A probe that cannot be read is logged and dropped; one whose answer
|
|
49
|
+
* cannot be queued is counted unanswered at once. Never throws: a redelivered probe would measure the redelivery.
|
|
50
|
+
*/
|
|
51
|
+
answer(body: JsonObject): Promise<void>;
|
|
52
|
+
/** Resolves once every probe answered so far has its ack or has timed out (a test waits for it). */
|
|
53
|
+
settled(): Promise<void>;
|
|
54
|
+
/** Stop waiting for acks: the worker is stopping (the probes still out are neither answered nor counted). */
|
|
55
|
+
close(): void;
|
|
56
|
+
private since;
|
|
57
|
+
private awaitAck;
|
|
58
|
+
}
|
|
@@ -18,8 +18,11 @@ export interface Received {
|
|
|
18
18
|
}
|
|
19
19
|
/** A receiver locked on one session: messages in order, settled one by one. */
|
|
20
20
|
export interface SessionReceiver {
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* At most `count` messages, waiting at most `waitMs` for the first (none: the session has gone quiet). With `signal`,
|
|
23
|
+
* the wait ends (rejects) when it is aborted.
|
|
24
|
+
*/
|
|
25
|
+
receive(count: number, waitMs: number, signal?: AbortSignal): Promise<Received[]>;
|
|
23
26
|
complete(message: Received): Promise<void>;
|
|
24
27
|
abandon(message: Received): Promise<void>;
|
|
25
28
|
deadLetter(message: Received, reason: string, description: string): Promise<void>;
|
|
@@ -27,8 +30,16 @@ export interface SessionReceiver {
|
|
|
27
30
|
}
|
|
28
31
|
export interface BusClient {
|
|
29
32
|
sender(queue: string): BusSender;
|
|
30
|
-
/** The next session that has messages; rejects (a timeout) when none has any. */
|
|
31
|
-
acceptNextSession(queue: string): Promise<SessionReceiver>;
|
|
33
|
+
/** The next session that has messages; rejects (a timeout) when none has any, or when `signal` is aborted. */
|
|
34
|
+
acceptNextSession(queue: string, signal?: AbortSignal): Promise<SessionReceiver>;
|
|
35
|
+
/**
|
|
36
|
+
* Open a new connection for what is asked next (the receivers' re-arm, when a call on the old one hangs). The old one
|
|
37
|
+
* is left open, since other receivers on it may still be handling a message whose session lock it holds: closing it
|
|
38
|
+
* then would drop their locks and the broker would hand the message to someone else while it is still being handled.
|
|
39
|
+
* Returns the old connection's close, for the caller to run once nothing it took on the old connection is in hand.
|
|
40
|
+
* Optional: a client without it is only asked again.
|
|
41
|
+
*/
|
|
42
|
+
reopen?(): () => Promise<void>;
|
|
32
43
|
close(): Promise<void>;
|
|
33
44
|
}
|
|
34
45
|
/** How the worker reaches a namespace: a SAS connection string, or an Entra identity on the namespace's host name. */
|
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
* gets one line (`inbound message`): its id, what came of it (completed, abandoned, dead_lettered), how long it waited in
|
|
7
7
|
* the queue and how long it took; never its body. For an activity that decodes, the line also says when the client sent it
|
|
8
8
|
* (`clientTiming`), so a message that reached Teams late can be told apart from one the person sent late.
|
|
9
|
+
*
|
|
10
|
+
* Stopping (the pod's SIGTERM, a cutover) drains: no session is taken any more and the waits for one or for the next
|
|
11
|
+
* message end at once; a message being handled is finished and settled; a message that arrives after the stop is
|
|
12
|
+
* abandoned (outcome `released`), and every session is closed, so its lock is released and the next worker takes its
|
|
13
|
+
* messages without waiting for the lock to expire. Nothing taken is left unsettled on purpose.
|
|
14
|
+
*
|
|
15
|
+
* A call on the broker that hangs (a dead AMQP connection the SDK does not notice: the ingress met one, #896) is given up
|
|
16
|
+
* after its deadline: the receiver is dropped, a new connection opened (`BusClient.reopen`), and the session taken again,
|
|
17
|
+
* so a wedged receiver re-arms itself instead of leaving its conversations waiting (`inbound receiver re-armed`). The old
|
|
18
|
+
* connection is closed only once no receiver still holds a session taken on it: another receiver may be handling a message
|
|
19
|
+
* there, and closing the connection under it would drop its session lock, so the broker would hand the same message to a
|
|
20
|
+
* receiver on the new connection while the first is still handling it (a duplicate reply).
|
|
21
|
+
*
|
|
22
|
+
* A session is held for at most SESSION_HOLD_MS of messages: then it is closed and taken again, so the lock renewal of
|
|
23
|
+
* the bus client (which must outlast that hold, plus the wait for one more message, plus the longest message handled)
|
|
24
|
+
* never runs out while a message is in hand; a lapsed lock would hand that message to another receiver (a duplicate).
|
|
9
25
|
*/
|
|
10
26
|
import type { Clock, Logger } from "@primusclaw/personal-agent";
|
|
11
27
|
import { type JsonObject } from "../cards/json.js";
|
|
@@ -16,9 +32,32 @@ export declare const IDLE_MS = 20000;
|
|
|
16
32
|
export declare const BACKOFF_MS = 3000;
|
|
17
33
|
/** After finding no session with messages, wait this long before asking again. */
|
|
18
34
|
export declare const NO_SESSION_PAUSE_MS = 1000;
|
|
35
|
+
/**
|
|
36
|
+
* A call for the next session that has not answered in this long is on a wedged connection. The SDK gives up on it by
|
|
37
|
+
* itself after its operation timeout (60 s), with the documented ServiceTimeout, when no session has messages.
|
|
38
|
+
*/
|
|
39
|
+
export declare const ACCEPT_DEADLINE_MS = 120000;
|
|
40
|
+
/** A wait for the next message (at most IDLE_MS) that has not ended this much later is on a wedged connection. */
|
|
41
|
+
export declare const RECEIVE_DEADLINE_MS: number;
|
|
42
|
+
/** A settlement (the SDK retries one itself) or a close that has not ended in this long is on a wedged connection. */
|
|
43
|
+
export declare const SETTLE_DEADLINE_MS = 60000;
|
|
44
|
+
/**
|
|
45
|
+
* A receiver that has held one session this long takes no further message from it: it closes the session, and the next
|
|
46
|
+
* accept takes it (or another) again. The session's lock is renewed for a bounded time from the accept (the bus client's
|
|
47
|
+
* lock renewal), so a busy conversation never keeps one lock past that bound while its messages keep coming.
|
|
48
|
+
*/
|
|
49
|
+
export declare const SESSION_HOLD_MS: number;
|
|
19
50
|
/** What the handled messages are counted in: how long each waited in the queue and took to handle. */
|
|
20
51
|
export interface InboundStats {
|
|
21
52
|
processed(queueLagMs: number | undefined, handleMs: number, ok: boolean): void;
|
|
53
|
+
/** A call on the broker hung and the receivers' connection was re-opened (once per connection, however many hung). */
|
|
54
|
+
rearmed?(): void;
|
|
55
|
+
}
|
|
56
|
+
/** A call on the broker that did not answer within its deadline. */
|
|
57
|
+
export declare class WedgedCall extends Error {
|
|
58
|
+
readonly call: string;
|
|
59
|
+
name: string;
|
|
60
|
+
constructor(call: string);
|
|
22
61
|
}
|
|
23
62
|
/** Whether a broker error is the documented "no session has messages" timeout of acceptNextSession. */
|
|
24
63
|
export declare function isIdleTimeout(error: unknown): boolean;
|
|
@@ -60,15 +99,42 @@ export interface ConsumerParts {
|
|
|
60
99
|
}
|
|
61
100
|
export declare class InboundConsumer {
|
|
62
101
|
private readonly parts;
|
|
63
|
-
private
|
|
102
|
+
private readonly stopping;
|
|
64
103
|
private readonly logger;
|
|
104
|
+
/** Which connection the receivers are on: a receiver re-opens it only if no other has since it took its session. */
|
|
105
|
+
private generation;
|
|
106
|
+
/** How many receivers are in a pass on each connection (by generation): a session taken there may be in hand. */
|
|
107
|
+
private readonly holders;
|
|
108
|
+
/** The close of each connection given up on, run once its last holder lets go. */
|
|
109
|
+
private readonly retiring;
|
|
65
110
|
constructor(parts: ConsumerParts);
|
|
66
|
-
/**
|
|
111
|
+
/** (a method, not a getter: the stop comes between two reads, which a narrowed property would hide) */
|
|
112
|
+
private isStopped;
|
|
113
|
+
/** Run the receivers until `stop`; resolves once each has settled what it took and closed its session. */
|
|
67
114
|
run(): Promise<void>;
|
|
115
|
+
/** Take nothing more: the waits end now, a message being handled is finished, and `run` resolves after the drain. */
|
|
68
116
|
stop(): void;
|
|
117
|
+
/**
|
|
118
|
+
* `call`, given up as wedged (WedgedCall) when it has not answered within `ms`; with `stoppable`, ended (rejected) by
|
|
119
|
+
* the stop too. The deadline is this consumer's own timer, so an SDK call that ignores its abort signal still ends.
|
|
120
|
+
*/
|
|
121
|
+
private within;
|
|
69
122
|
private loop;
|
|
123
|
+
/** Take a session on the current connection and handle it until it goes quiet; what failed, for the pause after. */
|
|
124
|
+
private pass;
|
|
125
|
+
private hold;
|
|
126
|
+
private letGo;
|
|
127
|
+
/** Close a connection given up on, once no receiver holds a session taken on it (a wedged close is not waited for). */
|
|
128
|
+
private retire;
|
|
70
129
|
private pause;
|
|
130
|
+
/**
|
|
131
|
+
* A call hung: a new connection is opened, once for all receivers that were on the old one, and the session taken
|
|
132
|
+
* again. The old connection is closed when its last holder lets go (`retire`), not now: see the head of this file.
|
|
133
|
+
*/
|
|
134
|
+
private rearm;
|
|
71
135
|
private drain;
|
|
136
|
+
/** A message taken after the stop goes back to the queue at once, for the next worker. */
|
|
137
|
+
private release;
|
|
72
138
|
private dispatch;
|
|
73
139
|
private record;
|
|
74
140
|
/** The one line for a message taken: ids, outcome and times only. */
|
|
@@ -4,7 +4,7 @@
|
|
|
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 ChoiceCardModel, type ChoiceChosenModel, 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 WorkDeliveredModel, 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";
|
|
@@ -18,6 +18,11 @@ export declare function workButtons(cardId: string, version: number, canAccept:
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function noteCard(value: string, actions?: CardElement[], title?: string, tone?: Tone): TeamsMessage;
|
|
20
20
|
declare function workCard(model: WorkCardModel): TeamsMessage;
|
|
21
|
+
/**
|
|
22
|
+
* A result Claw delivered without an Accept, where the card that asked for one was: the version, the pull request the item still
|
|
23
|
+
* watches, what the assistant said, and that a reply changes it. No buttons.
|
|
24
|
+
*/
|
|
25
|
+
declare function workDelivered(model: WorkDeliveredModel): TeamsMessage;
|
|
21
26
|
declare function workDone(model: WorkDoneModel): TeamsMessage;
|
|
22
27
|
declare function workNote(model: WorkNoteModel): TeamsMessage;
|
|
23
28
|
/** The board's own buttons: Accept all (the primary button) and a Retry for each task that failed or was stopped. */
|
|
@@ -44,6 +49,7 @@ export declare const assistantRenderers: {
|
|
|
44
49
|
board: typeof board;
|
|
45
50
|
confirmWrite: typeof confirmWrite;
|
|
46
51
|
workCard: typeof workCard;
|
|
52
|
+
workDelivered: typeof workDelivered;
|
|
47
53
|
workDone: typeof workDone;
|
|
48
54
|
workNote: typeof workNote;
|
|
49
55
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primusclaw/personal-agent-teams",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "The personal agent on Microsoft Teams: activities, Adaptive Cards, streams, Bot Connector, inbound queue, and the worker's Teams surface.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@azure/core-auth": "^1.11.0",
|
|
37
37
|
"@azure/service-bus": "^7.10.0",
|
|
38
|
-
"@primusclaw/personal-agent": "0.
|
|
39
|
-
"@primusclaw/personal-agent-runtime": "0.
|
|
38
|
+
"@primusclaw/personal-agent": "0.13.0",
|
|
39
|
+
"@primusclaw/personal-agent-runtime": "0.13.0",
|
|
40
40
|
"zod": "^4.6.7"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|