@sentry/junior 0.202.0 → 0.204.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-CMyTD4DD.js +17509 -0
- package/dist/agent-hooks-Bbcp9e33.js +4040 -0
- package/dist/agent-runner-DNb1A49M.js +678 -0
- package/dist/api/schema.d.ts +2728 -2639
- package/dist/api/schema.js +4 -169
- package/dist/api.d.ts +23 -17
- package/dist/api.js +3881 -5326
- package/dist/app-B1TOqBI8.d.ts +246 -0
- package/dist/app.d.ts +4 -520
- package/dist/app.js +9522 -11875
- package/dist/auth-pause-state-DosEalIG.js +168 -0
- package/dist/catalog-runtime-BReos-D4.js +7 -0
- package/dist/checkpoint-CNrPyRJN.js +2450 -0
- package/dist/cli/chat.d.ts +20 -0
- package/dist/cli/chat.js +229 -336
- package/dist/cli/check.d.ts +8 -0
- package/dist/cli/check.js +513 -806
- package/dist/cli/env.d.ts +13 -0
- package/dist/cli/env.js +63 -12
- package/dist/cli/init.d.ts +3 -0
- package/dist/cli/init.js +90 -159
- package/dist/cli/main.d.ts +6 -0
- package/dist/cli/main.js +43 -64
- package/dist/cli/plugins.d.ts +13 -0
- package/dist/cli/plugins.js +148 -227
- package/dist/cli/run.d.ts +16 -0
- package/dist/cli/run.js +52 -8
- package/dist/cli/snapshot-create.d.ts +4 -0
- package/dist/cli/snapshot-create.js +71 -125
- package/dist/cli/upgrade.d.ts +15 -0
- package/dist/cli/upgrade.js +232 -335
- package/dist/config-nGCW1OTG.js +941 -0
- package/dist/context-B45_WqVX.js +298 -0
- package/dist/conversation-privacy-B4voFRSm.js +182 -0
- package/dist/conversation-work-C6y3T5Hx.js +51 -0
- package/dist/credential-sync-kXr1hvO1.js +2660 -0
- package/dist/db-BeyXKJOI.d.ts +5 -0
- package/dist/destinations-BeBiJeEM.js +29 -0
- package/dist/execution-stats-DWfSihcH.js +373 -0
- package/dist/executor-DcMSlI5c.js +721 -0
- package/dist/experimental-CIXf7Uye.js +46 -0
- package/dist/history-ClE4toxe.d.ts +32 -0
- package/dist/history-CqTuSAdI.js +441 -0
- package/dist/instrumentation.d.ts +3 -3
- package/dist/instrumentation.js +130 -176
- package/dist/job-queue-Drn_LXlM.js +63 -0
- package/dist/logging-BzAk1S_s.js +1210 -0
- package/dist/model-profile-CZmVoGdX.js +49 -0
- package/dist/nitro.d.ts +31 -36
- package/dist/nitro.js +275 -456
- package/dist/oauth-callback-server-JiftokvA.js +130 -0
- package/dist/oauth-relay-CdCnu80W.js +62 -0
- package/dist/package-discovery-7a9YqLhE.js +455 -0
- package/dist/pending-auth-CWmSdZVg.js +185 -0
- package/dist/plugin-module-BKGOXca2.js +81 -0
- package/dist/plugins-BI9A1vKA.d.ts +95 -0
- package/dist/plugins-egKWjgue.js +99 -0
- package/dist/private-trace-result-BLvBjy_e.js +16 -0
- package/dist/profile-CrT5nXbw.js +861 -0
- package/dist/registry-DH1xUo2N.js +1419 -0
- package/dist/reporting-schema-DosTN__Q.js +105 -0
- package/dist/resolve-CZHnfxaS.js +546 -0
- package/dist/rolldown-runtime-B4FMCO8f.js +28 -0
- package/dist/runner-CZV2sC46.js +392 -0
- package/dist/sandbox-egress-signals-bHZfmhbd.js +46 -0
- package/dist/schema-Rn8-XEaN.js +1140 -0
- package/dist/sentry-CD3SdJl-.js +26 -0
- package/dist/skills-CIcDQSgM.js +316 -0
- package/dist/spawn-DdkUFRmq.js +29 -0
- package/dist/stats-DTUbAb88.js +2634 -0
- package/dist/store-C5qxF2ac.d.ts +208 -0
- package/dist/task-queue-CJIR4RF7.js +136 -0
- package/dist/task-runner-D-O3A-Cp.js +639 -0
- package/dist/thread-state-CRc9jTJS.js +431 -0
- package/dist/turn-execution-BkinIdJF.js +47 -0
- package/dist/turn-lifecycle-DQV19VTW.js +54 -0
- package/dist/usage-D3EbSO7w.js +296 -0
- package/dist/usage-schema-CKaDkH_j.js +20 -0
- package/dist/validation-C2CR-OX3.js +40 -0
- package/dist/vercel-queue-DIkVcfK4.js +167 -0
- package/dist/vercel.d.ts +6 -6
- package/dist/vercel.js +14 -6
- package/dist/version-CnXZ614E.d.ts +5 -0
- package/dist/version-DxcWdoKa.js +8 -0
- package/dist/version.d.ts +2 -4
- package/dist/version.js +2 -6
- package/dist/web-authorization-RMBxAR_t.js +76 -0
- package/dist/web-input-3EPfpf55.js +494 -0
- package/dist/work-fGofI7Op.js +509 -0
- package/dist/worker-CsOLq-mR.js +625 -0
- package/package.json +9 -9
- package/dist/agent-hooks-UXITLYOK.js +0 -51
- package/dist/catalog-runtime-BG3JLLK2.js +0 -14
- package/dist/chunk-2LYHWMR4.js +0 -46
- package/dist/chunk-2MK3QBGA.js +0 -321
- package/dist/chunk-3PGQSKJV.js +0 -692
- package/dist/chunk-3UI3WFTX.js +0 -519
- package/dist/chunk-3Y47VMHV.js +0 -6
- package/dist/chunk-4UO6FK4G.js +0 -64
- package/dist/chunk-5NOPO64K.js +0 -198
- package/dist/chunk-5PKWYPFT.js +0 -2943
- package/dist/chunk-63NKKFJL.js +0 -1228
- package/dist/chunk-6AYH6252.js +0 -787
- package/dist/chunk-6Y5B5PEX.js +0 -80
- package/dist/chunk-7DHZP5KJ.js +0 -333
- package/dist/chunk-7H2VZTWN.js +0 -103
- package/dist/chunk-7NL7T6VU.js +0 -406
- package/dist/chunk-A76OIMYN.js +0 -102
- package/dist/chunk-AWMS3SPP.js +0 -58
- package/dist/chunk-B3LY5RCL.js +0 -229
- package/dist/chunk-BD2KT3OB.js +0 -36
- package/dist/chunk-BXCX5QKA.js +0 -2086
- package/dist/chunk-C6VVF43U.js +0 -81
- package/dist/chunk-CEMMLV5L.js +0 -98
- package/dist/chunk-CM5HNV2W.js +0 -131
- package/dist/chunk-DA2KGZZI.js +0 -13
- package/dist/chunk-DBVY6HLX.js +0 -64
- package/dist/chunk-DIB4GX3G.js +0 -8
- package/dist/chunk-DKIJ2RP5.js +0 -68
- package/dist/chunk-DL2KLKVH.js +0 -931
- package/dist/chunk-DWPN6SCH.js +0 -172
- package/dist/chunk-ELWOYVOY.js +0 -206
- package/dist/chunk-EWT7H65X.js +0 -506
- package/dist/chunk-FA6POGLH.js +0 -70
- package/dist/chunk-HMREVIO2.js +0 -135
- package/dist/chunk-IIWUT4FO.js +0 -820
- package/dist/chunk-JAL3CH4G.js +0 -27
- package/dist/chunk-JSJQEWBJ.js +0 -3295
- package/dist/chunk-KHKKHDLD.js +0 -387
- package/dist/chunk-LA6R4A7Q.js +0 -706
- package/dist/chunk-LOOU2DUR.js +0 -20428
- package/dist/chunk-M6FHWXE3.js +0 -700
- package/dist/chunk-M76HMB7M.js +0 -1856
- package/dist/chunk-MAGNK5J4.js +0 -1520
- package/dist/chunk-MTM5IFCY.js +0 -1190
- package/dist/chunk-N7TMSOZH.js +0 -235
- package/dist/chunk-NHJU2ZAL.js +0 -56
- package/dist/chunk-NSXKRGRT.js +0 -717
- package/dist/chunk-OWMPFXJA.js +0 -1764
- package/dist/chunk-PDO5BLNM.js +0 -22
- package/dist/chunk-PEQXYSSE.js +0 -45
- package/dist/chunk-PW4P4JYF.js +0 -1135
- package/dist/chunk-QB54UQUS.js +0 -320
- package/dist/chunk-QP3OGJXF.js +0 -105
- package/dist/chunk-RC745GGZ.js +0 -122
- package/dist/chunk-REOIRYPR.js +0 -37
- package/dist/chunk-SCOZRLZ4.js +0 -164
- package/dist/chunk-TXJSXBV5.js +0 -1433
- package/dist/chunk-TXKUKMVO.js +0 -417
- package/dist/chunk-U2GPUYAL.js +0 -3656
- package/dist/chunk-UIE3R5XU.js +0 -17
- package/dist/chunk-UXPG6ZIN.js +0 -84
- package/dist/chunk-VFUK3X5B.js +0 -50
- package/dist/chunk-WQSHDTTI.js +0 -1163
- package/dist/chunk-X6GDDWQH.js +0 -60
- package/dist/chunk-Y2CM7HXH.js +0 -111
- package/dist/chunk-Y7X25LFY.js +0 -15
- package/dist/chunk-YDUR3ZYW.js +0 -10
- package/dist/conversation-work-VIOQ5ZF3.js +0 -54
- package/dist/db-3L2MCVRI.js +0 -26
- package/dist/discovery-DWVDM7UK.js +0 -44
- package/dist/experimental-P5FZM4CU.js +0 -12
- package/dist/oauth-callback-server-YVV6C6T2.js +0 -243
- package/dist/oauth-relay-5XPVRPYB.js +0 -8
- package/dist/plugins-YTYJMMJF.js +0 -14
- package/dist/runner-LQ7RETDP.js +0 -522
- package/dist/sandbox-egress-signals-FIL7EGPR.js +0 -73
- package/dist/sentry-MB3NL3IR.js +0 -42
- package/dist/skills-XRWYEDCD.js +0 -27
- package/dist/spawn-RC6SJUAI.js +0 -42
- package/dist/task-runner-7DY7ARYH.js +0 -36
- package/dist/validation-7MNQGCJA.js +0 -17
- package/dist/work-COALHUCG.js +0 -51
- package/dist/worker-6MURZIPD.js +0 -24
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
|
|
2
|
+
//#region src/chat/experimental.ts
|
|
3
|
+
var experimental_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
EXPERIMENTAL_FEATURES: () => EXPERIMENTAL_FEATURES,
|
|
5
|
+
getExperimentalFeatures: () => getExperimentalFeatures,
|
|
6
|
+
isExperimentalFeatureEnabled: () => isExperimentalFeatureEnabled,
|
|
7
|
+
setExperimentalFeatures: () => setExperimentalFeatures
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Known unstable product features that must be opted into explicitly.
|
|
11
|
+
* Add new keys here as features graduate from private experiments; remove them
|
|
12
|
+
* once they become stable defaults.
|
|
13
|
+
*/
|
|
14
|
+
const EXPERIMENTAL_FEATURES = ["passive-routing", "subagents"];
|
|
15
|
+
const EXPERIMENTAL_FEATURE_SET = new Set(EXPERIMENTAL_FEATURES);
|
|
16
|
+
let configuredExperimental = {};
|
|
17
|
+
function isExperimentalFeature(value) {
|
|
18
|
+
return EXPERIMENTAL_FEATURE_SET.has(value);
|
|
19
|
+
}
|
|
20
|
+
/** Replace app-level experimental opt-ins and return the previous setting. */
|
|
21
|
+
function setExperimentalFeatures(config) {
|
|
22
|
+
const previous = { ...configuredExperimental };
|
|
23
|
+
if (config === void 0) {
|
|
24
|
+
configuredExperimental = {};
|
|
25
|
+
return previous;
|
|
26
|
+
}
|
|
27
|
+
const next = {};
|
|
28
|
+
for (const [rawName, enabled] of Object.entries(config)) {
|
|
29
|
+
if (enabled === void 0) continue;
|
|
30
|
+
if (typeof enabled !== "boolean") throw new Error(`experimental.${rawName} must be a boolean when provided`);
|
|
31
|
+
if (!isExperimentalFeature(rawName)) throw new Error(`experimental.${rawName} is not a known experimental feature. Known features: ${EXPERIMENTAL_FEATURES.join(", ")}`);
|
|
32
|
+
next[rawName] = enabled;
|
|
33
|
+
}
|
|
34
|
+
configuredExperimental = next;
|
|
35
|
+
return previous;
|
|
36
|
+
}
|
|
37
|
+
/** Return a copy of the app-level experimental opt-ins configured by createApp(). */
|
|
38
|
+
function getExperimentalFeatures() {
|
|
39
|
+
return { ...configuredExperimental };
|
|
40
|
+
}
|
|
41
|
+
/** Return whether one experimental feature is enabled via createApp({ experimental }). */
|
|
42
|
+
function isExperimentalFeatureEnabled(feature) {
|
|
43
|
+
return configuredExperimental[feature] === true;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { setExperimentalFeatures as i, getExperimentalFeatures as n, isExperimentalFeatureEnabled as r, experimental_exports as t };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/chat/conversations/history.d.ts
|
|
3
|
+
/** Where a failed turn stopped. */
|
|
4
|
+
declare const conversationTurnFailureCodeSchema: z.ZodEnum<{
|
|
5
|
+
agent_run_failed: "agent_run_failed";
|
|
6
|
+
delivery_failed: "delivery_failed";
|
|
7
|
+
model_execution_failed: "model_execution_failed";
|
|
8
|
+
persistence_failed: "persistence_failed";
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Why a failed turn stopped.
|
|
12
|
+
* Values are fixed labels only. Do not store raw exception text.
|
|
13
|
+
*/
|
|
14
|
+
declare const conversationTurnFailureReasonSchema: z.ZodEnum<{
|
|
15
|
+
unknown: "unknown";
|
|
16
|
+
capacity: "capacity";
|
|
17
|
+
auth: "auth";
|
|
18
|
+
permission: "permission";
|
|
19
|
+
rate_limit: "rate_limit";
|
|
20
|
+
timeout: "timeout";
|
|
21
|
+
network: "network";
|
|
22
|
+
server: "server";
|
|
23
|
+
invalid_request: "invalid_request";
|
|
24
|
+
invalid_response: "invalid_response";
|
|
25
|
+
quota: "quota";
|
|
26
|
+
content_policy: "content_policy";
|
|
27
|
+
empty_output: "empty_output";
|
|
28
|
+
tool_errors: "tool_errors";
|
|
29
|
+
suppressed_output: "suppressed_output";
|
|
30
|
+
}>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { conversationTurnFailureReasonSchema as n, conversationTurnFailureCodeSchema as t };
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { c as TURN_REASONING_LEVELS, o as modelProfileSchema } from "./model-profile-CZmVoGdX.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { actorSchema } from "@sentry/junior-plugin-api";
|
|
4
|
+
//#region src/chat/conversations/provenance.ts
|
|
5
|
+
/**
|
|
6
|
+
* Durable message attribution shared by storage and projections.
|
|
7
|
+
* Attribution never grants credential authority.
|
|
8
|
+
*/
|
|
9
|
+
const conversationMessageAuthoritySchema = z.union([z.literal("instruction"), z.literal("context")]);
|
|
10
|
+
/** Canonical authority and actor metadata for one durable message event. */
|
|
11
|
+
const conversationMessageProvenanceSchema = z.object({
|
|
12
|
+
authority: conversationMessageAuthoritySchema,
|
|
13
|
+
actor: actorSchema.optional()
|
|
14
|
+
}).strict();
|
|
15
|
+
/** Build instruction provenance for an optional actor. */
|
|
16
|
+
function instructionProvenanceFor(actor) {
|
|
17
|
+
return actor ? {
|
|
18
|
+
authority: "instruction",
|
|
19
|
+
actor
|
|
20
|
+
} : { authority: "instruction" };
|
|
21
|
+
}
|
|
22
|
+
/** Unattributed ambient-context provenance for non-instruction messages. */
|
|
23
|
+
const contextProvenance = { authority: "context" };
|
|
24
|
+
function actorIdentityKey(actor) {
|
|
25
|
+
if (actor.platform === "system") return `system ${actor.name}`;
|
|
26
|
+
return actor.platform === "slack" ? `slack\u0000${actor.teamId}\u0000${actor.userId}` : `${actor.platform}\u0000${actor.userId}`;
|
|
27
|
+
}
|
|
28
|
+
/** Compare two actors by runtime identity only, never by display metadata. */
|
|
29
|
+
function sameActorIdentity(left, right) {
|
|
30
|
+
return Boolean(left && right && actorIdentityKey(left) === actorIdentityKey(right));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Return distinct instruction actors in first-seen order for attribution only.
|
|
34
|
+
* Never use this list as credential authority.
|
|
35
|
+
*/
|
|
36
|
+
function instructionActors(provenance) {
|
|
37
|
+
const seen = /* @__PURE__ */ new Set();
|
|
38
|
+
const actors = [];
|
|
39
|
+
for (const entry of provenance) {
|
|
40
|
+
if (entry.authority !== "instruction" || !entry.actor) continue;
|
|
41
|
+
const identity = actorIdentityKey(entry.actor);
|
|
42
|
+
if (seen.has(identity)) continue;
|
|
43
|
+
seen.add(identity);
|
|
44
|
+
actors.push(entry.actor);
|
|
45
|
+
}
|
|
46
|
+
return actors;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/chat/conversations/history.ts
|
|
50
|
+
/**
|
|
51
|
+
* Durable conversation event history port.
|
|
52
|
+
*
|
|
53
|
+
* Events append under the conversation lease in stable sequence order.
|
|
54
|
+
* Compaction and handoff replace the active model history without rewriting
|
|
55
|
+
* prior events. Unsupported stored events remain readable as opaque facts,
|
|
56
|
+
* while malformed known events fail loudly. Provider-specific message fields
|
|
57
|
+
* are validated by the Pi adapter when it restores model context.
|
|
58
|
+
*/
|
|
59
|
+
const userMessageEventDataSchema = z.object({
|
|
60
|
+
type: z.literal("user_message"),
|
|
61
|
+
role: z.never().optional(),
|
|
62
|
+
provenance: conversationMessageProvenanceSchema
|
|
63
|
+
}).passthrough();
|
|
64
|
+
const assistantMessageEventDataSchema = z.object({
|
|
65
|
+
type: z.literal("assistant_message"),
|
|
66
|
+
role: z.never().optional()
|
|
67
|
+
}).passthrough();
|
|
68
|
+
const toolResultEventDataSchema = z.object({
|
|
69
|
+
type: z.literal("tool_result"),
|
|
70
|
+
role: z.never().optional()
|
|
71
|
+
}).passthrough();
|
|
72
|
+
/**
|
|
73
|
+
* One replayable agent-history item. Junior owns `type` and user provenance,
|
|
74
|
+
* forbids the provider `role` discriminator, and leaves preserved message
|
|
75
|
+
* fields for the Pi adapter to validate when restoring model context.
|
|
76
|
+
*/
|
|
77
|
+
const agentHistoryItemSchema = z.discriminatedUnion("type", [
|
|
78
|
+
userMessageEventDataSchema,
|
|
79
|
+
assistantMessageEventDataSchema,
|
|
80
|
+
toolResultEventDataSchema
|
|
81
|
+
]);
|
|
82
|
+
const nativeReplacementHistoryItemSchema = z.object({
|
|
83
|
+
item: agentHistoryItemSchema,
|
|
84
|
+
sourceEventSeq: z.number().int().nonnegative().optional()
|
|
85
|
+
}).strict();
|
|
86
|
+
/**
|
|
87
|
+
* The complete agent history used immediately after a replacement. Later
|
|
88
|
+
* native history events append to it. Replacement entries are replayed model
|
|
89
|
+
* history, not new conversation activity.
|
|
90
|
+
*/
|
|
91
|
+
const replacementHistorySchema = z.array(nativeReplacementHistoryItemSchema);
|
|
92
|
+
const compactionDetailsSchema = z.object({
|
|
93
|
+
reason: z.literal("capacity"),
|
|
94
|
+
estimatedInputTokens: z.number().int().nonnegative(),
|
|
95
|
+
replacementInputTokens: z.number().int().nonnegative().optional(),
|
|
96
|
+
triggerTokens: z.number().int().nonnegative(),
|
|
97
|
+
inputLimitTokens: z.number().int().positive(),
|
|
98
|
+
inputMessageCount: z.number().int().nonnegative(),
|
|
99
|
+
retainedMessageCount: z.number().int().nonnegative(),
|
|
100
|
+
summaryChars: z.number().int().nonnegative()
|
|
101
|
+
}).strict();
|
|
102
|
+
const historyReplacementEventDataSchema = z.discriminatedUnion("type", [z.object({
|
|
103
|
+
type: z.literal("handoff"),
|
|
104
|
+
modelProfile: modelProfileSchema,
|
|
105
|
+
modelId: z.string().min(1),
|
|
106
|
+
reasoningLevel: z.string().min(1).optional(),
|
|
107
|
+
triggeringToolCallId: z.string().min(1).optional(),
|
|
108
|
+
summary: z.string().min(1).optional(),
|
|
109
|
+
replacementHistory: replacementHistorySchema
|
|
110
|
+
}).strict(), z.object({
|
|
111
|
+
type: z.literal("compaction"),
|
|
112
|
+
modelProfile: modelProfileSchema,
|
|
113
|
+
modelId: z.string().min(1),
|
|
114
|
+
details: compactionDetailsSchema.optional(),
|
|
115
|
+
summary: z.string().min(1).optional(),
|
|
116
|
+
replacementHistory: replacementHistorySchema
|
|
117
|
+
}).strict()]);
|
|
118
|
+
/** Validate an event that intentionally replaces active model history. */
|
|
119
|
+
const historyReplacementSchema = z.object({
|
|
120
|
+
data: historyReplacementEventDataSchema,
|
|
121
|
+
createdAtMs: z.number().finite()
|
|
122
|
+
}).strict();
|
|
123
|
+
const mcpProviderConnectedEventDataSchema = z.object({
|
|
124
|
+
type: z.literal("mcp_provider_connected"),
|
|
125
|
+
provider: z.string().min(1),
|
|
126
|
+
credentialSubjectId: z.string().min(1)
|
|
127
|
+
}).strict();
|
|
128
|
+
const unownedMcpProviderConnectedEventDataSchema = z.object({
|
|
129
|
+
type: z.literal("mcp_provider_connected_unowned"),
|
|
130
|
+
provider: z.string().min(1)
|
|
131
|
+
}).strict();
|
|
132
|
+
const authorizationKindSchema = z.union([z.literal("plugin"), z.literal("mcp")]);
|
|
133
|
+
const authorizationRequestedEventDataSchema = z.object({
|
|
134
|
+
type: z.literal("authorization_requested"),
|
|
135
|
+
kind: authorizationKindSchema,
|
|
136
|
+
provider: z.string().min(1),
|
|
137
|
+
actorId: z.string().min(1),
|
|
138
|
+
authorizationId: z.string().min(1),
|
|
139
|
+
delivery: z.union([z.literal("private_link_sent"), z.literal("private_link_reused")])
|
|
140
|
+
}).strict();
|
|
141
|
+
const authorizationCompletedEventDataSchema = z.object({
|
|
142
|
+
type: z.literal("authorization_completed"),
|
|
143
|
+
kind: authorizationKindSchema,
|
|
144
|
+
provider: z.string().min(1),
|
|
145
|
+
actorId: z.string().min(1),
|
|
146
|
+
authorizationId: z.string().min(1)
|
|
147
|
+
}).strict();
|
|
148
|
+
const toolExecutionStartedEventDataSchema = z.object({
|
|
149
|
+
type: z.literal("tool_execution_started"),
|
|
150
|
+
toolCallId: z.string().min(1),
|
|
151
|
+
toolName: z.string().min(1)
|
|
152
|
+
}).strict();
|
|
153
|
+
const guardianActionReviewedEventDataSchema = z.object({
|
|
154
|
+
type: z.literal("guardian_action_reviewed"),
|
|
155
|
+
turnId: z.string().min(1),
|
|
156
|
+
toolCallId: z.string().min(1),
|
|
157
|
+
toolName: z.string().min(1),
|
|
158
|
+
costUsd: z.number().finite().nonnegative().optional(),
|
|
159
|
+
decision: z.enum([
|
|
160
|
+
"allow",
|
|
161
|
+
"ask",
|
|
162
|
+
"deny"
|
|
163
|
+
]),
|
|
164
|
+
riskLevel: z.enum([
|
|
165
|
+
"low",
|
|
166
|
+
"medium",
|
|
167
|
+
"high",
|
|
168
|
+
"critical"
|
|
169
|
+
]),
|
|
170
|
+
userAuthorization: z.enum([
|
|
171
|
+
"high",
|
|
172
|
+
"medium",
|
|
173
|
+
"low",
|
|
174
|
+
"unknown"
|
|
175
|
+
])
|
|
176
|
+
}).strict();
|
|
177
|
+
const conversationMessageRoleSchema = z.union([
|
|
178
|
+
z.literal("user"),
|
|
179
|
+
z.literal("assistant"),
|
|
180
|
+
z.literal("system")
|
|
181
|
+
]);
|
|
182
|
+
const messageEventDataSchema = z.object({
|
|
183
|
+
type: z.literal("message"),
|
|
184
|
+
messageId: z.string().min(1),
|
|
185
|
+
role: conversationMessageRoleSchema,
|
|
186
|
+
text: z.string(),
|
|
187
|
+
authorIdentityId: z.string().min(1).optional(),
|
|
188
|
+
meta: z.record(z.string(), z.unknown()).optional()
|
|
189
|
+
}).strict();
|
|
190
|
+
const messageUpdatedEventDataSchema = messageEventDataSchema.extend({ type: z.literal("message_updated") });
|
|
191
|
+
const messageHandledEventDataSchema = z.object({
|
|
192
|
+
type: z.literal("message_handled"),
|
|
193
|
+
messageId: z.string().min(1)
|
|
194
|
+
}).strict();
|
|
195
|
+
const messagesSummarizedEventDataSchema = z.object({
|
|
196
|
+
type: z.literal("messages_summarized"),
|
|
197
|
+
historyFromSeq: z.number().int().nonnegative(),
|
|
198
|
+
compactions: z.array(z.object({
|
|
199
|
+
coveredMessageCount: z.number().int().nonnegative(),
|
|
200
|
+
createdAtMs: z.number(),
|
|
201
|
+
id: z.string().min(1),
|
|
202
|
+
summary: z.string()
|
|
203
|
+
}).strict())
|
|
204
|
+
}).strict();
|
|
205
|
+
/** Product surface that owns a durable conversation turn. */
|
|
206
|
+
const conversationTurnSurfaceSchema = z.enum([
|
|
207
|
+
"slack",
|
|
208
|
+
"api",
|
|
209
|
+
"scheduler",
|
|
210
|
+
"internal"
|
|
211
|
+
]);
|
|
212
|
+
/** Where a failed turn stopped. */
|
|
213
|
+
const conversationTurnFailureCodeSchema = z.enum([
|
|
214
|
+
"agent_run_failed",
|
|
215
|
+
"delivery_failed",
|
|
216
|
+
"model_execution_failed",
|
|
217
|
+
"persistence_failed"
|
|
218
|
+
]);
|
|
219
|
+
/**
|
|
220
|
+
* Why a failed turn stopped.
|
|
221
|
+
* Values are fixed labels only. Do not store raw exception text.
|
|
222
|
+
*/
|
|
223
|
+
const conversationTurnFailureReasonSchema = z.enum([
|
|
224
|
+
"auth",
|
|
225
|
+
"permission",
|
|
226
|
+
"rate_limit",
|
|
227
|
+
"capacity",
|
|
228
|
+
"timeout",
|
|
229
|
+
"network",
|
|
230
|
+
"server",
|
|
231
|
+
"invalid_request",
|
|
232
|
+
"invalid_response",
|
|
233
|
+
"quota",
|
|
234
|
+
"content_policy",
|
|
235
|
+
"unknown",
|
|
236
|
+
"empty_output",
|
|
237
|
+
"tool_errors",
|
|
238
|
+
"suppressed_output"
|
|
239
|
+
]);
|
|
240
|
+
const turnStartedEventDataSchema = z.object({
|
|
241
|
+
type: z.literal("turn_started"),
|
|
242
|
+
turnId: z.string().min(1),
|
|
243
|
+
inputMessageIds: z.array(z.string().min(1)).min(1),
|
|
244
|
+
surface: conversationTurnSurfaceSchema
|
|
245
|
+
}).strict().refine((data) => new Set(data.inputMessageIds).size === data.inputMessageIds.length, "turn input message ids must be unique");
|
|
246
|
+
const turnRoutedEventDataSchema = z.object({
|
|
247
|
+
type: z.literal("turn_routed"),
|
|
248
|
+
turnId: z.string().min(1),
|
|
249
|
+
modelProfile: modelProfileSchema,
|
|
250
|
+
modelId: z.string().min(1),
|
|
251
|
+
costUsd: z.number().finite().nonnegative().optional(),
|
|
252
|
+
reasoningLevel: z.enum(TURN_REASONING_LEVELS),
|
|
253
|
+
confidence: z.number().min(0).max(1).optional(),
|
|
254
|
+
source: z.enum([
|
|
255
|
+
"configured",
|
|
256
|
+
"inherited",
|
|
257
|
+
"router"
|
|
258
|
+
])
|
|
259
|
+
}).strict();
|
|
260
|
+
const turnContextEventDataSchema = z.object({
|
|
261
|
+
type: z.literal("turn_context"),
|
|
262
|
+
turnId: z.string().min(1),
|
|
263
|
+
pluginName: z.string().min(1),
|
|
264
|
+
kind: z.string().min(1).max(64),
|
|
265
|
+
version: z.number().int().positive(),
|
|
266
|
+
content: z.record(z.string(), z.unknown())
|
|
267
|
+
}).strict();
|
|
268
|
+
const structuredConversationEventDataSchema = z.object({
|
|
269
|
+
type: z.literal("structured_event"),
|
|
270
|
+
namespace: z.string().regex(/^[a-z][a-z0-9-]*$/),
|
|
271
|
+
name: z.string().regex(/^[a-z][a-z0-9_]*$/),
|
|
272
|
+
version: z.number().int().positive(),
|
|
273
|
+
turnId: z.string().min(1).optional(),
|
|
274
|
+
content: z.record(z.string(), z.unknown())
|
|
275
|
+
}).strict();
|
|
276
|
+
/** Durable attachment metadata on host-owned delivery events. */
|
|
277
|
+
const deliveredAttachmentSchema = z.object({
|
|
278
|
+
id: z.string().min(1),
|
|
279
|
+
filename: z.string().min(1),
|
|
280
|
+
contentType: z.string().min(1),
|
|
281
|
+
bytes: z.number().int().nonnegative()
|
|
282
|
+
}).strict();
|
|
283
|
+
/** Host-owned transcript item for files delivered to humans this turn. */
|
|
284
|
+
const attachmentsDeliveredEventDataSchema = z.object({
|
|
285
|
+
type: z.literal("attachments_delivered"),
|
|
286
|
+
attachments: z.array(deliveredAttachmentSchema).min(1),
|
|
287
|
+
toolCallId: z.string().min(1).optional(),
|
|
288
|
+
turnId: z.string().min(1).optional()
|
|
289
|
+
}).strict();
|
|
290
|
+
const turnCompletedEventDataSchema = z.object({
|
|
291
|
+
type: z.literal("turn_completed"),
|
|
292
|
+
turnId: z.string().min(1),
|
|
293
|
+
outcome: z.enum([
|
|
294
|
+
"success",
|
|
295
|
+
"no_reply",
|
|
296
|
+
"cancelled"
|
|
297
|
+
])
|
|
298
|
+
}).strict();
|
|
299
|
+
const turnFailedEventDataSchema = z.object({
|
|
300
|
+
type: z.literal("turn_failed"),
|
|
301
|
+
turnId: z.string().min(1),
|
|
302
|
+
failureCode: conversationTurnFailureCodeSchema,
|
|
303
|
+
failureReason: conversationTurnFailureReasonSchema.optional(),
|
|
304
|
+
eventId: z.string().regex(/^[a-f0-9]{32}$/i).optional()
|
|
305
|
+
}).strict();
|
|
306
|
+
const subagentStartedEventDataSchema = z.object({
|
|
307
|
+
type: z.literal("subagent_started"),
|
|
308
|
+
subagentInvocationId: z.string().min(1),
|
|
309
|
+
subagentKind: z.string().min(1),
|
|
310
|
+
modelId: z.string().min(1).optional(),
|
|
311
|
+
parentToolCallId: z.string().min(1).optional(),
|
|
312
|
+
reasoningLevel: z.string().min(1).optional(),
|
|
313
|
+
childConversationId: z.string().min(1)
|
|
314
|
+
}).strict();
|
|
315
|
+
const subagentEndedEventDataSchema = z.object({
|
|
316
|
+
type: z.literal("subagent_ended"),
|
|
317
|
+
subagentInvocationId: z.string().min(1),
|
|
318
|
+
outcome: z.union([
|
|
319
|
+
z.literal("success"),
|
|
320
|
+
z.literal("error"),
|
|
321
|
+
z.literal("aborted")
|
|
322
|
+
]),
|
|
323
|
+
errorCode: z.string().min(1).optional()
|
|
324
|
+
}).strict();
|
|
325
|
+
/** Prevent ordinary appends from bypassing history-replacement validation. */
|
|
326
|
+
const appendableConversationEventDataSchema = z.union([
|
|
327
|
+
messageEventDataSchema,
|
|
328
|
+
messageUpdatedEventDataSchema,
|
|
329
|
+
agentHistoryItemSchema,
|
|
330
|
+
mcpProviderConnectedEventDataSchema,
|
|
331
|
+
authorizationRequestedEventDataSchema,
|
|
332
|
+
authorizationCompletedEventDataSchema,
|
|
333
|
+
toolExecutionStartedEventDataSchema,
|
|
334
|
+
guardianActionReviewedEventDataSchema,
|
|
335
|
+
messageHandledEventDataSchema,
|
|
336
|
+
messagesSummarizedEventDataSchema,
|
|
337
|
+
turnStartedEventDataSchema,
|
|
338
|
+
turnContextEventDataSchema,
|
|
339
|
+
structuredConversationEventDataSchema,
|
|
340
|
+
attachmentsDeliveredEventDataSchema,
|
|
341
|
+
turnRoutedEventDataSchema,
|
|
342
|
+
turnCompletedEventDataSchema,
|
|
343
|
+
turnFailedEventDataSchema,
|
|
344
|
+
subagentStartedEventDataSchema,
|
|
345
|
+
subagentEndedEventDataSchema
|
|
346
|
+
]);
|
|
347
|
+
/** Strict event-data contract reused by the SQL row codec. */
|
|
348
|
+
const conversationEventDataSchema = z.union([
|
|
349
|
+
appendableConversationEventDataSchema,
|
|
350
|
+
historyReplacementEventDataSchema,
|
|
351
|
+
unownedMcpProviderConnectedEventDataSchema
|
|
352
|
+
]);
|
|
353
|
+
/** Event type names recognized by current readers and observational queries. */
|
|
354
|
+
const KNOWN_CONVERSATION_EVENT_TYPES = [
|
|
355
|
+
"message",
|
|
356
|
+
"message_updated",
|
|
357
|
+
"user_message",
|
|
358
|
+
"assistant_message",
|
|
359
|
+
"tool_result",
|
|
360
|
+
"mcp_provider_connected",
|
|
361
|
+
"mcp_provider_connected_unowned",
|
|
362
|
+
"authorization_requested",
|
|
363
|
+
"authorization_completed",
|
|
364
|
+
"tool_execution_started",
|
|
365
|
+
"guardian_action_reviewed",
|
|
366
|
+
"message_handled",
|
|
367
|
+
"messages_summarized",
|
|
368
|
+
"turn_started",
|
|
369
|
+
"turn_context",
|
|
370
|
+
"structured_event",
|
|
371
|
+
"attachments_delivered",
|
|
372
|
+
"turn_routed",
|
|
373
|
+
"turn_completed",
|
|
374
|
+
"turn_failed",
|
|
375
|
+
"subagent_started",
|
|
376
|
+
"subagent_ended",
|
|
377
|
+
"handoff",
|
|
378
|
+
"compaction"
|
|
379
|
+
];
|
|
380
|
+
const knownConversationEventTypeSchema = z.enum(KNOWN_CONVERSATION_EVENT_TYPES);
|
|
381
|
+
const unknownConversationEventDataSchema = z.object({
|
|
382
|
+
type: z.literal("unknown"),
|
|
383
|
+
originalType: z.string().min(1),
|
|
384
|
+
payload: z.unknown()
|
|
385
|
+
}).strict();
|
|
386
|
+
const conversationEventEnvelopeSchema = z.object({
|
|
387
|
+
schemaVersion: z.number().int().nonnegative(),
|
|
388
|
+
seq: z.number().int().nonnegative(),
|
|
389
|
+
historyVersion: z.number().int().nonnegative(),
|
|
390
|
+
idempotencyKey: z.string().min(1).optional(),
|
|
391
|
+
createdAtMs: z.number().finite()
|
|
392
|
+
}).strict();
|
|
393
|
+
/**
|
|
394
|
+
* Canonical ordered envelope for the durable conversation log.
|
|
395
|
+
* `schemaVersion` is persisted with every physical event row.
|
|
396
|
+
*/
|
|
397
|
+
const conversationEventSchema = z.union([conversationEventEnvelopeSchema.extend({
|
|
398
|
+
schemaVersion: z.literal(1),
|
|
399
|
+
data: conversationEventDataSchema
|
|
400
|
+
}), conversationEventEnvelopeSchema.extend({ data: unknownConversationEventDataSchema })]);
|
|
401
|
+
const storedConversationEventSchema = conversationEventEnvelopeSchema.extend({
|
|
402
|
+
type: z.string().min(1),
|
|
403
|
+
payload: z.unknown()
|
|
404
|
+
});
|
|
405
|
+
/**
|
|
406
|
+
* Decode a physical event row without making old or future event types
|
|
407
|
+
* unreadable. Unsupported rows stay opaque until an upgrade migration defines
|
|
408
|
+
* their semantics; known version-one events remain strict so corrupt canonical
|
|
409
|
+
* data cannot be mistaken for compatibility data.
|
|
410
|
+
*/
|
|
411
|
+
function decodeStoredConversationEvent(value) {
|
|
412
|
+
const stored = storedConversationEventSchema.parse(value);
|
|
413
|
+
const { type, payload, ...envelope } = stored;
|
|
414
|
+
const knownType = knownConversationEventTypeSchema.safeParse(type).success;
|
|
415
|
+
if (stored.schemaVersion === 1 && knownType) {
|
|
416
|
+
const data = typeof payload === "object" && payload !== null && !Array.isArray(payload) ? {
|
|
417
|
+
...payload,
|
|
418
|
+
type
|
|
419
|
+
} : { type };
|
|
420
|
+
return conversationEventSchema.parse({
|
|
421
|
+
...envelope,
|
|
422
|
+
data
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
return conversationEventSchema.parse({
|
|
426
|
+
...envelope,
|
|
427
|
+
data: {
|
|
428
|
+
type: "unknown",
|
|
429
|
+
originalType: type,
|
|
430
|
+
payload
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
/** Validate an append without permitting model-history replacement events. */
|
|
435
|
+
const newConversationEventSchema = z.object({
|
|
436
|
+
data: appendableConversationEventDataSchema,
|
|
437
|
+
idempotencyKey: z.string().min(1).optional(),
|
|
438
|
+
createdAtMs: z.number().finite()
|
|
439
|
+
}).strict();
|
|
440
|
+
//#endregion
|
|
441
|
+
export { conversationTurnFailureReasonSchema as a, newConversationEventSchema as c, instructionProvenanceFor as d, sameActorIdentity as f, conversationTurnFailureCodeSchema as i, contextProvenance as l, agentHistoryItemSchema as n, decodeStoredConversationEvent as o, conversationEventDataSchema as r, historyReplacementSchema as s, KNOWN_CONVERSATION_EVENT_TYPES as t, instructionActors as u };
|