@meshagent/meshagent 0.35.6 → 0.35.7

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 (47) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/browser/containers-client.d.ts +79 -2
  3. package/dist/browser/containers-client.js +341 -19
  4. package/dist/browser/database-client.d.ts +95 -24
  5. package/dist/browser/database-client.js +150 -49
  6. package/dist/browser/messaging-client.d.ts +33 -52
  7. package/dist/browser/messaging-client.js +180 -184
  8. package/dist/browser/participant.d.ts +5 -3
  9. package/dist/browser/participant.js +9 -1
  10. package/dist/browser/room-client.js +2 -0
  11. package/dist/browser/room-event.d.ts +6 -2
  12. package/dist/browser/room-event.js +4 -2
  13. package/dist/browser/secrets-client.d.ts +86 -16
  14. package/dist/browser/secrets-client.js +243 -44
  15. package/dist/browser/storage-client.d.ts +17 -4
  16. package/dist/browser/storage-client.js +104 -16
  17. package/dist/esm/containers-client.d.ts +79 -2
  18. package/dist/esm/containers-client.js +341 -19
  19. package/dist/esm/database-client.d.ts +95 -24
  20. package/dist/esm/database-client.js +150 -49
  21. package/dist/esm/messaging-client.d.ts +33 -52
  22. package/dist/esm/messaging-client.js +179 -180
  23. package/dist/esm/participant.d.ts +5 -3
  24. package/dist/esm/participant.js +9 -1
  25. package/dist/esm/room-client.js +2 -0
  26. package/dist/esm/room-event.d.ts +6 -2
  27. package/dist/esm/room-event.js +4 -2
  28. package/dist/esm/secrets-client.d.ts +86 -16
  29. package/dist/esm/secrets-client.js +243 -44
  30. package/dist/esm/storage-client.d.ts +17 -4
  31. package/dist/esm/storage-client.js +103 -16
  32. package/dist/node/containers-client.d.ts +79 -2
  33. package/dist/node/containers-client.js +341 -19
  34. package/dist/node/database-client.d.ts +95 -24
  35. package/dist/node/database-client.js +150 -49
  36. package/dist/node/messaging-client.d.ts +33 -52
  37. package/dist/node/messaging-client.js +180 -184
  38. package/dist/node/participant.d.ts +5 -3
  39. package/dist/node/participant.js +9 -1
  40. package/dist/node/room-client.js +2 -0
  41. package/dist/node/room-event.d.ts +6 -2
  42. package/dist/node/room-event.js +4 -2
  43. package/dist/node/secrets-client.d.ts +86 -16
  44. package/dist/node/secrets-client.js +243 -44
  45. package/dist/node/storage-client.d.ts +17 -4
  46. package/dist/node/storage-client.js +104 -16
  47. package/package.json +1 -1
@@ -1,11 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StorageClient = exports.FileHandle = void 0;
3
+ exports.StorageClient = exports.StorageEntry = exports.FileHandle = void 0;
4
4
  const room_event_1 = require("./room-event");
5
5
  const response_1 = require("./response");
6
6
  const utils_1 = require("./utils");
7
7
  const event_emitter_1 = require("./event-emitter");
8
8
  const room_server_client_1 = require("./room-server-client");
9
+ const _DEFAULT_UPLOAD_MIME_TYPE = "application/octet-stream";
10
+ const _UPLOAD_MIME_TYPES_BY_SUFFIX = new Map([
11
+ [".tar.gz", "application/x-tar"],
12
+ [".tgz", "application/x-tar"],
13
+ ]);
14
+ const _UPLOAD_MIME_TYPES_BY_EXTENSION = new Map([
15
+ [".bin", "application/octet-stream"],
16
+ [".css", "text/css"],
17
+ [".csv", "text/csv"],
18
+ [".gif", "image/gif"],
19
+ [".gz", "application/gzip"],
20
+ [".htm", "text/html"],
21
+ [".html", "text/html"],
22
+ [".jpeg", "image/jpeg"],
23
+ [".jpg", "image/jpeg"],
24
+ [".js", "text/javascript"],
25
+ [".json", "application/json"],
26
+ [".md", "text/markdown"],
27
+ [".mp3", "audio/mpeg"],
28
+ [".mp4", "video/mp4"],
29
+ [".pdf", "application/pdf"],
30
+ [".png", "image/png"],
31
+ [".svg", "image/svg+xml"],
32
+ [".tar", "application/x-tar"],
33
+ [".txt", "text/plain"],
34
+ [".ts", "text/typescript"],
35
+ [".tsx", "text/tsx"],
36
+ [".wasm", "application/wasm"],
37
+ [".webp", "image/webp"],
38
+ [".xml", "application/xml"],
39
+ [".yaml", "application/yaml"],
40
+ [".yml", "application/yaml"],
41
+ [".zip", "application/zip"],
42
+ ]);
43
+ function _unexpectedStorageResponseError(operation) {
44
+ return new room_server_client_1.RoomServerException(`unexpected return type from storage.${operation}`);
45
+ }
46
+ function _parseStorageTimestamp(value, operation) {
47
+ if (value == null) {
48
+ return null;
49
+ }
50
+ if (typeof value !== "string") {
51
+ throw _unexpectedStorageResponseError(operation);
52
+ }
53
+ const timestamp = new Date(value);
54
+ if (Number.isNaN(timestamp.getTime())) {
55
+ throw _unexpectedStorageResponseError(operation);
56
+ }
57
+ return timestamp;
58
+ }
9
59
  class FileHandle {
10
60
  constructor({ id }) {
11
61
  this.id = id;
@@ -13,10 +63,12 @@ class FileHandle {
13
63
  }
14
64
  exports.FileHandle = FileHandle;
15
65
  class StorageEntry {
16
- constructor({ name, isFolder, size = null }) {
66
+ constructor({ name, isFolder, size = null, createdAt = null, updatedAt = null }) {
17
67
  this.name = name;
18
68
  this.isFolder = isFolder;
19
69
  this.size = size;
70
+ this.createdAt = createdAt;
71
+ this.updatedAt = updatedAt;
20
72
  }
21
73
  nameWithoutExtension() {
22
74
  const segments = this.name
@@ -27,6 +79,7 @@ class StorageEntry {
27
79
  .replace(/\.[^/.]+$/, "");
28
80
  }
29
81
  }
82
+ exports.StorageEntry = StorageEntry;
30
83
  class StorageClient extends event_emitter_1.EventEmitter {
31
84
  constructor({ room }) {
32
85
  super();
@@ -36,18 +89,32 @@ class StorageClient extends event_emitter_1.EventEmitter {
36
89
  }
37
90
  async _handleFileUpdated(protocol, messageId, type, bytes) {
38
91
  const [data, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
39
- const event = new room_event_1.FileUpdatedEvent({ path: data["path"] });
92
+ const event = new room_event_1.FileUpdatedEvent({ path: data["path"], participantId: data["participant_id"] });
40
93
  this.client.emit(event);
41
94
  this.emit('file.updated', event);
42
95
  }
43
96
  async _handleFileDeleted(protocol, messageId, type, bytes) {
44
97
  const [data, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
45
- const event = new room_event_1.FileDeletedEvent({ path: data["path"] });
98
+ const event = new room_event_1.FileDeletedEvent({ path: data["path"], participantId: data["participant_id"] });
46
99
  this.client.emit(event);
47
100
  this.emit('file.deleted', event);
48
101
  }
49
102
  _unexpectedResponseError(operation) {
50
- return new room_server_client_1.RoomServerException(`unexpected return type from storage.${operation}`);
103
+ return _unexpectedStorageResponseError(operation);
104
+ }
105
+ _storageEntry(operation, value) {
106
+ if (typeof value["name"] !== "string" ||
107
+ typeof value["is_folder"] !== "boolean" ||
108
+ (value["size"] != null && typeof value["size"] !== "number")) {
109
+ throw this._unexpectedResponseError(operation);
110
+ }
111
+ return new StorageEntry({
112
+ name: value["name"],
113
+ isFolder: value["is_folder"],
114
+ size: typeof value["size"] === "number" ? value["size"] : null,
115
+ createdAt: _parseStorageTimestamp(value["created_at"], operation),
116
+ updatedAt: _parseStorageTimestamp(value["updated_at"], operation),
117
+ });
51
118
  }
52
119
  async _invoke(operation, input, callerContext) {
53
120
  return await this.client.invoke({
@@ -59,22 +126,26 @@ class StorageClient extends event_emitter_1.EventEmitter {
59
126
  }
60
127
  async list(path) {
61
128
  const response = await this._invoke("list", { path });
62
- if (!(response instanceof response_1.JsonContent)) {
129
+ if (!(response instanceof response_1.JsonContent) || !Array.isArray(response.json["files"])) {
63
130
  throw this._unexpectedResponseError("list");
64
131
  }
65
132
  const files = response.json["files"];
66
- const entries = files.map((f) => {
67
- return new StorageEntry({
68
- name: f["name"],
69
- isFolder: f["is_folder"],
70
- size: typeof f["size"] === "number" ? f["size"] : null,
71
- });
72
- });
133
+ const entries = files.map((f) => this._storageEntry("list", f));
73
134
  entries.sort((a, b) => a.name.localeCompare(b.name));
74
135
  return entries;
75
136
  }
76
- async delete(path) {
77
- await this._invoke("delete", { path, recursive: null });
137
+ async stat(path) {
138
+ const response = await this._invoke("stat", { path });
139
+ if (!(response instanceof response_1.JsonContent) || typeof response.json["exists"] !== "boolean") {
140
+ throw this._unexpectedResponseError("stat");
141
+ }
142
+ if (!response.json["exists"]) {
143
+ return null;
144
+ }
145
+ return this._storageEntry("stat", response.json);
146
+ }
147
+ async delete(path, { recursive = null, } = {}) {
148
+ await this._invoke("delete", { path, recursive });
78
149
  }
79
150
  async exists(path) {
80
151
  const result = await this._invoke("exists", { path });
@@ -91,6 +162,22 @@ class StorageClient extends event_emitter_1.EventEmitter {
91
162
  const lastSegment = segments.length > 0 ? segments[segments.length - 1] : undefined;
92
163
  return lastSegment ?? path;
93
164
  }
165
+ _defaultUploadMimeType(name, mimeType) {
166
+ if (typeof mimeType === "string" && mimeType.length > 0) {
167
+ return mimeType;
168
+ }
169
+ const lowerName = name.toLowerCase();
170
+ for (const [suffix, contentType] of _UPLOAD_MIME_TYPES_BY_SUFFIX.entries()) {
171
+ if (lowerName.endsWith(suffix)) {
172
+ return contentType;
173
+ }
174
+ }
175
+ const lastDot = lowerName.lastIndexOf(".");
176
+ if (lastDot >= 0) {
177
+ return _UPLOAD_MIME_TYPES_BY_EXTENSION.get(lowerName.slice(lastDot)) ?? _DEFAULT_UPLOAD_MIME_TYPE;
178
+ }
179
+ return _DEFAULT_UPLOAD_MIME_TYPE;
180
+ }
94
181
  async upload(path, bytes, { overwrite = false, name, mimeType = null, } = {}) {
95
182
  async function* singleChunk() {
96
183
  yield bytes;
@@ -104,6 +191,7 @@ class StorageClient extends event_emitter_1.EventEmitter {
104
191
  }
105
192
  async uploadStream(path, chunks, { overwrite = false, chunkSize = 64 * 1024, size = null, name, mimeType = null, } = {}) {
106
193
  const resolvedName = this._defaultUploadName(path, name);
194
+ const resolvedMimeType = this._defaultUploadMimeType(resolvedName, mimeType);
107
195
  const input = new _StorageUploadInputStream({
108
196
  path,
109
197
  overwrite,
@@ -111,7 +199,7 @@ class StorageClient extends event_emitter_1.EventEmitter {
111
199
  chunkSize,
112
200
  size,
113
201
  name: resolvedName,
114
- mimeType,
202
+ mimeType: resolvedMimeType,
115
203
  });
116
204
  const response = await this.client.invokeStream({
117
205
  toolkit: "storage",
@@ -4,14 +4,25 @@ import { RoomClient } from "./room-client";
4
4
  export interface DockerSecret {
5
5
  username: string;
6
6
  password: string;
7
- registry: string;
7
+ registry?: string | null;
8
8
  email?: string;
9
9
  }
10
10
  export interface ContainerImage {
11
11
  id: string;
12
12
  tags: string[];
13
13
  size?: number;
14
- labels: Record<string, unknown>;
14
+ labels: Record<string, string>;
15
+ }
16
+ export interface ImportedImage {
17
+ resolvedRef: string;
18
+ refs: string[];
19
+ }
20
+ export type BuildJobStatus = "queued" | "running" | "failed" | "cancelled" | "succeeded";
21
+ export interface BuildJob {
22
+ id: string;
23
+ tag: string;
24
+ status: BuildJobStatus;
25
+ exitCode?: number;
15
26
  }
16
27
  export interface ContainerParticipantInfo {
17
28
  id: string;
@@ -31,16 +42,24 @@ export interface ContainerLogsSession {
31
42
  result: Promise<void>;
32
43
  cancel(): Promise<void>;
33
44
  }
45
+ export interface BuildLogsSession {
46
+ stream: AsyncIterable<string>;
47
+ result: Promise<number | null>;
48
+ cancel(): Promise<void>;
49
+ }
34
50
  export declare class ExecSession {
35
51
  readonly command: string;
36
52
  readonly result: Promise<number>;
37
53
  readonly previousOutput: Uint8Array[];
54
+ readonly previousError: Uint8Array[];
38
55
  readonly output: AsyncIterable<Uint8Array>;
56
+ readonly stderr: AsyncIterable<Uint8Array>;
39
57
  private readonly requestId;
40
58
  private readonly containerId;
41
59
  private readonly tty?;
42
60
  private readonly resultCompleter;
43
61
  private readonly outputController;
62
+ private readonly errorController;
44
63
  private readonly queuedInput;
45
64
  private inputClosed;
46
65
  private closed;
@@ -64,6 +83,7 @@ export declare class ExecSession {
64
83
  close(status: number): void;
65
84
  closeError(error: unknown): void;
66
85
  addOutput(data: Uint8Array): void;
86
+ addError(data: Uint8Array): void;
67
87
  get isClosed(): boolean;
68
88
  private queueInput;
69
89
  private closeInputStream;
@@ -76,10 +96,32 @@ export declare class ContainersClient {
76
96
  private unexpectedResponseError;
77
97
  private invoke;
78
98
  listImages(): Promise<ContainerImage[]>;
99
+ deleteImage(params: {
100
+ image: string;
101
+ }): Promise<void>;
79
102
  pullImage(params: {
80
103
  tag: string;
81
104
  credentials?: DockerSecret[];
82
105
  }): Promise<void>;
106
+ pushImage(params: {
107
+ tag: string;
108
+ credentials?: DockerSecret[];
109
+ private?: boolean;
110
+ }): Promise<string>;
111
+ load(params: {
112
+ archivePath: string;
113
+ }): Promise<ImportedImage>;
114
+ loadImage(params: {
115
+ mounts: ContainerMountSpec[];
116
+ archivePath: string;
117
+ private?: boolean;
118
+ }): Promise<string>;
119
+ saveImage(params: {
120
+ tag: string;
121
+ mounts: ContainerMountSpec[];
122
+ archivePath: string;
123
+ private?: boolean;
124
+ }): Promise<string>;
83
125
  run(params: {
84
126
  image: string;
85
127
  command?: string;
@@ -96,6 +138,37 @@ export declare class ContainersClient {
96
138
  writableRootFs?: boolean;
97
139
  private?: boolean;
98
140
  }): Promise<string>;
141
+ startBuild(params: {
142
+ tag: string;
143
+ mounts: ContainerMountSpec[];
144
+ contextPath: string;
145
+ dockerfilePath?: string;
146
+ private?: boolean;
147
+ credentials?: DockerSecret[];
148
+ contextArchivePath?: string;
149
+ contextArchiveRef?: string;
150
+ contextArchiveMountPath?: string;
151
+ contextArchiveArch?: string;
152
+ }): Promise<string>;
153
+ build(params: {
154
+ tag: string;
155
+ mounts: ContainerMountSpec[];
156
+ contextPath: string;
157
+ dockerfilePath?: string;
158
+ private?: boolean;
159
+ credentials?: DockerSecret[];
160
+ contextArchivePath?: string;
161
+ contextArchiveRef?: string;
162
+ contextArchiveMountPath?: string;
163
+ contextArchiveArch?: string;
164
+ }): Promise<string>;
165
+ listBuilds(): Promise<BuildJob[]>;
166
+ cancelBuild(params: {
167
+ buildId: string;
168
+ }): Promise<void>;
169
+ deleteBuild(params: {
170
+ buildId: string;
171
+ }): Promise<void>;
99
172
  runService(params: {
100
173
  serviceId: string;
101
174
  env?: Record<string, string>;
@@ -119,6 +192,10 @@ export declare class ContainersClient {
119
192
  containerId: string;
120
193
  follow?: boolean;
121
194
  }): ContainerLogsSession;
195
+ getBuildLogs(params: {
196
+ buildId: string;
197
+ follow?: boolean;
198
+ }): BuildLogsSession;
122
199
  list(params?: {
123
200
  all?: boolean;
124
201
  }): Promise<RoomContainer[]>;