robotrock 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,165 @@
1
+ // src/schemas/index.ts
2
+ import { z } from "zod";
1
3
  import {
2
- DEFAULT_TASK_PRIORITY,
3
- DEFAULT_THREAD_UPDATE_STATUS,
4
- LOWEST_TASK_PRIORITY,
5
- TASK_PRIORITY_RANK,
6
- assignToSchema,
7
- createTaskBodySchema,
8
- taskContextSchema,
9
- taskPriorities,
10
- taskPrioritySchema,
11
- threadUpdateBodySchema,
12
- threadUpdateInputSchema,
13
- threadUpdateMessageSchema,
14
- threadUpdateStatusSchema,
15
- threadUpdateStatuses
16
- } from "../chunk-TAWMIQAM.js";
4
+ isPublicHttpUrl,
5
+ PUBLIC_HTTP_URL_ERROR
6
+ } from "@robotrock/core/utils";
7
+ import { validateContextPublicUrls } from "@robotrock/core/schemas";
8
+ var safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {
9
+ message: PUBLIC_HTTP_URL_ERROR
10
+ });
11
+ var jsonSchema7Schema = z.custom(
12
+ (val) => typeof val === "object" && val !== null,
13
+ { message: "Must be a valid JSON Schema object" }
14
+ );
15
+ var uiSchemaSchema = z.custom((val) => typeof val === "object" && val !== null, {
16
+ message: "Must be a valid UiSchema object"
17
+ });
18
+ var webhookHandlerSchema = z.object({
19
+ type: z.literal("webhook"),
20
+ url: safeUrlSchema,
21
+ headers: z.record(z.string(), z.string())
22
+ });
23
+ var triggerHandlerSchema = webhookHandlerSchema.extend({
24
+ type: z.literal("trigger"),
25
+ tokenId: z.string().min(1)
26
+ });
27
+ var handlerSchema = z.discriminatedUnion("type", [webhookHandlerSchema, triggerHandlerSchema]);
28
+ var taskActionSchema = z.object({
29
+ id: z.string().min(1),
30
+ title: z.string().min(1),
31
+ description: z.string().optional(),
32
+ schema: jsonSchema7Schema.optional(),
33
+ ui: uiSchemaSchema.optional(),
34
+ data: z.record(z.string(), z.unknown()).optional(),
35
+ handlers: z.array(handlerSchema).min(1).optional()
36
+ });
37
+ var uiFieldSchemaSchema = z.object({
38
+ "ui:widget": z.string().optional(),
39
+ "ui:title": z.string().optional(),
40
+ "ui:description": z.string().optional(),
41
+ "ui:options": z.record(z.string(), z.unknown()).optional(),
42
+ items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional()
43
+ }).passthrough();
44
+ var contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();
45
+ var contextDataSchema = z.object({
46
+ data: z.record(z.string(), z.unknown()),
47
+ ui: contextUiSchema
48
+ }).optional();
49
+ var taskContextObjectSchema = z.object({
50
+ app: z.string().min(1).optional(),
51
+ type: z.string().min(1),
52
+ name: z.string().min(1),
53
+ description: z.string().optional(),
54
+ validUntil: z.string().optional(),
55
+ context: contextDataSchema,
56
+ version: z.literal(2).optional(),
57
+ actions: z.array(taskActionSchema).min(1, "At least one action is required")
58
+ });
59
+ function refineContextPublicUrls(data, ctx) {
60
+ const error = validateContextPublicUrls(data.context);
61
+ if (error) {
62
+ ctx.addIssue({
63
+ code: z.ZodIssueCode.custom,
64
+ message: error,
65
+ path: ["context"]
66
+ });
67
+ }
68
+ }
69
+ var taskContextSchema = taskContextObjectSchema.superRefine(
70
+ refineContextPublicUrls
71
+ );
72
+ var assignToSchema = z.object({
73
+ users: z.array(z.string().email()).optional(),
74
+ groups: z.array(z.string().min(1)).optional()
75
+ }).refine(
76
+ (data) => {
77
+ const groups = data.groups ?? [];
78
+ if (groups.includes("all") && groups.length > 1) {
79
+ return false;
80
+ }
81
+ return true;
82
+ },
83
+ { message: 'Cannot combine "all" with other group slugs' }
84
+ );
85
+ var threadUpdateMessageSchema = z.string().min(1).max(500);
86
+ var threadUpdateStatuses = [
87
+ "info",
88
+ "queued",
89
+ "running",
90
+ "waiting",
91
+ "succeeded",
92
+ "failed",
93
+ "cancelled"
94
+ ];
95
+ var threadUpdateStatusSchema = z.enum(threadUpdateStatuses);
96
+ var DEFAULT_THREAD_UPDATE_STATUS = "info";
97
+ var threadUpdateInputSchema = z.object({
98
+ message: threadUpdateMessageSchema,
99
+ status: threadUpdateStatusSchema.optional()
100
+ });
101
+ var taskPriorities = ["low", "normal", "high", "urgent"];
102
+ var taskPrioritySchema = z.enum(taskPriorities);
103
+ var DEFAULT_TASK_PRIORITY = "normal";
104
+ var LOWEST_TASK_PRIORITY = "low";
105
+ var TASK_PRIORITY_RANK = {
106
+ low: 1,
107
+ normal: 2,
108
+ high: 3,
109
+ urgent: 4
110
+ };
111
+ var nonNegativeInt = z.number().int().nonnegative();
112
+ var agentCostTokensSchema = z.object({
113
+ input: nonNegativeInt.optional(),
114
+ output: nonNegativeInt.optional(),
115
+ total: nonNegativeInt.optional()
116
+ });
117
+ var agentCostSchema = z.object({
118
+ tokens: agentCostTokensSchema.optional(),
119
+ eur: z.number().nonnegative().optional(),
120
+ usd: z.number().nonnegative().optional()
121
+ });
122
+ var AGENT_INFO_MAX_KEYS = 32;
123
+ var agentTelemetrySchema = z.object({
124
+ version: z.string().min(1).optional(),
125
+ toolCallCount: nonNegativeInt.optional(),
126
+ cost: agentCostSchema.optional(),
127
+ info: z.record(z.string(), z.unknown()).optional()
128
+ }).refine(
129
+ (data) => {
130
+ const keys = data.info ? Object.keys(data.info) : [];
131
+ return keys.length <= AGENT_INFO_MAX_KEYS;
132
+ },
133
+ { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }
134
+ );
135
+ var createTaskBodySchema = taskContextObjectSchema.extend({
136
+ assignTo: assignToSchema.optional(),
137
+ /**
138
+ * Groups related tasks together. When omitted, the server generates one and
139
+ * returns it so the caller can reuse it on later tasks in the same thread.
140
+ */
141
+ threadId: z.string().min(1).optional(),
142
+ /**
143
+ * Optional thread priority. When set, applies to the whole thread and
144
+ * overwrites any previous priority. Omit on later tasks to leave unchanged.
145
+ */
146
+ priority: taskPrioritySchema.optional(),
147
+ /**
148
+ * Optional initial status update logged against the task's thread. Shows in
149
+ * the inbox status bar and the thread update log.
150
+ */
151
+ update: threadUpdateInputSchema.optional(),
152
+ agent: agentTelemetrySchema.optional()
153
+ }).superRefine(refineContextPublicUrls);
154
+ var threadUpdateBodySchema = threadUpdateInputSchema;
17
155
  export {
18
156
  DEFAULT_TASK_PRIORITY,
19
157
  DEFAULT_THREAD_UPDATE_STATUS,
20
158
  LOWEST_TASK_PRIORITY,
21
159
  TASK_PRIORITY_RANK,
160
+ agentCostSchema,
161
+ agentCostTokensSchema,
162
+ agentTelemetrySchema,
22
163
  assignToSchema,
23
164
  createTaskBodySchema,
24
165
  taskContextSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../../src/schemas/index.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n isPublicHttpUrl,\n PUBLIC_HTTP_URL_ERROR,\n} from \"@robotrock/core/utils\";\nimport { validateContextPublicUrls } from \"@robotrock/core/schemas\";\n\nexport interface JSONSchema7 {\n $id?: string;\n $ref?: string;\n $schema?: string;\n $comment?: string;\n type?: JSONSchema7TypeName | JSONSchema7TypeName[];\n enum?: unknown[];\n const?: unknown;\n multipleOf?: number;\n maximum?: number;\n exclusiveMaximum?: number;\n minimum?: number;\n exclusiveMinimum?: number;\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n format?: string;\n items?: JSONSchema7 | JSONSchema7[];\n additionalItems?: JSONSchema7 | boolean;\n maxItems?: number;\n minItems?: number;\n uniqueItems?: boolean;\n contains?: JSONSchema7;\n maxProperties?: number;\n minProperties?: number;\n required?: string[];\n properties?: Record<string, JSONSchema7>;\n patternProperties?: Record<string, JSONSchema7>;\n additionalProperties?: JSONSchema7 | boolean;\n dependencies?: Record<string, JSONSchema7 | string[]>;\n propertyNames?: JSONSchema7;\n if?: JSONSchema7;\n then?: JSONSchema7;\n else?: JSONSchema7;\n allOf?: JSONSchema7[];\n anyOf?: JSONSchema7[];\n oneOf?: JSONSchema7[];\n not?: JSONSchema7;\n title?: string;\n description?: string;\n default?: unknown;\n readOnly?: boolean;\n writeOnly?: boolean;\n examples?: unknown[];\n}\n\nexport type JSONSchema7TypeName =\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"null\";\n\nexport type ExtendedJSONSchema7 = JSONSchema7 & {\n enumNames?: string[];\n [key: string]: unknown;\n};\n\nexport type UiSchema = {\n \"ui:widget\"?: string;\n \"ui:title\"?: string;\n \"ui:description\"?: string;\n \"ui:placeholder\"?: string;\n \"ui:options\"?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\nconst safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {\n message: PUBLIC_HTTP_URL_ERROR,\n});\n\nconst jsonSchema7Schema = z.custom<ExtendedJSONSchema7>(\n (val) => typeof val === \"object\" && val !== null,\n { message: \"Must be a valid JSON Schema object\" }\n);\n\nconst uiSchemaSchema = z.custom<UiSchema>((val) => typeof val === \"object\" && val !== null, {\n message: \"Must be a valid UiSchema object\",\n});\n\nconst webhookHandlerSchema = z.object({\n type: z.literal(\"webhook\"),\n url: safeUrlSchema,\n headers: z.record(z.string(), z.string()),\n});\n\nconst triggerHandlerSchema = webhookHandlerSchema.extend({\n type: z.literal(\"trigger\"),\n tokenId: z.string().min(1),\n});\n\nconst handlerSchema = z.discriminatedUnion(\"type\", [webhookHandlerSchema, triggerHandlerSchema]);\n\nconst taskActionSchema = z.object({\n id: z.string().min(1),\n title: z.string().min(1),\n description: z.string().optional(),\n schema: jsonSchema7Schema.optional(),\n ui: uiSchemaSchema.optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n handlers: z.array(handlerSchema).min(1).optional(),\n});\n\nconst uiFieldSchemaSchema: z.ZodType<Record<string, unknown>> = z\n .object({\n \"ui:widget\": z.string().optional(),\n \"ui:title\": z.string().optional(),\n \"ui:description\": z.string().optional(),\n \"ui:options\": z.record(z.string(), z.unknown()).optional(),\n items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\nconst contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();\n\nconst contextDataSchema = z\n .object({\n data: z.record(z.string(), z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\nconst taskContextObjectSchema = z.object({\n app: z.string().min(1).optional(),\n type: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n validUntil: z.string().optional(),\n context: contextDataSchema,\n version: z.literal(2).optional(),\n actions: z.array(taskActionSchema).min(1, \"At least one action is required\"),\n});\n\nfunction refineContextPublicUrls<T extends { context?: z.infer<typeof contextDataSchema> }>(\n data: T,\n ctx: z.RefinementCtx\n) {\n const error = validateContextPublicUrls(data.context);\n if (error) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: error,\n path: [\"context\"],\n });\n }\n}\n\nexport const taskContextSchema = taskContextObjectSchema.superRefine(\n refineContextPublicUrls\n);\n\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (count toward seat limits).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nconst nonNegativeInt = z.number().int().nonnegative();\n\nexport const agentCostTokensSchema = z.object({\n input: nonNegativeInt.optional(),\n output: nonNegativeInt.optional(),\n total: nonNegativeInt.optional(),\n});\n\nexport const agentCostSchema = z.object({\n tokens: agentCostTokensSchema.optional(),\n eur: z.number().nonnegative().optional(),\n usd: z.number().nonnegative().optional(),\n});\n\nconst AGENT_INFO_MAX_KEYS = 32;\n\nexport const agentTelemetrySchema = z\n .object({\n version: z.string().min(1).optional(),\n toolCallCount: nonNegativeInt.optional(),\n cost: agentCostSchema.optional(),\n info: z.record(z.string(), z.unknown()).optional(),\n })\n .refine(\n (data) => {\n const keys = data.info ? Object.keys(data.info) : [];\n return keys.length <= AGENT_INFO_MAX_KEYS;\n },\n { message: `agent.info may contain at most ${AGENT_INFO_MAX_KEYS} keys` }\n );\n\nexport const createTaskBodySchema = taskContextObjectSchema\n .extend({\n assignTo: assignToSchema.optional(),\n /**\n * Groups related tasks together. When omitted, the server generates one and\n * returns it so the caller can reuse it on later tasks in the same thread.\n */\n threadId: z.string().min(1).optional(),\n /**\n * Optional thread priority. When set, applies to the whole thread and\n * overwrites any previous priority. Omit on later tasks to leave unchanged.\n */\n priority: taskPrioritySchema.optional(),\n /**\n * Optional initial status update logged against the task's thread. Shows in\n * the inbox status bar and the thread update log.\n */\n update: threadUpdateInputSchema.optional(),\n agent: agentTelemetrySchema.optional(),\n })\n .superRefine(refineContextPublicUrls);\n\n/** POST /v1/threads/:threadId/updates body: a standalone thread update. */\nexport const threadUpdateBodySchema = threadUpdateInputSchema;\n\n/** Where a thread update originated. */\nexport type ThreadUpdateSource = \"api\" | \"task_create\" | \"dashboard\";\n\n/** Lifecycle status carried by a thread update. */\nexport type ThreadUpdateStatus = (typeof threadUpdateStatuses)[number];\n\n/** A logged thread update as returned by the API. */\nexport interface ThreadUpdate {\n id: string;\n threadId: string;\n message: string;\n status: ThreadUpdateStatus;\n source: ThreadUpdateSource;\n createdAt: number;\n}\n\nexport type AssignToInput = z.infer<typeof assignToSchema>;\nexport type CreateTaskBodyInput = z.input<typeof createTaskBodySchema>;\nexport type CreateTaskBody = z.output<typeof createTaskBodySchema>;\nexport type ThreadUpdateBodyInput = z.input<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateBody = z.output<typeof threadUpdateBodySchema>;\nexport type ThreadUpdateInput = z.input<typeof threadUpdateInputSchema>;\nexport type TaskContextInput = z.input<typeof taskContextSchema>;\nexport type TaskContextOutput = z.output<typeof taskContextSchema>;\nexport type TaskContext = TaskContextOutput;\nexport type TaskAction = z.infer<typeof taskActionSchema>;\nexport type WebhookHandler = z.infer<typeof webhookHandlerSchema>;\nexport type TriggerHandler = z.infer<typeof triggerHandlerSchema>;\nexport type Handler = z.infer<typeof handlerSchema>;\nexport type AgentCostTokens = z.infer<typeof agentCostTokensSchema>;\nexport type AgentCost = z.infer<typeof agentCostSchema>;\nexport type AgentTelemetry = z.infer<typeof agentTelemetrySchema>;\nexport type AgentTelemetryInput = z.input<typeof agentTelemetrySchema>;\n\ntype InferObjectProperties<\n Props,\n Req extends PropertyKey,\n> = Props extends Record<string, unknown>\n ? ({\n [K in keyof Props as K extends Req ? K : never]-?: InferJsonSchema7<Props[K]>;\n } & {\n [K in keyof Props as K extends Req ? never : K]?: InferJsonSchema7<Props[K]>;\n } extends infer O\n ? { [K in keyof O]: O[K] }\n : never)\n : Record<string, unknown>;\n\ntype RequiredKeys<S> =\n S extends { readonly required: readonly string[] } ? S[\"required\"][number] : never;\n\nexport type InferJsonSchema7<S> = [S] extends [undefined]\n ? Record<string, never>\n : S extends { readonly const: infer C }\n ? C\n : S extends {\n readonly enum: readonly (infer E)[];\n }\n ? E\n : S extends {\n readonly type: \"object\";\n readonly properties?: infer Props;\n }\n ? InferObjectProperties<Props, RequiredKeys<S>>\n : S extends {\n readonly type: \"object\";\n readonly properties?: undefined;\n }\n ? Record<string, unknown>\n : S extends {\n readonly type: \"array\";\n readonly items?: infer Items;\n }\n ? Items extends readonly unknown[]\n ? InferJsonSchema7<Items[number]>[]\n : Items extends object\n ? InferJsonSchema7<Items>[]\n : unknown[]\n : S extends { readonly type: \"string\" }\n ? string\n : S extends { readonly type: \"number\" } | { readonly type: \"integer\" }\n ? number\n : S extends { readonly type: \"boolean\" }\n ? boolean\n : unknown;\n\nexport type TaskStatus = \"pending\" | \"open\" | \"handled\" | \"expired\";\n\nexport interface TaskResponse {\n success: boolean;\n task: {\n taskId: string;\n threadId: string;\n status: \"pending\" | \"open\";\n context: TaskContext;\n validUntil: string;\n submittedAt: string;\n };\n message: string;\n}\n\nexport interface ThreadUpdateResponse {\n success: boolean;\n update: ThreadUpdate;\n message: string;\n}\n\nexport interface Task {\n id: string;\n threadId?: string;\n createdAt: Date;\n status: TaskStatus;\n context: TaskContext;\n validUntil: number;\n handledAt?: number;\n handled?: {\n action: {\n id: string;\n data: unknown;\n };\n handledBy?: string;\n userId?: string;\n token?: string;\n };\n}\n\nexport type InferActionData<T extends { schema?: unknown }> = [\n Exclude<T[\"schema\"], undefined>,\n] extends [\n never,\n]\n ? Record<string, never>\n : Exclude<T[\"schema\"], undefined> extends infer S\n ? InferJsonSchema7<S>\n : Record<string, never>;\n\nexport type TupleElementIndices<T extends readonly unknown[]> = T extends readonly [\n unknown,\n ...unknown[],\n]\n ? Exclude<keyof T, keyof unknown[]>\n : number;\n\nexport interface TaskResult<T = Record<string, unknown>> {\n actionId: string;\n data: T;\n handledBy?: string;\n handledAt: Date;\n}\n\nexport interface ApprovalResult<T = Record<string, unknown>> extends TaskResult<T> {\n taskId: string;\n}\n\nexport type DiscriminatedApprovalResult<\n TActions extends readonly { id: string; schema?: unknown }[],\n> = {\n [I in TupleElementIndices<TActions>]: TActions[I] extends { id: string; schema?: unknown }\n ? Omit<ApprovalResult<InferActionData<TActions[I]>>, \"actionId\" | \"data\"> & {\n actionId: TActions[I][\"id\"];\n data: InferActionData<TActions[I]>;\n }\n : never\n}[TupleElementIndices<TActions>];\n"],"mappings":";AAAA,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC;AAuE1C,IAAM,gBAAgB,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,gBAAgB,GAAG,GAAG;AAAA,EACrE,SAAS;AACX,CAAC;AAED,IAAM,oBAAoB,EAAE;AAAA,EAC1B,CAAC,QAAQ,OAAO,QAAQ,YAAY,QAAQ;AAAA,EAC5C,EAAE,SAAS,qCAAqC;AAClD;AAEA,IAAM,iBAAiB,EAAE,OAAiB,CAAC,QAAQ,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAAA,EAC1F,SAAS;AACX,CAAC;AAED,IAAM,uBAAuB,EAAE,OAAO;AAAA,EACpC,MAAM,EAAE,QAAQ,SAAS;AAAA,EACzB,KAAK;AAAA,EACL,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;AAC1C,CAAC;AAED,IAAM,uBAAuB,qBAAqB,OAAO;AAAA,EACvD,MAAM,EAAE,QAAQ,SAAS;AAAA,EACzB,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAC3B,CAAC;AAED,IAAM,gBAAgB,EAAE,mBAAmB,QAAQ,CAAC,sBAAsB,oBAAoB,CAAC;AAE/F,IAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC;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yBAAyB;","names":[]}
@@ -0,0 +1,247 @@
1
+ import { z } from 'zod';
2
+ import { R as RobotRock, a as SendToHumanInput, S as SendToHumanActionInput, j as SendUpdateInput } from './client-D-XEBOWd.js';
3
+ import { DiscriminatedApprovalResult, ThreadUpdate } from './schemas/index.js';
4
+ import { ToolApprovalResponse } from 'ai';
5
+
6
+ declare const APPROVE_BY_HUMAN_ACTIONS$1: readonly [{
7
+ readonly id: "approve";
8
+ readonly title: "Approve";
9
+ }, {
10
+ readonly id: "decline";
11
+ readonly title: "Decline";
12
+ }];
13
+ /** How RobotRock waits for a human inside AI SDK tool `execute`. */
14
+ type RobotRockAiMode = "polling" | "trigger" | "workflow";
15
+ /**
16
+ * Polling: `client.sendToHuman()` blocks until handled (scripts, API routes with long timeout).
17
+ * Trigger: `sendToHumanTask.triggerAndWait()` uses wait tokens (Trigger.dev workers).
18
+ * Workflow: `sendToHumanInWorkflow()` uses workflow webhooks (Vercel Workflow).
19
+ */
20
+ type RobotRockAiPollingContext = {
21
+ mode?: "polling";
22
+ client: RobotRock;
23
+ };
24
+ type RobotRockAiTriggerContext = {
25
+ mode: "trigger";
26
+ /** Inbox app bucket; falls back to `ROBOTROCK_APP` in the Trigger worker. */
27
+ app?: string;
28
+ };
29
+ type RobotRockAiWorkflowContext = {
30
+ mode: "workflow";
31
+ /** Inbox app bucket; falls back to `ROBOTROCK_APP` in the workflow run. */
32
+ app?: string;
33
+ };
34
+ type RobotRockAiContext = RobotRockAiPollingContext | RobotRockAiTriggerContext | RobotRockAiWorkflowContext;
35
+ /** Shorthand for `{ mode: "trigger", app }`. */
36
+ declare function createRobotRockAiTriggerContext(options?: Omit<RobotRockAiTriggerContext, "mode">): RobotRockAiContext;
37
+ /** Shorthand for `{ mode: "workflow", app }`. */
38
+ declare function createRobotRockAiWorkflowContext(options?: Omit<RobotRockAiWorkflowContext, "mode">): RobotRockAiContext;
39
+ declare function normalizeRobotRockAiContext(clientOrContext: RobotRock | RobotRockAiContext): RobotRockAiContext;
40
+ declare function sendToHumanForAi<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]>(context: RobotRockAiContext, payload: SendToHumanInput<A>): Promise<DiscriminatedApprovalResult<A>>;
41
+ /**
42
+ * Posts a thread update for an AI tool, routing by execution mode.
43
+ *
44
+ * `sendUpdate` is fire-and-forget (no human wait), so only the workflow path
45
+ * needs durability — it runs inside a `"use step"`. Trigger and polling modes
46
+ * issue the request directly.
47
+ */
48
+ declare function sendUpdateForAi(context: RobotRockAiContext, payload: SendUpdateInput): Promise<ThreadUpdate>;
49
+ declare function approveByHumanForAi(context: RobotRockAiContext, payload: Omit<SendToHumanInput, "actions"> & {
50
+ app?: string;
51
+ }): Promise<DiscriminatedApprovalResult<typeof APPROVE_BY_HUMAN_ACTIONS$1>>;
52
+
53
+ type HumanToolResult = {
54
+ taskId: string;
55
+ actionId: string;
56
+ data: unknown;
57
+ handledBy?: string;
58
+ handledAt: string;
59
+ /** Present when action ids are approve/decline (or approve/reject). */
60
+ approved?: boolean;
61
+ };
62
+ type RobotRockToolCallInfo = {
63
+ toolName: string;
64
+ toolCallId: string;
65
+ input: unknown;
66
+ };
67
+ type RobotRockToolApprovalConfig = {
68
+ /** Tool names that require RobotRock inbox approval before execution. */
69
+ tools?: readonly string[];
70
+ /** Custom predicate when tool names alone are not enough. */
71
+ when?: (toolCall: RobotRockToolCallInfo) => boolean;
72
+ };
73
+ type FormatToolApprovalTaskOptions = {
74
+ type?: string;
75
+ approveActionId?: string;
76
+ denyActionId?: string;
77
+ };
78
+ type ResolveToolApprovalsOptions = {
79
+ formatTask?: (toolCall: RobotRockToolCallInfo) => SendToHumanInput;
80
+ approveActionId?: string;
81
+ denyActionId?: string;
82
+ };
83
+ type RunWithRobotRockApprovalsOptions<T> = {
84
+ /** Polling mode (requires `client`). */
85
+ client?: RobotRock;
86
+ /** Polling or Trigger mode; use `{ mode: "trigger" }` inside Trigger.dev workers. */
87
+ context?: RobotRockAiContext;
88
+ /** Initial messages; updated across approval rounds. */
89
+ messages?: unknown[];
90
+ maxRounds?: number;
91
+ resolveOptions?: ResolveToolApprovalsOptions;
92
+ generate: (messages: unknown[]) => Promise<T>;
93
+ };
94
+ type ToolApprovalRequestPart = {
95
+ type: "tool-approval-request";
96
+ approvalId: string;
97
+ toolCallId?: string;
98
+ toolCall?: RobotRockToolCallInfo;
99
+ isAutomatic?: boolean;
100
+ };
101
+
102
+ declare const APPROVE_BY_HUMAN_ACTIONS: readonly [{
103
+ readonly id: "approve";
104
+ readonly title: "Approve";
105
+ }, {
106
+ readonly id: "decline";
107
+ readonly title: "Decline";
108
+ }];
109
+ declare const approveByHumanInputSchema: z.ZodObject<{
110
+ type: z.ZodOptional<z.ZodString>;
111
+ name: z.ZodString;
112
+ description: z.ZodString;
113
+ contextSummary: z.ZodOptional<z.ZodString>;
114
+ }, z.core.$strip>;
115
+ type ApproveByHumanToolInput = z.infer<typeof approveByHumanInputSchema>;
116
+ type ApproveByHumanToolOptions = {
117
+ defaultType?: string;
118
+ description?: string;
119
+ toolName?: string;
120
+ };
121
+ type ApproveByHumanToolDurableOptions = ApproveByHumanToolOptions & RobotRockAiContext & {
122
+ mode: "trigger" | "workflow";
123
+ };
124
+ type ApproveByHumanToolDefinition = {
125
+ description: string;
126
+ inputSchema: typeof approveByHumanInputSchema;
127
+ execute: (input: ApproveByHumanToolInput) => Promise<HumanToolResult>;
128
+ };
129
+
130
+ declare const sendToHumanToolInputSchema: z.ZodObject<{
131
+ type: z.ZodString;
132
+ name: z.ZodString;
133
+ description: z.ZodOptional<z.ZodString>;
134
+ context: z.ZodOptional<z.ZodObject<{
135
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
136
+ ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
137
+ }, z.core.$strip>>;
138
+ validUntil: z.ZodOptional<z.ZodString>;
139
+ assignTo: z.ZodOptional<z.ZodObject<{
140
+ users: z.ZodOptional<z.ZodArray<z.ZodString>>;
141
+ groups: z.ZodOptional<z.ZodArray<z.ZodString>>;
142
+ }, z.core.$strip>>;
143
+ }, z.core.$strip>;
144
+ type SendToHumanToolInput = z.infer<typeof sendToHumanToolInputSchema>;
145
+ type CreateSendToHumanToolOptions<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]> = {
146
+ actions: A;
147
+ defaultType?: string;
148
+ description?: string;
149
+ toolName?: string;
150
+ /**
151
+ * Group every task this tool creates onto a shared thread. Pass the same
152
+ * value to {@link createSendUpdateTool} so updates land on the same thread.
153
+ */
154
+ threadId?: string;
155
+ };
156
+ type CreateSendToHumanToolDurableOptions<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]> = CreateSendToHumanToolOptions<A> & RobotRockAiContext & {
157
+ mode: "trigger" | "workflow";
158
+ };
159
+ type SendToHumanToolDefinition = {
160
+ description: string;
161
+ inputSchema: typeof sendToHumanToolInputSchema;
162
+ execute: (input: SendToHumanToolInput) => Promise<HumanToolResult>;
163
+ };
164
+
165
+ /**
166
+ * Result returned to the model by {@link createSendUpdateTool}.
167
+ *
168
+ * Updates are fire-and-forget, so a missing thread (no task created yet) is
169
+ * reported as `{ posted: false }` instead of throwing — that way an agent loop
170
+ * is never aborted by a non-critical progress update. Genuine failures (auth,
171
+ * validation, server errors) still throw.
172
+ */
173
+ type SendUpdateToolResult = {
174
+ posted: true;
175
+ threadId: string;
176
+ update: ThreadUpdate;
177
+ } | {
178
+ posted: false;
179
+ threadId: string;
180
+ reason: "thread_not_found";
181
+ message: string;
182
+ };
183
+ declare const sendUpdateToolInputSchema: z.ZodObject<{
184
+ threadId: z.ZodOptional<z.ZodString>;
185
+ message: z.ZodString;
186
+ status: z.ZodOptional<z.ZodEnum<{
187
+ info: "info";
188
+ queued: "queued";
189
+ running: "running";
190
+ waiting: "waiting";
191
+ succeeded: "succeeded";
192
+ failed: "failed";
193
+ cancelled: "cancelled";
194
+ }>>;
195
+ }, z.core.$strip>;
196
+ type SendUpdateToolInput = z.infer<typeof sendUpdateToolInputSchema>;
197
+ type CreateSendUpdateToolOptions = {
198
+ /**
199
+ * Session thread to post updates to when the model does not supply `threadId`.
200
+ * Pass the same value to {@link createSendToHumanTool} to auto-thread tasks
201
+ * and updates together.
202
+ */
203
+ threadId?: string;
204
+ description?: string;
205
+ };
206
+ type CreateSendUpdateToolDurableOptions = CreateSendUpdateToolOptions & RobotRockAiContext & {
207
+ mode: "trigger" | "workflow";
208
+ };
209
+ type SendUpdateToolDefinition = {
210
+ description: string;
211
+ inputSchema: typeof sendUpdateToolInputSchema;
212
+ execute: (input: SendUpdateToolInput) => Promise<SendUpdateToolResult>;
213
+ };
214
+
215
+ type RobotRockToolApprovalDecision = "user-approval" | undefined;
216
+ /**
217
+ * AI SDK 7+: pass the return value to `toolApproval` on `generateText`, `streamText`, or `ToolLoopAgent`.
218
+ * Returns `'user-approval'` for configured tools so execution pauses until a human responds via RobotRock.
219
+ */
220
+ declare function createRobotRockToolApproval(config: RobotRockToolApprovalConfig): (options: {
221
+ toolCall: RobotRockToolCallInfo;
222
+ }) => Promise<RobotRockToolApprovalDecision>;
223
+ /**
224
+ * AI SDK 5–6: use as `needsApproval` on tool definitions (or via {@link applyRobotRockToolApprovalToTools}).
225
+ */
226
+ declare function createRobotRockNeedsApproval(config: RobotRockToolApprovalConfig): (_input: unknown, options: {
227
+ toolCallId: string;
228
+ messages?: unknown[];
229
+ }) => Promise<boolean>;
230
+ /**
231
+ * AI SDK 5–6: merge `needsApproval` into each matching tool in a tools object.
232
+ */
233
+ declare function applyRobotRockToolApprovalToTools<T extends Record<string, object>>(tools: T, config: RobotRockToolApprovalConfig): T;
234
+ declare function collectApprovalRequests(source: unknown): ToolApprovalRequestPart[];
235
+ /**
236
+ * Create RobotRock tasks for pending AI SDK tool approvals and return `tool-approval-response` parts.
237
+ */
238
+ declare function resolveToolApprovalsViaRobotRock(clientOrContext: RobotRock | RobotRockAiContext, source: unknown, options?: ResolveToolApprovalsOptions): Promise<{
239
+ responses: ToolApprovalResponse[];
240
+ messages: unknown[];
241
+ }>;
242
+ /**
243
+ * Run `generate` in a loop until manual tool approvals are resolved via RobotRock or `maxRounds` is reached.
244
+ */
245
+ declare function runWithRobotRockApprovals<T>(options: RunWithRobotRockApprovalsOptions<T>): Promise<T>;
246
+
247
+ export { type ApproveByHumanToolDurableOptions as A, createRobotRockAiTriggerContext as B, type CreateSendToHumanToolOptions as C, normalizeRobotRockAiContext as D, sendToHumanForAi as E, type FormatToolApprovalTaskOptions as F, sendToHumanToolInputSchema as G, type HumanToolResult as H, sendUpdateForAi as I, sendUpdateToolInputSchema as J, type RobotRockAiWorkflowContext as R, type SendToHumanToolDefinition as S, type ToolApprovalRequestPart as T, type ApproveByHumanToolOptions as a, type ApproveByHumanToolDefinition as b, type CreateSendUpdateToolOptions as c, type SendUpdateToolDefinition as d, type CreateSendToHumanToolDurableOptions as e, type CreateSendUpdateToolDurableOptions as f, type RobotRockAiContext as g, type RobotRockAiMode as h, type RobotRockAiPollingContext as i, type RobotRockAiTriggerContext as j, applyRobotRockToolApprovalToTools as k, createRobotRockAiWorkflowContext as l, createRobotRockNeedsApproval as m, createRobotRockToolApproval as n, runWithRobotRockApprovals as o, type RobotRockToolCallInfo as p, APPROVE_BY_HUMAN_ACTIONS as q, resolveToolApprovalsViaRobotRock as r, type ResolveToolApprovalsOptions as s, type RobotRockToolApprovalConfig as t, type RobotRockToolApprovalDecision as u, type RunWithRobotRockApprovalsOptions as v, type SendUpdateToolResult as w, approveByHumanForAi as x, approveByHumanInputSchema as y, collectApprovalRequests as z };
@@ -1,5 +1,5 @@
1
1
  import * as _trigger_dev_sdk from '@trigger.dev/sdk';
2
- import { S as SendToHumanActionInput, a as SendToHumanInput } from '../client-CLcHdjOz.js';
2
+ import { S as SendToHumanActionInput, a as SendToHumanInput } from '../client-D-XEBOWd.js';
3
3
  export { R as RobotRockHandlerWebhookPayload } from '../handler-webhook-BqEi6Bk-.js';
4
4
  export { ApprovalResult, DiscriminatedApprovalResult, TaskContextInput, TaskResult } from '../schemas/index.js';
5
5
  import 'zod';