@verentis/sdk 1.0.0 → 1.0.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.
- package/README.md +31 -0
- package/dist/index.cjs +275 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +413 -4
- package/dist/index.d.ts +413 -4
- package/dist/index.js +275 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -290,7 +290,8 @@ var ExecutionsModule = class {
|
|
|
290
290
|
tool: options?.tool,
|
|
291
291
|
mode: options?.mode,
|
|
292
292
|
arguments: options?.arguments ?? [],
|
|
293
|
-
parameters: serializeParameters(options?.parameters)
|
|
293
|
+
parameters: serializeParameters(options?.parameters),
|
|
294
|
+
...options?.invocationKey ? { invocationKey: options.invocationKey } : {}
|
|
294
295
|
}),
|
|
295
296
|
headers: { "Content-Type": "application/json" }
|
|
296
297
|
});
|
|
@@ -336,9 +337,9 @@ var ExecutionsModule = class {
|
|
|
336
337
|
return descriptor;
|
|
337
338
|
}
|
|
338
339
|
/** Get an execution by id. */
|
|
339
|
-
async get(
|
|
340
|
+
async get(id2, options) {
|
|
340
341
|
const workspaceId = this.requireWorkspaceId(options?.workspaceId);
|
|
341
|
-
return this.http.request("GET", `/executions/${encodeURIComponent(
|
|
342
|
+
return this.http.request("GET", `/executions/${encodeURIComponent(id2)}`, {
|
|
342
343
|
params: { workspaceId }
|
|
343
344
|
});
|
|
344
345
|
}
|
|
@@ -363,17 +364,17 @@ var ExecutionsModule = class {
|
|
|
363
364
|
});
|
|
364
365
|
}
|
|
365
366
|
/** Get the captured stdout/stderr of an execution. */
|
|
366
|
-
async logs(
|
|
367
|
+
async logs(id2, options) {
|
|
367
368
|
const workspaceId = this.requireWorkspaceId(options?.workspaceId);
|
|
368
|
-
return this.http.request("GET", `/executions/${encodeURIComponent(
|
|
369
|
+
return this.http.request("GET", `/executions/${encodeURIComponent(id2)}/logs`, {
|
|
369
370
|
params: { workspaceId }
|
|
370
371
|
});
|
|
371
372
|
}
|
|
372
373
|
/** Cancel a pending or running execution. */
|
|
373
|
-
async cancel(
|
|
374
|
+
async cancel(id2, options) {
|
|
374
375
|
const workspaceId = this.requireWorkspaceId(options?.workspaceId);
|
|
375
|
-
return this.http.request("POST", `/executions/${encodeURIComponent(
|
|
376
|
-
body: JSON.stringify({ id, workspaceId }),
|
|
376
|
+
return this.http.request("POST", `/executions/${encodeURIComponent(id2)}/cancel`, {
|
|
377
|
+
body: JSON.stringify({ id: id2, workspaceId }),
|
|
377
378
|
headers: { "Content-Type": "application/json" }
|
|
378
379
|
});
|
|
379
380
|
}
|
|
@@ -381,16 +382,16 @@ var ExecutionsModule = class {
|
|
|
381
382
|
* Poll an execution until it reaches a terminal status. Returns immediately if it is already
|
|
382
383
|
* terminal. Throws if `timeoutMs` elapses or the supplied signal aborts.
|
|
383
384
|
*/
|
|
384
|
-
async wait(
|
|
385
|
+
async wait(id2, options) {
|
|
385
386
|
const interval = options?.intervalMs ?? 1e3;
|
|
386
387
|
const deadline = options?.timeoutMs ? Date.now() + options.timeoutMs : void 0;
|
|
387
388
|
for (; ; ) {
|
|
388
|
-
const execution = await this.get(
|
|
389
|
+
const execution = await this.get(id2, { workspaceId: options?.workspaceId });
|
|
389
390
|
if (isTerminalStatus(execution.status)) {
|
|
390
391
|
return execution;
|
|
391
392
|
}
|
|
392
393
|
if (deadline !== void 0 && Date.now() >= deadline) {
|
|
393
|
-
throw new Error(`Timed out waiting for execution '${
|
|
394
|
+
throw new Error(`Timed out waiting for execution '${id2}' to complete`);
|
|
394
395
|
}
|
|
395
396
|
await delay(interval, options?.signal);
|
|
396
397
|
}
|
|
@@ -407,11 +408,11 @@ var ExecutionsModule = class {
|
|
|
407
408
|
return this.wait(execution.id, options);
|
|
408
409
|
}
|
|
409
410
|
requireWorkspaceId(override) {
|
|
410
|
-
const
|
|
411
|
-
if (!
|
|
411
|
+
const id2 = override ?? this.workspaceId;
|
|
412
|
+
if (!id2) {
|
|
412
413
|
throw new Error("workspaceId is required: provide it in options or when creating the client");
|
|
413
414
|
}
|
|
414
|
-
return
|
|
415
|
+
return id2;
|
|
415
416
|
}
|
|
416
417
|
};
|
|
417
418
|
function serializeParameters(parameters) {
|
|
@@ -452,8 +453,8 @@ var EnginesModule = class {
|
|
|
452
453
|
}
|
|
453
454
|
});
|
|
454
455
|
}
|
|
455
|
-
async get(
|
|
456
|
-
return this.http.request("GET", `/engines/${encodeURIComponent(
|
|
456
|
+
async get(id2, options) {
|
|
457
|
+
return this.http.request("GET", `/engines/${encodeURIComponent(id2)}`, {
|
|
457
458
|
params: { workspaceId: this.requireWorkspaceId(options?.workspaceId) }
|
|
458
459
|
});
|
|
459
460
|
}
|
|
@@ -674,11 +675,11 @@ var FilesModule = class {
|
|
|
674
675
|
});
|
|
675
676
|
}
|
|
676
677
|
workspaceHeaders() {
|
|
677
|
-
const
|
|
678
|
+
const headers2 = {};
|
|
678
679
|
if (this.workspaceId) {
|
|
679
|
-
|
|
680
|
+
headers2["X-Workspace-Id"] = this.workspaceId;
|
|
680
681
|
}
|
|
681
|
-
return
|
|
682
|
+
return headers2;
|
|
682
683
|
}
|
|
683
684
|
};
|
|
684
685
|
function requireNonBlank(value, name) {
|
|
@@ -770,14 +771,14 @@ var InstallationsModule = class {
|
|
|
770
771
|
}
|
|
771
772
|
});
|
|
772
773
|
}
|
|
773
|
-
async update(
|
|
774
|
+
async update(id2, options) {
|
|
774
775
|
const workspaceId = this.requireWorkspaceId(options?.workspaceId);
|
|
775
776
|
return this.http.request(
|
|
776
777
|
"PUT",
|
|
777
|
-
`/installations/${encodeURIComponent(
|
|
778
|
+
`/installations/${encodeURIComponent(id2)}`,
|
|
778
779
|
{
|
|
779
780
|
body: JSON.stringify({
|
|
780
|
-
id,
|
|
781
|
+
id: id2,
|
|
781
782
|
workspaceId,
|
|
782
783
|
packageVersion: options?.packageVersion,
|
|
783
784
|
installMode: options?.installMode
|
|
@@ -786,8 +787,8 @@ var InstallationsModule = class {
|
|
|
786
787
|
}
|
|
787
788
|
);
|
|
788
789
|
}
|
|
789
|
-
async uninstall(
|
|
790
|
-
await this.http.request("DELETE", `/installations/${encodeURIComponent(
|
|
790
|
+
async uninstall(id2, options) {
|
|
791
|
+
await this.http.request("DELETE", `/installations/${encodeURIComponent(id2)}`, {
|
|
791
792
|
params: { workspaceId: this.requireWorkspaceId(options?.workspaceId) }
|
|
792
793
|
});
|
|
793
794
|
}
|
|
@@ -813,10 +814,10 @@ var ResourcesModule = class {
|
|
|
813
814
|
params: { workspaceId: this.requireWorkspaceId(options?.workspaceId) }
|
|
814
815
|
});
|
|
815
816
|
}
|
|
816
|
-
async get(
|
|
817
|
+
async get(id2, options) {
|
|
817
818
|
return this.http.request(
|
|
818
819
|
"GET",
|
|
819
|
-
`/resources/${encodeURIComponent(
|
|
820
|
+
`/resources/${encodeURIComponent(id2)}`,
|
|
820
821
|
{ params: { workspaceId: this.requireWorkspaceId(options?.workspaceId) } }
|
|
821
822
|
);
|
|
822
823
|
}
|
|
@@ -980,10 +981,10 @@ var NotificationsModule = class {
|
|
|
980
981
|
}
|
|
981
982
|
}
|
|
982
983
|
}
|
|
983
|
-
async request(
|
|
984
|
+
async request(id2, options) {
|
|
984
985
|
return this.http.request(
|
|
985
986
|
"GET",
|
|
986
|
-
`/notifications/requests/${encodeURIComponent(
|
|
987
|
+
`/notifications/requests/${encodeURIComponent(id2)}`,
|
|
987
988
|
{
|
|
988
989
|
params: {
|
|
989
990
|
workspaceId: this.requireWorkspaceId(options?.workspaceId),
|
|
@@ -1027,8 +1028,8 @@ var BusinessModule = class _BusinessModule {
|
|
|
1027
1028
|
body: JSON.stringify(command)
|
|
1028
1029
|
});
|
|
1029
1030
|
}
|
|
1030
|
-
async read(
|
|
1031
|
-
return this.http.request("GET", `/business/records/${encodeURIComponent(
|
|
1031
|
+
async read(id2) {
|
|
1032
|
+
return this.http.request("GET", `/business/records/${encodeURIComponent(id2)}`, { headers: this.headers() });
|
|
1032
1033
|
}
|
|
1033
1034
|
async list(kind) {
|
|
1034
1035
|
return this.http.request("GET", "/business/records", {
|
|
@@ -1070,6 +1071,190 @@ var BusinessModule = class _BusinessModule {
|
|
|
1070
1071
|
}
|
|
1071
1072
|
};
|
|
1072
1073
|
|
|
1074
|
+
// src/modules/chat.ts
|
|
1075
|
+
var JSON_HEADERS = { "Content-Type": "application/json" };
|
|
1076
|
+
var ChatModule = class {
|
|
1077
|
+
constructor(http, bridge = null, executions) {
|
|
1078
|
+
this.http = http;
|
|
1079
|
+
this.bridge = bridge;
|
|
1080
|
+
this.executions = executions;
|
|
1081
|
+
}
|
|
1082
|
+
http;
|
|
1083
|
+
bridge;
|
|
1084
|
+
executions;
|
|
1085
|
+
// ── Conversations ─────────────────────────────────────────────────
|
|
1086
|
+
listConversations(options) {
|
|
1087
|
+
return this.http.request("GET", "/chat/conversations", { params: page(options) });
|
|
1088
|
+
}
|
|
1089
|
+
createConversation(options) {
|
|
1090
|
+
const { idempotencyKey, ...body } = options;
|
|
1091
|
+
return this.http.request("POST", "/chat/conversations", { body: JSON.stringify(body), headers: headers(idempotencyKey) });
|
|
1092
|
+
}
|
|
1093
|
+
/** Opens (or returns the existing) direct conversation with one participant. */
|
|
1094
|
+
openDirect(participant) {
|
|
1095
|
+
return this.createConversation({ kind: "direct", participants: [participant] });
|
|
1096
|
+
}
|
|
1097
|
+
getConversation(conversationId) {
|
|
1098
|
+
return this.http.request("GET", `/chat/conversations/${id(conversationId)}`);
|
|
1099
|
+
}
|
|
1100
|
+
updateConversation(conversationId, changes) {
|
|
1101
|
+
return this.http.request("PATCH", `/chat/conversations/${id(conversationId)}`, { body: JSON.stringify(changes), headers: JSON_HEADERS });
|
|
1102
|
+
}
|
|
1103
|
+
join(conversationId) {
|
|
1104
|
+
return this.http.request("POST", `/chat/conversations/${id(conversationId)}/join`, { body: "{}", headers: JSON_HEADERS });
|
|
1105
|
+
}
|
|
1106
|
+
listPublicChannels(options) {
|
|
1107
|
+
return this.http.request("GET", "/chat/channels", { params: { ...page(options), query: options?.query } });
|
|
1108
|
+
}
|
|
1109
|
+
// ── Members ───────────────────────────────────────────────────────
|
|
1110
|
+
listMembers(conversationId) {
|
|
1111
|
+
return this.http.request("GET", `/chat/conversations/${id(conversationId)}/members`);
|
|
1112
|
+
}
|
|
1113
|
+
addMembers(conversationId, participants, role) {
|
|
1114
|
+
return this.http.request("POST", `/chat/conversations/${id(conversationId)}/members`, {
|
|
1115
|
+
body: JSON.stringify({ participants, role }),
|
|
1116
|
+
headers: JSON_HEADERS
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
/** Removes a member; pass yourself to leave. */
|
|
1120
|
+
async removeMember(conversationId, participant) {
|
|
1121
|
+
await this.http.request("DELETE", `/chat/conversations/${id(conversationId)}/members/${participant.kind}/${id(participant.id)}`);
|
|
1122
|
+
}
|
|
1123
|
+
changeRole(conversationId, participant, role) {
|
|
1124
|
+
return this.http.request("PUT", `/chat/conversations/${id(conversationId)}/members/${participant.kind}/${id(participant.id)}/role`, {
|
|
1125
|
+
body: JSON.stringify({ role }),
|
|
1126
|
+
headers: JSON_HEADERS
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
// ── Messages ──────────────────────────────────────────────────────
|
|
1130
|
+
listMessages(conversationId, options) {
|
|
1131
|
+
return this.http.request("GET", `/chat/conversations/${id(conversationId)}/messages`, {
|
|
1132
|
+
params: { before: options?.before, limit: options?.limit }
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
getMessage(conversationId, messageId) {
|
|
1136
|
+
return this.http.request("GET", `/chat/conversations/${id(conversationId)}/messages/${id(messageId)}`);
|
|
1137
|
+
}
|
|
1138
|
+
send(conversationId, parts, options) {
|
|
1139
|
+
return this.http.request("POST", `/chat/conversations/${id(conversationId)}/messages`, {
|
|
1140
|
+
body: JSON.stringify({ parts, replyTo: options?.replyTo }),
|
|
1141
|
+
headers: headers(options?.idempotencyKey)
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
/** Sends Markdown text (rendered without raw HTML by every reader). */
|
|
1145
|
+
sendText(conversationId, markdown, options) {
|
|
1146
|
+
return this.send(conversationId, [{ type: "text", data: { markdown } }], options);
|
|
1147
|
+
}
|
|
1148
|
+
/** Edits your own message; pass the revision you saw to reject a concurrent edit. */
|
|
1149
|
+
edit(conversationId, messageId, parts, options) {
|
|
1150
|
+
return this.http.request("PATCH", `/chat/conversations/${id(conversationId)}/messages/${id(messageId)}`, {
|
|
1151
|
+
body: JSON.stringify({ parts }),
|
|
1152
|
+
headers: { ...JSON_HEADERS, ...options?.revision ? { "If-Match": `"${options.revision}"` } : {} }
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
delete(conversationId, messageId) {
|
|
1156
|
+
return this.http.request("DELETE", `/chat/conversations/${id(conversationId)}/messages/${id(messageId)}`);
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Durable changes after a position: `afterSeq` is a snapshot's `highWatermark` (or the last sequence you applied);
|
|
1160
|
+
* `after` is the `next` cursor of a previous page.
|
|
1161
|
+
*/
|
|
1162
|
+
events(conversationId, options) {
|
|
1163
|
+
return this.http.request("GET", `/chat/conversations/${id(conversationId)}/events`, {
|
|
1164
|
+
params: { after: options?.after, afterSeq: options?.afterSeq, limit: options?.limit }
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
// ── Read state and preferences ────────────────────────────────────
|
|
1168
|
+
/** Marks messages read through a sequence; never moves back and never past what the server has. */
|
|
1169
|
+
markRead(conversationId, readThroughSeq) {
|
|
1170
|
+
return this.http.request("PUT", `/chat/conversations/${id(conversationId)}/read-state`, {
|
|
1171
|
+
body: JSON.stringify({ readThroughSeq }),
|
|
1172
|
+
headers: JSON_HEADERS
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
setPreferences(conversationId, preferences) {
|
|
1176
|
+
return this.http.request("PUT", `/chat/conversations/${id(conversationId)}/preferences`, {
|
|
1177
|
+
body: JSON.stringify(preferences),
|
|
1178
|
+
headers: JSON_HEADERS
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
// ── People, bots and commands ─────────────────────────────────────
|
|
1182
|
+
/** People in your workspace (name and avatar only). */
|
|
1183
|
+
searchPeople(options) {
|
|
1184
|
+
return this.http.request("GET", "/chat/people", { params: { ...page(options), query: options?.query } });
|
|
1185
|
+
}
|
|
1186
|
+
listBots() {
|
|
1187
|
+
return this.http.request("GET", "/chat/bots");
|
|
1188
|
+
}
|
|
1189
|
+
/** Workspace managers (`chat.manage`) decide whether a bot may message people directly. */
|
|
1190
|
+
updateBotSettings(botId, settings) {
|
|
1191
|
+
return this.http.request("PUT", `/chat/bots/${id(botId)}/settings`, { body: JSON.stringify(settings), headers: JSON_HEADERS });
|
|
1192
|
+
}
|
|
1193
|
+
listCommands() {
|
|
1194
|
+
return this.http.request("GET", "/chat/commands");
|
|
1195
|
+
}
|
|
1196
|
+
/** Validates and records a command invocation, returning the Execution request to run as you. */
|
|
1197
|
+
invokeCommand(conversationId, command, args, options) {
|
|
1198
|
+
return this.http.request("POST", `/chat/conversations/${id(conversationId)}/commands`, {
|
|
1199
|
+
body: JSON.stringify({ command, arguments: args ?? {} }),
|
|
1200
|
+
headers: headers(options?.idempotencyKey)
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Invokes an installed app's command and runs its script with your own authorisation. Retrying with the same
|
|
1205
|
+
* idempotency key reuses the invocation key, so Execution never runs it twice.
|
|
1206
|
+
*/
|
|
1207
|
+
async runCommand(conversationId, command, args, options) {
|
|
1208
|
+
if (!this.executions) throw new Error("Running commands needs the executions module.");
|
|
1209
|
+
const invocation = await this.invokeCommand(conversationId, command, args, options);
|
|
1210
|
+
const execution = await this.executions.run(invocation.filePath, {
|
|
1211
|
+
workspaceId: invocation.workspaceId,
|
|
1212
|
+
branch: invocation.branch,
|
|
1213
|
+
parameters: JSON.parse(invocation.parameters),
|
|
1214
|
+
invocationKey: invocation.invocationKey
|
|
1215
|
+
});
|
|
1216
|
+
return { invocation, execution };
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Posts as the installed app's bot from a running script. The bot is derived from the script's execution; the
|
|
1220
|
+
* conversation must have added the bot (or, for `userId`, the workspace must allow it to message people).
|
|
1221
|
+
* Retries briefly while Execution's start event is still on its way.
|
|
1222
|
+
*/
|
|
1223
|
+
async postAsBot(options) {
|
|
1224
|
+
const { idempotencyKey, ...body } = options;
|
|
1225
|
+
const request = { body: JSON.stringify(body), headers: headers(idempotencyKey ?? globalThis.crypto?.randomUUID?.()) };
|
|
1226
|
+
const deadline = Date.now() + 1e4;
|
|
1227
|
+
for (; ; ) {
|
|
1228
|
+
try {
|
|
1229
|
+
return await this.http.request("POST", "/chat/bot-messages", request);
|
|
1230
|
+
} catch (error) {
|
|
1231
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "execution_not_ready") throw error;
|
|
1232
|
+
const delay2 = Math.max(250, error.retryAfterMs ?? 1e3);
|
|
1233
|
+
if (Date.now() + delay2 > deadline) throw error;
|
|
1234
|
+
await new Promise((resolve) => setTimeout(resolve, delay2));
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
// ── Live hints ────────────────────────────────────────────────────
|
|
1239
|
+
/**
|
|
1240
|
+
* Subscribes to live change hints through the host (installed apps only). Returns an unsubscribe function.
|
|
1241
|
+
* Hints carry ids only; duplicates and reordering are normal, and hints are lost while disconnected.
|
|
1242
|
+
*/
|
|
1243
|
+
subscribeChanges(handlers) {
|
|
1244
|
+
if (!this.bridge) throw new Error("Live chat hints are only available to apps running inside the workspace.");
|
|
1245
|
+
return this.bridge.subscribeChat(handlers);
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
function id(value) {
|
|
1249
|
+
return encodeURIComponent(value);
|
|
1250
|
+
}
|
|
1251
|
+
function page(options) {
|
|
1252
|
+
return { cursor: options?.cursor, limit: options?.limit };
|
|
1253
|
+
}
|
|
1254
|
+
function headers(idempotencyKey) {
|
|
1255
|
+
return idempotencyKey ? { ...JSON_HEADERS, "Idempotency-Key": idempotencyKey } : JSON_HEADERS;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1073
1258
|
// src/transport/app-commands.ts
|
|
1074
1259
|
var APP_COMMAND_BATCH_SIZE = 200;
|
|
1075
1260
|
var APP_COMMANDS_CAPABILITY = "commands";
|
|
@@ -1113,7 +1298,7 @@ function element(value) {
|
|
|
1113
1298
|
return record(value) && identifier(value.id) && natural(value.version) && (value.versionNonce === void 0 || natural(value.versionNonce)) && (value.isDeleted === void 0 || typeof value.isDeleted === "boolean");
|
|
1114
1299
|
}
|
|
1115
1300
|
function files(value) {
|
|
1116
|
-
return record(value) && Object.keys(value).length <= 1e4 && Object.entries(value).every(([
|
|
1301
|
+
return record(value) && Object.keys(value).length <= 1e4 && Object.entries(value).every(([id2, file]) => record(file) && identifier(id2) && file.id === id2 && typeof file.dataURL === "string" && file.dataURL.length <= 10 * 1024 * 1024 && typeof file.mimeType === "string" && file.mimeType.length > 0 && file.mimeType.length <= 128 && natural(file.created) && (file.lastRetrieved === void 0 || natural(file.lastRetrieved)));
|
|
1117
1302
|
}
|
|
1118
1303
|
function isNativeSnapshot(value) {
|
|
1119
1304
|
if (!record(value) || !natural(value.sequence) || !natural(value.savedSequence) || value.savedSequence > value.sequence || typeof value.revision !== "string" || !value.revision || value.revision.length > 1024 || typeof value.readOnly !== "boolean" || !record(value.scene) || !Array.isArray(value.scene.elements) || value.scene.elements.length > 1e4 || !value.scene.elements.every(element) || !files(value.scene.files) || !record(value.scene.appState) || !Array.isArray(value.participants) || value.participants.length > 20)
|
|
@@ -1228,6 +1413,7 @@ var Bridge = class {
|
|
|
1228
1413
|
commandFlushScheduled = false;
|
|
1229
1414
|
commandRequests = /* @__PURE__ */ new Set();
|
|
1230
1415
|
_hostCapabilities = [];
|
|
1416
|
+
chatSubscribers = /* @__PURE__ */ new Set();
|
|
1231
1417
|
hostMessageHandlers = /* @__PURE__ */ new Map();
|
|
1232
1418
|
hostMessageRequests = /* @__PURE__ */ new Set();
|
|
1233
1419
|
wopiRequests = /* @__PURE__ */ new Map();
|
|
@@ -1431,13 +1617,13 @@ var Bridge = class {
|
|
|
1431
1617
|
}
|
|
1432
1618
|
};
|
|
1433
1619
|
}
|
|
1434
|
-
queueCommand(
|
|
1620
|
+
queueCommand(id2, change) {
|
|
1435
1621
|
if (change === "upsert") {
|
|
1436
|
-
this.commandRemovals.delete(
|
|
1437
|
-
this.commandUpserts.add(
|
|
1622
|
+
this.commandRemovals.delete(id2);
|
|
1623
|
+
this.commandUpserts.add(id2);
|
|
1438
1624
|
} else {
|
|
1439
|
-
this.commandUpserts.delete(
|
|
1440
|
-
this.commandRemovals.add(
|
|
1625
|
+
this.commandUpserts.delete(id2);
|
|
1626
|
+
this.commandRemovals.add(id2);
|
|
1441
1627
|
}
|
|
1442
1628
|
this.scheduleCommandFlush();
|
|
1443
1629
|
}
|
|
@@ -1449,14 +1635,14 @@ var Bridge = class {
|
|
|
1449
1635
|
this.flushCommands();
|
|
1450
1636
|
});
|
|
1451
1637
|
}
|
|
1452
|
-
commandSnapshot(
|
|
1453
|
-
const command = this.commands.get(
|
|
1638
|
+
commandSnapshot(id2) {
|
|
1639
|
+
const command = this.commands.get(id2);
|
|
1454
1640
|
if (!command) return null;
|
|
1455
1641
|
return command.busy ? { ...command.descriptor, busy: true } : command.descriptor;
|
|
1456
1642
|
}
|
|
1457
1643
|
flushCommands() {
|
|
1458
1644
|
if (!this.sessionId || !this._hostOrigin || this._destroyed) return;
|
|
1459
|
-
const upsert = [...this.commandUpserts].map((
|
|
1645
|
+
const upsert = [...this.commandUpserts].map((id2) => this.commandSnapshot(id2)).filter((c) => !!c);
|
|
1460
1646
|
const remove = this.commandReset ? [] : [...this.commandRemovals];
|
|
1461
1647
|
let reset = this.commandReset;
|
|
1462
1648
|
this.commandUpserts.clear();
|
|
@@ -1596,6 +1782,41 @@ var Bridge = class {
|
|
|
1596
1782
|
this.postToHost({ ...reply, error: "The reply could not be sent to the workspace." });
|
|
1597
1783
|
}
|
|
1598
1784
|
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Subscribes to the host's chat live hints (see `ChatModule.subscribeChanges`). The first subscriber asks the host
|
|
1787
|
+
* to relay; the last one to leave stops it. Messages from another session are ignored.
|
|
1788
|
+
*/
|
|
1789
|
+
subscribeChat(handlers) {
|
|
1790
|
+
if (this._destroyed) throw new Error("Bridge has been destroyed.");
|
|
1791
|
+
this.chatSubscribers.add(handlers);
|
|
1792
|
+
const subscribe = () => {
|
|
1793
|
+
if (this.sessionId && this._hostOrigin && this.chatSubscribers.size > 0)
|
|
1794
|
+
this.postToHost({ type: "verentis:chat:subscribe", version: 1, sessionId: this.sessionId });
|
|
1795
|
+
};
|
|
1796
|
+
if (this.chatSubscribers.size === 1) {
|
|
1797
|
+
if (this._hostOrigin) subscribe();
|
|
1798
|
+
else void this._initPromise.then(subscribe, () => void 0);
|
|
1799
|
+
}
|
|
1800
|
+
return () => {
|
|
1801
|
+
if (!this.chatSubscribers.delete(handlers) || this.chatSubscribers.size > 0) return;
|
|
1802
|
+
if (!this._destroyed && this.sessionId && this._hostOrigin)
|
|
1803
|
+
this.postToHost({ type: "verentis:chat:unsubscribe", version: 1, sessionId: this.sessionId });
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
receiveChat(data) {
|
|
1807
|
+
if (data.type !== "verentis:chat:changed" && data.type !== "verentis:chat:connection" && data.type !== "verentis:chat:subscribed" && data.type !== "verentis:chat:error") return false;
|
|
1808
|
+
if (!this._hostOrigin || data.sessionId !== this.sessionId) return true;
|
|
1809
|
+
for (const subscriber of [...this.chatSubscribers]) {
|
|
1810
|
+
try {
|
|
1811
|
+
if (data.type === "verentis:chat:changed") subscriber.onChange(data.hint);
|
|
1812
|
+
else if (data.type === "verentis:chat:error") subscriber.onError?.(String(data.reason).slice(0, 500));
|
|
1813
|
+
else subscriber.onConnection?.(data.status);
|
|
1814
|
+
} catch (error) {
|
|
1815
|
+
console.error("[Verentis SDK] Chat subscriber failed", error);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
return true;
|
|
1819
|
+
}
|
|
1599
1820
|
/** Subscribe to a specific message type from the host */
|
|
1600
1821
|
on(type, listener) {
|
|
1601
1822
|
if (!this.listeners.has(type)) {
|
|
@@ -1620,6 +1841,7 @@ var Bridge = class {
|
|
|
1620
1841
|
this.commandRequests.clear();
|
|
1621
1842
|
this.hostMessageHandlers.clear();
|
|
1622
1843
|
this.hostMessageRequests.clear();
|
|
1844
|
+
this.chatSubscribers.clear();
|
|
1623
1845
|
this.listeners.clear();
|
|
1624
1846
|
for (const pending of this.wopiRequests.values()) {
|
|
1625
1847
|
clearTimeout(pending.timer);
|
|
@@ -1652,7 +1874,7 @@ var Bridge = class {
|
|
|
1652
1874
|
if (this.sessionId && this.commands.size > 0) {
|
|
1653
1875
|
this.commandReset = true;
|
|
1654
1876
|
this.commandRemovals.clear();
|
|
1655
|
-
for (const
|
|
1877
|
+
for (const id2 of this.commands.keys()) this.commandUpserts.add(id2);
|
|
1656
1878
|
this.scheduleCommandFlush();
|
|
1657
1879
|
}
|
|
1658
1880
|
console.info("[Verentis SDK] Received verentis:init from host", {
|
|
@@ -1700,6 +1922,7 @@ var Bridge = class {
|
|
|
1700
1922
|
void this.receiveHostMessage(data);
|
|
1701
1923
|
return;
|
|
1702
1924
|
}
|
|
1925
|
+
if (this.receiveChat(data)) return;
|
|
1703
1926
|
const typeListeners = this.listeners.get(data.type);
|
|
1704
1927
|
if (typeListeners) {
|
|
1705
1928
|
for (const listener of typeListeners) {
|
|
@@ -1734,17 +1957,17 @@ var HttpTransport = class {
|
|
|
1734
1957
|
async request(method, path, options) {
|
|
1735
1958
|
const url = this.buildUrl(path, options?.params);
|
|
1736
1959
|
console.info("[Verentis SDK] Request started", { method, path, url });
|
|
1737
|
-
const
|
|
1960
|
+
const headers2 = {};
|
|
1738
1961
|
const authHeader = await this.auth.getAuthHeader();
|
|
1739
1962
|
if (authHeader) {
|
|
1740
|
-
|
|
1963
|
+
headers2["Authorization"] = authHeader;
|
|
1741
1964
|
}
|
|
1742
1965
|
if (options?.headers) {
|
|
1743
|
-
Object.assign(
|
|
1966
|
+
Object.assign(headers2, options.headers);
|
|
1744
1967
|
}
|
|
1745
1968
|
const response = await fetch(url, {
|
|
1746
1969
|
method,
|
|
1747
|
-
headers,
|
|
1970
|
+
headers: headers2,
|
|
1748
1971
|
body: options?.body
|
|
1749
1972
|
});
|
|
1750
1973
|
await this.ensureSuccess(response);
|
|
@@ -1763,15 +1986,15 @@ var HttpTransport = class {
|
|
|
1763
1986
|
async requestRaw(method, path, options) {
|
|
1764
1987
|
const url = this.buildUrl(path, options?.params);
|
|
1765
1988
|
console.info("[Verentis SDK] Raw request started", { method, path, url });
|
|
1766
|
-
const
|
|
1989
|
+
const headers2 = {};
|
|
1767
1990
|
const authHeader = await this.auth.getAuthHeader();
|
|
1768
1991
|
if (authHeader) {
|
|
1769
|
-
|
|
1992
|
+
headers2["Authorization"] = authHeader;
|
|
1770
1993
|
}
|
|
1771
1994
|
if (options?.headers) {
|
|
1772
|
-
Object.assign(
|
|
1995
|
+
Object.assign(headers2, options.headers);
|
|
1773
1996
|
}
|
|
1774
|
-
const response = await fetch(url, { method, headers, body: options?.body });
|
|
1997
|
+
const response = await fetch(url, { method, headers: headers2, body: options?.body });
|
|
1775
1998
|
console.info("[Verentis SDK] Raw request completed", {
|
|
1776
1999
|
method,
|
|
1777
2000
|
path,
|
|
@@ -1840,6 +2063,7 @@ var VerentisClient = class {
|
|
|
1840
2063
|
settings;
|
|
1841
2064
|
notifications;
|
|
1842
2065
|
business;
|
|
2066
|
+
chat;
|
|
1843
2067
|
context;
|
|
1844
2068
|
bridge;
|
|
1845
2069
|
collaboration;
|
|
@@ -1876,6 +2100,7 @@ var VerentisClient = class {
|
|
|
1876
2100
|
this.settings = new SettingsModule(this._http, options?.workspaceId);
|
|
1877
2101
|
this.notifications = new NotificationsModule(this._http, options?.workspaceId);
|
|
1878
2102
|
this.business = new BusinessModule(this._http);
|
|
2103
|
+
this.chat = new ChatModule(this._http, null, this.executions);
|
|
1879
2104
|
this._ready = Promise.resolve();
|
|
1880
2105
|
return;
|
|
1881
2106
|
}
|
|
@@ -1926,6 +2151,7 @@ var VerentisClient = class {
|
|
|
1926
2151
|
this.settings = new SettingsModule(http, context.workspace.id);
|
|
1927
2152
|
this.notifications = new NotificationsModule(http, context.workspace.id);
|
|
1928
2153
|
this.business = new BusinessModule(http);
|
|
2154
|
+
this.chat = new ChatModule(http, this.bridge, this.executions);
|
|
1929
2155
|
}
|
|
1930
2156
|
};
|
|
1931
2157
|
function detectEnvironment() {
|
|
@@ -2021,6 +2247,6 @@ function createVerentisClient(options) {
|
|
|
2021
2247
|
return new VerentisClient(options);
|
|
2022
2248
|
}
|
|
2023
2249
|
|
|
2024
|
-
export { APP_COMMANDS_CAPABILITY, APP_COMMAND_BATCH_SIZE, APP_COMMAND_ID_PATTERN, ApiError, ApiKeyAuth, Bridge, BridgeAuth, BusinessModule, ContextModule, EnginesModule, ExecutionsModule, FilesModule, HOST_MESSAGE_CHANNEL_PATTERN, HttpTransport, InstallationsModule, NativeCollaborationClient, NativeCollaborationError, NotificationsModule, ResourcesModule, SCRIPT_ARGUMENTS_SCHEMA, SettingsModule, TokenAuth, VerentisClient, createVerentisClient, exactHttpsOrigin, findBestMatch, isAppCommand, isDurableSaveConfirmed, isHeaderAction, isNativeSaveResult, isNativeSnapshot, isTerminalStatus, isTrustedMessage, matchMimeType, validateCollaborationDocument, validateNativeCommand };
|
|
2250
|
+
export { APP_COMMANDS_CAPABILITY, APP_COMMAND_BATCH_SIZE, APP_COMMAND_ID_PATTERN, ApiError, ApiKeyAuth, Bridge, BridgeAuth, BusinessModule, ChatModule, ContextModule, EnginesModule, ExecutionsModule, FilesModule, HOST_MESSAGE_CHANNEL_PATTERN, HttpTransport, InstallationsModule, NativeCollaborationClient, NativeCollaborationError, NotificationsModule, ResourcesModule, SCRIPT_ARGUMENTS_SCHEMA, SettingsModule, TokenAuth, VerentisClient, createVerentisClient, exactHttpsOrigin, findBestMatch, isAppCommand, isDurableSaveConfirmed, isHeaderAction, isNativeSaveResult, isNativeSnapshot, isTerminalStatus, isTrustedMessage, matchMimeType, validateCollaborationDocument, validateNativeCommand };
|
|
2025
2251
|
//# sourceMappingURL=index.js.map
|
|
2026
2252
|
//# sourceMappingURL=index.js.map
|