@meshagent/meshagent 0.44.13 → 0.45.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 (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/browser/index.d.ts +1 -1
  3. package/dist/browser/index.js +1 -1
  4. package/dist/browser/meshagent-client.d.ts +390 -372
  5. package/dist/browser/meshagent-client.js +841 -1040
  6. package/dist/browser/oauth-scopes.d.ts +1 -1
  7. package/dist/browser/oauth-scopes.js +64 -14
  8. package/dist/browser/participant-token.d.ts +68 -20
  9. package/dist/browser/participant-token.js +232 -61
  10. package/dist/browser/room-client.d.ts +4 -8
  11. package/dist/browser/room-client.js +4 -10
  12. package/dist/browser/services-client.d.ts +11 -0
  13. package/dist/browser/services-client.js +17 -0
  14. package/dist/browser/sqlite-client.d.ts +326 -0
  15. package/dist/browser/sqlite-client.js +630 -0
  16. package/dist/browser/toolkit-config.d.ts +7 -1
  17. package/dist/browser/toolkit-config.js +41 -22
  18. package/dist/esm/index.d.ts +1 -1
  19. package/dist/esm/index.js +1 -1
  20. package/dist/esm/meshagent-client.d.ts +390 -372
  21. package/dist/esm/meshagent-client.js +841 -1038
  22. package/dist/esm/oauth-scopes.d.ts +1 -1
  23. package/dist/esm/oauth-scopes.js +64 -14
  24. package/dist/esm/participant-token.d.ts +68 -20
  25. package/dist/esm/participant-token.js +228 -59
  26. package/dist/esm/room-client.d.ts +4 -8
  27. package/dist/esm/room-client.js +4 -10
  28. package/dist/esm/services-client.d.ts +11 -0
  29. package/dist/esm/services-client.js +17 -0
  30. package/dist/esm/sqlite-client.d.ts +326 -0
  31. package/dist/esm/sqlite-client.js +625 -0
  32. package/dist/esm/toolkit-config.d.ts +7 -1
  33. package/dist/esm/toolkit-config.js +41 -22
  34. package/dist/node/index.d.ts +1 -1
  35. package/dist/node/index.js +1 -1
  36. package/dist/node/meshagent-client.d.ts +390 -372
  37. package/dist/node/meshagent-client.js +841 -1040
  38. package/dist/node/oauth-scopes.d.ts +1 -1
  39. package/dist/node/oauth-scopes.js +64 -14
  40. package/dist/node/participant-token.d.ts +68 -20
  41. package/dist/node/participant-token.js +232 -61
  42. package/dist/node/room-client.d.ts +4 -8
  43. package/dist/node/room-client.js +4 -10
  44. package/dist/node/services-client.d.ts +11 -0
  45. package/dist/node/services-client.js +17 -0
  46. package/dist/node/sqlite-client.d.ts +326 -0
  47. package/dist/node/sqlite-client.js +630 -0
  48. package/dist/node/toolkit-config.d.ts +7 -1
  49. package/dist/node/toolkit-config.js +41 -22
  50. package/package.json +1 -1
  51. package/dist/browser/secrets-client.d.ts +0 -112
  52. package/dist/browser/secrets-client.js +0 -300
  53. package/dist/esm/secrets-client.d.ts +0 -112
  54. package/dist/esm/secrets-client.js +0 -296
  55. package/dist/node/secrets-client.d.ts +0 -112
  56. package/dist/node/secrets-client.js +0 -300
@@ -1,296 +0,0 @@
1
- import { BinaryContent, EmptyContent, FileContent, JsonContent } from "./response.js";
2
- import { RoomServerException } from "./room-server-client.js";
3
- import { unpackMessage } from "./utils.js";
4
- function isRecord(value) {
5
- return typeof value === "object" && value !== null && !Array.isArray(value);
6
- }
7
- export class SecretsClient {
8
- constructor({ room, oauthTokenRequestHandler, secretRequestHandler, }) {
9
- this._oauthRequestHandler = this._handleClientOAuthTokenRequest.bind(this);
10
- this._secretRequestHandler = this._handleClientSecretRequest.bind(this);
11
- this.client = room;
12
- this.oauthTokenRequestHandler = oauthTokenRequestHandler;
13
- this.secretRequestHandler = secretRequestHandler;
14
- this.client.protocol.addHandler("secrets.request_oauth_token", this._oauthRequestHandler);
15
- this.client.protocol.addHandler("secrets.request_secret", this._secretRequestHandler);
16
- }
17
- unexpectedResponse(operation) {
18
- return new RoomServerException(`unexpected return type from secrets.${operation}`);
19
- }
20
- async invoke(operation, input) {
21
- return await this.client.invokeContent({
22
- toolkit: "secrets",
23
- tool: operation,
24
- input,
25
- });
26
- }
27
- serializeConnectorRef(connector) {
28
- if (connector == null) {
29
- return null;
30
- }
31
- return {
32
- openai_connector_id: connector.openaiConnectorId ?? null,
33
- server_url: connector.serverUrl ?? null,
34
- client_secret_id: connector.clientSecretId ?? null,
35
- };
36
- }
37
- serializeOAuthConfig(oauth) {
38
- if (oauth == null) {
39
- return null;
40
- }
41
- return {
42
- client_id: oauth.client_id,
43
- client_secret: oauth.client_secret ?? null,
44
- authorization_endpoint: oauth.authorization_endpoint,
45
- token_endpoint: oauth.token_endpoint,
46
- no_pkce: oauth.no_pkce ?? null,
47
- scopes: oauth.scopes ?? null,
48
- };
49
- }
50
- parseAccessToken(operation, response) {
51
- if (!(response instanceof JsonContent)) {
52
- throw this.unexpectedResponse(operation);
53
- }
54
- const token = response.json["access_token"];
55
- if (typeof token !== "string" || token.length === 0) {
56
- return null;
57
- }
58
- return token;
59
- }
60
- parseSecretInfo(value) {
61
- if (!isRecord(value) || typeof value["id"] !== "string" || typeof value["name"] !== "string" || typeof value["type"] !== "string") {
62
- throw this.unexpectedResponse("list_secrets");
63
- }
64
- const delegatedTo = value["delegated_to"];
65
- if (delegatedTo !== undefined && delegatedTo !== null && typeof delegatedTo !== "string") {
66
- throw this.unexpectedResponse("list_secrets");
67
- }
68
- return {
69
- id: value["id"],
70
- name: value["name"],
71
- type: value["type"],
72
- delegatedTo: delegatedTo,
73
- };
74
- }
75
- async _handleClientOAuthTokenRequest(protocol, messageId, type, bytes) {
76
- if (!this.client.isActiveProtocol(protocol)) {
77
- return;
78
- }
79
- void messageId;
80
- void type;
81
- if (bytes == null) {
82
- throw new RoomServerException("invalid secrets.request_oauth_token payload");
83
- }
84
- if (this.oauthTokenRequestHandler == null) {
85
- throw new RoomServerException("No oauth token handler registered");
86
- }
87
- const [request] = unpackMessage(bytes);
88
- const requestId = request["request_id"];
89
- const challenge = request["challenge"];
90
- const requestPayload = request["request"];
91
- if (typeof requestId !== "string" || !isRecord(requestPayload)) {
92
- throw new RoomServerException("invalid secrets.request_oauth_token payload");
93
- }
94
- const oauth = requestPayload["oauth"];
95
- if (!isRecord(oauth) || typeof oauth["authorization_endpoint"] !== "string" || typeof oauth["token_endpoint"] !== "string") {
96
- throw new RoomServerException("invalid secrets.request_oauth_token payload");
97
- }
98
- const scopes = oauth["scopes"];
99
- if (scopes !== undefined && scopes !== null && (!Array.isArray(scopes) || scopes.some((scope) => typeof scope !== "string"))) {
100
- throw new RoomServerException("invalid secrets.request_oauth_token payload");
101
- }
102
- Promise.resolve(this.oauthTokenRequestHandler({
103
- requestId,
104
- authorizationEndpoint: oauth["authorization_endpoint"],
105
- tokenEndpoint: oauth["token_endpoint"],
106
- challenge: typeof challenge === "string" ? challenge : null,
107
- scopes: scopes ?? null,
108
- clientId: typeof oauth["client_id"] === "string" ? oauth["client_id"] : null,
109
- })).catch((error) => {
110
- console.warn("OAuth token request handler threw", error);
111
- });
112
- }
113
- async _handleClientSecretRequest(protocol, messageId, type, bytes) {
114
- if (!this.client.isActiveProtocol(protocol)) {
115
- return;
116
- }
117
- void messageId;
118
- void type;
119
- if (bytes == null) {
120
- throw new RoomServerException("invalid secrets.request_secret payload");
121
- }
122
- if (this.secretRequestHandler == null) {
123
- throw new RoomServerException("No secret handler registered");
124
- }
125
- const [request] = unpackMessage(bytes);
126
- const requestId = request["request_id"];
127
- const requestPayload = request["request"];
128
- if (typeof requestId !== "string" || !isRecord(requestPayload) || typeof requestPayload["url"] !== "string" || typeof requestPayload["type"] !== "string") {
129
- throw new RoomServerException("invalid secrets.request_secret payload");
130
- }
131
- Promise.resolve(this.secretRequestHandler({
132
- requestId,
133
- url: requestPayload["url"],
134
- type: requestPayload["type"],
135
- delegateTo: typeof requestPayload["delegate_to"] === "string" ? requestPayload["delegate_to"] : null,
136
- })).catch((error) => {
137
- console.warn("Secret request handler threw", error);
138
- });
139
- }
140
- async provideOAuthAuthorization({ requestId, code, }) {
141
- const response = await this.invoke("provide_oauth_authorization", {
142
- request_id: requestId,
143
- code,
144
- error: null,
145
- });
146
- if (response instanceof EmptyContent || response instanceof JsonContent) {
147
- return;
148
- }
149
- throw this.unexpectedResponse("provide_oauth_authorization");
150
- }
151
- async rejectOAuthAuthorization({ requestId, error, }) {
152
- const response = await this.invoke("provide_oauth_authorization", {
153
- request_id: requestId,
154
- code: null,
155
- error,
156
- });
157
- if (response instanceof EmptyContent || response instanceof JsonContent) {
158
- return;
159
- }
160
- throw this.unexpectedResponse("provide_oauth_authorization");
161
- }
162
- async provideSecret({ requestId, data, }) {
163
- const response = await this.invoke("provide_secret", new BinaryContent({
164
- data,
165
- headers: {
166
- request_id: requestId,
167
- error: null,
168
- },
169
- }));
170
- if (response instanceof EmptyContent || response instanceof JsonContent) {
171
- return;
172
- }
173
- throw this.unexpectedResponse("provide_secret");
174
- }
175
- async rejectSecret({ requestId, error, }) {
176
- const response = await this.invoke("provide_secret", new BinaryContent({
177
- data: new Uint8Array(0),
178
- headers: {
179
- request_id: requestId,
180
- error,
181
- },
182
- }));
183
- if (response instanceof EmptyContent || response instanceof JsonContent) {
184
- return;
185
- }
186
- throw this.unexpectedResponse("provide_secret");
187
- }
188
- async getOfflineOAuthToken({ connector, oauth, delegatedTo, delegatedBy, }) {
189
- const response = await this.invoke("get_offline_oauth_token", {
190
- connector: this.serializeConnectorRef(connector),
191
- oauth: this.serializeOAuthConfig(oauth),
192
- delegated_to: delegatedTo ?? null,
193
- delegated_by: delegatedBy ?? null,
194
- });
195
- return this.parseAccessToken("get_offline_oauth_token", response);
196
- }
197
- async requestOAuthToken({ connector, oauth, timeout = 60 * 5, fromParticipantId, redirectUri, delegateTo, }) {
198
- const response = await this.invoke("request_oauth_token", {
199
- connector: this.serializeConnectorRef(connector),
200
- oauth: this.serializeOAuthConfig(oauth),
201
- redirect_uri: typeof redirectUri === "string" ? redirectUri : redirectUri.toString(),
202
- timeout,
203
- participant_id: fromParticipantId,
204
- delegate_to: delegateTo ?? null,
205
- });
206
- return this.parseAccessToken("request_oauth_token", response);
207
- }
208
- async listSecrets() {
209
- const response = await this.invoke("list_secrets", {});
210
- if (!(response instanceof JsonContent)) {
211
- throw this.unexpectedResponse("list_secrets");
212
- }
213
- const secrets = response.json["secrets"];
214
- if (!Array.isArray(secrets)) {
215
- throw this.unexpectedResponse("list_secrets");
216
- }
217
- return secrets.map((item) => this.parseSecretInfo(item));
218
- }
219
- async exists({ secretId, delegatedTo, forIdentity, }) {
220
- const response = await this.invoke("exists", {
221
- secret_id: secretId,
222
- delegated_to: delegatedTo ?? null,
223
- for_identity: forIdentity ?? null,
224
- });
225
- if (!(response instanceof JsonContent) || typeof response.json["exists"] !== "boolean") {
226
- throw this.unexpectedResponse("exists");
227
- }
228
- return response.json["exists"];
229
- }
230
- async deleteSecret({ secretId, delegatedTo, }) {
231
- const response = await this.invoke("delete_secret", {
232
- id: secretId,
233
- delegated_to: delegatedTo ?? null,
234
- });
235
- if (response instanceof EmptyContent || response instanceof JsonContent) {
236
- return;
237
- }
238
- throw this.unexpectedResponse("delete_secret");
239
- }
240
- async deleteRequestedSecret({ url, type, delegatedTo, }) {
241
- const response = await this.invoke("delete_requested_secret", {
242
- url,
243
- type,
244
- delegated_to: delegatedTo ?? null,
245
- });
246
- if (response instanceof EmptyContent || response instanceof JsonContent) {
247
- return;
248
- }
249
- throw this.unexpectedResponse("delete_requested_secret");
250
- }
251
- async requestSecret({ fromParticipantId, url, type, timeout = 60 * 5, delegateTo, }) {
252
- const response = await this.invoke("request_secret", {
253
- url,
254
- type,
255
- participant_id: fromParticipantId,
256
- timeout,
257
- delegate_to: delegateTo ?? null,
258
- });
259
- if (response instanceof FileContent) {
260
- return response.data;
261
- }
262
- throw this.unexpectedResponse("request_secret");
263
- }
264
- async setSecret({ secretId, type, mimeType, name, delegatedTo, forIdentity, data, }) {
265
- const response = await this.invoke("set_secret", new BinaryContent({
266
- data,
267
- headers: {
268
- secret_id: secretId ?? null,
269
- type: type ?? mimeType ?? null,
270
- name: name ?? null,
271
- delegated_to: delegatedTo ?? null,
272
- for_identity: forIdentity ?? null,
273
- has_data: true,
274
- },
275
- }));
276
- if (response instanceof EmptyContent || response instanceof JsonContent) {
277
- return;
278
- }
279
- throw this.unexpectedResponse("set_secret");
280
- }
281
- async getSecret({ secretId, type, name, delegatedTo, }) {
282
- const response = await this.invoke("get_secret", {
283
- secret_id: secretId ?? null,
284
- type: type ?? null,
285
- name: name ?? null,
286
- delegated_to: delegatedTo ?? null,
287
- });
288
- if (response instanceof EmptyContent) {
289
- return null;
290
- }
291
- if (response instanceof FileContent) {
292
- return response;
293
- }
294
- throw this.unexpectedResponse("get_secret");
295
- }
296
- }
@@ -1,112 +0,0 @@
1
- import type { ConnectorRef, OAuthClientConfig } from "./meshagent-client.js";
2
- import { FileContent } from "./response.js";
3
- import { RoomClient } from "./room-client.js";
4
- export interface SecretInfo {
5
- id: string;
6
- name: string;
7
- type: string;
8
- delegatedTo?: string | null;
9
- }
10
- export interface OAuthTokenRequest {
11
- requestId: string;
12
- authorizationEndpoint: string;
13
- tokenEndpoint: string;
14
- challenge?: string | null;
15
- scopes?: string[] | null;
16
- clientId?: string | null;
17
- }
18
- export type OAuthTokenRequestHandler = (request: OAuthTokenRequest) => Promise<void> | void;
19
- export interface SecretRequest {
20
- requestId: string;
21
- url: string;
22
- type: string;
23
- delegateTo?: string | null;
24
- }
25
- export type SecretRequestHandler = (request: SecretRequest) => Promise<void> | void;
26
- export declare class SecretsClient {
27
- private readonly client;
28
- private readonly oauthTokenRequestHandler?;
29
- private readonly secretRequestHandler?;
30
- private readonly _oauthRequestHandler;
31
- private readonly _secretRequestHandler;
32
- constructor({ room, oauthTokenRequestHandler, secretRequestHandler, }: {
33
- room: RoomClient;
34
- oauthTokenRequestHandler?: OAuthTokenRequestHandler;
35
- secretRequestHandler?: SecretRequestHandler;
36
- });
37
- private unexpectedResponse;
38
- private invoke;
39
- private serializeConnectorRef;
40
- private serializeOAuthConfig;
41
- private parseAccessToken;
42
- private parseSecretInfo;
43
- private _handleClientOAuthTokenRequest;
44
- private _handleClientSecretRequest;
45
- provideOAuthAuthorization({ requestId, code, }: {
46
- requestId: string;
47
- code: string;
48
- }): Promise<void>;
49
- rejectOAuthAuthorization({ requestId, error, }: {
50
- requestId: string;
51
- error: string;
52
- }): Promise<void>;
53
- provideSecret({ requestId, data, }: {
54
- requestId: string;
55
- data: Uint8Array;
56
- }): Promise<void>;
57
- rejectSecret({ requestId, error, }: {
58
- requestId: string;
59
- error: string;
60
- }): Promise<void>;
61
- getOfflineOAuthToken({ connector, oauth, delegatedTo, delegatedBy, }: {
62
- connector?: ConnectorRef | null;
63
- oauth?: OAuthClientConfig | null;
64
- delegatedTo?: string | null;
65
- delegatedBy?: string | null;
66
- }): Promise<string | null>;
67
- requestOAuthToken({ connector, oauth, timeout, fromParticipantId, redirectUri, delegateTo, }: {
68
- connector?: ConnectorRef | null;
69
- oauth?: OAuthClientConfig | null;
70
- timeout?: number;
71
- fromParticipantId: string;
72
- redirectUri: string | URL;
73
- delegateTo?: string | null;
74
- }): Promise<string | null>;
75
- listSecrets(): Promise<SecretInfo[]>;
76
- exists({ secretId, delegatedTo, forIdentity, }: {
77
- secretId: string;
78
- delegatedTo?: string | null;
79
- forIdentity?: string | null;
80
- }): Promise<boolean>;
81
- deleteSecret({ secretId, delegatedTo, }: {
82
- secretId: string;
83
- delegatedTo?: string | null;
84
- }): Promise<void>;
85
- deleteRequestedSecret({ url, type, delegatedTo, }: {
86
- url: string;
87
- type: string;
88
- delegatedTo?: string | null;
89
- }): Promise<void>;
90
- requestSecret({ fromParticipantId, url, type, timeout, delegateTo, }: {
91
- fromParticipantId: string;
92
- url: string;
93
- type: string;
94
- timeout?: number;
95
- delegateTo?: string | null;
96
- }): Promise<Uint8Array>;
97
- setSecret({ secretId, type, mimeType, name, delegatedTo, forIdentity, data, }: {
98
- secretId?: string | null;
99
- type?: string | null;
100
- mimeType?: string | null;
101
- name?: string | null;
102
- delegatedTo?: string | null;
103
- forIdentity?: string | null;
104
- data: Uint8Array;
105
- }): Promise<void>;
106
- getSecret({ secretId, type, name, delegatedTo, }: {
107
- secretId?: string | null;
108
- type?: string | null;
109
- name?: string | null;
110
- delegatedTo?: string | null;
111
- }): Promise<FileContent | null>;
112
- }