robotrock 1.3.4 → 1.5.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 +11 -1
- package/dist/agent-admin.d.ts +5 -0
- package/dist/agent-admin.js +75 -2
- package/dist/agent-admin.js.map +1 -1
- package/dist/ai/index.d.ts +5 -5
- package/dist/ai/index.js +120 -4
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/trigger.d.ts +3 -3
- package/dist/ai/trigger.js +120 -4
- package/dist/ai/trigger.js.map +1 -1
- package/dist/ai/workflow.d.ts +3 -3
- package/dist/ai/workflow.js +120 -4
- package/dist/ai/workflow.js.map +1 -1
- package/dist/{client-CZ5eWH5v.d.ts → client-BxbxttFH.d.ts} +19 -1
- package/dist/eve/agent/index.d.ts +4 -4
- package/dist/eve/agent/index.js +577 -261
- package/dist/eve/agent/index.js.map +1 -1
- package/dist/eve/index.d.ts +4 -4
- package/dist/eve/index.js +507 -7
- package/dist/eve/index.js.map +1 -1
- package/dist/eve/tools/admin/assign-tasks.d.ts +40 -19
- package/dist/eve/tools/admin/assign-tasks.js +334 -25
- package/dist/eve/tools/admin/assign-tasks.js.map +1 -1
- package/dist/eve/tools/admin/get-workspace-usage.d.ts +71 -0
- package/dist/eve/tools/admin/get-workspace-usage.js +1365 -0
- package/dist/eve/tools/admin/get-workspace-usage.js.map +1 -0
- package/dist/eve/tools/admin/manage-groups.d.ts +122 -7
- package/dist/eve/tools/admin/manage-groups.js +350 -31
- package/dist/eve/tools/admin/manage-groups.js.map +1 -1
- package/dist/eve/tools/admin/manage-team-members.d.ts +86 -7
- package/dist/eve/tools/admin/manage-team-members.js +318 -16
- package/dist/eve/tools/admin/manage-team-members.js.map +1 -1
- package/dist/eve/tools/admin/query-tasks.d.ts +82 -7
- package/dist/eve/tools/admin/query-tasks.js +363 -40
- package/dist/eve/tools/admin/query-tasks.js.map +1 -1
- package/dist/eve/tools/catalog/generate-image.d.ts +64 -0
- package/dist/eve/tools/catalog/generate-image.js +2077 -0
- package/dist/eve/tools/catalog/generate-image.js.map +1 -0
- package/dist/eve/tools/catalog/generate-random-chart.d.ts +77 -0
- package/dist/eve/tools/catalog/generate-random-chart.js +411 -0
- package/dist/eve/tools/catalog/generate-random-chart.js.map +1 -0
- package/dist/eve/tools/catalog/search-products.d.ts +36 -43
- package/dist/eve/tools/catalog/search-products.js +253 -6
- package/dist/eve/tools/catalog/search-products.js.map +1 -1
- package/dist/eve/tools/identity/index.d.ts +2 -1
- package/dist/eve/tools/identity/index.js +26 -6
- package/dist/eve/tools/identity/index.js.map +1 -1
- package/dist/eve/tools/identity/my-access.d.ts +88 -3
- package/dist/eve/tools/identity/my-access.js +26 -6
- package/dist/eve/tools/identity/my-access.js.map +1 -1
- package/dist/eve/tools/identity/whoami.d.ts +1 -1
- package/dist/eve/tools/identity/whoami.js.map +1 -1
- package/dist/eve/tools/inbox/create-task.d.ts +1 -1
- package/dist/eve/tools/inbox/create-task.js +119 -2
- package/dist/eve/tools/inbox/create-task.js.map +1 -1
- package/dist/eve/tools/inbox/index.d.ts +1 -1
- package/dist/eve/tools/inbox/index.js +119 -2
- package/dist/eve/tools/inbox/index.js.map +1 -1
- package/dist/eve/tools/index.d.ts +5 -2
- package/dist/eve/tools/index.js +964 -115
- package/dist/eve/tools/index.js.map +1 -1
- package/dist/index-amkHKVGs.d.ts +1054 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +328 -13
- package/dist/index.js.map +1 -1
- package/dist/schemas/index.js +67 -1
- package/dist/schemas/index.js.map +1 -1
- package/dist/{tool-approval-bridge-DnGaRES4.d.ts → tool-approval-bridge-Cz7qQUpw.d.ts} +1 -1
- package/dist/{tool-reply-guidance-C3qrT1In.d.ts → tool-reply-guidance-CJko9liH.d.ts} +5 -2
- package/dist/tool-result-ui-meta-KT0VafEO.d.ts +52 -0
- package/dist/trigger/index.d.ts +1 -1
- package/dist/trigger/index.js +118 -2
- package/dist/trigger/index.js.map +1 -1
- package/dist/{trigger--qTIK0s6.d.ts → trigger-C1ooSegc.d.ts} +2 -2
- package/dist/workflow/index.d.ts +1 -1
- package/dist/workflow/index.js +118 -2
- package/dist/workflow/index.js.map +1 -1
- package/package.json +21 -4
- package/dist/index-Blq0XoAr.d.ts +0 -204
- package/dist/tool-ui-hint-CMpug5sC.d.ts +0 -13
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as eve_tools from 'eve/tools';
|
|
2
|
-
import { T as
|
|
2
|
+
import { T as ToolResultUiMeta, a as ToolUiHint } from '../../../tool-result-ui-meta-KT0VafEO.js';
|
|
3
|
+
import { T as ToolResultWithReplyGuidance } from '../../../tool-reply-guidance-CJko9liH.js';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
/** Eve tool slug — must match the agent tool filename `get_my_access.ts`. */
|
|
@@ -8,10 +9,94 @@ declare const myAccessInputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
|
8
9
|
declare function defineMyAccessTool(): eve_tools.ToolDefinition<Record<string, never>, ToolResultWithReplyGuidance<{
|
|
9
10
|
authenticated: false;
|
|
10
11
|
message: string;
|
|
11
|
-
}> |
|
|
12
|
+
}> | ({
|
|
13
|
+
access: {
|
|
14
|
+
email?: string | undefined;
|
|
15
|
+
workspace: string;
|
|
16
|
+
role: string;
|
|
17
|
+
tenantAdmin: boolean;
|
|
18
|
+
groups: string;
|
|
19
|
+
manageSettings: boolean;
|
|
20
|
+
manageBilling: boolean;
|
|
21
|
+
manageTeam: boolean;
|
|
22
|
+
manageIntegrations: boolean;
|
|
23
|
+
};
|
|
24
|
+
} & {
|
|
25
|
+
replyGuidance: string;
|
|
26
|
+
} & Partial<{
|
|
27
|
+
access: {
|
|
28
|
+
email?: string | undefined;
|
|
29
|
+
workspace: string;
|
|
30
|
+
role: string;
|
|
31
|
+
tenantAdmin: boolean;
|
|
32
|
+
groups: string;
|
|
33
|
+
manageSettings: boolean;
|
|
34
|
+
manageBilling: boolean;
|
|
35
|
+
manageTeam: boolean;
|
|
36
|
+
manageIntegrations: boolean;
|
|
37
|
+
};
|
|
38
|
+
} & {
|
|
39
|
+
ui: ToolResultUiMeta;
|
|
40
|
+
}> & Partial<{
|
|
41
|
+
access: {
|
|
42
|
+
email?: string | undefined;
|
|
43
|
+
workspace: string;
|
|
44
|
+
role: string;
|
|
45
|
+
tenantAdmin: boolean;
|
|
46
|
+
groups: string;
|
|
47
|
+
manageSettings: boolean;
|
|
48
|
+
manageBilling: boolean;
|
|
49
|
+
manageTeam: boolean;
|
|
50
|
+
manageIntegrations: boolean;
|
|
51
|
+
};
|
|
52
|
+
} & {
|
|
53
|
+
uiHint: ToolUiHint;
|
|
54
|
+
}>)>;
|
|
12
55
|
declare const myAccessTool: eve_tools.ToolDefinition<Record<string, never>, ToolResultWithReplyGuidance<{
|
|
13
56
|
authenticated: false;
|
|
14
57
|
message: string;
|
|
15
|
-
}> |
|
|
58
|
+
}> | ({
|
|
59
|
+
access: {
|
|
60
|
+
email?: string | undefined;
|
|
61
|
+
workspace: string;
|
|
62
|
+
role: string;
|
|
63
|
+
tenantAdmin: boolean;
|
|
64
|
+
groups: string;
|
|
65
|
+
manageSettings: boolean;
|
|
66
|
+
manageBilling: boolean;
|
|
67
|
+
manageTeam: boolean;
|
|
68
|
+
manageIntegrations: boolean;
|
|
69
|
+
};
|
|
70
|
+
} & {
|
|
71
|
+
replyGuidance: string;
|
|
72
|
+
} & Partial<{
|
|
73
|
+
access: {
|
|
74
|
+
email?: string | undefined;
|
|
75
|
+
workspace: string;
|
|
76
|
+
role: string;
|
|
77
|
+
tenantAdmin: boolean;
|
|
78
|
+
groups: string;
|
|
79
|
+
manageSettings: boolean;
|
|
80
|
+
manageBilling: boolean;
|
|
81
|
+
manageTeam: boolean;
|
|
82
|
+
manageIntegrations: boolean;
|
|
83
|
+
};
|
|
84
|
+
} & {
|
|
85
|
+
ui: ToolResultUiMeta;
|
|
86
|
+
}> & Partial<{
|
|
87
|
+
access: {
|
|
88
|
+
email?: string | undefined;
|
|
89
|
+
workspace: string;
|
|
90
|
+
role: string;
|
|
91
|
+
tenantAdmin: boolean;
|
|
92
|
+
groups: string;
|
|
93
|
+
manageSettings: boolean;
|
|
94
|
+
manageBilling: boolean;
|
|
95
|
+
manageTeam: boolean;
|
|
96
|
+
manageIntegrations: boolean;
|
|
97
|
+
};
|
|
98
|
+
} & {
|
|
99
|
+
uiHint: ToolUiHint;
|
|
100
|
+
}>)>;
|
|
16
101
|
|
|
17
102
|
export { MY_ACCESS_TOOL_NAME, defineMyAccessTool, myAccessInputSchema, myAccessTool };
|
|
@@ -72,9 +72,22 @@ function withUiHint(result, hint) {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// src/eve/tool-result-ui-meta.ts
|
|
76
|
+
var TOOL_UI_FIELD = "ui";
|
|
77
|
+
function withToolUi(result, ui) {
|
|
78
|
+
const existing = typeof result[TOOL_UI_FIELD] === "object" && result[TOOL_UI_FIELD] !== null && !Array.isArray(result[TOOL_UI_FIELD]) ? result[TOOL_UI_FIELD] : {};
|
|
79
|
+
return {
|
|
80
|
+
...result,
|
|
81
|
+
[TOOL_UI_FIELD]: {
|
|
82
|
+
...existing,
|
|
83
|
+
...ui
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
// src/eve/tool-reply-guidance.ts
|
|
76
89
|
var TOOL_REPLY_GUIDANCE_FIELD = "replyGuidance";
|
|
77
|
-
var MY_ACCESS_REPLY_GUIDANCE = "Access details may render in chat UI. Do not restate role, groups, or admin capabilities if already visible. Only explain what the user can or cannot do for their question (e.g. finance group required for refunds \u2265 $10,000). When access.tenantAdmin is false and the user needs manageTeam, manageGroups,
|
|
90
|
+
var MY_ACCESS_REPLY_GUIDANCE = "Access details may render in chat UI. Do not restate role, groups, or admin capabilities if already visible. Only explain what the user can or cannot do for their question (e.g. finance group required for refunds \u2265 $10,000). When access.tenantAdmin is false and the user needs manageTeam, manageGroups, query-tasks, or workspace-usage capabilities, explain briefly then call ask_question to offer sending an admin request to tenant admins \u2014 do not tell them to find an admin manually without offering delegation first.";
|
|
78
91
|
function withReplyGuidance(result, guidance) {
|
|
79
92
|
return {
|
|
80
93
|
...result,
|
|
@@ -84,11 +97,17 @@ function withReplyGuidance(result, guidance) {
|
|
|
84
97
|
|
|
85
98
|
// src/eve/tool-display-format.ts
|
|
86
99
|
function formatToolObjectResult(data, options) {
|
|
87
|
-
|
|
100
|
+
let result = withReplyGuidance(
|
|
101
|
+
data,
|
|
102
|
+
options.replyGuidance
|
|
103
|
+
);
|
|
104
|
+
if (options.ui) {
|
|
105
|
+
result = withToolUi(result, options.ui);
|
|
106
|
+
}
|
|
88
107
|
if (options.uiHint) {
|
|
89
|
-
|
|
108
|
+
result = withUiHint(result, options.uiHint);
|
|
90
109
|
}
|
|
91
|
-
return
|
|
110
|
+
return result;
|
|
92
111
|
}
|
|
93
112
|
|
|
94
113
|
// src/eve/tools/identity/format-my-access.ts
|
|
@@ -108,7 +127,8 @@ function formatMyAccessResult(input) {
|
|
|
108
127
|
}
|
|
109
128
|
},
|
|
110
129
|
{
|
|
111
|
-
replyGuidance: MY_ACCESS_REPLY_GUIDANCE
|
|
130
|
+
replyGuidance: MY_ACCESS_REPLY_GUIDANCE,
|
|
131
|
+
ui: { entity: "access" }
|
|
112
132
|
}
|
|
113
133
|
);
|
|
114
134
|
}
|
|
@@ -126,7 +146,7 @@ function tenantCapabilities(isAdmin) {
|
|
|
126
146
|
}
|
|
127
147
|
function defineMyAccessTool() {
|
|
128
148
|
return defineTool({
|
|
129
|
-
description: "Check the authenticated user's tenant role, group memberships, and admin capabilities in RobotRock. Always call this before tenant-admin tools (manage_team_members, manage_groups, query_tasks) in the same turn \u2014 including read-only requests like listing users. Results render as a visible access tool card in chat like other tools; do not restate role, groups, or capabilities in your reply.",
|
|
149
|
+
description: "Check the authenticated user's tenant role, group memberships, and admin capabilities in RobotRock. Always call this before tenant-admin tools (manage_team_members, manage_groups, query_tasks, get_workspace_usage) in the same turn \u2014 including read-only requests like listing users or usage. Results render as a visible access tool card in chat like other tools; do not restate role, groups, or capabilities in your reply.",
|
|
130
150
|
inputSchema: myAccessInputSchema,
|
|
131
151
|
async execute(_input, ctx) {
|
|
132
152
|
const caller = tryResolveTenantCaller(ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/eve/tools/identity/my-access.ts","../../../../src/eve/agent/attributes.ts","../../../../src/eve/agent/tenant.ts","../../../../src/eve/tool-ui-hint.ts","../../../../src/eve/tool-reply-guidance.ts","../../../../src/eve/tool-display-format.ts","../../../../src/eve/tools/identity/format-my-access.ts"],"sourcesContent":["import { defineTool } from \"eve/tools\";\nimport { z } from \"zod\";\nimport { tryResolveTenantCaller } from \"../../agent/tenant.js\";\nimport {\n MY_ACCESS_REPLY_GUIDANCE,\n withReplyGuidance,\n} from \"../../tool-reply-guidance.js\";\nimport { formatMyAccessResult } from \"./format-my-access.js\";\n\n/** Eve tool slug — must match the agent tool filename `get_my_access.ts`. */\nexport const MY_ACCESS_TOOL_NAME = \"get_my_access\";\n\nexport const myAccessInputSchema = z.object({});\n\nfunction tenantCapabilities(isAdmin: boolean) {\n return {\n manageSettings: isAdmin,\n manageBilling: isAdmin,\n manageTeam: isAdmin,\n manageIntegrations: isAdmin,\n };\n}\n\nexport function defineMyAccessTool() {\n return defineTool({\n description:\n \"Check the authenticated user's tenant role, group memberships, and admin capabilities in RobotRock. \" +\n \"Always call this before tenant-admin tools (manage_team_members, manage_groups, query_tasks) in the same turn — \" +\n \"including read-only requests like listing users. Results render as a visible access tool card in chat like other tools; \" +\n \"do not restate role, groups, or capabilities in your reply.\",\n inputSchema: myAccessInputSchema,\n async execute(_input, ctx) {\n const caller = tryResolveTenantCaller(ctx);\n if (!caller) {\n return withReplyGuidance(\n {\n authenticated: false as const,\n message:\n \"No RobotRock user is attached to this session. Dashboard chat supplies user context via the Eve proxy.\",\n },\n \"Explain that no user is attached to this session. Do not invent access details.\"\n );\n }\n\n return formatMyAccessResult({\n tenantSlug: caller.tenantSlug,\n tenantRole: caller.role,\n isTenantAdmin: caller.isAdmin,\n groupSlugs: caller.groups,\n capabilities: tenantCapabilities(caller.isAdmin),\n email: caller.email,\n });\n },\n });\n}\n\nexport const myAccessTool = defineMyAccessTool();\n","export function readStringAttribute(\n attributes: Readonly<Record<string, string | readonly string[]>> | undefined,\n key: string\n): string | undefined {\n const value = attributes?.[key];\n if (typeof value === \"string\" && value.length > 0) {\n return value;\n }\n if (Array.isArray(value) && typeof value[0] === \"string\" && value[0].length > 0) {\n return value[0];\n }\n return undefined;\n}\n\nexport function readStringArrayAttribute(\n attributes: Readonly<Record<string, string | readonly string[]>> | undefined,\n key: string\n): string[] {\n const value = attributes?.[key];\n if (typeof value === \"string\" && value.length > 0) {\n return [value];\n }\n if (Array.isArray(value)) {\n return value.filter(\n (entry): entry is string => typeof entry === \"string\" && entry.length > 0\n );\n }\n return [];\n}\n\nexport function parseTenantRole(\n value: string | undefined\n): \"admin\" | \"member\" | null {\n if (value === \"admin\" || value === \"member\") {\n return value;\n }\n return null;\n}\n","import type { SessionContext } from \"eve/context\";\nimport {\n parseTenantRole,\n readStringArrayAttribute,\n readStringAttribute,\n} from \"./attributes.js\";\n\nexport type TenantRole = \"admin\" | \"member\";\n\nexport type TenantCaller = {\n userId: string;\n email: string;\n name: string;\n tenantSlug: string;\n connectionId?: string;\n chatId?: string;\n role: TenantRole;\n isAdmin: boolean;\n groups: string[];\n workosUserId?: string;\n};\n\n/** Resolve the authenticated RobotRock dashboard user for the current session. */\nexport function tryResolveTenantCaller(ctx: SessionContext): TenantCaller | null {\n const caller = ctx.session.auth.initiator ?? ctx.session.auth.current;\n if (caller?.principalType !== \"user\") {\n return null;\n }\n\n const email = readStringAttribute(caller.attributes, \"email\");\n const name = readStringAttribute(caller.attributes, \"name\");\n const tenantSlug =\n readStringAttribute(caller.attributes, \"tenantSlug\") ??\n readStringAttribute(caller.attributes, \"tenantId\");\n const role = parseTenantRole(readStringAttribute(caller.attributes, \"role\"));\n if (!email || !tenantSlug || !caller.principalId || !role) {\n return null;\n }\n\n const workosUserId = readStringAttribute(caller.attributes, \"workosUserId\");\n const connectionId = readStringAttribute(caller.attributes, \"connectionId\");\n const chatId = readStringAttribute(caller.attributes, \"chatId\");\n const groups = readStringArrayAttribute(caller.attributes, \"groups\");\n\n return {\n userId: caller.principalId,\n email,\n name: name ?? email.split(\"@\")[0] ?? email,\n tenantSlug,\n ...(connectionId ? { connectionId } : {}),\n ...(chatId ? { chatId } : {}),\n role,\n isAdmin: role === \"admin\",\n groups,\n ...(workosUserId ? { workosUserId } : {}),\n };\n}\n\n/** Like {@link tryResolveTenantCaller} but throws when the session has no user. */\nexport function requireTenantCaller(ctx: SessionContext): TenantCaller {\n const caller = tryResolveTenantCaller(ctx);\n if (!caller) {\n throw new Error(\"An authenticated RobotRock tenant user is required.\");\n }\n return caller;\n}\n\nexport function isAdminCaller(ctx: SessionContext): boolean {\n return tryResolveTenantCaller(ctx)?.isAdmin === true;\n}\n\n/** Require an authenticated tenant admin for the current session. */\nexport function requireAdminCaller(ctx: SessionContext): TenantCaller {\n const caller = requireTenantCaller(ctx);\n if (!caller.isAdmin) {\n throw new Error(\"Tenant admin access is required.\");\n }\n return caller;\n}\n","/** Field name for optional layout hints on tool execute results. */\nexport const TOOL_UI_HINT_FIELD = \"uiHint\" as const;\n\n/** Top-level layout hint for RobotRock TRL rendering. Optional — omit to let the dashboard infer. */\nexport type ToolUiHint = \"list\" | \"chart\" | \"table\";\n\nconst TOOL_UI_HINTS = new Set<ToolUiHint>([\"list\", \"chart\", \"table\"]);\n\nexport function isToolUiHint(value: unknown): value is ToolUiHint {\n return typeof value === \"string\" && TOOL_UI_HINTS.has(value as ToolUiHint);\n}\n\n/** Attach an optional layout hint to a tool execute result. */\nexport function withUiHint<T extends Record<string, unknown>>(\n result: T,\n hint: ToolUiHint\n): T & { uiHint: ToolUiHint } {\n return {\n ...result,\n [TOOL_UI_HINT_FIELD]: hint,\n };\n}\n\n/** Read a validated layout hint from tool output; unknown values are ignored. */\nexport function extractToolUiHint(output: unknown): ToolUiHint | undefined {\n if (typeof output !== \"object\" || output === null || Array.isArray(output)) {\n return undefined;\n }\n\n const hint = (output as Record<string, unknown>)[TOOL_UI_HINT_FIELD];\n return isToolUiHint(hint) ? hint : undefined;\n}\n","import { TOOL_UI_HINT_FIELD } from \"./tool-ui-hint.js\";\n\n/** Field name agents read; dashboard widgets must ignore when rendering. */\nexport const TOOL_REPLY_GUIDANCE_FIELD = \"replyGuidance\" as const;\n\nexport const WHOAMI_REPLY_GUIDANCE =\n \"The dashboard shows a profile card with name, email, workspace, role, and groups. Do not restate those in your reply. Only add context not in the card (e.g. permissions, refund approval rules, missing group membership).\";\n\nexport const MY_ACCESS_REPLY_GUIDANCE =\n \"Access details may render in chat UI. Do not restate role, groups, or admin capabilities if already visible. Only explain what the user can or cannot do for their question (e.g. finance group required for refunds ≥ $10,000). When access.tenantAdmin is false and the user needs manageTeam, manageGroups, or query-tasks capabilities, explain briefly then call ask_question to offer sending an admin request to tenant admins — do not tell them to find an admin manually without offering delegation first.\";\n\nexport const CREATE_INBOX_TASK_REPLY_GUIDANCE =\n \"A task card shows title, assignee, and inbox status in chat. Do not restate task ID, assignee, or delegation details from the card. Only mention next steps or answer the user's question.\";\n\nexport const SEARCH_PRODUCTS_REPLY_GUIDANCE =\n \"Product results render as a list card in chat. Do not restate product names, prices, or SKUs. Only add context not in the list (e.g. no matches, recommendations).\";\n\nexport const MANAGE_TEAM_MEMBERS_LIST_REPLY_GUIDANCE =\n \"Team members render as a list card in chat. Do not restate names, emails, or roles from the list. Only add context not shown (e.g. duplicates, next admin actions).\";\n\nexport const MANAGE_TEAM_MEMBERS_DETAIL_REPLY_GUIDANCE =\n \"Team member details render in chat UI. Do not restate name, email, or role from the card. Only add next steps or policy context.\";\n\nexport const MANAGE_GROUPS_LIST_REPLY_GUIDANCE =\n \"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.\";\n\nexport const MANAGE_GROUPS_DETAIL_REPLY_GUIDANCE =\n \"Group details render in chat UI. Do not restate fields already visible in the card. Only add next steps.\";\n\nexport const QUERY_TASKS_LIST_REPLY_GUIDANCE =\n \"Tasks render as a list card in chat. Do not restate task names, ids, or statuses from the list. Only add context not shown (e.g. filters applied, recommended next action).\";\n\nexport const QUERY_TASKS_DETAIL_REPLY_GUIDANCE =\n \"Task details render in chat UI. Do not restate fields already visible in the card. Only add analysis or next steps.\";\n\nexport const ASSIGN_TASKS_REPLY_GUIDANCE =\n \"Reassignment results render in chat UI. Do not restate task ids or assignee emails from the card. Only mention failures, partial success, or next steps.\";\n\nexport const REFUND_CHARGE_REPLY_GUIDANCE =\n \"Refund details render in chat UI. Do not restate charge id, amount, or status from the card. Only add policy context or next steps.\";\n\nexport const DEPLOY_RELEASE_REPLY_GUIDANCE =\n \"Deploy details render in chat UI. Do not restate service, version, or environment from the card. Only add rollout context or next steps.\";\n\nexport const GET_WEATHER_REPLY_GUIDANCE =\n \"Weather details render in chat UI. Do not restate city, condition, or temperature from the card. Only add conversational context if needed.\";\n\nexport const ADMIN_MUTATION_REPLY_GUIDANCE =\n \"The action result renders in chat UI. Do not restate fields already visible in the card. Confirm outcome briefly or add next steps only.\";\n\nexport type ToolResultWithReplyGuidance<T extends Record<string, unknown>> = T & {\n replyGuidance: string;\n};\n\n/** Attach model-facing narration hints to a tool execute result. */\nexport function withReplyGuidance<T extends Record<string, unknown>>(\n result: T,\n guidance: string\n): ToolResultWithReplyGuidance<T> {\n return {\n ...result,\n [TOOL_REPLY_GUIDANCE_FIELD]: guidance,\n };\n}\n\n/** Remove agent-only fields before showing raw JSON in the dashboard. */\nexport function stripAgentOnlyToolFields(output: unknown): unknown {\n if (typeof output !== \"object\" || output === null || Array.isArray(output)) {\n return output;\n }\n\n const record = { ...(output as Record<string, unknown>) };\n delete record[TOOL_REPLY_GUIDANCE_FIELD];\n delete record[TOOL_UI_HINT_FIELD];\n return record;\n}\n","import { withReplyGuidance } from \"./tool-reply-guidance.js\";\nimport { withUiHint, type ToolUiHint } from \"./tool-ui-hint.js\";\n\nexport type FormatToolObjectResultOptions = {\n replyGuidance: string;\n /** Optional layout hint for TRL rendering. Omit to let the dashboard infer. */\n uiHint?: ToolUiHint;\n};\n\nexport type FormatToolListResultOptions = {\n replyGuidance: string;\n};\n\n/** Attach agent narration hints to plain tool JSON. No display/ui envelope. */\nexport function formatToolObjectResult(\n data: Record<string, unknown>,\n options: FormatToolObjectResultOptions\n) {\n const withGuidance = withReplyGuidance(data, options.replyGuidance);\n if (options.uiHint) {\n return withUiHint(withGuidance, options.uiHint);\n }\n return withGuidance;\n}\n\n/** Wrap an array field as plain tool JSON with reply guidance and list layout hint. */\nexport function formatToolListResult(\n listKey: string,\n items: Record<string, unknown>[],\n options: FormatToolListResultOptions\n) {\n return withUiHint(\n withReplyGuidance({ [listKey]: items }, options.replyGuidance),\n \"list\"\n );\n}\n\nexport function isAgentAdminErrorResult(\n result: unknown\n): result is { ok: false; message: string } {\n return (\n typeof result === \"object\" &&\n result !== null &&\n (result as { ok?: unknown }).ok === false &&\n typeof (result as { message?: unknown }).message === \"string\"\n );\n}\n","import { formatToolObjectResult } from \"../../tool-display-format.js\";\nimport { MY_ACCESS_REPLY_GUIDANCE } from \"../../tool-reply-guidance.js\";\n\ntype MyAccessResultInput = {\n tenantSlug: string;\n tenantRole?: string;\n isTenantAdmin: boolean;\n groupSlugs: string[];\n capabilities: {\n manageSettings: boolean;\n manageBilling: boolean;\n manageTeam: boolean;\n manageIntegrations: boolean;\n };\n email?: string;\n};\n\nexport function formatMyAccessResult(input: MyAccessResultInput) {\n return formatToolObjectResult(\n {\n access: {\n workspace: input.tenantSlug,\n role: input.tenantRole ?? \"member\",\n tenantAdmin: input.isTenantAdmin,\n groups: input.groupSlugs.join(\", \") || \"—\",\n manageSettings: input.capabilities.manageSettings,\n manageBilling: input.capabilities.manageBilling,\n manageTeam: input.capabilities.manageTeam,\n manageIntegrations: input.capabilities.manageIntegrations,\n ...(input.email ? { email: input.email } : {}),\n },\n },\n {\n replyGuidance: MY_ACCESS_REPLY_GUIDANCE,\n }\n );\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,SAAS;;;ACDX,SAAS,oBACd,YACA,KACoB;AACpB,QAAM,QAAQ,aAAa,GAAG;AAC9B,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG;AACjD,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,KAAK,KAAK,OAAO,MAAM,CAAC,MAAM,YAAY,MAAM,CAAC,EAAE,SAAS,GAAG;AAC/E,WAAO,MAAM,CAAC;AAAA,EAChB;AACA,SAAO;AACT;AAEO,SAAS,yBACd,YACA,KACU;AACV,QAAM,QAAQ,aAAa,GAAG;AAC9B,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG;AACjD,WAAO,CAAC,KAAK;AAAA,EACf;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM;AAAA,MACX,CAAC,UAA2B,OAAO,UAAU,YAAY,MAAM,SAAS;AAAA,IAC1E;AAAA,EACF;AACA,SAAO,CAAC;AACV;AAEO,SAAS,gBACd,OAC2B;AAC3B,MAAI,UAAU,WAAW,UAAU,UAAU;AAC3C,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACdO,SAAS,uBAAuB,KAA0C;AAC/E,QAAM,SAAS,IAAI,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK;AAC9D,MAAI,QAAQ,kBAAkB,QAAQ;AACpC,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,oBAAoB,OAAO,YAAY,OAAO;AAC5D,QAAM,OAAO,oBAAoB,OAAO,YAAY,MAAM;AAC1D,QAAM,aACJ,oBAAoB,OAAO,YAAY,YAAY,KACnD,oBAAoB,OAAO,YAAY,UAAU;AACnD,QAAM,O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1B,aAAa,MAAM;AAAA,QACnB,QAAQ,MAAM,WAAW,KAAK,IAAI,KAAK;AAAA,QACvC,gBAAgB,MAAM,aAAa;AAAA,QACnC,eAAe,MAAM,aAAa;AAAA,QAClC,YAAY,MAAM,aAAa;AAAA,QAC/B,oBAAoB,MAAM,aAAa;AAAA,QACvC,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;AAAA,MAC9C;AAAA,IACF;AAAA,IACA;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,EACF;AACF;;;AN1BO,IAAM,sBAAsB;AAE5B,IAAM,sBAAsB,EAAE,OAAO,CAAC,CAAC;AAE9C,SAAS,mBAAmB,SAAkB;AAC5C,SAAO;AAAA,IACL,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,YAAY;AAAA,IACZ,oBAAoB;AAAA,EACtB;AACF;AAEO,SAAS,qBAAqB;AACnC,SAAO,WAAW;AAAA,IAChB,aACE;AAAA,IAIF,aAAa;AAAA,IACb,MAAM,QAAQ,QAAQ,KAAK;AACzB,YAAM,SAAS,uBAAuB,GAAG;AACzC,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,UACL;AAAA,YACE,eAAe;AAAA,YACf,SACE;AAAA,UACJ;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,aAAO,qBAAqB;AAAA,QAC1B,YAAY,OAAO;AAAA,QACnB,YAAY,OAAO;AAAA,QACnB,eAAe,OAAO;AAAA,QACtB,YAAY,OAAO;AAAA,QACnB,cAAc,mBAAmB,OAAO,OAAO;AAAA,QAC/C,OAAO,OAAO;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;AAEO,IAAM,eAAe,mBAAmB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/eve/tools/identity/my-access.ts","../../../../src/eve/agent/attributes.ts","../../../../src/eve/agent/tenant.ts","../../../../src/eve/tool-ui-hint.ts","../../../../src/eve/tool-result-ui-meta.ts","../../../../src/eve/tool-reply-guidance.ts","../../../../src/eve/tool-display-format.ts","../../../../src/eve/tools/identity/format-my-access.ts"],"sourcesContent":["import { defineTool } from \"eve/tools\";\nimport { z } from \"zod\";\nimport { tryResolveTenantCaller } from \"../../agent/tenant.js\";\nimport {\n MY_ACCESS_REPLY_GUIDANCE,\n withReplyGuidance,\n} from \"../../tool-reply-guidance.js\";\nimport { formatMyAccessResult } from \"./format-my-access.js\";\n\n/** Eve tool slug — must match the agent tool filename `get_my_access.ts`. */\nexport const MY_ACCESS_TOOL_NAME = \"get_my_access\";\n\nexport const myAccessInputSchema = z.object({});\n\nfunction tenantCapabilities(isAdmin: boolean) {\n return {\n manageSettings: isAdmin,\n manageBilling: isAdmin,\n manageTeam: isAdmin,\n manageIntegrations: isAdmin,\n };\n}\n\nexport function defineMyAccessTool() {\n return defineTool({\n description:\n \"Check the authenticated user's tenant role, group memberships, and admin capabilities in RobotRock. \" +\n \"Always call this before tenant-admin tools (manage_team_members, manage_groups, query_tasks, get_workspace_usage) in the same turn — \" +\n \"including read-only requests like listing users or usage. Results render as a visible access tool card in chat like other tools; \" +\n \"do not restate role, groups, or capabilities in your reply.\",\n inputSchema: myAccessInputSchema,\n async execute(_input, ctx) {\n const caller = tryResolveTenantCaller(ctx);\n if (!caller) {\n return withReplyGuidance(\n {\n authenticated: false as const,\n message:\n \"No RobotRock user is attached to this session. Dashboard chat supplies user context via the Eve proxy.\",\n },\n \"Explain that no user is attached to this session. Do not invent access details.\"\n );\n }\n\n return formatMyAccessResult({\n tenantSlug: caller.tenantSlug,\n tenantRole: caller.role,\n isTenantAdmin: caller.isAdmin,\n groupSlugs: caller.groups,\n capabilities: tenantCapabilities(caller.isAdmin),\n email: caller.email,\n });\n },\n });\n}\n\nexport const myAccessTool = defineMyAccessTool();\n","export function readStringAttribute(\n attributes: Readonly<Record<string, string | readonly string[]>> | undefined,\n key: string\n): string | undefined {\n const value = attributes?.[key];\n if (typeof value === \"string\" && value.length > 0) {\n return value;\n }\n if (Array.isArray(value) && typeof value[0] === \"string\" && value[0].length > 0) {\n return value[0];\n }\n return undefined;\n}\n\nexport function readStringArrayAttribute(\n attributes: Readonly<Record<string, string | readonly string[]>> | undefined,\n key: string\n): string[] {\n const value = attributes?.[key];\n if (typeof value === \"string\" && value.length > 0) {\n return [value];\n }\n if (Array.isArray(value)) {\n return value.filter(\n (entry): entry is string => typeof entry === \"string\" && entry.length > 0\n );\n }\n return [];\n}\n\nexport function parseTenantRole(\n value: string | undefined\n): \"admin\" | \"member\" | null {\n if (value === \"admin\" || value === \"member\") {\n return value;\n }\n return null;\n}\n","import type { SessionContext } from \"eve/context\";\nimport {\n parseTenantRole,\n readStringArrayAttribute,\n readStringAttribute,\n} from \"./attributes.js\";\n\nexport type TenantRole = \"admin\" | \"member\";\n\nexport type TenantCaller = {\n userId: string;\n email: string;\n name: string;\n tenantSlug: string;\n connectionId?: string;\n chatId?: string;\n role: TenantRole;\n isAdmin: boolean;\n groups: string[];\n workosUserId?: string;\n};\n\n/** Resolve the authenticated RobotRock dashboard user for the current session. */\nexport function tryResolveTenantCaller(ctx: SessionContext): TenantCaller | null {\n const caller = ctx.session.auth.initiator ?? ctx.session.auth.current;\n if (caller?.principalType !== \"user\") {\n return null;\n }\n\n const email = readStringAttribute(caller.attributes, \"email\");\n const name = readStringAttribute(caller.attributes, \"name\");\n const tenantSlug =\n readStringAttribute(caller.attributes, \"tenantSlug\") ??\n readStringAttribute(caller.attributes, \"tenantId\");\n const role = parseTenantRole(readStringAttribute(caller.attributes, \"role\"));\n if (!email || !tenantSlug || !caller.principalId || !role) {\n return null;\n }\n\n const workosUserId = readStringAttribute(caller.attributes, \"workosUserId\");\n const connectionId = readStringAttribute(caller.attributes, \"connectionId\");\n const chatId = readStringAttribute(caller.attributes, \"chatId\");\n const groups = readStringArrayAttribute(caller.attributes, \"groups\");\n\n return {\n userId: caller.principalId,\n email,\n name: name ?? email.split(\"@\")[0] ?? email,\n tenantSlug,\n ...(connectionId ? { connectionId } : {}),\n ...(chatId ? { chatId } : {}),\n role,\n isAdmin: role === \"admin\",\n groups,\n ...(workosUserId ? { workosUserId } : {}),\n };\n}\n\n/** Like {@link tryResolveTenantCaller} but throws when the session has no user. */\nexport function requireTenantCaller(ctx: SessionContext): TenantCaller {\n const caller = tryResolveTenantCaller(ctx);\n if (!caller) {\n throw new Error(\"An authenticated RobotRock tenant user is required.\");\n }\n return caller;\n}\n\nexport function isAdminCaller(ctx: SessionContext): boolean {\n return tryResolveTenantCaller(ctx)?.isAdmin === true;\n}\n\n/** Require an authenticated tenant admin for the current session. */\nexport function requireAdminCaller(ctx: SessionContext): TenantCaller {\n const caller = requireTenantCaller(ctx);\n if (!caller.isAdmin) {\n throw new Error(\"Tenant admin access is required.\");\n }\n return caller;\n}\n","/** Field name for optional layout hints on tool execute results. */\nexport const TOOL_UI_HINT_FIELD = \"uiHint\" as const;\n\n/** Top-level layout hint for RobotRock TRL rendering. Optional — omit to let the dashboard infer. */\nexport type ToolUiHint = \"list\" | \"chart\" | \"table\";\n\nconst TOOL_UI_HINTS = new Set<ToolUiHint>([\"list\", \"chart\", \"table\"]);\n\nexport function isToolUiHint(value: unknown): value is ToolUiHint {\n return typeof value === \"string\" && TOOL_UI_HINTS.has(value as ToolUiHint);\n}\n\n/** Attach an optional layout hint to a tool execute result. */\nexport function withUiHint<T extends Record<string, unknown>>(\n result: T,\n hint: ToolUiHint\n): T & { uiHint: ToolUiHint } {\n return {\n ...result,\n [TOOL_UI_HINT_FIELD]: hint,\n };\n}\n\n/** Read a validated layout hint from tool output; unknown values are ignored. */\nexport function extractToolUiHint(output: unknown): ToolUiHint | undefined {\n if (typeof output !== \"object\" || output === null || Array.isArray(output)) {\n return undefined;\n }\n\n const hint = (output as Record<string, unknown>)[TOOL_UI_HINT_FIELD];\n return isToolUiHint(hint) ? hint : undefined;\n}\n","import { isToolUiHint, type ToolUiHint } from \"./tool-ui-hint.js\";\n\n/** Nested agent-only UI metadata on tool execute results. */\nexport const TOOL_UI_FIELD = \"ui\" as const;\n\n/** Free-form entity id: lowercase slug used as cache key (e.g. member, task). */\nexport const TOOL_RESULT_UI_ENTITY_ID_RE = /^[a-z][a-z0-9_]{0,63}$/;\n\n/**\n * Recommended entity ids for RobotRock tools. Not exhaustive — any valid slug is accepted.\n * @deprecated Prefer free-form `ui.entity` strings; this list is documentation only.\n */\nexport const TOOL_RESULT_UI_ENTITIES = [\n \"product\",\n \"member\",\n \"task\",\n \"group\",\n \"status\",\n \"object\",\n] as const;\n\nexport type ToolResultUiEntity = string;\n\n/** Render layout hint (not a cached atom). Derived from uiHint / legacy pattern. */\nexport type ToolResultUiLayout = ToolUiHint;\n\nexport type ToolResultUiMeta = {\n /** Hybrid presentation override: true = always show card, false = never. */\n present?: boolean;\n /** Entity id for row layout cache (free-form slug). */\n entity?: ToolResultUiEntity;\n /** Path to row array for list cards (e.g. \"rows\", \"items\"). */\n rowsPath?: string;\n /** Viz/collection layout hint — chart | table | list. Not a pattern atom. */\n layout?: ToolResultUiLayout;\n};\n\nexport function isToolResultUiEntityId(value: unknown): value is string {\n return typeof value === \"string\" && TOOL_RESULT_UI_ENTITY_ID_RE.test(value);\n}\n\n/** @deprecated Use isToolResultUiEntityId. */\nexport function isToolResultUiEntity(value: unknown): value is string {\n return isToolResultUiEntityId(value);\n}\n\n/** Map legacy top-level uiHint into a layout hint. */\nexport function uiHintToLayout(hint: ToolUiHint): ToolResultUiLayout {\n return hint;\n}\n\n/**\n * Map legacy `ui.pattern` values into layout / rowsPath behavior.\n * Patterns are no longer cached atoms.\n */\nexport function legacyPatternToLayout(\n pattern: string\n): ToolResultUiLayout | undefined {\n switch (pattern) {\n case \"chart\":\n return \"chart\";\n case \"table\":\n return \"table\";\n case \"list\":\n case \"query\":\n return \"list\";\n default:\n return undefined;\n }\n}\n\nfunction readPresent(value: unknown): boolean | undefined {\n return typeof value === \"boolean\" ? value : undefined;\n}\n\nfunction readRowsPath(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction readEntity(value: unknown): string | undefined {\n if (!isToolResultUiEntityId(value)) {\n return undefined;\n }\n return value;\n}\n\n/** Read and validate nested `ui` metadata (+ legacy uiHint / pattern → layout). */\nexport function extractToolResultUiMeta(\n output: unknown\n): ToolResultUiMeta | undefined {\n if (typeof output !== \"object\" || output === null || Array.isArray(output)) {\n return undefined;\n }\n\n const record = output as Record<string, unknown>;\n const rawUi = record[TOOL_UI_FIELD];\n const meta: ToolResultUiMeta = {};\n\n if (typeof rawUi === \"object\" && rawUi !== null && !Array.isArray(rawUi)) {\n const ui = rawUi as Record<string, unknown>;\n const present = readPresent(ui.present);\n if (present !== undefined) {\n meta.present = present;\n }\n const entity = readEntity(ui.entity);\n if (entity) {\n meta.entity = entity;\n }\n const rowsPath = readRowsPath(ui.rowsPath);\n if (rowsPath) {\n meta.rowsPath = rowsPath;\n }\n if (isToolUiHint(ui.layout)) {\n meta.layout = ui.layout;\n } else if (typeof ui.pattern === \"string\") {\n // Legacy nested pattern → layout hint only.\n const fromPattern = legacyPatternToLayout(ui.pattern);\n if (fromPattern) {\n meta.layout = fromPattern;\n }\n }\n }\n\n if (!meta.layout && isToolUiHint(record.uiHint)) {\n meta.layout = uiHintToLayout(record.uiHint);\n }\n\n if (\n meta.present === undefined &&\n meta.entity === undefined &&\n meta.rowsPath === undefined &&\n meta.layout === undefined\n ) {\n return undefined;\n }\n\n return meta;\n}\n\n/** Attach nested UI metadata to a tool execute result. */\nexport function withToolUi<T extends Record<string, unknown>>(\n result: T,\n ui: ToolResultUiMeta\n): T & { ui: ToolResultUiMeta } {\n const existing =\n typeof result[TOOL_UI_FIELD] === \"object\" &&\n result[TOOL_UI_FIELD] !== null &&\n !Array.isArray(result[TOOL_UI_FIELD])\n ? (result[TOOL_UI_FIELD] as ToolResultUiMeta)\n : {};\n\n return {\n ...result,\n [TOOL_UI_FIELD]: {\n ...existing,\n ...ui,\n },\n };\n}\n","import { TOOL_UI_FIELD } from \"./tool-result-ui-meta.js\";\nimport { TOOL_UI_HINT_FIELD } from \"./tool-ui-hint.js\";\n\n/** Field name agents read; dashboard widgets must ignore when rendering. */\nexport const TOOL_REPLY_GUIDANCE_FIELD = \"replyGuidance\" as const;\n\nexport const WHOAMI_REPLY_GUIDANCE =\n \"The dashboard shows a profile card with name, email, workspace, role, and groups. Do not restate those in your reply. Only add context not in the card (e.g. permissions, refund approval rules, missing group membership).\";\n\nexport const MY_ACCESS_REPLY_GUIDANCE =\n \"Access details may render in chat UI. Do not restate role, groups, or admin capabilities if already visible. Only explain what the user can or cannot do for their question (e.g. finance group required for refunds ≥ $10,000). When access.tenantAdmin is false and the user needs manageTeam, manageGroups, query-tasks, or workspace-usage capabilities, explain briefly then call ask_question to offer sending an admin request to tenant admins — do not tell them to find an admin manually without offering delegation first.\";\n\nexport const GET_WORKSPACE_USAGE_REPLY_GUIDANCE =\n \"Workspace plan and usage render as a card in chat. Do not restate plan name, task counts, seats, groups, API keys, or rate limits from the card. Only add context not shown (e.g. upgrade options, that LLM token/cost meters are not tracked, or next steps). Never invent token or dollar spend numbers.\";\n\nexport const CREATE_INBOX_TASK_REPLY_GUIDANCE =\n \"A task card shows title, assignee, and inbox status in chat. Do not restate task ID, assignee, or delegation details from the card. Only mention next steps or answer the user's question.\";\n\nexport const SEARCH_PRODUCTS_REPLY_GUIDANCE =\n \"Product results render as a list card in chat. Do not restate product names, prices, or SKUs. Only add context not in the list (e.g. no matches, recommendations).\";\n\nexport const GENERATE_RANDOM_CHART_REPLY_GUIDANCE =\n \"Chart metrics render as a chart card in chat. Do not restate series values, dates, or categories from the chart. Only add brief context (e.g. that this is demo data).\";\n\nexport const GENERATE_IMAGE_REPLY_GUIDANCE =\n \"The generated image renders in chat UI. Do not describe the image pixels or restate the prompt. Only add a short acknowledgement or next-step question if useful.\";\n\nexport const MANAGE_TEAM_MEMBERS_LIST_REPLY_GUIDANCE =\n \"Team members render as a list card in chat. Do not restate names, emails, or roles from the list. Only add context not shown (e.g. duplicates, next admin actions).\";\n\nexport const MANAGE_TEAM_MEMBERS_DETAIL_REPLY_GUIDANCE =\n \"Team member details render in chat UI. Do not restate name, email, or role from the card. Only add next steps or policy context.\";\n\nexport const MANAGE_GROUPS_LIST_REPLY_GUIDANCE =\n \"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.\";\n\nexport const MANAGE_GROUPS_DETAIL_REPLY_GUIDANCE =\n \"Group details render in chat UI. Do not restate fields already visible in the card. Only add next steps.\";\n\nexport const QUERY_TASKS_LIST_REPLY_GUIDANCE =\n \"Tasks render as a list card in chat. Do not restate task names, ids, or statuses from the list. Only add context not shown (e.g. filters applied, recommended next action).\";\n\nexport const QUERY_TASKS_DETAIL_REPLY_GUIDANCE =\n \"Task details render in chat UI. Do not restate fields already visible in the card. Only add analysis or next steps.\";\n\nexport const ASSIGN_TASKS_REPLY_GUIDANCE =\n \"Reassignment results render in chat UI. Do not restate task ids or assignee emails from the card. Only mention failures, partial success, or next steps.\";\n\nexport const REFUND_CHARGE_REPLY_GUIDANCE =\n \"Refund details render in chat UI. Do not restate charge id, amount, or status from the card. Only add policy context or next steps.\";\n\nexport const DEPLOY_RELEASE_REPLY_GUIDANCE =\n \"Deploy details render in chat UI. Do not restate service, version, or environment from the card. Only add rollout context or next steps.\";\n\nexport const GET_WEATHER_REPLY_GUIDANCE =\n \"Weather details render in chat UI. Do not restate city, condition, or temperature from the card. Only add conversational context if needed.\";\n\nexport const ADMIN_MUTATION_REPLY_GUIDANCE =\n \"The action result renders in chat UI. Do not restate fields already visible in the card. Confirm outcome briefly or add next steps only.\";\n\nexport type ToolResultWithReplyGuidance<T extends Record<string, unknown>> = T & {\n replyGuidance: string;\n};\n\n/** Attach model-facing narration hints to a tool execute result. */\nexport function withReplyGuidance<T extends Record<string, unknown>>(\n result: T,\n guidance: string\n): ToolResultWithReplyGuidance<T> {\n return {\n ...result,\n [TOOL_REPLY_GUIDANCE_FIELD]: guidance,\n };\n}\n\n/** Remove agent-only fields before showing raw JSON in the dashboard. */\nexport function stripAgentOnlyToolFields(output: unknown): unknown {\n if (typeof output !== \"object\" || output === null || Array.isArray(output)) {\n return output;\n }\n\n const record = { ...(output as Record<string, unknown>) };\n delete record[TOOL_REPLY_GUIDANCE_FIELD];\n delete record[TOOL_UI_HINT_FIELD];\n delete record[TOOL_UI_FIELD];\n return record;\n}\n","import { withReplyGuidance } from \"./tool-reply-guidance.js\";\nimport {\n withToolUi,\n type ToolResultUiEntity,\n type ToolResultUiMeta,\n} from \"./tool-result-ui-meta.js\";\nimport { withUiHint, type ToolUiHint } from \"./tool-ui-hint.js\";\n\nexport type FormatToolObjectResultOptions = {\n replyGuidance: string;\n /** @deprecated Prefer `ui.layout`. Mapped for backward compatibility. */\n uiHint?: ToolUiHint;\n ui?: ToolResultUiMeta;\n};\n\nexport type FormatToolListResultOptions = {\n replyGuidance: string;\n entity?: ToolResultUiEntity;\n present?: boolean;\n ui?: Omit<ToolResultUiMeta, \"rowsPath\" | \"layout\">;\n};\n\nexport type FormatToolQueryResultOptions = {\n replyGuidance: string;\n entity?: ToolResultUiEntity;\n present?: boolean;\n rowsPath?: string;\n ui?: ToolResultUiMeta;\n};\n\ntype WithReplyGuidance<T> = T & { replyGuidance: string };\ntype WithUiMeta<T> = T & { ui: ToolResultUiMeta };\ntype WithUiHintField<T> = T & { uiHint: ToolUiHint };\n\n/** Attach agent narration hints to plain tool JSON. No display/ui envelope. */\nexport function formatToolObjectResult<T extends Record<string, unknown>>(\n data: T,\n options: FormatToolObjectResultOptions\n): WithReplyGuidance<T> &\n Partial<WithUiMeta<T>> &\n Partial<WithUiHintField<T>> {\n let result: Record<string, unknown> = withReplyGuidance(\n data,\n options.replyGuidance\n );\n if (options.ui) {\n result = withToolUi(result, options.ui);\n }\n if (options.uiHint) {\n result = withUiHint(result, options.uiHint);\n }\n return result as WithReplyGuidance<T> &\n Partial<WithUiMeta<T>> &\n Partial<WithUiHintField<T>>;\n}\n\n/** Wrap an array field as plain tool JSON with reply guidance and list layout hint.\n *\n * Include `url` on each item when you know a navigable link — the dashboard\n * renders clickable Item rows. Use `attachments` / `files` / `documents` keys\n * for file downloads (Attachment layout). Set `entity` so the dashboard caches\n * a reusable row layout under that name.\n */\nexport function formatToolListResult<\n const K extends string,\n T extends Record<string, unknown>,\n>(\n listKey: K,\n items: T[],\n options: FormatToolListResultOptions\n): WithReplyGuidance<Record<K, T[]>> &\n WithUiMeta<Record<K, T[]>> &\n WithUiHintField<Record<K, T[]>> {\n const ui: ToolResultUiMeta = {\n ...options.ui,\n layout: \"list\",\n rowsPath: listKey,\n ...(options.entity ? { entity: options.entity } : {}),\n ...(options.present !== undefined ? { present: options.present } : {}),\n };\n\n return withUiHint(\n withToolUi(\n withReplyGuidance({ [listKey]: items } as Record<K, T[]>, options.replyGuidance),\n ui\n ),\n \"list\"\n ) as WithReplyGuidance<Record<K, T[]>> &\n WithUiMeta<Record<K, T[]>> &\n WithUiHintField<Record<K, T[]>>;\n}\n\n/** Format a query-style result: shared meta fields + typed row array. */\nexport function formatToolQueryResult<\n M extends Record<string, unknown>,\n T extends Record<string, unknown>,\n>(\n meta: M,\n rows: T[],\n options: FormatToolQueryResultOptions\n): WithReplyGuidance<M & Record<string, T[]>> & WithUiMeta<M & Record<string, T[]>> {\n const rowsPath = options.rowsPath ?? options.ui?.rowsPath ?? \"rows\";\n const ui: ToolResultUiMeta = {\n ...options.ui,\n layout: options.ui?.layout ?? \"list\",\n rowsPath,\n ...(options.entity ? { entity: options.entity } : {}),\n ...(options.present !== undefined ? { present: options.present } : {}),\n };\n\n return withToolUi(\n withReplyGuidance(\n {\n ...meta,\n [rowsPath]: rows,\n } as M & Record<string, T[]>,\n options.replyGuidance\n ),\n ui\n ) as WithReplyGuidance<M & Record<string, T[]>> &\n WithUiMeta<M & Record<string, T[]>>;\n}\n\nexport function isAgentAdminErrorResult(\n result: unknown\n): result is { ok: false; message: string } {\n return (\n typeof result === \"object\" &&\n result !== null &&\n (result as { ok?: unknown }).ok === false &&\n typeof (result as { message?: unknown }).message === \"string\"\n );\n}\n","import { formatToolObjectResult } from \"../../tool-display-format.js\";\nimport { MY_ACCESS_REPLY_GUIDANCE } from \"../../tool-reply-guidance.js\";\n\ntype MyAccessResultInput = {\n tenantSlug: string;\n tenantRole?: string;\n isTenantAdmin: boolean;\n groupSlugs: string[];\n capabilities: {\n manageSettings: boolean;\n manageBilling: boolean;\n manageTeam: boolean;\n manageIntegrations: boolean;\n };\n email?: string;\n};\n\nexport function formatMyAccessResult(input: MyAccessResultInput) {\n return formatToolObjectResult(\n {\n access: {\n workspace: input.tenantSlug,\n role: input.tenantRole ?? \"member\",\n tenantAdmin: input.isTenantAdmin,\n groups: input.groupSlugs.join(\", \") || \"—\",\n manageSettings: input.capabilities.manageSettings,\n manageBilling: input.capabilities.manageBilling,\n manageTeam: input.capabilities.manageTeam,\n manageIntegrations: input.capabilities.manageIntegrations,\n ...(input.email ? { email: input.email } : {}),\n },\n },\n {\n replyGuidance: MY_ACCESS_REPLY_GUIDANCE,\n ui: { entity: \"access\" },\n }\n );\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,SAAS;;;ACDX,SAAS,oBACd,YACA,KACoB;AACpB,QAAM,QAAQ,aAAa,GAAG;AAC9B,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG;AACjD,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,KAAK,KAAK,OAAO,MAAM,CAAC,MAAM,YAAY,MAAM,CAAC,EAAE,SAAS,GAAG;AAC/E,WAAO,MAAM,CAAC;AAAA,EAChB;AACA,SAAO;AACT;AAEO,SAAS,yBACd,YACA,KACU;AACV,QAAM,QAAQ,aAAa,GAAG;AAC9B,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG;AACjD,WAAO,CAAC,KAAK;AAAA,EACf;AACA,MAAI,MAAM,QAAQ,KAAK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C;AAAA,MAC9C;AAAA,IACF;AAAA,IACA;AAAA,MACE,eAAe;AAAA,MACf,IAAI,EAAE,QAAQ,SAAS;AAAA,IACzB;AAAA,EACF;AACF;;;AP3BO,IAAM,sBAAsB;AAE5B,IAAM,sBAAsB,EAAE,OAAO,CAAC,CAAC;AAE9C,SAAS,mBAAmB,SAAkB;AAC5C,SAAO;AAAA,IACL,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,YAAY;AAAA,IACZ,oBAAoB;AAAA,EACtB;AACF;AAEO,SAAS,qBAAqB;AACnC,SAAO,WAAW;AAAA,IAChB,aACE;AAAA,IAIF,aAAa;AAAA,IACb,MAAM,QAAQ,QAAQ,KAAK;AACzB,YAAM,SAAS,uBAAuB,GAAG;AACzC,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,UACL;AAAA,YACE,eAAe;AAAA,YACf,SACE;AAAA,UACJ;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,aAAO,qBAAqB;AAAA,QAC1B,YAAY,OAAO;AAAA,QACnB,YAAY,OAAO;AAAA,QACnB,eAAe,OAAO;AAAA,QACtB,YAAY,OAAO;AAAA,QACnB,cAAc,mBAAmB,OAAO,OAAO;AAAA,QAC/C,OAAO,OAAO;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;AAEO,IAAM,eAAe,mBAAmB;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as eve_tools from 'eve/tools';
|
|
2
2
|
import { T as TenantRole } from '../../../tenant-DmN0MMyC.js';
|
|
3
|
-
import { T as ToolResultWithReplyGuidance } from '../../../tool-reply-guidance-
|
|
3
|
+
import { T as ToolResultWithReplyGuidance } from '../../../tool-reply-guidance-CJko9liH.js';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import 'eve/context';
|
|
6
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/eve/tools/identity/whoami.ts","../../../../src/eve/agent/attributes.ts","../../../../src/eve/agent/tenant.ts","../../../../src/eve/tool-reply-guidance.ts"],"sourcesContent":["import { defineTool } from \"eve/tools\";\nimport { z } from \"zod\";\nimport { tryResolveTenantCaller } from \"../../agent/tenant.js\";\nimport {\n WHOAMI_REPLY_GUIDANCE,\n withReplyGuidance,\n} from \"../../tool-reply-guidance.js\";\n\nexport const WHOAMI_TOOL_NAME = \"whoami\";\n\nexport const whoamiInputSchema = z.object({});\n\nexport function defineWhoamiTool() {\n return defineTool({\n description:\n \"Return the authenticated RobotRock user, tenant, role, and group memberships for the current chat session. \" +\n \"The dashboard renders a profile card — do not repeat name, email, workspace, role, or groups in your reply; only add context not shown in the card.\",\n inputSchema: whoamiInputSchema,\n async execute(_input, ctx) {\n const caller = tryResolveTenantCaller(ctx);\n if (!caller) {\n return withReplyGuidance(\n {\n authenticated: false as const,\n message:\n \"No RobotRock user is attached to this session. Dashboard chat supplies user context via the Eve proxy.\",\n },\n \"Explain that no user is attached to this session. Do not invent identity details.\"\n );\n }\n\n return withReplyGuidance(\n {\n authenticated: true as const,\n userId: caller.userId,\n name: caller.name,\n email: caller.email,\n tenantSlug: caller.tenantSlug,\n role: caller.role,\n isAdmin: caller.isAdmin,\n groups: caller.groups.map((slug) => ({ slug })),\n ...(caller.workosUserId ? { workosUserId: caller.workosUserId } : {}),\n sessionId: ctx.session.id,\n },\n WHOAMI_REPLY_GUIDANCE\n );\n },\n });\n}\n\nexport const whoamiTool = defineWhoamiTool();\n","export function readStringAttribute(\n attributes: Readonly<Record<string, string | readonly string[]>> | undefined,\n key: string\n): string | undefined {\n const value = attributes?.[key];\n if (typeof value === \"string\" && value.length > 0) {\n return value;\n }\n if (Array.isArray(value) && typeof value[0] === \"string\" && value[0].length > 0) {\n return value[0];\n }\n return undefined;\n}\n\nexport function readStringArrayAttribute(\n attributes: Readonly<Record<string, string | readonly string[]>> | undefined,\n key: string\n): string[] {\n const value = attributes?.[key];\n if (typeof value === \"string\" && value.length > 0) {\n return [value];\n }\n if (Array.isArray(value)) {\n return value.filter(\n (entry): entry is string => typeof entry === \"string\" && entry.length > 0\n );\n }\n return [];\n}\n\nexport function parseTenantRole(\n value: string | undefined\n): \"admin\" | \"member\" | null {\n if (value === \"admin\" || value === \"member\") {\n return value;\n }\n return null;\n}\n","import type { SessionContext } from \"eve/context\";\nimport {\n parseTenantRole,\n readStringArrayAttribute,\n readStringAttribute,\n} from \"./attributes.js\";\n\nexport type TenantRole = \"admin\" | \"member\";\n\nexport type TenantCaller = {\n userId: string;\n email: string;\n name: string;\n tenantSlug: string;\n connectionId?: string;\n chatId?: string;\n role: TenantRole;\n isAdmin: boolean;\n groups: string[];\n workosUserId?: string;\n};\n\n/** Resolve the authenticated RobotRock dashboard user for the current session. */\nexport function tryResolveTenantCaller(ctx: SessionContext): TenantCaller | null {\n const caller = ctx.session.auth.initiator ?? ctx.session.auth.current;\n if (caller?.principalType !== \"user\") {\n return null;\n }\n\n const email = readStringAttribute(caller.attributes, \"email\");\n const name = readStringAttribute(caller.attributes, \"name\");\n const tenantSlug =\n readStringAttribute(caller.attributes, \"tenantSlug\") ??\n readStringAttribute(caller.attributes, \"tenantId\");\n const role = parseTenantRole(readStringAttribute(caller.attributes, \"role\"));\n if (!email || !tenantSlug || !caller.principalId || !role) {\n return null;\n }\n\n const workosUserId = readStringAttribute(caller.attributes, \"workosUserId\");\n const connectionId = readStringAttribute(caller.attributes, \"connectionId\");\n const chatId = readStringAttribute(caller.attributes, \"chatId\");\n const groups = readStringArrayAttribute(caller.attributes, \"groups\");\n\n return {\n userId: caller.principalId,\n email,\n name: name ?? email.split(\"@\")[0] ?? email,\n tenantSlug,\n ...(connectionId ? { connectionId } : {}),\n ...(chatId ? { chatId } : {}),\n role,\n isAdmin: role === \"admin\",\n groups,\n ...(workosUserId ? { workosUserId } : {}),\n };\n}\n\n/** Like {@link tryResolveTenantCaller} but throws when the session has no user. */\nexport function requireTenantCaller(ctx: SessionContext): TenantCaller {\n const caller = tryResolveTenantCaller(ctx);\n if (!caller) {\n throw new Error(\"An authenticated RobotRock tenant user is required.\");\n }\n return caller;\n}\n\nexport function isAdminCaller(ctx: SessionContext): boolean {\n return tryResolveTenantCaller(ctx)?.isAdmin === true;\n}\n\n/** Require an authenticated tenant admin for the current session. */\nexport function requireAdminCaller(ctx: SessionContext): TenantCaller {\n const caller = requireTenantCaller(ctx);\n if (!caller.isAdmin) {\n throw new Error(\"Tenant admin access is required.\");\n }\n return caller;\n}\n","import { TOOL_UI_HINT_FIELD } from \"./tool-ui-hint.js\";\n\n/** Field name agents read; dashboard widgets must ignore when rendering. */\nexport const TOOL_REPLY_GUIDANCE_FIELD = \"replyGuidance\" as const;\n\nexport const WHOAMI_REPLY_GUIDANCE =\n \"The dashboard shows a profile card with name, email, workspace, role, and groups. Do not restate those in your reply. Only add context not in the card (e.g. permissions, refund approval rules, missing group membership).\";\n\nexport const MY_ACCESS_REPLY_GUIDANCE =\n \"Access details may render in chat UI. Do not restate role, groups, or admin capabilities if already visible. Only explain what the user can or cannot do for their question (e.g. finance group required for refunds ≥ $10,000). When access.tenantAdmin is false and the user needs manageTeam, manageGroups, or query-tasks capabilities, explain briefly then call ask_question to offer sending an admin request to tenant admins — do not tell them to find an admin manually without offering delegation first.\";\n\nexport const CREATE_INBOX_TASK_REPLY_GUIDANCE =\n \"A task card shows title, assignee, and inbox status in chat. Do not restate task ID, assignee, or delegation details from the card. Only mention next steps or answer the user's question.\";\n\nexport const SEARCH_PRODUCTS_REPLY_GUIDANCE =\n \"Product results render as a list card in chat. Do not restate product names, prices, or SKUs. Only add context not in the list (e.g. no matches, recommendations).\";\n\nexport const MANAGE_TEAM_MEMBERS_LIST_REPLY_GUIDANCE =\n \"Team members render as a list card in chat. Do not restate names, emails, or roles from the list. Only add context not shown (e.g. duplicates, next admin actions).\";\n\nexport const MANAGE_TEAM_MEMBERS_DETAIL_REPLY_GUIDANCE =\n \"Team member details render in chat UI. Do not restate name, email, or role from the card. Only add next steps or policy context.\";\n\nexport const MANAGE_GROUPS_LIST_REPLY_GUIDANCE =\n \"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.\";\n\nexport const MANAGE_GROUPS_DETAIL_REPLY_GUIDANCE =\n \"Group details render in chat UI. Do not restate fields already visible in the card. Only add next steps.\";\n\nexport const QUERY_TASKS_LIST_REPLY_GUIDANCE =\n \"Tasks render as a list card in chat. Do not restate task names, ids, or statuses from the list. Only add context not shown (e.g. filters applied, recommended next action).\";\n\nexport const QUERY_TASKS_DETAIL_REPLY_GUIDANCE =\n \"Task details render in chat UI. Do not restate fields already visible in the card. Only add analysis or next steps.\";\n\nexport const ASSIGN_TASKS_REPLY_GUIDANCE =\n \"Reassignment results render in chat UI. Do not restate task ids or assignee emails from the card. Only mention failures, partial success, or next steps.\";\n\nexport const REFUND_CHARGE_REPLY_GUIDANCE =\n \"Refund details render in chat UI. Do not restate charge id, amount, or status from the card. Only add policy context or next steps.\";\n\nexport const DEPLOY_RELEASE_REPLY_GUIDANCE =\n \"Deploy details render in chat UI. Do not restate service, version, or environment from the card. Only add rollout context or next steps.\";\n\nexport const GET_WEATHER_REPLY_GUIDANCE =\n \"Weather details render in chat UI. Do not restate city, condition, or temperature from the card. Only add conversational context if needed.\";\n\nexport const ADMIN_MUTATION_REPLY_GUIDANCE =\n \"The action result renders in chat UI. Do not restate fields already visible in the card. Confirm outcome briefly or add next steps only.\";\n\nexport type ToolResultWithReplyGuidance<T extends Record<string, unknown>> = T & {\n replyGuidance: string;\n};\n\n/** Attach model-facing narration hints to a tool execute result. */\nexport function withReplyGuidance<T extends Record<string, unknown>>(\n result: T,\n guidance: string\n): ToolResultWithReplyGuidance<T> {\n return {\n ...result,\n [TOOL_REPLY_GUIDANCE_FIELD]: guidance,\n };\n}\n\n/** Remove agent-only fields before showing raw JSON in the dashboard. */\nexport function stripAgentOnlyToolFields(output: unknown): unknown {\n if (typeof output !== \"object\" || output === null || Array.isArray(output)) {\n return output;\n }\n\n const record = { ...(output as Record<string, unknown>) };\n delete record[TOOL_REPLY_GUIDANCE_FIELD];\n delete record[TOOL_UI_HINT_FIELD];\n return record;\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,SAAS;;;ACDX,SAAS,oBACd,YACA,KACoB;AACpB,QAAM,QAAQ,aAAa,GAAG;AAC9B,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG;AACjD,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,KAAK,KAAK,OAAO,MAAM,CAAC,MAAM,YAAY,MAAM,CAAC,EAAE,SAAS,GAAG;AAC/E,WAAO,MAAM,CAAC;AAAA,EAChB;AACA,SAAO;AACT;AAEO,SAAS,yBACd,YACA,KACU;AACV,QAAM,QAAQ,aAAa,GAAG;AAC9B,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG;AACjD,WAAO,CAAC,KAAK;AAAA,EACf;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM;AAAA,MACX,CAAC,UAA2B,OAAO,UAAU,YAAY,MAAM,SAAS;AAAA,IAC1E;AAAA,EACF;AACA,SAAO,CAAC;AACV;AAEO,SAAS,gBACd,OAC2B;AAC3B,MAAI,UAAU,WAAW,UAAU,UAAU;AAC3C,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACdO,SAAS,uBAAuB,KAA0C;AAC/E,QAAM,SAAS,IAAI,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK;AAC9D,MAAI,QAAQ,kBAAkB,QAAQ;AACpC,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,oBAAoB,OAAO,YAAY,OAAO;AAC5D,QAAM,OAAO,oBAAoB,OAAO,YAAY,MAAM;AAC1D,QAAM,aACJ,oBAAoB,OAAO,YAAY,YAAY,KACnD,oBAAoB,OAAO,YAAY,UAAU;AACnD,QAAM,OAAO,gBAAgB,oBAAoB,OAAO,YAAY,MAAM,CAAC;AAC3E,MAAI,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AAAA,UACb,SAAS,OAAO;AAAA,UAChB,QAAQ,OAAO,OAAO,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AAAA,UAC9C,GAAI,OAAO,eAAe,EAAE,cAAc,OAAO,aAAa,IAAI,CAAC;AAAA,UACnE,WAAW,IAAI,QAAQ;AAAA,QACzB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,IAAM,aAAa,iBAAiB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/eve/tools/identity/whoami.ts","../../../../src/eve/agent/attributes.ts","../../../../src/eve/agent/tenant.ts","../../../../src/eve/tool-reply-guidance.ts"],"sourcesContent":["import { defineTool } from \"eve/tools\";\nimport { z } from \"zod\";\nimport { tryResolveTenantCaller } from \"../../agent/tenant.js\";\nimport {\n WHOAMI_REPLY_GUIDANCE,\n withReplyGuidance,\n} from \"../../tool-reply-guidance.js\";\n\nexport const WHOAMI_TOOL_NAME = \"whoami\";\n\nexport const whoamiInputSchema = z.object({});\n\nexport function defineWhoamiTool() {\n return defineTool({\n description:\n \"Return the authenticated RobotRock user, tenant, role, and group memberships for the current chat session. \" +\n \"The dashboard renders a profile card — do not repeat name, email, workspace, role, or groups in your reply; only add context not shown in the card.\",\n inputSchema: whoamiInputSchema,\n async execute(_input, ctx) {\n const caller = tryResolveTenantCaller(ctx);\n if (!caller) {\n return withReplyGuidance(\n {\n authenticated: false as const,\n message:\n \"No RobotRock user is attached to this session. Dashboard chat supplies user context via the Eve proxy.\",\n },\n \"Explain that no user is attached to this session. Do not invent identity details.\"\n );\n }\n\n return withReplyGuidance(\n {\n authenticated: true as const,\n userId: caller.userId,\n name: caller.name,\n email: caller.email,\n tenantSlug: caller.tenantSlug,\n role: caller.role,\n isAdmin: caller.isAdmin,\n groups: caller.groups.map((slug) => ({ slug })),\n ...(caller.workosUserId ? { workosUserId: caller.workosUserId } : {}),\n sessionId: ctx.session.id,\n },\n WHOAMI_REPLY_GUIDANCE\n );\n },\n });\n}\n\nexport const whoamiTool = defineWhoamiTool();\n","export function readStringAttribute(\n attributes: Readonly<Record<string, string | readonly string[]>> | undefined,\n key: string\n): string | undefined {\n const value = attributes?.[key];\n if (typeof value === \"string\" && value.length > 0) {\n return value;\n }\n if (Array.isArray(value) && typeof value[0] === \"string\" && value[0].length > 0) {\n return value[0];\n }\n return undefined;\n}\n\nexport function readStringArrayAttribute(\n attributes: Readonly<Record<string, string | readonly string[]>> | undefined,\n key: string\n): string[] {\n const value = attributes?.[key];\n if (typeof value === \"string\" && value.length > 0) {\n return [value];\n }\n if (Array.isArray(value)) {\n return value.filter(\n (entry): entry is string => typeof entry === \"string\" && entry.length > 0\n );\n }\n return [];\n}\n\nexport function parseTenantRole(\n value: string | undefined\n): \"admin\" | \"member\" | null {\n if (value === \"admin\" || value === \"member\") {\n return value;\n }\n return null;\n}\n","import type { SessionContext } from \"eve/context\";\nimport {\n parseTenantRole,\n readStringArrayAttribute,\n readStringAttribute,\n} from \"./attributes.js\";\n\nexport type TenantRole = \"admin\" | \"member\";\n\nexport type TenantCaller = {\n userId: string;\n email: string;\n name: string;\n tenantSlug: string;\n connectionId?: string;\n chatId?: string;\n role: TenantRole;\n isAdmin: boolean;\n groups: string[];\n workosUserId?: string;\n};\n\n/** Resolve the authenticated RobotRock dashboard user for the current session. */\nexport function tryResolveTenantCaller(ctx: SessionContext): TenantCaller | null {\n const caller = ctx.session.auth.initiator ?? ctx.session.auth.current;\n if (caller?.principalType !== \"user\") {\n return null;\n }\n\n const email = readStringAttribute(caller.attributes, \"email\");\n const name = readStringAttribute(caller.attributes, \"name\");\n const tenantSlug =\n readStringAttribute(caller.attributes, \"tenantSlug\") ??\n readStringAttribute(caller.attributes, \"tenantId\");\n const role = parseTenantRole(readStringAttribute(caller.attributes, \"role\"));\n if (!email || !tenantSlug || !caller.principalId || !role) {\n return null;\n }\n\n const workosUserId = readStringAttribute(caller.attributes, \"workosUserId\");\n const connectionId = readStringAttribute(caller.attributes, \"connectionId\");\n const chatId = readStringAttribute(caller.attributes, \"chatId\");\n const groups = readStringArrayAttribute(caller.attributes, \"groups\");\n\n return {\n userId: caller.principalId,\n email,\n name: name ?? email.split(\"@\")[0] ?? email,\n tenantSlug,\n ...(connectionId ? { connectionId } : {}),\n ...(chatId ? { chatId } : {}),\n role,\n isAdmin: role === \"admin\",\n groups,\n ...(workosUserId ? { workosUserId } : {}),\n };\n}\n\n/** Like {@link tryResolveTenantCaller} but throws when the session has no user. */\nexport function requireTenantCaller(ctx: SessionContext): TenantCaller {\n const caller = tryResolveTenantCaller(ctx);\n if (!caller) {\n throw new Error(\"An authenticated RobotRock tenant user is required.\");\n }\n return caller;\n}\n\nexport function isAdminCaller(ctx: SessionContext): boolean {\n return tryResolveTenantCaller(ctx)?.isAdmin === true;\n}\n\n/** Require an authenticated tenant admin for the current session. */\nexport function requireAdminCaller(ctx: SessionContext): TenantCaller {\n const caller = requireTenantCaller(ctx);\n if (!caller.isAdmin) {\n throw new Error(\"Tenant admin access is required.\");\n }\n return caller;\n}\n","import { TOOL_UI_FIELD } from \"./tool-result-ui-meta.js\";\nimport { TOOL_UI_HINT_FIELD } from \"./tool-ui-hint.js\";\n\n/** Field name agents read; dashboard widgets must ignore when rendering. */\nexport const TOOL_REPLY_GUIDANCE_FIELD = \"replyGuidance\" as const;\n\nexport const WHOAMI_REPLY_GUIDANCE =\n \"The dashboard shows a profile card with name, email, workspace, role, and groups. Do not restate those in your reply. Only add context not in the card (e.g. permissions, refund approval rules, missing group membership).\";\n\nexport const MY_ACCESS_REPLY_GUIDANCE =\n \"Access details may render in chat UI. Do not restate role, groups, or admin capabilities if already visible. Only explain what the user can or cannot do for their question (e.g. finance group required for refunds ≥ $10,000). When access.tenantAdmin is false and the user needs manageTeam, manageGroups, query-tasks, or workspace-usage capabilities, explain briefly then call ask_question to offer sending an admin request to tenant admins — do not tell them to find an admin manually without offering delegation first.\";\n\nexport const GET_WORKSPACE_USAGE_REPLY_GUIDANCE =\n \"Workspace plan and usage render as a card in chat. Do not restate plan name, task counts, seats, groups, API keys, or rate limits from the card. Only add context not shown (e.g. upgrade options, that LLM token/cost meters are not tracked, or next steps). Never invent token or dollar spend numbers.\";\n\nexport const CREATE_INBOX_TASK_REPLY_GUIDANCE =\n \"A task card shows title, assignee, and inbox status in chat. Do not restate task ID, assignee, or delegation details from the card. Only mention next steps or answer the user's question.\";\n\nexport const SEARCH_PRODUCTS_REPLY_GUIDANCE =\n \"Product results render as a list card in chat. Do not restate product names, prices, or SKUs. Only add context not in the list (e.g. no matches, recommendations).\";\n\nexport const GENERATE_RANDOM_CHART_REPLY_GUIDANCE =\n \"Chart metrics render as a chart card in chat. Do not restate series values, dates, or categories from the chart. Only add brief context (e.g. that this is demo data).\";\n\nexport const GENERATE_IMAGE_REPLY_GUIDANCE =\n \"The generated image renders in chat UI. Do not describe the image pixels or restate the prompt. Only add a short acknowledgement or next-step question if useful.\";\n\nexport const MANAGE_TEAM_MEMBERS_LIST_REPLY_GUIDANCE =\n \"Team members render as a list card in chat. Do not restate names, emails, or roles from the list. Only add context not shown (e.g. duplicates, next admin actions).\";\n\nexport const MANAGE_TEAM_MEMBERS_DETAIL_REPLY_GUIDANCE =\n \"Team member details render in chat UI. Do not restate name, email, or role from the card. Only add next steps or policy context.\";\n\nexport const MANAGE_GROUPS_LIST_REPLY_GUIDANCE =\n \"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.\";\n\nexport const MANAGE_GROUPS_DETAIL_REPLY_GUIDANCE =\n \"Group details render in chat UI. Do not restate fields already visible in the card. Only add next steps.\";\n\nexport const QUERY_TASKS_LIST_REPLY_GUIDANCE =\n \"Tasks render as a list card in chat. Do not restate task names, ids, or statuses from the list. Only add context not shown (e.g. filters applied, recommended next action).\";\n\nexport const QUERY_TASKS_DETAIL_REPLY_GUIDANCE =\n \"Task details render in chat UI. Do not restate fields already visible in the card. Only add analysis or next steps.\";\n\nexport const ASSIGN_TASKS_REPLY_GUIDANCE =\n \"Reassignment results render in chat UI. Do not restate task ids or assignee emails from the card. Only mention failures, partial success, or next steps.\";\n\nexport const REFUND_CHARGE_REPLY_GUIDANCE =\n \"Refund details render in chat UI. Do not restate charge id, amount, or status from the card. Only add policy context or next steps.\";\n\nexport const DEPLOY_RELEASE_REPLY_GUIDANCE =\n \"Deploy details render in chat UI. Do not restate service, version, or environment from the card. Only add rollout context or next steps.\";\n\nexport const GET_WEATHER_REPLY_GUIDANCE =\n \"Weather details render in chat UI. Do not restate city, condition, or temperature from the card. Only add conversational context if needed.\";\n\nexport const ADMIN_MUTATION_REPLY_GUIDANCE =\n \"The action result renders in chat UI. Do not restate fields already visible in the card. Confirm outcome briefly or add next steps only.\";\n\nexport type ToolResultWithReplyGuidance<T extends Record<string, unknown>> = T & {\n replyGuidance: string;\n};\n\n/** Attach model-facing narration hints to a tool execute result. */\nexport function withReplyGuidance<T extends Record<string, unknown>>(\n result: T,\n guidance: string\n): ToolResultWithReplyGuidance<T> {\n return {\n ...result,\n [TOOL_REPLY_GUIDANCE_FIELD]: guidance,\n };\n}\n\n/** Remove agent-only fields before showing raw JSON in the dashboard. */\nexport function stripAgentOnlyToolFields(output: unknown): unknown {\n if (typeof output !== \"object\" || output === null || Array.isArray(output)) {\n return output;\n }\n\n const record = { ...(output as Record<string, unknown>) };\n delete record[TOOL_REPLY_GUIDANCE_FIELD];\n delete record[TOOL_UI_HINT_FIELD];\n delete record[TOOL_UI_FIELD];\n return record;\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,SAAS;;;ACDX,SAAS,oBACd,YACA,KACoB;AACpB,QAAM,QAAQ,aAAa,GAAG;AAC9B,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG;AACjD,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,KAAK,KAAK,OAAO,MAAM,CAAC,MAAM,YAAY,MAAM,CAAC,EAAE,SAAS,GAAG;AAC/E,WAAO,MAAM,C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AE,aAAa,IAAI,CAAC;AAAA,IACvC,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;AAAA,IAC3B;AAAA,IACA,SAAS,SAAS;AAAA,IAClB;AAAA,IACA,GAAI,eAAe,EAAE,aAAa,IAAI,CAAC;AAAA,EACzC;AACF;;;ACpDO,IAAM,4BAA4B;AAElC,IAAM,wBACX;AA0DK,SAAS,kBACd,QACA,UACgC;AAChC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,CAAC,yBAAyB,GAAG;AAAA,EAC/B;AACF;;;AHjEO,IAAM,mBAAmB;AAEzB,IAAM,oBAAoB,EAAE,OAAO,CAAC,CAAC;AAErC,SAAS,mBAAmB;AACjC,SAAO,WAAW;AAAA,IAChB,aACE;AAAA,IAEF,aAAa;AAAA,IACb,MAAM,QAAQ,QAAQ,KAAK;AACzB,YAAM,SAAS,uBAAuB,GAAG;AACzC,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,UACL;AAAA,YACE,eAAe;AAAA,YACf,SACE;AAAA,UACJ;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,QACL;AAAA,UACE,eAAe;AAAA,UACf,QAAQ,OAAO;AAAA,UACf,MAAM,OAAO;AAAA,UACb,OAAO,OAAO;AAAA,UACd,YAAY,OAAO;AAAA,UACnB,MAAM,OAAO;AAAA,UACb,SAAS,OAAO;AAAA,UAChB,QAAQ,OAAO,OAAO,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AAAA,UAC9C,GAAI,OAAO,eAAe,EAAE,cAAc,OAAO,aAAa,IAAI,CAAC;AAAA,UACnE,WAAW,IAAI,QAAQ;AAAA,QACzB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,IAAM,aAAa,iBAAiB;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as eve_tools from 'eve/tools';
|
|
2
|
-
import { T as ToolResultWithReplyGuidance } from '../../../tool-reply-guidance-
|
|
2
|
+
import { T as ToolResultWithReplyGuidance } from '../../../tool-reply-guidance-CJko9liH.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { a as TenantCaller } from '../../../tenant-DmN0MMyC.js';
|
|
5
5
|
import 'eve/context';
|
|
@@ -449,6 +449,40 @@ var agentChatLinkTaskBodySchema = z.object({
|
|
|
449
449
|
publicTaskId: z.string().min(1),
|
|
450
450
|
toolCallId: z.string().min(1)
|
|
451
451
|
});
|
|
452
|
+
var AGENT_FILE_TAGS_MAX = 20;
|
|
453
|
+
var AGENT_FILE_TAG_MAX_LENGTH = 64;
|
|
454
|
+
function normalizeAgentFileTags(tags) {
|
|
455
|
+
if (!tags?.length) return void 0;
|
|
456
|
+
const seen = /* @__PURE__ */ new Set();
|
|
457
|
+
const out = [];
|
|
458
|
+
for (const raw of tags) {
|
|
459
|
+
const tag = raw.trim().toLowerCase().slice(0, AGENT_FILE_TAG_MAX_LENGTH);
|
|
460
|
+
if (!tag || seen.has(tag)) continue;
|
|
461
|
+
seen.add(tag);
|
|
462
|
+
out.push(tag);
|
|
463
|
+
if (out.length >= AGENT_FILE_TAGS_MAX) break;
|
|
464
|
+
}
|
|
465
|
+
return out.length > 0 ? out : void 0;
|
|
466
|
+
}
|
|
467
|
+
var agentChatUploadImageBodySchema = z.object({
|
|
468
|
+
mediaType: z.string().min(1),
|
|
469
|
+
/** Raw base64 (no data: URL prefix). */
|
|
470
|
+
base64: z.string().min(1),
|
|
471
|
+
chatId: z.string().min(1).optional(),
|
|
472
|
+
publicTaskId: z.string().min(1).optional(),
|
|
473
|
+
source: z.string().min(1).optional(),
|
|
474
|
+
/** Display / search name (e.g. `sunset-robot.png`). */
|
|
475
|
+
filename: z.string().min(1).max(255).optional(),
|
|
476
|
+
/** Human-readable description (e.g. generation prompt). */
|
|
477
|
+
description: z.string().min(1).max(2e3).optional(),
|
|
478
|
+
/**
|
|
479
|
+
* Optional labels for later grouping/filtering.
|
|
480
|
+
* Normalized to lowercase trimmed unique strings (max 20, 64 chars each).
|
|
481
|
+
*/
|
|
482
|
+
tags: z.array(z.string().min(1).max(AGENT_FILE_TAG_MAX_LENGTH)).max(AGENT_FILE_TAGS_MAX).optional().transform((tags) => normalizeAgentFileTags(tags))
|
|
483
|
+
}).refine((data) => Boolean(data.chatId || data.publicTaskId), {
|
|
484
|
+
message: "Provide chatId and/or publicTaskId"
|
|
485
|
+
});
|
|
452
486
|
|
|
453
487
|
// ../core/src/schemas/tool-result-display.ts
|
|
454
488
|
import { z as z2 } from "zod";
|
|
@@ -477,7 +511,8 @@ var tenantRoleSchema = z3.enum(["admin", "member"]);
|
|
|
477
511
|
var agentAdminUserSchema = z3.object({
|
|
478
512
|
id: z3.string(),
|
|
479
513
|
email: z3.string().email(),
|
|
480
|
-
name: z3.string()
|
|
514
|
+
name: z3.string(),
|
|
515
|
+
profilePictureUrl: z3.string().nullable().optional()
|
|
481
516
|
});
|
|
482
517
|
var agentAdminMemberSchema = z3.object({
|
|
483
518
|
userId: z3.string(),
|
|
@@ -562,6 +597,37 @@ var assignTasksBodySchema = z3.object({
|
|
|
562
597
|
{ message: "assignTo needs at least one user email or group slug." }
|
|
563
598
|
)
|
|
564
599
|
});
|
|
600
|
+
var agentAdminPlanLimitsSchema = z3.object({
|
|
601
|
+
tasksPerDay: z3.number(),
|
|
602
|
+
members: z3.number(),
|
|
603
|
+
apiKeys: z3.number(),
|
|
604
|
+
groups: z3.number(),
|
|
605
|
+
auditLogRetention: z3.number(),
|
|
606
|
+
rateLimitPerSecond: z3.number(),
|
|
607
|
+
taskRetentionDays: z3.number()
|
|
608
|
+
});
|
|
609
|
+
var agentAdminUsageSchema = z3.object({
|
|
610
|
+
workspace: z3.string(),
|
|
611
|
+
planName: z3.string(),
|
|
612
|
+
planType: z3.string(),
|
|
613
|
+
trialState: z3.enum(["none", "active", "expired"]),
|
|
614
|
+
daysRemaining: z3.number().nullable(),
|
|
615
|
+
isPaidPro: z3.boolean(),
|
|
616
|
+
subscriptionStatus: z3.string().nullable(),
|
|
617
|
+
tasksToday: z3.number(),
|
|
618
|
+
maxTasksPerDay: z3.number().nullable(),
|
|
619
|
+
tasksResetAt: z3.number(),
|
|
620
|
+
openTasks: z3.number(),
|
|
621
|
+
totalTasks: z3.number(),
|
|
622
|
+
seatsCurrent: z3.number(),
|
|
623
|
+
seatsMax: z3.number().nullable(),
|
|
624
|
+
groupsCurrent: z3.number(),
|
|
625
|
+
groupsMax: z3.number().nullable(),
|
|
626
|
+
apiKeysCurrent: z3.number(),
|
|
627
|
+
apiKeysMax: z3.number().nullable(),
|
|
628
|
+
rateLimitPerSecond: z3.number(),
|
|
629
|
+
limits: agentAdminPlanLimitsSchema
|
|
630
|
+
});
|
|
565
631
|
|
|
566
632
|
// src/schemas/index.ts
|
|
567
633
|
var handlerUrlSchema2 = z4.string().refine((url) => isAllowedHandlerUrl(url), {
|
|
@@ -865,7 +931,11 @@ function resolveRobotRockAuthConfig(overrides) {
|
|
|
865
931
|
"RobotRock auth is required. Set ROBOTROCK_API_KEY, ROBOTROCK_AGENT_SERVICE_TOKEN with tenant context, or pass auth when creating the client."
|
|
866
932
|
);
|
|
867
933
|
}
|
|
868
|
-
return {
|
|
934
|
+
return {
|
|
935
|
+
kind: "apiKey",
|
|
936
|
+
apiKey,
|
|
937
|
+
...overrides?.actingUserId?.trim() ? { actingUserId: overrides.actingUserId.trim() } : {}
|
|
938
|
+
};
|
|
869
939
|
}
|
|
870
940
|
|
|
871
941
|
// src/chat-correlation.ts
|
|
@@ -1070,6 +1140,51 @@ function createChatsApi(config) {
|
|
|
1070
1140
|
data
|
|
1071
1141
|
);
|
|
1072
1142
|
}
|
|
1143
|
+
},
|
|
1144
|
+
async uploadImage(input) {
|
|
1145
|
+
const validation = agentChatUploadImageBodySchema.safeParse(input);
|
|
1146
|
+
if (!validation.success) {
|
|
1147
|
+
throw new RobotRockError(
|
|
1148
|
+
`Invalid image upload: ${validation.error.issues[0]?.message}`,
|
|
1149
|
+
400,
|
|
1150
|
+
validation.error.issues
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1153
|
+
const response = await fetch(`${config.baseUrl}/agent-chats/images`, {
|
|
1154
|
+
method: "POST",
|
|
1155
|
+
headers: headers(),
|
|
1156
|
+
body: JSON.stringify(validation.data)
|
|
1157
|
+
});
|
|
1158
|
+
const data = await parseResponseBody(response);
|
|
1159
|
+
if (!response.ok) {
|
|
1160
|
+
throw new RobotRockError(
|
|
1161
|
+
getErrorMessage(data, "Failed to upload chat image"),
|
|
1162
|
+
response.status,
|
|
1163
|
+
data
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
const uploaded = data;
|
|
1167
|
+
if (typeof uploaded.storageId !== "string" || typeof uploaded.url !== "string" || typeof uploaded.mediaType !== "string") {
|
|
1168
|
+
throw new RobotRockError(
|
|
1169
|
+
"Image upload returned an invalid response",
|
|
1170
|
+
500,
|
|
1171
|
+
data
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
return {
|
|
1175
|
+
storageId: uploaded.storageId,
|
|
1176
|
+
url: uploaded.url,
|
|
1177
|
+
mediaType: uploaded.mediaType,
|
|
1178
|
+
...typeof uploaded.chatId === "string" ? { chatId: uploaded.chatId } : {},
|
|
1179
|
+
...typeof uploaded.publicTaskId === "string" ? { publicTaskId: uploaded.publicTaskId } : {},
|
|
1180
|
+
...typeof uploaded.filename === "string" ? { filename: uploaded.filename } : {},
|
|
1181
|
+
...typeof uploaded.description === "string" ? { description: uploaded.description } : {},
|
|
1182
|
+
...Array.isArray(uploaded.tags) ? {
|
|
1183
|
+
tags: uploaded.tags.filter(
|
|
1184
|
+
(tag) => typeof tag === "string"
|
|
1185
|
+
)
|
|
1186
|
+
} : {}
|
|
1187
|
+
};
|
|
1073
1188
|
}
|
|
1074
1189
|
};
|
|
1075
1190
|
}
|
|
@@ -1139,6 +1254,7 @@ var RobotRock = class {
|
|
|
1139
1254
|
}
|
|
1140
1255
|
this.auth = resolveRobotRockAuthConfig({
|
|
1141
1256
|
...apiKey ? { apiKey } : {},
|
|
1257
|
+
...config.actingUserId ? { actingUserId: config.actingUserId } : {},
|
|
1142
1258
|
...agentService ? { agentService } : {}
|
|
1143
1259
|
});
|
|
1144
1260
|
this.chatCorrelation = config.chatCorrelation;
|
|
@@ -1536,6 +1652,7 @@ function tryCreateBoundRobotRockClient(ctx) {
|
|
|
1536
1652
|
if (apiKey) {
|
|
1537
1653
|
return createClient({
|
|
1538
1654
|
apiKey,
|
|
1655
|
+
...caller?.userId ? { actingUserId: caller.userId } : {},
|
|
1539
1656
|
baseUrl: process.env.ROBOTROCK_BASE_URL?.trim(),
|
|
1540
1657
|
chatCorrelation
|
|
1541
1658
|
});
|