@sentry/junior 0.315.0 → 0.317.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/dist/{admin-5jUYY46p.js → admin-CAugg87B.js} +1 -1
- package/dist/{agent-runner-C7GNLRB6.js → agent-runner-AjrEV6Qe.js} +13532 -12811
- package/dist/{reporting-window-C4dbzDiR.js → agent-status-BA5x3Xtp.js} +33 -1
- package/dist/{agent-update-delivery-BNEYQsAf.js → agent-update-delivery-B_YIZcgf.js} +10 -37
- package/dist/api/schema.d.ts +609 -104
- package/dist/api/schema.js +6 -6
- package/dist/api.js +373 -469
- package/dist/{app-D_bAXRDe.d.ts → app-MoNAsVV5.d.ts} +52 -28
- package/dist/app.d.ts +1 -1
- package/dist/app.js +177 -132
- package/dist/catalog-runtime-DfSpJZdY.js +6 -0
- package/dist/{change-record-Bqsa5ZXE.d.ts → change-record-BzJgLsv7.d.ts} +60 -1
- package/dist/{adapter-context-BlSGE44V.js → channel-access-j-YAVYK4.js} +2 -42
- package/dist/{chat-core-engine-CxkwRpn9.js → chat-core-engine-aH85nEHv.js} +4 -3
- package/dist/{child-message--2G3Ft26.js → child-message-DHjQLEd1.js} +1 -1
- package/dist/cli/chat.js +23 -23
- package/dist/cli/check.js +5 -5
- package/dist/cli/main.js +2 -2
- package/dist/cli/plugins.js +5 -4
- package/dist/cli/snapshot-create.js +5 -2
- package/dist/cli/upgrade.js +27 -5
- package/dist/config-CHQ8X251.js +2422 -0
- package/dist/{continue-in-slack-BGKjIdFp.js → continue-in-slack-D-FZ8Fin.js} +2 -3
- package/dist/{conversation-feed-Sl8lKKmR.js → conversation-feed--9S0_PXL.js} +9 -4
- package/dist/{proxy-path-Dc-0jXGi.js → conversation-privacy-B1uXn5sf.js} +2 -16
- package/dist/{conversation-turn-BoLK9i6g.js → conversation-turn-BUE_7xaN.js} +102 -172
- package/dist/{create-BOycVH9h.js → create-DoDIYgtZ.js} +12 -10
- package/dist/{credential-sync-Mn4OdkEh.js → credential-sync-BJOqGnjV.js} +17 -12
- package/dist/{db-DXTOYRzR.js → db-BFmyYZtJ.js} +20276 -27398
- package/dist/{deployment-CG3TchWh.js → deployment-DXq9ZLU4.js} +17 -15
- package/dist/{engine-context-dyWlfNdD.js → engine-context-CgQ7mlHt.js} +264 -50
- package/dist/{html-CfXEwl_h.js → html-B3VKTGbJ.js} +6 -2
- package/dist/instrumentation.js +15 -7
- package/dist/{job-runner-CySgpi9v.js → job-runner-A1lCkybD.js} +397 -22
- package/dist/{lineage-tRTOcrsL.js → lineage-Bktb0UcV.js} +1 -1
- package/dist/{list-DXBz8SYL.js → list-Bxvg5wXf.js} +260 -698
- package/dist/{logging-czs0nqLC.js → logging--smS7XRK.js} +2 -2
- package/dist/{mailbox-turn-79Nv1JXv.js → mailbox-turn-uSXhUFc9.js} +648 -2957
- package/dist/{message-BTox2Cmb.js → message-BNenhsmB.js} +12 -22
- package/dist/{model-input-IRGa98V7.js → model-input-BReSnwHp.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +20 -6
- package/dist/{oauth-callback-server-NXK7AlBp.js → oauth-callback-server-CE4soEIY.js} +2 -2
- package/dist/{oauth-relay-6NBPSpFE.js → oauth-relay-C36gX1gH.js} +2 -2
- package/dist/{package-discovery-BI6T_RkD.js → package-discovery-DD9vencX.js} +1 -50
- package/dist/{parent-result-Dg6P6roR.js → parent-result-Ck1rFYRQ.js} +93 -106
- package/dist/{plugins-BXMdNdyA.js → plugins-D_Ru4CWc.js} +1 -1
- package/dist/profile-BQ-iBDsZ.js +4657 -0
- package/dist/{transcript-BHhJVY0P.js → prompt-Dv7gkpD6.js} +97 -103
- package/dist/proxy-path-BHYoKZdq.js +15 -0
- package/dist/registry-iXMT5Jmh.js +3279 -0
- package/dist/reports-WKHfGTsU.js +195 -0
- package/dist/{resolve-BUFkmxkT.js → resolve-tony4ibz.js} +9 -29
- package/dist/{result-DfATzX77.js → result-Bta_dlWa.js} +42 -117
- package/dist/run-conversation-DL6ru7iW.js +336 -0
- package/dist/{runner-CmKP3inb.js → runner-BstDRbD9.js} +7 -7
- package/dist/{sandbox-egress-signals-DYo5BsM7.js → sandbox-egress-signals-oSJMJOnn.js} +1 -1
- package/dist/{schema-DrBMdPmv.js → schema-DfqrHACA.js} +67 -84
- package/dist/sender-actors-CPglLd5R.js +83 -0
- package/dist/{service-account-CxTX7nnR.js → service-account-CTV_jaNu.js} +3 -1
- package/dist/{skills-BlHUDj7k.js → skills-BCEU41zM.js} +4 -4
- package/dist/{slack-conversation-unfurl-Dhe3lB1U.js → slack-conversation-unfurl-DxVmhbGP.js} +7 -6
- package/dist/{spawn-CfvlFdfz.js → spawn-frczVPIr.js} +11 -8
- package/dist/{system-prompt-table-CDCYVwqN.js → system-prompt-table-CiXy0eNR.js} +91 -70
- package/dist/{task-runner-DcdQJd9e.js → task-runner-C9Yc2_ae.js} +35 -49
- package/dist/{thread-context-DF5uDcWN.js → thread-context-CqZDKErp.js} +6 -6
- package/dist/topics-SRN7IVX-.js +24 -0
- package/dist/turn-membership-CENFf3kI.js +856 -0
- package/dist/{turn-wake-um5Ubd4m.js → turn-wake-BhloiI2h.js} +4 -5
- package/dist/{media-Cr9pGkzr.js → types-C4iC-IMC.js} +819 -777
- package/dist/user-customization-CvfuY9Eo.js +93 -0
- package/dist/users-ByG5RCEJ.js +181 -0
- package/dist/{validation-CJyuOPD2.js → validation-8gjfR91V.js} +1 -1
- package/dist/{version-Bhe7RPIe.js → version-BeZhWWBE.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{worker-D8PRgUqr.js → worker-BqMQQNRk.js} +5 -4
- package/migrations/20261125171254_conversation_visibility/migration.sql +4 -0
- package/migrations/20261125171254_conversation_visibility/snapshot.json +67 -0
- package/migrations/20261125171257_conversation_visibility_backfill/migration.sql +25 -0
- package/migrations/20261125171257_conversation_visibility_backfill/snapshot.json +9 -0
- package/migrations/20261125213232_drop_versions_notify/migration.sql +19 -0
- package/migrations/20261125213232_drop_versions_notify/snapshot.json +9 -0
- package/migrations/20261125225138_conversation_kind_root_thread/migration.sql +23 -0
- package/migrations/20261125225138_conversation_kind_root_thread/snapshot.json +55 -0
- package/migrations/20261125225142_conversation_kind_root_thread_backfill/migration.sql +7 -0
- package/migrations/20261125225142_conversation_kind_root_thread_backfill/snapshot.json +9 -0
- package/migrations/20261126000151_conversation_event_message_role_seq_index/migration.sql +1 -0
- package/migrations/20261126000151_conversation_event_message_role_seq_index/snapshot.json +69 -0
- package/migrations/20261126012917_merge_leaves/migration.sql +2 -0
- package/migrations/20261126012917_merge_leaves/snapshot.json +12 -0
- package/migrations/20261126025226_drop_agent_invocations/migration.sql +6 -0
- package/migrations/20261126025226_drop_agent_invocations/snapshot.json +9 -0
- package/migrations/20261126033000_space_conversations_lead_children/migration.sql +155 -0
- package/migrations/20261126033000_space_conversations_lead_children/snapshot.json +9 -0
- package/migrations/20261126144620_drop_user_message_time_index/migration.sql +1 -0
- package/migrations/20261126144620_drop_user_message_time_index/snapshot.json +38 -0
- package/migrations/20261126153100_inbox_item_subjects/migration.sql +140 -0
- package/migrations/20261126153100_inbox_item_subjects/snapshot.json +9 -0
- package/migrations/20261126153103_inbox_item_subjects_not_null/migration.sql +12 -0
- package/migrations/20261126153103_inbox_item_subjects_not_null/snapshot.json +9 -0
- package/migrations/20261126153105_inbox_item_subject_indexes/migration.sql +1 -0
- package/migrations/20261126153105_inbox_item_subject_indexes/snapshot.json +9 -0
- package/migrations/20261126153108_automation_run_conversation_index/migration.sql +1 -0
- package/migrations/20261126153108_automation_run_conversation_index/snapshot.json +9 -0
- package/migrations/20261126153159_inbox_item_subjects_schema/migration.sql +4 -0
- package/migrations/20261126153159_inbox_item_subjects_schema/snapshot.json +437 -0
- package/migrations/20261126153259_inbox_questions/migration.sql +76 -0
- package/migrations/20261126153259_inbox_questions/snapshot.json +9 -0
- package/migrations/20261126153301_inbox_questions_valid/migration.sql +3 -0
- package/migrations/20261126153301_inbox_questions_valid/snapshot.json +9 -0
- package/migrations/20261126153343_inbox_questions_schema/migration.sql +5 -0
- package/migrations/20261126153343_inbox_questions_schema/snapshot.json +407 -0
- package/migrations/20261126154025_inbox_item_owners/migration.sql +74 -0
- package/migrations/20261126154025_inbox_item_owners/snapshot.json +9 -0
- package/migrations/20261126154048_inbox_item_open_subject_key_index/migration.sql +1 -0
- package/migrations/20261126154048_inbox_item_open_subject_key_index/snapshot.json +9 -0
- package/migrations/20261126154051_drop_inbox_item_owner_indexes/migration.sql +7 -0
- package/migrations/20261126154051_drop_inbox_item_owner_indexes/snapshot.json +9 -0
- package/migrations/20261126154121_inbox_item_owners_schema/migration.sql +8 -0
- package/migrations/20261126154121_inbox_item_owners_schema/snapshot.json +311 -0
- package/migrations/20261126175601_conversation_event_turn/migration.sql +5 -0
- package/migrations/20261126175601_conversation_event_turn/snapshot.json +103 -0
- package/migrations/20261126175614_conversation_event_turn_index/migration.sql +1 -0
- package/migrations/20261126175614_conversation_event_turn_index/snapshot.json +62 -0
- package/migrations/20261126230028_merge_leaves/migration.sql +2 -0
- package/migrations/20261126230028_merge_leaves/snapshot.json +12 -0
- package/migrations/20261126231932_space_lead_holds_name/migration.sql +46 -0
- package/migrations/20261126231932_space_lead_holds_name/snapshot.json +58 -0
- package/migrations/20261127001022_merge_leaves/migration.sql +2 -0
- package/migrations/20261127001022_merge_leaves/snapshot.json +12 -0
- package/package.json +5 -5
- package/skills/jr-rpc/SKILL.md +3 -5
- package/dist/direct-url-BYgYfuIy.js +0 -22
- package/dist/markers-CE0HMXWT.js +0 -67
- package/dist/people-Cegp1Iwq.js +0 -81
- package/dist/start-conversation-Uh8Sk1EF.js +0 -162
- package/dist/turn-session-routing-GtetHsdO.js +0 -1309
- package/dist/user-customization-B27StpVQ.js +0 -9
- package/dist/web-message-id-C6P83ans.js +0 -10
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { m as logInfo, p as logException } from "./logging
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { B as
|
|
8
|
-
import { t as
|
|
9
|
-
import { i as postinstall,
|
|
1
|
+
import { Bo as credentialContextForActor, Br as getQueueProvider, Fi as createPluginDecider, Hi as createSandboxCapability, Js as sleep, Ku as getStateAdapter, Li as createPluginModel, Lr as QUEUE_SIGNATURE_MAX_AGE_MS, Oi as slackMention, Ri as createPluginModelCostRecorder, Rr as signQueueMessage, Sl as isToolInputError, So as findMatchingWatches, St as getRegistrations, Vi as basePluginContext, Wi as withPluginHookSpan, Zn as resolveEventMentions, a as getDb, cr as getTurnRequestDeadline, ec as readActorIdentity, jr as getVercelConversationWorkQueue, kt as juniorToolOutputSchema, lf as juniorConversations, lo as workspaceSnapshotFinishedEvent, ns as createPluginAnnotations, uf as juniorSpaceConfigurations, wo as isQuietEvent, xl as ToolInputError, xo as deliverWatch, zr as verifyQueueMessage } from "./db-BFmyYZtJ.js";
|
|
2
|
+
import { i as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC } from "./topics-SRN7IVX-.js";
|
|
3
|
+
import { N as fenceLock, P as withLock } from "./config-CHQ8X251.js";
|
|
4
|
+
import { h as logWarn, m as logInfo, p as logException } from "./logging--smS7XRK.js";
|
|
5
|
+
import { c as SANDBOX_REPOS_ROOT, d as SANDBOX_WORKSPACE_ROOT, s as SANDBOX_JUNIOR_ROOT } from "./prompt-Dv7gkpD6.js";
|
|
6
|
+
import { Hn as isValidTimeZone, Vn as getZonedDateTimeParts } from "./types-C4iC-IMC.js";
|
|
7
|
+
import { $t as setWorkspaceSnapshotBuild, B as resolveEventAuthor, Qt as setWorkspaceSnapshot, Vt as getWorkspace, Xt as invalidateReadySnapshot, Yt as workspaceRepoCheckoutPath, Zt as loadSnapshotsForProfile, ci as validateConfigValue, j as enqueueEventNotification, k as addQuietEventNote, li as configValueSchema, si as validateConfigKey } from "./mailbox-turn-uSXhUFc9.js";
|
|
8
|
+
import { E as createSandboxEgressCredentialToken, _ as WorkspaceSnapshotNotReadyError, j as buildSandboxEgressNetworkPolicy, o as getSandboxProvider, p as isAbortError, r as isStale, t as create, u as SANDBOX_RUNTIME, y as isWorkspaceSnapshotNotReadyError } from "./profile-BQ-iBDsZ.js";
|
|
9
|
+
import { i as postinstall, o as getSandboxResources, r as dependencies } from "./resolve-tony4ibz.js";
|
|
10
10
|
import * as z from "zod";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import { createHash, randomUUID } from "node:crypto";
|
|
13
|
-
import { eventSchema } from "@sentry/junior-plugin-api";
|
|
13
|
+
import { escapeTagTextAndQuotes, eventSchema, objectAnnotationSchema, renderInlineTag } from "@sentry/junior-plugin-api";
|
|
14
14
|
import { and, asc, eq, sql } from "drizzle-orm";
|
|
15
15
|
import { alias } from "drizzle-orm/pg-core";
|
|
16
16
|
import { structuredPatch } from "diff";
|
|
@@ -59,6 +59,14 @@ async function unsetSpaceConfiguration(spaceId, key) {
|
|
|
59
59
|
await getDb().delete(juniorSpaceConfigurations).where(and(eq(juniorSpaceConfigurations.spaceId, spaceId), eq(juniorSpaceConfigurations.key, key)));
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
+
* Return the id of the Space that a Conversation's root is in, if any. In a
|
|
63
|
+
* Space, the root is the Space's Lead.
|
|
64
|
+
*/
|
|
65
|
+
async function readConversationSpaceId(conversationId) {
|
|
66
|
+
const [row] = await getDb().select({ spaceId: rootConversation.spaceId }).from(juniorConversations).innerJoin(rootConversation, eq(rootConversation.conversationId, sql`coalesce(${juniorConversations.rootConversationId}, ${juniorConversations.conversationId})`)).where(eq(juniorConversations.conversationId, conversationId)).limit(1);
|
|
67
|
+
return row?.spaceId ?? void 0;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
62
70
|
* Return the configuration of the Space that a Conversation's root is in. A
|
|
63
71
|
* child is in the Space of its root. A Conversation outside a Space has none.
|
|
64
72
|
*/
|
|
@@ -69,6 +77,111 @@ async function readConversationSpaceConfiguration(conversationId) {
|
|
|
69
77
|
}).from(juniorConversations).innerJoin(rootConversation, eq(rootConversation.conversationId, sql`coalesce(${juniorConversations.rootConversationId}, ${juniorConversations.conversationId})`)).innerJoin(juniorSpaceConfigurations, eq(juniorSpaceConfigurations.spaceId, rootConversation.spaceId)).where(eq(juniorConversations.conversationId, conversationId));
|
|
70
78
|
return Object.fromEntries(rows.map((row) => [row.key, configValueSchema.parse(JSON.parse(row.value))]));
|
|
71
79
|
}
|
|
80
|
+
// src/chat/tool-support/zod-tool.ts
|
|
81
|
+
function isContentOnlyToolResult(value) {
|
|
82
|
+
return value !== null && typeof value === "object" && Array.isArray(value.content) && !("details" in value);
|
|
83
|
+
}
|
|
84
|
+
function isStructuredToolResultEnvelope(value) {
|
|
85
|
+
return value !== null && typeof value === "object" && Array.isArray(value.content) && "details" in value;
|
|
86
|
+
}
|
|
87
|
+
function parseToolContent(content) {
|
|
88
|
+
for (const item of content) if (!item || typeof item !== "object" || (item.type === "text" ? typeof item.text !== "string" : item.type === "image" ? typeof item.data !== "string" || typeof item.mimeType !== "string" : true)) throw new TypeError("zodTool() content must contain valid text or image items.");
|
|
89
|
+
return content;
|
|
90
|
+
}
|
|
91
|
+
function formatZodPath(path) {
|
|
92
|
+
return path.length > 0 ? path.map(String).join(".") : "root";
|
|
93
|
+
}
|
|
94
|
+
function formatToolInputError(error) {
|
|
95
|
+
return `Invalid tool arguments: ${error.issues.slice(0, 5).map((issue) => `${formatZodPath(issue.path)}: ${issue.message}`).join("; ") || "input did not match schema"}`;
|
|
96
|
+
}
|
|
97
|
+
/** Parse tool input with its Zod schema, as a model-repairable error on failure. */
|
|
98
|
+
function parseToolInput(schema, args) {
|
|
99
|
+
const result = schema.safeParse(args);
|
|
100
|
+
if (!result.success) throw new ToolInputError(formatToolInputError(result.error), { cause: result.error });
|
|
101
|
+
return result.data;
|
|
102
|
+
}
|
|
103
|
+
/** Declare the static definition of a Zod tool once, for the registry and its factory. */
|
|
104
|
+
function zodToolDefinition(definition) {
|
|
105
|
+
return definition;
|
|
106
|
+
}
|
|
107
|
+
function zodTool(definition) {
|
|
108
|
+
const { inputSchema, outputSchema, prepareArguments, execute, ...toolDef } = definition;
|
|
109
|
+
let modelInputSchema;
|
|
110
|
+
try {
|
|
111
|
+
modelInputSchema = z.toJSONSchema(inputSchema);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
throw new TypeError("zodTool() inputSchema must be representable as JSON Schema.", { cause: error });
|
|
114
|
+
}
|
|
115
|
+
let modelOutputSchema;
|
|
116
|
+
if (outputSchema) try {
|
|
117
|
+
modelOutputSchema = z.toJSONSchema(outputSchema);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
throw new TypeError("zodTool() outputSchema must be representable as JSON Schema.", { cause: error });
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
...toolDef,
|
|
123
|
+
inputSchema: modelInputSchema,
|
|
124
|
+
...modelOutputSchema ? { outputSchema: modelOutputSchema } : void 0,
|
|
125
|
+
prepareArguments(args) {
|
|
126
|
+
return parseToolInput(inputSchema, prepareArguments ? prepareArguments(args) : args);
|
|
127
|
+
},
|
|
128
|
+
...execute ? { async execute(input, options) {
|
|
129
|
+
const result = await execute(input, options);
|
|
130
|
+
if (!outputSchema) {
|
|
131
|
+
if (isContentOnlyToolResult(result)) return result;
|
|
132
|
+
throw new TypeError("zodTool() content-only tools must return { content } without details.");
|
|
133
|
+
}
|
|
134
|
+
if (isStructuredToolResultEnvelope(result)) return {
|
|
135
|
+
content: parseToolContent(result.content),
|
|
136
|
+
details: outputSchema.parse(result.details)
|
|
137
|
+
};
|
|
138
|
+
return outputSchema.parse(result);
|
|
139
|
+
} } : void 0
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// src/chat/conversations/annotation-results.ts
|
|
143
|
+
/** Save object annotations and retain returned facts in the tool result. */
|
|
144
|
+
async function saveObjectAnnotations(conversationId, plugin, value) {
|
|
145
|
+
const annotations = objectAnnotationSchema.array().parse(value);
|
|
146
|
+
await getDb().transaction(async (db) => {
|
|
147
|
+
const store = createPluginAnnotations({
|
|
148
|
+
conversationId,
|
|
149
|
+
plugin,
|
|
150
|
+
db
|
|
151
|
+
});
|
|
152
|
+
for (const annotation of annotations) {
|
|
153
|
+
await store.upsert(annotation);
|
|
154
|
+
await store.remove("resource_link", annotation.key);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return annotations.map((annotation) => ({
|
|
158
|
+
...annotation,
|
|
159
|
+
plugin
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Save annotations from a successful plugin tool result and attach their cards.
|
|
164
|
+
* An Annotation marks work that the Conversation did, so a read-only tool must
|
|
165
|
+
* not return one: looking up an object does not link it.
|
|
166
|
+
*/
|
|
167
|
+
async function annotateToolResult(conversationId, plugin, result, options) {
|
|
168
|
+
if (typeof result !== "object" || result === null) return result;
|
|
169
|
+
if ("isError" in result && result.isError === true) return result;
|
|
170
|
+
const details = "details" in result && typeof result.details === "object" && result.details !== null ? result.details : result;
|
|
171
|
+
if ("timed_out" in details && details.timed_out === true || "isError" in details && details.isError === true || !("objectAnnotations" in details) || !Array.isArray(details.objectAnnotations)) return result;
|
|
172
|
+
if (options.readOnly) throw new Error(`Read-only ${plugin} tool returned objectAnnotations. Return them only from tools that change the object.`);
|
|
173
|
+
const cards = await saveObjectAnnotations(conversationId, plugin, details.objectAnnotations);
|
|
174
|
+
const { objectAnnotations: _annotations, ...rest } = details;
|
|
175
|
+
const annotated = {
|
|
176
|
+
...rest,
|
|
177
|
+
objectCards: cards
|
|
178
|
+
};
|
|
179
|
+
if (details !== result) return {
|
|
180
|
+
...result,
|
|
181
|
+
details: annotated
|
|
182
|
+
};
|
|
183
|
+
return annotated;
|
|
184
|
+
}
|
|
72
185
|
// src/chat/sandbox/file-utils.ts
|
|
73
186
|
/** Normalize model-supplied numeric knobs before they reach filesystem tools. */
|
|
74
187
|
function positiveInteger(value) {
|
|
@@ -355,15 +468,6 @@ function createWriteFileTool() {
|
|
|
355
468
|
}
|
|
356
469
|
});
|
|
357
470
|
}
|
|
358
|
-
// src/chat/tools/system-time.ts
|
|
359
|
-
const systemTimeInputSchema = z.object({ timezone: z.string().trim().min(1).optional().describe("Optional IANA timezone, for example America/Los_Angeles. When set, iso_local and timezone_offset_minutes are for that zone.") });
|
|
360
|
-
const systemTimeOutputSchema = juniorToolOutputSchema.extend({
|
|
361
|
-
unix_ms: z.number().describe("Current time in epoch milliseconds, for millisecond inputs."),
|
|
362
|
-
iso_utc: z.string(),
|
|
363
|
-
iso_local: z.string(),
|
|
364
|
-
timezone: z.string().nullable(),
|
|
365
|
-
timezone_offset_minutes: z.number()
|
|
366
|
-
});
|
|
367
471
|
const systemTimeToolDefinition = zodToolDefinition({
|
|
368
472
|
description: "Return current system time in UTC and optional local IANA timezone formats. Use when the user asks for current time/date context. Pass timezone when the answer should be in a known IANA zone such as America/Los_Angeles.",
|
|
369
473
|
annotations: {
|
|
@@ -372,8 +476,14 @@ const systemTimeToolDefinition = zodToolDefinition({
|
|
|
372
476
|
openWorldHint: false,
|
|
373
477
|
readOnlyHint: true
|
|
374
478
|
},
|
|
375
|
-
inputSchema:
|
|
376
|
-
outputSchema:
|
|
479
|
+
inputSchema: z.object({ timezone: z.string().trim().min(1).optional().describe("Optional IANA timezone, for example America/Los_Angeles. When set, iso_local and timezone_offset_minutes are for that zone.") }),
|
|
480
|
+
outputSchema: juniorToolOutputSchema.extend({
|
|
481
|
+
unix_ms: z.number().describe("Current time in epoch milliseconds, for millisecond inputs."),
|
|
482
|
+
iso_utc: z.string(),
|
|
483
|
+
iso_local: z.string(),
|
|
484
|
+
timezone: z.string().nullable(),
|
|
485
|
+
timezone_offset_minutes: z.number()
|
|
486
|
+
}),
|
|
377
487
|
privateTraceResult: (result) => ({
|
|
378
488
|
unix_ms: result.unix_ms,
|
|
379
489
|
iso_utc: result.iso_utc,
|
|
@@ -429,6 +539,271 @@ function getTimeZoneOffsetMinutes(timestampMs, timezone) {
|
|
|
429
539
|
const asUtcMs = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
|
|
430
540
|
return Math.round((timestampMs - asUtcMs) / 6e4);
|
|
431
541
|
}
|
|
542
|
+
// src/chat/tool-support/plugin-tool-denied-error.ts
|
|
543
|
+
const NOT_RUN_LINE = "This action was blocked by policy and was not executed.";
|
|
544
|
+
const RAN_LINE = "This action ran, but policy rejected its result. Its changes may still be in place.";
|
|
545
|
+
const PLUGIN_DENIAL_INSTRUCTIONS = ["Do not retry it or reach the same result through a workaround or another tool.", "Stop and explain what was blocked and why."].join("\n");
|
|
546
|
+
/** Expected tool failure when a plugin hook refuses a tool call by policy. */
|
|
547
|
+
var PluginToolDeniedError = class extends Error {
|
|
548
|
+
/** `ran` is true when an after-execution hook rejected the result. */
|
|
549
|
+
constructor(reason, options = {}) {
|
|
550
|
+
super(`${options.ran ? RAN_LINE : NOT_RUN_LINE}\n${PLUGIN_DENIAL_INSTRUCTIONS}\nReason: ${reason}`);
|
|
551
|
+
this.name = "PluginToolDeniedError";
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
// src/chat/plugins/after-tool-hooks.ts
|
|
555
|
+
/** Render a nudge as the marked text the agent reads. */
|
|
556
|
+
function renderToolResultNudge(nudge) {
|
|
557
|
+
return renderInlineTag("plugin-note", escapeTagTextAndQuotes(nudge.message), { plugin: nudge.pluginName });
|
|
558
|
+
}
|
|
559
|
+
async function activeWorkspace(sandbox) {
|
|
560
|
+
const id = sandbox.workspaceId();
|
|
561
|
+
const workspace = id ? await getWorkspace(getDb(), id) : void 0;
|
|
562
|
+
if (!workspace) return void 0;
|
|
563
|
+
return {
|
|
564
|
+
name: workspace.name,
|
|
565
|
+
repos: workspace.repos.map((repo) => ({
|
|
566
|
+
path: workspaceRepoCheckoutPath(repo.repo),
|
|
567
|
+
provider: repo.provider,
|
|
568
|
+
repo: repo.repo
|
|
569
|
+
}))
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Run each plugin's `afterToolExecute` hook in registration order. A denial
|
|
574
|
+
* throws `PluginToolDeniedError` and skips later hooks. An abort stops the
|
|
575
|
+
* checks and keeps the tool result.
|
|
576
|
+
*/
|
|
577
|
+
async function runAfterToolExecuteHooks(args) {
|
|
578
|
+
const hooked = args.plugins.filter((plugin) => plugin.hooks?.afterToolExecute);
|
|
579
|
+
if (hooked.length === 0) return [];
|
|
580
|
+
const { signal } = args.tool;
|
|
581
|
+
const sandbox = createSandboxCapability(args.sandbox.workspace, signal);
|
|
582
|
+
let workspace;
|
|
583
|
+
try {
|
|
584
|
+
workspace = await activeWorkspace(args.sandbox);
|
|
585
|
+
} catch (error) {
|
|
586
|
+
logException(error, "agent.plugin.after_tool_execute.failed", { "gen_ai.tool.name": args.tool.name });
|
|
587
|
+
return [];
|
|
588
|
+
}
|
|
589
|
+
const nudges = [];
|
|
590
|
+
for (const plugin of hooked) {
|
|
591
|
+
if (signal?.aborted) break;
|
|
592
|
+
const pluginName = plugin.manifest.name;
|
|
593
|
+
const onCost = createPluginModelCostRecorder({
|
|
594
|
+
...args.turn,
|
|
595
|
+
pluginName,
|
|
596
|
+
source: "afterToolExecute",
|
|
597
|
+
toolName: args.tool.name
|
|
598
|
+
});
|
|
599
|
+
let denial;
|
|
600
|
+
try {
|
|
601
|
+
await withPluginHookSpan(pluginName, "afterToolExecute", async () => await plugin.hooks.afterToolExecute({
|
|
602
|
+
...basePluginContext(plugin),
|
|
603
|
+
decider: createPluginDecider(pluginName, {
|
|
604
|
+
onCost,
|
|
605
|
+
signal
|
|
606
|
+
}),
|
|
607
|
+
decision: {
|
|
608
|
+
deny(reason) {
|
|
609
|
+
denial = reason;
|
|
610
|
+
},
|
|
611
|
+
nudge(message) {
|
|
612
|
+
nudges.push({
|
|
613
|
+
message,
|
|
614
|
+
pluginName
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
model: createPluginModel(pluginName, plugin.model, {
|
|
619
|
+
onCost,
|
|
620
|
+
signal
|
|
621
|
+
}),
|
|
622
|
+
sandbox,
|
|
623
|
+
...signal ? { signal } : void 0,
|
|
624
|
+
tool: {
|
|
625
|
+
input: args.tool.input,
|
|
626
|
+
name: args.tool.name
|
|
627
|
+
},
|
|
628
|
+
...workspace ? { workspace } : void 0
|
|
629
|
+
}));
|
|
630
|
+
} catch (error) {
|
|
631
|
+
if (signal?.aborted) break;
|
|
632
|
+
const attributes = {
|
|
633
|
+
"app.plugin.name": pluginName,
|
|
634
|
+
"gen_ai.tool.name": args.tool.name
|
|
635
|
+
};
|
|
636
|
+
if (isToolInputError(error)) logWarn("agent.plugin.after_tool_execute.failed", {
|
|
637
|
+
...attributes,
|
|
638
|
+
"error.type": "tool_input_error"
|
|
639
|
+
});
|
|
640
|
+
else logException(error, "agent.plugin.after_tool_execute.failed", attributes);
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (denial !== void 0) throw new PluginToolDeniedError(denial, { ran: true });
|
|
644
|
+
}
|
|
645
|
+
return nudges;
|
|
646
|
+
}
|
|
647
|
+
// src/chat/plugins/hooks/runner.ts
|
|
648
|
+
function normalizeEnv(value) {
|
|
649
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
|
|
650
|
+
const env = {};
|
|
651
|
+
for (const [key, rawValue] of Object.entries(value)) if (typeof rawValue === "string") env[key] = rawValue;
|
|
652
|
+
return env;
|
|
653
|
+
}
|
|
654
|
+
/** Create one runner over runtime hook plugins registered by the app. */
|
|
655
|
+
function createPluginHookRunner(input = {}) {
|
|
656
|
+
const loaded = getRegistrations();
|
|
657
|
+
return {
|
|
658
|
+
async afterToolExecute(tool) {
|
|
659
|
+
if (!input.toolRun) return [];
|
|
660
|
+
const { sandbox, ...turn } = input.toolRun;
|
|
661
|
+
return await runAfterToolExecuteHooks({
|
|
662
|
+
plugins: loaded,
|
|
663
|
+
sandbox: sandbox(),
|
|
664
|
+
tool,
|
|
665
|
+
turn
|
|
666
|
+
});
|
|
667
|
+
},
|
|
668
|
+
async afterMcpTool(tool) {
|
|
669
|
+
const cards = [];
|
|
670
|
+
for (const plugin of loaded) {
|
|
671
|
+
if (plugin.manifest.name !== tool.provider) continue;
|
|
672
|
+
const hook = plugin.hooks?.afterMcpTool;
|
|
673
|
+
if (!hook) continue;
|
|
674
|
+
const annotations = tool.conversationId ? createPluginAnnotations({
|
|
675
|
+
conversationId: tool.conversationId,
|
|
676
|
+
db: getDb(),
|
|
677
|
+
plugin: plugin.manifest.name
|
|
678
|
+
}) : void 0;
|
|
679
|
+
try {
|
|
680
|
+
const result = await hook({
|
|
681
|
+
...basePluginContext(plugin),
|
|
682
|
+
...tool.conversationId ? { conversationId: tool.conversationId } : void 0,
|
|
683
|
+
...annotations ? { annotations } : void 0,
|
|
684
|
+
result: {
|
|
685
|
+
content: tool.content,
|
|
686
|
+
structuredContent: tool.structuredContent
|
|
687
|
+
},
|
|
688
|
+
tool: {
|
|
689
|
+
arguments: tool.arguments,
|
|
690
|
+
name: tool.toolName
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
if (result && tool.conversationId) cards.push(...await saveObjectAnnotations(tool.conversationId, plugin.manifest.name, result.objectAnnotations));
|
|
694
|
+
} catch (error) {
|
|
695
|
+
logWarn("agent.plugin.after_mcp_tool.failed", {
|
|
696
|
+
"app.plugin.name": plugin.manifest.name,
|
|
697
|
+
"gen_ai.tool.name": tool.toolName,
|
|
698
|
+
"exception.message": error instanceof Error ? error.message : String(error)
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return cards;
|
|
703
|
+
},
|
|
704
|
+
async prepareWorkspace(sandbox, repos, signal) {
|
|
705
|
+
const preparers = new Set(loaded.filter((plugin) => plugin.hooks?.workspacePrepare).map((plugin) => plugin.manifest.name));
|
|
706
|
+
const unhandledProviders = [...new Set(repos.map((repo) => repo.provider).filter((provider) => !preparers.has(provider)))].sort();
|
|
707
|
+
if (unhandledProviders.length > 0) throw new Error(`Workspace repository providers have no preparation hook: ${unhandledProviders.join(", ")}`);
|
|
708
|
+
const selectedRepos = repos.map((repo) => ({
|
|
709
|
+
provider: repo.provider,
|
|
710
|
+
repo: repo.repo,
|
|
711
|
+
path: workspaceRepoCheckoutPath(repo.repo)
|
|
712
|
+
}));
|
|
713
|
+
const paths = /* @__PURE__ */ new Set();
|
|
714
|
+
for (const entry of selectedRepos) {
|
|
715
|
+
const key = entry.path.toLowerCase();
|
|
716
|
+
if (paths.has(key)) throw new Error(`Workspace checkout path collision: ${entry.path}`);
|
|
717
|
+
paths.add(key);
|
|
718
|
+
}
|
|
719
|
+
const sandboxCapability = createSandboxCapability(sandbox, signal);
|
|
720
|
+
const finalizers = [];
|
|
721
|
+
for (const plugin of loaded) {
|
|
722
|
+
const hook = plugin.hooks?.workspacePrepare;
|
|
723
|
+
if (!hook) continue;
|
|
724
|
+
const selected = selectedRepos.filter((repo) => repo.provider === plugin.manifest.name).map((repo) => ({
|
|
725
|
+
path: repo.path,
|
|
726
|
+
repo: repo.repo
|
|
727
|
+
}));
|
|
728
|
+
if (selected.length === 0) continue;
|
|
729
|
+
const finalize = await hook({
|
|
730
|
+
...basePluginContext(plugin),
|
|
731
|
+
repos: selected,
|
|
732
|
+
sandbox: sandboxCapability
|
|
733
|
+
});
|
|
734
|
+
if (finalize) finalizers.push(finalize);
|
|
735
|
+
}
|
|
736
|
+
return async () => {
|
|
737
|
+
for (const finalize of finalizers) await finalize();
|
|
738
|
+
};
|
|
739
|
+
},
|
|
740
|
+
async prepareSandbox(sandbox) {
|
|
741
|
+
const sandboxCapability = createSandboxCapability(sandbox);
|
|
742
|
+
for (const plugin of loaded) {
|
|
743
|
+
const pluginName = plugin.manifest.name;
|
|
744
|
+
const hook = plugin.hooks?.sandboxPrepare;
|
|
745
|
+
if (!hook) continue;
|
|
746
|
+
logInfo("agent.plugin.sandbox_preparation.started", { "app.plugin.name": pluginName });
|
|
747
|
+
await withPluginHookSpan(pluginName, "sandboxPrepare", async () => await hook({
|
|
748
|
+
...basePluginContext(plugin),
|
|
749
|
+
actor: input.actor,
|
|
750
|
+
sandbox: sandboxCapability
|
|
751
|
+
}));
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
async beforeToolExecute(tool) {
|
|
755
|
+
const env = {};
|
|
756
|
+
let nextInput = { ...tool.input };
|
|
757
|
+
const actors = input.actors?.() ?? (input.actor ? [input.actor] : []);
|
|
758
|
+
for (const plugin of loaded) {
|
|
759
|
+
const pluginName = plugin.manifest.name;
|
|
760
|
+
const hook = plugin.hooks?.beforeToolExecute;
|
|
761
|
+
if (!hook) continue;
|
|
762
|
+
let replacement;
|
|
763
|
+
let blocked;
|
|
764
|
+
await withPluginHookSpan(pluginName, "beforeToolExecute", async () => await hook({
|
|
765
|
+
...basePluginContext(plugin),
|
|
766
|
+
actor: input.actor,
|
|
767
|
+
actors,
|
|
768
|
+
tool: {
|
|
769
|
+
name: tool.name,
|
|
770
|
+
input: nextInput
|
|
771
|
+
},
|
|
772
|
+
users: { resolveActor: async () => input.actor ? await readActorIdentity(input.actor) : void 0 },
|
|
773
|
+
juniorRoot: SANDBOX_JUNIOR_ROOT,
|
|
774
|
+
env: {
|
|
775
|
+
get(key) {
|
|
776
|
+
return env[key] ?? normalizeEnv(nextInput["env"])[key];
|
|
777
|
+
},
|
|
778
|
+
set(key, value) {
|
|
779
|
+
env[key] = value;
|
|
780
|
+
}
|
|
781
|
+
},
|
|
782
|
+
decision: {
|
|
783
|
+
deny(reason) {
|
|
784
|
+
blocked = new PluginToolDeniedError(reason);
|
|
785
|
+
},
|
|
786
|
+
redirect(message) {
|
|
787
|
+
blocked = new ToolInputError(message);
|
|
788
|
+
},
|
|
789
|
+
replaceInput(input) {
|
|
790
|
+
replacement = input;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}));
|
|
794
|
+
if (blocked) throw blocked;
|
|
795
|
+
if (replacement !== void 0) {
|
|
796
|
+
if (typeof replacement !== "object" || replacement === null || Array.isArray(replacement)) throw new Error(`Plugin "${pluginName}" replaced tool input with a non-object value`);
|
|
797
|
+
nextInput = { ...replacement };
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return {
|
|
801
|
+
input: nextInput,
|
|
802
|
+
env
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
}
|
|
432
807
|
// src/chat/events/ingest.ts
|
|
433
808
|
/** Match a normalized event and enqueue notifications into conversations. */
|
|
434
809
|
async function ingestEvent(input, options) {
|
|
@@ -1128,4 +1503,4 @@ async function ensureWorkspaceSnapshotBuild(input) {
|
|
|
1128
1503
|
else await sendWorkspaceSnapshotJob(message);
|
|
1129
1504
|
return "building";
|
|
1130
1505
|
}
|
|
1131
|
-
export {
|
|
1506
|
+
export { annotateToolResult as A, restoreLineEndings as C, normalizeToLf as D, isMissingPathError as E, listSpaceConfiguration as F, readConversationSpaceConfiguration as I, readConversationSpaceId as L, parseToolInput as M, zodTool as N, positiveInteger as O, zodToolDefinition as P, setSpaceConfiguration as R, prepareTextReplacementArguments as S, validateAndApplyTextEdits as T, editFileToolDefinition as _, prepareWorkspaceSnapshot as a, buildCompactDiff as b, renderToolResultNudge as c, systemTimeToolDefinition as d, createWriteFileTool as f, createEditFileTool as g, readFileToolDefinition as h, requireReadyWorkspaceSnapshot as i, saveObjectAnnotations as j, resolveWorkspacePath as k, PluginToolDeniedError as l, createReadFileTool as m, processWorkspaceSnapshotJob as n, ingestEvent as o, writeFileToolDefinition as p, verifyWorkspaceSnapshotJobMessage as r, createPluginHookRunner as s, ensureWorkspaceSnapshotBuild as t, createSystemTimeTool as u, bashToolDefinition as v, stripBom as w, detectLineEnding as x, createBashTool as y, unsetSpaceConfiguration as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { K as conversationKindFromRow, a as getDb, lf as juniorConversations } from "./db-BFmyYZtJ.js";
|
|
2
2
|
import { desc, eq, sql } from "drizzle-orm";
|
|
3
3
|
// src/chat/conversations/lineage.ts
|
|
4
4
|
/**
|