copilotz 1.0.0-rc.21 → 1.0.0-rc.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/CHANGELOG.md +320 -1
  2. package/README.md +217 -87
  3. package/hosts/orgs/mod.d.ts +33 -13
  4. package/hosts/orgs/mod.js +183 -84
  5. package/hosts/web/address.d.ts +11 -0
  6. package/hosts/web/address.js +46 -0
  7. package/hosts/web/assets.js +11 -5
  8. package/hosts/web/entrances.d.ts +250 -0
  9. package/hosts/web/entrances.js +362 -0
  10. package/hosts/web/host.d.ts +15 -3
  11. package/hosts/web/host.js +31 -18
  12. package/hosts/web/mod.d.ts +4 -2
  13. package/hosts/web/mod.js +6 -0
  14. package/hosts/web/node/bundle.d.ts +5 -0
  15. package/hosts/web/node/bundle.js +1 -1
  16. package/hosts/web/node/mod.d.ts +6 -4
  17. package/hosts/web/node/mod.js +6 -4
  18. package/hosts/web/node/serve.d.ts +20 -23
  19. package/hosts/web/node/serve.js +10 -21
  20. package/hosts/web/routes.d.ts +23 -17
  21. package/hosts/web/routes.js +56 -32
  22. package/hosts/web/server.d.ts +89 -44
  23. package/hosts/web/server.js +208 -108
  24. package/hosts/web/signin.d.ts +7 -10
  25. package/hosts/web/signin.js +6 -3
  26. package/hosts/web/surface.d.ts +20 -0
  27. package/hosts/web/surface.js +42 -0
  28. package/hosts/web/theme/css.d.ts +2 -1
  29. package/hosts/web/theme/css.js +9 -2
  30. package/hosts/web/tickets.d.ts +14 -1
  31. package/hosts/web/tickets.js +30 -7
  32. package/hosts/web/widget.d.ts +31 -0
  33. package/hosts/web/widget.js +429 -0
  34. package/hosts/web/widgets.d.ts +43 -0
  35. package/hosts/web/widgets.js +117 -0
  36. package/package.json +5 -1
  37. package/plugins/access/contacts/actions/forget.js +3 -1
  38. package/plugins/access/contacts/actions/start.js +18 -8
  39. package/plugins/access/contacts/collections/contact.d.ts +2 -2
  40. package/plugins/access/contacts/collections/contact.js +1 -1
  41. package/plugins/access/contacts/contract.d.ts +5 -5
  42. package/plugins/access/contacts/contract.js +5 -5
  43. package/plugins/access/contacts/mod.d.ts +4 -0
  44. package/plugins/access/contacts/mod.js +4 -0
  45. package/plugins/access/contacts/views/contact.js +1 -0
  46. package/plugins/access/dev/actions/sign-in.d.ts +1 -0
  47. package/plugins/access/dev/actions/sign-in.js +38 -0
  48. package/plugins/access/dev/mod.d.ts +17 -0
  49. package/plugins/access/dev/mod.js +31 -0
  50. package/plugins/access/dev/shared/nearby.d.ts +2 -0
  51. package/plugins/access/dev/shared/nearby.js +27 -0
  52. package/plugins/access/directory/actions/invite.js +2 -2
  53. package/plugins/access/directory/actions/org.js +11 -8
  54. package/plugins/access/directory/collections/credit-code.d.ts +1 -1
  55. package/plugins/access/google/actions/sign-in.js +2 -0
  56. package/plugins/access/google/mod.d.ts +4 -2
  57. package/plugins/access/google/mod.js +15 -2
  58. package/plugins/access/identity/actions/session.js +5 -3
  59. package/plugins/access/identity/mod.d.ts +4 -2
  60. package/plugins/access/identity/mod.js +17 -2
  61. package/plugins/access/mod.d.ts +7 -0
  62. package/plugins/access/mod.js +1 -0
  63. package/plugins/access/spaces/shared/declared.d.ts +1 -1
  64. package/plugins/access/spaces/shared/rules.d.ts +16 -5
  65. package/plugins/access/spaces/shared/rules.js +74 -6
  66. package/plugins/agents/chat/actions/send.d.ts +21 -0
  67. package/plugins/agents/chat/actions/send.js +72 -13
  68. package/plugins/agents/chat/collections/file.d.ts +15 -0
  69. package/plugins/agents/chat/collections/file.js +12 -3
  70. package/plugins/agents/chat/collections/live.d.ts +11 -0
  71. package/plugins/agents/chat/collections/live.js +11 -1
  72. package/plugins/agents/chat/collections/message.d.ts +1 -1
  73. package/plugins/agents/chat/collections/wait.d.ts +1 -1
  74. package/plugins/agents/chat/contract.d.ts +3 -2
  75. package/plugins/agents/chat/contract.js +1 -0
  76. package/plugins/agents/chat/mod.d.ts +9 -3
  77. package/plugins/agents/chat/mod.js +28 -7
  78. package/plugins/agents/chat/processors/failed.js +8 -3
  79. package/plugins/agents/chat/processors/turn.js +6 -3
  80. package/plugins/agents/chat/shared/agents.js +11 -2
  81. package/plugins/agents/chat/shared/live.d.ts +4 -2
  82. package/plugins/agents/chat/shared/live.js +2 -1
  83. package/plugins/agents/chat/shared/types.d.ts +8 -0
  84. package/plugins/agents/history/collections/outline.d.ts +2 -2
  85. package/plugins/agents/openapi/shared/files.js +2 -0
  86. package/plugins/agents/routines/collections/routine.d.ts +1 -1
  87. package/plugins/billing/credits/collections/plan.d.ts +2 -2
  88. package/plugins/billing/credits/collections/room.d.ts +1 -1
  89. package/plugins/billing/usage/collections/rollup.d.ts +2 -2
  90. package/plugins/billing/usage/collections/usage.d.ts +2 -2
  91. package/plugins/compute/cloud/actions/pool.js +2 -0
  92. package/plugins/compute/cloud/actions/remote.js +4 -2
  93. package/plugins/compute/cloud/actions/vms.js +2 -0
  94. package/plugins/compute/cloud/collections/pool-vm.d.ts +1 -1
  95. package/plugins/compute/computers/actions/admit.js +2 -0
  96. package/plugins/compute/computers/actions/code.js +2 -0
  97. package/plugins/compute/computers/actions/enrollment.js +2 -0
  98. package/plugins/compute/computers/actions/work.js +3 -0
  99. package/plugins/compute/computers/program/version.d.ts +1 -1
  100. package/plugins/compute/computers/program/version.js +1 -1
  101. package/plugins/compute/computers/resources/downloads.js +1 -1
  102. package/plugins/compute/computers/resources/previews.js +5 -2
  103. package/plugins/interfaces/maintenance/mod.d.ts +3 -1
  104. package/plugins/interfaces/maintenance/mod.js +3 -1
  105. package/plugins/interfaces/mcp/actions/call.d.ts +4 -0
  106. package/plugins/interfaces/mcp/actions/call.js +120 -18
  107. package/plugins/interfaces/mcp/actions/conversation.d.ts +1 -0
  108. package/plugins/interfaces/mcp/actions/conversation.js +49 -0
  109. package/plugins/interfaces/mcp/actions/prune.js +5 -3
  110. package/plugins/interfaces/mcp/collections/opening.d.ts +24 -0
  111. package/plugins/interfaces/mcp/collections/opening.js +28 -0
  112. package/plugins/interfaces/mcp/mod.d.ts +27 -3
  113. package/plugins/interfaces/mcp/mod.js +42 -7
  114. package/plugins/interfaces/mcp/resources/server.d.ts +13 -4
  115. package/plugins/interfaces/mcp/resources/server.js +163 -21
  116. package/plugins/interfaces/mcp/resources/tools.d.ts +88 -12
  117. package/plugins/interfaces/mcp/resources/tools.js +113 -19
  118. package/plugins/interfaces/mcp/resources/widgets.d.ts +161 -0
  119. package/plugins/interfaces/mcp/resources/widgets.js +246 -0
  120. package/plugins/interfaces/mcp/shared/keys.d.ts +25 -19
  121. package/plugins/interfaces/mcp/shared/keys.js +55 -9
  122. package/plugins/interfaces/mcp/shared/settings.d.ts +70 -37
  123. package/plugins/interfaces/mcp/shared/settings.js +64 -39
  124. package/plugins/interfaces/mcp/views/offered.d.ts +1 -1
  125. package/plugins/interfaces/mod.d.ts +2 -1
  126. package/plugins/interfaces/mod.js +2 -1
  127. package/plugins/interfaces/voice/collections/blocked.d.ts +2 -2
  128. package/plugins/interfaces/voice/collections/call.d.ts +3 -3
  129. package/plugins/interfaces/voice/contract.d.ts +1 -1
  130. package/plugins/interfaces/voice/mod.d.ts +3 -3
  131. package/plugins/interfaces/voice/mod.js +3 -3
  132. package/plugins/interfaces/voice/resources/relay.d.ts +5 -3
  133. package/plugins/interfaces/voice/resources/relay.js +17 -6
  134. package/plugins/interfaces/voice/resources/tools.js +2 -0
  135. package/plugins/interfaces/voice/shared/settings.d.ts +5 -0
  136. package/plugins/interfaces/voice/views/call.d.ts +18 -11
  137. package/plugins/interfaces/voice/views/call.js +15 -3
  138. package/plugins/interfaces/voice/views/message.d.ts +1 -1
  139. package/plugins/interfaces/web/actions/arrive.d.ts +1 -0
  140. package/plugins/interfaces/web/actions/arrive.js +120 -0
  141. package/plugins/interfaces/web/actions/prune.d.ts +1 -0
  142. package/plugins/interfaces/web/actions/prune.js +51 -0
  143. package/plugins/interfaces/web/actions/sending.d.ts +1 -0
  144. package/plugins/interfaces/web/actions/sending.js +222 -0
  145. package/plugins/interfaces/web/actions/spent.d.ts +2 -0
  146. package/plugins/interfaces/web/actions/spent.js +59 -0
  147. package/plugins/interfaces/web/collections/rate.d.ts +122 -0
  148. package/plugins/interfaces/web/collections/rate.js +37 -0
  149. package/plugins/interfaces/web/collections/visitor.d.ts +110 -0
  150. package/plugins/interfaces/web/collections/visitor.js +64 -0
  151. package/plugins/interfaces/web/contract.d.ts +4 -0
  152. package/plugins/interfaces/web/contract.js +1 -0
  153. package/plugins/interfaces/web/lines.d.ts +36 -0
  154. package/plugins/interfaces/web/lines.js +78 -0
  155. package/plugins/interfaces/web/processors/forget.d.ts +10 -0
  156. package/plugins/interfaces/web/processors/forget.js +14 -0
  157. package/plugins/interfaces/web/resources/entrance.d.ts +47 -0
  158. package/plugins/interfaces/web/resources/entrance.js +83 -0
  159. package/plugins/interfaces/web/resources/spend.d.ts +2 -0
  160. package/plugins/interfaces/web/resources/spend.js +62 -0
  161. package/plugins/interfaces/web/shared/budget.d.ts +65 -0
  162. package/plugins/interfaces/web/shared/budget.js +134 -0
  163. package/plugins/interfaces/web/shared/lines.d.ts +158 -0
  164. package/plugins/interfaces/web/shared/lines.js +156 -0
  165. package/plugins/interfaces/web/shared/secret.d.ts +33 -0
  166. package/plugins/interfaces/web/shared/secret.js +86 -0
  167. package/plugins/interfaces/whatsapp/collections/phone.d.ts +1 -1
  168. package/plugins/interfaces/whatsapp/mod.d.ts +1 -1
  169. package/plugins/interfaces/whatsapp/mod.js +1 -1
  170. package/plugins/interfaces/whatsapp/views/message.d.ts +1 -1
  171. package/plugins/models/contract.d.ts +1 -1
  172. package/plugins/models/shared/generate.js +13 -4
  173. package/plugins/models/shared/transcribe.js +7 -1
  174. package/plugins/models/shared/use.d.ts +16 -2
  175. package/plugins/models/shared/use.js +20 -0
  176. package/runtime/browsers.d.ts +153 -17
  177. package/runtime/browsers.js +336 -30
  178. package/runtime/cache.js +25 -5
  179. package/runtime/caller.d.ts +117 -0
  180. package/runtime/caller.js +215 -0
  181. package/runtime/client.d.ts +47 -3
  182. package/runtime/client.js +132 -42
  183. package/runtime/define.d.ts +30 -9
  184. package/runtime/executor.js +7 -6
  185. package/runtime/expiring.d.ts +23 -0
  186. package/runtime/expiring.js +64 -0
  187. package/runtime/links.d.ts +27 -4
  188. package/runtime/links.js +49 -11
  189. package/runtime/memory.js +102 -15
  190. package/runtime/mod.d.ts +3 -1
  191. package/runtime/mod.js +3 -1
  192. package/runtime/mongo.d.ts +12 -0
  193. package/runtime/mongo.js +44 -0
  194. package/runtime/observe.js +82 -9
  195. package/runtime/ops.d.ts +9 -1
  196. package/runtime/owner.d.ts +14 -1
  197. package/runtime/owner.js +78 -23
  198. package/runtime/reads.js +2 -2
  199. package/runtime/registry.js +9 -3
  200. package/runtime/runtime.d.ts +7 -0
  201. package/runtime/runtime.js +1 -0
  202. package/runtime/timers.js +2 -0
  203. package/runtime/views.d.ts +1 -1
  204. package/runtime/views.js +2 -2
  205. package/runtime/wire.d.ts +1 -1
  206. package/stores/sql/postgres/maintenance.d.ts +8 -1
  207. package/stores/sql/postgres/maintenance.js +76 -9
  208. package/stores/sql/postgres/mod.d.ts +12 -4
  209. package/stores/sql/postgres/mod.js +21 -8
  210. package/plugins/interfaces/mcp/shared/caller.d.ts +0 -45
  211. package/plugins/interfaces/mcp/shared/caller.js +0 -99
@@ -11,7 +11,7 @@ import { constant, forget, ident, others, prepare, remembered, TABLES, } from ".
11
11
  import { postgresPool } from "./pool.js";
12
12
  import { dropTenant } from "./tenants.js";
13
13
  import { statement } from "../shared/statement.js";
14
- import { allowed, alone, connect, noRole, triggers } from "./maintenance.js";
14
+ import { allowed, alone, confined, connect, noRole, triggers } from "./maintenance.js";
15
15
  import { connections } from "../shared/capped.js";
16
16
  import { upTo, weight } from "../shared/rows.js";
17
17
  export { postgresPool } from "./pool.js";
@@ -91,6 +91,11 @@ const unique = (events) => {
91
91
  export async function postgresStore(options) {
92
92
  if (!options.url === !options.pool)
93
93
  throw new Error("postgresStore takes a url or a pool");
94
+ const storeRole = options.maintenance?.storeRole === true;
95
+ if (storeRole && options.maintenance?.url !== undefined) {
96
+ throw new Error("postgresStore's maintenance runs as a role of its own (url) or as the store's own role " +
97
+ "(storeRole: true), not both");
98
+ }
94
99
  const tenant = options.tenant ?? "";
95
100
  if (tenant.includes("\u0000"))
96
101
  throw new Error("A tenant can't contain a NUL character");
@@ -124,6 +129,12 @@ export async function postgresStore(options) {
124
129
  * temporary object last, whatever the statement set (in its transaction).
125
130
  */
126
131
  const settled = "SELECT pg_catalog.set_config('search_path', 'pg_catalog, pg_temp', true)";
132
+ /**
133
+ * The role check on a server, on the connection maintenance SQL runs on:
134
+ * a role of its own holds exactly maintenance's grants; the store's own
135
+ * role can't run server commands or reach its files (maintenance.ts).
136
+ */
137
+ const checked = (db) => storeRole ? confined(db) : allowed(db, schema);
127
138
  let layout;
128
139
  try {
129
140
  layout = await prepare(pool, schema);
@@ -569,7 +580,7 @@ export async function postgresStore(options) {
569
580
  throw triggered();
570
581
  // What the role holds is as it was: no large object, setting or grant came of it.
571
582
  if (pool.server)
572
- await allowed(counted(tx), schema);
583
+ await checked(counted(tx));
573
584
  // Events it wrote into the log keep their numbers: this commit's go after them.
574
585
  if (last !== undefined)
575
586
  last = Math.max(last, Number(after.seq));
@@ -918,27 +929,29 @@ export async function postgresStore(options) {
918
929
  /**
919
930
  * Refuses maintenance SQL where it could reach what isn't this tenant's: a
920
931
  * schema other tenants share; on a server, a role that holds anything
921
- * beyond maintenance's grants; in PGlite, another schema's tables
922
- * (maintenance.ts). `db` is the connection it runs on.
932
+ * beyond maintenance's grants, or as the store's own role, one that could
933
+ * run server commands or reach its files; in PGlite, another schema's
934
+ * tables (maintenance.ts). `db` is the connection it runs on.
923
935
  */
924
936
  const reachable = async (db) => {
925
937
  if (pool.server)
926
- return await allowed(db, schema);
938
+ return await checked(db);
927
939
  if (await others(counted(committed), schema, tenant))
928
940
  throw sharedSchema();
929
941
  await alone(db, schema);
930
942
  };
931
943
  /**
932
944
  * On a server, a connection of its own for one maintenance statement, as
933
- * the maintenance role, closed after, within the cap (maintenance.ts).
945
+ * the maintenance role (or the store's own), closed after, within the cap
946
+ * (maintenance.ts).
934
947
  */
935
948
  const dedicated = async (work) => {
936
949
  // A schema other tenants share comes first: no role would make SQL there theirs alone.
937
950
  if (await others(counted(committed), schema, tenant))
938
951
  throw sharedSchema();
939
- if (!options.maintenance)
952
+ const url = storeRole ? pool.url : options.maintenance?.url;
953
+ if (!url)
940
954
  throw noRole();
941
- const url = options.maintenance.url;
942
955
  return await capped(async () => {
943
956
  const db = await connect(url);
944
957
  try {
@@ -1,45 +0,0 @@
1
- /**
2
- * Who's calling, as far as the network says (see `McpCaller` in
3
- * settings.ts): the caller's address, from the header the app's front sets,
4
- * believed only through the front.
5
- *
6
- * - **With `front`** (the front's secret): a request without it came around
7
- * the front, straight to the app: it's refused (`refused`).
8
- * - **With `hops`:** the entry that many from the end of the header's list,
9
- * the one the app's own proxy appended.
10
- * - **An address that can't be read** (none, garbled, too few entries) is
11
- * no address of its own: it's counted with every other such call, in one
12
- * tight bucket (`unvouched`), never let through unlimited.
13
- * - **How it's counted:** an IPv4 address by itself (also written as IPv6,
14
- * `::ffff:a.b.c.d`); an IPv6 address by its /64 (one customer's network
15
- * has billions of addresses).
16
- * - **Exempt ranges** (a shared proxy's: OpenAI's) apply only to an address
17
- * read this way, never to one the caller claims.
18
- *
19
- * Nothing here is kept: limits count an HMAC of what's counted.
20
- */
21
- import type { McpCaller } from "./settings.js";
22
- /** Headers that hold a list of addresses, each proxy appending its own: they need `hops`. */
23
- export declare const LISTS: string[];
24
- /** Who calls: refused (around the front), or what to count them by and whether they're exempt. */
25
- export type Caller = "refused" | {
26
- counted: string;
27
- exempt: boolean;
28
- };
29
- /** Calls whose address can't be read, all counted as one. */
30
- export declare const UNVOUCHED = "unvouched";
31
- /** Who calls, by the app's `caller` settings; undefined without them (nothing goes by address). */
32
- export declare function callerFrom(request: Request, caller: McpCaller | undefined): Caller | undefined;
33
- type Bits = {
34
- bits: bigint;
35
- size: 32 | 128;
36
- };
37
- /**
38
- * An address as bits: IPv4 in 32; IPv6 in 128, unless it's an IPv4 address
39
- * written as one (`::ffff:a.b.c.d`, `::ffff:cb00:7163`), which is IPv4.
40
- * Undefined when it isn't an address. A zone (`%eth0`) or brackets aren't taken.
41
- */
42
- export declare function addressOf(text: string): Bits | undefined;
43
- /** Whether `text` is a CIDR range. */
44
- export declare const rangeOk: (text: string) => boolean;
45
- export {};
@@ -1,99 +0,0 @@
1
- /** The header the web host's front carries its secret in. */
2
- const FRONT = "x-copilotz-front";
3
- /** Headers that hold a list of addresses, each proxy appending its own: they need `hops`. */
4
- export const LISTS = ["x-forwarded-for"];
5
- /** Calls whose address can't be read, all counted as one. */
6
- export const UNVOUCHED = "unvouched";
7
- /** Whether two strings are the same, taking as long whatever their first difference. */
8
- const same = (a, b) => {
9
- let differ = a.length ^ b.length;
10
- for (let i = 0; i < Math.max(a.length, b.length); i++) {
11
- differ |= (a.charCodeAt(i) || 0) ^ (b.charCodeAt(i) || 0);
12
- }
13
- return differ === 0;
14
- };
15
- /** Who calls, by the app's `caller` settings; undefined without them (nothing goes by address). */
16
- export function callerFrom(request, caller) {
17
- if (!caller)
18
- return undefined;
19
- if (caller.front !== undefined) {
20
- const said = request.headers.get(FRONT);
21
- if (said === null || !same(said, caller.front))
22
- return "refused";
23
- }
24
- const list = (request.headers.get(caller.header) ?? "").split(",").map((part) => part.trim())
25
- .filter(Boolean);
26
- const entry = caller.hops ? list.at(-caller.hops) : list.length === 1 ? list[0] : undefined;
27
- const at = entry ? addressOf(entry) : undefined;
28
- if (!at)
29
- return { counted: UNVOUCHED, exempt: false };
30
- return {
31
- counted: at.size === 32 ? `4:${at.bits.toString(16)}` : `6:${(at.bits >> 64n).toString(16)}`,
32
- exempt: inRanges(at, caller.exempt),
33
- };
34
- }
35
- /** An IPv4 address's 32 bits, from "a.b.c.d". */
36
- function v4(text) {
37
- const parts = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(text)?.slice(1).map(Number);
38
- if (!parts || parts.some((p) => p > 255))
39
- return undefined;
40
- return parts.reduce((n, p) => (n << 8n) | BigInt(p), 0n);
41
- }
42
- /**
43
- * An address as bits: IPv4 in 32; IPv6 in 128, unless it's an IPv4 address
44
- * written as one (`::ffff:a.b.c.d`, `::ffff:cb00:7163`), which is IPv4.
45
- * Undefined when it isn't an address. A zone (`%eth0`) or brackets aren't taken.
46
- */
47
- export function addressOf(text) {
48
- const four = v4(text);
49
- if (four !== undefined)
50
- return { bits: four, size: 32 };
51
- if (!/^[0-9a-f:.]+$/i.test(text) || text.split("::").length > 2)
52
- return undefined;
53
- // A dotted IPv4 at the end, as its two groups.
54
- let written = text;
55
- const dotted = /^(.*:)(\d{1,3}(?:\.\d{1,3}){3})$/.exec(text);
56
- if (dotted) {
57
- const bits = v4(dotted[2]);
58
- if (bits === undefined)
59
- return undefined;
60
- written = `${dotted[1]}${(bits >> 16n).toString(16)}:${(bits & 0xffffn).toString(16)}`;
61
- }
62
- if (written.includes("."))
63
- return undefined;
64
- const [head, tail] = written.includes("::") ? written.split("::") : [written, undefined];
65
- const left = head ? head.split(":") : [];
66
- const right = tail ? tail.split(":") : [];
67
- const missing = 8 - left.length - right.length;
68
- if (tail === undefined ? left.length !== 8 : missing < 1)
69
- return undefined;
70
- const groups = [...left, ...Array(tail === undefined ? 0 : missing).fill("0"), ...right];
71
- if (groups.some((g) => !/^[0-9a-f]{1,4}$/i.test(g)))
72
- return undefined;
73
- const bits = groups.reduce((n, g) => (n << 16n) | BigInt(parseInt(g, 16)), 0n);
74
- // IPv4-mapped: ::ffff:0:0/96.
75
- if (bits >> 32n === 0xffffn)
76
- return { bits: bits & 0xffffffffn, size: 32 };
77
- return { bits, size: 128 };
78
- }
79
- /** A CIDR range (`192.0.2.0/24`, `2001:db8::/32`) as its bits and prefix; undefined when malformed. */
80
- function rangeOf(text) {
81
- const [address, prefix, ...more] = text.split("/");
82
- const at = addressOf(address ?? "");
83
- const length = Number(prefix);
84
- if (!at || more.length || !/^\d{1,3}$/.test(prefix ?? "") || length > at.size)
85
- return undefined;
86
- return { ...at, length };
87
- }
88
- /** Whether `text` is a CIDR range. */
89
- export const rangeOk = (text) => !!rangeOf(text);
90
- /** Whether an address is in any of the ranges. */
91
- function inRanges(at, ranges = []) {
92
- return ranges.some((text) => {
93
- const range = rangeOf(text);
94
- if (!range || range.size !== at.size)
95
- return false;
96
- const shift = BigInt(at.size - range.length);
97
- return (at.bits >> shift) === (range.bits >> shift);
98
- });
99
- }