@spine-event-engine/server 2.0.0-snapshot.22 → 2.0.0-snapshot.23
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/README.md +104 -7
- package/REFERENCE.md +194 -19
- package/dist/agent/agent-admission.d.ts +80 -0
- package/dist/agent/agent-admission.d.ts.map +1 -0
- package/dist/agent/agent-admission.js +127 -0
- package/dist/agent/agent-admission.js.map +1 -0
- package/dist/agent/agent-ai-binding.d.ts +24 -0
- package/dist/agent/agent-ai-binding.d.ts.map +1 -0
- package/dist/agent/agent-ai-binding.js +48 -0
- package/dist/agent/agent-ai-binding.js.map +1 -0
- package/dist/agent/agent-ai-runtime.d.ts +76 -0
- package/dist/agent/agent-ai-runtime.d.ts.map +1 -0
- package/dist/agent/agent-ai-runtime.js +1269 -0
- package/dist/agent/agent-ai-runtime.js.map +1 -0
- package/dist/agent/agent-execution-capacity.d.ts +43 -0
- package/dist/agent/agent-execution-capacity.d.ts.map +1 -0
- package/dist/agent/agent-execution-capacity.js +147 -0
- package/dist/agent/agent-execution-capacity.js.map +1 -0
- package/dist/agent/agent-execution-fault.d.ts +18 -0
- package/dist/agent/agent-execution-fault.d.ts.map +1 -0
- package/dist/agent/agent-execution-fault.js +31 -0
- package/dist/agent/agent-execution-fault.js.map +1 -0
- package/dist/agent/agent-execution-session.d.ts +103 -0
- package/dist/agent/agent-execution-session.d.ts.map +1 -0
- package/dist/agent/agent-execution-session.js +238 -0
- package/dist/agent/agent-execution-session.js.map +1 -0
- package/dist/agent/agent-history.d.ts +148 -0
- package/dist/agent/agent-history.d.ts.map +1 -0
- package/dist/agent/agent-history.js +340 -0
- package/dist/agent/agent-history.js.map +1 -0
- package/dist/agent/agent-interaction-audit.d.ts +58 -0
- package/dist/agent/agent-interaction-audit.d.ts.map +1 -0
- package/dist/agent/agent-interaction-audit.js +114 -0
- package/dist/agent/agent-interaction-audit.js.map +1 -0
- package/dist/agent/agent-interaction-events.d.ts +40 -0
- package/dist/agent/agent-interaction-events.d.ts.map +1 -0
- package/dist/agent/agent-interaction-events.js +129 -0
- package/dist/agent/agent-interaction-events.js.map +1 -0
- package/dist/agent/agent-mcp-budget.d.ts +125 -0
- package/dist/agent/agent-mcp-budget.d.ts.map +1 -0
- package/dist/agent/agent-mcp-budget.js +566 -0
- package/dist/agent/agent-mcp-budget.js.map +1 -0
- package/dist/agent/agent-mcp-host.d.ts +125 -0
- package/dist/agent/agent-mcp-host.d.ts.map +1 -0
- package/dist/agent/agent-mcp-host.js +15 -0
- package/dist/agent/agent-mcp-host.js.map +1 -0
- package/dist/agent/agent-mcp-runtime.d.ts +199 -0
- package/dist/agent/agent-mcp-runtime.d.ts.map +1 -0
- package/dist/agent/agent-mcp-runtime.js +621 -0
- package/dist/agent/agent-mcp-runtime.js.map +1 -0
- package/dist/agent/agent-model-selection.d.ts +129 -0
- package/dist/agent/agent-model-selection.d.ts.map +1 -0
- package/dist/agent/agent-model-selection.js +342 -0
- package/dist/agent/agent-model-selection.js.map +1 -0
- package/dist/agent/agent-read-runtime.d.ts +70 -0
- package/dist/agent/agent-read-runtime.d.ts.map +1 -0
- package/dist/agent/agent-read-runtime.js +320 -0
- package/dist/agent/agent-read-runtime.js.map +1 -0
- package/dist/agent/agent-revisions.d.ts +35 -0
- package/dist/agent/agent-revisions.d.ts.map +1 -0
- package/dist/agent/agent-revisions.js +133 -0
- package/dist/agent/agent-revisions.js.map +1 -0
- package/dist/agent/agent-scheduler.d.ts +99 -0
- package/dist/agent/agent-scheduler.d.ts.map +1 -0
- package/dist/agent/agent-scheduler.js +398 -0
- package/dist/agent/agent-scheduler.js.map +1 -0
- package/dist/bus/command-bus.d.ts +62 -0
- package/dist/bus/command-bus.d.ts.map +1 -1
- package/dist/bus/command-bus.js +51 -2
- package/dist/bus/command-bus.js.map +1 -1
- package/dist/bus/event-bus.d.ts +137 -3
- package/dist/bus/event-bus.d.ts.map +1 -1
- package/dist/bus/event-bus.js +133 -2
- package/dist/bus/event-bus.js.map +1 -1
- package/dist/bus/saved-dispatcher-binding.d.ts +96 -0
- package/dist/bus/saved-dispatcher-binding.d.ts.map +1 -0
- package/dist/bus/saved-dispatcher-binding.js +35 -0
- package/dist/bus/saved-dispatcher-binding.js.map +1 -0
- package/dist/context/bounded-context.d.ts +36 -2
- package/dist/context/bounded-context.d.ts.map +1 -1
- package/dist/context/bounded-context.js +253 -54
- package/dist/context/bounded-context.js.map +1 -1
- package/dist/context/tenant-index.d.ts +25 -0
- package/dist/context/tenant-index.d.ts.map +1 -1
- package/dist/context/tenant-index.js +45 -1
- package/dist/context/tenant-index.js.map +1 -1
- package/dist/entity/entity.d.ts +82 -3
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +121 -22
- package/dist/entity/entity.js.map +1 -1
- package/dist/handler/generated-handler-registry.js +8 -3
- package/dist/handler/generated-handler-registry.js.map +1 -1
- package/dist/handler/handler-metadata.d.ts +17 -1
- package/dist/handler/handler-metadata.d.ts.map +1 -1
- package/dist/handler/handler-metadata.js +10 -4
- package/dist/handler/handler-metadata.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/repository/commit-fence.d.ts +11 -0
- package/dist/repository/commit-fence.d.ts.map +1 -1
- package/dist/repository/commit-fence.js +13 -0
- package/dist/repository/commit-fence.js.map +1 -1
- package/dist/repository/repository.d.ts +222 -13
- package/dist/repository/repository.d.ts.map +1 -1
- package/dist/repository/repository.js +2323 -123
- package/dist/repository/repository.js.map +1 -1
- package/dist/runtime/signal-publisher.d.ts +6 -0
- package/dist/runtime/signal-publisher.d.ts.map +1 -1
- package/dist/runtime/signal-publisher.js +13 -0
- package/dist/runtime/signal-publisher.js.map +1 -1
- package/dist/runtime/standalone-handler-runtime.d.ts +7 -0
- package/dist/runtime/standalone-handler-runtime.d.ts.map +1 -1
- package/dist/runtime/standalone-handler-runtime.js +148 -11
- package/dist/runtime/standalone-handler-runtime.js.map +1 -1
- package/dist/server/server.d.ts +9 -0
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +13 -1
- package/dist/server/server.js.map +1 -1
- package/dist/testing/index.d.ts +57 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +87 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -12
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
import { create, equals } from "@bufbuild/protobuf";
|
|
15
|
+
import { AnySchema } from "@bufbuild/protobuf/wkt";
|
|
16
|
+
import { AnyMessages, TypeUrls, Validate } from "@spine-event-engine/core";
|
|
17
|
+
import { CommandIdSchema, EventIdSchema, EventSchema, MessageIdSchema, } from "@spine-event-engine/proto";
|
|
18
|
+
import { AgentOperationRefSchema, AiModelKind, } from "@spine-event-engine/proto/agent";
|
|
19
|
+
import {} from "@spine-event-engine/proto/generated/spine/server/agent/execution_record_pb.js";
|
|
20
|
+
/**
|
|
21
|
+
* Requires the original identifier's concrete Protobuf type URL.
|
|
22
|
+
*
|
|
23
|
+
* @param value Candidate typed identifier.
|
|
24
|
+
* @param field Diagnostic field name.
|
|
25
|
+
* @returns Candidate after its type URL is checked.
|
|
26
|
+
*/
|
|
27
|
+
const typedId = (value, field) => {
|
|
28
|
+
if (!value?.typeUrl.trim())
|
|
29
|
+
throw new TypeError(`Agent interaction requires typed ${field}.`);
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Copies the original signal ID and domain payload type from accepted work.
|
|
34
|
+
*
|
|
35
|
+
* @param accepted Original accepted Command, Event, or rejection.
|
|
36
|
+
* @returns Canonical source MessageId.
|
|
37
|
+
*/
|
|
38
|
+
const sourceRef = (accepted) => {
|
|
39
|
+
const signal = accepted.signal;
|
|
40
|
+
if (signal.case === "command") {
|
|
41
|
+
const id = signal.value.id;
|
|
42
|
+
if (!id?.uuid.trim())
|
|
43
|
+
throw new TypeError("Agent interaction requires source Command ID.");
|
|
44
|
+
const typeUrl = signal.value.message?.typeUrl;
|
|
45
|
+
if (!typeUrl?.trim())
|
|
46
|
+
throw new TypeError("Agent interaction requires source payload type.");
|
|
47
|
+
return create(MessageIdSchema, { id: AnyMessages.pack(CommandIdSchema, id), typeUrl });
|
|
48
|
+
}
|
|
49
|
+
if (signal.case === "event") {
|
|
50
|
+
const id = signal.value.id;
|
|
51
|
+
if (!id?.value.trim())
|
|
52
|
+
throw new TypeError("Agent interaction requires source Event ID.");
|
|
53
|
+
const typeUrl = signal.value.message?.typeUrl;
|
|
54
|
+
if (!typeUrl?.trim())
|
|
55
|
+
throw new TypeError("Agent interaction requires source payload type.");
|
|
56
|
+
return create(MessageIdSchema, { id: AnyMessages.pack(EventIdSchema, id), typeUrl });
|
|
57
|
+
}
|
|
58
|
+
throw new TypeError("Agent interaction requires a source signal.");
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Creates immutable System-event facts from accepted Agent work.
|
|
62
|
+
*/
|
|
63
|
+
export const AgentInteractionEvents = Object.freeze({
|
|
64
|
+
/**
|
|
65
|
+
* Correlates a named operation with its typed Agent, source signal, and selected model.
|
|
66
|
+
*
|
|
67
|
+
* @param accepted Durable accepted invocation.
|
|
68
|
+
* @param operation Named model operation.
|
|
69
|
+
* @param stateSchema Generated Agent state descriptor.
|
|
70
|
+
* @param selected Selected deployment for this operation kind.
|
|
71
|
+
* @returns Complete operation reference.
|
|
72
|
+
*/
|
|
73
|
+
operationRef(accepted, operation, stateSchema, selected) {
|
|
74
|
+
const stateType = accepted.key?.scope?.stateType;
|
|
75
|
+
if (stateType !== stateSchema.typeName)
|
|
76
|
+
throw new TypeError("Agent interaction state type does not match accepted work.");
|
|
77
|
+
const agentId = typedId(accepted.recipientId, "Agent ID");
|
|
78
|
+
if (!operation.operation?.value.trim() || !operation.conversation?.value.trim())
|
|
79
|
+
throw new TypeError("Agent interaction requires operation and conversation IDs.");
|
|
80
|
+
if (!selected.model?.name?.value.trim() ||
|
|
81
|
+
!selected.model.revision?.value.trim() ||
|
|
82
|
+
(selected.kind !== AiModelKind.GENERATION && selected.kind !== AiModelKind.DECISION))
|
|
83
|
+
throw new TypeError("Agent interaction requires a selected model and kind.");
|
|
84
|
+
const result = create(AgentOperationRefSchema, {
|
|
85
|
+
operation: operation.operation,
|
|
86
|
+
agent: create(MessageIdSchema, {
|
|
87
|
+
id: agentId,
|
|
88
|
+
typeUrl: TypeUrls.derive(stateSchema),
|
|
89
|
+
}),
|
|
90
|
+
sourceSignal: sourceRef(accepted),
|
|
91
|
+
model: selected.model,
|
|
92
|
+
kind: selected.kind,
|
|
93
|
+
conversation: operation.conversation,
|
|
94
|
+
});
|
|
95
|
+
return Validate.check(AgentOperationRefSchema, result);
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Wraps one typed System-event payload with original causality and Agent producer identity.
|
|
99
|
+
*
|
|
100
|
+
* @typeParam Schema Generated System-event descriptor.
|
|
101
|
+
* @param accepted Durable source Command, Event, or rejection.
|
|
102
|
+
* @param metadata Spine ID, Time, and origin metadata provider.
|
|
103
|
+
* @param agentId Original typed Agent identifier.
|
|
104
|
+
* @param schema Generated System-event descriptor.
|
|
105
|
+
* @param payload Matching typed System-event message.
|
|
106
|
+
* @returns Fresh Event envelope without mutating accepted work.
|
|
107
|
+
*/
|
|
108
|
+
envelope(accepted, metadata, agentId, schema, payload) {
|
|
109
|
+
const producer = typedId(agentId, "Agent ID");
|
|
110
|
+
if (!accepted.recipientId || !equals(AnySchema, accepted.recipientId, producer))
|
|
111
|
+
throw new TypeError("Agent interaction producer differs from accepted recipient.");
|
|
112
|
+
sourceRef(accepted);
|
|
113
|
+
const origin = accepted.signal.case === "command"
|
|
114
|
+
? metadata.eventFromCommand(accepted.signal.value, {})
|
|
115
|
+
: accepted.signal.case === "event"
|
|
116
|
+
? metadata.eventFromEvent(accepted.signal.value, {})
|
|
117
|
+
: undefined;
|
|
118
|
+
if (!origin)
|
|
119
|
+
throw new TypeError("Agent interaction requires a source signal.");
|
|
120
|
+
const context = origin.context;
|
|
121
|
+
context.producerId = producer;
|
|
122
|
+
return Validate.check(EventSchema, create(EventSchema, {
|
|
123
|
+
id: origin.id,
|
|
124
|
+
context,
|
|
125
|
+
message: AnyMessages.pack(schema, payload),
|
|
126
|
+
}));
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
//# sourceMappingURL=agent-interaction-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-interaction-events.js","sourceRoot":"","sources":["../../src/agent/agent-interaction-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAqB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAY,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAsB,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EACL,eAAe,EACf,aAAa,EACb,WAAW,EACX,eAAe,GAEhB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,EACvB,WAAW,GAEZ,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAIN,MAAM,+EAA+E,CAA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AC,OAAO,CAAC;QAC/B,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC9B,OAAO,QAAQ,CAAC,KAAK,CACnB,WAAW,EACX,MAAM,CAAC,WAAW,EAAE;YAClB,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,OAAO;YACP,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;SAC3C,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { AiMcpMessageRequest, AiMcpMessageTicket, AiToolInvocation } from "@spine-event-engine/ai/spi/adapter";
|
|
2
|
+
import { type AgentHistoryEntry, type ToolRequest, type ToolResponse } from "@spine-event-engine/proto/agent";
|
|
3
|
+
import { type AgentExecutionRecord, type AgentExecutionHead, type AgentNamedOperation } from "@spine-event-engine/proto/generated/spine/server/agent/execution_record_pb.js";
|
|
4
|
+
import { type AgentExecutionCapacity } from "@spine-event-engine/storage/provider";
|
|
5
|
+
import type { AgentMcpIntent } from "./agent-mcp-host.js";
|
|
6
|
+
import { AgentInteractionAudit } from "./agent-interaction-audit.js";
|
|
7
|
+
/**
|
|
8
|
+
* Provides the fenced record, capacity, and mutation view used by MCP.
|
|
9
|
+
*/
|
|
10
|
+
interface JournalSession {
|
|
11
|
+
/**
|
|
12
|
+
* Stops physical work when the execution claim closes.
|
|
13
|
+
*/
|
|
14
|
+
readonly signal: AbortSignal;
|
|
15
|
+
/**
|
|
16
|
+
* Reads the current durable execution record.
|
|
17
|
+
*
|
|
18
|
+
* @returns Current durable execution record.
|
|
19
|
+
*/
|
|
20
|
+
record(): AgentExecutionRecord;
|
|
21
|
+
/**
|
|
22
|
+
* Writes one fenced record mutation with optional Agent history rows.
|
|
23
|
+
*
|
|
24
|
+
* @param change Record transformation under the claim token.
|
|
25
|
+
* @param historyEntries Rows included in the provider mutation.
|
|
26
|
+
* @returns The saved record image.
|
|
27
|
+
*/
|
|
28
|
+
update(change: (record: AgentExecutionRecord) => AgentExecutionRecord, historyEntries?: readonly AgentHistoryEntry[]): Promise<AgentExecutionRecord>;
|
|
29
|
+
/**
|
|
30
|
+
* Reads provider limits for complete encoded rows.
|
|
31
|
+
*
|
|
32
|
+
* @returns Provider limits for complete encoded rows.
|
|
33
|
+
*/
|
|
34
|
+
capacity(): AgentExecutionCapacity;
|
|
35
|
+
/**
|
|
36
|
+
* Reads current saved model preferences for the Agent instance.
|
|
37
|
+
*
|
|
38
|
+
* @returns Current saved model preferences.
|
|
39
|
+
*/
|
|
40
|
+
preferences(): Readonly<AgentExecutionHead["preferences"]>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Charges MCP physical messages to the same fenced invocation ledger as model sends.
|
|
44
|
+
*/
|
|
45
|
+
export declare class AgentMcpBudget {
|
|
46
|
+
#private;
|
|
47
|
+
private readonly session;
|
|
48
|
+
private readonly operation;
|
|
49
|
+
private readonly deadlineEpochMs;
|
|
50
|
+
private readonly audit;
|
|
51
|
+
/**
|
|
52
|
+
* Binds one MCP operation to the shared fenced invocation budget.
|
|
53
|
+
*
|
|
54
|
+
* @param session Fenced execution journal.
|
|
55
|
+
* @param operation Saved named operation.
|
|
56
|
+
* @param deadlineEpochMs Original operation deadline.
|
|
57
|
+
* @param audit Paired Agent history and System Event writer.
|
|
58
|
+
*/
|
|
59
|
+
constructor(session: JournalSession, operation: AgentNamedOperation, deadlineEpochMs: number | undefined, audit: AgentInteractionAudit | undefined);
|
|
60
|
+
/**
|
|
61
|
+
* Checks invocation bounds using measured receipts and full unknown credit.
|
|
62
|
+
*
|
|
63
|
+
* @param record Current durable invocation.
|
|
64
|
+
* @param input Proposed physical input bytes.
|
|
65
|
+
* @param output Proposed physical response allowance.
|
|
66
|
+
*/
|
|
67
|
+
static checkSharedBytes(record: AgentExecutionRecord, input: number, output: number): void;
|
|
68
|
+
/**
|
|
69
|
+
* Returns unspent configured invocation output credit, if configured.
|
|
70
|
+
*
|
|
71
|
+
* @param record Durable execution record containing receipts and optional bounds.
|
|
72
|
+
* @returns Remaining byte credit, or undefined when no total bound was configured.
|
|
73
|
+
*/
|
|
74
|
+
static remainingOutputCredit(record: AgentExecutionRecord): bigint | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Persists full request bytes and response credit before a physical MCP send.
|
|
77
|
+
*
|
|
78
|
+
* @param server Configured MCP server identifier.
|
|
79
|
+
* @param request Physical protocol message and byte bounds.
|
|
80
|
+
* @returns Fenced ticket for the one physical send.
|
|
81
|
+
*/
|
|
82
|
+
reserveMessage(server: string, request: AiMcpMessageRequest): Promise<AiMcpMessageTicket>;
|
|
83
|
+
/**
|
|
84
|
+
* Rejects the chunk that crosses persisted full response credit.
|
|
85
|
+
*
|
|
86
|
+
* @param ticketId Saved physical-message ticket.
|
|
87
|
+
* @param bytes Newly decoded response bytes.
|
|
88
|
+
*/
|
|
89
|
+
onReceived(ticketId: string, bytes: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* Persists known receipt; unknown work retains its full original credit.
|
|
92
|
+
*
|
|
93
|
+
* @param ticketId Saved physical-message ticket.
|
|
94
|
+
* @param receivedBytes Complete decoded response size, when known.
|
|
95
|
+
* @returns When the receipt is persisted.
|
|
96
|
+
*/
|
|
97
|
+
finishMessage(ticketId: string, receivedBytes?: number): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Persists one authorized proposal and never reissues an uncertain write.
|
|
100
|
+
*
|
|
101
|
+
* @param invocation Model proposal and provider call identity.
|
|
102
|
+
* @param facts Vetted server, tool, arguments, and effect.
|
|
103
|
+
* @param operationLimit Capability tool-call bound.
|
|
104
|
+
* @returns Saved or newly allocated tool intent.
|
|
105
|
+
*/
|
|
106
|
+
journalToolIntent(invocation: AiToolInvocation, facts: Pick<ToolRequest, "server" | "tool" | "argumentsJson" | "effect">, operationLimit: number | undefined): Promise<AgentMcpIntent>;
|
|
107
|
+
/**
|
|
108
|
+
* Persists the pre-send boundary; repeating a read may retain this flag.
|
|
109
|
+
*
|
|
110
|
+
* @param callId Saved logical tool-call identity.
|
|
111
|
+
* @returns When the dispatch marker is persisted.
|
|
112
|
+
*/
|
|
113
|
+
markToolDispatched(callId: string): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Persists a complete tool result and its typed conversation row together.
|
|
116
|
+
*
|
|
117
|
+
* @param callId Saved logical tool-call identity.
|
|
118
|
+
* @param response Bounded tool result.
|
|
119
|
+
* @param history Typed conversation rows retained with the result.
|
|
120
|
+
* @returns When the fenced result and history are persisted.
|
|
121
|
+
*/
|
|
122
|
+
finishTool(callId: string, response: ToolResponse, history: readonly AgentHistoryEntry[]): Promise<void>;
|
|
123
|
+
}
|
|
124
|
+
export {};
|
|
125
|
+
//# sourceMappingURL=agent-mcp-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-mcp-budget.d.ts","sourceRoot":"","sources":["../../src/agent/agent-mcp-budget.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAeL,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAQL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EAEzB,MAAM,+EAA+E,CAAC;AACvF,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;GAEG;AACH,UAAU,cAAc;IACtB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B;;;;OAIG;IACH,MAAM,IAAI,oBAAoB,CAAC;IAE/B;;;;;;OAMG;IACH,MAAM,CACJ,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