@artinet/sdk 0.6.6 → 0.6.8
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/browser/messenger/messenger.d.ts +6 -6
- package/dist/browser/messenger/messenger.js +31 -32
- package/dist/browser/utils/utils.d.ts +21 -1
- package/dist/browser/utils/utils.js +26 -2
- package/dist/messenger/messenger.d.ts +6 -6
- package/dist/messenger/messenger.js +31 -32
- package/dist/services/a2a/helpers/content.js +8 -8
- package/dist/services/a2a/service.d.ts +6 -6
- package/dist/services/a2a/service.js +23 -23
- package/dist/services/core/manager.js +10 -3
- package/dist/services/mcp/modules/mem.d.ts +58 -0
- package/dist/services/mcp/modules/mem.js +112 -0
- package/dist/utils/utils.d.ts +21 -1
- package/dist/utils/utils.js +26 -2
- package/package.json +7 -1
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { A2A } from "../types/index.js";
|
|
6
6
|
import * as describe from "../create/describe.js";
|
|
7
|
-
import { ClientFactoryOptions, ClientConfig, Client, Transport, RequestOptions } from
|
|
8
|
-
import { z } from
|
|
7
|
+
import { ClientFactoryOptions, ClientConfig, Client, Transport, RequestOptions } from '@a2a-js/sdk/client';
|
|
8
|
+
import { z } from 'zod/v4';
|
|
9
9
|
export declare const MessengerParamsSchema: z.ZodObject<{
|
|
10
10
|
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
11
11
|
authToken: z.ZodOptional<z.ZodString>;
|
|
@@ -19,7 +19,7 @@ type BaseMessengerParams = z.infer<typeof MessengerParamsSchema>;
|
|
|
19
19
|
* @returns True if the parameters are a valid MessengerParams object, false otherwise.
|
|
20
20
|
*/
|
|
21
21
|
export declare const isMessengerParams: (params: unknown) => params is MessengerParams;
|
|
22
|
-
export interface MessengerParams extends Omit<BaseMessengerParams,
|
|
22
|
+
export interface MessengerParams extends Omit<BaseMessengerParams, 'baseUrl'> {
|
|
23
23
|
baseUrl: URL | string;
|
|
24
24
|
factory?: Partial<ClientFactoryOptions>;
|
|
25
25
|
config?: ClientConfig;
|
|
@@ -28,7 +28,7 @@ export interface MessengerParams extends Omit<BaseMessengerParams, "baseUrl"> {
|
|
|
28
28
|
* Messenger is the main communication client for interacting with remote A2A-compatible services.
|
|
29
29
|
* It provides methods for sending messages, retrieving tasks, canceling operations, and handling streaming responses.
|
|
30
30
|
*/
|
|
31
|
-
declare class Messenger implements Omit<Transport,
|
|
31
|
+
declare class Messenger implements Omit<Transport, 'getAuthenticatedExtendedAgentCard' | 'getExtendedAgentCard'> {
|
|
32
32
|
private _headers;
|
|
33
33
|
private _fallbackPath?;
|
|
34
34
|
private _baseUrl;
|
|
@@ -88,7 +88,7 @@ declare class Messenger implements Omit<Transport, "getAuthenticatedExtendedAgen
|
|
|
88
88
|
* @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
|
|
89
89
|
* @returns A promise resolving to true if the capability is supported.
|
|
90
90
|
*/
|
|
91
|
-
supports(capability:
|
|
91
|
+
supports(capability: 'streaming' | 'pushNotifications' | 'stateTransitionHistory' | 'extensions'): Promise<boolean>;
|
|
92
92
|
/**
|
|
93
93
|
* Adds a single header to be included in all requests.
|
|
94
94
|
* @param name The header name.
|
|
@@ -100,7 +100,7 @@ declare class Messenger implements Omit<Transport, "getAuthenticatedExtendedAgen
|
|
|
100
100
|
* @param name The header name to remove.
|
|
101
101
|
*/
|
|
102
102
|
removeHeader(name: string): void;
|
|
103
|
-
static create({ baseUrl, headers, fallbackPath, factory, config
|
|
103
|
+
static create({ baseUrl, headers, fallbackPath, factory, config }: MessengerParams): Promise<Messenger>;
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Creates a new Messenger instance.
|
|
@@ -6,9 +6,9 @@ import { A2A } from "../types/index.js";
|
|
|
6
6
|
import { validateSchema } from "../utils/schema-validation.js";
|
|
7
7
|
import { logger } from "../config/index.js";
|
|
8
8
|
import * as describe from "../create/describe.js";
|
|
9
|
-
import { ClientFactory, ClientFactoryOptions, AgentCardResolver, } from
|
|
10
|
-
import { Runtime } from
|
|
11
|
-
import { z } from
|
|
9
|
+
import { ClientFactory, ClientFactoryOptions, AgentCardResolver, } from '@a2a-js/sdk/client';
|
|
10
|
+
import { Runtime } from '@artinet/types';
|
|
11
|
+
import { z } from 'zod/v4';
|
|
12
12
|
class HeaderInterceptor {
|
|
13
13
|
constructor(_getCustomHeaders) {
|
|
14
14
|
this._getCustomHeaders = _getCustomHeaders;
|
|
@@ -40,14 +40,14 @@ class NestedAgentCardResolver {
|
|
|
40
40
|
const agentCard = await AgentCardResolver.default
|
|
41
41
|
.resolve(baseUrl, path)
|
|
42
42
|
.catch((error) => {
|
|
43
|
-
logger.
|
|
43
|
+
logger.debug('Failed to fetch agent card', { error });
|
|
44
44
|
return undefined;
|
|
45
45
|
});
|
|
46
46
|
if (agentCard) {
|
|
47
47
|
return agentCard;
|
|
48
48
|
}
|
|
49
|
-
logger.
|
|
50
|
-
const response = await this._fetchImpl(baseUrl + (path ??
|
|
49
|
+
logger.debug('Fetching agent card from', { baseUrl });
|
|
50
|
+
const response = await this._fetchImpl(baseUrl + (path ?? '/well-known/agent-card.json'));
|
|
51
51
|
if (!response.ok) {
|
|
52
52
|
throw new Error(`Failed to fetch Agent Card from ${baseUrl}: ${response.status}`);
|
|
53
53
|
}
|
|
@@ -77,35 +77,34 @@ class Messenger {
|
|
|
77
77
|
constructor(baseUrl, _headers = {}, _fallbackPath, factory = ClientFactoryOptions.default, config) {
|
|
78
78
|
this._headers = _headers;
|
|
79
79
|
this._fallbackPath = _fallbackPath;
|
|
80
|
-
this._baseUrl = typeof baseUrl ===
|
|
81
|
-
this._fallbackPath = _fallbackPath ??
|
|
80
|
+
this._baseUrl = typeof baseUrl === 'string' ? baseUrl : baseUrl.toString();
|
|
81
|
+
this._fallbackPath = _fallbackPath ?? '/agent.json';
|
|
82
82
|
this._factory = new ClientFactory(ClientFactoryOptions.createFrom(factory, {
|
|
83
83
|
clientConfig: {
|
|
84
84
|
...config,
|
|
85
|
-
interceptors: [
|
|
86
|
-
...(config?.interceptors ?? []),
|
|
87
|
-
new HeaderInterceptor(() => this.headers),
|
|
88
|
-
],
|
|
85
|
+
interceptors: [...(config?.interceptors ?? []), new HeaderInterceptor(() => this.headers)],
|
|
89
86
|
},
|
|
90
87
|
}));
|
|
91
88
|
//RAII
|
|
92
89
|
this.clientPromise = this.reset(this._baseUrl, this._fallbackPath);
|
|
93
90
|
}
|
|
94
91
|
async reset(baseUrl = this._baseUrl, fallbackPath = this._fallbackPath) {
|
|
95
|
-
this._baseUrl = typeof baseUrl ===
|
|
96
|
-
this._fallbackPath = fallbackPath ??
|
|
97
|
-
this.clientPromise = this._factory
|
|
98
|
-
.createFromUrl(this._baseUrl)
|
|
99
|
-
.catch(async (error) => {
|
|
92
|
+
this._baseUrl = typeof baseUrl === 'string' ? baseUrl : baseUrl.toString();
|
|
93
|
+
this._fallbackPath = fallbackPath ?? '/agent.json';
|
|
94
|
+
this.clientPromise = this._factory.createFromUrl(this._baseUrl).catch(async (error) => {
|
|
100
95
|
if (!this._fallbackPath) {
|
|
101
|
-
logger.
|
|
96
|
+
logger.debug('Messenger: Failed to create client, no fallback path provided', { error });
|
|
102
97
|
throw error;
|
|
103
98
|
}
|
|
104
|
-
logger.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
logger.debug('Messenger: Failed to create client, falling back to fallback path: ', {
|
|
100
|
+
error,
|
|
101
|
+
fallbackPath: this._fallbackPath,
|
|
102
|
+
});
|
|
103
|
+
return await this._factory.createFromUrl(this._baseUrl, this._fallbackPath).catch(async (error) => {
|
|
104
|
+
logger.debug('Messenger: Failed to create client, at fallback path: ', {
|
|
105
|
+
error,
|
|
106
|
+
fallbackPath: this._fallbackPath,
|
|
107
|
+
});
|
|
109
108
|
throw error;
|
|
110
109
|
});
|
|
111
110
|
});
|
|
@@ -152,7 +151,7 @@ class Messenger {
|
|
|
152
151
|
yield* client.sendMessageStream(describe.messageSendParams(params), options);
|
|
153
152
|
}
|
|
154
153
|
catch (error) {
|
|
155
|
-
logger.error(
|
|
154
|
+
logger.error('Messenger: Failed to send message stream', { error });
|
|
156
155
|
throw error;
|
|
157
156
|
}
|
|
158
157
|
}
|
|
@@ -211,7 +210,7 @@ class Messenger {
|
|
|
211
210
|
yield* client.resubscribeTask(params, options);
|
|
212
211
|
}
|
|
213
212
|
catch (error) {
|
|
214
|
-
logger.error(
|
|
213
|
+
logger.error('Messenger: Failed to resubscribe task', { error });
|
|
215
214
|
throw error;
|
|
216
215
|
}
|
|
217
216
|
}
|
|
@@ -226,13 +225,13 @@ class Messenger {
|
|
|
226
225
|
return false;
|
|
227
226
|
}
|
|
228
227
|
switch (capability) {
|
|
229
|
-
case
|
|
228
|
+
case 'streaming':
|
|
230
229
|
return !!card.capabilities.streaming;
|
|
231
|
-
case
|
|
230
|
+
case 'pushNotifications':
|
|
232
231
|
return !!card.capabilities.pushNotifications;
|
|
233
|
-
case
|
|
232
|
+
case 'stateTransitionHistory':
|
|
234
233
|
return !!card.capabilities.stateTransitionHistory;
|
|
235
|
-
case
|
|
234
|
+
case 'extensions':
|
|
236
235
|
return !!card.capabilities.extensions;
|
|
237
236
|
default:
|
|
238
237
|
return false;
|
|
@@ -253,11 +252,11 @@ class Messenger {
|
|
|
253
252
|
removeHeader(name) {
|
|
254
253
|
delete this.headers[name];
|
|
255
254
|
}
|
|
256
|
-
static async create({ baseUrl, headers, fallbackPath, factory, config
|
|
255
|
+
static async create({ baseUrl, headers, fallbackPath, factory, config }) {
|
|
257
256
|
const _factory = {
|
|
258
257
|
...ClientFactoryOptions.default,
|
|
259
258
|
cardResolver: new NestedAgentCardResolver({
|
|
260
|
-
path:
|
|
259
|
+
path: '/.well-known/agent-card.json',
|
|
261
260
|
}),
|
|
262
261
|
...factory,
|
|
263
262
|
};
|
|
@@ -265,7 +264,7 @@ class Messenger {
|
|
|
265
264
|
const card = await messenger.getAgentCard();
|
|
266
265
|
/**Validate the agent card to ensure the target conforms to the A2A specification */
|
|
267
266
|
await validateSchema(A2A.AgentCardSchema, card).catch((error) => {
|
|
268
|
-
logger.warn(
|
|
267
|
+
logger.warn('Messenger: Invalid agent card detected', { error });
|
|
269
268
|
});
|
|
270
269
|
return messenger;
|
|
271
270
|
}
|
|
@@ -21,12 +21,32 @@ export declare function sleep(ms: number): Promise<void>;
|
|
|
21
21
|
/**
|
|
22
22
|
* Formats a JSON object into a string with indentation.
|
|
23
23
|
* @param json - The JSON object to format.
|
|
24
|
+
* @param replacer - A function that transforms the results.
|
|
25
|
+
* @param space - Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
|
|
24
26
|
* @returns A string representation of the JSON object.
|
|
25
27
|
*/
|
|
26
|
-
export declare function formatJson(json: object): string;
|
|
28
|
+
export declare function formatJson(json: object, replacer?: (number | string)[] | null, space?: string | number): string;
|
|
27
29
|
/**
|
|
28
30
|
* Formats an error into a standard error object for logging.
|
|
29
31
|
* @param error - The error to format.
|
|
30
32
|
* @returns A standard error object.
|
|
31
33
|
*/
|
|
32
34
|
export declare function formatError(error: unknown): Error;
|
|
35
|
+
/**
|
|
36
|
+
* Executes a function immediately.
|
|
37
|
+
* @param fn - The function to execute.
|
|
38
|
+
* @returns The result of the function.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const result = iife(() => {
|
|
43
|
+
* return 1 + 1;
|
|
44
|
+
* });
|
|
45
|
+
* console.log(result); // 2
|
|
46
|
+
* ```
|
|
47
|
+
* LangChain <3
|
|
48
|
+
* @see https://github.com/langchain-ai/langchainjs/blob/981cf9c480925187a524fd6ad1dbf0488d2758eb/libs/langchain-core/src/language_models/utils.ts#L5
|
|
49
|
+
*/
|
|
50
|
+
export declare const iife: <T>(fn: () => T) => T;
|
|
51
|
+
export declare function encodeBase64(data: string): string;
|
|
52
|
+
export declare function decodeBase64(data: string): string;
|
|
@@ -25,10 +25,12 @@ export function sleep(ms) {
|
|
|
25
25
|
/**
|
|
26
26
|
* Formats a JSON object into a string with indentation.
|
|
27
27
|
* @param json - The JSON object to format.
|
|
28
|
+
* @param replacer - A function that transforms the results.
|
|
29
|
+
* @param space - Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
|
|
28
30
|
* @returns A string representation of the JSON object.
|
|
29
31
|
*/
|
|
30
|
-
export function formatJson(json) {
|
|
31
|
-
return JSON.stringify(json,
|
|
32
|
+
export function formatJson(json, replacer = null, space = 2) {
|
|
33
|
+
return JSON.stringify(json, replacer, space);
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Formats an error into a standard error object for logging.
|
|
@@ -41,3 +43,25 @@ export function formatError(error) {
|
|
|
41
43
|
}
|
|
42
44
|
return new Error(String(error));
|
|
43
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Executes a function immediately.
|
|
48
|
+
* @param fn - The function to execute.
|
|
49
|
+
* @returns The result of the function.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const result = iife(() => {
|
|
54
|
+
* return 1 + 1;
|
|
55
|
+
* });
|
|
56
|
+
* console.log(result); // 2
|
|
57
|
+
* ```
|
|
58
|
+
* LangChain <3
|
|
59
|
+
* @see https://github.com/langchain-ai/langchainjs/blob/981cf9c480925187a524fd6ad1dbf0488d2758eb/libs/langchain-core/src/language_models/utils.ts#L5
|
|
60
|
+
*/
|
|
61
|
+
export const iife = (fn) => fn();
|
|
62
|
+
export function encodeBase64(data) {
|
|
63
|
+
return Buffer.from(data).toString('base64');
|
|
64
|
+
}
|
|
65
|
+
export function decodeBase64(data) {
|
|
66
|
+
return Buffer.from(data, 'base64').toString();
|
|
67
|
+
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { A2A } from "../types/index.js";
|
|
6
6
|
import * as describe from "../create/describe.js";
|
|
7
|
-
import { ClientFactoryOptions, ClientConfig, Client, Transport, RequestOptions } from
|
|
8
|
-
import { z } from
|
|
7
|
+
import { ClientFactoryOptions, ClientConfig, Client, Transport, RequestOptions } from '@a2a-js/sdk/client';
|
|
8
|
+
import { z } from 'zod/v4';
|
|
9
9
|
export declare const MessengerParamsSchema: z.ZodObject<{
|
|
10
10
|
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
11
11
|
authToken: z.ZodOptional<z.ZodString>;
|
|
@@ -19,7 +19,7 @@ type BaseMessengerParams = z.infer<typeof MessengerParamsSchema>;
|
|
|
19
19
|
* @returns True if the parameters are a valid MessengerParams object, false otherwise.
|
|
20
20
|
*/
|
|
21
21
|
export declare const isMessengerParams: (params: unknown) => params is MessengerParams;
|
|
22
|
-
export interface MessengerParams extends Omit<BaseMessengerParams,
|
|
22
|
+
export interface MessengerParams extends Omit<BaseMessengerParams, 'baseUrl'> {
|
|
23
23
|
baseUrl: URL | string;
|
|
24
24
|
factory?: Partial<ClientFactoryOptions>;
|
|
25
25
|
config?: ClientConfig;
|
|
@@ -28,7 +28,7 @@ export interface MessengerParams extends Omit<BaseMessengerParams, "baseUrl"> {
|
|
|
28
28
|
* Messenger is the main communication client for interacting with remote A2A-compatible services.
|
|
29
29
|
* It provides methods for sending messages, retrieving tasks, canceling operations, and handling streaming responses.
|
|
30
30
|
*/
|
|
31
|
-
declare class Messenger implements Omit<Transport,
|
|
31
|
+
declare class Messenger implements Omit<Transport, 'getAuthenticatedExtendedAgentCard' | 'getExtendedAgentCard'> {
|
|
32
32
|
private _headers;
|
|
33
33
|
private _fallbackPath?;
|
|
34
34
|
private _baseUrl;
|
|
@@ -88,7 +88,7 @@ declare class Messenger implements Omit<Transport, "getAuthenticatedExtendedAgen
|
|
|
88
88
|
* @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
|
|
89
89
|
* @returns A promise resolving to true if the capability is supported.
|
|
90
90
|
*/
|
|
91
|
-
supports(capability:
|
|
91
|
+
supports(capability: 'streaming' | 'pushNotifications' | 'stateTransitionHistory' | 'extensions'): Promise<boolean>;
|
|
92
92
|
/**
|
|
93
93
|
* Adds a single header to be included in all requests.
|
|
94
94
|
* @param name The header name.
|
|
@@ -100,7 +100,7 @@ declare class Messenger implements Omit<Transport, "getAuthenticatedExtendedAgen
|
|
|
100
100
|
* @param name The header name to remove.
|
|
101
101
|
*/
|
|
102
102
|
removeHeader(name: string): void;
|
|
103
|
-
static create({ baseUrl, headers, fallbackPath, factory, config
|
|
103
|
+
static create({ baseUrl, headers, fallbackPath, factory, config }: MessengerParams): Promise<Messenger>;
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Creates a new Messenger instance.
|
|
@@ -6,9 +6,9 @@ import { A2A } from "../types/index.js";
|
|
|
6
6
|
import { validateSchema } from "../utils/schema-validation.js";
|
|
7
7
|
import { logger } from "../config/index.js";
|
|
8
8
|
import * as describe from "../create/describe.js";
|
|
9
|
-
import { ClientFactory, ClientFactoryOptions, AgentCardResolver, } from
|
|
10
|
-
import { Runtime } from
|
|
11
|
-
import { z } from
|
|
9
|
+
import { ClientFactory, ClientFactoryOptions, AgentCardResolver, } from '@a2a-js/sdk/client';
|
|
10
|
+
import { Runtime } from '@artinet/types';
|
|
11
|
+
import { z } from 'zod/v4';
|
|
12
12
|
class HeaderInterceptor {
|
|
13
13
|
_getCustomHeaders;
|
|
14
14
|
constructor(_getCustomHeaders) {
|
|
@@ -43,14 +43,14 @@ class NestedAgentCardResolver {
|
|
|
43
43
|
const agentCard = await AgentCardResolver.default
|
|
44
44
|
.resolve(baseUrl, path)
|
|
45
45
|
.catch((error) => {
|
|
46
|
-
logger.
|
|
46
|
+
logger.debug('Failed to fetch agent card', { error });
|
|
47
47
|
return undefined;
|
|
48
48
|
});
|
|
49
49
|
if (agentCard) {
|
|
50
50
|
return agentCard;
|
|
51
51
|
}
|
|
52
|
-
logger.
|
|
53
|
-
const response = await this._fetchImpl(baseUrl + (path ??
|
|
52
|
+
logger.debug('Fetching agent card from', { baseUrl });
|
|
53
|
+
const response = await this._fetchImpl(baseUrl + (path ?? '/well-known/agent-card.json'));
|
|
54
54
|
if (!response.ok) {
|
|
55
55
|
throw new Error(`Failed to fetch Agent Card from ${baseUrl}: ${response.status}`);
|
|
56
56
|
}
|
|
@@ -85,35 +85,34 @@ class Messenger {
|
|
|
85
85
|
constructor(baseUrl, _headers = {}, _fallbackPath, factory = ClientFactoryOptions.default, config) {
|
|
86
86
|
this._headers = _headers;
|
|
87
87
|
this._fallbackPath = _fallbackPath;
|
|
88
|
-
this._baseUrl = typeof baseUrl ===
|
|
89
|
-
this._fallbackPath = _fallbackPath ??
|
|
88
|
+
this._baseUrl = typeof baseUrl === 'string' ? baseUrl : baseUrl.toString();
|
|
89
|
+
this._fallbackPath = _fallbackPath ?? '/agent.json';
|
|
90
90
|
this._factory = new ClientFactory(ClientFactoryOptions.createFrom(factory, {
|
|
91
91
|
clientConfig: {
|
|
92
92
|
...config,
|
|
93
|
-
interceptors: [
|
|
94
|
-
...(config?.interceptors ?? []),
|
|
95
|
-
new HeaderInterceptor(() => this.headers),
|
|
96
|
-
],
|
|
93
|
+
interceptors: [...(config?.interceptors ?? []), new HeaderInterceptor(() => this.headers)],
|
|
97
94
|
},
|
|
98
95
|
}));
|
|
99
96
|
//RAII
|
|
100
97
|
this.clientPromise = this.reset(this._baseUrl, this._fallbackPath);
|
|
101
98
|
}
|
|
102
99
|
async reset(baseUrl = this._baseUrl, fallbackPath = this._fallbackPath) {
|
|
103
|
-
this._baseUrl = typeof baseUrl ===
|
|
104
|
-
this._fallbackPath = fallbackPath ??
|
|
105
|
-
this.clientPromise = this._factory
|
|
106
|
-
.createFromUrl(this._baseUrl)
|
|
107
|
-
.catch(async (error) => {
|
|
100
|
+
this._baseUrl = typeof baseUrl === 'string' ? baseUrl : baseUrl.toString();
|
|
101
|
+
this._fallbackPath = fallbackPath ?? '/agent.json';
|
|
102
|
+
this.clientPromise = this._factory.createFromUrl(this._baseUrl).catch(async (error) => {
|
|
108
103
|
if (!this._fallbackPath) {
|
|
109
|
-
logger.
|
|
104
|
+
logger.debug('Messenger: Failed to create client, no fallback path provided', { error });
|
|
110
105
|
throw error;
|
|
111
106
|
}
|
|
112
|
-
logger.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
107
|
+
logger.debug('Messenger: Failed to create client, falling back to fallback path: ', {
|
|
108
|
+
error,
|
|
109
|
+
fallbackPath: this._fallbackPath,
|
|
110
|
+
});
|
|
111
|
+
return await this._factory.createFromUrl(this._baseUrl, this._fallbackPath).catch(async (error) => {
|
|
112
|
+
logger.debug('Messenger: Failed to create client, at fallback path: ', {
|
|
113
|
+
error,
|
|
114
|
+
fallbackPath: this._fallbackPath,
|
|
115
|
+
});
|
|
117
116
|
throw error;
|
|
118
117
|
});
|
|
119
118
|
});
|
|
@@ -160,7 +159,7 @@ class Messenger {
|
|
|
160
159
|
yield* client.sendMessageStream(describe.messageSendParams(params), options);
|
|
161
160
|
}
|
|
162
161
|
catch (error) {
|
|
163
|
-
logger.error(
|
|
162
|
+
logger.error('Messenger: Failed to send message stream', { error });
|
|
164
163
|
throw error;
|
|
165
164
|
}
|
|
166
165
|
}
|
|
@@ -219,7 +218,7 @@ class Messenger {
|
|
|
219
218
|
yield* client.resubscribeTask(params, options);
|
|
220
219
|
}
|
|
221
220
|
catch (error) {
|
|
222
|
-
logger.error(
|
|
221
|
+
logger.error('Messenger: Failed to resubscribe task', { error });
|
|
223
222
|
throw error;
|
|
224
223
|
}
|
|
225
224
|
}
|
|
@@ -234,13 +233,13 @@ class Messenger {
|
|
|
234
233
|
return false;
|
|
235
234
|
}
|
|
236
235
|
switch (capability) {
|
|
237
|
-
case
|
|
236
|
+
case 'streaming':
|
|
238
237
|
return !!card.capabilities.streaming;
|
|
239
|
-
case
|
|
238
|
+
case 'pushNotifications':
|
|
240
239
|
return !!card.capabilities.pushNotifications;
|
|
241
|
-
case
|
|
240
|
+
case 'stateTransitionHistory':
|
|
242
241
|
return !!card.capabilities.stateTransitionHistory;
|
|
243
|
-
case
|
|
242
|
+
case 'extensions':
|
|
244
243
|
return !!card.capabilities.extensions;
|
|
245
244
|
default:
|
|
246
245
|
return false;
|
|
@@ -261,11 +260,11 @@ class Messenger {
|
|
|
261
260
|
removeHeader(name) {
|
|
262
261
|
delete this.headers[name];
|
|
263
262
|
}
|
|
264
|
-
static async create({ baseUrl, headers, fallbackPath, factory, config
|
|
263
|
+
static async create({ baseUrl, headers, fallbackPath, factory, config }) {
|
|
265
264
|
const _factory = {
|
|
266
265
|
...ClientFactoryOptions.default,
|
|
267
266
|
cardResolver: new NestedAgentCardResolver({
|
|
268
|
-
path:
|
|
267
|
+
path: '/.well-known/agent-card.json',
|
|
269
268
|
}),
|
|
270
269
|
...factory,
|
|
271
270
|
};
|
|
@@ -273,7 +272,7 @@ class Messenger {
|
|
|
273
272
|
const card = await messenger.getAgentCard();
|
|
274
273
|
/**Validate the agent card to ensure the target conforms to the A2A specification */
|
|
275
274
|
await validateSchema(A2A.AgentCardSchema, card).catch((error) => {
|
|
276
|
-
logger.warn(
|
|
275
|
+
logger.warn('Messenger: Invalid agent card detected', { error });
|
|
277
276
|
});
|
|
278
277
|
return messenger;
|
|
279
278
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { getParts } from
|
|
5
|
+
import { getParts } from './part.js';
|
|
6
6
|
/**
|
|
7
7
|
* Extracts the content of an agent response.
|
|
8
8
|
* @param input - The input event.
|
|
@@ -17,16 +17,16 @@ export function extractTextContent(input, legacy = true) {
|
|
|
17
17
|
[]);
|
|
18
18
|
if (legacy) {
|
|
19
19
|
return (parts.text ??
|
|
20
|
-
parts.file?.map((file) => file.bytes).join(
|
|
21
|
-
parts.file?.map((file) => file.uri).join(
|
|
22
|
-
parts.data?.map((data) => JSON.stringify(data)).join(
|
|
20
|
+
parts.file?.map((file) => file.bytes).join('\n') ??
|
|
21
|
+
parts.file?.map((file) => file.uri).join('\n') ??
|
|
22
|
+
parts.data?.map((data) => JSON.stringify(data)).join('\n') ??
|
|
23
23
|
undefined);
|
|
24
24
|
}
|
|
25
|
-
return parts.text && parts.text !==
|
|
25
|
+
return parts.text && parts.text !== ''
|
|
26
26
|
? parts.text
|
|
27
|
-
: parts.file?.map((file) => file.bytes ?? file.uri).join(
|
|
28
|
-
parts.data?.map((data) => JSON.stringify(data)).join(
|
|
29
|
-
undefined;
|
|
27
|
+
: (parts.file?.map((file) => file.bytes ?? file.uri).join('\n') ??
|
|
28
|
+
parts.data?.map((data) => JSON.stringify(data)).join('\n') ??
|
|
29
|
+
undefined);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* @deprecated Use extractTextContent instead.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { A2A } from "../../types/index.js";
|
|
6
|
-
import { ServiceParams } from
|
|
6
|
+
import { ServiceParams } from './factory/service.js';
|
|
7
7
|
/**
|
|
8
8
|
* @note We endeavor to remove all optional parameters from below this class.
|
|
9
9
|
* This will allow the service to act as the boundary to our Hexagonal Architecture.
|
|
@@ -30,9 +30,9 @@ export declare class Service implements A2A.Service {
|
|
|
30
30
|
get contexts(): A2A.Contexts;
|
|
31
31
|
set contexts(contexts: A2A.Contexts);
|
|
32
32
|
get streams(): A2A.Streams;
|
|
33
|
-
get overrides(): Partial<Omit<A2A.EventConsumer,
|
|
34
|
-
set overrides(overrides: Partial<Omit<A2A.EventConsumer,
|
|
35
|
-
execute({ engine, context
|
|
33
|
+
get overrides(): Partial<Omit<A2A.EventConsumer, 'contextId'>> | undefined;
|
|
34
|
+
set overrides(overrides: Partial<Omit<A2A.EventConsumer, 'contextId'>>);
|
|
35
|
+
execute({ engine, context }: {
|
|
36
36
|
engine: A2A.Engine;
|
|
37
37
|
context: A2A.Context;
|
|
38
38
|
}): Promise<void>;
|
|
@@ -41,11 +41,11 @@ export declare class Service implements A2A.Service {
|
|
|
41
41
|
getTask(params: A2A.TaskQueryParams, options?: A2A.ServiceOptions): Promise<A2A.Task>;
|
|
42
42
|
cancelTask(params: A2A.TaskIdParams, options?: A2A.ServiceOptions): Promise<A2A.Task>;
|
|
43
43
|
sendMessage(params: A2A.MessageSendParams, options?: A2A.ServiceOptions): Promise<A2A.SendMessageSuccessResult>;
|
|
44
|
-
sendMessage(message: string | A2A.MessageSendParams[
|
|
44
|
+
sendMessage(message: string | A2A.MessageSendParams['message'], options?: A2A.ServiceOptions): Promise<A2A.SendMessageSuccessResult>;
|
|
45
45
|
protected _sendMessage(params: A2A.MessageSendParams, options?: A2A.ServiceOptions): Promise<A2A.SendMessageSuccessResult>;
|
|
46
46
|
sendMessageStream(params: A2A.MessageSendParams, options?: A2A.ServiceOptions): AsyncGenerator<A2A.Update>;
|
|
47
47
|
sendMessageStream(message: string, options?: A2A.ServiceOptions): AsyncGenerator<A2A.Update>;
|
|
48
|
-
sendMessageStream(params: A2A.MessageSendParams[
|
|
48
|
+
sendMessageStream(params: A2A.MessageSendParams['message'], options?: A2A.ServiceOptions): AsyncGenerator<A2A.Update>;
|
|
49
49
|
/**
|
|
50
50
|
* @deprecated Use sendMessageStream instead
|
|
51
51
|
*/
|
|
@@ -6,21 +6,20 @@ import { A2A } from "../../types/index.js";
|
|
|
6
6
|
import { validateSchema } from "../../utils/schema-validation.js";
|
|
7
7
|
import * as describe from "../../create/describe.js";
|
|
8
8
|
import { INVALID_REQUEST, TASK_NOT_FOUND } from "../../utils/errors.js";
|
|
9
|
-
import { Messenger } from
|
|
10
|
-
import { execute } from
|
|
11
|
-
import { createService } from
|
|
12
|
-
import { getReferences } from
|
|
9
|
+
import { Messenger } from './messenger.js';
|
|
10
|
+
import { execute } from './execute.js';
|
|
11
|
+
import { createService } from './factory/service.js';
|
|
12
|
+
import { getReferences } from './helpers/references.js';
|
|
13
13
|
import { logger } from "../../config/index.js";
|
|
14
14
|
const taskToMessageParams = (task) => {
|
|
15
|
-
const latestUserMessage = task.history?.filter((msg) => msg.role ===
|
|
15
|
+
const latestUserMessage = task.history?.filter((msg) => msg.role === 'user')?.pop() ??
|
|
16
16
|
/**fallback to the first message if no user message is found */
|
|
17
17
|
task.history?.[0];
|
|
18
18
|
if (!latestUserMessage) {
|
|
19
|
-
throw INVALID_REQUEST(
|
|
19
|
+
throw INVALID_REQUEST('No user message found');
|
|
20
20
|
}
|
|
21
|
-
if (latestUserMessage.contextId &&
|
|
22
|
-
|
|
23
|
-
throw INVALID_REQUEST("User message context ID does not match task context ID");
|
|
21
|
+
if (latestUserMessage.contextId && latestUserMessage.contextId !== task.contextId) {
|
|
22
|
+
throw INVALID_REQUEST('User message context ID does not match task context ID');
|
|
24
23
|
}
|
|
25
24
|
const messageParams = {
|
|
26
25
|
message: {
|
|
@@ -49,13 +48,13 @@ const bindNotifier = async (context, taskId, config, notifier) => {
|
|
|
49
48
|
if (!notifier || !config) {
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
52
|
-
context.publisher.on(
|
|
51
|
+
context.publisher.on('update', async (task, update) => {
|
|
53
52
|
await notifier.notify(task, update, context).catch((error) => {
|
|
54
|
-
logger.error(
|
|
53
|
+
logger.error('Error sending push notification: ', { error });
|
|
55
54
|
});
|
|
56
55
|
});
|
|
57
56
|
await notifier.register(taskId, config).catch((error) => {
|
|
58
|
-
logger.error(
|
|
57
|
+
logger.error('Error registering push notification: ', { error });
|
|
59
58
|
});
|
|
60
59
|
};
|
|
61
60
|
/**
|
|
@@ -114,10 +113,12 @@ export class Service {
|
|
|
114
113
|
return this._contexts;
|
|
115
114
|
}
|
|
116
115
|
set contexts(contexts) {
|
|
117
|
-
this._contexts
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
this._contexts.list().then((list) => {
|
|
117
|
+
list.forEach((context) => {
|
|
118
|
+
contexts.set(context.contextId, context);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
this._contexts = contexts;
|
|
121
122
|
}
|
|
122
123
|
get streams() {
|
|
123
124
|
return this._streams;
|
|
@@ -131,7 +132,7 @@ export class Service {
|
|
|
131
132
|
...overrides,
|
|
132
133
|
};
|
|
133
134
|
}
|
|
134
|
-
async execute({ engine, context
|
|
135
|
+
async execute({ engine, context }) {
|
|
135
136
|
await execute(engine, context);
|
|
136
137
|
}
|
|
137
138
|
async getAgentCard() {
|
|
@@ -143,7 +144,7 @@ export class Service {
|
|
|
143
144
|
await context.publisher.onCancel(describe.update.canceled({
|
|
144
145
|
contextId: context.contextId,
|
|
145
146
|
taskId: context.taskId,
|
|
146
|
-
message: describe.message(
|
|
147
|
+
message: describe.message('service stopped'),
|
|
147
148
|
}));
|
|
148
149
|
}
|
|
149
150
|
return;
|
|
@@ -233,8 +234,7 @@ export class Service {
|
|
|
233
234
|
}
|
|
234
235
|
async *sendMessageStream(_params, options) {
|
|
235
236
|
let params;
|
|
236
|
-
if (typeof _params ===
|
|
237
|
-
(typeof _params === "object" && "parts" in _params)) {
|
|
237
|
+
if (typeof _params === 'string' || (typeof _params === 'object' && 'parts' in _params)) {
|
|
238
238
|
params = describe.messageSendParams(_params);
|
|
239
239
|
}
|
|
240
240
|
else {
|
|
@@ -252,7 +252,7 @@ export class Service {
|
|
|
252
252
|
}
|
|
253
253
|
async *_sendMessageStream(params, options) {
|
|
254
254
|
const messageParams = await validateSchema(A2A.MessageSendParamsSchema, params);
|
|
255
|
-
logger.info(
|
|
255
|
+
logger.info('Service[streamMessage]:', {
|
|
256
256
|
taskId: messageParams.message.taskId,
|
|
257
257
|
contextId: messageParams.message.contextId,
|
|
258
258
|
});
|
|
@@ -265,7 +265,7 @@ export class Service {
|
|
|
265
265
|
...messageParams.metadata,
|
|
266
266
|
},
|
|
267
267
|
}));
|
|
268
|
-
logger.debug(
|
|
268
|
+
logger.debug('Service[streamMessage]: task created', {
|
|
269
269
|
taskId: task.id,
|
|
270
270
|
contextId: task.contextId,
|
|
271
271
|
});
|
|
@@ -294,7 +294,7 @@ export class Service {
|
|
|
294
294
|
if (!task) {
|
|
295
295
|
throw TASK_NOT_FOUND({ taskId: taskParams.id });
|
|
296
296
|
}
|
|
297
|
-
logger.debug(
|
|
297
|
+
logger.debug('Service[resubscribe]:', {
|
|
298
298
|
taskId: task.id,
|
|
299
299
|
contextId: task.contextId,
|
|
300
300
|
});
|
|
@@ -72,9 +72,9 @@ export class Manager {
|
|
|
72
72
|
async list() {
|
|
73
73
|
const listed = Array.from(this.cache.values());
|
|
74
74
|
if (this.storage) {
|
|
75
|
+
const storedList = (await this.storage.list?.())?.filter((item) => item !== undefined && !listed.includes(item));
|
|
75
76
|
/** Could be an expensive operation */
|
|
76
|
-
listed.push(...(
|
|
77
|
-
[]));
|
|
77
|
+
listed.push(...(storedList ?? []));
|
|
78
78
|
}
|
|
79
79
|
return listed;
|
|
80
80
|
}
|
|
@@ -88,7 +88,14 @@ export class Manager {
|
|
|
88
88
|
}
|
|
89
89
|
const results = [];
|
|
90
90
|
if (filter) {
|
|
91
|
-
|
|
91
|
+
const items = Array.from(this.cache.values());
|
|
92
|
+
const filterResults = await Promise.all(items.map(async (item) => {
|
|
93
|
+
if (await filter(item)) {
|
|
94
|
+
return item;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}));
|
|
98
|
+
results.push(...filterResults.filter((item) => item !== undefined));
|
|
92
99
|
}
|
|
93
100
|
if (this.storage) {
|
|
94
101
|
const storageFilter = async (item) => {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
6
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
7
|
+
import { z } from 'zod/v4';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for mounting an in-memory MCP server.
|
|
10
|
+
*/
|
|
11
|
+
declare const InMemoryParamsSchema: z.ZodObject<{
|
|
12
|
+
type: z.ZodEnum<{
|
|
13
|
+
factory: "factory";
|
|
14
|
+
constructor: "constructor";
|
|
15
|
+
}>;
|
|
16
|
+
target: z.ZodString;
|
|
17
|
+
module: z.ZodString;
|
|
18
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
export type InMemoryParams = z.infer<typeof InMemoryParamsSchema>;
|
|
21
|
+
/**
|
|
22
|
+
* Mounts an MCP server in-memory for direct integration.
|
|
23
|
+
* Creates a linked transport pair for client-server communication without network overhead.
|
|
24
|
+
* @docs https://modelcontextprotocol.io/docs/concepts/transports#in-memory
|
|
25
|
+
*
|
|
26
|
+
* @param params - {@link InMemoryParams} Configuration for the server module
|
|
27
|
+
* @param extract - Optional function to extract the McpServer from the imported module.
|
|
28
|
+
* Use when the module's export structure doesn't match standard factory/constructor patterns.
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { mountMemServer } from "@artinet/sdk/mcp/mem";
|
|
32
|
+
* import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
33
|
+
*
|
|
34
|
+
* // Mount a server using a factory function with custom extraction
|
|
35
|
+
* const { server, clientTransport } = await mountMemServer(
|
|
36
|
+
* {
|
|
37
|
+
* type: "factory",
|
|
38
|
+
* target: "createServer",
|
|
39
|
+
* module: "@modelcontextprotocol/server-everything/dist/everything.js",
|
|
40
|
+
* },
|
|
41
|
+
* (module) => module.createServer().server
|
|
42
|
+
* );
|
|
43
|
+
*
|
|
44
|
+
* // Connect a client to the in-memory server
|
|
45
|
+
* const client = new Client({ name: "my-client", version: "1.0.0" });
|
|
46
|
+
* await client.connect(clientTransport);
|
|
47
|
+
*
|
|
48
|
+
* // Use the client
|
|
49
|
+
* const tools = await client.listTools();
|
|
50
|
+
* ```
|
|
51
|
+
* @returns Promise containing the {@link McpServer} instance and linked transport pair
|
|
52
|
+
*/
|
|
53
|
+
export declare function mountMemServer(params: InMemoryParams, extract?: (module: any) => McpServer): Promise<{
|
|
54
|
+
serverTransport: InMemoryTransport;
|
|
55
|
+
clientTransport: InMemoryTransport;
|
|
56
|
+
server: McpServer;
|
|
57
|
+
}>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
6
|
+
import { logger } from "../../../config/index.js";
|
|
7
|
+
import { z } from 'zod/v4';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for mounting an in-memory MCP server.
|
|
10
|
+
*/
|
|
11
|
+
const InMemoryParamsSchema = z.object({
|
|
12
|
+
/** Whether to invoke the target as a factory function or constructor */
|
|
13
|
+
type: z.enum(['factory', 'constructor']),
|
|
14
|
+
/** The name of the exported factory function or constructor class */
|
|
15
|
+
target: z.string(),
|
|
16
|
+
/** The module path to dynamically import (e.g., '@modelcontextprotocol/server-everything/dist/everything.js') */
|
|
17
|
+
module: z.string(),
|
|
18
|
+
/** Optional arguments to pass to the factory function or constructor */
|
|
19
|
+
args: z.record(z.string(), z.unknown()).optional(),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Mounts an MCP server in-memory for direct integration.
|
|
23
|
+
* Creates a linked transport pair for client-server communication without network overhead.
|
|
24
|
+
* @docs https://modelcontextprotocol.io/docs/concepts/transports#in-memory
|
|
25
|
+
*
|
|
26
|
+
* @param params - {@link InMemoryParams} Configuration for the server module
|
|
27
|
+
* @param extract - Optional function to extract the McpServer from the imported module.
|
|
28
|
+
* Use when the module's export structure doesn't match standard factory/constructor patterns.
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { mountMemServer } from "@artinet/sdk/mcp/mem";
|
|
32
|
+
* import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
33
|
+
*
|
|
34
|
+
* // Mount a server using a factory function with custom extraction
|
|
35
|
+
* const { server, clientTransport } = await mountMemServer(
|
|
36
|
+
* {
|
|
37
|
+
* type: "factory",
|
|
38
|
+
* target: "createServer",
|
|
39
|
+
* module: "@modelcontextprotocol/server-everything/dist/everything.js",
|
|
40
|
+
* },
|
|
41
|
+
* (module) => module.createServer().server
|
|
42
|
+
* );
|
|
43
|
+
*
|
|
44
|
+
* // Connect a client to the in-memory server
|
|
45
|
+
* const client = new Client({ name: "my-client", version: "1.0.0" });
|
|
46
|
+
* await client.connect(clientTransport);
|
|
47
|
+
*
|
|
48
|
+
* // Use the client
|
|
49
|
+
* const tools = await client.listTools();
|
|
50
|
+
* ```
|
|
51
|
+
* @returns Promise containing the {@link McpServer} instance and linked transport pair
|
|
52
|
+
*/
|
|
53
|
+
export async function mountMemServer(params, extract) {
|
|
54
|
+
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
|
|
55
|
+
//IFFE
|
|
56
|
+
const modules = (() => {
|
|
57
|
+
const modules = new Map();
|
|
58
|
+
return async (moduleName) => {
|
|
59
|
+
if (modules.has(moduleName)) {
|
|
60
|
+
return modules.get(moduleName);
|
|
61
|
+
}
|
|
62
|
+
const module = await import(moduleName).catch((error) => {
|
|
63
|
+
logger.error(`Failed to import module ${moduleName}`, error);
|
|
64
|
+
throw error;
|
|
65
|
+
});
|
|
66
|
+
if (module) {
|
|
67
|
+
modules.set(moduleName, module);
|
|
68
|
+
}
|
|
69
|
+
return module;
|
|
70
|
+
};
|
|
71
|
+
})();
|
|
72
|
+
const module = await modules(params.module).catch((error) => {
|
|
73
|
+
logger.error(`Failed to import module ${params.module}`, error);
|
|
74
|
+
throw error;
|
|
75
|
+
});
|
|
76
|
+
if (!module) {
|
|
77
|
+
logger.warn(`Failed to import module ${params.module}`);
|
|
78
|
+
throw new Error(`Failed to import module ${params.module}`);
|
|
79
|
+
}
|
|
80
|
+
let server;
|
|
81
|
+
if (extract) {
|
|
82
|
+
server = extract(module);
|
|
83
|
+
}
|
|
84
|
+
else if (params.type === 'factory') {
|
|
85
|
+
const factory = module[params.target];
|
|
86
|
+
if (!factory) {
|
|
87
|
+
const error = new Error(`Failed to find factory ${params.target} in module ${params.module}`);
|
|
88
|
+
logger.error(error.message, error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
server = factory(params.args);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const constructor = module[params.target];
|
|
95
|
+
if (!constructor) {
|
|
96
|
+
const error = new Error(`Failed to find constructor ${params.target} in module ${params.module}`);
|
|
97
|
+
logger.error(error.message, error);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
server = new constructor(params.args);
|
|
101
|
+
}
|
|
102
|
+
if (!server?.connect) {
|
|
103
|
+
const error = new Error(`Server ${params.target} does not have a connect method`);
|
|
104
|
+
logger.error(error.message, error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
await server.connect(serverTransport).catch((error) => {
|
|
108
|
+
logger.error(`Failed to connect to server ${params.target}`, error);
|
|
109
|
+
throw error;
|
|
110
|
+
});
|
|
111
|
+
return { serverTransport, clientTransport, server };
|
|
112
|
+
}
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -21,12 +21,32 @@ export declare function sleep(ms: number): Promise<void>;
|
|
|
21
21
|
/**
|
|
22
22
|
* Formats a JSON object into a string with indentation.
|
|
23
23
|
* @param json - The JSON object to format.
|
|
24
|
+
* @param replacer - A function that transforms the results.
|
|
25
|
+
* @param space - Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
|
|
24
26
|
* @returns A string representation of the JSON object.
|
|
25
27
|
*/
|
|
26
|
-
export declare function formatJson(json: object): string;
|
|
28
|
+
export declare function formatJson(json: object, replacer?: (number | string)[] | null, space?: string | number): string;
|
|
27
29
|
/**
|
|
28
30
|
* Formats an error into a standard error object for logging.
|
|
29
31
|
* @param error - The error to format.
|
|
30
32
|
* @returns A standard error object.
|
|
31
33
|
*/
|
|
32
34
|
export declare function formatError(error: unknown): Error;
|
|
35
|
+
/**
|
|
36
|
+
* Executes a function immediately.
|
|
37
|
+
* @param fn - The function to execute.
|
|
38
|
+
* @returns The result of the function.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const result = iife(() => {
|
|
43
|
+
* return 1 + 1;
|
|
44
|
+
* });
|
|
45
|
+
* console.log(result); // 2
|
|
46
|
+
* ```
|
|
47
|
+
* LangChain <3
|
|
48
|
+
* @see https://github.com/langchain-ai/langchainjs/blob/981cf9c480925187a524fd6ad1dbf0488d2758eb/libs/langchain-core/src/language_models/utils.ts#L5
|
|
49
|
+
*/
|
|
50
|
+
export declare const iife: <T>(fn: () => T) => T;
|
|
51
|
+
export declare function encodeBase64(data: string): string;
|
|
52
|
+
export declare function decodeBase64(data: string): string;
|
package/dist/utils/utils.js
CHANGED
|
@@ -25,10 +25,12 @@ export function sleep(ms) {
|
|
|
25
25
|
/**
|
|
26
26
|
* Formats a JSON object into a string with indentation.
|
|
27
27
|
* @param json - The JSON object to format.
|
|
28
|
+
* @param replacer - A function that transforms the results.
|
|
29
|
+
* @param space - Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
|
|
28
30
|
* @returns A string representation of the JSON object.
|
|
29
31
|
*/
|
|
30
|
-
export function formatJson(json) {
|
|
31
|
-
return JSON.stringify(json,
|
|
32
|
+
export function formatJson(json, replacer = null, space = 2) {
|
|
33
|
+
return JSON.stringify(json, replacer, space);
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Formats an error into a standard error object for logging.
|
|
@@ -41,3 +43,25 @@ export function formatError(error) {
|
|
|
41
43
|
}
|
|
42
44
|
return new Error(String(error));
|
|
43
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Executes a function immediately.
|
|
48
|
+
* @param fn - The function to execute.
|
|
49
|
+
* @returns The result of the function.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const result = iife(() => {
|
|
54
|
+
* return 1 + 1;
|
|
55
|
+
* });
|
|
56
|
+
* console.log(result); // 2
|
|
57
|
+
* ```
|
|
58
|
+
* LangChain <3
|
|
59
|
+
* @see https://github.com/langchain-ai/langchainjs/blob/981cf9c480925187a524fd6ad1dbf0488d2758eb/libs/langchain-core/src/language_models/utils.ts#L5
|
|
60
|
+
*/
|
|
61
|
+
export const iife = (fn) => fn();
|
|
62
|
+
export function encodeBase64(data) {
|
|
63
|
+
return Buffer.from(data).toString('base64');
|
|
64
|
+
}
|
|
65
|
+
export function decodeBase64(data) {
|
|
66
|
+
return Buffer.from(data, 'base64').toString();
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artinet/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"description": "A TypeScript SDK for building collaborative AI agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"import": "./dist/services/mcp/index.js",
|
|
23
23
|
"default": "./dist/services/mcp/index.js"
|
|
24
24
|
},
|
|
25
|
+
"./mcp/mem": {
|
|
26
|
+
"types": "./dist/services/mcp/modules/mem.d.ts",
|
|
27
|
+
"import": "./dist/services/mcp/modules/mem.js",
|
|
28
|
+
"default": "./dist/services/mcp/modules/mem.js"
|
|
29
|
+
},
|
|
25
30
|
"./serverless": {
|
|
26
31
|
"types": "./dist/server/express/serverless/index.d.ts",
|
|
27
32
|
"import": "./dist/server/express/serverless/index.js",
|
|
@@ -154,6 +159,7 @@
|
|
|
154
159
|
"@cfworker/json-schema": "^4.1.1",
|
|
155
160
|
"@eslint/js": "^9.25.1",
|
|
156
161
|
"@modelcontextprotocol/sdk": "^1.24.3",
|
|
162
|
+
"@modelcontextprotocol/server-everything": "^2026.1.14",
|
|
157
163
|
"@opentelemetry/api": "^1.9.0",
|
|
158
164
|
"@trpc/server": "^11.4.3",
|
|
159
165
|
"@types/cors": "^2.8.17",
|