@sentry/junior 0.91.0 → 0.92.1
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-MXAF7RQL.js → agent-hooks-KL7I3ZRC.js} +7 -7
- package/dist/api/people/list.d.ts +3 -3
- package/dist/api/people/list.js +15 -15
- package/dist/api/people/list.query.d.ts +2 -2
- package/dist/api/people/profile.d.ts +3 -3
- package/dist/api/people/profile.js +12 -12
- package/dist/api/people/profile.query.d.ts +2 -2
- package/dist/api/people/shared.d.ts +13 -13
- package/dist/api/people/types.d.ts +12 -12
- package/dist/api-reference.d.ts +1 -1
- package/dist/app.js +365 -265
- package/dist/{catalog-runtime-DXE6NXHT.js → catalog-runtime-NZHMSMYC.js} +2 -2
- package/dist/chat/actor.d.ts +75 -0
- package/dist/chat/agent/prompt.d.ts +2 -2
- package/dist/chat/agent/request.d.ts +13 -13
- package/dist/chat/agent/resume.d.ts +5 -4
- package/dist/chat/agent/tools.d.ts +4 -2
- package/dist/chat/capabilities/jr-rpc-command.d.ts +1 -1
- package/dist/chat/conversation-privacy.d.ts +11 -0
- package/dist/chat/conversations/sql/migrations.d.ts +1 -1
- package/dist/chat/conversations/sql/schema/conversations.d.ts +2 -19
- package/dist/chat/conversations/sql/schema.d.ts +2 -19
- package/dist/chat/conversations/sql/store.d.ts +3 -3
- package/dist/chat/conversations/store.d.ts +4 -4
- package/dist/chat/credentials/context.d.ts +4 -4
- package/dist/chat/logging.d.ts +2 -2
- package/dist/chat/no-reply.d.ts +1 -1
- package/dist/chat/oauth-flow.d.ts +1 -1
- package/dist/chat/pi/messages.d.ts +2 -2
- package/dist/chat/pi/transcript.d.ts +15 -0
- package/dist/chat/plugins/agent-hooks.d.ts +5 -3
- package/dist/chat/plugins/credential-hooks.d.ts +2 -8
- package/dist/chat/prompt.d.ts +3 -6
- package/dist/chat/runtime/reply-executor.d.ts +1 -1
- package/dist/chat/runtime/turn-input.d.ts +1 -1
- package/dist/chat/sandbox/egress/schemas.d.ts +2 -2
- package/dist/chat/sandbox/egress/session.d.ts +1 -1
- package/dist/chat/services/context-compaction.d.ts +1 -1
- package/dist/chat/services/conversation-memory.d.ts +1 -1
- package/dist/chat/services/mcp-auth-orchestration.d.ts +1 -1
- package/dist/chat/services/message-actor-identity.d.ts +4 -4
- package/dist/chat/services/pending-auth.d.ts +2 -2
- package/dist/chat/services/plugin-auth-orchestration.d.ts +1 -1
- package/dist/chat/services/provider-default-config.d.ts +1 -1
- package/dist/chat/services/subscribed-decision.d.ts +1 -1
- package/dist/chat/services/turn-result.d.ts +1 -1
- package/dist/chat/services/turn-session-record.d.ts +11 -8
- package/dist/chat/services/turn-thinking-level.d.ts +1 -1
- package/dist/chat/slack/assistant-thread/title.d.ts +1 -1
- package/dist/chat/slack/tools/canvas/create.d.ts +41 -1
- package/dist/chat/slack/tools/canvas/edit.d.ts +60 -1
- package/dist/chat/slack/tools/canvas/read.d.ts +60 -1
- package/dist/chat/slack/tools/canvas/write.d.ts +41 -1
- package/dist/chat/slack/tools/channel-list-messages.d.ts +45 -1
- package/dist/chat/slack/tools/context.d.ts +3 -3
- package/dist/chat/slack/tools/list/add-items.d.ts +42 -1
- package/dist/chat/slack/tools/list/create.d.ts +40 -1
- package/dist/chat/slack/tools/list/get-items.d.ts +40 -1
- package/dist/chat/slack/tools/list/update-item.d.ts +46 -1
- package/dist/chat/slack/tools/message-add-reaction.d.ts +40 -1
- package/dist/chat/slack/tools/send-message.d.ts +45 -1
- package/dist/chat/slack/tools/thread-read.d.ts +44 -1
- package/dist/chat/slack/tools/user-lookup.d.ts +45 -1
- package/dist/chat/slack/user.d.ts +3 -3
- package/dist/chat/slack/vision-context.d.ts +2 -2
- package/dist/chat/sql/schema.d.ts +2 -19
- package/dist/chat/state/conversation-details.d.ts +4 -4
- package/dist/chat/state/conversation.d.ts +1 -1
- package/dist/chat/state/session-log.d.ts +140 -26
- package/dist/chat/state/turn-session.d.ts +18 -5
- package/dist/chat/task-execution/slack-work.d.ts +2 -2
- package/dist/chat/task-execution/state.d.ts +4 -4
- package/dist/chat/tool-support/zod-tool.d.ts +16 -4
- package/dist/chat/tools/advisor/tool.d.ts +41 -1
- package/dist/chat/tools/definition.d.ts +10 -0
- package/dist/chat/tools/execute-tool.d.ts +41 -1
- package/dist/chat/tools/resource-events.d.ts +124 -3
- package/dist/chat/tools/runtime/report-progress.d.ts +40 -1
- package/dist/chat/tools/sandbox/bash.d.ts +41 -1
- package/dist/chat/tools/sandbox/edit-file.d.ts +44 -1
- package/dist/chat/tools/sandbox/find-files.d.ts +42 -1
- package/dist/chat/tools/sandbox/grep.d.ts +46 -1
- package/dist/chat/tools/sandbox/list-dir.d.ts +41 -1
- package/dist/chat/tools/sandbox/read-file.d.ts +42 -1
- package/dist/chat/tools/sandbox/write-file.d.ts +41 -1
- package/dist/chat/tools/search-tools.d.ts +102 -1
- package/dist/chat/tools/skill/call-mcp-tool.d.ts +10 -1
- package/dist/chat/tools/skill/load-skill.d.ts +40 -1
- package/dist/chat/tools/skill/search-mcp-tools.d.ts +100 -1
- package/dist/chat/tools/system-time.d.ts +38 -1
- package/dist/chat/tools/types.d.ts +4 -4
- package/dist/chat/tools/web/fetch-tool.d.ts +41 -1
- package/dist/chat/tools/web/image-generate.d.ts +62 -1
- package/dist/chat/tools/web/search.d.ts +41 -1
- package/dist/{chunk-HXL2ZV74.js → chunk-3F54A3YM.js} +82 -11
- package/dist/{chunk-ZGDTBSQ7.js → chunk-56SIBIVF.js} +930 -660
- package/dist/{chunk-DACFZ5CI.js → chunk-7K3JALTQ.js} +18 -12
- package/dist/{chunk-IRRMABQD.js → chunk-APIVR44P.js} +10 -10
- package/dist/{chunk-XP7F4LYB.js → chunk-BTH37NCU.js} +4 -4
- package/dist/{chunk-5GBUZI6M.js → chunk-H7KUZAMZ.js} +4 -4
- package/dist/{chunk-PIB4EOW6.js → chunk-IWKVXO3F.js} +19 -72
- package/dist/{chunk-TYUXD3FN.js → chunk-MC4ZZE4Q.js} +1 -1
- package/dist/{chunk-2S7M37HY.js → chunk-NIFONS4W.js} +86 -47
- package/dist/{chunk-AOISHLSF.js → chunk-O6ZYIHFC.js} +143 -20
- package/dist/{chunk-GCWD2VHP.js → chunk-OQQU3SD6.js} +285 -124
- package/dist/{chunk-NW7AXDA5.js → chunk-OZJXGX4U.js} +2 -2
- package/dist/{chunk-KC42JAAQ.js → chunk-PFXC67GJ.js} +3 -3
- package/dist/{chunk-QCKGI74V.js → chunk-PGR4WGZW.js} +10 -10
- package/dist/{chunk-ZUK7BL63.js → chunk-S6QKIGRM.js} +66 -54
- package/dist/{chunk-IX76WFJV.js → chunk-TF5VLGA7.js} +10 -10
- package/dist/{chunk-AN2437E3.js → chunk-YTNPU7I2.js} +2 -2
- package/dist/{chunk-3MPOMK3K.js → chunk-YYBX2BD5.js} +61 -3
- package/dist/{chunk-ONFOWI2D.js → chunk-Z4FOYQXW.js} +16 -15
- package/dist/{chunk-RS6ANWVT.js → chunk-ZATRYQLR.js} +1 -1
- package/dist/cli/chat.js +20 -20
- package/dist/cli/check.js +3 -3
- package/dist/cli/plugins.js +9 -9
- package/dist/cli/snapshot-warmup.js +6 -6
- package/dist/cli/upgrade.js +9 -9
- package/dist/{db-CXI7PR5U.js → db-GCK43OO3.js} +4 -4
- package/dist/instrumentation.js +1 -1
- package/dist/reporting/conversations.d.ts +3 -3
- package/dist/reporting.d.ts +1 -1
- package/dist/reporting.js +48 -50
- package/dist/{runner-FKL3RAHA.js → runner-Y73GZ2VE.js} +20 -18
- package/dist/{validation-I7GD2YWS.js → validation-KYAWETI4.js} +3 -3
- package/package.json +6 -6
- package/dist/chat/requester.d.ts +0 -68
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getConnectedStateContext,
|
|
3
3
|
getStateAdapter
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ZATRYQLR.js";
|
|
5
5
|
import {
|
|
6
6
|
getConversationStore
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NIFONS4W.js";
|
|
8
8
|
import {
|
|
9
9
|
getChatConfig
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-3F54A3YM.js";
|
|
11
11
|
import {
|
|
12
12
|
parseDestination
|
|
13
13
|
} from "./chunk-GHGPTPBL.js";
|
|
14
14
|
import {
|
|
15
15
|
logWarn,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} from "./chunk-
|
|
16
|
+
parseActor,
|
|
17
|
+
storedSlackActorSchema,
|
|
18
|
+
toStoredSlackActor
|
|
19
|
+
} from "./chunk-S6QKIGRM.js";
|
|
20
20
|
import {
|
|
21
21
|
isRecord
|
|
22
22
|
} from "./chunk-OB42YVAE.js";
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
// src/chat/state/session-log.ts
|
|
25
25
|
import { isDeepStrictEqual } from "util";
|
|
26
26
|
import { z as z2 } from "zod";
|
|
27
|
+
import { actorSchema } from "@sentry/junior-plugin-api";
|
|
27
28
|
|
|
28
29
|
// src/chat/pi/messages.ts
|
|
29
30
|
import { z } from "zod";
|
|
@@ -37,32 +38,67 @@ var piContentMessageSchema = z.object({
|
|
|
37
38
|
|
|
38
39
|
// src/chat/state/session-log.ts
|
|
39
40
|
var AGENT_SESSION_LOG_PREFIX = "junior:agent-session-log";
|
|
40
|
-
var AGENT_SESSION_LOG_SCHEMA_VERSION =
|
|
41
|
+
var AGENT_SESSION_LOG_SCHEMA_VERSION = 2;
|
|
41
42
|
var INITIAL_SESSION_ID = "session_0";
|
|
42
43
|
var SESSION_ID_PREFIX = "session_";
|
|
43
44
|
var STATE_STORE_LOCK_TTL_MS = 5e3;
|
|
45
|
+
var schemaVersionSchema = z2.union([z2.literal(1), z2.literal(2)]);
|
|
46
|
+
var piMessageAuthoritySchema = z2.union([
|
|
47
|
+
z2.literal("instruction"),
|
|
48
|
+
z2.literal("context")
|
|
49
|
+
]);
|
|
50
|
+
var piMessageProvenanceSchema = z2.object({
|
|
51
|
+
authority: piMessageAuthoritySchema,
|
|
52
|
+
actor: actorSchema.optional()
|
|
53
|
+
}).strict();
|
|
54
|
+
var unattributedContextProvenance = {
|
|
55
|
+
authority: "context"
|
|
56
|
+
};
|
|
57
|
+
function instructionProvenance(actor) {
|
|
58
|
+
return actor ? { authority: "instruction", actor } : { authority: "instruction" };
|
|
59
|
+
}
|
|
60
|
+
function isDefaultContextProvenance(provenance) {
|
|
61
|
+
return provenance.authority === "context" && !provenance.actor;
|
|
62
|
+
}
|
|
63
|
+
function legacyActorProvenance(actor) {
|
|
64
|
+
if (actor.teamId && actor.slackUserId && actor.platform) {
|
|
65
|
+
return instructionProvenance({
|
|
66
|
+
platform: "slack",
|
|
67
|
+
teamId: actor.teamId,
|
|
68
|
+
userId: actor.slackUserId,
|
|
69
|
+
...actor.slackUserName ? { userName: actor.slackUserName } : {},
|
|
70
|
+
...actor.fullName ? { fullName: actor.fullName } : {},
|
|
71
|
+
...actor.email ? { email: actor.email } : {}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return unattributedContextProvenance;
|
|
75
|
+
}
|
|
44
76
|
var piMessageEntrySchema = z2.object({
|
|
45
|
-
schemaVersion:
|
|
77
|
+
schemaVersion: schemaVersionSchema,
|
|
46
78
|
type: z2.literal("pi_message"),
|
|
47
79
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
48
80
|
message: piMessageSchema,
|
|
49
|
-
|
|
81
|
+
provenance: piMessageProvenanceSchema.optional(),
|
|
82
|
+
// Legacy v1 latest-wins actor, decoded into provenance on read.
|
|
83
|
+
actor: storedSlackActorSchema.optional()
|
|
50
84
|
});
|
|
51
85
|
var projectionResetEntrySchema = z2.object({
|
|
52
|
-
schemaVersion:
|
|
86
|
+
schemaVersion: schemaVersionSchema,
|
|
53
87
|
type: z2.literal("projection_reset"),
|
|
54
88
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
55
89
|
messages: z2.array(piMessageSchema),
|
|
56
|
-
|
|
90
|
+
provenance: z2.array(piMessageProvenanceSchema).optional(),
|
|
91
|
+
// Legacy v1 latest-wins actor; v1 resets carry no per-message provenance.
|
|
92
|
+
actor: storedSlackActorSchema.optional()
|
|
57
93
|
});
|
|
58
|
-
var
|
|
59
|
-
schemaVersion:
|
|
60
|
-
type: z2.literal("
|
|
94
|
+
var actorRecordedEntrySchema = z2.object({
|
|
95
|
+
schemaVersion: schemaVersionSchema,
|
|
96
|
+
type: z2.literal("actor_recorded"),
|
|
61
97
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
62
|
-
|
|
98
|
+
actor: storedSlackActorSchema
|
|
63
99
|
});
|
|
64
100
|
var mcpProviderConnectedEntrySchema = z2.object({
|
|
65
|
-
schemaVersion:
|
|
101
|
+
schemaVersion: schemaVersionSchema,
|
|
66
102
|
type: z2.literal("mcp_provider_connected"),
|
|
67
103
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
68
104
|
provider: z2.string().min(1)
|
|
@@ -72,13 +108,13 @@ var authorizationKindSchema = z2.union([
|
|
|
72
108
|
z2.literal("mcp")
|
|
73
109
|
]);
|
|
74
110
|
var authorizationRequestedEntrySchema = z2.object({
|
|
75
|
-
schemaVersion:
|
|
111
|
+
schemaVersion: schemaVersionSchema,
|
|
76
112
|
type: z2.literal("authorization_requested"),
|
|
77
113
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
78
114
|
createdAtMs: z2.number().int().nonnegative(),
|
|
79
115
|
kind: authorizationKindSchema,
|
|
80
116
|
provider: z2.string().min(1),
|
|
81
|
-
|
|
117
|
+
actorId: z2.string().min(1),
|
|
82
118
|
authorizationId: z2.string().min(1),
|
|
83
119
|
delivery: z2.union([
|
|
84
120
|
z2.literal("private_link_sent"),
|
|
@@ -86,13 +122,13 @@ var authorizationRequestedEntrySchema = z2.object({
|
|
|
86
122
|
])
|
|
87
123
|
});
|
|
88
124
|
var authorizationCompletedEntrySchema = z2.object({
|
|
89
|
-
schemaVersion:
|
|
125
|
+
schemaVersion: schemaVersionSchema,
|
|
90
126
|
type: z2.literal("authorization_completed"),
|
|
91
127
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
92
128
|
createdAtMs: z2.number().int().nonnegative(),
|
|
93
129
|
kind: authorizationKindSchema,
|
|
94
130
|
provider: z2.string().min(1),
|
|
95
|
-
|
|
131
|
+
actorId: z2.string().min(1),
|
|
96
132
|
authorizationId: z2.string().min(1)
|
|
97
133
|
});
|
|
98
134
|
var transcriptRefSchema = z2.object({
|
|
@@ -101,7 +137,7 @@ var transcriptRefSchema = z2.object({
|
|
|
101
137
|
key: z2.string().min(1)
|
|
102
138
|
});
|
|
103
139
|
var toolExecutionStartedEntrySchema = z2.object({
|
|
104
|
-
schemaVersion:
|
|
140
|
+
schemaVersion: schemaVersionSchema,
|
|
105
141
|
type: z2.literal("tool_execution_started"),
|
|
106
142
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
107
143
|
createdAtMs: z2.number().int().nonnegative(),
|
|
@@ -110,7 +146,7 @@ var toolExecutionStartedEntrySchema = z2.object({
|
|
|
110
146
|
args: z2.unknown().optional()
|
|
111
147
|
});
|
|
112
148
|
var subagentStartedEntrySchema = z2.object({
|
|
113
|
-
schemaVersion:
|
|
149
|
+
schemaVersion: schemaVersionSchema,
|
|
114
150
|
type: z2.literal("subagent_started"),
|
|
115
151
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
116
152
|
subagentInvocationId: z2.string().min(1),
|
|
@@ -123,7 +159,7 @@ var subagentStartedEntrySchema = z2.object({
|
|
|
123
159
|
createdAtMs: z2.number().int().nonnegative()
|
|
124
160
|
});
|
|
125
161
|
var subagentEndedEntrySchema = z2.object({
|
|
126
|
-
schemaVersion:
|
|
162
|
+
schemaVersion: schemaVersionSchema,
|
|
127
163
|
type: z2.literal("subagent_ended"),
|
|
128
164
|
sessionId: z2.string().min(1).default(INITIAL_SESSION_ID),
|
|
129
165
|
subagentInvocationId: z2.string().min(1),
|
|
@@ -140,7 +176,7 @@ var subagentEndedEntrySchema = z2.object({
|
|
|
140
176
|
var sessionLogEntrySchema = z2.discriminatedUnion("type", [
|
|
141
177
|
piMessageEntrySchema,
|
|
142
178
|
projectionResetEntrySchema,
|
|
143
|
-
|
|
179
|
+
actorRecordedEntrySchema,
|
|
144
180
|
mcpProviderConnectedEntrySchema,
|
|
145
181
|
authorizationRequestedEntrySchema,
|
|
146
182
|
authorizationCompletedEntrySchema,
|
|
@@ -159,6 +195,28 @@ function key(scope) {
|
|
|
159
195
|
function rawKey(scope) {
|
|
160
196
|
return [AGENT_SESSION_LOG_PREFIX, scope.conversationId].join(":");
|
|
161
197
|
}
|
|
198
|
+
function storedRecord(value) {
|
|
199
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
200
|
+
}
|
|
201
|
+
function migrateStoredEntry(value) {
|
|
202
|
+
const record = storedRecord(value);
|
|
203
|
+
if (!record) {
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
const migrated = { ...record };
|
|
207
|
+
if ("requester" in migrated && !("actor" in migrated)) {
|
|
208
|
+
migrated.actor = migrated.requester;
|
|
209
|
+
}
|
|
210
|
+
delete migrated.requester;
|
|
211
|
+
if (migrated.type === "requester_recorded") {
|
|
212
|
+
migrated.type = "actor_recorded";
|
|
213
|
+
}
|
|
214
|
+
if ("requesterId" in migrated && !("actorId" in migrated)) {
|
|
215
|
+
migrated.actorId = migrated.requesterId;
|
|
216
|
+
}
|
|
217
|
+
delete migrated.requesterId;
|
|
218
|
+
return migrated;
|
|
219
|
+
}
|
|
162
220
|
function normalizeMessageCount(value) {
|
|
163
221
|
return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
|
|
164
222
|
}
|
|
@@ -223,36 +281,29 @@ function projectionEntries(entries, sessionId) {
|
|
|
223
281
|
const currentId = resetIndex < 0 ? INITIAL_SESSION_ID : entrySessionId(entries[resetIndex]);
|
|
224
282
|
return entries.slice(startIndex).filter((entry) => entrySessionId(entry) === currentId);
|
|
225
283
|
}
|
|
226
|
-
function
|
|
227
|
-
for (let index = values.length - 1; index >= 0; index -= 1) {
|
|
228
|
-
if (predicate(values[index])) return index;
|
|
229
|
-
}
|
|
230
|
-
return -1;
|
|
231
|
-
}
|
|
232
|
-
function piEntry(message, sessionId, requester) {
|
|
284
|
+
function piEntry(message, sessionId, provenance) {
|
|
233
285
|
return {
|
|
234
286
|
schemaVersion: AGENT_SESSION_LOG_SCHEMA_VERSION,
|
|
235
287
|
type: "pi_message",
|
|
236
288
|
sessionId,
|
|
237
289
|
message,
|
|
238
|
-
|
|
290
|
+
// Ambient context is the decode default, so only attributed/instruction
|
|
291
|
+
// provenance needs to be persisted on the entry.
|
|
292
|
+
...provenance && !isDefaultContextProvenance(provenance) ? { provenance } : {}
|
|
239
293
|
};
|
|
240
294
|
}
|
|
241
|
-
function resetEntry(messages, sessionId,
|
|
295
|
+
function resetEntry(messages, sessionId, provenance) {
|
|
296
|
+
if (provenance.length !== messages.length) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
"projection_reset provenance must align one-to-one with messages"
|
|
299
|
+
);
|
|
300
|
+
}
|
|
242
301
|
return {
|
|
243
302
|
schemaVersion: AGENT_SESSION_LOG_SCHEMA_VERSION,
|
|
244
303
|
type: "projection_reset",
|
|
245
304
|
sessionId,
|
|
246
305
|
messages,
|
|
247
|
-
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function requesterRecordedEntry(requester, sessionId) {
|
|
251
|
-
return {
|
|
252
|
-
schemaVersion: AGENT_SESSION_LOG_SCHEMA_VERSION,
|
|
253
|
-
type: "requester_recorded",
|
|
254
|
-
sessionId,
|
|
255
|
-
requester
|
|
306
|
+
provenance
|
|
256
307
|
};
|
|
257
308
|
}
|
|
258
309
|
function mcpProviderConnectedEntry(provider, sessionId) {
|
|
@@ -284,7 +335,7 @@ function authorizationRequestedEntry(args) {
|
|
|
284
335
|
createdAtMs: args.createdAtMs,
|
|
285
336
|
kind: args.kind,
|
|
286
337
|
provider: args.provider,
|
|
287
|
-
|
|
338
|
+
actorId: args.actorId,
|
|
288
339
|
authorizationId: args.authorizationId,
|
|
289
340
|
delivery: args.delivery
|
|
290
341
|
};
|
|
@@ -297,7 +348,7 @@ function authorizationCompletedEntry(args) {
|
|
|
297
348
|
createdAtMs: args.createdAtMs,
|
|
298
349
|
kind: args.kind,
|
|
299
350
|
provider: args.provider,
|
|
300
|
-
|
|
351
|
+
actorId: args.actorId,
|
|
301
352
|
authorizationId: args.authorizationId
|
|
302
353
|
};
|
|
303
354
|
}
|
|
@@ -344,43 +395,70 @@ function decode(value) {
|
|
|
344
395
|
if (typeof value === "string") {
|
|
345
396
|
return decode(JSON.parse(value));
|
|
346
397
|
}
|
|
347
|
-
const parsed = sessionLogEntrySchema.safeParse(value);
|
|
398
|
+
const parsed = sessionLogEntrySchema.safeParse(migrateStoredEntry(value));
|
|
348
399
|
if (parsed.success) {
|
|
349
400
|
return parsed.data;
|
|
350
401
|
}
|
|
351
402
|
return piEntry(piMessageSchema.parse(value), INITIAL_SESSION_ID);
|
|
352
403
|
}
|
|
404
|
+
function piEntryProvenance(entry) {
|
|
405
|
+
if (entry.provenance) {
|
|
406
|
+
return entry.provenance;
|
|
407
|
+
}
|
|
408
|
+
if (entry.actor) {
|
|
409
|
+
return legacyActorProvenance(entry.actor);
|
|
410
|
+
}
|
|
411
|
+
return unattributedContextProvenance;
|
|
412
|
+
}
|
|
353
413
|
function project(entries, sessionId) {
|
|
354
414
|
let messages = [];
|
|
355
|
-
let
|
|
415
|
+
let provenance = [];
|
|
356
416
|
for (const entry of projectionEntries(entries, sessionId)) {
|
|
357
417
|
if (entry.type === "pi_message") {
|
|
358
418
|
messages.push(entry.message);
|
|
359
|
-
|
|
360
|
-
requester = entry.requester;
|
|
361
|
-
}
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
if (entry.type === "requester_recorded") {
|
|
365
|
-
requester = entry.requester;
|
|
419
|
+
provenance.push(piEntryProvenance(entry));
|
|
366
420
|
continue;
|
|
367
421
|
}
|
|
368
422
|
if (entry.type === "authorization_completed") {
|
|
369
423
|
messages.push(authorizationObservationMessage(entry));
|
|
424
|
+
provenance.push(unattributedContextProvenance);
|
|
370
425
|
continue;
|
|
371
426
|
}
|
|
372
427
|
if (entry.type === "projection_reset") {
|
|
373
|
-
|
|
374
|
-
if (entry.
|
|
375
|
-
|
|
428
|
+
const resetProvenance = entry.provenance ?? entry.messages.map(() => unattributedContextProvenance);
|
|
429
|
+
if (resetProvenance.length !== entry.messages.length) {
|
|
430
|
+
throw new Error(
|
|
431
|
+
"projection_reset provenance must align one-to-one with messages"
|
|
432
|
+
);
|
|
376
433
|
}
|
|
434
|
+
messages = [...entry.messages];
|
|
435
|
+
provenance = [...resetProvenance];
|
|
377
436
|
continue;
|
|
378
437
|
}
|
|
379
438
|
}
|
|
380
|
-
return { messages,
|
|
439
|
+
return { messages, provenance };
|
|
381
440
|
}
|
|
382
|
-
function
|
|
383
|
-
|
|
441
|
+
function actorIdentityKey(actor) {
|
|
442
|
+
if (actor.platform === "system") {
|
|
443
|
+
return `system ${actor.name}`;
|
|
444
|
+
}
|
|
445
|
+
return actor.platform === "slack" ? `slack\0${actor.teamId}\0${actor.userId}` : `${actor.platform}\0${actor.userId}`;
|
|
446
|
+
}
|
|
447
|
+
function instructionActors(provenance) {
|
|
448
|
+
const seen = /* @__PURE__ */ new Set();
|
|
449
|
+
const actors = [];
|
|
450
|
+
for (const entry of provenance) {
|
|
451
|
+
if (entry.authority !== "instruction" || !entry.actor) {
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
const identity = actorIdentityKey(entry.actor);
|
|
455
|
+
if (seen.has(identity)) {
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
seen.add(identity);
|
|
459
|
+
actors.push(entry.actor);
|
|
460
|
+
}
|
|
461
|
+
return actors;
|
|
384
462
|
}
|
|
385
463
|
function connectedMcpProviders(entries, sessionId) {
|
|
386
464
|
const providers = /* @__PURE__ */ new Set();
|
|
@@ -391,33 +469,65 @@ function connectedMcpProviders(entries, sessionId) {
|
|
|
391
469
|
}
|
|
392
470
|
return [...providers].sort((left, right) => left.localeCompare(right));
|
|
393
471
|
}
|
|
394
|
-
function
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
472
|
+
function isUserMessage(message) {
|
|
473
|
+
return message.role === "user";
|
|
474
|
+
}
|
|
475
|
+
function resolveCommitProvenance(args) {
|
|
476
|
+
if (args.explicitProvenance) {
|
|
477
|
+
if (args.explicitProvenance.length !== args.nextMessages.length) {
|
|
478
|
+
throw new Error("commit provenance must align one-to-one with messages");
|
|
479
|
+
}
|
|
480
|
+
return args.explicitProvenance;
|
|
481
|
+
}
|
|
482
|
+
const matchingPrefix = countMatchingPrefix(
|
|
483
|
+
args.existing.messages,
|
|
484
|
+
args.nextMessages
|
|
485
|
+
);
|
|
486
|
+
const provenance = args.nextMessages.map(
|
|
487
|
+
(_, index) => index < matchingPrefix ? args.existing.provenance[index] ?? unattributedContextProvenance : unattributedContextProvenance
|
|
488
|
+
);
|
|
489
|
+
if (args.newMessageProvenance) {
|
|
490
|
+
for (let index = args.nextMessages.length - 1; index >= matchingPrefix; index -= 1) {
|
|
491
|
+
if (isUserMessage(args.nextMessages[index])) {
|
|
492
|
+
provenance[index] = args.newMessageProvenance;
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
403
495
|
}
|
|
404
|
-
|
|
496
|
+
}
|
|
497
|
+
if (args.trailingMessageProvenance) {
|
|
498
|
+
if (args.trailingMessageProvenance.length > provenance.length) {
|
|
499
|
+
throw new Error(
|
|
500
|
+
"trailing commit provenance cannot exceed committed messages"
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
const newMessageCount = args.nextMessages.length - matchingPrefix;
|
|
504
|
+
if (args.trailingMessageProvenance.length > newMessageCount) {
|
|
505
|
+
throw new Error(
|
|
506
|
+
"trailing commit provenance must align to newly committed messages"
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
const start = provenance.length - args.trailingMessageProvenance.length;
|
|
510
|
+
args.trailingMessageProvenance.forEach((entry, offset) => {
|
|
511
|
+
provenance[start + offset] = entry;
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
return provenance;
|
|
515
|
+
}
|
|
516
|
+
function commitEntries(existing, nextMessages, nextProvenance, sessionId, entries) {
|
|
517
|
+
const matchingPrefix = countMatchingPrefix(existing.messages, nextMessages);
|
|
518
|
+
if (matchingPrefix === existing.messages.length) {
|
|
519
|
+
const newMessages = nextMessages.slice(matchingPrefix);
|
|
520
|
+
const newProvenance = nextProvenance.slice(matchingPrefix);
|
|
405
521
|
return {
|
|
406
522
|
entries: newMessages.map(
|
|
407
|
-
(message, index) => piEntry(
|
|
408
|
-
message,
|
|
409
|
-
sessionId,
|
|
410
|
-
index === requesterIndex ? requester : void 0
|
|
411
|
-
)
|
|
523
|
+
(message, index) => piEntry(message, sessionId, newProvenance[index])
|
|
412
524
|
),
|
|
413
525
|
sessionId
|
|
414
526
|
};
|
|
415
527
|
}
|
|
416
528
|
const resetSessionId = nextSessionId(entries);
|
|
417
529
|
return {
|
|
418
|
-
entries: [
|
|
419
|
-
resetEntry(nextMessages, resetSessionId, requester ?? existingRequester)
|
|
420
|
-
],
|
|
530
|
+
entries: [resetEntry(nextMessages, resetSessionId, nextProvenance)],
|
|
421
531
|
sessionId: resetSessionId
|
|
422
532
|
};
|
|
423
533
|
}
|
|
@@ -485,24 +595,28 @@ async function defaultStore() {
|
|
|
485
595
|
}
|
|
486
596
|
async function loadEntries(args) {
|
|
487
597
|
const store = args.store ?? await defaultStore();
|
|
488
|
-
return await store.read(args);
|
|
598
|
+
return (await store.read(args)).map(decode);
|
|
489
599
|
}
|
|
490
600
|
async function loadActivityEntries(args) {
|
|
491
601
|
const entries = await loadEntries(args);
|
|
492
602
|
return projectionEntries(entries, args.sessionId).filter(isActivityEntry);
|
|
493
603
|
}
|
|
494
|
-
async function
|
|
604
|
+
async function loadMessagesWithProvenance(args) {
|
|
495
605
|
const messageCount = normalizeMessageCount(args.messageCount);
|
|
496
606
|
if (messageCount === 0) {
|
|
497
|
-
return [];
|
|
607
|
+
return { messages: [], provenance: [] };
|
|
498
608
|
}
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
609
|
+
const projection = project(await loadEntries(args), args.sessionId);
|
|
610
|
+
return projection.messages.length >= messageCount ? {
|
|
611
|
+
messages: projection.messages.slice(0, messageCount),
|
|
612
|
+
provenance: projection.provenance.slice(0, messageCount)
|
|
613
|
+
} : void 0;
|
|
502
614
|
}
|
|
503
615
|
async function loadProjection(args) {
|
|
504
|
-
|
|
505
|
-
|
|
616
|
+
return project(await loadEntries(args), args.sessionId).messages;
|
|
617
|
+
}
|
|
618
|
+
async function loadProjectionWithProvenance(args) {
|
|
619
|
+
return project(await loadEntries(args), args.sessionId);
|
|
506
620
|
}
|
|
507
621
|
async function loadConnectedMcpProviders(args) {
|
|
508
622
|
return connectedMcpProviders(await loadEntries(args));
|
|
@@ -537,7 +651,7 @@ async function recordAuthorizationRequested(args) {
|
|
|
537
651
|
kind: args.kind,
|
|
538
652
|
sessionId,
|
|
539
653
|
provider: args.provider,
|
|
540
|
-
|
|
654
|
+
actorId: args.actorId,
|
|
541
655
|
authorizationId: args.authorizationId,
|
|
542
656
|
delivery: args.delivery
|
|
543
657
|
})
|
|
@@ -562,7 +676,7 @@ async function recordAuthorizationCompleted(args) {
|
|
|
562
676
|
kind: args.kind,
|
|
563
677
|
sessionId,
|
|
564
678
|
provider: args.provider,
|
|
565
|
-
|
|
679
|
+
actorId: args.actorId,
|
|
566
680
|
authorizationId: args.authorizationId
|
|
567
681
|
})
|
|
568
682
|
],
|
|
@@ -634,13 +748,19 @@ async function commitMessages(args) {
|
|
|
634
748
|
const entries = await store.read(args);
|
|
635
749
|
const existingProjection = project(entries);
|
|
636
750
|
const currentId = currentSessionId(entries);
|
|
751
|
+
const nextProvenance = resolveCommitProvenance({
|
|
752
|
+
existing: existingProjection,
|
|
753
|
+
nextMessages: args.messages,
|
|
754
|
+
...args.provenance ? { explicitProvenance: args.provenance } : {},
|
|
755
|
+
...args.trailingMessageProvenance ? { trailingMessageProvenance: args.trailingMessageProvenance } : {},
|
|
756
|
+
...args.newMessageProvenance ? { newMessageProvenance: args.newMessageProvenance } : {}
|
|
757
|
+
});
|
|
637
758
|
const commit = commitEntries(
|
|
638
|
-
existingProjection
|
|
759
|
+
existingProjection,
|
|
639
760
|
args.messages,
|
|
761
|
+
nextProvenance,
|
|
640
762
|
currentId,
|
|
641
|
-
entries
|
|
642
|
-
existingProjection.requester,
|
|
643
|
-
args.requester
|
|
763
|
+
entries
|
|
644
764
|
);
|
|
645
765
|
await store.append({
|
|
646
766
|
scope: args,
|
|
@@ -648,13 +768,26 @@ async function commitMessages(args) {
|
|
|
648
768
|
ttlMs: args.ttlMs
|
|
649
769
|
});
|
|
650
770
|
return {
|
|
651
|
-
sessionId: commit.sessionId
|
|
771
|
+
sessionId: commit.sessionId,
|
|
772
|
+
provenance: nextProvenance
|
|
652
773
|
};
|
|
653
774
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
775
|
+
function instructionProvenanceFor(actor) {
|
|
776
|
+
return instructionProvenance(actor);
|
|
777
|
+
}
|
|
778
|
+
var contextProvenance = unattributedContextProvenance;
|
|
779
|
+
function parseStoredMessageProvenance(value, expectedLength) {
|
|
780
|
+
if (value === void 0) {
|
|
781
|
+
return Array.from(
|
|
782
|
+
{ length: expectedLength },
|
|
783
|
+
() => unattributedContextProvenance
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
const parsed = z2.array(piMessageProvenanceSchema).safeParse(value);
|
|
787
|
+
if (!parsed.success || parsed.data.length !== expectedLength) {
|
|
788
|
+
return void 0;
|
|
789
|
+
}
|
|
790
|
+
return parsed.data;
|
|
658
791
|
}
|
|
659
792
|
|
|
660
793
|
// src/chat/state/turn-session.ts
|
|
@@ -733,8 +866,8 @@ function parseSource(value) {
|
|
|
733
866
|
const result = sourceSchema.safeParse(value);
|
|
734
867
|
return result.success ? result.data : void 0;
|
|
735
868
|
}
|
|
736
|
-
function
|
|
737
|
-
return
|
|
869
|
+
function sessionLogActor(actor) {
|
|
870
|
+
return actor?.platform === "slack" ? toStoredSlackActor(actor) : void 0;
|
|
738
871
|
}
|
|
739
872
|
function parseAgentTurnSessionFields(parsed) {
|
|
740
873
|
const status = parseAgentTurnSessionStatus(parsed);
|
|
@@ -751,7 +884,8 @@ function parseAgentTurnSessionFields(parsed) {
|
|
|
751
884
|
const cumulativeUsage = parseAgentTurnUsage(parsed.cumulativeUsage);
|
|
752
885
|
const lastProgressAtMs = toFiniteNonNegativeNumber(parsed.lastProgressAtMs);
|
|
753
886
|
const logSessionId = typeof parsed.logSessionId === "string" ? parsed.logSessionId : void 0;
|
|
754
|
-
const
|
|
887
|
+
const actorValue = parsed.actor !== void 0 ? parsed.actor : parsed.requester;
|
|
888
|
+
const actor = actorValue === void 0 ? void 0 : parseActor(actorValue);
|
|
755
889
|
const startedAtMs = toFiniteNonNegativeNumber(parsed.startedAtMs);
|
|
756
890
|
const surface = parseAgentTurnSurface(parsed.surface);
|
|
757
891
|
const turnStartMessageIndex = toNonNegativeInteger(
|
|
@@ -759,7 +893,7 @@ function parseAgentTurnSessionFields(parsed) {
|
|
|
759
893
|
);
|
|
760
894
|
const destination = parsed.destination === void 0 ? void 0 : parseDestination(parsed.destination);
|
|
761
895
|
const source = parsed.source === void 0 ? void 0 : parseSource(parsed.source);
|
|
762
|
-
if (typeof conversationId !== "string" || typeof sessionId !== "string" || sliceId === void 0 || version === void 0 || updatedAtMs === void 0 || parsed.destination !== void 0 && !destination || parsed.source !== void 0 && !source ||
|
|
896
|
+
if (typeof conversationId !== "string" || typeof sessionId !== "string" || sliceId === void 0 || version === void 0 || updatedAtMs === void 0 || parsed.destination !== void 0 && !destination || parsed.source !== void 0 && !source || actorValue !== void 0 && !actor) {
|
|
763
897
|
return void 0;
|
|
764
898
|
}
|
|
765
899
|
return {
|
|
@@ -777,7 +911,7 @@ function parseAgentTurnSessionFields(parsed) {
|
|
|
777
911
|
...cumulativeUsage ? { cumulativeUsage } : {},
|
|
778
912
|
...destination ? { destination } : {},
|
|
779
913
|
...source ? { source } : {},
|
|
780
|
-
...
|
|
914
|
+
...actor ? { actor } : {},
|
|
781
915
|
...Array.isArray(parsed.loadedSkillNames) ? {
|
|
782
916
|
loadedSkillNames: parsed.loadedSkillNames.filter(
|
|
783
917
|
(value) => typeof value === "string"
|
|
@@ -803,9 +937,17 @@ function parseAgentTurnSessionRecord(value) {
|
|
|
803
937
|
if (!fields || committedMessageCount === void 0) {
|
|
804
938
|
return void 0;
|
|
805
939
|
}
|
|
940
|
+
const committedMessageProvenance = parseStoredMessageProvenance(
|
|
941
|
+
parsed.committedMessageProvenance,
|
|
942
|
+
committedMessageCount
|
|
943
|
+
);
|
|
944
|
+
if (!committedMessageProvenance) {
|
|
945
|
+
return void 0;
|
|
946
|
+
}
|
|
806
947
|
return {
|
|
807
948
|
...fields,
|
|
808
|
-
committedMessageCount
|
|
949
|
+
committedMessageCount,
|
|
950
|
+
committedMessageProvenance
|
|
809
951
|
};
|
|
810
952
|
}
|
|
811
953
|
function parseAgentTurnSessionSummary(value) {
|
|
@@ -849,7 +991,7 @@ async function recordConversationActivityMetadata(args) {
|
|
|
849
991
|
conversationId: args.summary.conversationId,
|
|
850
992
|
destination: args.summary.destination,
|
|
851
993
|
nowMs: args.nowMs,
|
|
852
|
-
|
|
994
|
+
actor: sessionLogActor(args.summary.actor),
|
|
853
995
|
source,
|
|
854
996
|
visibility: args.destinationVisibility
|
|
855
997
|
});
|
|
@@ -860,7 +1002,7 @@ async function recordConversationActivityMetadata(args) {
|
|
|
860
1002
|
destination: args.summary.destination,
|
|
861
1003
|
execution: conversationExecutionFromSummary(args.summary),
|
|
862
1004
|
lastActivityAtMs: args.summary.updatedAtMs,
|
|
863
|
-
|
|
1005
|
+
actor: sessionLogActor(args.summary.actor),
|
|
864
1006
|
source,
|
|
865
1007
|
updatedAtMs: args.nowMs,
|
|
866
1008
|
visibility: args.destinationVisibility
|
|
@@ -876,22 +1018,25 @@ async function recordConversationActivityMetadata(args) {
|
|
|
876
1018
|
);
|
|
877
1019
|
}
|
|
878
1020
|
}
|
|
879
|
-
function
|
|
1021
|
+
function materializePiProjection(committedMessageCount, includeProjectionTail, sessionMessages, sessionProjection) {
|
|
880
1022
|
if (committedMessageCount === 0) {
|
|
881
1023
|
return sessionProjection;
|
|
882
1024
|
}
|
|
883
|
-
if (includeProjectionTail && sessionProjection.length >= committedMessageCount) {
|
|
1025
|
+
if (includeProjectionTail && sessionProjection.messages.length >= committedMessageCount) {
|
|
884
1026
|
return sessionProjection;
|
|
885
1027
|
}
|
|
886
1028
|
if (sessionMessages) {
|
|
887
1029
|
return sessionMessages;
|
|
888
1030
|
}
|
|
889
|
-
if (sessionProjection.length >= committedMessageCount) {
|
|
890
|
-
return
|
|
1031
|
+
if (sessionProjection.messages.length >= committedMessageCount) {
|
|
1032
|
+
return {
|
|
1033
|
+
messages: sessionProjection.messages.slice(0, committedMessageCount),
|
|
1034
|
+
provenance: sessionProjection.provenance.slice(0, committedMessageCount)
|
|
1035
|
+
};
|
|
891
1036
|
}
|
|
892
1037
|
return void 0;
|
|
893
1038
|
}
|
|
894
|
-
function materializeAgentTurnSessionRecord(stored,
|
|
1039
|
+
function materializeAgentTurnSessionRecord(stored, piProjection) {
|
|
895
1040
|
return {
|
|
896
1041
|
version: stored.version,
|
|
897
1042
|
...stored.channelName ? { channelName: stored.channelName } : {},
|
|
@@ -902,7 +1047,9 @@ function materializeAgentTurnSessionRecord(stored, piMessages) {
|
|
|
902
1047
|
startedAtMs: stored.startedAtMs,
|
|
903
1048
|
lastProgressAtMs: stored.lastProgressAtMs,
|
|
904
1049
|
updatedAtMs: stored.updatedAtMs,
|
|
905
|
-
piMessages,
|
|
1050
|
+
piMessages: piProjection.messages,
|
|
1051
|
+
piMessageProvenance: piProjection.provenance,
|
|
1052
|
+
actors: instructionActors(piProjection.provenance),
|
|
906
1053
|
cumulativeDurationMs: stored.cumulativeDurationMs,
|
|
907
1054
|
...stored.destination ? { destination: stored.destination } : {},
|
|
908
1055
|
...stored.source ? { source: stored.source } : {},
|
|
@@ -910,7 +1057,7 @@ function materializeAgentTurnSessionRecord(stored, piMessages) {
|
|
|
910
1057
|
...stored.resumeReason ? { resumeReason: stored.resumeReason } : {},
|
|
911
1058
|
...stored.errorMessage ? { errorMessage: stored.errorMessage } : {},
|
|
912
1059
|
...stored.loadedSkillNames ? { loadedSkillNames: stored.loadedSkillNames } : {},
|
|
913
|
-
...stored.
|
|
1060
|
+
...stored.actor ? { actor: stored.actor } : {},
|
|
914
1061
|
...stored.resumedFromSliceId !== void 0 ? { resumedFromSliceId: stored.resumedFromSliceId } : {},
|
|
915
1062
|
...stored.surface ? { surface: stored.surface } : {},
|
|
916
1063
|
...stored.traceId ? { traceId: stored.traceId } : {},
|
|
@@ -933,25 +1080,25 @@ async function getAgentTurnSessionRecord(conversationId, sessionId) {
|
|
|
933
1080
|
if (!parsed) {
|
|
934
1081
|
return void 0;
|
|
935
1082
|
}
|
|
936
|
-
const sessionMessages = await
|
|
1083
|
+
const sessionMessages = await loadMessagesWithProvenance({
|
|
937
1084
|
conversationId,
|
|
938
1085
|
messageCount: parsed.committedMessageCount,
|
|
939
1086
|
...parsed.logSessionId ? { sessionId: parsed.logSessionId } : {}
|
|
940
1087
|
});
|
|
941
|
-
const sessionProjection = await
|
|
1088
|
+
const sessionProjection = await loadProjectionWithProvenance({
|
|
942
1089
|
conversationId,
|
|
943
1090
|
...parsed.logSessionId ? { sessionId: parsed.logSessionId } : {}
|
|
944
1091
|
});
|
|
945
|
-
const
|
|
1092
|
+
const piProjection = materializePiProjection(
|
|
946
1093
|
parsed.committedMessageCount,
|
|
947
1094
|
parsed.state === "running" || parsed.state === "awaiting_resume",
|
|
948
1095
|
sessionMessages,
|
|
949
1096
|
sessionProjection
|
|
950
1097
|
);
|
|
951
|
-
if (!
|
|
1098
|
+
if (!piProjection) {
|
|
952
1099
|
return void 0;
|
|
953
1100
|
}
|
|
954
|
-
return materializeAgentTurnSessionRecord(parsed,
|
|
1101
|
+
return materializeAgentTurnSessionRecord(parsed, piProjection);
|
|
955
1102
|
}
|
|
956
1103
|
function buildStoredRecord(args) {
|
|
957
1104
|
const nowMs = Date.now();
|
|
@@ -966,12 +1113,13 @@ function buildStoredRecord(args) {
|
|
|
966
1113
|
lastProgressAtMs: args.lastProgressAtMs ?? nowMs,
|
|
967
1114
|
updatedAtMs: nowMs,
|
|
968
1115
|
committedMessageCount: args.committedMessageCount,
|
|
1116
|
+
committedMessageProvenance: args.committedMessageProvenance,
|
|
969
1117
|
...args.logSessionId ? { logSessionId: args.logSessionId } : {},
|
|
970
1118
|
cumulativeDurationMs: args.cumulativeDurationMs,
|
|
971
1119
|
...args.cumulativeUsage ? { cumulativeUsage: args.cumulativeUsage } : {},
|
|
972
1120
|
...args.destination ? { destination: args.destination } : {},
|
|
973
1121
|
...args.source ? { source: args.source } : {},
|
|
974
|
-
...args.
|
|
1122
|
+
...args.actor ? { actor: args.actor } : {},
|
|
975
1123
|
...Array.isArray(args.loadedSkillNames) ? {
|
|
976
1124
|
loadedSkillNames: args.loadedSkillNames.filter(
|
|
977
1125
|
(value) => typeof value === "string"
|
|
@@ -995,6 +1143,7 @@ async function setStoredRecord(args) {
|
|
|
995
1143
|
);
|
|
996
1144
|
const {
|
|
997
1145
|
committedMessageCount: _committedMessageCount,
|
|
1146
|
+
committedMessageProvenance: _committedMessageProvenance,
|
|
998
1147
|
errorMessage: _errorMessage,
|
|
999
1148
|
logSessionId: _logSessionId,
|
|
1000
1149
|
turnStartMessageIndex: _turnStartMessageIndex,
|
|
@@ -1007,7 +1156,10 @@ async function setStoredRecord(args) {
|
|
|
1007
1156
|
nowMs: Date.now(),
|
|
1008
1157
|
summary
|
|
1009
1158
|
});
|
|
1010
|
-
return materializeAgentTurnSessionRecord(args.record,
|
|
1159
|
+
return materializeAgentTurnSessionRecord(args.record, {
|
|
1160
|
+
messages: [...args.piMessages],
|
|
1161
|
+
provenance: [...args.piMessageProvenance]
|
|
1162
|
+
});
|
|
1011
1163
|
}
|
|
1012
1164
|
async function updateAgentTurnSessionState(args) {
|
|
1013
1165
|
const parsed = await getStoredAgentTurnSessionRecord(
|
|
@@ -1019,6 +1171,7 @@ async function updateAgentTurnSessionState(args) {
|
|
|
1019
1171
|
}
|
|
1020
1172
|
return await setStoredRecord({
|
|
1021
1173
|
piMessages: args.existing.piMessages,
|
|
1174
|
+
piMessageProvenance: args.existing.piMessageProvenance,
|
|
1022
1175
|
ttlMs: AGENT_TURN_SESSION_TTL_MS,
|
|
1023
1176
|
record: buildStoredRecord({
|
|
1024
1177
|
conversationId: args.existing.conversationId,
|
|
@@ -1026,6 +1179,7 @@ async function updateAgentTurnSessionState(args) {
|
|
|
1026
1179
|
sliceId: args.existing.sliceId,
|
|
1027
1180
|
state: args.state,
|
|
1028
1181
|
committedMessageCount: parsed.committedMessageCount,
|
|
1182
|
+
committedMessageProvenance: parsed.committedMessageProvenance,
|
|
1029
1183
|
...parsed.channelName ? { channelName: parsed.channelName } : {},
|
|
1030
1184
|
startedAtMs: parsed.startedAtMs,
|
|
1031
1185
|
lastProgressAtMs: parsed.lastProgressAtMs,
|
|
@@ -1036,7 +1190,7 @@ async function updateAgentTurnSessionState(args) {
|
|
|
1036
1190
|
...args.existing.destination ? { destination: args.existing.destination } : {},
|
|
1037
1191
|
...args.existing.source ? { source: args.existing.source } : {},
|
|
1038
1192
|
...args.existing.loadedSkillNames ? { loadedSkillNames: args.existing.loadedSkillNames } : {},
|
|
1039
|
-
...args.existing.
|
|
1193
|
+
...args.existing.actor ? { actor: args.existing.actor } : {},
|
|
1040
1194
|
...args.existing.resumeReason ? { resumeReason: args.existing.resumeReason } : {},
|
|
1041
1195
|
...args.existing.resumedFromSliceId !== void 0 ? { resumedFromSliceId: args.existing.resumedFromSliceId } : {},
|
|
1042
1196
|
...args.existing.surface ? { surface: args.existing.surface } : {},
|
|
@@ -1052,18 +1206,22 @@ async function upsertAgentTurnSessionRecord(args) {
|
|
|
1052
1206
|
args.sessionId
|
|
1053
1207
|
);
|
|
1054
1208
|
const ttlMs = Math.max(1, args.ttlMs ?? AGENT_TURN_SESSION_TTL_MS);
|
|
1209
|
+
const instructionActor = args.actor ?? existingRecord?.actor;
|
|
1055
1210
|
const commit = await commitMessages({
|
|
1056
1211
|
conversationId: args.conversationId,
|
|
1057
1212
|
messages: args.piMessages,
|
|
1058
|
-
|
|
1213
|
+
...instructionActor ? { newMessageProvenance: instructionProvenanceFor(instructionActor) } : {},
|
|
1214
|
+
...args.trailingMessageProvenance ? { trailingMessageProvenance: args.trailingMessageProvenance } : {},
|
|
1059
1215
|
ttlMs
|
|
1060
1216
|
});
|
|
1061
1217
|
return await setStoredRecord({
|
|
1062
1218
|
conversationStore: args.conversationStore,
|
|
1063
1219
|
destinationVisibility: args.destinationVisibility,
|
|
1064
1220
|
piMessages: args.piMessages,
|
|
1221
|
+
piMessageProvenance: commit.provenance,
|
|
1065
1222
|
ttlMs,
|
|
1066
1223
|
record: buildStoredRecord({
|
|
1224
|
+
committedMessageProvenance: commit.provenance,
|
|
1067
1225
|
...args.channelName ?? existingRecord?.channelName ? { channelName: args.channelName ?? existingRecord?.channelName } : {},
|
|
1068
1226
|
conversationId: args.conversationId,
|
|
1069
1227
|
sessionId: args.sessionId,
|
|
@@ -1079,7 +1237,7 @@ async function upsertAgentTurnSessionRecord(args) {
|
|
|
1079
1237
|
...args.destination ?? existingRecord?.destination ? { destination: args.destination ?? existingRecord?.destination } : {},
|
|
1080
1238
|
...args.source ?? existingRecord?.source ? { source: args.source ?? existingRecord?.source } : {},
|
|
1081
1239
|
...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
|
|
1082
|
-
...args.
|
|
1240
|
+
...args.actor ?? existingRecord?.actor ? { actor: args.actor ?? existingRecord?.actor } : {},
|
|
1083
1241
|
...args.resumeReason ? { resumeReason: args.resumeReason } : {},
|
|
1084
1242
|
...args.errorMessage ? { errorMessage: args.errorMessage } : {},
|
|
1085
1243
|
...args.resumedFromSliceId !== void 0 ? { resumedFromSliceId: args.resumedFromSliceId } : {},
|
|
@@ -1112,7 +1270,7 @@ async function recordAgentTurnSessionSummary(args) {
|
|
|
1112
1270
|
...args.cumulativeUsage ?? existing?.cumulativeUsage ? { cumulativeUsage: args.cumulativeUsage ?? existing?.cumulativeUsage } : {},
|
|
1113
1271
|
...args.destination ?? existing?.destination ? { destination: args.destination ?? existing?.destination } : {},
|
|
1114
1272
|
...args.source ?? existing?.source ? { source: args.source ?? existing?.source } : {},
|
|
1115
|
-
...args.
|
|
1273
|
+
...args.actor ?? existing?.actor ? { actor: args.actor ?? existing?.actor } : {},
|
|
1116
1274
|
...Array.isArray(args.loadedSkillNames) ? {
|
|
1117
1275
|
loadedSkillNames: args.loadedSkillNames.filter(
|
|
1118
1276
|
(value) => typeof value === "string"
|
|
@@ -1195,8 +1353,10 @@ function getInterruptionMarker() {
|
|
|
1195
1353
|
|
|
1196
1354
|
export {
|
|
1197
1355
|
piContentMessageSchema,
|
|
1356
|
+
instructionActors,
|
|
1198
1357
|
loadActivityEntries,
|
|
1199
1358
|
loadProjection,
|
|
1359
|
+
loadProjectionWithProvenance,
|
|
1200
1360
|
loadConnectedMcpProviders,
|
|
1201
1361
|
recordMcpProviderConnected,
|
|
1202
1362
|
recordAuthorizationRequested,
|
|
@@ -1205,7 +1365,8 @@ export {
|
|
|
1205
1365
|
recordSubagentStarted,
|
|
1206
1366
|
recordSubagentEnded,
|
|
1207
1367
|
commitMessages,
|
|
1208
|
-
|
|
1368
|
+
instructionProvenanceFor,
|
|
1369
|
+
contextProvenance,
|
|
1209
1370
|
getAgentTurnSessionRecord,
|
|
1210
1371
|
upsertAgentTurnSessionRecord,
|
|
1211
1372
|
recordAgentTurnSessionSummary,
|