robotrock 0.4.0 → 0.6.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.
- package/README.md +17 -2
- package/dist/ai/index.d.ts +3 -3
- package/dist/ai/index.js +9 -2
- package/dist/ai/trigger.d.ts +2 -2
- package/dist/ai/trigger.js +5 -2
- package/dist/ai/workflow.d.ts +2 -2
- package/dist/ai/workflow.js +5 -2
- package/dist/{chunk-RW2CQQZU.js → chunk-7VBBX2HA.js} +100 -5
- package/dist/chunk-7VBBX2HA.js.map +1 -0
- package/dist/{chunk-2KFY7ZJV.js → chunk-TAWMIQAM.js} +21 -1
- package/dist/chunk-TAWMIQAM.js.map +1 -0
- package/dist/{chunk-PZTTI6MW.js → chunk-ZCMXX7IG.js} +4 -2
- package/dist/chunk-ZCMXX7IG.js.map +1 -0
- package/dist/{client-BOm2Ce2f.d.ts → client-CLcHdjOz.d.ts} +6 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/schemas/index.d.ts +15 -1
- package/dist/schemas/index.js +11 -1
- package/dist/trigger/index.d.ts +1 -1
- package/dist/trigger/index.js +2 -2
- package/dist/workflow/index.d.ts +23 -3
- package/dist/workflow/index.js +19 -3
- package/dist/workflow/index.js.map +1 -1
- package/dist/{workflow-iDk0Hlyg.d.ts → workflow-CFcRMNhy.d.ts} +87 -3
- package/package.json +6 -2
- package/dist/chunk-2KFY7ZJV.js.map +0 -1
- package/dist/chunk-PZTTI6MW.js.map +0 -1
- package/dist/chunk-RW2CQQZU.js.map +0 -1
package/README.md
CHANGED
|
@@ -158,6 +158,21 @@ await robotrock.sendToHuman({
|
|
|
158
158
|
|
|
159
159
|
`status` is optional and one of: `info` | `queued` | `running` | `waiting` | `succeeded` | `failed` | `cancelled`. The `update` field is top-level (like `threadId` and `assignTo`), not inside `context`.
|
|
160
160
|
|
|
161
|
+
Updates are fire-and-forget, so the integration packages expose them too:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
// Vercel Workflow: durable step, returns immediately (no suspend)
|
|
165
|
+
import { sendUpdateInWorkflow } from "robotrock/workflow";
|
|
166
|
+
await sendUpdateInWorkflow({ threadId, message: "Build started.", status: "running" });
|
|
167
|
+
|
|
168
|
+
// Vercel AI SDK: let an agent report progress on its thread
|
|
169
|
+
import { createSendUpdateTool } from "robotrock/ai";
|
|
170
|
+
const sendUpdate = createSendUpdateTool(robotrock, { threadId });
|
|
171
|
+
|
|
172
|
+
// Trigger.dev: no wrapper needed — call the SDK directly inside a task
|
|
173
|
+
await robotrock.sendUpdate({ threadId, message: "Job running.", status: "running" });
|
|
174
|
+
```
|
|
175
|
+
|
|
161
176
|
## Other client methods
|
|
162
177
|
|
|
163
178
|
```typescript
|
|
@@ -248,7 +263,7 @@ const result = await generateText({
|
|
|
248
263
|
});
|
|
249
264
|
```
|
|
250
265
|
|
|
251
|
-
For AI SDK tool execution approval (approve `deleteFile` before it runs), use `createRobotRockToolApproval`, `resolveToolApprovalsViaRobotRock`, and `runWithRobotRockApprovals` from `robotrock/ai`. See the [Vercel AI integration docs](https://
|
|
266
|
+
For AI SDK tool execution approval (approve `deleteFile` before it runs), use `createRobotRockToolApproval`, `resolveToolApprovalsViaRobotRock`, and `runWithRobotRockApprovals` from `robotrock/ai`. See the [Vercel AI integration docs](https://docs.robotrock.io/integrations/vercel-ai).
|
|
252
267
|
|
|
253
268
|
Run long polls inside Trigger.dev or a worker — not short serverless HTTP handlers.
|
|
254
269
|
|
|
@@ -258,7 +273,7 @@ Run long polls inside Trigger.dev or a worker — not short serverless HTTP hand
|
|
|
258
273
|
|--------|-------------|
|
|
259
274
|
| `robotrock` | `createClient`, `RobotRock`, env helpers, types, schemas |
|
|
260
275
|
| `robotrock/trigger` | `sendToHumanTask`, `approveByHumanTask` for Trigger.dev |
|
|
261
|
-
| `robotrock/workflow` | `sendToHumanInWorkflow`, `approveByHumanInWorkflow` for Vercel Workflow |
|
|
276
|
+
| `robotrock/workflow` | `sendToHumanInWorkflow`, `approveByHumanInWorkflow`, `sendUpdateInWorkflow` for Vercel Workflow |
|
|
262
277
|
| `robotrock/ai` | Vercel AI SDK tools and `toolApproval` bridge (peer: `ai`) |
|
|
263
278
|
| `robotrock/ai/trigger` | Same API, documented for `mode: "trigger"` in Trigger.dev workers |
|
|
264
279
|
| `robotrock/ai/workflow` | Same API, documented for `mode: "workflow"` in Vercel Workflow |
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { R as RobotRockToolCallInfo, F as FormatToolApprovalTaskOptions, H as HumanToolResult } from '../workflow-
|
|
2
|
-
export { A as APPROVE_BY_HUMAN_ACTIONS, d as ApproveByHumanToolDurableOptions, c as ApproveByHumanToolOptions,
|
|
3
|
-
import { a as SendToHumanInput } from '../client-
|
|
1
|
+
import { R as RobotRockToolCallInfo, F as FormatToolApprovalTaskOptions, H as HumanToolResult } from '../workflow-CFcRMNhy.js';
|
|
2
|
+
export { A as APPROVE_BY_HUMAN_ACTIONS, d as ApproveByHumanToolDurableOptions, c as ApproveByHumanToolOptions, x as CreateRobotRockAiToolsOptions, f as CreateSendToHumanToolDurableOptions, C as CreateSendToHumanToolOptions, j as CreateSendUpdateToolDurableOptions, i as CreateSendUpdateToolOptions, J as ResolveToolApprovalsOptions, o as RobotRockAiContext, p as RobotRockAiMode, q as RobotRockAiPollingContext, r as RobotRockAiTriggerContext, t as RobotRockAiWorkflowContext, K as RobotRockToolApprovalConfig, I as RobotRockToolApprovalDecision, L as RunWithRobotRockApprovalsOptions, S as SendUpdateToolResult, T as ToolApprovalRequestPart, y as applyRobotRockToolApprovalToTools, k as approveByHumanForAi, b as approveByHumanInputSchema, a as approveByHumanTool, z as collectApprovalRequests, u as createRobotRockAiTools, v as createRobotRockAiTriggerContext, w as createRobotRockAiWorkflowContext, B as createRobotRockNeedsApproval, D as createRobotRockToolApproval, e as createSendToHumanTool, g as createSendUpdateTool, n as normalizeRobotRockAiContext, E as resolveToolApprovalsViaRobotRock, G as runWithRobotRockApprovals, l as sendToHumanForAi, s as sendToHumanToolInputSchema, m as sendUpdateForAi, h as sendUpdateToolInputSchema } from '../workflow-CFcRMNhy.js';
|
|
3
|
+
import { a as SendToHumanInput } from '../client-CLcHdjOz.js';
|
|
4
4
|
import { DiscriminatedApprovalResult } from '../schemas/index.js';
|
|
5
5
|
import 'ai';
|
|
6
6
|
import 'zod';
|
package/dist/ai/index.js
CHANGED
|
@@ -12,15 +12,19 @@ import {
|
|
|
12
12
|
createRobotRockNeedsApproval,
|
|
13
13
|
createRobotRockToolApproval,
|
|
14
14
|
createSendToHumanTool,
|
|
15
|
+
createSendUpdateTool,
|
|
15
16
|
defaultFormatToolApprovalTask,
|
|
16
17
|
normalizeRobotRockAiContext,
|
|
17
18
|
resolveToolApprovalsViaRobotRock,
|
|
18
19
|
runWithRobotRockApprovals,
|
|
19
20
|
sendToHumanForAi,
|
|
20
21
|
sendToHumanToolInputSchema,
|
|
22
|
+
sendUpdateForAi,
|
|
23
|
+
sendUpdateToolInputSchema,
|
|
21
24
|
toHumanToolResult
|
|
22
|
-
} from "../chunk-
|
|
23
|
-
import "../chunk-
|
|
25
|
+
} from "../chunk-7VBBX2HA.js";
|
|
26
|
+
import "../chunk-ZCMXX7IG.js";
|
|
27
|
+
import "../chunk-TAWMIQAM.js";
|
|
24
28
|
export {
|
|
25
29
|
APPROVE_BY_HUMAN_ACTIONS,
|
|
26
30
|
DEFAULT_APPROVE_ACTIONS,
|
|
@@ -35,12 +39,15 @@ export {
|
|
|
35
39
|
createRobotRockNeedsApproval,
|
|
36
40
|
createRobotRockToolApproval,
|
|
37
41
|
createSendToHumanTool,
|
|
42
|
+
createSendUpdateTool,
|
|
38
43
|
defaultFormatToolApprovalTask,
|
|
39
44
|
normalizeRobotRockAiContext,
|
|
40
45
|
resolveToolApprovalsViaRobotRock,
|
|
41
46
|
runWithRobotRockApprovals,
|
|
42
47
|
sendToHumanForAi,
|
|
43
48
|
sendToHumanToolInputSchema,
|
|
49
|
+
sendUpdateForAi,
|
|
50
|
+
sendUpdateToolInputSchema,
|
|
44
51
|
toHumanToolResult
|
|
45
52
|
};
|
|
46
53
|
//# sourceMappingURL=index.js.map
|
package/dist/ai/trigger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { o as RobotRockAiContext, p as RobotRockAiMode, q as RobotRockAiPollingContext, r as RobotRockAiTriggerContext, y as applyRobotRockToolApprovalToTools, a as approveByHumanTool, u as createRobotRockAiTools, v as createRobotRockAiTriggerContext, B as createRobotRockNeedsApproval, D as createRobotRockToolApproval, e as createSendToHumanTool, g as createSendUpdateTool, E as resolveToolApprovalsViaRobotRock, G as runWithRobotRockApprovals } from '../workflow-CFcRMNhy.js';
|
|
2
2
|
import 'ai';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../client-
|
|
4
|
+
import '../client-CLcHdjOz.js';
|
|
5
5
|
import '../schemas/index.js';
|
package/dist/ai/trigger.js
CHANGED
|
@@ -6,10 +6,12 @@ import {
|
|
|
6
6
|
createRobotRockNeedsApproval,
|
|
7
7
|
createRobotRockToolApproval,
|
|
8
8
|
createSendToHumanTool,
|
|
9
|
+
createSendUpdateTool,
|
|
9
10
|
resolveToolApprovalsViaRobotRock,
|
|
10
11
|
runWithRobotRockApprovals
|
|
11
|
-
} from "../chunk-
|
|
12
|
-
import "../chunk-
|
|
12
|
+
} from "../chunk-7VBBX2HA.js";
|
|
13
|
+
import "../chunk-ZCMXX7IG.js";
|
|
14
|
+
import "../chunk-TAWMIQAM.js";
|
|
13
15
|
export {
|
|
14
16
|
applyRobotRockToolApprovalToTools,
|
|
15
17
|
approveByHumanTool,
|
|
@@ -18,6 +20,7 @@ export {
|
|
|
18
20
|
createRobotRockNeedsApproval,
|
|
19
21
|
createRobotRockToolApproval,
|
|
20
22
|
createSendToHumanTool,
|
|
23
|
+
createSendUpdateTool,
|
|
21
24
|
resolveToolApprovalsViaRobotRock,
|
|
22
25
|
runWithRobotRockApprovals
|
|
23
26
|
};
|
package/dist/ai/workflow.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { o as RobotRockAiContext, p as RobotRockAiMode, q as RobotRockAiPollingContext, r as RobotRockAiTriggerContext, t as RobotRockAiWorkflowContext, y as applyRobotRockToolApprovalToTools, a as approveByHumanTool, u as createRobotRockAiTools, w as createRobotRockAiWorkflowContext, B as createRobotRockNeedsApproval, D as createRobotRockToolApproval, e as createSendToHumanTool, g as createSendUpdateTool, E as resolveToolApprovalsViaRobotRock, G as runWithRobotRockApprovals } from '../workflow-CFcRMNhy.js';
|
|
2
2
|
import 'ai';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../client-
|
|
4
|
+
import '../client-CLcHdjOz.js';
|
|
5
5
|
import '../schemas/index.js';
|
package/dist/ai/workflow.js
CHANGED
|
@@ -6,10 +6,12 @@ import {
|
|
|
6
6
|
createRobotRockNeedsApproval,
|
|
7
7
|
createRobotRockToolApproval,
|
|
8
8
|
createSendToHumanTool,
|
|
9
|
+
createSendUpdateTool,
|
|
9
10
|
resolveToolApprovalsViaRobotRock,
|
|
10
11
|
runWithRobotRockApprovals
|
|
11
|
-
} from "../chunk-
|
|
12
|
-
import "../chunk-
|
|
12
|
+
} from "../chunk-7VBBX2HA.js";
|
|
13
|
+
import "../chunk-ZCMXX7IG.js";
|
|
14
|
+
import "../chunk-TAWMIQAM.js";
|
|
13
15
|
export {
|
|
14
16
|
applyRobotRockToolApprovalToTools,
|
|
15
17
|
approveByHumanTool,
|
|
@@ -18,6 +20,7 @@ export {
|
|
|
18
20
|
createRobotRockNeedsApproval,
|
|
19
21
|
createRobotRockToolApproval,
|
|
20
22
|
createSendToHumanTool,
|
|
23
|
+
createSendUpdateTool,
|
|
21
24
|
resolveToolApprovalsViaRobotRock,
|
|
22
25
|
runWithRobotRockApprovals
|
|
23
26
|
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
RobotRockError,
|
|
3
|
+
createClient,
|
|
4
|
+
resolveRobotRockConfig
|
|
5
|
+
} from "./chunk-ZCMXX7IG.js";
|
|
6
|
+
import {
|
|
7
|
+
assignToSchema,
|
|
8
|
+
threadUpdateStatusSchema
|
|
9
|
+
} from "./chunk-TAWMIQAM.js";
|
|
4
10
|
|
|
5
11
|
// src/ai/context.ts
|
|
6
12
|
var APPROVE_BY_HUMAN_ACTIONS = [
|
|
@@ -59,6 +65,22 @@ async function sendToHumanForAi(context, payload) {
|
|
|
59
65
|
taskId: result.taskId
|
|
60
66
|
};
|
|
61
67
|
}
|
|
68
|
+
async function sendUpdateForAi(context, payload) {
|
|
69
|
+
if (context.mode === "workflow") {
|
|
70
|
+
const { sendUpdateInWorkflow } = await import("./workflow/index.js");
|
|
71
|
+
return sendUpdateInWorkflow({
|
|
72
|
+
...payload,
|
|
73
|
+
...context.app ? { app: context.app } : {}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (context.mode === "trigger") {
|
|
77
|
+
const client = createClient(
|
|
78
|
+
resolveRobotRockConfig(context.app ? { app: context.app } : void 0)
|
|
79
|
+
);
|
|
80
|
+
return client.sendUpdate(payload);
|
|
81
|
+
}
|
|
82
|
+
return context.client.sendUpdate(payload);
|
|
83
|
+
}
|
|
62
84
|
async function approveByHumanForAi(context, payload) {
|
|
63
85
|
if (context.mode === "trigger") {
|
|
64
86
|
const { approveByHumanTask } = await import("./trigger/index.js");
|
|
@@ -201,7 +223,8 @@ function createSendToHumanTool(clientOrOptions, maybeOptions) {
|
|
|
201
223
|
context: taskContext,
|
|
202
224
|
validUntil: input.validUntil,
|
|
203
225
|
assignTo: input.assignTo,
|
|
204
|
-
actions: options.actions
|
|
226
|
+
actions: options.actions,
|
|
227
|
+
...options.threadId ? { threadId: options.threadId } : {}
|
|
205
228
|
};
|
|
206
229
|
const result = await sendToHumanForAi(aiContext, payload);
|
|
207
230
|
return toHumanToolResult(result);
|
|
@@ -209,6 +232,60 @@ function createSendToHumanTool(clientOrOptions, maybeOptions) {
|
|
|
209
232
|
});
|
|
210
233
|
}
|
|
211
234
|
|
|
235
|
+
// src/ai/create-send-update-tool.ts
|
|
236
|
+
import { tool as tool3 } from "ai";
|
|
237
|
+
import { z as z3 } from "zod";
|
|
238
|
+
var sendUpdateToolInputSchema = z3.object({
|
|
239
|
+
threadId: z3.string().optional().describe(
|
|
240
|
+
"Thread to post the update to. Use the `threadId` returned by a prior send-to-human task. Omit only when a session threadId is configured on the tool."
|
|
241
|
+
),
|
|
242
|
+
message: z3.string().describe("Short progress update (1-2 sentences) shown in the inbox status bar"),
|
|
243
|
+
status: threadUpdateStatusSchema.optional().describe(
|
|
244
|
+
"Lifecycle status driving the status-bar icon/color: info, queued, running, waiting, succeeded, failed, cancelled"
|
|
245
|
+
)
|
|
246
|
+
});
|
|
247
|
+
function createSendUpdateTool(clientOrOptions, maybeOptions = {}) {
|
|
248
|
+
const isDurable = typeof clientOrOptions === "object" && clientOrOptions !== null && "mode" in clientOrOptions && (clientOrOptions.mode === "trigger" || clientOrOptions.mode === "workflow");
|
|
249
|
+
const aiContext = normalizeRobotRockAiContext(
|
|
250
|
+
isDurable ? {
|
|
251
|
+
mode: clientOrOptions.mode,
|
|
252
|
+
app: clientOrOptions.app
|
|
253
|
+
} : clientOrOptions
|
|
254
|
+
);
|
|
255
|
+
const options = isDurable ? clientOrOptions : maybeOptions;
|
|
256
|
+
const description = options.description ?? "Post a short progress update to the RobotRock thread you are working on. Use to report status changes (running, succeeded, failed) so humans can follow along in the inbox.";
|
|
257
|
+
return tool3({
|
|
258
|
+
description,
|
|
259
|
+
inputSchema: sendUpdateToolInputSchema,
|
|
260
|
+
execute: async (input) => {
|
|
261
|
+
const threadId = input.threadId ?? options.threadId;
|
|
262
|
+
if (!threadId) {
|
|
263
|
+
throw new Error(
|
|
264
|
+
"createSendUpdateTool: no threadId. Pass `threadId` from a prior send-to-human result, or configure a session `threadId` in the tool options."
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
const update = await sendUpdateForAi(aiContext, {
|
|
269
|
+
threadId,
|
|
270
|
+
message: input.message,
|
|
271
|
+
status: input.status
|
|
272
|
+
});
|
|
273
|
+
return { posted: true, threadId, update };
|
|
274
|
+
} catch (error) {
|
|
275
|
+
if (error instanceof RobotRockError && error.statusCode === 404) {
|
|
276
|
+
return {
|
|
277
|
+
posted: false,
|
|
278
|
+
threadId,
|
|
279
|
+
reason: "thread_not_found",
|
|
280
|
+
message: `No task exists for thread "${threadId}" yet, so the update was not posted. Create a task on this thread with send-to-human before reporting progress.`
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
212
289
|
// src/ai/create-ai-tools.ts
|
|
213
290
|
function createRobotRockAiTools(options) {
|
|
214
291
|
const mode = options.mode ?? (options.client ? "polling" : "trigger");
|
|
@@ -221,7 +298,22 @@ function createRobotRockAiTools(options) {
|
|
|
221
298
|
return {
|
|
222
299
|
context,
|
|
223
300
|
approveByHuman: (toolOptions) => durableContext ? approveByHumanTool({ ...durableContext, ...toolOptions }) : approveByHumanTool(pollingClient, toolOptions),
|
|
224
|
-
sendToHuman: (toolOptions) => durableContext ? createSendToHumanTool({
|
|
301
|
+
sendToHuman: (toolOptions) => durableContext ? createSendToHumanTool({
|
|
302
|
+
...durableContext,
|
|
303
|
+
...options.threadId ? { threadId: options.threadId } : {},
|
|
304
|
+
...toolOptions
|
|
305
|
+
}) : createSendToHumanTool(pollingClient, {
|
|
306
|
+
...options.threadId ? { threadId: options.threadId } : {},
|
|
307
|
+
...toolOptions
|
|
308
|
+
}),
|
|
309
|
+
sendUpdate: (toolOptions = {}) => durableContext ? createSendUpdateTool({
|
|
310
|
+
...durableContext,
|
|
311
|
+
...options.threadId ? { threadId: options.threadId } : {},
|
|
312
|
+
...toolOptions
|
|
313
|
+
}) : createSendUpdateTool(pollingClient, {
|
|
314
|
+
...options.threadId ? { threadId: options.threadId } : {},
|
|
315
|
+
...toolOptions
|
|
316
|
+
})
|
|
225
317
|
};
|
|
226
318
|
}
|
|
227
319
|
function createRobotRockAiTriggerContext(options = {}) {
|
|
@@ -496,6 +588,7 @@ async function runWithRobotRockApprovals(options) {
|
|
|
496
588
|
export {
|
|
497
589
|
normalizeRobotRockAiContext,
|
|
498
590
|
sendToHumanForAi,
|
|
591
|
+
sendUpdateForAi,
|
|
499
592
|
approveByHumanForAi,
|
|
500
593
|
toHumanToolResult,
|
|
501
594
|
APPROVE_BY_HUMAN_ACTIONS2 as APPROVE_BY_HUMAN_ACTIONS,
|
|
@@ -503,6 +596,8 @@ export {
|
|
|
503
596
|
approveByHumanTool,
|
|
504
597
|
sendToHumanToolInputSchema,
|
|
505
598
|
createSendToHumanTool,
|
|
599
|
+
sendUpdateToolInputSchema,
|
|
600
|
+
createSendUpdateTool,
|
|
506
601
|
createRobotRockAiTools,
|
|
507
602
|
createRobotRockAiTriggerContext,
|
|
508
603
|
createRobotRockAiWorkflowContext,
|
|
@@ -515,4 +610,4 @@ export {
|
|
|
515
610
|
resolveToolApprovalsViaRobotRock,
|
|
516
611
|
runWithRobotRockApprovals
|
|
517
612
|
};
|
|
518
|
-
//# sourceMappingURL=chunk-
|
|
613
|
+
//# sourceMappingURL=chunk-7VBBX2HA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ai/context.ts","../src/ai/human-tool-result.ts","../src/ai/approve-by-human-tool.ts","../src/ai/create-send-to-human-tool.ts","../src/ai/create-send-update-tool.ts","../src/ai/create-ai-tools.ts","../src/ai/format-tool-approval-task.ts","../src/ai/tool-approval-bridge.ts"],"sourcesContent":["import {\n createClient,\n type RobotRock,\n type SendToHumanActionInput,\n type SendToHumanInput,\n type SendUpdateInput,\n} from \"../client.js\";\nimport { resolveRobotRockConfig } from \"../env.js\";\nimport type { DiscriminatedApprovalResult, ThreadUpdate } from \"../schemas/index.js\";\nconst APPROVE_BY_HUMAN_ACTIONS = [\n { id: \"approve\", title: \"Approve\" },\n { id: \"decline\", title: \"Decline\" },\n] as const;\n\n/** How RobotRock waits for a human inside AI SDK tool `execute`. */\nexport type RobotRockAiMode = \"polling\" | \"trigger\" | \"workflow\";\n\n/**\n * Polling: `client.sendToHuman()` blocks until handled (scripts, API routes with long timeout).\n * Trigger: `sendToHumanTask.triggerAndWait()` uses wait tokens (Trigger.dev workers).\n * Workflow: `sendToHumanInWorkflow()` uses workflow webhooks (Vercel Workflow).\n */\nexport type RobotRockAiPollingContext = {\n mode?: \"polling\";\n client: RobotRock;\n};\n\nexport type RobotRockAiTriggerContext = {\n mode: \"trigger\";\n /** Inbox app bucket; falls back to `ROBOTROCK_APP` in the Trigger worker. */\n app?: string;\n};\n\nexport type RobotRockAiWorkflowContext = {\n mode: \"workflow\";\n /** Inbox app bucket; falls back to `ROBOTROCK_APP` in the workflow run. */\n app?: string;\n};\n\nexport type RobotRockAiContext =\n | RobotRockAiPollingContext\n | RobotRockAiTriggerContext\n | RobotRockAiWorkflowContext;\n\nexport function isRobotRockClient(value: unknown): value is RobotRock {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"sendToHuman\" in value &&\n typeof (value as RobotRock).sendToHuman === \"function\"\n );\n}\n\nexport function normalizeRobotRockAiContext(\n clientOrContext: RobotRock | RobotRockAiContext\n): RobotRockAiContext {\n if (isRobotRockClient(clientOrContext)) {\n return { mode: \"polling\", client: clientOrContext };\n }\n\n if (clientOrContext.mode === \"trigger\" || clientOrContext.mode === \"workflow\") {\n return clientOrContext;\n }\n\n if (clientOrContext.mode === \"polling\" || clientOrContext.mode === undefined) {\n if (!(\"client\" in clientOrContext) || !clientOrContext.client) {\n throw new Error('RobotRock AI polling mode requires `client` on the context object.');\n }\n return { mode: \"polling\", client: clientOrContext.client };\n }\n\n throw new Error(`Unknown RobotRock AI mode: ${String((clientOrContext as { mode?: string }).mode)}`);\n}\n\nexport async function sendToHumanForAi<\n A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[],\n>(\n context: RobotRockAiContext,\n payload: SendToHumanInput<A>\n): Promise<DiscriminatedApprovalResult<A>> {\n if (context.mode === \"trigger\") {\n const { sendToHumanTask } = await import(\"../trigger/index.js\");\n const waitResult = await sendToHumanTask.triggerAndWait({\n ...payload,\n ...(context.app ? { app: context.app } : {}),\n });\n\n if (!waitResult.ok) {\n throw waitResult.error;\n }\n\n return waitResult.output as DiscriminatedApprovalResult<A>;\n }\n\n if (context.mode === \"workflow\") {\n const { sendToHumanInWorkflow } = await import(\"../workflow/index.js\");\n const result = await sendToHumanInWorkflow({\n ...payload,\n ...(context.app ? { app: context.app } : {}),\n });\n return result as unknown as DiscriminatedApprovalResult<A>;\n }\n\n const result = await context.client.sendToHuman(payload);\n\n if (result.mode !== \"handled\") {\n throw new Error(\n \"RobotRock task was created but not handled. Configure client polling or webhook, or use mode: 'trigger' / 'workflow' for durable waits.\"\n );\n }\n\n return {\n actionId: result.actionId,\n data: result.data,\n handledBy: result.handledBy,\n handledAt: result.handledAt,\n taskId: result.taskId,\n } as DiscriminatedApprovalResult<A>;\n}\n\n/**\n * Posts a thread update for an AI tool, routing by execution mode.\n *\n * `sendUpdate` is fire-and-forget (no human wait), so only the workflow path\n * needs durability — it runs inside a `\"use step\"`. Trigger and polling modes\n * issue the request directly.\n */\nexport async function sendUpdateForAi(\n context: RobotRockAiContext,\n payload: SendUpdateInput\n): Promise<ThreadUpdate> {\n if (context.mode === \"workflow\") {\n const { sendUpdateInWorkflow } = await import(\"../workflow/index.js\");\n return sendUpdateInWorkflow({\n ...payload,\n ...(context.app ? { app: context.app } : {}),\n });\n }\n\n if (context.mode === \"trigger\") {\n const client = createClient(\n resolveRobotRockConfig(context.app ? { app: context.app } : undefined)\n );\n return client.sendUpdate(payload);\n }\n\n return context.client.sendUpdate(payload);\n}\n\nexport async function approveByHumanForAi(\n context: RobotRockAiContext,\n payload: Omit<SendToHumanInput, \"actions\"> & { app?: string }\n): Promise<DiscriminatedApprovalResult<typeof APPROVE_BY_HUMAN_ACTIONS>> {\n if (context.mode === \"trigger\") {\n const { approveByHumanTask } = await import(\"../trigger/index.js\");\n const waitResult = await approveByHumanTask.triggerAndWait({\n ...payload,\n ...(context.app ? { app: context.app } : {}),\n });\n\n if (!waitResult.ok) {\n throw waitResult.error;\n }\n\n return waitResult.output;\n }\n\n if (context.mode === \"workflow\") {\n const { approveByHumanInWorkflow } = await import(\"../workflow/index.js\");\n return await approveByHumanInWorkflow({\n ...payload,\n ...(context.app ? { app: context.app } : {}),\n });\n }\n\n const result = await context.client.sendToHuman({\n ...payload,\n actions: APPROVE_BY_HUMAN_ACTIONS,\n });\n\n if (result.mode !== \"handled\") {\n throw new Error(\n \"RobotRock approval was not handled. Configure client polling or use mode: 'trigger' / 'workflow' for durable waits.\"\n );\n }\n\n return {\n actionId: result.actionId,\n data: result.data,\n handledBy: result.handledBy,\n handledAt: result.handledAt,\n taskId: result.taskId,\n } as DiscriminatedApprovalResult<typeof APPROVE_BY_HUMAN_ACTIONS>;\n}\n","import type { DiscriminatedApprovalResult } from \"../schemas/index.js\";\nimport type { HumanToolResult } from \"./types.js\";\n\nconst APPROVE_IDS = new Set([\"approve\", \"approved\"]);\nconst DECLINE_IDS = new Set([\"decline\", \"reject\", \"deny\", \"denied\"]);\n\nexport function toHumanToolResult(\n result: DiscriminatedApprovalResult<readonly { id: string }[]>\n): HumanToolResult {\n const payload: HumanToolResult = {\n taskId: result.taskId,\n actionId: result.actionId,\n data: result.data,\n handledBy: result.handledBy,\n handledAt: result.handledAt.toISOString(),\n };\n\n if (APPROVE_IDS.has(result.actionId)) {\n payload.approved = true;\n } else if (DECLINE_IDS.has(result.actionId)) {\n payload.approved = false;\n }\n\n return payload;\n}\n","import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { RobotRock } from \"../client.js\";\nimport { approveByHumanForAi, normalizeRobotRockAiContext, type RobotRockAiContext } from \"./context.js\";\nimport { toHumanToolResult } from \"./human-tool-result.js\";\nimport type { HumanToolResult } from \"./types.js\";\n\nconst APPROVE_BY_HUMAN_ACTIONS = [\n { id: \"approve\", title: \"Approve\" },\n { id: \"decline\", title: \"Decline\" },\n] as const;\n\nconst approveByHumanInputSchema = z.object({\n type: z\n .string()\n .optional()\n .describe(\"Task type slug; defaults to ai-approval\"),\n name: z.string().describe(\"Short title for the approval request\"),\n description: z\n .string()\n .describe(\"What needs approval and the consequences of approving or declining\"),\n contextSummary: z\n .string()\n .optional()\n .describe(\"Optional markdown summary shown to the reviewer\"),\n});\n\nexport type ApproveByHumanToolOptions = {\n defaultType?: string;\n description?: string;\n toolName?: string;\n};\n\nexport type ApproveByHumanToolDurableOptions = ApproveByHumanToolOptions &\n RobotRockAiContext & { mode: \"trigger\" | \"workflow\" };\n\n/**\n * AI SDK tool with fixed approve/decline actions; blocks until a human decides.\n *\n * - `approveByHumanTool(robotrock)` — polling via `client.sendToHuman()` (default).\n * - `approveByHumanTool({ mode: \"trigger\", app?: \"my-agent\" })` — durable wait via Trigger.dev.\n * - `approveByHumanTool({ mode: \"workflow\", app?: \"my-agent\" })` — durable wait via Vercel Workflow.\n */\nexport function approveByHumanTool(\n clientOrContext: RobotRock | ApproveByHumanToolDurableOptions,\n maybeOptions: ApproveByHumanToolOptions = {}\n) {\n const isDurable =\n typeof clientOrContext === \"object\" &&\n clientOrContext !== null &&\n \"mode\" in clientOrContext &&\n (clientOrContext.mode === \"trigger\" || clientOrContext.mode === \"workflow\");\n\n const aiContext = normalizeRobotRockAiContext(\n isDurable\n ? {\n mode: (clientOrContext as ApproveByHumanToolDurableOptions).mode,\n app: (clientOrContext as ApproveByHumanToolDurableOptions).app,\n }\n : (clientOrContext as RobotRock)\n );\n const options = isDurable\n ? (clientOrContext as ApproveByHumanToolDurableOptions)\n : maybeOptions;\n const description =\n options.description ??\n \"Request explicit human approval before a sensitive or irreversible step. Returns whether the human approved or declined.\";\n\n return tool({\n description,\n inputSchema: approveByHumanInputSchema,\n execute: async (input: z.infer<typeof approveByHumanInputSchema>): Promise<HumanToolResult> => {\n const taskContext =\n input.contextSummary !== undefined\n ? {\n data: { summary: input.contextSummary },\n ui: {\n summary: { \"ui:widget\": \"textarea\", \"ui:options\": { rows: 6 } },\n },\n }\n : undefined;\n\n const result = await approveByHumanForAi(aiContext, {\n type: input.type ?? options.defaultType ?? \"ai-approval\",\n name: input.name,\n description: input.description,\n context: taskContext,\n });\n\n return toHumanToolResult(result);\n },\n });\n}\n\nexport { APPROVE_BY_HUMAN_ACTIONS, approveByHumanInputSchema };\n","import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport { assignToSchema } from \"../schemas/index.js\";\nimport type { RobotRock, SendToHumanActionInput, SendToHumanInput } from \"../client.js\";\nimport type { TaskContextInput } from \"../schemas/index.js\";\nimport {\n normalizeRobotRockAiContext,\n sendToHumanForAi,\n type RobotRockAiContext,\n} from \"./context.js\";\nimport { toHumanToolResult } from \"./human-tool-result.js\";\nimport type { HumanToolResult } from \"./types.js\";\n\nconst contextInputSchema = z\n .object({\n data: z.record(z.unknown()).optional(),\n ui: z.record(z.unknown()).optional(),\n })\n .optional();\n\nconst sendToHumanToolInputSchema = z.object({\n type: z.string().describe(\"Task type slug shown in the RobotRock inbox\"),\n name: z.string().describe(\"Short title for the human reviewer\"),\n description: z\n .string()\n .optional()\n .describe(\"What you need from the human and why you cannot proceed alone\"),\n context: contextInputSchema.describe(\"Optional structured context for the inbox UI\"),\n validUntil: z\n .string()\n .datetime()\n .optional()\n .describe(\"Optional ISO deadline for the task\"),\n assignTo: assignToSchema\n .optional()\n .describe(\n \"Assign to tenant member emails and/or group slugs; narrows who sees the task in the inbox\"\n ),\n});\n\nexport type CreateSendToHumanToolOptions<\n A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[],\n> = {\n actions: A;\n defaultType?: string;\n description?: string;\n toolName?: string;\n /**\n * Group every task this tool creates onto a shared thread. Pass the same\n * value to {@link createSendUpdateTool} so updates land on the same thread.\n */\n threadId?: string;\n};\n\nexport type CreateSendToHumanToolDurableOptions<\n A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[],\n> = CreateSendToHumanToolOptions<A> & RobotRockAiContext & { mode: \"trigger\" | \"workflow\" };\n\n/**\n * AI SDK tool that blocks until a human handles a RobotRock task with developer-defined actions.\n *\n * - `createSendToHumanTool(robotrock, options)` — polling (default).\n * - `createSendToHumanTool({ mode: \"trigger\", actions: [...], app?: \"my-agent\" })` — Trigger.dev wait tokens.\n * - `createSendToHumanTool({ mode: \"workflow\", actions: [...], app?: \"my-agent\" })` — Vercel Workflow webhooks.\n */\nexport function createSendToHumanTool<\n A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[],\n>(\n clientOrOptions: RobotRock | CreateSendToHumanToolDurableOptions<A>,\n maybeOptions?: CreateSendToHumanToolOptions<A>\n) {\n const isDurable =\n typeof clientOrOptions === \"object\" &&\n clientOrOptions !== null &&\n \"mode\" in clientOrOptions &&\n (clientOrOptions.mode === \"trigger\" || clientOrOptions.mode === \"workflow\");\n\n const aiContext = normalizeRobotRockAiContext(\n isDurable\n ? {\n mode: (clientOrOptions as CreateSendToHumanToolDurableOptions<A>).mode,\n app: (clientOrOptions as CreateSendToHumanToolDurableOptions<A>).app,\n }\n : (clientOrOptions as RobotRock)\n );\n const options = (isDurable ? clientOrOptions : maybeOptions!) as CreateSendToHumanToolOptions<A>;\n const description =\n options.description ??\n \"Request structured input or a decision from a human in the RobotRock inbox. Use when you lack required information, need policy approval, or must confirm an irreversible step.\";\n\n return tool({\n description,\n inputSchema: sendToHumanToolInputSchema,\n execute: async (\n input: z.infer<typeof sendToHumanToolInputSchema>\n ): Promise<HumanToolResult> => {\n const taskContext: TaskContextInput[\"context\"] | undefined = input.context\n ? ({\n data: input.context.data ?? {},\n ui: input.context.ui,\n } as TaskContextInput[\"context\"])\n : undefined;\n\n const payload: SendToHumanInput<A> = {\n type: input.type ?? options.defaultType ?? \"ai-human-input\",\n name: input.name,\n description: input.description,\n context: taskContext,\n validUntil: input.validUntil,\n assignTo: input.assignTo,\n actions: options.actions,\n ...(options.threadId ? { threadId: options.threadId } : {}),\n };\n\n const result = await sendToHumanForAi(aiContext, payload);\n\n return toHumanToolResult(result);\n },\n });\n}\n\nexport { sendToHumanToolInputSchema };\n","import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport { threadUpdateStatusSchema } from \"../schemas/index.js\";\nimport { RobotRockError, type RobotRock } from \"../client.js\";\nimport type { ThreadUpdate } from \"../schemas/index.js\";\nimport {\n normalizeRobotRockAiContext,\n sendUpdateForAi,\n type RobotRockAiContext,\n} from \"./context.js\";\n\n/**\n * Result returned to the model by {@link createSendUpdateTool}.\n *\n * Updates are fire-and-forget, so a missing thread (no task created yet) is\n * reported as `{ posted: false }` instead of throwing — that way an agent loop\n * is never aborted by a non-critical progress update. Genuine failures (auth,\n * validation, server errors) still throw.\n */\nexport type SendUpdateToolResult =\n | { posted: true; threadId: string; update: ThreadUpdate }\n | {\n posted: false;\n threadId: string;\n reason: \"thread_not_found\";\n message: string;\n };\n\nconst sendUpdateToolInputSchema = z.object({\n threadId: z\n .string()\n .optional()\n .describe(\n \"Thread to post the update to. Use the `threadId` returned by a prior send-to-human task. Omit only when a session threadId is configured on the tool.\"\n ),\n message: z\n .string()\n .describe(\"Short progress update (1-2 sentences) shown in the inbox status bar\"),\n status: threadUpdateStatusSchema\n .optional()\n .describe(\n \"Lifecycle status driving the status-bar icon/color: info, queued, running, waiting, succeeded, failed, cancelled\"\n ),\n});\n\nexport type CreateSendUpdateToolOptions = {\n /**\n * Session thread to post updates to when the model does not supply `threadId`.\n * Pass the same value to {@link createSendToHumanTool} to auto-thread tasks\n * and updates together.\n */\n threadId?: string;\n description?: string;\n};\n\nexport type CreateSendUpdateToolDurableOptions = CreateSendUpdateToolOptions &\n RobotRockAiContext & { mode: \"trigger\" | \"workflow\" };\n\n/**\n * AI SDK tool that posts a progress update to a RobotRock thread.\n *\n * Fire-and-forget (no human wait): the agent reports status as it works.\n *\n * - `createSendUpdateTool(robotrock, options?)` — polling client (default).\n * - `createSendUpdateTool({ mode: \"trigger\", app?: \"my-agent\" })` — Trigger.dev worker.\n * - `createSendUpdateTool({ mode: \"workflow\", app?: \"my-agent\" })` — Vercel Workflow (durable step).\n *\n * The thread is resolved from the tool input `threadId`, falling back to a\n * session `threadId` in the options. Provide at least one.\n */\nexport function createSendUpdateTool(\n clientOrOptions: RobotRock | CreateSendUpdateToolDurableOptions,\n maybeOptions: CreateSendUpdateToolOptions = {}\n) {\n const isDurable =\n typeof clientOrOptions === \"object\" &&\n clientOrOptions !== null &&\n \"mode\" in clientOrOptions &&\n (clientOrOptions.mode === \"trigger\" || clientOrOptions.mode === \"workflow\");\n\n const aiContext: RobotRockAiContext = normalizeRobotRockAiContext(\n isDurable\n ? {\n mode: (clientOrOptions as CreateSendUpdateToolDurableOptions).mode,\n app: (clientOrOptions as CreateSendUpdateToolDurableOptions).app,\n }\n : (clientOrOptions as RobotRock)\n );\n const options = isDurable\n ? (clientOrOptions as CreateSendUpdateToolDurableOptions)\n : maybeOptions;\n const description =\n options.description ??\n \"Post a short progress update to the RobotRock thread you are working on. Use to report status changes (running, succeeded, failed) so humans can follow along in the inbox.\";\n\n return tool({\n description,\n inputSchema: sendUpdateToolInputSchema,\n execute: async (\n input: z.infer<typeof sendUpdateToolInputSchema>\n ): Promise<SendUpdateToolResult> => {\n const threadId = input.threadId ?? options.threadId;\n if (!threadId) {\n throw new Error(\n \"createSendUpdateTool: no threadId. Pass `threadId` from a prior send-to-human result, or configure a session `threadId` in the tool options.\"\n );\n }\n\n try {\n const update = await sendUpdateForAi(aiContext, {\n threadId,\n message: input.message,\n status: input.status,\n });\n return { posted: true, threadId, update };\n } catch (error) {\n if (error instanceof RobotRockError && error.statusCode === 404) {\n return {\n posted: false,\n threadId,\n reason: \"thread_not_found\",\n message: `No task exists for thread \"${threadId}\" yet, so the update was not posted. Create a task on this thread with send-to-human before reporting progress.`,\n };\n }\n throw error;\n }\n },\n });\n}\n\nexport { sendUpdateToolInputSchema };\n","import type { RobotRock, SendToHumanActionInput } from \"../client.js\";\nimport type {\n RobotRockAiContext,\n RobotRockAiTriggerContext,\n RobotRockAiWorkflowContext,\n} from \"./context.js\";\nimport { normalizeRobotRockAiContext } from \"./context.js\";\nimport { approveByHumanTool as buildApproveByHumanTool } from \"./approve-by-human-tool.js\";\nimport {\n createSendToHumanTool as buildSendToHumanTool,\n type CreateSendToHumanToolOptions,\n} from \"./create-send-to-human-tool.js\";\nimport {\n createSendUpdateTool as buildSendUpdateTool,\n type CreateSendUpdateToolOptions,\n} from \"./create-send-update-tool.js\";\nimport type { ApproveByHumanToolOptions } from \"./approve-by-human-tool.js\";\n\nexport type CreateRobotRockAiToolsOptions = {\n /** @default \"polling\" when `client` is passed; `\"trigger\"` or `\"workflow\"` for durable waits. */\n mode?: \"polling\" | \"trigger\" | \"workflow\";\n client?: RobotRock;\n app?: string;\n /**\n * Shared thread for tasks and updates these tools create. Enables the\n * `sendUpdate` tool to auto-thread onto tasks made by the `sendToHuman` tool.\n */\n threadId?: string;\n};\n\n/**\n * Build AI SDK tools for a given RobotRock execution mode.\n *\n * @example Polling (Next.js route, scripts)\n * ```ts\n * const tools = createRobotRockAiTools({ client: robotrock });\n * ```\n *\n * @example Trigger.dev worker\n * ```ts\n * const tools = createRobotRockAiTools({ mode: \"trigger\", app: \"my-agent\" });\n * ```\n *\n * @example Vercel Workflow + DurableAgent\n * ```ts\n * const tools = createRobotRockAiTools({ mode: \"workflow\", app: \"my-agent\" });\n * ```\n */\nexport function createRobotRockAiTools(options: CreateRobotRockAiToolsOptions) {\n const mode = options.mode ?? (options.client ? \"polling\" : \"trigger\");\n\n if (mode === \"polling\" && !options.client) {\n throw new Error('createRobotRockAiTools: polling mode requires `client`.');\n }\n\n const context: RobotRockAiContext =\n mode === \"trigger\"\n ? { mode: \"trigger\", app: options.app }\n : mode === \"workflow\"\n ? { mode: \"workflow\", app: options.app }\n : { mode: \"polling\", client: options.client! };\n\n const durableContext =\n context.mode === \"trigger\" || context.mode === \"workflow\" ? context : null;\n const pollingClient = context.mode === \"polling\" ? context.client : undefined;\n\n return {\n context,\n approveByHuman: (toolOptions?: ApproveByHumanToolOptions) =>\n durableContext\n ? buildApproveByHumanTool({ ...durableContext, ...toolOptions })\n : buildApproveByHumanTool(pollingClient!, toolOptions),\n sendToHuman: <A extends readonly SendToHumanActionInput[]>(\n toolOptions: CreateSendToHumanToolOptions<A>\n ) =>\n durableContext\n ? buildSendToHumanTool({\n ...durableContext,\n ...(options.threadId ? { threadId: options.threadId } : {}),\n ...toolOptions,\n })\n : buildSendToHumanTool(pollingClient!, {\n ...(options.threadId ? { threadId: options.threadId } : {}),\n ...toolOptions,\n }),\n sendUpdate: (toolOptions: CreateSendUpdateToolOptions = {}) =>\n durableContext\n ? buildSendUpdateTool({\n ...durableContext,\n ...(options.threadId ? { threadId: options.threadId } : {}),\n ...toolOptions,\n })\n : buildSendUpdateTool(pollingClient!, {\n ...(options.threadId ? { threadId: options.threadId } : {}),\n ...toolOptions,\n }),\n };\n}\n\n/** Shorthand for `{ mode: \"trigger\", app }`. */\nexport function createRobotRockAiTriggerContext(\n options: Omit<RobotRockAiTriggerContext, \"mode\"> = {}\n): RobotRockAiContext {\n return { mode: \"trigger\", ...options };\n}\n\n/** Shorthand for `{ mode: \"workflow\", app }`. */\nexport function createRobotRockAiWorkflowContext(\n options: Omit<RobotRockAiWorkflowContext, \"mode\"> = {}\n): RobotRockAiContext {\n return { mode: \"workflow\", ...options };\n}\n\nexport { normalizeRobotRockAiContext };\n","import type { SendToHumanInput } from \"../client.js\";\nimport type { FormatToolApprovalTaskOptions, RobotRockToolCallInfo } from \"./types.js\";\n\nconst DEFAULT_APPROVE_ACTIONS = [\n { id: \"approve\", title: \"Approve execution\" },\n { id: \"deny\", title: \"Deny\" },\n] as const;\n\n/**\n * Build a RobotRock task payload for an AI SDK tool approval request.\n */\nexport function defaultFormatToolApprovalTask(\n toolCall: RobotRockToolCallInfo,\n options: FormatToolApprovalTaskOptions = {}\n): SendToHumanInput {\n const approveId = options.approveActionId ?? \"approve\";\n const denyId = options.denyActionId ?? \"deny\";\n\n let inputPreview: string;\n try {\n inputPreview = JSON.stringify(toolCall.input, null, 2);\n } catch {\n inputPreview = String(toolCall.input);\n }\n\n return {\n type: options.type ?? \"ai-tool-approval\",\n name: `Approve: ${toolCall.toolName}`,\n description: `Review the proposed \\`${toolCall.toolName}\\` tool call before it runs.`,\n context: {\n data: {\n toolName: toolCall.toolName,\n toolCallId: toolCall.toolCallId,\n input: toolCall.input,\n },\n ui: {\n toolName: { \"ui:widget\": \"text\" },\n toolCallId: { \"ui:widget\": \"text\" },\n input: { \"ui:widget\": \"textarea\" },\n },\n },\n actions: [\n { id: approveId, title: \"Approve execution\" },\n { id: denyId, title: \"Deny\" },\n ],\n };\n}\n\nexport { DEFAULT_APPROVE_ACTIONS };\n","import type { ToolApprovalResponse } from \"ai\";\nimport type { RobotRock } from \"../client.js\";\nimport {\n normalizeRobotRockAiContext,\n sendToHumanForAi,\n type RobotRockAiContext,\n} from \"./context.js\";\nimport { defaultFormatToolApprovalTask } from \"./format-tool-approval-task.js\";\nimport type {\n ResolveToolApprovalsOptions,\n RobotRockToolApprovalConfig,\n RobotRockToolCallInfo,\n RunWithRobotRockApprovalsOptions,\n ToolApprovalRequestPart,\n} from \"./types.js\";\n\nexport type RobotRockToolApprovalDecision = \"user-approval\" | undefined;\n\nfunction buildToolMatcher(config: RobotRockToolApprovalConfig) {\n const names = config.tools ? new Set(config.tools) : null;\n\n return (toolCall: RobotRockToolCallInfo): boolean => {\n if (config.when?.(toolCall)) {\n return true;\n }\n if (names && names.has(toolCall.toolName)) {\n return true;\n }\n return false;\n };\n}\n\n/**\n * AI SDK 7+: pass the return value to `toolApproval` on `generateText`, `streamText`, or `ToolLoopAgent`.\n * Returns `'user-approval'` for configured tools so execution pauses until a human responds via RobotRock.\n */\nexport function createRobotRockToolApproval(config: RobotRockToolApprovalConfig) {\n const matches = buildToolMatcher(config);\n\n const toolApproval = async (options: {\n toolCall: RobotRockToolCallInfo;\n }): Promise<RobotRockToolApprovalDecision> => {\n return matches(options.toolCall) ? \"user-approval\" : undefined;\n };\n\n return toolApproval;\n}\n\n/**\n * AI SDK 5–6: use as `needsApproval` on tool definitions (or via {@link applyRobotRockToolApprovalToTools}).\n */\nexport function createRobotRockNeedsApproval(config: RobotRockToolApprovalConfig) {\n const matches = buildToolMatcher(config);\n\n return async (\n _input: unknown,\n options: { toolCallId: string; messages?: unknown[] }\n ): Promise<boolean> => {\n const toolCall = findToolCallInMessages(options.messages, options.toolCallId);\n if (!toolCall) {\n return false;\n }\n return matches(toolCall);\n };\n}\n\n/**\n * AI SDK 5–6: merge `needsApproval` into each matching tool in a tools object.\n */\nexport function applyRobotRockToolApprovalToTools<T extends Record<string, object>>(\n tools: T,\n config: RobotRockToolApprovalConfig\n): T {\n const names = config.tools ? new Set(config.tools) : null;\n const needsApproval = createRobotRockNeedsApproval(config);\n\n const next = { ...tools } as T;\n\n for (const key of Object.keys(tools) as Array<keyof T>) {\n const name = String(key);\n const shouldApply =\n (names && names.has(name)) || (names === null && config.when !== undefined);\n\n if (!shouldApply) {\n continue;\n }\n\n const existing = tools[key];\n next[key] = {\n ...existing,\n needsApproval,\n } as T[keyof T];\n }\n\n return next;\n}\n\nfunction findToolCallInMessages(\n messages: unknown[] | undefined,\n toolCallId: string\n): RobotRockToolCallInfo | undefined {\n if (!messages) {\n return undefined;\n }\n\n for (const message of messages) {\n if (typeof message !== \"object\" || message === null) {\n continue;\n }\n const role = (message as { role?: string }).role;\n if (role !== \"assistant\") {\n continue;\n }\n const content = (message as { content?: unknown }).content;\n if (!Array.isArray(content)) {\n continue;\n }\n\n for (const part of content) {\n if (typeof part !== \"object\" || part === null) {\n continue;\n }\n const p = part as Record<string, unknown>;\n if (p.type === \"tool-call\" && p.toolCallId === toolCallId) {\n return {\n toolName: String(p.toolName ?? \"\"),\n toolCallId,\n input: p.input,\n };\n }\n }\n }\n\n return undefined;\n}\n\nfunction collectApprovalRequests(source: unknown): ToolApprovalRequestPart[] {\n const requests: ToolApprovalRequestPart[] = [];\n\n const visit = (value: unknown) => {\n if (!value) {\n return;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n visit(item);\n }\n return;\n }\n\n if (typeof value !== \"object\") {\n return;\n }\n\n const obj = value as Record<string, unknown>;\n\n if (obj.type === \"tool-approval-request\" && typeof obj.approvalId === \"string\") {\n if (obj.isAutomatic === true) {\n return;\n }\n\n const embedded = obj.toolCall as Record<string, unknown> | undefined;\n const toolCallId =\n typeof obj.toolCallId === \"string\"\n ? obj.toolCallId\n : typeof embedded?.toolCallId === \"string\"\n ? embedded.toolCallId\n : undefined;\n\n let toolCall: RobotRockToolCallInfo | undefined;\n if (embedded && typeof embedded.toolName === \"string\") {\n toolCall = {\n toolName: embedded.toolName,\n toolCallId: String(embedded.toolCallId ?? toolCallId ?? \"\"),\n input: embedded.input,\n };\n } else if (toolCallId) {\n toolCall = findToolCallInMessages(\n (source as { messages?: unknown[] }).messages,\n toolCallId\n );\n }\n\n requests.push({\n type: \"tool-approval-request\",\n approvalId: obj.approvalId,\n toolCallId,\n toolCall,\n isAutomatic: obj.isAutomatic === true,\n });\n return;\n }\n\n if (Array.isArray(obj.content)) {\n visit(obj.content);\n }\n if (Array.isArray(obj.steps)) {\n visit(obj.steps);\n }\n if (obj.response && typeof obj.response === \"object\") {\n visit((obj.response as { messages?: unknown[] }).messages);\n }\n };\n\n visit(source);\n\n if (typeof source === \"object\" && source !== null && Array.isArray((source as { content?: unknown[] }).content)) {\n visit((source as { content: unknown[] }).content);\n }\n\n const seen = new Set<string>();\n return requests.filter((r) => {\n if (seen.has(r.approvalId)) {\n return false;\n }\n seen.add(r.approvalId);\n return true;\n });\n}\n\nfunction resolveToolCallForRequest(\n request: ToolApprovalRequestPart,\n source: unknown,\n messages: unknown[]\n): RobotRockToolCallInfo {\n if (request.toolCall) {\n return request.toolCall;\n }\n\n const toolCallId = request.toolCallId;\n if (toolCallId) {\n const fromMessages = findToolCallInMessages(messages, toolCallId);\n if (fromMessages) {\n return fromMessages;\n }\n }\n\n if (typeof source === \"object\" && source !== null && Array.isArray((source as { toolCalls?: unknown[] }).toolCalls)) {\n for (const call of (source as { toolCalls: Array<Record<string, unknown>> }).toolCalls) {\n if (call.toolCallId === toolCallId) {\n return {\n toolName: String(call.toolName ?? \"\"),\n toolCallId: String(call.toolCallId ?? \"\"),\n input: call.input,\n };\n }\n }\n }\n\n throw new Error(\n `Could not resolve tool call for approval ${request.approvalId}. Pass messages that include the assistant tool-call.`\n );\n}\n\n/**\n * Create RobotRock tasks for pending AI SDK tool approvals and return `tool-approval-response` parts.\n */\nexport async function resolveToolApprovalsViaRobotRock(\n clientOrContext: RobotRock | RobotRockAiContext,\n source: unknown,\n options: ResolveToolApprovalsOptions = {}\n): Promise<{\n responses: ToolApprovalResponse[];\n messages: unknown[];\n}> {\n const context = normalizeRobotRockAiContext(clientOrContext);\n const approveId = options.approveActionId ?? \"approve\";\n const denyId = options.denyActionId ?? \"deny\";\n const formatTask = options.formatTask ?? defaultFormatToolApprovalTask;\n\n const baseMessages =\n typeof source === \"object\" && source !== null && Array.isArray((source as { messages?: unknown[] }).messages)\n ? [...(source as { messages: unknown[] }).messages]\n : [];\n\n const requests = collectApprovalRequests(source);\n const responses: ToolApprovalResponse[] = [];\n\n for (const request of requests) {\n const toolCall = resolveToolCallForRequest(request, source, baseMessages);\n const taskInput = formatTask(toolCall, {\n approveActionId: approveId,\n denyActionId: denyId,\n });\n\n const result = await sendToHumanForAi(context, taskInput);\n\n const approved = result.actionId === approveId;\n const reason =\n typeof result.data === \"object\" &&\n result.data !== null &&\n \"reason\" in result.data &&\n typeof (result.data as { reason?: unknown }).reason === \"string\"\n ? (result.data as { reason: string }).reason\n : approved\n ? \"Approved in RobotRock inbox\"\n : \"Denied in RobotRock inbox\";\n\n responses.push({\n type: \"tool-approval-response\",\n approvalId: request.approvalId,\n approved,\n reason,\n });\n }\n\n const messages = [...baseMessages];\n if (responses.length > 0) {\n messages.push({ role: \"tool\", content: responses });\n }\n\n return { responses, messages };\n}\n\n/**\n * Run `generate` in a loop until manual tool approvals are resolved via RobotRock or `maxRounds` is reached.\n */\nexport async function runWithRobotRockApprovals<T>(\n options: RunWithRobotRockApprovalsOptions<T>\n): Promise<T> {\n const clientOrContext =\n options.context ??\n (options.client\n ? options.client\n : (() => {\n throw new Error(\"runWithRobotRockApprovals requires `client` or `context`.\");\n })());\n\n const maxRounds = options.maxRounds ?? 20;\n let messages = options.messages ? [...options.messages] : [];\n let lastResult: T | undefined;\n\n for (let round = 0; round < maxRounds; round++) {\n lastResult = await options.generate(messages);\n const { responses, messages: nextMessages } = await resolveToolApprovalsViaRobotRock(\n clientOrContext,\n { ...(lastResult as object), messages },\n options.resolveOptions\n );\n\n if (responses.length === 0) {\n return lastResult;\n }\n\n messages = nextMessages;\n }\n\n throw new Error(`RobotRock approval loop exceeded maxRounds (${maxRounds})`);\n}\n\nexport { collectApprovalRequests };\n"],"mappings":";;;;;;;;;;;AASA,IAAM,2BAA2B;AAAA,EAC/B,EAAE,IAAI,WAAW,OAAO,UAAU;AAAA,EAClC,EAAE,IAAI,WAAW,OAAO,UAAU;AACpC;AAgCO,SAAS,kBAAkB,OAAoC;AACpE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,iBAAiB,SACjB,OAAQ,MAAoB,gBAAgB;AAEhD;AAEO,SAAS,4BACd,iBACoB;AACpB,MAAI,kBAAkB,eAAe,GAAG;AACtC,WAAO,EAAE,MAAM,WAAW,QAAQ,gBAAgB;AAAA,EACpD;AAEA,MAAI,gBAAgB,SAAS,aAAa,gBAAgB,SAAS,YAAY;AAC7E,WAAO;AAAA,EACT;AAEA,MAAI,gBAAgB,SAAS,aAAa,gBAAgB,SAAS,QAAW;AAC5E,QAAI,EA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AChB,CAAC;AAED,UAAM,SAAS,MAAM,iBAAiB,SAAS,SAAS;AAExD,UAAM,WAAW,OAAO,aAAa;AACrC,UAAM,SACJ,OAAO,OAAO,SAAS,YACvB,OAAO,SAAS,QAChB,YAAY,OAAO,QACnB,OAAQ,OAAO,KAA8B,WAAW,WACnD,OAAO,KAA4B,SACpC,WACE,gCACA;AAER,cAAU,KAAK;AAAA,MACb,MAAM;AAAA,MACN,YAAY,QAAQ;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,WAAW,CAAC,GAAG,YAAY;AACjC,MAAI,UAAU,SAAS,GAAG;AACxB,aAAS,KAAK,EAAE,MAAM,QAAQ,SAAS,UAAU,CAAC;AAAA,EACpD;AAEA,SAAO,EAAE,WAAW,SAAS;AAC/B;AAKA,eAAsB,0BACpB,SACY;AACZ,QAAM,kBACJ,QAAQ,YACP,QAAQ,SACL,QAAQ,UACP,MAAM;AACL,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E,GAAG;AAET,QAAM,YAAY,QAAQ,aAAa;AACvC,MAAI,WAAW,QAAQ,WAAW,CAAC,GAAG,QAAQ,QAAQ,IAAI,CAAC;AAC3D,MAAI;AAEJ,WAAS,QAAQ,GAAG,QAAQ,WAAW,SAAS;AAC9C,iBAAa,MAAM,QAAQ,SAAS,QAAQ;AAC5C,UAAM,EAAE,WAAW,UAAU,aAAa,IAAI,MAAM;AAAA,MAClD;AAAA,MACA,EAAE,GAAI,YAAuB,SAAS;AAAA,MACtC,QAAQ;AAAA,IACV;AAEA,QAAI,UAAU,WAAW,GAAG;AAC1B,aAAO;AAAA,IACT;AAEA,eAAW;AAAA,EACb;AAEA,QAAM,IAAI,MAAM,+CAA+C,SAAS,GAAG;AAC7E;","names":["result","APPROVE_BY_HUMAN_ACTIONS","tool","z","z","tool","tool","z","z","tool"]}
|
|
@@ -126,6 +126,16 @@ var threadUpdateInputSchema = z.object({
|
|
|
126
126
|
message: threadUpdateMessageSchema,
|
|
127
127
|
status: threadUpdateStatusSchema.optional()
|
|
128
128
|
});
|
|
129
|
+
var taskPriorities = ["low", "normal", "high", "urgent"];
|
|
130
|
+
var taskPrioritySchema = z.enum(taskPriorities);
|
|
131
|
+
var DEFAULT_TASK_PRIORITY = "normal";
|
|
132
|
+
var LOWEST_TASK_PRIORITY = "low";
|
|
133
|
+
var TASK_PRIORITY_RANK = {
|
|
134
|
+
low: 1,
|
|
135
|
+
normal: 2,
|
|
136
|
+
high: 3,
|
|
137
|
+
urgent: 4
|
|
138
|
+
};
|
|
129
139
|
var createTaskBodySchema = taskContextSchema.extend({
|
|
130
140
|
assignTo: assignToSchema.optional(),
|
|
131
141
|
/**
|
|
@@ -133,6 +143,11 @@ var createTaskBodySchema = taskContextSchema.extend({
|
|
|
133
143
|
* returns it so the caller can reuse it on later tasks in the same thread.
|
|
134
144
|
*/
|
|
135
145
|
threadId: z.string().min(1).optional(),
|
|
146
|
+
/**
|
|
147
|
+
* Optional thread priority. When set, applies to the whole thread and
|
|
148
|
+
* overwrites any previous priority. Omit on later tasks to leave unchanged.
|
|
149
|
+
*/
|
|
150
|
+
priority: taskPrioritySchema.optional(),
|
|
136
151
|
/**
|
|
137
152
|
* Optional initial status update logged against the task's thread. Shows in
|
|
138
153
|
* the inbox status bar and the thread update log.
|
|
@@ -151,7 +166,12 @@ export {
|
|
|
151
166
|
threadUpdateStatusSchema,
|
|
152
167
|
DEFAULT_THREAD_UPDATE_STATUS,
|
|
153
168
|
threadUpdateInputSchema,
|
|
169
|
+
taskPriorities,
|
|
170
|
+
taskPrioritySchema,
|
|
171
|
+
DEFAULT_TASK_PRIORITY,
|
|
172
|
+
LOWEST_TASK_PRIORITY,
|
|
173
|
+
TASK_PRIORITY_RANK,
|
|
154
174
|
createTaskBodySchema,
|
|
155
175
|
threadUpdateBodySchema
|
|
156
176
|
};
|
|
157
|
-
//# sourceMappingURL=chunk-
|
|
177
|
+
//# sourceMappingURL=chunk-TAWMIQAM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/index.ts"],"sourcesContent":["import { z } from \"zod\";\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\n .string()\n .refine((url) => url.startsWith(\"http://\") || url.startsWith(\"https://\"), {\n message: \"URL must start with http:// or https://\",\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()),\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.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.unknown()).optional(),\n items: z.lazy(() => z.record(uiFieldSchemaSchema)).optional(),\n })\n .passthrough();\n\nconst contextUiSchema = z.record(uiFieldSchemaSchema).optional();\n\nconst contextDataSchema = z\n .object({\n data: z.record(z.unknown()),\n ui: contextUiSchema,\n })\n .optional();\n\nexport const taskContextSchema = 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\n/**\n * Assignment targets at task create (not stored in task context JSON).\n * Unknown user emails are auto-provisioned as assignee memberships (not full team seats).\n */\nexport const assignToSchema = z\n .object({\n users: z.array(z.string().email()).optional(),\n groups: z.array(z.string().min(1)).optional(),\n })\n .refine(\n (data) => {\n const groups = data.groups ?? [];\n if (groups.includes(\"all\") && groups.length > 1) {\n return false;\n }\n return true;\n },\n { message: 'Cannot combine \"all\" with other group slugs' }\n );\n\n/** A short thread-scoped status update message (1-2 sentences). */\nexport const threadUpdateMessageSchema = z.string().min(1).max(500);\n\n/**\n * Lifecycle status carried by a thread update. Drives the icon and color shown\n * in the inbox status bar. Defaults to `info` when omitted.\n */\nexport const threadUpdateStatuses = [\n \"info\",\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n] as const;\n\nexport const threadUpdateStatusSchema = z.enum(threadUpdateStatuses);\n\n/** The default status applied when an update omits one. */\nexport const DEFAULT_THREAD_UPDATE_STATUS: ThreadUpdateStatus = \"info\";\n\n/** Shared shape for a thread update (standalone and at task creation). */\nexport const threadUpdateInputSchema = z.object({\n message: threadUpdateMessageSchema,\n status: threadUpdateStatusSchema.optional(),\n});\n\n/** Thread priority levels for inbox ordering and display. */\nexport const taskPriorities = [\"low\", \"normal\", \"high\", \"urgent\"] as const;\n\nexport const taskPrioritySchema = z.enum(taskPriorities);\n\nexport type TaskPriority = (typeof taskPriorities)[number];\n\nexport const DEFAULT_TASK_PRIORITY: TaskPriority = \"normal\";\n\nexport const LOWEST_TASK_PRIORITY: TaskPriority = \"low\";\n\nexport const TASK_PRIORITY_RANK: Record<TaskPriority, number> = {\n low: 1,\n normal: 2,\n high: 3,\n urgent: 4,\n};\n\nexport const createTaskBodySchema = taskContextSchema.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});\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>;\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]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O,SAAS,KAAK,KAAK,OAAO,SAAS,GAAG;AAC/C,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EACA,EAAE,SAAS,8CAA8C;AAC3D;AAGK,IAAM,4BAA4B,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG;AAM3D,IAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,2BAA2B,EAAE,KAAK,oBAAoB;AAG5D,IAAM,+BAAmD;AAGzD,IAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,SAAS;AAAA,EACT,QAAQ,yBAAyB,SAAS;AAC5C,CAAC;AAGM,IAAM,iBAAiB,CAAC,OAAO,UAAU,QAAQ,QAAQ;AAEzD,IAAM,qBAAqB,EAAE,KAAK,cAAc;AAIhD,IAAM,wBAAsC;AAE5C,IAAM,uBAAqC;AAE3C,IAAM,qBAAmD;AAAA,EAC9D,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AACV;AAEO,IAAM,uBAAuB,kBAAkB,OAAO;AAAA,EAC3D,UAAU,eAAe,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKlC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKrC,UAAU,mBAAmB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtC,QAAQ,wBAAwB,SAAS;AAC3C,CAAC;AAGM,IAAM,yBAAyB;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createTaskBodySchema,
|
|
3
3
|
threadUpdateBodySchema
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-TAWMIQAM.js";
|
|
5
5
|
|
|
6
6
|
// src/approval-result.ts
|
|
7
7
|
var TaskTimeoutError = class extends Error {
|
|
@@ -111,6 +111,7 @@ var RobotRock = class {
|
|
|
111
111
|
...normalizedTask,
|
|
112
112
|
...task.assignTo !== void 0 ? { assignTo: task.assignTo } : {},
|
|
113
113
|
...task.threadId !== void 0 ? { threadId: task.threadId } : {},
|
|
114
|
+
...task.priority !== void 0 ? { priority: task.priority } : {},
|
|
114
115
|
...task.update !== void 0 ? { update: task.update } : {}
|
|
115
116
|
};
|
|
116
117
|
const validation = createTaskBodySchema.safeParse(bodyPayload);
|
|
@@ -289,6 +290,7 @@ function normalizeSendToHumanInput(task, clientDefaults) {
|
|
|
289
290
|
idempotencyKey: _idempotencyKey,
|
|
290
291
|
assignTo: _assignTo,
|
|
291
292
|
threadId: _threadId,
|
|
293
|
+
priority: _priority,
|
|
292
294
|
update: _update,
|
|
293
295
|
validUntil,
|
|
294
296
|
app: taskApp,
|
|
@@ -369,4 +371,4 @@ export {
|
|
|
369
371
|
resolveRobotRockConfig,
|
|
370
372
|
resolveRobotRockClient
|
|
371
373
|
};
|
|
372
|
-
//# sourceMappingURL=chunk-
|
|
374
|
+
//# sourceMappingURL=chunk-ZCMXX7IG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/approval-result.ts","../src/client.ts","../src/env.ts"],"sourcesContent":["import type { DiscriminatedApprovalResult, Task } from \"./schemas/index.js\";\n\nexport class TaskTimeoutError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"TaskTimeoutError\";\n }\n}\n\nexport class TaskExpiredError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"TaskExpiredError\";\n }\n}\n\n/**\n * Map a handled API task to a discriminated approval result.\n * Runtime validation is minimal; TypeScript narrows via `task.actions` at the call site.\n */\nexport function toDiscriminatedApprovalResult<A extends readonly { id: string; schema?: unknown }[]>(\n actions: A,\n task: Task\n): DiscriminatedApprovalResult<A> {\n void actions;\n\n if (!task.handled) {\n throw new Error(\"Task has no handled result\");\n }\n\n return {\n actionId: task.handled.action.id,\n data: task.handled.action.data,\n handledBy: task.handled.handledBy,\n handledAt: new Date(task.handledAt ?? Date.now()),\n taskId: task.id,\n } as DiscriminatedApprovalResult<A>;\n}\n","import {\n type AssignToInput,\n type TaskContextInput,\n createTaskBodySchema,\n threadUpdateBodySchema,\n} from \"./schemas/index.js\";\nimport {\n TaskExpiredError,\n TaskTimeoutError,\n toDiscriminatedApprovalResult,\n} from \"./approval-result.js\";\nimport type {\n DiscriminatedApprovalResult,\n Task,\n TaskPriority,\n TaskResponse,\n ThreadUpdate,\n ThreadUpdateResponse,\n ThreadUpdateStatus,\n} from \"./schemas/index.js\";\n\nexport type RobotRockWebhookConfig = {\n url: string;\n headers?: Record<string, string>;\n};\n\nexport interface RobotRockPollingOptions {\n /** Poll interval when no webhook is configured (ms). @default 2000 */\n intervalMs?: number;\n /**\n * Max time to poll when no webhook is configured (ms).\n * Polling also stops when the task's `validUntil` passes, whichever is sooner.\n * @default 86400000 (24h)\n */\n timeoutMs?: number;\n}\n\ntype RobotRockClientBaseConfig = {\n /** Optional override for API key. Falls back to ROBOTROCK_API_KEY. */\n apiKey?: string;\n /**\n * Base URL for the RobotRock API\n * @default \"https://api.robotrock.io/v1\"\n */\n baseUrl?: string;\n /**\n * Default inbox app bucket for every task from this client.\n * When omitted, the API uses your API key name.\n */\n app?: string;\n /**\n * Task context format version sent on every `sendToHuman` request.\n * @default 2\n */\n version?: 2;\n};\n\n/** Client config with a webhook (mutually exclusive with `polling`). */\nexport type RobotRockWebhookClientConfig = RobotRockClientBaseConfig & {\n webhook: RobotRockWebhookConfig;\n polling?: never;\n};\n\n/** Client config without a webhook; optional `polling` controls the wait loop. */\nexport type RobotRockPollingClientConfig = RobotRockClientBaseConfig & {\n webhook?: never;\n polling?: RobotRockPollingOptions;\n};\n\nexport type RobotRockConfig = RobotRockWebhookClientConfig | RobotRockPollingClientConfig;\n\nexport type SendToHumanActionInput = Omit<TaskContextInput[\"actions\"][number], \"handlers\">;\n\nexport type SendToHumanValidUntil = Date | string;\n\nexport type SendToHumanInput<\n A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[],\n> = Omit<TaskContextInput, \"app\" | \"actions\" | \"version\" | \"validUntil\"> & {\n actions: A;\n /** Task deadline; serialized to an ISO 8601 string on the wire. */\n validUntil?: SendToHumanValidUntil;\n /** Optional idempotency key to prevent duplicate tasks */\n idempotencyKey?: string;\n /** Assign to tenant users (email) and/or groups (slug). Narrows inbox visibility. */\n assignTo?: AssignToInput;\n /**\n * Groups related tasks together in the inbox. Omit to let the server generate\n * one (returned as `task.threadId`) and reuse it on later tasks in the thread.\n */\n threadId?: string;\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?: TaskPriority;\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?: {\n /** A short status update (1-2 sentences). */\n message: string;\n /** Lifecycle status for the icon/color in the status bar. @default \"info\" */\n status?: ThreadUpdateStatus;\n };\n};\n\ntype SendToHumanWithAppInput<\n A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[],\n> = (SendToHumanInput<A> | Readonly<SendToHumanInput<A>>) & {\n /** Inbox app bucket. Overrides the client `app` when set. */\n app?: string;\n};\n\nexport type SendUpdateInput = {\n /** The thread to log the update against (from `task.threadId`). */\n threadId: string;\n /** A short status update (1-2 sentences). */\n message: string;\n /** Lifecycle status for the icon/color in the status bar. @default \"info\" */\n status?: ThreadUpdateStatus;\n};\n\nexport type SendToHumanResult<\n A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[],\n> =\n | {\n mode: \"created\";\n task: TaskResponse[\"task\"];\n }\n | ({\n mode: \"handled\";\n task: TaskResponse[\"task\"];\n } & DiscriminatedApprovalResult<A>);\n\nconst DEFAULT_POLL_INTERVAL_MS = 2_000;\nconst DEFAULT_TIMEOUT_MS = 24 * 60 * 60 * 1_000;\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction parseValidUntilMs(value: string | number | Date | undefined): number | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n if (value instanceof Date) {\n const ms = value.getTime();\n return Number.isNaN(ms) ? undefined : ms;\n }\n\n if (typeof value === \"number\") {\n return Number.isFinite(value) ? value : undefined;\n }\n\n const parsed = Date.parse(value);\n return Number.isNaN(parsed) ? undefined : parsed;\n}\n\nfunction serializeValidUntil(value: SendToHumanValidUntil): string {\n if (value instanceof Date) {\n const ms = value.getTime();\n if (Number.isNaN(ms)) {\n throw new RobotRockError(\"Invalid validUntil: Date is invalid\", 400);\n }\n return value.toISOString();\n }\n\n if (typeof value === \"string\" && !Number.isNaN(Date.parse(value))) {\n return new Date(value).toISOString();\n }\n\n throw new RobotRockError(\"Invalid validUntil: expected a Date or parseable date string\", 400);\n}\n\nexport class RobotRockError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number,\n public readonly response?: unknown\n ) {\n super(message);\n this.name = \"RobotRockError\";\n }\n}\n\n/**\n * RobotRock API client for creating and querying human-in-the-loop tasks.\n */\nexport class RobotRock {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly app?: string;\n private readonly version: 2;\n private readonly webhook?: RobotRockWebhookConfig;\n private readonly polling: RobotRockPollingOptions;\n\n constructor(config: RobotRockConfig) {\n if (config.webhook && config.polling) {\n throw new Error(\n \"RobotRock client cannot configure both webhook and polling. Use webhook for callbacks or polling to block until handled.\"\n );\n }\n\n const apiKey = config.apiKey ?? process.env.ROBOTROCK_API_KEY;\n if (!apiKey) {\n throw new Error(\n \"RobotRock API key is required. Set ROBOTROCK_API_KEY or pass apiKey when creating the client.\"\n );\n }\n this.apiKey = apiKey;\n const rawBase = config.baseUrl ?? \"https://api.robotrock.io/v1\";\n this.baseUrl = rawBase.replace(/\\/+$/, \"\");\n this.app = config.app;\n this.version = config.version ?? 2;\n this.webhook = config.webhook;\n this.polling = config.polling ?? {};\n }\n\n /**\n * Create a task via POST /v1 without waiting for a human response.\n */\n async createTask<const A extends readonly SendToHumanActionInput[]>(\n task: SendToHumanWithAppInput<A>\n ): Promise<TaskResponse[\"task\"]> {\n const normalizedTask = normalizeSendToHumanInput(task, {\n webhook: this.webhook,\n app: this.app,\n version: this.version,\n });\n const bodyPayload = {\n ...normalizedTask,\n ...(task.assignTo !== undefined ? { assignTo: task.assignTo } : {}),\n ...(task.threadId !== undefined ? { threadId: task.threadId } : {}),\n ...(task.priority !== undefined ? { priority: task.priority } : {}),\n ...(task.update !== undefined ? { update: task.update } : {}),\n };\n const validation = createTaskBodySchema.safeParse(bodyPayload);\n if (!validation.success) {\n throw new RobotRockError(\n `Invalid task: ${validation.error.errors[0]?.message}`,\n 400,\n validation.error.errors\n );\n }\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"X-Api-Key\": this.apiKey,\n };\n\n if (task.idempotencyKey) {\n headers[\"Idempotency-Key\"] = task.idempotencyKey;\n }\n\n const response = await fetch(`${this.baseUrl}/`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(validation.data),\n });\n\n const data = await parseResponseBody(response);\n\n if (!response.ok) {\n throw new RobotRockError(\n getErrorMessage(data, \"Failed to create task\"),\n response.status,\n data\n );\n }\n\n return (data as unknown as TaskResponse).task;\n }\n\n async sendToHuman<const A extends readonly SendToHumanActionInput[]>(\n task: SendToHumanWithAppInput<A>\n ): Promise<SendToHumanResult<A>> {\n const normalizedTask = normalizeSendToHumanInput(task, {\n webhook: this.webhook,\n app: this.app,\n version: this.version,\n });\n const createdTaskTask = await this.createTask(task);\n const hasHandlers = normalizedTask.actions.some(\n (action) => Array.isArray(action.handlers) && action.handlers.length > 0\n );\n\n if (hasHandlers) {\n return {\n mode: \"created\",\n task: createdTaskTask,\n };\n }\n\n const timeoutMs = this.polling.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const pollIntervalMs = this.polling.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const pollingDeadline = Date.now() + timeoutMs;\n const validUntilMs = parseValidUntilMs(createdTaskTask.validUntil);\n const deadline =\n validUntilMs !== undefined ? Math.min(pollingDeadline, validUntilMs) : pollingDeadline;\n const taskId = createdTaskTask.taskId;\n\n while (Date.now() < deadline) {\n const existing = await this.getTask(taskId);\n\n if (existing?.status === \"handled\" && existing.handled) {\n return {\n mode: \"handled\",\n task: createdTaskTask,\n ...(toDiscriminatedApprovalResult(\n normalizedTask.actions as unknown as A,\n existing\n ) as DiscriminatedApprovalResult<A>),\n };\n }\n\n if (existing?.status === \"expired\" || (existing && Date.now() >= existing.validUntil)) {\n throw new TaskExpiredError(\"Task reached validUntil before a human completed it\");\n }\n\n const remainingMs = deadline - Date.now();\n await sleep(Math.min(pollIntervalMs, Math.max(0, remainingMs)));\n }\n\n if (validUntilMs !== undefined && Date.now() >= validUntilMs) {\n throw new TaskExpiredError(\"Task reached validUntil before a human completed it\");\n }\n\n throw new TaskTimeoutError(`No human response within ${timeoutMs}ms`);\n }\n\n /**\n * Get a task by public task id (returned as `task.taskId` from {@link sendToHuman}).\n */\n async getTask(taskId: string): Promise<Task | null> {\n const response = await fetch(`${this.baseUrl}/tasks/${taskId}`, {\n method: \"GET\",\n headers: {\n \"X-Api-Key\": this.apiKey,\n },\n });\n\n if (response.status === 404) {\n return null;\n }\n\n const data = await parseResponseBody(response);\n\n if (!response.ok) {\n throw new RobotRockError(\n getErrorMessage(data, \"Failed to get task\"),\n response.status,\n data\n );\n }\n\n return data as unknown as Task;\n }\n\n /**\n * Log a status update against a thread. The update shows in the inbox status\n * bar and thread update log for every task in the thread.\n */\n async sendUpdate({ threadId, message, status }: SendUpdateInput): Promise<ThreadUpdate> {\n if (!threadId) {\n throw new RobotRockError(\"threadId is required to send an update\", 400);\n }\n\n const validation = threadUpdateBodySchema.safeParse({ message, status });\n if (!validation.success) {\n throw new RobotRockError(\n `Invalid update: ${validation.error.errors[0]?.message}`,\n 400,\n validation.error.errors\n );\n }\n\n const response = await fetch(\n `${this.baseUrl}/threads/${encodeURIComponent(threadId)}/updates`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Api-Key\": this.apiKey,\n },\n body: JSON.stringify(validation.data),\n }\n );\n\n const data = await parseResponseBody(response);\n\n if (!response.ok) {\n throw new RobotRockError(\n getErrorMessage(data, \"Failed to send update\"),\n response.status,\n data\n );\n }\n\n return (data as unknown as ThreadUpdateResponse).update;\n }\n\n async cancelTask(taskId: string): Promise<void> {\n const response = await fetch(`${this.baseUrl}/tasks/${taskId}/cancel`, {\n method: \"POST\",\n headers: {\n \"X-Api-Key\": this.apiKey,\n },\n });\n\n if (!response.ok) {\n const data = await parseResponseBody(response);\n throw new RobotRockError(\n getErrorMessage(data, \"Failed to cancel task\"),\n response.status,\n data\n );\n }\n }\n}\n\nexport function createClient(config: RobotRockConfig): RobotRock {\n return new RobotRock(config);\n}\n\nexport function attachWebhookToActions(\n actions: readonly SendToHumanActionInput[],\n webhook: RobotRockWebhookConfig\n): TaskContextInput[\"actions\"] {\n return actions.map((action) => ({\n ...action,\n handlers: webhookToHandlers(webhook),\n }));\n}\n\nfunction webhookToHandlers(\n webhook: RobotRockWebhookConfig\n): TaskContextInput[\"actions\"][number][\"handlers\"] {\n return [\n {\n type: \"webhook\" as const,\n url: webhook.url,\n headers: webhook.headers ?? {},\n },\n ];\n}\n\nfunction normalizeSendToHumanInput<\n A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[],\n>(\n task: SendToHumanWithAppInput<A>,\n clientDefaults: { webhook?: RobotRockWebhookConfig; app?: string; version: 2 }\n): TaskContextInput {\n const {\n actions,\n idempotencyKey: _idempotencyKey,\n assignTo: _assignTo,\n threadId: _threadId,\n priority: _priority,\n update: _update,\n validUntil,\n app: taskApp,\n ...rest\n } = task;\n\n const webhook = clientDefaults.webhook;\n const normalizedActions: TaskContextInput[\"actions\"] = webhook\n ? attachWebhookToActions(actions, webhook)\n : (actions as unknown as TaskContextInput[\"actions\"]);\n\n const app = taskApp ?? clientDefaults.app;\n\n return {\n ...rest,\n version: clientDefaults.version,\n ...(app ? { app } : {}),\n ...(validUntil !== undefined ? { validUntil: serializeValidUntil(validUntil) } : {}),\n actions: normalizedActions,\n };\n}\n\ntype ParsedResponseBody = Record<string, unknown> | unknown[] | string | null;\n\nasync function parseResponseBody(response: Response): Promise<ParsedResponseBody> {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n const bodyText = await response.text();\n\n if (!bodyText) {\n return null;\n }\n\n if (contentType.toLowerCase().includes(\"application/json\")) {\n try {\n return JSON.parse(bodyText) as ParsedResponseBody;\n } catch {\n // Fall through and return text body below so error messages stay useful.\n }\n }\n\n try {\n return JSON.parse(bodyText) as ParsedResponseBody;\n } catch {\n return bodyText;\n }\n}\n\nfunction getErrorMessage(data: ParsedResponseBody, fallback: string): string {\n if (data && typeof data === \"object\" && !Array.isArray(data)) {\n const maybeMessage = (data as Record<string, unknown>).message;\n if (typeof maybeMessage === \"string\" && maybeMessage.trim()) {\n return maybeMessage;\n }\n }\n\n if (typeof data === \"string\" && data.trim()) {\n const compact = data.replace(/\\s+/g, \" \").trim();\n const snippet = compact.length > 180 ? `${compact.slice(0, 180)}...` : compact;\n return `${fallback}. Server returned non-JSON response: ${snippet}`;\n }\n\n return fallback;\n}\n","import { createClient, type RobotRock, type RobotRockConfig } from \"./client.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.robotrock.io/v1\";\n\n/**\n * Read RobotRock client config from environment variables.\n *\n * - `ROBOTROCK_API_KEY` (required when not passed explicitly)\n * - `ROBOTROCK_BASE_URL` or `ROBOTROCK_API_URL` (optional)\n * - `ROBOTROCK_APP` (optional inbox app bucket)\n */\nexport function resolveRobotRockConfig(\n overrides?: Partial<RobotRockConfig>\n): RobotRockConfig {\n const apiKey = overrides?.apiKey ?? process.env.ROBOTROCK_API_KEY;\n if (!apiKey) {\n throw new Error(\n \"RobotRock API key is required. Set ROBOTROCK_API_KEY or pass apiKey when creating the client.\"\n );\n }\n\n const baseUrl =\n overrides?.baseUrl ??\n process.env.ROBOTROCK_BASE_URL ??\n process.env.ROBOTROCK_API_URL ??\n DEFAULT_BASE_URL;\n\n const app = overrides?.app ?? process.env.ROBOTROCK_APP;\n\n return app ? { apiKey, baseUrl, app } : { apiKey, baseUrl };\n}\n\n/** Use an explicit client or create one from env / optional config overrides. */\nexport function resolveRobotRockClient(\n client?: RobotRock,\n configOverrides?: Partial<RobotRockConfig>\n): RobotRock {\n if (client) {\n return client;\n }\n return createClient(resolveRobotRockConfig(configOverrides));\n}\n"],"mappings":";;;;;;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAMO,SAAS,8BACd,SACA,MACgC;AAChC,OAAK;AAEL,MAAI,CAAC,KAAK,SAAS;AACjB,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AAEA,SAAO;AAAA,IACL,UAAU,KAAK,QAAQ,OAAO;AAAA,IAC9B,MAAM,KAAK,QAAQ,OAAO;AAAA,IAC1B,WAAW,KAAK,QAAQ;AAAA,IACxB,WAAW,IAAI,KAAK,KAAK,aAAa,KAAK,IAAI,CAAC;AAAA,IAChD,QAAQ,KAAK;AAAA,EACf;AACF;;;ACkGA,IAAM,2BAA2B;AACjC,IAAM,qBAAqB,KAAK,KAAK,KAAK;AAE1C,SAAS,MAAM,IAA2B;AACxC,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD;AAEA,SAAS,kBAAkB,OAA+D;AACxF,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,MAAM;AACzB,UAAM,KAAK,MAAM,QAAQ;AACzB,WAAO,OAAO,MAAM,EAAE,IAAI,SAAY;AAAA,EACxC;AAEA,MAA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AQ,IAAI;AAE1C,SAAO,MAAM,EAAE,QAAQ,SAAS,IAAI,IAAI,EAAE,QAAQ,QAAQ;AAC5D;AAGO,SAAS,uBACd,QACA,iBACW;AACX,MAAI,QAAQ;AACV,WAAO;AAAA,EACT;AACA,SAAO,aAAa,uBAAuB,eAAe,CAAC;AAC7D;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TaskContextInput, AssignToInput, ThreadUpdateStatus, TaskResponse, DiscriminatedApprovalResult, Task, ThreadUpdate } from './schemas/index.js';
|
|
1
|
+
import { TaskContextInput, AssignToInput, TaskPriority, ThreadUpdateStatus, TaskResponse, DiscriminatedApprovalResult, Task, ThreadUpdate } from './schemas/index.js';
|
|
2
2
|
|
|
3
3
|
type RobotRockWebhookConfig = {
|
|
4
4
|
url: string;
|
|
@@ -59,6 +59,11 @@ type SendToHumanInput<A extends readonly SendToHumanActionInput[] = readonly Sen
|
|
|
59
59
|
* one (returned as `task.threadId`) and reuse it on later tasks in the thread.
|
|
60
60
|
*/
|
|
61
61
|
threadId?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Optional thread priority. When set, applies to the whole thread and
|
|
64
|
+
* overwrites any previous priority. Omit on later tasks to leave unchanged.
|
|
65
|
+
*/
|
|
66
|
+
priority?: TaskPriority;
|
|
62
67
|
/**
|
|
63
68
|
* Optional initial status update logged against the task's thread. Shows in
|
|
64
69
|
* the inbox status bar and the thread update log.
|