@sentry/junior 0.311.0 → 0.312.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/{adapter-context-G2M0y6rP.js → adapter-context-BRjEWRy1.js} +2 -2
- package/dist/{adapter-B1wujchl.js → adapter-iIq7ihf7.js} +1 -1
- package/dist/{admin-DCiBhUT1.js → admin-DhInw5K9.js} +1 -1
- package/dist/{agent-runner-BVHPUIc8.js → agent-runner-C9iDurwX.js} +3423 -3477
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +6 -6
- package/dist/api.d.ts +2 -2
- package/dist/api.js +289 -306
- package/dist/{app-Cw5Vy6H6.d.ts → app-DRFrC8Mw.d.ts} +2 -9
- package/dist/app.d.ts +1 -1
- package/dist/app.js +338 -604
- package/dist/{background-compaction-queue-CJDnWVOJ.js → background-compaction-queue-DrKi7w3d.js} +10 -85
- package/dist/callback-mFlTUWWx.js +75 -0
- package/dist/{catalog-runtime-DMY3VV-D.js → catalog-runtime-D7xapBAX.js} +1 -1
- package/dist/channel-access-CJGfNTdn.js +221 -0
- package/dist/child-message-DcsritGf.js +179 -0
- package/dist/cli/chat.js +18 -19
- package/dist/cli/check.js +3 -3
- package/dist/cli/init.js +0 -1
- package/dist/cli/main.js +3 -7
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/run.d.ts +1 -2
- package/dist/cli/run.js +1 -2
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-BrXDQefC.js → config-kXB2Y5tl.js} +59 -27
- package/dist/{continue-in-slack-DNXSC9So.js → continue-in-slack-O6pV5004.js} +7 -8
- package/dist/{conversation-feed-DkinDu5o.js → conversation-feed-uNOv_x68.js} +74 -20
- package/dist/{conversation-privacy-DxttrKb9.js → conversation-privacy-L4ja1_W6.js} +1 -1
- package/dist/{conversation-turn-DWw7Xhdr.js → conversation-turn-CeLbHqdw.js} +31 -27
- package/dist/{credential-sync-Bk8wGb8Y.js → credential-sync-I8VBGk05.js} +16 -15
- package/dist/{projection-Cns7XwWa.js → credentialed-Cb6E2phL.js} +16308 -20732
- package/dist/{db-7ETESH44.d.ts → db-BbC5stfa.d.ts} +11 -6
- package/dist/{db-DTxzH7u5.js → db-LAyyX8tk.js} +174 -91
- package/dist/{executor-DqTiYj9S.js → executor-SCub-fAq.js} +117 -97
- package/dist/{html-B9Sl4Axb.js → html-BCZ3Xtb_.js} +6 -6
- package/dist/ingest-BDf3D50j.js +3836 -0
- package/dist/{install-Sg4ePfLl.js → install-DCFJFkC0.js} +2 -2
- package/dist/instrumentation.js +3 -3
- package/dist/{lineage-BHAMpNKr.js → lineage-B_m-4TJw.js} +2 -2
- package/dist/{stop-CYsfc0Ed.js → list-CN2QA2R9.js} +663 -442
- package/dist/{logging-FjclQsXu.js → logging-dQ9ZRGQ8.js} +1 -1
- package/dist/{schedule-BLJ476XQ.js → media-CYm1QD8T.js} +1055 -11
- package/dist/{message-CJ7_RL50.js → message-DSXGj1hM.js} +19 -26
- package/dist/{model-input-CMLh4Cwq.js → model-input--TrP9hYV.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -3
- package/dist/{oauth-callback-server-RVcbiDjL.js → oauth-callback-server-DHCZC6B4.js} +2 -2
- package/dist/{oauth-relay-Bu9kkaQu.js → oauth-relay-pPMGnDZt.js} +1 -1
- package/dist/{registry-BPwuOP2O.js → registry-CZOzddwu.js} +1 -1
- package/dist/{resolve-BK29bBry.js → resolve-cKOQ14Dh.js} +3 -3
- package/dist/result-DcvEOe1r.js +574 -0
- package/dist/result-event-type-BdIJuZxg.js +48 -0
- package/dist/{runner-BcAE-cJm.js → runner-DBfUW44l.js} +14 -16
- package/dist/{sandbox-egress-signals-C-q0go5b.js → sandbox-egress-signals-BVF_xAm1.js} +1 -1
- package/dist/{schema-DYcJeV7d.d.ts → schema-BEHKxr4I.d.ts} +166 -242
- package/dist/{schema-BLgSZXcL.js → schema-Bk9Nm2E8.js} +106 -121
- package/dist/{service-account-iJoCtkHR.js → service-account-CVYsFjty.js} +3 -3
- package/dist/{service-account-gN0zqf0S.js → service-account-Ts4ulcrV.js} +5 -5
- package/dist/{skills-BoZ80epJ.js → skills-VTnhAJWm.js} +2 -2
- package/dist/{slack-conversation-unfurl-CogYrITA.js → slack-conversation-unfurl-fuLnF1jE.js} +9 -9
- package/dist/{spawn-Dk92r7mX.js → spawn-vxAarlX5.js} +6 -5
- package/dist/start-conversation-CEn2KH1A.js +941 -0
- package/dist/{state-DH3Cmgp3.js → state-C1P3_Ywk.js} +4 -4
- package/dist/statuses-_cRJHXK7.js +150 -0
- package/dist/store-DFZaN-Ix.js +492 -0
- package/dist/task-queue-Cx4Lmjyk.js +90 -0
- package/dist/task-runner-CbTwFA6k.js +1432 -0
- package/dist/{thread-context-BW2BsQbH.js → thread-context-BkAZDTX2.js} +7 -7
- package/dist/thread-state-DhPndWi1.js +5625 -0
- package/dist/{validation-DrJd0nnq.js → validation-nIzMtAVJ.js} +1 -1
- package/dist/{task-queue-C_zldF5J.js → vercel-queue-hW90XzbG.js} +93 -172
- package/dist/{version-CNKZ8owc.js → version-Brbtz4Qf.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{warmup-BWdHew2H.js → warmup-BDA5myRK.js} +6463 -12290
- package/dist/web-message-id-C6P83ans.js +10 -0
- package/dist/{worker-t9qpu_Zx.js → worker-D63RcaVD.js} +20 -7
- package/migrations/0143_todos.sql +14 -0
- package/migrations/0144_inbox_items.sql +32 -0
- package/migrations/0145_todo_changed_by_agent.sql +1 -0
- package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
- package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
- package/migrations/0148_authorization_request_index.sql +1 -0
- package/migrations/0149_conversation_metadata.sql +10 -0
- package/migrations/0150_conversation_metadata_fill.sql +39 -0
- package/migrations/0151_conversation_search_index.sql +1 -0
- package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
- package/migrations/0153_artifact_expiry.sql +1 -0
- package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
- package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
- package/migrations/0156_conversation_kind_lead.sql +6 -0
- package/migrations/0157_conversation_lead_actor_index.sql +1 -0
- package/migrations/meta/0143_snapshot.json +6434 -0
- package/migrations/meta/0144_snapshot.json +6434 -0
- package/migrations/meta/0145_snapshot.json +6440 -0
- package/migrations/meta/0146_snapshot.json +6446 -0
- package/migrations/meta/0147_snapshot.json +6452 -0
- package/migrations/meta/0148_snapshot.json +6474 -0
- package/migrations/meta/0149_snapshot.json +6490 -0
- package/migrations/meta/0150_snapshot.json +6490 -0
- package/migrations/meta/0151_snapshot.json +6505 -0
- package/migrations/meta/0152_snapshot.json +6505 -0
- package/migrations/meta/0153_snapshot.json +6511 -0
- package/migrations/meta/0154_snapshot.json +6533 -0
- package/migrations/meta/0155_snapshot.json +6511 -0
- package/migrations/meta/0156_snapshot.json +6511 -0
- package/migrations/meta/0157_snapshot.json +6527 -0
- package/migrations/meta/_journal.json +106 -1
- package/package.json +6 -6
- package/skills/design-automation-skill/SKILL.md +108 -0
- package/dist/briefs-BDjnug6Y.js +0 -395
- package/dist/conversation-ca__NDQW.js +0 -1063
- package/dist/prompt-CDqcsDYC.js +0 -910
- package/dist/store-DmmMIrQi.js +0 -335
- package/dist/task-runner-C7oCJQIx.js +0 -294
- package/dist/turn-session-routing-Xh_2nSQe.js +0 -261
- package/dist/web-message-id-Ch5dPq-a.js +0 -306
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { a as conversationTurnFailureReasonSchema, h as usageSchema, i as conversationTurnFailureCodeSchema } from "./history-CYstOMKX.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
import { actorUserIdSchema, destinationVisibilitySchema, eventMatchFieldsSchema, eventMatchSchema, eventReachSchema, eventTypeSchema, pluginEventTypeSchema, slackDestinationSchema, taskOutcomeSchema } from "@sentry/junior-plugin-api";
|
|
3
|
+
import { actorUserIdSchema, conversationAnnotationInputSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, destinationVisibilitySchema, eventMatchFieldsSchema, eventMatchSchema, eventReachSchema, eventTypeSchema, objectFactFields, objectTypeSchema, pluginEventTypeSchema, slackDestinationSchema, taskOutcomeSchema } from "@sentry/junior-plugin-api";
|
|
4
4
|
// src/chat/automations/task.ts
|
|
5
5
|
/**
|
|
6
6
|
* The work of an Automation run. An Automation runs either a written
|
|
@@ -43,7 +43,7 @@ function automationTaskColumns(task) {
|
|
|
43
43
|
skill: task.skill
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
// src/chat/
|
|
46
|
+
// src/chat/inbox-items/user-input-request.ts
|
|
47
47
|
const USER_INPUT_LIMITS = {
|
|
48
48
|
maxButtonOptions: 5,
|
|
49
49
|
maxDescriptionChars: 200,
|
|
@@ -190,25 +190,25 @@ function formatUserInputAnswer(request, answer) {
|
|
|
190
190
|
if (normalized.other) lines.push(answerLine(`Other: ${normalized.other}`));
|
|
191
191
|
return lines.join("\n");
|
|
192
192
|
}
|
|
193
|
-
// src/chat/
|
|
193
|
+
// src/chat/inbox-items/evidence.ts
|
|
194
194
|
/**
|
|
195
|
-
* One source that an agent cites for
|
|
195
|
+
* One source that an agent cites for an Inbox item: a link or a
|
|
196
196
|
* Conversation, with a short label and an optional one-line note. A link
|
|
197
197
|
* points outside Junior; a Conversation reference points to work in Junior.
|
|
198
198
|
* The question stores the list, and the dashboard shows it beside the
|
|
199
199
|
* answer choices.
|
|
200
200
|
*/
|
|
201
|
-
const
|
|
201
|
+
const inboxItemEvidenceSchema = z.object({
|
|
202
202
|
conversationId: z.string().min(1).max(500).optional(),
|
|
203
203
|
label: z.string().min(1).max(120),
|
|
204
204
|
note: z.string().min(1).max(200).optional(),
|
|
205
205
|
url: z.string().min(1).max(2e3).optional()
|
|
206
206
|
}).strict().refine((entry) => entry.url === void 0 !== (entry.conversationId === void 0), "Evidence has a `url` or a `conversationId`, not both.");
|
|
207
207
|
/**
|
|
208
|
-
* The question of
|
|
208
|
+
* The question of an Inbox item with the evidence for its answer. Evidence
|
|
209
209
|
* is part of the question, so it is stored in the `request` column.
|
|
210
210
|
*/
|
|
211
|
-
const
|
|
211
|
+
const inboxItemRequestSchema = savedUserInputRequestSchema.safeExtend({ evidence: z.array(inboxItemEvidenceSchema).optional() });
|
|
212
212
|
/** Validate the persisted Slack creator identity for an event automation. */
|
|
213
213
|
const eventAutomationPrincipalSchema = z.object({
|
|
214
214
|
slackUserId: actorUserIdSchema,
|
|
@@ -858,8 +858,12 @@ const automationTitleSchema = z.string().trim().min(1).max(60);
|
|
|
858
858
|
* who says "me".
|
|
859
859
|
*/
|
|
860
860
|
const automationInstructionToolSchema = automationTaskTextSchema.describe("Work to perform when the Automation runs. Say what to do, what to post, and when to post nothing. Do not say where to post: the outcomes set that, a run triggered by a Slack message replies in its thread, and each run ends with one message at most. The run does not see this conversation, so words like \"this channel\" or \"here\" will mean nothing then. Where the run reads or changes something, write the exact target, such as a channel mention, a repo, or a link. Keep every person the user means, including \"me\". Write the creator as \"the Automation creator\"; each run knows who that is. Write anyone else, including a requester who is not the creator, as their Slack mention, such as <@U123>. Preserve the user's scope, targets, and constraints. Do not add permissions or side effects the user did not request.");
|
|
861
|
-
/**
|
|
862
|
-
|
|
861
|
+
/**
|
|
862
|
+
* Context input for agent tools. It follows the same rules as an instruction.
|
|
863
|
+
* Action review reads the stored context, not the skill, so the context also
|
|
864
|
+
* names the scope of the writes a run needs.
|
|
865
|
+
*/
|
|
866
|
+
const automationContextToolSchema = automationTaskTextSchema.describe("What a run needs beyond the skill: input values, such as a repo or who to tag; when to post nothing; and the scope of writes. Not the skill steps. Instruction rules apply: no place to post, exact targets, \"the Automation creator\", others as <@U123>.");
|
|
863
867
|
const automationEditFieldsSchema = z.object({
|
|
864
868
|
title: automationTitleSchema.optional(),
|
|
865
869
|
/** Replaces the whole task, so a mode switch drops the other mode's text. */
|
|
@@ -872,6 +876,945 @@ const eventAutomationEditSchema = automationEditFieldsSchema.extend({ trigger: e
|
|
|
872
876
|
identifier: z.string().trim().min(1).max(300).optional(),
|
|
873
877
|
label: z.string().trim().min(1).max(500)
|
|
874
878
|
}).optional() }).strict();
|
|
879
|
+
// src/chat/attachments/input.ts
|
|
880
|
+
/**
|
|
881
|
+
* Largest file that Junior stores from Slack or the web, or loads into the
|
|
882
|
+
* sandbox.
|
|
883
|
+
*
|
|
884
|
+
* Every path streams the bytes, so this cap does not depend on function
|
|
885
|
+
* memory. It bounds transfer time and sandbox disk use.
|
|
886
|
+
*/
|
|
887
|
+
const MAX_ATTACHMENT_BYTES = 262144e3;
|
|
888
|
+
/** Most files on one web Message, as in one Slack message. */
|
|
889
|
+
const MAX_INPUT_ATTACHMENTS = 10;
|
|
890
|
+
/** File facts that a browser declares before it uploads the bytes. */
|
|
891
|
+
const inputFileSchema = z.object({
|
|
892
|
+
filename: z.string().trim().min(1).max(255),
|
|
893
|
+
contentType: z.string().trim().toLowerCase().max(127).regex(/^[a-z0-9][\w.+-]*\/[a-z0-9][\w.+-]*$/),
|
|
894
|
+
bytes: z.number().int().min(1).max(MAX_ATTACHMENT_BYTES)
|
|
895
|
+
}).strict();
|
|
896
|
+
/** Safe attachment facts shared by mailbox input and transcript messages. */
|
|
897
|
+
const messageAttachmentSchema = z.object({
|
|
898
|
+
id: z.string().min(1),
|
|
899
|
+
filename: z.string().min(1),
|
|
900
|
+
contentType: z.string().min(1),
|
|
901
|
+
bytes: z.number().int().nonnegative(),
|
|
902
|
+
/**
|
|
903
|
+
* True for a large Slack file that Junior has not stored yet. A
|
|
904
|
+
* dashboard read downloads it from Slack, so it has no preview.
|
|
905
|
+
*/
|
|
906
|
+
pending: z.literal(true).optional()
|
|
907
|
+
}).strict();
|
|
908
|
+
/** Read attachment metadata without exposing object storage keys or bytes. */
|
|
909
|
+
function readMessageAttachments(value) {
|
|
910
|
+
return messageAttachmentSchema.array().parse(value ?? []);
|
|
911
|
+
}
|
|
912
|
+
// src/chat/automations/card.ts
|
|
913
|
+
/** Saved automation facts shown with a Message, not a live status view. */
|
|
914
|
+
const automationCardSchema = z.object({
|
|
915
|
+
kind: z.literal("automation"),
|
|
916
|
+
id: z.string().min(1),
|
|
917
|
+
title: z.string().min(1).max(160),
|
|
918
|
+
url: z.string().url().nullable(),
|
|
919
|
+
instruction: z.string().max(4e3),
|
|
920
|
+
trigger: z.string().min(1),
|
|
921
|
+
warning: z.string().nullable()
|
|
922
|
+
}).strict();
|
|
923
|
+
/** Render saved card facts for text-only delivery and accessible fallbacks. */
|
|
924
|
+
function automationCardText(card) {
|
|
925
|
+
return [
|
|
926
|
+
card.title,
|
|
927
|
+
card.warning,
|
|
928
|
+
card.trigger,
|
|
929
|
+
card.instruction,
|
|
930
|
+
card.url,
|
|
931
|
+
`Automation ID: ${card.id}`
|
|
932
|
+
].filter(Boolean).join("\n");
|
|
933
|
+
}
|
|
934
|
+
// src/chat/conversations/cards.ts
|
|
935
|
+
const storedCardSchema = automationCardSchema.extend({ operation: z.enum([
|
|
936
|
+
"created",
|
|
937
|
+
"updated",
|
|
938
|
+
"deleted"
|
|
939
|
+
]).optional() });
|
|
940
|
+
/** Render each built-in card with its own text format. */
|
|
941
|
+
function messageCardText(card) {
|
|
942
|
+
switch (card.kind) {
|
|
943
|
+
case "object": return [
|
|
944
|
+
card.title,
|
|
945
|
+
card.label !== card.title ? card.label : void 0,
|
|
946
|
+
card.description,
|
|
947
|
+
card.status,
|
|
948
|
+
...objectFactFields(card.facts).map((field) => `${field.label}: ${field.value}`),
|
|
949
|
+
card.trigger,
|
|
950
|
+
card.warning,
|
|
951
|
+
card.url
|
|
952
|
+
].filter(Boolean).join("\n");
|
|
953
|
+
case "automation": return automationCardText(card);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
/** Identify a deleted object whose pending card must be omitted. */
|
|
957
|
+
const removedCardSchema = z.object({
|
|
958
|
+
plugin: z.string().min(1),
|
|
959
|
+
key: z.string().min(1)
|
|
960
|
+
}).strict();
|
|
961
|
+
/** Store only the annotation identity with a Message. */
|
|
962
|
+
const messageCardRefSchema = removedCardSchema.extend({ kind: z.literal("object") });
|
|
963
|
+
/** Remove display facts before saving or reporting a Message card. */
|
|
964
|
+
function messageCardRef(card) {
|
|
965
|
+
return card.kind === "object" ? {
|
|
966
|
+
kind: "object",
|
|
967
|
+
plugin: card.plugin,
|
|
968
|
+
key: card.key
|
|
969
|
+
} : {
|
|
970
|
+
kind: "object",
|
|
971
|
+
plugin: "junior",
|
|
972
|
+
key: card.id
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
/** Read references, including identities from older saved card snapshots. */
|
|
976
|
+
function readMessageCardRefs(value) {
|
|
977
|
+
return [...storedCardSchema.array().parse(value.cards ?? []).flatMap(({ operation, ...card }) => operation === "deleted" ? [] : [messageCardRef(card)]), ...messageCardRefSchema.strip().array().parse(value.objectCards ?? [])];
|
|
978
|
+
}
|
|
979
|
+
/** Resolve current saved facts without fetching providers or changing history. */
|
|
980
|
+
function resolveMessageCards(refs, annotations) {
|
|
981
|
+
return refs.map((ref) => {
|
|
982
|
+
const annotation = annotations.find((item) => item.kind === ref.kind && item.plugin === ref.plugin && item.key === ref.key);
|
|
983
|
+
return annotation ? annotationCard(annotation) : {
|
|
984
|
+
...ref,
|
|
985
|
+
objectType: "item",
|
|
986
|
+
title: ref.key,
|
|
987
|
+
label: ref.key,
|
|
988
|
+
url: null,
|
|
989
|
+
warning: "Saved annotation is unavailable."
|
|
990
|
+
};
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
/** Copy saved annotation facts without storage timestamps for Message delivery. */
|
|
994
|
+
function annotationCard(annotation) {
|
|
995
|
+
const { createdAt: _createdAt, updatedAt: _updatedAt, ...value } = annotation;
|
|
996
|
+
return value.kind === "object" ? value : {
|
|
997
|
+
...value,
|
|
998
|
+
kind: "object",
|
|
999
|
+
objectType: value.objectType ?? "item",
|
|
1000
|
+
title: value.label
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
// src/chat/inbox-items/change-record.ts
|
|
1004
|
+
/**
|
|
1005
|
+
* The person change to an Inbox item that one message records. Each inbound
|
|
1006
|
+
* message and saved Message that reports a take, answer, or dismiss carries
|
|
1007
|
+
* its own record, so the dashboard shows what that message did, not what the
|
|
1008
|
+
* item looks like now.
|
|
1009
|
+
*
|
|
1010
|
+
* Stored Messages and queued inputs keep this shape and their
|
|
1011
|
+
* `reviewItemChange` and `reviewItemChanges` keys from before Review items
|
|
1012
|
+
* became Inbox items, so these names stay.
|
|
1013
|
+
*/
|
|
1014
|
+
const inboxItemChangeRecordSchema = z.object({
|
|
1015
|
+
kind: z.enum([
|
|
1016
|
+
"submitted",
|
|
1017
|
+
"dismissed",
|
|
1018
|
+
"taken"
|
|
1019
|
+
]),
|
|
1020
|
+
reviewItemId: z.string().min(1)
|
|
1021
|
+
}).strict();
|
|
1022
|
+
// src/api/schema/conversation-read-position.ts
|
|
1023
|
+
/**
|
|
1024
|
+
* How far the signed-in viewer has read a Conversation transcript.
|
|
1025
|
+
*
|
|
1026
|
+
* `lastReadSeq` is the event sequence of the last transcript row the viewer
|
|
1027
|
+
* saw. Reports only move it forward: the server keeps the highest value it
|
|
1028
|
+
* receives. It is never before the viewer's own latest Message.
|
|
1029
|
+
*/
|
|
1030
|
+
const conversationReadPositionSchema = z.object({ lastReadSeq: z.number().int().nonnegative() }).strict();
|
|
1031
|
+
// src/api/schema/conversation-kind.ts
|
|
1032
|
+
/** Where a Conversation sits in its tree. See `TERMINOLOGY.md`. */
|
|
1033
|
+
const conversationKindSchema = z.enum([
|
|
1034
|
+
"root",
|
|
1035
|
+
"automation",
|
|
1036
|
+
"lead",
|
|
1037
|
+
"thread",
|
|
1038
|
+
"task"
|
|
1039
|
+
]);
|
|
1040
|
+
// src/api/schema/conversation-title.ts
|
|
1041
|
+
/** Longest Conversation title that a rename can save. */
|
|
1042
|
+
const CONVERSATION_TITLE_MAX_LENGTH = 200;
|
|
1043
|
+
/** A Conversation title that a caller chooses, at creation or on rename. */
|
|
1044
|
+
const conversationTitleSchema = z.string().trim().min(1).max(200);
|
|
1045
|
+
/** A participant's new title for one Conversation. Every viewer sees it. */
|
|
1046
|
+
const renameConversationBodySchema = z.object({ title: conversationTitleSchema }).strict();
|
|
1047
|
+
/** The stored title after the rename. */
|
|
1048
|
+
const renameConversationResponseSchema = z.object({ title: z.string().min(1) }).strict();
|
|
1049
|
+
// src/api/schema/conversation-tree-state.ts
|
|
1050
|
+
/**
|
|
1051
|
+
* What a Conversation and its child Conversations need, for one viewer.
|
|
1052
|
+
* See "Viewer state" in `TERMINOLOGY.md`.
|
|
1053
|
+
*/
|
|
1054
|
+
const conversationTreeStateSchema = z.enum([
|
|
1055
|
+
"needs_you",
|
|
1056
|
+
"working",
|
|
1057
|
+
"done"
|
|
1058
|
+
]);
|
|
1059
|
+
// src/chat/agent-invocations/agent-types.ts
|
|
1060
|
+
/**
|
|
1061
|
+
* Child agent types. A type is plain data: when to pick it and what the child
|
|
1062
|
+
* reads with its task. Runtime code reads only these fields, never a type
|
|
1063
|
+
* name, so types can later come from configuration. Types do not limit tools:
|
|
1064
|
+
* Guardian reviews each child action against the root user's messages, as for
|
|
1065
|
+
* any child. A child keeps its type for later agent invocations. How a child
|
|
1066
|
+
* starts, fresh or forked from its parent's history, is not a type: see
|
|
1067
|
+
* `fork` on the agent invocation.
|
|
1068
|
+
*/
|
|
1069
|
+
const AGENT_TYPES = ["explore", "reviewer"];
|
|
1070
|
+
/**
|
|
1071
|
+
* Stored name of a child agent type. A stored name stays readable after its
|
|
1072
|
+
* type is removed; the runtime then treats the child as a
|
|
1073
|
+
* child without a type.
|
|
1074
|
+
*/
|
|
1075
|
+
const agentTypeSchema = z.string().regex(/^[a-z][a-z0-9_-]*$/);
|
|
1076
|
+
const AGENT_TYPE_DEFINITIONS = {
|
|
1077
|
+
explore: {
|
|
1078
|
+
whenToUse: "Investigation across code, docs, logs, telemetry, or the web. Use it when an answer needs reading across many files or sources and you need the conclusion with evidence, not the raw output.",
|
|
1079
|
+
instructions: "You are an explore agent. Your job is to investigate and report, so do not change anything outside your sandbox unless the task asks for it. Report what you found with exact evidence, such as paths, lines, links, and ids."
|
|
1080
|
+
},
|
|
1081
|
+
reviewer: {
|
|
1082
|
+
whenToUse: "An independent second opinion on a change, plan, or claim. Give it the evidence to judge, not your conclusion.",
|
|
1083
|
+
instructions: "You are a reviewer agent. Give an independent assessment. Do not assume that the parent's framing is correct: verify each claim against the evidence. Do not change anything outside your own sandbox. Report concrete problems ranked by severity, each with its evidence, and say clearly when you found none."
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
function agentTypeDefinition(type) {
|
|
1087
|
+
return type && Object.hasOwn(AGENT_TYPE_DEFINITIONS, type) ? AGENT_TYPE_DEFINITIONS[type] : void 0;
|
|
1088
|
+
}
|
|
1089
|
+
/** Model-facing list of child agent types. */
|
|
1090
|
+
function formatAgentTypes() {
|
|
1091
|
+
return AGENT_TYPES.map((type) => `- "${type}": ${AGENT_TYPE_DEFINITIONS[type].whenToUse}`).join("\n");
|
|
1092
|
+
}
|
|
1093
|
+
/** Return the instructions that a child of this type reads with its task. */
|
|
1094
|
+
function agentTypeInstructions(type) {
|
|
1095
|
+
return agentTypeDefinition(type)?.instructions;
|
|
1096
|
+
}
|
|
1097
|
+
// src/api/schema/child-agent-totals.ts
|
|
1098
|
+
/**
|
|
1099
|
+
* The part of a Conversation total that its child agents spent, at any depth.
|
|
1100
|
+
* Present only when the Conversation has child agents. The Conversation's own
|
|
1101
|
+
* part is the total minus this part.
|
|
1102
|
+
*/
|
|
1103
|
+
const conversationChildAgentTotalsSchema = z.object({
|
|
1104
|
+
auxiliaryCostUsd: z.number().finite().nonnegative().optional(),
|
|
1105
|
+
count: z.number().int().positive(),
|
|
1106
|
+
cumulativeDurationMs: z.number(),
|
|
1107
|
+
cumulativeUsage: usageSchema.optional()
|
|
1108
|
+
}).strict();
|
|
1109
|
+
// src/api/schema/object-preview-image.ts
|
|
1110
|
+
/**
|
|
1111
|
+
* One saved preview image of an object, such as a pull request screenshot,
|
|
1112
|
+
* at 1x and 2x. Both name the Junior image route, never the image host.
|
|
1113
|
+
*/
|
|
1114
|
+
const objectPreviewImageSchema = z.object({
|
|
1115
|
+
src: z.string().startsWith("/api/images/"),
|
|
1116
|
+
srcSet: z.string().min(1)
|
|
1117
|
+
}).strict();
|
|
1118
|
+
const CUT_TOKEN_RE = /<(?:[@#!][^<>]*|[a-z]+:[^\s<>|]*(?:\|[^<>]*)?|[a-z]*)$/i;
|
|
1119
|
+
/**
|
|
1120
|
+
* Cut preview text to the schema limit. The cut ends with "…" at a word
|
|
1121
|
+
* break, and never leaves half a surrogate pair or an unclosed Slack token
|
|
1122
|
+
* such as `<@U1` or `<https://…`, so mentions and links still parse.
|
|
1123
|
+
*/
|
|
1124
|
+
function activityPreviewText(text) {
|
|
1125
|
+
if (text.length <= 400) return text;
|
|
1126
|
+
let cut = text.slice(0, 399);
|
|
1127
|
+
const space = cut.search(/\s\S*$/);
|
|
1128
|
+
if (space > 0 && /\S/.test(text[cut.length])) cut = cut.slice(0, space);
|
|
1129
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
1130
|
+
if (last >= 55296 && last <= 56319) cut = cut.slice(0, -1);
|
|
1131
|
+
return `${cut.replace(CUT_TOKEN_RE, "").trimEnd()}…`;
|
|
1132
|
+
}
|
|
1133
|
+
// src/api/schema/conversation.ts
|
|
1134
|
+
/**
|
|
1135
|
+
* The status of one Conversation's own work. See `TERMINOLOGY.md` and
|
|
1136
|
+
* `conversationStatusSql`, the only place that derives it.
|
|
1137
|
+
*/
|
|
1138
|
+
const conversationReportStatusSchema = z.enum([
|
|
1139
|
+
"needs_input",
|
|
1140
|
+
"working",
|
|
1141
|
+
"done"
|
|
1142
|
+
]);
|
|
1143
|
+
const conversationSurfaceSchema = z.enum([
|
|
1144
|
+
"api",
|
|
1145
|
+
"internal",
|
|
1146
|
+
"scheduler",
|
|
1147
|
+
"slack"
|
|
1148
|
+
]);
|
|
1149
|
+
const conversationUsageSchema = usageSchema;
|
|
1150
|
+
const conversationParamsSchema = z.object({ conversationId: z.string().min(1) }).strict();
|
|
1151
|
+
const conversationAttachmentParamsSchema = z.object({
|
|
1152
|
+
attachmentId: z.string().min(1),
|
|
1153
|
+
conversationId: z.string().min(1)
|
|
1154
|
+
}).strict();
|
|
1155
|
+
const conversationAttachmentQuerySchema = z.object({
|
|
1156
|
+
/**
|
|
1157
|
+
* Send `Content-Disposition: attachment` even for a type that previews
|
|
1158
|
+
* inline, so a same-window download link saves the file.
|
|
1159
|
+
*/
|
|
1160
|
+
download: z.stringbool().optional() }).strict();
|
|
1161
|
+
const conversationDetailQuerySchema = z.object({
|
|
1162
|
+
/** Omit to get the latest three Turns, up to the default page limit. */
|
|
1163
|
+
limit: z.coerce.number().int().min(1).max(1e3).optional(),
|
|
1164
|
+
/** Also return `unreadPage` when the detail has an `unreadCursor`. */
|
|
1165
|
+
unreadPage: z.stringbool().optional(),
|
|
1166
|
+
/**
|
|
1167
|
+
* Also return `mailbox`, read before history. A sent version that still
|
|
1168
|
+
* matches gets `{ unchanged: true, mailbox }` instead of 304, so a poll
|
|
1169
|
+
* needs one request.
|
|
1170
|
+
*/
|
|
1171
|
+
mailbox: z.stringbool().optional(),
|
|
1172
|
+
/**
|
|
1173
|
+
* An `appendCursor` from an earlier detail. Events then hold only newer
|
|
1174
|
+
* events, with `appended: true`, while the cursor still applies.
|
|
1175
|
+
*/
|
|
1176
|
+
after: z.string().min(1).optional()
|
|
1177
|
+
}).strict();
|
|
1178
|
+
const conversationEventsLimitSchema = z.coerce.number().int().min(1).max(1e3).default(150);
|
|
1179
|
+
/**
|
|
1180
|
+
* Page toward the start with `before`, toward the latest with `after`, or
|
|
1181
|
+
* both ways from one event with `around`. A link target asks for the page
|
|
1182
|
+
* around one event by its `event` seq, around one `message` by its id, or
|
|
1183
|
+
* around the start of a `turn`.
|
|
1184
|
+
*/
|
|
1185
|
+
const conversationEventsQuerySchema = z.union([
|
|
1186
|
+
z.object({
|
|
1187
|
+
before: z.string().min(1),
|
|
1188
|
+
limit: conversationEventsLimitSchema
|
|
1189
|
+
}).strict(),
|
|
1190
|
+
z.object({
|
|
1191
|
+
after: z.string().min(1),
|
|
1192
|
+
limit: conversationEventsLimitSchema
|
|
1193
|
+
}).strict(),
|
|
1194
|
+
z.object({
|
|
1195
|
+
around: z.string().min(1),
|
|
1196
|
+
limit: conversationEventsLimitSchema
|
|
1197
|
+
}).strict(),
|
|
1198
|
+
z.object({
|
|
1199
|
+
event: z.coerce.number().int().min(0),
|
|
1200
|
+
limit: conversationEventsLimitSchema
|
|
1201
|
+
}).strict(),
|
|
1202
|
+
z.object({
|
|
1203
|
+
turn: z.string().min(1),
|
|
1204
|
+
limit: conversationEventsLimitSchema
|
|
1205
|
+
}).strict(),
|
|
1206
|
+
z.object({
|
|
1207
|
+
message: z.string().min(1),
|
|
1208
|
+
limit: conversationEventsLimitSchema
|
|
1209
|
+
}).strict()
|
|
1210
|
+
]);
|
|
1211
|
+
/** Client key that makes a retried send the same Message. */
|
|
1212
|
+
const idempotencyKeySchema = z.string().trim().min(1).max(200);
|
|
1213
|
+
const createConversationMessageBodySchema = z.object({
|
|
1214
|
+
idempotencyKey: idempotencyKeySchema,
|
|
1215
|
+
message: z.string().trim().max(32e3),
|
|
1216
|
+
/** Uploads from `POST /api/conversations/attachment-uploads`. */
|
|
1217
|
+
uploadIds: z.array(z.string().min(1).max(64)).max(10).optional()
|
|
1218
|
+
}).strict().refine((body) => Boolean(body.message || body.uploadIds?.length), "Add a message or a file.");
|
|
1219
|
+
const createConversationBodySchema = createConversationMessageBodySchema.safeExtend({
|
|
1220
|
+
/** Saved title. Title generation runs only when it is omitted. */
|
|
1221
|
+
title: conversationTitleSchema.optional(),
|
|
1222
|
+
/** New roots default public. Private roots stay participant-only. */
|
|
1223
|
+
visibility: z.enum(["private", "public"]).optional()
|
|
1224
|
+
});
|
|
1225
|
+
const acceptedConversationMessageSchema = z.object({
|
|
1226
|
+
conversationId: z.string().min(1),
|
|
1227
|
+
messageId: z.string().min(1),
|
|
1228
|
+
status: z.enum(["accepted", "duplicate"])
|
|
1229
|
+
}).strict();
|
|
1230
|
+
const actorIdentitySchema = z.object({
|
|
1231
|
+
/**
|
|
1232
|
+
* Junior API path of the profile photo: the person's Slack photo, then
|
|
1233
|
+
* their Google photo.
|
|
1234
|
+
*/
|
|
1235
|
+
avatarUrl: z.string().optional(),
|
|
1236
|
+
email: z.string().optional(),
|
|
1237
|
+
fullName: z.string().optional(),
|
|
1238
|
+
slackUserId: z.string().optional(),
|
|
1239
|
+
slackUserName: z.string().optional()
|
|
1240
|
+
}).strict();
|
|
1241
|
+
const conversationAuxiliaryCostsSchema = z.object({
|
|
1242
|
+
costUsd: z.number().finite().nonnegative(),
|
|
1243
|
+
operations: z.array(z.object({
|
|
1244
|
+
costUsd: z.number().finite().nonnegative(),
|
|
1245
|
+
events: z.number().int().positive(),
|
|
1246
|
+
name: z.string().min(1),
|
|
1247
|
+
namespace: z.string().min(1)
|
|
1248
|
+
}).strict()).min(1)
|
|
1249
|
+
}).strict();
|
|
1250
|
+
/** Optional reverse link from a task-triggered conversation back to its task. */
|
|
1251
|
+
const conversationSourceTaskSchema = z.object({
|
|
1252
|
+
id: z.string().min(1).optional(),
|
|
1253
|
+
kind: z.enum(["scheduled", "event"]),
|
|
1254
|
+
label: z.string().min(1).optional(),
|
|
1255
|
+
title: z.string().min(1).optional(),
|
|
1256
|
+
/** Message id of the run's trigger input, which is not from a person. */
|
|
1257
|
+
triggerMessageId: z.string().min(1).optional(),
|
|
1258
|
+
/** Short trigger text, such as an event or a schedule. */
|
|
1259
|
+
triggerLabel: z.string().min(1).optional(),
|
|
1260
|
+
/** Credential mode this run used. Unset when the run record is gone. */
|
|
1261
|
+
credentialMode: z.enum(["creator", "system"]).optional(),
|
|
1262
|
+
/** Name of the creator whose credentials this run used. */
|
|
1263
|
+
credentialUser: z.string().min(1).optional()
|
|
1264
|
+
}).strict().superRefine((value, context) => {
|
|
1265
|
+
if (Boolean(value.id) !== Boolean(value.label)) context.addIssue({
|
|
1266
|
+
code: "custom",
|
|
1267
|
+
message: "sourceTask id and label must both be set or both omitted"
|
|
1268
|
+
});
|
|
1269
|
+
});
|
|
1270
|
+
const conversationAnnotationReportSchema = conversationAnnotationInputSchema.and(z.object({
|
|
1271
|
+
plugin: z.string().min(1),
|
|
1272
|
+
createdAt: z.string().datetime(),
|
|
1273
|
+
updatedAt: z.string().datetime(),
|
|
1274
|
+
previewImages: z.array(objectPreviewImageSchema).optional()
|
|
1275
|
+
}));
|
|
1276
|
+
const conversationActivityPreviewSchema = z.object({
|
|
1277
|
+
createdAt: z.string().datetime(),
|
|
1278
|
+
mentions: z.array(actorIdentitySchema).optional(),
|
|
1279
|
+
role: z.enum(["assistant", "user"]),
|
|
1280
|
+
text: z.string().min(1).max(400)
|
|
1281
|
+
}).strict();
|
|
1282
|
+
const conversationSummaryReportSchema = z.object({
|
|
1283
|
+
displayTitle: z.string(),
|
|
1284
|
+
/**
|
|
1285
|
+
* Conversation metadata, when the viewer may see private content. A new
|
|
1286
|
+
* Conversation has none until its first Turn completes.
|
|
1287
|
+
*/
|
|
1288
|
+
summary: z.string().optional(),
|
|
1289
|
+
activityPreview: conversationActivityPreviewSchema.optional(),
|
|
1290
|
+
cumulativeDurationMs: z.number(),
|
|
1291
|
+
cumulativeUsage: conversationUsageSchema.optional(),
|
|
1292
|
+
auxiliaryCosts: conversationAuxiliaryCostsSchema.optional(),
|
|
1293
|
+
childAgentTotals: conversationChildAgentTotalsSchema.optional(),
|
|
1294
|
+
conversationId: z.string(),
|
|
1295
|
+
kind: conversationKindSchema,
|
|
1296
|
+
/** Present on Threads and Tasks. */
|
|
1297
|
+
parentConversationId: z.string().min(1).optional(),
|
|
1298
|
+
isParticipant: z.boolean(),
|
|
1299
|
+
visibility: z.enum(["private", "public"]).optional(),
|
|
1300
|
+
status: conversationReportStatusSchema,
|
|
1301
|
+
/** Feed rows and the detail only. */
|
|
1302
|
+
treeState: conversationTreeStateSchema.optional(),
|
|
1303
|
+
/**
|
|
1304
|
+
* A Conversation in the tree has an active Watch or a pending Timer.
|
|
1305
|
+
* Feed rows and the detail only.
|
|
1306
|
+
*/
|
|
1307
|
+
watching: z.boolean().optional(),
|
|
1308
|
+
/**
|
|
1309
|
+
* A Turn is queued or running. Live views poll and show thinking on it,
|
|
1310
|
+
* since `status` can read `needs_input` while a Turn runs.
|
|
1311
|
+
*/
|
|
1312
|
+
turnActive: z.boolean(),
|
|
1313
|
+
startedAt: z.string(),
|
|
1314
|
+
lastSeenAt: z.string(),
|
|
1315
|
+
lastProgressAt: z.string(),
|
|
1316
|
+
lastMessageAt: z.string().datetime().optional(),
|
|
1317
|
+
surface: conversationSurfaceSchema,
|
|
1318
|
+
actorIdentity: actorIdentitySchema.optional(),
|
|
1319
|
+
participants: z.array(actorIdentitySchema).optional(),
|
|
1320
|
+
/**
|
|
1321
|
+
* When this Conversation was archived for everyone, or null. It shows
|
|
1322
|
+
* only while it and every ancestor are unarchived.
|
|
1323
|
+
*/
|
|
1324
|
+
archivedAt: z.string().datetime().nullable().optional(),
|
|
1325
|
+
pinnedAt: z.string().datetime().nullable().optional(),
|
|
1326
|
+
/** The viewer's place in Pinned. Unset until they reorder their pins. */
|
|
1327
|
+
pinPosition: z.number().int().optional(),
|
|
1328
|
+
channel: z.string().optional(),
|
|
1329
|
+
channelName: z.string().optional(),
|
|
1330
|
+
channelNameRedacted: z.boolean().optional(),
|
|
1331
|
+
locationId: z.string().optional(),
|
|
1332
|
+
sentryTraceUrl: z.string().optional(),
|
|
1333
|
+
locationUrl: z.string().url().optional(),
|
|
1334
|
+
traceId: z.string().optional(),
|
|
1335
|
+
/**
|
|
1336
|
+
* Plugin-owned resource links for this conversation.
|
|
1337
|
+
* Present on the conversation feed when the viewer can see private content.
|
|
1338
|
+
* Clients must not fetch provider state while rendering these links.
|
|
1339
|
+
*/
|
|
1340
|
+
annotations: z.array(conversationAnnotationReportSchema).optional(),
|
|
1341
|
+
/** Plugin-selected annotations for the compact conversation row. */
|
|
1342
|
+
sidebarAnnotations: z.array(conversationSidebarAnnotationSchema).optional(),
|
|
1343
|
+
assignedWork: z.boolean().optional(),
|
|
1344
|
+
finishedWorkAt: z.string().datetime().optional(),
|
|
1345
|
+
/**
|
|
1346
|
+
* Dashboard Priority membership for this conversation summary.
|
|
1347
|
+
* Present on the conversation feed. Clients must not recompute it.
|
|
1348
|
+
*
|
|
1349
|
+
* True only when:
|
|
1350
|
+
* - unfinished work was last seen within 48 hours
|
|
1351
|
+
* - finished assigned work has conversation activity after the finish time
|
|
1352
|
+
* - there is no known work and the conversation was last seen within 3 hours
|
|
1353
|
+
*/
|
|
1354
|
+
isPriority: z.boolean().optional(),
|
|
1355
|
+
unfinishedWork: z.boolean().optional(),
|
|
1356
|
+
/**
|
|
1357
|
+
* True on the conversation feed when a Turn in the conversation or a
|
|
1358
|
+
* child waits on a person to finish an authorization that has not
|
|
1359
|
+
* expired.
|
|
1360
|
+
*/
|
|
1361
|
+
awaitingAuthorization: z.boolean().optional(),
|
|
1362
|
+
/**
|
|
1363
|
+
* True on the conversation feed when the conversation's latest Turn
|
|
1364
|
+
* failed and no newer Turn started.
|
|
1365
|
+
*/
|
|
1366
|
+
latestTurnFailed: z.boolean().optional()
|
|
1367
|
+
}).strict();
|
|
1368
|
+
/** One Event listed on a message that holds several Events. */
|
|
1369
|
+
const conversationReportMessageEventSchema = z.object({
|
|
1370
|
+
eventType: z.string().min(1),
|
|
1371
|
+
label: z.string().min(1).optional(),
|
|
1372
|
+
objectType: objectTypeSchema.optional(),
|
|
1373
|
+
trustedSummary: z.string().min(1).optional()
|
|
1374
|
+
}).strict();
|
|
1375
|
+
const conversationReportMessageEventDataSchema = z.object({
|
|
1376
|
+
type: z.literal("message"),
|
|
1377
|
+
messageId: z.string().min(1),
|
|
1378
|
+
role: z.enum([
|
|
1379
|
+
"assistant",
|
|
1380
|
+
"system",
|
|
1381
|
+
"user"
|
|
1382
|
+
]),
|
|
1383
|
+
source: z.enum(["slack", "web"]).optional(),
|
|
1384
|
+
actorIdentity: actorIdentitySchema.optional(),
|
|
1385
|
+
/** Identity id of the author. Detail `authors` maps it to the person. */
|
|
1386
|
+
actorIdentityId: z.string().min(1).optional(),
|
|
1387
|
+
/** Agent invocation whose input this is. An agent wrote it, not a person. */
|
|
1388
|
+
agentInvocationId: z.string().min(1).optional(),
|
|
1389
|
+
eventType: z.string().min(1).optional(),
|
|
1390
|
+
/** Namespace of the first Event, such as `github`. */
|
|
1391
|
+
eventNamespace: z.string().min(1).optional(),
|
|
1392
|
+
/**
|
|
1393
|
+
* Resource identifier of the first Event, such as the id of a watched
|
|
1394
|
+
* Conversation. Only for viewers who can see private content.
|
|
1395
|
+
*/
|
|
1396
|
+
eventIdentifier: z.string().min(1).optional(),
|
|
1397
|
+
eventObjectType: objectTypeSchema.optional(),
|
|
1398
|
+
explicitMention: z.boolean().optional(),
|
|
1399
|
+
quiet: z.literal(true).optional(),
|
|
1400
|
+
trustedSummary: z.string().min(1).optional(),
|
|
1401
|
+
/**
|
|
1402
|
+
* The Watch Events when several arrived together. A message that also
|
|
1403
|
+
* records Inbox item changes lists its own Event here even when it has
|
|
1404
|
+
* one.
|
|
1405
|
+
*/
|
|
1406
|
+
events: z.array(conversationReportMessageEventSchema).optional(),
|
|
1407
|
+
cards: z.array(messageCardRefSchema).optional(),
|
|
1408
|
+
/** Person changes to Inbox items that this message records. */
|
|
1409
|
+
reviewItemChanges: z.array(inboxItemChangeRecordSchema).min(1).optional(),
|
|
1410
|
+
text: z.string().optional(),
|
|
1411
|
+
attachments: z.array(messageAttachmentSchema).optional(),
|
|
1412
|
+
redacted: z.literal(true).optional()
|
|
1413
|
+
}).strict().superRefine((data, context) => {
|
|
1414
|
+
if (data.text === void 0 === (data.redacted !== true)) context.addIssue({
|
|
1415
|
+
code: "custom",
|
|
1416
|
+
message: "message content must be text or explicitly redacted"
|
|
1417
|
+
});
|
|
1418
|
+
if (data.redacted && (data.actorIdentity || data.cards || data.attachments || data.events || data.reviewItemChanges)) context.addIssue({
|
|
1419
|
+
code: "custom",
|
|
1420
|
+
message: "redacted messages must not expose actor identity, cards, attachments, events, or inbox item changes"
|
|
1421
|
+
});
|
|
1422
|
+
});
|
|
1423
|
+
const conversationReportMessageHandledEventDataSchema = z.object({
|
|
1424
|
+
type: z.literal("message_handled"),
|
|
1425
|
+
messageId: z.string().min(1)
|
|
1426
|
+
}).strict();
|
|
1427
|
+
const conversationReportToolCallSchema = z.object({
|
|
1428
|
+
toolCallId: z.string().min(1),
|
|
1429
|
+
name: z.string().min(1),
|
|
1430
|
+
status: z.enum([
|
|
1431
|
+
"running",
|
|
1432
|
+
"completed",
|
|
1433
|
+
"error"
|
|
1434
|
+
]),
|
|
1435
|
+
startedAt: z.string().datetime().optional(),
|
|
1436
|
+
startedSeq: z.number().int().nonnegative().optional(),
|
|
1437
|
+
input: z.unknown().optional(),
|
|
1438
|
+
output: z.unknown().optional(),
|
|
1439
|
+
/** The Conversation that a completed `startConversation` call started. */
|
|
1440
|
+
startedConversationId: z.string().min(1).optional()
|
|
1441
|
+
}).strict().superRefine((call, context) => {
|
|
1442
|
+
if (call.startedAt === void 0 !== (call.startedSeq === void 0)) context.addIssue({
|
|
1443
|
+
code: "custom",
|
|
1444
|
+
message: "tool start sequence and timestamp must be provided together"
|
|
1445
|
+
});
|
|
1446
|
+
});
|
|
1447
|
+
const conversationReportReasoningPartSchema = z.object({
|
|
1448
|
+
type: z.literal("reasoning"),
|
|
1449
|
+
text: z.string().min(1).optional(),
|
|
1450
|
+
redacted: z.literal(true).optional()
|
|
1451
|
+
}).strict().superRefine((data, context) => {
|
|
1452
|
+
if (data.text === void 0 === (data.redacted !== true)) context.addIssue({
|
|
1453
|
+
code: "custom",
|
|
1454
|
+
message: "reasoning content must be text or explicitly redacted"
|
|
1455
|
+
});
|
|
1456
|
+
});
|
|
1457
|
+
const conversationReportAssistantToolCallPartSchema = z.object({
|
|
1458
|
+
type: z.literal("tool_call"),
|
|
1459
|
+
toolCallId: z.string().min(1)
|
|
1460
|
+
}).strict();
|
|
1461
|
+
const conversationReportAssistantMetadataSchema = z.object({ parts: z.array(z.discriminatedUnion("type", [conversationReportReasoningPartSchema, conversationReportAssistantToolCallPartSchema])).min(1) }).strict();
|
|
1462
|
+
const conversationReportToolCallsEventDataSchema = z.object({
|
|
1463
|
+
type: z.literal("tool_calls"),
|
|
1464
|
+
calls: z.array(conversationReportToolCallSchema).min(1),
|
|
1465
|
+
assistant: conversationReportAssistantMetadataSchema.optional()
|
|
1466
|
+
}).strict().superRefine((data, context) => {
|
|
1467
|
+
if (!data.assistant) return;
|
|
1468
|
+
const callCounts = /* @__PURE__ */ new Map();
|
|
1469
|
+
for (const call of data.calls) callCounts.set(call.toolCallId, (callCounts.get(call.toolCallId) ?? 0) + 1);
|
|
1470
|
+
const partCounts = /* @__PURE__ */ new Map();
|
|
1471
|
+
for (const part of data.assistant.parts) {
|
|
1472
|
+
if (part.type !== "tool_call") continue;
|
|
1473
|
+
partCounts.set(part.toolCallId, (partCounts.get(part.toolCallId) ?? 0) + 1);
|
|
1474
|
+
}
|
|
1475
|
+
if (callCounts.size !== partCounts.size || [...callCounts].some(([toolCallId, count]) => partCounts.get(toolCallId) !== count)) context.addIssue({
|
|
1476
|
+
code: "custom",
|
|
1477
|
+
path: ["assistant", "parts"],
|
|
1478
|
+
message: "assistant tool parts must reference every call exactly once"
|
|
1479
|
+
});
|
|
1480
|
+
});
|
|
1481
|
+
const conversationReportAssistantMessageEventDataSchema = z.object({
|
|
1482
|
+
type: z.literal("assistant_message"),
|
|
1483
|
+
parts: z.array(conversationReportReasoningPartSchema)
|
|
1484
|
+
}).strict();
|
|
1485
|
+
const conversationReportTurnLifecycleEventDataSchema = z.discriminatedUnion("state", [
|
|
1486
|
+
z.object({
|
|
1487
|
+
type: z.literal("turn_lifecycle"),
|
|
1488
|
+
turnId: z.string().min(1),
|
|
1489
|
+
state: z.enum([
|
|
1490
|
+
"succeeded",
|
|
1491
|
+
"no_reply",
|
|
1492
|
+
"blocked"
|
|
1493
|
+
])
|
|
1494
|
+
}).strict(),
|
|
1495
|
+
z.object({
|
|
1496
|
+
type: z.literal("turn_lifecycle"),
|
|
1497
|
+
turnId: z.string().min(1),
|
|
1498
|
+
state: z.literal("started"),
|
|
1499
|
+
inputMessageIds: z.array(z.string().min(1)).min(1).optional()
|
|
1500
|
+
}).strict(),
|
|
1501
|
+
z.object({
|
|
1502
|
+
type: z.literal("turn_lifecycle"),
|
|
1503
|
+
turnId: z.string().min(1),
|
|
1504
|
+
state: z.literal("failed"),
|
|
1505
|
+
failureCode: conversationTurnFailureCodeSchema,
|
|
1506
|
+
failureReason: conversationTurnFailureReasonSchema.optional(),
|
|
1507
|
+
eventId: z.string().regex(/^[a-f0-9]{32}$/i).optional(),
|
|
1508
|
+
sentryEventUrl: z.string().url().optional()
|
|
1509
|
+
}).strict()
|
|
1510
|
+
]);
|
|
1511
|
+
const conversationReportGuardianActionReviewedEventDataSchema = z.object({
|
|
1512
|
+
type: z.literal("guardian_action_reviewed"),
|
|
1513
|
+
turnId: z.string().min(1),
|
|
1514
|
+
toolCallId: z.string().min(1),
|
|
1515
|
+
toolName: z.string().min(1),
|
|
1516
|
+
decision: z.enum([
|
|
1517
|
+
"allow",
|
|
1518
|
+
"ask",
|
|
1519
|
+
"deny"
|
|
1520
|
+
]),
|
|
1521
|
+
riskLevel: z.enum([
|
|
1522
|
+
"low",
|
|
1523
|
+
"medium",
|
|
1524
|
+
"high",
|
|
1525
|
+
"critical"
|
|
1526
|
+
]),
|
|
1527
|
+
userAuthorization: z.enum([
|
|
1528
|
+
"high",
|
|
1529
|
+
"medium",
|
|
1530
|
+
"low",
|
|
1531
|
+
"unknown"
|
|
1532
|
+
])
|
|
1533
|
+
}).strict();
|
|
1534
|
+
const conversationReportTurnContextEventDataSchema = z.object({
|
|
1535
|
+
type: z.literal("turn_context"),
|
|
1536
|
+
turnId: z.string().min(1),
|
|
1537
|
+
pluginName: z.string().min(1),
|
|
1538
|
+
kind: z.string().min(1),
|
|
1539
|
+
version: z.number().int().positive(),
|
|
1540
|
+
content: z.record(z.string(), z.unknown())
|
|
1541
|
+
}).strict();
|
|
1542
|
+
const conversationReportStructuredEventDataSchema = z.object({
|
|
1543
|
+
type: z.literal("structured_event"),
|
|
1544
|
+
namespace: z.string().min(1),
|
|
1545
|
+
name: z.string().min(1),
|
|
1546
|
+
version: z.number().int().positive(),
|
|
1547
|
+
turnId: z.string().min(1).optional(),
|
|
1548
|
+
presentation: conversationEventPresentationSchema
|
|
1549
|
+
}).strict();
|
|
1550
|
+
const conversationReportAttachmentsDeliveredEventDataSchema = z.object({
|
|
1551
|
+
type: z.literal("attachments_delivered"),
|
|
1552
|
+
attachments: z.array(messageAttachmentSchema).min(1)
|
|
1553
|
+
}).strict();
|
|
1554
|
+
/** Junior text that a plugin tool posted to its provider. */
|
|
1555
|
+
const conversationReportReplyPostedEventDataSchema = z.object({
|
|
1556
|
+
type: z.literal("reply_posted"),
|
|
1557
|
+
plugin: z.string().min(1),
|
|
1558
|
+
text: z.string().min(1),
|
|
1559
|
+
url: z.string().url().optional()
|
|
1560
|
+
}).strict();
|
|
1561
|
+
const conversationReportCompactionEventDataSchema = z.object({
|
|
1562
|
+
type: z.literal("compaction"),
|
|
1563
|
+
modelId: z.string().min(1).optional(),
|
|
1564
|
+
summary: z.string().min(1).optional(),
|
|
1565
|
+
details: z.object({
|
|
1566
|
+
reason: z.literal("capacity"),
|
|
1567
|
+
estimatedInputTokens: z.number().int().nonnegative(),
|
|
1568
|
+
replacementInputTokens: z.number().int().nonnegative().optional(),
|
|
1569
|
+
triggerTokens: z.number().int().nonnegative(),
|
|
1570
|
+
inputLimitTokens: z.number().int().positive(),
|
|
1571
|
+
inputMessageCount: z.number().int().nonnegative(),
|
|
1572
|
+
retainedMessageCount: z.number().int().nonnegative(),
|
|
1573
|
+
summaryChars: z.number().int().nonnegative()
|
|
1574
|
+
}).strict().optional()
|
|
1575
|
+
}).strict();
|
|
1576
|
+
const conversationReportSubagentEventDataSchema = z.object({
|
|
1577
|
+
type: z.literal("subagent"),
|
|
1578
|
+
startedSeq: z.number().int().nonnegative(),
|
|
1579
|
+
startedAt: z.string().datetime(),
|
|
1580
|
+
childConversationId: z.string().min(1),
|
|
1581
|
+
/** The child's Conversation kind. Only a Thread has its own page link. */
|
|
1582
|
+
childKind: z.enum(["thread", "task"]),
|
|
1583
|
+
subagentKind: z.string().min(1),
|
|
1584
|
+
agentName: z.string().min(1).optional(),
|
|
1585
|
+
task: z.string().min(1).optional(),
|
|
1586
|
+
title: z.string().min(1).optional(),
|
|
1587
|
+
parentToolCallId: z.string().min(1).optional(),
|
|
1588
|
+
status: z.enum([
|
|
1589
|
+
"running",
|
|
1590
|
+
"completed",
|
|
1591
|
+
"blocked",
|
|
1592
|
+
"error",
|
|
1593
|
+
"aborted"
|
|
1594
|
+
])
|
|
1595
|
+
}).strict();
|
|
1596
|
+
/** Privacy-safe event variants owned by the conversation reporting API. */
|
|
1597
|
+
const conversationReportEventDataSchema = z.discriminatedUnion("type", [
|
|
1598
|
+
conversationReportMessageEventDataSchema,
|
|
1599
|
+
conversationReportMessageHandledEventDataSchema,
|
|
1600
|
+
conversationReportAssistantMessageEventDataSchema,
|
|
1601
|
+
conversationReportToolCallsEventDataSchema,
|
|
1602
|
+
conversationReportTurnLifecycleEventDataSchema,
|
|
1603
|
+
conversationReportTurnContextEventDataSchema,
|
|
1604
|
+
conversationReportStructuredEventDataSchema,
|
|
1605
|
+
conversationReportAttachmentsDeliveredEventDataSchema,
|
|
1606
|
+
conversationReportReplyPostedEventDataSchema,
|
|
1607
|
+
conversationReportGuardianActionReviewedEventDataSchema,
|
|
1608
|
+
conversationReportCompactionEventDataSchema,
|
|
1609
|
+
conversationReportSubagentEventDataSchema
|
|
1610
|
+
]);
|
|
1611
|
+
/** One ordered, privacy-safe canonical event projected for API consumers. */
|
|
1612
|
+
const conversationReportEventSchema = z.object({
|
|
1613
|
+
seq: z.number().int().nonnegative(),
|
|
1614
|
+
createdAt: z.string().datetime(),
|
|
1615
|
+
data: conversationReportEventDataSchema,
|
|
1616
|
+
/** People mentioned in the event text, resolved at read time. */
|
|
1617
|
+
mentions: z.array(actorIdentitySchema).optional(),
|
|
1618
|
+
model: z.object({ modelId: z.string().min(1) }).strict().optional(),
|
|
1619
|
+
modelCall: z.object({
|
|
1620
|
+
provider: z.string().min(1).optional(),
|
|
1621
|
+
api: z.string().min(1).optional(),
|
|
1622
|
+
stopReason: z.string().min(1).optional(),
|
|
1623
|
+
usage: conversationUsageSchema.optional()
|
|
1624
|
+
}).strict().optional()
|
|
1625
|
+
}).strict();
|
|
1626
|
+
/** Availability of the canonical event history attached to a detail report. */
|
|
1627
|
+
const conversationEventHistorySchema = z.discriminatedUnion("status", [
|
|
1628
|
+
z.object({ status: z.literal("available") }).strict(),
|
|
1629
|
+
z.object({
|
|
1630
|
+
status: z.literal("redacted"),
|
|
1631
|
+
reason: z.literal("non_public_conversation")
|
|
1632
|
+
}).strict(),
|
|
1633
|
+
z.object({
|
|
1634
|
+
status: z.literal("expired"),
|
|
1635
|
+
expiredAt: z.string().datetime()
|
|
1636
|
+
}).strict()
|
|
1637
|
+
]);
|
|
1638
|
+
const conversationModelUsageSchema = z.object({
|
|
1639
|
+
modelId: z.string(),
|
|
1640
|
+
usage: conversationUsageSchema
|
|
1641
|
+
}).strict();
|
|
1642
|
+
/** Enforce event ordering and history visibility across paginated wire payloads. */
|
|
1643
|
+
function validateConversationEvents(report, context) {
|
|
1644
|
+
if (report.eventHistory.status === "expired" && report.events.length > 0) context.addIssue({
|
|
1645
|
+
code: "custom",
|
|
1646
|
+
path: ["events"],
|
|
1647
|
+
message: "expired event history must not contain events"
|
|
1648
|
+
});
|
|
1649
|
+
for (let index = 1; index < report.events.length; index += 1) if (report.events[index].seq <= report.events[index - 1].seq) context.addIssue({
|
|
1650
|
+
code: "custom",
|
|
1651
|
+
path: [
|
|
1652
|
+
"events",
|
|
1653
|
+
index,
|
|
1654
|
+
"seq"
|
|
1655
|
+
],
|
|
1656
|
+
message: "report event sequences must be strictly increasing"
|
|
1657
|
+
});
|
|
1658
|
+
for (const [index, event] of report.events.entries()) {
|
|
1659
|
+
if (event.data.type === "message") {
|
|
1660
|
+
if (report.eventHistory.status === "redacted" && event.data.redacted !== true) context.addIssue({
|
|
1661
|
+
code: "custom",
|
|
1662
|
+
path: [
|
|
1663
|
+
"events",
|
|
1664
|
+
index,
|
|
1665
|
+
"data"
|
|
1666
|
+
],
|
|
1667
|
+
message: "redacted event history must redact messages"
|
|
1668
|
+
});
|
|
1669
|
+
if (report.eventHistory.status === "available" && event.data.redacted === true) context.addIssue({
|
|
1670
|
+
code: "custom",
|
|
1671
|
+
path: [
|
|
1672
|
+
"events",
|
|
1673
|
+
index,
|
|
1674
|
+
"data"
|
|
1675
|
+
],
|
|
1676
|
+
message: "available event history must expose messages"
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
if (report.eventHistory.status === "redacted" && event.data.type === "tool_calls" && event.data.calls.some((call) => call.input !== void 0 || call.output !== void 0)) context.addIssue({
|
|
1680
|
+
code: "custom",
|
|
1681
|
+
path: [
|
|
1682
|
+
"events",
|
|
1683
|
+
index,
|
|
1684
|
+
"data"
|
|
1685
|
+
],
|
|
1686
|
+
message: "redacted event history must redact tool payloads"
|
|
1687
|
+
});
|
|
1688
|
+
if (report.eventHistory.status === "redacted" && event.data.type === "assistant_message" && event.data.parts.some((part) => part.text !== void 0)) context.addIssue({
|
|
1689
|
+
code: "custom",
|
|
1690
|
+
path: [
|
|
1691
|
+
"events",
|
|
1692
|
+
index,
|
|
1693
|
+
"data"
|
|
1694
|
+
],
|
|
1695
|
+
message: "redacted event history must redact assistant messages"
|
|
1696
|
+
});
|
|
1697
|
+
if (report.eventHistory.status === "available" && event.data.type === "assistant_message" && event.data.parts.some((part) => part.redacted === true)) context.addIssue({
|
|
1698
|
+
code: "custom",
|
|
1699
|
+
path: [
|
|
1700
|
+
"events",
|
|
1701
|
+
index,
|
|
1702
|
+
"data"
|
|
1703
|
+
],
|
|
1704
|
+
message: "available event history must expose reasoning"
|
|
1705
|
+
});
|
|
1706
|
+
if (event.data.type === "tool_calls" && (report.eventHistory.status === "redacted" && event.data.assistant?.parts.some((part) => part.type === "reasoning" && part.text !== void 0) || report.eventHistory.status === "available" && event.data.assistant?.parts.some((part) => part.type === "reasoning" && part.redacted === true))) context.addIssue({
|
|
1707
|
+
code: "custom",
|
|
1708
|
+
path: [
|
|
1709
|
+
"events",
|
|
1710
|
+
index,
|
|
1711
|
+
"data",
|
|
1712
|
+
"assistant"
|
|
1713
|
+
],
|
|
1714
|
+
message: "assistant reasoning must match event history visibility"
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
/** One Conversation in the agent tree of a child Conversation. */
|
|
1719
|
+
const conversationAgentTreeNodeSchema = z.object({
|
|
1720
|
+
conversationId: z.string().min(1),
|
|
1721
|
+
kind: conversationKindSchema,
|
|
1722
|
+
label: z.string().min(1),
|
|
1723
|
+
/**
|
|
1724
|
+
* Agent type of a child, such as `explore`. Absent for a root, a child
|
|
1725
|
+
* without a type, or a viewer who cannot see private content.
|
|
1726
|
+
*/
|
|
1727
|
+
agentType: agentTypeSchema.optional(),
|
|
1728
|
+
/**
|
|
1729
|
+
* The child started with its parent's history. Absent like `agentType`,
|
|
1730
|
+
* or when the child started fresh.
|
|
1731
|
+
*/
|
|
1732
|
+
fork: z.literal(true).optional()
|
|
1733
|
+
}).strict();
|
|
1734
|
+
const conversationEventPageSchema = z.object({
|
|
1735
|
+
events: z.array(conversationReportEventSchema),
|
|
1736
|
+
eventHistory: conversationEventHistorySchema,
|
|
1737
|
+
previousCursor: z.string().min(1).optional(),
|
|
1738
|
+
/** Present on `after` and `around` pages when newer events follow. */
|
|
1739
|
+
nextCursor: z.string().min(1).optional(),
|
|
1740
|
+
generatedAt: z.string()
|
|
1741
|
+
}).strict().superRefine(validateConversationEvents);
|
|
1742
|
+
/**
|
|
1743
|
+
* Carries the detail version token in both directions. A custom header, not
|
|
1744
|
+
* `ETag`, for the reason on `CONTENT_VERSION_HEADER`.
|
|
1745
|
+
*/
|
|
1746
|
+
const CONVERSATION_DETAIL_VERSION_HEADER = "x-junior-detail-version";
|
|
1747
|
+
/**
|
|
1748
|
+
* Carries the change token of the Conversation tree that a detail report was
|
|
1749
|
+
* built from. The dashboard compares it with the token of `GET /api/versions`
|
|
1750
|
+
* and asks for the report only when they differ.
|
|
1751
|
+
*/
|
|
1752
|
+
const CONVERSATION_VERSION_HEADER = "x-junior-conversation-version";
|
|
1753
|
+
const conversationDetailReportSchema = conversationSummaryReportSchema.extend({
|
|
1754
|
+
/**
|
|
1755
|
+
* The parent chain of a child Conversation, root first, with this
|
|
1756
|
+
* Conversation last. Root Conversations omit it.
|
|
1757
|
+
*/
|
|
1758
|
+
agentTree: z.array(conversationAgentTreeNodeSchema).min(2).optional(),
|
|
1759
|
+
/** The viewer's effective auto-archive choice. Participants only. */
|
|
1760
|
+
autoArchive: z.boolean().optional(),
|
|
1761
|
+
/** The viewer can fork this conversation from an assistant reply. */
|
|
1762
|
+
canFork: z.boolean().optional(),
|
|
1763
|
+
/** The viewer can move this dashboard conversation to a Slack thread. */
|
|
1764
|
+
canContinueInSlack: z.literal(true).optional(),
|
|
1765
|
+
/**
|
|
1766
|
+
* Event Turn replies stay out of the Location. Set only for a root with
|
|
1767
|
+
* a Location, when the viewer is a participant, who can change it.
|
|
1768
|
+
*/
|
|
1769
|
+
deliveryPaused: z.boolean().optional(),
|
|
1770
|
+
/**
|
|
1771
|
+
* The viewer gets this conversation in their active feed. Participants
|
|
1772
|
+
* only. False after an unsubscribe, until they mention Junior again.
|
|
1773
|
+
*/
|
|
1774
|
+
subscribed: z.boolean().optional(),
|
|
1775
|
+
/** How far the signed-in viewer has read. Absent until they read. */
|
|
1776
|
+
readPosition: conversationReadPositionSchema.optional(),
|
|
1777
|
+
/**
|
|
1778
|
+
* Pass as `after` to the events API to read from the read position.
|
|
1779
|
+
* Present only when unread events start before `events`.
|
|
1780
|
+
*/
|
|
1781
|
+
unreadCursor: z.string().min(1).optional(),
|
|
1782
|
+
/**
|
|
1783
|
+
* The `around` page of `unreadCursor`, when the request asks for it. A
|
|
1784
|
+
* reader who opens at the read position needs no second request.
|
|
1785
|
+
*/
|
|
1786
|
+
unreadPage: conversationEventPageSchema.optional(),
|
|
1787
|
+
forkedFromConversationId: z.string().optional(),
|
|
1788
|
+
/** Title of the fork source, when the viewer can open it. */
|
|
1789
|
+
forkedFromTitle: z.string().optional(),
|
|
1790
|
+
forks: z.array(z.string()).optional(),
|
|
1791
|
+
/** People named in `summary`, resolved at read time. */
|
|
1792
|
+
summaryMentions: z.array(actorIdentitySchema).optional(),
|
|
1793
|
+
modelUsage: z.array(conversationModelUsageSchema).optional(),
|
|
1794
|
+
/**
|
|
1795
|
+
* Each person who wrote in the Conversation, by each of their Identity
|
|
1796
|
+
* ids. Messages and pending messages name their author with
|
|
1797
|
+
* `actorIdentityId`.
|
|
1798
|
+
*/
|
|
1799
|
+
authors: z.record(z.string(), actorIdentitySchema).optional(),
|
|
1800
|
+
events: z.array(conversationReportEventSchema),
|
|
1801
|
+
/**
|
|
1802
|
+
* Events hold only the events after the request's `after` cursor. The
|
|
1803
|
+
* report omits `previousCursor` and `unreadCursor`: the reader keeps its
|
|
1804
|
+
* own.
|
|
1805
|
+
*/
|
|
1806
|
+
appended: z.literal(true).optional(),
|
|
1807
|
+
/**
|
|
1808
|
+
* Pass as `after` on the next detail read to get only newer events.
|
|
1809
|
+
* Absent after a purge.
|
|
1810
|
+
*/
|
|
1811
|
+
appendCursor: z.string().min(1).optional(),
|
|
1812
|
+
eventHistory: conversationEventHistorySchema,
|
|
1813
|
+
previousCursor: z.string().min(1).optional(),
|
|
1814
|
+
generatedAt: z.string(),
|
|
1815
|
+
sentryConversationUrl: z.string().optional(),
|
|
1816
|
+
sourceTask: conversationSourceTaskSchema.optional()
|
|
1817
|
+
}).strict().superRefine(validateConversationEvents);
|
|
875
1818
|
// src/api/schema/automation.ts
|
|
876
1819
|
const automationDestinationSchema = z.object({
|
|
877
1820
|
channelId: z.string().min(1),
|
|
@@ -1221,6 +2164,23 @@ const automationEventCatalogSchema = z.array(z.object({
|
|
|
1221
2164
|
}).strict());
|
|
1222
2165
|
const automationScheduleIntentSchema = scheduleIntentSchema;
|
|
1223
2166
|
const automationSchedulePreviewSchema = scheduledAutomationSchema.pick({ schedule: true }).extend({ nextRunAtMs: z.number() }).strict();
|
|
2167
|
+
// src/api/schema/response.ts
|
|
2168
|
+
/** Stable error body returned by Junior-owned REST endpoints. */
|
|
2169
|
+
const apiErrorSchema = z.object({ error: z.string().min(1) }).strict();
|
|
2170
|
+
/**
|
|
2171
|
+
* Carries a content token in both directions. A custom header, not `ETag` /
|
|
2172
|
+
* `If-None-Match`: the Vercel CDN removes `If-None-Match` before it calls the
|
|
2173
|
+
* function, with every `Cache-Control` value, and no setting stops this. The
|
|
2174
|
+
* CDN then answers a match with a 304 only after the function built the full
|
|
2175
|
+
* response, so the read is not saved and the 304 does not show in app
|
|
2176
|
+
* telemetry. A probe deployment confirmed this for `private, no-cache`,
|
|
2177
|
+
* `no-cache`, `private, no-store`, `private, max-age=0, must-revalidate`, and
|
|
2178
|
+
* no header. See
|
|
2179
|
+
* https://vercel.com/docs/manage-cdn-usage#optimizing-fast-origin-transfer.
|
|
2180
|
+
* A read that sends the token of the copy it holds gets an empty 304 while
|
|
2181
|
+
* the content is unchanged.
|
|
2182
|
+
*/
|
|
2183
|
+
const CONTENT_VERSION_HEADER = "x-junior-content-version";
|
|
1224
2184
|
// src/chat/notifications/schedule.ts
|
|
1225
2185
|
/**
|
|
1226
2186
|
* Notification hours for one user.
|
|
@@ -1309,4 +2269,88 @@ function isWithinNotificationSchedule(schedule, timezone, nowMs) {
|
|
|
1309
2269
|
if (minutes < end) return schedule.days.includes((weekday + 6) % 7);
|
|
1310
2270
|
return false;
|
|
1311
2271
|
}
|
|
1312
|
-
|
|
2272
|
+
// src/chat/attachments/media.ts
|
|
2273
|
+
const INPUT_IMAGE_TYPES = [
|
|
2274
|
+
"image/png",
|
|
2275
|
+
"image/jpeg",
|
|
2276
|
+
"image/gif",
|
|
2277
|
+
"image/webp"
|
|
2278
|
+
];
|
|
2279
|
+
/** Video types that browsers play in a `<video>` element. */
|
|
2280
|
+
const INLINE_VIDEO_TYPES = ["video/mp4", "video/webm"];
|
|
2281
|
+
/** Leading bytes of each accepted image type. `null` matches any byte. */
|
|
2282
|
+
const IMAGE_SIGNATURES = [
|
|
2283
|
+
{
|
|
2284
|
+
mediaType: "image/png",
|
|
2285
|
+
bytes: [
|
|
2286
|
+
137,
|
|
2287
|
+
80,
|
|
2288
|
+
78,
|
|
2289
|
+
71,
|
|
2290
|
+
13,
|
|
2291
|
+
10,
|
|
2292
|
+
26,
|
|
2293
|
+
10
|
|
2294
|
+
]
|
|
2295
|
+
},
|
|
2296
|
+
{
|
|
2297
|
+
mediaType: "image/jpeg",
|
|
2298
|
+
bytes: [
|
|
2299
|
+
255,
|
|
2300
|
+
216,
|
|
2301
|
+
255
|
|
2302
|
+
]
|
|
2303
|
+
},
|
|
2304
|
+
{
|
|
2305
|
+
mediaType: "image/gif",
|
|
2306
|
+
bytes: [
|
|
2307
|
+
71,
|
|
2308
|
+
73,
|
|
2309
|
+
70,
|
|
2310
|
+
56,
|
|
2311
|
+
55,
|
|
2312
|
+
97
|
|
2313
|
+
]
|
|
2314
|
+
},
|
|
2315
|
+
{
|
|
2316
|
+
mediaType: "image/gif",
|
|
2317
|
+
bytes: [
|
|
2318
|
+
71,
|
|
2319
|
+
73,
|
|
2320
|
+
70,
|
|
2321
|
+
56,
|
|
2322
|
+
57,
|
|
2323
|
+
97
|
|
2324
|
+
]
|
|
2325
|
+
},
|
|
2326
|
+
{
|
|
2327
|
+
mediaType: "image/webp",
|
|
2328
|
+
bytes: [
|
|
2329
|
+
82,
|
|
2330
|
+
73,
|
|
2331
|
+
70,
|
|
2332
|
+
70,
|
|
2333
|
+
null,
|
|
2334
|
+
null,
|
|
2335
|
+
null,
|
|
2336
|
+
null,
|
|
2337
|
+
87,
|
|
2338
|
+
69,
|
|
2339
|
+
66,
|
|
2340
|
+
80
|
|
2341
|
+
]
|
|
2342
|
+
}
|
|
2343
|
+
];
|
|
2344
|
+
/**
|
|
2345
|
+
* Detect an accepted image type from file bytes. Use this instead of a file
|
|
2346
|
+
* name or declared content type, which can be wrong.
|
|
2347
|
+
*/
|
|
2348
|
+
function detectImageMediaType(data) {
|
|
2349
|
+
return IMAGE_SIGNATURES.find(({ bytes }) => data.length >= bytes.length && bytes.every((byte, index) => byte === null || data[index] === byte))?.mediaType;
|
|
2350
|
+
}
|
|
2351
|
+
/** Report whether a media type is a raster image accepted by vision models. */
|
|
2352
|
+
function isVisionImageMediaType(mediaType) {
|
|
2353
|
+
const normalized = mediaType.split(";", 1)[0]?.trim().toLowerCase();
|
|
2354
|
+
return normalized ? INPUT_IMAGE_TYPES.some((type) => type === normalized) : false;
|
|
2355
|
+
}
|
|
2356
|
+
export { conversationReportStatusSchema as $, formatUserInputAnswer as $t, automationVersionActivateSchema as A, automationContextToolSchema as At, conversationActivityPreviewSchema as B, toolScheduleIntentSchema as Bt, automationRunListSchema as C, removedCardSchema as Ct, automationSchedulePreviewSchema as D, inputFileSchema as Dt, automationScheduleIntentSchema as E, MAX_INPUT_ATTACHMENTS as Et, scheduledAutomationSummarySchema as F, scheduledAutomationSchema as Ft, conversationDetailReportSchema as G, isValidTimeZone as Gt, conversationAttachmentQuerySchema as H, getFirstRunAtMs as Ht, CONVERSATION_DETAIL_VERSION_HEADER as I, scheduledRunSchema as It, conversationEventsQuerySchema as J, inboxItemRequestSchema as Jt, conversationEventHistorySchema as K, eventAutomationSchema as Kt, CONVERSATION_VERSION_HEADER as L, ScheduleIntentError as Lt, automationVersionParamsSchema as M, automationTitleSchema as Mt, automationVersionSchema as N, taskOutcomeInputSchema as Nt, automationSummarySchema as O, messageAttachmentSchema as Ot, eventAutomationSummarySchema as P, SCHEDULED_AUTOMATION_SYSTEM_ACTOR as Pt, conversationReportMessageEventSchema as Q, buttonUserInputField as Qt, acceptedConversationMessageSchema as R, compileScheduleIntent as Rt, automationParamsSchema as S, readMessageCardRefs as St, automationRunWindowsSchema as T, MAX_ATTACHMENT_BYTES as Tt, conversationAuxiliaryCostsSchema as U, getNextRunAtMs as Ut, conversationAttachmentParamsSchema as V, weekdaySchema as Vt, conversationDetailQuerySchema as W, getZonedDateTimeParts as Wt, conversationReportEventDataSchema as X, USER_INPUT_NOTE as Xt, conversationParamsSchema as Y, USER_INPUT_LIMITS as Yt, conversationReportEventSchema as Z, answeredChoices as Zt, automationLifecycleSchema as _, conversationReadPositionSchema as _t, DEFAULT_NOTIFICATION_SCHEDULE as a, automationTaskDescription as an, idempotencyKeySchema as at, automationListQuerySchema as b, messageCardRef as bt, CONTENT_VERSION_HEADER as c, AGENT_TYPES as ct, automationEditSchema as d, formatAgentTypes as dt, isEmptyUserInputAnswer as en, conversationSummaryReportSchema as et, automationEventCatalogSchema as f, conversationTreeStateSchema as ft, automationExecutionStatusSchema as g, renameConversationResponseSchema as gt, automationExecutionStatusDaySchema as h, renameConversationBodySchema as ht, isVisionImageMediaType as i, automationTaskColumns as in, createConversationMessageBodySchema as it, automationVersionListSchema as j, automationInstructionToolSchema as jt, automationUpdateSchema as k, readMessageAttachments as kt, apiErrorSchema as l, agentTypeInstructions as lt, automationExecutionSchema as m, conversationTitleSchema as mt, INPUT_IMAGE_TYPES as n, userInputRequestSchema as nn, conversationUsageSchema as nt, isWithinNotificationSchedule as o, automationTaskSchema as on, activityPreviewText as ot, automationExecutionListSchema as p, CONVERSATION_TITLE_MAX_LENGTH as pt, conversationEventPageSchema as q, eventAutomationTriggerSchema as qt, detectImageMediaType as r, automationSkillNameSchema as rn, createConversationBodySchema as rt, notificationScheduleSchema as s, automationTaskText as sn, conversationChildAgentTotalsSchema as st, INLINE_VIDEO_TYPES as t, normalizeUserInputAnswer as tn, conversationSurfaceSchema as tt, automationEditErrorSchema as u, agentTypeSchema as ut, automationListItemSchema as v, inboxItemChangeRecordSchema as vt, automationRunSchema as w, resolveMessageCards as wt, automationListSchema as x, messageCardText as xt, automationListPageSchema as y, annotationCard as yt, actorIdentitySchema as z, scheduleIntentFromTool as zt };
|