@primusclaw/personal-agent-teams 0.3.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
  }
package/dist/main.js CHANGED
@@ -3816,21 +3816,34 @@ ${model.page}`),
3816
3816
  [confirmButton()]
3817
3817
  );
3818
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
+ };
3819
3835
  function bindingCard(model) {
3836
+ const words = BINDING_WORDS[model.lang === "zh" ? "zh" : "en"];
3820
3837
  return message(
3821
3838
  [
3822
- header(`Connect ${model.bot}`, { tone: "accent", subtitle: model.lead.trim(), emoji: "connect" }),
3823
- text2(
3824
- "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."
3825
- ),
3826
- note(
3827
- "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."
3828
- ),
3839
+ header(words.title(model.bot), { tone: "accent", subtitle: model.lead.trim(), emoji: "connect" }),
3840
+ text2(words.body),
3841
+ note(words.note),
3829
3842
  note(model.notice)
3830
3843
  ],
3831
3844
  buttons([
3832
- openUrl("Open link", model.confirmUrl),
3833
- 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" })
3834
3847
  ])
3835
3848
  );
3836
3849
  }
@@ -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.3.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.3.0",
35
- "@primusclaw/personal-agent-runtime": "0.3.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": {