@truealter/sdk 0.5.1 → 0.5.3
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 +115 -50
- package/dist/bin/alter-identity.js +383 -48
- package/dist/bin/mcp-bridge.js +40 -4
- package/dist/index.cjs +517 -64
- package/dist/index.d.cts +480 -128
- package/dist/index.d.ts +480 -128
- package/dist/index.js +496 -65
- package/package.json +3 -3
- package/dist/mcp-bridge.js +0 -166
package/dist/bin/mcp-bridge.js
CHANGED
|
@@ -214,6 +214,10 @@ var AlterInvalidResponse = class extends AlterError {
|
|
|
214
214
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
215
215
|
}
|
|
216
216
|
};
|
|
217
|
+
|
|
218
|
+
// src/meta.ts
|
|
219
|
+
var SDK_NAME = "@truealter/sdk";
|
|
220
|
+
var SDK_VERSION = "0.5.3" ;
|
|
217
221
|
var X402Client = class {
|
|
218
222
|
signer;
|
|
219
223
|
maxPerQuery;
|
|
@@ -324,6 +328,9 @@ var MCPClient = class {
|
|
|
324
328
|
x402;
|
|
325
329
|
signing;
|
|
326
330
|
extraHeaders;
|
|
331
|
+
preflightHook;
|
|
332
|
+
preflightPromise = null;
|
|
333
|
+
preflightDone = false;
|
|
327
334
|
requestCounter = 0;
|
|
328
335
|
initialised = false;
|
|
329
336
|
constructor(opts = {}) {
|
|
@@ -332,17 +339,43 @@ var MCPClient = class {
|
|
|
332
339
|
this.fetchImpl = opts.fetch ?? fetch;
|
|
333
340
|
this.timeoutMs = opts.timeoutMs ?? 3e4;
|
|
334
341
|
this.maxRetries = opts.maxRetries ?? 2;
|
|
335
|
-
this.clientInfo = opts.clientInfo ?? { name:
|
|
342
|
+
this.clientInfo = opts.clientInfo ?? { name: SDK_NAME, version: SDK_VERSION };
|
|
336
343
|
this.x402 = opts.x402;
|
|
337
344
|
this.signing = opts.signing;
|
|
338
345
|
this.extraHeaders = opts.extraHeaders;
|
|
346
|
+
this.preflightHook = opts.preflightHook;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Run the lazy preflight hook (D-MIN-VERSION-FLOOR-1) exactly once.
|
|
350
|
+
* Idempotent and serialised: concurrent callers share the same
|
|
351
|
+
* promise. Throws from the hook propagate to every concurrent caller.
|
|
352
|
+
*/
|
|
353
|
+
async runPreflight() {
|
|
354
|
+
if (this.preflightDone) return;
|
|
355
|
+
if (!this.preflightHook) {
|
|
356
|
+
this.preflightDone = true;
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (!this.preflightPromise) {
|
|
360
|
+
this.preflightPromise = this.preflightHook().then(
|
|
361
|
+
() => {
|
|
362
|
+
this.preflightDone = true;
|
|
363
|
+
},
|
|
364
|
+
(err) => {
|
|
365
|
+
this.preflightPromise = null;
|
|
366
|
+
throw err;
|
|
367
|
+
}
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
await this.preflightPromise;
|
|
339
371
|
}
|
|
340
372
|
/**
|
|
341
373
|
* Send the MCP `initialize` handshake and capture the resulting session
|
|
342
|
-
* id. Idempotent
|
|
374
|
+
* id. Idempotent: safe to call multiple times.
|
|
343
375
|
*/
|
|
344
376
|
async initialize() {
|
|
345
377
|
if (this.initialised) return null;
|
|
378
|
+
await this.runPreflight();
|
|
346
379
|
const result = await this.rpc("initialize", {
|
|
347
380
|
protocolVersion: MCP_PROTOCOL_VERSION,
|
|
348
381
|
capabilities: {},
|
|
@@ -502,7 +535,10 @@ var MCPClient = class {
|
|
|
502
535
|
...this.extraHeaders ?? {},
|
|
503
536
|
"Content-Type": "application/json",
|
|
504
537
|
Accept: "application/json",
|
|
505
|
-
"User-Agent": `${this.clientInfo.name}/${this.clientInfo.version}
|
|
538
|
+
"User-Agent": `${this.clientInfo.name}/${this.clientInfo.version}`,
|
|
539
|
+
"X-Alter-Client-Id": "alter-identity",
|
|
540
|
+
"X-Alter-Client-Version": SDK_VERSION,
|
|
541
|
+
"X-Alter-Client-Channel": "npm"
|
|
506
542
|
};
|
|
507
543
|
if (this.apiKey) headers["X-ALTER-API-Key"] = this.apiKey;
|
|
508
544
|
if (this.sessionId) headers["Mcp-Session-Id"] = this.sessionId;
|
|
@@ -589,7 +625,7 @@ function buildExtraHeaders() {
|
|
|
589
625
|
}
|
|
590
626
|
var EXTRA_HEADERS = buildExtraHeaders();
|
|
591
627
|
console.warn(
|
|
592
|
-
"This bridge is a dev/demo surface. Authenticated MCP tools require ES256 per-invocation signing; for production, import `@truealter/sdk` directly. Bridge signing
|
|
628
|
+
"This bridge is a dev/demo surface. Authenticated MCP tools require ES256 per-invocation signing; for production, import `@truealter/sdk` directly. Bridge signing is planned for a future release."
|
|
593
629
|
);
|
|
594
630
|
var client = new MCPClient({
|
|
595
631
|
endpoint: ENDPOINT,
|