@mcpmesh/sdk 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/jobs.spec.d.ts +2 -0
- package/dist/__tests__/jobs.spec.d.ts.map +1 -0
- package/dist/__tests__/jobs.spec.js +445 -0
- package/dist/__tests__/jobs.spec.js.map +1 -0
- package/dist/__tests__/llm-agent-model-params.test.d.ts +16 -0
- package/dist/__tests__/llm-agent-model-params.test.d.ts.map +1 -0
- package/dist/__tests__/llm-agent-model-params.test.js +229 -0
- package/dist/__tests__/llm-agent-model-params.test.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +221 -0
- package/dist/jobs.d.ts.map +1 -0
- package/dist/jobs.js +363 -0
- package/dist/jobs.js.map +1 -0
- package/dist/llm-agent.d.ts +3 -0
- package/dist/llm-agent.d.ts.map +1 -1
- package/dist/llm-agent.js +30 -2
- package/dist/llm-agent.js.map +1 -1
- package/dist/types.d.ts +33 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the `modelParams` escape-hatch — issue #1019.
|
|
3
|
+
*
|
|
4
|
+
* The TS SDK exposes a typed option surface (`maxOutputTokens`, `temperature`,
|
|
5
|
+
* `topP`, `stop`) that maps to wire `model_params` keys. For vendor-specific
|
|
6
|
+
* kwargs that the typed surface doesn't expose (e.g., Gemini `thinking_config`,
|
|
7
|
+
* Anthropic `output_config`, OpenAI `reasoning_effort`) callers can pass an
|
|
8
|
+
* arbitrary dict via `options.modelParams`. The dict is merged into the wire
|
|
9
|
+
* `model_params` BEFORE typed fields, so typed options always win on collision
|
|
10
|
+
* (keeping the typed surface authoritative).
|
|
11
|
+
*
|
|
12
|
+
* Covers both the buffered (`complete()`) and the streaming (`streamComplete()`)
|
|
13
|
+
* paths since both build `model_params` independently.
|
|
14
|
+
*/
|
|
15
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
16
|
+
vi.mock("@mcpmesh/core", () => ({
|
|
17
|
+
generateTraceId: () => "trace-mock",
|
|
18
|
+
generateSpanId: () => "span-mock",
|
|
19
|
+
injectTraceContext: (argsJson) => argsJson,
|
|
20
|
+
publishSpan: vi.fn(async () => false),
|
|
21
|
+
parseSseResponse: (s) => s,
|
|
22
|
+
parseSseResponseToObject: (s) => JSON.parse(s),
|
|
23
|
+
}));
|
|
24
|
+
vi.mock("../http-pool.js", () => ({
|
|
25
|
+
getDispatcher: () => undefined,
|
|
26
|
+
}));
|
|
27
|
+
import { MeshDelegatedProvider } from "../llm-agent.js";
|
|
28
|
+
function makeSseStream(blocks) {
|
|
29
|
+
const encoder = new TextEncoder();
|
|
30
|
+
let i = 0;
|
|
31
|
+
return new ReadableStream({
|
|
32
|
+
pull(controller) {
|
|
33
|
+
if (i < blocks.length) {
|
|
34
|
+
controller.enqueue(encoder.encode(blocks[i]));
|
|
35
|
+
i += 1;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
controller.close();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function sseEvent(payload) {
|
|
44
|
+
return `event: message\ndata: ${JSON.stringify(payload)}\n\n`;
|
|
45
|
+
}
|
|
46
|
+
function makeMockResponse(blocks) {
|
|
47
|
+
return {
|
|
48
|
+
ok: true,
|
|
49
|
+
status: 200,
|
|
50
|
+
statusText: "OK",
|
|
51
|
+
body: makeSseStream(blocks),
|
|
52
|
+
headers: {
|
|
53
|
+
get: (name) => name.toLowerCase() === "content-type" ? "text/event-stream" : null,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const ENDPOINT = "http://provider.local:9001";
|
|
58
|
+
const FN_BUFFERED = "process_chat";
|
|
59
|
+
const FN_STREAM = "process_chat_stream";
|
|
60
|
+
// ----------------------------------------------------------------------------
|
|
61
|
+
// complete() — buffered path
|
|
62
|
+
// ----------------------------------------------------------------------------
|
|
63
|
+
describe("MeshDelegatedProvider.complete() — modelParams escape hatch", () => {
|
|
64
|
+
let originalFetch;
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
originalFetch = globalThis.fetch;
|
|
67
|
+
});
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
globalThis.fetch = originalFetch;
|
|
70
|
+
vi.restoreAllMocks();
|
|
71
|
+
});
|
|
72
|
+
function mockJsonResponse(body) {
|
|
73
|
+
return {
|
|
74
|
+
ok: true,
|
|
75
|
+
status: 200,
|
|
76
|
+
statusText: "OK",
|
|
77
|
+
headers: {
|
|
78
|
+
get: (name) => name.toLowerCase() === "content-type" ? "application/json" : null,
|
|
79
|
+
},
|
|
80
|
+
text: async () => JSON.stringify(body),
|
|
81
|
+
json: async () => body,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function mcpToolResponse(payload) {
|
|
85
|
+
return {
|
|
86
|
+
jsonrpc: "2.0",
|
|
87
|
+
id: 1,
|
|
88
|
+
result: {
|
|
89
|
+
content: [{ type: "text", text: JSON.stringify(payload) }],
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// complete() expects the MCP content[0].text payload to be the
|
|
94
|
+
// mesh-provider shape: { role, content, tool_calls?, _mesh_usage? }
|
|
95
|
+
const STUB_COMPLETION = { role: "assistant", content: "ok" };
|
|
96
|
+
it("merges modelParams keys into the wire request's model_params", async () => {
|
|
97
|
+
let capturedBody;
|
|
98
|
+
const fetchMock = vi.fn(async (_url, init) => {
|
|
99
|
+
capturedBody = init.body;
|
|
100
|
+
return mockJsonResponse(mcpToolResponse(STUB_COMPLETION));
|
|
101
|
+
});
|
|
102
|
+
globalThis.fetch = fetchMock;
|
|
103
|
+
const provider = new MeshDelegatedProvider(ENDPOINT, FN_BUFFERED, false);
|
|
104
|
+
const messages = [{ role: "user", content: "hi" }];
|
|
105
|
+
await provider.complete("anthropic/claude-sonnet-4-5", messages, undefined, {
|
|
106
|
+
maxOutputTokens: 256,
|
|
107
|
+
modelParams: {
|
|
108
|
+
thinking_config: { thinking_budget: 0 },
|
|
109
|
+
reasoning_effort: "high",
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const body = JSON.parse(capturedBody);
|
|
113
|
+
const request = body.params.arguments.request;
|
|
114
|
+
const modelParams = request.model_params;
|
|
115
|
+
expect(modelParams.thinking_config).toEqual({ thinking_budget: 0 });
|
|
116
|
+
expect(modelParams.reasoning_effort).toBe("high");
|
|
117
|
+
// Typed fields still flow through
|
|
118
|
+
expect(modelParams.max_tokens).toBe(256);
|
|
119
|
+
expect(modelParams.model).toBe("anthropic/claude-sonnet-4-5");
|
|
120
|
+
});
|
|
121
|
+
it("typed options win over modelParams on collision", async () => {
|
|
122
|
+
let capturedBody;
|
|
123
|
+
const fetchMock = vi.fn(async (_url, init) => {
|
|
124
|
+
capturedBody = init.body;
|
|
125
|
+
return mockJsonResponse(mcpToolResponse(STUB_COMPLETION));
|
|
126
|
+
});
|
|
127
|
+
globalThis.fetch = fetchMock;
|
|
128
|
+
const provider = new MeshDelegatedProvider(ENDPOINT, FN_BUFFERED, false);
|
|
129
|
+
const messages = [{ role: "user", content: "hi" }];
|
|
130
|
+
await provider.complete("anthropic/claude-sonnet-4-5", messages, undefined, {
|
|
131
|
+
temperature: 0.5,
|
|
132
|
+
maxOutputTokens: 200,
|
|
133
|
+
modelParams: {
|
|
134
|
+
temperature: 0.9, // caller tried to set via escape hatch — typed wins
|
|
135
|
+
max_tokens: 999, // caller used the wire-name; typed maxOutputTokens wins
|
|
136
|
+
thinking_config: { thinking_budget: 0 },
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
const body = JSON.parse(capturedBody);
|
|
140
|
+
const modelParams = body.params.arguments.request.model_params;
|
|
141
|
+
expect(modelParams.temperature).toBe(0.5);
|
|
142
|
+
expect(modelParams.max_tokens).toBe(200);
|
|
143
|
+
// Untouched vendor-specific keys flow through
|
|
144
|
+
expect(modelParams.thinking_config).toEqual({ thinking_budget: 0 });
|
|
145
|
+
});
|
|
146
|
+
it("vendor-specific keys flow through untouched (no key translation)", async () => {
|
|
147
|
+
let capturedBody;
|
|
148
|
+
const fetchMock = vi.fn(async (_url, init) => {
|
|
149
|
+
capturedBody = init.body;
|
|
150
|
+
return mockJsonResponse(mcpToolResponse(STUB_COMPLETION));
|
|
151
|
+
});
|
|
152
|
+
globalThis.fetch = fetchMock;
|
|
153
|
+
const provider = new MeshDelegatedProvider(ENDPOINT, FN_BUFFERED, false);
|
|
154
|
+
const messages = [{ role: "user", content: "hi" }];
|
|
155
|
+
await provider.complete("anthropic/claude-sonnet-4-5", messages, undefined, {
|
|
156
|
+
modelParams: {
|
|
157
|
+
output_config: { format: { type: "json_schema", schema: { type: "object" } } },
|
|
158
|
+
extra_headers: { "x-vendor-flag": "1" },
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
const body = JSON.parse(capturedBody);
|
|
162
|
+
const modelParams = body.params.arguments.request.model_params;
|
|
163
|
+
expect(modelParams.output_config).toEqual({
|
|
164
|
+
format: { type: "json_schema", schema: { type: "object" } },
|
|
165
|
+
});
|
|
166
|
+
expect(modelParams.extra_headers).toEqual({ "x-vendor-flag": "1" });
|
|
167
|
+
});
|
|
168
|
+
it("absent modelParams → behavior unchanged (no model_params keys leak)", async () => {
|
|
169
|
+
let capturedBody;
|
|
170
|
+
const fetchMock = vi.fn(async (_url, init) => {
|
|
171
|
+
capturedBody = init.body;
|
|
172
|
+
return mockJsonResponse(mcpToolResponse(STUB_COMPLETION));
|
|
173
|
+
});
|
|
174
|
+
globalThis.fetch = fetchMock;
|
|
175
|
+
const provider = new MeshDelegatedProvider(ENDPOINT, FN_BUFFERED, false);
|
|
176
|
+
const messages = [{ role: "user", content: "hi" }];
|
|
177
|
+
// No options at all; model="default" so no model_params should be emitted.
|
|
178
|
+
await provider.complete("default", messages);
|
|
179
|
+
const body = JSON.parse(capturedBody);
|
|
180
|
+
const request = body.params.arguments.request;
|
|
181
|
+
expect(request.model_params).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
// ----------------------------------------------------------------------------
|
|
185
|
+
// streamComplete() — streaming path
|
|
186
|
+
// ----------------------------------------------------------------------------
|
|
187
|
+
describe("MeshDelegatedProvider.streamComplete() — modelParams escape hatch", () => {
|
|
188
|
+
let originalFetch;
|
|
189
|
+
beforeEach(() => {
|
|
190
|
+
originalFetch = globalThis.fetch;
|
|
191
|
+
});
|
|
192
|
+
afterEach(() => {
|
|
193
|
+
globalThis.fetch = originalFetch;
|
|
194
|
+
vi.restoreAllMocks();
|
|
195
|
+
});
|
|
196
|
+
async function drain(gen) {
|
|
197
|
+
const out = [];
|
|
198
|
+
for await (const c of gen)
|
|
199
|
+
out.push(c);
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
it("merges modelParams into the streaming request and lets typed options win", async () => {
|
|
203
|
+
let capturedBody;
|
|
204
|
+
const fetchMock = vi.fn(async (_url, init) => {
|
|
205
|
+
capturedBody = init.body;
|
|
206
|
+
const body = JSON.parse(capturedBody);
|
|
207
|
+
const reqId = body.id;
|
|
208
|
+
return makeMockResponse([
|
|
209
|
+
sseEvent({ jsonrpc: "2.0", id: reqId, result: { content: [{ type: "text", text: "" }] } }),
|
|
210
|
+
]);
|
|
211
|
+
});
|
|
212
|
+
globalThis.fetch = fetchMock;
|
|
213
|
+
const provider = new MeshDelegatedProvider(ENDPOINT, FN_STREAM, false);
|
|
214
|
+
const messages = [{ role: "user", content: "hi" }];
|
|
215
|
+
await drain(provider.streamComplete("anthropic/claude-sonnet-4-5", messages, undefined, {
|
|
216
|
+
temperature: 0.4,
|
|
217
|
+
modelParams: {
|
|
218
|
+
temperature: 0.9, // typed wins
|
|
219
|
+
thinking_config: { thinking_budget: 0 }, // flows through
|
|
220
|
+
},
|
|
221
|
+
}));
|
|
222
|
+
const body = JSON.parse(capturedBody);
|
|
223
|
+
const modelParams = body.params.arguments.request.model_params;
|
|
224
|
+
expect(modelParams.temperature).toBe(0.4);
|
|
225
|
+
expect(modelParams.thinking_config).toEqual({ thinking_budget: 0 });
|
|
226
|
+
expect(modelParams.model).toBe("anthropic/claude-sonnet-4-5");
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
//# sourceMappingURL=llm-agent-model-params.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-agent-model-params.test.js","sourceRoot":"","sources":["../../src/__tests__/llm-agent-model-params.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEzE,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAC9B,eAAe,EAAE,GAAG,EAAE,CAAC,YAAY;IACnC,cAAc,EAAE,GAAG,EAAE,CAAC,WAAW;IACjC,kBAAkB,EAAE,CAAC,QAAgB,EAAE,EAAE,CAAC,QAAQ;IAClD,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC;IACrC,gBAAgB,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC;IAClC,wBAAwB,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;CACvD,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC;IAChC,aAAa,EAAE,GAAG,EAAE,CAAC,SAAS;CAC/B,CAAC,CAAC,CAAC;AAEJ,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,SAAS,aAAa,CA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AAC,OAAO,CAAC,YAAuC,CAAC;QAC1F,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC,CAAC;QACpE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ import { llm } from "./llm.js";
|
|
|
56
56
|
import { llmProvider } from "./llm-provider.js";
|
|
57
57
|
import { sseStream } from "./sse-stream.js";
|
|
58
58
|
import { mount as a2aMount } from "./a2a/producer/index.js";
|
|
59
|
+
import { postEvent as jobsPostEvent, subscribeEvents as jobsSubscribeEvents } from "./jobs.js";
|
|
59
60
|
/**
|
|
60
61
|
* `mesh.a2a` namespace — A2A v1.0 producer surface (issue #933).
|
|
61
62
|
*
|
|
@@ -71,6 +72,18 @@ interface MeshA2ANamespace {
|
|
|
71
72
|
*/
|
|
72
73
|
mount: typeof a2aMount;
|
|
73
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* `mesh.jobs` namespace — MeshJob event-injection convenience helpers
|
|
77
|
+
* (mirrors Python's `mesh.jobs` submodule shipped via PR #1041 for
|
|
78
|
+
* issue #1032). The `postEvent` helper lets MCP tool bodies push an
|
|
79
|
+
* event into a running job by id without holding a `JobProxy` reference
|
|
80
|
+
* in scope (the SDK resolves the registry URL from
|
|
81
|
+
* `MCP_MESH_REGISTRY_URL` and reuses a process-cached `JobProxy`).
|
|
82
|
+
*/
|
|
83
|
+
interface MeshJobsNamespace {
|
|
84
|
+
postEvent: typeof jobsPostEvent;
|
|
85
|
+
subscribeEvents: typeof jobsSubscribeEvents;
|
|
86
|
+
}
|
|
74
87
|
interface MeshNamespace {
|
|
75
88
|
(server: import("fastmcp").FastMCP, config: import("./types.js").AgentConfig): MeshAgent;
|
|
76
89
|
route: typeof route;
|
|
@@ -85,6 +98,8 @@ interface MeshNamespace {
|
|
|
85
98
|
sseStream: typeof sseStream;
|
|
86
99
|
/** A2A v1.0 producer surface (issue #933). */
|
|
87
100
|
a2a: MeshA2ANamespace;
|
|
101
|
+
/** MeshJob event-injection helpers (mirrors Python `mesh.jobs`). */
|
|
102
|
+
jobs: MeshJobsNamespace;
|
|
88
103
|
}
|
|
89
104
|
/**
|
|
90
105
|
* Main mesh function with route and llm helpers attached.
|
|
@@ -128,6 +143,7 @@ export { readJobHeaders, runWithJobContext, makeJobController, } from "./inbound
|
|
|
128
143
|
export { ClaimDispatcher, type ClaimHandler, } from "./claim-dispatcher.js";
|
|
129
144
|
export { registerJobHelperTools } from "./jobs-helper-tools.js";
|
|
130
145
|
export { registerCancelRoute } from "./jobs-cancel-route.js";
|
|
146
|
+
export { postEvent, subscribeEvents, JobNotFoundError, JobTerminalError, type JobEvent, type JobEventReceipt, type SubscribeEventsOptions, } from "./jobs.js";
|
|
131
147
|
export { JobController, JobProxy } from "@mcpmesh/core";
|
|
132
148
|
export { A2AClient, A2AJob, A2AStream, A2ABearer, A2AError, A2ATimeoutError, A2AAuthError, A2AJobError, A2AJobFailedError, A2AJobCanceledError, type A2AClientConfig, type A2ABearerConfig, type A2AMessage, type A2AResponse, type A2ATaskEnvelope, type A2AEvent, type A2AEventKind, } from "./a2a/index.js";
|
|
133
149
|
export { A2AProducerRegistry, A2ATaskStore, buildAgentCard, buildBearerAuthMiddleware, buildCompletedTask, buildDispatcherMiddleware, buildFailedTask, buildWorkingTask, stringifyResult, TERMINAL_EVICTION_MS, DEFAULT_INPUT_MODES as A2A_DEFAULT_INPUT_MODES, DEFAULT_OUTPUT_MODES as A2A_DEFAULT_OUTPUT_MODES, JSONRPC_AUTH_ERROR as A2A_JSONRPC_AUTH_ERROR, JSONRPC_PARSE_ERROR as A2A_JSONRPC_PARSE_ERROR, JSONRPC_INVALID_REQUEST as A2A_JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND as A2A_JSONRPC_METHOD_NOT_FOUND, JSONRPC_INVALID_PARAMS as A2A_JSONRPC_INVALID_PARAMS, type A2AMountConfig, type A2ASurfaceMetadata, type A2ADependencies, type A2AHandler, type CardRenderContext as A2ACardRenderContext, type TaskRecord as A2ATaskRecord, } from "./a2a/producer/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAkB,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAkB,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,m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BAAwB,IAAI,4BAA4B,EACxD,sBAAsB,IAAI,0BAA0B,EACpD,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,iBAAiB,IAAI,oBAAoB,EAC9C,KAAK,UAAU,IAAI,aAAa,GACjC,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,YAAY,EAAE,8BAA8B;AAC5C,aAAa,EACb,WAAW,EACX,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,iBAAiB,EAEjB,eAAe,EACf,aAAa,EACb,aAAa,EACb,OAAO,EACP,WAAW,EACX,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,QAAQ,EACR,cAAc,EACd,YAAY,EAEZ,eAAe,EACf,cAAc,EACd,aAAa,EAEb,cAAc,EACd,YAAY,EACZ,eAAe,EACf,iBAAiB,EAEjB,cAAc,EAEd,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,eAAe,IAAI,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,12 @@ import { llm } from "./llm.js";
|
|
|
56
56
|
import { llmProvider } from "./llm-provider.js";
|
|
57
57
|
import { sseStream } from "./sse-stream.js";
|
|
58
58
|
import { mount as a2aMount } from "./a2a/producer/index.js";
|
|
59
|
+
import { postEvent as jobsPostEvent, subscribeEvents as jobsSubscribeEvents, } from "./jobs.js";
|
|
59
60
|
const a2a = { mount: a2aMount };
|
|
61
|
+
const jobs = {
|
|
62
|
+
postEvent: jobsPostEvent,
|
|
63
|
+
subscribeEvents: jobsSubscribeEvents,
|
|
64
|
+
};
|
|
60
65
|
/**
|
|
61
66
|
* Main mesh function with route and llm helpers attached.
|
|
62
67
|
*
|
|
@@ -75,6 +80,7 @@ const mesh = Object.assign(meshFn, {
|
|
|
75
80
|
llmProvider,
|
|
76
81
|
sseStream,
|
|
77
82
|
a2a,
|
|
83
|
+
jobs,
|
|
78
84
|
});
|
|
79
85
|
// Main API
|
|
80
86
|
export { mesh, MeshAgent };
|
|
@@ -132,6 +138,12 @@ export { readJobHeaders, runWithJobContext, makeJobController, } from "./inbound
|
|
|
132
138
|
export { ClaimDispatcher, } from "./claim-dispatcher.js";
|
|
133
139
|
export { registerJobHelperTools } from "./jobs-helper-tools.js";
|
|
134
140
|
export { registerCancelRoute } from "./jobs-cancel-route.js";
|
|
141
|
+
// MeshJob event-injection helpers + typed errors (mirrors Python
|
|
142
|
+
// `mesh.jobs` shipped via PR #1041 for issue #1032). The
|
|
143
|
+
// `mesh.jobs.postEvent` helper is the primary surface; the error
|
|
144
|
+
// classes are exported so consumers can `instanceof`-discriminate
|
|
145
|
+
// against the napi binding's generic Error.
|
|
146
|
+
export { postEvent, subscribeEvents, JobNotFoundError, JobTerminalError, } from "./jobs.js";
|
|
135
147
|
// Re-export napi-rs job primitives for users who want to drop down
|
|
136
148
|
// to the underlying handles directly (e.g. constructing a JobProxy
|
|
137
149
|
// from a known job_id).
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,C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 -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public `mesh.jobs` namespace — convenience helpers for the MeshJob
|
|
3
|
+
* event-injection primitive (Phase 1, MeshJob substrate; event-channel
|
|
4
|
+
* extension landed in v2.2).
|
|
5
|
+
*
|
|
6
|
+
* The primary surfaces are:
|
|
7
|
+
*
|
|
8
|
+
* - {@link postEvent} — fire-and-forget helper to push an event into a
|
|
9
|
+
* running job by id, without holding a `JobProxy` reference. Intended
|
|
10
|
+
* for MCP tool bodies that receive a `jobId` in their request payload
|
|
11
|
+
* (e.g. a "submit_user_input" tool exposed by an orchestrator agent).
|
|
12
|
+
*
|
|
13
|
+
* - {@link JobNotFoundError} / {@link JobTerminalError} — typed `Error`
|
|
14
|
+
* subclasses translated from the Rust core's `JobError` variants. The
|
|
15
|
+
* napi binding surfaces all `JobError` variants as a plain `Error`
|
|
16
|
+
* today (see `src/runtime/core/src/jobs_napi.rs::job_error_to_napi`),
|
|
17
|
+
* so we re-classify on the TypeScript side via stable
|
|
18
|
+
* error-message substrings ("job is terminal" / "job not found").
|
|
19
|
+
*
|
|
20
|
+
* The `JobController` / `JobProxy` napi-rs classes from `@mcpmesh/core`
|
|
21
|
+
* already expose `recvEvent` / `sendEvent` methods directly — application
|
|
22
|
+
* code calls them via the `MeshJob`-typed parameter the framework
|
|
23
|
+
* injects. This module just adds the helper + error classes around that
|
|
24
|
+
* surface, mirroring Python's `mesh.jobs.post_event` API one-for-one.
|
|
25
|
+
*/
|
|
26
|
+
import { JobProxy } from "@mcpmesh/core";
|
|
27
|
+
/**
|
|
28
|
+
* Event posted into a running job's event log. Matches the OpenAPI
|
|
29
|
+
* `JobEvent` schema field-for-field (and the Rust `JobEvent` /
|
|
30
|
+
* Python `job_event_to_pydict` shape). Returned by `JobController.recvEvent`.
|
|
31
|
+
*/
|
|
32
|
+
export interface JobEvent {
|
|
33
|
+
/** Server-assigned job UUID this event belongs to. */
|
|
34
|
+
job_id: string;
|
|
35
|
+
/** Per-job monotonic sequence number assigned by the registry. */
|
|
36
|
+
seq: number;
|
|
37
|
+
/** User-supplied event type tag (e.g. "signal", "user_input"). */
|
|
38
|
+
type: string;
|
|
39
|
+
/** Arbitrary JSON-shaped payload carried with the event (or `null`). */
|
|
40
|
+
payload: unknown;
|
|
41
|
+
/** W3C trace context propagated by the poster (or `null`). */
|
|
42
|
+
trace_context: unknown;
|
|
43
|
+
/** Identifier of the agent that posted the event (or `null`). */
|
|
44
|
+
posted_by: string | null;
|
|
45
|
+
/** Unix epoch seconds at which the registry created the row. */
|
|
46
|
+
created_at: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Receipt returned by `JobProxy.sendEvent` / `postEvent`. Matches the
|
|
50
|
+
* OpenAPI `JobEventPostResponse` schema field-for-field.
|
|
51
|
+
*/
|
|
52
|
+
export interface JobEventReceipt {
|
|
53
|
+
/** Server-assigned job UUID the event was posted into. */
|
|
54
|
+
job_id: string;
|
|
55
|
+
/** Per-job monotonic sequence number assigned by the registry. */
|
|
56
|
+
seq: number;
|
|
57
|
+
/** Unix epoch seconds at which the registry created the row. */
|
|
58
|
+
created_at: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The targeted job does not exist (or has been swept) in the registry.
|
|
62
|
+
*
|
|
63
|
+
* Translated from the Rust `JobError::Other(BackendError::NotFound)`
|
|
64
|
+
* path (`GET/POST /jobs/{id}/events` → HTTP 404).
|
|
65
|
+
*/
|
|
66
|
+
export declare class JobNotFoundError extends Error {
|
|
67
|
+
readonly name = "JobNotFoundError";
|
|
68
|
+
constructor(message: string);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The targeted job is in a terminal state (completed / failed /
|
|
72
|
+
* cancelled) and no longer accepts events.
|
|
73
|
+
*
|
|
74
|
+
* Translated from the Rust `JobError::JobTerminal` variant — the
|
|
75
|
+
* registry returns HTTP 409 once the job row is terminal and the Rust
|
|
76
|
+
* layer maps that to `JobTerminal`.
|
|
77
|
+
*/
|
|
78
|
+
export declare class JobTerminalError extends Error {
|
|
79
|
+
readonly name = "JobTerminalError";
|
|
80
|
+
constructor(message: string);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Re-classify a generic `Error` raised by the napi layer into one of the
|
|
84
|
+
* typed subclasses, if the message matches. Returns the original error
|
|
85
|
+
* (or a typed clone) — callers should `throw` the returned value.
|
|
86
|
+
*
|
|
87
|
+
* Exported so tests can exercise the substring contract without a real
|
|
88
|
+
* napi failure path.
|
|
89
|
+
*/
|
|
90
|
+
export declare function translateJobError(err: unknown): unknown;
|
|
91
|
+
/**
|
|
92
|
+
* Return a process-cached `JobProxy` for the given
|
|
93
|
+
* `(registryUrl, jobId)` pair, constructing one on first miss.
|
|
94
|
+
*
|
|
95
|
+
* Cache is a bounded LRU: hits bump the entry to the most-recent end of
|
|
96
|
+
* the insertion-order map, misses on a full cache evict the
|
|
97
|
+
* least-recent entry before inserting. Exported only for tests; not
|
|
98
|
+
* part of the public API.
|
|
99
|
+
*/
|
|
100
|
+
export declare function _getOrCreateProxy(registryUrl: string, jobId: string): JobProxy;
|
|
101
|
+
/**
|
|
102
|
+
* Clear the JobProxy cache. Exposed for tests — not part of the public
|
|
103
|
+
* API. Equivalent to dropping all entries; the underlying napi handles
|
|
104
|
+
* are released when JS GC runs.
|
|
105
|
+
*/
|
|
106
|
+
export declare function _clearProxyCache(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Post an event to a running job by ID.
|
|
109
|
+
*
|
|
110
|
+
* Convenience helper for tool bodies that hold a `jobId` (e.g. from a
|
|
111
|
+
* request body, a token lookup, or a stashed reference) but do NOT
|
|
112
|
+
* have a `JobProxy` reference in scope. Constructs (or reuses, via the
|
|
113
|
+
* LRU cache) a `JobProxy` bound to the current agent's registry URL
|
|
114
|
+
* and forwards the call.
|
|
115
|
+
*
|
|
116
|
+
* Mirrors Python's `mesh.jobs.post_event` API one-for-one.
|
|
117
|
+
*
|
|
118
|
+
* @param jobId - Target job's server-assigned id.
|
|
119
|
+
* @param eventType - Event type tag (e.g. `"extend_deadline"`,
|
|
120
|
+
* `"user_input"`, or any user-defined string). The running handler
|
|
121
|
+
* can filter via `await job.recvEvent(["..."])`.
|
|
122
|
+
* @param payload - Optional JSON-serializable payload carried with the
|
|
123
|
+
* event. `undefined`/`null` is normalized to an empty object before
|
|
124
|
+
* forwarding — the Rust layer accepts either.
|
|
125
|
+
* @returns Receipt `{ job_id, seq, created_at }`. `seq` is the
|
|
126
|
+
* server-assigned sequence number useful for stitching follow-up
|
|
127
|
+
* `recvEvent` calls.
|
|
128
|
+
*
|
|
129
|
+
* @throws {@link JobNotFoundError} If the registry doesn't know the
|
|
130
|
+
* job (sweep already removed it, or wrong id).
|
|
131
|
+
* @throws {@link JobTerminalError} If the job has already reached a
|
|
132
|
+
* terminal state — no more events accepted.
|
|
133
|
+
* @throws Error For transport errors (registry unreachable, 5xx after
|
|
134
|
+
* retries, malformed payload, etc.) — the underlying error message
|
|
135
|
+
* is preserved.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* Inside an MCP tool body that holds a job id:
|
|
139
|
+
* ```ts
|
|
140
|
+
* agent.addTool({
|
|
141
|
+
* name: "submit_user_input",
|
|
142
|
+
* capability: "submit_user_input",
|
|
143
|
+
* parameters: z.object({ jobId: z.string(), text: z.string() }),
|
|
144
|
+
* execute: async ({ jobId, text }) => {
|
|
145
|
+
* const receipt = await mesh.jobs.postEvent(
|
|
146
|
+
* jobId,
|
|
147
|
+
* "user_input",
|
|
148
|
+
* { text },
|
|
149
|
+
* );
|
|
150
|
+
* return { posted_seq: receipt.seq };
|
|
151
|
+
* },
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function postEvent(jobId: string, eventType: string, payload?: unknown): Promise<JobEventReceipt>;
|
|
156
|
+
/**
|
|
157
|
+
* Options for {@link subscribeEvents}. All fields are optional —
|
|
158
|
+
* defaults match Python's `mesh.jobs.subscribe_events` keyword args.
|
|
159
|
+
*/
|
|
160
|
+
export interface SubscribeEventsOptions {
|
|
161
|
+
/**
|
|
162
|
+
* Optional event-type filter applied server-side. Only events whose
|
|
163
|
+
* `type` matches one of these is yielded. Omit for all types.
|
|
164
|
+
*/
|
|
165
|
+
types?: string[];
|
|
166
|
+
/**
|
|
167
|
+
* Initial cursor (default `0` ≡ from the beginning of the event log).
|
|
168
|
+
* Pass a higher value to skip historical events. Accepts both
|
|
169
|
+
* `number` and `bigint` for callers stitching from an `i64`-sourced
|
|
170
|
+
* cursor.
|
|
171
|
+
*/
|
|
172
|
+
after?: number | bigint;
|
|
173
|
+
/**
|
|
174
|
+
* Long-poll wait budget per registry call (in seconds). Default `30`.
|
|
175
|
+
* Capped at `60` by the registry. Pass `null` to skip the long-poll
|
|
176
|
+
* entirely (single immediate read; rarely needed — tight-poll callers
|
|
177
|
+
* should pass `0` instead).
|
|
178
|
+
*/
|
|
179
|
+
longPollSecs?: number | null;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Subscribe to events posted to a running job by ID.
|
|
183
|
+
*
|
|
184
|
+
* Long-lived async iterator. Each call manages its own cursor —
|
|
185
|
+
* multiple subscribers can observe the same job's events independently
|
|
186
|
+
* without affecting the producer's `recvEvent` consumption (the
|
|
187
|
+
* producer's cursor is per-controller; this observer's cursor is
|
|
188
|
+
* per-call).
|
|
189
|
+
*
|
|
190
|
+
* The iterator runs indefinitely until the caller breaks out of the
|
|
191
|
+
* `for await` loop or the underlying registry returns
|
|
192
|
+
* {@link JobNotFoundError}. There is no automatic terminal-state
|
|
193
|
+
* detection — use a synthetic event type (e.g. `{ type: "ended" }`)
|
|
194
|
+
* posted by your application to signal iteration end.
|
|
195
|
+
*
|
|
196
|
+
* Mirrors Python's `mesh.jobs.subscribe_events` one-for-one.
|
|
197
|
+
*
|
|
198
|
+
* @param jobId - Target job's server-assigned id.
|
|
199
|
+
* @param options - Optional filter / cursor / long-poll knobs.
|
|
200
|
+
* @yields Event objects: `{ seq, type, payload, trace_context,
|
|
201
|
+
* posted_by, created_at, job_id }`.
|
|
202
|
+
*
|
|
203
|
+
* @throws {@link JobNotFoundError} If the job has been reaped from the
|
|
204
|
+
* registry (404 on the `GET /jobs/{id}/events` endpoint).
|
|
205
|
+
* @throws Error For transport errors (registry unreachable, 5xx after
|
|
206
|
+
* retries, malformed payload, etc.) — the underlying error message
|
|
207
|
+
* is preserved.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* Mirror events from a running job into a downstream system:
|
|
211
|
+
* ```ts
|
|
212
|
+
* for await (const event of mesh.jobs.subscribeEvents(jobId, {
|
|
213
|
+
* types: ["progress", "result"],
|
|
214
|
+
* })) {
|
|
215
|
+
* await downstream.publish(event);
|
|
216
|
+
* if (event.type === "result") break; // caller-defined termination
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function subscribeEvents(jobId: string, options?: SubscribeEventsOptions): AsyncGenerator<JobEvent, void, unknown>;
|
|
221
|
+
//# sourceMappingURL=jobs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobs.d.ts","sourceRoot":"","sources":["../src/jobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,aAAa,EAAE,OAAO,CAAC;IACvB,iEAAiE;IACjE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAC;CACp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