@sentry/junior 0.188.0 → 0.190.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/{agent-hooks-5RQEVLQD.js → agent-hooks-3IG2FQW2.js} +11 -11
- package/dist/api/acp/conversations.d.ts +2 -2
- package/dist/api/conversations/list.d.ts +7 -0
- package/dist/api/people/shared.d.ts +54 -0
- package/dist/api.js +44 -55
- package/dist/app.d.ts +1 -1
- package/dist/app.js +1025 -349
- package/dist/{catalog-runtime-L4A6BJ3U.js → catalog-runtime-2OT7S3ZC.js} +4 -4
- package/dist/chat/actor.d.ts +7 -2
- package/dist/chat/agent/resume.d.ts +0 -2
- package/dist/chat/agent/types.d.ts +8 -9
- package/dist/chat/agent-dispatch/work.d.ts +1 -10
- package/dist/chat/agent-invocations/spawn.d.ts +1 -1
- package/dist/chat/agent-invocations/types.d.ts +44 -108
- package/dist/chat/app/conversation-work.d.ts +16 -8
- package/dist/chat/conversation-privacy.d.ts +7 -7
- package/dist/chat/conversations/destination.d.ts +12 -0
- package/dist/chat/conversations/projection.d.ts +2 -2
- package/dist/chat/conversations/sql/location.d.ts +13 -4
- package/dist/chat/{api-turns → conversations}/stop.d.ts +2 -2
- package/dist/chat/conversations/store.d.ts +4 -4
- package/dist/chat/conversations/structured-events.d.ts +1 -1
- package/dist/chat/{api-turns/authorization.d.ts → conversations/web-authorization.d.ts} +1 -0
- package/dist/chat/conversations/web-input.d.ts +98 -0
- package/dist/chat/conversations/web-mailbox.d.ts +12 -0
- package/dist/chat/event-tasks/tool-support.d.ts +1 -7
- package/dist/chat/providers/slack/runtime.d.ts +1 -0
- package/dist/chat/providers/slack/system-turn.d.ts +8 -0
- package/dist/chat/resource-events/actor.d.ts +13 -12
- package/dist/chat/resource-events/notification.d.ts +1 -1
- package/dist/chat/services/guardian-action-policy.d.ts +1 -1
- package/dist/chat/services/turn-session-routing.d.ts +2 -2
- package/dist/chat/source.d.ts +3 -3
- package/dist/chat/task-execution/assistant-message.d.ts +32 -0
- package/dist/chat/task-execution/conversation-turn.d.ts +8 -0
- package/dist/chat/{api-turns → task-execution}/mailbox-input.d.ts +1 -2
- package/dist/chat/task-execution/mailbox-turn.d.ts +52 -0
- package/dist/chat/task-execution/paused-turn.d.ts +1 -1
- package/dist/chat/task-execution/slack-work.d.ts +0 -2
- package/dist/chat/task-execution/state.d.ts +2 -2
- package/dist/chat/task-execution/store.d.ts +1 -1
- package/dist/chat/task-execution/turn-cursor.d.ts +10 -1
- package/dist/chat/tools/types.d.ts +9 -2
- package/dist/{chunk-XJIPMHKI.js → chunk-2MKHYSYL.js} +3 -3
- package/dist/{chunk-QCGNHSMA.js → chunk-2MRF22J4.js} +25 -10
- package/dist/{chunk-HCIVBCP5.js → chunk-3J3BCB4J.js} +1 -1
- package/dist/chunk-4BLFIYVK.js +703 -0
- package/dist/{chunk-NZLZ4KYZ.js → chunk-4PKEJK5B.js} +1 -1
- package/dist/{chunk-VFZAUQ5V.js → chunk-62DRKZQU.js} +5 -183
- package/dist/{chunk-QIOUTXTZ.js → chunk-663DQH5W.js} +1 -1
- package/dist/{chunk-Z5SKZE5B.js → chunk-67MMSYSE.js} +4 -12
- package/dist/{chunk-ZX7RSBQ6.js → chunk-6BXUSF7J.js} +1 -1
- package/dist/{chunk-W42ENMJW.js → chunk-6H7YU6XH.js} +1 -1
- package/dist/{chunk-WGZJ5SU4.js → chunk-7UJ6IJCK.js} +1 -1
- package/dist/{chunk-QDHJTKPE.js → chunk-7Y7XMI6P.js} +8 -6
- package/dist/{chunk-6YGFBU3A.js → chunk-BGOLRC36.js} +62 -336
- package/dist/{chunk-CVBDVIF4.js → chunk-BUJU6C2J.js} +1 -1
- package/dist/{chunk-XI4PVY2T.js → chunk-CZXZKTAI.js} +5 -5
- package/dist/chunk-DA2KGZZI.js +13 -0
- package/dist/{chunk-RMB7CERI.js → chunk-DJZGQ7OL.js} +311 -137
- package/dist/{chunk-FIUCHYT6.js → chunk-DVX6U6GI.js} +1 -1
- package/dist/{chunk-AW77HH54.js → chunk-ECOR3OXY.js} +19 -299
- package/dist/{chunk-WW2Y7JIA.js → chunk-F3K2267N.js} +51 -50
- package/dist/{chunk-W2DDJCPS.js → chunk-FVFJ57RK.js} +8 -8
- package/dist/{chunk-UVUXFRYN.js → chunk-GWCFXTB6.js} +211 -7
- package/dist/{chunk-X55FOVZO.js → chunk-HI5KXE3C.js} +3 -3
- package/dist/{chunk-ERZMACYA.js → chunk-IRQ3RSX3.js} +3 -3
- package/dist/{chunk-32XSSFZV.js → chunk-JV7U4665.js} +1 -1
- package/dist/chunk-MNHJ4WLE.js +285 -0
- package/dist/{chunk-SC67CH3C.js → chunk-OJFX2FP7.js} +14 -17
- package/dist/{chunk-IUUQWIG2.js → chunk-OKAHLUSU.js} +70 -19
- package/dist/{chunk-PSHMPRIU.js → chunk-OON4IQHH.js} +2 -2
- package/dist/{chunk-6JZGXLL2.js → chunk-OYCOLHCR.js} +5 -7
- package/dist/{chunk-3HEZWDS5.js → chunk-REVH4BZU.js} +2 -2
- package/dist/{chunk-CDSLOYOR.js → chunk-RLYJYEIY.js} +6 -6
- package/dist/{chunk-CZRWU4ZM.js → chunk-T66GV7A3.js} +2 -5
- package/dist/{chunk-Q7O74WOO.js → chunk-VWNIDTFR.js} +2 -2
- package/dist/{chunk-CIG6WI7Q.js → chunk-W2C4TPLB.js} +5 -5
- package/dist/{chunk-QIMN3FXL.js → chunk-Y4WL4OYD.js} +1 -1
- package/dist/{chunk-MQDIIFZM.js → chunk-YFU4DGZY.js} +12 -5
- package/dist/chunk-YKIAUKYH.js +311 -0
- package/dist/{chunk-QVH6FW3T.js → chunk-ZFCO2TMB.js} +7 -3
- package/dist/cli/chat.js +34 -33
- package/dist/cli/check.js +5 -5
- package/dist/cli/plugins.js +12 -12
- package/dist/cli/snapshot-create.js +9 -9
- package/dist/cli/upgrade.js +6 -6
- package/dist/db/schema/agent-invocations.d.ts +18 -42
- package/dist/db/schema/conversations.d.ts +62 -0
- package/dist/db/schema.d.ts +49 -42
- package/dist/{db-YPRZAA2T.js → db-2IFDMDDY.js} +6 -6
- package/dist/instrumentation.js +3 -3
- package/dist/nitro.js +6 -6
- package/dist/{oauth-callback-server-DBBIR3XG.js → oauth-callback-server-SZSS2KH6.js} +30 -28
- package/dist/{runner-FKVFFPLO.js → runner-2N4QU77X.js} +25 -21
- package/dist/{skills-4RBAZEMV.js → skills-VU2LZAKX.js} +5 -5
- package/dist/spawn-3K7RV4T5.js +42 -0
- package/dist/task-runner-52DYFHW3.js +36 -0
- package/dist/{validation-E6Z5LHZM.js → validation-IJGHK7NI.js} +5 -5
- package/dist/version.js +1 -1
- package/dist/{work-OFTXWOK4.js → work-DI45MLRL.js} +22 -21
- package/dist/{worker-OMWNOKTJ.js → worker-FY7KWG2M.js} +10 -10
- package/migrations/0037_conversation_location.sql +23 -0
- package/migrations/meta/0037_snapshot.json +3192 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +4 -4
- package/dist/chat/api-turns/assistant-message.d.ts +0 -12
- package/dist/chat/api-turns/cancellation.d.ts +0 -24
- package/dist/chat/api-turns/routing.d.ts +0 -51
- package/dist/chat/api-turns/work.d.ts +0 -99
- package/dist/chat/task-execution/slack-resource-event.d.ts +0 -55
- package/dist/chunk-6FGN7ZEG.js +0 -221
- package/dist/chunk-LODJKINF.js +0 -1502
- package/dist/spawn-CO7QFCNJ.js +0 -41
- package/dist/task-runner-DUGZGI7V.js +0 -34
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
JUNIOR_NATIVE_EVENT_NAMESPACE,
|
|
3
|
+
ToolInputError,
|
|
4
|
+
addAgentTurnUsage,
|
|
5
|
+
agentsInstructionsUpdatedEvent,
|
|
6
|
+
authenticationLinkedEvent,
|
|
7
|
+
authenticationUnlinkedEvent,
|
|
8
|
+
fallbackShortTitle,
|
|
9
|
+
generateShortTitle
|
|
10
|
+
} from "./chunk-YKIAUKYH.js";
|
|
4
11
|
import {
|
|
5
12
|
bindProviderConversation,
|
|
6
13
|
createSqlConversationEventStore,
|
|
@@ -9,18 +16,18 @@ import {
|
|
|
9
16
|
getSqlExecutor,
|
|
10
17
|
sanitizePostgresJson,
|
|
11
18
|
withConversationEventLock
|
|
12
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-OKAHLUSU.js";
|
|
13
20
|
import {
|
|
14
21
|
SANDBOX_REPOS_ROOT,
|
|
15
22
|
SANDBOX_WORKSPACE_ROOT,
|
|
16
23
|
sleep
|
|
17
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-HI5KXE3C.js";
|
|
18
25
|
import {
|
|
19
26
|
MUTATION_LOCK_TTL_MS,
|
|
20
27
|
fenceLock,
|
|
21
28
|
getStateAdapter,
|
|
22
29
|
withLock
|
|
23
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-6BXUSF7J.js";
|
|
24
31
|
import {
|
|
25
32
|
agentHistoryItemSchema,
|
|
26
33
|
contextProvenance,
|
|
@@ -33,7 +40,7 @@ import {
|
|
|
33
40
|
escapeXml,
|
|
34
41
|
resolveGatewayModel,
|
|
35
42
|
unwrapCurrentInstruction
|
|
36
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-VWNIDTFR.js";
|
|
37
44
|
import {
|
|
38
45
|
parseSlackMessageTs,
|
|
39
46
|
toStoredSlackActor
|
|
@@ -43,7 +50,7 @@ import {
|
|
|
43
50
|
logException,
|
|
44
51
|
logWarn,
|
|
45
52
|
setSpanAttributes
|
|
46
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-Y4WL4OYD.js";
|
|
47
54
|
|
|
48
55
|
// src/chat/turn-context-tag.ts
|
|
49
56
|
var TURN_CONTEXT_TAG = "runtime-turn-context";
|
|
@@ -567,69 +574,6 @@ function getConversationMessageSlackTs(message) {
|
|
|
567
574
|
import { createHash } from "crypto";
|
|
568
575
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
|
|
569
576
|
|
|
570
|
-
// src/chat/services/short-title.ts
|
|
571
|
-
var SHORT_TITLE_MAX_LENGTH = 60;
|
|
572
|
-
var TITLE_PROMPTS = {
|
|
573
|
-
conversation: [
|
|
574
|
-
"Generate a concise 5-8 word conversation title from the first user message below.",
|
|
575
|
-
"Capture the user's main request.",
|
|
576
|
-
"Reply with ONLY the title, with no quotes or trailing punctuation."
|
|
577
|
-
],
|
|
578
|
-
task: [
|
|
579
|
-
"Generate a concise 5-8 word task title from the task instruction below.",
|
|
580
|
-
"Capture the task's main purpose.",
|
|
581
|
-
"Reply with ONLY the title, with no quotes or trailing punctuation."
|
|
582
|
-
]
|
|
583
|
-
};
|
|
584
|
-
function normalizeShortTitle(value) {
|
|
585
|
-
return value.replace(/\s+/g, " ").trim().slice(0, SHORT_TITLE_MAX_LENGTH);
|
|
586
|
-
}
|
|
587
|
-
function fallbackShortTitle(sourceText, fallback = "Untitled") {
|
|
588
|
-
const firstLine = sourceText.split(/\r?\n/).map((line) => line.trim()).find((line) => line.length > 0) ?? "";
|
|
589
|
-
return normalizeShortTitle(firstLine) || fallback;
|
|
590
|
-
}
|
|
591
|
-
async function generateShortTitle(args) {
|
|
592
|
-
const sourceText = args.sourceText.trim();
|
|
593
|
-
if (!sourceText) return void 0;
|
|
594
|
-
try {
|
|
595
|
-
const result = await args.completeText({
|
|
596
|
-
modelId: botConfig.fastModelId,
|
|
597
|
-
temperature: 0,
|
|
598
|
-
promptName: `junior.${args.kind}_title`,
|
|
599
|
-
messages: [
|
|
600
|
-
{
|
|
601
|
-
role: "user",
|
|
602
|
-
content: [
|
|
603
|
-
...TITLE_PROMPTS[args.kind],
|
|
604
|
-
"",
|
|
605
|
-
args.kind === "conversation" ? `First user message: ${sourceText.slice(0, 500)}` : `Task instruction: ${sourceText.slice(0, 500)}`
|
|
606
|
-
].join("\n"),
|
|
607
|
-
timestamp: Date.now()
|
|
608
|
-
}
|
|
609
|
-
],
|
|
610
|
-
metadata: {
|
|
611
|
-
modelId: botConfig.fastModelId
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
const title = normalizeShortTitle(result.text);
|
|
615
|
-
return title || void 0;
|
|
616
|
-
} catch (error) {
|
|
617
|
-
logWarn(`${args.kind}.title.generation.failed`, {
|
|
618
|
-
"exception.message": error instanceof Error ? error.message : String(error)
|
|
619
|
-
});
|
|
620
|
-
return void 0;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
async function resolveTaskTitle(args) {
|
|
624
|
-
const explicit = normalizeShortTitle(args.title ?? "");
|
|
625
|
-
if (explicit) return explicit;
|
|
626
|
-
return generateShortTitle({
|
|
627
|
-
completeText: args.completeText,
|
|
628
|
-
kind: "task",
|
|
629
|
-
sourceText: args.instruction
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
|
|
633
577
|
// src/chat/services/conversation-title.ts
|
|
634
578
|
var inFlightTitles = /* @__PURE__ */ new Map();
|
|
635
579
|
async function ensureConversationTitle(args) {
|
|
@@ -941,131 +885,6 @@ var piContentMessageSchema = z.object({
|
|
|
941
885
|
role: z.string().min(1)
|
|
942
886
|
}).passthrough().transform((value) => value);
|
|
943
887
|
|
|
944
|
-
// src/chat/conversations/structured-events.ts
|
|
945
|
-
import {
|
|
946
|
-
conversationEventPresentationSchema,
|
|
947
|
-
defineConversationEvent
|
|
948
|
-
} from "@sentry/junior-plugin-api";
|
|
949
|
-
import { z as z2 } from "zod";
|
|
950
|
-
var JUNIOR_NATIVE_EVENT_NAMESPACE = "junior";
|
|
951
|
-
var authenticationEventContentSchema = z2.object({
|
|
952
|
-
accountLabel: z2.string().trim().min(1).max(120).optional(),
|
|
953
|
-
actorId: z2.string().min(1),
|
|
954
|
-
authorizationId: z2.string().min(1).optional(),
|
|
955
|
-
provider: z2.string().regex(/^[a-z][a-z0-9-]*$/),
|
|
956
|
-
providerLabel: z2.string().trim().min(1).max(80).optional()
|
|
957
|
-
}).strict();
|
|
958
|
-
var agentsInstructionsUpdatedContentSchema = z2.object({
|
|
959
|
-
action: z2.enum(["loaded", "replaced", "cleared"]),
|
|
960
|
-
directory: z2.string().trim().min(1).max(500).optional(),
|
|
961
|
-
fingerprint: z2.string().trim().min(1).max(128),
|
|
962
|
-
sources: z2.array(
|
|
963
|
-
z2.object({
|
|
964
|
-
content: z2.string().min(1).max(32 * 1024),
|
|
965
|
-
path: z2.string().trim().min(1).max(500)
|
|
966
|
-
}).strict()
|
|
967
|
-
).max(32),
|
|
968
|
-
textBytes: z2.number().int().nonnegative().optional()
|
|
969
|
-
}).strict();
|
|
970
|
-
function providerTitle(content) {
|
|
971
|
-
return content.providerLabel?.trim() || content.provider;
|
|
972
|
-
}
|
|
973
|
-
function agentsInstructionsTitle(action) {
|
|
974
|
-
if (action === "loaded") return "Loaded AGENTS.md";
|
|
975
|
-
if (action === "replaced") return "Updated AGENTS.md";
|
|
976
|
-
return "Cleared AGENTS.md";
|
|
977
|
-
}
|
|
978
|
-
function sourceFilename(sourcePath) {
|
|
979
|
-
return sourcePath.split("/").at(-1) || sourcePath;
|
|
980
|
-
}
|
|
981
|
-
function formatBytes(bytes) {
|
|
982
|
-
if (bytes < 1024) return `${bytes} bytes`;
|
|
983
|
-
const kilobytes = bytes / 1024;
|
|
984
|
-
return `${Number.isInteger(kilobytes) ? kilobytes : kilobytes.toFixed(1)} KB`;
|
|
985
|
-
}
|
|
986
|
-
function agentsInstructionsPreview(content) {
|
|
987
|
-
const source = content.sources[0];
|
|
988
|
-
if (!source) return void 0;
|
|
989
|
-
const filename = sourceFilename(source.path);
|
|
990
|
-
const label = content.sources.length === 1 ? filename : `${content.sources.length} AGENTS.md files`;
|
|
991
|
-
return typeof content.textBytes === "number" ? `${label} \xB7 ${formatBytes(content.textBytes)}` : label;
|
|
992
|
-
}
|
|
993
|
-
var authenticationLinkedEvent = defineConversationEvent({
|
|
994
|
-
name: "authentication_linked",
|
|
995
|
-
version: 1,
|
|
996
|
-
schema: authenticationEventContentSchema,
|
|
997
|
-
renderEvent(event) {
|
|
998
|
-
const provider = providerTitle(event);
|
|
999
|
-
return {
|
|
1000
|
-
icon: "link",
|
|
1001
|
-
title: `${provider} connected`,
|
|
1002
|
-
...event.accountLabel ? { preview: `Connected as \`${event.accountLabel}\`` } : void 0,
|
|
1003
|
-
details: [
|
|
1004
|
-
{
|
|
1005
|
-
title: `${provider} connected`,
|
|
1006
|
-
...event.accountLabel ? { description: `Connected as \`${event.accountLabel}\`` } : void 0,
|
|
1007
|
-
metadata: [event.provider]
|
|
1008
|
-
}
|
|
1009
|
-
]
|
|
1010
|
-
};
|
|
1011
|
-
}
|
|
1012
|
-
});
|
|
1013
|
-
var authenticationUnlinkedEvent = defineConversationEvent({
|
|
1014
|
-
name: "authentication_unlinked",
|
|
1015
|
-
version: 1,
|
|
1016
|
-
schema: authenticationEventContentSchema,
|
|
1017
|
-
renderEvent(event) {
|
|
1018
|
-
const provider = providerTitle(event);
|
|
1019
|
-
return {
|
|
1020
|
-
icon: "key",
|
|
1021
|
-
title: `${provider} disconnected`,
|
|
1022
|
-
details: [
|
|
1023
|
-
{
|
|
1024
|
-
title: `${provider} disconnected`,
|
|
1025
|
-
metadata: [event.provider]
|
|
1026
|
-
}
|
|
1027
|
-
]
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
});
|
|
1031
|
-
var agentsInstructionsUpdatedEvent = defineConversationEvent({
|
|
1032
|
-
name: "agents_instructions_updated",
|
|
1033
|
-
version: 1,
|
|
1034
|
-
schema: agentsInstructionsUpdatedContentSchema,
|
|
1035
|
-
renderEvent(event) {
|
|
1036
|
-
const title = agentsInstructionsTitle(event.action);
|
|
1037
|
-
const preview = agentsInstructionsPreview(event);
|
|
1038
|
-
return {
|
|
1039
|
-
icon: "brain",
|
|
1040
|
-
title,
|
|
1041
|
-
...preview ? { preview } : void 0,
|
|
1042
|
-
...event.sources.length > 0 ? {
|
|
1043
|
-
details: event.sources.map((source) => ({
|
|
1044
|
-
title: sourceFilename(source.path),
|
|
1045
|
-
content: source.content
|
|
1046
|
-
}))
|
|
1047
|
-
} : void 0
|
|
1048
|
-
};
|
|
1049
|
-
}
|
|
1050
|
-
});
|
|
1051
|
-
var NATIVE_EVENT_DEFINITIONS = [
|
|
1052
|
-
authenticationLinkedEvent,
|
|
1053
|
-
authenticationUnlinkedEvent,
|
|
1054
|
-
agentsInstructionsUpdatedEvent
|
|
1055
|
-
];
|
|
1056
|
-
function getJuniorNativeEventDefinition(args) {
|
|
1057
|
-
return NATIVE_EVENT_DEFINITIONS.find(
|
|
1058
|
-
(definition) => definition.eventName === args.name && definition.version === args.version
|
|
1059
|
-
);
|
|
1060
|
-
}
|
|
1061
|
-
function renderJuniorNativeConversationEvent(args) {
|
|
1062
|
-
if (args.namespace !== JUNIOR_NATIVE_EVENT_NAMESPACE) return void 0;
|
|
1063
|
-
const definition = getJuniorNativeEventDefinition(args);
|
|
1064
|
-
if (!definition) return void 0;
|
|
1065
|
-
const presentation = definition.renderEvent(definition.parse(args.content));
|
|
1066
|
-
return presentation === void 0 ? void 0 : conversationEventPresentationSchema.parse(presentation);
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
888
|
// src/chat/pi/conversation-events.ts
|
|
1070
889
|
function authorizationObservationMessage(data, createdAtMs) {
|
|
1071
890
|
const label = data.kind === "mcp" ? "MCP authorization" : "Authorization";
|
|
@@ -1737,7 +1556,11 @@ async function persistWithRetry(persist) {
|
|
|
1737
1556
|
}
|
|
1738
1557
|
|
|
1739
1558
|
// src/chat/task-execution/turn-cursor.ts
|
|
1740
|
-
import {
|
|
1559
|
+
import {
|
|
1560
|
+
actorSchema,
|
|
1561
|
+
sourceSchema
|
|
1562
|
+
} from "@sentry/junior-plugin-api";
|
|
1563
|
+
import { z as z2 } from "zod";
|
|
1741
1564
|
|
|
1742
1565
|
// src/chat/repository-instructions.ts
|
|
1743
1566
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -1745,16 +1568,6 @@ import path2 from "path";
|
|
|
1745
1568
|
|
|
1746
1569
|
// src/chat/tools/sandbox/file-utils.ts
|
|
1747
1570
|
import path from "path";
|
|
1748
|
-
|
|
1749
|
-
// src/chat/tools/execution/tool-input-error.ts
|
|
1750
|
-
var ToolInputError = class extends Error {
|
|
1751
|
-
constructor(message, options) {
|
|
1752
|
-
super(message, options);
|
|
1753
|
-
this.name = "ToolInputError";
|
|
1754
|
-
}
|
|
1755
|
-
};
|
|
1756
|
-
|
|
1757
|
-
// src/chat/tools/sandbox/file-utils.ts
|
|
1758
1571
|
var MAX_TEXT_CHARS = 6e4;
|
|
1759
1572
|
var RIPGREP_EXCLUDED_GLOBS = [
|
|
1760
1573
|
"!**/.git/**",
|
|
@@ -2202,64 +2015,67 @@ function definedProps(values) {
|
|
|
2202
2015
|
Object.entries(values).filter(([, value]) => value !== void 0)
|
|
2203
2016
|
);
|
|
2204
2017
|
}
|
|
2205
|
-
var turnStatusSchema =
|
|
2018
|
+
var turnStatusSchema = z2.enum([
|
|
2206
2019
|
"running",
|
|
2207
2020
|
"paused",
|
|
2208
2021
|
"completed",
|
|
2209
2022
|
"failed",
|
|
2210
2023
|
"abandoned"
|
|
2211
2024
|
]);
|
|
2212
|
-
var turnSurfaceSchema =
|
|
2025
|
+
var turnSurfaceSchema = z2.enum([
|
|
2213
2026
|
"slack",
|
|
2214
2027
|
"api",
|
|
2215
2028
|
"scheduler",
|
|
2216
2029
|
"internal"
|
|
2217
2030
|
]);
|
|
2218
|
-
var turnPauseReasonSchema =
|
|
2031
|
+
var turnPauseReasonSchema = z2.enum([
|
|
2219
2032
|
"timeout",
|
|
2220
2033
|
"auth",
|
|
2221
2034
|
"yield",
|
|
2222
2035
|
"retry"
|
|
2223
2036
|
]);
|
|
2224
|
-
var nonNegativeNumberSchema =
|
|
2225
|
-
var seqCursorSchema =
|
|
2226
|
-
var storedTurnSummarySchema =
|
|
2227
|
-
schemaVersion:
|
|
2228
|
-
version:
|
|
2229
|
-
conversationId:
|
|
2230
|
-
dispatchId:
|
|
2231
|
-
dispatchOutcome:
|
|
2232
|
-
resultMessageId:
|
|
2037
|
+
var nonNegativeNumberSchema = z2.number().finite().nonnegative();
|
|
2038
|
+
var seqCursorSchema = z2.number().int().min(-1);
|
|
2039
|
+
var storedTurnSummarySchema = z2.object({
|
|
2040
|
+
schemaVersion: z2.literal(TURN_CURSOR_SCHEMA_VERSION),
|
|
2041
|
+
version: z2.number().int().nonnegative(),
|
|
2042
|
+
conversationId: z2.string().min(1),
|
|
2043
|
+
dispatchId: z2.string().min(1).optional(),
|
|
2044
|
+
dispatchOutcome: z2.enum(["blocked", "completed", "failed"]).optional(),
|
|
2045
|
+
resultMessageId: z2.string().min(1).optional(),
|
|
2233
2046
|
resumeReason: turnPauseReasonSchema.optional(),
|
|
2234
|
-
turnId:
|
|
2235
|
-
sliceId:
|
|
2047
|
+
turnId: z2.string().min(1),
|
|
2048
|
+
sliceId: z2.number().int().nonnegative(),
|
|
2236
2049
|
state: turnStatusSchema,
|
|
2237
2050
|
surface: turnSurfaceSchema.optional(),
|
|
2238
2051
|
updatedAtMs: nonNegativeNumberSchema
|
|
2239
2052
|
}).strip();
|
|
2240
|
-
var storedTurnRecordSchema =
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2053
|
+
var storedTurnRecordSchema = z2.object({
|
|
2054
|
+
// TODO(dcramer): Require Actor after no deployed Turn cursor can omit it.
|
|
2055
|
+
actor: actorSchema.optional(),
|
|
2056
|
+
schemaVersion: z2.literal(TURN_CURSOR_SCHEMA_VERSION),
|
|
2057
|
+
version: z2.number().int().nonnegative(),
|
|
2058
|
+
conversationId: z2.string().min(1),
|
|
2059
|
+
dispatchId: z2.string().min(1).optional(),
|
|
2060
|
+
dispatchOutcome: z2.enum(["blocked", "completed", "failed"]).optional(),
|
|
2061
|
+
resultMessageId: z2.string().min(1).optional(),
|
|
2247
2062
|
lastProgressAtMs: nonNegativeNumberSchema,
|
|
2248
2063
|
resumeReason: turnPauseReasonSchema.optional(),
|
|
2249
|
-
publishExternally:
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2064
|
+
publishExternally: z2.boolean().optional(),
|
|
2065
|
+
source: sourceSchema.optional(),
|
|
2066
|
+
resumedFromSliceId: z2.number().int().nonnegative().optional(),
|
|
2067
|
+
turnId: z2.string().min(1),
|
|
2068
|
+
sliceId: z2.number().int().nonnegative(),
|
|
2253
2069
|
startedAtMs: nonNegativeNumberSchema,
|
|
2254
2070
|
state: turnStatusSchema,
|
|
2255
2071
|
surface: turnSurfaceSchema.optional(),
|
|
2256
|
-
traceId:
|
|
2072
|
+
traceId: z2.string().optional(),
|
|
2257
2073
|
updatedAtMs: nonNegativeNumberSchema,
|
|
2258
2074
|
committedSeq: seqCursorSchema,
|
|
2259
|
-
historyVersion:
|
|
2260
|
-
errorMessage:
|
|
2075
|
+
historyVersion: z2.number().int().nonnegative().optional(),
|
|
2076
|
+
errorMessage: z2.string().optional(),
|
|
2261
2077
|
turnStartSeq: seqCursorSchema.optional(),
|
|
2262
|
-
runtimeContext:
|
|
2078
|
+
runtimeContext: z2.array(piMessageSchema).optional()
|
|
2263
2079
|
}).strip();
|
|
2264
2080
|
function conversationExecutionFromSummary(summary) {
|
|
2265
2081
|
const status = summary.state === "completed" || summary.state === "abandoned" ? "idle" : summary.state;
|
|
@@ -2311,7 +2127,7 @@ async function recordConversationActivityMetadata(args) {
|
|
|
2311
2127
|
if (!hasParent && !destination && !conversation) {
|
|
2312
2128
|
return;
|
|
2313
2129
|
}
|
|
2314
|
-
const activitySource = hasParent ? "internal" : args.source?.
|
|
2130
|
+
const activitySource = hasParent ? "internal" : args.source?.kind === "web" ? "web" : destination?.platform === "local" ? "local" : destination ? args.summary.surface : void 0;
|
|
2315
2131
|
await conversationStore.recordActivity({
|
|
2316
2132
|
activityAtMs: args.summary.updatedAtMs,
|
|
2317
2133
|
channelName: args.summary.channelName,
|
|
@@ -2343,6 +2159,7 @@ async function recordConversationActivityMetadata(args) {
|
|
|
2343
2159
|
function materializeTurnRecord(stored, piProjection, turnStartMessageIndex, restoreVolatileContext = true, runtimeMetrics) {
|
|
2344
2160
|
const restoredProjection = restoreVolatileContext && (stored.state === "running" || stored.state === "paused") ? restoreRuntimeContext(piProjection, stored.runtimeContext) : piProjection;
|
|
2345
2161
|
return {
|
|
2162
|
+
...definedProps({ actor: stored.actor }),
|
|
2346
2163
|
schemaVersion: stored.schemaVersion,
|
|
2347
2164
|
version: stored.version,
|
|
2348
2165
|
conversationId: stored.conversationId,
|
|
@@ -2364,6 +2181,7 @@ function materializeTurnRecord(stored, piProjection, turnStartMessageIndex, rest
|
|
|
2364
2181
|
errorMessage: stored.errorMessage,
|
|
2365
2182
|
resumeReason: stored.resumeReason,
|
|
2366
2183
|
publishExternally: stored.publishExternally,
|
|
2184
|
+
source: stored.source,
|
|
2367
2185
|
resultMessageId: stored.resultMessageId,
|
|
2368
2186
|
resumedFromSliceId: stored.resumedFromSliceId,
|
|
2369
2187
|
surface: stored.surface,
|
|
@@ -2470,12 +2288,14 @@ function buildStoredRecord(args) {
|
|
|
2470
2288
|
updatedAtMs: nowMs,
|
|
2471
2289
|
committedSeq: args.committedSeq,
|
|
2472
2290
|
...definedProps({
|
|
2291
|
+
actor: args.actor,
|
|
2473
2292
|
dispatchId: args.dispatchId,
|
|
2474
2293
|
dispatchOutcome: args.dispatchOutcome,
|
|
2475
2294
|
errorMessage: args.errorMessage,
|
|
2476
2295
|
historyVersion: args.historyVersion,
|
|
2477
2296
|
resumeReason: args.resumeReason,
|
|
2478
2297
|
publishExternally: args.publishExternally,
|
|
2298
|
+
source: args.source,
|
|
2479
2299
|
resultMessageId: args.resultMessageId,
|
|
2480
2300
|
resumedFromSliceId: args.resumedFromSliceId,
|
|
2481
2301
|
runtimeContext: args.runtimeContext && args.runtimeContext.length > 0 ? args.runtimeContext : void 0,
|
|
@@ -2534,6 +2354,7 @@ async function updateTurnState(args) {
|
|
|
2534
2354
|
return void 0;
|
|
2535
2355
|
}
|
|
2536
2356
|
return await setStoredRecord({
|
|
2357
|
+
actor: args.existing.actor,
|
|
2537
2358
|
fence: args.fence,
|
|
2538
2359
|
piMessages: args.existing.piMessages,
|
|
2539
2360
|
piMessageProvenance: args.existing.piMessageProvenance,
|
|
@@ -2549,6 +2370,7 @@ async function updateTurnState(args) {
|
|
|
2549
2370
|
turnStartMessageIndex: args.existing.turnStartMessageIndex
|
|
2550
2371
|
}),
|
|
2551
2372
|
record: buildStoredRecord({
|
|
2373
|
+
actor: args.existing.actor,
|
|
2552
2374
|
conversationId: args.existing.conversationId,
|
|
2553
2375
|
turnId: args.existing.turnId,
|
|
2554
2376
|
sliceId: args.existing.sliceId,
|
|
@@ -2564,6 +2386,7 @@ async function updateTurnState(args) {
|
|
|
2564
2386
|
historyVersion: parsed.historyVersion,
|
|
2565
2387
|
resumeReason: args.existing.resumeReason,
|
|
2566
2388
|
publishExternally: args.existing.publishExternally,
|
|
2389
|
+
source: args.existing.source,
|
|
2567
2390
|
resultMessageId: args.resultMessageId ?? args.existing.resultMessageId,
|
|
2568
2391
|
resumedFromSliceId: args.existing.resumedFromSliceId,
|
|
2569
2392
|
surface: args.existing.surface,
|
|
@@ -2617,7 +2440,7 @@ async function upsertTurnRecordLocked(args, fence) {
|
|
|
2617
2440
|
const turnStartSeq = durableTurnStartMessageIndex === void 0 ? existingRecord?.turnStartSeq : durableTurnStartMessageIndex <= 0 ? -1 : commit.messageSeqs[durableTurnStartMessageIndex - 1] ?? commit.committedSeq;
|
|
2618
2441
|
const turnStartMessageIndex = durableTurnStartMessageIndex ?? (turnStartSeq === void 0 ? void 0 : commit.messageSeqs.filter((seq) => seq <= turnStartSeq).length);
|
|
2619
2442
|
return await setStoredRecord({
|
|
2620
|
-
actor: args.actor,
|
|
2443
|
+
actor: existingRecord?.actor ?? args.actor,
|
|
2621
2444
|
fence,
|
|
2622
2445
|
conversationStore: args.conversationStore,
|
|
2623
2446
|
destination: args.destination,
|
|
@@ -2638,6 +2461,7 @@ async function upsertTurnRecordLocked(args, fence) {
|
|
|
2638
2461
|
...definedProps({ indexTtlMs: args.ttlMs }),
|
|
2639
2462
|
turnStartMessageIndex,
|
|
2640
2463
|
record: buildStoredRecord({
|
|
2464
|
+
actor: existingRecord?.actor ?? args.actor,
|
|
2641
2465
|
conversationId: args.conversationId,
|
|
2642
2466
|
turnId: args.turnId,
|
|
2643
2467
|
sliceId: args.sliceId,
|
|
@@ -2652,6 +2476,7 @@ async function upsertTurnRecordLocked(args, fence) {
|
|
|
2652
2476
|
lastProgressAtMs: args.lastProgressAtMs,
|
|
2653
2477
|
resumeReason: args.resumeReason,
|
|
2654
2478
|
publishExternally: args.publishExternally ?? existingRecord?.publishExternally,
|
|
2479
|
+
source: args.source ?? existingRecord?.source,
|
|
2655
2480
|
resultMessageId: args.resultMessageId ?? existingRecord?.resultMessageId,
|
|
2656
2481
|
resumedFromSliceId: args.resumedFromSliceId,
|
|
2657
2482
|
runtimeContext: args.state === "running" || args.state === "paused" ? retainedRuntimeContext : void 0,
|
|
@@ -2808,96 +2633,6 @@ async function failTurnRecord(args) {
|
|
|
2808
2633
|
);
|
|
2809
2634
|
}
|
|
2810
2635
|
|
|
2811
|
-
// src/chat/usage.ts
|
|
2812
|
-
var agentTurnUsageSchema = usageSchema;
|
|
2813
|
-
var COMPONENT_USAGE_FIELDS = [
|
|
2814
|
-
"inputTokens",
|
|
2815
|
-
"outputTokens",
|
|
2816
|
-
"cachedInputTokens",
|
|
2817
|
-
"cacheCreationTokens"
|
|
2818
|
-
];
|
|
2819
|
-
var COST_COMPONENT_FIELDS = [
|
|
2820
|
-
"input",
|
|
2821
|
-
"output",
|
|
2822
|
-
"cacheRead",
|
|
2823
|
-
"cacheWrite"
|
|
2824
|
-
];
|
|
2825
|
-
function hasAgentTurnUsage(usage) {
|
|
2826
|
-
return Boolean(
|
|
2827
|
-
usage && (Object.entries(usage).some(
|
|
2828
|
-
([field, value]) => field !== "cost" && typeof value === "number" && Number.isFinite(value)
|
|
2829
|
-
) || Object.values(usage.cost ?? {}).some(
|
|
2830
|
-
(value) => typeof value === "number" && Number.isFinite(value)
|
|
2831
|
-
))
|
|
2832
|
-
);
|
|
2833
|
-
}
|
|
2834
|
-
function getFiniteCount(value) {
|
|
2835
|
-
return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : void 0;
|
|
2836
|
-
}
|
|
2837
|
-
function getFiniteCost(value) {
|
|
2838
|
-
return typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : void 0;
|
|
2839
|
-
}
|
|
2840
|
-
function addCost(left, right) {
|
|
2841
|
-
return Math.round(((left ?? 0) + right) * 1e12) / 1e12;
|
|
2842
|
-
}
|
|
2843
|
-
function getComponentTotal(usage) {
|
|
2844
|
-
let total;
|
|
2845
|
-
for (const field of COMPONENT_USAGE_FIELDS) {
|
|
2846
|
-
const value = getFiniteCount(usage[field]);
|
|
2847
|
-
if (value === void 0) continue;
|
|
2848
|
-
total = (total ?? 0) + value;
|
|
2849
|
-
}
|
|
2850
|
-
return total;
|
|
2851
|
-
}
|
|
2852
|
-
function addAgentTurnUsage(...usages) {
|
|
2853
|
-
const components = {};
|
|
2854
|
-
let componentTotal;
|
|
2855
|
-
let totalOnlyTokens;
|
|
2856
|
-
let reasoningTokens;
|
|
2857
|
-
const cost = {};
|
|
2858
|
-
for (const usage of usages) {
|
|
2859
|
-
if (!usage) continue;
|
|
2860
|
-
const reasoning = getFiniteCount(usage.reasoningTokens);
|
|
2861
|
-
if (reasoning !== void 0) {
|
|
2862
|
-
reasoningTokens = (reasoningTokens ?? 0) + reasoning;
|
|
2863
|
-
}
|
|
2864
|
-
if (usage.cost) {
|
|
2865
|
-
for (const field of [...COST_COMPONENT_FIELDS, "total"]) {
|
|
2866
|
-
const value = getFiniteCost(usage.cost[field]);
|
|
2867
|
-
if (value === void 0) continue;
|
|
2868
|
-
cost[field] = addCost(cost[field], value);
|
|
2869
|
-
}
|
|
2870
|
-
}
|
|
2871
|
-
const usageComponentTotal = getComponentTotal(usage);
|
|
2872
|
-
if (usageComponentTotal !== void 0) {
|
|
2873
|
-
componentTotal = (componentTotal ?? 0) + usageComponentTotal;
|
|
2874
|
-
for (const field of COMPONENT_USAGE_FIELDS) {
|
|
2875
|
-
const value = getFiniteCount(usage[field]);
|
|
2876
|
-
if (value === void 0) continue;
|
|
2877
|
-
components[field] = (components[field] ?? 0) + value;
|
|
2878
|
-
}
|
|
2879
|
-
continue;
|
|
2880
|
-
}
|
|
2881
|
-
const totalTokens = getFiniteCount(usage.totalTokens);
|
|
2882
|
-
if (totalTokens !== void 0) {
|
|
2883
|
-
totalOnlyTokens = (totalOnlyTokens ?? 0) + totalTokens;
|
|
2884
|
-
}
|
|
2885
|
-
}
|
|
2886
|
-
if (totalOnlyTokens !== void 0) {
|
|
2887
|
-
return {
|
|
2888
|
-
totalTokens: totalOnlyTokens + (componentTotal ?? 0),
|
|
2889
|
-
...reasoningTokens !== void 0 ? { reasoningTokens } : void 0,
|
|
2890
|
-
...Object.keys(cost).length > 0 ? { cost } : void 0
|
|
2891
|
-
};
|
|
2892
|
-
}
|
|
2893
|
-
const result = {
|
|
2894
|
-
...components,
|
|
2895
|
-
...reasoningTokens !== void 0 ? { reasoningTokens } : void 0,
|
|
2896
|
-
...Object.keys(cost).length > 0 ? { cost } : void 0
|
|
2897
|
-
};
|
|
2898
|
-
return hasAgentTurnUsage(result) ? result : void 0;
|
|
2899
|
-
}
|
|
2900
|
-
|
|
2901
2636
|
// src/chat/services/turn-limit.ts
|
|
2902
2637
|
var TurnSliceLimitExceededError = class extends Error {
|
|
2903
2638
|
constructor(maxSlices) {
|
|
@@ -3087,7 +2822,6 @@ async function saveDone(args) {
|
|
|
3087
2822
|
}
|
|
3088
2823
|
|
|
3089
2824
|
export {
|
|
3090
|
-
renderJuniorNativeConversationEvent,
|
|
3091
2825
|
TURN_CONTEXT_TAG,
|
|
3092
2826
|
isAssistantMessage,
|
|
3093
2827
|
isToolResultMessage,
|
|
@@ -3119,10 +2853,6 @@ export {
|
|
|
3119
2853
|
createConversationMemoryService,
|
|
3120
2854
|
isHumanConversationMessage,
|
|
3121
2855
|
getConversationMessageSlackTs,
|
|
3122
|
-
SHORT_TITLE_MAX_LENGTH,
|
|
3123
|
-
fallbackShortTitle,
|
|
3124
|
-
generateShortTitle,
|
|
3125
|
-
resolveTaskTitle,
|
|
3126
2856
|
resolveConversationTitle,
|
|
3127
2857
|
persistConversationMessageSummaries,
|
|
3128
2858
|
projectConversationMessages,
|
|
@@ -3145,7 +2875,6 @@ export {
|
|
|
3145
2875
|
recordToolExecutionStarted,
|
|
3146
2876
|
recordAttachmentsDelivered,
|
|
3147
2877
|
recordGuardianActionReviewed,
|
|
3148
|
-
ToolInputError,
|
|
3149
2878
|
MAX_TEXT_CHARS,
|
|
3150
2879
|
RIPGREP_EXCLUDED_GLOBS,
|
|
3151
2880
|
DEFAULT_SEARCH_COMMAND_TIMEOUT_MS,
|
|
@@ -3164,9 +2893,6 @@ export {
|
|
|
3164
2893
|
renderAgentsInstructions,
|
|
3165
2894
|
buildAgentsInstructionsMessage,
|
|
3166
2895
|
findVisibleAgentsInstructions,
|
|
3167
|
-
agentTurnUsageSchema,
|
|
3168
|
-
hasAgentTurnUsage,
|
|
3169
|
-
addAgentTurnUsage,
|
|
3170
2896
|
TurnSliceLimitExceededError,
|
|
3171
2897
|
buildTurnLimitResponse,
|
|
3172
2898
|
persistWithRetry,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runWithTurnRequestDeadline
|
|
3
|
+
} from "./chunk-7UJ6IJCK.js";
|
|
1
4
|
import {
|
|
2
5
|
QUEUE_SIGNATURE_MAX_AGE_MS,
|
|
3
6
|
createVercelQueueClient,
|
|
4
7
|
signQueueMessage,
|
|
5
8
|
verifyQueueMessage
|
|
6
9
|
} from "./chunk-7H2VZTWN.js";
|
|
7
|
-
import {
|
|
8
|
-
runWithTurnRequestDeadline
|
|
9
|
-
} from "./chunk-WGZJ5SU4.js";
|
|
10
10
|
import {
|
|
11
11
|
logWarn
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-Y4WL4OYD.js";
|
|
13
13
|
|
|
14
14
|
// src/chat/plugins/task-queue.ts
|
|
15
15
|
import { createHash } from "crypto";
|
|
@@ -129,7 +129,7 @@ function pluginTaskCallback() {
|
|
|
129
129
|
onRejected: logPluginTaskQueueMessageRejected,
|
|
130
130
|
// Load the runner on first use so this module can send without a cycle.
|
|
131
131
|
run: async (message) => {
|
|
132
|
-
const { processPluginTask } = await import("./task-runner-
|
|
132
|
+
const { processPluginTask } = await import("./task-runner-52DYFHW3.js");
|
|
133
133
|
await processPluginTask(message);
|
|
134
134
|
},
|
|
135
135
|
topic: PLUGIN_TASK_QUEUE_TOPIC,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/chat/state/turn-id.ts
|
|
2
|
+
function buildDeterministicTurnId(messageId) {
|
|
3
|
+
const sanitized = messageId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4
|
+
return `turn_${sanitized}`;
|
|
5
|
+
}
|
|
6
|
+
function buildDeterministicAssistantMessageId(turnId) {
|
|
7
|
+
return `${turnId}:assistant:1`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
buildDeterministicTurnId,
|
|
12
|
+
buildDeterministicAssistantMessageId
|
|
13
|
+
};
|