robotrock 0.8.3 → 0.8.5
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.
- package/README.md +56 -0
- package/dist/ai/index.js +33 -4
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/trigger.js +33 -4
- package/dist/ai/trigger.js.map +1 -1
- package/dist/ai/workflow.js +33 -4
- package/dist/ai/workflow.js.map +1 -1
- package/dist/index.d.ts +69 -2
- package/dist/index.js +249 -2
- package/dist/index.js.map +1 -1
- package/dist/otel/index.d.ts +49 -0
- package/dist/otel/index.js +633 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/schemas/index.d.ts +56 -1
- package/dist/schemas/index.js +35 -2
- package/dist/schemas/index.js.map +1 -1
- package/dist/trigger/index.js +31 -2
- package/dist/trigger/index.js.map +1 -1
- package/dist/workflow/index.js +31 -2
- package/dist/workflow/index.js.map +1 -1
- package/package.json +10 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/agent-telemetry-from-otel.ts","../../src/schemas/index.ts","../../../core/src/utils/safe-url.ts","../../../core/src/schemas/task.ts","../../../core/src/schemas/context-urls.ts"],"sourcesContent":["import { trace } from \"@opentelemetry/api\";\nimport {\n agentTelemetrySchema,\n type AgentCost,\n type AgentOtel,\n type AgentOtelSpanSummary,\n type AgentTelemetry,\n type AgentTelemetryInput,\n} from \"./schemas/index.js\";\n\nconst AGENT_INFO_MAX_KEYS = 32;\n\nfunction sumToolCalls(toolCalls: Record<string, number>): number {\n return Object.values(toolCalls).reduce((sum, count) => sum + count, 0);\n}\n\n/** Minimal span interface — compatible with `@opentelemetry/api` Span. */\nexport type OtelSpanLike = {\n spanContext(): {\n traceId: string;\n spanId: string;\n traceFlags?: number;\n };\n};\n\nexport type OtelSpanSummaryInput = {\n name: string;\n durationMs: number;\n status: \"ok\" | \"error\";\n};\n\nexport type AgentTelemetryFromOtelOptions = {\n /** Agent or deploy version (semver, git SHA, tag). */\n version?: string;\n /** Active span; defaults to `trace.getActiveSpan()` when omitted. */\n span?: OtelSpanLike | null;\n toolCalls?: Record<string, number>;\n toolCallCount?: number;\n cost?: AgentCost;\n /** Extra keys merged into `agent.info` (e.g. model, promptVariant). */\n extraInfo?: Record<string, unknown>;\n /** Structured span tree snapshot; traceId/spanId filled from span when omitted. */\n otel?: {\n traceId?: string;\n spanId?: string;\n rootDurationMs?: number;\n spans?: OtelSpanSummaryInput[];\n };\n /** `Date.now()` at agent run start — used for `info.durationMs` when set. */\n runStartedAt?: number;\n};\n\nfunction isValidTraceId(traceId: string | undefined): traceId is string {\n return (\n typeof traceId === \"string\" &&\n traceId.length > 0 &&\n traceId !== \"00000000000000000000000000000000\"\n );\n}\n\nfunction resolveSpanContext(\n span?: OtelSpanLike | null\n): { traceId: string; spanId: string } | undefined {\n const active = span ?? trace.getActiveSpan();\n const ctx = active?.spanContext();\n if (!ctx || !isValidTraceId(ctx.traceId)) {\n return undefined;\n }\n return { traceId: ctx.traceId, spanId: ctx.spanId };\n}\n\nfunction countErrorSpans(spans: OtelSpanSummaryInput[] | undefined): number {\n if (!spans) return 0;\n return spans.filter((entry) => entry.status === \"error\").length;\n}\n\nfunction buildInfo(\n options: AgentTelemetryFromOtelOptions,\n spanCtx: { traceId: string; spanId: string } | undefined\n): Record<string, unknown> | undefined {\n const info: Record<string, unknown> = { ...options.extraInfo };\n\n if (spanCtx) {\n info.traceId = spanCtx.traceId;\n info.spanId = spanCtx.spanId;\n }\n\n if (options.runStartedAt != null) {\n const durationMs = Date.now() - options.runStartedAt;\n if (durationMs >= 0) {\n info.durationMs = durationMs;\n }\n }\n\n const errorCount = countErrorSpans(options.otel?.spans);\n if (errorCount > 0) {\n info.errorCount = errorCount;\n }\n\n const keys = Object.keys(info);\n if (keys.length === 0) {\n return undefined;\n }\n if (keys.length > AGENT_INFO_MAX_KEYS) {\n const trimmed: Record<string, unknown> = {};\n for (const key of keys.slice(0, AGENT_INFO_MAX_KEYS)) {\n trimmed[key] = info[key];\n }\n return trimmed;\n }\n return info;\n}\n\nfunction buildOtelBlock(\n options: AgentTelemetryFromOtelOptions,\n spanCtx: { traceId: string; spanId: string } | undefined\n): AgentOtel | undefined {\n const traceId = options.otel?.traceId ?? spanCtx?.traceId;\n if (!isValidTraceId(traceId)) {\n return undefined;\n }\n\n const spans = options.otel?.spans as AgentOtelSpanSummary[] | undefined;\n const rootDurationMs =\n options.otel?.rootDurationMs ??\n (options.runStartedAt != null\n ? Math.max(0, Date.now() - options.runStartedAt)\n : undefined);\n\n const block: AgentOtel = { traceId };\n const spanId = options.otel?.spanId ?? spanCtx?.spanId;\n if (spanId) {\n block.spanId = spanId;\n }\n if (rootDurationMs != null) {\n block.rootDurationMs = rootDurationMs;\n }\n if (spans && spans.length > 0) {\n block.spans = spans;\n }\n return block;\n}\n\n/**\n * Build RobotRock `agent` telemetry from the active OpenTelemetry span and\n * optional run metadata. Validates against `agentTelemetrySchema`.\n *\n * Use at `sendToHuman` time to snapshot how the agent ran before the human gate.\n * Full traces still export to your OTel collector; this compact form feeds\n * Statistics and feedback analysis.\n */\nexport function agentTelemetryFromOtel(\n options: AgentTelemetryFromOtelOptions = {}\n): AgentTelemetry {\n const spanCtx = resolveSpanContext(options.span);\n\n const telemetry: AgentTelemetryInput = {};\n\n if (options.version) {\n telemetry.version = options.version;\n }\n if (options.toolCalls && Object.keys(options.toolCalls).length > 0) {\n telemetry.toolCalls = options.toolCalls;\n }\n if (options.toolCallCount !== undefined) {\n telemetry.toolCallCount = options.toolCallCount;\n } else if (telemetry.toolCalls) {\n const sum = sumToolCalls(telemetry.toolCalls);\n if (sum > 0) {\n telemetry.toolCallCount = sum;\n }\n }\n if (options.cost) {\n telemetry.cost = options.cost;\n }\n\n const info = buildInfo(options, spanCtx);\n if (info) {\n telemetry.info = info;\n }\n\n const otel = buildOtelBlock(options, spanCtx);\n if (otel) {\n telemetry.otel = otel;\n }\n\n return agentTelemetrySchema.parse(telemetry);\n}\n\n/** Derive per-tool counts from a span summary list (by span name). */\nexport function toolCallsFromOtelSpans(\n spans: OtelSpanSummaryInput[]\n): Record<string, number> {\n const counts: Record<string, number> = {};\n for (const span of spans) {\n counts[span.name] = (counts[span.name] ?? 0) + 1;\n }\n return counts;\n}\n","import { z } from \"zod\";\nimport {\n isPublicHttpUrl,\n PUBLIC_HTTP_URL_ERROR,\n} from \"@robotrock/core/utils\";\nimport { validateContextPublicUrls } from \"@robotrock/core/schemas\";\n\nexport interface JSONSchema7 {\n $id?: string;\n $ref?: string;\n $schema?: string;\n $comment?: string;\n type?: JSONSchema7TypeName | JSONSchema7TypeName[];\n enum?: unknown[];\n const?: unknown;\n multipleOf?: number;\n maximum?: number;\n exclusiveMaximum?: number;\n minimum?: number;\n exclusiveMinimum?: number;\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n format?: string;\n items?: JSONSchema7 | JSONSchema7[];\n additionalItems?: JSONSchema7 | boolean;\n maxItems?: number;\n minItems?: number;\n uniqueItems?: boolean;\n contains?: JSONSchema7;\n maxProperties?: number;\n minProperties?: number;\n required?: string[];\n properties?: Record<string, JSONSchema7>;\n patternProperties?: Record<string, JSONSchema7>;\n additionalProperties?: JSONSchema7 | boolean;\n dependencies?: Record<string, JSONSchema7 | string[]>;\n propertyNames?: JSONSchema7;\n if?: JSONSchema7;\n then?: JSONSchema7;\n else?: JSONSchema7;\n allOf?: JSONSchema7[];\n anyOf?: JSONSchema7[];\n oneOf?: JSONSchema7[];\n not?: JSONSchema7;\n title?: string;\n description?: string;\n default?: unknown;\n readOnly?: boolean;\n writeOnly?: boolean;\n examples?: unknown[];\n}\n\nexport type JSONSchema7TypeName =\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"null\";\n\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\nconst taskContextObjectSchema = z.object({\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\nconst AGENT_TOOL_CALLS_MAX_KEYS = 64;\nexport const AGENT_OTEL_SPANS_MAX = 32;\n\nexport const agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);\n\nexport const agentOtelSpanStatusSchema = z.enum([\"ok\", \"error\"]);\n\nexport const agentOtelSpanSummarySchema = z.object({\n name: z.string().min(1),\n durationMs: z.number().nonnegative(),\n status: agentOtelSpanStatusSchema,\n});\n\nexport const agentOtelSchema = z.object({\n traceId: z.string().min(1),\n spanId: z.string().min(1).optional(),\n rootDurationMs: z.number().nonnegative().optional(),\n spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional(),\n});\n\nexport const agentTelemetrySchema = z\n .object({\n version: z.string().min(1).optional(),\n toolCallCount: nonNegativeInt.optional(),\n toolCalls: agentToolCallsSchema.optional(),\n cost: agentCostSchema.optional(),\n info: z.record(z.string(), z.unknown()).optional(),\n otel: agentOtelSchema.optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n )\n .refine(\n (data) => {\n const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];\n return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;\n },\n {\n message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`,\n }\n );\n\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;\nexport type AgentOtelSpanStatus = z.infer<typeof agentOtelSpanStatusSchema>;\nexport type AgentOtelSpanSummary = z.infer<typeof agentOtelSpanSummarySchema>;\nexport type AgentOtel = z.infer<typeof agentOtelSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n\ntype InferObjectProperties<\n Props,\n Req extends PropertyKey,\n> = Props extends Record<string, unknown>\n ? ({\n [K in keyof Props as K extends Req ? K : never]-?: InferJsonSchema7<Props[K]>;\n } & {\n [K in keyof Props as K extends Req ? never : K]?: InferJsonSchema7<Props[K]>;\n } extends infer O\n ? { [K in keyof O]: O[K] }\n : never)\n : Record<string, unknown>;\n\ntype RequiredKeys<S> =\n S extends { readonly required: readonly string[] } ? S[\"required\"][number] : never;\n\nexport type InferJsonSchema7<S> = [S] extends [undefined]\n ? Record<string, never>\n : S extends { readonly const: infer C }\n ? C\n : S extends {\n readonly enum: readonly (infer E)[];\n }\n ? E\n : S extends {\n readonly type: \"object\";\n readonly properties?: infer Props;\n }\n ? InferObjectProperties<Props, RequiredKeys<S>>\n : S extends {\n readonly type: \"object\";\n readonly properties?: undefined;\n }\n ? Record<string, unknown>\n : S extends {\n readonly type: \"array\";\n readonly items?: infer Items;\n }\n ? Items extends readonly unknown[]\n ? InferJsonSchema7<Items[number]>[]\n : Items extends object\n ? InferJsonSchema7<Items>[]\n : unknown[]\n : S extends { readonly type: \"string\" }\n ? string\n : S extends { readonly type: \"number\" } | { readonly type: \"integer\" }\n ? number\n : S extends { readonly type: \"boolean\" }\n ? boolean\n : unknown;\n\nexport type TaskStatus = \"pending\" | \"open\" | \"handled\" | \"expired\";\n\nexport interface TaskResponse {\n success: boolean;\n task: {\n taskId: string;\n threadId: string;\n status: \"pending\" | \"open\";\n context: TaskContext;\n validUntil: string;\n submittedAt: string;\n };\n message: string;\n}\n\nexport interface ThreadUpdateResponse {\n success: boolean;\n update: ThreadUpdate;\n message: string;\n}\n\nexport interface Task {\n id: string;\n threadId?: string;\n createdAt: Date;\n status: TaskStatus;\n context: TaskContext;\n validUntil: number;\n handledAt?: number;\n handled?: {\n action: {\n id: string;\n data: unknown;\n };\n handledBy?: string;\n userId?: string;\n token?: string;\n };\n}\n\nexport type InferActionData<T extends { schema?: unknown }> = [\n Exclude<T[\"schema\"], undefined>,\n] extends [\n never,\n]\n ? Record<string, never>\n : Exclude<T[\"schema\"], undefined> extends infer S\n ? InferJsonSchema7<S>\n : Record<string, never>;\n\nexport type TupleElementIndices<T extends readonly unknown[]> = T extends readonly [\n unknown,\n ...unknown[],\n]\n ? Exclude<keyof T, keyof unknown[]>\n : number;\n\nexport interface TaskResult<T = Record<string, unknown>> {\n actionId: string;\n data: T;\n handledBy?: string;\n handledAt: Date;\n}\n\nexport interface ApprovalResult<T = Record<string, unknown>> extends TaskResult<T> {\n taskId: string;\n}\n\nexport type DiscriminatedApprovalResult<\n TActions extends readonly { id: string; schema?: unknown }[],\n> = {\n [I in TupleElementIndices<TActions>]: TActions[I] extends { id: string; schema?: unknown }\n ? Omit<ApprovalResult<InferActionData<TActions[I]>>, \"actionId\" | \"data\"> & {\n actionId: TActions[I][\"id\"];\n data: InferActionData<TActions[I]>;\n }\n : never\n}[TupleElementIndices<TActions>];\n","const BLOCKED_HOSTNAMES = new Set([\n \"localhost\",\n \"metadata.google.internal\",\n \"metadata.goog\",\n]);\n\nfunction normalizeHostname(hostname: string): string {\n return hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n}\n\nfunction isBlockedIpv4(host: string): boolean {\n const match = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(host);\n if (!match) {\n return false;\n }\n\n const octets = match.slice(1, 5).map((part) => Number(part));\n if (octets.some((octet) => Number.isNaN(octet) || octet < 0 || octet > 255)) {\n return true;\n }\n\n const [a, b, _c, _d] = octets;\n if (a === undefined || b === undefined) {\n return true;\n }\n if (a === 127 || a === 0) return true;\n if (a === 10) return true;\n if (a === 169 && b === 254) return true;\n if (a === 192 && b === 168) return true;\n if (a === 172 && b >= 16 && b <= 31) return true;\n if (a === 100 && b >= 64 && b <= 127) return true;\n\n return false;\n}\n\nfunction ipv4FromNumericHost(host: string): string | null {\n if (/^\\d+$/.test(host)) {\n const num = Number(host);\n if (!Number.isFinite(num) || num < 0 || num > 0xffffffff) {\n return null;\n }\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n return `${a}.${b}.${c}.${d}`;\n }\n\n const hexMatch = /^0x([0-9a-f]{1,8})$/i.exec(host);\n if (hexMatch) {\n const num = Number.parseInt(hexMatch[1]!, 16);\n if (!Number.isFinite(num) || num < 0 || num > 0xffffffff) {\n return null;\n }\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n return `${a}.${b}.${c}.${d}`;\n }\n\n return null;\n}\n\nfunction isBlockedIpv4Mapped(host: string): boolean {\n const mappedDotted = /^::ffff:(\\d{1,3}(?:\\.\\d{1,3}){3})$/i.exec(host);\n if (mappedDotted) {\n return isBlockedIpv4(mappedDotted[1]!);\n }\n\n const mappedHex = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(host);\n if (mappedHex) {\n const high = Number.parseInt(mappedHex[1]!, 16);\n const low = Number.parseInt(mappedHex[2]!, 16);\n if (Number.isFinite(high) && Number.isFinite(low)) {\n const a = (high >> 8) & 0xff;\n const b = high & 0xff;\n const c = (low >> 8) & 0xff;\n const d = low & 0xff;\n return isBlockedIpv4(`${a}.${b}.${c}.${d}`);\n }\n }\n\n return false;\n}\n\nfunction isBlockedIpv6(host: string): boolean {\n if (host === \"::1\" || host === \"0:0:0:0:0:0:0:1\") {\n return true;\n }\n if (host.startsWith(\"fc\") || host.startsWith(\"fd\")) {\n return true;\n }\n if (host.startsWith(\"fe80:\")) {\n return true;\n }\n if (isBlockedIpv4Mapped(host)) {\n return true;\n }\n return false;\n}\n\nfunction isBlockedHostname(hostname: string): boolean {\n const host = normalizeHostname(hostname);\n if (!host) {\n return true;\n }\n if (BLOCKED_HOSTNAMES.has(host)) {\n return true;\n }\n if (host.endsWith(\".localhost\") || host.endsWith(\".local\")) {\n return true;\n }\n\n const numericIpv4 = ipv4FromNumericHost(host);\n if (numericIpv4 && isBlockedIpv4(numericIpv4)) {\n return true;\n }\n\n return isBlockedIpv4(host) || isBlockedIpv6(host);\n}\n\n/**\n * Returns true when the URL uses http(s) and targets a public, non-reserved host.\n */\nexport function isPublicHttpUrl(urlString: string): boolean {\n let url: URL;\n try {\n url = new URL(urlString);\n } catch {\n return false;\n }\n\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n return false;\n }\n if (url.username || url.password) {\n return false;\n }\n\n return !isBlockedHostname(url.hostname);\n}\n\nexport const PUBLIC_HTTP_URL_ERROR =\n \"URL must be a public http:// or https:// address\";\n\nconst FORBIDDEN_HANDLER_HEADERS = new Set([\n \"host\",\n \"connection\",\n \"content-length\",\n \"transfer-encoding\",\n \"te\",\n \"trailer\",\n \"upgrade\",\n \"proxy-authorization\",\n \"proxy-connection\",\n \"keep-alive\",\n \"x-robotrock-signature\",\n \"x-robotrock-delivery-id\",\n \"x-robotrock-delivery-attempt\",\n]);\n\n/**\n * Allow only safe custom webhook headers; blocks overrides of delivery metadata.\n */\nexport function filterHandlerHeaders(\n headers: Record<string, string> | undefined\n): Record<string, string> {\n if (!headers) {\n return {};\n }\n\n const filtered: Record<string, string> = {};\n for (const [rawKey, value] of Object.entries(headers)) {\n const key = rawKey.toLowerCase().trim();\n if (!key || FORBIDDEN_HANDLER_HEADERS.has(key)) {\n continue;\n }\n if (!/^[a-z0-9][a-z0-9._-]*$/.test(key)) {\n continue;\n }\n filtered[key] = value;\n }\n return filtered;\n}\n","import { z } from \"zod\";\nimport { isPublicHttpUrl, PUBLIC_HTTP_URL_ERROR } from \"../utils/safe-url\";\nimport { validateContextPublicUrls } from \"./context-urls\";\nimport type { JSONSchema7 } from \"./json-schema\";\n\n/**\n * Extended JSONSchema7 type that includes RJSF extensions like enumNames\n */\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\n/**\n * UI Schema for RJSF form customization\n */\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n// Helper schemas\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\n// JSONSchema7 validation\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\n// UiSchema validation\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\n// Handler schemas (per-action handlers for webhooks, triggers, etc.)\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\n// Action schema with JSONSchema-based feedback and optional handlers\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n // Optional handlers for this action - if present, must have at least 1\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\n// UI Field Schema\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\n// Context UI Schema\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\n// Context data schema\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\n// Main TaskContext schema\nconst taskContextObjectSchema = z.object({\n /** Source application id; omitted tasks are grouped in the default inbox. */\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\n/** Token usage for a single agent run (optional breakdown). */\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\n/** Monetary and token cost for a single agent run. */\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\nexport const AGENT_TOOL_CALLS_MAX_KEYS = 64;\nexport const AGENT_OTEL_SPANS_MAX = 32;\n\n/** Per-tool invocation counts keyed by tool name (e.g. `{ readFile: 3, grep: 2 }`). */\nexport const agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);\n\nexport const agentOtelSpanStatusSchema = z.enum([\"ok\", \"error\"]);\n\n/** Compact OpenTelemetry span summary for feedback analysis. */\nexport const agentOtelSpanSummarySchema = z.object({\n name: z.string().min(1),\n durationMs: z.number().nonnegative(),\n status: agentOtelSpanStatusSchema,\n});\n\n/**\n * Structured OpenTelemetry snapshot at task create (not shown in inbox UI).\n * Pair with full traces in your observability backend via `traceId`.\n */\nexport const agentOtelSchema = z.object({\n traceId: z.string().min(1),\n spanId: z.string().min(1).optional(),\n rootDurationMs: z.number().nonnegative().optional(),\n spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional(),\n});\n\n/**\n * Agent-only telemetry at task create (not shown in inbox reviewer UI).\n * Use to track version, cost, tool calls, and experiment metadata.\n */\nexport const agentTelemetrySchema = z\n .object({\n /** Agent or app version (semver, git SHA, deploy tag — caller-defined). */\n version: z.string().min(1).optional(),\n /** Total tool invocations. When omitted but `toolCalls` is set, the sum of counts is used. */\n toolCallCount: nonNegativeInt.optional(),\n /** Per-tool invocation counts keyed by tool name. */\n toolCalls: agentToolCallsSchema.optional(),\n cost: agentCostSchema.optional(),\n /** Free-form metadata for experiments (model, prompt variant, etc.). */\n info: z.record(z.string(), z.unknown()).optional(),\n /** Structured OpenTelemetry span snapshot for feedback analysis. */\n otel: agentOtelSchema.optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n )\n .refine(\n (data) => {\n const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];\n return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;\n },\n {\n message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`,\n }\n );\n\n/** Sum invocation counts from an agent.toolCalls map. */\nexport function sumAgentToolCalls(\n toolCalls: Record<string, number> | undefined\n): number {\n if (!toolCalls) return 0;\n return Object.values(toolCalls).reduce((sum, count) => sum + count, 0);\n}\n\n/** POST /v1 body: task context plus optional assignment. */\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n /** Agent telemetry (version, cost, tool calls) — not shown in inbox UI. */\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\n// Type exports\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type SafeUrl = z.infer<typeof safeUrlSchema>;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type ContextData = z.infer<typeof contextDataSchema>;\nexport type ContextUiSchema = z.infer<typeof contextUiSchema>;\nexport type UiFieldSchema = z.infer<typeof uiFieldSchemaSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;\nexport type AgentOtelSpanStatus = z.infer<typeof agentOtelSpanStatusSchema>;\nexport type AgentOtelSpanSummary = z.infer<typeof agentOtelSpanSummarySchema>;\nexport type AgentOtel = z.infer<typeof agentOtelSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n","import { isPublicHttpUrl, PUBLIC_HTTP_URL_ERROR } from \"../utils/safe-url\";\n\ntype ContextInput = {\n data?: Record<string, unknown>;\n ui?: Record<string, unknown>;\n};\n\nfunction resolveLinkUrl(value: string): string {\n return value.startsWith(\"http://\") || value.startsWith(\"https://\")\n ? value\n : `https://${value}`;\n}\n\nfunction widgetType(\n ui: Record<string, unknown> | undefined,\n field: string\n): string | undefined {\n const fieldUi = ui?.[field];\n if (typeof fieldUi !== \"object\" || fieldUi === null) {\n return undefined;\n }\n const widget = (fieldUi as Record<string, unknown>)[\"ui:widget\"];\n return typeof widget === \"string\" ? widget : undefined;\n}\n\nfunction validateUrlValue(value: unknown, widget: string): string | null {\n if (widget === \"image\" || widget === \"link\") {\n if (typeof value !== \"string\") {\n return PUBLIC_HTTP_URL_ERROR;\n }\n const url = widget === \"link\" ? resolveLinkUrl(value) : value;\n if (!isPublicHttpUrl(url)) {\n return PUBLIC_HTTP_URL_ERROR;\n }\n return null;\n }\n\n if (widget === \"attachments\" && Array.isArray(value)) {\n for (const item of value) {\n if (typeof item !== \"object\" || item === null) {\n continue;\n }\n const url = (item as { url?: unknown }).url;\n if (typeof url === \"string\" && !isPublicHttpUrl(resolveLinkUrl(url))) {\n return PUBLIC_HTTP_URL_ERROR;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Validates URL-bearing context widget values (image, link, attachments).\n * Returns an error message or null when valid.\n */\nexport function validateContextPublicUrls(\n context: ContextInput | undefined\n): string | null {\n if (!context?.data) {\n return null;\n }\n\n for (const [field, value] of Object.entries(context.data)) {\n const widget = widgetType(context.ui, field);\n if (!widget) {\n continue;\n }\n const error = validateUrlValue(value, widget);\n if (error) {\n return `context.data.${field}: ${error}`;\n }\n }\n\n return null;\n}\n"],"mappings":";AAAA,SAAS,aAAa;;;ACAtB,SAAS,KAAAA,UAAS;;;ACAlB,IAAM,oBAAoB,oBAAI,IAAI;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,kBAAkB,UAA0B;AACnD,SAAO,SAAS,YAAY,EAAE,QAAQ,YAAY,EAAE;AACtD;AAEA,SAAS,cAAc,MAAuB;AAC5C,QAAM,QAAQ,+CAA+C,KAAK,IAAI;AACtE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC;AAC3D,MAAI,OAAO,KAAK,CAAC,UAAU,OAAO,MAAM,KAAK,KAAK,QAAQ,KAAK,QAAQ,GAAG,GAAG;AAC3E,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,GAAG,GAAG,IAAI,EAAE,IAAI;AACvB,MAAI,MAAM,UAAa,MAAM,QAAW;AACtC,WAAO;AAAA,EACT;AACA,MAAI,MAAM,OAAO,MAAM,EAAG,QAAO;AACjC,MAAI,MAAM,GAAI,QAAO;AACrB,MAAI,MAAM,OAAO,MAAM,IAAK,QAAO;AACnC,MAAI,MAAM,OAAO,MAAM,IAAK,QAAO;AACnC,MAAI,MAAM,OAAO,KAAK,MAAM,KAAK,GAAI,QAAO;AAC5C,MAAI,MAAM,OAAO,KAAK,MAAM,KAAK,IAAK,QAAO;AAE7C,SAAO;AACT;AAEA,SAAS,oBAAo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C1B;AAChB,QAAM,UAAU,mBAAmB,QAAQ,IAAI;AAE/C,QAAM,YAAiC,CAAC;AAExC,MAAI,QAAQ,SAAS;AACnB,cAAU,UAAU,QAAQ;AAAA,EAC9B;AACA,MAAI,QAAQ,aAAa,OAAO,KAAK,QAAQ,SAAS,EAAE,SAAS,GAAG;AAClE,cAAU,YAAY,QAAQ;AAAA,EAChC;AACA,MAAI,QAAQ,kBAAkB,QAAW;AACvC,cAAU,gBAAgB,QAAQ;AAAA,EACpC,WAAW,UAAU,WAAW;AAC9B,UAAM,MAAM,aAAa,UAAU,SAAS;AAC5C,QAAI,MAAM,GAAG;AACX,gBAAU,gBAAgB;AAAA,IAC5B;AAAA,EACF;AACA,MAAI,QAAQ,MAAM;AAChB,cAAU,OAAO,QAAQ;AAAA,EAC3B;AAEA,QAAM,OAAO,UAAU,SAAS,OAAO;AACvC,MAAI,MAAM;AACR,cAAU,OAAO;AAAA,EACnB;AAEA,QAAM,OAAO,eAAe,SAAS,OAAO;AAC5C,MAAI,MAAM;AACR,cAAU,OAAO;AAAA,EACnB;AAEA,SAAOC,sBAAqB,MAAM,SAAS;AAC7C;AAGO,SAAS,uBACd,OACwB;AACxB,QAAM,SAAiC,CAAC;AACxC,aAAW,QAAQ,OAAO;AACxB,WAAO,KAAK,IAAI,KAAK,OAAO,KAAK,IAAI,KAAK,KAAK;AAAA,EACjD;AACA,SAAO;AACT;","names":["z","safeUrlSchema","z","jsonSchema7Schema","uiSchemaSchema","webhookHandlerSchema","triggerHandlerSchema","handlerSchema","taskActionSchema","uiFieldSchemaSchema","contextUiSchema","contextDataSchema","taskContextObjectSchema","refineContextPublicUrls","taskContextSchema","assignToSchema","threadUpdateMessageSchema","threadUpdateStatuses","threadUpdateStatusSchema","threadUpdateInputSchema","z","threadUpdateMessageSchema","threadUpdateStatusSchema","taskPriorities","taskPrioritySchema","nonNegativeInt","z","agentCostTokensSchema","agentCostSchema","AGENT_INFO_MAX_KEYS","AGENT_TOOL_CALLS_MAX_KEYS","AGENT_OTEL_SPANS_MAX","agentToolCallsSchema","agentOtelSpanStatusSchema","agentOtelSpanSummarySchema","agentOtelSchema","agentTelemetrySchema","createTaskBodySchema","taskContextObjectSchema","assignToSchema","taskPrioritySchema","threadUpdateInputSchema","refineContextPublicUrls","AGENT_INFO_MAX_KEYS","agentTelemetrySchema"]}
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -192,7 +192,33 @@ declare const agentCostSchema: z.ZodObject<{
|
|
|
192
192
|
eur: z.ZodOptional<z.ZodNumber>;
|
|
193
193
|
usd: z.ZodOptional<z.ZodNumber>;
|
|
194
194
|
}, z.core.$strip>;
|
|
195
|
+
declare const AGENT_OTEL_SPANS_MAX = 32;
|
|
195
196
|
declare const agentToolCallsSchema: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
197
|
+
declare const agentOtelSpanStatusSchema: z.ZodEnum<{
|
|
198
|
+
error: "error";
|
|
199
|
+
ok: "ok";
|
|
200
|
+
}>;
|
|
201
|
+
declare const agentOtelSpanSummarySchema: z.ZodObject<{
|
|
202
|
+
name: z.ZodString;
|
|
203
|
+
durationMs: z.ZodNumber;
|
|
204
|
+
status: z.ZodEnum<{
|
|
205
|
+
error: "error";
|
|
206
|
+
ok: "ok";
|
|
207
|
+
}>;
|
|
208
|
+
}, z.core.$strip>;
|
|
209
|
+
declare const agentOtelSchema: z.ZodObject<{
|
|
210
|
+
traceId: z.ZodString;
|
|
211
|
+
spanId: z.ZodOptional<z.ZodString>;
|
|
212
|
+
rootDurationMs: z.ZodOptional<z.ZodNumber>;
|
|
213
|
+
spans: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
214
|
+
name: z.ZodString;
|
|
215
|
+
durationMs: z.ZodNumber;
|
|
216
|
+
status: z.ZodEnum<{
|
|
217
|
+
error: "error";
|
|
218
|
+
ok: "ok";
|
|
219
|
+
}>;
|
|
220
|
+
}, z.core.$strip>>>;
|
|
221
|
+
}, z.core.$strip>;
|
|
196
222
|
declare const agentTelemetrySchema: z.ZodObject<{
|
|
197
223
|
version: z.ZodOptional<z.ZodString>;
|
|
198
224
|
toolCallCount: z.ZodOptional<z.ZodNumber>;
|
|
@@ -207,6 +233,19 @@ declare const agentTelemetrySchema: z.ZodObject<{
|
|
|
207
233
|
usd: z.ZodOptional<z.ZodNumber>;
|
|
208
234
|
}, z.core.$strip>>;
|
|
209
235
|
info: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
236
|
+
otel: z.ZodOptional<z.ZodObject<{
|
|
237
|
+
traceId: z.ZodString;
|
|
238
|
+
spanId: z.ZodOptional<z.ZodString>;
|
|
239
|
+
rootDurationMs: z.ZodOptional<z.ZodNumber>;
|
|
240
|
+
spans: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
241
|
+
name: z.ZodString;
|
|
242
|
+
durationMs: z.ZodNumber;
|
|
243
|
+
status: z.ZodEnum<{
|
|
244
|
+
error: "error";
|
|
245
|
+
ok: "ok";
|
|
246
|
+
}>;
|
|
247
|
+
}, z.core.$strip>>>;
|
|
248
|
+
}, z.core.$strip>>;
|
|
210
249
|
}, z.core.$strip>;
|
|
211
250
|
declare const createTaskBodySchema: z.ZodObject<{
|
|
212
251
|
app: z.ZodOptional<z.ZodString>;
|
|
@@ -274,6 +313,19 @@ declare const createTaskBodySchema: z.ZodObject<{
|
|
|
274
313
|
usd: z.ZodOptional<z.ZodNumber>;
|
|
275
314
|
}, z.core.$strip>>;
|
|
276
315
|
info: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
316
|
+
otel: z.ZodOptional<z.ZodObject<{
|
|
317
|
+
traceId: z.ZodString;
|
|
318
|
+
spanId: z.ZodOptional<z.ZodString>;
|
|
319
|
+
rootDurationMs: z.ZodOptional<z.ZodNumber>;
|
|
320
|
+
spans: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
321
|
+
name: z.ZodString;
|
|
322
|
+
durationMs: z.ZodNumber;
|
|
323
|
+
status: z.ZodEnum<{
|
|
324
|
+
error: "error";
|
|
325
|
+
ok: "ok";
|
|
326
|
+
}>;
|
|
327
|
+
}, z.core.$strip>>>;
|
|
328
|
+
}, z.core.$strip>>;
|
|
277
329
|
}, z.core.$strip>>;
|
|
278
330
|
}, z.core.$strip>;
|
|
279
331
|
/** POST /v1/threads/:threadId/updates body: a standalone thread update. */
|
|
@@ -318,6 +370,9 @@ type Handler = z.infer<typeof handlerSchema>;
|
|
|
318
370
|
type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;
|
|
319
371
|
type AgentCost = z.infer<typeof agentCostSchema>;
|
|
320
372
|
type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;
|
|
373
|
+
type AgentOtelSpanStatus = z.infer<typeof agentOtelSpanStatusSchema>;
|
|
374
|
+
type AgentOtelSpanSummary = z.infer<typeof agentOtelSpanSummarySchema>;
|
|
375
|
+
type AgentOtel = z.infer<typeof agentOtelSchema>;
|
|
321
376
|
type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;
|
|
322
377
|
type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;
|
|
323
378
|
type InferObjectProperties<Props, Req extends PropertyKey> = Props extends Record<string, unknown> ? ({
|
|
@@ -421,4 +476,4 @@ type DiscriminatedApprovalResult<TActions extends readonly {
|
|
|
421
476
|
} : never;
|
|
422
477
|
}[TupleElementIndices<TActions>];
|
|
423
478
|
|
|
424
|
-
export { type AgentCost, type AgentCostTokens, type AgentTelemetry, type AgentTelemetryInput, type AgentToolCalls, 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_PRIORITY_RANK, type Task, type TaskAction, type TaskContext, 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, agentCostSchema, agentCostTokensSchema, agentTelemetrySchema, agentToolCallsSchema, assignToSchema, createTaskBodySchema, taskContextSchema, taskPriorities, taskPrioritySchema, threadUpdateBodySchema, threadUpdateInputSchema, threadUpdateMessageSchema, threadUpdateStatusSchema, threadUpdateStatuses };
|
|
479
|
+
export { AGENT_OTEL_SPANS_MAX, type AgentCost, type AgentCostTokens, type AgentOtel, type AgentOtelSpanStatus, type AgentOtelSpanSummary, type AgentTelemetry, type AgentTelemetryInput, type AgentToolCalls, 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_PRIORITY_RANK, type Task, type TaskAction, type TaskContext, 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, agentCostSchema, agentCostTokensSchema, agentOtelSchema, agentOtelSpanStatusSchema, agentOtelSpanSummarySchema, agentTelemetrySchema, agentToolCallsSchema, assignToSchema, createTaskBodySchema, taskContextSchema, taskPriorities, taskPrioritySchema, threadUpdateBodySchema, threadUpdateInputSchema, threadUpdateMessageSchema, threadUpdateStatusSchema, threadUpdateStatuses };
|
package/dist/schemas/index.js
CHANGED
|
@@ -291,7 +291,20 @@ var agentCostSchema = z.object({
|
|
|
291
291
|
});
|
|
292
292
|
var AGENT_INFO_MAX_KEYS = 32;
|
|
293
293
|
var AGENT_TOOL_CALLS_MAX_KEYS = 64;
|
|
294
|
+
var AGENT_OTEL_SPANS_MAX = 32;
|
|
294
295
|
var agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);
|
|
296
|
+
var agentOtelSpanStatusSchema = z.enum(["ok", "error"]);
|
|
297
|
+
var agentOtelSpanSummarySchema = z.object({
|
|
298
|
+
name: z.string().min(1),
|
|
299
|
+
durationMs: z.number().nonnegative(),
|
|
300
|
+
status: agentOtelSpanStatusSchema
|
|
301
|
+
});
|
|
302
|
+
var agentOtelSchema = z.object({
|
|
303
|
+
traceId: z.string().min(1),
|
|
304
|
+
spanId: z.string().min(1).optional(),
|
|
305
|
+
rootDurationMs: z.number().nonnegative().optional(),
|
|
306
|
+
spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional()
|
|
307
|
+
});
|
|
295
308
|
var agentTelemetrySchema = z.object({
|
|
296
309
|
/** Agent or app version (semver, git SHA, deploy tag — caller-defined). */
|
|
297
310
|
version: z.string().min(1).optional(),
|
|
@@ -301,7 +314,9 @@ var agentTelemetrySchema = z.object({
|
|
|
301
314
|
toolCalls: agentToolCallsSchema.optional(),
|
|
302
315
|
cost: agentCostSchema.optional(),
|
|
303
316
|
/** Free-form metadata for experiments (model, prompt variant, etc.). */
|
|
304
|
-
info: z.record(z.string(), z.unknown()).optional()
|
|
317
|
+
info: z.record(z.string(), z.unknown()).optional(),
|
|
318
|
+
/** Structured OpenTelemetry span snapshot for feedback analysis. */
|
|
319
|
+
otel: agentOtelSchema.optional()
|
|
305
320
|
}).refine(
|
|
306
321
|
(data) => {
|
|
307
322
|
const keys = data.info ? Object.keys(data.info) : [];
|
|
@@ -455,13 +470,27 @@ var agentCostSchema2 = z2.object({
|
|
|
455
470
|
});
|
|
456
471
|
var AGENT_INFO_MAX_KEYS2 = 32;
|
|
457
472
|
var AGENT_TOOL_CALLS_MAX_KEYS2 = 64;
|
|
473
|
+
var AGENT_OTEL_SPANS_MAX2 = 32;
|
|
458
474
|
var agentToolCallsSchema2 = z2.record(z2.string().min(1), nonNegativeInt2);
|
|
475
|
+
var agentOtelSpanStatusSchema2 = z2.enum(["ok", "error"]);
|
|
476
|
+
var agentOtelSpanSummarySchema2 = z2.object({
|
|
477
|
+
name: z2.string().min(1),
|
|
478
|
+
durationMs: z2.number().nonnegative(),
|
|
479
|
+
status: agentOtelSpanStatusSchema2
|
|
480
|
+
});
|
|
481
|
+
var agentOtelSchema2 = z2.object({
|
|
482
|
+
traceId: z2.string().min(1),
|
|
483
|
+
spanId: z2.string().min(1).optional(),
|
|
484
|
+
rootDurationMs: z2.number().nonnegative().optional(),
|
|
485
|
+
spans: z2.array(agentOtelSpanSummarySchema2).max(AGENT_OTEL_SPANS_MAX2).optional()
|
|
486
|
+
});
|
|
459
487
|
var agentTelemetrySchema2 = z2.object({
|
|
460
488
|
version: z2.string().min(1).optional(),
|
|
461
489
|
toolCallCount: nonNegativeInt2.optional(),
|
|
462
490
|
toolCalls: agentToolCallsSchema2.optional(),
|
|
463
491
|
cost: agentCostSchema2.optional(),
|
|
464
|
-
info: z2.record(z2.string(), z2.unknown()).optional()
|
|
492
|
+
info: z2.record(z2.string(), z2.unknown()).optional(),
|
|
493
|
+
otel: agentOtelSchema2.optional()
|
|
465
494
|
}).refine(
|
|
466
495
|
(data) => {
|
|
467
496
|
const keys = data.info ? Object.keys(data.info) : [];
|
|
@@ -498,12 +527,16 @@ var createTaskBodySchema2 = taskContextObjectSchema2.extend({
|
|
|
498
527
|
}).superRefine(refineContextPublicUrls2);
|
|
499
528
|
var threadUpdateBodySchema = threadUpdateInputSchema2;
|
|
500
529
|
export {
|
|
530
|
+
AGENT_OTEL_SPANS_MAX2 as AGENT_OTEL_SPANS_MAX,
|
|
501
531
|
DEFAULT_TASK_PRIORITY,
|
|
502
532
|
DEFAULT_THREAD_UPDATE_STATUS,
|
|
503
533
|
LOWEST_TASK_PRIORITY,
|
|
504
534
|
TASK_PRIORITY_RANK,
|
|
505
535
|
agentCostSchema2 as agentCostSchema,
|
|
506
536
|
agentCostTokensSchema2 as agentCostTokensSchema,
|
|
537
|
+
agentOtelSchema2 as agentOtelSchema,
|
|
538
|
+
agentOtelSpanStatusSchema2 as agentOtelSpanStatusSchema,
|
|
539
|
+
agentOtelSpanSummarySchema2 as agentOtelSpanSummarySchema,
|
|
507
540
|
agentTelemetrySchema2 as agentTelemetrySchema,
|
|
508
541
|
agentToolCallsSchema2 as agentToolCallsSchema,
|
|
509
542
|
assignToSchema2 as assignToSchema,
|
|
@@ -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\nconst taskContextObjectSchema = z.object({\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\nconst AGENT_TOOL_CALLS_MAX_KEYS = 64;\n\nexport const agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);\n\nexport const agentTelemetrySchema = z\n .object({\n version: z.string().min(1).optional(),\n toolCallCount: nonNegativeInt.optional(),\n toolCalls: agentToolCallsSchema.optional(),\n cost: agentCostSchema.optional(),\n info: z.record(z.string(), z.unknown()).optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n )\n .refine(\n (data) => {\n const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];\n return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;\n },\n {\n message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`,\n }\n );\n\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n\ntype InferObjectProperties<\n Props,\n Req extends PropertyKey,\n> = Props extends Record<string, unknown>\n ? ({\n [K in keyof Props as K extends Req ? K : never]-?: InferJsonSchema7<Props[K]>;\n } & {\n [K in keyof Props as K extends Req ? never : K]?: InferJsonSchema7<Props[K]>;\n } extends infer O\n ? { [K in keyof O]: O[K] }\n : never)\n : Record<string, unknown>;\n\ntype RequiredKeys<S> =\n S extends { readonly required: readonly string[] } ? S[\"required\"][number] : never;\n\nexport type InferJsonSchema7<S> = [S] extends [undefined]\n ? Record<string, never>\n : S extends { readonly const: infer C }\n ? C\n : S extends {\n readonly enum: readonly (infer E)[];\n }\n ? E\n : S extends {\n readonly type: \"object\";\n readonly properties?: infer Props;\n }\n ? InferObjectProperties<Props, RequiredKeys<S>>\n : S extends {\n readonly type: \"object\";\n readonly properties?: undefined;\n }\n ? Record<string, unknown>\n : S extends {\n readonly type: \"array\";\n readonly items?: infer Items;\n }\n ? Items extends readonly unknown[]\n ? InferJsonSchema7<Items[number]>[]\n : Items extends object\n ? InferJsonSchema7<Items>[]\n : unknown[]\n : S extends { readonly type: \"string\" }\n ? string\n : S extends { readonly type: \"number\" } | { readonly type: \"integer\" }\n ? number\n : S extends { readonly type: \"boolean\" }\n ? boolean\n : unknown;\n\nexport type TaskStatus = \"pending\" | \"open\" | \"handled\" | \"expired\";\n\nexport interface TaskResponse {\n success: boolean;\n task: {\n taskId: string;\n threadId: string;\n status: \"pending\" | \"open\";\n context: TaskContext;\n validUntil: string;\n submittedAt: string;\n };\n message: string;\n}\n\nexport interface ThreadUpdateResponse {\n success: boolean;\n update: ThreadUpdate;\n message: string;\n}\n\nexport interface Task {\n id: string;\n threadId?: string;\n createdAt: Date;\n status: TaskStatus;\n context: TaskContext;\n validUntil: number;\n handledAt?: number;\n handled?: {\n action: {\n id: string;\n data: unknown;\n };\n handledBy?: string;\n userId?: string;\n token?: string;\n };\n}\n\nexport type InferActionData<T extends { schema?: unknown }> = [\n Exclude<T[\"schema\"], undefined>,\n] extends [\n never,\n]\n ? Record<string, never>\n : Exclude<T[\"schema\"], undefined> extends infer S\n ? InferJsonSchema7<S>\n : Record<string, never>;\n\nexport type TupleElementIndices<T extends readonly unknown[]> = T extends readonly [\n unknown,\n ...unknown[],\n]\n ? Exclude<keyof T, keyof unknown[]>\n : number;\n\nexport interface TaskResult<T = Record<string, unknown>> {\n actionId: string;\n data: T;\n handledBy?: string;\n handledAt: Date;\n}\n\nexport interface ApprovalResult<T = Record<string, unknown>> extends TaskResult<T> {\n taskId: string;\n}\n\nexport type DiscriminatedApprovalResult<\n TActions extends readonly { id: string; schema?: unknown }[],\n> = {\n [I in TupleElementIndices<TActions>]: TActions[I] extends { id: string; schema?: unknown }\n ? Omit<ApprovalResult<InferActionData<TActions[I]>>, \"actionId\" | \"data\"> & {\n actionId: TActions[I][\"id\"];\n data: InferActionData<TActions[I]>;\n }\n : never\n}[TupleElementIndices<TActions>];\n","const BLOCKED_HOSTNAMES = new Set([\n \"localhost\",\n \"metadata.google.internal\",\n \"metadata.goog\",\n]);\n\nfunction normalizeHostname(hostname: string): string {\n return hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n}\n\nfunction isBlockedIpv4(host: string): boolean {\n const match = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(host);\n if (!match) {\n return false;\n }\n\n const octets = match.slice(1, 5).map((part) => Number(part));\n if (octets.some((octet) => Number.isNaN(octet) || octet < 0 || octet > 255)) {\n return true;\n }\n\n const [a, b, _c, _d] = octets;\n if (a === undefined || b === undefined) {\n return true;\n }\n if (a === 127 || a === 0) return true;\n if (a === 10) return true;\n if (a === 169 && b === 254) return true;\n if (a === 192 && b === 168) return true;\n if (a === 172 && b >= 16 && b <= 31) return true;\n if (a === 100 && b >= 64 && b <= 127) return true;\n\n return false;\n}\n\nfunction ipv4FromNumericHost(host: string): string | null {\n if (/^\\d+$/.test(host)) {\n const num = Number(host);\n if (!Number.isFinite(num) || num < 0 || num > 0xffffffff) {\n return null;\n }\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n return `${a}.${b}.${c}.${d}`;\n }\n\n const hexMatch = /^0x([0-9a-f]{1,8})$/i.exec(host);\n if (hexMatch) {\n const num = Number.parseInt(hexMatch[1]!, 16);\n if (!Number.isFinite(num) || num < 0 || num > 0xffffffff) {\n return null;\n }\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n return `${a}.${b}.${c}.${d}`;\n }\n\n return null;\n}\n\nfunction isBlockedIpv4Mapped(host: string): boolean {\n const mappedDotted = /^::ffff:(\\d{1,3}(?:\\.\\d{1,3}){3})$/i.exec(host);\n if (mappedDotted) {\n return isBlockedIpv4(mappedDotted[1]!);\n }\n\n const mappedHex = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(host);\n if (mappedHex) {\n const high = Number.parseInt(mappedHex[1]!, 16);\n const low = Number.parseInt(mappedHex[2]!, 16);\n if (Number.isFinite(high) && Number.isFinite(low)) {\n const a = (high >> 8) & 0xff;\n const b = high & 0xff;\n const c = (low >> 8) & 0xff;\n const d = low & 0xff;\n return isBlockedIpv4(`${a}.${b}.${c}.${d}`);\n }\n }\n\n return false;\n}\n\nfunction isBlockedIpv6(host: string): boolean {\n if (host === \"::1\" || host === \"0:0:0:0:0:0:0:1\") {\n return true;\n }\n if (host.startsWith(\"fc\") || host.startsWith(\"fd\")) {\n return true;\n }\n if (host.startsWith(\"fe80:\")) {\n return true;\n }\n if (isBlockedIpv4Mapped(host)) {\n return true;\n }\n return false;\n}\n\nfunction isBlockedHostname(hostname: string): boolean {\n const host = normalizeHostname(hostname);\n if (!host) {\n return true;\n }\n if (BLOCKED_HOSTNAMES.has(host)) {\n return true;\n }\n if (host.endsWith(\".localhost\") || host.endsWith(\".local\")) {\n return true;\n }\n\n const numericIpv4 = ipv4FromNumericHost(host);\n if (numericIpv4 && isBlockedIpv4(numericIpv4)) {\n return true;\n }\n\n return isBlockedIpv4(host) || isBlockedIpv6(host);\n}\n\n/**\n * Returns true when the URL uses http(s) and targets a public, non-reserved host.\n */\nexport function isPublicHttpUrl(urlString: string): boolean {\n let url: URL;\n try {\n url = new URL(urlString);\n } catch {\n return false;\n }\n\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n return false;\n }\n if (url.username || url.password) {\n return false;\n }\n\n return !isBlockedHostname(url.hostname);\n}\n\nexport const PUBLIC_HTTP_URL_ERROR =\n \"URL must be a public http:// or https:// address\";\n\nconst FORBIDDEN_HANDLER_HEADERS = new Set([\n \"host\",\n \"connection\",\n \"content-length\",\n \"transfer-encoding\",\n \"te\",\n \"trailer\",\n \"upgrade\",\n \"proxy-authorization\",\n \"proxy-connection\",\n \"keep-alive\",\n \"x-robotrock-signature\",\n \"x-robotrock-delivery-id\",\n \"x-robotrock-delivery-attempt\",\n]);\n\n/**\n * Allow only safe custom webhook headers; blocks overrides of delivery metadata.\n */\nexport function filterHandlerHeaders(\n headers: Record<string, string> | undefined\n): Record<string, string> {\n if (!headers) {\n return {};\n }\n\n const filtered: Record<string, string> = {};\n for (const [rawKey, value] of Object.entries(headers)) {\n const key = rawKey.toLowerCase().trim();\n if (!key || FORBIDDEN_HANDLER_HEADERS.has(key)) {\n continue;\n }\n if (!/^[a-z0-9][a-z0-9._-]*$/.test(key)) {\n continue;\n }\n filtered[key] = value;\n }\n return filtered;\n}\n","import { z } from \"zod\";\nimport { isPublicHttpUrl, PUBLIC_HTTP_URL_ERROR } from \"../utils/safe-url\";\nimport { validateContextPublicUrls } from \"./context-urls\";\nimport type { JSONSchema7 } from \"./json-schema\";\n\n/**\n * Extended JSONSchema7 type that includes RJSF extensions like enumNames\n */\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\n/**\n * UI Schema for RJSF form customization\n */\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n// Helper schemas\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\n// JSONSchema7 validation\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\n// UiSchema validation\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\n// Handler schemas (per-action handlers for webhooks, triggers, etc.)\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\n// Action schema with JSONSchema-based feedback and optional handlers\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n // Optional handlers for this action - if present, must have at least 1\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\n// UI Field Schema\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\n// Context UI Schema\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\n// Context data schema\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\n// Main TaskContext schema\nconst taskContextObjectSchema = z.object({\n /** Source application id; omitted tasks are grouped in the default inbox. */\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\n/** Token usage for a single agent run (optional breakdown). */\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\n/** Monetary and token cost for a single agent run. */\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\nexport const AGENT_TOOL_CALLS_MAX_KEYS = 64;\n\n/** Per-tool invocation counts keyed by tool name (e.g. `{ readFile: 3, grep: 2 }`). */\nexport const agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);\n\n/**\n * Agent-only telemetry at task create (not shown in inbox reviewer UI).\n * Use to track version, cost, tool calls, and experiment metadata.\n */\nexport const agentTelemetrySchema = z\n .object({\n /** Agent or app version (semver, git SHA, deploy tag — caller-defined). */\n version: z.string().min(1).optional(),\n /** Total tool invocations. When omitted but `toolCalls` is set, the sum of counts is used. */\n toolCallCount: nonNegativeInt.optional(),\n /** Per-tool invocation counts keyed by tool name. */\n toolCalls: agentToolCallsSchema.optional(),\n cost: agentCostSchema.optional(),\n /** Free-form metadata for experiments (model, prompt variant, etc.). */\n info: z.record(z.string(), z.unknown()).optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n )\n .refine(\n (data) => {\n const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];\n return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;\n },\n {\n message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`,\n }\n );\n\n/** Sum invocation counts from an agent.toolCalls map. */\nexport function sumAgentToolCalls(\n toolCalls: Record<string, number> | undefined\n): number {\n if (!toolCalls) return 0;\n return Object.values(toolCalls).reduce((sum, count) => sum + count, 0);\n}\n\n/** POST /v1 body: task context plus optional assignment. */\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n /** Agent telemetry (version, cost, tool calls) — not shown in inbox UI. */\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\n// Type exports\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type SafeUrl = z.infer<typeof safeUrlSchema>;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type ContextData = z.infer<typeof contextDataSchema>;\nexport type ContextUiSchema = z.infer<typeof contextUiSchema>;\nexport type UiFieldSchema = z.infer<typeof uiFieldSchemaSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n","import { isPublicHttpUrl, PUBLIC_HTTP_URL_ERROR } from \"../utils/safe-url\";\n\ntype ContextInput = {\n data?: Record<string, unknown>;\n ui?: Record<string, unknown>;\n};\n\nfunction resolveLinkUrl(value: string): string {\n return value.startsWith(\"http://\") || value.startsWith(\"https://\")\n ? value\n : `https://${value}`;\n}\n\nfunction widgetType(\n ui: Record<string, unknown> | undefined,\n field: string\n): string | undefined {\n const fieldUi = ui?.[field];\n if (typeof fieldUi !== \"object\" || fieldUi === null) {\n return undefined;\n }\n const widget = (fieldUi as Record<string, unknown>)[\"ui:widget\"];\n return typeof widget === \"string\" ? widget : undefined;\n}\n\nfunction validateUrlValue(value: unknown, widget: string): string | null {\n if (widget === \"image\" || widget === \"link\") {\n if (typeof value !== \"string\") {\n return PUBLIC_HTTP_URL_ERROR;\n }\n const url = widget === \"link\" ? resolveLinkUrl(value) : value;\n if (!isPublicHttpUrl(url)) {\n return PUBLIC_HTTP_URL_ERROR;\n }\n return null;\n }\n\n if (widget === \"attachments\" && Array.isArray(value)) {\n for (const item of value) {\n if (typeof item !== \"object\" || item === null) {\n continue;\n }\n const url = (item as { url?: unknown }).url;\n if (typeof url === \"string\" && !isPublicHttpUrl(resolveLinkUrl(url))) {\n return PUBLIC_HTTP_URL_ERROR;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Validates URL-bearing context widget values (image, link, attachments).\n * Returns an error message or null when valid.\n */\nexport function validateContextPublicUrls(\n context: ContextInput | undefined\n): string | null {\n if (!context?.data) {\n return null;\n }\n\n for (const [field, value] of Object.entries(context.data)) {\n const widget = widgetType(context.ui, field);\n if (!widget) {\n continue;\n }\n const error = validateUrlValue(value, widget);\n if (error) {\n return `context.data.${field}: ${error}`;\n }\n }\n\n return null;\n}\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACAlB,IAAM,oBAAoB,oBAAI,IAAI;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,kBAAkB,UAA0B;AACnD,SAAO,SAAS,YAAY,EAAE,QAAQ,YAAY,EAAE;AACtD;AAEA,SAAS,cAAc,MAAuB;AAC5C,QAAM,QAAQ,+CAA+C,KAAK,IAAI;AACtE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC;AAC3D,MAAI,OAAO,KAAK,CAAC,UAAU,OAAO,MAAM,KAAK,KAAK,QAAQ,KAAK,QA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B,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtC,QAAQF,yBAAwB,SAAS;AAAA,EACzC,OAAOS,sBAAqB,SAAS;AACvC,CAAC,EACA,YAAYf,wBAAuB;AAG/B,IAAM,yBAAyBM;","names":["z","safeUrlSchema","z","jsonSchema7Schema","uiSchemaSchema","webhookHandlerSchema","triggerHandlerSchema","handlerSchema","taskActionSchema","uiFieldSchemaSchema","contextUiSchema","contextDataSchema","taskContextObjectSchema","refineContextPublicUrls","taskContextSchema","assignToSchema","threadUpdateMessageSchema","threadUpdateStatuses","threadUpdateStatusSchema","threadUpdateInputSchema","taskPriorities","taskPrioritySchema","nonNegativeInt","agentCostTokensSchema","agentCostSchema","AGENT_INFO_MAX_KEYS","AGENT_TOOL_CALLS_MAX_KEYS","agentToolCallsSchema","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 isPublicHttpUrl,\n PUBLIC_HTTP_URL_ERROR,\n} from \"@robotrock/core/utils\";\nimport { validateContextPublicUrls } from \"@robotrock/core/schemas\";\n\nexport interface JSONSchema7 {\n $id?: string;\n $ref?: string;\n $schema?: string;\n $comment?: string;\n type?: JSONSchema7TypeName | JSONSchema7TypeName[];\n enum?: unknown[];\n const?: unknown;\n multipleOf?: number;\n maximum?: number;\n exclusiveMaximum?: number;\n minimum?: number;\n exclusiveMinimum?: number;\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n format?: string;\n items?: JSONSchema7 | JSONSchema7[];\n additionalItems?: JSONSchema7 | boolean;\n maxItems?: number;\n minItems?: number;\n uniqueItems?: boolean;\n contains?: JSONSchema7;\n maxProperties?: number;\n minProperties?: number;\n required?: string[];\n properties?: Record<string, JSONSchema7>;\n patternProperties?: Record<string, JSONSchema7>;\n additionalProperties?: JSONSchema7 | boolean;\n dependencies?: Record<string, JSONSchema7 | string[]>;\n propertyNames?: JSONSchema7;\n if?: JSONSchema7;\n then?: JSONSchema7;\n else?: JSONSchema7;\n allOf?: JSONSchema7[];\n anyOf?: JSONSchema7[];\n oneOf?: JSONSchema7[];\n not?: JSONSchema7;\n title?: string;\n description?: string;\n default?: unknown;\n readOnly?: boolean;\n writeOnly?: boolean;\n examples?: unknown[];\n}\n\nexport type JSONSchema7TypeName =\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"null\";\n\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\nconst taskContextObjectSchema = z.object({\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\nconst AGENT_TOOL_CALLS_MAX_KEYS = 64;\nexport const AGENT_OTEL_SPANS_MAX = 32;\n\nexport const agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);\n\nexport const agentOtelSpanStatusSchema = z.enum([\"ok\", \"error\"]);\n\nexport const agentOtelSpanSummarySchema = z.object({\n name: z.string().min(1),\n durationMs: z.number().nonnegative(),\n status: agentOtelSpanStatusSchema,\n});\n\nexport const agentOtelSchema = z.object({\n traceId: z.string().min(1),\n spanId: z.string().min(1).optional(),\n rootDurationMs: z.number().nonnegative().optional(),\n spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional(),\n});\n\nexport const agentTelemetrySchema = z\n .object({\n version: z.string().min(1).optional(),\n toolCallCount: nonNegativeInt.optional(),\n toolCalls: agentToolCallsSchema.optional(),\n cost: agentCostSchema.optional(),\n info: z.record(z.string(), z.unknown()).optional(),\n otel: agentOtelSchema.optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n )\n .refine(\n (data) => {\n const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];\n return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;\n },\n {\n message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`,\n }\n );\n\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;\nexport type AgentOtelSpanStatus = z.infer<typeof agentOtelSpanStatusSchema>;\nexport type AgentOtelSpanSummary = z.infer<typeof agentOtelSpanSummarySchema>;\nexport type AgentOtel = z.infer<typeof agentOtelSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n\ntype InferObjectProperties<\n Props,\n Req extends PropertyKey,\n> = Props extends Record<string, unknown>\n ? ({\n [K in keyof Props as K extends Req ? K : never]-?: InferJsonSchema7<Props[K]>;\n } & {\n [K in keyof Props as K extends Req ? never : K]?: InferJsonSchema7<Props[K]>;\n } extends infer O\n ? { [K in keyof O]: O[K] }\n : never)\n : Record<string, unknown>;\n\ntype RequiredKeys<S> =\n S extends { readonly required: readonly string[] } ? S[\"required\"][number] : never;\n\nexport type InferJsonSchema7<S> = [S] extends [undefined]\n ? Record<string, never>\n : S extends { readonly const: infer C }\n ? C\n : S extends {\n readonly enum: readonly (infer E)[];\n }\n ? E\n : S extends {\n readonly type: \"object\";\n readonly properties?: infer Props;\n }\n ? InferObjectProperties<Props, RequiredKeys<S>>\n : S extends {\n readonly type: \"object\";\n readonly properties?: undefined;\n }\n ? Record<string, unknown>\n : S extends {\n readonly type: \"array\";\n readonly items?: infer Items;\n }\n ? Items extends readonly unknown[]\n ? InferJsonSchema7<Items[number]>[]\n : Items extends object\n ? InferJsonSchema7<Items>[]\n : unknown[]\n : S extends { readonly type: \"string\" }\n ? string\n : S extends { readonly type: \"number\" } | { readonly type: \"integer\" }\n ? number\n : S extends { readonly type: \"boolean\" }\n ? boolean\n : unknown;\n\nexport type TaskStatus = \"pending\" | \"open\" | \"handled\" | \"expired\";\n\nexport interface TaskResponse {\n success: boolean;\n task: {\n taskId: string;\n threadId: string;\n status: \"pending\" | \"open\";\n context: TaskContext;\n validUntil: string;\n submittedAt: string;\n };\n message: string;\n}\n\nexport interface ThreadUpdateResponse {\n success: boolean;\n update: ThreadUpdate;\n message: string;\n}\n\nexport interface Task {\n id: string;\n threadId?: string;\n createdAt: Date;\n status: TaskStatus;\n context: TaskContext;\n validUntil: number;\n handledAt?: number;\n handled?: {\n action: {\n id: string;\n data: unknown;\n };\n handledBy?: string;\n userId?: string;\n token?: string;\n };\n}\n\nexport type InferActionData<T extends { schema?: unknown }> = [\n Exclude<T[\"schema\"], undefined>,\n] extends [\n never,\n]\n ? Record<string, never>\n : Exclude<T[\"schema\"], undefined> extends infer S\n ? InferJsonSchema7<S>\n : Record<string, never>;\n\nexport type TupleElementIndices<T extends readonly unknown[]> = T extends readonly [\n unknown,\n ...unknown[],\n]\n ? Exclude<keyof T, keyof unknown[]>\n : number;\n\nexport interface TaskResult<T = Record<string, unknown>> {\n actionId: string;\n data: T;\n handledBy?: string;\n handledAt: Date;\n}\n\nexport interface ApprovalResult<T = Record<string, unknown>> extends TaskResult<T> {\n taskId: string;\n}\n\nexport type DiscriminatedApprovalResult<\n TActions extends readonly { id: string; schema?: unknown }[],\n> = {\n [I in TupleElementIndices<TActions>]: TActions[I] extends { id: string; schema?: unknown }\n ? Omit<ApprovalResult<InferActionData<TActions[I]>>, \"actionId\" | \"data\"> & {\n actionId: TActions[I][\"id\"];\n data: InferActionData<TActions[I]>;\n }\n : never\n}[TupleElementIndices<TActions>];\n","const BLOCKED_HOSTNAMES = new Set([\n \"localhost\",\n \"metadata.google.internal\",\n \"metadata.goog\",\n]);\n\nfunction normalizeHostname(hostname: string): string {\n return hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n}\n\nfunction isBlockedIpv4(host: string): boolean {\n const match = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(host);\n if (!match) {\n return false;\n }\n\n const octets = match.slice(1, 5).map((part) => Number(part));\n if (octets.some((octet) => Number.isNaN(octet) || octet < 0 || octet > 255)) {\n return true;\n }\n\n const [a, b, _c, _d] = octets;\n if (a === undefined || b === undefined) {\n return true;\n }\n if (a === 127 || a === 0) return true;\n if (a === 10) return true;\n if (a === 169 && b === 254) return true;\n if (a === 192 && b === 168) return true;\n if (a === 172 && b >= 16 && b <= 31) return true;\n if (a === 100 && b >= 64 && b <= 127) return true;\n\n return false;\n}\n\nfunction ipv4FromNumericHost(host: string): string | null {\n if (/^\\d+$/.test(host)) {\n const num = Number(host);\n if (!Number.isFinite(num) || num < 0 || num > 0xffffffff) {\n return null;\n }\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n return `${a}.${b}.${c}.${d}`;\n }\n\n const hexMatch = /^0x([0-9a-f]{1,8})$/i.exec(host);\n if (hexMatch) {\n const num = Number.parseInt(hexMatch[1]!, 16);\n if (!Number.isFinite(num) || num < 0 || num > 0xffffffff) {\n return null;\n }\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n return `${a}.${b}.${c}.${d}`;\n }\n\n return null;\n}\n\nfunction isBlockedIpv4Mapped(host: string): boolean {\n const mappedDotted = /^::ffff:(\\d{1,3}(?:\\.\\d{1,3}){3})$/i.exec(host);\n if (mappedDotted) {\n return isBlockedIpv4(mappedDotted[1]!);\n }\n\n const mappedHex = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(host);\n if (mappedHex) {\n const high = Number.parseInt(mappedHex[1]!, 16);\n const low = Number.parseInt(mappedHex[2]!, 16);\n if (Number.isFinite(high) && Number.isFinite(low)) {\n const a = (high >> 8) & 0xff;\n const b = high & 0xff;\n const c = (low >> 8) & 0xff;\n const d = low & 0xff;\n return isBlockedIpv4(`${a}.${b}.${c}.${d}`);\n }\n }\n\n return false;\n}\n\nfunction isBlockedIpv6(host: string): boolean {\n if (host === \"::1\" || host === \"0:0:0:0:0:0:0:1\") {\n return true;\n }\n if (host.startsWith(\"fc\") || host.startsWith(\"fd\")) {\n return true;\n }\n if (host.startsWith(\"fe80:\")) {\n return true;\n }\n if (isBlockedIpv4Mapped(host)) {\n return true;\n }\n return false;\n}\n\nfunction isBlockedHostname(hostname: string): boolean {\n const host = normalizeHostname(hostname);\n if (!host) {\n return true;\n }\n if (BLOCKED_HOSTNAMES.has(host)) {\n return true;\n }\n if (host.endsWith(\".localhost\") || host.endsWith(\".local\")) {\n return true;\n }\n\n const numericIpv4 = ipv4FromNumericHost(host);\n if (numericIpv4 && isBlockedIpv4(numericIpv4)) {\n return true;\n }\n\n return isBlockedIpv4(host) || isBlockedIpv6(host);\n}\n\n/**\n * Returns true when the URL uses http(s) and targets a public, non-reserved host.\n */\nexport function isPublicHttpUrl(urlString: string): boolean {\n let url: URL;\n try {\n url = new URL(urlString);\n } catch {\n return false;\n }\n\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n return false;\n }\n if (url.username || url.password) {\n return false;\n }\n\n return !isBlockedHostname(url.hostname);\n}\n\nexport const PUBLIC_HTTP_URL_ERROR =\n \"URL must be a public http:// or https:// address\";\n\nconst FORBIDDEN_HANDLER_HEADERS = new Set([\n \"host\",\n \"connection\",\n \"content-length\",\n \"transfer-encoding\",\n \"te\",\n \"trailer\",\n \"upgrade\",\n \"proxy-authorization\",\n \"proxy-connection\",\n \"keep-alive\",\n \"x-robotrock-signature\",\n \"x-robotrock-delivery-id\",\n \"x-robotrock-delivery-attempt\",\n]);\n\n/**\n * Allow only safe custom webhook headers; blocks overrides of delivery metadata.\n */\nexport function filterHandlerHeaders(\n headers: Record<string, string> | undefined\n): Record<string, string> {\n if (!headers) {\n return {};\n }\n\n const filtered: Record<string, string> = {};\n for (const [rawKey, value] of Object.entries(headers)) {\n const key = rawKey.toLowerCase().trim();\n if (!key || FORBIDDEN_HANDLER_HEADERS.has(key)) {\n continue;\n }\n if (!/^[a-z0-9][a-z0-9._-]*$/.test(key)) {\n continue;\n }\n filtered[key] = value;\n }\n return filtered;\n}\n","import { z } from \"zod\";\nimport { isPublicHttpUrl, PUBLIC_HTTP_URL_ERROR } from \"../utils/safe-url\";\nimport { validateContextPublicUrls } from \"./context-urls\";\nimport type { JSONSchema7 } from \"./json-schema\";\n\n/**\n * Extended JSONSchema7 type that includes RJSF extensions like enumNames\n */\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\n/**\n * UI Schema for RJSF form customization\n */\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n// Helper schemas\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\n// JSONSchema7 validation\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\n// UiSchema validation\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\n// Handler schemas (per-action handlers for webhooks, triggers, etc.)\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\n// Action schema with JSONSchema-based feedback and optional handlers\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n // Optional handlers for this action - if present, must have at least 1\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\n// UI Field Schema\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\n// Context UI Schema\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\n// Context data schema\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\n// Main TaskContext schema\nconst taskContextObjectSchema = z.object({\n /** Source application id; omitted tasks are grouped in the default inbox. */\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\n/** Token usage for a single agent run (optional breakdown). */\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\n/** Monetary and token cost for a single agent run. */\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\nexport const AGENT_TOOL_CALLS_MAX_KEYS = 64;\nexport const AGENT_OTEL_SPANS_MAX = 32;\n\n/** Per-tool invocation counts keyed by tool name (e.g. `{ readFile: 3, grep: 2 }`). */\nexport const agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);\n\nexport const agentOtelSpanStatusSchema = z.enum([\"ok\", \"error\"]);\n\n/** Compact OpenTelemetry span summary for feedback analysis. */\nexport const agentOtelSpanSummarySchema = z.object({\n name: z.string().min(1),\n durationMs: z.number().nonnegative(),\n status: agentOtelSpanStatusSchema,\n});\n\n/**\n * Structured OpenTelemetry snapshot at task create (not shown in inbox UI).\n * Pair with full traces in your observability backend via `traceId`.\n */\nexport const agentOtelSchema = z.object({\n traceId: z.string().min(1),\n spanId: z.string().min(1).optional(),\n rootDurationMs: z.number().nonnegative().optional(),\n spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional(),\n});\n\n/**\n * Agent-only telemetry at task create (not shown in inbox reviewer UI).\n * Use to track version, cost, tool calls, and experiment metadata.\n */\nexport const agentTelemetrySchema = z\n .object({\n /** Agent or app version (semver, git SHA, deploy tag — caller-defined). */\n version: z.string().min(1).optional(),\n /** Total tool invocations. When omitted but `toolCalls` is set, the sum of counts is used. */\n toolCallCount: nonNegativeInt.optional(),\n /** Per-tool invocation counts keyed by tool name. */\n toolCalls: agentToolCallsSchema.optional(),\n cost: agentCostSchema.optional(),\n /** Free-form metadata for experiments (model, prompt variant, etc.). */\n info: z.record(z.string(), z.unknown()).optional(),\n /** Structured OpenTelemetry span snapshot for feedback analysis. */\n otel: agentOtelSchema.optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n )\n .refine(\n (data) => {\n const keys = data.toolCalls ? Object.keys(data.toolCalls) : [];\n return keys.length <= AGENT_TOOL_CALLS_MAX_KEYS;\n },\n {\n message: `agent.toolCalls may contain at most ${AGENT_TOOL_CALLS_MAX_KEYS} tool names`,\n }\n );\n\n/** Sum invocation counts from an agent.toolCalls map. */\nexport function sumAgentToolCalls(\n toolCalls: Record<string, number> | undefined\n): number {\n if (!toolCalls) return 0;\n return Object.values(toolCalls).reduce((sum, count) => sum + count, 0);\n}\n\n/** POST /v1 body: task context plus optional assignment. */\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n /** Agent telemetry (version, cost, tool calls) — not shown in inbox UI. */\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\n// Type exports\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type SafeUrl = z.infer<typeof safeUrlSchema>;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type ContextData = z.infer<typeof contextDataSchema>;\nexport type ContextUiSchema = z.infer<typeof contextUiSchema>;\nexport type UiFieldSchema = z.infer<typeof uiFieldSchemaSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentToolCalls = z.infer<typeof agentToolCallsSchema>;\nexport type AgentOtelSpanStatus = z.infer<typeof agentOtelSpanStatusSchema>;\nexport type AgentOtelSpanSummary = z.infer<typeof agentOtelSpanSummarySchema>;\nexport type AgentOtel = z.infer<typeof agentOtelSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n","import { isPublicHttpUrl, PUBLIC_HTTP_URL_ERROR } from \"../utils/safe-url\";\n\ntype ContextInput = {\n data?: Record<string, unknown>;\n ui?: Record<string, unknown>;\n};\n\nfunction resolveLinkUrl(value: string): string {\n return value.startsWith(\"http://\") || value.startsWith(\"https://\")\n ? value\n : `https://${value}`;\n}\n\nfunction widgetType(\n ui: Record<string, unknown> | undefined,\n field: string\n): string | undefined {\n const fieldUi = ui?.[field];\n if (typeof fieldUi !== \"object\" || fieldUi === null) {\n return undefined;\n }\n const widget = (fieldUi as Record<string, unknown>)[\"ui:widget\"];\n return typeof widget === \"string\" ? widget : undefined;\n}\n\nfunction validateUrlValue(value: unknown, widget: string): string | null {\n if (widget === \"image\" || widget === \"link\") {\n if (typeof value !== \"string\") {\n return PUBLIC_HTTP_URL_ERROR;\n }\n const url = widget === \"link\" ? resolveLinkUrl(value) : value;\n if (!isPublicHttpUrl(url)) {\n return PUBLIC_HTTP_URL_ERROR;\n }\n return null;\n }\n\n if (widget === \"attachments\" && Array.isArray(value)) {\n for (const item of value) {\n if (typeof item !== \"object\" || item === null) {\n continue;\n }\n const url = (item as { url?: unknown }).url;\n if (typeof url === \"string\" && !isPublicHttpUrl(resolveLinkUrl(url))) {\n return PUBLIC_HTTP_URL_ERROR;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Validates URL-bearing context widget values (image, link, attachments).\n * Returns an error message or null when valid.\n */\nexport function validateContextPublicUrls(\n context: ContextInput | undefined\n): string | null {\n if (!context?.data) {\n return null;\n }\n\n for (const [field, value] of Object.entries(context.data)) {\n const widget = widgetType(context.ui, field);\n if (!widget) {\n continue;\n }\n const error = validateUrlValue(value, widget);\n if (error) {\n return `context.data.${field}: ${error}`;\n }\n }\n\n return null;\n}\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACAlB,IAAM,oBAAoB,oBAAI,IAAI;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,kBAAkB,UAA0B;AACnD,SAAO,SAAS,YAAY,EAAE,QAAQ,YAAY,EAAE;AACtD;AAEA,SAAS,cAAc,MAAuB;AAC5C,QAAM,QAAQ,+CAA+C,KAAK,IAAI;AACtE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC;AAC3D,MAAI,OAAO,KAAK,CAAC,UAAU,OAAO,MAAM,KAAK,KA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AqB,SAAS;AACvC,CAAC,EACA,YAAYnB,wBAAuB;AAG/B,IAAM,yBAAyBM;","names":["z","safeUrlSchema","z","jsonSchema7Schema","uiSchemaSchema","webhookHandlerSchema","triggerHandlerSchema","handlerSchema","taskActionSchema","uiFieldSchemaSchema","contextUiSchema","contextDataSchema","taskContextObjectSchema","refineContextPublicUrls","taskContextSchema","assignToSchema","threadUpdateMessageSchema","threadUpdateStatuses","threadUpdateStatusSchema","threadUpdateInputSchema","taskPriorities","taskPrioritySchema","nonNegativeInt","agentCostTokensSchema","agentCostSchema","AGENT_INFO_MAX_KEYS","AGENT_TOOL_CALLS_MAX_KEYS","AGENT_OTEL_SPANS_MAX","agentToolCallsSchema","agentOtelSpanStatusSchema","agentOtelSpanSummarySchema","agentOtelSchema","agentTelemetrySchema","createTaskBodySchema"]}
|
package/dist/trigger/index.js
CHANGED
|
@@ -294,7 +294,20 @@ var agentCostSchema = z.object({
|
|
|
294
294
|
});
|
|
295
295
|
var AGENT_INFO_MAX_KEYS = 32;
|
|
296
296
|
var AGENT_TOOL_CALLS_MAX_KEYS = 64;
|
|
297
|
+
var AGENT_OTEL_SPANS_MAX = 32;
|
|
297
298
|
var agentToolCallsSchema = z.record(z.string().min(1), nonNegativeInt);
|
|
299
|
+
var agentOtelSpanStatusSchema = z.enum(["ok", "error"]);
|
|
300
|
+
var agentOtelSpanSummarySchema = z.object({
|
|
301
|
+
name: z.string().min(1),
|
|
302
|
+
durationMs: z.number().nonnegative(),
|
|
303
|
+
status: agentOtelSpanStatusSchema
|
|
304
|
+
});
|
|
305
|
+
var agentOtelSchema = z.object({
|
|
306
|
+
traceId: z.string().min(1),
|
|
307
|
+
spanId: z.string().min(1).optional(),
|
|
308
|
+
rootDurationMs: z.number().nonnegative().optional(),
|
|
309
|
+
spans: z.array(agentOtelSpanSummarySchema).max(AGENT_OTEL_SPANS_MAX).optional()
|
|
310
|
+
});
|
|
298
311
|
var agentTelemetrySchema = z.object({
|
|
299
312
|
/** Agent or app version (semver, git SHA, deploy tag — caller-defined). */
|
|
300
313
|
version: z.string().min(1).optional(),
|
|
@@ -304,7 +317,9 @@ var agentTelemetrySchema = z.object({
|
|
|
304
317
|
toolCalls: agentToolCallsSchema.optional(),
|
|
305
318
|
cost: agentCostSchema.optional(),
|
|
306
319
|
/** Free-form metadata for experiments (model, prompt variant, etc.). */
|
|
307
|
-
info: z.record(z.string(), z.unknown()).optional()
|
|
320
|
+
info: z.record(z.string(), z.unknown()).optional(),
|
|
321
|
+
/** Structured OpenTelemetry span snapshot for feedback analysis. */
|
|
322
|
+
otel: agentOtelSchema.optional()
|
|
308
323
|
}).refine(
|
|
309
324
|
(data) => {
|
|
310
325
|
const keys = data.info ? Object.keys(data.info) : [];
|
|
@@ -449,13 +464,27 @@ var agentCostSchema2 = z2.object({
|
|
|
449
464
|
});
|
|
450
465
|
var AGENT_INFO_MAX_KEYS2 = 32;
|
|
451
466
|
var AGENT_TOOL_CALLS_MAX_KEYS2 = 64;
|
|
467
|
+
var AGENT_OTEL_SPANS_MAX2 = 32;
|
|
452
468
|
var agentToolCallsSchema2 = z2.record(z2.string().min(1), nonNegativeInt2);
|
|
469
|
+
var agentOtelSpanStatusSchema2 = z2.enum(["ok", "error"]);
|
|
470
|
+
var agentOtelSpanSummarySchema2 = z2.object({
|
|
471
|
+
name: z2.string().min(1),
|
|
472
|
+
durationMs: z2.number().nonnegative(),
|
|
473
|
+
status: agentOtelSpanStatusSchema2
|
|
474
|
+
});
|
|
475
|
+
var agentOtelSchema2 = z2.object({
|
|
476
|
+
traceId: z2.string().min(1),
|
|
477
|
+
spanId: z2.string().min(1).optional(),
|
|
478
|
+
rootDurationMs: z2.number().nonnegative().optional(),
|
|
479
|
+
spans: z2.array(agentOtelSpanSummarySchema2).max(AGENT_OTEL_SPANS_MAX2).optional()
|
|
480
|
+
});
|
|
453
481
|
var agentTelemetrySchema2 = z2.object({
|
|
454
482
|
version: z2.string().min(1).optional(),
|
|
455
483
|
toolCallCount: nonNegativeInt2.optional(),
|
|
456
484
|
toolCalls: agentToolCallsSchema2.optional(),
|
|
457
485
|
cost: agentCostSchema2.optional(),
|
|
458
|
-
info: z2.record(z2.string(), z2.unknown()).optional()
|
|
486
|
+
info: z2.record(z2.string(), z2.unknown()).optional(),
|
|
487
|
+
otel: agentOtelSchema2.optional()
|
|
459
488
|
}).refine(
|
|
460
489
|
(data) => {
|
|
461
490
|
const keys = data.info ? Object.keys(data.info) : [];
|