@primusclaw/personal-agent-teams 0.15.2 → 0.15.3
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 +94 -114
- package/dist/main.js +94 -114
- package/dist/types/activity/inbound/mentions.d.ts +1 -1
- package/dist/types/assembly/inbound.d.ts +12 -1
- package/dist/types/assembly/outbound.d.ts +14 -8
- package/dist/types/assembly/worker.d.ts +12 -2
- package/dist/types/connector/errors.d.ts +2 -0
- package/dist/types/connector/limits.d.ts +1 -3
- package/dist/types/connector/outbox.d.ts +28 -28
- package/dist/types/gate/gate-token.d.ts +13 -0
- package/dist/types/probe/probe.d.ts +10 -4
- package/package.json +3 -3
- package/dist/types/gate/no-queue.d.ts +0 -22
package/dist/index.js
CHANGED
|
@@ -5314,6 +5314,9 @@ var UndeliverableError = class extends Error {
|
|
|
5314
5314
|
this.code = details.code ?? "";
|
|
5315
5315
|
}
|
|
5316
5316
|
};
|
|
5317
|
+
function isUndelivered(error) {
|
|
5318
|
+
return error instanceof UndeliverableError || error instanceof UnaddressableError;
|
|
5319
|
+
}
|
|
5317
5320
|
var DeadlineError = class extends Error {
|
|
5318
5321
|
name = "TimeoutError";
|
|
5319
5322
|
};
|
|
@@ -5851,7 +5854,7 @@ function tokenSourceOf(env, secretSet) {
|
|
|
5851
5854
|
const fallback = secretSet ? "secret" : "imds";
|
|
5852
5855
|
return oneOf(env, "BOT_TOKEN_SOURCE", ["imds", "federated", "secret"], fallback);
|
|
5853
5856
|
}
|
|
5854
|
-
function botFromEnv(env, mode) {
|
|
5857
|
+
function botFromEnv(env, mode, holdsToken) {
|
|
5855
5858
|
const secretSet = get(env, "BOT_CLIENT_SECRET") !== "";
|
|
5856
5859
|
const tokenSource = tokenSourceOf(env, secretSet);
|
|
5857
5860
|
const federated = tokenSource === "federated";
|
|
@@ -5862,7 +5865,7 @@ function botFromEnv(env, mode) {
|
|
|
5862
5865
|
}
|
|
5863
5866
|
const settings = {
|
|
5864
5867
|
tokenSource,
|
|
5865
|
-
msiClientId:
|
|
5868
|
+
msiClientId: holdsToken && !secret ? required(env, "BOT_MSI_CLIENT_ID") : get(env, "BOT_MSI_CLIENT_ID"),
|
|
5866
5869
|
clientId: secret ? required(env, "BOT_CLIENT_ID") : get(env, "BOT_CLIENT_ID"),
|
|
5867
5870
|
clientSecretIgnored: secretSet && !secret,
|
|
5868
5871
|
tenantId: federated || secret ? required(env, "BOT_TENANT_ID") : get(env, "BOT_TENANT_ID"),
|
|
@@ -5887,11 +5890,11 @@ var NO_QUEUES = {
|
|
|
5887
5890
|
outboundQueue: "",
|
|
5888
5891
|
receiverCount: 0
|
|
5889
5892
|
};
|
|
5890
|
-
function busFromEnv(env, namespace) {
|
|
5893
|
+
function busFromEnv(env, namespace, mode) {
|
|
5891
5894
|
return {
|
|
5892
5895
|
namespace,
|
|
5893
5896
|
listenConnectionString: namespace ? "" : required(env, "SERVICEBUS_LISTEN_CONNECTION_STRING"),
|
|
5894
|
-
sendConnectionString: namespace ? "" : required(env, "SERVICEBUS_SEND_CONNECTION_STRING"),
|
|
5897
|
+
sendConnectionString: namespace || mode === "direct" ? "" : required(env, "SERVICEBUS_SEND_CONNECTION_STRING"),
|
|
5895
5898
|
inboundQueue: env["INBOUND_QUEUE"] ?? "primusclaw-inbound",
|
|
5896
5899
|
outboundQueue: env["OUTBOUND_QUEUE"] ?? "primusclaw-outbound",
|
|
5897
5900
|
receiverCount: wholeNumber(env, "RECEIVER_COUNT", 8)
|
|
@@ -5918,8 +5921,8 @@ function teamsSettingsFromEnv(env, options = {}) {
|
|
|
5918
5921
|
const queues = options.queues ?? true;
|
|
5919
5922
|
return {
|
|
5920
5923
|
outboundMode: mode,
|
|
5921
|
-
bot: botFromEnv(env, mode),
|
|
5922
|
-
bus: queues ? busFromEnv(env, namespace) : NO_QUEUES,
|
|
5924
|
+
bot: botFromEnv(env, mode, mode === "direct" && queues),
|
|
5925
|
+
bus: queues ? busFromEnv(env, namespace, mode) : NO_QUEUES,
|
|
5923
5926
|
workerIdentity: why ? identityFor(env, why) : void 0,
|
|
5924
5927
|
installHintUrl,
|
|
5925
5928
|
style: styleFromEnv(env)
|
|
@@ -6580,8 +6583,15 @@ var DeliveryProbe = class {
|
|
|
6580
6583
|
this.logger.warn("delivery probe not read", { why: "malformed" });
|
|
6581
6584
|
return;
|
|
6582
6585
|
}
|
|
6586
|
+
if (this.stopping.signal.aborted) return;
|
|
6587
|
+
if (this.parts.inboundOnly === true) {
|
|
6588
|
+
const elapsedMs = this.since(sent);
|
|
6589
|
+
this.logger.info("delivery probe", { id, outcome: "answered", feedback_ms: elapsedMs, reply_ms: elapsedMs });
|
|
6590
|
+
this.parts.stats?.probed(elapsedMs, elapsedMs);
|
|
6591
|
+
return;
|
|
6592
|
+
}
|
|
6583
6593
|
const outbox = this.parts.outbox;
|
|
6584
|
-
if (outbox === void 0
|
|
6594
|
+
if (outbox === void 0) return;
|
|
6585
6595
|
const ack = `probe-${id}`;
|
|
6586
6596
|
const waiter = this.parts.acks.expect(ack);
|
|
6587
6597
|
try {
|
|
@@ -6988,7 +6998,16 @@ function inboundHandler(parts) {
|
|
|
6988
6998
|
logger.warn("an inbound activity was not read", { why: event.error.kind });
|
|
6989
6999
|
return;
|
|
6990
7000
|
}
|
|
6991
|
-
if (event.value
|
|
7001
|
+
if (event.value === void 0) return;
|
|
7002
|
+
try {
|
|
7003
|
+
await parts.route(event.value);
|
|
7004
|
+
} catch (error) {
|
|
7005
|
+
if (!isUndelivered(error)) throw error;
|
|
7006
|
+
logger.warn("a reply to an inbound message was not delivered; the message is completed, not redelivered", {
|
|
7007
|
+
error: error.name
|
|
7008
|
+
});
|
|
7009
|
+
if (event.value.id) parts.markProcessed?.(event.value.id);
|
|
7010
|
+
}
|
|
6992
7011
|
};
|
|
6993
7012
|
}
|
|
6994
7013
|
function editedText(activity, parts) {
|
|
@@ -6998,7 +7017,7 @@ function editedText(activity, parts) {
|
|
|
6998
7017
|
|
|
6999
7018
|
// packages/teams/src/assembly/outbound.ts
|
|
7000
7019
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
7001
|
-
import { silentLogger as
|
|
7020
|
+
import { silentLogger as silentLogger19, turn as turn3 } from "@primusclaw/personal-agent";
|
|
7002
7021
|
import { StartupError } from "@primusclaw/personal-agent-runtime/worker";
|
|
7003
7022
|
|
|
7004
7023
|
// packages/teams/src/connector/outbox.ts
|
|
@@ -7014,8 +7033,7 @@ var DEFAULT_LIMITS = {
|
|
|
7014
7033
|
sendDeadlineMs: 3e4,
|
|
7015
7034
|
openAttempts: 2,
|
|
7016
7035
|
openRequestTimeoutMs: 8e3,
|
|
7017
|
-
openDeadlineMs: 12e3
|
|
7018
|
-
queueStickyMs: 6e4
|
|
7036
|
+
openDeadlineMs: 12e3
|
|
7019
7037
|
};
|
|
7020
7038
|
|
|
7021
7039
|
// packages/teams/src/connector/request.ts
|
|
@@ -7246,7 +7264,6 @@ function throwIfAborted(signal) {
|
|
|
7246
7264
|
var ConnectorOutbox = class {
|
|
7247
7265
|
constructor(options) {
|
|
7248
7266
|
this.options = options;
|
|
7249
|
-
this.fallback = options.fallback;
|
|
7250
7267
|
this.clock = options.clock;
|
|
7251
7268
|
this.logger = options.logger ?? silentLogger15;
|
|
7252
7269
|
this.policy = options.policy ?? DEFAULT_CONNECTOR_HOSTS;
|
|
@@ -7263,7 +7280,6 @@ var ConnectorOutbox = class {
|
|
|
7263
7280
|
});
|
|
7264
7281
|
}
|
|
7265
7282
|
options;
|
|
7266
|
-
fallback;
|
|
7267
7283
|
clock;
|
|
7268
7284
|
logger;
|
|
7269
7285
|
policy;
|
|
@@ -7271,8 +7287,6 @@ var ConnectorOutbox = class {
|
|
|
7271
7287
|
limits;
|
|
7272
7288
|
client;
|
|
7273
7289
|
lanes = new Lanes();
|
|
7274
|
-
/** conversation -> until when (monotonic ms) its sends go to the queue. */
|
|
7275
|
-
onQueueUntil = /* @__PURE__ */ new Map();
|
|
7276
7290
|
/** The bot's token source, which also fetches what a user attached. */
|
|
7277
7291
|
get tokens() {
|
|
7278
7292
|
return this.options.tokens;
|
|
@@ -7282,9 +7296,10 @@ var ConnectorOutbox = class {
|
|
|
7282
7296
|
return this.lanes.size;
|
|
7283
7297
|
}
|
|
7284
7298
|
/**
|
|
7285
|
-
* Deliver one envelope to Teams. Delivered: Teams has it. undefined:
|
|
7286
|
-
*
|
|
7287
|
-
*
|
|
7299
|
+
* Deliver one envelope to Teams. Delivered: Teams has it. undefined: a typing indicator that could not be sent was
|
|
7300
|
+
* dropped (nobody waits for one). A send that is not confirmed as delivered rejects with the reason (UndeliverableError, or
|
|
7301
|
+
* UnaddressableError for an address the policy refuses, before any request is made). An aborted `options.signal` sends nothing more and rejects
|
|
7302
|
+
* with its reason: no retry.
|
|
7288
7303
|
*/
|
|
7289
7304
|
async publish(envelope2, options = {}) {
|
|
7290
7305
|
const described = describe(envelope2);
|
|
@@ -7293,7 +7308,6 @@ var ConnectorOutbox = class {
|
|
|
7293
7308
|
described.key,
|
|
7294
7309
|
async () => {
|
|
7295
7310
|
throwIfAborted(options.signal);
|
|
7296
|
-
if (this.queuedFor(described.key) > 0) return this.whileOnQueue(envelope2, described, options);
|
|
7297
7311
|
return this.direct(envelope2, described, started, options);
|
|
7298
7312
|
},
|
|
7299
7313
|
options.signal
|
|
@@ -7311,21 +7325,6 @@ var ConnectorOutbox = class {
|
|
|
7311
7325
|
});
|
|
7312
7326
|
return { activityId: answer.id };
|
|
7313
7327
|
}
|
|
7314
|
-
async whileOnQueue(envelope2, described, options) {
|
|
7315
|
-
const { operation, kind, key, conversation, content } = described;
|
|
7316
|
-
this.logger.info("direct send skipped: the conversation stays on the queue", {
|
|
7317
|
-
operation,
|
|
7318
|
-
kind,
|
|
7319
|
-
leftMs: this.queuedFor(key),
|
|
7320
|
-
conversation,
|
|
7321
|
-
content
|
|
7322
|
-
});
|
|
7323
|
-
if (operation === "delete") {
|
|
7324
|
-
throw new DeleteUnsupportedError("the conversation is on the queue, which cannot delete a message");
|
|
7325
|
-
}
|
|
7326
|
-
if (kind !== "typing") this.stayOnQueue(key);
|
|
7327
|
-
return this.fallback.publish(envelope2, options);
|
|
7328
|
-
}
|
|
7329
7328
|
async direct(envelope2, described, started, options) {
|
|
7330
7329
|
let current = envelope2;
|
|
7331
7330
|
try {
|
|
@@ -7346,7 +7345,7 @@ var ConnectorOutbox = class {
|
|
|
7346
7345
|
}
|
|
7347
7346
|
} catch (error) {
|
|
7348
7347
|
throwIfAborted(options.signal);
|
|
7349
|
-
return this.notDelivered(error,
|
|
7348
|
+
return this.notDelivered(error, described, started);
|
|
7350
7349
|
}
|
|
7351
7350
|
}
|
|
7352
7351
|
plainRetry(error, envelope2) {
|
|
@@ -7355,9 +7354,10 @@ var ConnectorOutbox = class {
|
|
|
7355
7354
|
const plain2 = isObject(activity) ? this.plain(activity) : void 0;
|
|
7356
7355
|
return plain2 === void 0 ? void 0 : { ...envelope2, activity: plain2 };
|
|
7357
7356
|
}
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7357
|
+
/** A send that was not confirmed as delivered: logged, counted and thrown (a typing indicator is dropped, a delete has its own error). */
|
|
7358
|
+
notDelivered(error, described, started) {
|
|
7359
|
+
if (!isUndelivered(error)) throw error;
|
|
7360
|
+
const { operation, kind, conversation, content } = described;
|
|
7361
7361
|
const fields = {
|
|
7362
7362
|
operation,
|
|
7363
7363
|
kind,
|
|
@@ -7375,9 +7375,9 @@ var ConnectorOutbox = class {
|
|
|
7375
7375
|
this.logger.warn("direct typing dropped", fields);
|
|
7376
7376
|
return void 0;
|
|
7377
7377
|
}
|
|
7378
|
-
this.logger.warn("direct send not delivered
|
|
7379
|
-
this.
|
|
7380
|
-
|
|
7378
|
+
this.logger.warn("direct send not delivered", fields);
|
|
7379
|
+
this.options.stats?.undelivered();
|
|
7380
|
+
throw error;
|
|
7381
7381
|
}
|
|
7382
7382
|
/** The whole of one send is bounded: a server that answers slowly, or a token source that hangs, cannot hold the line. */
|
|
7383
7383
|
async deliver(envelope2, typing, signal) {
|
|
@@ -7408,22 +7408,10 @@ var ConnectorOutbox = class {
|
|
|
7408
7408
|
timer.dispose();
|
|
7409
7409
|
}
|
|
7410
7410
|
}
|
|
7411
|
-
/** Whatever goes to the queue keeps its conversation there for `queueStickyMs` more. */
|
|
7412
|
-
stayOnQueue(key) {
|
|
7413
|
-
const now = this.clock.monotonicMs();
|
|
7414
|
-
this.onQueueUntil.set(key, now + this.limits.queueStickyMs);
|
|
7415
|
-
for (const [other, until] of this.onQueueUntil) {
|
|
7416
|
-
if (until <= now) this.onQueueUntil.delete(other);
|
|
7417
|
-
}
|
|
7418
|
-
}
|
|
7419
|
-
/** Milliseconds the conversation stays on the queue (0 or less: it does not). */
|
|
7420
|
-
queuedFor(key) {
|
|
7421
|
-
return (this.onQueueUntil.get(key) ?? 0) - this.clock.monotonicMs();
|
|
7422
|
-
}
|
|
7423
7411
|
/**
|
|
7424
|
-
* One request of a Teams stream: sent once,
|
|
7425
|
-
*
|
|
7426
|
-
*
|
|
7412
|
+
* One request of a Teams stream: sent once, in the conversation's order (a retry would break the stream's
|
|
7413
|
+
* one-request-a-second limit). Throws StreamRefusedError when the request is
|
|
7414
|
+
* not confirmed as delivered (refused by Teams or by the address policy, or not answered in time).
|
|
7427
7415
|
*/
|
|
7428
7416
|
async publishStream(envelope2, options = {}) {
|
|
7429
7417
|
const described = describe(envelope2);
|
|
@@ -7434,7 +7422,6 @@ var ConnectorOutbox = class {
|
|
|
7434
7422
|
key,
|
|
7435
7423
|
async () => {
|
|
7436
7424
|
throwIfAborted(signal);
|
|
7437
|
-
if (this.queuedFor(key) > 0) throw new StreamRefusedError("the conversation is on the queue");
|
|
7438
7425
|
try {
|
|
7439
7426
|
const request = buildRequestLazily(envelope2, this.policy);
|
|
7440
7427
|
return await this.once(request, this.limits.requestTimeoutMs, 1, "send", signal);
|
|
@@ -7486,7 +7473,7 @@ var ConnectorOutbox = class {
|
|
|
7486
7473
|
}
|
|
7487
7474
|
/**
|
|
7488
7475
|
* The bot's 1:1 conversation with `userId` (a `29:` id from a group activity), created if it does not exist yet.
|
|
7489
|
-
* Throws ConversationNotOpenedError, with the status Teams answered (never a body).
|
|
7476
|
+
* Throws ConversationNotOpenedError, with the status Teams answered (never a body).
|
|
7490
7477
|
*/
|
|
7491
7478
|
async openPersonal(serviceUrl, userId, tenantId, botId) {
|
|
7492
7479
|
const started = this.clock.monotonicMs();
|
|
@@ -7522,7 +7509,7 @@ var ConnectorOutbox = class {
|
|
|
7522
7509
|
/**
|
|
7523
7510
|
* The members of a group chat the bot is in, each as the Bot Connector gives it. One request and one retry on a
|
|
7524
7511
|
* rejected token. Throws UnaddressableError for an address the policy refuses and UndeliverableError when Teams did
|
|
7525
|
-
* not answer.
|
|
7512
|
+
* not answer.
|
|
7526
7513
|
*/
|
|
7527
7514
|
async listMembers(serviceUrl, conversationId2) {
|
|
7528
7515
|
const request = buildListMembers(serviceUrl, conversationId2, this.policy);
|
|
@@ -7546,7 +7533,7 @@ var ConnectorOutbox = class {
|
|
|
7546
7533
|
return members;
|
|
7547
7534
|
}
|
|
7548
7535
|
}
|
|
7549
|
-
/** Closes the token source
|
|
7536
|
+
/** Closes the token source. */
|
|
7550
7537
|
async close() {
|
|
7551
7538
|
await this.options.tokens.close();
|
|
7552
7539
|
}
|
|
@@ -7664,26 +7651,7 @@ var ImdsTokenProvider = class extends CachedTokenProvider {
|
|
|
7664
7651
|
}
|
|
7665
7652
|
};
|
|
7666
7653
|
|
|
7667
|
-
// packages/teams/src/gate/
|
|
7668
|
-
import { silentLogger as silentLogger18 } from "@primusclaw/personal-agent";
|
|
7669
|
-
var NoQueue = class {
|
|
7670
|
-
constructor(logger = silentLogger18) {
|
|
7671
|
-
this.logger = logger;
|
|
7672
|
-
}
|
|
7673
|
-
logger;
|
|
7674
|
-
publish(envelope2) {
|
|
7675
|
-
if (envelope2.operation === "delete") {
|
|
7676
|
-
return Promise.reject(new DeleteUnsupportedError("the gate's test entry has no queue"));
|
|
7677
|
-
}
|
|
7678
|
-
this.logger.warn("gate entry: a send the recording connector did not take is dropped (there is no queue)", {
|
|
7679
|
-
operation: envelope2.operation
|
|
7680
|
-
});
|
|
7681
|
-
return Promise.resolve(void 0);
|
|
7682
|
-
}
|
|
7683
|
-
close() {
|
|
7684
|
-
return Promise.resolve();
|
|
7685
|
-
}
|
|
7686
|
-
};
|
|
7654
|
+
// packages/teams/src/gate/gate-token.ts
|
|
7687
7655
|
var GateToken = class {
|
|
7688
7656
|
token;
|
|
7689
7657
|
constructor(runId) {
|
|
@@ -7770,7 +7738,7 @@ function azureBusClient(connection, lockRenewalMs) {
|
|
|
7770
7738
|
}
|
|
7771
7739
|
|
|
7772
7740
|
// packages/teams/src/servicebus/outbox.ts
|
|
7773
|
-
import { errorName as errorName8, pyJsonDumps, silentLogger as
|
|
7741
|
+
import { errorName as errorName8, pyJsonDumps, silentLogger as silentLogger18 } from "@primusclaw/personal-agent";
|
|
7774
7742
|
var IDLE_REOPEN_MS = 24e4;
|
|
7775
7743
|
var ServiceBusOutbox = class {
|
|
7776
7744
|
constructor(client, queue, clock, logger) {
|
|
@@ -7779,7 +7747,7 @@ var ServiceBusOutbox = class {
|
|
|
7779
7747
|
this.clock = clock;
|
|
7780
7748
|
this.sender = client.sender(queue);
|
|
7781
7749
|
this.usedAt = clock.monotonicMs();
|
|
7782
|
-
this.logger = logger ??
|
|
7750
|
+
this.logger = logger ?? silentLogger18;
|
|
7783
7751
|
}
|
|
7784
7752
|
client;
|
|
7785
7753
|
queue;
|
|
@@ -7826,7 +7794,7 @@ var HANDLER_MARGIN_MS = 10 * 6e4;
|
|
|
7826
7794
|
var LOCK_RENEWAL_MS = SESSION_HOLD_MS + RECEIVE_DEADLINE_MS + turn3.TURN_DEADLINE_SECONDS * 1e3 + HANDLER_MARGIN_MS + SETTLE_DEADLINE_MS;
|
|
7827
7795
|
function botTokenSource(settings, deps) {
|
|
7828
7796
|
const { bot } = settings;
|
|
7829
|
-
const logger = deps.logger ??
|
|
7797
|
+
const logger = deps.logger ?? silentLogger19;
|
|
7830
7798
|
const base2 = { clock: deps.clock, logger, ...deps.fetch ? { fetch: deps.fetch } : {} };
|
|
7831
7799
|
if (bot.clientSecretIgnored) {
|
|
7832
7800
|
logger.warn("BOT_CLIENT_SECRET is set but not used: BOT_TOKEN_SOURCE names another source", {
|
|
@@ -7882,54 +7850,52 @@ function workerCredential(settings, deps) {
|
|
|
7882
7850
|
}
|
|
7883
7851
|
function busConnections(settings, credential) {
|
|
7884
7852
|
const { bus } = settings;
|
|
7885
|
-
|
|
7853
|
+
const direct = settings.outboundMode === "direct";
|
|
7854
|
+
if (!bus.namespace) return [bus.listenConnectionString, direct ? void 0 : bus.sendConnectionString];
|
|
7886
7855
|
if (credential === void 0) throw new StartupError("SERVICEBUS_NAMESPACE needs the worker identity");
|
|
7887
7856
|
const identity = { namespace: bus.namespace, credential };
|
|
7888
|
-
return [identity, identity];
|
|
7857
|
+
return [identity, direct ? void 0 : identity];
|
|
7889
7858
|
}
|
|
7890
|
-
function gateOutbound(gate, deps) {
|
|
7859
|
+
function gateOutbound(gate, deps, stats) {
|
|
7891
7860
|
const tokens = new GateToken(gate.runId);
|
|
7892
7861
|
const policy = onlyConnector(gate.connectorUrl);
|
|
7893
|
-
(deps.logger ??
|
|
7862
|
+
(deps.logger ?? silentLogger19).warn("release gate test entry: outbound to the recording connector only; no queue", {
|
|
7894
7863
|
runId: gate.runId
|
|
7895
7864
|
});
|
|
7896
7865
|
const outbox = new ConnectorOutbox({
|
|
7897
7866
|
tokens,
|
|
7898
|
-
fallback: new NoQueue(deps.logger),
|
|
7899
7867
|
clock: deps.clock,
|
|
7900
7868
|
policy,
|
|
7869
|
+
...stats ? { stats } : {},
|
|
7901
7870
|
...deps.logger ? { logger: deps.logger } : {},
|
|
7902
7871
|
...deps.fetch ? { fetch: deps.fetch } : {}
|
|
7903
7872
|
});
|
|
7904
7873
|
return { outbox, tokens, policy, close: () => outbox.close() };
|
|
7905
7874
|
}
|
|
7906
|
-
function
|
|
7875
|
+
function queueOutbound(settings, outbound, deps) {
|
|
7907
7876
|
const queue = new ServiceBusOutbox(outbound, settings.bus.outboundQueue, deps.clock, deps.logger);
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
(deps.logger ??
|
|
7877
|
+
return { outbox: queue, queue, tokens: void 0, policy: DEFAULT_CONNECTOR_HOSTS, close: () => queue.close() };
|
|
7878
|
+
}
|
|
7879
|
+
function directOutbound(settings, deps, stats) {
|
|
7880
|
+
(deps.logger ?? silentLogger19).info(
|
|
7881
|
+
"outbound mode: direct to the Bot Connector (no queue: a send that is not confirmed as delivered fails)"
|
|
7882
|
+
);
|
|
7912
7883
|
const tokens = botTokenSource(settings, deps);
|
|
7913
7884
|
const outbox = new ConnectorOutbox({
|
|
7914
7885
|
tokens,
|
|
7915
|
-
fallback: queue,
|
|
7916
7886
|
clock: deps.clock,
|
|
7887
|
+
...stats ? { stats } : {},
|
|
7917
7888
|
...deps.logger ? { logger: deps.logger } : {},
|
|
7918
7889
|
...deps.fetch ? { fetch: deps.fetch } : {}
|
|
7919
7890
|
});
|
|
7920
|
-
return {
|
|
7921
|
-
outbox,
|
|
7922
|
-
queue,
|
|
7923
|
-
tokens,
|
|
7924
|
-
policy: DEFAULT_CONNECTOR_HOSTS,
|
|
7925
|
-
close: async () => {
|
|
7926
|
-
await outbox.close();
|
|
7927
|
-
await queue.close();
|
|
7928
|
-
}
|
|
7929
|
-
};
|
|
7891
|
+
return { outbox, tokens, policy: DEFAULT_CONNECTOR_HOSTS, close: () => outbox.close() };
|
|
7930
7892
|
}
|
|
7931
|
-
function busClients(connections) {
|
|
7932
|
-
|
|
7893
|
+
function busClients(connections, makeClient = azureBusClient) {
|
|
7894
|
+
const [inbound2, outbound] = connections;
|
|
7895
|
+
return [
|
|
7896
|
+
makeClient(inbound2, LOCK_RENEWAL_MS),
|
|
7897
|
+
outbound === void 0 ? void 0 : makeClient(outbound, LOCK_RENEWAL_MS)
|
|
7898
|
+
];
|
|
7933
7899
|
}
|
|
7934
7900
|
|
|
7935
7901
|
// packages/teams/src/assembly/secrets.ts
|
|
@@ -7943,7 +7909,7 @@ import {
|
|
|
7943
7909
|
pyStr as pyStr20,
|
|
7944
7910
|
pyStrip as pyStrip17,
|
|
7945
7911
|
SecretsUnavailable as SecretsUnavailable2,
|
|
7946
|
-
silentLogger as
|
|
7912
|
+
silentLogger as silentLogger20
|
|
7947
7913
|
} from "@primusclaw/personal-agent";
|
|
7948
7914
|
|
|
7949
7915
|
// packages/teams/src/azure/keyvault-config.ts
|
|
@@ -8049,7 +8015,7 @@ var KeyVaultSecretSource = class {
|
|
|
8049
8015
|
this.credential = credential;
|
|
8050
8016
|
this.options = options;
|
|
8051
8017
|
this.fetch = options.fetch ?? globalThis.fetch;
|
|
8052
|
-
this.logger = options.logger ??
|
|
8018
|
+
this.logger = options.logger ?? silentLogger20;
|
|
8053
8019
|
this.sleep = options.sleep ?? ((ms, signal) => options.clock.sleep(ms, signal));
|
|
8054
8020
|
}
|
|
8055
8021
|
url;
|
|
@@ -8255,11 +8221,14 @@ function teamsTypedEvent(botName, logger) {
|
|
|
8255
8221
|
return read.ok ? read.value : void 0;
|
|
8256
8222
|
};
|
|
8257
8223
|
}
|
|
8258
|
-
function transport(teams, gate, deps) {
|
|
8259
|
-
if (gate !== void 0) return { outbound: gateOutbound(gate, deps), inbound: void 0 };
|
|
8224
|
+
function transport(teams, gate, deps, stats, makeClient) {
|
|
8225
|
+
if (gate !== void 0) return { outbound: gateOutbound(gate, deps, stats), inbound: void 0 };
|
|
8260
8226
|
const credential = workerCredential(teams, deps);
|
|
8261
|
-
const [inbound2, out] = busClients(busConnections(teams, credential));
|
|
8262
|
-
return {
|
|
8227
|
+
const [inbound2, out] = busClients(busConnections(teams, credential), makeClient);
|
|
8228
|
+
return {
|
|
8229
|
+
outbound: out === void 0 ? directOutbound(teams, deps, stats) : queueOutbound(teams, out, deps),
|
|
8230
|
+
inbound: inbound2
|
|
8231
|
+
};
|
|
8263
8232
|
}
|
|
8264
8233
|
function surfaceOf(teams, outbound, gate, deps) {
|
|
8265
8234
|
const acks = new AckRegistry(deps.clock, deps.logger);
|
|
@@ -8292,7 +8261,10 @@ function connect(teams, parts, context) {
|
|
|
8292
8261
|
botName,
|
|
8293
8262
|
logger: context.logger,
|
|
8294
8263
|
groupContext: context.groupContext,
|
|
8295
|
-
probe
|
|
8264
|
+
probe,
|
|
8265
|
+
markProcessed: (activityId) => {
|
|
8266
|
+
context.store.idempotency.markProcessed(activityId);
|
|
8267
|
+
}
|
|
8296
8268
|
});
|
|
8297
8269
|
const source = inbound2 === void 0 ? void 0 : new InboundConsumer({
|
|
8298
8270
|
client: inbound2,
|
|
@@ -8324,15 +8296,23 @@ function connect(teams, parts, context) {
|
|
|
8324
8296
|
return { routes, source };
|
|
8325
8297
|
}
|
|
8326
8298
|
function opened(teams, botName, gate, deps) {
|
|
8327
|
-
|
|
8299
|
+
let metrics;
|
|
8300
|
+
const { outbound, inbound: inbound2 } = transport(teams, gate, deps, {
|
|
8301
|
+
undelivered: () => {
|
|
8302
|
+
metrics?.outboundUndelivered?.();
|
|
8303
|
+
}
|
|
8304
|
+
});
|
|
8328
8305
|
const { acks, surface } = surfaceOf(teams, outbound, gate, deps);
|
|
8329
8306
|
let probe;
|
|
8330
8307
|
return {
|
|
8331
8308
|
surface,
|
|
8332
8309
|
typedEvent: teamsTypedEvent(botName, deps.logger),
|
|
8333
8310
|
connect: (context) => {
|
|
8311
|
+
metrics = context.metrics;
|
|
8334
8312
|
probe = new DeliveryProbe({
|
|
8335
8313
|
outbox: outbound.queue,
|
|
8314
|
+
// (no queue and no relay in direct mode: the probe covers the inbound hops; the gate answers none)
|
|
8315
|
+
inboundOnly: gate === void 0 && outbound.queue === void 0,
|
|
8336
8316
|
acks,
|
|
8337
8317
|
clock: context.clock,
|
|
8338
8318
|
logger: context.logger,
|
package/dist/main.js
CHANGED
|
@@ -1590,6 +1590,9 @@ var UndeliverableError = class extends Error {
|
|
|
1590
1590
|
this.code = details.code ?? "";
|
|
1591
1591
|
}
|
|
1592
1592
|
};
|
|
1593
|
+
function isUndelivered(error) {
|
|
1594
|
+
return error instanceof UndeliverableError || error instanceof UnaddressableError;
|
|
1595
|
+
}
|
|
1593
1596
|
var DeadlineError = class extends Error {
|
|
1594
1597
|
name = "TimeoutError";
|
|
1595
1598
|
};
|
|
@@ -2144,7 +2147,7 @@ function tokenSourceOf(env, secretSet) {
|
|
|
2144
2147
|
const fallback = secretSet ? "secret" : "imds";
|
|
2145
2148
|
return oneOf(env, "BOT_TOKEN_SOURCE", ["imds", "federated", "secret"], fallback);
|
|
2146
2149
|
}
|
|
2147
|
-
function botFromEnv(env, mode) {
|
|
2150
|
+
function botFromEnv(env, mode, holdsToken) {
|
|
2148
2151
|
const secretSet = get(env, "BOT_CLIENT_SECRET") !== "";
|
|
2149
2152
|
const tokenSource = tokenSourceOf(env, secretSet);
|
|
2150
2153
|
const federated = tokenSource === "federated";
|
|
@@ -2155,7 +2158,7 @@ function botFromEnv(env, mode) {
|
|
|
2155
2158
|
}
|
|
2156
2159
|
const settings = {
|
|
2157
2160
|
tokenSource,
|
|
2158
|
-
msiClientId:
|
|
2161
|
+
msiClientId: holdsToken && !secret ? required(env, "BOT_MSI_CLIENT_ID") : get(env, "BOT_MSI_CLIENT_ID"),
|
|
2159
2162
|
clientId: secret ? required(env, "BOT_CLIENT_ID") : get(env, "BOT_CLIENT_ID"),
|
|
2160
2163
|
clientSecretIgnored: secretSet && !secret,
|
|
2161
2164
|
tenantId: federated || secret ? required(env, "BOT_TENANT_ID") : get(env, "BOT_TENANT_ID"),
|
|
@@ -2180,11 +2183,11 @@ var NO_QUEUES = {
|
|
|
2180
2183
|
outboundQueue: "",
|
|
2181
2184
|
receiverCount: 0
|
|
2182
2185
|
};
|
|
2183
|
-
function busFromEnv(env, namespace) {
|
|
2186
|
+
function busFromEnv(env, namespace, mode) {
|
|
2184
2187
|
return {
|
|
2185
2188
|
namespace,
|
|
2186
2189
|
listenConnectionString: namespace ? "" : required(env, "SERVICEBUS_LISTEN_CONNECTION_STRING"),
|
|
2187
|
-
sendConnectionString: namespace ? "" : required(env, "SERVICEBUS_SEND_CONNECTION_STRING"),
|
|
2190
|
+
sendConnectionString: namespace || mode === "direct" ? "" : required(env, "SERVICEBUS_SEND_CONNECTION_STRING"),
|
|
2188
2191
|
inboundQueue: env["INBOUND_QUEUE"] ?? "primusclaw-inbound",
|
|
2189
2192
|
outboundQueue: env["OUTBOUND_QUEUE"] ?? "primusclaw-outbound",
|
|
2190
2193
|
receiverCount: wholeNumber(env, "RECEIVER_COUNT", 8)
|
|
@@ -2211,8 +2214,8 @@ function teamsSettingsFromEnv(env, options = {}) {
|
|
|
2211
2214
|
const queues = options.queues ?? true;
|
|
2212
2215
|
return {
|
|
2213
2216
|
outboundMode: mode,
|
|
2214
|
-
bot: botFromEnv(env, mode),
|
|
2215
|
-
bus: queues ? busFromEnv(env, namespace) : NO_QUEUES,
|
|
2217
|
+
bot: botFromEnv(env, mode, mode === "direct" && queues),
|
|
2218
|
+
bus: queues ? busFromEnv(env, namespace, mode) : NO_QUEUES,
|
|
2216
2219
|
workerIdentity: why ? identityFor(env, why) : void 0,
|
|
2217
2220
|
installHintUrl,
|
|
2218
2221
|
style: styleFromEnv(env)
|
|
@@ -2873,8 +2876,15 @@ var DeliveryProbe = class {
|
|
|
2873
2876
|
this.logger.warn("delivery probe not read", { why: "malformed" });
|
|
2874
2877
|
return;
|
|
2875
2878
|
}
|
|
2879
|
+
if (this.stopping.signal.aborted) return;
|
|
2880
|
+
if (this.parts.inboundOnly === true) {
|
|
2881
|
+
const elapsedMs = this.since(sent);
|
|
2882
|
+
this.logger.info("delivery probe", { id, outcome: "answered", feedback_ms: elapsedMs, reply_ms: elapsedMs });
|
|
2883
|
+
this.parts.stats?.probed(elapsedMs, elapsedMs);
|
|
2884
|
+
return;
|
|
2885
|
+
}
|
|
2876
2886
|
const outbox = this.parts.outbox;
|
|
2877
|
-
if (outbox === void 0
|
|
2887
|
+
if (outbox === void 0) return;
|
|
2878
2888
|
const ack = `probe-${id}`;
|
|
2879
2889
|
const waiter = this.parts.acks.expect(ack);
|
|
2880
2890
|
try {
|
|
@@ -6957,7 +6967,16 @@ function inboundHandler(parts) {
|
|
|
6957
6967
|
logger.warn("an inbound activity was not read", { why: event.error.kind });
|
|
6958
6968
|
return;
|
|
6959
6969
|
}
|
|
6960
|
-
if (event.value
|
|
6970
|
+
if (event.value === void 0) return;
|
|
6971
|
+
try {
|
|
6972
|
+
await parts.route(event.value);
|
|
6973
|
+
} catch (error) {
|
|
6974
|
+
if (!isUndelivered(error)) throw error;
|
|
6975
|
+
logger.warn("a reply to an inbound message was not delivered; the message is completed, not redelivered", {
|
|
6976
|
+
error: error.name
|
|
6977
|
+
});
|
|
6978
|
+
if (event.value.id) parts.markProcessed?.(event.value.id);
|
|
6979
|
+
}
|
|
6961
6980
|
};
|
|
6962
6981
|
}
|
|
6963
6982
|
function editedText(activity, parts) {
|
|
@@ -6967,7 +6986,7 @@ function editedText(activity, parts) {
|
|
|
6967
6986
|
|
|
6968
6987
|
// packages/teams/src/assembly/outbound.ts
|
|
6969
6988
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
6970
|
-
import { silentLogger as
|
|
6989
|
+
import { silentLogger as silentLogger19, turn as turn3 } from "@primusclaw/personal-agent";
|
|
6971
6990
|
import { StartupError } from "@primusclaw/personal-agent-runtime/worker";
|
|
6972
6991
|
|
|
6973
6992
|
// packages/teams/src/connector/outbox.ts
|
|
@@ -6983,8 +7002,7 @@ var DEFAULT_LIMITS = {
|
|
|
6983
7002
|
sendDeadlineMs: 3e4,
|
|
6984
7003
|
openAttempts: 2,
|
|
6985
7004
|
openRequestTimeoutMs: 8e3,
|
|
6986
|
-
openDeadlineMs: 12e3
|
|
6987
|
-
queueStickyMs: 6e4
|
|
7005
|
+
openDeadlineMs: 12e3
|
|
6988
7006
|
};
|
|
6989
7007
|
|
|
6990
7008
|
// packages/teams/src/connector/request.ts
|
|
@@ -7215,7 +7233,6 @@ function throwIfAborted(signal) {
|
|
|
7215
7233
|
var ConnectorOutbox = class {
|
|
7216
7234
|
constructor(options) {
|
|
7217
7235
|
this.options = options;
|
|
7218
|
-
this.fallback = options.fallback;
|
|
7219
7236
|
this.clock = options.clock;
|
|
7220
7237
|
this.logger = options.logger ?? silentLogger15;
|
|
7221
7238
|
this.policy = options.policy ?? DEFAULT_CONNECTOR_HOSTS;
|
|
@@ -7232,7 +7249,6 @@ var ConnectorOutbox = class {
|
|
|
7232
7249
|
});
|
|
7233
7250
|
}
|
|
7234
7251
|
options;
|
|
7235
|
-
fallback;
|
|
7236
7252
|
clock;
|
|
7237
7253
|
logger;
|
|
7238
7254
|
policy;
|
|
@@ -7240,8 +7256,6 @@ var ConnectorOutbox = class {
|
|
|
7240
7256
|
limits;
|
|
7241
7257
|
client;
|
|
7242
7258
|
lanes = new Lanes();
|
|
7243
|
-
/** conversation -> until when (monotonic ms) its sends go to the queue. */
|
|
7244
|
-
onQueueUntil = /* @__PURE__ */ new Map();
|
|
7245
7259
|
/** The bot's token source, which also fetches what a user attached. */
|
|
7246
7260
|
get tokens() {
|
|
7247
7261
|
return this.options.tokens;
|
|
@@ -7251,9 +7265,10 @@ var ConnectorOutbox = class {
|
|
|
7251
7265
|
return this.lanes.size;
|
|
7252
7266
|
}
|
|
7253
7267
|
/**
|
|
7254
|
-
* Deliver one envelope to Teams. Delivered: Teams has it. undefined:
|
|
7255
|
-
*
|
|
7256
|
-
*
|
|
7268
|
+
* Deliver one envelope to Teams. Delivered: Teams has it. undefined: a typing indicator that could not be sent was
|
|
7269
|
+
* dropped (nobody waits for one). A send that is not confirmed as delivered rejects with the reason (UndeliverableError, or
|
|
7270
|
+
* UnaddressableError for an address the policy refuses, before any request is made). An aborted `options.signal` sends nothing more and rejects
|
|
7271
|
+
* with its reason: no retry.
|
|
7257
7272
|
*/
|
|
7258
7273
|
async publish(envelope2, options = {}) {
|
|
7259
7274
|
const described = describe(envelope2);
|
|
@@ -7262,7 +7277,6 @@ var ConnectorOutbox = class {
|
|
|
7262
7277
|
described.key,
|
|
7263
7278
|
async () => {
|
|
7264
7279
|
throwIfAborted(options.signal);
|
|
7265
|
-
if (this.queuedFor(described.key) > 0) return this.whileOnQueue(envelope2, described, options);
|
|
7266
7280
|
return this.direct(envelope2, described, started, options);
|
|
7267
7281
|
},
|
|
7268
7282
|
options.signal
|
|
@@ -7280,21 +7294,6 @@ var ConnectorOutbox = class {
|
|
|
7280
7294
|
});
|
|
7281
7295
|
return { activityId: answer.id };
|
|
7282
7296
|
}
|
|
7283
|
-
async whileOnQueue(envelope2, described, options) {
|
|
7284
|
-
const { operation, kind, key, conversation, content } = described;
|
|
7285
|
-
this.logger.info("direct send skipped: the conversation stays on the queue", {
|
|
7286
|
-
operation,
|
|
7287
|
-
kind,
|
|
7288
|
-
leftMs: this.queuedFor(key),
|
|
7289
|
-
conversation,
|
|
7290
|
-
content
|
|
7291
|
-
});
|
|
7292
|
-
if (operation === "delete") {
|
|
7293
|
-
throw new DeleteUnsupportedError("the conversation is on the queue, which cannot delete a message");
|
|
7294
|
-
}
|
|
7295
|
-
if (kind !== "typing") this.stayOnQueue(key);
|
|
7296
|
-
return this.fallback.publish(envelope2, options);
|
|
7297
|
-
}
|
|
7298
7297
|
async direct(envelope2, described, started, options) {
|
|
7299
7298
|
let current = envelope2;
|
|
7300
7299
|
try {
|
|
@@ -7315,7 +7314,7 @@ var ConnectorOutbox = class {
|
|
|
7315
7314
|
}
|
|
7316
7315
|
} catch (error) {
|
|
7317
7316
|
throwIfAborted(options.signal);
|
|
7318
|
-
return this.notDelivered(error,
|
|
7317
|
+
return this.notDelivered(error, described, started);
|
|
7319
7318
|
}
|
|
7320
7319
|
}
|
|
7321
7320
|
plainRetry(error, envelope2) {
|
|
@@ -7324,9 +7323,10 @@ var ConnectorOutbox = class {
|
|
|
7324
7323
|
const plain2 = isObject(activity) ? this.plain(activity) : void 0;
|
|
7325
7324
|
return plain2 === void 0 ? void 0 : { ...envelope2, activity: plain2 };
|
|
7326
7325
|
}
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7326
|
+
/** A send that was not confirmed as delivered: logged, counted and thrown (a typing indicator is dropped, a delete has its own error). */
|
|
7327
|
+
notDelivered(error, described, started) {
|
|
7328
|
+
if (!isUndelivered(error)) throw error;
|
|
7329
|
+
const { operation, kind, conversation, content } = described;
|
|
7330
7330
|
const fields = {
|
|
7331
7331
|
operation,
|
|
7332
7332
|
kind,
|
|
@@ -7344,9 +7344,9 @@ var ConnectorOutbox = class {
|
|
|
7344
7344
|
this.logger.warn("direct typing dropped", fields);
|
|
7345
7345
|
return void 0;
|
|
7346
7346
|
}
|
|
7347
|
-
this.logger.warn("direct send not delivered
|
|
7348
|
-
this.
|
|
7349
|
-
|
|
7347
|
+
this.logger.warn("direct send not delivered", fields);
|
|
7348
|
+
this.options.stats?.undelivered();
|
|
7349
|
+
throw error;
|
|
7350
7350
|
}
|
|
7351
7351
|
/** The whole of one send is bounded: a server that answers slowly, or a token source that hangs, cannot hold the line. */
|
|
7352
7352
|
async deliver(envelope2, typing, signal) {
|
|
@@ -7377,22 +7377,10 @@ var ConnectorOutbox = class {
|
|
|
7377
7377
|
timer.dispose();
|
|
7378
7378
|
}
|
|
7379
7379
|
}
|
|
7380
|
-
/** Whatever goes to the queue keeps its conversation there for `queueStickyMs` more. */
|
|
7381
|
-
stayOnQueue(key) {
|
|
7382
|
-
const now = this.clock.monotonicMs();
|
|
7383
|
-
this.onQueueUntil.set(key, now + this.limits.queueStickyMs);
|
|
7384
|
-
for (const [other, until] of this.onQueueUntil) {
|
|
7385
|
-
if (until <= now) this.onQueueUntil.delete(other);
|
|
7386
|
-
}
|
|
7387
|
-
}
|
|
7388
|
-
/** Milliseconds the conversation stays on the queue (0 or less: it does not). */
|
|
7389
|
-
queuedFor(key) {
|
|
7390
|
-
return (this.onQueueUntil.get(key) ?? 0) - this.clock.monotonicMs();
|
|
7391
|
-
}
|
|
7392
7380
|
/**
|
|
7393
|
-
* One request of a Teams stream: sent once,
|
|
7394
|
-
*
|
|
7395
|
-
*
|
|
7381
|
+
* One request of a Teams stream: sent once, in the conversation's order (a retry would break the stream's
|
|
7382
|
+
* one-request-a-second limit). Throws StreamRefusedError when the request is
|
|
7383
|
+
* not confirmed as delivered (refused by Teams or by the address policy, or not answered in time).
|
|
7396
7384
|
*/
|
|
7397
7385
|
async publishStream(envelope2, options = {}) {
|
|
7398
7386
|
const described = describe(envelope2);
|
|
@@ -7403,7 +7391,6 @@ var ConnectorOutbox = class {
|
|
|
7403
7391
|
key,
|
|
7404
7392
|
async () => {
|
|
7405
7393
|
throwIfAborted(signal);
|
|
7406
|
-
if (this.queuedFor(key) > 0) throw new StreamRefusedError("the conversation is on the queue");
|
|
7407
7394
|
try {
|
|
7408
7395
|
const request = buildRequestLazily(envelope2, this.policy);
|
|
7409
7396
|
return await this.once(request, this.limits.requestTimeoutMs, 1, "send", signal);
|
|
@@ -7455,7 +7442,7 @@ var ConnectorOutbox = class {
|
|
|
7455
7442
|
}
|
|
7456
7443
|
/**
|
|
7457
7444
|
* The bot's 1:1 conversation with `userId` (a `29:` id from a group activity), created if it does not exist yet.
|
|
7458
|
-
* Throws ConversationNotOpenedError, with the status Teams answered (never a body).
|
|
7445
|
+
* Throws ConversationNotOpenedError, with the status Teams answered (never a body).
|
|
7459
7446
|
*/
|
|
7460
7447
|
async openPersonal(serviceUrl, userId, tenantId, botId) {
|
|
7461
7448
|
const started = this.clock.monotonicMs();
|
|
@@ -7491,7 +7478,7 @@ var ConnectorOutbox = class {
|
|
|
7491
7478
|
/**
|
|
7492
7479
|
* The members of a group chat the bot is in, each as the Bot Connector gives it. One request and one retry on a
|
|
7493
7480
|
* rejected token. Throws UnaddressableError for an address the policy refuses and UndeliverableError when Teams did
|
|
7494
|
-
* not answer.
|
|
7481
|
+
* not answer.
|
|
7495
7482
|
*/
|
|
7496
7483
|
async listMembers(serviceUrl, conversationId2) {
|
|
7497
7484
|
const request = buildListMembers(serviceUrl, conversationId2, this.policy);
|
|
@@ -7515,7 +7502,7 @@ var ConnectorOutbox = class {
|
|
|
7515
7502
|
return members;
|
|
7516
7503
|
}
|
|
7517
7504
|
}
|
|
7518
|
-
/** Closes the token source
|
|
7505
|
+
/** Closes the token source. */
|
|
7519
7506
|
async close() {
|
|
7520
7507
|
await this.options.tokens.close();
|
|
7521
7508
|
}
|
|
@@ -7633,26 +7620,7 @@ var ImdsTokenProvider = class extends CachedTokenProvider {
|
|
|
7633
7620
|
}
|
|
7634
7621
|
};
|
|
7635
7622
|
|
|
7636
|
-
// packages/teams/src/gate/
|
|
7637
|
-
import { silentLogger as silentLogger18 } from "@primusclaw/personal-agent";
|
|
7638
|
-
var NoQueue = class {
|
|
7639
|
-
constructor(logger = silentLogger18) {
|
|
7640
|
-
this.logger = logger;
|
|
7641
|
-
}
|
|
7642
|
-
logger;
|
|
7643
|
-
publish(envelope2) {
|
|
7644
|
-
if (envelope2.operation === "delete") {
|
|
7645
|
-
return Promise.reject(new DeleteUnsupportedError("the gate's test entry has no queue"));
|
|
7646
|
-
}
|
|
7647
|
-
this.logger.warn("gate entry: a send the recording connector did not take is dropped (there is no queue)", {
|
|
7648
|
-
operation: envelope2.operation
|
|
7649
|
-
});
|
|
7650
|
-
return Promise.resolve(void 0);
|
|
7651
|
-
}
|
|
7652
|
-
close() {
|
|
7653
|
-
return Promise.resolve();
|
|
7654
|
-
}
|
|
7655
|
-
};
|
|
7623
|
+
// packages/teams/src/gate/gate-token.ts
|
|
7656
7624
|
var GateToken = class {
|
|
7657
7625
|
token;
|
|
7658
7626
|
constructor(runId) {
|
|
@@ -7739,7 +7707,7 @@ function azureBusClient(connection, lockRenewalMs) {
|
|
|
7739
7707
|
}
|
|
7740
7708
|
|
|
7741
7709
|
// packages/teams/src/servicebus/outbox.ts
|
|
7742
|
-
import { errorName as errorName8, pyJsonDumps, silentLogger as
|
|
7710
|
+
import { errorName as errorName8, pyJsonDumps, silentLogger as silentLogger18 } from "@primusclaw/personal-agent";
|
|
7743
7711
|
var IDLE_REOPEN_MS = 24e4;
|
|
7744
7712
|
var ServiceBusOutbox = class {
|
|
7745
7713
|
constructor(client, queue, clock, logger) {
|
|
@@ -7748,7 +7716,7 @@ var ServiceBusOutbox = class {
|
|
|
7748
7716
|
this.clock = clock;
|
|
7749
7717
|
this.sender = client.sender(queue);
|
|
7750
7718
|
this.usedAt = clock.monotonicMs();
|
|
7751
|
-
this.logger = logger ??
|
|
7719
|
+
this.logger = logger ?? silentLogger18;
|
|
7752
7720
|
}
|
|
7753
7721
|
client;
|
|
7754
7722
|
queue;
|
|
@@ -7795,7 +7763,7 @@ var HANDLER_MARGIN_MS = 10 * 6e4;
|
|
|
7795
7763
|
var LOCK_RENEWAL_MS = SESSION_HOLD_MS + RECEIVE_DEADLINE_MS + turn3.TURN_DEADLINE_SECONDS * 1e3 + HANDLER_MARGIN_MS + SETTLE_DEADLINE_MS;
|
|
7796
7764
|
function botTokenSource(settings, deps) {
|
|
7797
7765
|
const { bot } = settings;
|
|
7798
|
-
const logger = deps.logger ??
|
|
7766
|
+
const logger = deps.logger ?? silentLogger19;
|
|
7799
7767
|
const base2 = { clock: deps.clock, logger, ...deps.fetch ? { fetch: deps.fetch } : {} };
|
|
7800
7768
|
if (bot.clientSecretIgnored) {
|
|
7801
7769
|
logger.warn("BOT_CLIENT_SECRET is set but not used: BOT_TOKEN_SOURCE names another source", {
|
|
@@ -7851,54 +7819,52 @@ function workerCredential(settings, deps) {
|
|
|
7851
7819
|
}
|
|
7852
7820
|
function busConnections(settings, credential) {
|
|
7853
7821
|
const { bus } = settings;
|
|
7854
|
-
|
|
7822
|
+
const direct = settings.outboundMode === "direct";
|
|
7823
|
+
if (!bus.namespace) return [bus.listenConnectionString, direct ? void 0 : bus.sendConnectionString];
|
|
7855
7824
|
if (credential === void 0) throw new StartupError("SERVICEBUS_NAMESPACE needs the worker identity");
|
|
7856
7825
|
const identity = { namespace: bus.namespace, credential };
|
|
7857
|
-
return [identity, identity];
|
|
7826
|
+
return [identity, direct ? void 0 : identity];
|
|
7858
7827
|
}
|
|
7859
|
-
function gateOutbound(gate, deps) {
|
|
7828
|
+
function gateOutbound(gate, deps, stats) {
|
|
7860
7829
|
const tokens = new GateToken(gate.runId);
|
|
7861
7830
|
const policy = onlyConnector(gate.connectorUrl);
|
|
7862
|
-
(deps.logger ??
|
|
7831
|
+
(deps.logger ?? silentLogger19).warn("release gate test entry: outbound to the recording connector only; no queue", {
|
|
7863
7832
|
runId: gate.runId
|
|
7864
7833
|
});
|
|
7865
7834
|
const outbox = new ConnectorOutbox({
|
|
7866
7835
|
tokens,
|
|
7867
|
-
fallback: new NoQueue(deps.logger),
|
|
7868
7836
|
clock: deps.clock,
|
|
7869
7837
|
policy,
|
|
7838
|
+
...stats ? { stats } : {},
|
|
7870
7839
|
...deps.logger ? { logger: deps.logger } : {},
|
|
7871
7840
|
...deps.fetch ? { fetch: deps.fetch } : {}
|
|
7872
7841
|
});
|
|
7873
7842
|
return { outbox, tokens, policy, close: () => outbox.close() };
|
|
7874
7843
|
}
|
|
7875
|
-
function
|
|
7844
|
+
function queueOutbound(settings, outbound, deps) {
|
|
7876
7845
|
const queue = new ServiceBusOutbox(outbound, settings.bus.outboundQueue, deps.clock, deps.logger);
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
(deps.logger ??
|
|
7846
|
+
return { outbox: queue, queue, tokens: void 0, policy: DEFAULT_CONNECTOR_HOSTS, close: () => queue.close() };
|
|
7847
|
+
}
|
|
7848
|
+
function directOutbound(settings, deps, stats) {
|
|
7849
|
+
(deps.logger ?? silentLogger19).info(
|
|
7850
|
+
"outbound mode: direct to the Bot Connector (no queue: a send that is not confirmed as delivered fails)"
|
|
7851
|
+
);
|
|
7881
7852
|
const tokens = botTokenSource(settings, deps);
|
|
7882
7853
|
const outbox = new ConnectorOutbox({
|
|
7883
7854
|
tokens,
|
|
7884
|
-
fallback: queue,
|
|
7885
7855
|
clock: deps.clock,
|
|
7856
|
+
...stats ? { stats } : {},
|
|
7886
7857
|
...deps.logger ? { logger: deps.logger } : {},
|
|
7887
7858
|
...deps.fetch ? { fetch: deps.fetch } : {}
|
|
7888
7859
|
});
|
|
7889
|
-
return {
|
|
7890
|
-
outbox,
|
|
7891
|
-
queue,
|
|
7892
|
-
tokens,
|
|
7893
|
-
policy: DEFAULT_CONNECTOR_HOSTS,
|
|
7894
|
-
close: async () => {
|
|
7895
|
-
await outbox.close();
|
|
7896
|
-
await queue.close();
|
|
7897
|
-
}
|
|
7898
|
-
};
|
|
7860
|
+
return { outbox, tokens, policy: DEFAULT_CONNECTOR_HOSTS, close: () => outbox.close() };
|
|
7899
7861
|
}
|
|
7900
|
-
function busClients(connections) {
|
|
7901
|
-
|
|
7862
|
+
function busClients(connections, makeClient = azureBusClient) {
|
|
7863
|
+
const [inbound2, outbound] = connections;
|
|
7864
|
+
return [
|
|
7865
|
+
makeClient(inbound2, LOCK_RENEWAL_MS),
|
|
7866
|
+
outbound === void 0 ? void 0 : makeClient(outbound, LOCK_RENEWAL_MS)
|
|
7867
|
+
];
|
|
7902
7868
|
}
|
|
7903
7869
|
|
|
7904
7870
|
// packages/teams/src/assembly/secrets.ts
|
|
@@ -7912,7 +7878,7 @@ import {
|
|
|
7912
7878
|
pyStr as pyStr20,
|
|
7913
7879
|
pyStrip as pyStrip17,
|
|
7914
7880
|
SecretsUnavailable as SecretsUnavailable2,
|
|
7915
|
-
silentLogger as
|
|
7881
|
+
silentLogger as silentLogger20
|
|
7916
7882
|
} from "@primusclaw/personal-agent";
|
|
7917
7883
|
|
|
7918
7884
|
// packages/teams/src/azure/keyvault-config.ts
|
|
@@ -8018,7 +7984,7 @@ var KeyVaultSecretSource = class {
|
|
|
8018
7984
|
this.credential = credential;
|
|
8019
7985
|
this.options = options;
|
|
8020
7986
|
this.fetch = options.fetch ?? globalThis.fetch;
|
|
8021
|
-
this.logger = options.logger ??
|
|
7987
|
+
this.logger = options.logger ?? silentLogger20;
|
|
8022
7988
|
this.sleep = options.sleep ?? ((ms, signal) => options.clock.sleep(ms, signal));
|
|
8023
7989
|
}
|
|
8024
7990
|
url;
|
|
@@ -8224,11 +8190,14 @@ function teamsTypedEvent(botName, logger) {
|
|
|
8224
8190
|
return read.ok ? read.value : void 0;
|
|
8225
8191
|
};
|
|
8226
8192
|
}
|
|
8227
|
-
function transport(teams, gate, deps) {
|
|
8228
|
-
if (gate !== void 0) return { outbound: gateOutbound(gate, deps), inbound: void 0 };
|
|
8193
|
+
function transport(teams, gate, deps, stats, makeClient) {
|
|
8194
|
+
if (gate !== void 0) return { outbound: gateOutbound(gate, deps, stats), inbound: void 0 };
|
|
8229
8195
|
const credential = workerCredential(teams, deps);
|
|
8230
|
-
const [inbound2, out] = busClients(busConnections(teams, credential));
|
|
8231
|
-
return {
|
|
8196
|
+
const [inbound2, out] = busClients(busConnections(teams, credential), makeClient);
|
|
8197
|
+
return {
|
|
8198
|
+
outbound: out === void 0 ? directOutbound(teams, deps, stats) : queueOutbound(teams, out, deps),
|
|
8199
|
+
inbound: inbound2
|
|
8200
|
+
};
|
|
8232
8201
|
}
|
|
8233
8202
|
function surfaceOf(teams, outbound, gate, deps) {
|
|
8234
8203
|
const acks = new AckRegistry(deps.clock, deps.logger);
|
|
@@ -8261,7 +8230,10 @@ function connect(teams, parts, context) {
|
|
|
8261
8230
|
botName,
|
|
8262
8231
|
logger: context.logger,
|
|
8263
8232
|
groupContext: context.groupContext,
|
|
8264
|
-
probe
|
|
8233
|
+
probe,
|
|
8234
|
+
markProcessed: (activityId) => {
|
|
8235
|
+
context.store.idempotency.markProcessed(activityId);
|
|
8236
|
+
}
|
|
8265
8237
|
});
|
|
8266
8238
|
const source = inbound2 === void 0 ? void 0 : new InboundConsumer({
|
|
8267
8239
|
client: inbound2,
|
|
@@ -8293,15 +8265,23 @@ function connect(teams, parts, context) {
|
|
|
8293
8265
|
return { routes, source };
|
|
8294
8266
|
}
|
|
8295
8267
|
function opened(teams, botName, gate, deps) {
|
|
8296
|
-
|
|
8268
|
+
let metrics;
|
|
8269
|
+
const { outbound, inbound: inbound2 } = transport(teams, gate, deps, {
|
|
8270
|
+
undelivered: () => {
|
|
8271
|
+
metrics?.outboundUndelivered?.();
|
|
8272
|
+
}
|
|
8273
|
+
});
|
|
8297
8274
|
const { acks, surface } = surfaceOf(teams, outbound, gate, deps);
|
|
8298
8275
|
let probe;
|
|
8299
8276
|
return {
|
|
8300
8277
|
surface,
|
|
8301
8278
|
typedEvent: teamsTypedEvent(botName, deps.logger),
|
|
8302
8279
|
connect: (context) => {
|
|
8280
|
+
metrics = context.metrics;
|
|
8303
8281
|
probe = new DeliveryProbe({
|
|
8304
8282
|
outbox: outbound.queue,
|
|
8283
|
+
// (no queue and no relay in direct mode: the probe covers the inbound hops; the gate answers none)
|
|
8284
|
+
inboundOnly: gate === void 0 && outbound.queue === void 0,
|
|
8305
8285
|
acks,
|
|
8306
8286
|
clock: context.clock,
|
|
8307
8287
|
logger: context.logger,
|
|
@@ -25,7 +25,7 @@ export declare function addressedToBot(activity: Activity, botName?: string): bo
|
|
|
25
25
|
/**
|
|
26
26
|
* `text` without the bot's name typed as words ahead of a command (`@<name> /approvals`, `<name> /approvals`), and how many code points
|
|
27
27
|
* that took off its start. A mention a person picks is an entity, which `messageText` drops; one Teams on a phone sends as plain words
|
|
28
|
-
* (
|
|
28
|
+
* ("@<name> /approvals") has none, so it stayed in the text and `/approvals` was read as a sentence, not as the
|
|
29
29
|
* command. Only the name first and a command word after it: any other words, the name alone, a word that merely starts with the name
|
|
30
30
|
* and a path (`/tmp/app.log`) stay as they were typed, so no ordinary chat becomes a command. A name taken off here, with its @ or without,
|
|
31
31
|
* is the person naming the bot, so the caller also reads the message as naming the bot first (`addressedToBot` reads only the @ form).
|
|
@@ -20,6 +20,17 @@ export interface InboundParts {
|
|
|
20
20
|
readonly groupContext?: GroupContextChanges;
|
|
21
21
|
/** Answers the delivery probe (`primusclaw.probe`); none: a probe is dropped unanswered. */
|
|
22
22
|
readonly probe?: DeliveryProbe;
|
|
23
|
+
/**
|
|
24
|
+
* Marks an activity processed: the router does it only after its handler succeeded, so a message completed after a reply
|
|
25
|
+
* that was not confirmed as delivered is marked here, and a second copy of the activity (the ingress may queue one twice) is dropped.
|
|
26
|
+
*/
|
|
27
|
+
readonly markProcessed?: (activityId: string) => void;
|
|
23
28
|
}
|
|
24
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The handler of one inbound body. A reply that was not confirmed as delivered (`isUndelivered`: already logged and counted where it was sent,
|
|
31
|
+
* after any retries its failure allows) ends the handling of the message but does not fail it: the consumer completes it, and the
|
|
32
|
+
* activity is marked processed (by its id, when it has one). A redelivery, or a second copy of the activity, would run again what the handler did before
|
|
33
|
+
* the send (a setting it changed, a turn it started), and the send has been tried as far as its failure allows. Any other failure still fails
|
|
34
|
+
* the handler, so the broker redelivers the message.
|
|
35
|
+
*/
|
|
25
36
|
export declare function inboundHandler(parts: InboundParts): (body: JsonObject) => Promise<void>;
|
|
@@ -3,6 +3,7 @@ import { StartupError } from "@primusclaw/personal-agent-runtime/worker";
|
|
|
3
3
|
import { FederatedCredential } from "../azure/workload-identity.js";
|
|
4
4
|
import type { TeamsSettings } from "../config/env.js";
|
|
5
5
|
import { type ServiceUrlPolicy } from "../connector/hosts.js";
|
|
6
|
+
import { type ConnectorStats } from "../connector/outbox.js";
|
|
6
7
|
import type { TokenSource } from "../connector/tokens/cached.js";
|
|
7
8
|
import type { GateEntry } from "../gate/entry-env.js";
|
|
8
9
|
import type { Outbox } from "../outbound/outbox.js";
|
|
@@ -33,21 +34,26 @@ export { StartupError };
|
|
|
33
34
|
export declare function botTokenSource(settings: TeamsSettings, deps: AssemblyDeps): TokenSource;
|
|
34
35
|
/** The worker identity's credential (one for both queues and the vault), when the settings name the identity. */
|
|
35
36
|
export declare function workerCredential(settings: TeamsSettings, deps: AssemblyDeps): FederatedCredential | undefined;
|
|
36
|
-
/**
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* (inbound, outbound): the worker identity on the namespace when SERVICEBUS_NAMESPACE is set, else the connection strings.
|
|
39
|
+
* Direct mode has no outbound queue: its outbound connection is none.
|
|
40
|
+
*/
|
|
41
|
+
export declare function busConnections(settings: TeamsSettings, credential: FederatedCredential | undefined): readonly [BusConnection, BusConnection | undefined];
|
|
38
42
|
export interface Outbound {
|
|
39
43
|
readonly outbox: Outbox;
|
|
40
44
|
/** The bot's token, which also fetches a pasted image (direct mode and the gate only). */
|
|
41
45
|
readonly tokens: TokenSource | undefined;
|
|
42
46
|
/** Where the bot's token may go. */
|
|
43
47
|
readonly policy: ServiceUrlPolicy;
|
|
44
|
-
/** The outbound queue itself (the delivery probe's answer
|
|
48
|
+
/** The outbound queue itself (OUTBOUND_MODE=servicebus only: the delivery probe's answer goes through the relay). */
|
|
45
49
|
readonly queue?: Outbox;
|
|
46
50
|
close(): Promise<void>;
|
|
47
51
|
}
|
|
48
52
|
/** The release gate's test entry: the recording connector and nothing else (Microsoft's hosts included). */
|
|
49
|
-
export declare function gateOutbound(gate: GateEntry, deps: AssemblyDeps): Outbound;
|
|
50
|
-
/** The
|
|
51
|
-
export declare function
|
|
52
|
-
/**
|
|
53
|
-
export declare function
|
|
53
|
+
export declare function gateOutbound(gate: GateEntry, deps: AssemblyDeps, stats?: ConnectorStats): Outbound;
|
|
54
|
+
/** The default (OUTBOUND_MODE=servicebus): every send goes to the outbound queue, which a relay posts to Teams. */
|
|
55
|
+
export declare function queueOutbound(settings: TeamsSettings, outbound: BusClient, deps: AssemblyDeps): Outbound;
|
|
56
|
+
/** OUTBOUND_MODE=direct: the worker posts to the Bot Connector itself. There is no queue behind it, and nothing is handed to one. */
|
|
57
|
+
export declare function directOutbound(settings: TeamsSettings, deps: AssemblyDeps, stats?: ConnectorStats): Outbound;
|
|
58
|
+
/** The SDK clients of the queues: the inbound one, and the outbound one when there is an outbound queue. */
|
|
59
|
+
export declare function busClients(connections: readonly [BusConnection, BusConnection | undefined], makeClient?: (connection: BusConnection, lockRenewalMs: number) => BusClient): readonly [BusClient, BusClient | undefined];
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The worker on Teams (`BuildWorker`): runtime's worker assembly with the Teams surface. What is Teams' own is here:
|
|
3
3
|
* its settings (OUTBOUND_MODE, BOT_*, SERVICEBUS_*, the reply style), secrets from Azure Key Vault, how it reaches Teams
|
|
4
|
-
* (the
|
|
4
|
+
* (the Bot Connector directly, or with OUTBOUND_MODE=servicebus the outbound queue), its `TeamsSurface` with the Adaptive Card renderers, the inbound queue's
|
|
5
5
|
* consumer, and the release gate's test entry (its routes on the loopback instead of the queue).
|
|
6
6
|
*/
|
|
7
7
|
import { type ConversationRef, type JsonObject, type Logger } from "@primusclaw/personal-agent";
|
|
8
|
-
import { type BuildWorker, type OpenedSurface, type ReplyStyle, type SurfaceAdapter, type SurfaceShape } from "@primusclaw/personal-agent-runtime/worker";
|
|
8
|
+
import { type BuildWorker, type OpenedSurface, type ReplyStyle, type SurfaceAdapter, type SurfaceDeps, type SurfaceShape } from "@primusclaw/personal-agent-runtime/worker";
|
|
9
9
|
import { type TeamsSettings } from "../config/env.js";
|
|
10
|
+
import type { ConnectorStats } from "../connector/outbox.js";
|
|
10
11
|
import { type Style } from "../config/style.js";
|
|
12
|
+
import { type GateEntry } from "../gate/entry-env.js";
|
|
13
|
+
import type { BusClient } from "../servicebus/client.js";
|
|
14
|
+
import { busClients, type Outbound } from "./outbound.js";
|
|
11
15
|
/** The Teams style's reading of a conversation kind (`style.streams_in`'s conversation types). */
|
|
12
16
|
export declare function conversationTypeOf(kind: string): string;
|
|
13
17
|
/** The switches of the Teams reply style the features read. */
|
|
@@ -23,6 +27,12 @@ export declare function teamsShape(teams: Pick<TeamsSettings, "style" | "install
|
|
|
23
27
|
* core's event (what a plugin's `handleAsTyped` hands the router); undefined when it cannot be read.
|
|
24
28
|
*/
|
|
25
29
|
export declare function teamsTypedEvent(botName: string, logger: Logger): OpenedSurface["typedEvent"];
|
|
30
|
+
export interface Transport {
|
|
31
|
+
readonly outbound: Outbound;
|
|
32
|
+
readonly inbound: BusClient | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** The two ends of the worker's transport: how it posts to Teams, and the inbound queue it reads (none for the gate). */
|
|
35
|
+
export declare function transport(teams: TeamsSettings, gate: GateEntry | undefined, deps: SurfaceDeps, stats: ConnectorStats, makeClient?: Parameters<typeof busClients>[1]): Transport;
|
|
26
36
|
/**
|
|
27
37
|
* The Teams surface: the release gate's test entry is read first (TEAMS_GATE_ENTRY), the secrets come from where
|
|
28
38
|
* SECRETS_SOURCE says (the environment or Azure Key Vault), and the Teams settings are read after core's.
|
|
@@ -28,6 +28,8 @@ export declare class UndeliverableError extends Error {
|
|
|
28
28
|
cause?: unknown;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
+
/** A send that was not confirmed as delivered, as `ConnectorOutbox.publish` throws it: any retry its failure allows is over, the reason is in the error. */
|
|
32
|
+
export declare function isUndelivered(error: unknown): error is UndeliverableError | UnaddressableError;
|
|
31
33
|
/** The overall deadline of one operation passed (the `signal.reason` of a deadline, and what a raced wait rejects with). */
|
|
32
34
|
export declare class DeadlineError extends Error {
|
|
33
35
|
name: string;
|
|
@@ -8,7 +8,7 @@ export interface ConnectorLimits {
|
|
|
8
8
|
readonly maxAttempts: number;
|
|
9
9
|
/** The first backoff, doubled after every failure. */
|
|
10
10
|
readonly backoffMs: number;
|
|
11
|
-
/** A longer Retry-After is not waited for: the
|
|
11
|
+
/** A longer Retry-After is not waited for: the send is given up and fails. */
|
|
12
12
|
readonly maxRetryAfterMs: number;
|
|
13
13
|
/** Everything one send does (token, requests, waits) together, enforced, not just checked. */
|
|
14
14
|
readonly sendDeadlineMs: number;
|
|
@@ -17,7 +17,5 @@ export interface ConnectorLimits {
|
|
|
17
17
|
readonly openRequestTimeoutMs: number;
|
|
18
18
|
/** Everything one createConversation does together. */
|
|
19
19
|
readonly openDeadlineMs: number;
|
|
20
|
-
/** A conversation stays on the queue until it has been quiet this long (the relay's cold start was 15-44 s). */
|
|
21
|
-
readonly queueStickyMs: number;
|
|
22
20
|
}
|
|
23
21
|
export declare const DEFAULT_LIMITS: ConnectorLimits;
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Direct delivery to the Bot Connector,
|
|
2
|
+
* Direct delivery to the Bot Connector, and nothing behind it.
|
|
3
3
|
*
|
|
4
4
|
* - Order: one conversation's sends are serialised in this process, first come first sent, and a retry holds the line.
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - At least once: a request that timed out or was answered with a 5xx may have reached Teams; the retry
|
|
9
|
-
*
|
|
10
|
-
* - A
|
|
5
|
+
* - A send that is not confirmed as delivered (token unavailable, retries or the overall deadline used up, a refusal by Teams, an
|
|
6
|
+
* address the policy refuses, which fails before any request is made) is logged, counted (`stats.undelivered`) and thrown to the caller, like any other failed send. It is
|
|
7
|
+
* not handed to another path, and it leaves no state behind: the next send to the conversation goes direct again.
|
|
8
|
+
* - At least once: a request that timed out or was answered with a 5xx may have reached Teams; the retry can then post
|
|
9
|
+
* the message twice.
|
|
10
|
+
* - A typing indicator that is not confirmed as delivered is dropped: nobody waits for one. A delete that is not confirmed as delivered throws
|
|
11
|
+
* DeleteUnsupportedError.
|
|
11
12
|
*
|
|
12
13
|
* Secrets and bodies are never logged: one line per send with the operation, status and latency, and the target
|
|
13
14
|
* conversation's id and the activity's kind (`outboundLogFields`).
|
|
14
15
|
*/
|
|
15
16
|
import { type Clock, type Logger } from "@primusclaw/personal-agent";
|
|
16
17
|
import { type JsonObject } from "../cards/json.js";
|
|
17
|
-
import { type ConnectorMember, type Delivered, type DirectOutbox, type
|
|
18
|
+
import { type ConnectorMember, type Delivered, type DirectOutbox, type PublishOptions, type TeamsEnvelope } from "../outbound/outbox.js";
|
|
18
19
|
import { type ServiceUrlPolicy } from "./hosts.js";
|
|
19
20
|
import { type ConnectorLimits } from "./limits.js";
|
|
20
21
|
import { type Sleep } from "./retry.js";
|
|
21
22
|
import type { TokenSource } from "./tokens/cached.js";
|
|
23
|
+
/** What is counted of the sends: the ones that were not confirmed as delivered. */
|
|
24
|
+
export interface ConnectorStats {
|
|
25
|
+
/** A send, reply or update that was not confirmed as delivered and was thrown to the caller. */
|
|
26
|
+
undelivered(): void;
|
|
27
|
+
}
|
|
22
28
|
export interface ConnectorOutboxOptions {
|
|
23
|
-
/** The bot's token source (IMDS or
|
|
29
|
+
/** The bot's token source (IMDS, federated or an app registration's secret); it also fetches what a user attached. */
|
|
24
30
|
readonly tokens: TokenSource;
|
|
25
|
-
/** The outbound queue: where a send Teams did not take goes. Closed by whoever made it. */
|
|
26
|
-
readonly fallback: Outbox;
|
|
27
31
|
readonly clock: Clock;
|
|
28
32
|
readonly fetch?: typeof fetch;
|
|
29
33
|
/** The backoff wait; default `clock.sleep`. */
|
|
@@ -34,10 +38,11 @@ export interface ConnectorOutboxOptions {
|
|
|
34
38
|
/** The activity without its reply-style extras, for a second try after a 400 (default `plainDecorations`). */
|
|
35
39
|
readonly plain?: (activity: JsonObject) => JsonObject | undefined;
|
|
36
40
|
readonly limits?: Partial<ConnectorLimits>;
|
|
41
|
+
/** Where the sends that were not confirmed as delivered are counted; none: they are only logged. */
|
|
42
|
+
readonly stats?: ConnectorStats;
|
|
37
43
|
}
|
|
38
44
|
export declare class ConnectorOutbox implements DirectOutbox {
|
|
39
45
|
private readonly options;
|
|
40
|
-
private readonly fallback;
|
|
41
46
|
private readonly clock;
|
|
42
47
|
private readonly logger;
|
|
43
48
|
private readonly policy;
|
|
@@ -45,33 +50,28 @@ export declare class ConnectorOutbox implements DirectOutbox {
|
|
|
45
50
|
private readonly limits;
|
|
46
51
|
private readonly client;
|
|
47
52
|
private readonly lanes;
|
|
48
|
-
/** conversation -> until when (monotonic ms) its sends go to the queue. */
|
|
49
|
-
private readonly onQueueUntil;
|
|
50
53
|
constructor(options: ConnectorOutboxOptions);
|
|
51
54
|
/** The bot's token source, which also fetches what a user attached. */
|
|
52
55
|
get tokens(): TokenSource;
|
|
53
56
|
/** How many conversations hold or wait for their line just now (0 once every send is over). */
|
|
54
57
|
get lanesInUse(): number;
|
|
55
58
|
/**
|
|
56
|
-
* Deliver one envelope to Teams. Delivered: Teams has it. undefined:
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
+
* Deliver one envelope to Teams. Delivered: Teams has it. undefined: a typing indicator that could not be sent was
|
|
60
|
+
* dropped (nobody waits for one). A send that is not confirmed as delivered rejects with the reason (UndeliverableError, or
|
|
61
|
+
* UnaddressableError for an address the policy refuses, before any request is made). An aborted `options.signal` sends nothing more and rejects
|
|
62
|
+
* with its reason: no retry.
|
|
59
63
|
*/
|
|
60
64
|
publish(envelope: TeamsEnvelope, options?: PublishOptions): Promise<Delivered | undefined>;
|
|
61
|
-
private whileOnQueue;
|
|
62
65
|
private direct;
|
|
63
66
|
private plainRetry;
|
|
67
|
+
/** A send that was not confirmed as delivered: logged, counted and thrown (a typing indicator is dropped, a delete has its own error). */
|
|
64
68
|
private notDelivered;
|
|
65
69
|
/** The whole of one send is bounded: a server that answers slowly, or a token source that hangs, cannot hold the line. */
|
|
66
70
|
private deliver;
|
|
67
|
-
/** Whatever goes to the queue keeps its conversation there for `queueStickyMs` more. */
|
|
68
|
-
private stayOnQueue;
|
|
69
|
-
/** Milliseconds the conversation stays on the queue (0 or less: it does not). */
|
|
70
|
-
private queuedFor;
|
|
71
71
|
/**
|
|
72
|
-
* One request of a Teams stream: sent once,
|
|
73
|
-
*
|
|
74
|
-
*
|
|
72
|
+
* One request of a Teams stream: sent once, in the conversation's order (a retry would break the stream's
|
|
73
|
+
* one-request-a-second limit). Throws StreamRefusedError when the request is
|
|
74
|
+
* not confirmed as delivered (refused by Teams or by the address policy, or not answered in time).
|
|
75
75
|
*/
|
|
76
76
|
publishStream(envelope: TeamsEnvelope, options?: PublishOptions): Promise<Delivered>;
|
|
77
77
|
private streamRefused;
|
|
@@ -82,16 +82,16 @@ export declare class ConnectorOutbox implements DirectOutbox {
|
|
|
82
82
|
private once;
|
|
83
83
|
/**
|
|
84
84
|
* The bot's 1:1 conversation with `userId` (a `29:` id from a group activity), created if it does not exist yet.
|
|
85
|
-
* Throws ConversationNotOpenedError, with the status Teams answered (never a body).
|
|
85
|
+
* Throws ConversationNotOpenedError, with the status Teams answered (never a body).
|
|
86
86
|
*/
|
|
87
87
|
openPersonal(serviceUrl: string, userId: string, tenantId: string, botId: string): Promise<string>;
|
|
88
88
|
private notOpened;
|
|
89
89
|
/**
|
|
90
90
|
* The members of a group chat the bot is in, each as the Bot Connector gives it. One request and one retry on a
|
|
91
91
|
* rejected token. Throws UnaddressableError for an address the policy refuses and UndeliverableError when Teams did
|
|
92
|
-
* not answer.
|
|
92
|
+
* not answer.
|
|
93
93
|
*/
|
|
94
94
|
listMembers(serviceUrl: string, conversationId: string): Promise<ConnectorMember[]>;
|
|
95
|
-
/** Closes the token source
|
|
95
|
+
/** Closes the token source. */
|
|
96
96
|
close(): Promise<void>;
|
|
97
97
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The test entry's stand-in for what production has behind the Bot Connector: a made-up bot token that goes only to the
|
|
3
|
+
* recording connector. Nothing of the gate reaches Service Bus or Teams.
|
|
4
|
+
*/
|
|
5
|
+
import type { TokenSource } from "../connector/tokens/cached.js";
|
|
6
|
+
/** The bot's token in the test entry: made up, and sent only to the recording connector (its service-URL policy). */
|
|
7
|
+
export declare class GateToken implements TokenSource {
|
|
8
|
+
private readonly token;
|
|
9
|
+
constructor(runId: string);
|
|
10
|
+
get(): Promise<string>;
|
|
11
|
+
invalidate(): void;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
* The delivery probe: a synthetic message that takes the path every person's message takes, so a broken or slow path is
|
|
3
3
|
* seen when nobody is writing, not when somebody's message is lost. The ingress puts a `primusclaw.probe` on the inbound
|
|
4
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
|
|
6
|
-
* typing indicator there, with an ack. The relay takes that
|
|
7
|
-
* it back on the inbound queue as it acks a posted message.
|
|
5
|
+
* like any message and answers it here. With OUTBOUND_MODE=servicebus (the default) it answers the way it answers a
|
|
6
|
+
* person: one envelope on the outbound queue, as it would put a typing indicator there, with an ack. The relay takes that
|
|
7
|
+
* envelope (operation `probe`), posts nothing to Teams, and acks it back on the inbound queue as it acks a posted message.
|
|
8
|
+
*
|
|
9
|
+
* With the worker posting to Teams directly (OUTBOUND_MODE=direct) there is no outbound queue and no relay: the
|
|
10
|
+
* probe covers the hops that exist, the ingress, the inbound queue, the consumer and the handler, and is answered as soon
|
|
11
|
+
* as the worker has it (`inboundOnly`); nothing is sent anywhere.
|
|
8
12
|
*
|
|
9
13
|
* Two times are measured from when the ingress sent the probe: `feedback`, until the worker had queued its answer (when a
|
|
10
14
|
* person's typing indicator is queued), and `reply`, until the relay's ack came back to the worker (the whole round trip
|
|
@@ -26,8 +30,10 @@ export interface ProbeStats {
|
|
|
26
30
|
probed(feedbackMs: number, replyMs: number | null): void;
|
|
27
31
|
}
|
|
28
32
|
export interface ProbeParts {
|
|
29
|
-
/** The outbound queue (the relay's); none (the release gate's test entry):
|
|
33
|
+
/** The outbound queue (the relay's); none (the release gate's test entry, or `inboundOnly`): nothing is queued. */
|
|
30
34
|
readonly outbox: Outbox | undefined;
|
|
35
|
+
/** Direct outbound: no queue and no relay, so a probe is answered, and its times taken, when the worker has it. */
|
|
36
|
+
readonly inboundOnly?: boolean;
|
|
31
37
|
readonly acks: AckRegistry;
|
|
32
38
|
readonly clock: Clock;
|
|
33
39
|
readonly stats?: ProbeStats;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primusclaw/personal-agent-teams",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
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.15.
|
|
39
|
-
"@primusclaw/personal-agent-runtime": "0.15.
|
|
38
|
+
"@primusclaw/personal-agent": "0.15.3",
|
|
39
|
+
"@primusclaw/personal-agent-runtime": "0.15.3",
|
|
40
40
|
"zod": "^4.6.7"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The test entry's stand-ins for what production has behind the Bot Connector: no queue (a send the recording connector
|
|
3
|
-
* did not take is dropped and logged; nothing of the gate reaches Service Bus or Teams) and a made-up bot token that goes
|
|
4
|
-
* only to the recording connector.
|
|
5
|
-
*/
|
|
6
|
-
import type { Logger } from "@primusclaw/personal-agent";
|
|
7
|
-
import type { TokenSource } from "../connector/tokens/cached.js";
|
|
8
|
-
import { type Delivered, type Outbox, type TeamsEnvelope } from "../outbound/outbox.js";
|
|
9
|
-
export declare class NoQueue implements Outbox {
|
|
10
|
-
private readonly logger;
|
|
11
|
-
constructor(logger?: Logger);
|
|
12
|
-
publish(envelope: TeamsEnvelope): Promise<Delivered | undefined>;
|
|
13
|
-
close(): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
/** The bot's token in the test entry: made up, and sent only to the recording connector (its service-URL policy). */
|
|
16
|
-
export declare class GateToken implements TokenSource {
|
|
17
|
-
private readonly token;
|
|
18
|
-
constructor(runId: string);
|
|
19
|
-
get(): Promise<string>;
|
|
20
|
-
invalidate(): void;
|
|
21
|
-
close(): Promise<void>;
|
|
22
|
-
}
|