robotrock 0.9.0 → 1.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 (52) hide show
  1. package/dist/ai/index.d.ts +18 -7
  2. package/dist/ai/index.js +852 -115
  3. package/dist/ai/index.js.map +1 -1
  4. package/dist/ai/trigger.d.ts +4 -3
  5. package/dist/ai/trigger.js +810 -115
  6. package/dist/ai/trigger.js.map +1 -1
  7. package/dist/ai/workflow.d.ts +15 -4
  8. package/dist/ai/workflow.js +729 -115
  9. package/dist/ai/workflow.js.map +1 -1
  10. package/dist/client-XTnFHGFE.d.ts +248 -0
  11. package/dist/eve/agent/index.d.ts +188 -0
  12. package/dist/eve/agent/index.js +2322 -0
  13. package/dist/eve/agent/index.js.map +1 -0
  14. package/dist/eve/index.d.ts +5 -0
  15. package/dist/eve/index.js +446 -0
  16. package/dist/eve/index.js.map +1 -0
  17. package/dist/eve/tools/identity/index.d.ts +6 -0
  18. package/dist/eve/tools/identity/index.js +144 -0
  19. package/dist/eve/tools/identity/index.js.map +1 -0
  20. package/dist/eve/tools/identity/my-access.d.ts +58 -0
  21. package/dist/eve/tools/identity/my-access.js +106 -0
  22. package/dist/eve/tools/identity/my-access.js.map +1 -0
  23. package/dist/eve/tools/identity/whoami.d.ts +45 -0
  24. package/dist/eve/tools/identity/whoami.js +101 -0
  25. package/dist/eve/tools/identity/whoami.js.map +1 -0
  26. package/dist/eve/tools/inbox/create-task.d.ts +113 -0
  27. package/dist/eve/tools/inbox/create-task.js +1557 -0
  28. package/dist/eve/tools/inbox/create-task.js.map +1 -0
  29. package/dist/eve/tools/inbox/index.d.ts +5 -0
  30. package/dist/eve/tools/inbox/index.js +1557 -0
  31. package/dist/eve/tools/inbox/index.js.map +1 -0
  32. package/dist/eve/tools/index.d.ts +17 -0
  33. package/dist/eve/tools/index.js +1654 -0
  34. package/dist/eve/tools/index.js.map +1 -0
  35. package/dist/index-BL9qKHA8.d.ts +141 -0
  36. package/dist/index.d.ts +12 -44
  37. package/dist/index.js +793 -97
  38. package/dist/index.js.map +1 -1
  39. package/dist/schemas/index.d.ts +11 -1
  40. package/dist/schemas/index.js +126 -8
  41. package/dist/schemas/index.js.map +1 -1
  42. package/dist/tenant-5YKDrdC-.d.ts +23 -0
  43. package/dist/{tool-approval-bridge-G765kMJR.d.ts → tool-approval-bridge-C4bTm8vu.d.ts} +93 -2
  44. package/dist/trigger/index.d.ts +2 -1
  45. package/dist/trigger/index.js +495 -87
  46. package/dist/trigger/index.js.map +1 -1
  47. package/dist/{trigger-D0shjqk0.d.ts → trigger-Dn0DFiyU.d.ts} +64 -3
  48. package/dist/workflow/index.d.ts +2 -1
  49. package/dist/workflow/index.js +496 -88
  50. package/dist/workflow/index.js.map +1 -1
  51. package/package.json +44 -7
  52. package/dist/client-Cy7YLxms.d.ts +0 -145
@@ -79,6 +79,15 @@ declare const handlerSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
79
79
  type: z.ZodLiteral<"trigger">;
80
80
  tokenId: z.ZodString;
81
81
  }, z.core.$strip>], "type">;
82
+ /** Action config without handlers — used for chat widgets and agent tool input. */
83
+ declare const taskActionInputSchema: z.ZodObject<{
84
+ id: z.ZodString;
85
+ title: z.ZodString;
86
+ description: z.ZodOptional<z.ZodString>;
87
+ schema: z.ZodOptional<z.ZodCustom<ExtendedJSONSchema7, ExtendedJSONSchema7>>;
88
+ ui: z.ZodOptional<z.ZodCustom<UiSchema, UiSchema>>;
89
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
90
+ }, z.core.$strip>;
82
91
  declare const taskActionSchema: z.ZodObject<{
83
92
  id: z.ZodString;
84
93
  title: z.ZodString;
@@ -427,6 +436,7 @@ type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;
427
436
  type TaskContextInput = z.input<typeof taskContextSchema>;
428
437
  type TaskContextOutput = z.output<typeof taskContextSchema>;
429
438
  type TaskContext = TaskContextOutput;
439
+ type TaskActionInput = z.infer<typeof taskActionInputSchema>;
430
440
  type TaskAction = z.infer<typeof taskActionSchema>;
431
441
  type WebhookHandler = z.infer<typeof webhookHandlerSchema>;
432
442
  type TriggerHandler = z.infer<typeof triggerHandlerSchema>;
@@ -534,4 +544,4 @@ type DiscriminatedApprovalResult<TActions extends readonly {
534
544
  } : never;
535
545
  }[TupleElementIndices<TActions>];
536
546
 
537
- export { type AgentTelemetry, type AgentTelemetryInput, type ApprovalResult, type AssignToInput, type CreateTaskBody, type CreateTaskBodyInput, DEFAULT_TASK_PRIORITY, DEFAULT_THREAD_UPDATE_STATUS, type DiscriminatedApprovalResult, type ExtendedJSONSchema7, type Handler, type InferActionData, type InferJsonSchema7, type JSONSchema7, type JSONSchema7TypeName, LOWEST_TASK_PRIORITY, TASK_CONTEXT_FORMAT_VERSION, TASK_PRIORITY_RANK, type Task, type TaskAction, type TaskContext, type TaskContextFormatVersion, type TaskContextInput, type TaskContextOutput, type TaskPriority, type TaskResponse, type TaskResult, type TaskStatus, type ThreadUpdate, type ThreadUpdateBody, type ThreadUpdateBodyInput, type ThreadUpdateInput, type ThreadUpdateResponse, type ThreadUpdateSource, type ThreadUpdateStatus, type TriggerHandler, type TupleElementIndices, type UiSchema, type WebhookHandler, agentTelemetrySchema, assignToSchema, createTaskBodySchema, taskContextSchema, taskPriorities, taskPrioritySchema, threadUpdateBodySchema, threadUpdateInputSchema, threadUpdateMessageSchema, threadUpdateStatusSchema, threadUpdateStatuses };
547
+ export { type AgentTelemetry, type AgentTelemetryInput, type ApprovalResult, type AssignToInput, type CreateTaskBody, type CreateTaskBodyInput, DEFAULT_TASK_PRIORITY, DEFAULT_THREAD_UPDATE_STATUS, type DiscriminatedApprovalResult, type ExtendedJSONSchema7, type Handler, type InferActionData, type InferJsonSchema7, type JSONSchema7, type JSONSchema7TypeName, LOWEST_TASK_PRIORITY, TASK_CONTEXT_FORMAT_VERSION, TASK_PRIORITY_RANK, type Task, type TaskAction, type TaskActionInput, type TaskContext, type TaskContextFormatVersion, type TaskContextInput, type TaskContextOutput, type TaskPriority, type TaskResponse, type TaskResult, type TaskStatus, type ThreadUpdate, type ThreadUpdateBody, type ThreadUpdateBodyInput, type ThreadUpdateInput, type ThreadUpdateResponse, type ThreadUpdateSource, type ThreadUpdateStatus, type TriggerHandler, type TupleElementIndices, type UiSchema, type WebhookHandler, agentTelemetrySchema, assignToSchema, createTaskBodySchema, taskActionInputSchema, taskContextSchema, taskPriorities, taskPrioritySchema, threadUpdateBodySchema, threadUpdateInputSchema, threadUpdateMessageSchema, threadUpdateStatusSchema, threadUpdateStatuses };
@@ -108,6 +108,25 @@ function isBlockedHostname(hostname) {
108
108
  }
109
109
  return isBlockedIpv4(host) || isBlockedIpv6(host);
110
110
  }
111
+ function isLoopbackHandlerUrl(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
+ const host = url.hostname.toLowerCase();
125
+ return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]" || host.endsWith(".localhost");
126
+ }
127
+ function isAllowedHandlerUrl(urlString) {
128
+ return isPublicHttpUrl(urlString) || isLoopbackHandlerUrl(urlString);
129
+ }
111
130
  function isPublicHttpUrl(urlString) {
112
131
  let url;
113
132
  try {
@@ -124,6 +143,7 @@ function isPublicHttpUrl(urlString) {
124
143
  return !isBlockedHostname(url.hostname);
125
144
  }
126
145
  var PUBLIC_HTTP_URL_ERROR = "URL must be a public http:// or https:// address";
146
+ var HANDLER_URL_ERROR = "Handler URL must be a public or loopback http:// or https:// address";
127
147
 
128
148
  // ../core/src/schemas/task.ts
129
149
  import { z } from "zod";
@@ -185,6 +205,9 @@ function validateContextPublicUrls(context) {
185
205
  var safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {
186
206
  message: PUBLIC_HTTP_URL_ERROR
187
207
  });
208
+ var handlerUrlSchema = z.string().refine((url) => isAllowedHandlerUrl(url), {
209
+ message: HANDLER_URL_ERROR
210
+ });
188
211
  var jsonSchema7Schema = z.custom(
189
212
  (val) => typeof val === "object" && val !== null,
190
213
  { message: "Must be a valid JSON Schema object" }
@@ -194,7 +217,7 @@ var uiSchemaSchema = z.custom((val) => typeof val === "object" && val !== null,
194
217
  });
195
218
  var webhookHandlerSchema = z.object({
196
219
  type: z.literal("webhook"),
197
- url: safeUrlSchema,
220
+ url: handlerUrlSchema,
198
221
  headers: z.record(z.string(), z.string())
199
222
  });
200
223
  var triggerHandlerSchema = webhookHandlerSchema.extend({
@@ -202,13 +225,15 @@ var triggerHandlerSchema = webhookHandlerSchema.extend({
202
225
  tokenId: z.string().min(1)
203
226
  });
204
227
  var handlerSchema = z.discriminatedUnion("type", [webhookHandlerSchema, triggerHandlerSchema]);
205
- var taskActionSchema = z.object({
228
+ var taskActionInputSchema = z.object({
206
229
  id: z.string().min(1),
207
230
  title: z.string().min(1),
208
231
  description: z.string().optional(),
209
232
  schema: jsonSchema7Schema.optional(),
210
233
  ui: uiSchemaSchema.optional(),
211
- data: z.record(z.string(), z.unknown()).optional(),
234
+ data: z.record(z.string(), z.unknown()).optional()
235
+ });
236
+ var taskActionSchema = taskActionInputSchema.extend({
212
237
  // Optional handlers for this action - if present, must have at least 1
213
238
  handlers: z.array(handlerSchema).min(1).optional()
214
239
  });
@@ -316,10 +341,100 @@ var createTaskBodySchema = taskContextObjectBaseSchema.extend({
316
341
  /** Agent release version — not shown in inbox UI. */
317
342
  agent: agentTelemetrySchema.optional()
318
343
  }).transform(normalizeTaskContextVersion).superRefine(refineContextPublicUrls);
344
+ var agentChatSeedActionSchema = z.object({
345
+ /** Stable action id echoed back on submit; auto-derived from title when omitted. */
346
+ id: z.string().min(1).optional(),
347
+ title: z.string().min(1),
348
+ description: z.string().optional(),
349
+ /** JSON Schema object for the form fields. */
350
+ schema: z.record(z.string(), z.unknown()).optional(),
351
+ /** RJSF ui schema overrides (ui:widget, ui:enumNames, etc.). */
352
+ ui: z.record(z.string(), z.unknown()).optional(),
353
+ /** Optional default field values. */
354
+ data: z.record(z.string(), z.unknown()).optional()
355
+ });
356
+ var agentChatSeedMessageSchema = z.object({
357
+ role: z.enum(["user", "assistant"]),
358
+ text: z.string().min(1),
359
+ /** Optional display-name override for the message sender. */
360
+ senderName: z.string().min(1).optional(),
361
+ /**
362
+ * Optional structured input request rendered as a styled RobotRock action
363
+ * widget below the message text. Use this instead of asking the user to reply
364
+ * in plain text so the request is always a proper action form.
365
+ */
366
+ requestActionInput: z.object({
367
+ prompt: z.string().optional(),
368
+ action: agentChatSeedActionSchema
369
+ }).optional()
370
+ });
371
+ var eveAgentChatTransportSchema = z.object({
372
+ kind: z.literal("eve"),
373
+ chatId: z.string().min(1),
374
+ baseUrl: z.string().url(),
375
+ sessionId: z.string().optional(),
376
+ continuationToken: z.string().optional(),
377
+ streamIndex: z.number().int().nonnegative().optional(),
378
+ isStreaming: z.boolean().optional()
379
+ });
380
+ var createAgentChatBodySchema = z.object({
381
+ /** Agent id (eve agent name). Required unless `parentChatId` is set. */
382
+ agentIdentifier: z.string().min(1).optional(),
383
+ /** Inherit tenant/connection/agent from an existing chat (agent-spawned chats). */
384
+ parentChatId: z.string().min(1).optional(),
385
+ /** Convex tenantEveConnections id; resolved from the tenant when omitted. */
386
+ eveConnectionId: z.string().min(1).optional(),
387
+ /** Source application id; groups the chat under an inbox section. */
388
+ app: z.string().min(1).optional(),
389
+ assignTo: assignToSchema.optional(),
390
+ title: z.string().min(1),
391
+ messages: z.array(agentChatSeedMessageSchema).default([]),
392
+ /** Provenance label stored on the session ("cron" | "agent" | ...). */
393
+ source: z.string().min(1).optional()
394
+ }).refine((data) => Boolean(data.agentIdentifier || data.parentChatId), {
395
+ message: "Provide either agentIdentifier or parentChatId"
396
+ });
397
+ var agentChatAuditInputBodySchema = z.object({
398
+ eveSessionId: z.string().min(1),
399
+ userId: z.string().min(1),
400
+ actionId: z.string().min(1),
401
+ actionTitle: z.string().optional(),
402
+ prompt: z.string().optional(),
403
+ data: z.record(z.string(), z.unknown()).optional(),
404
+ idempotencyKey: z.string().optional(),
405
+ /** Eve input request id — used to merge staged HITL metadata. */
406
+ requestId: z.string().optional(),
407
+ /** Eve tool call id — fallback lookup for staged HITL metadata. */
408
+ toolCallId: z.string().optional()
409
+ });
410
+ var eveHitlStagedOptionSchema = z.object({
411
+ id: z.string(),
412
+ label: z.string()
413
+ });
414
+ var agentChatStageHitlBodySchema = z.object({
415
+ eveSessionId: z.string().min(1),
416
+ requests: z.array(
417
+ z.object({
418
+ requestId: z.string().min(1),
419
+ toolCallId: z.string().min(1),
420
+ toolName: z.string().min(1),
421
+ prompt: z.string().min(1),
422
+ display: z.enum(["confirmation", "select", "text"]).optional(),
423
+ allowFreeform: z.boolean().optional(),
424
+ options: z.array(eveHitlStagedOptionSchema).optional(),
425
+ toolInput: z.record(z.string(), z.unknown()).optional()
426
+ })
427
+ )
428
+ });
429
+ var agentChatLinkTaskBodySchema = z.object({
430
+ eveSessionId: z.string().min(1),
431
+ publicTaskId: z.string().min(1),
432
+ toolCallId: z.string().min(1)
433
+ });
319
434
 
320
435
  // src/schemas/index.ts
321
- var safeUrlSchema2 = z2.string().refine((url) => isPublicHttpUrl(url), {
322
- message: PUBLIC_HTTP_URL_ERROR
436
+ var handlerUrlSchema2 = z2.string().refine((url) => isAllowedHandlerUrl(url), {
437
+ message: HANDLER_URL_ERROR
323
438
  });
324
439
  var jsonSchema7Schema2 = z2.custom(
325
440
  (val) => typeof val === "object" && val !== null,
@@ -330,7 +445,7 @@ var uiSchemaSchema2 = z2.custom((val) => typeof val === "object" && val !== null
330
445
  });
331
446
  var webhookHandlerSchema2 = z2.object({
332
447
  type: z2.literal("webhook"),
333
- url: safeUrlSchema2,
448
+ url: handlerUrlSchema2,
334
449
  headers: z2.record(z2.string(), z2.string())
335
450
  });
336
451
  var triggerHandlerSchema2 = webhookHandlerSchema2.extend({
@@ -338,13 +453,15 @@ var triggerHandlerSchema2 = webhookHandlerSchema2.extend({
338
453
  tokenId: z2.string().min(1)
339
454
  });
340
455
  var handlerSchema2 = z2.discriminatedUnion("type", [webhookHandlerSchema2, triggerHandlerSchema2]);
341
- var taskActionSchema2 = z2.object({
456
+ var taskActionInputSchema2 = z2.object({
342
457
  id: z2.string().min(1),
343
458
  title: z2.string().min(1),
344
459
  description: z2.string().optional(),
345
460
  schema: jsonSchema7Schema2.optional(),
346
461
  ui: uiSchemaSchema2.optional(),
347
- data: z2.record(z2.string(), z2.unknown()).optional(),
462
+ data: z2.record(z2.string(), z2.unknown()).optional()
463
+ });
464
+ var taskActionSchema2 = taskActionInputSchema2.extend({
348
465
  handlers: z2.array(handlerSchema2).min(1).optional()
349
466
  });
350
467
  var uiFieldSchemaSchema2 = z2.object({
@@ -466,6 +583,7 @@ export {
466
583
  agentTelemetrySchema2 as agentTelemetrySchema,
467
584
  assignToSchema2 as assignToSchema,
468
585
  createTaskBodySchema2 as createTaskBodySchema,
586
+ taskActionInputSchema2 as taskActionInputSchema,
469
587
  taskContextSchema2 as taskContextSchema,
470
588
  taskPriorities2 as taskPriorities,
471
589
  taskPrioritySchema2 as taskPrioritySchema,
@@ -1 +1 @@
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\n/** Task context wire format version (always `2` today). */\nexport const TASK_CONTEXT_FORMAT_VERSION = 2 as const;\nexport type TaskContextFormatVersion = typeof TASK_CONTEXT_FORMAT_VERSION;\n\nconst taskContextObjectBaseSchema = 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 contextVersion: z.literal(2).optional(),\n /** @deprecated Use `contextVersion`. Accepted on ingest only. */\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction normalizeTaskContextVersion<T extends { contextVersion?: 2; version?: 2 }>(\n data: T\n): Omit<T, \"version\" | \"contextVersion\"> & { contextVersion: 2 } {\n const { version: legacyVersion, contextVersion, ...rest } = data;\n return {\n ...rest,\n contextVersion: contextVersion ?? legacyVersion ?? TASK_CONTEXT_FORMAT_VERSION,\n };\n}\n\nconst taskContextObjectSchema = taskContextObjectBaseSchema.transform(\n normalizeTaskContextVersion\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\nexport const agentTelemetrySchema = z.object({\n version: z.string().min(1),\n});\n\nexport const createTaskBodySchema = taskContextObjectBaseSchema\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 .transform(normalizeTaskContextVersion)\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 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\nexport const TASK_CONTEXT_FORMAT_VERSION = 2 as const;\nexport type TaskContextFormatVersion = typeof TASK_CONTEXT_FORMAT_VERSION;\n\n// Main TaskContext schema\nconst taskContextObjectBaseSchema = 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 /** Task context wire format version. @default 2 */\n contextVersion: z.literal(2).optional(),\n /** @deprecated Use `contextVersion`. Accepted on ingest only. */\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction normalizeTaskContextVersion<T extends { contextVersion?: 2; version?: 2 }>(\n data: T\n): Omit<T, \"version\" | \"contextVersion\"> & { contextVersion: 2 } {\n const { version: legacyVersion, contextVersion, ...rest } = data;\n return {\n ...rest,\n contextVersion: contextVersion ?? legacyVersion ?? TASK_CONTEXT_FORMAT_VERSION,\n };\n}\n\nconst taskContextObjectSchema = taskContextObjectBaseSchema.transform(\n normalizeTaskContextVersion\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\n/**\n * Agent release at task create (not shown in inbox reviewer UI).\n * Used for feedback analysis over deploys.\n */\nexport const agentTelemetrySchema = z.object({\n /** Agent or app version (semver, git SHA, deploy tag — caller-defined). */\n version: z.string().min(1),\n});\n\n/** POST /v1 body: task context plus optional assignment. */\nexport const createTaskBodySchema = taskContextObjectBaseSchema\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 release version — not shown in inbox UI. */\n agent: agentTelemetrySchema.optional(),\n })\n .transform(normalizeTaskContextVersion)\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 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;;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lC,UAAUhB,GAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKrC,UAAUsB,oBAAmB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtC,QAAQF,yBAAwB,SAAS;AAAA,EACzC,OAAOG,sBAAqB,SAAS;AACvC,CAAC,EACA,UAAUX,4BAA2B,EACrC,YAAYE,wBAAuB;AAG/B,IAAM,yBAAyBM;","names":["z","safeUrlSchema","z","jsonSchema7Schema","uiSchemaSchema","webhookHandlerSchema","triggerHandlerSchema","handlerSchema","taskActionSchema","uiFieldSchemaSchema","contextUiSchema","contextDataSchema","TASK_CONTEXT_FORMAT_VERSION","taskContextObjectBaseSchema","normalizeTaskContextVersion","taskContextObjectSchema","refineContextPublicUrls","taskContextSchema","assignToSchema","threadUpdateMessageSchema","threadUpdateStatuses","threadUpdateStatusSchema","threadUpdateInputSchema","taskPriorities","taskPrioritySchema","agentTelemetrySchema","createTaskBodySchema"]}
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 isAllowedHandlerUrl,\n HANDLER_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 handlerUrlSchema = z.string().refine((url) => isAllowedHandlerUrl(url), {\n message: HANDLER_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: handlerUrlSchema,\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 config without handlers — used for chat widgets and agent tool input. */\nexport const taskActionInputSchema = 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});\n\nconst taskActionSchema = taskActionInputSchema.extend({\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\n/** Task context wire format version (always `2` today). */\nexport const TASK_CONTEXT_FORMAT_VERSION = 2 as const;\nexport type TaskContextFormatVersion = typeof TASK_CONTEXT_FORMAT_VERSION;\n\nconst taskContextObjectBaseSchema = 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 contextVersion: z.literal(2).optional(),\n /** @deprecated Use `contextVersion`. Accepted on ingest only. */\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction normalizeTaskContextVersion<T extends { contextVersion?: 2; version?: 2 }>(\n data: T\n): Omit<T, \"version\" | \"contextVersion\"> & { contextVersion: 2 } {\n const { version: legacyVersion, contextVersion, ...rest } = data;\n return {\n ...rest,\n contextVersion: contextVersion ?? legacyVersion ?? TASK_CONTEXT_FORMAT_VERSION,\n };\n}\n\nconst taskContextObjectSchema = taskContextObjectBaseSchema.transform(\n normalizeTaskContextVersion\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\nexport const agentTelemetrySchema = z.object({\n version: z.string().min(1),\n});\n\nexport const createTaskBodySchema = taskContextObjectBaseSchema\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 .transform(normalizeTaskContextVersion)\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 TaskActionInput = z.infer<typeof taskActionInputSchema>;\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 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 * True when a handler URL targets the local machine. Convex cloud cannot POST\n * these directly; loopback deliveries are queued in Redis and drained by a local\n * worker (see apps/api handler-outbound).\n */\nexport function isLoopbackHandlerUrl(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 const host = url.hostname.toLowerCase();\n return (\n host === \"localhost\" ||\n host === \"127.0.0.1\" ||\n host === \"::1\" ||\n host === \"[::1]\" ||\n host.endsWith(\".localhost\")\n );\n}\n\n/**\n * Webhook/trigger handler URLs may target a public host or loopback (local dev).\n */\nexport function isAllowedHandlerUrl(urlString: string): boolean {\n return isPublicHttpUrl(urlString) || isLoopbackHandlerUrl(urlString);\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\nexport const HANDLER_URL_ERROR =\n \"Handler URL must be a public or loopback 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 {\n isAllowedHandlerUrl,\n isPublicHttpUrl,\n HANDLER_URL_ERROR,\n PUBLIC_HTTP_URL_ERROR,\n} 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\nexport const safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\nconst handlerUrlSchema = z.string().refine((url) => isAllowedHandlerUrl(url), {\n message: HANDLER_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: handlerUrlSchema,\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 config without handlers — used for chat widgets and agent tool input. */\nexport const taskActionInputSchema = 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});\n\n// Action schema with JSONSchema-based feedback and optional handlers\nconst taskActionSchema = taskActionInputSchema.extend({\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\nexport const TASK_CONTEXT_FORMAT_VERSION = 2 as const;\nexport type TaskContextFormatVersion = typeof TASK_CONTEXT_FORMAT_VERSION;\n\n// Main TaskContext schema\nconst taskContextObjectBaseSchema = 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 /** Task context wire format version. @default 2 */\n contextVersion: z.literal(2).optional(),\n /** @deprecated Use `contextVersion`. Accepted on ingest only. */\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction normalizeTaskContextVersion<T extends { contextVersion?: 2; version?: 2 }>(\n data: T\n): Omit<T, \"version\" | \"contextVersion\"> & { contextVersion: 2 } {\n const { version: legacyVersion, contextVersion, ...rest } = data;\n return {\n ...rest,\n contextVersion: contextVersion ?? legacyVersion ?? TASK_CONTEXT_FORMAT_VERSION,\n };\n}\n\nconst taskContextObjectSchema = taskContextObjectBaseSchema.transform(\n normalizeTaskContextVersion\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\n/**\n * Agent release at task create (not shown in inbox reviewer UI).\n * Used for feedback analysis over deploys.\n */\nexport const agentTelemetrySchema = z.object({\n /** Agent or app version (semver, git SHA, deploy tag — caller-defined). */\n version: z.string().min(1),\n});\n\n/** POST /v1 body: task context plus optional assignment. */\nexport const createTaskBodySchema = taskContextObjectBaseSchema\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 release version — not shown in inbox UI. */\n agent: agentTelemetrySchema.optional(),\n })\n .transform(normalizeTaskContextVersion)\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Action widget config for a seeded assistant message (mirrors the `requestActionInput` tool input). */\nexport const agentChatSeedActionSchema = z.object({\n /** Stable action id echoed back on submit; auto-derived from title when omitted. */\n id: z.string().min(1).optional(),\n title: z.string().min(1),\n description: z.string().optional(),\n /** JSON Schema object for the form fields. */\n schema: z.record(z.string(), z.unknown()).optional(),\n /** RJSF ui schema overrides (ui:widget, ui:enumNames, etc.). */\n ui: z.record(z.string(), z.unknown()).optional(),\n /** Optional default field values. */\n data: z.record(z.string(), z.unknown()).optional(),\n});\n\n/** A single pre-seeded chat message injected into a programmatic agent chat. */\nexport const agentChatSeedMessageSchema = z.object({\n role: z.enum([\"user\", \"assistant\"]),\n text: z.string().min(1),\n /** Optional display-name override for the message sender. */\n senderName: z.string().min(1).optional(),\n /**\n * Optional structured input request rendered as a styled RobotRock action\n * widget below the message text. Use this instead of asking the user to reply\n * in plain text so the request is always a proper action form.\n */\n requestActionInput: z\n .object({\n prompt: z.string().optional(),\n action: agentChatSeedActionSchema,\n })\n .optional(),\n});\n\n/**\n * POST /v1/agent-chats body: create + assign one or more agent chat sessions.\n * Either `agentIdentifier` (new chat) or `parentChatId` (spawned from a chat) is required.\n */\nconst eveAgentChatTransportSchema = z.object({\n kind: z.literal(\"eve\"),\n chatId: z.string().min(1),\n baseUrl: z.string().url(),\n sessionId: z.string().optional(),\n continuationToken: z.string().optional(),\n streamIndex: z.number().int().nonnegative().optional(),\n isStreaming: z.boolean().optional(),\n});\n\nexport const createAgentChatBodySchema = z\n .object({\n /** Agent id (eve agent name). Required unless `parentChatId` is set. */\n agentIdentifier: z.string().min(1).optional(),\n /** Inherit tenant/connection/agent from an existing chat (agent-spawned chats). */\n parentChatId: z.string().min(1).optional(),\n /** Convex tenantEveConnections id; resolved from the tenant when omitted. */\n eveConnectionId: z.string().min(1).optional(),\n /** Source application id; groups the chat under an inbox section. */\n app: z.string().min(1).optional(),\n assignTo: assignToSchema.optional(),\n title: z.string().min(1),\n messages: z.array(agentChatSeedMessageSchema).default([]),\n /** Provenance label stored on the session (\"cron\" | \"agent\" | ...). */\n source: z.string().min(1).optional(),\n })\n .refine((data) => Boolean(data.agentIdentifier || data.parentChatId), {\n message: \"Provide either agentIdentifier or parentChatId\",\n });\n\n/** POST /v1/agent-chats/transport body: persist live-chat cursor for the browser. */\nexport const agentChatTransportBodySchema = eveAgentChatTransportSchema;\n\n/** POST /v1/agent-chats/audit-input body: log Eve HITL choices from agent hooks. */\nexport const agentChatAuditInputBodySchema = z.object({\n eveSessionId: z.string().min(1),\n userId: z.string().min(1),\n actionId: z.string().min(1),\n actionTitle: z.string().optional(),\n prompt: z.string().optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n idempotencyKey: z.string().optional(),\n /** Eve input request id — used to merge staged HITL metadata. */\n requestId: z.string().optional(),\n /** Eve tool call id — fallback lookup for staged HITL metadata. */\n toolCallId: z.string().optional(),\n});\n\nconst eveHitlStagedOptionSchema = z.object({\n id: z.string(),\n label: z.string(),\n});\n\n/** POST /v1/agent-chats/stage-hitl body: persist pending Eve HITL requests on the chat. */\nexport const agentChatStageHitlBodySchema = z.object({\n eveSessionId: z.string().min(1),\n requests: z.array(\n z.object({\n requestId: z.string().min(1),\n toolCallId: z.string().min(1),\n toolName: z.string().min(1),\n prompt: z.string().min(1),\n display: z.enum([\"confirmation\", \"select\", \"text\"]).optional(),\n allowFreeform: z.boolean().optional(),\n options: z.array(eveHitlStagedOptionSchema).optional(),\n toolInput: z.record(z.string(), z.unknown()).optional(),\n })\n ),\n});\n\n/** POST /v1/agent-chats/link-task body: associate an inbox task with an Eve chat session. */\nexport const agentChatLinkTaskBodySchema = z.object({\n eveSessionId: z.string().min(1),\n publicTaskId: z.string().min(1),\n toolCallId: z.string().min(1),\n});\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 AgentChatSeedAction = z.output<typeof agentChatSeedActionSchema>;\nexport type AgentChatSeedMessage = z.output<typeof agentChatSeedMessageSchema>;\nexport type CreateAgentChatBodyInput = z.input<typeof createAgentChatBodySchema>;\nexport type CreateAgentChatBody = z.output<typeof createAgentChatBodySchema>;\nexport type AgentChatTransportBody = z.output<typeof agentChatTransportBodySchema>;\nexport type AgentChatAuditInputBody = z.output<typeof agentChatAuditInputBodySchema>;\nexport type AgentChatStageHitlBody = z.output<typeof agentChatStageHitlBodySchema>;\nexport type AgentChatLinkTaskBody = z.output<typeof agentChatLinkTaskBodySchema>;\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 TaskActionInput = z.infer<typeof taskActionInputSchema>;\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 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;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CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKrC,UAAUuB,oBAAmB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtC,QAAQF,yBAAwB,SAAS;AAAA,EACzC,OAAOG,sBAAqB,SAAS;AACvC,CAAC,EACA,UAAUX,4BAA2B,EACrC,YAAYE,wBAAuB;AAG/B,IAAM,yBAAyBM;","names":["z","handlerUrlSchema","z","jsonSchema7Schema","uiSchemaSchema","webhookHandlerSchema","triggerHandlerSchema","handlerSchema","taskActionInputSchema","taskActionSchema","uiFieldSchemaSchema","contextUiSchema","contextDataSchema","TASK_CONTEXT_FORMAT_VERSION","taskContextObjectBaseSchema","normalizeTaskContextVersion","taskContextObjectSchema","refineContextPublicUrls","taskContextSchema","assignToSchema","threadUpdateMessageSchema","threadUpdateStatuses","threadUpdateStatusSchema","threadUpdateInputSchema","taskPriorities","taskPrioritySchema","agentTelemetrySchema","createTaskBodySchema"]}
@@ -0,0 +1,23 @@
1
+ import { SessionContext } from 'eve/context';
2
+
3
+ type TenantRole = "admin" | "member";
4
+ type TenantCaller = {
5
+ userId: string;
6
+ email: string;
7
+ name: string;
8
+ tenantSlug: string;
9
+ connectionId?: string;
10
+ role: TenantRole;
11
+ isAdmin: boolean;
12
+ groups: string[];
13
+ workosUserId?: string;
14
+ };
15
+ /** Resolve the authenticated RobotRock dashboard user for the current session. */
16
+ declare function tryResolveTenantCaller(ctx: SessionContext): TenantCaller | null;
17
+ /** Like {@link tryResolveTenantCaller} but throws when the session has no user. */
18
+ declare function requireTenantCaller(ctx: SessionContext): TenantCaller;
19
+ declare function isAdminCaller(ctx: SessionContext): boolean;
20
+ /** Require an authenticated tenant admin for the current session. */
21
+ declare function requireAdminCaller(ctx: SessionContext): TenantCaller;
22
+
23
+ export { type TenantRole as T, type TenantCaller as a, requireTenantCaller as b, isAdminCaller as i, requireAdminCaller as r, tryResolveTenantCaller as t };
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { R as RobotRock, a as SendToHumanInput, S as SendToHumanActionInput, k as SendUpdateInput } from './client-Cy7YLxms.js';
2
+ import { R as RobotRock, a as SendToHumanInput, S as SendToHumanActionInput, n as SendUpdateInput } from './client-XTnFHGFE.js';
3
3
  import { DiscriminatedApprovalResult, ThreadUpdate } from './schemas/index.js';
4
4
  import { ToolApprovalResponse } from 'ai';
5
5
 
@@ -46,6 +46,14 @@ declare function sendToHumanForAi<A extends readonly SendToHumanActionInput[] =
46
46
  * issue the request directly.
47
47
  */
48
48
  declare function sendUpdateForAi(context: RobotRockAiContext, payload: SendUpdateInput): Promise<ThreadUpdate>;
49
+ /**
50
+ * Close an agent chat from a chat-agent tool. Idempotent server-side, so all
51
+ * modes resolve a client and call `chats.close` directly (no durable step).
52
+ */
53
+ declare function closeChatForAi(context: RobotRockAiContext, payload: {
54
+ chatId: string;
55
+ reason?: string;
56
+ }): Promise<void>;
49
57
  declare function approveByHumanForAi(context: RobotRockAiContext, payload: Omit<SendToHumanInput, "actions"> & {
50
58
  app?: string;
51
59
  }): Promise<DiscriminatedApprovalResult<typeof APPROVE_BY_HUMAN_ACTIONS$1>>;
@@ -212,6 +220,89 @@ type SendUpdateToolDefinition = {
212
220
  execute: (input: SendUpdateToolInput) => Promise<SendUpdateToolResult>;
213
221
  };
214
222
 
223
+ declare const REQUEST_ACTION_INPUT_TOOL_NAME: "requestActionInput";
224
+ /** Stable slug when the model omits `action.id` (common LLM mistake). */
225
+ declare function defaultRequestActionInputActionId(title: string): string;
226
+ declare function normalizeRequestActionInputToolInput(input: z.input<typeof requestActionInputToolInputSchema>): RequestActionInputToolInput;
227
+ declare const requestActionInputToolOutputSchema: z.ZodObject<{
228
+ actionId: z.ZodString;
229
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
230
+ }, z.core.$strip>;
231
+ type RequestActionInputToolOutput = z.infer<typeof requestActionInputToolOutputSchema>;
232
+ declare const requestActionInputToolInputSchema: z.ZodObject<{
233
+ prompt: z.ZodOptional<z.ZodString>;
234
+ action: z.ZodObject<{
235
+ id: z.ZodOptional<z.ZodString>;
236
+ title: z.ZodString;
237
+ description: z.ZodOptional<z.ZodString>;
238
+ schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
239
+ ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
240
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
241
+ }, z.core.$strip>;
242
+ }, z.core.$strip>;
243
+ type RequestActionInputToolInput = z.infer<typeof requestActionInputToolInputSchema>;
244
+ type RequestActionInputToolOptions = {
245
+ description?: string;
246
+ toolName?: string;
247
+ };
248
+ type RequestActionInputToolDefinition = {
249
+ description: string;
250
+ inputSchema: typeof requestActionInputToolInputSchema;
251
+ outputSchema: typeof requestActionInputToolOutputSchema;
252
+ };
253
+ declare function buildRequestActionInputToolDefinition(options?: RequestActionInputToolOptions): RequestActionInputToolDefinition;
254
+ declare function isRequestActionInputToolPart(part: {
255
+ type?: string;
256
+ }, toolName?: string): boolean;
257
+
258
+ declare const REPORT_STATUS_TOOL_NAME: "reportStatus";
259
+ declare const reportStatusPhaseSchema: z.ZodEnum<{
260
+ info: "info";
261
+ running: "running";
262
+ waiting: "waiting";
263
+ succeeded: "succeeded";
264
+ failed: "failed";
265
+ }>;
266
+ type ReportStatusPhase = z.infer<typeof reportStatusPhaseSchema>;
267
+ declare const reportStatusToolInputSchema: z.ZodObject<{
268
+ message: z.ZodString;
269
+ phase: z.ZodOptional<z.ZodEnum<{
270
+ info: "info";
271
+ running: "running";
272
+ waiting: "waiting";
273
+ succeeded: "succeeded";
274
+ failed: "failed";
275
+ }>>;
276
+ }, z.core.$strip>;
277
+ declare const reportStatusToolOutputSchema: z.ZodObject<{
278
+ message: z.ZodString;
279
+ phase: z.ZodEnum<{
280
+ info: "info";
281
+ running: "running";
282
+ waiting: "waiting";
283
+ succeeded: "succeeded";
284
+ failed: "failed";
285
+ }>;
286
+ }, z.core.$strip>;
287
+ type ReportStatusToolInput = z.infer<typeof reportStatusToolInputSchema>;
288
+ type ReportStatusToolOutput = z.infer<typeof reportStatusToolOutputSchema>;
289
+ type ReportStatusToolOptions = {
290
+ description?: string;
291
+ toolName?: string;
292
+ };
293
+ type ReportStatusToolDefinition = {
294
+ description: string;
295
+ inputSchema: typeof reportStatusToolInputSchema;
296
+ outputSchema: typeof reportStatusToolOutputSchema;
297
+ execute: (input: ReportStatusToolInput) => Promise<ReportStatusToolOutput>;
298
+ };
299
+ declare function normalizeReportStatusToolInput(input: z.input<typeof reportStatusToolInputSchema>): ReportStatusToolInput;
300
+ declare function executeReportStatusTool(input: ReportStatusToolInput): Promise<ReportStatusToolOutput>;
301
+ declare function buildReportStatusToolDefinition(options?: ReportStatusToolOptions): ReportStatusToolDefinition;
302
+ declare function isReportStatusToolPart(part: {
303
+ type?: string;
304
+ }, toolName?: string): boolean;
305
+
215
306
  type RobotRockToolApprovalDecision = "user-approval" | undefined;
216
307
  /**
217
308
  * AI SDK 7+: pass the return value to `toolApproval` on `generateText`, `streamText`, or `ToolLoopAgent`.
@@ -244,4 +335,4 @@ declare function resolveToolApprovalsViaRobotRock(clientOrContext: RobotRock | R
244
335
  */
245
336
  declare function runWithRobotRockApprovals<T>(options: RunWithRobotRockApprovalsOptions<T>): Promise<T>;
246
337
 
247
- export { type ApproveByHumanToolDurableOptions as A, createRobotRockAiTriggerContext as B, type CreateSendToHumanToolOptions as C, normalizeRobotRockAiContext as D, sendToHumanForAi as E, type FormatToolApprovalTaskOptions as F, sendToHumanToolInputSchema as G, type HumanToolResult as H, sendUpdateForAi as I, sendUpdateToolInputSchema as J, type RobotRockAiWorkflowContext as R, type SendToHumanToolDefinition as S, type ToolApprovalRequestPart as T, type ApproveByHumanToolOptions as a, type ApproveByHumanToolDefinition as b, type CreateSendUpdateToolOptions as c, type SendUpdateToolDefinition as d, type CreateSendToHumanToolDurableOptions as e, type CreateSendUpdateToolDurableOptions as f, type RobotRockAiContext as g, type RobotRockAiMode as h, type RobotRockAiPollingContext as i, type RobotRockAiTriggerContext as j, applyRobotRockToolApprovalToTools as k, createRobotRockAiWorkflowContext as l, createRobotRockNeedsApproval as m, createRobotRockToolApproval as n, runWithRobotRockApprovals as o, type RobotRockToolCallInfo as p, APPROVE_BY_HUMAN_ACTIONS as q, resolveToolApprovalsViaRobotRock as r, type ResolveToolApprovalsOptions as s, type RobotRockToolApprovalConfig as t, type RobotRockToolApprovalDecision as u, type RunWithRobotRockApprovalsOptions as v, type SendUpdateToolResult as w, approveByHumanForAi as x, approveByHumanInputSchema as y, collectApprovalRequests as z };
338
+ export { normalizeRequestActionInputToolInput as $, type ApproveByHumanToolDurableOptions as A, type ReportStatusToolOutput as B, type CreateSendToHumanToolOptions as C, type RequestActionInputToolInput as D, type RequestActionInputToolOutput as E, type FormatToolApprovalTaskOptions as F, type ResolveToolApprovalsOptions as G, type HumanToolResult as H, type RobotRockToolApprovalConfig as I, type RobotRockToolApprovalDecision as J, type RunWithRobotRockApprovalsOptions as K, type SendUpdateToolResult as L, approveByHumanForAi as M, approveByHumanInputSchema as N, buildReportStatusToolDefinition as O, buildRequestActionInputToolDefinition as P, closeChatForAi as Q, type RobotRockAiWorkflowContext as R, type SendToHumanToolDefinition as S, type ToolApprovalRequestPart as T, collectApprovalRequests as U, createRobotRockAiTriggerContext as V, defaultRequestActionInputActionId as W, executeReportStatusTool as X, isReportStatusToolPart as Y, isRequestActionInputToolPart as Z, normalizeReportStatusToolInput as _, type ApproveByHumanToolOptions as a, normalizeRobotRockAiContext as a0, reportStatusPhaseSchema as a1, reportStatusToolInputSchema as a2, reportStatusToolOutputSchema as a3, requestActionInputToolInputSchema as a4, requestActionInputToolOutputSchema as a5, sendToHumanForAi as a6, sendToHumanToolInputSchema as a7, sendUpdateForAi as a8, sendUpdateToolInputSchema as a9, type ApproveByHumanToolDefinition as b, type CreateSendUpdateToolOptions as c, type SendUpdateToolDefinition as d, type RequestActionInputToolOptions as e, type RequestActionInputToolDefinition as f, type ReportStatusToolOptions as g, type ReportStatusToolDefinition as h, type CreateSendToHumanToolDurableOptions as i, type CreateSendUpdateToolDurableOptions as j, type RobotRockAiContext as k, type RobotRockAiMode as l, type RobotRockAiPollingContext as m, type RobotRockAiTriggerContext as n, applyRobotRockToolApprovalToTools as o, createRobotRockAiWorkflowContext as p, createRobotRockNeedsApproval as q, createRobotRockToolApproval as r, resolveToolApprovalsViaRobotRock as s, runWithRobotRockApprovals as t, type RobotRockToolCallInfo as u, APPROVE_BY_HUMAN_ACTIONS as v, REPORT_STATUS_TOOL_NAME as w, REQUEST_ACTION_INPUT_TOOL_NAME as x, type ReportStatusPhase as y, type ReportStatusToolInput as z };
@@ -1,9 +1,10 @@
1
1
  import * as _trigger_dev_sdk from '@trigger.dev/sdk';
2
2
  import { R as RobotRockPlatformOtelFields } from '../otel-platform-DzHyHkGk.js';
3
3
  export { a as RobotRockHandlerWebhookPayload } from '../otel-platform-DzHyHkGk.js';
4
- import { S as SendToHumanActionInput, a as SendToHumanInput } from '../client-Cy7YLxms.js';
4
+ import { S as SendToHumanActionInput, a as SendToHumanInput } from '../client-XTnFHGFE.js';
5
5
  export { ApprovalResult, DiscriminatedApprovalResult, TaskContextInput, TaskResult } from '../schemas/index.js';
6
6
  import '@opentelemetry/api';
7
+ import '@robotrock/core';
7
8
  import 'zod';
8
9
 
9
10
  type SendToHumanPayload<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]> = SendToHumanInput<A> & RobotRockPlatformOtelFields & {