@overtable/schemas 0.0.0-stage → 0.1.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +202 -0
  3. package/README.md +55 -2
  4. package/dist/index.d.ts +215 -0
  5. package/dist/index.js +759 -0
  6. package/dist/json-schema/pairs/calendar.freebusy.answer.json +41 -0
  7. package/dist/json-schema/pairs/calendar.freebusy.ask.json +32 -0
  8. package/dist/json-schema/pairs/contact.channel.answer.json +26 -0
  9. package/dist/json-schema/pairs/contact.channel.ask.json +7 -0
  10. package/dist/json-schema/pairs/message.answer.json +7 -0
  11. package/dist/json-schema/pairs/message.ask.json +17 -0
  12. package/dist/json-schema/pairs/note.answer.json +7 -0
  13. package/dist/json-schema/pairs/note.ask.json +17 -0
  14. package/dist/json-schema/pairs/offers.list.answer.json +68 -0
  15. package/dist/json-schema/pairs/offers.list.ask.json +14 -0
  16. package/dist/json-schema/pairs/overtable.ping.answer.json +17 -0
  17. package/dist/json-schema/pairs/overtable.ping.ask.json +7 -0
  18. package/dist/json-schema/pairs/preferences.ask.answer.json +22 -0
  19. package/dist/json-schema/pairs/preferences.ask.ask.json +17 -0
  20. package/dist/json-schema/pairs/quote.answer.json +57 -0
  21. package/dist/json-schema/pairs/quote.ask.json +85 -0
  22. package/dist/json-schema/pairs/rate.range.answer.json +60 -0
  23. package/dist/json-schema/pairs/rate.range.ask.json +17 -0
  24. package/dist/json-schema/pairs/recommendation.ask.answer.json +21 -0
  25. package/dist/json-schema/pairs/recommendation.ask.ask.json +17 -0
  26. package/dist/json-schema/pairs/scope.ask.answer.json +25 -0
  27. package/dist/json-schema/pairs/scope.ask.ask.json +17 -0
  28. package/dist/json-schema/pairs/slot.answer.json +43 -0
  29. package/dist/json-schema/pairs/slot.ask.json +35 -0
  30. package/dist/json-schema/requests/order.json +56 -0
  31. package/dist/json-schema/requests/poll.json +30 -0
  32. package/dist/json-schema/requests/quote.json +56 -0
  33. package/dist/json-schema/requests/request_answer.json +216 -0
  34. package/dist/json-schema/requests/request_create.json +676 -0
  35. package/dist/json-schema/requests/slot.json +33 -0
  36. package/dist/json-schema/share/availability.json +50 -0
  37. package/dist/json-schema/share/contact_details.json +45 -0
  38. package/dist/json-schema/share/documents.json +59 -0
  39. package/dist/json-schema/share/finance.json +71 -0
  40. package/dist/json-schema/share/health.json +52 -0
  41. package/dist/json-schema/share/location.json +45 -0
  42. package/dist/json-schema/share/preferences.json +46 -0
  43. package/dist/json-schema/share/share.json +458 -0
  44. package/package.json +47 -4
package/dist/index.js ADDED
@@ -0,0 +1,759 @@
1
+ // packages/schemas/src/pairs.ts
2
+ import { z as z2 } from "zod";
3
+
4
+ // packages/shared/dist/schemas.js
5
+ import { z } from "zod";
6
+
7
+ // packages/shared/dist/constants.js
8
+ var PASSKEY_CHALLENGE_TTL_MS = 5 * 60 * 1e3;
9
+ var RECOVERY_CODE_TTL_MS = 15 * 60 * 1e3;
10
+ var OAUTH_ACCESS_TOKEN_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
11
+ var OAUTH_ACCESS_TOKEN_SLIDE_STEP_MS = 60 * 60 * 1e3;
12
+ var OAUTH_REFRESH_TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
13
+ var OAUTH_CODE_TTL_MS = 2 * 60 * 1e3;
14
+ var RECOVERY_FREEZE_MS = 24 * 60 * 60 * 1e3;
15
+ var DEFAULT_THREAD_WINDOW_MS = 60 * 60 * 1e3;
16
+ var ROOM_MIN_MEMBERS = 3;
17
+ var ROOM_MAX_MEMBERS_HARD_LIMIT = 32;
18
+ var DEFAULT_RATE_WINDOW_MS = 60 * 1e3;
19
+ var DEFAULT_REGISTER_WINDOW_MS = 60 * 60 * 1e3;
20
+ var INVITE_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
21
+ var AUTH_RATE_WINDOW_MS = 15 * 60 * 1e3;
22
+ var APP_RATE_WINDOW_MS = 15 * 60 * 1e3;
23
+ var DEFAULT_JOIN_WINDOW_MS = 15 * 60 * 1e3;
24
+ var DEFAULT_PUBLIC_AGENT_WINDOW_MS = 15 * 60 * 1e3;
25
+ var WAKE_WEBHOOK_BACKOFF_MS = [0, 5e3, 3e4, 12e4, 6e5, 36e5];
26
+ var WAKE_WEBHOOK_MAX_ATTEMPTS = WAKE_WEBHOOK_BACKOFF_MS.length;
27
+ var WAKE_SECRET_GRACE_MS = 24 * 60 * 60 * 1e3;
28
+ var REPLY_MAX_MINUTES = 7 * 24 * 60;
29
+ var MCP_EVENTS_MAX_BODY_BYTES = 256 * 1024;
30
+ var MCP_EVENTS_DEFAULT_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
31
+ var MCP_EVENTS_MIN_TTL_MS = 60 * 60 * 1e3;
32
+ var MCP_EVENTS_VERIFY_CACHE_MS = 24 * 60 * 60 * 1e3;
33
+
34
+ // packages/shared/dist/email.js
35
+ var MAX_EMAIL_LENGTH = 254;
36
+ var MAX_EMAIL_LOCAL_LENGTH = 64;
37
+ var LOCAL_PART = /^[A-Za-z0-9_%+-]+(\.[A-Za-z0-9_%+-]+)*$/;
38
+ var DOMAIN_LABEL = /^[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/;
39
+ var TOP_LEVEL_LABEL = /^[A-Za-z]{2,63}$/;
40
+ function normalizeEmailAddress(raw) {
41
+ const value = raw.replace(/^ +| +$/g, "");
42
+ if (value.length === 0 || value.length > MAX_EMAIL_LENGTH) {
43
+ return null;
44
+ }
45
+ const parts = value.split("@");
46
+ if (parts.length !== 2) {
47
+ return null;
48
+ }
49
+ const [local = "", rawDomain = ""] = parts;
50
+ if (local.length > MAX_EMAIL_LOCAL_LENGTH || !LOCAL_PART.test(local)) {
51
+ return null;
52
+ }
53
+ const domain = normalizeEmailDomain(rawDomain);
54
+ return domain ? `${local}@${domain}` : null;
55
+ }
56
+ function normalizeEmailDomain(raw) {
57
+ const labels = raw.split(".");
58
+ const tld = labels[labels.length - 1] ?? "";
59
+ if (labels.length < 2 || !labels.every((label) => DOMAIN_LABEL.test(label)) || !TOP_LEVEL_LABEL.test(tld)) {
60
+ return null;
61
+ }
62
+ return raw.toLowerCase();
63
+ }
64
+
65
+ // packages/shared/dist/sharing.js
66
+ var SHARING_CATEGORIES = [
67
+ "free_text",
68
+ "availability",
69
+ "recommendations",
70
+ "preferences",
71
+ "location",
72
+ "contact_details",
73
+ "documents",
74
+ "finance",
75
+ "health",
76
+ "votes",
77
+ "commit"
78
+ ];
79
+ var COMMIT_CATEGORY = "commit";
80
+ var RULE_CATEGORIES = SHARING_CATEGORIES.filter((c) => c !== COMMIT_CATEGORY);
81
+ var SHARING_DECISIONS = ["allow", "ask", "deny"];
82
+
83
+ // packages/shared/dist/schemas.js
84
+ var MAX_TEXT = 16e3;
85
+ var MAX_IMAGES = 8;
86
+ var MAX_IMAGE_BYTES = 1048576;
87
+ var MAX_IMAGE_DATA_CHARS = Math.ceil(MAX_IMAGE_BYTES * (4 / 3)) + 128;
88
+ var ALLOWED_IMAGE_MIME_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
89
+ var MAX_SEND_BODY_BYTES = MAX_IMAGES * MAX_IMAGE_DATA_CHARS + MAX_TEXT * 6 + 64 * 1024;
90
+ var MAX_JSON_BODY_BYTES = 64 * 1024;
91
+ var UNSAFE_CHARS = /[\p{Cc}\u202A-\u202E\u2066-\u2069]/u;
92
+ function singleLine(max) {
93
+ return z.string().trim().min(1).max(max).refine((v) => !UNSAFE_CHARS.test(v), "Must not contain control characters");
94
+ }
95
+ var registerBotSchema = z.object({
96
+ botName: singleLine(80),
97
+ humanName: singleLine(80)
98
+ });
99
+ var MAX_WEBHOOK_HEADERS = 8;
100
+ var MAX_WEBHOOK_HEADER_NAME = 64;
101
+ var MAX_WEBHOOK_HEADER_VALUE = 1024;
102
+ var MAX_WEBHOOK_HEADERS_BYTES = 4096;
103
+ var HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
104
+ var HEADER_VALUE = /^[\x21-\x7e]([\x20-\x7e\t]*[\x21-\x7e])?$/;
105
+ var REFUSED_HEADER_NAMES = /* @__PURE__ */ new Set([
106
+ "connection",
107
+ "keep-alive",
108
+ "proxy-authenticate",
109
+ "proxy-authorization",
110
+ "proxy-connection",
111
+ "te",
112
+ "trailer",
113
+ "transfer-encoding",
114
+ "upgrade",
115
+ "host",
116
+ "content-length",
117
+ "content-type",
118
+ "expect"
119
+ ]);
120
+ function isRefusedWebhookHeaderName(name) {
121
+ const lower = name.toLowerCase();
122
+ return REFUSED_HEADER_NAMES.has(lower) || lower.startsWith("x-relais-");
123
+ }
124
+ var webhookHeaderSchema = z.object({
125
+ name: z.string().min(1).max(MAX_WEBHOOK_HEADER_NAME).regex(HEADER_NAME, "Header name must be an HTTP token"),
126
+ value: z.string().min(1, "Header value must not be empty").max(MAX_WEBHOOK_HEADER_VALUE, `Header value exceeds ${MAX_WEBHOOK_HEADER_VALUE} characters`).regex(HEADER_VALUE, "Header value must be printable ASCII without control characters")
127
+ });
128
+ var webhookHeadersSchema = z.array(webhookHeaderSchema).max(MAX_WEBHOOK_HEADERS, `At most ${MAX_WEBHOOK_HEADERS} extra headers`).superRefine((headers, ctx) => {
129
+ const seen = /* @__PURE__ */ new Set();
130
+ let bytes = 0;
131
+ for (const { name, value } of headers) {
132
+ bytes += name.length + value.length + 4;
133
+ if (name.length > MAX_WEBHOOK_HEADER_NAME || !HEADER_NAME.test(name)) {
134
+ continue;
135
+ }
136
+ const lower = name.toLowerCase();
137
+ if (isRefusedWebhookHeaderName(name)) {
138
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: `Header ${lower} is not allowed` });
139
+ }
140
+ if (seen.has(lower)) {
141
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: `Header ${lower} appears twice` });
142
+ }
143
+ seen.add(lower);
144
+ }
145
+ if (bytes > MAX_WEBHOOK_HEADERS_BYTES) {
146
+ ctx.addIssue({
147
+ code: z.ZodIssueCode.custom,
148
+ message: `Extra headers exceed ${MAX_WEBHOOK_HEADERS_BYTES} bytes`
149
+ });
150
+ }
151
+ });
152
+ var webhookConfigSchema = z.object({
153
+ url: z.string().url().max(2048).refine((v) => {
154
+ const u = new URL(v);
155
+ return (u.protocol === "https:" || u.protocol === "http:") && !u.username && !u.password;
156
+ }, "Webhook URL must be http(s) without credentials"),
157
+ secret: z.string().min(16).max(256),
158
+ headers: webhookHeadersSchema.optional().default([])
159
+ });
160
+ var clearWebhookSchema = z.object({
161
+ clear: z.literal(true)
162
+ });
163
+ var emailAddressSchema = z.string().max(MAX_EMAIL_LENGTH).transform((value, ctx) => {
164
+ const address = normalizeEmailAddress(value);
165
+ if (!address) {
166
+ ctx.addIssue({
167
+ code: z.ZodIssueCode.custom,
168
+ message: "address must be a plain email address like name+overtable@example.com"
169
+ });
170
+ return z.NEVER;
171
+ }
172
+ return address;
173
+ });
174
+ var wakeEmailSchema = z.object({
175
+ address: emailAddressSchema
176
+ });
177
+ var CLAUDE_FIRE_URL_RE = /^https:\/\/api\.anthropic\.com\/v1\/claude_code\/routines\/trig_[A-Za-z0-9_-]+\/fire$/;
178
+ var wakeFireSchema = z.object({
179
+ url: z.string().trim().max(2048).refine((value) => CLAUDE_FIRE_URL_RE.test(value), {
180
+ message: "fireUrl must be https://api.anthropic.com/v1/claude_code/routines/trig_\u2026/fire"
181
+ }),
182
+ token: z.string().trim().min(20).max(512).refine((value) => value.startsWith("sk-ant-oat01-"), {
183
+ message: "fireToken must be a per-routine bearer token (sk-ant-oat01-\u2026)"
184
+ })
185
+ });
186
+ var imageSchema = z.object({
187
+ data: z.string().min(1).max(MAX_IMAGE_DATA_CHARS),
188
+ mimeType: z.enum(ALLOWED_IMAGE_MIME_TYPES).optional()
189
+ });
190
+ var sharingCategorySchema = z.enum(SHARING_CATEGORIES, {
191
+ errorMap: () => ({ message: `category must be one of ${SHARING_CATEGORIES.join(", ")}` })
192
+ });
193
+ var MAX_APPROVAL_FIELDS = 8;
194
+ var approvalFieldsSchema = z.record(z.string().regex(/^[a-z][a-z0-9_]{0,39}$/, "approvalFields keys: lowercase letters, digits and _, starting with a letter"), z.number().finite()).refine((fields) => Object.keys(fields).length <= MAX_APPROVAL_FIELDS, `At most ${MAX_APPROVAL_FIELDS} approvalFields`);
195
+ var sendMessageSchema = z.object({
196
+ toBotId: z.string().uuid(),
197
+ text: z.string().trim().min(1).max(MAX_TEXT),
198
+ images: z.array(imageSchema).max(MAX_IMAGES).optional().default([]),
199
+ urgent: z.boolean().optional().default(false),
200
+ threadId: singleLine(128).nullable().optional().default(null),
201
+ requiresHumanApproval: z.boolean().optional().default(false),
202
+ category: sharingCategorySchema.optional().default("free_text"),
203
+ approvalFields: approvalFieldsSchema.optional(),
204
+ /** Ask the recipient for a reply: the message then wakes it, and the sender can follow the answer. */
205
+ replyRequested: z.boolean().optional(),
206
+ /** How long the sender waits for that reply, in minutes. Default REPLY_DEFAULT_MINUTES. */
207
+ replyWithinMinutes: z.number().int().min(1).max(REPLY_MAX_MINUTES).optional()
208
+ });
209
+ var redeemInviteSchema = z.object({
210
+ code: z.string().trim().min(6).max(64)
211
+ });
212
+ var joinSchema = registerBotSchema.extend({
213
+ code: z.string().trim()
214
+ });
215
+ var acceptContactSchema = z.object({
216
+ peerBotId: z.string().uuid()
217
+ });
218
+ var removeContactSchema = z.object({
219
+ peerBotId: z.string().uuid()
220
+ });
221
+ var blockSchema = z.object({
222
+ peerBotId: z.string().uuid()
223
+ });
224
+ var createRoomSchema = z.object({
225
+ name: singleLine(80),
226
+ /** Active contacts of the creator to add at once. With this list, size must be 3 to max. */
227
+ memberBotIds: z.array(z.string().uuid()).max(ROOM_MAX_MEMBERS_HARD_LIMIT - 1).optional().default([])
228
+ }).superRefine((value, ctx) => {
229
+ if (value.memberBotIds.length === 0) {
230
+ return;
231
+ }
232
+ if (new Set(value.memberBotIds).size !== value.memberBotIds.length) {
233
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Each member may appear only once", path: ["memberBotIds"] });
234
+ }
235
+ const size = value.memberBotIds.length + 1;
236
+ if (size < ROOM_MIN_MEMBERS) {
237
+ ctx.addIssue({
238
+ code: z.ZodIssueCode.custom,
239
+ message: `A group needs at least ${ROOM_MIN_MEMBERS} members (you included)`,
240
+ path: ["memberBotIds"]
241
+ });
242
+ }
243
+ });
244
+ function roomRefFields() {
245
+ return {
246
+ roomId: z.string().uuid().optional(),
247
+ groupId: z.string().uuid().optional()
248
+ };
249
+ }
250
+ function resolveRoomId(value, ctx) {
251
+ const roomId = value.roomId;
252
+ const groupId = value.groupId;
253
+ if (roomId && groupId && roomId !== groupId) {
254
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "roomId and groupId must be the same when both are set" });
255
+ return z.NEVER;
256
+ }
257
+ const id = roomId ?? groupId;
258
+ if (!id) {
259
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "roomId or groupId is required" });
260
+ return z.NEVER;
261
+ }
262
+ return id;
263
+ }
264
+ var roomIdSchema = z.object(roomRefFields()).transform((value, ctx) => ({ roomId: resolveRoomId(value, ctx) }));
265
+ var roomMemberSchema = z.object({
266
+ ...roomRefFields(),
267
+ botId: z.string().uuid()
268
+ }).transform((value, ctx) => ({ roomId: resolveRoomId(value, ctx), botId: value.botId }));
269
+ var sendRoomMessageSchema = z.object({
270
+ ...roomRefFields(),
271
+ text: z.string().trim().min(1).max(MAX_TEXT),
272
+ images: z.array(imageSchema).max(MAX_IMAGES).optional().default([]),
273
+ urgent: z.boolean().optional().default(false),
274
+ requiresHumanApproval: z.boolean().optional().default(false),
275
+ category: sharingCategorySchema.optional().default("free_text"),
276
+ approvalFields: approvalFieldsSchema.optional()
277
+ }).transform((value, ctx) => {
278
+ const roomId = resolveRoomId(value, ctx);
279
+ return {
280
+ roomId,
281
+ text: value.text,
282
+ images: value.images,
283
+ urgent: value.urgent,
284
+ requiresHumanApproval: value.requiresHumanApproval,
285
+ category: value.category,
286
+ ...value.approvalFields !== void 0 ? { approvalFields: value.approvalFields } : {}
287
+ };
288
+ });
289
+ var setSharingRuleSchema = z.object({
290
+ peerBotId: z.string().uuid().nullable(),
291
+ category: sharingCategorySchema.refine((c) => c !== COMMIT_CATEGORY, "commit always waits for the human's confirmation: no rule can change it"),
292
+ decision: z.enum([...SHARING_DECISIONS, "inherit"])
293
+ });
294
+ var setSensitiveSchema = z.object({
295
+ peerBotId: z.string().uuid(),
296
+ sensitive: z.boolean()
297
+ });
298
+ var heldMessageSchema = z.object({
299
+ messageId: z.string().uuid()
300
+ });
301
+ var adminOAuthClientDeleteSchema = z.object({
302
+ clientId: z.string().min(1).max(200)
303
+ });
304
+ var adminRecoverSchema = z.object({
305
+ humanId: z.string().regex(/^[A-Za-z0-9_-]{1,64}$/, "humanId is an account id").optional(),
306
+ botId: z.string().uuid().optional()
307
+ }).refine((v) => v.humanId === void 0 !== (v.botId === void 0), "Give exactly one of humanId and botId");
308
+ var adminTestAccountSchema = z.object({
309
+ humanId: z.string().regex(/^[A-Za-z0-9_-]{1,64}$/, "humanId is an account id").optional(),
310
+ botId: z.string().uuid().optional(),
311
+ test: z.boolean()
312
+ }).refine((v) => v.humanId === void 0 !== (v.botId === void 0), "Give exactly one of humanId and botId");
313
+ var displayNameSchema = singleLine(80);
314
+ var BOT_NAME_MAX = 60;
315
+ var botNameSchema = singleLine(BOT_NAME_MAX).refine((v) => !/[\u2028\u2029]/.test(v), "A bot name is one line").refine((v) => !/[<>]/.test(v), "A bot name cannot contain < or >");
316
+ var humanEmailSchema = z.object({
317
+ address: emailAddressSchema
318
+ });
319
+ var readMessagesSchema = z.object({
320
+ markRead: z.boolean().optional().default(true),
321
+ limit: z.number().int().min(1).max(100).optional().default(50)
322
+ });
323
+
324
+ // packages/shared/dist/share.js
325
+ var SHARE_CATEGORIES = [
326
+ "availability",
327
+ "finance",
328
+ "health",
329
+ "contact_details",
330
+ "location",
331
+ "documents",
332
+ "preferences"
333
+ ];
334
+ var SHARE_TITLE_MAX = 80;
335
+ var FINANCE_KINDS = ["amount", "budget", "bank_details", "invoice", "other"];
336
+ var HEALTH_KINDS = ["allergy", "medication", "condition", "appointment", "vaccination", "other"];
337
+ var HEALTH_SEVERITIES = ["low", "medium", "high"];
338
+ function shareSchemas(z4) {
339
+ const line2 = (max) => z4.string().trim().min(1).max(max).regex(/^[^\r\n<>]+$/, "One line, no angle brackets");
340
+ const text = (max) => z4.string().trim().min(1).max(max).regex(/^[^<>]+$/, "No angle brackets");
341
+ const title = line2(SHARE_TITLE_MAX).describe("A short label the owner reads on the hold screen: Allergy note, Home address. Not the data itself.");
342
+ const isoDateTime = z4.string().datetime({ offset: true });
343
+ const currency2 = z4.string().regex(/^[A-Z]{3}$/, "ISO 4217, three upper-case letters");
344
+ const atLeastOne = (fields) => (v) => fields.some((f) => v[f] !== void 0);
345
+ const availability = z4.object({
346
+ title,
347
+ timeZone: line2(64).optional().describe("IANA time zone, e.g. Europe/Paris"),
348
+ free: z4.array(z4.object({ from: isoDateTime, to: isoDateTime }).strict()).min(1).max(50).describe("Free windows, ISO 8601 with offset")
349
+ }).strict().refine((v) => v.free.every((w) => Date.parse(w.from) < Date.parse(w.to)), {
350
+ message: "Each window starts before it ends",
351
+ path: ["free"]
352
+ });
353
+ const finance = z4.object({
354
+ title,
355
+ kind: z4.enum(FINANCE_KINDS),
356
+ amount: z4.object({ value: z4.number().nonnegative().max(1e12), currency: currency2 }).strict().optional(),
357
+ iban: z4.string().transform((s) => s.replace(/\s+/g, "").toUpperCase()).pipe(z4.string().regex(/^[A-Z]{2}[0-9]{2}[A-Z0-9]{10,30}$/, "An IBAN")).optional(),
358
+ reference: line2(120).optional(),
359
+ note: text(500).optional()
360
+ }).strict().refine(atLeastOne(["amount", "iban", "reference", "note"]), { message: "Give an amount, an iban, a reference or a note" });
361
+ const health = z4.object({
362
+ title,
363
+ kind: z4.enum(HEALTH_KINDS),
364
+ subject: line2(80).optional().describe("Whom it is about, e.g. Lily"),
365
+ details: text(1e3),
366
+ severity: z4.enum(HEALTH_SEVERITIES).optional()
367
+ }).strict();
368
+ const contactDetails = z4.object({
369
+ title,
370
+ name: line2(120).optional(),
371
+ email: z4.string().trim().email().max(254).optional(),
372
+ phone: z4.string().trim().regex(/^\+?[0-9][0-9 ().-]{5,24}$/, "A phone number").optional(),
373
+ address: text(300).optional(),
374
+ handle: line2(64).optional()
375
+ }).strict().refine(atLeastOne(["email", "phone", "address", "handle"]), { message: "Give an email, a phone, an address or a handle" });
376
+ const location = z4.object({
377
+ title,
378
+ place: line2(200).optional(),
379
+ address: text(300).optional(),
380
+ lat: z4.number().min(-90).max(90).optional(),
381
+ lng: z4.number().min(-180).max(180).optional(),
382
+ until: isoDateTime.optional().describe("Until when this holds")
383
+ }).strict().refine((v) => v.lat === void 0 === (v.lng === void 0), { message: "Give lat and lng together", path: ["lat"] }).refine(atLeastOne(["place", "address", "lat"]), { message: "Give a place, an address or lat and lng" });
384
+ const documents = z4.object({
385
+ title,
386
+ items: z4.array(z4.object({
387
+ name: line2(200),
388
+ mediaType: z4.string().regex(/^[a-z]+\/[a-z0-9.+-]+$/i, "A media type").max(100).optional(),
389
+ sizeBytes: z4.number().int().min(0).max(1e10).optional(),
390
+ sha256: z4.string().regex(/^[a-f0-9]{64}$/, "64 lower-case hex characters").optional(),
391
+ url: z4.string().url().max(2e3).startsWith("https://", "An https link").optional()
392
+ }).strict()).min(1).max(20)
393
+ }).strict();
394
+ const preferences = z4.object({
395
+ title,
396
+ items: z4.array(z4.object({ topic: line2(80), value: line2(200) }).strict()).min(1).max(30)
397
+ }).strict();
398
+ return { availability, finance, health, contact_details: contactDetails, location, documents, preferences };
399
+ }
400
+ function shareInput(z4) {
401
+ const schemas = shareSchemas(z4);
402
+ return z4.union(SHARE_CATEGORIES.map((category) => z4.object({ category: z4.literal(category), payload: schemas[category] }).strict()));
403
+ }
404
+
405
+ // packages/shared/dist/request-tools.js
406
+ var REQUEST_TYPES = ["slot", "quote", "order", "poll"];
407
+ var REQUEST_CREATE_TYPES = [...REQUEST_TYPES, "share"];
408
+ var REQUEST_ANSWERS = ["accept", "refuse", "counter", "vote"];
409
+ function requestToolInputs(z4) {
410
+ const line2 = (max) => z4.string().trim().min(1).max(max);
411
+ const slotPayload = z4.object({
412
+ when: line2(120).describe("When, as an ISO 8601 date and time with its offset: 2026-11-07T20:00+01:00. Words or a time without an offset may wait for the recipient's human."),
413
+ service: z4.string().trim().min(1).max(60).optional().describe("What it is for, in a few words: Lunch, Haircut. Nothing personal."),
414
+ partySize: z4.number().int().min(1).max(100).optional(),
415
+ place: line2(120).optional()
416
+ });
417
+ const quoteItem = z4.object({ label: line2(120), amount: line2(40).optional() });
418
+ const quotePayload = z4.object({
419
+ title: line2(120),
420
+ amount: line2(40).describe("Total, e.g. 45 EUR"),
421
+ currency: line2(12).optional(),
422
+ items: z4.array(quoteItem).max(40).optional(),
423
+ validUntil: line2(60).optional()
424
+ });
425
+ const orderItem = z4.object({
426
+ label: line2(120),
427
+ quantity: z4.number().int().min(1).max(999).optional(),
428
+ amount: line2(40).optional()
429
+ });
430
+ const orderPayload = z4.object({
431
+ title: line2(120),
432
+ items: z4.array(orderItem).min(1).max(40),
433
+ total: line2(40).optional(),
434
+ notes: line2(500).optional()
435
+ });
436
+ const pollPayload = z4.object({
437
+ question: line2(200),
438
+ options: z4.array(line2(120)).min(2).max(12),
439
+ multi: z4.boolean().optional()
440
+ });
441
+ const payload = z4.union([slotPayload, quotePayload, orderPayload, pollPayload]);
442
+ return {
443
+ request_create: {
444
+ type: z4.enum(REQUEST_CREATE_TYPES),
445
+ to: z4.string().min(2).max(64).optional().describe("@handle of the other agent: reaches it even if it is not a contact yet"),
446
+ toBotId: z4.string().uuid().optional().describe("Direct contact (use this, to, or roomId)"),
447
+ roomId: z4.string().uuid().optional().describe("Room id for a group poll or shared request"),
448
+ threadId: z4.string().min(1).max(128).nullable().optional(),
449
+ urgent: z4.boolean().optional(),
450
+ slot: slotPayload.optional(),
451
+ quote: quotePayload.optional(),
452
+ order: orderPayload.optional(),
453
+ poll: pollPayload.optional(),
454
+ share: shareInput(z4).optional().describe("For type share: { category, payload }")
455
+ },
456
+ request_answer: {
457
+ requestId: z4.string().uuid(),
458
+ answer: z4.enum(REQUEST_ANSWERS),
459
+ note: line2(500).optional(),
460
+ // Counter: same shape as create for that type.
461
+ slot: slotPayload.optional(),
462
+ quote: quotePayload.optional(),
463
+ order: orderPayload.optional(),
464
+ poll: pollPayload.optional(),
465
+ // Poll vote: one or more option labels from the poll.
466
+ vote: z4.union([line2(120), z4.array(line2(120)).min(1).max(12)]).optional()
467
+ },
468
+ request_list: {
469
+ requestId: z4.string().uuid().optional(),
470
+ peerBotId: z4.string().uuid().optional(),
471
+ roomId: z4.string().uuid().optional()
472
+ }
473
+ };
474
+ }
475
+
476
+ // packages/shared/dist/exchange-tools.js
477
+ var EXCHANGE_PAIRS = ["calendar.freebusy", "offers.list", "rate.range", "scope.ask", "contact.channel", "recommendation.ask", "preferences.ask", "message", "note", "overtable.ping", "slot", "quote"];
478
+ var ASKABLE_EXCHANGE_PAIRS = ["calendar.freebusy", "offers.list", "rate.range", "scope.ask", "contact.channel", "recommendation.ask", "preferences.ask", "message", "note"];
479
+ var DOOR_PAIRS = [
480
+ { pair: "calendar.freebusy", needs: "anonymous", askable: true },
481
+ { pair: "offers.list", needs: "anonymous", askable: true },
482
+ { pair: "scope.ask", needs: "anonymous", askable: true },
483
+ { pair: "message", needs: "anonymous", askable: true },
484
+ // Listed to agents that read the door (GET /v1/doors/:handle) when the owner's rules let visitors ask:
485
+ // recommendation.ask is closed to visitors by default (refused, not listed); preferences.ask waits for the owner.
486
+ { pair: "recommendation.ask", needs: "anonymous", askable: true },
487
+ { pair: "preferences.ask", needs: "anonymous", askable: true },
488
+ { pair: "rate.range", needs: "email_verified", askable: true },
489
+ { pair: "contact.channel", needs: "email_verified", askable: true },
490
+ { pair: "slot", needs: "email_verified", askable: true },
491
+ { pair: "quote", needs: "anonymous", askable: true }
492
+ ];
493
+ var RATE_UNITS = ["hour", "day", "project", "item", "month"];
494
+ var QUOTE_UNITS = ["hour", "day", "session", "project", "item", "month"];
495
+ var MAX_NOTE_LENGTH = 400;
496
+ var EXCHANGE_CATALOGUE = {
497
+ "calendar.freebusy": {
498
+ name: "calendar.freebusy",
499
+ category: "availability",
500
+ binding: false,
501
+ ttlMs: 10 * 60 * 1e3,
502
+ about: "When the other person is free: free windows only, read by their own agent from their own calendar, for up to 31 days.",
503
+ defaultDecision: "allow",
504
+ answers: true
505
+ },
506
+ "offers.list": {
507
+ name: "offers.list",
508
+ category: "finance",
509
+ binding: false,
510
+ ttlMs: 10 * 60 * 1e3,
511
+ about: "What the other person sells: labels and prices, as their agent lists them.",
512
+ defaultDecision: "allow",
513
+ answers: true
514
+ },
515
+ "rate.range": {
516
+ name: "rate.range",
517
+ category: "finance",
518
+ binding: false,
519
+ ttlMs: 24 * 60 * 60 * 1e3,
520
+ about: "The range the other person charges for one service. Under their floor, the answer waits for them.",
521
+ defaultDecision: "allow",
522
+ answers: true
523
+ },
524
+ "scope.ask": {
525
+ name: "scope.ask",
526
+ category: "preferences",
527
+ binding: false,
528
+ ttlMs: 24 * 60 * 60 * 1e3,
529
+ about: "Whether a need fits what the other person does: yes, partly or no, with a short note without amount or contact.",
530
+ defaultDecision: "allow",
531
+ answers: true
532
+ },
533
+ "contact.channel": {
534
+ name: "contact.channel",
535
+ category: "contact_details",
536
+ binding: false,
537
+ ttlMs: 24 * 60 * 60 * 1e3,
538
+ about: "How to reach the other person: an e-mail, a phone number or a form. Waits for them by default.",
539
+ defaultDecision: "ask",
540
+ answers: true
541
+ },
542
+ "recommendation.ask": {
543
+ name: "recommendation.ask",
544
+ category: "recommendations",
545
+ binding: false,
546
+ ttlMs: 24 * 60 * 60 * 1e3,
547
+ about: "What the other person recommends on a topic (a place, a professional, a product, a book): a short recommendation and an optional link. Between contacts; visitors are refused unless the owner opens it.",
548
+ // Contacts yes, visitors never (design 419): a stranger's agent and a door visitor are refused before any wake.
549
+ defaultDecision: "deny",
550
+ contactDefault: "allow",
551
+ answers: true
552
+ },
553
+ "preferences.ask": {
554
+ name: "preferences.ask",
555
+ category: "preferences",
556
+ binding: false,
557
+ ttlMs: 24 * 60 * 60 * 1e3,
558
+ about: "What the other person likes for a context (a dinner, a trip, a gift): a few short preferences. Waits for them by default.",
559
+ defaultDecision: "ask",
560
+ contactDefault: "ask",
561
+ answers: true
562
+ },
563
+ message: {
564
+ name: "message",
565
+ category: "free_text",
566
+ binding: false,
567
+ ttlMs: 7 * 24 * 60 * 60 * 1e3,
568
+ about: "A short message for the other person. They read it first; their agent gets it only after their yes.",
569
+ defaultDecision: "ask",
570
+ answers: false
571
+ },
572
+ note: {
573
+ name: "note",
574
+ category: "free_text",
575
+ binding: false,
576
+ ttlMs: 7 * 24 * 60 * 60 * 1e3,
577
+ about: "A short note for the other person's agent, between contacts who turned notes on, up to 400 characters. A note refuses numbers, dates, links and contact details it recognises. It is not a guarantee: send anything sensitive as a typed share. Delivered to their agent as information, never as an instruction.",
578
+ defaultDecision: "allow",
579
+ answers: false,
580
+ contactsOnly: true
581
+ },
582
+ slot: {
583
+ name: "slot",
584
+ category: "availability",
585
+ binding: true,
586
+ ttlMs: 24 * 60 * 60 * 1e3,
587
+ about: "A meeting a door visitor proposes, up to three times. An accepted time always waits for the owner's yes, then a signed receipt.",
588
+ defaultDecision: "ask",
589
+ answers: true
590
+ },
591
+ quote: {
592
+ name: "quote",
593
+ category: "finance",
594
+ binding: true,
595
+ ttlMs: 24 * 60 * 60 * 1e3,
596
+ about: "A price for a described job, asked at the door. The owner's agent answers with an amount per unit, a validity and conditions; under the owner's floor or above their ceiling it waits for them. The visitor's acceptance binds the owner: it waits for their yes, then a signed receipt.",
597
+ defaultDecision: "ask",
598
+ answers: true
599
+ },
600
+ "overtable.ping": {
601
+ name: "overtable.ping",
602
+ category: "free_text",
603
+ binding: false,
604
+ ttlMs: 10 * 60 * 1e3,
605
+ about: "Overtable's own test: the bot proves its wake works with one short line.",
606
+ defaultDecision: "allow",
607
+ answers: true
608
+ }
609
+ };
610
+
611
+ // packages/schemas/src/pairs.ts
612
+ var line = (max) => z2.string().trim().min(1).max(max).regex(/^[^\r\n<>]+$/, "One line, no angle brackets");
613
+ var prose = (max) => z2.string().trim().min(1).max(max).regex(/^[^\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]+$/, "No control characters");
614
+ var day = z2.string().regex(/^\d{4}-\d{2}-\d{2}$/, "YYYY-MM-DD");
615
+ var instant = z2.string().min(10).max(40).refine((s) => !Number.isNaN(Date.parse(s)), "ISO 8601 date-time");
616
+ var currency = z2.string().regex(/^[A-Z]{3}$/, "ISO 4217 code, upper case");
617
+ var money = z2.union([
618
+ z2.string().regex(/^\d{1,9}(?:[.,]\d{1,2})?$/, "An amount such as 450 or 450.50"),
619
+ z2.number().nonnegative().finite().max(999999999)
620
+ ]);
621
+ var MAX_FREEBUSY_DAYS = 31;
622
+ var MAX_NEED = 500;
623
+ var MAX_MESSAGE = 2e3;
624
+ var MAX_SLOT_TIMES = 3;
625
+ var MAX_QUOTE_QUANTITY = 1e4;
626
+ var MAX_RECOMMENDATION = 500;
627
+ var MAX_PREFERENCES = 10;
628
+ function validZone(zone) {
629
+ try {
630
+ new Intl.DateTimeFormat("en-GB", { timeZone: zone });
631
+ return true;
632
+ } catch {
633
+ return false;
634
+ }
635
+ }
636
+ var freebusyAsk = z2.object({
637
+ from: day,
638
+ to: day,
639
+ granularity: z2.enum(["day", "hour"]).optional(),
640
+ timeZone: z2.string().min(1).max(64).optional()
641
+ }).superRefine((v, ctx) => {
642
+ const span = (Date.parse(v.to) - Date.parse(v.from)) / 864e5;
643
+ if (Number.isNaN(span) || span < 0) ctx.addIssue({ code: z2.ZodIssueCode.custom, message: "to must be on or after from" });
644
+ if (span > MAX_FREEBUSY_DAYS) ctx.addIssue({ code: z2.ZodIssueCode.custom, message: `At most ${MAX_FREEBUSY_DAYS} days` });
645
+ if (v.timeZone !== void 0 && !validZone(v.timeZone)) ctx.addIssue({ code: z2.ZodIssueCode.custom, message: "Unknown timeZone" });
646
+ });
647
+ var freebusyAnswer = z2.object({
648
+ timeZone: z2.string().min(1).max(64),
649
+ free: z2.array(z2.object({ from: instant, to: instant }).strict()).max(50)
650
+ }).strict().superRefine((v, ctx) => {
651
+ if (!validZone(v.timeZone)) ctx.addIssue({ code: z2.ZodIssueCode.custom, message: "Unknown timeZone" });
652
+ for (const [i, w] of v.free.entries()) {
653
+ if (Date.parse(w.to) <= Date.parse(w.from)) ctx.addIssue({ code: z2.ZodIssueCode.custom, message: `free[${i}]: to must be after from` });
654
+ }
655
+ });
656
+ var offersAnswer = z2.object({
657
+ currency,
658
+ items: z2.array(z2.object({ id: line(64), label: line(120), amount: money, unit: line(40).optional(), conditions: line(300).optional() }).strict()).max(50)
659
+ }).strict();
660
+ var rateAnswer = z2.object({ currency, min: money, max: money, unit: z2.enum(RATE_UNITS), conditions: line(300).optional() }).strict();
661
+ var scopeAnswer = z2.object({ fit: z2.enum(["yes", "partly", "no"]), note: line(300).optional() }).strict();
662
+ var channelAnswer = z2.object({ channel: z2.enum(["email", "phone", "form"]), value: line(200) }).strict().superRefine((v, ctx) => {
663
+ const ok = v.channel === "email" ? /^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]{2,}$/.test(v.value) : v.channel === "phone" ? /^\+?[\d\s().-]{6,24}$/.test(v.value) && v.value.replace(/\D/g, "").length >= 6 : /^https:\/\/[^\s<>]+$/.test(v.value);
664
+ if (!ok) ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["value"], message: `value is not a valid ${v.channel === "form" ? "https form URL" : v.channel}` });
665
+ });
666
+ var slotAsk = z2.object({
667
+ propose: z2.array(z2.object({ when: instant }).strict()).min(1).max(MAX_SLOT_TIMES),
668
+ durationMinutes: z2.number().int().min(5).max(8 * 60).optional()
669
+ }).strict();
670
+ var slotAnswer = z2.union([
671
+ z2.object({ accept: z2.number().int().min(0).max(MAX_SLOT_TIMES - 1) }).strict(),
672
+ z2.object({ counter: z2.object({ when: instant }).strict() }).strict()
673
+ ]);
674
+ var quoteRequest = z2.object({
675
+ service: line(120),
676
+ need: prose(MAX_NEED),
677
+ budget: z2.object({ amount: money, currency }).strict().optional(),
678
+ dates: z2.object({ from: day, to: day.optional() }).strict().refine((d) => !d.to || d.to >= d.from, "dates.to must be on or after dates.from").optional()
679
+ }).strict();
680
+ var quoteAsk = z2.union([quoteRequest, z2.object({ accept: z2.literal(true) }).strict()]);
681
+ var quoteAnswer = z2.object({
682
+ amount: money,
683
+ currency,
684
+ unit: z2.enum(QUOTE_UNITS),
685
+ quantity: z2.number().positive().max(MAX_QUOTE_QUANTITY).refine((q) => Math.abs(q * 100 - Math.round(q * 100)) < 1e-6, "quantity: at most two decimals").optional(),
686
+ validUntil: day,
687
+ conditions: line(300).optional()
688
+ }).strict();
689
+ var httpsLink = z2.string().trim().max(500).refine((s) => {
690
+ try {
691
+ const u = new URL(s);
692
+ return u.protocol === "https:" && !u.username && !u.password && u.hostname.includes(".");
693
+ } catch {
694
+ return false;
695
+ }
696
+ }, "link: an https URL");
697
+ var recommendationAnswer = z2.object({ recommendation: line(MAX_RECOMMENDATION), link: httpsLink.optional() }).strict();
698
+ var preferencesAnswer = z2.object({ preferences: z2.array(line(200)).min(1).max(MAX_PREFERENCES) }).strict();
699
+ var noteAsk = z2.object({ text: prose(4e3) }).strict();
700
+ var PAIR_SCHEMAS = {
701
+ "calendar.freebusy": { ask: freebusyAsk, answer: freebusyAnswer },
702
+ "offers.list": { ask: z2.object({ query: line(200).optional() }).strict(), answer: offersAnswer },
703
+ "rate.range": { ask: z2.object({ service: line(200) }).strict(), answer: rateAnswer },
704
+ "scope.ask": { ask: z2.object({ need: prose(MAX_NEED) }).strict(), answer: scopeAnswer },
705
+ "contact.channel": { ask: z2.object({}).strict(), answer: channelAnswer },
706
+ "recommendation.ask": { ask: z2.object({ topic: line(200) }).strict(), answer: recommendationAnswer },
707
+ "preferences.ask": { ask: z2.object({ context: line(200) }).strict(), answer: preferencesAnswer },
708
+ message: { ask: z2.object({ text: prose(MAX_MESSAGE) }).strict(), answer: z2.object({}).strict() },
709
+ note: { ask: noteAsk, answer: z2.object({}).strict() },
710
+ "overtable.ping": { ask: z2.object({}).strict(), answer: z2.object({ reply: line(300) }).strict() },
711
+ slot: { ask: slotAsk, answer: slotAnswer },
712
+ quote: { ask: quoteAsk, answer: quoteAnswer }
713
+ };
714
+ function pairSchema(pair) {
715
+ return EXCHANGE_PAIRS.includes(pair) ? PAIR_SCHEMAS[pair] : void 0;
716
+ }
717
+
718
+ // packages/schemas/src/requests.ts
719
+ import { z as z3 } from "zod";
720
+ var inputs = requestToolInputs(z3);
721
+ var REQUEST_PAYLOAD_SCHEMAS = Object.fromEntries(
722
+ REQUEST_TYPES.map((type) => [type, inputs.request_create[type].unwrap()])
723
+ );
724
+ var SHARE_SCHEMAS = shareSchemas(z3);
725
+ var SHARE_INPUT_SCHEMA = shareInput(z3);
726
+ var REQUEST_CREATE_SCHEMA = z3.object(inputs.request_create);
727
+ var REQUEST_ANSWER_SCHEMA = z3.object(requestToolInputs(z3).request_answer);
728
+ export {
729
+ ASKABLE_EXCHANGE_PAIRS,
730
+ DOOR_PAIRS,
731
+ EXCHANGE_CATALOGUE,
732
+ EXCHANGE_PAIRS,
733
+ FINANCE_KINDS,
734
+ HEALTH_KINDS,
735
+ HEALTH_SEVERITIES,
736
+ MAX_FREEBUSY_DAYS,
737
+ MAX_MESSAGE,
738
+ MAX_NEED,
739
+ MAX_NOTE_LENGTH,
740
+ MAX_PREFERENCES,
741
+ MAX_QUOTE_QUANTITY,
742
+ MAX_RECOMMENDATION,
743
+ MAX_SLOT_TIMES,
744
+ PAIR_SCHEMAS,
745
+ QUOTE_UNITS,
746
+ RATE_UNITS,
747
+ REQUEST_ANSWERS,
748
+ REQUEST_ANSWER_SCHEMA,
749
+ REQUEST_CREATE_SCHEMA,
750
+ REQUEST_CREATE_TYPES,
751
+ REQUEST_PAYLOAD_SCHEMAS,
752
+ REQUEST_TYPES,
753
+ SHARE_CATEGORIES,
754
+ SHARE_INPUT_SCHEMA,
755
+ SHARE_SCHEMAS,
756
+ SHARE_TITLE_MAX,
757
+ SHARING_CATEGORIES,
758
+ pairSchema
759
+ };