@sentry/junior 0.297.0 → 0.299.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 (94) hide show
  1. package/dist/{actor-6jsm_v96.js → actor-D2iXzvlN.js} +2 -1
  2. package/dist/{state-DFnmLmfn.js → adapter-AgCNqqsG.js} +49 -133
  3. package/dist/{admin-tmGIw4KS.js → admin-1VwEXztm.js} +2 -2
  4. package/dist/{agent-runner-CneTquAE.js → agent-runner-Ciet8_nn.js} +1067 -1353
  5. package/dist/api/schema.d.ts +2 -2
  6. package/dist/api/schema.js +8 -7
  7. package/dist/api.d.ts +1 -1
  8. package/dist/api.js +125 -43
  9. package/dist/{app-BJojZ7HL.d.ts → app--ky-Eu33.d.ts} +6 -4
  10. package/dist/app.d.ts +1 -1
  11. package/dist/app.js +126 -299
  12. package/dist/{automation-BrP6ImrC.js → automation-M3RFJUBf.js} +1 -1
  13. package/dist/{background-compaction-queue-CwfJy3Cd.js → background-compaction-queue-CnimvRdk.js} +4 -4
  14. package/dist/{briefs-uFTuhMqA.js → briefs-CwzvgdCa.js} +4 -4
  15. package/dist/{catalog-runtime-0kuQqYL4.js → catalog-runtime-DaBaHY7u.js} +1 -1
  16. package/dist/cli/chat.js +17 -17
  17. package/dist/cli/check.js +3 -3
  18. package/dist/cli/main.js +3 -3
  19. package/dist/cli/plugins.js +5 -5
  20. package/dist/cli/snapshot-create.js +4 -4
  21. package/dist/cli/upgrade.d.ts +1 -1
  22. package/dist/cli/upgrade.js +4 -4
  23. package/dist/{config-Dj9M_nqB.js → config-CAXIpWQb.js} +80 -6
  24. package/dist/{connections-B96JUM5o.js → connections-Dy0hPdUq.js} +6 -6
  25. package/dist/continue-in-slack-DIOjFj76.js +176 -0
  26. package/dist/{conversation-CvcBU1z2.js → conversation-fCWD9Az3.js} +73 -13
  27. package/dist/{conversation-feed-BSMlGZnS.js → conversation-feed-BPK8vkkZ.js} +88 -3
  28. package/dist/{conversation-privacy-DI29jbZV.js → conversation-privacy-DUgtRkf8.js} +1 -1
  29. package/dist/{conversation-turn-CZWBr091.js → conversation-turn-DkJB6yMF.js} +85 -68
  30. package/dist/{credential-sync-Blhx4_xf.js → credential-sync-RX24Y8aY.js} +18 -18
  31. package/dist/{db-CrtyFRz7.d.ts → db-B07FtU9g.d.ts} +1 -1
  32. package/dist/{db-Br0tfAo7.js → db-COYOGzYS.js} +171 -12
  33. package/dist/{executor-BMPipFVA.js → executor-BWmAgSyi.js} +40 -11
  34. package/dist/{media-BepyEUNm.js → history-IjdmO_r6.js} +1 -85
  35. package/dist/instrumentation.js +2 -2
  36. package/dist/lineage-D-5jm_oj.js +37 -0
  37. package/dist/{logging-CQjlDQYX.js → logging-DPLEa8Bn.js} +1 -1
  38. package/dist/media-BAHvgkok.js +85 -0
  39. package/dist/{message-BOZEIuxy.js → message-BIHR1yRk.js} +9 -10
  40. package/dist/model-input-BPZYH8Nd.js +82 -0
  41. package/dist/nitro.d.ts +1 -1
  42. package/dist/nitro.js +17 -9
  43. package/dist/{oauth-callback-server-V_DuMuNX.js → oauth-callback-server-R7qvSzFG.js} +2 -2
  44. package/dist/{plugins-HYh_JOdw.js → plugins-CBW2Prb_.js} +1 -1
  45. package/dist/{projection-B08mfi0u.js → projection-DEdP1q6f.js} +261 -36
  46. package/dist/{prompt-BlutWLNt.js → prompt-4M98h_tC.js} +4 -4
  47. package/dist/{registry-BDWgCJDf.js → registry-BTKmKM-r.js} +3 -3
  48. package/dist/{resolve-2Z_o_SsI.js → resolve-B8hXNVZ3.js} +3 -3
  49. package/dist/{result-CAujiaci.js → result-g-XAaOj6.js} +158 -69
  50. package/dist/{runner-D2Chc02N.js → runner-BlPSA5A8.js} +9 -9
  51. package/dist/{sandbox-egress-signals-CFoJduFj.js → sandbox-egress-signals-Pai-MzEY.js} +1 -1
  52. package/dist/{schema-Bqa5NbcP.js → schema-BNnY_trV.js} +47 -7
  53. package/dist/{schema-Ce2XCS7O.d.ts → schema-DbuWR-DN.d.ts} +663 -346
  54. package/dist/{service-account-C9kRQEb_.js → service-account-9OLNQMyz.js} +4 -4
  55. package/dist/{service-account-CERfXEVU.js → service-account-BYGZ08DQ.js} +3 -3
  56. package/dist/session-stop-2XJrcNCy.js +3356 -0
  57. package/dist/{skills-B0m1nZ_j.js → skills-DpBQoeHV.js} +3 -3
  58. package/dist/slack-conversation-unfurl-BcDIWo67.js +370 -0
  59. package/dist/spawn-09GssFod.js +73 -0
  60. package/dist/state-Cufq0_rH.js +132 -0
  61. package/dist/{user-input-request-CXNIov9n.js → statuses-B8mUfghF.js} +30 -25
  62. package/dist/{stop-BCH9VNGf.js → stop-U7iUrR1g.js} +6011 -5773
  63. package/dist/{store-B59rOYbS.js → store-BHiaHCQu.js} +24 -4
  64. package/dist/{store-m5bmdmsP.js → store-CSgUTMdv.js} +10 -10
  65. package/dist/{task-queue-N0kuCknH.js → task-queue-bMNq0clp.js} +4 -4
  66. package/dist/{task-runner-COOwR8qm.js → task-runner-B__rxwxU.js} +10 -10
  67. package/dist/{thread-context-Cd44z_W5.js → thread-context-d0ceWbVT.js} +18 -18
  68. package/dist/{turn-session-routing-BlCtVFRN.js → turn-session-routing-BVZHBFCF.js} +5 -5
  69. package/dist/turn-user-message-BEw7acTP.js +355 -0
  70. package/dist/users-BK3dbxZL.js +424 -0
  71. package/dist/{validation-Ba2OcUse.js → validation-BDVJjO2E.js} +1 -1
  72. package/dist/{version-KNDzIAh6.js → version-DQgZoQ3D.js} +1 -1
  73. package/dist/version.js +1 -1
  74. package/dist/{viewer-BPpuN2f9.js → viewer-CAWfFo29.js} +25 -54
  75. package/dist/{warmup-Bskrwmk1.js → warmup-9ySPacF9.js} +1137 -143
  76. package/dist/{worker-B1skZlit.js → worker-D8jJO-WO.js} +8 -7
  77. package/migrations/0104_code_change_draft.sql +1 -0
  78. package/migrations/0105_attachment_uploads.sql +14 -0
  79. package/migrations/0106_conversation_agent_config.sql +1 -0
  80. package/migrations/meta/0104_snapshot.json +4516 -0
  81. package/migrations/meta/0105_snapshot.json +4611 -0
  82. package/migrations/meta/0106_snapshot.json +4617 -0
  83. package/migrations/meta/_journal.json +21 -0
  84. package/package.json +4 -4
  85. package/dist/attempt-selection-ClP3MMPr.js +0 -61
  86. package/dist/locks-D-0h111u.js +0 -48
  87. package/dist/notification-gusCgdQ6.js +0 -1284
  88. package/dist/prompt-input-Dxn8cDC0.js +0 -1424
  89. package/dist/session-stop-B-I1rAS1.js +0 -181
  90. package/dist/spawn-CwMjRRtn.js +0 -80
  91. package/dist/turn-cancel-DDu8TOwt.js +0 -201
  92. package/dist/turn-user-message-ygLG3ylQ.js +0 -641
  93. package/dist/turn-wake-DmQec4AG.js +0 -161
  94. package/dist/{oauth-relay-CsfIazeF.js → oauth-relay-DRzq73b6.js} +1 -1
@@ -1,6 +1,6 @@
1
1
  import { _ as withScope } from "./sentry-BRTJqumy.js";
2
- import "./config-Dj9M_nqB.js";
3
- import { h as logWarn, p as logException } from "./logging-CQjlDQYX.js";
2
+ import "./config-CAXIpWQb.js";
3
+ import { h as logWarn, p as logException } from "./logging-DPLEa8Bn.js";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
5
5
  import { sql } from "drizzle-orm";
6
6
  import { bigint, boolean, check, date, doublePrecision, foreignKey, index, integer, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
@@ -121,6 +121,7 @@ const juniorConversations = pgTable("junior_conversations", {
121
121
  lastEnqueuedAt: timestamptz("last_enqueued_at"),
122
122
  parentConversationId: text("parent_conversation_id").references(() => juniorConversations.conversationId),
123
123
  kind: text("kind").$type(),
124
+ agentConfig: jsonb("agent_config_json").$type(),
124
125
  archivedAt: timestamptz("archived_at"),
125
126
  legacyChildArchivedAt: timestamptz("child_archived_at"),
126
127
  forkedFromConversationId: text("forked_from_conversation_id").references(() => juniorConversations.conversationId, { onDelete: "set null" }),
@@ -180,6 +181,28 @@ const juniorAttachments = pgTable("junior_attachments", {
180
181
  index("junior_attachments_provider_idx").on(table.conversationId, table.provider, table.providerId),
181
182
  index("junior_attachments_gc_idx").on(table.storageProvider, table.deleteRequestedAt, table.createdAt)
182
183
  ]);
184
+ /**
185
+ * Browser uploads that wait for a web Message.
186
+ *
187
+ * A row binds one object key to the viewer, Conversation, and Message
188
+ * idempotency key that asked for it. A Message turns the upload into a
189
+ * `junior_attachments` row with the same id. Cleanup deletes the object of an
190
+ * upload that no Message used.
191
+ */
192
+ const juniorAttachmentUploads = pgTable("junior_attachment_uploads", {
193
+ id: text("id").primaryKey(),
194
+ /** No foreign key: a new Conversation has no row until its first send. */
195
+ conversationId: text("conversation_id").notNull(),
196
+ userId: text("user_id").notNull(),
197
+ idempotencyKey: text("idempotency_key").notNull(),
198
+ storageProvider: text("storage_provider").notNull(),
199
+ storageKey: text("storage_key").notNull(),
200
+ filename: text("filename").notNull(),
201
+ contentType: text("content_type").notNull(),
202
+ /** Size that the browser declared and the upload target allows. */
203
+ bytes: integer("bytes").notNull(),
204
+ createdAt: timestamptz("created_at").notNull()
205
+ }, (table) => [index("junior_attachment_uploads_gc_idx").on(table.storageProvider, table.createdAt)]);
183
206
  // src/db/schema/code.ts
184
207
  /** Repository known to Junior through an installed code plugin. */
185
208
  const juniorCodeRepositories = pgTable("junior_code_repositories", {
@@ -195,6 +218,7 @@ const juniorCodeChanges = pgTable("junior_code_changes", {
195
218
  id: uuid("id").primaryKey(),
196
219
  closedAt: timestamptz("closed_at"),
197
220
  conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
221
+ draft: boolean("draft").notNull().default(false),
198
222
  /** Latest push, review, or comment by a person, from the code plugin. */
199
223
  lastActivityAt: timestamptz("last_activity_at"),
200
224
  mergedAt: timestamptz("merged_at"),
@@ -753,6 +777,7 @@ const juniorSnapshots = pgTable("junior_snapshots", {
753
777
  // src/db/schema.ts
754
778
  const juniorSqlSchema = {
755
779
  juniorArtifacts,
780
+ juniorAttachmentUploads,
756
781
  juniorAttachments,
757
782
  juniorCodeChanges,
758
783
  juniorCodeRepositories,
@@ -901,9 +926,18 @@ const POOL_MAX = 10;
901
926
  function toWebSocketError(error, failure) {
902
927
  if (error instanceof Error) return error;
903
928
  const event = error ?? {};
904
- const reason = typeof event.message === "string" && event.message || event.error instanceof Error && event.error.message || typeof event.type === "string" && event.type || String(error);
929
+ const cause = event.error instanceof Error ? event.error : void 0;
930
+ const reason = typeof event.message === "string" && event.message || cause?.message || cause && `${cause.name} (no message)` || typeof event.type === "string" && event.type || String(error);
905
931
  return new Error(`WebSocket ${failure}: ${reason}`, event.error === void 0 ? void 0 : { cause: event.error });
906
932
  }
933
+ function warnWebSocketFailure(name, error, failure) {
934
+ const reported = toWebSocketError(error, failure);
935
+ logWarn(name, {
936
+ "app.db.driver": "neon",
937
+ "error.type": reported.name,
938
+ "exception.message": reported.message
939
+ });
940
+ }
907
941
  /**
908
942
  * Sends a pool query over Neon's SQL-over-HTTP endpoint when no idle
909
943
  * WebSocket client is free.
@@ -959,7 +993,7 @@ var OverflowPool = class extends Pool {
959
993
  client.release();
960
994
  return;
961
995
  }
962
- logException(toWebSocketError(error, "connect failed"), "db.pool.client.connect_failed", { "app.db.driver": "neon" });
996
+ warnWebSocketFailure("db.pool.client.connect_failed", error, "connect failed");
963
997
  });
964
998
  }
965
999
  /** Keep every pool query in `callback` on WebSocket. */
@@ -1120,12 +1154,7 @@ function createNeonJuniorSqlExecutor(args) {
1120
1154
  dispatcher
1121
1155
  });
1122
1156
  pool.on("error", (error) => {
1123
- const failure = toWebSocketError(error, "idle client failed");
1124
- logWarn("db.pool.client.failed", {
1125
- "app.db.driver": "neon",
1126
- "error.type": failure.name,
1127
- "exception.message": failure.message
1128
- });
1157
+ warnWebSocketFailure("db.pool.client.failed", error, "idle client failed");
1129
1158
  });
1130
1159
  if (onInfo) forwardInfoMessages(pool, onInfo);
1131
1160
  return new NeonExecutor(pool, dispatcher);
@@ -1265,4 +1294,4 @@ function createJuniorSqlExecutor(args) {
1265
1294
  statementTimeoutMs
1266
1295
  });
1267
1296
  }
1268
- export { juniorConversations as A, isUserInstruction as C, juniorCodeChanges as D, juniorConversationAnnotations as E, juniorUsers as M, juniorDestinations as N, juniorCodeRepositories as O, juniorArtifacts as P, juniorConversationMetrics as S, juniorApiTokens as T, juniorConversationReadPositions as _, juniorPushSubscriptions as a, juniorConversationBriefs as b, juniorReviewItemSlackCards as c, juniorAutomationVersions as d, juniorAutomations as f, juniorAgentInvocations as g, juniorAgentBindings as h, juniorWorkspaces as i, juniorIdentities as j, juniorAttachments as k, juniorReviewItems as l, juniorLocationConfigurations as m, juniorSnapshots as n, juniorReviewItemAssignees as o, juniorStats as p, juniorWorkspaceRepos as r, juniorReviewItemConversations as s, createJuniorSqlExecutor as t, juniorAutomationRuns as u, juniorConversationParticipants as v, juniorConversationEvents as w, CONVERSATION_METRICS as x, juniorConversationBindings as y };
1297
+ export { juniorAttachments as A, isUserInstruction as C, juniorCodeChanges as D, juniorConversationAnnotations as E, juniorArtifacts as F, juniorIdentities as M, juniorUsers as N, juniorCodeRepositories as O, juniorDestinations as P, juniorConversationMetrics as S, juniorApiTokens as T, juniorConversationReadPositions as _, juniorPushSubscriptions as a, juniorConversationBriefs as b, juniorReviewItemSlackCards as c, juniorAutomationVersions as d, juniorAutomations as f, juniorAgentInvocations as g, juniorAgentBindings as h, juniorWorkspaces as i, juniorConversations as j, juniorAttachmentUploads as k, juniorReviewItems as l, juniorLocationConfigurations as m, juniorSnapshots as n, juniorReviewItemAssignees as o, juniorStats as p, juniorWorkspaceRepos as r, juniorReviewItemConversations as s, createJuniorSqlExecutor as t, juniorAutomationRuns as u, juniorConversationParticipants as v, juniorConversationEvents as w, CONVERSATION_METRICS as x, juniorConversationBindings as y };
@@ -555,88 +555,4 @@ const newConversationEventSchema = z.object({
555
555
  idempotencyKey: z.string().min(1).optional(),
556
556
  createdAtMs: z.number().finite()
557
557
  }).strict();
558
- // src/chat/attachments/media.ts
559
- const INPUT_IMAGE_TYPES = [
560
- "image/png",
561
- "image/jpeg",
562
- "image/gif",
563
- "image/webp"
564
- ];
565
- /** Video types that browsers play in a `<video>` element. */
566
- const INLINE_VIDEO_TYPES = ["video/mp4", "video/webm"];
567
- /** Leading bytes of each accepted image type. `null` matches any byte. */
568
- const IMAGE_SIGNATURES = [
569
- {
570
- mediaType: "image/png",
571
- bytes: [
572
- 137,
573
- 80,
574
- 78,
575
- 71,
576
- 13,
577
- 10,
578
- 26,
579
- 10
580
- ]
581
- },
582
- {
583
- mediaType: "image/jpeg",
584
- bytes: [
585
- 255,
586
- 216,
587
- 255
588
- ]
589
- },
590
- {
591
- mediaType: "image/gif",
592
- bytes: [
593
- 71,
594
- 73,
595
- 70,
596
- 56,
597
- 55,
598
- 97
599
- ]
600
- },
601
- {
602
- mediaType: "image/gif",
603
- bytes: [
604
- 71,
605
- 73,
606
- 70,
607
- 56,
608
- 57,
609
- 97
610
- ]
611
- },
612
- {
613
- mediaType: "image/webp",
614
- bytes: [
615
- 82,
616
- 73,
617
- 70,
618
- 70,
619
- null,
620
- null,
621
- null,
622
- null,
623
- 87,
624
- 69,
625
- 66,
626
- 80
627
- ]
628
- }
629
- ];
630
- /**
631
- * Detect an accepted image type from file bytes. Use this instead of a file
632
- * name or declared content type, which can be wrong.
633
- */
634
- function detectImageMediaType(data) {
635
- return IMAGE_SIGNATURES.find(({ bytes }) => data.length >= bytes.length && bytes.every((byte, index) => byte === null || data[index] === byte))?.mediaType;
636
- }
637
- /** Report whether a media type is a raster image accepted by vision models. */
638
- function isVisionImageMediaType(mediaType) {
639
- const normalized = mediaType.split(";", 1)[0]?.trim().toLowerCase();
640
- return normalized ? INPUT_IMAGE_TYPES.some((type) => type === normalized) : false;
641
- }
642
- export { instructionProvenanceFor as _, KNOWN_CONVERSATION_EVENT_TYPES as a, conversationTurnFailureCodeSchema as c, historyReplacementSchema as d, newConversationEventSchema as f, instructionActors as g, contextProvenance as h, isVisionImageMediaType as i, conversationTurnFailureReasonSchema as l, agentInstructionProvenance as m, INPUT_IMAGE_TYPES as n, agentHistoryItemSchema as o, encodeHistoryPayload as p, detectImageMediaType as r, conversationEventDataSchema as s, INLINE_VIDEO_TYPES as t, decodeStoredConversationEvent as u, sameActorIdentity as v, usageSchema as y };
558
+ export { conversationTurnFailureReasonSchema as a, newConversationEventSchema as c, contextProvenance as d, instructionActors as f, usageSchema as h, conversationTurnFailureCodeSchema as i, encodeHistoryPayload as l, sameActorIdentity as m, agentHistoryItemSchema as n, decodeStoredConversationEvent as o, instructionProvenanceFor as p, conversationEventDataSchema as r, historyReplacementSchema as s, KNOWN_CONVERSATION_EVENT_TYPES as t, agentInstructionProvenance as u };
@@ -1,6 +1,6 @@
1
1
  import { a as getClient, c as init, i as getActiveSpan, o as getGlobalScope, p as spanToJSON, s as getTraceData } from "./sentry-BRTJqumy.js";
2
- import { B as getDeploymentTelemetryAttributes, z as getDeploymentServiceVersion } from "./logging-CQjlDQYX.js";
3
- import { n as getCurrentConversationPrivacy } from "./conversation-privacy-DI29jbZV.js";
2
+ import { B as getDeploymentTelemetryAttributes, z as getDeploymentServiceVersion } from "./logging-DPLEa8Bn.js";
3
+ import { n as getCurrentConversationPrivacy } from "./conversation-privacy-DUgtRkf8.js";
4
4
  import { n as redactSandboxEgressProxyPath } from "./proxy-path-BHYoKZdq.js";
5
5
  import { t as consumePrivateTraceResultMarker } from "./private-trace-result-CE7_lEdq.js";
6
6
  import { n as promoteHttpRouteName, r as routeNameMiddleware, t as nameRequestRoute } from "./sentry-route-name-BhwWnfqj.js";
@@ -0,0 +1,37 @@
1
+ import { D as conversationKindFromRow, o as getDb } from "./db-COYOGzYS.js";
2
+ import { j as juniorConversations } from "./executor-BWmAgSyi.js";
3
+ import { desc, eq, sql } from "drizzle-orm";
4
+ // src/chat/conversations/lineage.ts
5
+ /**
6
+ * Read the parent chain of a Conversation in one query, root first, with the
7
+ * Conversation last. Returns an empty list when the Conversation is missing.
8
+ *
9
+ * The chain stops at a parent that is missing or that is already in the
10
+ * chain. Then the first entry still has a `parentConversationId`, so callers
11
+ * can tell a broken chain from one that ends at a root.
12
+ */
13
+ async function readConversationLineage(conversationId) {
14
+ const lineage = sql`(
15
+ with recursive lineage(conversation_id, parent_conversation_id, depth, path) as (
16
+ select selected.conversation_id, selected.parent_conversation_id, 0, array[selected.conversation_id]
17
+ from junior_conversations selected
18
+ where selected.conversation_id = ${conversationId}
19
+ union all
20
+ select parent.conversation_id, parent.parent_conversation_id, lineage.depth + 1, lineage.path || parent.conversation_id
21
+ from junior_conversations parent
22
+ join lineage on parent.conversation_id = lineage.parent_conversation_id
23
+ where parent.conversation_id <> all(lineage.path)
24
+ )
25
+ select conversation_id, depth from lineage
26
+ ) conversation_lineage`;
27
+ return (await getDb().select({
28
+ conversationId: juniorConversations.conversationId,
29
+ kind: juniorConversations.kind,
30
+ parentConversationId: juniorConversations.parentConversationId
31
+ }).from(juniorConversations).innerJoin(lineage, eq(sql`conversation_lineage.conversation_id`, juniorConversations.conversationId)).orderBy(desc(sql`conversation_lineage.depth`))).map((row) => ({
32
+ conversationId: row.conversationId,
33
+ kind: conversationKindFromRow(row),
34
+ ...row.parentConversationId ? { parentConversationId: row.parentConversationId } : void 0
35
+ }));
36
+ }
37
+ export { readConversationLineage as t };
@@ -1,5 +1,5 @@
1
1
  import { _ as withScope, d as setTag, f as setUser, h as startSpan, i as getActiveSpan, l as logger, n as captureMessage, p as spanToJSON, s as getTraceData, t as captureException } from "./sentry-BRTJqumy.js";
2
- import { t as JUNIOR_VERSION } from "./version-KNDzIAh6.js";
2
+ import { t as JUNIOR_VERSION } from "./version-DQgZoQ3D.js";
3
3
  import path from "node:path";
4
4
  import { styleText } from "node:util";
5
5
  import { ConfigError, configureSync, getConfig, getLogger } from "@logtape/logtape";
@@ -0,0 +1,85 @@
1
+ // src/chat/attachments/media.ts
2
+ const INPUT_IMAGE_TYPES = [
3
+ "image/png",
4
+ "image/jpeg",
5
+ "image/gif",
6
+ "image/webp"
7
+ ];
8
+ /** Video types that browsers play in a `<video>` element. */
9
+ const INLINE_VIDEO_TYPES = ["video/mp4", "video/webm"];
10
+ /** Leading bytes of each accepted image type. `null` matches any byte. */
11
+ const IMAGE_SIGNATURES = [
12
+ {
13
+ mediaType: "image/png",
14
+ bytes: [
15
+ 137,
16
+ 80,
17
+ 78,
18
+ 71,
19
+ 13,
20
+ 10,
21
+ 26,
22
+ 10
23
+ ]
24
+ },
25
+ {
26
+ mediaType: "image/jpeg",
27
+ bytes: [
28
+ 255,
29
+ 216,
30
+ 255
31
+ ]
32
+ },
33
+ {
34
+ mediaType: "image/gif",
35
+ bytes: [
36
+ 71,
37
+ 73,
38
+ 70,
39
+ 56,
40
+ 55,
41
+ 97
42
+ ]
43
+ },
44
+ {
45
+ mediaType: "image/gif",
46
+ bytes: [
47
+ 71,
48
+ 73,
49
+ 70,
50
+ 56,
51
+ 57,
52
+ 97
53
+ ]
54
+ },
55
+ {
56
+ mediaType: "image/webp",
57
+ bytes: [
58
+ 82,
59
+ 73,
60
+ 70,
61
+ 70,
62
+ null,
63
+ null,
64
+ null,
65
+ null,
66
+ 87,
67
+ 69,
68
+ 66,
69
+ 80
70
+ ]
71
+ }
72
+ ];
73
+ /**
74
+ * Detect an accepted image type from file bytes. Use this instead of a file
75
+ * name or declared content type, which can be wrong.
76
+ */
77
+ function detectImageMediaType(data) {
78
+ return IMAGE_SIGNATURES.find(({ bytes }) => data.length >= bytes.length && bytes.every((byte, index) => byte === null || data[index] === byte))?.mediaType;
79
+ }
80
+ /** Report whether a media type is a raster image accepted by vision models. */
81
+ function isVisionImageMediaType(mediaType) {
82
+ const normalized = mediaType.split(";", 1)[0]?.trim().toLowerCase();
83
+ return normalized ? INPUT_IMAGE_TYPES.some((type) => type === normalized) : false;
84
+ }
85
+ export { isVisionImageMediaType as i, INPUT_IMAGE_TYPES as n, detectImageMediaType as r, INLINE_VIDEO_TYPES as t };
@@ -1,13 +1,12 @@
1
1
  import { v as __exportAll } from "./sentry-BRTJqumy.js";
2
- import { go as readConversationAccessFromSql, po as canAccessConversation, zn as renderUntrustedTag } from "./projection-B08mfi0u.js";
3
- import { n as botConfig } from "./config-Dj9M_nqB.js";
4
- import { M as SYSTEM_IDENTITY_ID, a as getConversationStore, o as getDb } from "./db-Br0tfAo7.js";
5
- import { Ft as actorFromRun, It as toolInvocationDestination } from "./agent-runner-CneTquAE.js";
6
- import { I as findChildAgentConversationId, M as AgentMessagePausedError, O as createAgentInvocationForMessage, P as AgentMessageTargetError, x as enqueueAgentInvocation } from "./warmup-Bskrwmk1.js";
7
- import { C as getActiveAgentInvocationForConversation, E as getLatestAgentInvocationForConversation, W as PARENT_AGENT_TARGET } from "./turn-user-message-ygLG3ylQ.js";
8
- import { b as postAutomatedTurnLimitNoticeForConversation, t as EVENT_WAIT_MS, w as admitAutomatedTurn } from "./notification-gusCgdQ6.js";
9
- import { r as appendAndEnqueueInboundMessage } from "./store-B59rOYbS.js";
10
- import { a as enqueueAgentMessageToParent } from "./result-CAujiaci.js";
2
+ import { Jn as renderUntrustedTag, Mo as readConversationAccessFromSql, ko as canAccessConversation } from "./projection-DEdP1q6f.js";
3
+ import { n as botConfig } from "./config-CAXIpWQb.js";
4
+ import { a as getConversationStore, j as SYSTEM_IDENTITY_ID, o as getDb } from "./db-COYOGzYS.js";
5
+ import { Mt as actorFromRun, Nt as toolInvocationDestination } from "./agent-runner-Ciet8_nn.js";
6
+ import { M as EVENT_WAIT_MS, Z as postAutomatedTurnLimitNoticeForConversation, tt as admitAutomatedTurn } from "./session-stop-2XJrcNCy.js";
7
+ import { A as readChildConversationSender, H as enqueueAgentInvocation, Z as createAgentInvocationForMessage, at as findChildAgentConversationId, g as getActiveAgentInvocationForConversation, lt as PARENT_AGENT_TARGET, rt as AgentMessageTargetError, tt as AgentMessagePausedError, y as getLatestAgentInvocationForConversation } from "./warmup-9ySPacF9.js";
8
+ import { r as appendAndEnqueueInboundMessage } from "./store-BHiaHCQu.js";
9
+ import { a as enqueueAgentMessageToParent } from "./result-g-XAaOj6.js";
11
10
  // src/chat/agent-invocations/top-level-message.ts
12
11
  const AGENT_MESSAGE_EVENT_NAMESPACE = "junior";
13
12
  /** Event type of a message from another top-level agent. */
@@ -116,7 +115,7 @@ function bindMessageAgent(run, options) {
116
115
  call.signal?.throwIfAborted();
117
116
  const queue = typeof options.queue === "function" ? options.queue() : options.queue;
118
117
  if (input.to === "parent") {
119
- const sender = await getActiveAgentInvocationForConversation(run.conversationId) ?? await getLatestAgentInvocationForConversation(run.conversationId);
118
+ const sender = await getActiveAgentInvocationForConversation(run.conversationId) ?? await getLatestAgentInvocationForConversation(run.conversationId) ?? await readChildConversationSender(run.conversationId);
120
119
  if (!sender) throw new AgentMessageTargetError("This conversation has no parent agent");
121
120
  await enqueueAgentMessageToParent({
122
121
  actor,
@@ -0,0 +1,82 @@
1
+ import { v as __exportAll } from "./sentry-BRTJqumy.js";
2
+ import { s as getSqlExecutor } from "./db-COYOGzYS.js";
3
+ import { gt as readLiveAttachment } from "./agent-runner-Ciet8_nn.js";
4
+ import { i as isVisionImageMediaType, r as detectImageMediaType } from "./media-BAHvgkok.js";
5
+ // src/chat/attachments/model-input.ts
6
+ var model_input_exports = /* @__PURE__ */ __exportAll({
7
+ MAX_MODEL_ATTACHMENTS: () => 3,
8
+ MAX_MODEL_ATTACHMENT_BYTES: () => MAX_MODEL_ATTACHMENT_BYTES,
9
+ buildStoredAttachmentPromptText: () => buildStoredAttachmentPromptText,
10
+ loadInputAttachments: () => loadInputAttachments
11
+ });
12
+ /** Largest file that Slack and web send to the model in the prompt. */
13
+ const MAX_MODEL_ATTACHMENT_BYTES = 5242880;
14
+ /** Tell the model how to read a stored file that the prompt does not carry. */
15
+ function buildStoredAttachmentPromptText(args) {
16
+ return [
17
+ "<attachment>",
18
+ `filename: ${args.filename ?? "unnamed"}`,
19
+ `media_type: ${args.mediaType}`,
20
+ `attachment_id: ${args.attachmentId}`,
21
+ "Use loadAttachment with this id to access the original file.",
22
+ "</attachment>"
23
+ ].join("\n");
24
+ }
25
+ async function readStoredBytes(args) {
26
+ const record = await readLiveAttachment({
27
+ attachmentId: args.attachment.id,
28
+ conversationId: args.conversationId,
29
+ db: getSqlExecutor()
30
+ });
31
+ if (!record || record.storageProvider !== args.storage.provider) throw new Error("Input attachment is no longer available.");
32
+ const body = await args.storage.get(record.storageKey);
33
+ if (!body) throw new Error("Input attachment contents are unavailable.");
34
+ const data = Buffer.from(await new Response(body).arrayBuffer());
35
+ if (data.byteLength !== record.bytes) throw new Error("Input attachment size does not match stored metadata.");
36
+ return data;
37
+ }
38
+ /**
39
+ * Build model input for the stored files of one web Message.
40
+ *
41
+ * Like Slack, the first images within the size limit go to the model as
42
+ * images. Every other file gets a note that points to `loadAttachment`.
43
+ */
44
+ async function loadInputAttachments(args) {
45
+ let images = 0;
46
+ return await Promise.all(args.attachments.map(async (attachment) => {
47
+ const base = {
48
+ attachmentId: attachment.id,
49
+ filename: attachment.filename,
50
+ mediaType: attachment.contentType
51
+ };
52
+ if (!(isVisionImageMediaType(attachment.contentType) && attachment.bytes <= 5242880 && images < 3)) return {
53
+ ...base,
54
+ promptText: buildStoredAttachmentPromptText({
55
+ attachmentId: attachment.id,
56
+ filename: attachment.filename,
57
+ mediaType: attachment.contentType
58
+ })
59
+ };
60
+ images += 1;
61
+ const data = await readStoredBytes({
62
+ attachment,
63
+ conversationId: args.conversationId,
64
+ storage: args.storage
65
+ });
66
+ const mediaType = detectImageMediaType(data);
67
+ if (!mediaType) return {
68
+ ...base,
69
+ promptText: buildStoredAttachmentPromptText({
70
+ attachmentId: attachment.id,
71
+ filename: attachment.filename,
72
+ mediaType: attachment.contentType
73
+ })
74
+ };
75
+ return {
76
+ ...base,
77
+ data,
78
+ mediaType
79
+ };
80
+ }));
81
+ }
82
+ export { buildStoredAttachmentPromptText as n, model_input_exports as r, MAX_MODEL_ATTACHMENT_BYTES as t };
package/dist/nitro.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as JuniorDashboardOptions } from "./app-BJojZ7HL.js";
1
+ import { i as JuniorDashboardOptions } from "./app--ky-Eu33.js";
2
2
  import { n as JuniorPluginSet } from "./plugins-B_0Cr0MO.js";
3
3
  import { withSentryConfig as withSentryConfig$1 } from "@sentry/nitro";
4
4
  type SentryNitroConfig = Parameters<typeof withSentryConfig$1>[0];
package/dist/nitro.js CHANGED
@@ -1,8 +1,8 @@
1
- import { A as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, D as JUNIOR_AUTO_ARCHIVE_CRON_SCHEDULE, F as JUNIOR_RETENTION_CRON_SCHEDULE, I as JUNIOR_RETENTION_ROUTE, L as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, M as JUNIOR_HEARTBEAT_CRON_SCHEDULE, N as JUNIOR_HEARTBEAT_ROUTE, O as JUNIOR_AUTO_ARCHIVE_ROUTE, P as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, j as JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE, k as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE, z as getDeploymentServiceVersion } from "./logging-CQjlDQYX.js";
1
+ import { A as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, D as JUNIOR_AUTO_ARCHIVE_CRON_SCHEDULE, F as JUNIOR_RETENTION_CRON_SCHEDULE, I as JUNIOR_RETENTION_ROUTE, L as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, M as JUNIOR_HEARTBEAT_CRON_SCHEDULE, N as JUNIOR_HEARTBEAT_ROUTE, O as JUNIOR_AUTO_ARCHIVE_ROUTE, P as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, j as JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE, k as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE, z as getDeploymentServiceVersion } from "./logging-DPLEa8Bn.js";
2
2
  import { d as resolvePackageDir, t as discoverInstalledPluginPackageContent, u as isValidPackageName } from "./package-discovery-DJhGdS4c.js";
3
- import { a as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, h as CACHE_WARMUP_QUEUE_TOPIC, t as BACKGROUND_COMPACTION_QUEUE_TOPIC, u as resolveConversationWorkQueueTopic } from "./background-compaction-queue-CwfJy3Cd.js";
4
- import { a as pluginRuntimeRegistrationsFromPluginSet, r as pluginCatalogConfigFromPluginSet } from "./plugins-HYh_JOdw.js";
5
- import { t as PLUGIN_TASK_QUEUE_TOPIC } from "./task-queue-N0kuCknH.js";
3
+ import { a as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, h as CACHE_WARMUP_QUEUE_TOPIC, t as BACKGROUND_COMPACTION_QUEUE_TOPIC, u as resolveConversationWorkQueueTopic } from "./background-compaction-queue-CnimvRdk.js";
4
+ import { t as PLUGIN_TASK_QUEUE_TOPIC } from "./task-queue-bMNq0clp.js";
5
+ import { a as pluginRuntimeRegistrationsFromPluginSet, r as pluginCatalogConfigFromPluginSet } from "./plugins-CBW2Prb_.js";
6
6
  import { n as loadPluginSetFromModule, r as resolvePluginModule } from "./plugin-module-Cf5gVPWP.js";
7
7
  import path from "node:path";
8
8
  import { cpSync, existsSync, mkdirSync, readdirSync, statSync } from "node:fs";
@@ -14,12 +14,14 @@ import { sentryOrchestrionPlugin } from "@sentry/server-utils/orchestrion/rollup
14
14
  * bundling.
15
15
  *
16
16
  * pi-ai registers API providers via a top-level side-effect in
17
- * register-builtins.js. Nitro's default moduleSideEffects whitelist only
18
- * includes unenv polyfills, so rolldown tree-shakes the registration call
19
- * and the apiProviderRegistry Map stays empty at runtime.
17
+ * register-builtins.js. Older Nitro builds set a moduleSideEffects allowlist
18
+ * with only unenv polyfills, so rolldown tree-shook the registration call and
19
+ * the apiProviderRegistry Map stayed empty at runtime
20
+ * (https://github.com/nitrojs/nitro/issues/4085).
20
21
  *
21
- * TODO(upstream): Track https://github.com/nitrojs/nitro/issues/XXXX for
22
- * native moduleSideEffects configuration support.
22
+ * TODO(dcramer): Remove this override when a production build shows that
23
+ * pi-ai providers register without it. nitrojs/nitro#4164 removed the
24
+ * allowlist, and every Nitro version that Junior supports includes that fix.
23
25
  */
24
26
  function applyRolldownTreeshakeWorkaround(nitro) {
25
27
  nitro.options.rolldownConfig = {
@@ -260,11 +262,17 @@ function configureVercelDeployment(nitro, options) {
260
262
  addQueueTrigger(JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, BACKGROUND_COMPACTION_QUEUE_TOPIC);
261
263
  return defaultMaxDuration;
262
264
  }
265
+ function dropRoutedServerEntry(nitro) {
266
+ const serverEntry = nitro.options.serverEntry;
267
+ if (!serverEntry) return;
268
+ if (Object.values(nitro.options.routes).some((route) => (typeof route === "string" ? route : route.handler) === serverEntry.handler)) nitro.options.serverEntry = false;
269
+ }
263
270
  /** Nitro module that configures deployment wiring and copies app/plugin content into the Vercel build output. */
264
271
  function juniorNitro(options = {}) {
265
272
  return { nitro: { setup(nitro) {
266
273
  const cwd = path.resolve(options.cwd ?? nitro.options.rootDir ?? process.cwd());
267
274
  const functionMaxDurationSeconds = configureVercelDeployment(nitro, options);
275
+ dropRoutedServerEntry(nitro);
268
276
  applyRolldownTreeshakeWorkaround(nitro);
269
277
  if (dashboardEnabled(options.dashboard)) nitro.options.publicAssets.push({
270
278
  baseURL: "/_junior/dashboard/assets",
@@ -1,5 +1,5 @@
1
- import { Hn as createUserTokenStore } from "./projection-B08mfi0u.js";
2
- import { a as GET, n as syncLocalOAuthCredential, r as GET$1 } from "./credential-sync-Blhx4_xf.js";
1
+ import { Zn as createUserTokenStore } from "./projection-DEdP1q6f.js";
2
+ import { a as GET, n as syncLocalOAuthCredential, r as GET$1 } from "./credential-sync-RX24Y8aY.js";
3
3
  import { createServer } from "node:http";
4
4
  // src/chat/local/oauth-callback-server.ts
5
5
  const LOCAL_OAUTH_TIMEOUT_MS = 6e5;
@@ -89,7 +89,7 @@ function pluginCatalogConfigFromEnv(env = process.env) {
89
89
  }
90
90
  /** Return registrations that expose in-process runtime code. */
91
91
  function pluginRuntimeRegistrationsFromPluginSet(pluginSet) {
92
- return pluginSet?.registrations.filter((plugin) => plugin.hooks || plugin.tasks || plugin.userPages?.length) ?? [];
92
+ return pluginSet?.registrations.filter((plugin) => plugin.hooks || plugin.tasks || plugin.userPages?.length || plugin.objectLinks?.length) ?? [];
93
93
  }
94
94
  /** Return registrations that expose host CLI commands. */
95
95
  function pluginCliRegistrationsFromPluginSet(pluginSet) {