@multi-agent-protocol/sdk 0.1.5 → 0.1.6
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/{index-BVrYVfaf.d.cts → index-iu0EgJzG.d.cts} +69 -14
- package/dist/{index-BVrYVfaf.d.ts → index-iu0EgJzG.d.ts} +69 -14
- package/dist/index.cjs +110 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +110 -10
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +110 -10
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +110 -10
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/testing.cjs
CHANGED
|
@@ -4899,6 +4899,52 @@ var AgentConnection = class _AgentConnection {
|
|
|
4899
4899
|
await agent.connect({ auth: options?.auth });
|
|
4900
4900
|
return agent;
|
|
4901
4901
|
}
|
|
4902
|
+
/**
|
|
4903
|
+
* Create an AgentConnection over WebSocket without performing the MAP handshake.
|
|
4904
|
+
*
|
|
4905
|
+
* Use this when you need to control the connection flow — e.g., to handle
|
|
4906
|
+
* server-driven auth negotiation before registration.
|
|
4907
|
+
*
|
|
4908
|
+
* @example
|
|
4909
|
+
* ```typescript
|
|
4910
|
+
* const agent = await AgentConnection.createConnection('ws://localhost:8080', {
|
|
4911
|
+
* name: 'Worker',
|
|
4912
|
+
* role: 'processor',
|
|
4913
|
+
* });
|
|
4914
|
+
*
|
|
4915
|
+
* const result = await agent.connectOnly();
|
|
4916
|
+
* if (result.authRequired) {
|
|
4917
|
+
* await agent.authenticate({ method: result.authRequired.methods[0], token: cred });
|
|
4918
|
+
* }
|
|
4919
|
+
* await agent.register();
|
|
4920
|
+
* ```
|
|
4921
|
+
*/
|
|
4922
|
+
static async createConnection(url, options) {
|
|
4923
|
+
const parsedUrl = new URL(url);
|
|
4924
|
+
if (!["ws:", "wss:"].includes(parsedUrl.protocol)) {
|
|
4925
|
+
throw new Error(`Unsupported protocol: ${parsedUrl.protocol}. Use ws: or wss:`);
|
|
4926
|
+
}
|
|
4927
|
+
const timeout = options?.connectTimeout ?? 1e4;
|
|
4928
|
+
const ws = new WebSocket(url);
|
|
4929
|
+
await waitForOpen(ws, timeout);
|
|
4930
|
+
const stream = websocketStream(ws);
|
|
4931
|
+
const createStream = async () => {
|
|
4932
|
+
const newWs = new WebSocket(url);
|
|
4933
|
+
await waitForOpen(newWs, timeout);
|
|
4934
|
+
return websocketStream(newWs);
|
|
4935
|
+
};
|
|
4936
|
+
const reconnection = options?.reconnection === true ? { enabled: true } : typeof options?.reconnection === "object" ? options.reconnection : void 0;
|
|
4937
|
+
return new _AgentConnection(stream, {
|
|
4938
|
+
name: options?.name,
|
|
4939
|
+
role: options?.role,
|
|
4940
|
+
capabilities: options?.capabilities,
|
|
4941
|
+
visibility: options?.visibility,
|
|
4942
|
+
parent: options?.parent,
|
|
4943
|
+
scopes: options?.scopes,
|
|
4944
|
+
createStream,
|
|
4945
|
+
reconnection
|
|
4946
|
+
});
|
|
4947
|
+
}
|
|
4902
4948
|
/**
|
|
4903
4949
|
* Connect and register an agent via agentic-mesh transport.
|
|
4904
4950
|
*
|
|
@@ -4995,6 +5041,65 @@ var AgentConnection = class _AgentConnection {
|
|
|
4995
5041
|
this.#connection._transitionTo("connected");
|
|
4996
5042
|
return { connection: connectResult, agent: registerResult.agent };
|
|
4997
5043
|
}
|
|
5044
|
+
/**
|
|
5045
|
+
* Connect to the MAP system without registering an agent.
|
|
5046
|
+
*
|
|
5047
|
+
* Use this when the server may require authentication before registration.
|
|
5048
|
+
* After connecting, check `authRequired` in the response and call
|
|
5049
|
+
* `authenticate()` if needed, then `register()` to complete the handshake.
|
|
5050
|
+
*
|
|
5051
|
+
* @example
|
|
5052
|
+
* ```typescript
|
|
5053
|
+
* const result = await agent.connectOnly();
|
|
5054
|
+
*
|
|
5055
|
+
* if (result.authRequired) {
|
|
5056
|
+
* const method = result.authRequired.methods[0];
|
|
5057
|
+
* await agent.authenticate({ method, token: myCredential });
|
|
5058
|
+
* }
|
|
5059
|
+
*
|
|
5060
|
+
* await agent.register();
|
|
5061
|
+
* ```
|
|
5062
|
+
*/
|
|
5063
|
+
async connectOnly(options) {
|
|
5064
|
+
const connectParams = {
|
|
5065
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
5066
|
+
participantType: "agent",
|
|
5067
|
+
participantId: options?.agentId,
|
|
5068
|
+
name: this.#options.name,
|
|
5069
|
+
capabilities: this.#options.capabilities,
|
|
5070
|
+
resumeToken: options?.resumeToken,
|
|
5071
|
+
auth: options?.auth
|
|
5072
|
+
};
|
|
5073
|
+
const connectResult = await this.#connection.sendRequest(CORE_METHODS.CONNECT, connectParams);
|
|
5074
|
+
this.#sessionId = connectResult.sessionId;
|
|
5075
|
+
this.#serverCapabilities = connectResult.capabilities;
|
|
5076
|
+
this.#connected = true;
|
|
5077
|
+
this.#lastConnectOptions = options;
|
|
5078
|
+
return connectResult;
|
|
5079
|
+
}
|
|
5080
|
+
/**
|
|
5081
|
+
* Register as an agent after connecting.
|
|
5082
|
+
*
|
|
5083
|
+
* Call this after `connectOnly()` and optional `authenticate()` to complete
|
|
5084
|
+
* the connection handshake. Uses the options provided during construction
|
|
5085
|
+
* (name, role, scopes, etc.) unless overridden.
|
|
5086
|
+
*/
|
|
5087
|
+
async register(overrides) {
|
|
5088
|
+
const registerParams = {
|
|
5089
|
+
agentId: overrides?.agentId ?? this.#lastConnectOptions?.agentId,
|
|
5090
|
+
name: overrides?.name ?? this.#options.name,
|
|
5091
|
+
role: overrides?.role ?? this.#options.role,
|
|
5092
|
+
parent: this.#options.parent,
|
|
5093
|
+
scopes: this.#options.scopes,
|
|
5094
|
+
visibility: this.#options.visibility,
|
|
5095
|
+
capabilities: this.#options.capabilities
|
|
5096
|
+
};
|
|
5097
|
+
const registerResult = await this.#connection.sendRequest(LIFECYCLE_METHODS.AGENTS_REGISTER, registerParams);
|
|
5098
|
+
this.#agentId = registerResult.agent.id;
|
|
5099
|
+
this.#currentState = registerResult.agent.state;
|
|
5100
|
+
this.#connection._transitionTo("connected");
|
|
5101
|
+
return registerResult.agent;
|
|
5102
|
+
}
|
|
4998
5103
|
/**
|
|
4999
5104
|
* Authenticate with the server after connection.
|
|
5000
5105
|
*
|
|
@@ -5007,20 +5112,15 @@ var AgentConnection = class _AgentConnection {
|
|
|
5007
5112
|
*
|
|
5008
5113
|
* @example
|
|
5009
5114
|
* ```typescript
|
|
5010
|
-
* const
|
|
5115
|
+
* const result = await agent.connectOnly();
|
|
5011
5116
|
*
|
|
5012
|
-
*
|
|
5013
|
-
* const connectResult = await agent.connectOnly();
|
|
5014
|
-
*
|
|
5015
|
-
* if (connectResult.authRequired) {
|
|
5117
|
+
* if (result.authRequired) {
|
|
5016
5118
|
* const authResult = await agent.authenticate({
|
|
5017
|
-
* method:
|
|
5018
|
-
* token:
|
|
5119
|
+
* method: result.authRequired.methods[0],
|
|
5120
|
+
* token: myCredential,
|
|
5019
5121
|
* });
|
|
5020
|
-
*
|
|
5021
5122
|
* if (authResult.success) {
|
|
5022
|
-
*
|
|
5023
|
-
* await agent.register({ name: 'MyAgent', role: 'worker' });
|
|
5123
|
+
* await agent.register();
|
|
5024
5124
|
* }
|
|
5025
5125
|
* }
|
|
5026
5126
|
* ```
|