robotrock 1.1.0 → 1.3.1
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 +2 -2
- package/dist/agent-admin.d.ts +82 -0
- package/dist/agent-admin.js +938 -0
- package/dist/agent-admin.js.map +1 -0
- package/dist/ai/index.d.ts +6 -5
- package/dist/ai/index.js +407 -188
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/trigger.d.ts +4 -3
- package/dist/ai/trigger.js +407 -188
- package/dist/ai/trigger.js.map +1 -1
- package/dist/ai/workflow.d.ts +4 -3
- package/dist/ai/workflow.js +404 -185
- package/dist/ai/workflow.js.map +1 -1
- package/dist/auth-headers-qL-ZeEtd.d.ts +13 -0
- package/dist/{client-XTnFHGFE.d.ts → client-YO9Y1rkH.d.ts} +29 -17
- package/dist/eve/agent/index.d.ts +11 -35
- package/dist/eve/agent/index.js +678 -146
- package/dist/eve/agent/index.js.map +1 -1
- package/dist/eve/index.d.ts +5 -2
- package/dist/eve/index.js +195 -2
- package/dist/eve/index.js.map +1 -1
- package/dist/eve/tools/admin/assign-tasks.d.ts +39 -0
- package/dist/eve/tools/admin/assign-tasks.js +1060 -0
- package/dist/eve/tools/admin/assign-tasks.js.map +1 -0
- package/dist/eve/tools/admin/manage-groups.d.ts +53 -0
- package/dist/eve/tools/admin/manage-groups.js +1218 -0
- package/dist/eve/tools/admin/manage-groups.js.map +1 -0
- package/dist/eve/tools/admin/manage-team-members.d.ts +45 -0
- package/dist/eve/tools/admin/manage-team-members.js +1160 -0
- package/dist/eve/tools/admin/manage-team-members.js.map +1 -0
- package/dist/eve/tools/admin/query-tasks.d.ts +71 -0
- package/dist/eve/tools/admin/query-tasks.js +1161 -0
- package/dist/eve/tools/admin/query-tasks.js.map +1 -0
- package/dist/eve/tools/catalog/search-products.d.ts +57 -0
- package/dist/eve/tools/catalog/search-products.js +94 -0
- package/dist/eve/tools/catalog/search-products.js.map +1 -0
- package/dist/eve/tools/identity/index.d.ts +2 -0
- package/dist/eve/tools/identity/index.js +117 -27
- package/dist/eve/tools/identity/index.js.map +1 -1
- package/dist/eve/tools/identity/my-access.d.ts +6 -46
- package/dist/eve/tools/identity/my-access.js +91 -10
- package/dist/eve/tools/identity/my-access.js.map +1 -1
- package/dist/eve/tools/identity/whoami.d.ts +7 -8
- package/dist/eve/tools/identity/whoami.js +33 -17
- package/dist/eve/tools/identity/whoami.js.map +1 -1
- package/dist/eve/tools/inbox/create-task.d.ts +5 -4
- package/dist/eve/tools/inbox/create-task.js +365 -137
- package/dist/eve/tools/inbox/create-task.js.map +1 -1
- package/dist/eve/tools/inbox/index.d.ts +1 -0
- package/dist/eve/tools/inbox/index.js +365 -137
- package/dist/eve/tools/inbox/index.js.map +1 -1
- package/dist/eve/tools/index.d.ts +7 -0
- package/dist/eve/tools/index.js +1362 -168
- package/dist/eve/tools/index.js.map +1 -1
- package/dist/{index-BL9qKHA8.d.ts → index-DoQN48Bm.d.ts} +61 -2
- package/dist/index.d.ts +6 -3
- package/dist/index.js +325 -119
- package/dist/index.js.map +1 -1
- package/dist/schemas/index.d.ts +6 -1
- package/dist/schemas/index.js +177 -48
- package/dist/schemas/index.js.map +1 -1
- package/dist/{tool-approval-bridge-C4bTm8vu.d.ts → tool-approval-bridge-aMA79Z1B.d.ts} +1 -1
- package/dist/tool-reply-guidance-C3qrT1In.d.ts +25 -0
- package/dist/trigger/index.d.ts +2 -1
- package/dist/trigger/index.js +310 -108
- package/dist/trigger/index.js.map +1 -1
- package/dist/{trigger-Dn0DFiyU.d.ts → trigger-CXrbKVCL.d.ts} +2 -2
- package/dist/workflow/index.d.ts +2 -1
- package/dist/workflow/index.js +310 -108
- package/dist/workflow/index.js.map +1 -1
- package/package.json +30 -6
|
@@ -0,0 +1,1218 @@
|
|
|
1
|
+
// src/eve/tools/admin/manage-groups.ts
|
|
2
|
+
import { defineTool } from "eve/tools";
|
|
3
|
+
import { z as z5 } from "zod";
|
|
4
|
+
|
|
5
|
+
// src/http.ts
|
|
6
|
+
var RobotRockError = class extends Error {
|
|
7
|
+
constructor(message, statusCode, response) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.statusCode = statusCode;
|
|
10
|
+
this.response = response;
|
|
11
|
+
this.name = "RobotRockError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
async function parseResponseBody(response) {
|
|
15
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
16
|
+
const bodyText = await response.text();
|
|
17
|
+
if (!bodyText) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
if (contentType.toLowerCase().includes("application/json")) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(bodyText);
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(bodyText);
|
|
28
|
+
} catch {
|
|
29
|
+
return bodyText;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getErrorMessage(data, fallback) {
|
|
33
|
+
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
34
|
+
const record = data;
|
|
35
|
+
const maybeMessage = record.message;
|
|
36
|
+
const maybeHint = record.hint;
|
|
37
|
+
if (typeof maybeMessage === "string" && maybeMessage.trim()) {
|
|
38
|
+
if (typeof maybeHint === "string" && maybeHint.trim()) {
|
|
39
|
+
return `${maybeMessage.trim()} ${maybeHint.trim()}`;
|
|
40
|
+
}
|
|
41
|
+
return maybeMessage;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (typeof data === "string" && data.trim()) {
|
|
45
|
+
const compact = data.replace(/\s+/g, " ").trim();
|
|
46
|
+
const snippet = compact.length > 180 ? `${compact.slice(0, 180)}...` : compact;
|
|
47
|
+
return `${fallback}. Server returned non-JSON response: ${snippet}`;
|
|
48
|
+
}
|
|
49
|
+
return fallback;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../core/src/schemas/task.ts
|
|
53
|
+
import { z } from "zod";
|
|
54
|
+
|
|
55
|
+
// ../core/src/utils/safe-url.ts
|
|
56
|
+
var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
|
|
57
|
+
"localhost",
|
|
58
|
+
"metadata.google.internal",
|
|
59
|
+
"metadata.goog"
|
|
60
|
+
]);
|
|
61
|
+
function normalizeHostname(hostname) {
|
|
62
|
+
return hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
63
|
+
}
|
|
64
|
+
function isBlockedIpv4(host) {
|
|
65
|
+
const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
66
|
+
if (!match) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const octets = match.slice(1, 5).map((part) => Number(part));
|
|
70
|
+
if (octets.some((octet) => Number.isNaN(octet) || octet < 0 || octet > 255)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const [a, b, _c, _d] = octets;
|
|
74
|
+
if (a === void 0 || b === void 0) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (a === 127 || a === 0) return true;
|
|
78
|
+
if (a === 10) return true;
|
|
79
|
+
if (a === 169 && b === 254) return true;
|
|
80
|
+
if (a === 192 && b === 168) return true;
|
|
81
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
82
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
function ipv4FromNumericHost(host) {
|
|
86
|
+
if (/^\d+$/.test(host)) {
|
|
87
|
+
const num = Number(host);
|
|
88
|
+
if (!Number.isFinite(num) || num < 0 || num > 4294967295) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const a = num >>> 24 & 255;
|
|
92
|
+
const b = num >>> 16 & 255;
|
|
93
|
+
const c = num >>> 8 & 255;
|
|
94
|
+
const d = num & 255;
|
|
95
|
+
return `${a}.${b}.${c}.${d}`;
|
|
96
|
+
}
|
|
97
|
+
const hexMatch = /^0x([0-9a-f]{1,8})$/i.exec(host);
|
|
98
|
+
if (hexMatch) {
|
|
99
|
+
const num = Number.parseInt(hexMatch[1], 16);
|
|
100
|
+
if (!Number.isFinite(num) || num < 0 || num > 4294967295) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const a = num >>> 24 & 255;
|
|
104
|
+
const b = num >>> 16 & 255;
|
|
105
|
+
const c = num >>> 8 & 255;
|
|
106
|
+
const d = num & 255;
|
|
107
|
+
return `${a}.${b}.${c}.${d}`;
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
function isBlockedIpv4Mapped(host) {
|
|
112
|
+
const mappedDotted = /^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/i.exec(host);
|
|
113
|
+
if (mappedDotted) {
|
|
114
|
+
return isBlockedIpv4(mappedDotted[1]);
|
|
115
|
+
}
|
|
116
|
+
const mappedHex = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(host);
|
|
117
|
+
if (mappedHex) {
|
|
118
|
+
const high = Number.parseInt(mappedHex[1], 16);
|
|
119
|
+
const low = Number.parseInt(mappedHex[2], 16);
|
|
120
|
+
if (Number.isFinite(high) && Number.isFinite(low)) {
|
|
121
|
+
const a = high >> 8 & 255;
|
|
122
|
+
const b = high & 255;
|
|
123
|
+
const c = low >> 8 & 255;
|
|
124
|
+
const d = low & 255;
|
|
125
|
+
return isBlockedIpv4(`${a}.${b}.${c}.${d}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
function isBlockedIpv6(host) {
|
|
131
|
+
if (host === "::1" || host === "0:0:0:0:0:0:0:1") {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
if (host.startsWith("fc") || host.startsWith("fd")) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (host.startsWith("fe80:")) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
if (isBlockedIpv4Mapped(host)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
function isBlockedHostname(hostname) {
|
|
146
|
+
const host = normalizeHostname(hostname);
|
|
147
|
+
if (!host) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (BLOCKED_HOSTNAMES.has(host)) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (host.endsWith(".localhost") || host.endsWith(".local")) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
const numericIpv4 = ipv4FromNumericHost(host);
|
|
157
|
+
if (numericIpv4 && isBlockedIpv4(numericIpv4)) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
return isBlockedIpv4(host) || isBlockedIpv6(host);
|
|
161
|
+
}
|
|
162
|
+
function isLoopbackHandlerUrl(urlString) {
|
|
163
|
+
let url;
|
|
164
|
+
try {
|
|
165
|
+
url = new URL(urlString);
|
|
166
|
+
} catch {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
if (url.username || url.password) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
const host = url.hostname.toLowerCase();
|
|
176
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]" || host.endsWith(".localhost");
|
|
177
|
+
}
|
|
178
|
+
function isAllowedHandlerUrl(urlString) {
|
|
179
|
+
return isPublicHttpUrl(urlString) || isLoopbackHandlerUrl(urlString);
|
|
180
|
+
}
|
|
181
|
+
function isPublicHttpUrl(urlString) {
|
|
182
|
+
let url;
|
|
183
|
+
try {
|
|
184
|
+
url = new URL(urlString);
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (url.username || url.password) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
return !isBlockedHostname(url.hostname);
|
|
195
|
+
}
|
|
196
|
+
var PUBLIC_HTTP_URL_ERROR = "URL must be a public http:// or https:// address";
|
|
197
|
+
var HANDLER_URL_ERROR = "Handler URL must be a public or loopback http:// or https:// address";
|
|
198
|
+
|
|
199
|
+
// ../core/src/schemas/context-urls.ts
|
|
200
|
+
function resolveLinkUrl(value) {
|
|
201
|
+
return value.startsWith("http://") || value.startsWith("https://") ? value : `https://${value}`;
|
|
202
|
+
}
|
|
203
|
+
function widgetType(ui, field) {
|
|
204
|
+
const fieldUi = ui?.[field];
|
|
205
|
+
if (typeof fieldUi !== "object" || fieldUi === null) {
|
|
206
|
+
return void 0;
|
|
207
|
+
}
|
|
208
|
+
const widget = fieldUi["ui:widget"];
|
|
209
|
+
return typeof widget === "string" ? widget : void 0;
|
|
210
|
+
}
|
|
211
|
+
function validateUrlValue(value, widget) {
|
|
212
|
+
if (widget === "image" || widget === "link") {
|
|
213
|
+
if (typeof value !== "string") {
|
|
214
|
+
return PUBLIC_HTTP_URL_ERROR;
|
|
215
|
+
}
|
|
216
|
+
const url = widget === "link" ? resolveLinkUrl(value) : value;
|
|
217
|
+
if (!isPublicHttpUrl(url)) {
|
|
218
|
+
return PUBLIC_HTTP_URL_ERROR;
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
if (widget === "attachments" && Array.isArray(value)) {
|
|
223
|
+
for (const item of value) {
|
|
224
|
+
if (typeof item !== "object" || item === null) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const url = item.url;
|
|
228
|
+
if (typeof url === "string" && !isPublicHttpUrl(resolveLinkUrl(url))) {
|
|
229
|
+
return PUBLIC_HTTP_URL_ERROR;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
function validateContextPublicUrls(context) {
|
|
236
|
+
if (!context?.data) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
for (const [field, value] of Object.entries(context.data)) {
|
|
240
|
+
const widget = widgetType(context.ui, field);
|
|
241
|
+
if (!widget) {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const error = validateUrlValue(value, widget);
|
|
245
|
+
if (error) {
|
|
246
|
+
return `context.data.${field}: ${error}`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ../core/src/schemas/task.ts
|
|
253
|
+
var safeUrlSchema = z.string().refine((url) => isPublicHttpUrl(url), {
|
|
254
|
+
message: PUBLIC_HTTP_URL_ERROR
|
|
255
|
+
});
|
|
256
|
+
var handlerUrlSchema = z.string().refine((url) => isAllowedHandlerUrl(url), {
|
|
257
|
+
message: HANDLER_URL_ERROR
|
|
258
|
+
});
|
|
259
|
+
var jsonSchema7Schema = z.custom(
|
|
260
|
+
(val) => typeof val === "object" && val !== null,
|
|
261
|
+
{ message: "Must be a valid JSON Schema object" }
|
|
262
|
+
);
|
|
263
|
+
var uiSchemaSchema = z.custom((val) => typeof val === "object" && val !== null, {
|
|
264
|
+
message: "Must be a valid UiSchema object"
|
|
265
|
+
});
|
|
266
|
+
var webhookHandlerSchema = z.object({
|
|
267
|
+
type: z.literal("webhook"),
|
|
268
|
+
url: handlerUrlSchema,
|
|
269
|
+
headers: z.record(z.string(), z.string())
|
|
270
|
+
});
|
|
271
|
+
var triggerHandlerSchema = webhookHandlerSchema.extend({
|
|
272
|
+
type: z.literal("trigger"),
|
|
273
|
+
tokenId: z.string().min(1)
|
|
274
|
+
});
|
|
275
|
+
var handlerSchema = z.discriminatedUnion("type", [webhookHandlerSchema, triggerHandlerSchema]);
|
|
276
|
+
var taskActionInputSchema = z.object({
|
|
277
|
+
id: z.string().min(1),
|
|
278
|
+
title: z.string().min(1),
|
|
279
|
+
description: z.string().optional(),
|
|
280
|
+
schema: jsonSchema7Schema.optional(),
|
|
281
|
+
ui: uiSchemaSchema.optional(),
|
|
282
|
+
data: z.record(z.string(), z.unknown()).optional()
|
|
283
|
+
});
|
|
284
|
+
var taskActionSchema = taskActionInputSchema.extend({
|
|
285
|
+
// Optional handlers for this action - if present, must have at least 1
|
|
286
|
+
handlers: z.array(handlerSchema).min(1).optional()
|
|
287
|
+
});
|
|
288
|
+
var uiFieldSchemaSchema = z.object({
|
|
289
|
+
"ui:widget": z.string().optional(),
|
|
290
|
+
"ui:title": z.string().optional(),
|
|
291
|
+
"ui:description": z.string().optional(),
|
|
292
|
+
"ui:options": z.record(z.string(), z.unknown()).optional(),
|
|
293
|
+
items: z.lazy(() => z.record(z.string(), uiFieldSchemaSchema)).optional()
|
|
294
|
+
}).passthrough();
|
|
295
|
+
var contextUiSchema = z.record(z.string(), uiFieldSchemaSchema).optional();
|
|
296
|
+
var contextDataSchema = z.object({
|
|
297
|
+
data: z.record(z.string(), z.unknown()),
|
|
298
|
+
ui: contextUiSchema
|
|
299
|
+
}).optional();
|
|
300
|
+
var TASK_CONTEXT_FORMAT_VERSION = 2;
|
|
301
|
+
var taskContextObjectBaseSchema = z.object({
|
|
302
|
+
/** Source application id; omitted tasks are grouped in the default inbox. */
|
|
303
|
+
app: z.string().min(1).optional(),
|
|
304
|
+
type: z.string().min(1),
|
|
305
|
+
name: z.string().min(1),
|
|
306
|
+
description: z.string().optional(),
|
|
307
|
+
validUntil: z.string().optional(),
|
|
308
|
+
context: contextDataSchema,
|
|
309
|
+
/** Task context wire format version. @default 2 */
|
|
310
|
+
contextVersion: z.literal(2).optional(),
|
|
311
|
+
/** @deprecated Use `contextVersion`. Accepted on ingest only. */
|
|
312
|
+
version: z.literal(2).optional(),
|
|
313
|
+
actions: z.array(taskActionSchema).min(1, "At least one action is required")
|
|
314
|
+
});
|
|
315
|
+
function normalizeTaskContextVersion(data) {
|
|
316
|
+
const { version: legacyVersion, contextVersion, ...rest } = data;
|
|
317
|
+
return {
|
|
318
|
+
...rest,
|
|
319
|
+
contextVersion: contextVersion ?? legacyVersion ?? TASK_CONTEXT_FORMAT_VERSION
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
var taskContextObjectSchema = taskContextObjectBaseSchema.transform(
|
|
323
|
+
normalizeTaskContextVersion
|
|
324
|
+
);
|
|
325
|
+
function refineContextPublicUrls(data, ctx) {
|
|
326
|
+
const error = validateContextPublicUrls(data.context);
|
|
327
|
+
if (error) {
|
|
328
|
+
ctx.addIssue({
|
|
329
|
+
code: z.ZodIssueCode.custom,
|
|
330
|
+
message: error,
|
|
331
|
+
path: ["context"]
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
var taskContextSchema = taskContextObjectSchema.superRefine(
|
|
336
|
+
refineContextPublicUrls
|
|
337
|
+
);
|
|
338
|
+
var assignToSchema = z.object({
|
|
339
|
+
users: z.array(z.string().email()).optional(),
|
|
340
|
+
groups: z.array(z.string().min(1)).optional()
|
|
341
|
+
}).refine(
|
|
342
|
+
(data) => {
|
|
343
|
+
const groups = data.groups ?? [];
|
|
344
|
+
if (groups.includes("all") && groups.length > 1) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
return true;
|
|
348
|
+
},
|
|
349
|
+
{ message: 'Cannot combine "all" with other group slugs' }
|
|
350
|
+
);
|
|
351
|
+
var threadUpdateMessageSchema = z.string().min(1).max(500);
|
|
352
|
+
var threadUpdateStatuses = [
|
|
353
|
+
"info",
|
|
354
|
+
"queued",
|
|
355
|
+
"running",
|
|
356
|
+
"waiting",
|
|
357
|
+
"succeeded",
|
|
358
|
+
"failed",
|
|
359
|
+
"cancelled"
|
|
360
|
+
];
|
|
361
|
+
var threadUpdateStatusSchema = z.enum(threadUpdateStatuses);
|
|
362
|
+
var threadUpdateInputSchema = z.object({
|
|
363
|
+
message: threadUpdateMessageSchema,
|
|
364
|
+
status: threadUpdateStatusSchema.optional()
|
|
365
|
+
});
|
|
366
|
+
var taskPriorities = ["low", "normal", "high", "urgent"];
|
|
367
|
+
var taskPrioritySchema = z.enum(taskPriorities);
|
|
368
|
+
var agentTelemetrySchema = z.object({
|
|
369
|
+
/** Agent or app version (semver, git SHA, deploy tag — caller-defined). */
|
|
370
|
+
version: z.string().min(1)
|
|
371
|
+
});
|
|
372
|
+
var createTaskBodySchema = taskContextObjectBaseSchema.extend({
|
|
373
|
+
assignTo: assignToSchema.optional(),
|
|
374
|
+
/**
|
|
375
|
+
* Groups related tasks together. When omitted, the server generates one and
|
|
376
|
+
* returns it so the caller can reuse it on later tasks in the same thread.
|
|
377
|
+
*/
|
|
378
|
+
threadId: z.string().min(1).optional(),
|
|
379
|
+
/**
|
|
380
|
+
* Optional thread priority. When set, applies to the whole thread and
|
|
381
|
+
* overwrites any previous priority. Omit on later tasks to leave unchanged.
|
|
382
|
+
*/
|
|
383
|
+
priority: taskPrioritySchema.optional(),
|
|
384
|
+
/**
|
|
385
|
+
* Optional initial status update logged against the task's thread. Shows in
|
|
386
|
+
* the inbox status bar and the thread update log.
|
|
387
|
+
*/
|
|
388
|
+
update: threadUpdateInputSchema.optional(),
|
|
389
|
+
/** Agent release version — not shown in inbox UI. */
|
|
390
|
+
agent: agentTelemetrySchema.optional()
|
|
391
|
+
}).transform(normalizeTaskContextVersion).superRefine(refineContextPublicUrls);
|
|
392
|
+
var agentChatSeedActionSchema = z.object({
|
|
393
|
+
/** Stable action id echoed back on submit; auto-derived from title when omitted. */
|
|
394
|
+
id: z.string().min(1).optional(),
|
|
395
|
+
title: z.string().min(1),
|
|
396
|
+
description: z.string().optional(),
|
|
397
|
+
/** JSON Schema object for the form fields. */
|
|
398
|
+
schema: z.record(z.string(), z.unknown()).optional(),
|
|
399
|
+
/** RJSF ui schema overrides (ui:widget, ui:enumNames, etc.). */
|
|
400
|
+
ui: z.record(z.string(), z.unknown()).optional(),
|
|
401
|
+
/** Optional default field values. */
|
|
402
|
+
data: z.record(z.string(), z.unknown()).optional()
|
|
403
|
+
});
|
|
404
|
+
var agentChatSeedMessageSchema = z.object({
|
|
405
|
+
role: z.enum(["user", "assistant"]),
|
|
406
|
+
text: z.string().min(1),
|
|
407
|
+
/** Optional display-name override for the message sender. */
|
|
408
|
+
senderName: z.string().min(1).optional(),
|
|
409
|
+
/**
|
|
410
|
+
* Optional structured input request rendered as a styled RobotRock action
|
|
411
|
+
* widget below the message text. Use this instead of asking the user to reply
|
|
412
|
+
* in plain text so the request is always a proper action form.
|
|
413
|
+
*/
|
|
414
|
+
requestActionInput: z.object({
|
|
415
|
+
prompt: z.string().optional(),
|
|
416
|
+
action: agentChatSeedActionSchema
|
|
417
|
+
}).optional()
|
|
418
|
+
});
|
|
419
|
+
var eveAgentChatTransportSchema = z.object({
|
|
420
|
+
kind: z.literal("eve"),
|
|
421
|
+
chatId: z.string().min(1),
|
|
422
|
+
baseUrl: z.string().url(),
|
|
423
|
+
sessionId: z.string().optional(),
|
|
424
|
+
continuationToken: z.string().optional(),
|
|
425
|
+
streamIndex: z.number().int().nonnegative().optional(),
|
|
426
|
+
isStreaming: z.boolean().optional()
|
|
427
|
+
});
|
|
428
|
+
var createAgentChatBodySchema = z.object({
|
|
429
|
+
/** Agent id (eve agent name). Required unless `parentChatId` is set. */
|
|
430
|
+
agentIdentifier: z.string().min(1).optional(),
|
|
431
|
+
/** Inherit tenant/connection/agent from an existing chat (agent-spawned chats). */
|
|
432
|
+
parentChatId: z.string().min(1).optional(),
|
|
433
|
+
/** Convex tenantEveConnections id; resolved from the tenant when omitted. */
|
|
434
|
+
eveConnectionId: z.string().min(1).optional(),
|
|
435
|
+
/** Source application id; groups the chat under an inbox section. */
|
|
436
|
+
app: z.string().min(1).optional(),
|
|
437
|
+
/** Email of the user who owns the chat. Required unless `parentChatId` is set. */
|
|
438
|
+
ownerEmail: z.string().email().optional(),
|
|
439
|
+
title: z.string().min(1),
|
|
440
|
+
messages: z.array(agentChatSeedMessageSchema).default([]),
|
|
441
|
+
/** Provenance label stored on the session ("cron" | "agent" | ...). */
|
|
442
|
+
source: z.string().min(1).optional()
|
|
443
|
+
}).refine((data) => Boolean(data.agentIdentifier || data.parentChatId), {
|
|
444
|
+
message: "Provide either agentIdentifier or parentChatId"
|
|
445
|
+
}).refine((data) => Boolean(data.ownerEmail || data.parentChatId), {
|
|
446
|
+
message: "Provide ownerEmail unless parentChatId is set"
|
|
447
|
+
});
|
|
448
|
+
var agentChatAuditToolBodySchema = z.object({
|
|
449
|
+
eveSessionId: z.string().min(1),
|
|
450
|
+
userId: z.string().min(1),
|
|
451
|
+
toolCallId: z.string().min(1),
|
|
452
|
+
toolName: z.string().min(1),
|
|
453
|
+
input: z.record(z.string(), z.unknown()).default({}),
|
|
454
|
+
success: z.boolean(),
|
|
455
|
+
status: z.enum(["completed", "failed", "rejected"]),
|
|
456
|
+
error: z.string().optional(),
|
|
457
|
+
idempotencyKey: z.string().optional()
|
|
458
|
+
});
|
|
459
|
+
var agentChatAuditInputBodySchema = z.object({
|
|
460
|
+
eveSessionId: z.string().min(1),
|
|
461
|
+
userId: z.string().min(1),
|
|
462
|
+
actionId: z.string().min(1),
|
|
463
|
+
actionTitle: z.string().optional(),
|
|
464
|
+
prompt: z.string().optional(),
|
|
465
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
466
|
+
idempotencyKey: z.string().optional(),
|
|
467
|
+
/** Eve input request id — used to merge staged HITL metadata. */
|
|
468
|
+
requestId: z.string().optional(),
|
|
469
|
+
/** Eve tool call id — fallback lookup for staged HITL metadata. */
|
|
470
|
+
toolCallId: z.string().optional()
|
|
471
|
+
});
|
|
472
|
+
var eveHitlStagedOptionSchema = z.object({
|
|
473
|
+
id: z.string(),
|
|
474
|
+
label: z.string()
|
|
475
|
+
});
|
|
476
|
+
var agentChatStageHitlBodySchema = z.object({
|
|
477
|
+
eveSessionId: z.string().min(1),
|
|
478
|
+
requests: z.array(
|
|
479
|
+
z.object({
|
|
480
|
+
requestId: z.string().min(1),
|
|
481
|
+
toolCallId: z.string().min(1),
|
|
482
|
+
toolName: z.string().min(1),
|
|
483
|
+
prompt: z.string().min(1),
|
|
484
|
+
display: z.enum(["confirmation", "select", "text"]).optional(),
|
|
485
|
+
allowFreeform: z.boolean().optional(),
|
|
486
|
+
options: z.array(eveHitlStagedOptionSchema).optional(),
|
|
487
|
+
toolInput: z.record(z.string(), z.unknown()).optional()
|
|
488
|
+
})
|
|
489
|
+
)
|
|
490
|
+
});
|
|
491
|
+
var agentChatLinkTaskBodySchema = z.object({
|
|
492
|
+
eveSessionId: z.string().min(1),
|
|
493
|
+
publicTaskId: z.string().min(1),
|
|
494
|
+
toolCallId: z.string().min(1)
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// ../core/src/schemas/tool-result-display.ts
|
|
498
|
+
import { z as z2 } from "zod";
|
|
499
|
+
var toolDisplayMetadataSchema = z2.object({
|
|
500
|
+
widget: z2.string().optional(),
|
|
501
|
+
title: z2.string().optional(),
|
|
502
|
+
description: z2.string().optional()
|
|
503
|
+
});
|
|
504
|
+
var toolDisplayEnvelopeSchema = z2.object({
|
|
505
|
+
display: toolDisplayMetadataSchema.optional(),
|
|
506
|
+
data: z2.record(z2.string(), z2.unknown()),
|
|
507
|
+
ui: z2.record(
|
|
508
|
+
z2.string(),
|
|
509
|
+
z2.object({
|
|
510
|
+
"ui:widget": z2.string().optional(),
|
|
511
|
+
"ui:title": z2.string().optional(),
|
|
512
|
+
"ui:description": z2.string().optional(),
|
|
513
|
+
"ui:options": z2.record(z2.string(), z2.unknown()).optional()
|
|
514
|
+
}).passthrough()
|
|
515
|
+
).optional()
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// ../core/src/schemas/agent-admin.ts
|
|
519
|
+
import { z as z3 } from "zod";
|
|
520
|
+
var tenantRoleSchema = z3.enum(["admin", "member"]);
|
|
521
|
+
var agentAdminUserSchema = z3.object({
|
|
522
|
+
id: z3.string(),
|
|
523
|
+
email: z3.string().email(),
|
|
524
|
+
name: z3.string()
|
|
525
|
+
});
|
|
526
|
+
var agentAdminMemberSchema = z3.object({
|
|
527
|
+
userId: z3.string(),
|
|
528
|
+
role: z3.string(),
|
|
529
|
+
membershipKind: z3.enum(["team", "assignee"]),
|
|
530
|
+
hasLoggedIn: z3.boolean(),
|
|
531
|
+
user: agentAdminUserSchema
|
|
532
|
+
});
|
|
533
|
+
var agentAdminGroupSchema = z3.object({
|
|
534
|
+
id: z3.string(),
|
|
535
|
+
name: z3.string(),
|
|
536
|
+
slug: z3.string(),
|
|
537
|
+
description: z3.string().nullable(),
|
|
538
|
+
memberCount: z3.number().optional()
|
|
539
|
+
});
|
|
540
|
+
var agentAdminGroupDetailSchema = agentAdminGroupSchema.extend({
|
|
541
|
+
members: z3.array(
|
|
542
|
+
z3.object({
|
|
543
|
+
userId: z3.string(),
|
|
544
|
+
user: agentAdminUserSchema
|
|
545
|
+
})
|
|
546
|
+
)
|
|
547
|
+
});
|
|
548
|
+
var agentAdminTaskSummarySchema = z3.object({
|
|
549
|
+
id: z3.string(),
|
|
550
|
+
convexId: z3.string(),
|
|
551
|
+
status: z3.string(),
|
|
552
|
+
type: z3.string().nullable(),
|
|
553
|
+
name: z3.string().nullable(),
|
|
554
|
+
description: z3.string().nullable(),
|
|
555
|
+
validUntil: z3.number(),
|
|
556
|
+
createdAt: z3.number(),
|
|
557
|
+
threadPriority: z3.string().nullable(),
|
|
558
|
+
handledByUserId: z3.string().nullable()
|
|
559
|
+
});
|
|
560
|
+
var inviteMemberBodySchema = z3.object({
|
|
561
|
+
email: z3.string().email(),
|
|
562
|
+
role: tenantRoleSchema.optional()
|
|
563
|
+
});
|
|
564
|
+
var updateMemberRoleBodySchema = z3.object({
|
|
565
|
+
role: tenantRoleSchema
|
|
566
|
+
});
|
|
567
|
+
var createGroupBodySchema = z3.object({
|
|
568
|
+
name: z3.string().min(1),
|
|
569
|
+
description: z3.string().optional()
|
|
570
|
+
});
|
|
571
|
+
var updateGroupBodySchema = z3.object({
|
|
572
|
+
name: z3.string().min(1).optional(),
|
|
573
|
+
description: z3.string().optional()
|
|
574
|
+
});
|
|
575
|
+
var addGroupMemberBodySchema = z3.object({
|
|
576
|
+
userId: z3.string().min(1).describe("Convex user id or member email.")
|
|
577
|
+
});
|
|
578
|
+
var listTasksQuerySchema = z3.object({
|
|
579
|
+
statusFilter: z3.enum(["all", "open", "handled", "expired"]).optional(),
|
|
580
|
+
typeFilter: z3.string().optional(),
|
|
581
|
+
appFilter: z3.string().optional(),
|
|
582
|
+
sortField: z3.enum(["type", "date", "status", "validUntil"]).optional(),
|
|
583
|
+
sortDirection: z3.enum(["asc", "desc"]).optional(),
|
|
584
|
+
limit: z3.coerce.number().int().positive().max(100).optional(),
|
|
585
|
+
cursor: z3.string().optional()
|
|
586
|
+
});
|
|
587
|
+
var searchTasksQuerySchema = z3.object({
|
|
588
|
+
q: z3.string().min(1),
|
|
589
|
+
limit: z3.coerce.number().int().positive().max(100).optional()
|
|
590
|
+
});
|
|
591
|
+
var assignTasksResultSchema = z3.object({
|
|
592
|
+
taskId: z3.string(),
|
|
593
|
+
success: z3.boolean(),
|
|
594
|
+
message: z3.string().optional(),
|
|
595
|
+
name: z3.string().nullable().optional(),
|
|
596
|
+
description: z3.string().nullable().optional(),
|
|
597
|
+
type: z3.string().nullable().optional()
|
|
598
|
+
});
|
|
599
|
+
var assignTasksResponseSchema = z3.object({
|
|
600
|
+
results: z3.array(assignTasksResultSchema)
|
|
601
|
+
});
|
|
602
|
+
var assignTasksBodySchema = z3.object({
|
|
603
|
+
taskIds: z3.array(z3.string().min(1)).min(1).max(100),
|
|
604
|
+
assignTo: assignToSchema.refine(
|
|
605
|
+
(value) => (value.users?.length ?? 0) > 0 || (value.groups?.length ?? 0) > 0,
|
|
606
|
+
{ message: "assignTo needs at least one user email or group slug." }
|
|
607
|
+
)
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
// ../core/src/handler-retry.ts
|
|
611
|
+
var HANDLER_RETRY_DELAYS_MS = [
|
|
612
|
+
6e4,
|
|
613
|
+
// 1m
|
|
614
|
+
3e5,
|
|
615
|
+
// 5m
|
|
616
|
+
18e5,
|
|
617
|
+
// 30m
|
|
618
|
+
36e5,
|
|
619
|
+
// 1h
|
|
620
|
+
216e5,
|
|
621
|
+
// 6h
|
|
622
|
+
864e5,
|
|
623
|
+
// 24h
|
|
624
|
+
1728e5
|
|
625
|
+
// 48h
|
|
626
|
+
];
|
|
627
|
+
var HANDLER_MAX_ATTEMPTS = HANDLER_RETRY_DELAYS_MS.length + 1;
|
|
628
|
+
|
|
629
|
+
// ../core/src/attribution/index.ts
|
|
630
|
+
import { z as z4 } from "zod";
|
|
631
|
+
|
|
632
|
+
// ../core/src/app-url.ts
|
|
633
|
+
var PRODUCTION_APP_URL = "https://app.robotrock.io";
|
|
634
|
+
var PRODUCTION_API_URL = "https://api.robotrock.io/v1";
|
|
635
|
+
var DEV_API_URL = "http://localhost:4001/v1";
|
|
636
|
+
var APP_SIGNUP_URL = `${PRODUCTION_APP_URL}/sign-up`;
|
|
637
|
+
function normalizeRobotRockApiBaseUrl(baseUrl) {
|
|
638
|
+
const trimmed = baseUrl.trim().replace(/\/+$/, "");
|
|
639
|
+
if (trimmed.endsWith("/v1")) {
|
|
640
|
+
return trimmed;
|
|
641
|
+
}
|
|
642
|
+
return `${trimmed}/v1`;
|
|
643
|
+
}
|
|
644
|
+
function getRobotRockApiBaseUrl() {
|
|
645
|
+
const explicit = process.env.ROBOTROCK_BASE_URL?.trim() || process.env.ROBOTROCK_API_URL?.trim();
|
|
646
|
+
if (explicit) {
|
|
647
|
+
return normalizeRobotRockApiBaseUrl(explicit);
|
|
648
|
+
}
|
|
649
|
+
if (process.env.NODE_ENV === "production") {
|
|
650
|
+
return PRODUCTION_API_URL;
|
|
651
|
+
}
|
|
652
|
+
return DEV_API_URL;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// ../core/src/attribution/index.ts
|
|
656
|
+
var ATTRIBUTION_COOKIE_MAX_AGE = 60 * 60 * 24 * 90;
|
|
657
|
+
var attributionSchema = z4.object({
|
|
658
|
+
utmSource: z4.string().optional(),
|
|
659
|
+
utmMedium: z4.string().optional(),
|
|
660
|
+
utmCampaign: z4.string().optional(),
|
|
661
|
+
utmContent: z4.string().optional(),
|
|
662
|
+
utmTerm: z4.string().optional(),
|
|
663
|
+
gclid: z4.string().optional(),
|
|
664
|
+
landingUrl: z4.string().optional(),
|
|
665
|
+
referrer: z4.string().optional(),
|
|
666
|
+
capturedAt: z4.number()
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
// src/auth-headers.ts
|
|
670
|
+
var ROBOTROCK_ACTING_USER_ID_HEADER = "x-robotrock-acting-user-id";
|
|
671
|
+
function buildRobotRockAuthHeaders(auth) {
|
|
672
|
+
if (auth.kind === "apiKey") {
|
|
673
|
+
const headers2 = {
|
|
674
|
+
"X-Api-Key": auth.apiKey
|
|
675
|
+
};
|
|
676
|
+
if (auth.actingUserId?.trim()) {
|
|
677
|
+
headers2[ROBOTROCK_ACTING_USER_ID_HEADER] = auth.actingUserId.trim();
|
|
678
|
+
}
|
|
679
|
+
return headers2;
|
|
680
|
+
}
|
|
681
|
+
const headers = {
|
|
682
|
+
Authorization: `Bearer ${auth.token}`,
|
|
683
|
+
"X-RobotRock-Tenant-Slug": auth.tenantSlug,
|
|
684
|
+
"X-RobotRock-Connection-Id": auth.connectionId
|
|
685
|
+
};
|
|
686
|
+
if (auth.actingUserId?.trim()) {
|
|
687
|
+
headers[ROBOTROCK_ACTING_USER_ID_HEADER] = auth.actingUserId.trim();
|
|
688
|
+
}
|
|
689
|
+
return headers;
|
|
690
|
+
}
|
|
691
|
+
function resolveRobotRockAuthConfig(overrides) {
|
|
692
|
+
if (overrides?.agentService) {
|
|
693
|
+
return {
|
|
694
|
+
kind: "agentService",
|
|
695
|
+
...overrides.agentService
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
const apiKey = overrides?.apiKey ?? process.env.ROBOTROCK_API_KEY;
|
|
699
|
+
if (!apiKey) {
|
|
700
|
+
throw new Error(
|
|
701
|
+
"RobotRock auth is required. Set ROBOTROCK_API_KEY, ROBOTROCK_AGENT_SERVICE_TOKEN with tenant context, or pass auth when creating the client."
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
return { kind: "apiKey", apiKey };
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/eve/agent/attributes.ts
|
|
708
|
+
function readStringAttribute(attributes, key) {
|
|
709
|
+
const value = attributes?.[key];
|
|
710
|
+
if (typeof value === "string" && value.length > 0) {
|
|
711
|
+
return value;
|
|
712
|
+
}
|
|
713
|
+
if (Array.isArray(value) && typeof value[0] === "string" && value[0].length > 0) {
|
|
714
|
+
return value[0];
|
|
715
|
+
}
|
|
716
|
+
return void 0;
|
|
717
|
+
}
|
|
718
|
+
function readStringArrayAttribute(attributes, key) {
|
|
719
|
+
const value = attributes?.[key];
|
|
720
|
+
if (typeof value === "string" && value.length > 0) {
|
|
721
|
+
return [value];
|
|
722
|
+
}
|
|
723
|
+
if (Array.isArray(value)) {
|
|
724
|
+
return value.filter(
|
|
725
|
+
(entry) => typeof entry === "string" && entry.length > 0
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
return [];
|
|
729
|
+
}
|
|
730
|
+
function parseTenantRole(value) {
|
|
731
|
+
if (value === "admin" || value === "member") {
|
|
732
|
+
return value;
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// src/eve/agent/tenant.ts
|
|
738
|
+
function tryResolveTenantCaller(ctx) {
|
|
739
|
+
const caller = ctx.session.auth.initiator ?? ctx.session.auth.current;
|
|
740
|
+
if (caller?.principalType !== "user") {
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
const email = readStringAttribute(caller.attributes, "email");
|
|
744
|
+
const name = readStringAttribute(caller.attributes, "name");
|
|
745
|
+
const tenantSlug = readStringAttribute(caller.attributes, "tenantSlug") ?? readStringAttribute(caller.attributes, "tenantId");
|
|
746
|
+
const role = parseTenantRole(readStringAttribute(caller.attributes, "role"));
|
|
747
|
+
if (!email || !tenantSlug || !caller.principalId || !role) {
|
|
748
|
+
return null;
|
|
749
|
+
}
|
|
750
|
+
const workosUserId = readStringAttribute(caller.attributes, "workosUserId");
|
|
751
|
+
const connectionId = readStringAttribute(caller.attributes, "connectionId");
|
|
752
|
+
const groups = readStringArrayAttribute(caller.attributes, "groups");
|
|
753
|
+
return {
|
|
754
|
+
userId: caller.principalId,
|
|
755
|
+
email,
|
|
756
|
+
name: name ?? email.split("@")[0] ?? email,
|
|
757
|
+
tenantSlug,
|
|
758
|
+
...connectionId ? { connectionId } : {},
|
|
759
|
+
role,
|
|
760
|
+
isAdmin: role === "admin",
|
|
761
|
+
groups,
|
|
762
|
+
...workosUserId ? { workosUserId } : {}
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
function requireTenantCaller(ctx) {
|
|
766
|
+
const caller = tryResolveTenantCaller(ctx);
|
|
767
|
+
if (!caller) {
|
|
768
|
+
throw new Error("An authenticated RobotRock tenant user is required.");
|
|
769
|
+
}
|
|
770
|
+
return caller;
|
|
771
|
+
}
|
|
772
|
+
function requireAdminCaller(ctx) {
|
|
773
|
+
const caller = requireTenantCaller(ctx);
|
|
774
|
+
if (!caller.isAdmin) {
|
|
775
|
+
throw new Error("Tenant admin access is required.");
|
|
776
|
+
}
|
|
777
|
+
return caller;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
// src/agent-admin.ts
|
|
781
|
+
async function agentAdminFetch(config, path, init) {
|
|
782
|
+
const baseUrl = (config.baseUrl?.trim() || getRobotRockApiBaseUrl()).replace(
|
|
783
|
+
/\/+$/,
|
|
784
|
+
""
|
|
785
|
+
);
|
|
786
|
+
const url = `${baseUrl}/agent-admin${path}`;
|
|
787
|
+
const response = await fetch(url, {
|
|
788
|
+
...init,
|
|
789
|
+
headers: {
|
|
790
|
+
"Content-Type": "application/json",
|
|
791
|
+
...buildRobotRockAuthHeaders(config.auth),
|
|
792
|
+
...init?.headers ?? {}
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
const data = await parseResponseBody(response);
|
|
796
|
+
if (!response.ok) {
|
|
797
|
+
throw new RobotRockError(
|
|
798
|
+
getErrorMessage(data, `Agent admin request failed (${response.status})`),
|
|
799
|
+
response.status,
|
|
800
|
+
data
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
return data;
|
|
804
|
+
}
|
|
805
|
+
function createAgentAdminApi(config) {
|
|
806
|
+
return {
|
|
807
|
+
members: {
|
|
808
|
+
list: () => agentAdminFetch(config, "/members"),
|
|
809
|
+
get: (memberRef) => agentAdminFetch(config, `/members/${encodeURIComponent(memberRef)}`),
|
|
810
|
+
invite: (body) => agentAdminFetch(config, "/members", {
|
|
811
|
+
method: "POST",
|
|
812
|
+
body: JSON.stringify(body)
|
|
813
|
+
}),
|
|
814
|
+
updateRole: (memberRef, role) => agentAdminFetch(
|
|
815
|
+
config,
|
|
816
|
+
`/members/${encodeURIComponent(memberRef)}/role`,
|
|
817
|
+
{
|
|
818
|
+
method: "PATCH",
|
|
819
|
+
body: JSON.stringify({ role })
|
|
820
|
+
}
|
|
821
|
+
),
|
|
822
|
+
remove: (memberId) => agentAdminFetch(
|
|
823
|
+
config,
|
|
824
|
+
`/members/${encodeURIComponent(memberId)}`,
|
|
825
|
+
{
|
|
826
|
+
method: "DELETE"
|
|
827
|
+
}
|
|
828
|
+
)
|
|
829
|
+
},
|
|
830
|
+
groups: {
|
|
831
|
+
list: () => agentAdminFetch(config, "/groups"),
|
|
832
|
+
get: (groupId) => agentAdminFetch(
|
|
833
|
+
config,
|
|
834
|
+
`/groups/${encodeURIComponent(groupId)}`
|
|
835
|
+
),
|
|
836
|
+
create: (body) => agentAdminFetch(config, "/groups", {
|
|
837
|
+
method: "POST",
|
|
838
|
+
body: JSON.stringify(body)
|
|
839
|
+
}),
|
|
840
|
+
update: (groupId, body) => agentAdminFetch(
|
|
841
|
+
config,
|
|
842
|
+
`/groups/${encodeURIComponent(groupId)}`,
|
|
843
|
+
{
|
|
844
|
+
method: "PATCH",
|
|
845
|
+
body: JSON.stringify(body)
|
|
846
|
+
}
|
|
847
|
+
),
|
|
848
|
+
delete: (groupId) => agentAdminFetch(
|
|
849
|
+
config,
|
|
850
|
+
`/groups/${encodeURIComponent(groupId)}`,
|
|
851
|
+
{
|
|
852
|
+
method: "DELETE"
|
|
853
|
+
}
|
|
854
|
+
),
|
|
855
|
+
addMember: (groupRef, memberRef) => agentAdminFetch(
|
|
856
|
+
config,
|
|
857
|
+
`/groups/${encodeURIComponent(groupRef)}/members`,
|
|
858
|
+
{
|
|
859
|
+
method: "POST",
|
|
860
|
+
body: JSON.stringify({ userId: memberRef })
|
|
861
|
+
}
|
|
862
|
+
),
|
|
863
|
+
removeMember: (groupRef, memberRef) => agentAdminFetch(
|
|
864
|
+
config,
|
|
865
|
+
`/groups/${encodeURIComponent(groupRef)}/members/${encodeURIComponent(memberRef)}`,
|
|
866
|
+
{ method: "DELETE" }
|
|
867
|
+
)
|
|
868
|
+
},
|
|
869
|
+
tasks: {
|
|
870
|
+
list: (query) => {
|
|
871
|
+
const params = new URLSearchParams();
|
|
872
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
873
|
+
if (value !== void 0 && value !== "") {
|
|
874
|
+
params.set(key, String(value));
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
const suffix = params.size > 0 ? `?${params.toString()}` : "";
|
|
878
|
+
return agentAdminFetch(
|
|
879
|
+
config,
|
|
880
|
+
`/tasks${suffix}`
|
|
881
|
+
);
|
|
882
|
+
},
|
|
883
|
+
search: (q, limit) => {
|
|
884
|
+
const params = new URLSearchParams({ q });
|
|
885
|
+
if (limit !== void 0) {
|
|
886
|
+
params.set("limit", String(limit));
|
|
887
|
+
}
|
|
888
|
+
return agentAdminFetch(
|
|
889
|
+
config,
|
|
890
|
+
`/tasks/search?${params.toString()}`
|
|
891
|
+
);
|
|
892
|
+
},
|
|
893
|
+
get: (taskId) => agentAdminFetch(config, `/tasks/${taskId}`),
|
|
894
|
+
assign: (body) => agentAdminFetch(config, "/tasks/assign", {
|
|
895
|
+
method: "POST",
|
|
896
|
+
body: JSON.stringify(body)
|
|
897
|
+
})
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
function createBoundAgentAdminClient(ctx) {
|
|
902
|
+
const caller = requireTenantCaller(ctx);
|
|
903
|
+
const baseUrl = process.env.ROBOTROCK_BASE_URL?.trim();
|
|
904
|
+
const serviceToken = process.env.ROBOTROCK_AGENT_SERVICE_TOKEN?.trim();
|
|
905
|
+
if (caller.connectionId && serviceToken) {
|
|
906
|
+
return createAgentAdminApi({
|
|
907
|
+
baseUrl,
|
|
908
|
+
auth: resolveRobotRockAuthConfig({
|
|
909
|
+
agentService: {
|
|
910
|
+
token: serviceToken,
|
|
911
|
+
tenantSlug: caller.tenantSlug,
|
|
912
|
+
connectionId: caller.connectionId,
|
|
913
|
+
actingUserId: caller.userId
|
|
914
|
+
}
|
|
915
|
+
})
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
const apiKey = process.env.ROBOTROCK_API_KEY?.trim();
|
|
919
|
+
if (apiKey) {
|
|
920
|
+
return createAgentAdminApi({
|
|
921
|
+
baseUrl,
|
|
922
|
+
auth: {
|
|
923
|
+
kind: "apiKey",
|
|
924
|
+
apiKey,
|
|
925
|
+
actingUserId: caller.userId
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
throw new Error(
|
|
930
|
+
"Agent admin auth is unset. Set ROBOTROCK_AGENT_SERVICE_TOKEN for hosted multi-tenant agents, or ROBOTROCK_API_KEY for self-hosted and localhost deployments."
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
function requireBoundAgentAdminClient(ctx) {
|
|
934
|
+
requireAdminCaller(ctx);
|
|
935
|
+
return createBoundAgentAdminClient(ctx);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// src/eve/tool-result-display.ts
|
|
939
|
+
function toolDisplayResult(data, options) {
|
|
940
|
+
const display = options?.widget || options?.title || options?.description ? {
|
|
941
|
+
...options.widget ? { widget: options.widget } : {},
|
|
942
|
+
...options.title ? { title: options.title } : {},
|
|
943
|
+
...options.description ? { description: options.description } : {}
|
|
944
|
+
} : void 0;
|
|
945
|
+
return {
|
|
946
|
+
...display ? { display } : {},
|
|
947
|
+
data,
|
|
948
|
+
...options?.ui ? { ui: options.ui } : {}
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// src/eve/tool-reply-guidance.ts
|
|
953
|
+
var TOOL_REPLY_GUIDANCE_FIELD = "replyGuidance";
|
|
954
|
+
var MANAGE_GROUPS_LIST_REPLY_GUIDANCE = "Groups render as a list card in chat. Do not restate group names, slugs, or descriptions from the list. Use slug (not internal id) for get, update, delete, and membership actions. Only add context not shown.";
|
|
955
|
+
var MANAGE_GROUPS_DETAIL_REPLY_GUIDANCE = "Group details render in chat UI. Do not restate fields already visible in the card. Only add next steps.";
|
|
956
|
+
var ADMIN_MUTATION_REPLY_GUIDANCE = "The action result renders in chat UI. Do not restate fields already visible in the card. Confirm outcome briefly or add next steps only.";
|
|
957
|
+
function withReplyGuidance(result, guidance) {
|
|
958
|
+
return {
|
|
959
|
+
...result,
|
|
960
|
+
[TOOL_REPLY_GUIDANCE_FIELD]: guidance
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// src/eve/tool-display-format.ts
|
|
965
|
+
function formatToolObjectResult(data, options) {
|
|
966
|
+
return withReplyGuidance(
|
|
967
|
+
toolDisplayResult(data, {
|
|
968
|
+
title: options.title,
|
|
969
|
+
description: options.description,
|
|
970
|
+
ui: options.ui
|
|
971
|
+
}),
|
|
972
|
+
options.replyGuidance
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
function formatToolListResult(listKey, items, options) {
|
|
976
|
+
const listFieldUi = options.itemWidget ? {
|
|
977
|
+
"ui:widget": "list",
|
|
978
|
+
items: {
|
|
979
|
+
"ui:widget": options.itemWidget,
|
|
980
|
+
...options.itemUi ?? {}
|
|
981
|
+
}
|
|
982
|
+
} : {
|
|
983
|
+
"ui:widget": "table",
|
|
984
|
+
...options.itemUi ? { items: options.itemUi } : {}
|
|
985
|
+
};
|
|
986
|
+
return formatToolObjectResult(
|
|
987
|
+
{ [listKey]: items },
|
|
988
|
+
{
|
|
989
|
+
title: options.title,
|
|
990
|
+
ui: {
|
|
991
|
+
[listKey]: listFieldUi
|
|
992
|
+
},
|
|
993
|
+
replyGuidance: options.replyGuidance
|
|
994
|
+
}
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// src/eve/tools/admin/format-groups-list.ts
|
|
999
|
+
var GROUP_ITEM_UI = {
|
|
1000
|
+
name: { "ui:title": "Name" },
|
|
1001
|
+
slug: { "ui:title": "Slug" },
|
|
1002
|
+
description: { "ui:title": "Description" },
|
|
1003
|
+
memberCount: { "ui:title": "Members", "ui:widget": "number" }
|
|
1004
|
+
};
|
|
1005
|
+
function serializeGroupRow(group) {
|
|
1006
|
+
return {
|
|
1007
|
+
name: group.name,
|
|
1008
|
+
slug: group.slug,
|
|
1009
|
+
description: group.description,
|
|
1010
|
+
memberCount: group.memberCount ?? null
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
function formatGroupsListResult(groups) {
|
|
1014
|
+
const countLabel = groups.length === 1 ? "1 group" : `${groups.length} groups`;
|
|
1015
|
+
return formatToolListResult(
|
|
1016
|
+
"groups",
|
|
1017
|
+
groups.map(serializeGroupRow),
|
|
1018
|
+
{
|
|
1019
|
+
title: countLabel,
|
|
1020
|
+
itemWidget: "tenantGroup",
|
|
1021
|
+
replyGuidance: MANAGE_GROUPS_LIST_REPLY_GUIDANCE
|
|
1022
|
+
}
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
function formatGroupDetailResult(group) {
|
|
1026
|
+
return formatToolObjectResult(
|
|
1027
|
+
{
|
|
1028
|
+
name: group.name,
|
|
1029
|
+
slug: group.slug,
|
|
1030
|
+
description: group.description,
|
|
1031
|
+
members: group.members.map((member) => ({
|
|
1032
|
+
name: member.user.name,
|
|
1033
|
+
email: member.user.email
|
|
1034
|
+
}))
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
title: group.name,
|
|
1038
|
+
ui: {
|
|
1039
|
+
name: { "ui:title": "Name" },
|
|
1040
|
+
slug: { "ui:title": "Slug" },
|
|
1041
|
+
description: { "ui:title": "Description" },
|
|
1042
|
+
members: {
|
|
1043
|
+
"ui:widget": "list",
|
|
1044
|
+
"ui:title": "Members",
|
|
1045
|
+
items: {
|
|
1046
|
+
name: { "ui:title": "Name" },
|
|
1047
|
+
email: { "ui:title": "Email" }
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
},
|
|
1051
|
+
replyGuidance: MANAGE_GROUPS_DETAIL_REPLY_GUIDANCE
|
|
1052
|
+
}
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
function formatGroupSummaryResult(group) {
|
|
1056
|
+
return formatToolObjectResult(serializeGroupRow(group), {
|
|
1057
|
+
title: group.name,
|
|
1058
|
+
ui: GROUP_ITEM_UI,
|
|
1059
|
+
replyGuidance: MANAGE_GROUPS_DETAIL_REPLY_GUIDANCE
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// src/eve/tools/admin/manage-groups.ts
|
|
1064
|
+
var MANAGE_GROUPS_TOOL_NAME = "manage_groups";
|
|
1065
|
+
var manageGroupsInputSchema = z5.object({
|
|
1066
|
+
action: z5.enum([
|
|
1067
|
+
"list",
|
|
1068
|
+
"get",
|
|
1069
|
+
"create",
|
|
1070
|
+
"update",
|
|
1071
|
+
"delete",
|
|
1072
|
+
"add_member",
|
|
1073
|
+
"remove_member"
|
|
1074
|
+
]),
|
|
1075
|
+
groupId: z5.string().min(1).optional().describe(
|
|
1076
|
+
"Convex group id for get, update, delete, and membership actions. Prefer slug when the group list only shows slug."
|
|
1077
|
+
),
|
|
1078
|
+
slug: z5.string().min(1).optional().describe(
|
|
1079
|
+
"Group slug (e.g. finance) for get, update, delete, and membership actions."
|
|
1080
|
+
),
|
|
1081
|
+
userId: z5.string().min(1).optional().describe(
|
|
1082
|
+
"User id for add_member and remove_member. Prefer email when the member list only shows email."
|
|
1083
|
+
),
|
|
1084
|
+
email: z5.string().email().optional().describe("Member email for add_member and remove_member."),
|
|
1085
|
+
name: z5.string().min(1).optional().describe("Group name for create and update."),
|
|
1086
|
+
description: z5.string().optional().describe("Group description for create and update.")
|
|
1087
|
+
}).superRefine((input, ctx) => {
|
|
1088
|
+
const requireField = (field, message) => {
|
|
1089
|
+
if (!input[field]) {
|
|
1090
|
+
ctx.addIssue({ code: "custom", message, path: [field] });
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
const requireGroupIdOrSlug = (message) => {
|
|
1094
|
+
if (!input.groupId && !input.slug) {
|
|
1095
|
+
ctx.addIssue({ code: "custom", message, path: ["slug"] });
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
const requireUserIdOrEmail = (message) => {
|
|
1099
|
+
if (!input.userId && !input.email) {
|
|
1100
|
+
ctx.addIssue({ code: "custom", message, path: ["email"] });
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
switch (input.action) {
|
|
1104
|
+
case "get":
|
|
1105
|
+
case "delete":
|
|
1106
|
+
requireGroupIdOrSlug(
|
|
1107
|
+
"groupId or slug is required for this action."
|
|
1108
|
+
);
|
|
1109
|
+
break;
|
|
1110
|
+
case "create":
|
|
1111
|
+
requireField("name", "name is required when creating a group.");
|
|
1112
|
+
break;
|
|
1113
|
+
case "update":
|
|
1114
|
+
requireGroupIdOrSlug("groupId or slug is required for update.");
|
|
1115
|
+
break;
|
|
1116
|
+
case "add_member":
|
|
1117
|
+
case "remove_member":
|
|
1118
|
+
requireGroupIdOrSlug(
|
|
1119
|
+
"groupId or slug is required for membership changes."
|
|
1120
|
+
);
|
|
1121
|
+
requireUserIdOrEmail(
|
|
1122
|
+
"userId or email is required for membership changes."
|
|
1123
|
+
);
|
|
1124
|
+
break;
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
function formatGroupMutationResult(payload, title) {
|
|
1128
|
+
return formatToolObjectResult(payload, {
|
|
1129
|
+
title,
|
|
1130
|
+
replyGuidance: ADMIN_MUTATION_REPLY_GUIDANCE
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
function resolveGroupRef(input) {
|
|
1134
|
+
return input.groupId ?? input.slug;
|
|
1135
|
+
}
|
|
1136
|
+
function resolveMemberRef(input) {
|
|
1137
|
+
return input.userId ?? input.email;
|
|
1138
|
+
}
|
|
1139
|
+
function defineManageGroupsTool() {
|
|
1140
|
+
return defineTool({
|
|
1141
|
+
description: "Tenant-admin tool for workspace groups: list, get, create, update, delete, and manage group membership. Requires tenant admin access. Use group slug (e.g. finance) from list results for get and membership actions \u2014 internal ids are optional. Use member email for add_member and remove_member when user ids are unknown. Results render as chat UI cards \u2014 do not restate group or member fields in your reply.",
|
|
1142
|
+
inputSchema: manageGroupsInputSchema,
|
|
1143
|
+
async execute(input, ctx) {
|
|
1144
|
+
const api = requireBoundAgentAdminClient(ctx);
|
|
1145
|
+
try {
|
|
1146
|
+
switch (input.action) {
|
|
1147
|
+
case "list": {
|
|
1148
|
+
const result = await api.groups.list();
|
|
1149
|
+
return formatGroupsListResult(result.groups);
|
|
1150
|
+
}
|
|
1151
|
+
case "get": {
|
|
1152
|
+
const result = await api.groups.get(resolveGroupRef(input));
|
|
1153
|
+
return formatGroupDetailResult(result.group);
|
|
1154
|
+
}
|
|
1155
|
+
case "create": {
|
|
1156
|
+
const result = await api.groups.create({
|
|
1157
|
+
name: input.name,
|
|
1158
|
+
description: input.description
|
|
1159
|
+
});
|
|
1160
|
+
return formatGroupSummaryResult(result.group);
|
|
1161
|
+
}
|
|
1162
|
+
case "update": {
|
|
1163
|
+
const result = await api.groups.update(resolveGroupRef(input), {
|
|
1164
|
+
name: input.name,
|
|
1165
|
+
description: input.description
|
|
1166
|
+
});
|
|
1167
|
+
return formatGroupSummaryResult(result.group);
|
|
1168
|
+
}
|
|
1169
|
+
case "delete": {
|
|
1170
|
+
const result = await api.groups.delete(resolveGroupRef(input));
|
|
1171
|
+
return formatGroupMutationResult(
|
|
1172
|
+
result,
|
|
1173
|
+
"Group deleted"
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
case "add_member": {
|
|
1177
|
+
const result = await api.groups.addMember(
|
|
1178
|
+
resolveGroupRef(input),
|
|
1179
|
+
resolveMemberRef(input)
|
|
1180
|
+
);
|
|
1181
|
+
return formatGroupMutationResult(
|
|
1182
|
+
result,
|
|
1183
|
+
"Group member added"
|
|
1184
|
+
);
|
|
1185
|
+
}
|
|
1186
|
+
case "remove_member": {
|
|
1187
|
+
const result = await api.groups.removeMember(
|
|
1188
|
+
resolveGroupRef(input),
|
|
1189
|
+
resolveMemberRef(input)
|
|
1190
|
+
);
|
|
1191
|
+
return formatGroupMutationResult(
|
|
1192
|
+
result,
|
|
1193
|
+
"Group member removed"
|
|
1194
|
+
);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
} catch (error) {
|
|
1198
|
+
if (error instanceof RobotRockError) {
|
|
1199
|
+
return {
|
|
1200
|
+
ok: false,
|
|
1201
|
+
status: error.statusCode,
|
|
1202
|
+
message: error.message,
|
|
1203
|
+
response: error.response
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
throw error;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
var manageGroupsTool = defineManageGroupsTool();
|
|
1212
|
+
export {
|
|
1213
|
+
MANAGE_GROUPS_TOOL_NAME,
|
|
1214
|
+
defineManageGroupsTool,
|
|
1215
|
+
manageGroupsInputSchema,
|
|
1216
|
+
manageGroupsTool
|
|
1217
|
+
};
|
|
1218
|
+
//# sourceMappingURL=manage-groups.js.map
|