@primusclaw/personal-agent-teams 0.2.0 → 0.4.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.
@@ -0,0 +1,97 @@
1
+ // packages/teams/src/connector/hosts.ts
2
+ import { pyStrip, silentLogger } from "@primusclaw/personal-agent";
3
+
4
+ // packages/teams/src/connector/errors.ts
5
+ var UnaddressableError = class extends Error {
6
+ name = "UnaddressableError";
7
+ };
8
+
9
+ // packages/teams/src/connector/hosts.ts
10
+ var DEFAULT_HOSTS = ["smba.trafficmanager.net"];
11
+ var DEFAULT_SUFFIXES = [
12
+ ".botframework.com",
13
+ ".botframework.us",
14
+ ".teams.microsoft.com",
15
+ ".teams.microsoft.us"
16
+ ];
17
+ var LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
18
+ var NAME = new RegExp(`^${LABEL}(?:\\.${LABEL})+$`);
19
+ function ambiguous(text) {
20
+ for (const ch of text) {
21
+ const code = ch.codePointAt(0) ?? 0;
22
+ if (code <= 32 || code === 127 || code === 92) return true;
23
+ }
24
+ return false;
25
+ }
26
+ function parse(serviceUrl) {
27
+ if (typeof serviceUrl !== "string" || ambiguous(serviceUrl)) return void 0;
28
+ try {
29
+ return new URL(serviceUrl);
30
+ } catch {
31
+ return void 0;
32
+ }
33
+ }
34
+ var ConnectorHosts = class _ConnectorHosts {
35
+ /** `hosts`: exact host names. `suffixes`: ".example.com" allows any name under example.com, not example.com itself. */
36
+ constructor(hosts = DEFAULT_HOSTS, suffixes = DEFAULT_SUFFIXES) {
37
+ this.hosts = hosts;
38
+ this.suffixes = suffixes;
39
+ }
40
+ hosts;
41
+ suffixes;
42
+ /** The lower-cased host of `serviceUrl` when it is an https Bot Connector address on an allowed host; throws otherwise. */
43
+ host(serviceUrl) {
44
+ if (typeof serviceUrl !== "string") throw new UnaddressableError("the serviceUrl is not a string");
45
+ const url = parse(serviceUrl);
46
+ const host = url?.hostname.toLowerCase() ?? "";
47
+ const allowed = url !== void 0 && url.protocol === "https:" && url.username === "" && url.password === "" && (url.port === "" || url.port === "443") && (this.hosts.includes(host) || this.suffixes.some((suffix) => host.endsWith(suffix)));
48
+ if (!allowed) throw new UnaddressableError(`the serviceUrl host ${host || "?"} is not a Bot Connector host`);
49
+ return host;
50
+ }
51
+ check(serviceUrl) {
52
+ this.host(serviceUrl);
53
+ }
54
+ /**
55
+ * The allow-list from two ";"- or ","-separated settings. An unset setting (undefined) keeps its default; a set one
56
+ * replaces it, so an empty value allows nothing of that kind. Suffixes are written `.example.com` or `*.example.com`.
57
+ * An entry that is not a host name of at least two labels is ignored with an error in the log, so a typo narrows the
58
+ * list instead of widening it.
59
+ */
60
+ static fromSettings(hosts, suffixes, logger = silentLogger) {
61
+ return new _ConnectorHosts(
62
+ hosts === void 0 ? DEFAULT_HOSTS : entries(hosts, false, logger),
63
+ suffixes === void 0 ? DEFAULT_SUFFIXES : entries(suffixes, true, logger)
64
+ );
65
+ }
66
+ };
67
+ function entries(value, suffix, logger) {
68
+ const out = [];
69
+ for (const raw of value.split(/[;,]/)) {
70
+ const entry = asciiLower(pyStrip(raw));
71
+ if (!entry) continue;
72
+ const name = suffix ? removePrefix(removePrefix(entry, "*."), ".") : entry;
73
+ if (!NAME.test(name)) {
74
+ logger.error("ignoring Bot Connector entry: not a host name of at least two labels", {
75
+ kind: suffix ? "suffix" : "host",
76
+ entry
77
+ });
78
+ continue;
79
+ }
80
+ out.push(suffix ? `.${name}` : name);
81
+ }
82
+ return out;
83
+ }
84
+ function asciiLower(text) {
85
+ return text.replace(/[A-Z]/g, (ch) => ch.toLowerCase());
86
+ }
87
+ function removePrefix(text, prefix) {
88
+ return text.startsWith(prefix) ? text.slice(prefix.length) : text;
89
+ }
90
+ var DEFAULT_CONNECTOR_HOSTS = new ConnectorHosts();
91
+ export {
92
+ ConnectorHosts,
93
+ DEFAULT_CONNECTOR_HOSTS,
94
+ DEFAULT_HOSTS,
95
+ DEFAULT_SUFFIXES,
96
+ UnaddressableError
97
+ };
package/dist/index.js CHANGED
@@ -2347,21 +2347,34 @@ ${model.page}`),
2347
2347
  [confirmButton()]
2348
2348
  );
2349
2349
  }
2350
+ var BINDING_WORDS = {
2351
+ en: {
2352
+ title: (bot) => `Connect ${bot}`,
2353
+ body: "Open the link, sign in to your Primus account and confirm once. After that I work as you on the Primus platform, with your own permissions.",
2354
+ note: "The link works once and runs out in 10 minutes. I use a token that lasts 5 minutes, never your password. You can remove the connection in SaFE under identity bindings.",
2355
+ open: "Open link",
2356
+ confirmed: "I confirmed"
2357
+ },
2358
+ zh: {
2359
+ title: (bot) => `\u8FDE\u63A5 ${bot}`,
2360
+ body: "\u6253\u5F00\u94FE\u63A5\uFF0C\u767B\u5F55\u4F60\u7684 Primus \u8D26\u53F7\u5E76\u786E\u8BA4\u4E00\u6B21\u3002\u4E4B\u540E\u6211\u5728 Primus \u5E73\u53F0\u4E0A\u4EE5\u4F60\u7684\u8EAB\u4EFD\u3001\u7528\u4F60\u81EA\u5DF1\u7684\u6743\u9650\u505A\u4E8B\u3002",
2361
+ note: "\u94FE\u63A5\u53EA\u80FD\u7528\u4E00\u6B21\uFF0C10 \u5206\u949F\u540E\u5931\u6548\u3002\u6211\u7528\u7684\u662F 5 \u5206\u949F\u6709\u6548\u7684\u4EE4\u724C\uFF0C\u4ECE\u4E0D\u7528\u4F60\u7684\u5BC6\u7801\u3002\u4F60\u53EF\u4EE5\u5728 SaFE \u7684\u8EAB\u4EFD\u7ED1\u5B9A\u91CC\u5220\u9664\u8FD9\u4E2A\u8FDE\u63A5\u3002",
2362
+ open: "\u6253\u5F00\u94FE\u63A5",
2363
+ confirmed: "\u6211\u5DF2\u786E\u8BA4"
2364
+ }
2365
+ };
2350
2366
  function bindingCard(model) {
2367
+ const words = BINDING_WORDS[model.lang === "zh" ? "zh" : "en"];
2351
2368
  return message(
2352
2369
  [
2353
- header(`Connect ${model.bot}`, { tone: "accent", subtitle: model.lead.trim(), emoji: "connect" }),
2354
- text(
2355
- "Open the link, sign in to your Primus account and confirm once. After that I work as you on the Primus platform, with your own permissions."
2356
- ),
2357
- note(
2358
- "The link works once and runs out in 10 minutes. I use a token that lasts 5 minutes, never your password. You can remove the connection in SaFE under identity bindings."
2359
- ),
2370
+ header(words.title(model.bot), { tone: "accent", subtitle: model.lead.trim(), emoji: "connect" }),
2371
+ text(words.body),
2372
+ note(words.note),
2360
2373
  note(model.notice)
2361
2374
  ],
2362
2375
  buttons([
2363
- openUrl("Open link", model.confirmUrl),
2364
- execute("I confirmed", "primusclaw.bind", { primusclaw: "bind", action: "confirm" })
2376
+ openUrl(words.open, model.confirmUrl),
2377
+ execute(words.confirmed, "primusclaw.bind", { primusclaw: "bind", action: "confirm" })
2365
2378
  ])
2366
2379
  );
2367
2380
  }
@@ -4179,19 +4192,31 @@ function busNamespace(raw) {
4179
4192
  }
4180
4193
  return value;
4181
4194
  }
4195
+ function tokenSourceOf(env, secretSet) {
4196
+ const fallback = secretSet ? "secret" : "imds";
4197
+ return oneOf(env, "BOT_TOKEN_SOURCE", ["imds", "federated", "secret"], fallback);
4198
+ }
4182
4199
  function botFromEnv(env, mode) {
4183
- const tokenSource = oneOf(env, "BOT_TOKEN_SOURCE", ["imds", "federated"], "imds");
4200
+ const secretSet = get(env, "BOT_CLIENT_SECRET") !== "";
4201
+ const tokenSource = tokenSourceOf(env, secretSet);
4184
4202
  const federated = tokenSource === "federated";
4185
- if (federated && mode !== "direct")
4186
- throw new TeamsConfigError("BOT_TOKEN_SOURCE=federated needs OUTBOUND_MODE=direct");
4187
- return {
4203
+ const secret = tokenSource === "secret";
4204
+ if ((federated || secret) && mode !== "direct") {
4205
+ const what = get(env, "BOT_TOKEN_SOURCE") ? `BOT_TOKEN_SOURCE=${tokenSource}` : "BOT_CLIENT_SECRET";
4206
+ throw new TeamsConfigError(`${what} needs OUTBOUND_MODE=direct`);
4207
+ }
4208
+ const settings2 = {
4188
4209
  tokenSource,
4189
- msiClientId: mode === "direct" ? required(env, "BOT_MSI_CLIENT_ID") : "",
4190
- tenantId: federated ? required(env, "BOT_TENANT_ID") : get(env, "BOT_TENANT_ID"),
4210
+ msiClientId: mode === "direct" && !secret ? required(env, "BOT_MSI_CLIENT_ID") : get(env, "BOT_MSI_CLIENT_ID"),
4211
+ clientId: secret ? required(env, "BOT_CLIENT_ID") : get(env, "BOT_CLIENT_ID"),
4212
+ clientSecretIgnored: secretSet && !secret,
4213
+ tenantId: federated || secret ? required(env, "BOT_TENANT_ID") : get(env, "BOT_TENANT_ID"),
4191
4214
  assertionKeyFile: federated ? required(env, "BOT_ASSERTION_KEY_FILE") : get(env, "BOT_ASSERTION_KEY_FILE"),
4192
4215
  assertionIssuer: federated ? httpsIssuer(env) : "",
4193
4216
  assertionSubject: federated ? required(env, "BOT_ASSERTION_SUBJECT") : get(env, "BOT_ASSERTION_SUBJECT")
4194
4217
  };
4218
+ const clientSecret = secret ? required(env, "BOT_CLIENT_SECRET") : "";
4219
+ return Object.defineProperty(settings2, "clientSecret", { value: clientSecret, enumerable: false });
4195
4220
  }
4196
4221
  function wholeNumber(env, name, fallback) {
4197
4222
  const raw = get(env, name);
@@ -5057,7 +5082,7 @@ import {
5057
5082
 
5058
5083
  // packages/teams/src/assembly/outbound.ts
5059
5084
  import { readFileSync as readFileSync2 } from "node:fs";
5060
- import { silentLogger as silentLogger16 } from "@primusclaw/personal-agent";
5085
+ import { silentLogger as silentLogger17 } from "@primusclaw/personal-agent";
5061
5086
 
5062
5087
  // packages/teams/src/connector/outbox.ts
5063
5088
  import { pyStr as pyStr8, silentLogger as silentLogger12 } from "@primusclaw/personal-agent";
@@ -5613,8 +5638,72 @@ function buildRequestLazily(envelope2, policy) {
5613
5638
  return () => buildRequest(envelope2, policy);
5614
5639
  }
5615
5640
 
5616
- // packages/teams/src/connector/tokens/imds.ts
5641
+ // packages/teams/src/connector/tokens/client-secret.ts
5617
5642
  import { silentLogger as silentLogger13 } from "@primusclaw/personal-agent";
5643
+ var ClientSecretTokenProvider = class extends CachedTokenProvider {
5644
+ source = "secret";
5645
+ scope;
5646
+ clientId;
5647
+ tenantId;
5648
+ #secret;
5649
+ fetch;
5650
+ logger;
5651
+ url;
5652
+ /** Throws (an Error naming the missing setting, never a value) rather than at the first token. */
5653
+ constructor(options) {
5654
+ super(options.clock);
5655
+ const named = [
5656
+ ["client id", options.clientId],
5657
+ ["tenant id", options.tenantId],
5658
+ ["client secret", options.clientSecret]
5659
+ ];
5660
+ for (const [name, value] of named) {
5661
+ if (!value) throw new Error(`the client secret token needs the ${name}`);
5662
+ }
5663
+ this.clientId = options.clientId;
5664
+ this.tenantId = options.tenantId;
5665
+ this.#secret = options.clientSecret;
5666
+ this.fetch = options.fetch ?? globalThis.fetch;
5667
+ this.logger = options.logger ?? silentLogger13;
5668
+ this.url = options.url || `${ENTRA_TOKEN_HOST}/${pyQuote(options.tenantId, "")}/oauth2/v2.0/token`;
5669
+ this.scope = options.scope ?? BOT_CONNECTOR_SCOPE;
5670
+ }
5671
+ async fetchToken(signal) {
5672
+ const form = new URLSearchParams({
5673
+ grant_type: "client_credentials",
5674
+ client_id: this.clientId,
5675
+ client_secret: this.#secret,
5676
+ scope: this.scope
5677
+ });
5678
+ const { status, text: text4 } = await tokenRequest(
5679
+ { fetch: this.fetch, clock: this.clock },
5680
+ "Entra ID",
5681
+ this.url,
5682
+ { method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body: form.toString() },
5683
+ ENTRA_TIMEOUT_MS,
5684
+ signal
5685
+ );
5686
+ if (status !== 200) {
5687
+ throw new TokenError(`Entra ID answered ${String(status)}${entraCodes(text4)}`, status === 429 || status >= 500);
5688
+ }
5689
+ const answer = parseTokenAnswer(text4);
5690
+ if (answer === void 0) throw new TokenError("Entra ID answered without a usable token");
5691
+ this.keep(answer.token, answer.expiresIn);
5692
+ if (this.scope === BOT_CONNECTOR_SCOPE) {
5693
+ this.logger.info("bot connector token fetched with the client secret", { validForS: answer.expiresIn });
5694
+ } else {
5695
+ this.logger.info("token fetched with the client secret", {
5696
+ scope: this.scope,
5697
+ clientId: this.clientId,
5698
+ validForS: answer.expiresIn
5699
+ });
5700
+ }
5701
+ return answer.token;
5702
+ }
5703
+ };
5704
+
5705
+ // packages/teams/src/connector/tokens/imds.ts
5706
+ import { silentLogger as silentLogger14 } from "@primusclaw/personal-agent";
5618
5707
  var BOT_CONNECTOR_RESOURCE = "https://api.botframework.com";
5619
5708
  var IMDS_TOKEN_URL = "http://169.254.169.254/metadata/identity/oauth2/token";
5620
5709
  var IMDS_API_VERSION = "2018-02-01";
@@ -5625,7 +5714,7 @@ var ImdsTokenProvider = class extends CachedTokenProvider {
5625
5714
  this.clientId = clientId;
5626
5715
  if (!clientId) throw new Error("the managed identity's client id is required");
5627
5716
  this.fetch = options.fetch ?? globalThis.fetch;
5628
- this.logger = options.logger ?? silentLogger13;
5717
+ this.logger = options.logger ?? silentLogger14;
5629
5718
  this.url = options.url ?? IMDS_TOKEN_URL;
5630
5719
  }
5631
5720
  clientId;
@@ -5659,9 +5748,9 @@ var ImdsTokenProvider = class extends CachedTokenProvider {
5659
5748
  };
5660
5749
 
5661
5750
  // packages/teams/src/gate/no-queue.ts
5662
- import { silentLogger as silentLogger14 } from "@primusclaw/personal-agent";
5751
+ import { silentLogger as silentLogger15 } from "@primusclaw/personal-agent";
5663
5752
  var NoQueue = class {
5664
- constructor(logger = silentLogger14) {
5753
+ constructor(logger = silentLogger15) {
5665
5754
  this.logger = logger;
5666
5755
  }
5667
5756
  logger;
@@ -5754,7 +5843,7 @@ function azureBusClient(connection, lockRenewalMs) {
5754
5843
  }
5755
5844
 
5756
5845
  // packages/teams/src/servicebus/outbox.ts
5757
- import { errorName as errorName7, pyJsonDumps, silentLogger as silentLogger15 } from "@primusclaw/personal-agent";
5846
+ import { errorName as errorName7, pyJsonDumps, silentLogger as silentLogger16 } from "@primusclaw/personal-agent";
5758
5847
  var IDLE_REOPEN_MS = 24e4;
5759
5848
  var ServiceBusOutbox = class {
5760
5849
  constructor(client, queue, clock, logger) {
@@ -5763,7 +5852,7 @@ var ServiceBusOutbox = class {
5763
5852
  this.clock = clock;
5764
5853
  this.sender = client.sender(queue);
5765
5854
  this.usedAt = clock.monotonicMs();
5766
- this.logger = logger ?? silentLogger15;
5855
+ this.logger = logger ?? silentLogger16;
5767
5856
  }
5768
5857
  client;
5769
5858
  queue;
@@ -5812,8 +5901,23 @@ var StartupError = class extends Error {
5812
5901
  };
5813
5902
  function botTokenSource(settings2, deps) {
5814
5903
  const { bot } = settings2;
5815
- const logger = deps.logger ?? silentLogger16;
5904
+ const logger = deps.logger ?? silentLogger17;
5816
5905
  const base2 = { clock: deps.clock, logger, ...deps.fetch ? { fetch: deps.fetch } : {} };
5906
+ if (bot.clientSecretIgnored) {
5907
+ logger.warn("BOT_CLIENT_SECRET is set but not used: BOT_TOKEN_SOURCE names another source", {
5908
+ tokenSource: bot.tokenSource
5909
+ });
5910
+ }
5911
+ if (bot.tokenSource === "secret") {
5912
+ const provider = new ClientSecretTokenProvider({
5913
+ ...base2,
5914
+ clientId: bot.clientId,
5915
+ tenantId: bot.tenantId,
5916
+ clientSecret: bot.clientSecret
5917
+ });
5918
+ logger.info("bot token source: secret", { clientId: bot.clientId, tenantId: bot.tenantId });
5919
+ return provider;
5920
+ }
5817
5921
  if (bot.tokenSource !== "federated") {
5818
5922
  logger.info("bot token source: imds", { clientId: bot.msiClientId });
5819
5923
  return new ImdsTokenProvider(bot.msiClientId, base2);
@@ -5861,7 +5965,7 @@ function busConnections(settings2, credential) {
5861
5965
  function gateOutbound(gate, deps) {
5862
5966
  const tokens = new GateToken(gate.runId);
5863
5967
  const policy = onlyConnector(gate.connectorUrl);
5864
- (deps.logger ?? silentLogger16).warn("release gate test entry: outbound to the recording connector only; no queue", {
5968
+ (deps.logger ?? silentLogger17).warn("release gate test entry: outbound to the recording connector only; no queue", {
5865
5969
  runId: gate.runId
5866
5970
  });
5867
5971
  const outbox = new ConnectorOutbox({
@@ -5879,7 +5983,7 @@ function productionOutbound(settings2, outbound, deps) {
5879
5983
  if (settings2.outboundMode !== "direct") {
5880
5984
  return { outbox: queue, tokens: void 0, policy: DEFAULT_CONNECTOR_HOSTS, close: () => queue.close() };
5881
5985
  }
5882
- (deps.logger ?? silentLogger16).info("outbound mode: direct to the Bot Connector (the queue is the fallback)");
5986
+ (deps.logger ?? silentLogger17).info("outbound mode: direct to the Bot Connector (the queue is the fallback)");
5883
5987
  const tokens = botTokenSource(settings2, deps);
5884
5988
  const outbox = new ConnectorOutbox({
5885
5989
  tokens,
@@ -6231,7 +6335,7 @@ function runFollowUps(base2, errors) {
6231
6335
  }
6232
6336
  };
6233
6337
  }
6234
- function proactiveParts(base2, style, assistant, errors) {
6338
+ function proactiveParts(base2, style, assistant, errors, router) {
6235
6339
  const { store, claw, surface, settings: settings2 } = base2;
6236
6340
  const deps = {
6237
6341
  store,
@@ -6260,11 +6364,36 @@ function proactiveParts(base2, style, assistant, errors) {
6260
6364
  clock: base2.clock,
6261
6365
  logger: base2.logger,
6262
6366
  publicEvent: (event) => publicRunEvent(event, errors, (text4) => looksLikeServiceError(text4) || looksInternal(text4)),
6263
- botName: "Clawy"
6367
+ botName: "Clawy",
6368
+ ...router === void 0 ? {} : { identityAfterRefusal: identityAfterRefusal(base2, router) }
6264
6369
  };
6265
6370
  const proactive = new Proactive(deps);
6266
6371
  return { proactive, release: new Release(deps, proactive) };
6267
6372
  }
6373
+ function identityAfterRefusal(base2, router) {
6374
+ return async (userId, conversation, turn8) => {
6375
+ const { store } = base2;
6376
+ const once = `${IDENTITY_REFUSED_PREFIX}${userId}:${turn8}`;
6377
+ if (!turn8) return;
6378
+ const claim = store.idempotency.claimEvent(once);
6379
+ if (claim.state !== "claimed") return;
6380
+ let sent = false;
6381
+ try {
6382
+ const person = {
6383
+ id: userId,
6384
+ channelUserId: store.members.channelIdOf(userId) ?? "",
6385
+ name: store.members.memberName(userId) ?? "",
6386
+ email: ""
6387
+ };
6388
+ const r = router();
6389
+ sent = await r.ctx.credentials.identityAfterRefusal(r.chat(person, conversation));
6390
+ } finally {
6391
+ if (sent) store.idempotency.finishEvent(once);
6392
+ else store.idempotency.releaseEvent(once, claim.holder);
6393
+ }
6394
+ };
6395
+ }
6396
+ var IDENTITY_REFUSED_PREFIX = "identity-refused:";
6268
6397
  function proactiveHold(parts) {
6269
6398
  return {
6270
6399
  muted: (userId) => parts.proactive.muted(userId) ?? null,
@@ -6876,7 +7005,7 @@ function routerDeps(base2, built, errors) {
6876
7005
  connectionsText: whoamiConnections(plugins.integrations),
6877
7006
  reportView: (userId, scope) => w8.reportView(userId, scope),
6878
7007
  note: noteFactory,
6879
- subscriptions: subs === void 0 ? void 0 : { ensure: (u) => subs.ensure(u), remove: (u, key) => subs.remove(u, key) },
7008
+ subscriptions: subs === void 0 ? void 0 : { ensure: (u, credential) => subs.ensure(u, credential), remove: (u, key) => subs.remove(u, key) },
6880
7009
  handlers: built.handlers,
6881
7010
  integrations: plugins.integrations
6882
7011
  };
@@ -7002,7 +7131,7 @@ function buildFeatures(given) {
7002
7131
  hooks,
7003
7132
  reviewHandoff: (userId, event) => lateReview.handoff?.take(userId, event) ?? "dropped"
7004
7133
  });
7005
- const proactive = proactiveParts(base2, teams.style, assistant, errors);
7134
+ const proactive = proactiveParts(base2, teams.style, assistant, errors, get3);
7006
7135
  const reach = followReach(proactive, base2);
7007
7136
  const remote = remoteAgents(base2, { switches, guard, reach, errors, directChat: assistant.directChat, hooks });
7008
7137
  const w8 = w8Parts(base2, { briefEnabled: switches.brief, assistantOn: (userId) => assistant.chat.on(userId) });
@@ -7124,7 +7253,7 @@ function metricsRoutes(render) {
7124
7253
  }
7125
7254
 
7126
7255
  // packages/teams/src/assembly/inbound.ts
7127
- import { silentLogger as silentLogger18 } from "@primusclaw/personal-agent";
7256
+ import { silentLogger as silentLogger19 } from "@primusclaw/personal-agent";
7128
7257
 
7129
7258
  // packages/teams/src/activity/inbound/actions.ts
7130
7259
  import { cpHead as cpHead4, pyStr as pyStr11 } from "@primusclaw/personal-agent";
@@ -8108,7 +8237,7 @@ import {
8108
8237
  err as err4,
8109
8238
  ok as ok4,
8110
8239
  pyStr as pyStr19,
8111
- silentLogger as silentLogger17
8240
+ silentLogger as silentLogger18
8112
8241
  } from "@primusclaw/personal-agent";
8113
8242
  function wireReferenceOf(activity) {
8114
8243
  const ref = {
@@ -8140,7 +8269,7 @@ function base(activity, sender) {
8140
8269
  };
8141
8270
  }
8142
8271
  function messageOf(activity, sender, options) {
8143
- const logger = options.logger ?? silentLogger17;
8272
+ const logger = options.logger ?? silentLogger18;
8144
8273
  const personal = isPersonal(activity);
8145
8274
  const found = quotesOf(activity);
8146
8275
  const attached = inboundFiles(activity);
@@ -8212,7 +8341,7 @@ function text3(value) {
8212
8341
  return typeof value === "number" && value !== 0 ? String(value) : "";
8213
8342
  }
8214
8343
  function inboundHandler(parts) {
8215
- const logger = parts.logger ?? silentLogger18;
8344
+ const logger = parts.logger ?? silentLogger19;
8216
8345
  return async (body) => {
8217
8346
  if (body["type"] === DELIVERED) {
8218
8347
  const activityId = text3(body["activity_id"]);
@@ -8415,7 +8544,7 @@ import {
8415
8544
  pyStr as pyStr20,
8416
8545
  pyStrip as pyStrip20,
8417
8546
  SecretsUnavailable as SecretsUnavailable2,
8418
- silentLogger as silentLogger19
8547
+ silentLogger as silentLogger20
8419
8548
  } from "@primusclaw/personal-agent";
8420
8549
 
8421
8550
  // packages/teams/src/azure/keyvault-config.ts
@@ -8511,7 +8640,7 @@ var KeyVaultSecretSource = class {
8511
8640
  this.credential = credential;
8512
8641
  this.options = options;
8513
8642
  this.fetch = options.fetch ?? globalThis.fetch;
8514
- this.logger = options.logger ?? silentLogger19;
8643
+ this.logger = options.logger ?? silentLogger20;
8515
8644
  this.sleep = options.sleep ?? ((ms, signal) => options.clock.sleep(ms, signal));
8516
8645
  }
8517
8646
  url;
package/dist/main.js CHANGED
@@ -680,19 +680,31 @@ function busNamespace(raw) {
680
680
  }
681
681
  return value;
682
682
  }
683
+ function tokenSourceOf(env, secretSet) {
684
+ const fallback = secretSet ? "secret" : "imds";
685
+ return oneOf(env, "BOT_TOKEN_SOURCE", ["imds", "federated", "secret"], fallback);
686
+ }
683
687
  function botFromEnv(env, mode) {
684
- const tokenSource = oneOf(env, "BOT_TOKEN_SOURCE", ["imds", "federated"], "imds");
688
+ const secretSet = get(env, "BOT_CLIENT_SECRET") !== "";
689
+ const tokenSource = tokenSourceOf(env, secretSet);
685
690
  const federated = tokenSource === "federated";
686
- if (federated && mode !== "direct")
687
- throw new TeamsConfigError("BOT_TOKEN_SOURCE=federated needs OUTBOUND_MODE=direct");
688
- return {
691
+ const secret = tokenSource === "secret";
692
+ if ((federated || secret) && mode !== "direct") {
693
+ const what = get(env, "BOT_TOKEN_SOURCE") ? `BOT_TOKEN_SOURCE=${tokenSource}` : "BOT_CLIENT_SECRET";
694
+ throw new TeamsConfigError(`${what} needs OUTBOUND_MODE=direct`);
695
+ }
696
+ const settings2 = {
689
697
  tokenSource,
690
- msiClientId: mode === "direct" ? required(env, "BOT_MSI_CLIENT_ID") : "",
691
- tenantId: federated ? required(env, "BOT_TENANT_ID") : get(env, "BOT_TENANT_ID"),
698
+ msiClientId: mode === "direct" && !secret ? required(env, "BOT_MSI_CLIENT_ID") : get(env, "BOT_MSI_CLIENT_ID"),
699
+ clientId: secret ? required(env, "BOT_CLIENT_ID") : get(env, "BOT_CLIENT_ID"),
700
+ clientSecretIgnored: secretSet && !secret,
701
+ tenantId: federated || secret ? required(env, "BOT_TENANT_ID") : get(env, "BOT_TENANT_ID"),
692
702
  assertionKeyFile: federated ? required(env, "BOT_ASSERTION_KEY_FILE") : get(env, "BOT_ASSERTION_KEY_FILE"),
693
703
  assertionIssuer: federated ? httpsIssuer(env) : "",
694
704
  assertionSubject: federated ? required(env, "BOT_ASSERTION_SUBJECT") : get(env, "BOT_ASSERTION_SUBJECT")
695
705
  };
706
+ const clientSecret = secret ? required(env, "BOT_CLIENT_SECRET") : "";
707
+ return Object.defineProperty(settings2, "clientSecret", { value: clientSecret, enumerable: false });
696
708
  }
697
709
  function wholeNumber(env, name, fallback) {
698
710
  const raw = get(env, name);
@@ -3804,21 +3816,34 @@ ${model.page}`),
3804
3816
  [confirmButton()]
3805
3817
  );
3806
3818
  }
3819
+ var BINDING_WORDS = {
3820
+ en: {
3821
+ title: (bot) => `Connect ${bot}`,
3822
+ body: "Open the link, sign in to your Primus account and confirm once. After that I work as you on the Primus platform, with your own permissions.",
3823
+ note: "The link works once and runs out in 10 minutes. I use a token that lasts 5 minutes, never your password. You can remove the connection in SaFE under identity bindings.",
3824
+ open: "Open link",
3825
+ confirmed: "I confirmed"
3826
+ },
3827
+ zh: {
3828
+ title: (bot) => `\u8FDE\u63A5 ${bot}`,
3829
+ body: "\u6253\u5F00\u94FE\u63A5\uFF0C\u767B\u5F55\u4F60\u7684 Primus \u8D26\u53F7\u5E76\u786E\u8BA4\u4E00\u6B21\u3002\u4E4B\u540E\u6211\u5728 Primus \u5E73\u53F0\u4E0A\u4EE5\u4F60\u7684\u8EAB\u4EFD\u3001\u7528\u4F60\u81EA\u5DF1\u7684\u6743\u9650\u505A\u4E8B\u3002",
3830
+ note: "\u94FE\u63A5\u53EA\u80FD\u7528\u4E00\u6B21\uFF0C10 \u5206\u949F\u540E\u5931\u6548\u3002\u6211\u7528\u7684\u662F 5 \u5206\u949F\u6709\u6548\u7684\u4EE4\u724C\uFF0C\u4ECE\u4E0D\u7528\u4F60\u7684\u5BC6\u7801\u3002\u4F60\u53EF\u4EE5\u5728 SaFE \u7684\u8EAB\u4EFD\u7ED1\u5B9A\u91CC\u5220\u9664\u8FD9\u4E2A\u8FDE\u63A5\u3002",
3831
+ open: "\u6253\u5F00\u94FE\u63A5",
3832
+ confirmed: "\u6211\u5DF2\u786E\u8BA4"
3833
+ }
3834
+ };
3807
3835
  function bindingCard(model) {
3836
+ const words = BINDING_WORDS[model.lang === "zh" ? "zh" : "en"];
3808
3837
  return message(
3809
3838
  [
3810
- header(`Connect ${model.bot}`, { tone: "accent", subtitle: model.lead.trim(), emoji: "connect" }),
3811
- text2(
3812
- "Open the link, sign in to your Primus account and confirm once. After that I work as you on the Primus platform, with your own permissions."
3813
- ),
3814
- note(
3815
- "The link works once and runs out in 10 minutes. I use a token that lasts 5 minutes, never your password. You can remove the connection in SaFE under identity bindings."
3816
- ),
3839
+ header(words.title(model.bot), { tone: "accent", subtitle: model.lead.trim(), emoji: "connect" }),
3840
+ text2(words.body),
3841
+ note(words.note),
3817
3842
  note(model.notice)
3818
3843
  ],
3819
3844
  buttons([
3820
- openUrl("Open link", model.confirmUrl),
3821
- execute("I confirmed", "primusclaw.bind", { primusclaw: "bind", action: "confirm" })
3845
+ openUrl(words.open, model.confirmUrl),
3846
+ execute(words.confirmed, "primusclaw.bind", { primusclaw: "bind", action: "confirm" })
3822
3847
  ])
3823
3848
  );
3824
3849
  }
@@ -4997,7 +5022,7 @@ import {
4997
5022
 
4998
5023
  // packages/teams/src/assembly/outbound.ts
4999
5024
  import { readFileSync as readFileSync2 } from "node:fs";
5000
- import { silentLogger as silentLogger16 } from "@primusclaw/personal-agent";
5025
+ import { silentLogger as silentLogger17 } from "@primusclaw/personal-agent";
5001
5026
 
5002
5027
  // packages/teams/src/connector/outbox.ts
5003
5028
  import { pyStr as pyStr8, silentLogger as silentLogger12 } from "@primusclaw/personal-agent";
@@ -5553,8 +5578,72 @@ function buildRequestLazily(envelope2, policy) {
5553
5578
  return () => buildRequest(envelope2, policy);
5554
5579
  }
5555
5580
 
5556
- // packages/teams/src/connector/tokens/imds.ts
5581
+ // packages/teams/src/connector/tokens/client-secret.ts
5557
5582
  import { silentLogger as silentLogger13 } from "@primusclaw/personal-agent";
5583
+ var ClientSecretTokenProvider = class extends CachedTokenProvider {
5584
+ source = "secret";
5585
+ scope;
5586
+ clientId;
5587
+ tenantId;
5588
+ #secret;
5589
+ fetch;
5590
+ logger;
5591
+ url;
5592
+ /** Throws (an Error naming the missing setting, never a value) rather than at the first token. */
5593
+ constructor(options) {
5594
+ super(options.clock);
5595
+ const named = [
5596
+ ["client id", options.clientId],
5597
+ ["tenant id", options.tenantId],
5598
+ ["client secret", options.clientSecret]
5599
+ ];
5600
+ for (const [name, value] of named) {
5601
+ if (!value) throw new Error(`the client secret token needs the ${name}`);
5602
+ }
5603
+ this.clientId = options.clientId;
5604
+ this.tenantId = options.tenantId;
5605
+ this.#secret = options.clientSecret;
5606
+ this.fetch = options.fetch ?? globalThis.fetch;
5607
+ this.logger = options.logger ?? silentLogger13;
5608
+ this.url = options.url || `${ENTRA_TOKEN_HOST}/${pyQuote(options.tenantId, "")}/oauth2/v2.0/token`;
5609
+ this.scope = options.scope ?? BOT_CONNECTOR_SCOPE;
5610
+ }
5611
+ async fetchToken(signal) {
5612
+ const form = new URLSearchParams({
5613
+ grant_type: "client_credentials",
5614
+ client_id: this.clientId,
5615
+ client_secret: this.#secret,
5616
+ scope: this.scope
5617
+ });
5618
+ const { status, text: text4 } = await tokenRequest(
5619
+ { fetch: this.fetch, clock: this.clock },
5620
+ "Entra ID",
5621
+ this.url,
5622
+ { method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body: form.toString() },
5623
+ ENTRA_TIMEOUT_MS,
5624
+ signal
5625
+ );
5626
+ if (status !== 200) {
5627
+ throw new TokenError(`Entra ID answered ${String(status)}${entraCodes(text4)}`, status === 429 || status >= 500);
5628
+ }
5629
+ const answer = parseTokenAnswer(text4);
5630
+ if (answer === void 0) throw new TokenError("Entra ID answered without a usable token");
5631
+ this.keep(answer.token, answer.expiresIn);
5632
+ if (this.scope === BOT_CONNECTOR_SCOPE) {
5633
+ this.logger.info("bot connector token fetched with the client secret", { validForS: answer.expiresIn });
5634
+ } else {
5635
+ this.logger.info("token fetched with the client secret", {
5636
+ scope: this.scope,
5637
+ clientId: this.clientId,
5638
+ validForS: answer.expiresIn
5639
+ });
5640
+ }
5641
+ return answer.token;
5642
+ }
5643
+ };
5644
+
5645
+ // packages/teams/src/connector/tokens/imds.ts
5646
+ import { silentLogger as silentLogger14 } from "@primusclaw/personal-agent";
5558
5647
  var BOT_CONNECTOR_RESOURCE = "https://api.botframework.com";
5559
5648
  var IMDS_TOKEN_URL = "http://169.254.169.254/metadata/identity/oauth2/token";
5560
5649
  var IMDS_API_VERSION = "2018-02-01";
@@ -5565,7 +5654,7 @@ var ImdsTokenProvider = class extends CachedTokenProvider {
5565
5654
  this.clientId = clientId;
5566
5655
  if (!clientId) throw new Error("the managed identity's client id is required");
5567
5656
  this.fetch = options.fetch ?? globalThis.fetch;
5568
- this.logger = options.logger ?? silentLogger13;
5657
+ this.logger = options.logger ?? silentLogger14;
5569
5658
  this.url = options.url ?? IMDS_TOKEN_URL;
5570
5659
  }
5571
5660
  clientId;
@@ -5599,9 +5688,9 @@ var ImdsTokenProvider = class extends CachedTokenProvider {
5599
5688
  };
5600
5689
 
5601
5690
  // packages/teams/src/gate/no-queue.ts
5602
- import { silentLogger as silentLogger14 } from "@primusclaw/personal-agent";
5691
+ import { silentLogger as silentLogger15 } from "@primusclaw/personal-agent";
5603
5692
  var NoQueue = class {
5604
- constructor(logger = silentLogger14) {
5693
+ constructor(logger = silentLogger15) {
5605
5694
  this.logger = logger;
5606
5695
  }
5607
5696
  logger;
@@ -5694,7 +5783,7 @@ function azureBusClient(connection, lockRenewalMs) {
5694
5783
  }
5695
5784
 
5696
5785
  // packages/teams/src/servicebus/outbox.ts
5697
- import { errorName as errorName7, pyJsonDumps, silentLogger as silentLogger15 } from "@primusclaw/personal-agent";
5786
+ import { errorName as errorName7, pyJsonDumps, silentLogger as silentLogger16 } from "@primusclaw/personal-agent";
5698
5787
  var IDLE_REOPEN_MS = 24e4;
5699
5788
  var ServiceBusOutbox = class {
5700
5789
  constructor(client, queue, clock, logger) {
@@ -5703,7 +5792,7 @@ var ServiceBusOutbox = class {
5703
5792
  this.clock = clock;
5704
5793
  this.sender = client.sender(queue);
5705
5794
  this.usedAt = clock.monotonicMs();
5706
- this.logger = logger ?? silentLogger15;
5795
+ this.logger = logger ?? silentLogger16;
5707
5796
  }
5708
5797
  client;
5709
5798
  queue;
@@ -5752,8 +5841,23 @@ var StartupError = class extends Error {
5752
5841
  };
5753
5842
  function botTokenSource(settings2, deps) {
5754
5843
  const { bot } = settings2;
5755
- const logger = deps.logger ?? silentLogger16;
5844
+ const logger = deps.logger ?? silentLogger17;
5756
5845
  const base2 = { clock: deps.clock, logger, ...deps.fetch ? { fetch: deps.fetch } : {} };
5846
+ if (bot.clientSecretIgnored) {
5847
+ logger.warn("BOT_CLIENT_SECRET is set but not used: BOT_TOKEN_SOURCE names another source", {
5848
+ tokenSource: bot.tokenSource
5849
+ });
5850
+ }
5851
+ if (bot.tokenSource === "secret") {
5852
+ const provider = new ClientSecretTokenProvider({
5853
+ ...base2,
5854
+ clientId: bot.clientId,
5855
+ tenantId: bot.tenantId,
5856
+ clientSecret: bot.clientSecret
5857
+ });
5858
+ logger.info("bot token source: secret", { clientId: bot.clientId, tenantId: bot.tenantId });
5859
+ return provider;
5860
+ }
5757
5861
  if (bot.tokenSource !== "federated") {
5758
5862
  logger.info("bot token source: imds", { clientId: bot.msiClientId });
5759
5863
  return new ImdsTokenProvider(bot.msiClientId, base2);
@@ -5801,7 +5905,7 @@ function busConnections(settings2, credential) {
5801
5905
  function gateOutbound(gate, deps) {
5802
5906
  const tokens = new GateToken(gate.runId);
5803
5907
  const policy = onlyConnector(gate.connectorUrl);
5804
- (deps.logger ?? silentLogger16).warn("release gate test entry: outbound to the recording connector only; no queue", {
5908
+ (deps.logger ?? silentLogger17).warn("release gate test entry: outbound to the recording connector only; no queue", {
5805
5909
  runId: gate.runId
5806
5910
  });
5807
5911
  const outbox = new ConnectorOutbox({
@@ -5819,7 +5923,7 @@ function productionOutbound(settings2, outbound, deps) {
5819
5923
  if (settings2.outboundMode !== "direct") {
5820
5924
  return { outbox: queue, tokens: void 0, policy: DEFAULT_CONNECTOR_HOSTS, close: () => queue.close() };
5821
5925
  }
5822
- (deps.logger ?? silentLogger16).info("outbound mode: direct to the Bot Connector (the queue is the fallback)");
5926
+ (deps.logger ?? silentLogger17).info("outbound mode: direct to the Bot Connector (the queue is the fallback)");
5823
5927
  const tokens = botTokenSource(settings2, deps);
5824
5928
  const outbox = new ConnectorOutbox({
5825
5929
  tokens,
@@ -6199,7 +6303,7 @@ function runFollowUps(base2, errors) {
6199
6303
  }
6200
6304
  };
6201
6305
  }
6202
- function proactiveParts(base2, style, assistant, errors) {
6306
+ function proactiveParts(base2, style, assistant, errors, router) {
6203
6307
  const { store, claw, surface, settings: settings2 } = base2;
6204
6308
  const deps = {
6205
6309
  store,
@@ -6228,11 +6332,36 @@ function proactiveParts(base2, style, assistant, errors) {
6228
6332
  clock: base2.clock,
6229
6333
  logger: base2.logger,
6230
6334
  publicEvent: (event) => publicRunEvent(event, errors, (text4) => looksLikeServiceError(text4) || looksInternal(text4)),
6231
- botName: "Clawy"
6335
+ botName: "Clawy",
6336
+ ...router === void 0 ? {} : { identityAfterRefusal: identityAfterRefusal(base2, router) }
6232
6337
  };
6233
6338
  const proactive = new Proactive(deps);
6234
6339
  return { proactive, release: new Release(deps, proactive) };
6235
6340
  }
6341
+ function identityAfterRefusal(base2, router) {
6342
+ return async (userId, conversation, turn8) => {
6343
+ const { store } = base2;
6344
+ const once = `${IDENTITY_REFUSED_PREFIX}${userId}:${turn8}`;
6345
+ if (!turn8) return;
6346
+ const claim = store.idempotency.claimEvent(once);
6347
+ if (claim.state !== "claimed") return;
6348
+ let sent = false;
6349
+ try {
6350
+ const person = {
6351
+ id: userId,
6352
+ channelUserId: store.members.channelIdOf(userId) ?? "",
6353
+ name: store.members.memberName(userId) ?? "",
6354
+ email: ""
6355
+ };
6356
+ const r = router();
6357
+ sent = await r.ctx.credentials.identityAfterRefusal(r.chat(person, conversation));
6358
+ } finally {
6359
+ if (sent) store.idempotency.finishEvent(once);
6360
+ else store.idempotency.releaseEvent(once, claim.holder);
6361
+ }
6362
+ };
6363
+ }
6364
+ var IDENTITY_REFUSED_PREFIX = "identity-refused:";
6236
6365
  function proactiveHold(parts) {
6237
6366
  return {
6238
6367
  muted: (userId) => parts.proactive.muted(userId) ?? null,
@@ -6844,7 +6973,7 @@ function routerDeps(base2, built, errors) {
6844
6973
  connectionsText: whoamiConnections(plugins.integrations),
6845
6974
  reportView: (userId, scope) => w8.reportView(userId, scope),
6846
6975
  note: noteFactory,
6847
- subscriptions: subs === void 0 ? void 0 : { ensure: (u) => subs.ensure(u), remove: (u, key) => subs.remove(u, key) },
6976
+ subscriptions: subs === void 0 ? void 0 : { ensure: (u, credential) => subs.ensure(u, credential), remove: (u, key) => subs.remove(u, key) },
6848
6977
  handlers: built.handlers,
6849
6978
  integrations: plugins.integrations
6850
6979
  };
@@ -6970,7 +7099,7 @@ function buildFeatures(given) {
6970
7099
  hooks,
6971
7100
  reviewHandoff: (userId, event) => lateReview.handoff?.take(userId, event) ?? "dropped"
6972
7101
  });
6973
- const proactive = proactiveParts(base2, teams.style, assistant, errors);
7102
+ const proactive = proactiveParts(base2, teams.style, assistant, errors, get3);
6974
7103
  const reach = followReach(proactive, base2);
6975
7104
  const remote = remoteAgents(base2, { switches, guard, reach, errors, directChat: assistant.directChat, hooks });
6976
7105
  const w8 = w8Parts(base2, { briefEnabled: switches.brief, assistantOn: (userId) => assistant.chat.on(userId) });
@@ -7092,7 +7221,7 @@ function metricsRoutes(render) {
7092
7221
  }
7093
7222
 
7094
7223
  // packages/teams/src/assembly/inbound.ts
7095
- import { silentLogger as silentLogger18 } from "@primusclaw/personal-agent";
7224
+ import { silentLogger as silentLogger19 } from "@primusclaw/personal-agent";
7096
7225
 
7097
7226
  // packages/teams/src/activity/inbound/actions.ts
7098
7227
  import { cpHead as cpHead4, pyStr as pyStr11 } from "@primusclaw/personal-agent";
@@ -8076,7 +8205,7 @@ import {
8076
8205
  err as err4,
8077
8206
  ok as ok4,
8078
8207
  pyStr as pyStr19,
8079
- silentLogger as silentLogger17
8208
+ silentLogger as silentLogger18
8080
8209
  } from "@primusclaw/personal-agent";
8081
8210
  function wireReferenceOf(activity) {
8082
8211
  const ref = {
@@ -8108,7 +8237,7 @@ function base(activity, sender) {
8108
8237
  };
8109
8238
  }
8110
8239
  function messageOf(activity, sender, options) {
8111
- const logger = options.logger ?? silentLogger17;
8240
+ const logger = options.logger ?? silentLogger18;
8112
8241
  const personal = isPersonal(activity);
8113
8242
  const found = quotesOf(activity);
8114
8243
  const attached = inboundFiles(activity);
@@ -8180,7 +8309,7 @@ function text3(value) {
8180
8309
  return typeof value === "number" && value !== 0 ? String(value) : "";
8181
8310
  }
8182
8311
  function inboundHandler(parts) {
8183
- const logger = parts.logger ?? silentLogger18;
8312
+ const logger = parts.logger ?? silentLogger19;
8184
8313
  return async (body) => {
8185
8314
  if (body["type"] === DELIVERED) {
8186
8315
  const activityId = text3(body["activity_id"]);
@@ -8383,7 +8512,7 @@ import {
8383
8512
  pyStr as pyStr20,
8384
8513
  pyStrip as pyStrip20,
8385
8514
  SecretsUnavailable as SecretsUnavailable2,
8386
- silentLogger as silentLogger19
8515
+ silentLogger as silentLogger20
8387
8516
  } from "@primusclaw/personal-agent";
8388
8517
 
8389
8518
  // packages/teams/src/azure/keyvault-config.ts
@@ -8479,7 +8608,7 @@ var KeyVaultSecretSource = class {
8479
8608
  this.credential = credential;
8480
8609
  this.options = options;
8481
8610
  this.fetch = options.fetch ?? globalThis.fetch;
8482
- this.logger = options.logger ?? silentLogger19;
8611
+ this.logger = options.logger ?? silentLogger20;
8483
8612
  this.sleep = options.sleep ?? ((ms, signal) => options.clock.sleep(ms, signal));
8484
8613
  }
8485
8614
  url;
@@ -3,7 +3,7 @@
3
3
  * become in the chat, what quiet hours and /pause hold and later release, approval cards sent again, and the two views of it
4
4
  * the router and the remote agents read (`ProactiveHold`, `FollowReach`).
5
5
  */
6
- import type { Conversation, ConversationRef, FollowReach, JsonObject, ProactiveHold, PublicErrors } from "@primusclaw/personal-agent";
6
+ import type { Conversation, ConversationRef, FollowReach, JsonObject, ProactiveHold, PublicErrors, Router } from "@primusclaw/personal-agent";
7
7
  import { Proactive, Release } from "@primusclaw/personal-agent";
8
8
  import type { Style } from "../config/style.js";
9
9
  import type { AssistantParts } from "./features-assistant.js";
@@ -15,7 +15,9 @@ export interface ProactiveParts {
15
15
  readonly proactive: Proactive;
16
16
  readonly release: Release;
17
17
  }
18
- export declare function proactiveParts(base: AssemblyBase, style: Style, assistant: Pick<AssistantParts, "receipts" | "directChat">, errors: PublicErrors): ProactiveParts;
18
+ export declare function proactiveParts(base: AssemblyBase, style: Style, assistant: Pick<AssistantParts, "receipts" | "directChat">, errors: PublicErrors, router?: () => Router): ProactiveParts;
19
+ /** The event claim key prefix of a turn whose identity card was sent (`identityAfterRefusal`). */
20
+ export declare const IDENTITY_REFUSED_PREFIX = "identity-refused:";
19
21
  /** What the router reads of quiet hours and /pause (`muted` as a word or null, `release` on /resume). */
20
22
  export declare function proactiveHold(parts: ProactiveParts): ProactiveHold;
21
23
  /**
@@ -5,10 +5,16 @@ export type Env = Readonly<Record<string, string | undefined>>;
5
5
  export declare class TeamsConfigError extends Error {
6
6
  name: string;
7
7
  }
8
- export type BotTokenSource = "imds" | "federated";
8
+ export type BotTokenSource = "imds" | "federated" | "secret";
9
9
  export interface BotSettings {
10
10
  readonly tokenSource: BotTokenSource;
11
11
  readonly msiClientId: string;
12
+ /** BOT_CLIENT_ID: the app registration's client id, with `secret`. */
13
+ readonly clientId: string;
14
+ /** BOT_CLIENT_SECRET, with `secret` ("" otherwise). Not enumerable: a dump of the settings does not show it. */
15
+ readonly clientSecret: string;
16
+ /** BOT_CLIENT_SECRET is set but BOT_TOKEN_SOURCE names another source, which wins (the worker warns at start). */
17
+ readonly clientSecretIgnored: boolean;
12
18
  readonly tenantId: string;
13
19
  readonly assertionKeyFile: string;
14
20
  readonly assertionIssuer: string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A token from Entra ID for an app registration's client secret (the OAuth client credentials grant): the most common
3
+ * way to run a bot outside Azure, where neither a managed identity nor a federated credential is at hand. By default the
4
+ * scope is the bot's Bot Connector scope.
5
+ *
6
+ * The secret goes into the token request's form and nowhere else: it is never logged, never part of an error message,
7
+ * and hidden from `JSON.stringify` and `util.inspect` of the provider. A refusal by Entra (400/401: wrong tenant, client
8
+ * id or secret, an expired secret) is not transient; a 429, a 5xx or a network error is. Errors name the AADSTS codes
9
+ * only, never the description (it can echo the request).
10
+ */
11
+ import { type Clock, type Logger } from "@primusclaw/personal-agent";
12
+ import { CachedTokenProvider } from "./cached.js";
13
+ export interface ClientSecretOptions {
14
+ readonly clientId: string;
15
+ readonly tenantId: string;
16
+ readonly clientSecret: string;
17
+ readonly clock: Clock;
18
+ readonly fetch?: typeof fetch;
19
+ readonly logger?: Logger;
20
+ /** The token endpoint; default Entra ID's for the tenant. */
21
+ readonly url?: string;
22
+ readonly scope?: string;
23
+ }
24
+ export declare class ClientSecretTokenProvider extends CachedTokenProvider {
25
+ #private;
26
+ readonly source = "secret";
27
+ readonly scope: string;
28
+ readonly clientId: string;
29
+ readonly tenantId: string;
30
+ private readonly fetch;
31
+ private readonly logger;
32
+ private readonly url;
33
+ /** Throws (an Error naming the missing setting, never a value) rather than at the first token. */
34
+ constructor(options: ClientSecretOptions);
35
+ protected fetchToken(signal?: AbortSignal): Promise<string>;
36
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @primusclaw/personal-agent-teams/connector-hosts: the Bot Connector host rule alone (where the bot's token may be
3
+ * sent), for the Teams ingress (@primusclaw/personal-agent-teams-ingress), which applies the worker's rule to the
4
+ * serviceUrl of every activity it accepts. An entry of its own so that the ingress loads this module and core, not the
5
+ * worker.
6
+ */
7
+ export { ConnectorHosts, DEFAULT_CONNECTOR_HOSTS, DEFAULT_HOSTS, DEFAULT_SUFFIXES } from "./connector/hosts.js";
8
+ export type { ServiceUrlPolicy } from "./connector/hosts.js";
9
+ export { UnaddressableError } from "./connector/errors.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent-teams",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "The personal agent on Microsoft Teams: activities, Adaptive Cards, streams, Bot Connector, inbound queue, process assembly.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,6 +17,10 @@
17
17
  ".": {
18
18
  "types": "./dist/types/index.d.ts",
19
19
  "default": "./dist/index.js"
20
+ },
21
+ "./connector-hosts": {
22
+ "types": "./dist/types/connector-hosts.d.ts",
23
+ "default": "./dist/connector-hosts.js"
20
24
  }
21
25
  },
22
26
  "files": [
@@ -31,8 +35,8 @@
31
35
  "dependencies": {
32
36
  "@azure/core-auth": "^1.11.0",
33
37
  "@azure/service-bus": "^7.10.0",
34
- "@primusclaw/personal-agent": "0.2.0",
35
- "@primusclaw/personal-agent-runtime": "0.2.0",
38
+ "@primusclaw/personal-agent": "0.4.0",
39
+ "@primusclaw/personal-agent-runtime": "0.4.0",
36
40
  "zod": "^4.6.7"
37
41
  },
38
42
  "devDependencies": {