marona 2.1.0 → 2.4.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/CHANGELOG.md +13 -0
- package/README.md +81 -43
- package/dist/b2a-codec.d.ts +44 -0
- package/dist/b2a-codec.d.ts.map +1 -0
- package/dist/b2a-codec.js +194 -0
- package/dist/b2a-codec.js.map +1 -0
- package/dist/b2a-runner.d.ts +74 -0
- package/dist/b2a-runner.d.ts.map +1 -0
- package/dist/b2a-runner.js +218 -0
- package/dist/b2a-runner.js.map +1 -0
- package/dist/b2a.d.ts +1 -0
- package/dist/b2a.d.ts.map +1 -1
- package/dist/b2a.js +1 -0
- package/dist/b2a.js.map +1 -1
- package/dist/index.d.ts +30 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +77 -1
- package/dist/index.js.map +1 -1
- package/dist/protocols.d.ts +18 -0
- package/dist/protocols.d.ts.map +1 -0
- package/dist/protocols.js +24 -0
- package/dist/protocols.js.map +1 -0
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## 2.3.0 — 2026-11-11
|
|
2
|
+
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
- Add extensible Agent protocols and unified Runner.connect / Runner.run dispatch.
|
|
6
|
+
- Validate structured B2A responses before encoding and return typed or schema-validated output.
|
|
7
|
+
- Add protocol selection, extension interfaces, persistent and single-run package examples.
|
|
8
|
+
- Keep the previous B2A configuration and runner entry points for compatibility.
|
|
9
|
+
|
|
10
|
+
- Add Agent-bound B2A configuration and B2ARunner persistent sessions with user/session identity.
|
|
11
|
+
- Add independent HTTP/MCP codec providers, typed feedback events, delivery acknowledgment, and automatic protocol state management.
|
|
12
|
+
- Replace manual B2A workflow examples with the runner API.
|
|
13
|
+
|
|
1
14
|
# 2.0.1 — 2026-10-24
|
|
2
15
|
|
|
3
16
|
## 2.1.0 — 2026-11-11
|
package/README.md
CHANGED
|
@@ -5,12 +5,12 @@ Hub capabilities, streaming, realtime and A2A collaboration.
|
|
|
5
5
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
8
|
-
Version **2.
|
|
8
|
+
Version **2.4.0**. [Package registry](https://www.npmjs.com/package/marona/v/2.4.0).
|
|
9
9
|
|
|
10
10
|
Node.js 20+; run this server example with tsx.
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
npm install marona@2.
|
|
13
|
+
npm install marona@2.4.0
|
|
14
14
|
npm install --save-dev typescript tsx @types/node
|
|
15
15
|
```
|
|
16
16
|
|
|
@@ -147,51 +147,92 @@ Push notifications are not implemented.
|
|
|
147
147
|
Native B2A v0.1 exchanges decoded semantic intent and agent responses. The
|
|
148
148
|
independent neural service owns signal decoding and feedback encoding, with
|
|
149
149
|
vendor-hosted MCP, HTTP or local plugin backends. Models and device drivers
|
|
150
|
-
are supplied by the interface provider
|
|
150
|
+
are supplied by the interface provider. Configure `Agent.protocols` and connect with
|
|
151
|
+
`Runner.connect`, following the persistent realtime session lifecycle. These examples
|
|
152
|
+
read one captured signal file using your configured provider.
|
|
153
|
+
|
|
154
|
+
One configured protocol is selected automatically. With several configured protocols,
|
|
155
|
+
select by name (`protocol="b2a"` in Python, the corresponding option/overload in
|
|
156
|
+
other SDKs). Duplicate names and ambiguous selection are rejected. Implement
|
|
157
|
+
`AgentProtocol` to add another protocol without adding Agent properties. Existing
|
|
158
|
+
A2A peers and servers retain their agent-to-agent role; they are not automatically
|
|
159
|
+
converted into input protocols. `Agent.b2a` and `B2ARunner` remain compatibility APIs.
|
|
151
160
|
|
|
152
161
|
Save as `examples/b2a_example.mts`:
|
|
153
162
|
|
|
154
163
|
```typescript
|
|
155
|
-
import { readFile } from
|
|
156
|
-
import {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
consent: { granted: true, scopes: ["intent", "feedback", "context"] },
|
|
169
|
-
capabilities: { input: ["semantic.intent"], output: ["application/json"] },
|
|
170
|
-
agent: { name: "B2A Assistant", model: process.env.MARONA_MODEL ?? "marona/auto",
|
|
171
|
-
instructions: "Interpret the decoded intent in context. Preserve uncertainty and ask when clarification is needed." },
|
|
172
|
-
context: { source: "decoder-output-example" },
|
|
164
|
+
import { readFile } from 'node:fs/promises';
|
|
165
|
+
import { Agent, B2A, B2ACodec, Runner, Marona } from 'marona';
|
|
166
|
+
const env = process.env;
|
|
167
|
+
const signal = JSON.parse(await readFile(process.argv[2]!, 'utf8'));
|
|
168
|
+
const client = new Marona({ apiKey: env.MARONA_API_KEY });
|
|
169
|
+
const neuralService = new B2ACodec(env.B2A_CODEC_URL!, {
|
|
170
|
+
token: env.B2A_NEURAL_TOKEN!, transport: (env.B2A_CODEC_TRANSPORT ?? 'mcp') as 'mcp' | 'http',
|
|
171
|
+
});
|
|
172
|
+
const agent = new Agent({
|
|
173
|
+
name: 'B2A Intent Agent', model: env.MARONA_MODEL ?? 'marona/auto',
|
|
174
|
+
instructions: 'Interpret decoded intent in context. Preserve uncertainty and use connected tools under Marona permissions.',
|
|
175
|
+
tools: await client.hub.connect(),
|
|
176
|
+
protocols: [new B2A({ provider: neuralService, outputProfile: env.B2A_OUTPUT_PROFILE! })],
|
|
173
177
|
});
|
|
178
|
+
const session = await Runner.connect(agent, { userId: env.B2A_USER_ID!, sessionId: env.B2A_SESSION_ID! });
|
|
174
179
|
try {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const exchange = await client.b2a.sendMessage(session.session_id, message);
|
|
182
|
-
// Forward agent.response payloads to your independent encoder. Its delivery result
|
|
183
|
-
// determines whether to send feedback.ack; simply receiving JSON is not presentation.
|
|
184
|
-
console.log(JSON.stringify(exchange, null, 2));
|
|
185
|
-
} finally {
|
|
186
|
-
await client.b2a.closeSession(session.session_id);
|
|
187
|
-
}
|
|
180
|
+
await session.send(signal);
|
|
181
|
+
for await (const event of session) {
|
|
182
|
+
console.log(event);
|
|
183
|
+
if (['feedback', 'signal.status', 'error'].includes(event.type)) break;
|
|
184
|
+
}
|
|
185
|
+
} finally { await session.close(); }
|
|
188
186
|
```
|
|
189
187
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
### Single run with structured output
|
|
189
|
+
|
|
190
|
+
Save as `examples/b2a_structured.mts`. This opens a connection, decodes the signal, runs
|
|
191
|
+
the agent, validates the response, encodes feedback, and closes the connection.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { readFile } from 'node:fs/promises';
|
|
195
|
+
import { Agent, B2A, B2ACodec, Runner, Marona } from 'marona';
|
|
196
|
+
const env = process.env;
|
|
197
|
+
const signal = JSON.parse(await readFile(process.argv[2]!, 'utf8'));
|
|
198
|
+
const client = new Marona({ apiKey: env.MARONA_API_KEY });
|
|
199
|
+
const neuralService = new B2ACodec(env.B2A_CODEC_URL!, {
|
|
200
|
+
token: env.B2A_NEURAL_TOKEN!, transport: (env.B2A_CODEC_TRANSPORT ?? 'mcp') as 'mcp' | 'http',
|
|
201
|
+
});
|
|
202
|
+
interface NeuralResponse { text: string; }
|
|
203
|
+
const agent = new Agent({
|
|
204
|
+
outputSchemaStrict: true,
|
|
205
|
+
outputSchema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'], additionalProperties: false },
|
|
206
|
+
name: 'B2A Intent Agent', model: env.MARONA_MODEL ?? 'marona/auto',
|
|
207
|
+
instructions: 'Interpret decoded intent in context. Preserve uncertainty and use connected tools under Marona permissions.',
|
|
208
|
+
tools: await client.hub.connect(),
|
|
209
|
+
protocols: [new B2A({ provider: neuralService, outputProfile: env.B2A_OUTPUT_PROFILE! })],
|
|
210
|
+
});
|
|
211
|
+
const result = await Runner.run<NeuralResponse>(agent, signal, {
|
|
212
|
+
userId: env.B2A_USER_ID!, sessionId: env.B2A_SESSION_ID!,
|
|
213
|
+
});
|
|
214
|
+
console.log(result.output.text);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Python returns the declared Pydantic model in `result.output`. Other SDKs validate
|
|
218
|
+
the declared JSON schema and expose their language's structured output representation.
|
|
219
|
+
Invalid output is rejected before encoding. Decoder abstention, required approval,
|
|
220
|
+
or failure does not become a successful typed result; use a persistent connection
|
|
221
|
+
for interactive clarification, approvals, and feedback delivery acknowledgments.
|
|
222
|
+
|
|
223
|
+
The SDK manages protocol messages, sequencing, event cursors, decoding and encoding.
|
|
224
|
+
Set B2A_CODEC_URL, B2A_NEURAL_TOKEN, B2A_OUTPUT_PROFILE, B2A_USER_ID and
|
|
225
|
+
B2A_SESSION_ID. Use B2A_CODEC_TRANSPORT=mcp or http. `session_id` identifies
|
|
226
|
+
an application conversation; each connection gets a separate native transport
|
|
227
|
+
session. The application authorizes processing before connecting; device and
|
|
228
|
+
protocol scope fields are supplied internally. Closing revokes those scopes.
|
|
229
|
+
|
|
230
|
+
Keep the session open to send more signals. Feedback events contain encoded
|
|
231
|
+
output; printing them does not deliver feedback. An interface driver acknowledges
|
|
232
|
+
presentation only after delivery. Failed or uncertain sends are never replayed
|
|
233
|
+
automatically. Native B2A supports server-hosted Hub tools and agent graphs;
|
|
234
|
+
SDK-local functions, callbacks and peer callbacks require server-hosted equivalents.
|
|
235
|
+
B2A v0.1 uses HTTP JSON and retained cursor events, not WebSocket transport.
|
|
195
236
|
See the repository's `docs/b2a-protocol.md` for the complete wire contract.
|
|
196
237
|
|
|
197
238
|
## Execution and errors
|
|
@@ -211,7 +252,4 @@ specific examples and migration guidance. These files are generated from
|
|
|
211
252
|
`docs/client-sdk-guides.json`; verify them with
|
|
212
253
|
`python scripts/sync_client_sdk_docs.py --check`.
|
|
213
254
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
- Output validation errors expose the agent name, original output and safe validation details for controlled recovery.
|
|
217
|
-
- Connected-tool and streaming behavior is covered by the Python parity fixtures.
|
|
255
|
+
Communication protocols are configured through `protocols`; `Runner.connect` opens persistent connections and `Runner.run` completes a single input. The 2.3 B2A entry points remain compatible.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { B2AIntent, type B2AJsonObject } from "./b2a.js";
|
|
2
|
+
export type B2ADecodeStatus = "decoded" | "abstain" | "poor_signal" | "calibration_required";
|
|
3
|
+
export interface B2ADecodeResult {
|
|
4
|
+
status: B2ADecodeStatus;
|
|
5
|
+
intent: B2AIntent | null;
|
|
6
|
+
provenance: B2AJsonObject;
|
|
7
|
+
uncertainty: B2AJsonObject;
|
|
8
|
+
}
|
|
9
|
+
export interface B2AEncodedFeedback {
|
|
10
|
+
feedbackId: string;
|
|
11
|
+
profile: string;
|
|
12
|
+
mediaType: string;
|
|
13
|
+
content: B2AJsonObject;
|
|
14
|
+
provenance: B2AJsonObject;
|
|
15
|
+
}
|
|
16
|
+
export interface B2ACodecOptions {
|
|
17
|
+
token: string;
|
|
18
|
+
transport?: "http" | "mcp";
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
decodeTool?: string;
|
|
21
|
+
encodeTool?: string;
|
|
22
|
+
decodePath?: string;
|
|
23
|
+
encodePath?: string;
|
|
24
|
+
allowSimulation?: boolean;
|
|
25
|
+
fetch?: typeof globalThis.fetch;
|
|
26
|
+
}
|
|
27
|
+
/** Typed client for independent neural services; does not run neural models. */
|
|
28
|
+
export declare class B2ACodec {
|
|
29
|
+
private readonly url;
|
|
30
|
+
private readonly options;
|
|
31
|
+
constructor(url: string, options: B2ACodecOptions);
|
|
32
|
+
decode(signal: B2AJsonObject, options: {
|
|
33
|
+
consent: boolean;
|
|
34
|
+
}): Promise<B2ADecodeResult>;
|
|
35
|
+
encode(response: B2AJsonObject, options: {
|
|
36
|
+
profile: string;
|
|
37
|
+
consent: boolean;
|
|
38
|
+
context?: B2AJsonObject;
|
|
39
|
+
mediaTypes?: string[];
|
|
40
|
+
}): Promise<B2AEncodedFeedback>;
|
|
41
|
+
private provenance;
|
|
42
|
+
private call;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=b2a-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"b2a-codec.d.ts","sourceRoot":"","sources":["../src/b2a-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAE3E,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,sBAAsB,CAAC;AAC7F,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,aAAa,CAAC;IAC1B,WAAW,EAAE,aAAa,CAAC;CAC5B;AACD,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,aAAa,CAAC;IACvB,UAAU,EAAE,aAAa,CAAC;CAC3B;AACD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,gFAAgF;AAChF,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;gBACxC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe;IAiB3C,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IAuBtF,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,aAAa,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAUlK,OAAO,CAAC,UAAU;YAKJ,IAAI;CAwCnB"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { B2AIntent, B2AProtocolError } from "./b2a.js";
|
|
2
|
+
/** Typed client for independent neural services; does not run neural models. */
|
|
3
|
+
export class B2ACodec {
|
|
4
|
+
url;
|
|
5
|
+
options;
|
|
6
|
+
constructor(url, options) {
|
|
7
|
+
const parsed = new URL(url);
|
|
8
|
+
if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password || parsed.search || parsed.hash)
|
|
9
|
+
throw new B2AProtocolError("Codec URL must be HTTP(S) without credentials, query, or fragment");
|
|
10
|
+
if (parsed.protocol === "http:" && !["localhost", "127.0.0.1", "[::1]"].includes(parsed.hostname))
|
|
11
|
+
throw new B2AProtocolError("Remote codec endpoints require HTTPS");
|
|
12
|
+
this.url = parsed.toString().replace(/\/$/, "");
|
|
13
|
+
this.options = { transport: "http", timeoutMs: 60_000, decodeTool: "decode", encodeTool: "encode",
|
|
14
|
+
decodePath: "/v1/decode", encodePath: "/v1/encode", allowSimulation: false, fetch: globalThis.fetch, ...options };
|
|
15
|
+
for (const value of [this.options.token, this.options.decodeTool, this.options.encodeTool])
|
|
16
|
+
text(value);
|
|
17
|
+
for (const path of [this.options.decodePath, this.options.encodePath]) {
|
|
18
|
+
if (!path.startsWith("/") || path.startsWith("//") || /[?#\\]/.test(path))
|
|
19
|
+
throw new B2AProtocolError("Invalid codec path");
|
|
20
|
+
}
|
|
21
|
+
if (!["http", "mcp"].includes(this.options.transport) || typeof this.options.allowSimulation !== "boolean" ||
|
|
22
|
+
!Number.isFinite(this.options.timeoutMs) || this.options.timeoutMs <= 0)
|
|
23
|
+
throw new B2AProtocolError("Invalid codec configuration");
|
|
24
|
+
}
|
|
25
|
+
async decode(signal, options) {
|
|
26
|
+
consent(options.consent);
|
|
27
|
+
const input = object(signal);
|
|
28
|
+
const data = await this.call("decode", { signal: input, consent: true });
|
|
29
|
+
const status = data.status;
|
|
30
|
+
if (!["decoded", "abstain", "poor_signal", "calibration_required"].includes(status))
|
|
31
|
+
throw new B2AProtocolError("Invalid decoder status");
|
|
32
|
+
const provenance = this.provenance(data.provenance ?? {});
|
|
33
|
+
const uncertainty = object(data.uncertainty ?? {});
|
|
34
|
+
let intent = null;
|
|
35
|
+
if (status === "decoded") {
|
|
36
|
+
const metadata = { ...provenance, uncertainty };
|
|
37
|
+
if (input.signal_id != null)
|
|
38
|
+
metadata.signal_id = text(input.signal_id);
|
|
39
|
+
const decoder = {};
|
|
40
|
+
if (provenance.backend != null)
|
|
41
|
+
decoder.id = text(provenance.backend);
|
|
42
|
+
if (provenance.version != null)
|
|
43
|
+
decoder.version = text(provenance.version);
|
|
44
|
+
if (data.confidence != null && typeof data.confidence !== "number")
|
|
45
|
+
throw new B2AProtocolError("Invalid decoder confidence");
|
|
46
|
+
intent = new B2AIntent(data.intent, {
|
|
47
|
+
confidence: data.confidence == null ? undefined : data.confidence,
|
|
48
|
+
provenance: metadata, ...(Object.keys(decoder).length ? { decoder } : {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if (data.intent != null)
|
|
52
|
+
throw new B2AProtocolError("Abstaining decoder returned actionable intent");
|
|
53
|
+
return { status, intent, provenance, uncertainty };
|
|
54
|
+
}
|
|
55
|
+
async encode(response, options) {
|
|
56
|
+
consent(options.consent);
|
|
57
|
+
const profile = text(options.profile), media = options.mediaTypes ?? ["application/json"];
|
|
58
|
+
if (!media.length)
|
|
59
|
+
throw new B2AProtocolError("At least one interface media type is required");
|
|
60
|
+
media.forEach(text);
|
|
61
|
+
const data = await this.call("encode", { request: { response: object(response), profile, context: object(options.context ?? {}) }, consent: true });
|
|
62
|
+
if (data.profile !== profile || !media.includes(data.media_type))
|
|
63
|
+
throw new B2AProtocolError("Encoder output does not match interface capabilities");
|
|
64
|
+
return { feedbackId: text(data.feedback_id), profile, mediaType: text(data.media_type),
|
|
65
|
+
content: object(data.content), provenance: this.provenance(data.provenance ?? {}) };
|
|
66
|
+
}
|
|
67
|
+
provenance(value) {
|
|
68
|
+
const result = object(value), flag = Object.hasOwn(result, "simulation") ? result.simulation : false;
|
|
69
|
+
if (typeof flag !== "boolean" || (flag && !this.options.allowSimulation))
|
|
70
|
+
throw new B2AProtocolError("Neural output failed provenance validation");
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
async call(operation, arguments_) {
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
const timer = setTimeout(() => controller.abort(), this.options.timeoutMs);
|
|
76
|
+
const headers = { Authorization: `Bearer ${this.options.token}`, "Content-Type": "application/json", Accept: "application/json, text/event-stream" };
|
|
77
|
+
let sessionId = null;
|
|
78
|
+
const post = async (body, path = "") => {
|
|
79
|
+
const response = await this.options.fetch(this.url + path, { method: "POST", headers, body: JSON.stringify(body), redirect: "error", signal: controller.signal });
|
|
80
|
+
if (!response.ok)
|
|
81
|
+
throw new B2AProtocolError(`Neural service returned HTTP ${response.status}`);
|
|
82
|
+
return response;
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
if (this.options.transport === "http") {
|
|
86
|
+
const response = await post(arguments_, operation === "decode" ? this.options.decodePath : this.options.encodePath);
|
|
87
|
+
return object(await response.json());
|
|
88
|
+
}
|
|
89
|
+
const initialization = await post({ jsonrpc: "2.0", id: 1, method: "initialize", params: {
|
|
90
|
+
protocolVersion: "2025-11-25", capabilities: {}, clientInfo: { name: "marona", version: "2.4.0" },
|
|
91
|
+
} });
|
|
92
|
+
sessionId = initialization.headers.get("mcp-session-id");
|
|
93
|
+
if (sessionId)
|
|
94
|
+
headers["Mcp-Session-Id"] = sessionId;
|
|
95
|
+
const initialized = await rpc(initialization, 1);
|
|
96
|
+
const version = text(initialized.protocolVersion);
|
|
97
|
+
if (!["2025-11-25", "2025-06-18", "2025-03-26"].includes(version))
|
|
98
|
+
throw new B2AProtocolError("Unsupported MCP protocol version");
|
|
99
|
+
headers["MCP-Protocol-Version"] = version;
|
|
100
|
+
const notification = await post({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
101
|
+
await notification.body?.cancel();
|
|
102
|
+
const result = await rpc(await post({ jsonrpc: "2.0", id: 2, method: "tools/call", params: {
|
|
103
|
+
name: operation === "decode" ? this.options.decodeTool : this.options.encodeTool, arguments: arguments_,
|
|
104
|
+
} }), 2);
|
|
105
|
+
const structured = object(result.structuredContent);
|
|
106
|
+
if (result.isError === true || structured.success !== true)
|
|
107
|
+
throw new B2AProtocolError("Neural MCP tool failed");
|
|
108
|
+
return object(structured.data);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
if (sessionId) {
|
|
113
|
+
try {
|
|
114
|
+
const response = await this.options.fetch(this.url, { method: "DELETE", headers, redirect: "error", signal: AbortSignal.timeout(1000) });
|
|
115
|
+
await response.body?.cancel();
|
|
116
|
+
}
|
|
117
|
+
catch { /* Best-effort session cleanup only. */ }
|
|
118
|
+
}
|
|
119
|
+
controller.abort();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function consent(value) { if (value !== true)
|
|
124
|
+
throw new B2AProtocolError("Neural processing requires explicit consent"); }
|
|
125
|
+
function text(value) { if (typeof value !== "string" || !value.trim())
|
|
126
|
+
throw new B2AProtocolError("Expected nonempty codec text"); return value; }
|
|
127
|
+
function object(value) {
|
|
128
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
129
|
+
throw new B2AProtocolError("Expected a codec JSON object");
|
|
130
|
+
const seen = new Set();
|
|
131
|
+
const visit = (v) => {
|
|
132
|
+
if (v === null || typeof v === "string" || typeof v === "boolean" || (typeof v === "number" && Number.isFinite(v)))
|
|
133
|
+
return;
|
|
134
|
+
if (typeof v !== "object" || !v || seen.has(v))
|
|
135
|
+
throw new B2AProtocolError("Codec values must be finite JSON");
|
|
136
|
+
if (!Array.isArray(v) && Object.getPrototypeOf(v) !== Object.prototype && Object.getPrototypeOf(v) !== null)
|
|
137
|
+
throw new B2AProtocolError("Codec values must be plain JSON");
|
|
138
|
+
seen.add(v);
|
|
139
|
+
Object.values(v).forEach(visit);
|
|
140
|
+
seen.delete(v);
|
|
141
|
+
};
|
|
142
|
+
visit(value);
|
|
143
|
+
return JSON.parse(JSON.stringify(value));
|
|
144
|
+
}
|
|
145
|
+
async function rpc(response, id) {
|
|
146
|
+
const check = (value) => {
|
|
147
|
+
const message = object(value);
|
|
148
|
+
if (message.id !== id)
|
|
149
|
+
return null;
|
|
150
|
+
if (message.jsonrpc !== "2.0" || message.error !== undefined)
|
|
151
|
+
throw new B2AProtocolError("Neural MCP request failed");
|
|
152
|
+
return object(message.result);
|
|
153
|
+
};
|
|
154
|
+
if (!response.headers.get("content-type")?.includes("text/event-stream")) {
|
|
155
|
+
const result = check(await response.json());
|
|
156
|
+
if (result)
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
else if (response.body) {
|
|
160
|
+
const reader = response.body.getReader(), decoder = new TextDecoder();
|
|
161
|
+
let buffer = "", data = [], size = 0;
|
|
162
|
+
try {
|
|
163
|
+
while (true) {
|
|
164
|
+
const chunk = await reader.read();
|
|
165
|
+
if (chunk.done)
|
|
166
|
+
break;
|
|
167
|
+
size += chunk.value.length;
|
|
168
|
+
if (size > 2_097_152)
|
|
169
|
+
throw new B2AProtocolError("MCP response exceeds size limit");
|
|
170
|
+
buffer += decoder.decode(chunk.value, { stream: true });
|
|
171
|
+
let newline;
|
|
172
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
173
|
+
const line = buffer.slice(0, newline).replace(/\r$/, "");
|
|
174
|
+
buffer = buffer.slice(newline + 1);
|
|
175
|
+
if (!line) {
|
|
176
|
+
if (data.length && data.join("\n").trim()) {
|
|
177
|
+
const result = check(JSON.parse(data.join("\n")));
|
|
178
|
+
if (result)
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
data = [];
|
|
182
|
+
}
|
|
183
|
+
else if (line.startsWith("data:"))
|
|
184
|
+
data.push(line.slice(5).replace(/^ /, ""));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
await reader.cancel();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
throw new B2AProtocolError("MCP response did not match the request");
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=b2a-codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"b2a-codec.js","sourceRoot":"","sources":["../src/b2a-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAsB,MAAM,UAAU,CAAC;AA4B3E,gFAAgF;AAChF,MAAM,OAAO,QAAQ;IACF,GAAG,CAAS;IACZ,OAAO,CAA4B;IACpD,YAAY,GAAW,EAAE,OAAwB;QAC/C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI;YACtH,MAAM,IAAI,gBAAgB,CAAC,mEAAmE,CAAC,CAAC;QAClG,IAAI,M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AAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;oBAC7F,IAAI,CAAC,IAAI,EAAE,CAAC;wBACV,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;4BAAC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;4BAAC,IAAI,MAAM;gCAAE,OAAO,MAAM,CAAC;wBAAC,CAAC;wBAC5H,IAAI,GAAG,EAAE,CAAC;oBACZ,CAAC;yBAAM,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;wBAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;gBAClF,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YAAC,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;QAAC,CAAC;IACtC,CAAC;IACD,MAAM,IAAI,gBAAgB,CAAC,wCAAwC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type AgentProtocol, type ProtocolIdentity } from './protocols.js';
|
|
2
|
+
import { B2AClient, type B2AJsonObject, type B2ASession } from './b2a.js';
|
|
3
|
+
import type { B2ACodec, B2AEncodedFeedback } from './b2a-codec.js';
|
|
4
|
+
import { type Agent, type JsonMap, type RunResult, type RunnerOptions } from './index.js';
|
|
5
|
+
export type B2AProvider = Pick<B2ACodec, 'decode' | 'encode'>;
|
|
6
|
+
export declare class B2A implements AgentProtocol<B2AConnection> {
|
|
7
|
+
readonly name = "b2a";
|
|
8
|
+
readonly provider: B2AProvider;
|
|
9
|
+
readonly outputProfile: string;
|
|
10
|
+
readonly outputMediaTypes: string[];
|
|
11
|
+
readonly context: B2AJsonObject;
|
|
12
|
+
readonly execute: boolean;
|
|
13
|
+
constructor(options: {
|
|
14
|
+
provider: B2AProvider;
|
|
15
|
+
outputProfile: string;
|
|
16
|
+
outputMediaTypes?: string[];
|
|
17
|
+
context?: B2AJsonObject;
|
|
18
|
+
execute?: boolean;
|
|
19
|
+
});
|
|
20
|
+
connect(agent: Agent, options: ProtocolIdentity): Promise<B2AConnection>;
|
|
21
|
+
run(agent: Agent, input: unknown, options: RunnerOptions & ProtocolIdentity): Promise<RunResult>;
|
|
22
|
+
}
|
|
23
|
+
export interface B2ASessionEvent {
|
|
24
|
+
type: string;
|
|
25
|
+
data: B2AJsonObject;
|
|
26
|
+
responseId?: string;
|
|
27
|
+
feedback?: B2AEncodedFeedback;
|
|
28
|
+
output?: unknown;
|
|
29
|
+
}
|
|
30
|
+
export declare class B2ARunError extends Error {
|
|
31
|
+
readonly event: B2ASessionEvent;
|
|
32
|
+
constructor(event: B2ASessionEvent);
|
|
33
|
+
}
|
|
34
|
+
/** Persistent SDK connection; native session identity remains separate from conversation identity. */
|
|
35
|
+
export declare class B2AConnection implements AsyncIterableIterator<B2ASessionEvent> {
|
|
36
|
+
private client;
|
|
37
|
+
private config;
|
|
38
|
+
private snapshot;
|
|
39
|
+
readonly sessionId: string;
|
|
40
|
+
private agent?;
|
|
41
|
+
readonly protocolSessionId: string;
|
|
42
|
+
/** @internal */ completedResult?: RunResult;
|
|
43
|
+
private cursor;
|
|
44
|
+
private queue;
|
|
45
|
+
private closed;
|
|
46
|
+
private failed;
|
|
47
|
+
private pending;
|
|
48
|
+
private tail;
|
|
49
|
+
constructor(client: B2AClient, config: B2A, snapshot: B2ASession, sessionId: string, agent?: Agent | undefined);
|
|
50
|
+
get status(): string;
|
|
51
|
+
private serial;
|
|
52
|
+
private active;
|
|
53
|
+
send(input: JsonMap): Promise<void>;
|
|
54
|
+
sendSignal(signal: B2AJsonObject): Promise<void>;
|
|
55
|
+
private sendMessage;
|
|
56
|
+
private poll;
|
|
57
|
+
private accept;
|
|
58
|
+
updateContext(context: B2AJsonObject): Promise<void>;
|
|
59
|
+
respondToApproval(approvalId: string, approved: boolean): Promise<void>;
|
|
60
|
+
acknowledgeFeedback(responseId: string, status: 'presented' | 'failed'): Promise<void>;
|
|
61
|
+
close(): Promise<void>;
|
|
62
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<B2ASessionEvent>;
|
|
63
|
+
return(): Promise<IteratorResult<B2ASessionEvent>>;
|
|
64
|
+
next(): Promise<IteratorResult<B2ASessionEvent>>;
|
|
65
|
+
}
|
|
66
|
+
export declare class B2ARunner {
|
|
67
|
+
static connect(agent: Agent, options: {
|
|
68
|
+
userId: string;
|
|
69
|
+
sessionId: string;
|
|
70
|
+
}): Promise<B2AConnection>;
|
|
71
|
+
/** @internal */
|
|
72
|
+
static open(agent: Agent, config: B2A, options: ProtocolIdentity & RunnerOptions): Promise<B2AConnection>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=b2a-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"b2a-runner.d.ts","sourceRoot":"","sources":["../src/b2a-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAgC,KAAK,aAAa,EAAE,KAAK,UAAU,EAAiB,MAAM,UAAU,CAAC;AACvH,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAA8B,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAEtH,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAA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