@sentry/junior 0.187.0 → 0.189.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-XVAE2554.js → agent-hooks-6QRYH6PX.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 +41 -52
- package/dist/app.d.ts +1 -1
- package/dist/app.js +1001 -338
- package/dist/{catalog-runtime-DWFAC562.js → catalog-runtime-IETJLJFG.js} +4 -4
- package/dist/chat/agent/resume.d.ts +0 -2
- package/dist/chat/agent/types.d.ts +9 -14
- 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 +296 -24
- 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/location.d.ts +3 -8
- 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 +8 -11
- 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/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 +5 -5
- 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 +42 -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/{chunk-WL3R2KTS.js → chunk-4RHJ3CXR.js} +90 -289
- package/dist/{chunk-U6ZQHRIP.js → chunk-5CXCGDIL.js} +1 -1
- package/dist/{chunk-HXR3FHTE.js → chunk-5VWAY27R.js} +7 -3
- package/dist/{chunk-D3GDGREI.js → chunk-6AUR6PWR.js} +3 -3
- package/dist/{chunk-EIWYZXSM.js → chunk-7R5JRPCY.js} +8 -6
- package/dist/{chunk-WRDW3A3D.js → chunk-AC7MDOJW.js} +5 -7
- package/dist/{chunk-URZ7UD4P.js → chunk-BYBSI5TI.js} +2 -2
- package/dist/{chunk-MUPPP7A7.js → chunk-CMWIMFM6.js} +4 -182
- package/dist/{chunk-WKIS4VRK.js → chunk-CUYFCI4G.js} +70 -39
- package/dist/chunk-DA2KGZZI.js +13 -0
- package/dist/{chunk-Q6OCUQ7W.js → chunk-DYXVAO2E.js} +1 -1
- package/dist/{chunk-QH3I7ZOK.js → chunk-E3PDZPGV.js} +1 -1
- package/dist/{chunk-NU775DLU.js → chunk-GP32KD2J.js} +4 -12
- package/dist/{chunk-STF4GSK4.js → chunk-KN32OWL2.js} +5 -5
- package/dist/chunk-LHKZKAZ4.js +285 -0
- package/dist/{chunk-D5BWM37G.js → chunk-MFSET7Q7.js} +51 -341
- package/dist/{chunk-DUE4EUNL.js → chunk-MI6ZBDTS.js} +6 -6
- package/dist/{chunk-27T5HZHO.js → chunk-MRXMFB4L.js} +6 -87
- package/dist/{chunk-4A2R3AQB.js → chunk-MVPLEPSI.js} +1 -1
- package/dist/{chunk-7LRRVMPH.js → chunk-NY2F7BZA.js} +1 -1
- package/dist/chunk-O35GZCKL.js +311 -0
- package/dist/{chunk-U3KMII5Y.js → chunk-OEIITG5F.js} +1 -1
- package/dist/{chunk-6FKNNUSN.js → chunk-PCPSX4ES.js} +209 -7
- package/dist/{chunk-6YCIYOVA.js → chunk-PY3EIEAF.js} +1 -1
- package/dist/{chunk-U5POFCKM.js → chunk-QNIOBNOY.js} +284 -123
- package/dist/{chunk-JCRXXEMC.js → chunk-S3SGZUOI.js} +1 -1
- package/dist/chunk-SR6OMO5C.js +703 -0
- package/dist/{chunk-TQHCZXN7.js → chunk-UCWO5MKP.js} +7 -7
- package/dist/{chunk-ITLYUKGZ.js → chunk-VKQWU4PO.js} +2 -2
- package/dist/{chunk-JZPDYKRG.js → chunk-WDHPN2GH.js} +3 -3
- package/dist/{chunk-P2VU5JNH.js → chunk-WMUAKAIF.js} +42 -42
- package/dist/{chunk-NIKLTFBP.js → chunk-WN6VLHOU.js} +12 -5
- package/dist/{chunk-VC343WHM.js → chunk-WWYUYKKV.js} +1 -1
- package/dist/{chunk-OM4SFFJK.js → chunk-WYDF6PGK.js} +3 -3
- package/dist/{chunk-KRYJ5VOD.js → chunk-YNZPOFF3.js} +16 -21
- package/dist/{chunk-Z6OHCDXP.js → chunk-YYSEH2WC.js} +2 -2
- package/dist/{chunk-BITZUBPJ.js → chunk-YYZNESC3.js} +8 -8
- package/dist/{chunk-2VUDJGB6.js → chunk-ZUPDSJUE.js} +2 -5
- package/dist/{chunk-X5SXFVZT.js → chunk-ZV6PFUA4.js} +1 -1
- 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/conversations.d.ts +62 -0
- package/dist/db/schema.d.ts +31 -0
- package/dist/{db-FBHAWVXU.js → db-LPJKR2EO.js} +6 -6
- package/dist/instrumentation.js +3 -3
- package/dist/nitro.js +6 -6
- package/dist/{oauth-callback-server-5HS5ULC6.js → oauth-callback-server-DMXF4TTQ.js} +30 -28
- package/dist/{runner-46W6NV6B.js → runner-L5DPVYCN.js} +24 -20
- package/dist/{skills-TG3QC4B6.js → skills-NXG3LBCK.js} +5 -5
- package/dist/spawn-VRUIGKWW.js +42 -0
- package/dist/task-runner-7YTBSPXW.js +36 -0
- package/dist/{validation-GMRIDBC5.js → validation-CH36LTOS.js} +5 -5
- package/dist/version.js +1 -1
- package/dist/{work-W4ULBJTU.js → work-HBC5Y5VZ.js} +22 -21
- package/dist/{worker-M6NVACS2.js → worker-5RDZHLXH.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 -47
- package/dist/chunk-4YD3DET6.js +0 -1503
- package/dist/chunk-6FGN7ZEG.js +0 -221
- package/dist/spawn-Y6YWBIJS.js +0 -41
- package/dist/task-runner-YSGBPN4U.js +0 -34
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
persistConversationMessages
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MFSET7Q7.js";
|
|
4
4
|
import {
|
|
5
5
|
JUNIOR_THREAD_STATE_TTL_MS
|
|
6
6
|
} from "./chunk-3Y47VMHV.js";
|
|
7
7
|
import {
|
|
8
8
|
getDb
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-CUYFCI4G.js";
|
|
10
10
|
import {
|
|
11
11
|
juniorLocationConfigurations
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-5VWAY27R.js";
|
|
13
13
|
import {
|
|
14
14
|
getStateAdapter
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5CXCGDIL.js";
|
|
16
16
|
import {
|
|
17
17
|
juniorDestinations
|
|
18
18
|
} from "./chunk-VFUK3X5B.js";
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
isRecord,
|
|
21
21
|
toOptionalNumber,
|
|
22
22
|
toOptionalString
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-PY3EIEAF.js";
|
|
24
24
|
|
|
25
25
|
// src/chat/state/conversation.ts
|
|
26
26
|
function defaultConversationState() {
|
|
@@ -507,85 +507,6 @@ function getLocationConfigurationService(destination) {
|
|
|
507
507
|
});
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
-
// src/chat/services/turn-session-routing.ts
|
|
511
|
-
async function loadConversationChain(conversationId, conversationStore) {
|
|
512
|
-
const chain = [];
|
|
513
|
-
const seen = /* @__PURE__ */ new Set();
|
|
514
|
-
let cursor = conversationId;
|
|
515
|
-
while (cursor && !seen.has(cursor)) {
|
|
516
|
-
seen.add(cursor);
|
|
517
|
-
const conversation = await conversationStore.get({
|
|
518
|
-
conversationId: cursor
|
|
519
|
-
});
|
|
520
|
-
if (!conversation) {
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
chain.push(conversation);
|
|
524
|
-
cursor = conversation.lineage?.parentConversationId;
|
|
525
|
-
}
|
|
526
|
-
return chain;
|
|
527
|
-
}
|
|
528
|
-
function slackSourceForDestination(args) {
|
|
529
|
-
if (args.source?.platform !== "slack" || args.source.channelId !== args.destination.channelId) {
|
|
530
|
-
return void 0;
|
|
531
|
-
}
|
|
532
|
-
const threadTs = args.source.threadTs?.trim();
|
|
533
|
-
return {
|
|
534
|
-
platform: "slack",
|
|
535
|
-
visibility: args.source.visibility ?? "public",
|
|
536
|
-
teamId: args.source.teamId?.trim() || args.destination.teamId,
|
|
537
|
-
channelId: args.source.channelId,
|
|
538
|
-
...threadTs ? { threadTs } : void 0
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
async function resolveConversationRouting(args) {
|
|
542
|
-
const conversationStore = args.conversationStore ?? (await import("./db-FBHAWVXU.js")).getConversationStore();
|
|
543
|
-
const chain = await loadConversationChain(
|
|
544
|
-
args.conversationId,
|
|
545
|
-
conversationStore
|
|
546
|
-
);
|
|
547
|
-
let destination;
|
|
548
|
-
let source;
|
|
549
|
-
let location;
|
|
550
|
-
for (const conversation of chain) {
|
|
551
|
-
destination ??= conversation.destination;
|
|
552
|
-
source ??= conversation.sessionSource;
|
|
553
|
-
location ??= conversation.location;
|
|
554
|
-
if (destination && source) {
|
|
555
|
-
break;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (!destination) {
|
|
559
|
-
return void 0;
|
|
560
|
-
}
|
|
561
|
-
if (destination.platform === "slack") {
|
|
562
|
-
const slackSource = slackSourceForDestination({ destination, source });
|
|
563
|
-
return {
|
|
564
|
-
destination,
|
|
565
|
-
...location ? { location } : void 0,
|
|
566
|
-
...slackSource ? { source: slackSource } : void 0
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
return {
|
|
570
|
-
destination,
|
|
571
|
-
...location ? { location } : void 0,
|
|
572
|
-
...source ? { source } : void 0
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
async function resolveTurnSessionRouting(args) {
|
|
576
|
-
const routing = await resolveConversationRouting(args);
|
|
577
|
-
if (!routing?.destination || !routing.source) {
|
|
578
|
-
throw new Error(
|
|
579
|
-
`Conversation ${args.conversationId} is missing durable routing metadata`
|
|
580
|
-
);
|
|
581
|
-
}
|
|
582
|
-
return {
|
|
583
|
-
destination: routing.destination,
|
|
584
|
-
source: routing.source,
|
|
585
|
-
...routing.location ? { location: routing.location } : void 0
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
|
|
589
510
|
export {
|
|
590
511
|
configValueSchema,
|
|
591
512
|
coerceThreadConversationState,
|
|
@@ -594,7 +515,5 @@ export {
|
|
|
594
515
|
persistThreadRuntimeState,
|
|
595
516
|
getPersistedThreadState,
|
|
596
517
|
persistThreadStateById,
|
|
597
|
-
getLocationConfigurationService
|
|
598
|
-
resolveConversationRouting,
|
|
599
|
-
resolveTurnSessionRouting
|
|
518
|
+
getLocationConfigurationService
|
|
600
519
|
};
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import {
|
|
2
|
+
usageSchema
|
|
3
|
+
} from "./chunk-PDO5BLNM.js";
|
|
4
|
+
import {
|
|
5
|
+
botConfig
|
|
6
|
+
} from "./chunk-BYBSI5TI.js";
|
|
7
|
+
import {
|
|
8
|
+
logWarn
|
|
9
|
+
} from "./chunk-PY3EIEAF.js";
|
|
10
|
+
|
|
11
|
+
// src/chat/conversations/structured-events.ts
|
|
12
|
+
import {
|
|
13
|
+
conversationEventPresentationSchema,
|
|
14
|
+
defineConversationEvent
|
|
15
|
+
} from "@sentry/junior-plugin-api";
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
var JUNIOR_NATIVE_EVENT_NAMESPACE = "junior";
|
|
18
|
+
var authenticationEventContentSchema = z.object({
|
|
19
|
+
accountLabel: z.string().trim().min(1).max(120).optional(),
|
|
20
|
+
actorId: z.string().min(1),
|
|
21
|
+
authorizationId: z.string().min(1).optional(),
|
|
22
|
+
provider: z.string().regex(/^[a-z][a-z0-9-]*$/),
|
|
23
|
+
providerLabel: z.string().trim().min(1).max(80).optional()
|
|
24
|
+
}).strict();
|
|
25
|
+
var agentsInstructionsUpdatedContentSchema = z.object({
|
|
26
|
+
action: z.enum(["loaded", "replaced", "cleared"]),
|
|
27
|
+
directory: z.string().trim().min(1).max(500).optional(),
|
|
28
|
+
fingerprint: z.string().trim().min(1).max(128),
|
|
29
|
+
sources: z.array(
|
|
30
|
+
z.object({
|
|
31
|
+
content: z.string().min(1).max(32 * 1024),
|
|
32
|
+
path: z.string().trim().min(1).max(500)
|
|
33
|
+
}).strict()
|
|
34
|
+
).max(32),
|
|
35
|
+
textBytes: z.number().int().nonnegative().optional()
|
|
36
|
+
}).strict();
|
|
37
|
+
function providerTitle(content) {
|
|
38
|
+
return content.providerLabel?.trim() || content.provider;
|
|
39
|
+
}
|
|
40
|
+
function agentsInstructionsTitle(action) {
|
|
41
|
+
if (action === "loaded") return "Loaded AGENTS.md";
|
|
42
|
+
if (action === "replaced") return "Updated AGENTS.md";
|
|
43
|
+
return "Cleared AGENTS.md";
|
|
44
|
+
}
|
|
45
|
+
function sourceFilename(sourcePath) {
|
|
46
|
+
return sourcePath.split("/").at(-1) || sourcePath;
|
|
47
|
+
}
|
|
48
|
+
function formatBytes(bytes) {
|
|
49
|
+
if (bytes < 1024) return `${bytes} bytes`;
|
|
50
|
+
const kilobytes = bytes / 1024;
|
|
51
|
+
return `${Number.isInteger(kilobytes) ? kilobytes : kilobytes.toFixed(1)} KB`;
|
|
52
|
+
}
|
|
53
|
+
function agentsInstructionsPreview(content) {
|
|
54
|
+
const source = content.sources[0];
|
|
55
|
+
if (!source) return void 0;
|
|
56
|
+
const filename = sourceFilename(source.path);
|
|
57
|
+
const label = content.sources.length === 1 ? filename : `${content.sources.length} AGENTS.md files`;
|
|
58
|
+
return typeof content.textBytes === "number" ? `${label} \xB7 ${formatBytes(content.textBytes)}` : label;
|
|
59
|
+
}
|
|
60
|
+
var authenticationLinkedEvent = defineConversationEvent({
|
|
61
|
+
name: "authentication_linked",
|
|
62
|
+
version: 1,
|
|
63
|
+
schema: authenticationEventContentSchema,
|
|
64
|
+
renderEvent(event) {
|
|
65
|
+
const provider = providerTitle(event);
|
|
66
|
+
return {
|
|
67
|
+
icon: "link",
|
|
68
|
+
title: `${provider} connected`,
|
|
69
|
+
...event.accountLabel ? { preview: `Connected as \`${event.accountLabel}\`` } : void 0,
|
|
70
|
+
details: [
|
|
71
|
+
{
|
|
72
|
+
title: `${provider} connected`,
|
|
73
|
+
...event.accountLabel ? { description: `Connected as \`${event.accountLabel}\`` } : void 0,
|
|
74
|
+
metadata: [event.provider]
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
var authenticationUnlinkedEvent = defineConversationEvent({
|
|
81
|
+
name: "authentication_unlinked",
|
|
82
|
+
version: 1,
|
|
83
|
+
schema: authenticationEventContentSchema,
|
|
84
|
+
renderEvent(event) {
|
|
85
|
+
const provider = providerTitle(event);
|
|
86
|
+
return {
|
|
87
|
+
icon: "key",
|
|
88
|
+
title: `${provider} disconnected`,
|
|
89
|
+
details: [
|
|
90
|
+
{
|
|
91
|
+
title: `${provider} disconnected`,
|
|
92
|
+
metadata: [event.provider]
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
var agentsInstructionsUpdatedEvent = defineConversationEvent({
|
|
99
|
+
name: "agents_instructions_updated",
|
|
100
|
+
version: 1,
|
|
101
|
+
schema: agentsInstructionsUpdatedContentSchema,
|
|
102
|
+
renderEvent(event) {
|
|
103
|
+
const title = agentsInstructionsTitle(event.action);
|
|
104
|
+
const preview = agentsInstructionsPreview(event);
|
|
105
|
+
return {
|
|
106
|
+
icon: "brain",
|
|
107
|
+
title,
|
|
108
|
+
...preview ? { preview } : void 0,
|
|
109
|
+
...event.sources.length > 0 ? {
|
|
110
|
+
details: event.sources.map((source) => ({
|
|
111
|
+
title: sourceFilename(source.path),
|
|
112
|
+
content: source.content
|
|
113
|
+
}))
|
|
114
|
+
} : void 0
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
var NATIVE_EVENT_DEFINITIONS = [
|
|
119
|
+
authenticationLinkedEvent,
|
|
120
|
+
authenticationUnlinkedEvent,
|
|
121
|
+
agentsInstructionsUpdatedEvent
|
|
122
|
+
];
|
|
123
|
+
function getJuniorNativeEventDefinition(args) {
|
|
124
|
+
return NATIVE_EVENT_DEFINITIONS.find(
|
|
125
|
+
(definition) => definition.eventName === args.name && definition.version === args.version
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
function renderJuniorNativeConversationEvent(args) {
|
|
129
|
+
if (args.namespace !== JUNIOR_NATIVE_EVENT_NAMESPACE) return void 0;
|
|
130
|
+
const definition = getJuniorNativeEventDefinition(args);
|
|
131
|
+
if (!definition) return void 0;
|
|
132
|
+
const presentation = definition.renderEvent(definition.parse(args.content));
|
|
133
|
+
return presentation === void 0 ? void 0 : conversationEventPresentationSchema.parse(presentation);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/chat/usage.ts
|
|
137
|
+
var agentTurnUsageSchema = usageSchema;
|
|
138
|
+
var COMPONENT_USAGE_FIELDS = [
|
|
139
|
+
"inputTokens",
|
|
140
|
+
"outputTokens",
|
|
141
|
+
"cachedInputTokens",
|
|
142
|
+
"cacheCreationTokens"
|
|
143
|
+
];
|
|
144
|
+
var COST_COMPONENT_FIELDS = [
|
|
145
|
+
"input",
|
|
146
|
+
"output",
|
|
147
|
+
"cacheRead",
|
|
148
|
+
"cacheWrite"
|
|
149
|
+
];
|
|
150
|
+
function hasAgentTurnUsage(usage) {
|
|
151
|
+
return Boolean(
|
|
152
|
+
usage && (Object.entries(usage).some(
|
|
153
|
+
([field, value]) => field !== "cost" && typeof value === "number" && Number.isFinite(value)
|
|
154
|
+
) || Object.values(usage.cost ?? {}).some(
|
|
155
|
+
(value) => typeof value === "number" && Number.isFinite(value)
|
|
156
|
+
))
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
function getFiniteCount(value) {
|
|
160
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : void 0;
|
|
161
|
+
}
|
|
162
|
+
function getFiniteCost(value) {
|
|
163
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : void 0;
|
|
164
|
+
}
|
|
165
|
+
function addCost(left, right) {
|
|
166
|
+
return Math.round(((left ?? 0) + right) * 1e12) / 1e12;
|
|
167
|
+
}
|
|
168
|
+
function getComponentTotal(usage) {
|
|
169
|
+
let total;
|
|
170
|
+
for (const field of COMPONENT_USAGE_FIELDS) {
|
|
171
|
+
const value = getFiniteCount(usage[field]);
|
|
172
|
+
if (value === void 0) continue;
|
|
173
|
+
total = (total ?? 0) + value;
|
|
174
|
+
}
|
|
175
|
+
return total;
|
|
176
|
+
}
|
|
177
|
+
function addAgentTurnUsage(...usages) {
|
|
178
|
+
const components = {};
|
|
179
|
+
let componentTotal;
|
|
180
|
+
let totalOnlyTokens;
|
|
181
|
+
let reasoningTokens;
|
|
182
|
+
const cost = {};
|
|
183
|
+
for (const usage of usages) {
|
|
184
|
+
if (!usage) continue;
|
|
185
|
+
const reasoning = getFiniteCount(usage.reasoningTokens);
|
|
186
|
+
if (reasoning !== void 0) {
|
|
187
|
+
reasoningTokens = (reasoningTokens ?? 0) + reasoning;
|
|
188
|
+
}
|
|
189
|
+
if (usage.cost) {
|
|
190
|
+
for (const field of [...COST_COMPONENT_FIELDS, "total"]) {
|
|
191
|
+
const value = getFiniteCost(usage.cost[field]);
|
|
192
|
+
if (value === void 0) continue;
|
|
193
|
+
cost[field] = addCost(cost[field], value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const usageComponentTotal = getComponentTotal(usage);
|
|
197
|
+
if (usageComponentTotal !== void 0) {
|
|
198
|
+
componentTotal = (componentTotal ?? 0) + usageComponentTotal;
|
|
199
|
+
for (const field of COMPONENT_USAGE_FIELDS) {
|
|
200
|
+
const value = getFiniteCount(usage[field]);
|
|
201
|
+
if (value === void 0) continue;
|
|
202
|
+
components[field] = (components[field] ?? 0) + value;
|
|
203
|
+
}
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const totalTokens = getFiniteCount(usage.totalTokens);
|
|
207
|
+
if (totalTokens !== void 0) {
|
|
208
|
+
totalOnlyTokens = (totalOnlyTokens ?? 0) + totalTokens;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (totalOnlyTokens !== void 0) {
|
|
212
|
+
return {
|
|
213
|
+
totalTokens: totalOnlyTokens + (componentTotal ?? 0),
|
|
214
|
+
...reasoningTokens !== void 0 ? { reasoningTokens } : void 0,
|
|
215
|
+
...Object.keys(cost).length > 0 ? { cost } : void 0
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const result = {
|
|
219
|
+
...components,
|
|
220
|
+
...reasoningTokens !== void 0 ? { reasoningTokens } : void 0,
|
|
221
|
+
...Object.keys(cost).length > 0 ? { cost } : void 0
|
|
222
|
+
};
|
|
223
|
+
return hasAgentTurnUsage(result) ? result : void 0;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/chat/services/short-title.ts
|
|
227
|
+
var SHORT_TITLE_MAX_LENGTH = 60;
|
|
228
|
+
var TITLE_PROMPTS = {
|
|
229
|
+
conversation: [
|
|
230
|
+
"Generate a concise 5-8 word conversation title from the first user message below.",
|
|
231
|
+
"Capture the user's main request.",
|
|
232
|
+
"Reply with ONLY the title, with no quotes or trailing punctuation."
|
|
233
|
+
],
|
|
234
|
+
task: [
|
|
235
|
+
"Generate a concise 5-8 word task title from the task instruction below.",
|
|
236
|
+
"Capture the task's main purpose.",
|
|
237
|
+
"Reply with ONLY the title, with no quotes or trailing punctuation."
|
|
238
|
+
]
|
|
239
|
+
};
|
|
240
|
+
function normalizeShortTitle(value) {
|
|
241
|
+
return value.replace(/\s+/g, " ").trim().slice(0, SHORT_TITLE_MAX_LENGTH);
|
|
242
|
+
}
|
|
243
|
+
function fallbackShortTitle(sourceText, fallback = "Untitled") {
|
|
244
|
+
const firstLine = sourceText.split(/\r?\n/).map((line) => line.trim()).find((line) => line.length > 0) ?? "";
|
|
245
|
+
return normalizeShortTitle(firstLine) || fallback;
|
|
246
|
+
}
|
|
247
|
+
async function generateShortTitle(args) {
|
|
248
|
+
const sourceText = args.sourceText.trim();
|
|
249
|
+
if (!sourceText) return void 0;
|
|
250
|
+
try {
|
|
251
|
+
const result = await args.completeText({
|
|
252
|
+
modelId: botConfig.fastModelId,
|
|
253
|
+
temperature: 0,
|
|
254
|
+
promptName: `junior.${args.kind}_title`,
|
|
255
|
+
messages: [
|
|
256
|
+
{
|
|
257
|
+
role: "user",
|
|
258
|
+
content: [
|
|
259
|
+
...TITLE_PROMPTS[args.kind],
|
|
260
|
+
"",
|
|
261
|
+
args.kind === "conversation" ? `First user message: ${sourceText.slice(0, 500)}` : `Task instruction: ${sourceText.slice(0, 500)}`
|
|
262
|
+
].join("\n"),
|
|
263
|
+
timestamp: Date.now()
|
|
264
|
+
}
|
|
265
|
+
],
|
|
266
|
+
metadata: {
|
|
267
|
+
modelId: botConfig.fastModelId
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
const title = normalizeShortTitle(result.text);
|
|
271
|
+
return title || void 0;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
logWarn(`${args.kind}.title.generation.failed`, {
|
|
274
|
+
"exception.message": error instanceof Error ? error.message : String(error)
|
|
275
|
+
});
|
|
276
|
+
return void 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async function resolveTaskTitle(args) {
|
|
280
|
+
const explicit = normalizeShortTitle(args.title ?? "");
|
|
281
|
+
if (explicit) return explicit;
|
|
282
|
+
return generateShortTitle({
|
|
283
|
+
completeText: args.completeText,
|
|
284
|
+
kind: "task",
|
|
285
|
+
sourceText: args.instruction
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/chat/tools/execution/tool-input-error.ts
|
|
290
|
+
var ToolInputError = class extends Error {
|
|
291
|
+
constructor(message, options) {
|
|
292
|
+
super(message, options);
|
|
293
|
+
this.name = "ToolInputError";
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export {
|
|
298
|
+
JUNIOR_NATIVE_EVENT_NAMESPACE,
|
|
299
|
+
authenticationLinkedEvent,
|
|
300
|
+
authenticationUnlinkedEvent,
|
|
301
|
+
agentsInstructionsUpdatedEvent,
|
|
302
|
+
renderJuniorNativeConversationEvent,
|
|
303
|
+
SHORT_TITLE_MAX_LENGTH,
|
|
304
|
+
fallbackShortTitle,
|
|
305
|
+
generateShortTitle,
|
|
306
|
+
resolveTaskTitle,
|
|
307
|
+
ToolInputError,
|
|
308
|
+
agentTurnUsageSchema,
|
|
309
|
+
hasAgentTurnUsage,
|
|
310
|
+
addAgentTurnUsage
|
|
311
|
+
};
|