maka-agent 0.2.0-dev.26.20260909 → 0.2.0-dev.28.20260911
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/LICENSE +106 -0
- package/dist/cli-core.js +28 -0
- package/dist/runtime-host-cli.js +43 -3
- package/dist/runtime-host-handoff-surface.js +10 -8
- package/dist/runtime-host-lifecycle-transaction.js +28 -3
- package/dist/runtime-host-local-source-retirement.js +1 -1
- package/dist/runtime-host-run-command.js +15 -7
- package/dist/runtime-host-setup-command.js +29 -6
- package/dist/runtime-host-update-command.js +49 -5
- package/dist/session-export-command.js +72 -0
- package/dist/session-import-command.js +69 -0
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +9 -4
- package/node_modules/@maka/core/dist/diagnostic-log.js +18 -7
- package/node_modules/@maka/core/dist/text-sanitize.js +8 -2
- package/node_modules/@maka/core/dist/usage-stats/types.js +2 -0
- package/node_modules/@maka/core/dist/workhub-routing.js +126 -0
- package/node_modules/@maka/core/package.json +2 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +15 -11
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +3 -1
- package/node_modules/@maka/runtime/dist/bots/bot-test.js +2 -1
- package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +24 -20
- package/node_modules/@maka/runtime/dist/bots/slack-bridge.js +5 -3
- package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +87 -29
- package/node_modules/@maka/runtime/dist/bots/wecom-bridge.js +40 -36
- package/node_modules/@maka/runtime/dist/builtin-tools.js +21 -2
- package/node_modules/@maka/runtime/dist/computer-use-tools.js +4 -1
- package/node_modules/@maka/runtime/dist/deep-research-tools.js +11 -5
- package/node_modules/@maka/runtime/dist/edit-replace.js +2 -2
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +5 -6
- package/node_modules/@maka/runtime/dist/memory-extraction-evidence.js +7 -1
- package/node_modules/@maka/runtime/dist/memory-extraction.js +12 -7
- package/node_modules/@maka/runtime/dist/openai-responses-websocket.js +2 -5
- package/node_modules/@maka/runtime/dist/plugin-agent-service.js +131 -0
- package/node_modules/@maka/runtime/dist/plugin-approval-service.js +33 -0
- package/node_modules/@maka/runtime/dist/plugin-attachment-service.js +53 -0
- package/node_modules/@maka/runtime/dist/plugin-command-service.js +100 -0
- package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +11 -2
- package/node_modules/@maka/runtime/dist/plugin-data-services.js +332 -0
- package/node_modules/@maka/runtime/dist/plugin-fs-service.js +62 -0
- package/node_modules/@maka/runtime/dist/plugin-goal-service.js +61 -0
- package/node_modules/@maka/runtime/dist/plugin-invocation-signal.js +24 -0
- package/node_modules/@maka/runtime/dist/plugin-llm-service.js +85 -0
- package/node_modules/@maka/runtime/dist/plugin-lsp-service.js +94 -0
- package/node_modules/@maka/runtime/dist/plugin-scope-registry.js +91 -0
- package/node_modules/@maka/runtime/dist/plugin-session-query-service.js +71 -0
- package/node_modules/@maka/runtime/dist/plugin-shell-env-service.js +87 -0
- package/node_modules/@maka/runtime/dist/plugin-shell-service.js +74 -0
- package/node_modules/@maka/runtime/dist/plugin-skill-service.js +93 -0
- package/node_modules/@maka/runtime/dist/plugin-system-prompt-service.js +346 -0
- package/node_modules/@maka/runtime/dist/plugin-tool-service.js +18 -52
- package/node_modules/@maka/runtime/dist/plugin-user-question-service.js +43 -0
- package/node_modules/@maka/runtime/dist/plugin-web-service.js +69 -0
- package/node_modules/@maka/runtime/dist/request-customization-fetch.js +14 -7
- package/node_modules/@maka/runtime/dist/session-export.js +178 -0
- package/node_modules/@maka/runtime/dist/session-import.js +100 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +6 -1
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +9 -6
- package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +13 -6
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +43 -10
- package/node_modules/@maka/runtime/dist/stream-graph-handoff.js +6 -1
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +1 -4
- package/node_modules/@maka/runtime/dist/system-prompt/workspace-instructions.js +11 -6
- package/node_modules/@maka/runtime/dist/tavily-search.js +8 -2
- package/node_modules/@maka/runtime/dist/text-line-window.js +49 -0
- package/node_modules/@maka/runtime/dist/tool-output.js +35 -12
- package/node_modules/@maka/runtime/dist/unified-diff.js +40 -10
- package/node_modules/@maka/runtime/dist/web-fetch-tool.js +4 -2
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +82 -33
- package/node_modules/@maka/runtime/dist/workspace-executor.js +2 -6
- package/node_modules/@maka/runtime/package.json +20 -1
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +73 -24
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +46 -12
- package/node_modules/@maka/runtime-host/dist/operator/setup-frame.js +31 -21
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +7 -4
- package/node_modules/@maka/runtime-host/dist/protocol/artifact.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +10 -1
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +30 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +3 -2
- package/node_modules/@maka/runtime-host/dist/protocol/skill-catalog.js +2 -1
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +25 -23
- package/node_modules/@maka/runtime-host/dist/server/artifact-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +62 -4
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +481 -11
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +74 -0
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +6 -1
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +2 -2
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +30 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +114 -20
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +49 -12
- package/node_modules/@maka/runtime-host/dist/server/plugin-data-runtime.js +234 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +12 -0
- package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +17 -8
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +189 -92
- package/node_modules/@maka/runtime-host/dist/server/runtime-resource-projection.js +3 -9
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +20 -21
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +24 -2
- package/node_modules/@maka/runtime-host/dist/server/skill-catalog-coordinator.js +18 -2
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +44 -35
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +92 -10
- package/node_modules/@maka/runtime-host/dist/transport/framed-byte-stream-transport.js +4 -1
- package/node_modules/@maka/runtime-host/dist/transport/local-ipc-framing.js +4 -2
- package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +9 -8
- package/node_modules/@maka/runtime-host/dist/transport/resumable-peer-stream.js +14 -9
- package/node_modules/@maka/storage/dist/agent-run-store.js +54 -10
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +32 -10
- package/node_modules/@maka/storage/dist/context-value-mutation-gate.js +59 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +1 -1
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +909 -34
- package/node_modules/@maka/storage/dist/session-message-projection.js +8 -4
- package/node_modules/@maka/storage/dist/session-store.js +2 -2
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +18 -4
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +12 -5
- package/node_modules/@maka/storage/dist/stable-storage.js +2 -1
- package/node_modules/@maka/storage/package.json +2 -0
- package/node_modules/@modelcontextprotocol/client/dist/src-D_zzAWoS.mjs +22 -5
- package/node_modules/@modelcontextprotocol/client/dist/src-NAgB4Mp8.cjs +22 -5
- package/node_modules/zod/v4/core/memoizer.cjs +12 -16
- package/node_modules/zod/v4/core/memoizer.js +12 -16
- package/package.json +1 -1
|
@@ -69,10 +69,14 @@ function normalizePreviewText(text) {
|
|
|
69
69
|
return text.replace(/\s+/g, ' ').trim();
|
|
70
70
|
}
|
|
71
71
|
function truncatePreview(text, maxLength = 96) {
|
|
72
|
-
const chars =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const chars = [];
|
|
73
|
+
for (const point of text) {
|
|
74
|
+
if (chars.length === maxLength) {
|
|
75
|
+
return `${chars.slice(0, maxLength - 1).join('')}…`;
|
|
76
|
+
}
|
|
77
|
+
chars.push(point);
|
|
78
|
+
}
|
|
79
|
+
return text;
|
|
76
80
|
}
|
|
77
81
|
/** One Turn's summary, folded message by message in transcript order. */
|
|
78
82
|
export function foldTurnContribution(current, turnId, sequence, message) {
|
|
@@ -446,9 +446,9 @@ class SqliteSessionStore {
|
|
|
446
446
|
await this.ensureReady();
|
|
447
447
|
await this.metadata.updateMessageAdmission(admission);
|
|
448
448
|
}
|
|
449
|
-
async reorderMessageAdmissions(sessionId, messageIds) {
|
|
449
|
+
async reorderMessageAdmissions(sessionId, messageIds, disposition = 'followup') {
|
|
450
450
|
await this.ensureReady();
|
|
451
|
-
await this.metadata.reorderMessageAdmissions(sessionId, messageIds);
|
|
451
|
+
await this.metadata.reorderMessageAdmissions(sessionId, messageIds, disposition);
|
|
452
452
|
}
|
|
453
453
|
async cancelMessageAdmissions(sessionId, messageIds) {
|
|
454
454
|
await this.ensureReady();
|
|
@@ -24,6 +24,7 @@ import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
|
24
24
|
import { CONTEXT_OFFLOAD_ID_MAX_CODE_POINTS, } from '@maka/core/context-offload';
|
|
25
25
|
import { configureSqliteContextOffloadDatabase, migrateSqliteContextOffloadDatabase, } from './sqlite-context-offload-schema.js';
|
|
26
26
|
import { readStableBoundedFile, syncDirectory, syncDirectoryChain, syncFile, } from './stable-storage.js';
|
|
27
|
+
import { runWithContextValueMutation } from './context-value-mutation-gate.js';
|
|
27
28
|
const MAX_MEDIA_TYPE_CODE_POINTS = 256;
|
|
28
29
|
const SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
29
30
|
const MANAGED_FILE_LOCATOR_PATTERN = /^sha256\/([0-9a-f]{2})\/([0-9a-f]{64})$/;
|
|
@@ -40,7 +41,7 @@ export class SqliteContextOffloadStore {
|
|
|
40
41
|
#onUnavailable;
|
|
41
42
|
#storageRoot;
|
|
42
43
|
#valueRoot;
|
|
43
|
-
#
|
|
44
|
+
#mutationGateKey;
|
|
44
45
|
#closed = false;
|
|
45
46
|
constructor(path, options) {
|
|
46
47
|
if (!path)
|
|
@@ -57,6 +58,11 @@ export class SqliteContextOffloadStore {
|
|
|
57
58
|
this.#valueRoot = this.#storageRoot
|
|
58
59
|
? join(this.#storageRoot, CONTEXT_OFFLOAD_VALUES_DIRECTORY_NAME)
|
|
59
60
|
: undefined;
|
|
61
|
+
// The canonical root is the key, so every writer of these files -- this
|
|
62
|
+
// Store and an importer publishing into the same workspace -- queues in one
|
|
63
|
+
// place. A Store with no durable root holds no managed files, so it queues
|
|
64
|
+
// against itself alone and keeps the behaviour it had.
|
|
65
|
+
this.#mutationGateKey = this.#storageRoot ?? `memory:${randomUUID()}`;
|
|
60
66
|
const Database = loadDatabaseSync();
|
|
61
67
|
this.#database = new Database(path);
|
|
62
68
|
try {
|
|
@@ -874,10 +880,18 @@ export class SqliteContextOffloadStore {
|
|
|
874
880
|
}
|
|
875
881
|
return join(valueRoot, 'sha256', match[1], blobId);
|
|
876
882
|
}
|
|
883
|
+
/**
|
|
884
|
+
* Takes a turn in the Storage Root's context mutation queue.
|
|
885
|
+
*
|
|
886
|
+
* This used to be a promise tail private to the instance, which serialised
|
|
887
|
+
* this Store's publication against its own collection and fenced nothing
|
|
888
|
+
* else. An importer publishing payloads into a live workspace has to take the
|
|
889
|
+
* same turn: these operations read database state, await, and only then act
|
|
890
|
+
* on files, so anything interleaving at that await acts on a decision that is
|
|
891
|
+
* no longer true.
|
|
892
|
+
*/
|
|
877
893
|
#runManagedValueMutation(operation) {
|
|
878
|
-
|
|
879
|
-
this.#managedValueMutationTail = pending.then(() => undefined, () => undefined);
|
|
880
|
-
return pending;
|
|
894
|
+
return runWithContextValueMutation(this.#mutationGateKey, operation);
|
|
881
895
|
}
|
|
882
896
|
#markBlobUnreferencedIfEligible(blobId, unreferencedAt) {
|
|
883
897
|
this.#database
|
|
@@ -1799,7 +1799,7 @@ export class SqliteSessionMetadataStore {
|
|
|
1799
1799
|
}
|
|
1800
1800
|
});
|
|
1801
1801
|
}
|
|
1802
|
-
async reorderMessageAdmissions(sessionId, messageIds) {
|
|
1802
|
+
async reorderMessageAdmissions(sessionId, messageIds, disposition = 'followup') {
|
|
1803
1803
|
this.assertOpen();
|
|
1804
1804
|
assertSafeSessionId(sessionId);
|
|
1805
1805
|
const unique = [...new Set(messageIds)];
|
|
@@ -1813,13 +1813,13 @@ export class SqliteSessionMetadataStore {
|
|
|
1813
1813
|
.prepare(`
|
|
1814
1814
|
SELECT message_id
|
|
1815
1815
|
FROM message_admissions
|
|
1816
|
-
WHERE session_id = ? AND disposition =
|
|
1816
|
+
WHERE session_id = ? AND disposition = ?
|
|
1817
1817
|
ORDER BY queue_order, sequence
|
|
1818
1818
|
`)
|
|
1819
|
-
.all(sessionId);
|
|
1819
|
+
.all(sessionId, disposition);
|
|
1820
1820
|
const current = rows.map((row) => row.message_id);
|
|
1821
1821
|
const currentIds = new Set(current);
|
|
1822
|
-
if (current.length !== unique.length ||
|
|
1822
|
+
if ((disposition === 'followup' && current.length !== unique.length) ||
|
|
1823
1823
|
unique.some((messageId) => !currentIds.has(messageId))) {
|
|
1824
1824
|
throw new SessionMetadataConflictError('Message admission reorder identity conflict');
|
|
1825
1825
|
}
|
|
@@ -1828,7 +1828,14 @@ export class SqliteSessionMetadataStore {
|
|
|
1828
1828
|
SET queue_order = ?
|
|
1829
1829
|
WHERE session_id = ? AND message_id = ?
|
|
1830
1830
|
`);
|
|
1831
|
-
|
|
1831
|
+
// Older steering may already be in flight. Keep those entries in their
|
|
1832
|
+
// slots so recovery never interleaves them with a newly reordered batch.
|
|
1833
|
+
const selected = new Set(unique);
|
|
1834
|
+
let next = 0;
|
|
1835
|
+
current.forEach((messageId, index) => {
|
|
1836
|
+
const orderedId = selected.has(messageId) ? unique[next++] : messageId;
|
|
1837
|
+
update.run(index, sessionId, orderedId);
|
|
1838
|
+
});
|
|
1832
1839
|
});
|
|
1833
1840
|
}
|
|
1834
1841
|
async readCoordinationTranscriptIndexState() {
|
|
@@ -42,7 +42,8 @@ export async function readStableBoundedFile(input, dependencies = {}) {
|
|
|
42
42
|
}
|
|
43
43
|
try {
|
|
44
44
|
const initial = await stableFileSnapshot(handle, input, deps);
|
|
45
|
-
|
|
45
|
+
// One extra byte detects growth even if the file shrinks before the final stat.
|
|
46
|
+
const bytes = Buffer.allocUnsafe(Number(initial.size) + 1);
|
|
46
47
|
let offset = 0;
|
|
47
48
|
while (offset < bytes.length) {
|
|
48
49
|
const result = await handle.read(bytes, offset, bytes.length - offset, offset);
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
"./scheduled-task-store": "./dist/scheduled-task-store.js",
|
|
44
44
|
"./quiescent-session-snapshot": "./dist/quiescent-session-snapshot.js",
|
|
45
45
|
"./production-session-snapshot": "./dist/production-session-snapshot.js",
|
|
46
|
+
"./session-bundle-contract": "./dist/session-bundle-contract.js",
|
|
47
|
+
"./session-bundle-file-service": "./dist/session-bundle-file-service.js",
|
|
46
48
|
"./session-bundle-policy": "./dist/session-bundle-policy.js",
|
|
47
49
|
"./session-copy-cleanup": "./dist/session-copy-cleanup.js",
|
|
48
50
|
"./session-todo-authority": "./dist/session-todo-authority.js",
|
|
@@ -5552,6 +5552,22 @@ function requestStateAccessor(value) {
|
|
|
5552
5552
|
/** Shared no-state accessor: the common case allocates nothing per request. */
|
|
5553
5553
|
const NO_REQUEST_STATE = requestStateAccessor(void 0);
|
|
5554
5554
|
let writeNegotiatedProtocolVersion;
|
|
5555
|
+
// Separate scopes keep pending transport sends from retaining request arguments.
|
|
5556
|
+
function makaCancellationErrorObserver(protocol) {
|
|
5557
|
+
return (error) => protocol._onerror(new Error(`Failed to send cancellation: ${error}`));
|
|
5558
|
+
}
|
|
5559
|
+
function makaRequestErrorObserver(protocol, messageId, reject) {
|
|
5560
|
+
return {
|
|
5561
|
+
onError(error) {
|
|
5562
|
+
protocol._progressHandlers.delete(messageId);
|
|
5563
|
+
reject?.(error);
|
|
5564
|
+
},
|
|
5565
|
+
release() {
|
|
5566
|
+
// Native reject retains the settled promise graph until explicitly revoked.
|
|
5567
|
+
reject = void 0;
|
|
5568
|
+
}
|
|
5569
|
+
};
|
|
5570
|
+
}
|
|
5555
5571
|
/**
|
|
5556
5572
|
* Implements MCP protocol framing on top of a pluggable transport, including
|
|
5557
5573
|
* features like request/response linking, notifications, and progress.
|
|
@@ -6055,6 +6071,7 @@ var Protocol = class {
|
|
|
6055
6071
|
const flowStartedAt = Date.now();
|
|
6056
6072
|
let onAbort;
|
|
6057
6073
|
let cleanupMessageId;
|
|
6074
|
+
let sendObserver;
|
|
6058
6075
|
return new Promise((resolve, reject) => {
|
|
6059
6076
|
const earlyReject = (error) => {
|
|
6060
6077
|
reject(error);
|
|
@@ -6107,7 +6124,7 @@ var Protocol = class {
|
|
|
6107
6124
|
relatedRequestId,
|
|
6108
6125
|
resumptionToken,
|
|
6109
6126
|
onresumptiontoken
|
|
6110
|
-
}).catch((
|
|
6127
|
+
}).catch(makaCancellationErrorObserver(this));
|
|
6111
6128
|
else requestAbort.abort();
|
|
6112
6129
|
reject(reason instanceof SdkError ? reason : new SdkError(SdkErrorCode.RequestTimeout, String(reason)));
|
|
6113
6130
|
};
|
|
@@ -6148,17 +6165,17 @@ var Protocol = class {
|
|
|
6148
6165
|
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
6149
6166
|
const timeoutHandler = () => cancel(new SdkError(SdkErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
6150
6167
|
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
6168
|
+
sendObserver = makaRequestErrorObserver(this, messageId, reject);
|
|
6151
6169
|
this._transport.send(outbound, {
|
|
6152
6170
|
relatedRequestId,
|
|
6153
6171
|
resumptionToken,
|
|
6154
6172
|
onresumptiontoken,
|
|
6155
6173
|
headers,
|
|
6156
6174
|
requestSignal: requestAbort?.signal
|
|
6157
|
-
}).catch(
|
|
6158
|
-
this._progressHandlers.delete(messageId);
|
|
6159
|
-
reject(error);
|
|
6160
|
-
});
|
|
6175
|
+
}).catch(sendObserver.onError);
|
|
6161
6176
|
}).finally(() => {
|
|
6177
|
+
// Release request state without dropping queued frames or closing the connection.
|
|
6178
|
+
sendObserver?.release();
|
|
6162
6179
|
if (onAbort) options?.signal?.removeEventListener("abort", onAbort);
|
|
6163
6180
|
if (cleanupMessageId !== void 0) {
|
|
6164
6181
|
this._responseHandlers.delete(cleanupMessageId);
|
|
@@ -5553,6 +5553,22 @@ function requestStateAccessor(value) {
|
|
|
5553
5553
|
/** Shared no-state accessor: the common case allocates nothing per request. */
|
|
5554
5554
|
const NO_REQUEST_STATE = requestStateAccessor(void 0);
|
|
5555
5555
|
let writeNegotiatedProtocolVersion;
|
|
5556
|
+
// Separate scopes keep pending transport sends from retaining request arguments.
|
|
5557
|
+
function makaCancellationErrorObserver(protocol) {
|
|
5558
|
+
return (error) => protocol._onerror(new Error(`Failed to send cancellation: ${error}`));
|
|
5559
|
+
}
|
|
5560
|
+
function makaRequestErrorObserver(protocol, messageId, reject) {
|
|
5561
|
+
return {
|
|
5562
|
+
onError(error) {
|
|
5563
|
+
protocol._progressHandlers.delete(messageId);
|
|
5564
|
+
reject?.(error);
|
|
5565
|
+
},
|
|
5566
|
+
release() {
|
|
5567
|
+
// Native reject retains the settled promise graph until explicitly revoked.
|
|
5568
|
+
reject = void 0;
|
|
5569
|
+
}
|
|
5570
|
+
};
|
|
5571
|
+
}
|
|
5556
5572
|
/**
|
|
5557
5573
|
* Implements MCP protocol framing on top of a pluggable transport, including
|
|
5558
5574
|
* features like request/response linking, notifications, and progress.
|
|
@@ -6056,6 +6072,7 @@ var Protocol = class {
|
|
|
6056
6072
|
const flowStartedAt = Date.now();
|
|
6057
6073
|
let onAbort;
|
|
6058
6074
|
let cleanupMessageId;
|
|
6075
|
+
let sendObserver;
|
|
6059
6076
|
return new Promise((resolve, reject) => {
|
|
6060
6077
|
const earlyReject = (error) => {
|
|
6061
6078
|
reject(error);
|
|
@@ -6108,7 +6125,7 @@ var Protocol = class {
|
|
|
6108
6125
|
relatedRequestId,
|
|
6109
6126
|
resumptionToken,
|
|
6110
6127
|
onresumptiontoken
|
|
6111
|
-
}).catch((
|
|
6128
|
+
}).catch(makaCancellationErrorObserver(this));
|
|
6112
6129
|
else requestAbort.abort();
|
|
6113
6130
|
reject(reason instanceof SdkError ? reason : new SdkError(SdkErrorCode.RequestTimeout, String(reason)));
|
|
6114
6131
|
};
|
|
@@ -6149,17 +6166,17 @@ var Protocol = class {
|
|
|
6149
6166
|
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
6150
6167
|
const timeoutHandler = () => cancel(new SdkError(SdkErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
6151
6168
|
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
6169
|
+
sendObserver = makaRequestErrorObserver(this, messageId, reject);
|
|
6152
6170
|
this._transport.send(outbound, {
|
|
6153
6171
|
relatedRequestId,
|
|
6154
6172
|
resumptionToken,
|
|
6155
6173
|
onresumptiontoken,
|
|
6156
6174
|
headers,
|
|
6157
6175
|
requestSignal: requestAbort?.signal
|
|
6158
|
-
}).catch(
|
|
6159
|
-
this._progressHandlers.delete(messageId);
|
|
6160
|
-
reject(error);
|
|
6161
|
-
});
|
|
6176
|
+
}).catch(sendObserver.onError);
|
|
6162
6177
|
}).finally(() => {
|
|
6178
|
+
// Release request state without dropping queued frames or closing the connection.
|
|
6179
|
+
sendObserver?.release();
|
|
6163
6180
|
if (onAbort) options?.signal?.removeEventListener("abort", onAbort);
|
|
6164
6181
|
if (cleanupMessageId !== void 0) {
|
|
6165
6182
|
this._responseHandlers.delete(cleanupMessageId);
|
|
@@ -187,9 +187,6 @@ const memo = {
|
|
|
187
187
|
attach(inst) {
|
|
188
188
|
var _a;
|
|
189
189
|
let isRecursiveInst;
|
|
190
|
-
// `bucket` memoized for one parse; a recursive schema is re-entered many times and its bucket never changes
|
|
191
|
-
let lastCtx;
|
|
192
|
-
let lastBucket;
|
|
193
190
|
// Wraps `parse` in a deferred so it sees the container's final parse. Core's own deferred copies `parse` into `run` when there are no checks, and it ran first, so `run` is patched to match; with checks, `run` reads `parse` dynamically.
|
|
194
191
|
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
195
192
|
inst._zod.deferred.push(() => {
|
|
@@ -213,15 +210,7 @@ const memo = {
|
|
|
213
210
|
state = { buckets: new Map(), backEdges: undefined };
|
|
214
211
|
ctx[STATE] = state;
|
|
215
212
|
}
|
|
216
|
-
|
|
217
|
-
if (lastCtx === ctx) {
|
|
218
|
-
bucket = lastBucket;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
bucket = bucketFor(state, inst);
|
|
222
|
-
lastCtx = ctx;
|
|
223
|
-
lastBucket = bucket;
|
|
224
|
-
}
|
|
213
|
+
const bucket = bucketFor(state, inst);
|
|
225
214
|
const hit = bucket.get(input);
|
|
226
215
|
if (hit) {
|
|
227
216
|
payload.value = hit.value;
|
|
@@ -237,12 +226,19 @@ const memo = {
|
|
|
237
226
|
}
|
|
238
227
|
return payload;
|
|
239
228
|
}
|
|
229
|
+
const previousHandoff = handoff;
|
|
240
230
|
handoff = bucket;
|
|
241
231
|
const depth = open.length;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
232
|
+
let result;
|
|
233
|
+
let entry;
|
|
234
|
+
try {
|
|
235
|
+
result = base(payload, ctx);
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
handoff = previousHandoff;
|
|
239
|
+
// A container that rejected its input outright allocated nothing.
|
|
240
|
+
entry = open.length > depth ? open.pop() : undefined;
|
|
241
|
+
}
|
|
246
242
|
// Both paths written out so the sync one allocates no closure. It runs once per node, and capturing here cost more than everything else combined.
|
|
247
243
|
if (result instanceof Promise) {
|
|
248
244
|
return result.then((r) => {
|
|
@@ -180,9 +180,6 @@ const memo = {
|
|
|
180
180
|
attach(inst) {
|
|
181
181
|
var _a;
|
|
182
182
|
let isRecursiveInst;
|
|
183
|
-
// `bucket` memoized for one parse; a recursive schema is re-entered many times and its bucket never changes
|
|
184
|
-
let lastCtx;
|
|
185
|
-
let lastBucket;
|
|
186
183
|
// Wraps `parse` in a deferred so it sees the container's final parse. Core's own deferred copies `parse` into `run` when there are no checks, and it ran first, so `run` is patched to match; with checks, `run` reads `parse` dynamically.
|
|
187
184
|
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
188
185
|
inst._zod.deferred.push(() => {
|
|
@@ -206,15 +203,7 @@ const memo = {
|
|
|
206
203
|
state = { buckets: new Map(), backEdges: undefined };
|
|
207
204
|
ctx[STATE] = state;
|
|
208
205
|
}
|
|
209
|
-
|
|
210
|
-
if (lastCtx === ctx) {
|
|
211
|
-
bucket = lastBucket;
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
bucket = bucketFor(state, inst);
|
|
215
|
-
lastCtx = ctx;
|
|
216
|
-
lastBucket = bucket;
|
|
217
|
-
}
|
|
206
|
+
const bucket = bucketFor(state, inst);
|
|
218
207
|
const hit = bucket.get(input);
|
|
219
208
|
if (hit) {
|
|
220
209
|
payload.value = hit.value;
|
|
@@ -230,12 +219,19 @@ const memo = {
|
|
|
230
219
|
}
|
|
231
220
|
return payload;
|
|
232
221
|
}
|
|
222
|
+
const previousHandoff = handoff;
|
|
233
223
|
handoff = bucket;
|
|
234
224
|
const depth = open.length;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
225
|
+
let result;
|
|
226
|
+
let entry;
|
|
227
|
+
try {
|
|
228
|
+
result = base(payload, ctx);
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
handoff = previousHandoff;
|
|
232
|
+
// A container that rejected its input outright allocated nothing.
|
|
233
|
+
entry = open.length > depth ? open.pop() : undefined;
|
|
234
|
+
}
|
|
239
235
|
// Both paths written out so the sync one allocates no closure. It runs once per node, and capturing here cost more than everything else combined.
|
|
240
236
|
if (result instanceof Promise) {
|
|
241
237
|
return result.then((r) => {
|