@sentry/junior 0.316.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.
Files changed (122) hide show
  1. package/dist/{admin-QYiDMnsu.js → admin-CAugg87B.js} +1 -1
  2. package/dist/{agent-runner-Cr5Fhjf-.js → agent-runner-AjrEV6Qe.js} +13438 -13149
  3. package/dist/{reporting-window-C4dbzDiR.js → agent-status-BA5x3Xtp.js} +33 -1
  4. package/dist/{agent-update-delivery-BY13DPSD.js → agent-update-delivery-B_YIZcgf.js} +5 -5
  5. package/dist/api/schema.d.ts +558 -102
  6. package/dist/api/schema.js +6 -6
  7. package/dist/api.js +230 -213
  8. package/dist/{app-BhvzRD__.d.ts → app-MoNAsVV5.d.ts} +34 -14
  9. package/dist/app.d.ts +1 -1
  10. package/dist/app.js +167 -122
  11. package/dist/catalog-runtime-DfSpJZdY.js +6 -0
  12. package/dist/{change-record-Bqsa5ZXE.d.ts → change-record-BzJgLsv7.d.ts} +60 -1
  13. package/dist/{adapter-context-Bref7aPI.js → channel-access-j-YAVYK4.js} +2 -42
  14. package/dist/{chat-core-engine-3dtlMku3.js → chat-core-engine-aH85nEHv.js} +4 -3
  15. package/dist/{child-message--2G3Ft26.js → child-message-DHjQLEd1.js} +1 -1
  16. package/dist/cli/chat.js +23 -23
  17. package/dist/cli/check.js +5 -5
  18. package/dist/cli/main.js +2 -2
  19. package/dist/cli/plugins.js +5 -4
  20. package/dist/cli/snapshot-create.js +5 -2
  21. package/dist/cli/upgrade.js +5 -3
  22. package/dist/config-CHQ8X251.js +2422 -0
  23. package/dist/{continue-in-slack-DbQUFe_F.js → continue-in-slack-D-FZ8Fin.js} +2 -3
  24. package/dist/{conversation-feed-B84pMjHo.js → conversation-feed--9S0_PXL.js} +3 -3
  25. package/dist/{proxy-path-BTmXDjfx.js → conversation-privacy-B1uXn5sf.js} +2 -16
  26. package/dist/{conversation-turn-DzEpTIaf.js → conversation-turn-BUE_7xaN.js} +99 -76
  27. package/dist/{create-DUJBXr6E.js → create-DoDIYgtZ.js} +12 -9
  28. package/dist/{credential-sync-JH_K9Adg.js → credential-sync-BJOqGnjV.js} +17 -12
  29. package/dist/{db-DhzvUY23.js → db-BFmyYZtJ.js} +20265 -27551
  30. package/dist/{deployment-BhvrhQeh.js → deployment-DXq9ZLU4.js} +17 -15
  31. package/dist/{engine-context-C9Nal48K.js → engine-context-CgQ7mlHt.js} +264 -47
  32. package/dist/{html-B_12WjKT.js → html-B3VKTGbJ.js} +6 -2
  33. package/dist/instrumentation.js +15 -7
  34. package/dist/{job-runner-DO8nslyY.js → job-runner-A1lCkybD.js} +391 -24
  35. package/dist/{lineage-D3AZAJVe.js → lineage-Bktb0UcV.js} +1 -1
  36. package/dist/{list-B0zsb5Cp.js → list-Bxvg5wXf.js} +224 -544
  37. package/dist/{logging-B8KEJegM.js → logging--smS7XRK.js} +2 -2
  38. package/dist/{session-stop-DponjDUZ.js → mailbox-turn-uSXhUFc9.js} +4747 -7039
  39. package/dist/{message-B5fKDYzz.js → message-BNenhsmB.js} +12 -22
  40. package/dist/{model-input-CuMWy37l.js → model-input-BReSnwHp.js} +3 -3
  41. package/dist/nitro.d.ts +1 -1
  42. package/dist/nitro.js +20 -6
  43. package/dist/{oauth-callback-server-B3Vvlydo.js → oauth-callback-server-CE4soEIY.js} +2 -2
  44. package/dist/{oauth-relay-6ERrGPbA.js → oauth-relay-C36gX1gH.js} +2 -2
  45. package/dist/{package-discovery-BI6T_RkD.js → package-discovery-DD9vencX.js} +1 -50
  46. package/dist/{list-mkB_GU8R.js → parent-result-Ck1rFYRQ.js} +107 -92
  47. package/dist/{plugins-BXMdNdyA.js → plugins-D_Ru4CWc.js} +1 -1
  48. package/dist/profile-BQ-iBDsZ.js +4657 -0
  49. package/dist/{transcript-CCi7323k.js → prompt-Dv7gkpD6.js} +97 -103
  50. package/dist/proxy-path-BHYoKZdq.js +15 -0
  51. package/dist/registry-iXMT5Jmh.js +3279 -0
  52. package/dist/reports-WKHfGTsU.js +195 -0
  53. package/dist/{resolve-D5JVvv6A.js → resolve-tony4ibz.js} +9 -29
  54. package/dist/{result-CS_7mo8a.js → result-Bta_dlWa.js} +25 -116
  55. package/dist/run-conversation-DL6ru7iW.js +336 -0
  56. package/dist/{runner-BzAES5W3.js → runner-BstDRbD9.js} +7 -7
  57. package/dist/{sandbox-egress-signals-Dwhk2Q5F.js → sandbox-egress-signals-oSJMJOnn.js} +1 -1
  58. package/dist/{schema-z5-wA6N4.js → schema-DfqrHACA.js} +48 -86
  59. package/dist/sender-actors-CPglLd5R.js +83 -0
  60. package/dist/{service-account-D6AsAtc1.js → service-account-CTV_jaNu.js} +3 -1
  61. package/dist/{skills-DgJ9GBPR.js → skills-BCEU41zM.js} +4 -4
  62. package/dist/{slack-conversation-unfurl-Dq71EkhM.js → slack-conversation-unfurl-DxVmhbGP.js} +7 -6
  63. package/dist/{spawn-BJWpdwhQ.js → spawn-frczVPIr.js} +11 -8
  64. package/dist/{system-prompt-table-iIgpmslr.js → system-prompt-table-CiXy0eNR.js} +88 -69
  65. package/dist/{task-runner-BJae4JwE.js → task-runner-C9Yc2_ae.js} +20 -46
  66. package/dist/{thread-context-fiMNylbg.js → thread-context-CqZDKErp.js} +6 -6
  67. package/dist/topics-SRN7IVX-.js +24 -0
  68. package/dist/turn-membership-CENFf3kI.js +856 -0
  69. package/dist/{turn-wake-BjDW7x-5.js → turn-wake-BhloiI2h.js} +4 -5
  70. package/dist/{media-BebquhET.js → types-C4iC-IMC.js} +801 -771
  71. package/dist/user-customization-CvfuY9Eo.js +93 -0
  72. package/dist/users-ByG5RCEJ.js +181 -0
  73. package/dist/{validation-D5WmmmhX.js → validation-8gjfR91V.js} +1 -1
  74. package/dist/{version-CBQoanXb.js → version-BeZhWWBE.js} +1 -1
  75. package/dist/version.js +1 -1
  76. package/dist/{worker-Cyb4kF17.js → worker-BqMQQNRk.js} +5 -4
  77. package/migrations/20261126025226_drop_agent_invocations/migration.sql +6 -0
  78. package/migrations/20261126025226_drop_agent_invocations/snapshot.json +9 -0
  79. package/migrations/20261126033000_space_conversations_lead_children/migration.sql +155 -0
  80. package/migrations/20261126033000_space_conversations_lead_children/snapshot.json +9 -0
  81. package/migrations/20261126144620_drop_user_message_time_index/migration.sql +1 -0
  82. package/migrations/20261126144620_drop_user_message_time_index/snapshot.json +38 -0
  83. package/migrations/20261126153100_inbox_item_subjects/migration.sql +140 -0
  84. package/migrations/20261126153100_inbox_item_subjects/snapshot.json +9 -0
  85. package/migrations/20261126153103_inbox_item_subjects_not_null/migration.sql +12 -0
  86. package/migrations/20261126153103_inbox_item_subjects_not_null/snapshot.json +9 -0
  87. package/migrations/20261126153105_inbox_item_subject_indexes/migration.sql +1 -0
  88. package/migrations/20261126153105_inbox_item_subject_indexes/snapshot.json +9 -0
  89. package/migrations/20261126153108_automation_run_conversation_index/migration.sql +1 -0
  90. package/migrations/20261126153108_automation_run_conversation_index/snapshot.json +9 -0
  91. package/migrations/20261126153159_inbox_item_subjects_schema/migration.sql +4 -0
  92. package/migrations/20261126153159_inbox_item_subjects_schema/snapshot.json +437 -0
  93. package/migrations/20261126153259_inbox_questions/migration.sql +76 -0
  94. package/migrations/20261126153259_inbox_questions/snapshot.json +9 -0
  95. package/migrations/20261126153301_inbox_questions_valid/migration.sql +3 -0
  96. package/migrations/20261126153301_inbox_questions_valid/snapshot.json +9 -0
  97. package/migrations/20261126153343_inbox_questions_schema/migration.sql +5 -0
  98. package/migrations/20261126153343_inbox_questions_schema/snapshot.json +407 -0
  99. package/migrations/20261126154025_inbox_item_owners/migration.sql +74 -0
  100. package/migrations/20261126154025_inbox_item_owners/snapshot.json +9 -0
  101. package/migrations/20261126154048_inbox_item_open_subject_key_index/migration.sql +1 -0
  102. package/migrations/20261126154048_inbox_item_open_subject_key_index/snapshot.json +9 -0
  103. package/migrations/20261126154051_drop_inbox_item_owner_indexes/migration.sql +7 -0
  104. package/migrations/20261126154051_drop_inbox_item_owner_indexes/snapshot.json +9 -0
  105. package/migrations/20261126154121_inbox_item_owners_schema/migration.sql +8 -0
  106. package/migrations/20261126154121_inbox_item_owners_schema/snapshot.json +311 -0
  107. package/migrations/20261126175601_conversation_event_turn/migration.sql +5 -0
  108. package/migrations/20261126175601_conversation_event_turn/snapshot.json +103 -0
  109. package/migrations/20261126175614_conversation_event_turn_index/migration.sql +1 -0
  110. package/migrations/20261126175614_conversation_event_turn_index/snapshot.json +62 -0
  111. package/migrations/20261126230028_merge_leaves/migration.sql +2 -0
  112. package/migrations/20261126230028_merge_leaves/snapshot.json +12 -0
  113. package/migrations/20261126231932_space_lead_holds_name/migration.sql +46 -0
  114. package/migrations/20261126231932_space_lead_holds_name/snapshot.json +58 -0
  115. package/migrations/20261127001022_merge_leaves/migration.sql +2 -0
  116. package/migrations/20261127001022_merge_leaves/snapshot.json +12 -0
  117. package/package.json +5 -5
  118. package/dist/people-CUtFApfL.js +0 -81
  119. package/dist/start-conversation-B-LIqqNi.js +0 -162
  120. package/dist/turn-session-routing-D15orfwy.js +0 -1309
  121. package/dist/user-customization-B27StpVQ.js +0 -9
  122. package/dist/web-message-id-C6P83ans.js +0 -10
@@ -1,16 +1,16 @@
1
- import { $i as getVercelConversationWorkQueue, Dr as buildSandboxEgressNetworkPolicy, Eu as juniorSpaceConfigurations, Gn as create, Gu as workspaceSnapshotFinishedEvent, Hn as loadSnapshotsForProfile, Pd as sleep, Pn as getWorkspace, Tu as juniorConversations, Un as setWorkspaceSnapshot, V as slackMention, Vn as invalidateReadySnapshot, Wn as setWorkspaceSnapshotBuild, Xn as getSandboxProvider, Zd as ToolInputError, a as getDb, aa as QUEUE_SIGNATURE_MAX_AGE_MS, br as createSandboxEgressCredentialToken, ca as getQueueProvider, cp as withLock, dr as WorkspaceSnapshotNotReadyError, id as findMatchingWatches, nf as getStateAdapter, oa as signQueueMessage, od as isQuietEvent, of as credentialContextForActor, pr as isWorkspaceSnapshotNotReadyError, q as createPluginHookRunner, qn as isStale, rd as deliverWatch, sa as verifyQueueMessage, sp as fenceLock, sr as isAbortError, xn as getTurnRequestDeadline, yi as SANDBOX_RUNTIME } from "./db-DhzvUY23.js";
2
- import { h as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC } from "./package-discovery-BI6T_RkD.js";
3
- import { M as SANDBOX_WORKSPACE_ROOT, k as SANDBOX_REPOS_ROOT } from "./transcript-CCi7323k.js";
4
- import { m as logInfo, p as logException } from "./logging-B8KEJegM.js";
5
- import { cn as isValidTimeZone, sn as getZonedDateTimeParts } from "./media-BebquhET.js";
6
- import { ln as enqueueEventNotification, na as validateConfigValue, ra as configValueSchema, sn as addQuietEventNote, ta as validateConfigKey, yn as resolveEventAuthor } from "./session-stop-DponjDUZ.js";
7
- import { B as zodToolDefinition, H as juniorToolOutputSchema, z as zodTool } from "./turn-session-routing-D15orfwy.js";
8
- import { t as resolveEventMentions } from "./people-CUtFApfL.js";
9
- import { i as postinstall, r as dependencies, s as getSandboxResources } from "./resolve-D5JVvv6A.js";
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,8 +59,8 @@ 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. A
63
- * child is in the Space of its root.
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
64
  */
65
65
  async function readConversationSpaceId(conversationId) {
66
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);
@@ -77,6 +77,111 @@ async function readConversationSpaceConfiguration(conversationId) {
77
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));
78
78
  return Object.fromEntries(rows.map((row) => [row.key, configValueSchema.parse(JSON.parse(row.value))]));
79
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
+ }
80
185
  // src/chat/sandbox/file-utils.ts
81
186
  /** Normalize model-supplied numeric knobs before they reach filesystem tools. */
82
187
  function positiveInteger(value) {
@@ -363,15 +468,6 @@ function createWriteFileTool() {
363
468
  }
364
469
  });
365
470
  }
366
- // src/chat/tools/system-time.ts
367
- 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.") });
368
- const systemTimeOutputSchema = juniorToolOutputSchema.extend({
369
- unix_ms: z.number().describe("Current time in epoch milliseconds, for millisecond inputs."),
370
- iso_utc: z.string(),
371
- iso_local: z.string(),
372
- timezone: z.string().nullable(),
373
- timezone_offset_minutes: z.number()
374
- });
375
471
  const systemTimeToolDefinition = zodToolDefinition({
376
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.",
377
473
  annotations: {
@@ -380,8 +476,14 @@ const systemTimeToolDefinition = zodToolDefinition({
380
476
  openWorldHint: false,
381
477
  readOnlyHint: true
382
478
  },
383
- inputSchema: systemTimeInputSchema,
384
- outputSchema: systemTimeOutputSchema,
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
+ }),
385
487
  privateTraceResult: (result) => ({
386
488
  unix_ms: result.unix_ms,
387
489
  iso_utc: result.iso_utc,
@@ -437,6 +539,271 @@ function getTimeZoneOffsetMinutes(timestampMs, timezone) {
437
539
  const asUtcMs = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
438
540
  return Math.round((timestampMs - asUtcMs) / 6e4);
439
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
+ }
440
807
  // src/chat/events/ingest.ts
441
808
  /** Match a normalized event and enqueue notifications into conversations. */
442
809
  async function ingestEvent(input, options) {
@@ -1136,4 +1503,4 @@ async function ensureWorkspaceSnapshotBuild(input) {
1136
1503
  else await sendWorkspaceSnapshotJob(message);
1137
1504
  return "building";
1138
1505
  }
1139
- export { setSpaceConfiguration as A, isMissingPathError as C, listSpaceConfiguration as D, resolveWorkspacePath as E, readConversationSpaceConfiguration as O, validateAndApplyTextEdits as S, positiveInteger as T, buildCompactDiff as _, prepareWorkspaceSnapshot as a, restoreLineEndings as b, systemTimeToolDefinition as c, createReadFileTool as d, readFileToolDefinition as f, createBashTool as g, bashToolDefinition as h, requireReadyWorkspaceSnapshot as i, unsetSpaceConfiguration as j, readConversationSpaceId as k, createWriteFileTool as l, editFileToolDefinition as m, processWorkspaceSnapshotJob as n, ingestEvent as o, createEditFileTool as p, verifyWorkspaceSnapshotJobMessage as r, createSystemTimeTool as s, ensureWorkspaceSnapshotBuild as t, writeFileToolDefinition as u, detectLineEnding as v, normalizeToLf as w, stripBom as x, prepareTextReplacementArguments as y };
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 { Ds as conversationKindFromRow, Tu as juniorConversations, a as getDb } from "./db-DhzvUY23.js";
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
  /**