robotrock 0.8.1 → 0.8.4

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.
@@ -1,10 +1,187 @@
1
1
  // src/schemas/index.ts
2
+ import { z as z2 } from "zod";
3
+
4
+ // ../core/src/utils/safe-url.ts
5
+ var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
6
+ "localhost",
7
+ "metadata.google.internal",
8
+ "metadata.goog"
9
+ ]);
10
+ function normalizeHostname(hostname) {
11
+ return hostname.toLowerCase().replace(/^\[|\]$/g, "");
12
+ }
13
+ function isBlockedIpv4(host) {
14
+ const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
15
+ if (!match) {
16
+ return false;
17
+ }
18
+ const octets = match.slice(1, 5).map((part) => Number(part));
19
+ if (octets.some((octet) => Number.isNaN(octet) || octet < 0 || octet > 255)) {
20
+ return true;
21
+ }
22
+ const [a, b, _c, _d] = octets;
23
+ if (a === void 0 || b === void 0) {
24
+ return true;
25
+ }
26
+ if (a === 127 || a === 0) return true;
27
+ if (a === 10) return true;
28
+ if (a === 169 && b === 254) return true;
29
+ if (a === 192 && b === 168) return true;
30
+ if (a === 172 && b >= 16 && b <= 31) return true;
31
+ if (a === 100 && b >= 64 && b <= 127) return true;
32
+ return false;
33
+ }
34
+ function ipv4FromNumericHost(host) {
35
+ if (/^\d+$/.test(host)) {
36
+ const num = Number(host);
37
+ if (!Number.isFinite(num) || num < 0 || num > 4294967295) {
38
+ return null;
39
+ }
40
+ const a = num >>> 24 & 255;
41
+ const b = num >>> 16 & 255;
42
+ const c = num >>> 8 & 255;
43
+ const d = num & 255;
44
+ return `${a}.${b}.${c}.${d}`;
45
+ }
46
+ const hexMatch = /^0x([0-9a-f]{1,8})$/i.exec(host);
47
+ if (hexMatch) {
48
+ const num = Number.parseInt(hexMatch[1], 16);
49
+ if (!Number.isFinite(num) || num < 0 || num > 4294967295) {
50
+ return null;
51
+ }
52
+ const a = num >>> 24 & 255;
53
+ const b = num >>> 16 & 255;
54
+ const c = num >>> 8 & 255;
55
+ const d = num & 255;
56
+ return `${a}.${b}.${c}.${d}`;
57
+ }
58
+ return null;
59
+ }
60
+ function isBlockedIpv4Mapped(host) {
61
+ const mappedDotted = /^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/i.exec(host);
62
+ if (mappedDotted) {
63
+ return isBlockedIpv4(mappedDotted[1]);
64
+ }
65
+ const mappedHex = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(host);
66
+ if (mappedHex) {
67
+ const high = Number.parseInt(mappedHex[1], 16);
68
+ const low = Number.parseInt(mappedHex[2], 16);
69
+ if (Number.isFinite(high) && Number.isFinite(low)) {
70
+ const a = high >> 8 & 255;
71
+ const b = high & 255;
72
+ const c = low >> 8 & 255;
73
+ const d = low & 255;
74
+ return isBlockedIpv4(`${a}.${b}.${c}.${d}`);
75
+ }
76
+ }
77
+ return false;
78
+ }
79
+ function isBlockedIpv6(host) {
80
+ if (host === "::1" || host === "0:0:0:0:0:0:0:1") {
81
+ return true;
82
+ }
83
+ if (host.startsWith("fc") || host.startsWith("fd")) {
84
+ return true;
85
+ }
86
+ if (host.startsWith("fe80:")) {
87
+ return true;
88
+ }
89
+ if (isBlockedIpv4Mapped(host)) {
90
+ return true;
91
+ }
92
+ return false;
93
+ }
94
+ function isBlockedHostname(hostname) {
95
+ const host = normalizeHostname(hostname);
96
+ if (!host) {
97
+ return true;
98
+ }
99
+ if (BLOCKED_HOSTNAMES.has(host)) {
100
+ return true;
101
+ }
102
+ if (host.endsWith(".localhost") || host.endsWith(".local")) {
103
+ return true;
104
+ }
105
+ const numericIpv4 = ipv4FromNumericHost(host);
106
+ if (numericIpv4 && isBlockedIpv4(numericIpv4)) {
107
+ return true;
108
+ }
109
+ return isBlockedIpv4(host) || isBlockedIpv6(host);
110
+ }
111
+ function isPublicHttpUrl(urlString) {
112
+ let url;
113
+ try {
114
+ url = new URL(urlString);
115
+ } catch {
116
+ return false;
117
+ }
118
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
119
+ return false;
120
+ }
121
+ if (url.username || url.password) {
122
+ return false;
123
+ }
124
+ return !isBlockedHostname(url.hostname);
125
+ }
126
+ var PUBLIC_HTTP_URL_ERROR = "URL must be a public http:// or https:// address";
127
+
128
+ // ../core/src/schemas/task.ts
2
129
  import { z } from "zod";
3
- import {
4
- isPublicHttpUrl,
5
- PUBLIC_HTTP_URL_ERROR
6
- } from "@robotrock/core/utils";
7
- import { validateContextPublicUrls } from "@robotrock/core/schemas";
130
+
131
+ // ../core/src/schemas/context-urls.ts
132
+ function resolveLinkUrl(value) {
133
+ return value.startsWith("http://") || value.startsWith("https://") ? value : `https://${value}`;
134
+ }
135
+ function widgetType(ui, field) {
136
+ const fieldUi = ui?.[field];
137
+ if (typeof fieldUi !== "object" || fieldUi === null) {
138
+ return void 0;
139
+ }
140
+ const widget = fieldUi["ui:widget"];
141
+ return typeof widget === "string" ? widget : void 0;
142
+ }
143
+ function validateUrlValue(value, widget) {
144
+ if (widget === "image" || widget === "link") {
145
+ if (typeof value !== "string") {
146
+ return PUBLIC_HTTP_URL_ERROR;
147
+ }
148
+ const url = widget === "link" ? resolveLinkUrl(value) : value;
149
+ if (!isPublicHttpUrl(url)) {
150
+ return PUBLIC_HTTP_URL_ERROR;
151
+ }
152
+ return null;
153
+ }
154
+ if (widget === "attachments" && Array.isArray(value)) {
155
+ for (const item of value) {
156
+ if (typeof item !== "object" || item === null) {
157
+ continue;
158
+ }
159
+ const url = item.url;
160
+ if (typeof url === "string" && !isPublicHttpUrl(resolveLinkUrl(url))) {
161
+ return PUBLIC_HTTP_URL_ERROR;
162
+ }
163
+ }
164
+ }
165
+ return null;
166
+ }
167
+ function validateContextPublicUrls(context) {
168
+ if (!context?.data) {
169
+ return null;
170
+ }
171
+ for (const [field, value] of Object.entries(context.data)) {
172
+ const widget = widgetType(context.ui, field);
173
+ if (!widget) {
174
+ continue;
175
+ }
176
+ const error = validateUrlValue(value, widget);
177
+ if (error) {
178
+ return `context.data.${field}: ${error}`;
179
+ }
180
+ }
181
+ return null;
182
+ }
183
+
184
+ // ../core/src/schemas/task.ts
8
185
  var safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {
9
186
  message: PUBLIC_HTTP_URL_ERROR
10
187
  });
@@ -32,6 +209,7 @@ var taskActionSchema = z.object({
32
209
  schema: jsonSchema7Schema.optional(),
33
210
  ui: uiSchemaSchema.optional(),
34
211
  data: z.record(z.string(), z.unknown()).optional(),
212
+ // Optional handlers for this action - if present, must have at least 1
35
213
  handlers: z.array(handlerSchema).min(1).optional()
36
214
  });
37
215
  var uiFieldSchemaSchema = z.object({
@@ -47,6 +225,7 @@ var contextDataSchema = z.object({
47
225
  ui: contextUiSchema
48
226
  }).optional();
49
227
  var taskContextObjectSchema = z.object({
228
+ /** Source application id; omitted tasks are grouped in the default inbox. */
50
229
  app: z.string().min(1).optional(),
51
230
  type: z.string().min(1),
52
231
  name: z.string().min(1),
@@ -93,21 +272,12 @@ var threadUpdateStatuses = [
93
272
  "cancelled"
94
273
  ];
95
274
  var threadUpdateStatusSchema = z.enum(threadUpdateStatuses);
96
- var DEFAULT_THREAD_UPDATE_STATUS = "info";
97
275
  var threadUpdateInputSchema = z.object({
98
276
  message: threadUpdateMessageSchema,
99
277
  status: threadUpdateStatusSchema.optional()
100
278
  });
101
279
  var taskPriorities = ["low", "normal", "high", "urgent"];
102
280
  var taskPrioritySchema = z.enum(taskPriorities);
103
- var DEFAULT_TASK_PRIORITY = "normal";
104
- var LOWEST_TASK_PRIORITY = "low";
105
- var TASK_PRIORITY_RANK = {
106
- low: 1,
107
- normal: 2,
108
- high: 3,
109
- urgent: 4
110
- };
111
281
  var nonNegativeInt = z.number().int().nonnegative();
112
282
  var agentCostTokensSchema = z.object({
113
283
  input: nonNegativeInt.optional(),
@@ -120,17 +290,47 @@ var agentCostSchema = z.object({
120
290
  usd: z.number().nonnegative().optional()
121
291
  });
122
292
  var AGENT_INFO_MAX_KEYS = 32;
293
+ var AGENT_TOOL_CALLS_MAX_KEYS = 64;
294
+ var AGENT_OTEL_SPANS_MAX = 32;
295
+ var agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);
296
+ var agentOtelSpanStatusSchema = z.enum(["ok", "error"]);
297
+ var agentOtelSpanSummarySchema = z.object({
298
+ name: z.string().min(1),
299
+ durationMs: z.number().nonnegative(),
300
+ status: agentOtelSpanStatusSchema
301
+ });
302
+ var agentOtelSchema = z.object({
303
+ traceId: z.string().min(1),
304
+ spanId: z.string().min(1).optional(),
305
+ rootDurationMs: z.number().nonnegative().optional(),
306
+ spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional()
307
+ });
123
308
  var agentTelemetrySchema = z.object({
309
+ /** Agent or app version (semver, git SHA, deploy tag — caller-defined). */
124
310
  version: z.string().min(1).optional(),
311
+ /** Total tool invocations. When omitted but `toolCalls` is set, the sum of counts is used. */
125
312
  toolCallCount: nonNegativeInt.optional(),
313
+ /** Per-tool invocation counts keyed by tool name. */
314
+ toolCalls: agentToolCallsSchema.optional(),
126
315
  cost: agentCostSchema.optional(),
127
- info: z.record(z.string(), z.unknown()).optional()
316
+ /** Free-form metadata for experiments (model, prompt variant, etc.). */
317
+ info: z.record(z.string(), z.unknown()).optional(),
318
+ /** Structured OpenTelemetry span snapshot for feedback analysis. */
319
+ otel: agentOtelSchema.optional()
128
320
  }).refine(
129
321
  (data) => {
130
322
  const keys = data.info ? Object.keys(data.info) : [];
131
323
  return keys.length <= AGENT_INFO_MAX_KEYS;
132
324
  },
133
325
  { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }
326
+ ).refine(
327
+ (data) => {
328
+ const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];
329
+ return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;
330
+ },
331
+ {
332
+ message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`
333
+ }
134
334
  );
135
335
  var createTaskBodySchema = taskContextObjectSchema.extend({
136
336
  assignTo: assignToSchema.optional(),
@@ -149,26 +349,205 @@ var createTaskBodySchema = taskContextObjectSchema.extend({
149
349
  * the inbox status bar and the thread update log.
150
350
  */
151
351
  update: threadUpdateInputSchema.optional(),
352
+ /** Agent telemetry (version, cost, tool calls) — not shown in inbox UI. */
152
353
  agent: agentTelemetrySchema.optional()
153
354
  }).superRefine(refineContextPublicUrls);
154
- var threadUpdateBodySchema = threadUpdateInputSchema;
355
+
356
+ // src/schemas/index.ts
357
+ var safeUrlSchema2 = z2.string().refine((url) => isPublicHttpUrl(url), {
358
+ message: PUBLIC_HTTP_URL_ERROR
359
+ });
360
+ var jsonSchema7Schema2 = z2.custom(
361
+ (val) => typeof val === "object" && val !== null,
362
+ { message: "Must be a valid JSON Schema object" }
363
+ );
364
+ var uiSchemaSchema2 = z2.custom((val) => typeof val === "object" && val !== null, {
365
+ message: "Must be a valid UiSchema object"
366
+ });
367
+ var webhookHandlerSchema2 = z2.object({
368
+ type: z2.literal("webhook"),
369
+ url: safeUrlSchema2,
370
+ headers: z2.record(z2.string(), z2.string())
371
+ });
372
+ var triggerHandlerSchema2 = webhookHandlerSchema2.extend({
373
+ type: z2.literal("trigger"),
374
+ tokenId: z2.string().min(1)
375
+ });
376
+ var handlerSchema2 = z2.discriminatedUnion("type", [webhookHandlerSchema2, triggerHandlerSchema2]);
377
+ var taskActionSchema2 = z2.object({
378
+ id: z2.string().min(1),
379
+ title: z2.string().min(1),
380
+ description: z2.string().optional(),
381
+ schema: jsonSchema7Schema2.optional(),
382
+ ui: uiSchemaSchema2.optional(),
383
+ data: z2.record(z2.string(), z2.unknown()).optional(),
384
+ handlers: z2.array(handlerSchema2).min(1).optional()
385
+ });
386
+ var uiFieldSchemaSchema2 = z2.object({
387
+ "ui:widget": z2.string().optional(),
388
+ "ui:title": z2.string().optional(),
389
+ "ui:description": z2.string().optional(),
390
+ "ui:options": z2.record(z2.string(), z2.unknown()).optional(),
391
+ items: z2.lazy(() => z2.record(z2.string(), uiFieldSchemaSchema2)).optional()
392
+ }).passthrough();
393
+ var contextUiSchema2 = z2.record(z2.string(), uiFieldSchemaSchema2).optional();
394
+ var contextDataSchema2 = z2.object({
395
+ data: z2.record(z2.string(), z2.unknown()),
396
+ ui: contextUiSchema2
397
+ }).optional();
398
+ var taskContextObjectSchema2 = z2.object({
399
+ app: z2.string().min(1).optional(),
400
+ type: z2.string().min(1),
401
+ name: z2.string().min(1),
402
+ description: z2.string().optional(),
403
+ validUntil: z2.string().optional(),
404
+ context: contextDataSchema2,
405
+ version: z2.literal(2).optional(),
406
+ actions: z2.array(taskActionSchema2).min(1, "At least one action is required")
407
+ });
408
+ function refineContextPublicUrls2(data, ctx) {
409
+ const error = validateContextPublicUrls(data.context);
410
+ if (error) {
411
+ ctx.addIssue({
412
+ code: z2.ZodIssueCode.custom,
413
+ message: error,
414
+ path: ["context"]
415
+ });
416
+ }
417
+ }
418
+ var taskContextSchema2 = taskContextObjectSchema2.superRefine(
419
+ refineContextPublicUrls2
420
+ );
421
+ var assignToSchema2 = z2.object({
422
+ users: z2.array(z2.string().email()).optional(),
423
+ groups: z2.array(z2.string().min(1)).optional()
424
+ }).refine(
425
+ (data) => {
426
+ const groups = data.groups ?? [];
427
+ if (groups.includes("all") && groups.length > 1) {
428
+ return false;
429
+ }
430
+ return true;
431
+ },
432
+ { message: 'Cannot combine "all" with other group slugs' }
433
+ );
434
+ var threadUpdateMessageSchema2 = z2.string().min(1).max(500);
435
+ var threadUpdateStatuses2 = [
436
+ "info",
437
+ "queued",
438
+ "running",
439
+ "waiting",
440
+ "succeeded",
441
+ "failed",
442
+ "cancelled"
443
+ ];
444
+ var threadUpdateStatusSchema2 = z2.enum(threadUpdateStatuses2);
445
+ var DEFAULT_THREAD_UPDATE_STATUS = "info";
446
+ var threadUpdateInputSchema2 = z2.object({
447
+ message: threadUpdateMessageSchema2,
448
+ status: threadUpdateStatusSchema2.optional()
449
+ });
450
+ var taskPriorities2 = ["low", "normal", "high", "urgent"];
451
+ var taskPrioritySchema2 = z2.enum(taskPriorities2);
452
+ var DEFAULT_TASK_PRIORITY = "normal";
453
+ var LOWEST_TASK_PRIORITY = "low";
454
+ var TASK_PRIORITY_RANK = {
455
+ low: 1,
456
+ normal: 2,
457
+ high: 3,
458
+ urgent: 4
459
+ };
460
+ var nonNegativeInt2 = z2.number().int().nonnegative();
461
+ var agentCostTokensSchema2 = z2.object({
462
+ input: nonNegativeInt2.optional(),
463
+ output: nonNegativeInt2.optional(),
464
+ total: nonNegativeInt2.optional()
465
+ });
466
+ var agentCostSchema2 = z2.object({
467
+ tokens: agentCostTokensSchema2.optional(),
468
+ eur: z2.number().nonnegative().optional(),
469
+ usd: z2.number().nonnegative().optional()
470
+ });
471
+ var AGENT_INFO_MAX_KEYS2 = 32;
472
+ var AGENT_TOOL_CALLS_MAX_KEYS2 = 64;
473
+ var AGENT_OTEL_SPANS_MAX2 = 32;
474
+ var agentToolCallsSchema2 = z2.record(z2.string().min(1), nonNegativeInt2);
475
+ var agentOtelSpanStatusSchema2 = z2.enum(["ok", "error"]);
476
+ var agentOtelSpanSummarySchema2 = z2.object({
477
+ name: z2.string().min(1),
478
+ durationMs: z2.number().nonnegative(),
479
+ status: agentOtelSpanStatusSchema2
480
+ });
481
+ var agentOtelSchema2 = z2.object({
482
+ traceId: z2.string().min(1),
483
+ spanId: z2.string().min(1).optional(),
484
+ rootDurationMs: z2.number().nonnegative().optional(),
485
+ spans: z2.array(agentOtelSpanSummarySchema2).max(AGENT_OTEL_SPANS_MAX2).optional()
486
+ });
487
+ var agentTelemetrySchema2 = z2.object({
488
+ version: z2.string().min(1).optional(),
489
+ toolCallCount: nonNegativeInt2.optional(),
490
+ toolCalls: agentToolCallsSchema2.optional(),
491
+ cost: agentCostSchema2.optional(),
492
+ info: z2.record(z2.string(), z2.unknown()).optional(),
493
+ otel: agentOtelSchema2.optional()
494
+ }).refine(
495
+ (data) => {
496
+ const keys = data.info ? Object.keys(data.info) : [];
497
+ return keys.length <= AGENT_INFO_MAX_KEYS2;
498
+ },
499
+ { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS2} keys` }
500
+ ).refine(
501
+ (data) => {
502
+ const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];
503
+ return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS2;
504
+ },
505
+ {
506
+ message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS2} tool names`
507
+ }
508
+ );
509
+ var createTaskBodySchema2 = taskContextObjectSchema2.extend({
510
+ assignTo: assignToSchema2.optional(),
511
+ /**
512
+ * Groups related tasks together. When omitted, the server generates one and
513
+ * returns it so the caller can reuse it on later tasks in the same thread.
514
+ */
515
+ threadId: z2.string().min(1).optional(),
516
+ /**
517
+ * Optional thread priority. When set, applies to the whole thread and
518
+ * overwrites any previous priority. Omit on later tasks to leave unchanged.
519
+ */
520
+ priority: taskPrioritySchema2.optional(),
521
+ /**
522
+ * Optional initial status update logged against the task's thread. Shows in
523
+ * the inbox status bar and the thread update log.
524
+ */
525
+ update: threadUpdateInputSchema2.optional(),
526
+ agent: agentTelemetrySchema2.optional()
527
+ }).superRefine(refineContextPublicUrls2);
528
+ var threadUpdateBodySchema = threadUpdateInputSchema2;
155
529
  export {
530
+ AGENT_OTEL_SPANS_MAX2 as AGENT_OTEL_SPANS_MAX,
156
531
  DEFAULT_TASK_PRIORITY,
157
532
  DEFAULT_THREAD_UPDATE_STATUS,
158
533
  LOWEST_TASK_PRIORITY,
159
534
  TASK_PRIORITY_RANK,
160
- agentCostSchema,
161
- agentCostTokensSchema,
162
- agentTelemetrySchema,
163
- assignToSchema,
164
- createTaskBodySchema,
165
- taskContextSchema,
166
- taskPriorities,
167
- taskPrioritySchema,
535
+ agentCostSchema2 as agentCostSchema,
536
+ agentCostTokensSchema2 as agentCostTokensSchema,
537
+ agentOtelSchema2 as agentOtelSchema,
538
+ agentOtelSpanStatusSchema2 as agentOtelSpanStatusSchema,
539
+ agentOtelSpanSummarySchema2 as agentOtelSpanSummarySchema,
540
+ agentTelemetrySchema2 as agentTelemetrySchema,
541
+ agentToolCallsSchema2 as agentToolCallsSchema,
542
+ assignToSchema2 as assignToSchema,
543
+ createTaskBodySchema2 as createTaskBodySchema,
544
+ taskContextSchema2 as taskContextSchema,
545
+ taskPriorities2 as taskPriorities,
546
+ taskPrioritySchema2 as taskPrioritySchema,
168
547
  threadUpdateBodySchema,
169
- threadUpdateInputSchema,
170
- threadUpdateMessageSchema,
171
- threadUpdateStatusSchema,
172
- threadUpdateStatuses
548
+ threadUpdateInputSchema2 as threadUpdateInputSchema,
549
+ threadUpdateMessageSchema2 as threadUpdateMessageSchema,
550
+ threadUpdateStatusSchema2 as threadUpdateStatusSchema,
551
+ threadUpdateStatuses2 as threadUpdateStatuses
173
552
  };
174
553
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schemas/index.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n isPublicHttpUrl,\n PUBLIC_HTTP_URL_ERROR,\n} from \"@robotrock/core/utils\";\nimport { validateContextPublicUrls } from \"@robotrock/core/schemas\";\n\nexport interface JSONSchema7 {\n $id?: string;\n $ref?: string;\n $schema?: string;\n $comment?: string;\n type?: JSONSchema7TypeName | JSONSchema7TypeName[];\n enum?: unknown[];\n const?: unknown;\n multipleOf?: number;\n maximum?: number;\n exclusiveMaximum?: number;\n minimum?: number;\n exclusiveMinimum?: number;\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n format?: string;\n items?: JSONSchema7 | JSONSchema7[];\n additionalItems?: JSONSchema7 | boolean;\n maxItems?: number;\n minItems?: number;\n uniqueItems?: boolean;\n contains?: JSONSchema7;\n maxProperties?: number;\n minProperties?: number;\n required?: string[];\n properties?: Record<string, JSONSchema7>;\n patternProperties?: Record<string, JSONSchema7>;\n additionalProperties?: JSONSchema7 | boolean;\n dependencies?: Record<string, JSONSchema7 | string[]>;\n propertyNames?: JSONSchema7;\n if?: JSONSchema7;\n then?: JSONSchema7;\n else?: JSONSchema7;\n allOf?: JSONSchema7[];\n anyOf?: JSONSchema7[];\n oneOf?: JSONSchema7[];\n not?: JSONSchema7;\n title?: string;\n description?: string;\n default?: unknown;\n readOnly?: boolean;\n writeOnly?: boolean;\n examples?: unknown[];\n}\n\nexport type JSONSchema7TypeName =\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"null\";\n\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\nconst taskContextObjectSchema = z.object({\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\n\nexport const agentTelemetrySchema = z\n .object({\n version: z.string().min(1).optional(),\n toolCallCount: nonNegativeInt.optional(),\n cost: agentCostSchema.optional(),\n info: z.record(z.string(), z.unknown()).optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n );\n\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n\ntype InferObjectProperties<\n Props,\n Req extends PropertyKey,\n> = Props extends Record<string, unknown>\n ? ({\n [K in keyof Props as K extends Req ? K : never]-?: InferJsonSchema7<Props[K]>;\n } & {\n [K in keyof Props as K extends Req ? never : K]?: InferJsonSchema7<Props[K]>;\n } extends infer O\n ? { [K in keyof O]: O[K] }\n : never)\n : Record<string, unknown>;\n\ntype RequiredKeys<S> =\n S extends { readonly required: readonly string[] } ? S[\"required\"][number] : never;\n\nexport type InferJsonSchema7<S> = [S] extends [undefined]\n ? Record<string, never>\n : S extends { readonly const: infer C }\n ? C\n : S extends {\n readonly enum: readonly (infer E)[];\n }\n ? E\n : S extends {\n readonly type: \"object\";\n readonly properties?: infer Props;\n }\n ? InferObjectProperties<Props, RequiredKeys<S>>\n : S extends {\n readonly type: \"object\";\n readonly properties?: undefined;\n }\n ? Record<string, unknown>\n : S extends {\n readonly type: \"array\";\n readonly items?: infer Items;\n }\n ? Items extends readonly unknown[]\n ? InferJsonSchema7<Items[number]>[]\n : Items extends object\n ? InferJsonSchema7<Items>[]\n : unknown[]\n : S extends { readonly type: \"string\" }\n ? string\n : S extends { readonly type: \"number\" } | { readonly type: \"integer\" }\n ? number\n : S extends { readonly type: \"boolean\" }\n ? boolean\n : unknown;\n\nexport type TaskStatus = \"pending\" | \"open\" | \"handled\" | \"expired\";\n\nexport interface TaskResponse {\n success: boolean;\n task: {\n taskId: string;\n threadId: string;\n status: \"pending\" | \"open\";\n context: TaskContext;\n validUntil: string;\n submittedAt: string;\n };\n message: string;\n}\n\nexport interface ThreadUpdateResponse {\n success: boolean;\n update: ThreadUpdate;\n message: string;\n}\n\nexport interface Task {\n id: string;\n threadId?: string;\n createdAt: Date;\n status: TaskStatus;\n context: TaskContext;\n validUntil: number;\n handledAt?: number;\n handled?: {\n action: {\n id: string;\n data: unknown;\n };\n handledBy?: string;\n userId?: string;\n token?: string;\n };\n}\n\nexport type InferActionData<T extends { schema?: unknown }> = [\n Exclude<T[\"schema\"], undefined>,\n] extends [\n never,\n]\n ? Record<string, never>\n : Exclude<T[\"schema\"], undefined> extends infer S\n ? InferJsonSchema7<S>\n : Record<string, never>;\n\nexport type TupleElementIndices<T extends readonly unknown[]> = T extends readonly [\n unknown,\n ...unknown[],\n]\n ? Exclude<keyof T, keyof unknown[]>\n : number;\n\nexport interface TaskResult<T = Record<string, unknown>> {\n actionId: string;\n data: T;\n handledBy?: string;\n handledAt: Date;\n}\n\nexport interface ApprovalResult<T = Record<string, unknown>> extends TaskResult<T> {\n taskId: string;\n}\n\nexport type DiscriminatedApprovalResult<\n TActions extends readonly { id: string; schema?: unknown }[],\n> = {\n [I in TupleElementIndices<TActions>]: TActions[I] extends { id: string; schema?: unknown }\n ? Omit<ApprovalResult<InferActionData<TActions[I]>>, \"actionId\" | \"data\"> & {\n actionId: TActions[I][\"id\"];\n data: InferActionData<TActions[I]>;\n }\n : never\n}[TupleElementIndices<TActions>];\n"],"mappings":";AAAA,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC;AAuE1C,IAAM,gBAAgB,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,gBAAgB,GAAG,GAAG;AAAA,EACrE,SAAS;AACX,CAAC;AAED,IAAM,oBAAoB,EAAE;AAAA,EAC1B,CAAC,QAAQ,OAAO,QAAQ,YAAY,QAAQ;AAAA,EAC5C,EAAE,SAAS,qCAAqC;AAClD;AAEA,IAAM,iBAAiB,EAAE,OAAiB,CAAC,QAAQ,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAAA,EAC1F,SAAS;AACX,CAAC;AAED,IAAM,uBAAuB,EAAE,OAAO;AAAA,EACpC,MAAM,EAAE,QAAQ,SAAS;AAAA,EACzB,KAAK;AAAA,EACL,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;AAC1C,CAAC;AAED,IAAM,uBAAuB,qBAAqB,OAAO;AAAA,EACvD,MAAM,EAAE,QAAQ,SAAS;AAAA,EACzB,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAC3B,C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UAAU,mBAAmB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtC,QAAQ,wBAAwB,SAAS;AAAA,EACzC,OAAO,qBAAqB,SAAS;AACvC,CAAC,EACA,YAAY,uBAAuB;AAG/B,IAAM,yBAAyB;","names":[]}
1
+ {"version":3,"sources":["../../src/schemas/index.ts","../../../core/src/utils/safe-url.ts","../../../core/src/schemas/task.ts","../../../core/src/schemas/context-urls.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n isPublicHttpUrl,\n PUBLIC_HTTP_URL_ERROR,\n} from \"@robotrock/core/utils\";\nimport { validateContextPublicUrls } from \"@robotrock/core/schemas\";\n\nexport interface JSONSchema7 {\n $id?: string;\n $ref?: string;\n $schema?: string;\n $comment?: string;\n type?: JSONSchema7TypeName | JSONSchema7TypeName[];\n enum?: unknown[];\n const?: unknown;\n multipleOf?: number;\n maximum?: number;\n exclusiveMaximum?: number;\n minimum?: number;\n exclusiveMinimum?: number;\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n format?: string;\n items?: JSONSchema7 | JSONSchema7[];\n additionalItems?: JSONSchema7 | boolean;\n maxItems?: number;\n minItems?: number;\n uniqueItems?: boolean;\n contains?: JSONSchema7;\n maxProperties?: number;\n minProperties?: number;\n required?: string[];\n properties?: Record<string, JSONSchema7>;\n patternProperties?: Record<string, JSONSchema7>;\n additionalProperties?: JSONSchema7 | boolean;\n dependencies?: Record<string, JSONSchema7 | string[]>;\n propertyNames?: JSONSchema7;\n if?: JSONSchema7;\n then?: JSONSchema7;\n else?: JSONSchema7;\n allOf?: JSONSchema7[];\n anyOf?: JSONSchema7[];\n oneOf?: JSONSchema7[];\n not?: JSONSchema7;\n title?: string;\n description?: string;\n default?: unknown;\n readOnly?: boolean;\n writeOnly?: boolean;\n examples?: unknown[];\n}\n\nexport type JSONSchema7TypeName =\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"null\";\n\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\nconst taskContextObjectSchema = z.object({\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\nconst AGENT_TOOL_CALLS_MAX_KEYS = 64;\nexport const AGENT_OTEL_SPANS_MAX = 32;\n\nexport const agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);\n\nexport const agentOtelSpanStatusSchema = z.enum([\"ok\", \"error\"]);\n\nexport const agentOtelSpanSummarySchema = z.object({\n name: z.string().min(1),\n durationMs: z.number().nonnegative(),\n status: agentOtelSpanStatusSchema,\n});\n\nexport const agentOtelSchema = z.object({\n traceId: z.string().min(1),\n spanId: z.string().min(1).optional(),\n rootDurationMs: z.number().nonnegative().optional(),\n spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional(),\n});\n\nexport const agentTelemetrySchema = z\n .object({\n version: z.string().min(1).optional(),\n toolCallCount: nonNegativeInt.optional(),\n toolCalls: agentToolCallsSchema.optional(),\n cost: agentCostSchema.optional(),\n info: z.record(z.string(), z.unknown()).optional(),\n otel: agentOtelSchema.optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n )\n .refine(\n (data) => {\n const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];\n return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;\n },\n {\n message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`,\n }\n );\n\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;\nexport type AgentOtelSpanStatus = z.infer<typeof agentOtelSpanStatusSchema>;\nexport type AgentOtelSpanSummary = z.infer<typeof agentOtelSpanSummarySchema>;\nexport type AgentOtel = z.infer<typeof agentOtelSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n\ntype InferObjectProperties<\n Props,\n Req extends PropertyKey,\n> = Props extends Record<string, unknown>\n ? ({\n [K in keyof Props as K extends Req ? K : never]-?: InferJsonSchema7<Props[K]>;\n } & {\n [K in keyof Props as K extends Req ? never : K]?: InferJsonSchema7<Props[K]>;\n } extends infer O\n ? { [K in keyof O]: O[K] }\n : never)\n : Record<string, unknown>;\n\ntype RequiredKeys<S> =\n S extends { readonly required: readonly string[] } ? S[\"required\"][number] : never;\n\nexport type InferJsonSchema7<S> = [S] extends [undefined]\n ? Record<string, never>\n : S extends { readonly const: infer C }\n ? C\n : S extends {\n readonly enum: readonly (infer E)[];\n }\n ? E\n : S extends {\n readonly type: \"object\";\n readonly properties?: infer Props;\n }\n ? InferObjectProperties<Props, RequiredKeys<S>>\n : S extends {\n readonly type: \"object\";\n readonly properties?: undefined;\n }\n ? Record<string, unknown>\n : S extends {\n readonly type: \"array\";\n readonly items?: infer Items;\n }\n ? Items extends readonly unknown[]\n ? InferJsonSchema7<Items[number]>[]\n : Items extends object\n ? InferJsonSchema7<Items>[]\n : unknown[]\n : S extends { readonly type: \"string\" }\n ? string\n : S extends { readonly type: \"number\" } | { readonly type: \"integer\" }\n ? number\n : S extends { readonly type: \"boolean\" }\n ? boolean\n : unknown;\n\nexport type TaskStatus = \"pending\" | \"open\" | \"handled\" | \"expired\";\n\nexport interface TaskResponse {\n success: boolean;\n task: {\n taskId: string;\n threadId: string;\n status: \"pending\" | \"open\";\n context: TaskContext;\n validUntil: string;\n submittedAt: string;\n };\n message: string;\n}\n\nexport interface ThreadUpdateResponse {\n success: boolean;\n update: ThreadUpdate;\n message: string;\n}\n\nexport interface Task {\n id: string;\n threadId?: string;\n createdAt: Date;\n status: TaskStatus;\n context: TaskContext;\n validUntil: number;\n handledAt?: number;\n handled?: {\n action: {\n id: string;\n data: unknown;\n };\n handledBy?: string;\n userId?: string;\n token?: string;\n };\n}\n\nexport type InferActionData<T extends { schema?: unknown }> = [\n Exclude<T[\"schema\"], undefined>,\n] extends [\n never,\n]\n ? Record<string, never>\n : Exclude<T[\"schema\"], undefined> extends infer S\n ? InferJsonSchema7<S>\n : Record<string, never>;\n\nexport type TupleElementIndices<T extends readonly unknown[]> = T extends readonly [\n unknown,\n ...unknown[],\n]\n ? Exclude<keyof T, keyof unknown[]>\n : number;\n\nexport interface TaskResult<T = Record<string, unknown>> {\n actionId: string;\n data: T;\n handledBy?: string;\n handledAt: Date;\n}\n\nexport interface ApprovalResult<T = Record<string, unknown>> extends TaskResult<T> {\n taskId: string;\n}\n\nexport type DiscriminatedApprovalResult<\n TActions extends readonly { id: string; schema?: unknown }[],\n> = {\n [I in TupleElementIndices<TActions>]: TActions[I] extends { id: string; schema?: unknown }\n ? Omit<ApprovalResult<InferActionData<TActions[I]>>, \"actionId\" | \"data\"> & {\n actionId: TActions[I][\"id\"];\n data: InferActionData<TActions[I]>;\n }\n : never\n}[TupleElementIndices<TActions>];\n","const BLOCKED_HOSTNAMES = new Set([\n \"localhost\",\n \"metadata.google.internal\",\n \"metadata.goog\",\n]);\n\nfunction normalizeHostname(hostname: string): string {\n return hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n}\n\nfunction isBlockedIpv4(host: string): boolean {\n const match = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(host);\n if (!match) {\n return false;\n }\n\n const octets = match.slice(1, 5).map((part) => Number(part));\n if (octets.some((octet) => Number.isNaN(octet) || octet < 0 || octet > 255)) {\n return true;\n }\n\n const [a, b, _c, _d] = octets;\n if (a === undefined || b === undefined) {\n return true;\n }\n if (a === 127 || a === 0) return true;\n if (a === 10) return true;\n if (a === 169 && b === 254) return true;\n if (a === 192 && b === 168) return true;\n if (a === 172 && b >= 16 && b <= 31) return true;\n if (a === 100 && b >= 64 && b <= 127) return true;\n\n return false;\n}\n\nfunction ipv4FromNumericHost(host: string): string | null {\n if (/^\\d+$/.test(host)) {\n const num = Number(host);\n if (!Number.isFinite(num) || num < 0 || num > 0xffffffff) {\n return null;\n }\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n return `${a}.${b}.${c}.${d}`;\n }\n\n const hexMatch = /^0x([0-9a-f]{1,8})$/i.exec(host);\n if (hexMatch) {\n const num = Number.parseInt(hexMatch[1]!, 16);\n if (!Number.isFinite(num) || num < 0 || num > 0xffffffff) {\n return null;\n }\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n return `${a}.${b}.${c}.${d}`;\n }\n\n return null;\n}\n\nfunction isBlockedIpv4Mapped(host: string): boolean {\n const mappedDotted = /^::ffff:(\\d{1,3}(?:\\.\\d{1,3}){3})$/i.exec(host);\n if (mappedDotted) {\n return isBlockedIpv4(mappedDotted[1]!);\n }\n\n const mappedHex = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(host);\n if (mappedHex) {\n const high = Number.parseInt(mappedHex[1]!, 16);\n const low = Number.parseInt(mappedHex[2]!, 16);\n if (Number.isFinite(high) && Number.isFinite(low)) {\n const a = (high >> 8) & 0xff;\n const b = high & 0xff;\n const c = (low >> 8) & 0xff;\n const d = low & 0xff;\n return isBlockedIpv4(`${a}.${b}.${c}.${d}`);\n }\n }\n\n return false;\n}\n\nfunction isBlockedIpv6(host: string): boolean {\n if (host === \"::1\" || host === \"0:0:0:0:0:0:0:1\") {\n return true;\n }\n if (host.startsWith(\"fc\") || host.startsWith(\"fd\")) {\n return true;\n }\n if (host.startsWith(\"fe80:\")) {\n return true;\n }\n if (isBlockedIpv4Mapped(host)) {\n return true;\n }\n return false;\n}\n\nfunction isBlockedHostname(hostname: string): boolean {\n const host = normalizeHostname(hostname);\n if (!host) {\n return true;\n }\n if (BLOCKED_HOSTNAMES.has(host)) {\n return true;\n }\n if (host.endsWith(\".localhost\") || host.endsWith(\".local\")) {\n return true;\n }\n\n const numericIpv4 = ipv4FromNumericHost(host);\n if (numericIpv4 && isBlockedIpv4(numericIpv4)) {\n return true;\n }\n\n return isBlockedIpv4(host) || isBlockedIpv6(host);\n}\n\n/**\n * Returns true when the URL uses http(s) and targets a public, non-reserved host.\n */\nexport function isPublicHttpUrl(urlString: string): boolean {\n let url: URL;\n try {\n url = new URL(urlString);\n } catch {\n return false;\n }\n\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n return false;\n }\n if (url.username || url.password) {\n return false;\n }\n\n return !isBlockedHostname(url.hostname);\n}\n\nexport const PUBLIC_HTTP_URL_ERROR =\n \"URL must be a public http:// or https:// address\";\n\nconst FORBIDDEN_HANDLER_HEADERS = new Set([\n \"host\",\n \"connection\",\n \"content-length\",\n \"transfer-encoding\",\n \"te\",\n \"trailer\",\n \"upgrade\",\n \"proxy-authorization\",\n \"proxy-connection\",\n \"keep-alive\",\n \"x-robotrock-signature\",\n \"x-robotrock-delivery-id\",\n \"x-robotrock-delivery-attempt\",\n]);\n\n/**\n * Allow only safe custom webhook headers; blocks overrides of delivery metadata.\n */\nexport function filterHandlerHeaders(\n headers: Record<string, string> | undefined\n): Record<string, string> {\n if (!headers) {\n return {};\n }\n\n const filtered: Record<string, string> = {};\n for (const [rawKey, value] of Object.entries(headers)) {\n const key = rawKey.toLowerCase().trim();\n if (!key || FORBIDDEN_HANDLER_HEADERS.has(key)) {\n continue;\n }\n if (!/^[a-z0-9][a-z0-9._-]*$/.test(key)) {\n continue;\n }\n filtered[key] = value;\n }\n return filtered;\n}\n","import { z } from \"zod\";\nimport { isPublicHttpUrl, PUBLIC_HTTP_URL_ERROR } from \"../utils/safe-url\";\nimport { validateContextPublicUrls } from \"./context-urls\";\nimport type { JSONSchema7 } from \"./json-schema\";\n\n/**\n * Extended JSONSchema7 type that includes RJSF extensions like enumNames\n */\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\n/**\n * UI Schema for RJSF form customization\n */\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n// Helper schemas\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\n// JSONSchema7 validation\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\n// UiSchema validation\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\n// Handler schemas (per-action handlers for webhooks, triggers, etc.)\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\n// Action schema with JSONSchema-based feedback and optional handlers\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n // Optional handlers for this action - if present, must have at least 1\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\n// UI Field Schema\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\n// Context UI Schema\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\n// Context data schema\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\n// Main TaskContext schema\nconst taskContextObjectSchema = z.object({\n /** Source application id; omitted tasks are grouped in the default inbox. */\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\n/** Token usage for a single agent run (optional breakdown). */\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\n/** Monetary and token cost for a single agent run. */\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\nexport const AGENT_TOOL_CALLS_MAX_KEYS = 64;\nexport const AGENT_OTEL_SPANS_MAX = 32;\n\n/** Per-tool invocation counts keyed by tool name (e.g. `{ readFile: 3, grep: 2 }`). */\nexport const agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);\n\nexport const agentOtelSpanStatusSchema = z.enum([\"ok\", \"error\"]);\n\n/** Compact OpenTelemetry span summary for feedback analysis. */\nexport const agentOtelSpanSummarySchema = z.object({\n name: z.string().min(1),\n durationMs: z.number().nonnegative(),\n status: agentOtelSpanStatusSchema,\n});\n\n/**\n * Structured OpenTelemetry snapshot at task create (not shown in inbox UI).\n * Pair with full traces in your observability backend via `traceId`.\n */\nexport const agentOtelSchema = z.object({\n traceId: z.string().min(1),\n spanId: z.string().min(1).optional(),\n rootDurationMs: z.number().nonnegative().optional(),\n spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional(),\n});\n\n/**\n * Agent-only telemetry at task create (not shown in inbox reviewer UI).\n * Use to track version, cost, tool calls, and experiment metadata.\n */\nexport const agentTelemetrySchema = z\n .object({\n /** Agent or app version (semver, git SHA, deploy tag — caller-defined). */\n version: z.string().min(1).optional(),\n /** Total tool invocations. When omitted but `toolCalls` is set, the sum of counts is used. */\n toolCallCount: nonNegativeInt.optional(),\n /** Per-tool invocation counts keyed by tool name. */\n toolCalls: agentToolCallsSchema.optional(),\n cost: agentCostSchema.optional(),\n /** Free-form metadata for experiments (model, prompt variant, etc.). */\n info: z.record(z.string(), z.unknown()).optional(),\n /** Structured OpenTelemetry span snapshot for feedback analysis. */\n otel: agentOtelSchema.optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n )\n .refine(\n (data) => {\n const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];\n return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;\n },\n {\n message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`,\n }\n );\n\n/** Sum invocation counts from an agent.toolCalls map. */\nexport function sumAgentToolCalls(\n toolCalls: Record<string, number> | undefined\n): number {\n if (!toolCalls) return 0;\n return Object.values(toolCalls).reduce((sum, count) => sum + count, 0);\n}\n\n/** POST /v1 body: task context plus optional assignment. */\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n /** Agent telemetry (version, cost, tool calls) — not shown in inbox UI. */\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\n// Type exports\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type SafeUrl = z.infer<typeof safeUrlSchema>;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type ContextData = z.infer<typeof contextDataSchema>;\nexport type ContextUiSchema = z.infer<typeof contextUiSchema>;\nexport type UiFieldSchema = z.infer<typeof uiFieldSchemaSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;\nexport type AgentOtelSpanStatus = z.infer<typeof agentOtelSpanStatusSchema>;\nexport type AgentOtelSpanSummary = z.infer<typeof agentOtelSpanSummarySchema>;\nexport type AgentOtel = z.infer<typeof agentOtelSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n","import { isPublicHttpUrl, PUBLIC_HTTP_URL_ERROR } from \"../utils/safe-url\";\n\ntype ContextInput = {\n data?: Record<string, unknown>;\n ui?: Record<string, unknown>;\n};\n\nfunction resolveLinkUrl(value: string): string {\n return value.startsWith(\"http://\") || value.startsWith(\"https://\")\n ? value\n : `https://${value}`;\n}\n\nfunction widgetType(\n ui: Record<string, unknown> | undefined,\n field: string\n): string | undefined {\n const fieldUi = ui?.[field];\n if (typeof fieldUi !== \"object\" || fieldUi === null) {\n return undefined;\n }\n const widget = (fieldUi as Record<string, unknown>)[\"ui:widget\"];\n return typeof widget === \"string\" ? widget : undefined;\n}\n\nfunction validateUrlValue(value: unknown, widget: string): string | null {\n if (widget === \"image\" || widget === \"link\") {\n if (typeof value !== \"string\") {\n return PUBLIC_HTTP_URL_ERROR;\n }\n const url = widget === \"link\" ? resolveLinkUrl(value) : value;\n if (!isPublicHttpUrl(url)) {\n return PUBLIC_HTTP_URL_ERROR;\n }\n return null;\n }\n\n if (widget === \"attachments\" && Array.isArray(value)) {\n for (const item of value) {\n if (typeof item !== \"object\" || item === null) {\n continue;\n }\n const url = (item as { url?: unknown }).url;\n if (typeof url === \"string\" && !isPublicHttpUrl(resolveLinkUrl(url))) {\n return PUBLIC_HTTP_URL_ERROR;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Validates URL-bearing context widget values (image, link, attachments).\n * Returns an error message or null when valid.\n */\nexport function validateContextPublicUrls(\n context: ContextInput | undefined\n): string | null {\n if (!context?.data) {\n return null;\n }\n\n for (const [field, value] of Object.entries(context.data)) {\n const widget = widgetType(context.ui, field);\n if (!widget) {\n continue;\n }\n const error = validateUrlValue(value, widget);\n if (error) {\n return `context.data.${field}: ${error}`;\n }\n }\n\n return null;\n}\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACAlB,IAAM,oBAAoB,oBAAI,IAAI;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,kBAAkB,UAA0B;AACnD,SAAO,SAAS,YAAY,EAAE,QAAQ,YAAY,EAAE;AACtD;AAEA,SAAS,cAAc,MAAuB;AAC5C,QAAM,QAAQ,+CAA+C,KAAK,IAAI;AACtE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC;AAC3D,MAAI,OAAO,KAAK,CAAC,UAAU,OAAO,MAAM,KAAK,KAAK,QAAQ,KAAK,QAAQ,GAAG,GAAG;AAC3E,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,GAAG,GAAG,IAAI,EAAE,IAAI;AACvB,MAAI,MAAM,UAAa,MAAM,QAAW;AACtC,WAAO;AAAA,EACT;AACA,MAAI,MAAM,OAAO,MAAM,EAAG,QAAO;AACjC,MAAI,MAAM,GAAI,QAAO;AACrB,MAAI,MAAM,OAAO,MAAM,IAAK,QAAO;AACnC,MAAI,MAAM,OAAO,MAAM,IAAK,QAAO;AACnC,MAAI,MAAM,OAAO,KAAK,MAAM,KAAK,G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WAAWM,sBAAqB,SAAS;AAAA,EACzC,MAAMJ,iBAAgB,SAAS;AAAA,EAC/B,MAAMtB,GAAE,OAAOA,GAAE,OAAO,GAAGA,GAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACjD,MAAM6B,iBAAgB,SAAS;AACjC,CAAC,EACA;AAAA,EACC,CAAC,SAAS;AACR,UAAM,OAAO,KAAK,OAAO,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC;AACnD,WAAO,KAAK,UAAUN;AAAA,EACxB;AAAA,EACA,EAAE,SAAS,kCAAkCA,oBAAmB,QAAQ;AAC1E,EACC;AAAA,EACC,CAAC,SAAS;AACR,UAAM,OAAO,KAAK,YAAY,OAAO,KAAK,KAAK,SAAS,IAAI,CAAC;AAC7D,WAAO,KAAK,UAAUC;AAAA,EACxB;AAAA,EACA;AAAA,IACE,SAAS,uCAAuCA,0BAAyB;AAAA,EAC3E;AACF;AAEK,IAAMO,wBAAuBrB,yBACjC,OAAO;AAAA,EACN,UAAUG,gBAAe,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKlC,UAAUb,GAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKrC,UAAUmB,oBAAmB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtC,QAAQF,yBAAwB,SAAS;AAAA,EACzC,OAAOa,sBAAqB,SAAS;AACvC,CAAC,EACA,YAAYnB,wBAAuB;AAG/B,IAAM,yBAAyBM;","names":["z","safeUrlSchema","z","jsonSchema7Schema","uiSchemaSchema","webhookHandlerSchema","triggerHandlerSchema","handlerSchema","taskActionSchema","uiFieldSchemaSchema","contextUiSchema","contextDataSchema","taskContextObjectSchema","refineContextPublicUrls","taskContextSchema","assignToSchema","threadUpdateMessageSchema","threadUpdateStatuses","threadUpdateStatusSchema","threadUpdateInputSchema","taskPriorities","taskPrioritySchema","nonNegativeInt","agentCostTokensSchema","agentCostSchema","AGENT_INFO_MAX_KEYS","AGENT_TOOL_CALLS_MAX_KEYS","AGENT_OTEL_SPANS_MAX","agentToolCallsSchema","agentOtelSpanStatusSchema","agentOtelSpanSummarySchema","agentOtelSchema","agentTelemetrySchema","createTaskBodySchema"]}