@meshagent/meshagent 0.37.2 → 0.38.1

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 (77) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/browser/agent.js +74 -10
  3. package/dist/browser/developer-client.js +3 -0
  4. package/dist/browser/helpers.d.ts +2 -2
  5. package/dist/browser/helpers.js +1 -1
  6. package/dist/browser/meshagent-client.d.ts +25 -0
  7. package/dist/browser/meshagent-client.js +65 -0
  8. package/dist/browser/messaging-client.d.ts +29 -16
  9. package/dist/browser/messaging-client.js +256 -154
  10. package/dist/browser/participant.d.ts +7 -2
  11. package/dist/browser/participant.js +9 -9
  12. package/dist/browser/protocol.d.ts +85 -28
  13. package/dist/browser/protocol.js +356 -119
  14. package/dist/browser/room-client.d.ts +165 -29
  15. package/dist/browser/room-client.js +1114 -74
  16. package/dist/browser/room-event.d.ts +11 -0
  17. package/dist/browser/room-event.js +21 -1
  18. package/dist/browser/room-server-client.d.ts +2 -0
  19. package/dist/browser/room-server-client.js +6 -0
  20. package/dist/browser/runtime.d.ts +1 -1
  21. package/dist/browser/runtime.js +3 -1
  22. package/dist/browser/secrets-client.js +6 -2
  23. package/dist/browser/storage-client.d.ts +1 -0
  24. package/dist/browser/storage-client.js +9 -0
  25. package/dist/browser/sync-client.d.ts +16 -14
  26. package/dist/browser/sync-client.js +195 -116
  27. package/dist/esm/agent.js +74 -10
  28. package/dist/esm/developer-client.js +3 -0
  29. package/dist/esm/helpers.d.ts +2 -2
  30. package/dist/esm/helpers.js +1 -1
  31. package/dist/esm/meshagent-client.d.ts +25 -0
  32. package/dist/esm/meshagent-client.js +65 -0
  33. package/dist/esm/messaging-client.d.ts +29 -16
  34. package/dist/esm/messaging-client.js +256 -154
  35. package/dist/esm/participant.d.ts +7 -2
  36. package/dist/esm/participant.js +9 -9
  37. package/dist/esm/protocol.d.ts +85 -28
  38. package/dist/esm/protocol.js +352 -118
  39. package/dist/esm/room-client.d.ts +165 -29
  40. package/dist/esm/room-client.js +1112 -73
  41. package/dist/esm/room-event.d.ts +11 -0
  42. package/dist/esm/room-event.js +19 -0
  43. package/dist/esm/room-server-client.d.ts +2 -0
  44. package/dist/esm/room-server-client.js +7 -1
  45. package/dist/esm/runtime.d.ts +1 -1
  46. package/dist/esm/runtime.js +1 -1
  47. package/dist/esm/secrets-client.js +6 -2
  48. package/dist/esm/storage-client.d.ts +1 -0
  49. package/dist/esm/storage-client.js +9 -0
  50. package/dist/esm/sync-client.d.ts +16 -14
  51. package/dist/esm/sync-client.js +196 -117
  52. package/dist/node/agent.js +74 -10
  53. package/dist/node/developer-client.js +3 -0
  54. package/dist/node/helpers.d.ts +2 -2
  55. package/dist/node/helpers.js +1 -1
  56. package/dist/node/meshagent-client.d.ts +25 -0
  57. package/dist/node/meshagent-client.js +65 -0
  58. package/dist/node/messaging-client.d.ts +29 -16
  59. package/dist/node/messaging-client.js +256 -154
  60. package/dist/node/participant.d.ts +7 -2
  61. package/dist/node/participant.js +9 -9
  62. package/dist/node/protocol.d.ts +85 -28
  63. package/dist/node/protocol.js +356 -119
  64. package/dist/node/room-client.d.ts +165 -29
  65. package/dist/node/room-client.js +1114 -74
  66. package/dist/node/room-event.d.ts +11 -0
  67. package/dist/node/room-event.js +21 -1
  68. package/dist/node/room-server-client.d.ts +2 -0
  69. package/dist/node/room-server-client.js +6 -0
  70. package/dist/node/runtime.d.ts +1 -1
  71. package/dist/node/runtime.js +3 -1
  72. package/dist/node/secrets-client.js +6 -2
  73. package/dist/node/storage-client.d.ts +1 -0
  74. package/dist/node/storage-client.js +9 -0
  75. package/dist/node/sync-client.d.ts +16 -14
  76. package/dist/node/sync-client.js +195 -116
  77. package/package.json +6 -3
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.38.1]
2
+ - Updated the TypeScript HTML schema example to use `SimpleValue.string` for value properties.
3
+ - Removed the JavaScript and TypeScript schema registry example scripts as part of the example refresh.
4
+
5
+ ## [0.38.0]
6
+ - Stability
7
+
1
8
  ## [0.37.2]
2
9
  - Stability
3
10
 
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RemoteTaskRunner = exports.HostedToolkit = exports.Toolkit = exports.Tool = void 0;
4
4
  exports.startHostedToolkit = startHostedToolkit;
5
5
  const response_1 = require("./response");
6
+ const room_server_client_1 = require("./room-server-client");
6
7
  const tool_content_type_1 = require("./tool-content-type");
7
8
  const utils_1 = require("./utils");
9
+ const room_event_1 = require("./room-event");
8
10
  class Tool {
9
11
  constructor({ name, description, title, inputSchema, inputSpec, outputSpec, outputSchema, thumbnailUrl }) {
10
12
  this.name = name;
@@ -100,17 +102,46 @@ class HostedToolkit {
100
102
  exports.HostedToolkit = HostedToolkit;
101
103
  class _RemoteToolkitWrapper {
102
104
  constructor({ toolkit, room }) {
105
+ this._toolCallHandler = this._toolCall.bind(this);
106
+ this._roomEventHandler = this._onRoomEvent.bind(this);
107
+ this._started = false;
108
+ this._public = false;
109
+ this._registerTask = null;
103
110
  this.toolkit = toolkit;
104
111
  this.client = room;
105
112
  }
106
113
  async start({ public_: isPublic = false } = {}) {
107
- const handler = this._toolCall.bind(this);
108
- this.client.protocol.addHandler(`room.tool_call.${this.toolkit.name}`, handler);
109
- await this._register(isPublic);
114
+ if (this._started) {
115
+ throw new room_server_client_1.RoomServerException(`toolkit '${this.toolkit.name}' is already started`);
116
+ }
117
+ this._public = isPublic;
118
+ this.client.protocol.addHandler(`room.tool_call.${this.toolkit.name}`, this._toolCallHandler);
119
+ this.client.on("disconnected", this._roomEventHandler);
120
+ this.client.on("reconnected", this._roomEventHandler);
121
+ try {
122
+ await this._register(isPublic);
123
+ this._started = true;
124
+ }
125
+ catch (error) {
126
+ this.client.off("disconnected", this._roomEventHandler);
127
+ this.client.off("reconnected", this._roomEventHandler);
128
+ this.client.protocol.removeHandler(`room.tool_call.${this.toolkit.name}`, this._toolCallHandler);
129
+ throw error;
130
+ }
110
131
  }
111
132
  async stop() {
112
- await this._unregister();
113
- this.client.protocol.removeHandler(`room.tool_call.${this.toolkit.name}`);
133
+ if (!this._started) {
134
+ return;
135
+ }
136
+ this._started = false;
137
+ this.client.off("disconnected", this._roomEventHandler);
138
+ this.client.off("reconnected", this._roomEventHandler);
139
+ try {
140
+ await this._unregister();
141
+ }
142
+ finally {
143
+ this.client.protocol.removeHandler(`room.tool_call.${this.toolkit.name}`, this._toolCallHandler);
144
+ }
114
145
  }
115
146
  async _register(public_) {
116
147
  const response = await this.client.sendRequest("room.register_toolkit", {
@@ -125,13 +156,43 @@ class _RemoteToolkitWrapper {
125
156
  this._registrationId = json["id"];
126
157
  }
127
158
  async _unregister() {
128
- if (!this._registrationId)
159
+ const registrationId = this._registrationId;
160
+ this._registrationId = undefined;
161
+ if (registrationId == null || this.client.isClosed) {
129
162
  return;
163
+ }
130
164
  await this.client.sendRequest("room.unregister_toolkit", {
131
- id: this._registrationId,
165
+ id: registrationId,
132
166
  });
133
167
  }
168
+ _scheduleRegisterIfNeeded() {
169
+ if (!this._started || this._registrationId != null || this._registerTask != null || this.client.isClosed) {
170
+ return;
171
+ }
172
+ this._registerTask = this._register(this._public)
173
+ .catch((error) => {
174
+ console.warn(`unable to reregister hosted toolkit ${this.toolkit.name}`, error);
175
+ })
176
+ .finally(() => {
177
+ this._registerTask = null;
178
+ });
179
+ }
180
+ _onRoomEvent(event) {
181
+ if (!this._started || !(event instanceof room_event_1.RoomStatusEvent)) {
182
+ return;
183
+ }
184
+ if (event.status === "disconnected") {
185
+ this._registrationId = undefined;
186
+ return;
187
+ }
188
+ if (event.status === "reconnected") {
189
+ this._scheduleRegisterIfNeeded();
190
+ }
191
+ }
134
192
  async _toolCall(protocol, messageId, type, data) {
193
+ if (!this.client.isActiveProtocol(protocol)) {
194
+ return;
195
+ }
135
196
  try {
136
197
  const [message, _] = (0, utils_1.unpackMessage)(data);
137
198
  const toolName = message["name"];
@@ -157,11 +218,11 @@ class _RemoteToolkitWrapper {
157
218
  args = rawArguments ?? {};
158
219
  }
159
220
  const response = await this.toolkit.execute(toolName, args);
160
- await this.client.protocol.send("room.tool_call_response", response.pack(), messageId);
221
+ await this.client.protocol.send("room.tool_call_response", response.pack(), { id: messageId });
161
222
  }
162
223
  catch (e) {
163
224
  const err = new response_1.ErrorContent({ text: String(e) });
164
- await this.client.protocol.send("room.tool_call_response", err.pack(), messageId);
225
+ await this.client.protocol.send("room.tool_call_response", err.pack(), { id: messageId });
165
226
  }
166
227
  }
167
228
  }
@@ -186,7 +247,10 @@ class RemoteTaskRunner {
186
247
  async start() {
187
248
  }
188
249
  async stop() {
189
- this.client.protocol.removeHandler("agent.ask");
250
+ const handler = this.client.protocol.getHandler("agent.ask");
251
+ if (handler != null) {
252
+ this.client.protocol.removeHandler("agent.ask", handler);
253
+ }
190
254
  }
191
255
  }
192
256
  exports.RemoteTaskRunner = RemoteTaskRunner;
@@ -17,6 +17,9 @@ class DeveloperClient extends event_emitter_1.EventEmitter {
17
17
  this.emit("log", event);
18
18
  }
19
19
  async _handleDeveloperLog(protocol, messageId, type, bytes) {
20
+ if (!this.client.isActiveProtocol(protocol)) {
21
+ return;
22
+ }
20
23
  const [rawJson, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
21
24
  this._emitDeveloperLog(rawJson["type"], rawJson["data"]);
22
25
  }
@@ -1,7 +1,7 @@
1
1
  import { MeshSchema } from './schema';
2
2
  import { RoomClient } from './room-client';
3
3
  import { ParticipantToken } from './participant-token';
4
- import { WebSocketClientProtocol } from './protocol';
4
+ import { ProtocolFactory } from './protocol';
5
5
  export declare function validateSchemaName(name: string): void;
6
6
  export declare function deploySchema({ room, schema, name, overwrite }: {
7
7
  room: RoomClient;
@@ -31,4 +31,4 @@ export declare function websocketProtocol({ participantName, roomName, role, pro
31
31
  secret?: string;
32
32
  apiUrl?: string;
33
33
  apiKey?: string;
34
- }): Promise<WebSocketClientProtocol>;
34
+ }): Promise<ProtocolFactory>;
@@ -64,5 +64,5 @@ async function websocketProtocol({ participantName, roomName, role, projectId, a
64
64
  const url = websocketRoomUrl({ roomName, apiUrl });
65
65
  const token = participantToken({ participantName, roomName, role, projectId, apiKeyId, apiKey });
66
66
  const jwt = await token.toJwt({ token: secret, apiKey });
67
- return new protocol_1.WebSocketClientProtocol({ url, token: jwt });
67
+ return protocol_1.WebSocketClientProtocol.createFactory({ url, token: jwt });
68
68
  }
@@ -202,6 +202,14 @@ export interface Mailbox {
202
202
  roomId?: string;
203
203
  queue: string;
204
204
  }
205
+ export interface ProjectRepository {
206
+ id: string;
207
+ projectId: string;
208
+ name: string;
209
+ description: string;
210
+ annotations: Record<string, string>;
211
+ createdAt: Date;
212
+ }
205
213
  export interface Balance {
206
214
  balance: number;
207
215
  autoRechargeThreshold?: number | null;
@@ -278,6 +286,7 @@ export declare class Meshagent {
278
286
  private parseRoomShare;
279
287
  private parseRoomSession;
280
288
  private parseRoom;
289
+ private parseProjectRepository;
281
290
  private parseProjectRoomGrant;
282
291
  private parseProjectRoomGrantCount;
283
292
  private parseProjectUserGrantCount;
@@ -393,6 +402,22 @@ export declare class Meshagent {
393
402
  }): Promise<void>;
394
403
  listMailboxes(projectId: string): Promise<Mailbox[]>;
395
404
  deleteMailbox(projectId: string, address: string): Promise<void>;
405
+ createRepository(params: {
406
+ projectId: string;
407
+ name: string;
408
+ description?: string;
409
+ annotations?: Record<string, string>;
410
+ }): Promise<ProjectRepository>;
411
+ updateRepository(params: {
412
+ projectId: string;
413
+ repositoryId: string;
414
+ name: string;
415
+ description?: string;
416
+ annotations?: Record<string, string>;
417
+ }): Promise<ProjectRepository>;
418
+ getRepository(projectId: string, repositoryId: string): Promise<ProjectRepository>;
419
+ listRepositories(projectId: string): Promise<ProjectRepository[]>;
420
+ deleteRepository(projectId: string, repositoryId: string): Promise<void>;
396
421
  createService(projectId: string, service: ServiceSpec): Promise<string>;
397
422
  createRoomService(projectId: string, roomName: string, service: ServiceSpec): Promise<string>;
398
423
  updateRoomService(projectId: string, roomName: string, serviceId: string, service: ServiceSpec): Promise<void>;
@@ -226,6 +226,33 @@ class Meshagent {
226
226
  annotations: annotations && typeof annotations === "object" ? annotations : {},
227
227
  };
228
228
  }
229
+ parseProjectRepository(data) {
230
+ if (!data || typeof data !== "object") {
231
+ throw new requirement_1.RoomException("Invalid repository payload");
232
+ }
233
+ const { id, project_id: projectIdRaw, projectId, name, description, annotations, created_at: createdAtRaw, createdAt, } = data;
234
+ const projectIdValue = typeof projectId === "string"
235
+ ? projectId
236
+ : typeof projectIdRaw === "string"
237
+ ? projectIdRaw
238
+ : undefined;
239
+ const createdAtValue = typeof createdAt === "string"
240
+ ? createdAt
241
+ : typeof createdAtRaw === "string"
242
+ ? createdAtRaw
243
+ : undefined;
244
+ if (typeof id !== "string" || typeof projectIdValue !== "string" || typeof name !== "string" || typeof createdAtValue !== "string") {
245
+ throw new requirement_1.RoomException("Invalid repository payload: missing required fields");
246
+ }
247
+ return {
248
+ id,
249
+ projectId: projectIdValue,
250
+ name,
251
+ description: typeof description === "string" ? description : "",
252
+ annotations: annotations && typeof annotations === "object" ? annotations : {},
253
+ createdAt: new Date(createdAtValue),
254
+ };
255
+ }
229
256
  parseProjectRoomGrant(data) {
230
257
  if (!data || typeof data !== "object") {
231
258
  throw new requirement_1.RoomException("Invalid room grant payload");
@@ -892,6 +919,44 @@ class Meshagent {
892
919
  responseType: "void",
893
920
  });
894
921
  }
922
+ async createRepository(params) {
923
+ const { projectId, name, description = "", annotations = {} } = params;
924
+ const data = await this.request(`/accounts/projects/${projectId}/repositories`, {
925
+ method: "POST",
926
+ json: { name, description, annotations },
927
+ action: "create repository",
928
+ });
929
+ return this.parseProjectRepository(data);
930
+ }
931
+ async updateRepository(params) {
932
+ const { projectId, repositoryId, name, description = "", annotations = {} } = params;
933
+ const data = await this.request(`/accounts/projects/${projectId}/repositories/${repositoryId}`, {
934
+ method: "PUT",
935
+ json: { name, description, annotations },
936
+ action: "update repository",
937
+ });
938
+ return this.parseProjectRepository(data);
939
+ }
940
+ async getRepository(projectId, repositoryId) {
941
+ const data = await this.request(`/accounts/projects/${projectId}/repositories/${repositoryId}`, {
942
+ action: "fetch repository",
943
+ });
944
+ return this.parseProjectRepository(data);
945
+ }
946
+ async listRepositories(projectId) {
947
+ const data = await this.request(`/accounts/projects/${projectId}/repositories`, {
948
+ action: "list repositories",
949
+ });
950
+ const repositories = Array.isArray(data?.repositories) ? data.repositories : [];
951
+ return repositories.map((item) => this.parseProjectRepository(item));
952
+ }
953
+ async deleteRepository(projectId, repositoryId) {
954
+ await this.request(`/accounts/projects/${projectId}/repositories/${repositoryId}`, {
955
+ method: "DELETE",
956
+ action: "delete repository",
957
+ responseType: "void",
958
+ });
959
+ }
895
960
  async createService(projectId, service) {
896
961
  const data = await this.request(`/accounts/projects/${projectId}/services`, {
897
962
  method: "POST",
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from "./event-emitter";
2
- import { RoomClient } from "./room-client";
3
2
  import { Participant, RemoteParticipant } from "./participant";
3
+ import { RoomClient } from "./room-client";
4
4
  import { RoomMessageEvent } from "./room-event";
5
5
  type MessagePayload = Record<string, unknown>;
6
6
  export declare class MessagingClient extends EventEmitter<RoomMessageEvent> {
@@ -11,44 +11,57 @@ export declare class MessagingClient extends EventEmitter<RoomMessageEvent> {
11
11
  private _messageQueued;
12
12
  private _sendTask;
13
13
  private _messageQueueClosed;
14
- private _enabled;
14
+ private _desiredEnabled;
15
+ private _online;
16
+ private _enableInFlight;
15
17
  constructor({ room }: {
16
18
  room: RoomClient;
17
19
  });
20
+ get isEnabled(): boolean;
21
+ get online(): boolean;
22
+ get remoteParticipants(): RemoteParticipant[];
18
23
  private _messageInput;
19
- private _syntheticMessageEvent;
24
+ private _invoke;
25
+ private _invokeNowait;
26
+ start(): void;
27
+ stop(): Promise<void>;
28
+ private _nextQueuedMessage;
29
+ private _wakeMessageQueue;
30
+ private _queueMessage;
31
+ private _setOnline;
32
+ private _waitUntilOnline;
33
+ private _enableCurrentConnectionNowait;
34
+ private _clearCurrentConnectionState;
35
+ _onRoomDisconnect({ reason: _reason }: {
36
+ reason: string | null;
37
+ }): void;
38
+ _onRoomReconnect(): void;
20
39
  private _removeParticipant;
21
40
  private _markParticipantOffline;
22
41
  private _resolveMessageRecipient;
23
- private _queueMessage;
24
- private _rejectQueuedMessages;
25
- private _isParticipantNotFound;
26
- private _nextQueuedMessage;
42
+ private _dropQueuedMessage;
43
+ private _drainQueuedMessages;
27
44
  private _sendMessages;
28
- start(): Promise<void>;
29
- stop(): Promise<void>;
30
- sendMessage({ to, type, message, attachment, ignoreOffline }: {
45
+ sendMessage({ to, type, message, attachment, ignoreOffline, }: {
31
46
  to: Participant;
32
47
  type: string;
33
48
  message: MessagePayload;
34
49
  attachment?: Uint8Array;
35
50
  ignoreOffline?: boolean;
36
51
  }): Promise<void>;
37
- sendMessageNowait({ to, type, message, attachment }: {
52
+ sendMessageNowait({ to, type, message, attachment, }: {
38
53
  to: Participant;
39
54
  type: string;
40
55
  message: MessagePayload;
41
56
  attachment?: Uint8Array;
42
57
  }): void;
43
- enable(): Promise<void>;
44
- disable(): Promise<void>;
45
- broadcastMessage({ type, message, attachment }: {
58
+ enable(): void;
59
+ disable(): void;
60
+ broadcastMessage({ type, message, attachment, }: {
46
61
  type: string;
47
62
  message: MessagePayload;
48
63
  attachment?: Uint8Array;
49
64
  }): Promise<void>;
50
- get remoteParticipants(): RemoteParticipant[];
51
- get isEnabled(): boolean;
52
65
  getParticipants(): RemoteParticipant[];
53
66
  getParticipant(id: string): RemoteParticipant | null;
54
67
  getParticipantByName(name: string): RemoteParticipant | null;