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,393 +0,0 @@
1
- import * as ai from 'ai';
2
- import { ToolApprovalResponse } from 'ai';
3
- import { z } from 'zod';
4
- import { b as RobotRock, a as SendToHumanInput, S as SendToHumanActionInput, l as SendUpdateInput } from './client-CLcHdjOz.js';
5
- import { DiscriminatedApprovalResult, ThreadUpdate } from './schemas/index.js';
6
-
7
- declare const APPROVE_BY_HUMAN_ACTIONS$1: readonly [{
8
- readonly id: "approve";
9
- readonly title: "Approve";
10
- }, {
11
- readonly id: "decline";
12
- readonly title: "Decline";
13
- }];
14
- /** How RobotRock waits for a human inside AI SDK tool `execute`. */
15
- type RobotRockAiMode = "polling" | "trigger" | "workflow";
16
- /**
17
- * Polling: `client.sendToHuman()` blocks until handled (scripts, API routes with long timeout).
18
- * Trigger: `sendToHumanTask.triggerAndWait()` uses wait tokens (Trigger.dev workers).
19
- * Workflow: `sendToHumanInWorkflow()` uses workflow webhooks (Vercel Workflow).
20
- */
21
- type RobotRockAiPollingContext = {
22
- mode?: "polling";
23
- client: RobotRock;
24
- };
25
- type RobotRockAiTriggerContext = {
26
- mode: "trigger";
27
- /** Inbox app bucket; falls back to `ROBOTROCK_APP` in the Trigger worker. */
28
- app?: string;
29
- };
30
- type RobotRockAiWorkflowContext = {
31
- mode: "workflow";
32
- /** Inbox app bucket; falls back to `ROBOTROCK_APP` in the workflow run. */
33
- app?: string;
34
- };
35
- type RobotRockAiContext = RobotRockAiPollingContext | RobotRockAiTriggerContext | RobotRockAiWorkflowContext;
36
- declare function normalizeRobotRockAiContext(clientOrContext: RobotRock | RobotRockAiContext): RobotRockAiContext;
37
- declare function sendToHumanForAi<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]>(context: RobotRockAiContext, payload: SendToHumanInput<A>): Promise<DiscriminatedApprovalResult<A>>;
38
- /**
39
- * Posts a thread update for an AI tool, routing by execution mode.
40
- *
41
- * `sendUpdate` is fire-and-forget (no human wait), so only the workflow path
42
- * needs durability — it runs inside a `"use step"`. Trigger and polling modes
43
- * issue the request directly.
44
- */
45
- declare function sendUpdateForAi(context: RobotRockAiContext, payload: SendUpdateInput): Promise<ThreadUpdate>;
46
- declare function approveByHumanForAi(context: RobotRockAiContext, payload: Omit<SendToHumanInput, "actions"> & {
47
- app?: string;
48
- }): Promise<DiscriminatedApprovalResult<typeof APPROVE_BY_HUMAN_ACTIONS$1>>;
49
-
50
- type HumanToolResult = {
51
- taskId: string;
52
- actionId: string;
53
- data: unknown;
54
- handledBy?: string;
55
- handledAt: string;
56
- /** Present when action ids are approve/decline (or approve/reject). */
57
- approved?: boolean;
58
- };
59
- type RobotRockToolCallInfo = {
60
- toolName: string;
61
- toolCallId: string;
62
- input: unknown;
63
- };
64
- type RobotRockToolApprovalConfig = {
65
- /** Tool names that require RobotRock inbox approval before execution. */
66
- tools?: readonly string[];
67
- /** Custom predicate when tool names alone are not enough. */
68
- when?: (toolCall: RobotRockToolCallInfo) => boolean;
69
- };
70
- type FormatToolApprovalTaskOptions = {
71
- type?: string;
72
- approveActionId?: string;
73
- denyActionId?: string;
74
- };
75
- type ResolveToolApprovalsOptions = {
76
- formatTask?: (toolCall: RobotRockToolCallInfo) => SendToHumanInput;
77
- approveActionId?: string;
78
- denyActionId?: string;
79
- };
80
- type RunWithRobotRockApprovalsOptions<T> = {
81
- /** Polling mode (requires `client`). */
82
- client?: RobotRock;
83
- /** Polling or Trigger mode; use `{ mode: "trigger" }` inside Trigger.dev workers. */
84
- context?: RobotRockAiContext;
85
- /** Initial messages; updated across approval rounds. */
86
- messages?: unknown[];
87
- maxRounds?: number;
88
- resolveOptions?: ResolveToolApprovalsOptions;
89
- generate: (messages: unknown[]) => Promise<T>;
90
- };
91
- type ToolApprovalRequestPart = {
92
- type: "tool-approval-request";
93
- approvalId: string;
94
- toolCallId?: string;
95
- toolCall?: RobotRockToolCallInfo;
96
- isAutomatic?: boolean;
97
- };
98
-
99
- declare const APPROVE_BY_HUMAN_ACTIONS: readonly [{
100
- readonly id: "approve";
101
- readonly title: "Approve";
102
- }, {
103
- readonly id: "decline";
104
- readonly title: "Decline";
105
- }];
106
- declare const approveByHumanInputSchema: z.ZodObject<{
107
- type: z.ZodOptional<z.ZodString>;
108
- name: z.ZodString;
109
- description: z.ZodString;
110
- contextSummary: z.ZodOptional<z.ZodString>;
111
- }, "strip", z.ZodTypeAny, {
112
- description: string;
113
- name: string;
114
- type?: string | undefined;
115
- contextSummary?: string | undefined;
116
- }, {
117
- description: string;
118
- name: string;
119
- type?: string | undefined;
120
- contextSummary?: string | undefined;
121
- }>;
122
- type ApproveByHumanToolOptions = {
123
- defaultType?: string;
124
- description?: string;
125
- toolName?: string;
126
- };
127
- type ApproveByHumanToolDurableOptions = ApproveByHumanToolOptions & RobotRockAiContext & {
128
- mode: "trigger" | "workflow";
129
- };
130
- /**
131
- * AI SDK tool with fixed approve/decline actions; blocks until a human decides.
132
- *
133
- * - `approveByHumanTool(robotrock)` — polling via `client.sendToHuman()` (default).
134
- * - `approveByHumanTool({ mode: "trigger", app?: "my-agent" })` — durable wait via Trigger.dev.
135
- * - `approveByHumanTool({ mode: "workflow", app?: "my-agent" })` — durable wait via Vercel Workflow.
136
- */
137
- declare function approveByHumanTool(clientOrContext: RobotRock | ApproveByHumanToolDurableOptions, maybeOptions?: ApproveByHumanToolOptions): ai.Tool<{
138
- description: string;
139
- name: string;
140
- type?: string | undefined;
141
- contextSummary?: string | undefined;
142
- }, HumanToolResult>;
143
-
144
- declare const sendToHumanToolInputSchema: z.ZodObject<{
145
- type: z.ZodString;
146
- name: z.ZodString;
147
- description: z.ZodOptional<z.ZodString>;
148
- context: z.ZodOptional<z.ZodObject<{
149
- data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
150
- ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
151
- }, "strip", z.ZodTypeAny, {
152
- ui?: Record<string, unknown> | undefined;
153
- data?: Record<string, unknown> | undefined;
154
- }, {
155
- ui?: Record<string, unknown> | undefined;
156
- data?: Record<string, unknown> | undefined;
157
- }>>;
158
- validUntil: z.ZodOptional<z.ZodString>;
159
- assignTo: z.ZodOptional<z.ZodEffects<z.ZodObject<{
160
- users: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
161
- groups: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
162
- }, "strip", z.ZodTypeAny, {
163
- users?: string[] | undefined;
164
- groups?: string[] | undefined;
165
- }, {
166
- users?: string[] | undefined;
167
- groups?: string[] | undefined;
168
- }>, {
169
- users?: string[] | undefined;
170
- groups?: string[] | undefined;
171
- }, {
172
- users?: string[] | undefined;
173
- groups?: string[] | undefined;
174
- }>>;
175
- }, "strip", z.ZodTypeAny, {
176
- type: string;
177
- name: string;
178
- description?: string | undefined;
179
- validUntil?: string | undefined;
180
- context?: {
181
- ui?: Record<string, unknown> | undefined;
182
- data?: Record<string, unknown> | undefined;
183
- } | undefined;
184
- assignTo?: {
185
- users?: string[] | undefined;
186
- groups?: string[] | undefined;
187
- } | undefined;
188
- }, {
189
- type: string;
190
- name: string;
191
- description?: string | undefined;
192
- validUntil?: string | undefined;
193
- context?: {
194
- ui?: Record<string, unknown> | undefined;
195
- data?: Record<string, unknown> | undefined;
196
- } | undefined;
197
- assignTo?: {
198
- users?: string[] | undefined;
199
- groups?: string[] | undefined;
200
- } | undefined;
201
- }>;
202
- type CreateSendToHumanToolOptions<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]> = {
203
- actions: A;
204
- defaultType?: string;
205
- description?: string;
206
- toolName?: string;
207
- /**
208
- * Group every task this tool creates onto a shared thread. Pass the same
209
- * value to {@link createSendUpdateTool} so updates land on the same thread.
210
- */
211
- threadId?: string;
212
- };
213
- type CreateSendToHumanToolDurableOptions<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]> = CreateSendToHumanToolOptions<A> & RobotRockAiContext & {
214
- mode: "trigger" | "workflow";
215
- };
216
- /**
217
- * AI SDK tool that blocks until a human handles a RobotRock task with developer-defined actions.
218
- *
219
- * - `createSendToHumanTool(robotrock, options)` — polling (default).
220
- * - `createSendToHumanTool({ mode: "trigger", actions: [...], app?: "my-agent" })` — Trigger.dev wait tokens.
221
- * - `createSendToHumanTool({ mode: "workflow", actions: [...], app?: "my-agent" })` — Vercel Workflow webhooks.
222
- */
223
- declare function createSendToHumanTool<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]>(clientOrOptions: RobotRock | CreateSendToHumanToolDurableOptions<A>, maybeOptions?: CreateSendToHumanToolOptions<A>): ai.Tool<{
224
- type: string;
225
- name: string;
226
- description?: string | undefined;
227
- validUntil?: string | undefined;
228
- context?: {
229
- ui?: Record<string, unknown> | undefined;
230
- data?: Record<string, unknown> | undefined;
231
- } | undefined;
232
- assignTo?: {
233
- users?: string[] | undefined;
234
- groups?: string[] | undefined;
235
- } | undefined;
236
- }, HumanToolResult>;
237
-
238
- /**
239
- * Result returned to the model by {@link createSendUpdateTool}.
240
- *
241
- * Updates are fire-and-forget, so a missing thread (no task created yet) is
242
- * reported as `{ posted: false }` instead of throwing — that way an agent loop
243
- * is never aborted by a non-critical progress update. Genuine failures (auth,
244
- * validation, server errors) still throw.
245
- */
246
- type SendUpdateToolResult = {
247
- posted: true;
248
- threadId: string;
249
- update: ThreadUpdate;
250
- } | {
251
- posted: false;
252
- threadId: string;
253
- reason: "thread_not_found";
254
- message: string;
255
- };
256
- declare const sendUpdateToolInputSchema: z.ZodObject<{
257
- threadId: z.ZodOptional<z.ZodString>;
258
- message: z.ZodString;
259
- status: z.ZodOptional<z.ZodEnum<["info", "queued", "running", "waiting", "succeeded", "failed", "cancelled"]>>;
260
- }, "strip", z.ZodTypeAny, {
261
- message: string;
262
- status?: "info" | "queued" | "running" | "waiting" | "succeeded" | "failed" | "cancelled" | undefined;
263
- threadId?: string | undefined;
264
- }, {
265
- message: string;
266
- status?: "info" | "queued" | "running" | "waiting" | "succeeded" | "failed" | "cancelled" | undefined;
267
- threadId?: string | undefined;
268
- }>;
269
- type CreateSendUpdateToolOptions = {
270
- /**
271
- * Session thread to post updates to when the model does not supply `threadId`.
272
- * Pass the same value to {@link createSendToHumanTool} to auto-thread tasks
273
- * and updates together.
274
- */
275
- threadId?: string;
276
- description?: string;
277
- };
278
- type CreateSendUpdateToolDurableOptions = CreateSendUpdateToolOptions & RobotRockAiContext & {
279
- mode: "trigger" | "workflow";
280
- };
281
- /**
282
- * AI SDK tool that posts a progress update to a RobotRock thread.
283
- *
284
- * Fire-and-forget (no human wait): the agent reports status as it works.
285
- *
286
- * - `createSendUpdateTool(robotrock, options?)` — polling client (default).
287
- * - `createSendUpdateTool({ mode: "trigger", app?: "my-agent" })` — Trigger.dev worker.
288
- * - `createSendUpdateTool({ mode: "workflow", app?: "my-agent" })` — Vercel Workflow (durable step).
289
- *
290
- * The thread is resolved from the tool input `threadId`, falling back to a
291
- * session `threadId` in the options. Provide at least one.
292
- */
293
- declare function createSendUpdateTool(clientOrOptions: RobotRock | CreateSendUpdateToolDurableOptions, maybeOptions?: CreateSendUpdateToolOptions): ai.Tool<{
294
- message: string;
295
- status?: "info" | "queued" | "running" | "waiting" | "succeeded" | "failed" | "cancelled" | undefined;
296
- threadId?: string | undefined;
297
- }, SendUpdateToolResult>;
298
-
299
- type CreateRobotRockAiToolsOptions = {
300
- /** @default "polling" when `client` is passed; `"trigger"` or `"workflow"` for durable waits. */
301
- mode?: "polling" | "trigger" | "workflow";
302
- client?: RobotRock;
303
- app?: string;
304
- /**
305
- * Shared thread for tasks and updates these tools create. Enables the
306
- * `sendUpdate` tool to auto-thread onto tasks made by the `sendToHuman` tool.
307
- */
308
- threadId?: string;
309
- };
310
- /**
311
- * Build AI SDK tools for a given RobotRock execution mode.
312
- *
313
- * @example Polling (Next.js route, scripts)
314
- * ```ts
315
- * const tools = createRobotRockAiTools({ client: robotrock });
316
- * ```
317
- *
318
- * @example Trigger.dev worker
319
- * ```ts
320
- * const tools = createRobotRockAiTools({ mode: "trigger", app: "my-agent" });
321
- * ```
322
- *
323
- * @example Vercel Workflow + DurableAgent
324
- * ```ts
325
- * const tools = createRobotRockAiTools({ mode: "workflow", app: "my-agent" });
326
- * ```
327
- */
328
- declare function createRobotRockAiTools(options: CreateRobotRockAiToolsOptions): {
329
- context: RobotRockAiContext;
330
- approveByHuman: (toolOptions?: ApproveByHumanToolOptions) => ai.Tool<{
331
- description: string;
332
- name: string;
333
- type?: string | undefined;
334
- contextSummary?: string | undefined;
335
- }, HumanToolResult>;
336
- sendToHuman: <A extends readonly SendToHumanActionInput[]>(toolOptions: CreateSendToHumanToolOptions<A>) => ai.Tool<{
337
- type: string;
338
- name: string;
339
- description?: string | undefined;
340
- validUntil?: string | undefined;
341
- context?: {
342
- ui?: Record<string, unknown> | undefined;
343
- data?: Record<string, unknown> | undefined;
344
- } | undefined;
345
- assignTo?: {
346
- users?: string[] | undefined;
347
- groups?: string[] | undefined;
348
- } | undefined;
349
- }, HumanToolResult>;
350
- sendUpdate: (toolOptions?: CreateSendUpdateToolOptions) => ai.Tool<{
351
- message: string;
352
- status?: "info" | "queued" | "running" | "waiting" | "succeeded" | "failed" | "cancelled" | undefined;
353
- threadId?: string | undefined;
354
- }, SendUpdateToolResult>;
355
- };
356
- /** Shorthand for `{ mode: "trigger", app }`. */
357
- declare function createRobotRockAiTriggerContext(options?: Omit<RobotRockAiTriggerContext, "mode">): RobotRockAiContext;
358
- /** Shorthand for `{ mode: "workflow", app }`. */
359
- declare function createRobotRockAiWorkflowContext(options?: Omit<RobotRockAiWorkflowContext, "mode">): RobotRockAiContext;
360
-
361
- type RobotRockToolApprovalDecision = "user-approval" | undefined;
362
- /**
363
- * AI SDK 7+: pass the return value to `toolApproval` on `generateText`, `streamText`, or `ToolLoopAgent`.
364
- * Returns `'user-approval'` for configured tools so execution pauses until a human responds via RobotRock.
365
- */
366
- declare function createRobotRockToolApproval(config: RobotRockToolApprovalConfig): (options: {
367
- toolCall: RobotRockToolCallInfo;
368
- }) => Promise<RobotRockToolApprovalDecision>;
369
- /**
370
- * AI SDK 5–6: use as `needsApproval` on tool definitions (or via {@link applyRobotRockToolApprovalToTools}).
371
- */
372
- declare function createRobotRockNeedsApproval(config: RobotRockToolApprovalConfig): (_input: unknown, options: {
373
- toolCallId: string;
374
- messages?: unknown[];
375
- }) => Promise<boolean>;
376
- /**
377
- * AI SDK 5–6: merge `needsApproval` into each matching tool in a tools object.
378
- */
379
- declare function applyRobotRockToolApprovalToTools<T extends Record<string, object>>(tools: T, config: RobotRockToolApprovalConfig): T;
380
- declare function collectApprovalRequests(source: unknown): ToolApprovalRequestPart[];
381
- /**
382
- * Create RobotRock tasks for pending AI SDK tool approvals and return `tool-approval-response` parts.
383
- */
384
- declare function resolveToolApprovalsViaRobotRock(clientOrContext: RobotRock | RobotRockAiContext, source: unknown, options?: ResolveToolApprovalsOptions): Promise<{
385
- responses: ToolApprovalResponse[];
386
- messages: unknown[];
387
- }>;
388
- /**
389
- * Run `generate` in a loop until manual tool approvals are resolved via RobotRock or `maxRounds` is reached.
390
- */
391
- declare function runWithRobotRockApprovals<T>(options: RunWithRobotRockApprovalsOptions<T>): Promise<T>;
392
-
393
- export { APPROVE_BY_HUMAN_ACTIONS as A, createRobotRockNeedsApproval as B, type CreateSendToHumanToolOptions as C, createRobotRockToolApproval as D, resolveToolApprovalsViaRobotRock as E, type FormatToolApprovalTaskOptions as F, runWithRobotRockApprovals as G, type HumanToolResult as H, type RobotRockToolApprovalDecision as I, type ResolveToolApprovalsOptions as J, type RobotRockToolApprovalConfig as K, type RunWithRobotRockApprovalsOptions as L, type RobotRockToolCallInfo as R, type SendUpdateToolResult as S, type ToolApprovalRequestPart as T, approveByHumanTool as a, approveByHumanInputSchema as b, type ApproveByHumanToolOptions as c, type ApproveByHumanToolDurableOptions as d, createSendToHumanTool as e, type CreateSendToHumanToolDurableOptions as f, createSendUpdateTool as g, sendUpdateToolInputSchema as h, type CreateSendUpdateToolOptions as i, type CreateSendUpdateToolDurableOptions as j, approveByHumanForAi as k, sendToHumanForAi as l, sendUpdateForAi as m, normalizeRobotRockAiContext as n, type RobotRockAiContext as o, type RobotRockAiMode as p, type RobotRockAiPollingContext as q, type RobotRockAiTriggerContext as r, sendToHumanToolInputSchema as s, type RobotRockAiWorkflowContext as t, createRobotRockAiTools as u, createRobotRockAiTriggerContext as v, createRobotRockAiWorkflowContext as w, type CreateRobotRockAiToolsOptions as x, applyRobotRockToolApprovalToTools as y, collectApprovalRequests as z };