@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.
@@ -1,4 +1,4 @@
1
- import { P as ParticipantCapabilities, hG as SystemExposure, d as FederationRoutingConfig, S as Stream, cy as BaseConnection, f as SessionId, A as AgentId, n as Agent, m as ScopeId, o as Scope, g9 as TaskId, dH as MAPTask, c as Message, r as Event, k as ParticipantId, N as SubscriptionId, cG as ClientConnectionOptions, cF as ClientConnection, c3 as AgentsListRequestParams, fy as ScopesListRequestParams, q as SubscriptionFilter, fY as Subscription, e as EventType, bM as AgentConnectionOptions, X as AgentConnection } from './index-BVrYVfaf.cjs';
1
+ import { P as ParticipantCapabilities, hG as SystemExposure, d as FederationRoutingConfig, S as Stream, cy as BaseConnection, f as SessionId, A as AgentId, n as Agent, m as ScopeId, o as Scope, g9 as TaskId, dH as MAPTask, c as Message, r as Event, k as ParticipantId, N as SubscriptionId, cG as ClientConnectionOptions, cF as ClientConnection, c3 as AgentsListRequestParams, fy as ScopesListRequestParams, q as SubscriptionFilter, fY as Subscription, e as EventType, bM as AgentConnectionOptions, X as AgentConnection } from './index-iu0EgJzG.cjs';
2
2
  import 'events';
3
3
 
4
4
  /**
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as ParticipantCapabilities, hG as SystemExposure, d as FederationRoutingConfig, S as Stream, cy as BaseConnection, f as SessionId, A as AgentId, n as Agent, m as ScopeId, o as Scope, g9 as TaskId, dH as MAPTask, c as Message, r as Event, k as ParticipantId, N as SubscriptionId, cG as ClientConnectionOptions, cF as ClientConnection, c3 as AgentsListRequestParams, fy as ScopesListRequestParams, q as SubscriptionFilter, fY as Subscription, e as EventType, bM as AgentConnectionOptions, X as AgentConnection } from './index-BVrYVfaf.js';
1
+ import { P as ParticipantCapabilities, hG as SystemExposure, d as FederationRoutingConfig, S as Stream, cy as BaseConnection, f as SessionId, A as AgentId, n as Agent, m as ScopeId, o as Scope, g9 as TaskId, dH as MAPTask, c as Message, r as Event, k as ParticipantId, N as SubscriptionId, cG as ClientConnectionOptions, cF as ClientConnection, c3 as AgentsListRequestParams, fy as ScopesListRequestParams, q as SubscriptionFilter, fY as Subscription, e as EventType, bM as AgentConnectionOptions, X as AgentConnection } from './index-iu0EgJzG.js';
2
2
  import 'events';
3
3
 
4
4
  /**
package/dist/testing.js CHANGED
@@ -4897,6 +4897,52 @@ var AgentConnection = class _AgentConnection {
4897
4897
  await agent.connect({ auth: options?.auth });
4898
4898
  return agent;
4899
4899
  }
4900
+ /**
4901
+ * Create an AgentConnection over WebSocket without performing the MAP handshake.
4902
+ *
4903
+ * Use this when you need to control the connection flow — e.g., to handle
4904
+ * server-driven auth negotiation before registration.
4905
+ *
4906
+ * @example
4907
+ * ```typescript
4908
+ * const agent = await AgentConnection.createConnection('ws://localhost:8080', {
4909
+ * name: 'Worker',
4910
+ * role: 'processor',
4911
+ * });
4912
+ *
4913
+ * const result = await agent.connectOnly();
4914
+ * if (result.authRequired) {
4915
+ * await agent.authenticate({ method: result.authRequired.methods[0], token: cred });
4916
+ * }
4917
+ * await agent.register();
4918
+ * ```
4919
+ */
4920
+ static async createConnection(url, options) {
4921
+ const parsedUrl = new URL(url);
4922
+ if (!["ws:", "wss:"].includes(parsedUrl.protocol)) {
4923
+ throw new Error(`Unsupported protocol: ${parsedUrl.protocol}. Use ws: or wss:`);
4924
+ }
4925
+ const timeout = options?.connectTimeout ?? 1e4;
4926
+ const ws = new WebSocket(url);
4927
+ await waitForOpen(ws, timeout);
4928
+ const stream = websocketStream(ws);
4929
+ const createStream = async () => {
4930
+ const newWs = new WebSocket(url);
4931
+ await waitForOpen(newWs, timeout);
4932
+ return websocketStream(newWs);
4933
+ };
4934
+ const reconnection = options?.reconnection === true ? { enabled: true } : typeof options?.reconnection === "object" ? options.reconnection : void 0;
4935
+ return new _AgentConnection(stream, {
4936
+ name: options?.name,
4937
+ role: options?.role,
4938
+ capabilities: options?.capabilities,
4939
+ visibility: options?.visibility,
4940
+ parent: options?.parent,
4941
+ scopes: options?.scopes,
4942
+ createStream,
4943
+ reconnection
4944
+ });
4945
+ }
4900
4946
  /**
4901
4947
  * Connect and register an agent via agentic-mesh transport.
4902
4948
  *
@@ -4993,6 +5039,65 @@ var AgentConnection = class _AgentConnection {
4993
5039
  this.#connection._transitionTo("connected");
4994
5040
  return { connection: connectResult, agent: registerResult.agent };
4995
5041
  }
5042
+ /**
5043
+ * Connect to the MAP system without registering an agent.
5044
+ *
5045
+ * Use this when the server may require authentication before registration.
5046
+ * After connecting, check `authRequired` in the response and call
5047
+ * `authenticate()` if needed, then `register()` to complete the handshake.
5048
+ *
5049
+ * @example
5050
+ * ```typescript
5051
+ * const result = await agent.connectOnly();
5052
+ *
5053
+ * if (result.authRequired) {
5054
+ * const method = result.authRequired.methods[0];
5055
+ * await agent.authenticate({ method, token: myCredential });
5056
+ * }
5057
+ *
5058
+ * await agent.register();
5059
+ * ```
5060
+ */
5061
+ async connectOnly(options) {
5062
+ const connectParams = {
5063
+ protocolVersion: PROTOCOL_VERSION,
5064
+ participantType: "agent",
5065
+ participantId: options?.agentId,
5066
+ name: this.#options.name,
5067
+ capabilities: this.#options.capabilities,
5068
+ resumeToken: options?.resumeToken,
5069
+ auth: options?.auth
5070
+ };
5071
+ const connectResult = await this.#connection.sendRequest(CORE_METHODS.CONNECT, connectParams);
5072
+ this.#sessionId = connectResult.sessionId;
5073
+ this.#serverCapabilities = connectResult.capabilities;
5074
+ this.#connected = true;
5075
+ this.#lastConnectOptions = options;
5076
+ return connectResult;
5077
+ }
5078
+ /**
5079
+ * Register as an agent after connecting.
5080
+ *
5081
+ * Call this after `connectOnly()` and optional `authenticate()` to complete
5082
+ * the connection handshake. Uses the options provided during construction
5083
+ * (name, role, scopes, etc.) unless overridden.
5084
+ */
5085
+ async register(overrides) {
5086
+ const registerParams = {
5087
+ agentId: overrides?.agentId ?? this.#lastConnectOptions?.agentId,
5088
+ name: overrides?.name ?? this.#options.name,
5089
+ role: overrides?.role ?? this.#options.role,
5090
+ parent: this.#options.parent,
5091
+ scopes: this.#options.scopes,
5092
+ visibility: this.#options.visibility,
5093
+ capabilities: this.#options.capabilities
5094
+ };
5095
+ const registerResult = await this.#connection.sendRequest(LIFECYCLE_METHODS.AGENTS_REGISTER, registerParams);
5096
+ this.#agentId = registerResult.agent.id;
5097
+ this.#currentState = registerResult.agent.state;
5098
+ this.#connection._transitionTo("connected");
5099
+ return registerResult.agent;
5100
+ }
4996
5101
  /**
4997
5102
  * Authenticate with the server after connection.
4998
5103
  *
@@ -5005,20 +5110,15 @@ var AgentConnection = class _AgentConnection {
5005
5110
  *
5006
5111
  * @example
5007
5112
  * ```typescript
5008
- * const agent = new AgentConnection(stream, { name: 'MyAgent' });
5113
+ * const result = await agent.connectOnly();
5009
5114
  *
5010
- * // First connect to get auth requirements
5011
- * const connectResult = await agent.connectOnly();
5012
- *
5013
- * if (connectResult.authRequired) {
5115
+ * if (result.authRequired) {
5014
5116
  * const authResult = await agent.authenticate({
5015
- * method: 'api-key',
5016
- * token: process.env.AGENT_API_KEY,
5117
+ * method: result.authRequired.methods[0],
5118
+ * token: myCredential,
5017
5119
  * });
5018
- *
5019
5120
  * if (authResult.success) {
5020
- * // Now register the agent
5021
- * await agent.register({ name: 'MyAgent', role: 'worker' });
5121
+ * await agent.register();
5022
5122
  * }
5023
5123
  * }
5024
5124
  * ```