@meshagent/meshagent 0.31.1 → 0.31.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/browser/index.d.ts +2 -0
  3. package/dist/browser/index.js +2 -0
  4. package/dist/browser/memory-client.d.ts +23 -0
  5. package/dist/browser/memory-client.js +56 -0
  6. package/dist/browser/messaging-client.d.ts +5 -1
  7. package/dist/browser/messaging-client.js +49 -8
  8. package/dist/browser/participant-token.js +8 -2
  9. package/dist/browser/participant.d.ts +3 -1
  10. package/dist/browser/participant.js +5 -1
  11. package/dist/browser/room-client.d.ts +4 -0
  12. package/dist/browser/room-client.js +4 -0
  13. package/dist/browser/services-client.d.ts +28 -0
  14. package/dist/browser/services-client.js +93 -0
  15. package/dist/esm/index.d.ts +2 -0
  16. package/dist/esm/index.js +2 -0
  17. package/dist/esm/memory-client.d.ts +23 -0
  18. package/dist/esm/memory-client.js +52 -0
  19. package/dist/esm/messaging-client.d.ts +5 -1
  20. package/dist/esm/messaging-client.js +49 -8
  21. package/dist/esm/participant-token.js +8 -2
  22. package/dist/esm/participant.d.ts +3 -1
  23. package/dist/esm/participant.js +5 -1
  24. package/dist/esm/room-client.d.ts +4 -0
  25. package/dist/esm/room-client.js +4 -0
  26. package/dist/esm/services-client.d.ts +28 -0
  27. package/dist/esm/services-client.js +89 -0
  28. package/dist/node/index.d.ts +2 -0
  29. package/dist/node/index.js +2 -0
  30. package/dist/node/memory-client.d.ts +23 -0
  31. package/dist/node/memory-client.js +56 -0
  32. package/dist/node/messaging-client.d.ts +5 -1
  33. package/dist/node/messaging-client.js +49 -8
  34. package/dist/node/participant-token.js +8 -2
  35. package/dist/node/participant.d.ts +3 -1
  36. package/dist/node/participant.js +5 -1
  37. package/dist/node/room-client.d.ts +4 -0
  38. package/dist/node/room-client.js +4 -0
  39. package/dist/node/services-client.d.ts +28 -0
  40. package/dist/node/services-client.js +93 -0
  41. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.31.3]
2
+ - Stability
3
+
4
+ ## [0.31.2]
5
+ - Stability
6
+
1
7
  ## [0.31.1]
2
8
  - Stability
3
9
 
@@ -10,6 +10,7 @@ export * from './developer-client';
10
10
  export * from './document';
11
11
  export * from './meshagent-client';
12
12
  export * from './messaging-client';
13
+ export * from './memory-client';
13
14
  export * from './participant-token';
14
15
  export * from './participant';
15
16
  export * from './protocol';
@@ -22,6 +23,7 @@ export * from './room-server-client';
22
23
  export * from './runtime';
23
24
  export * from './schema';
24
25
  export * from './storage-client';
26
+ export * from './services-client';
25
27
  export * from './secrets-client';
26
28
  export * from './stream-controller';
27
29
  export * from './sync-client';
@@ -26,6 +26,7 @@ __exportStar(require("./developer-client"), exports);
26
26
  __exportStar(require("./document"), exports);
27
27
  __exportStar(require("./meshagent-client"), exports);
28
28
  __exportStar(require("./messaging-client"), exports);
29
+ __exportStar(require("./memory-client"), exports);
29
30
  __exportStar(require("./participant-token"), exports);
30
31
  __exportStar(require("./participant"), exports);
31
32
  __exportStar(require("./protocol"), exports);
@@ -38,6 +39,7 @@ __exportStar(require("./room-server-client"), exports);
38
39
  __exportStar(require("./runtime"), exports);
39
40
  __exportStar(require("./schema"), exports);
40
41
  __exportStar(require("./storage-client"), exports);
42
+ __exportStar(require("./services-client"), exports);
41
43
  __exportStar(require("./secrets-client"), exports);
42
44
  __exportStar(require("./stream-controller"), exports);
43
45
  __exportStar(require("./sync-client"), exports);
@@ -0,0 +1,23 @@
1
+ import { RoomClient } from "./room-client";
2
+ export declare class MemoryClient {
3
+ private readonly room;
4
+ constructor({ room }: {
5
+ room: RoomClient;
6
+ });
7
+ private unexpectedResponse;
8
+ private invoke;
9
+ list(params?: {
10
+ namespace?: string[] | null;
11
+ }): Promise<string[]>;
12
+ create(params: {
13
+ name: string;
14
+ namespace?: string[] | null;
15
+ overwrite?: boolean;
16
+ ignoreExists?: boolean;
17
+ }): Promise<void>;
18
+ drop(params: {
19
+ name: string;
20
+ namespace?: string[] | null;
21
+ ignoreMissing?: boolean;
22
+ }): Promise<void>;
23
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryClient = void 0;
4
+ const response_1 = require("./response");
5
+ const room_server_client_1 = require("./room-server-client");
6
+ class MemoryClient {
7
+ constructor({ room }) {
8
+ this.room = room;
9
+ }
10
+ unexpectedResponse(operation) {
11
+ return new room_server_client_1.RoomServerException(`unexpected return type from memory.${operation}`);
12
+ }
13
+ async invoke(operation, input) {
14
+ const response = await this.room.invoke({
15
+ toolkit: "memory",
16
+ tool: operation,
17
+ input,
18
+ });
19
+ if (response instanceof response_1.JsonContent) {
20
+ return response;
21
+ }
22
+ if (response instanceof response_1.EmptyContent) {
23
+ return null;
24
+ }
25
+ throw this.unexpectedResponse(operation);
26
+ }
27
+ async list(params) {
28
+ const response = await this.invoke("list", {
29
+ namespace: params?.namespace ?? null,
30
+ });
31
+ if (!(response instanceof response_1.JsonContent)) {
32
+ throw this.unexpectedResponse("list");
33
+ }
34
+ const memories = response.json["memories"];
35
+ if (!Array.isArray(memories)) {
36
+ return [];
37
+ }
38
+ return memories.filter((value) => typeof value === "string");
39
+ }
40
+ async create(params) {
41
+ await this.invoke("create", {
42
+ name: params.name,
43
+ namespace: params.namespace ?? null,
44
+ overwrite: params.overwrite ?? false,
45
+ ignore_exists: params.ignoreExists ?? false,
46
+ });
47
+ }
48
+ async drop(params) {
49
+ await this.invoke("drop", {
50
+ name: params.name,
51
+ namespace: params.namespace ?? null,
52
+ ignore_missing: params.ignoreMissing ?? false,
53
+ });
54
+ }
55
+ }
56
+ exports.MemoryClient = MemoryClient;
@@ -21,15 +21,19 @@ export declare class MessagingClient extends EventEmitter<RoomMessageEvent> {
21
21
  room: RoomClient;
22
22
  });
23
23
  private _messageInput;
24
+ private _removeParticipant;
25
+ private _resolveMessageRecipient;
26
+ private _participantNotFound;
24
27
  createStream({ to, header }: {
25
28
  to: Participant;
26
29
  header: Record<string, any>;
27
30
  }): Promise<MessageStreamWriter>;
28
- sendMessage({ to, type, message, attachment }: {
31
+ sendMessage({ to, type, message, attachment, ignoreOffline }: {
29
32
  to: Participant;
30
33
  type: string;
31
34
  message: Record<string, any>;
32
35
  attachment?: Uint8Array;
36
+ ignoreOffline?: boolean;
33
37
  }): Promise<void>;
34
38
  enable(onStreamAccept?: (reader: MessageStreamReader) => void): Promise<void>;
35
39
  disable(): Promise<void>;
@@ -5,6 +5,7 @@ const uuid_1 = require("uuid");
5
5
  const event_emitter_1 = require("./event-emitter");
6
6
  const participant_1 = require("./participant");
7
7
  const room_event_1 = require("./room-event");
8
+ const room_server_client_1 = require("./room-server-client");
8
9
  const utils_1 = require("./utils");
9
10
  const stream_controller_1 = require("./stream-controller");
10
11
  const completer_1 = require("./completer");
@@ -51,6 +52,37 @@ class MessagingClient extends event_emitter_1.EventEmitter {
51
52
  }
52
53
  return input;
53
54
  }
55
+ _removeParticipant(participantId) {
56
+ const participant = this._participants[participantId];
57
+ if (participant === undefined) {
58
+ return undefined;
59
+ }
60
+ participant._setOnline(false);
61
+ delete this._participants[participantId];
62
+ for (const [streamId, reader] of Object.entries(this._streamReaders)) {
63
+ if (reader._to.id !== participant.id) {
64
+ continue;
65
+ }
66
+ reader._controller.close();
67
+ delete this._streamReaders[streamId];
68
+ }
69
+ return participant;
70
+ }
71
+ _resolveMessageRecipient(to) {
72
+ if (!(to instanceof participant_1.RemoteParticipant)) {
73
+ return to;
74
+ }
75
+ if (to.online === false) {
76
+ return null;
77
+ }
78
+ return this._participants[to.id] ?? null;
79
+ }
80
+ _participantNotFound(ignoreOffline) {
81
+ if (ignoreOffline) {
82
+ return null;
83
+ }
84
+ throw new room_server_client_1.RoomServerException("the participant was not found");
85
+ }
54
86
  async createStream({ to, header }) {
55
87
  const streamId = (0, uuid_1.v4)();
56
88
  const completer = new completer_1.Completer();
@@ -62,12 +94,16 @@ class MessagingClient extends event_emitter_1.EventEmitter {
62
94
  });
63
95
  return completer.fut;
64
96
  }
65
- async sendMessage({ to, type, message, attachment }) {
97
+ async sendMessage({ to, type, message, attachment, ignoreOffline = false }) {
98
+ const resolvedTo = this._resolveMessageRecipient(to) ?? this._participantNotFound(ignoreOffline);
99
+ if (resolvedTo === null) {
100
+ return;
101
+ }
66
102
  await this.client.invoke({
67
103
  toolkit: "messaging",
68
104
  tool: "send",
69
105
  input: this._messageInput({
70
- toParticipantId: to.id,
106
+ toParticipantId: resolvedTo.id,
71
107
  type,
72
108
  message,
73
109
  attachment,
@@ -144,7 +180,7 @@ class MessagingClient extends event_emitter_1.EventEmitter {
144
180
  }
145
181
  _onParticipantEnabled(message) {
146
182
  const data = message.message;
147
- const p = new participant_1.RemoteParticipant(this.client, data["id"], data["role"]);
183
+ const p = new participant_1.RemoteParticipant(this.client, data["id"], data["role"], true);
148
184
  for (const [k, v] of Object.entries(data["attributes"] || {})) {
149
185
  p._attributes[k] = v;
150
186
  }
@@ -162,16 +198,15 @@ class MessagingClient extends event_emitter_1.EventEmitter {
162
198
  this.emit("participant_attributes_updated", { message });
163
199
  }
164
200
  _onParticipantDisabled(message) {
165
- const part = this._participants[message.message["id"]];
201
+ const part = this._removeParticipant(message.message["id"]);
166
202
  if (part) {
167
- delete this._participants[message.message["id"]];
168
203
  this.emit("participant_removed", { message });
169
204
  }
170
205
  }
171
206
  _onMessagingEnabled(message) {
172
207
  const participants = message.message["participants"];
173
208
  for (const data of participants) {
174
- const rp = new participant_1.RemoteParticipant(this.client, data["id"], data["role"]);
209
+ const rp = new participant_1.RemoteParticipant(this.client, data["id"], data["role"], true);
175
210
  for (const [k, v] of Object.entries(data["attributes"] || {})) {
176
211
  rp._attributes[k] = v;
177
212
  }
@@ -197,17 +232,23 @@ class MessagingClient extends event_emitter_1.EventEmitter {
197
232
  throw new Error("streams are not allowed by this client");
198
233
  }
199
234
  this._onStreamAcceptCallback(reader);
200
- this.sendMessage({
235
+ void this.sendMessage({
201
236
  to: from,
202
237
  type: "stream.accept",
203
238
  message: { stream_id: streamId },
239
+ ignoreOffline: true,
240
+ }).catch((error) => {
241
+ console.warn("unable to send stream response", error);
204
242
  });
205
243
  }
206
244
  catch (e) {
207
- this.sendMessage({
245
+ void this.sendMessage({
208
246
  to: from,
209
247
  type: "stream.reject",
210
248
  message: { stream_id: streamId, error: String(e) },
249
+ ignoreOffline: true,
250
+ }).catch((error) => {
251
+ console.warn("unable to send stream response", error);
211
252
  });
212
253
  }
213
254
  this._streamReaders[streamId] = reader;
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParticipantToken = exports.ParticipantGrant = exports.ApiScope = exports.SecretsGrant = exports.AdminGrant = exports.DeveloperGrant = exports.ContainersGrant = exports.StorageGrant = exports.StoragePathGrant = exports.SyncGrant = exports.SyncPathGrant = exports.DatabaseGrant = exports.TableGrant = exports.MessagingGrant = exports.QueuesGrant = exports.LivekitGrant = exports.AgentsGrant = void 0;
4
4
  const jose_1 = require("jose");
5
5
  const api_keys_1 = require("./api_keys");
6
+ function getEnvValue(name) {
7
+ if (typeof process === "undefined") {
8
+ return undefined;
9
+ }
10
+ return process.env?.[name];
11
+ }
6
12
  class AgentsGrant {
7
13
  constructor({ registerAgent, registerPublicToolkit, registerPrivateToolkit, call, useAgents, useTools, } = {}) {
8
14
  this.registerAgent = registerAgent ?? true;
@@ -371,7 +377,7 @@ class ParticipantToken {
371
377
  let resolvedSecret = token;
372
378
  let resolvedKid = this.apiKeyId;
373
379
  let resolvedSub = this.projectId;
374
- const apiKeyValue = apiKey ?? process.env.MESHAGENT_API_KEY;
380
+ const apiKeyValue = apiKey ?? getEnvValue("MESHAGENT_API_KEY");
375
381
  if (apiKeyValue) {
376
382
  const parsed = (0, api_keys_1.parseApiKey)(apiKeyValue);
377
383
  resolvedSecret ?? (resolvedSecret = parsed.secret);
@@ -380,7 +386,7 @@ class ParticipantToken {
380
386
  }
381
387
  let usingDefaultSecret = false;
382
388
  if (!resolvedSecret) {
383
- const envSecret = process.env.MESHAGENT_SECRET;
389
+ const envSecret = getEnvValue("MESHAGENT_SECRET");
384
390
  if (!envSecret) {
385
391
  throw new Error("ParticipantToken.toJwt: No secret provided. Pass `token`, `apiKey`, or set MESHAGENT_SECRET / MESHAGENT_API_KEY.");
386
392
  }
@@ -10,7 +10,9 @@ export declare abstract class Participant {
10
10
  }
11
11
  export declare class RemoteParticipant extends Participant {
12
12
  readonly role: string;
13
- constructor(client: RoomClient, id: string, role: string);
13
+ online?: boolean;
14
+ constructor(client: RoomClient, id: string, role: string, online?: boolean);
15
+ _setOnline(online: boolean): void;
14
16
  }
15
17
  export declare class LocalParticipant extends Participant {
16
18
  constructor(client: RoomClient, id: string);
@@ -18,9 +18,13 @@ class Participant {
18
18
  }
19
19
  exports.Participant = Participant;
20
20
  class RemoteParticipant extends Participant {
21
- constructor(client, id, role) {
21
+ constructor(client, id, role, online) {
22
22
  super(client, id);
23
23
  this.role = role;
24
+ this.online = online;
25
+ }
26
+ _setOnline(online) {
27
+ this.online = online;
24
28
  }
25
29
  }
26
30
  exports.RemoteParticipant = RemoteParticipant;
@@ -9,6 +9,8 @@ import { DatabaseClient } from "./database-client";
9
9
  import { AgentsClient, ToolkitDescription } from "./agent-client";
10
10
  import { SecretsClient } from "./secrets-client";
11
11
  import { ContainersClient } from "./containers-client";
12
+ import { MemoryClient } from "./memory-client";
13
+ import { ServicesClient } from "./services-client";
12
14
  import { RoomEvent } from "./room-event";
13
15
  import { Content } from "./response";
14
16
  interface RequestHeader {
@@ -25,6 +27,8 @@ export declare class RoomClient {
25
27
  readonly agents: AgentsClient;
26
28
  readonly secrets: SecretsClient;
27
29
  readonly containers: ContainersClient;
30
+ readonly memory: MemoryClient;
31
+ readonly services: ServicesClient;
28
32
  private _pendingRequests;
29
33
  private _ready;
30
34
  private _localParticipant;
@@ -14,6 +14,8 @@ const database_client_1 = require("./database-client");
14
14
  const agent_client_1 = require("./agent-client");
15
15
  const secrets_client_1 = require("./secrets-client");
16
16
  const containers_client_1 = require("./containers-client");
17
+ const memory_client_1 = require("./memory-client");
18
+ const services_client_1 = require("./services-client");
17
19
  const room_server_client_1 = require("./room-server-client");
18
20
  const response_1 = require("./response");
19
21
  class RoomClient {
@@ -37,6 +39,8 @@ class RoomClient {
37
39
  this.agents = new agent_client_1.AgentsClient({ room: this });
38
40
  this.secrets = new secrets_client_1.SecretsClient({ room: this });
39
41
  this.containers = new containers_client_1.ContainersClient({ room: this });
42
+ this.memory = new memory_client_1.MemoryClient({ room: this });
43
+ this.services = new services_client_1.ServicesClient({ room: this });
40
44
  }
41
45
  get localParticipant() {
42
46
  return this._localParticipant;
@@ -0,0 +1,28 @@
1
+ import { ServiceSpec } from "./meshagent-client";
2
+ import { RoomClient } from "./room-client";
3
+ export interface ServiceRuntimeState {
4
+ serviceId: string;
5
+ state: string;
6
+ containerId?: string;
7
+ restartScheduledAt?: number;
8
+ startedAt?: number;
9
+ restartCount: number;
10
+ lastExitCode?: number;
11
+ lastExitAt?: number;
12
+ }
13
+ export interface ListServicesResult {
14
+ services: ServiceSpec[];
15
+ serviceStates: Record<string, ServiceRuntimeState>;
16
+ }
17
+ export declare class ServicesClient {
18
+ private readonly room;
19
+ constructor({ room }: {
20
+ room: RoomClient;
21
+ });
22
+ private unexpectedResponse;
23
+ list(): Promise<ServiceSpec[]>;
24
+ listWithState(): Promise<ListServicesResult>;
25
+ restart(params: {
26
+ serviceId: string;
27
+ }): Promise<void>;
28
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServicesClient = void 0;
4
+ const response_1 = require("./response");
5
+ const room_server_client_1 = require("./room-server-client");
6
+ function isRecord(value) {
7
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
+ }
9
+ function toOptionalNumber(value) {
10
+ return typeof value === "number" ? value : undefined;
11
+ }
12
+ function toOptionalInteger(value) {
13
+ return typeof value === "number" && Number.isInteger(value) ? value : undefined;
14
+ }
15
+ function parseServiceRuntimeState(value) {
16
+ if (!isRecord(value) || typeof value["service_id"] !== "string") {
17
+ throw new room_server_client_1.RoomServerException("unexpected return type from services.list");
18
+ }
19
+ const state = value["state"];
20
+ const containerId = value["container_id"];
21
+ return {
22
+ serviceId: value["service_id"],
23
+ state: typeof state === "string" ? state : "unknown",
24
+ containerId: typeof containerId === "string" ? containerId : undefined,
25
+ restartScheduledAt: toOptionalNumber(value["restart_scheduled_at"]),
26
+ startedAt: toOptionalNumber(value["started_at"]),
27
+ restartCount: toOptionalInteger(value["restart_count"]) ?? 0,
28
+ lastExitCode: toOptionalInteger(value["last_exit_code"]),
29
+ lastExitAt: toOptionalNumber(value["last_exit_at"]),
30
+ };
31
+ }
32
+ function parseServiceSpecJson(value) {
33
+ if (typeof value === "string") {
34
+ const parsed = JSON.parse(value);
35
+ if (!isRecord(parsed)) {
36
+ throw new room_server_client_1.RoomServerException("unexpected return type from services.list");
37
+ }
38
+ return parsed;
39
+ }
40
+ if (!isRecord(value)) {
41
+ throw new room_server_client_1.RoomServerException("unexpected return type from services.list");
42
+ }
43
+ return value;
44
+ }
45
+ class ServicesClient {
46
+ constructor({ room }) {
47
+ this.room = room;
48
+ }
49
+ unexpectedResponse(operation) {
50
+ return new room_server_client_1.RoomServerException(`unexpected return type from services.${operation}`);
51
+ }
52
+ async list() {
53
+ return (await this.listWithState()).services;
54
+ }
55
+ async listWithState() {
56
+ const response = await this.room.invoke({
57
+ toolkit: "services",
58
+ tool: "list",
59
+ input: {},
60
+ });
61
+ if (!(response instanceof response_1.JsonContent)) {
62
+ throw this.unexpectedResponse("list");
63
+ }
64
+ const servicesRaw = response.json["services_json"];
65
+ const serviceStatesRaw = response.json["service_states"];
66
+ if (!Array.isArray(servicesRaw) || !Array.isArray(serviceStatesRaw)) {
67
+ throw this.unexpectedResponse("list");
68
+ }
69
+ const serviceStates = {};
70
+ for (const item of serviceStatesRaw) {
71
+ const state = parseServiceRuntimeState(item);
72
+ serviceStates[state.serviceId] = state;
73
+ }
74
+ return {
75
+ services: servicesRaw.map((item) => parseServiceSpecJson(item)),
76
+ serviceStates,
77
+ };
78
+ }
79
+ async restart(params) {
80
+ const response = await this.room.invoke({
81
+ toolkit: "services",
82
+ tool: "restart",
83
+ input: {
84
+ service_id: params.serviceId,
85
+ },
86
+ });
87
+ if (response instanceof response_1.EmptyContent || response instanceof response_1.JsonContent) {
88
+ return;
89
+ }
90
+ throw this.unexpectedResponse("restart");
91
+ }
92
+ }
93
+ exports.ServicesClient = ServicesClient;
@@ -10,6 +10,7 @@ export * from './developer-client';
10
10
  export * from './document';
11
11
  export * from './meshagent-client';
12
12
  export * from './messaging-client';
13
+ export * from './memory-client';
13
14
  export * from './participant-token';
14
15
  export * from './participant';
15
16
  export * from './protocol';
@@ -22,6 +23,7 @@ export * from './room-server-client';
22
23
  export * from './runtime';
23
24
  export * from './schema';
24
25
  export * from './storage-client';
26
+ export * from './services-client';
25
27
  export * from './secrets-client';
26
28
  export * from './stream-controller';
27
29
  export * from './sync-client';
package/dist/esm/index.js CHANGED
@@ -10,6 +10,7 @@ export * from './developer-client';
10
10
  export * from './document';
11
11
  export * from './meshagent-client';
12
12
  export * from './messaging-client';
13
+ export * from './memory-client';
13
14
  export * from './participant-token';
14
15
  export * from './participant';
15
16
  export * from './protocol';
@@ -22,6 +23,7 @@ export * from './room-server-client';
22
23
  export * from './runtime';
23
24
  export * from './schema';
24
25
  export * from './storage-client';
26
+ export * from './services-client';
25
27
  export * from './secrets-client';
26
28
  export * from './stream-controller';
27
29
  export * from './sync-client';
@@ -0,0 +1,23 @@
1
+ import { RoomClient } from "./room-client";
2
+ export declare class MemoryClient {
3
+ private readonly room;
4
+ constructor({ room }: {
5
+ room: RoomClient;
6
+ });
7
+ private unexpectedResponse;
8
+ private invoke;
9
+ list(params?: {
10
+ namespace?: string[] | null;
11
+ }): Promise<string[]>;
12
+ create(params: {
13
+ name: string;
14
+ namespace?: string[] | null;
15
+ overwrite?: boolean;
16
+ ignoreExists?: boolean;
17
+ }): Promise<void>;
18
+ drop(params: {
19
+ name: string;
20
+ namespace?: string[] | null;
21
+ ignoreMissing?: boolean;
22
+ }): Promise<void>;
23
+ }
@@ -0,0 +1,52 @@
1
+ import { EmptyContent, JsonContent } from "./response";
2
+ import { RoomServerException } from "./room-server-client";
3
+ export class MemoryClient {
4
+ constructor({ room }) {
5
+ this.room = room;
6
+ }
7
+ unexpectedResponse(operation) {
8
+ return new RoomServerException(`unexpected return type from memory.${operation}`);
9
+ }
10
+ async invoke(operation, input) {
11
+ const response = await this.room.invoke({
12
+ toolkit: "memory",
13
+ tool: operation,
14
+ input,
15
+ });
16
+ if (response instanceof JsonContent) {
17
+ return response;
18
+ }
19
+ if (response instanceof EmptyContent) {
20
+ return null;
21
+ }
22
+ throw this.unexpectedResponse(operation);
23
+ }
24
+ async list(params) {
25
+ const response = await this.invoke("list", {
26
+ namespace: params?.namespace ?? null,
27
+ });
28
+ if (!(response instanceof JsonContent)) {
29
+ throw this.unexpectedResponse("list");
30
+ }
31
+ const memories = response.json["memories"];
32
+ if (!Array.isArray(memories)) {
33
+ return [];
34
+ }
35
+ return memories.filter((value) => typeof value === "string");
36
+ }
37
+ async create(params) {
38
+ await this.invoke("create", {
39
+ name: params.name,
40
+ namespace: params.namespace ?? null,
41
+ overwrite: params.overwrite ?? false,
42
+ ignore_exists: params.ignoreExists ?? false,
43
+ });
44
+ }
45
+ async drop(params) {
46
+ await this.invoke("drop", {
47
+ name: params.name,
48
+ namespace: params.namespace ?? null,
49
+ ignore_missing: params.ignoreMissing ?? false,
50
+ });
51
+ }
52
+ }
@@ -21,15 +21,19 @@ export declare class MessagingClient extends EventEmitter<RoomMessageEvent> {
21
21
  room: RoomClient;
22
22
  });
23
23
  private _messageInput;
24
+ private _removeParticipant;
25
+ private _resolveMessageRecipient;
26
+ private _participantNotFound;
24
27
  createStream({ to, header }: {
25
28
  to: Participant;
26
29
  header: Record<string, any>;
27
30
  }): Promise<MessageStreamWriter>;
28
- sendMessage({ to, type, message, attachment }: {
31
+ sendMessage({ to, type, message, attachment, ignoreOffline }: {
29
32
  to: Participant;
30
33
  type: string;
31
34
  message: Record<string, any>;
32
35
  attachment?: Uint8Array;
36
+ ignoreOffline?: boolean;
33
37
  }): Promise<void>;
34
38
  enable(onStreamAccept?: (reader: MessageStreamReader) => void): Promise<void>;
35
39
  disable(): Promise<void>;