Squashed 'packages/mcp-typescript/' content from commit 2cc7dd1
git-subtree-dir: packages/mcp-typescript git-subtree-split: 2cc7dd104307d48bab8d27760f16c63c119d8a88
This commit is contained in:
92
dist/shared/protocol.d.ts
generated
vendored
Normal file
92
dist/shared/protocol.d.ts
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
import { AnyZodObject, ZodLiteral, ZodObject, z } from "zod";
|
||||
import { Notification, Progress, Request, Result } from "../types.js";
|
||||
import { Transport } from "./transport.js";
|
||||
/**
|
||||
* Callback for progress notifications.
|
||||
*/
|
||||
export type ProgressCallback = (progress: Progress) => void;
|
||||
/**
|
||||
* Implements MCP protocol framing on top of a pluggable transport, including
|
||||
* features like request/response linking, notifications, and progress.
|
||||
*/
|
||||
export declare class Protocol<SendRequestT extends Request, SendNotificationT extends Notification, SendResultT extends Result> {
|
||||
private _transport?;
|
||||
private _requestMessageId;
|
||||
private _requestHandlers;
|
||||
private _notificationHandlers;
|
||||
private _responseHandlers;
|
||||
private _progressHandlers;
|
||||
/**
|
||||
* Callback for when the connection is closed for any reason.
|
||||
*
|
||||
* This is invoked when close() is called as well.
|
||||
*/
|
||||
onclose?: () => void;
|
||||
/**
|
||||
* Callback for when an error occurs.
|
||||
*
|
||||
* Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.
|
||||
*/
|
||||
onerror?: (error: Error) => void;
|
||||
/**
|
||||
* A handler to invoke for any request types that do not have their own handler installed.
|
||||
*/
|
||||
fallbackRequestHandler?: (request: Request) => Promise<SendResultT>;
|
||||
/**
|
||||
* A handler to invoke for any notification types that do not have their own handler installed.
|
||||
*/
|
||||
fallbackNotificationHandler?: (notification: Notification) => Promise<void>;
|
||||
constructor();
|
||||
/**
|
||||
* Attaches to the given transport and starts listening for messages.
|
||||
*
|
||||
* The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
||||
*/
|
||||
connect(transport: Transport): Promise<void>;
|
||||
private _onclose;
|
||||
private _onerror;
|
||||
private _onnotification;
|
||||
private _onrequest;
|
||||
private _onprogress;
|
||||
private _onresponse;
|
||||
get transport(): Transport | undefined;
|
||||
/**
|
||||
* Closes the connection.
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/**
|
||||
* Sends a request and wait for a response, with optional progress notifications in the meantime (if supported by the server).
|
||||
*
|
||||
* Do not use this method to emit notifications! Use notification() instead.
|
||||
*/
|
||||
request<T extends AnyZodObject>(request: SendRequestT, resultSchema: T, onprogress?: ProgressCallback): Promise<z.infer<T>>;
|
||||
/**
|
||||
* Emits a notification, which is a one-way message that does not expect a response.
|
||||
*/
|
||||
notification(notification: SendNotificationT): Promise<void>;
|
||||
/**
|
||||
* Registers a handler to invoke when this protocol object receives a request with the given method.
|
||||
*
|
||||
* Note that this will replace any previous request handler for the same method.
|
||||
*/
|
||||
setRequestHandler<T extends ZodObject<{
|
||||
method: ZodLiteral<string>;
|
||||
}>>(requestSchema: T, handler: (request: z.infer<T>) => SendResultT | Promise<SendResultT>): void;
|
||||
/**
|
||||
* Removes the request handler for the given method.
|
||||
*/
|
||||
removeRequestHandler(method: string): void;
|
||||
/**
|
||||
* Registers a handler to invoke when this protocol object receives a notification with the given method.
|
||||
*
|
||||
* Note that this will replace any previous notification handler for the same method.
|
||||
*/
|
||||
setNotificationHandler<T extends ZodObject<{
|
||||
method: ZodLiteral<string>;
|
||||
}>>(notificationSchema: T, handler: (notification: z.infer<T>) => void | Promise<void>): void;
|
||||
/**
|
||||
* Removes the notification handler for the given method.
|
||||
*/
|
||||
removeNotificationHandler(method: string): void;
|
||||
}
|
||||
//# sourceMappingURL=protocol.d.ts.map
|
||||
1
dist/shared/protocol.d.ts.map
generated
vendored
Normal file
1
dist/shared/protocol.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/shared/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EA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AAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;;OAIG;IACH,OAAO,CAAC,CAAC,SAAS,YAAY,EAC5B,OAAO,EAAE,YAAY,EACrB,YAAY,EAAE,CAAC,EACf,UAAU,CAAC,EAAE,gBAAgB,GAC5B,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAuCtB;;OAEG;IACG,YAAY,CAAC,YAAY,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAalE;;;;OAIG;IACH,iBAAiB,CACf,CAAC,SAAS,SAAS,CAAC;QAClB,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;KAC5B,CAAC,EAEF,aAAa,EAAE,CAAC,EAChB,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GACnE,IAAI;IAMP;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI1C;;;;OAIG;IACH,sBAAsB,CACpB,CAAC,SAAS,SAAS,CAAC;QAClB,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;KAC5B,CAAC,EAEF,kBAAkB,EAAE,CAAC,EACrB,OAAO,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC1D,IAAI;IAQP;;OAEG;IACH,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAGhD"}
|
||||
224
dist/shared/protocol.js
generated
vendored
Normal file
224
dist/shared/protocol.js
generated
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
import { ErrorCode, McpError, PingRequestSchema, ProgressNotificationSchema, } from "../types.js";
|
||||
/**
|
||||
* Implements MCP protocol framing on top of a pluggable transport, including
|
||||
* features like request/response linking, notifications, and progress.
|
||||
*/
|
||||
export class Protocol {
|
||||
constructor() {
|
||||
this._requestMessageId = 0;
|
||||
this._requestHandlers = new Map();
|
||||
this._notificationHandlers = new Map();
|
||||
this._responseHandlers = new Map();
|
||||
this._progressHandlers = new Map();
|
||||
this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
|
||||
this._onprogress(notification);
|
||||
});
|
||||
this.setRequestHandler(PingRequestSchema,
|
||||
// Automatic pong by default.
|
||||
(_request) => ({}));
|
||||
}
|
||||
/**
|
||||
* Attaches to the given transport and starts listening for messages.
|
||||
*
|
||||
* The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
||||
*/
|
||||
async connect(transport) {
|
||||
this._transport = transport;
|
||||
this._transport.onclose = () => {
|
||||
this._onclose();
|
||||
};
|
||||
this._transport.onerror = (error) => {
|
||||
this._onerror(error);
|
||||
};
|
||||
this._transport.onmessage = (message) => {
|
||||
if (!("method" in message)) {
|
||||
this._onresponse(message);
|
||||
}
|
||||
else if ("id" in message) {
|
||||
this._onrequest(message);
|
||||
}
|
||||
else {
|
||||
this._onnotification(message);
|
||||
}
|
||||
};
|
||||
}
|
||||
_onclose() {
|
||||
var _a;
|
||||
const responseHandlers = this._responseHandlers;
|
||||
this._responseHandlers = new Map();
|
||||
this._progressHandlers.clear();
|
||||
this._transport = undefined;
|
||||
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
||||
const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
|
||||
for (const handler of responseHandlers.values()) {
|
||||
handler(error);
|
||||
}
|
||||
}
|
||||
_onerror(error) {
|
||||
var _a;
|
||||
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
||||
}
|
||||
_onnotification(notification) {
|
||||
var _a;
|
||||
const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler;
|
||||
// Ignore notifications not being subscribed to.
|
||||
if (handler === undefined) {
|
||||
return;
|
||||
}
|
||||
handler(notification).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
|
||||
}
|
||||
_onrequest(request) {
|
||||
var _a, _b;
|
||||
const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
|
||||
if (handler === undefined) {
|
||||
(_b = this._transport) === null || _b === void 0 ? void 0 : _b.send({
|
||||
jsonrpc: "2.0",
|
||||
id: request.id,
|
||||
error: {
|
||||
code: ErrorCode.MethodNotFound,
|
||||
message: "Method not found",
|
||||
},
|
||||
}).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
|
||||
return;
|
||||
}
|
||||
handler(request)
|
||||
.then((result) => {
|
||||
var _a;
|
||||
(_a = this._transport) === null || _a === void 0 ? void 0 : _a.send({
|
||||
result,
|
||||
jsonrpc: "2.0",
|
||||
id: request.id,
|
||||
});
|
||||
}, (error) => {
|
||||
var _a, _b;
|
||||
return (_a = this._transport) === null || _a === void 0 ? void 0 : _a.send({
|
||||
jsonrpc: "2.0",
|
||||
id: request.id,
|
||||
error: {
|
||||
code: error["code"]
|
||||
? Math.floor(Number(error["code"]))
|
||||
: ErrorCode.InternalError,
|
||||
message: (_b = error.message) !== null && _b !== void 0 ? _b : "Internal error",
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => this._onerror(new Error(`Failed to send response: ${error}`)));
|
||||
}
|
||||
_onprogress(notification) {
|
||||
const { progress, total, progressToken } = notification.params;
|
||||
const handler = this._progressHandlers.get(Number(progressToken));
|
||||
if (handler === undefined) {
|
||||
this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`));
|
||||
return;
|
||||
}
|
||||
handler({ progress, total });
|
||||
}
|
||||
_onresponse(response) {
|
||||
const messageId = response.id;
|
||||
const handler = this._responseHandlers.get(Number(messageId));
|
||||
if (handler === undefined) {
|
||||
this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
|
||||
return;
|
||||
}
|
||||
this._responseHandlers.delete(Number(messageId));
|
||||
this._progressHandlers.delete(Number(messageId));
|
||||
if ("result" in response) {
|
||||
handler(response);
|
||||
}
|
||||
else {
|
||||
const error = new McpError(response.error.code, response.error.message, response.error.data);
|
||||
handler(error);
|
||||
}
|
||||
}
|
||||
get transport() {
|
||||
return this._transport;
|
||||
}
|
||||
/**
|
||||
* Closes the connection.
|
||||
*/
|
||||
async close() {
|
||||
var _a;
|
||||
await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close());
|
||||
}
|
||||
/**
|
||||
* Sends a request and wait for a response, with optional progress notifications in the meantime (if supported by the server).
|
||||
*
|
||||
* Do not use this method to emit notifications! Use notification() instead.
|
||||
*/
|
||||
request(request, resultSchema, onprogress) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this._transport) {
|
||||
reject(new Error("Not connected"));
|
||||
return;
|
||||
}
|
||||
const messageId = this._requestMessageId++;
|
||||
const jsonrpcRequest = {
|
||||
...request,
|
||||
jsonrpc: "2.0",
|
||||
id: messageId,
|
||||
};
|
||||
if (onprogress) {
|
||||
this._progressHandlers.set(messageId, onprogress);
|
||||
jsonrpcRequest.params = {
|
||||
...request.params,
|
||||
_meta: { progressToken: messageId },
|
||||
};
|
||||
}
|
||||
this._responseHandlers.set(messageId, (response) => {
|
||||
if (response instanceof Error) {
|
||||
return reject(response);
|
||||
}
|
||||
try {
|
||||
const result = resultSchema.parse(response.result);
|
||||
resolve(result);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
this._transport.send(jsonrpcRequest).catch(reject);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Emits a notification, which is a one-way message that does not expect a response.
|
||||
*/
|
||||
async notification(notification) {
|
||||
if (!this._transport) {
|
||||
throw new Error("Not connected");
|
||||
}
|
||||
const jsonrpcNotification = {
|
||||
...notification,
|
||||
jsonrpc: "2.0",
|
||||
};
|
||||
await this._transport.send(jsonrpcNotification);
|
||||
}
|
||||
/**
|
||||
* Registers a handler to invoke when this protocol object receives a request with the given method.
|
||||
*
|
||||
* Note that this will replace any previous request handler for the same method.
|
||||
*/
|
||||
setRequestHandler(requestSchema, handler) {
|
||||
this._requestHandlers.set(requestSchema.shape.method.value, (request) => Promise.resolve(handler(requestSchema.parse(request))));
|
||||
}
|
||||
/**
|
||||
* Removes the request handler for the given method.
|
||||
*/
|
||||
removeRequestHandler(method) {
|
||||
this._requestHandlers.delete(method);
|
||||
}
|
||||
/**
|
||||
* Registers a handler to invoke when this protocol object receives a notification with the given method.
|
||||
*
|
||||
* Note that this will replace any previous notification handler for the same method.
|
||||
*/
|
||||
setNotificationHandler(notificationSchema, handler) {
|
||||
this._notificationHandlers.set(notificationSchema.shape.method.value, (notification) => Promise.resolve(handler(notificationSchema.parse(notification))));
|
||||
}
|
||||
/**
|
||||
* Removes the notification handler for the given method.
|
||||
*/
|
||||
removeNotificationHandler(method) {
|
||||
this._notificationHandlers.delete(method);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=protocol.js.map
|
||||
1
dist/shared/protocol.js.map
generated
vendored
Normal file
1
dist/shared/protocol.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
13
dist/shared/stdio.d.ts
generated
vendored
Normal file
13
dist/shared/stdio.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { JSONRPCMessage } from "../types.js";
|
||||
/**
|
||||
* Buffers a continuous stdio stream into discrete JSON-RPC messages.
|
||||
*/
|
||||
export declare class ReadBuffer {
|
||||
private _buffer?;
|
||||
append(chunk: Buffer): void;
|
||||
readMessage(): JSONRPCMessage | null;
|
||||
clear(): void;
|
||||
}
|
||||
export declare function deserializeMessage(line: string): JSONRPCMessage;
|
||||
export declare function serializeMessage(message: JSONRPCMessage): string;
|
||||
//# sourceMappingURL=stdio.d.ts.map
|
||||
1
dist/shared/stdio.d.ts.map
generated
vendored
Normal file
1
dist/shared/stdio.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../src/shared/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3B,WAAW,IAAI,cAAc,GAAG,IAAI;IAepC,KAAK,IAAI,IAAI;CAGd;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAE/D;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAEhE"}
|
||||
31
dist/shared/stdio.js
generated
vendored
Normal file
31
dist/shared/stdio.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { JSONRPCMessageSchema } from "../types.js";
|
||||
/**
|
||||
* Buffers a continuous stdio stream into discrete JSON-RPC messages.
|
||||
*/
|
||||
export class ReadBuffer {
|
||||
append(chunk) {
|
||||
this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
|
||||
}
|
||||
readMessage() {
|
||||
if (!this._buffer) {
|
||||
return null;
|
||||
}
|
||||
const index = this._buffer.indexOf("\n");
|
||||
if (index === -1) {
|
||||
return null;
|
||||
}
|
||||
const line = this._buffer.toString("utf8", 0, index);
|
||||
this._buffer = this._buffer.subarray(index + 1);
|
||||
return deserializeMessage(line);
|
||||
}
|
||||
clear() {
|
||||
this._buffer = undefined;
|
||||
}
|
||||
}
|
||||
export function deserializeMessage(line) {
|
||||
return JSONRPCMessageSchema.parse(JSON.parse(line));
|
||||
}
|
||||
export function serializeMessage(message) {
|
||||
return JSON.stringify(message) + "\n";
|
||||
}
|
||||
//# sourceMappingURL=stdio.js.map
|
||||
1
dist/shared/stdio.js.map
generated
vendored
Normal file
1
dist/shared/stdio.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"stdio.js","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dio.test.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=stdio.test.d.ts.map
|
||||
1
dist/shared/stdio.test.d.ts.map
generated
vendored
Normal file
1
dist/shared/stdio.test.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"stdio.test.d.ts","sourceRoot":"","sources":["../../src/shared/stdio.test.ts"],"names":[],"mappings":""}
|
||||
27
dist/shared/stdio.test.js
generated
vendored
Normal file
27
dist/shared/stdio.test.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ReadBuffer } from "./stdio.js";
|
||||
const testMessage = {
|
||||
jsonrpc: "2.0",
|
||||
method: "foobar",
|
||||
};
|
||||
test("should have no messages after initialization", () => {
|
||||
const readBuffer = new ReadBuffer();
|
||||
expect(readBuffer.readMessage()).toBeNull();
|
||||
});
|
||||
test("should only yield a message after a newline", () => {
|
||||
const readBuffer = new ReadBuffer();
|
||||
readBuffer.append(Buffer.from(JSON.stringify(testMessage)));
|
||||
expect(readBuffer.readMessage()).toBeNull();
|
||||
readBuffer.append(Buffer.from("\n"));
|
||||
expect(readBuffer.readMessage()).toEqual(testMessage);
|
||||
expect(readBuffer.readMessage()).toBeNull();
|
||||
});
|
||||
test("should be reusable after clearing", () => {
|
||||
const readBuffer = new ReadBuffer();
|
||||
readBuffer.append(Buffer.from("foobar"));
|
||||
readBuffer.clear();
|
||||
expect(readBuffer.readMessage()).toBeNull();
|
||||
readBuffer.append(Buffer.from(JSON.stringify(testMessage)));
|
||||
readBuffer.append(Buffer.from("\n"));
|
||||
expect(readBuffer.readMessage()).toEqual(testMessage);
|
||||
});
|
||||
//# sourceMappingURL=stdio.test.js.map
|
||||
1
dist/shared/stdio.test.js.map
generated
vendored
Normal file
1
dist/shared/stdio.test.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"stdio.test.js","sourceRoot":"","sources":["../../src/shared/stdio.test.ts"],"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CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5D,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AACxD,CAAC,CAAC,CAAC"}
|
||||
31
dist/shared/transport.d.ts
generated
vendored
Normal file
31
dist/shared/transport.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { JSONRPCMessage } from "../types.js";
|
||||
/**
|
||||
* Describes the minimal contract for a MCP transport that a client or server can communicate over.
|
||||
*/
|
||||
export interface Transport {
|
||||
/**
|
||||
* Sends a JSON-RPC message (request or response).
|
||||
*/
|
||||
send(message: JSONRPCMessage): Promise<void>;
|
||||
/**
|
||||
* Closes the connection.
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/**
|
||||
* Callback for when the connection is closed for any reason.
|
||||
*
|
||||
* This should be invoked when close() is called as well.
|
||||
*/
|
||||
onclose?: () => void;
|
||||
/**
|
||||
* Callback for when an error occurs.
|
||||
*
|
||||
* Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.
|
||||
*/
|
||||
onerror?: (error: Error) => void;
|
||||
/**
|
||||
* Callback for when a message (request or response) is received over the connection.
|
||||
*/
|
||||
onmessage?: (message: JSONRPCMessage) => void;
|
||||
}
|
||||
//# sourceMappingURL=transport.d.ts.map
|
||||
1
dist/shared/transport.d.ts.map
generated
vendored
Normal file
1
dist/shared/transport.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/shared/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAEjC;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CAC/C"}
|
||||
2
dist/shared/transport.js
generated
vendored
Normal file
2
dist/shared/transport.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=transport.js.map
|
||||
1
dist/shared/transport.js.map
generated
vendored
Normal file
1
dist/shared/transport.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/shared/transport.ts"],"names":[],"mappings":""}
|
||||
Reference in New Issue
Block a user