@myagentroam/agent 0.14.9 → 0.14.11
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/runtime/context/projection.js +3 -9
- package/dist/sdk/execution-compact-commit.d.ts +1 -1
- package/dist/sdk/execution-compact-commit.js +15 -1
- package/dist/sdk/execution-compaction.d.ts +1 -1
- package/dist/sdk/execution-compaction.js +1 -1
- package/dist/sdk/execution-model-lifecycle.d.ts +1 -1
- package/dist/sdk/execution-model-lifecycle.js +1 -1
- package/dist/sdk/session-execution-factory.d.ts +1 -1
- package/dist/sdk/session-execution-factory.js +9 -3
- package/dist/sdk/session-runtime.d.ts +3 -2
- package/dist/sdk/session-runtime.js +20 -10
- package/dist/session/mcp-discovery.d.ts +9 -0
- package/dist/session/mcp-discovery.js +65 -0
- package/dist/session/model-request.d.ts +2 -4
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { appliedInputRecord } from '../../session/deferred-input.js';
|
|
|
3
3
|
import { inputMetadataFromRecord } from '../../session/record-projection.js';
|
|
4
4
|
import { parseModelImages } from '../../model/image.js';
|
|
5
5
|
import { contextGcTargetKey, latestValidContextGcCheckpoint } from '../../session/context-gc-checkpoint.js';
|
|
6
|
+
import { parseMcpDiscoveryReceipt } from '../../session/mcp-discovery.js';
|
|
6
7
|
import { HISTORY_INPUT_LIMITS } from '../../session/history-input-limits.js';
|
|
7
8
|
import { replaceReadContextItems } from '../../prompts/read-context.js';
|
|
8
9
|
import { parseCodeCalls, parseObservations, renderObservationResult } from '../../session/code-observation-projection.js';
|
|
@@ -180,7 +181,7 @@ export function restoreModelContext(payload, providerModelId) {
|
|
|
180
181
|
return undefined;
|
|
181
182
|
if (payload.role === 'user' && typeof payload.content === 'string') {
|
|
182
183
|
const blocks = payload.textBlocks;
|
|
183
|
-
const discovery = payload.mcpDiscovery;
|
|
184
|
+
const discovery = parseMcpDiscoveryReceipt(payload.mcpDiscovery);
|
|
184
185
|
const textBlocks = Array.isArray(blocks) &&
|
|
185
186
|
Array.from(blocks).every((block) => block && typeof block.text === 'string') &&
|
|
186
187
|
blocks.map((block) => block.text).join('') === payload.content
|
|
@@ -190,14 +191,7 @@ export function restoreModelContext(payload, providerModelId) {
|
|
|
190
191
|
role: 'user',
|
|
191
192
|
content: payload.content,
|
|
192
193
|
contextKind: 'contextual',
|
|
193
|
-
...(
|
|
194
|
-
typeof discovery.id === 'string' &&
|
|
195
|
-
discovery.id.length <= 128 &&
|
|
196
|
-
Array.isArray(discovery.names) &&
|
|
197
|
-
discovery.names.length <= 20 &&
|
|
198
|
-
discovery.names.every((name) => typeof name === 'string' && name.length <= 512)
|
|
199
|
-
? { mcpDiscovery: { id: discovery.id, names: discovery.names } }
|
|
200
|
-
: {}),
|
|
194
|
+
...(discovery ? { mcpDiscovery: discovery } : {}),
|
|
201
195
|
...(textBlocks === undefined ? {} : { textBlocks })
|
|
202
196
|
};
|
|
203
197
|
}
|
|
@@ -16,7 +16,7 @@ export declare function commitExecutionCompaction(input: {
|
|
|
16
16
|
draft(retainedStart: number): Omit<SessionStoreCompactInput, 'retainedModelContext' | 'inlineMediaState'>;
|
|
17
17
|
readonly checkpoint: ResourceInputProjection['checkpoint'];
|
|
18
18
|
readonly withProjection: <T>(action: () => Promise<T>) => Promise<T>;
|
|
19
|
-
readonly
|
|
19
|
+
readonly pendingDiscoveryNames: (message: SessionModelMessage) => readonly string[];
|
|
20
20
|
readonly currentGeneration: () => string | undefined;
|
|
21
21
|
readonly recordCommit: (recordId: string) => void;
|
|
22
22
|
readonly replace: (retained: SessionModelMessage[]) => void;
|
|
@@ -11,7 +11,18 @@ export async function commitExecutionCompaction(input) {
|
|
|
11
11
|
if (retainedStart === 0)
|
|
12
12
|
return undefined;
|
|
13
13
|
const retained = [
|
|
14
|
-
...input.messages.slice(0, retainedStart).
|
|
14
|
+
...input.messages.slice(0, retainedStart).flatMap((message) => {
|
|
15
|
+
const receipt = message.mcpDiscovery;
|
|
16
|
+
if (!receipt)
|
|
17
|
+
return [];
|
|
18
|
+
const names = input.pendingDiscoveryNames(message);
|
|
19
|
+
if (!names.length)
|
|
20
|
+
return [];
|
|
21
|
+
// Do not preserve delivered definitions only because a sibling is pending.
|
|
22
|
+
return names.length === receipt.names.length
|
|
23
|
+
? [message]
|
|
24
|
+
: [{ ...message, mcpDiscovery: { id: receipt.id, names } }];
|
|
25
|
+
}),
|
|
15
26
|
...input.messages
|
|
16
27
|
.slice(retainedStart)
|
|
17
28
|
.filter((message) => message.contextKind !== 'private' || message.role === 'provider')
|
|
@@ -31,6 +42,9 @@ export async function commitExecutionCompaction(input) {
|
|
|
31
42
|
}
|
|
32
43
|
: {
|
|
33
44
|
...message,
|
|
45
|
+
...(message.mcpDiscovery
|
|
46
|
+
? { mcpDiscoveryPendingNames: input.pendingDiscoveryNames(message) }
|
|
47
|
+
: {}),
|
|
34
48
|
...(message.images?.length
|
|
35
49
|
? { images: message.images.map(({ dataBase64: _bytes, ...image }) => image) }
|
|
36
50
|
: {})
|
|
@@ -37,7 +37,7 @@ export declare function createExecutionCompaction(ports: {
|
|
|
37
37
|
generate(snapshot: Snapshot, compactionId: string, signal: AbortSignal): ReturnType<typeof generateExecutionCompaction>;
|
|
38
38
|
retainedResources(): Promise<string | undefined>;
|
|
39
39
|
withProjection<T>(action: () => Promise<T>): Promise<T>;
|
|
40
|
-
|
|
40
|
+
pendingDiscoveryNames(message: SessionModelMessage): readonly string[];
|
|
41
41
|
recordCommit(recordId: string): void;
|
|
42
42
|
invalidateContext(error: unknown): void;
|
|
43
43
|
invalidateUsage(): void;
|
|
@@ -78,7 +78,7 @@ export function createExecutionCompaction(ports) {
|
|
|
78
78
|
messageSources: ports.messageSources,
|
|
79
79
|
checkpoint: (value) => ports.resourceInput.checkpoint(value),
|
|
80
80
|
withProjection: ports.withProjection,
|
|
81
|
-
|
|
81
|
+
pendingDiscoveryNames: ports.pendingDiscoveryNames,
|
|
82
82
|
currentGeneration: () => modelContext.worldState.generation,
|
|
83
83
|
recordCommit: (recordId) => {
|
|
84
84
|
committed = true;
|
|
@@ -32,7 +32,7 @@ export declare class ExecutionModelLifecycle {
|
|
|
32
32
|
get usage(): AuthoritativeModelUsage | undefined;
|
|
33
33
|
resetSmart(): void;
|
|
34
34
|
invalidate(): void;
|
|
35
|
-
start(request: SessionModelRequest, onCompleted?: () => void): AsyncIterable<ModelEvent>;
|
|
35
|
+
start(request: SessionModelRequest, onCompleted?: () => Promise<void>): AsyncIterable<ModelEvent>;
|
|
36
36
|
afterModel(closedPrefixLength: number, request: SessionModelRequest | undefined): Promise<void>;
|
|
37
37
|
observeTokens(tokens: number): void;
|
|
38
38
|
observeUsage(usage: Omit<AuthoritativeModelUsage, 'historyMessages'> | undefined): void;
|
|
@@ -26,7 +26,7 @@ export declare function createSessionExecutionFactory(ports: {
|
|
|
26
26
|
sessionWriterOwner: object;
|
|
27
27
|
activeExecutionAdapters: AgentSessionComposition['activeExecutionAdapters'];
|
|
28
28
|
sessionId: string;
|
|
29
|
-
sessionRuntime: Pick<SessionRuntime, 'acknowledgeSkillContext' | 'acknowledgeMcpDiscovery' | '
|
|
29
|
+
sessionRuntime: Pick<SessionRuntime, 'acknowledgeSkillContext' | 'acknowledgeMcpDiscovery' | 'pendingMcpDiscoveryNames' | 'mcpDiscoveryRevision' | 'publishMcpDiscovery' | 'assertCanExecute' | 'bindExecutionContext' | 'deactivateExecution' | 'joinRecordProjection' | 'pendingSkillContext' | 'registerExecution' | 'publishEvent' | 'publishSkillContext' | 'restoreExecutionState' | 'scheduleTool' | 'sessionBackend' | 'unbindExecutionContext' | 'unregisterExecution' | 'updateContextualWorldState' | 'recordRequest' | 'completeRequest'>;
|
|
30
30
|
sessionSource: Awaited<ReturnType<SessionStore['getSession']>>['source'];
|
|
31
31
|
logicalWorkspace: string;
|
|
32
32
|
instructionWorkspace: string;
|
|
@@ -2,6 +2,7 @@ import { restoreMessages } from '../runtime/context/restore.js';
|
|
|
2
2
|
import { latestModelUsage, reasoningEffortBaseline } from '../runtime/context/usage.js';
|
|
3
3
|
import { publicModelUsage } from '../runtime/event-projection.js';
|
|
4
4
|
import { truncateModelText } from '../runtime/token-budget.js';
|
|
5
|
+
import { MCP_DISCOVERY_DELIVERED } from '../session/mcp-discovery.js';
|
|
5
6
|
import { executeRoundTools } from '../tools/execution.js';
|
|
6
7
|
import { pairedMcpToolNames } from '../tools/mcp/history.js';
|
|
7
8
|
import { ExecutionToolPermissions, projectPermissionTool, resolvePermissionMode, withToolPermissions } from '../tools/permissions.js';
|
|
@@ -658,7 +659,7 @@ export function createSessionExecutionFactory(ports) {
|
|
|
658
659
|
}),
|
|
659
660
|
retainedResources: async () => retainedSessionResourcesSnapshot(await loadRetainedSessionResources()),
|
|
660
661
|
withProjection: withRecordProjection,
|
|
661
|
-
|
|
662
|
+
pendingDiscoveryNames: (message) => sessionRuntime.pendingMcpDiscoveryNames(message),
|
|
662
663
|
recordCommit: (recordId) => inputs.recordCompactCommit({ changed: true, recordId, executionId }),
|
|
663
664
|
invalidateContext: (error) => executionOwner.invalidateContext(error),
|
|
664
665
|
invalidateUsage: invalidateCompactUsage,
|
|
@@ -803,10 +804,15 @@ export function createSessionExecutionFactory(ports) {
|
|
|
803
804
|
runTools: executeRoundTools,
|
|
804
805
|
startModel: (request) => {
|
|
805
806
|
const skillLoads = preparedSkillLoads.get(request.messages);
|
|
806
|
-
return modelLifecycle.start(request, () => {
|
|
807
|
+
return modelLifecycle.start(request, async () => {
|
|
807
808
|
if (skillLoads)
|
|
808
809
|
sessionRuntime.acknowledgeSkillContext(skillLoads);
|
|
809
|
-
sessionRuntime.acknowledgeMcpDiscovery(request.messages)
|
|
810
|
+
await sessionRuntime.acknowledgeMcpDiscovery(request.messages, (receipts) => store.append(sessionId, {
|
|
811
|
+
type: MCP_DISCOVERY_DELIVERED,
|
|
812
|
+
payload: { receipts },
|
|
813
|
+
executionId,
|
|
814
|
+
turnId
|
|
815
|
+
}));
|
|
810
816
|
});
|
|
811
817
|
},
|
|
812
818
|
recoverySignal: () => controller.signal,
|
|
@@ -4,6 +4,7 @@ import type { ModelAdapter } from '../model/contracts.js';
|
|
|
4
4
|
import type { ModelCredentialProvider } from '../model/configuration.js';
|
|
5
5
|
import type { SessionModelMessage, SessionModelRequest as ModelRequest } from '../session/model-request.js';
|
|
6
6
|
import type { SessionStore } from '../session/store/contracts.js';
|
|
7
|
+
import { type McpDiscoveryReceipt } from '../session/mcp-discovery.js';
|
|
7
8
|
import { type ContextualWorldState } from '../runtime/context/world-state.js';
|
|
8
9
|
import { TodoStore } from '../tools/agent/todo.js';
|
|
9
10
|
import type { ExecutionResult } from './types.js';
|
|
@@ -33,8 +34,8 @@ export declare class SessionRuntime {
|
|
|
33
34
|
acknowledgeSkillContext(delivered: ReadonlyMap<string, string>): void;
|
|
34
35
|
publishMcpDiscovery(recordId: string, message: SessionModelMessage): void;
|
|
35
36
|
get mcpDiscoveryRevision(): number;
|
|
36
|
-
|
|
37
|
-
acknowledgeMcpDiscovery(messages: readonly SessionModelMessage[]): void
|
|
37
|
+
pendingMcpDiscoveryNames(message: SessionModelMessage): readonly string[];
|
|
38
|
+
acknowledgeMcpDiscovery(messages: readonly SessionModelMessage[], persist: (receipts: readonly McpDiscoveryReceipt[]) => Promise<unknown>): Promise<void>;
|
|
38
39
|
recordRequest(modelId: string, request: ModelRequest): ExtensionRequestSnapshot;
|
|
39
40
|
completeRequest(snapshot: ExtensionRequestSnapshot): void;
|
|
40
41
|
captureRequest(input: Parameters<ExtensionRequestSnapshots['capture']>[0]): ExtensionRequestSnapshot | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AgentError } from '../error.js';
|
|
2
2
|
import { ExtensionRequestSnapshots } from '../extensions/model-request.js';
|
|
3
|
+
import { restorePendingMcpDiscovery } from '../session/mcp-discovery.js';
|
|
3
4
|
import { assertLoadedSkillCapacity, latestContextualWorldStateGeneration, parsePersistedContextualWorldState, recoverLoadedSkillEntries } from '../runtime/context/world-state.js';
|
|
4
5
|
import { TodoStore } from '../tools/agent/todo.js';
|
|
5
6
|
import { createSessionToolScheduler } from '../tools/scheduler.js';
|
|
@@ -89,20 +90,25 @@ export class SessionRuntime {
|
|
|
89
90
|
get mcpDiscoveryRevision() {
|
|
90
91
|
return this.#mcpDiscoveryRevision;
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
pendingMcpDiscoveryNames(message) {
|
|
93
94
|
const receipt = message.mcpDiscovery;
|
|
94
|
-
return (receipt?.names.
|
|
95
|
+
return (receipt?.names.filter((name) => this.#pendingMcpDiscovery.get(name) === receipt.id) ?? []);
|
|
95
96
|
}
|
|
96
|
-
acknowledgeMcpDiscovery(messages) {
|
|
97
|
+
async acknowledgeMcpDiscovery(messages, persist) {
|
|
97
98
|
if (!this.#pendingMcpDiscovery.size)
|
|
98
99
|
return;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
await this.withRecordProjection(async () => {
|
|
101
|
+
const receipts = messages.flatMap((message) => {
|
|
102
|
+
const names = this.pendingMcpDiscoveryNames(message);
|
|
103
|
+
return names.length ? [{ id: message.mcpDiscovery.id, names }] : [];
|
|
104
|
+
});
|
|
105
|
+
if (!receipts.length)
|
|
106
|
+
return;
|
|
107
|
+
await persist(receipts);
|
|
108
|
+
for (const receipt of receipts)
|
|
109
|
+
for (const name of receipt.names)
|
|
104
110
|
this.#pendingMcpDiscovery.delete(name);
|
|
105
|
-
}
|
|
111
|
+
});
|
|
106
112
|
}
|
|
107
113
|
recordRequest(modelId, request) {
|
|
108
114
|
return (this.#requestSnapshots ??= new ExtensionRequestSnapshots()).record(modelId, request);
|
|
@@ -144,7 +150,11 @@ export class SessionRuntime {
|
|
|
144
150
|
}
|
|
145
151
|
async restoreExecutionState(store, writerOwner) {
|
|
146
152
|
const sessionId = this.storedSession.id;
|
|
147
|
-
const state = await
|
|
153
|
+
const state = await this.withRecordProjection(async () => {
|
|
154
|
+
const state = await store.readExecutionState(sessionId);
|
|
155
|
+
this.#pendingMcpDiscovery = restorePendingMcpDiscovery(state.contextRecords);
|
|
156
|
+
return state;
|
|
157
|
+
});
|
|
148
158
|
const todo = this.restoreTodo(state.todo, store.hasRetainedSessionLease(sessionId, writerOwner));
|
|
149
159
|
const generation = latestContextualWorldStateGeneration(state.contextRecords);
|
|
150
160
|
const persisted = parsePersistedContextualWorldState(await store.readContextualWorldState(sessionId));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SessionRecord } from './record-contract.js';
|
|
2
|
+
export interface McpDiscoveryReceipt {
|
|
3
|
+
id: string;
|
|
4
|
+
names: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export declare const MCP_DISCOVERY_DELIVERED = "mcp.discovery.delivered";
|
|
7
|
+
export declare function parseMcpDiscoveryReceipt(value: unknown): McpDiscoveryReceipt | undefined;
|
|
8
|
+
/** Replay only delivery state. Current catalog policy still controls exposure. */
|
|
9
|
+
export declare function restorePendingMcpDiscovery(records: readonly SessionRecord[]): Map<string, string>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { compactSummaryFromCheckpoint } from './record-projection.js';
|
|
2
|
+
export const MCP_DISCOVERY_DELIVERED = 'mcp.discovery.delivered';
|
|
3
|
+
export function parseMcpDiscoveryReceipt(value) {
|
|
4
|
+
if (!isRecord(value))
|
|
5
|
+
return undefined;
|
|
6
|
+
const { id, names } = value;
|
|
7
|
+
if (typeof id === 'string' &&
|
|
8
|
+
id.length > 0 &&
|
|
9
|
+
id.length <= 128 &&
|
|
10
|
+
Array.isArray(names) &&
|
|
11
|
+
names.length <= 20 &&
|
|
12
|
+
names.every((name) => typeof name === 'string' && name.length <= 512))
|
|
13
|
+
return { id, names };
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Replay only delivery state. Current catalog policy still controls exposure. */
|
|
17
|
+
export function restorePendingMcpDiscovery(records) {
|
|
18
|
+
const pending = new Map();
|
|
19
|
+
for (const record of records) {
|
|
20
|
+
const { type, payload } = record;
|
|
21
|
+
if (!isRecord(payload))
|
|
22
|
+
continue;
|
|
23
|
+
if (type === 'model.context' && payload.role === 'user') {
|
|
24
|
+
const receipt = parseMcpDiscoveryReceipt(payload.mcpDiscovery);
|
|
25
|
+
if (receipt)
|
|
26
|
+
for (const name of receipt.names)
|
|
27
|
+
pending.set(name, receipt.id);
|
|
28
|
+
}
|
|
29
|
+
else if (type === MCP_DISCOVERY_DELIVERED && Array.isArray(payload.receipts)) {
|
|
30
|
+
for (const value of payload.receipts) {
|
|
31
|
+
const receipt = parseMcpDiscoveryReceipt(value);
|
|
32
|
+
if (!receipt)
|
|
33
|
+
continue;
|
|
34
|
+
for (const name of receipt.names)
|
|
35
|
+
if (pending.get(name) === receipt.id)
|
|
36
|
+
pending.delete(name);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (type === 'compact.completed' && compactSummaryFromCheckpoint(record)) {
|
|
40
|
+
pending.clear();
|
|
41
|
+
if (!Array.isArray(payload.retainedModelContext))
|
|
42
|
+
continue;
|
|
43
|
+
for (const message of payload.retainedModelContext) {
|
|
44
|
+
if (!isRecord(message) || message.role !== 'user')
|
|
45
|
+
continue;
|
|
46
|
+
const receipt = parseMcpDiscoveryReceipt(message.mcpDiscovery);
|
|
47
|
+
if (!receipt)
|
|
48
|
+
continue;
|
|
49
|
+
const saved = Array.isArray(message.mcpDiscoveryPendingNames)
|
|
50
|
+
? message.mcpDiscoveryPendingNames
|
|
51
|
+
: receipt.names;
|
|
52
|
+
for (const name of receipt.names) {
|
|
53
|
+
if (saved.includes(name))
|
|
54
|
+
pending.set(name, receipt.id);
|
|
55
|
+
else
|
|
56
|
+
pending.delete(name);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return pending;
|
|
62
|
+
}
|
|
63
|
+
function isRecord(value) {
|
|
64
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
65
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ModelMessage, ModelRequest } from '../model/contracts.js';
|
|
2
2
|
import type { ClientToolDefinition } from '../tools/contracts.js';
|
|
3
3
|
import type { CodeObservation, CodeToolCallRecord } from './code-observation-contract.js';
|
|
4
|
+
import type { McpDiscoveryReceipt } from './mcp-discovery.js';
|
|
4
5
|
/** Durable execution facts, projected to protocol input at the SDK adapter boundary. */
|
|
5
6
|
export interface SessionModelMessage extends ModelMessage {
|
|
6
7
|
calls?: readonly CodeToolCallRecord[];
|
|
@@ -8,10 +9,7 @@ export interface SessionModelMessage extends ModelMessage {
|
|
|
8
9
|
observationId?: string;
|
|
9
10
|
toolSearchTools?: readonly ClientToolDefinition[];
|
|
10
11
|
/** SDK discovery receipt; names are rebound to the current authorized catalog. */
|
|
11
|
-
mcpDiscovery?:
|
|
12
|
-
id: string;
|
|
13
|
-
names: readonly string[];
|
|
14
|
-
};
|
|
12
|
+
mcpDiscovery?: McpDiscoveryReceipt;
|
|
15
13
|
}
|
|
16
14
|
export interface SessionModelRequest extends ModelRequest {
|
|
17
15
|
messages: readonly SessionModelMessage[];
|