modulex-js 0.1.0 → 1.0.0
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 +74 -26
- package/dist/index.d.mts +2258 -640
- package/dist/index.d.ts +2258 -640
- package/dist/index.js +508 -234
- package/dist/index.mjs +508 -234
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -63,6 +63,12 @@ var ModulexError = class extends Error {
|
|
|
63
63
|
this.body = body;
|
|
64
64
|
this.headers = headers;
|
|
65
65
|
this.name = "ModulexError";
|
|
66
|
+
const env = extractErrorEnvelope(body);
|
|
67
|
+
if (env) {
|
|
68
|
+
if (typeof env.code === "string") this.code = env.code;
|
|
69
|
+
if (typeof env.reason === "string") this.reason = env.reason;
|
|
70
|
+
if (typeof env.layer === "string") this.layer = env.layer;
|
|
71
|
+
}
|
|
66
72
|
}
|
|
67
73
|
};
|
|
68
74
|
var BadRequestError = class extends ModulexError {
|
|
@@ -105,10 +111,18 @@ var RateLimitError = class extends ModulexError {
|
|
|
105
111
|
constructor(message, body, headers) {
|
|
106
112
|
super(message, 429, body, headers);
|
|
107
113
|
this.name = "RateLimitError";
|
|
108
|
-
|
|
109
|
-
this.
|
|
114
|
+
this.retryAfter = parseNumericHeader(headers, "retry-after");
|
|
115
|
+
this.limit = parseNumericHeader(headers, "x-ratelimit-limit");
|
|
116
|
+
this.remaining = parseNumericHeader(headers, "x-ratelimit-remaining");
|
|
117
|
+
this.reset = parseNumericHeader(headers, "x-ratelimit-reset");
|
|
110
118
|
}
|
|
111
119
|
};
|
|
120
|
+
function parseNumericHeader(headers, name) {
|
|
121
|
+
const raw = headers?.get(name);
|
|
122
|
+
if (raw == null) return void 0;
|
|
123
|
+
const n = Number(raw);
|
|
124
|
+
return Number.isNaN(n) ? void 0 : n;
|
|
125
|
+
}
|
|
112
126
|
var InternalError = class extends ModulexError {
|
|
113
127
|
constructor(message, body, headers) {
|
|
114
128
|
super(message, 500, body, headers);
|
|
@@ -166,18 +180,43 @@ function createErrorFromStatus(status, body, headers) {
|
|
|
166
180
|
return new ModulexError(message, status, body, headers);
|
|
167
181
|
}
|
|
168
182
|
}
|
|
183
|
+
function extractErrorEnvelope(body) {
|
|
184
|
+
if (!body || typeof body !== "object") return void 0;
|
|
185
|
+
const b = body;
|
|
186
|
+
const detail = b.detail;
|
|
187
|
+
if (detail && typeof detail === "object" && !Array.isArray(detail)) {
|
|
188
|
+
return detail;
|
|
189
|
+
}
|
|
190
|
+
if (typeof b.code === "string" || typeof b.reason === "string") {
|
|
191
|
+
return b;
|
|
192
|
+
}
|
|
193
|
+
return void 0;
|
|
194
|
+
}
|
|
169
195
|
function extractErrorMessage(body, status) {
|
|
170
|
-
if (body && typeof body === "object"
|
|
171
|
-
const
|
|
196
|
+
if (body && typeof body === "object") {
|
|
197
|
+
const b = body;
|
|
198
|
+
const detail = b.detail;
|
|
172
199
|
if (typeof detail === "string") return detail;
|
|
173
200
|
if (Array.isArray(detail)) {
|
|
174
201
|
return detail.map((d) => `${d.loc?.join(".")}: ${d.msg}`).join("; ");
|
|
175
202
|
}
|
|
203
|
+
const env = extractErrorEnvelope(body);
|
|
204
|
+
if (env) {
|
|
205
|
+
const reason = env.reason ?? env.message;
|
|
206
|
+
const code = env.code;
|
|
207
|
+
if (typeof reason === "string" && typeof code === "string") return `${reason} (${code})`;
|
|
208
|
+
if (typeof reason === "string") return reason;
|
|
209
|
+
if (typeof code === "string") return code;
|
|
210
|
+
}
|
|
211
|
+
if (typeof b.message === "string") return b.message;
|
|
176
212
|
}
|
|
177
213
|
return `HTTP ${status} error`;
|
|
178
214
|
}
|
|
179
215
|
|
|
180
216
|
// src/streaming.ts
|
|
217
|
+
function resolveEventType(event, data) {
|
|
218
|
+
return typeof data.type === "string" && data.type ? data.type : event;
|
|
219
|
+
}
|
|
181
220
|
async function* parseSSEStream(response, signal) {
|
|
182
221
|
const body = response.body;
|
|
183
222
|
if (!body) {
|
|
@@ -210,8 +249,10 @@ async function* parseSSEStream(response, signal) {
|
|
|
210
249
|
} catch {
|
|
211
250
|
parsedData = { raw: dataStr };
|
|
212
251
|
}
|
|
252
|
+
const ev = currentEvent || "message";
|
|
213
253
|
yield {
|
|
214
|
-
event:
|
|
254
|
+
event: ev,
|
|
255
|
+
type: resolveEventType(ev, parsedData),
|
|
215
256
|
data: parsedData,
|
|
216
257
|
id: currentId,
|
|
217
258
|
retry: currentRetry
|
|
@@ -263,8 +304,10 @@ async function* parseSSEStream(response, signal) {
|
|
|
263
304
|
} catch {
|
|
264
305
|
parsedData = { raw: dataStr };
|
|
265
306
|
}
|
|
307
|
+
const ev = currentEvent || "message";
|
|
266
308
|
yield {
|
|
267
|
-
event:
|
|
309
|
+
event: ev,
|
|
310
|
+
type: resolveEventType(ev, parsedData),
|
|
268
311
|
data: parsedData,
|
|
269
312
|
id: currentId,
|
|
270
313
|
retry: currentRetry
|
|
@@ -605,7 +648,8 @@ var Auth = class extends BaseResource {
|
|
|
605
648
|
/**
|
|
606
649
|
* POST /auth/invitations/{id}/accept
|
|
607
650
|
*
|
|
608
|
-
* Accepts a pending organization invitation.
|
|
651
|
+
* Accepts a pending organization invitation. On success the response
|
|
652
|
+
* includes the joined organization and the granted role.
|
|
609
653
|
*/
|
|
610
654
|
async acceptInvitation(invitationId, options) {
|
|
611
655
|
return this._post(
|
|
@@ -699,7 +743,9 @@ var Organizations = class extends BaseResource {
|
|
|
699
743
|
/**
|
|
700
744
|
* POST /organizations/invite
|
|
701
745
|
*
|
|
702
|
-
* Sends an invitation email to add a user to the current organization.
|
|
746
|
+
* Sends an invitation email to add a user to the current organization. The
|
|
747
|
+
* invited user joins as `admin`; the org `member` role was retired, so the
|
|
748
|
+
* backend rejects `role: 'member'` with HTTP 422.
|
|
703
749
|
*/
|
|
704
750
|
async invite(params, options) {
|
|
705
751
|
return this._post("/organizations/invite", params, options);
|
|
@@ -731,7 +777,9 @@ var Organizations = class extends BaseResource {
|
|
|
731
777
|
/**
|
|
732
778
|
* PUT /organizations/{orgId}/users/{userId}/role
|
|
733
779
|
*
|
|
734
|
-
* Updates a member's role within an organization.
|
|
780
|
+
* Updates a member's role within an organization. Only `'admin'` is accepted —
|
|
781
|
+
* the org `member` role was retired, so the backend rejects `role: 'member'`
|
|
782
|
+
* with HTTP 422.
|
|
735
783
|
*/
|
|
736
784
|
async updateRole(organizationId, userId, params, options) {
|
|
737
785
|
return this._put(
|
|
@@ -752,6 +800,67 @@ var Organizations = class extends BaseResource {
|
|
|
752
800
|
options
|
|
753
801
|
);
|
|
754
802
|
}
|
|
803
|
+
/**
|
|
804
|
+
* POST /organizations/invite/preview
|
|
805
|
+
*
|
|
806
|
+
* Previews the prorated cost of adding one seat to the current organization,
|
|
807
|
+
* for displaying to the user before confirming an invite. The organization is
|
|
808
|
+
* resolved from the `X-Organization-ID` header, so no request body is sent.
|
|
809
|
+
*
|
|
810
|
+
* Returns a discriminated union on `preview_available`: when `false`, the
|
|
811
|
+
* organization has no active paid subscription (a `reason` is provided); when
|
|
812
|
+
* `true`, full prorated pricing detail is returned.
|
|
813
|
+
*
|
|
814
|
+
* @remarks Admin-only: requires organization admin (or owner) permission.
|
|
815
|
+
*/
|
|
816
|
+
async invitePreview(options) {
|
|
817
|
+
return this._post("/organizations/invite/preview", void 0, options);
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* GET /organizations/settings
|
|
821
|
+
*
|
|
822
|
+
* Returns the per-organization preference settings (model visibility and the
|
|
823
|
+
* default composer LLM) for the current organization. The organization is
|
|
824
|
+
* resolved from the `X-Organization-ID` header.
|
|
825
|
+
*
|
|
826
|
+
* @remarks Available to any organization member.
|
|
827
|
+
*/
|
|
828
|
+
async getSettings(options) {
|
|
829
|
+
return this._get("/organizations/settings", options);
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* PUT /organizations/settings/llm-model-visibility
|
|
833
|
+
*
|
|
834
|
+
* Sets which models are visible in the dropdown for a single integration.
|
|
835
|
+
* Send the FULL desired visible list; an empty `models` array resets that
|
|
836
|
+
* integration's visibility to the catalog default. The organization is
|
|
837
|
+
* resolved from the `X-Organization-ID` header.
|
|
838
|
+
*
|
|
839
|
+
* @remarks Admin-only: requires organization admin (or owner) permission.
|
|
840
|
+
*/
|
|
841
|
+
async setModelVisibility(params, options) {
|
|
842
|
+
return this._put(
|
|
843
|
+
"/organizations/settings/llm-model-visibility",
|
|
844
|
+
params,
|
|
845
|
+
options
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* PUT /organizations/settings/composer-llm
|
|
850
|
+
*
|
|
851
|
+
* Persists the organization's default composer LLM. Composer requests that
|
|
852
|
+
* omit an explicit LLM fall back to this value. The organization is resolved
|
|
853
|
+
* from the `X-Organization-ID` header.
|
|
854
|
+
*
|
|
855
|
+
* @remarks Admin-only: requires organization admin (or owner) permission.
|
|
856
|
+
*/
|
|
857
|
+
async setComposerLlm(params, options) {
|
|
858
|
+
return this._put(
|
|
859
|
+
"/organizations/settings/composer-llm",
|
|
860
|
+
params,
|
|
861
|
+
options
|
|
862
|
+
);
|
|
863
|
+
}
|
|
755
864
|
};
|
|
756
865
|
|
|
757
866
|
// src/resources/workflows.ts
|
|
@@ -759,7 +868,13 @@ var Workflows = class extends BaseResource {
|
|
|
759
868
|
/**
|
|
760
869
|
* POST /workflows
|
|
761
870
|
*
|
|
762
|
-
* Creates a new workflow with the given schema.
|
|
871
|
+
* Creates a new workflow with the given schema. Returns HTTP 201.
|
|
872
|
+
* Requires organization admin/owner role.
|
|
873
|
+
*
|
|
874
|
+
* `params.visibility` is passed through unchanged with no client-side default;
|
|
875
|
+
* omit it to let the backend default to `"organization"`. `"private"` is no
|
|
876
|
+
* longer creator-only — it behaves like `"organization"` (any org admin/owner
|
|
877
|
+
* can view/run/resume).
|
|
763
878
|
*/
|
|
764
879
|
async create(params, options) {
|
|
765
880
|
return this._post("/workflows", params, options);
|
|
@@ -816,6 +931,7 @@ var Workflows = class extends BaseResource {
|
|
|
816
931
|
* PUT /workflows/{workflowId}
|
|
817
932
|
*
|
|
818
933
|
* Updates an existing workflow. Only provided fields are changed.
|
|
934
|
+
* Requires organization admin/owner role.
|
|
819
935
|
*/
|
|
820
936
|
async update(workflowId, params, options) {
|
|
821
937
|
return this._put(`/workflows/${workflowId}`, params, options);
|
|
@@ -823,7 +939,9 @@ var Workflows = class extends BaseResource {
|
|
|
823
939
|
/**
|
|
824
940
|
* DELETE /workflows/{workflowId}
|
|
825
941
|
*
|
|
826
|
-
*
|
|
942
|
+
* Permanently (hard) deletes a workflow. This is IRREVERSIBLE — the workflow
|
|
943
|
+
* row and its schema are removed from the database, not soft-deleted.
|
|
944
|
+
* Requires organization admin/owner role.
|
|
827
945
|
*/
|
|
828
946
|
async delete(workflowId, options) {
|
|
829
947
|
return this._delete(
|
|
@@ -849,6 +967,19 @@ var Workflows = class extends BaseResource {
|
|
|
849
967
|
}
|
|
850
968
|
});
|
|
851
969
|
}
|
|
970
|
+
/**
|
|
971
|
+
* GET /workflows/{workflowId}/changes — SSE stream
|
|
972
|
+
*
|
|
973
|
+
* Opens a Server-Sent Events stream of real-time collaboration changes for a
|
|
974
|
+
* workflow (canvas/composer sync). This is a data-only stream: each yielded
|
|
975
|
+
* value is a {@link WorkflowChangeEvent} discriminated on its `type` field
|
|
976
|
+
* (`connected`, `workflow_updated`, `user_joined`, `user_left`).
|
|
977
|
+
*/
|
|
978
|
+
async *listenChanges(workflowId, options) {
|
|
979
|
+
for await (const frame of this.streamSSE(`/workflows/${workflowId}/changes`, options)) {
|
|
980
|
+
yield frame.data;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
852
983
|
};
|
|
853
984
|
|
|
854
985
|
// src/resources/executions.ts
|
|
@@ -856,9 +987,14 @@ var Executions = class extends BaseResource {
|
|
|
856
987
|
/**
|
|
857
988
|
* POST /workflows/run
|
|
858
989
|
*
|
|
859
|
-
* Initiates a workflow run. Supports
|
|
860
|
-
*
|
|
861
|
-
*
|
|
990
|
+
* Initiates a workflow run. Supports two modes: a saved workflow (`workflowId`,
|
|
991
|
+
* which requires an active deployment — the backend returns 400 otherwise) or
|
|
992
|
+
* an inline ad-hoc definition (`workflow`). Returns immediately with run
|
|
993
|
+
* metadata (`status` is `"running"` for streaming runs); stream events via
|
|
994
|
+
* `listen()`.
|
|
995
|
+
*
|
|
996
|
+
* The legacy direct-LLM mode was removed; an `llm_config`-only request now
|
|
997
|
+
* returns HTTP 410 — use `client.assistant.chat()` instead.
|
|
862
998
|
*/
|
|
863
999
|
async run(params, options) {
|
|
864
1000
|
return this._post("/workflows/run", params, options);
|
|
@@ -868,6 +1004,10 @@ var Executions = class extends BaseResource {
|
|
|
868
1004
|
*
|
|
869
1005
|
* Returns the persisted state snapshot of a workflow thread at its latest
|
|
870
1006
|
* checkpoint.
|
|
1007
|
+
*
|
|
1008
|
+
* Throws `NotFoundError` on HTTP 404 — the thread does not exist OR is not
|
|
1009
|
+
* owned by your organization. Ownership failures return an identical 404 (not
|
|
1010
|
+
* 403) by design, so there is no existence leak.
|
|
871
1011
|
*/
|
|
872
1012
|
async getState(threadId, options) {
|
|
873
1013
|
return this._get(`/workflows/state/${threadId}`, options);
|
|
@@ -876,6 +1016,11 @@ var Executions = class extends BaseResource {
|
|
|
876
1016
|
* POST /workflows/resume/{threadId}
|
|
877
1017
|
*
|
|
878
1018
|
* Resumes a workflow that is waiting at an interrupt node.
|
|
1019
|
+
*
|
|
1020
|
+
* Guard responses: 400 (missing `resumeValue` or `runId`); 404 — a
|
|
1021
|
+
* `NotFoundError` — when there is no checkpoint for the thread OR the
|
|
1022
|
+
* run/thread is not owned by your organization. Ownership failures return an
|
|
1023
|
+
* identical 404 (not 403) by design, so there is no existence leak.
|
|
879
1024
|
*/
|
|
880
1025
|
async resume(params, options) {
|
|
881
1026
|
const { threadId, ...rest } = params;
|
|
@@ -888,7 +1033,13 @@ var Executions = class extends BaseResource {
|
|
|
888
1033
|
/**
|
|
889
1034
|
* POST /workflows/cancel/{runId}
|
|
890
1035
|
*
|
|
891
|
-
* Requests cancellation of an in-progress workflow run.
|
|
1036
|
+
* Requests cancellation of an in-progress workflow run. On success the
|
|
1037
|
+
* response `status` is `"cancellation_requested"`.
|
|
1038
|
+
*
|
|
1039
|
+
* Guard responses: 404 — a `NotFoundError` — when the run is unknown OR is not
|
|
1040
|
+
* owned by your organization (ownership failures return an identical 404, not
|
|
1041
|
+
* 403, by design, so there is no existence leak); 400 (the run is not in a
|
|
1042
|
+
* `running`/`interrupted` state).
|
|
892
1043
|
*/
|
|
893
1044
|
async cancel(runId, params, options) {
|
|
894
1045
|
return this._post(
|
|
@@ -900,14 +1051,53 @@ var Executions = class extends BaseResource {
|
|
|
900
1051
|
/**
|
|
901
1052
|
* GET /workflows/listen/{runId} — SSE stream
|
|
902
1053
|
*
|
|
903
|
-
* Opens a Server-Sent Events stream for real-time execution events of
|
|
904
|
-
*
|
|
1054
|
+
* Opens a Server-Sent Events stream for real-time execution events of an
|
|
1055
|
+
* in-progress workflow run. This is a data-only stream: each yielded value is
|
|
1056
|
+
* a {@link WorkflowSSEEvent} discriminated on its `type` field (`metadata`,
|
|
1057
|
+
* `node_started`, `node_update`, `interrupt`, `resumed`, `done`, `cancelled`,
|
|
1058
|
+
* `error`). The stream ends after a `done` or `error` event.
|
|
1059
|
+
*
|
|
1060
|
+
* A 404 on connect throws `NotFoundError` before any event is yielded — the
|
|
1061
|
+
* run does not exist OR is not owned by your organization (ownership failures
|
|
1062
|
+
* return an identical 404, not 403). The stream does NOT auto-reconnect on a
|
|
1063
|
+
* 404.
|
|
905
1064
|
*/
|
|
906
|
-
listen(runId, options) {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1065
|
+
async *listen(runId, options) {
|
|
1066
|
+
for await (const frame of this.streamSSE(`/workflows/listen/${runId}`, options)) {
|
|
1067
|
+
yield frame.data;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
|
|
1072
|
+
// src/resources/workflow-runs.ts
|
|
1073
|
+
var WorkflowRuns = class extends BaseResource {
|
|
1074
|
+
/**
|
|
1075
|
+
* GET /workflow-runs
|
|
1076
|
+
*
|
|
1077
|
+
* Lists workflow runs for the organization, newest first. Pass `workflowId`
|
|
1078
|
+
* for per-workflow history. Pagination is via `has_more` (no total count).
|
|
1079
|
+
*/
|
|
1080
|
+
async list(params, options) {
|
|
1081
|
+
return this._get("/workflow-runs", {
|
|
1082
|
+
...options,
|
|
1083
|
+
params: {
|
|
1084
|
+
...params,
|
|
1085
|
+
...options?.params
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* GET /workflow-runs/{runPk}
|
|
1091
|
+
*
|
|
1092
|
+
* Returns the full durable run record (including input/output snapshots).
|
|
1093
|
+
*
|
|
1094
|
+
* NOTE: `runPk` is the run table primary key (the `id` field of a
|
|
1095
|
+
* {@link WorkflowRunListItem} / {@link WorkflowRunDetail}), NOT the string
|
|
1096
|
+
* `run_id` used by `executions.listen()` / `executions.cancel()`. Passing a
|
|
1097
|
+
* `run_id` here returns 404.
|
|
1098
|
+
*/
|
|
1099
|
+
async get(runPk, options) {
|
|
1100
|
+
return this._get(`/workflow-runs/${runPk}`, options);
|
|
911
1101
|
}
|
|
912
1102
|
};
|
|
913
1103
|
|
|
@@ -1077,7 +1267,8 @@ var Credentials = class extends BaseResource {
|
|
|
1077
1267
|
/**
|
|
1078
1268
|
* GET /credentials/{credentialId}
|
|
1079
1269
|
*
|
|
1080
|
-
* Returns a single credential record
|
|
1270
|
+
* Returns a single credential record, including ownership and (optionally
|
|
1271
|
+
* masked) auth detail fields not present on the list endpoint.
|
|
1081
1272
|
*/
|
|
1082
1273
|
async get(credentialId, params, options) {
|
|
1083
1274
|
return this._get(`/credentials/${credentialId}`, {
|
|
@@ -1092,6 +1283,8 @@ var Credentials = class extends BaseResource {
|
|
|
1092
1283
|
* POST /credentials
|
|
1093
1284
|
*
|
|
1094
1285
|
* Creates a new credential. The auth data is encrypted at rest.
|
|
1286
|
+
*
|
|
1287
|
+
* @remarks Requires admin/owner role on the organization.
|
|
1095
1288
|
*/
|
|
1096
1289
|
async create(params, options) {
|
|
1097
1290
|
return this._post("/credentials", params, options);
|
|
@@ -1153,6 +1346,8 @@ var Credentials = class extends BaseResource {
|
|
|
1153
1346
|
* GET /credentials/{credentialId}/usage
|
|
1154
1347
|
*
|
|
1155
1348
|
* Returns usage statistics for a credential.
|
|
1349
|
+
*
|
|
1350
|
+
* @remarks Requires admin/owner role on the organization.
|
|
1156
1351
|
*/
|
|
1157
1352
|
async usage(credentialId, params, options) {
|
|
1158
1353
|
return this._get(`/credentials/${credentialId}/usage`, {
|
|
@@ -1167,7 +1362,9 @@ var Credentials = class extends BaseResource {
|
|
|
1167
1362
|
/**
|
|
1168
1363
|
* GET /credentials/{credentialId}/audit
|
|
1169
1364
|
*
|
|
1170
|
-
* Returns the audit log for a credential.
|
|
1365
|
+
* Returns the audit log for a credential as an array of entries.
|
|
1366
|
+
*
|
|
1367
|
+
* @remarks Requires admin/owner role on the organization.
|
|
1171
1368
|
*/
|
|
1172
1369
|
async audit(credentialId, params, options) {
|
|
1173
1370
|
return this._get(`/credentials/${credentialId}/audit`, {
|
|
@@ -1182,7 +1379,10 @@ var Credentials = class extends BaseResource {
|
|
|
1182
1379
|
/**
|
|
1183
1380
|
* POST /credentials/bulk-modulex-keys/stream — SSE
|
|
1184
1381
|
*
|
|
1185
|
-
* Streams bulk ModuleX managed key provisioning events.
|
|
1382
|
+
* Streams bulk ModuleX managed key provisioning events. Each event's
|
|
1383
|
+
* `data` field can be parsed as a {@link ModulexKeyBulkEventData}.
|
|
1384
|
+
*
|
|
1385
|
+
* @remarks Requires admin/owner role on the organization.
|
|
1186
1386
|
*/
|
|
1187
1387
|
bulkModulexKeys(options) {
|
|
1188
1388
|
return this.streamSSEPost("/credentials/bulk-modulex-keys/stream", void 0, options);
|
|
@@ -1193,7 +1393,11 @@ var Credentials = class extends BaseResource {
|
|
|
1193
1393
|
* Creates a credential for a Model Context Protocol (MCP) server.
|
|
1194
1394
|
*/
|
|
1195
1395
|
async mcpServer(params, options) {
|
|
1196
|
-
return this._post(
|
|
1396
|
+
return this._post(
|
|
1397
|
+
"/credentials/mcp-server",
|
|
1398
|
+
params,
|
|
1399
|
+
options
|
|
1400
|
+
);
|
|
1197
1401
|
}
|
|
1198
1402
|
/**
|
|
1199
1403
|
* POST /credentials/{credentialId}/refresh-discovery
|
|
@@ -1218,6 +1422,37 @@ var Credentials = class extends BaseResource {
|
|
|
1218
1422
|
options
|
|
1219
1423
|
);
|
|
1220
1424
|
}
|
|
1425
|
+
/**
|
|
1426
|
+
* POST /credentials/oauth2/initiate
|
|
1427
|
+
*
|
|
1428
|
+
* Initiates an OAuth2 authorization flow for an integration and returns the
|
|
1429
|
+
* authorization URL the user should be redirected to, along with a `state`
|
|
1430
|
+
* token correlating the flow.
|
|
1431
|
+
*
|
|
1432
|
+
* @remarks Requires admin/owner role on the organization.
|
|
1433
|
+
*/
|
|
1434
|
+
async initiateOAuth2(params, options) {
|
|
1435
|
+
return this._post(
|
|
1436
|
+
"/credentials/oauth2/initiate",
|
|
1437
|
+
params,
|
|
1438
|
+
options
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* POST /credentials/{credentialId}/oauth2/refresh
|
|
1443
|
+
*
|
|
1444
|
+
* Manually refreshes the access token of an existing OAuth2 credential and
|
|
1445
|
+
* returns the updated credential record.
|
|
1446
|
+
*
|
|
1447
|
+
* @remarks Requires admin/owner role on the organization.
|
|
1448
|
+
*/
|
|
1449
|
+
async refreshOAuth2(credentialId, options) {
|
|
1450
|
+
return this._post(
|
|
1451
|
+
`/credentials/${credentialId}/oauth2/refresh`,
|
|
1452
|
+
void 0,
|
|
1453
|
+
options
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1221
1456
|
};
|
|
1222
1457
|
|
|
1223
1458
|
// src/resources/integrations.ts
|
|
@@ -1261,7 +1496,7 @@ var Integrations = class extends BaseResource {
|
|
|
1261
1496
|
*/
|
|
1262
1497
|
async tool(integrationName, options) {
|
|
1263
1498
|
return this._get(
|
|
1264
|
-
`/integrations/tools/${integrationName}`,
|
|
1499
|
+
`/integrations/tools/${encodeURIComponent(integrationName)}`,
|
|
1265
1500
|
options
|
|
1266
1501
|
);
|
|
1267
1502
|
}
|
|
@@ -1283,7 +1518,7 @@ var Integrations = class extends BaseResource {
|
|
|
1283
1518
|
*/
|
|
1284
1519
|
async llmProvider(providerName, options) {
|
|
1285
1520
|
return this._get(
|
|
1286
|
-
`/integrations/llm-providers/${providerName}`,
|
|
1521
|
+
`/integrations/llm-providers/${encodeURIComponent(providerName)}`,
|
|
1287
1522
|
options
|
|
1288
1523
|
);
|
|
1289
1524
|
}
|
|
@@ -1305,7 +1540,7 @@ var Integrations = class extends BaseResource {
|
|
|
1305
1540
|
*/
|
|
1306
1541
|
async knowledgeProvider(providerName, options) {
|
|
1307
1542
|
return this._get(
|
|
1308
|
-
`/integrations/knowledge-providers/${providerName}`,
|
|
1543
|
+
`/integrations/knowledge-providers/${encodeURIComponent(providerName)}`,
|
|
1309
1544
|
options
|
|
1310
1545
|
);
|
|
1311
1546
|
}
|
|
@@ -1316,7 +1551,7 @@ var Integrations = class extends BaseResource {
|
|
|
1316
1551
|
*/
|
|
1317
1552
|
async get(integrationName, options) {
|
|
1318
1553
|
return this._get(
|
|
1319
|
-
`/integrations/${integrationName}`,
|
|
1554
|
+
`/integrations/${encodeURIComponent(integrationName)}`,
|
|
1320
1555
|
options
|
|
1321
1556
|
);
|
|
1322
1557
|
}
|
|
@@ -1328,6 +1563,9 @@ var Knowledge = class extends BaseResource {
|
|
|
1328
1563
|
* GET /knowledge-bases
|
|
1329
1564
|
*
|
|
1330
1565
|
* Lists knowledge bases for the current organization.
|
|
1566
|
+
*
|
|
1567
|
+
* The backend returns a bare JSON array (no pagination envelope); the
|
|
1568
|
+
* `limit`/`offset`/`status` query params control which records are returned.
|
|
1331
1569
|
*/
|
|
1332
1570
|
async list(params, options) {
|
|
1333
1571
|
return this._get("/knowledge-bases", {
|
|
@@ -1344,6 +1582,8 @@ var Knowledge = class extends BaseResource {
|
|
|
1344
1582
|
* POST /knowledge-bases
|
|
1345
1583
|
*
|
|
1346
1584
|
* Creates a new knowledge base.
|
|
1585
|
+
*
|
|
1586
|
+
* Requires an organization admin or owner role; non-admin keys receive 403.
|
|
1347
1587
|
*/
|
|
1348
1588
|
async create(params, options) {
|
|
1349
1589
|
return this._post("/knowledge-bases", params, options);
|
|
@@ -1371,6 +1611,8 @@ var Knowledge = class extends BaseResource {
|
|
|
1371
1611
|
* PUT /knowledge-bases/{kbId}
|
|
1372
1612
|
*
|
|
1373
1613
|
* Updates a knowledge base's name, description, or configuration.
|
|
1614
|
+
*
|
|
1615
|
+
* Requires an organization admin or owner role; non-admin keys receive 403.
|
|
1374
1616
|
*/
|
|
1375
1617
|
async update(knowledgeBaseId, params, options) {
|
|
1376
1618
|
return this._put(
|
|
@@ -1384,6 +1626,8 @@ var Knowledge = class extends BaseResource {
|
|
|
1384
1626
|
*
|
|
1385
1627
|
* Deletes a knowledge base. Pass `deleteFiles: true` to also remove
|
|
1386
1628
|
* the underlying stored files.
|
|
1629
|
+
*
|
|
1630
|
+
* Requires an organization admin or owner role; non-admin keys receive 403.
|
|
1387
1631
|
*/
|
|
1388
1632
|
async delete(knowledgeBaseId, params, options) {
|
|
1389
1633
|
return this._delete(
|
|
@@ -1402,6 +1646,9 @@ var Knowledge = class extends BaseResource {
|
|
|
1402
1646
|
* POST /knowledge-bases/{kbId}/archive
|
|
1403
1647
|
*
|
|
1404
1648
|
* Archives a knowledge base, pausing ingestion without deleting data.
|
|
1649
|
+
* Returns the updated knowledge base record.
|
|
1650
|
+
*
|
|
1651
|
+
* Requires an organization admin or owner role; non-admin keys receive 403.
|
|
1405
1652
|
*/
|
|
1406
1653
|
async archive(knowledgeBaseId, options) {
|
|
1407
1654
|
return this._post(
|
|
@@ -1414,6 +1661,9 @@ var Knowledge = class extends BaseResource {
|
|
|
1414
1661
|
* GET /knowledge-bases/{kbId}/documents
|
|
1415
1662
|
*
|
|
1416
1663
|
* Returns documents within a knowledge base.
|
|
1664
|
+
*
|
|
1665
|
+
* The backend returns a bare JSON array; the `limit`/`offset`/`status`
|
|
1666
|
+
* query params control which records are returned.
|
|
1417
1667
|
*/
|
|
1418
1668
|
async documents(knowledgeBaseId, params, options) {
|
|
1419
1669
|
return this._get(
|
|
@@ -1434,6 +1684,8 @@ var Knowledge = class extends BaseResource {
|
|
|
1434
1684
|
*
|
|
1435
1685
|
* Uploads a document file to a knowledge base for ingestion.
|
|
1436
1686
|
* Builds a `FormData` with the file and optional metadata JSON.
|
|
1687
|
+
*
|
|
1688
|
+
* Requires an organization admin or owner role; non-admin keys receive 403.
|
|
1437
1689
|
*/
|
|
1438
1690
|
async uploadDocument(knowledgeBaseId, params, options) {
|
|
1439
1691
|
const formData = new FormData();
|
|
@@ -1461,7 +1713,8 @@ var Knowledge = class extends BaseResource {
|
|
|
1461
1713
|
/**
|
|
1462
1714
|
* GET /knowledge-bases/{kbId}/documents/{docId}/status
|
|
1463
1715
|
*
|
|
1464
|
-
* Returns the processing status
|
|
1716
|
+
* Returns the processing status of a document. Some fields are conditional
|
|
1717
|
+
* on the document's `status` value.
|
|
1465
1718
|
*/
|
|
1466
1719
|
async documentStatus(knowledgeBaseId, documentId, options) {
|
|
1467
1720
|
return this._get(
|
|
@@ -1474,6 +1727,8 @@ var Knowledge = class extends BaseResource {
|
|
|
1474
1727
|
*
|
|
1475
1728
|
* Deletes a document and its chunks from the knowledge base.
|
|
1476
1729
|
* Pass `deleteFile: true` to also remove the source file from storage.
|
|
1730
|
+
*
|
|
1731
|
+
* Requires an organization admin or owner role; non-admin keys receive 403.
|
|
1477
1732
|
*/
|
|
1478
1733
|
async deleteDocument(knowledgeBaseId, documentId, params, options) {
|
|
1479
1734
|
return this._delete(
|
|
@@ -1491,7 +1746,9 @@ var Knowledge = class extends BaseResource {
|
|
|
1491
1746
|
/**
|
|
1492
1747
|
* POST /knowledge-bases/{kbId}/documents/{docId}/retry
|
|
1493
1748
|
*
|
|
1494
|
-
* Retries ingestion of a failed document.
|
|
1749
|
+
* Retries ingestion of a failed document. Returns the updated document record.
|
|
1750
|
+
*
|
|
1751
|
+
* Requires an organization admin or owner role; non-admin keys receive 403.
|
|
1495
1752
|
*/
|
|
1496
1753
|
async retryDocument(knowledgeBaseId, documentId, options) {
|
|
1497
1754
|
return this._post(
|
|
@@ -1635,6 +1892,7 @@ var Schedules = class extends BaseResource {
|
|
|
1635
1892
|
* POST /schedules/{scheduleId}/pause
|
|
1636
1893
|
*
|
|
1637
1894
|
* Pauses a schedule, preventing future runs until resumed.
|
|
1895
|
+
* Returns the updated schedule.
|
|
1638
1896
|
*/
|
|
1639
1897
|
async pause(scheduleId, options) {
|
|
1640
1898
|
return this._post(
|
|
@@ -1646,7 +1904,7 @@ var Schedules = class extends BaseResource {
|
|
|
1646
1904
|
/**
|
|
1647
1905
|
* POST /schedules/{scheduleId}/resume
|
|
1648
1906
|
*
|
|
1649
|
-
* Resumes a paused schedule.
|
|
1907
|
+
* Resumes a paused schedule. Returns the updated schedule.
|
|
1650
1908
|
*/
|
|
1651
1909
|
async resume(scheduleId, options) {
|
|
1652
1910
|
return this._post(
|
|
@@ -1713,204 +1971,293 @@ var Schedules = class extends BaseResource {
|
|
|
1713
1971
|
}
|
|
1714
1972
|
};
|
|
1715
1973
|
|
|
1716
|
-
// src/resources/
|
|
1717
|
-
var
|
|
1974
|
+
// src/resources/composer.ts
|
|
1975
|
+
var Composer = class extends BaseResource {
|
|
1718
1976
|
/**
|
|
1719
|
-
*
|
|
1977
|
+
* POST /composer/chat
|
|
1720
1978
|
*
|
|
1721
|
-
*
|
|
1979
|
+
* Starts a new Composer chat or sends a message to an existing session.
|
|
1980
|
+
* Returns a run ID that can be used to listen to the SSE stream.
|
|
1981
|
+
*
|
|
1982
|
+
* Errors: 409 if the chat has a pending HITL question (answer it via
|
|
1983
|
+
* `resume()` first); 402/403/429 for billing/limit gates.
|
|
1722
1984
|
*/
|
|
1723
|
-
async
|
|
1724
|
-
return this.
|
|
1985
|
+
async chat(params, options) {
|
|
1986
|
+
return this._post("/composer/chat", params, options);
|
|
1725
1987
|
}
|
|
1726
1988
|
/**
|
|
1727
|
-
* GET /
|
|
1989
|
+
* GET /composer/chats
|
|
1728
1990
|
*
|
|
1729
|
-
*
|
|
1991
|
+
* Lists the current user's Composer chats, newest first, with cursor
|
|
1992
|
+
* pagination (`next_cursor` is an ISO `updated_at` timestamp).
|
|
1730
1993
|
*/
|
|
1731
|
-
async
|
|
1732
|
-
return this._get(
|
|
1994
|
+
async list(params, options) {
|
|
1995
|
+
return this._get("/composer/chats", {
|
|
1996
|
+
...options,
|
|
1997
|
+
params: {
|
|
1998
|
+
...options?.params,
|
|
1999
|
+
limit: params?.limit,
|
|
2000
|
+
cursor: params?.cursor
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
1733
2003
|
}
|
|
1734
2004
|
/**
|
|
1735
|
-
* GET /
|
|
2005
|
+
* GET /composer/chat/{composerChatId}
|
|
1736
2006
|
*
|
|
1737
|
-
* Returns
|
|
2007
|
+
* Returns a Composer chat session with its messages, touched workflows, and
|
|
2008
|
+
* any open HITL question (`pending_user_input_request`).
|
|
1738
2009
|
*/
|
|
1739
|
-
async
|
|
1740
|
-
return this._get(
|
|
2010
|
+
async get(composerChatId, options) {
|
|
2011
|
+
return this._get(
|
|
2012
|
+
`/composer/chat/${composerChatId}`,
|
|
2013
|
+
options
|
|
2014
|
+
);
|
|
1741
2015
|
}
|
|
1742
2016
|
/**
|
|
1743
|
-
*
|
|
2017
|
+
* GET /composer/chat/{composerChatId}/listen/{runId} — SSE
|
|
2018
|
+
*
|
|
2019
|
+
* Opens a Server-Sent Events stream for real-time Composer output. This is a
|
|
2020
|
+
* data-only stream: each yielded value is a {@link ComposerSSEEvent}
|
|
2021
|
+
* discriminated on `type`. A `user_input_request` frame signals a HITL pause —
|
|
2022
|
+
* answer it with `resume()`.
|
|
1744
2023
|
*
|
|
1745
|
-
*
|
|
2024
|
+
* A 404 on connect throws `NotFoundError` before any event is yielded — the
|
|
2025
|
+
* chat/run does not exist OR is not owned by your organization (ownership
|
|
2026
|
+
* failures return an identical 404, not 403). The stream does NOT
|
|
2027
|
+
* auto-reconnect on a 404.
|
|
1746
2028
|
*/
|
|
1747
|
-
async
|
|
1748
|
-
|
|
2029
|
+
async *listen(composerChatId, runId, options) {
|
|
2030
|
+
for await (const frame of this.streamSSE(
|
|
2031
|
+
`/composer/chat/${composerChatId}/listen/${runId}`,
|
|
2032
|
+
options
|
|
2033
|
+
)) {
|
|
2034
|
+
yield frame.data;
|
|
2035
|
+
}
|
|
1749
2036
|
}
|
|
1750
2037
|
/**
|
|
1751
|
-
* POST /
|
|
2038
|
+
* POST /composer/chat/{composerChatId}/resume
|
|
2039
|
+
*
|
|
2040
|
+
* Answers an open HITL question and resumes the paused run. Returns a NEW
|
|
2041
|
+
* `run_id` to listen on.
|
|
1752
2042
|
*
|
|
1753
|
-
*
|
|
2043
|
+
* Errors: 404 (a `NotFoundError`) when the chat does not exist OR is not owned
|
|
2044
|
+
* by your organization (ownership failures return an identical 404, not 403);
|
|
2045
|
+
* 410 if the `requestId` is not pending or already consumed; 403 if the caller
|
|
2046
|
+
* is not the user who triggered the question. The `llm` config is required in
|
|
2047
|
+
* production (the backend returns 400 if omitted).
|
|
1754
2048
|
*/
|
|
1755
|
-
async
|
|
2049
|
+
async resume(composerChatId, params, options) {
|
|
1756
2050
|
return this._post(
|
|
1757
|
-
`/
|
|
1758
|
-
|
|
2051
|
+
`/composer/chat/${composerChatId}/resume`,
|
|
2052
|
+
params,
|
|
1759
2053
|
options
|
|
1760
2054
|
);
|
|
1761
2055
|
}
|
|
1762
2056
|
/**
|
|
1763
|
-
*
|
|
2057
|
+
* PATCH /composer/chat/{composerChatId}/focus
|
|
1764
2058
|
*
|
|
1765
|
-
*
|
|
2059
|
+
* Sets (or clears, with `workflowId: null`) the chat's focused workflow.
|
|
1766
2060
|
*/
|
|
1767
|
-
async
|
|
1768
|
-
return this.
|
|
1769
|
-
`/
|
|
1770
|
-
|
|
2061
|
+
async focus(composerChatId, params, options) {
|
|
2062
|
+
return this._patch(
|
|
2063
|
+
`/composer/chat/${composerChatId}/focus`,
|
|
2064
|
+
params,
|
|
1771
2065
|
options
|
|
1772
2066
|
);
|
|
1773
2067
|
}
|
|
1774
2068
|
/**
|
|
1775
|
-
* POST /
|
|
2069
|
+
* POST /composer/chat/{composerChatId}/save
|
|
1776
2070
|
*
|
|
1777
|
-
*
|
|
2071
|
+
* Saves the Composer's pending workflow changes. Without `workflowId` it
|
|
2072
|
+
* targets the chat's focused workflow (400 if there is none). Returns a
|
|
2073
|
+
* `workflow_sync` payload for refreshing the canvas.
|
|
1778
2074
|
*/
|
|
1779
|
-
async
|
|
2075
|
+
async save(composerChatId, params, options) {
|
|
1780
2076
|
return this._post(
|
|
1781
|
-
`/
|
|
2077
|
+
`/composer/chat/${composerChatId}/save`,
|
|
1782
2078
|
params,
|
|
1783
2079
|
options
|
|
1784
2080
|
);
|
|
1785
2081
|
}
|
|
1786
2082
|
/**
|
|
1787
|
-
* POST /
|
|
2083
|
+
* POST /composer/chat/{composerChatId}/revert
|
|
1788
2084
|
*
|
|
1789
|
-
*
|
|
2085
|
+
* Reverts pending changes to the last snapshot. Without `workflowId` it
|
|
2086
|
+
* targets the focused workflow (400 if there is none, or if no snapshot
|
|
2087
|
+
* exists). Returns a `workflow_sync` payload.
|
|
1790
2088
|
*/
|
|
1791
|
-
async
|
|
1792
|
-
return this._post(
|
|
2089
|
+
async revert(composerChatId, params, options) {
|
|
2090
|
+
return this._post(
|
|
2091
|
+
`/composer/chat/${composerChatId}/revert`,
|
|
2092
|
+
params,
|
|
2093
|
+
options
|
|
2094
|
+
);
|
|
1793
2095
|
}
|
|
1794
2096
|
/**
|
|
1795
|
-
*
|
|
2097
|
+
* DELETE /composer/chat/{composerChatId}
|
|
1796
2098
|
*
|
|
1797
|
-
*
|
|
2099
|
+
* Deletes a Composer chat session. Pass `permanent: true` for a hard delete
|
|
2100
|
+
* (default is a soft delete). `permanent` is sent as a query parameter.
|
|
1798
2101
|
*/
|
|
1799
|
-
async
|
|
1800
|
-
return this.
|
|
2102
|
+
async delete(composerChatId, params, options) {
|
|
2103
|
+
return this._delete(
|
|
2104
|
+
`/composer/chat/${composerChatId}`,
|
|
2105
|
+
void 0,
|
|
2106
|
+
{
|
|
2107
|
+
...options,
|
|
2108
|
+
params: { ...options?.params, permanent: params?.permanent }
|
|
2109
|
+
}
|
|
2110
|
+
);
|
|
1801
2111
|
}
|
|
1802
|
-
};
|
|
1803
|
-
|
|
1804
|
-
// src/resources/composer.ts
|
|
1805
|
-
var Composer = class extends BaseResource {
|
|
1806
2112
|
/**
|
|
1807
|
-
*
|
|
2113
|
+
* GET /composer/chat/{composerChatId}/status
|
|
1808
2114
|
*
|
|
1809
|
-
*
|
|
1810
|
-
*
|
|
2115
|
+
* Returns the real-time status of a Composer chat session, including HITL
|
|
2116
|
+
* pause state (`awaiting_input` / `pending_request_id`).
|
|
1811
2117
|
*/
|
|
1812
|
-
async
|
|
1813
|
-
return this.
|
|
2118
|
+
async status(composerChatId, options) {
|
|
2119
|
+
return this._get(
|
|
2120
|
+
`/composer/chat/${composerChatId}/status`,
|
|
2121
|
+
options
|
|
2122
|
+
);
|
|
1814
2123
|
}
|
|
1815
2124
|
/**
|
|
1816
|
-
*
|
|
2125
|
+
* POST /composer/chat/{composerChatId}/cancel
|
|
1817
2126
|
*
|
|
1818
|
-
*
|
|
2127
|
+
* Cancels the in-progress run for a Composer chat session.
|
|
2128
|
+
*
|
|
2129
|
+
* Throws `NotFoundError` on HTTP 404 — the chat does not exist OR is not owned
|
|
2130
|
+
* by your organization (ownership failures return an identical 404, not 403,
|
|
2131
|
+
* so there is no existence leak).
|
|
1819
2132
|
*/
|
|
1820
|
-
async
|
|
1821
|
-
return this.
|
|
1822
|
-
`/composer/chat/${composerChatId}`,
|
|
2133
|
+
async cancel(composerChatId, options) {
|
|
2134
|
+
return this._post(
|
|
2135
|
+
`/composer/chat/${composerChatId}/cancel`,
|
|
2136
|
+
void 0,
|
|
1823
2137
|
options
|
|
1824
2138
|
);
|
|
1825
2139
|
}
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
// src/resources/assistant.ts
|
|
2143
|
+
var Assistant = class extends BaseResource {
|
|
1826
2144
|
/**
|
|
1827
|
-
*
|
|
2145
|
+
* POST /assistant/chat
|
|
2146
|
+
*
|
|
2147
|
+
* Starts a new Assistant chat or sends a message to an existing one. Returns
|
|
2148
|
+
* a run ID to listen on.
|
|
1828
2149
|
*
|
|
1829
|
-
*
|
|
2150
|
+
* Errors: 409 if the chat has a pending HITL question or a run is already in
|
|
2151
|
+
* progress (answer via `resume()` / `cancel()` first); 402/403/429 at the
|
|
2152
|
+
* billing gate.
|
|
1830
2153
|
*/
|
|
1831
|
-
|
|
1832
|
-
return this.
|
|
1833
|
-
`/composer/chat/${composerChatId}/listen/${runId}`,
|
|
1834
|
-
options
|
|
1835
|
-
);
|
|
2154
|
+
async chat(params, options) {
|
|
2155
|
+
return this._post("/assistant/chat", params, options);
|
|
1836
2156
|
}
|
|
1837
2157
|
/**
|
|
1838
|
-
*
|
|
2158
|
+
* GET /assistant/chats
|
|
1839
2159
|
*
|
|
1840
|
-
*
|
|
2160
|
+
* Lists the current user's Assistant chats, newest first, with cursor
|
|
2161
|
+
* pagination (`next_cursor` is an ISO `updated_at` timestamp).
|
|
1841
2162
|
*/
|
|
1842
|
-
async
|
|
1843
|
-
return this.
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
2163
|
+
async list(params, options) {
|
|
2164
|
+
return this._get("/assistant/chats", {
|
|
2165
|
+
...options,
|
|
2166
|
+
params: {
|
|
2167
|
+
...options?.params,
|
|
2168
|
+
limit: params?.limit,
|
|
2169
|
+
cursor: params?.cursor
|
|
2170
|
+
}
|
|
2171
|
+
});
|
|
1848
2172
|
}
|
|
1849
2173
|
/**
|
|
1850
|
-
*
|
|
2174
|
+
* GET /assistant/chat/{chatId}
|
|
1851
2175
|
*
|
|
1852
|
-
*
|
|
2176
|
+
* Returns an Assistant chat with its messages and any open HITL question
|
|
2177
|
+
* (`pending_user_input_request`).
|
|
1853
2178
|
*/
|
|
1854
|
-
async
|
|
1855
|
-
return this.
|
|
1856
|
-
`/composer/chat/${composerChatId}/revert`,
|
|
1857
|
-
void 0,
|
|
1858
|
-
options
|
|
1859
|
-
);
|
|
2179
|
+
async get(chatId, options) {
|
|
2180
|
+
return this._get(`/assistant/chat/${chatId}`, options);
|
|
1860
2181
|
}
|
|
1861
2182
|
/**
|
|
1862
|
-
* GET /
|
|
2183
|
+
* GET /assistant/chat/{chatId}/listen/{runId} — SSE
|
|
2184
|
+
*
|
|
2185
|
+
* Opens a Server-Sent Events stream for real-time Assistant output. This is a
|
|
2186
|
+
* data-only stream: each yielded value is an {@link AssistantSSEEvent}
|
|
2187
|
+
* discriminated on `type`. A `user_input_request` frame signals a HITL pause —
|
|
2188
|
+
* answer it with `resume()`.
|
|
1863
2189
|
*
|
|
1864
|
-
*
|
|
2190
|
+
* A 404 on connect throws `NotFoundError` before any event is yielded — the
|
|
2191
|
+
* chat/run does not exist OR is not owned by your organization (ownership
|
|
2192
|
+
* failures return an identical 404, not 403). The stream does NOT
|
|
2193
|
+
* auto-reconnect on a 404.
|
|
1865
2194
|
*/
|
|
1866
|
-
async
|
|
1867
|
-
|
|
1868
|
-
`/
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
limit: params?.limit
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
);
|
|
2195
|
+
async *listen(chatId, runId, options) {
|
|
2196
|
+
for await (const frame of this.streamSSE(
|
|
2197
|
+
`/assistant/chat/${chatId}/listen/${runId}`,
|
|
2198
|
+
options
|
|
2199
|
+
)) {
|
|
2200
|
+
yield frame.data;
|
|
2201
|
+
}
|
|
1877
2202
|
}
|
|
1878
2203
|
/**
|
|
1879
|
-
*
|
|
2204
|
+
* POST /assistant/chat/{chatId}/resume
|
|
2205
|
+
*
|
|
2206
|
+
* Answers an open HITL question and resumes the paused run. Returns a NEW
|
|
2207
|
+
* `run_id` to listen on.
|
|
1880
2208
|
*
|
|
1881
|
-
*
|
|
1882
|
-
*
|
|
2209
|
+
* Errors: 404 (a `NotFoundError`) when the chat is not found OR is not owned by
|
|
2210
|
+
* your organization (ownership failures return an identical 404, not 403); 410
|
|
2211
|
+
* if the question was already answered or cancelled; 403 if the caller is not
|
|
2212
|
+
* the user who triggered it. `llm` is required (400 if omitted).
|
|
1883
2213
|
*/
|
|
1884
|
-
async
|
|
1885
|
-
return this.
|
|
1886
|
-
`/
|
|
2214
|
+
async resume(chatId, params, options) {
|
|
2215
|
+
return this._post(
|
|
2216
|
+
`/assistant/chat/${chatId}/resume`,
|
|
1887
2217
|
params,
|
|
1888
2218
|
options
|
|
1889
2219
|
);
|
|
1890
2220
|
}
|
|
1891
2221
|
/**
|
|
1892
|
-
* GET /
|
|
2222
|
+
* GET /assistant/chat/{chatId}/status
|
|
1893
2223
|
*
|
|
1894
|
-
* Returns
|
|
2224
|
+
* Returns real-time status including HITL pause state (`awaiting_input` /
|
|
2225
|
+
* `pending_request_id`).
|
|
1895
2226
|
*/
|
|
1896
|
-
async status(
|
|
1897
|
-
return this._get(
|
|
1898
|
-
`/composer/chat/${composerChatId}/status`,
|
|
1899
|
-
options
|
|
1900
|
-
);
|
|
2227
|
+
async status(chatId, options) {
|
|
2228
|
+
return this._get(`/assistant/chat/${chatId}/status`, options);
|
|
1901
2229
|
}
|
|
1902
2230
|
/**
|
|
1903
|
-
* POST /
|
|
2231
|
+
* POST /assistant/chat/{chatId}/cancel
|
|
1904
2232
|
*
|
|
1905
|
-
* Cancels the in-progress run
|
|
2233
|
+
* Cancels the in-progress run and clears any pending HITL question. The
|
|
2234
|
+
* returned `run_id` is the run that was cancelled. Errors: 404 (a
|
|
2235
|
+
* `NotFoundError`) when the chat is not found OR is not owned by your
|
|
2236
|
+
* organization (ownership failures return an identical 404, not 403); 400 if
|
|
2237
|
+
* there is no active execution.
|
|
1906
2238
|
*/
|
|
1907
|
-
async cancel(
|
|
2239
|
+
async cancel(chatId, options) {
|
|
1908
2240
|
return this._post(
|
|
1909
|
-
`/
|
|
2241
|
+
`/assistant/chat/${chatId}/cancel`,
|
|
1910
2242
|
void 0,
|
|
1911
2243
|
options
|
|
1912
2244
|
);
|
|
1913
2245
|
}
|
|
2246
|
+
/**
|
|
2247
|
+
* DELETE /assistant/chat/{chatId}
|
|
2248
|
+
*
|
|
2249
|
+
* Deletes an Assistant chat. Pass `permanent: true` for a hard delete
|
|
2250
|
+
* (default is a soft delete).
|
|
2251
|
+
*/
|
|
2252
|
+
async delete(chatId, params, options) {
|
|
2253
|
+
return this._delete(`/assistant/chat/${chatId}`, void 0, {
|
|
2254
|
+
...options,
|
|
2255
|
+
params: {
|
|
2256
|
+
...options?.params,
|
|
2257
|
+
permanent: params?.permanent
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
1914
2261
|
};
|
|
1915
2262
|
|
|
1916
2263
|
// src/resources/dashboard.ts
|
|
@@ -2002,54 +2349,6 @@ var Dashboard = class extends BaseResource {
|
|
|
2002
2349
|
}
|
|
2003
2350
|
};
|
|
2004
2351
|
|
|
2005
|
-
// src/resources/subscriptions.ts
|
|
2006
|
-
var Subscriptions = class extends BaseResource {
|
|
2007
|
-
/**
|
|
2008
|
-
* GET /subscriptions/organization-plans
|
|
2009
|
-
*
|
|
2010
|
-
* Returns the list of available organization subscription plans.
|
|
2011
|
-
*/
|
|
2012
|
-
async organizationPlans(options) {
|
|
2013
|
-
return this._get(
|
|
2014
|
-
"/subscriptions/organization-plans",
|
|
2015
|
-
options
|
|
2016
|
-
);
|
|
2017
|
-
}
|
|
2018
|
-
/**
|
|
2019
|
-
* GET /subscriptions/organization-billing
|
|
2020
|
-
*
|
|
2021
|
-
* Returns the current organization's billing status and active subscription.
|
|
2022
|
-
*/
|
|
2023
|
-
async billing(options) {
|
|
2024
|
-
return this._get("/subscriptions/organization-billing", options);
|
|
2025
|
-
}
|
|
2026
|
-
/**
|
|
2027
|
-
* POST /subscriptions/checkout-link
|
|
2028
|
-
*
|
|
2029
|
-
* Creates a Stripe Checkout session and returns the redirect URL.
|
|
2030
|
-
*/
|
|
2031
|
-
async checkoutLink(params, options) {
|
|
2032
|
-
return this._post(
|
|
2033
|
-
"/subscriptions/checkout-link",
|
|
2034
|
-
params,
|
|
2035
|
-
options
|
|
2036
|
-
);
|
|
2037
|
-
}
|
|
2038
|
-
/**
|
|
2039
|
-
* POST /subscriptions/customer-portal
|
|
2040
|
-
*
|
|
2041
|
-
* Creates a Stripe Customer Portal session and returns the redirect URL
|
|
2042
|
-
* for the user to manage their billing.
|
|
2043
|
-
*/
|
|
2044
|
-
async customerPortal(options) {
|
|
2045
|
-
return this._post(
|
|
2046
|
-
"/subscriptions/customer-portal",
|
|
2047
|
-
void 0,
|
|
2048
|
-
options
|
|
2049
|
-
);
|
|
2050
|
-
}
|
|
2051
|
-
};
|
|
2052
|
-
|
|
2053
2352
|
// src/resources/notifications.ts
|
|
2054
2353
|
var Notifications = class extends BaseResource {
|
|
2055
2354
|
/**
|
|
@@ -2064,6 +2363,14 @@ var Notifications = class extends BaseResource {
|
|
|
2064
2363
|
* POST /notifications/organization
|
|
2065
2364
|
*
|
|
2066
2365
|
* Creates a new notification for the organization or a specific user.
|
|
2366
|
+
*
|
|
2367
|
+
* Requires an organization context: an `X-Organization-ID` header is sent
|
|
2368
|
+
* automatically from the client's configured `organizationId` or from
|
|
2369
|
+
* `options.organizationId`. If neither is set, no header is sent and the
|
|
2370
|
+
* backend responds with HTTP 400 ("X-Organization-ID header is required").
|
|
2371
|
+
*
|
|
2372
|
+
* @returns The created notification wrapped in a `{ success, notification }`
|
|
2373
|
+
* envelope.
|
|
2067
2374
|
*/
|
|
2068
2375
|
async create(params, options) {
|
|
2069
2376
|
return this._post(
|
|
@@ -2076,44 +2383,10 @@ var Notifications = class extends BaseResource {
|
|
|
2076
2383
|
|
|
2077
2384
|
// src/resources/system.ts
|
|
2078
2385
|
var System = class extends BaseResource {
|
|
2079
|
-
/**
|
|
2080
|
-
* GET /system/health
|
|
2081
|
-
*
|
|
2082
|
-
* Returns the service health status, name, and version.
|
|
2083
|
-
*/
|
|
2084
|
-
async health(options) {
|
|
2085
|
-
return this._get(
|
|
2086
|
-
"/system/health",
|
|
2087
|
-
options
|
|
2088
|
-
);
|
|
2089
|
-
}
|
|
2090
|
-
/**
|
|
2091
|
-
* GET /system/metrics
|
|
2092
|
-
*
|
|
2093
|
-
* Returns Prometheus-format metrics as plain text.
|
|
2094
|
-
* This endpoint bypasses the JSON-parsing logic of `BaseResource.get()` and
|
|
2095
|
-
* reads the raw response body as a string.
|
|
2096
|
-
*/
|
|
2097
|
-
async metrics(options) {
|
|
2098
|
-
const orgId = options?.organizationId ?? this._config.organizationId;
|
|
2099
|
-
const url = `${this._config.baseUrl}/system/metrics`;
|
|
2100
|
-
const headers = {
|
|
2101
|
-
"Authorization": `Bearer ${this._config.apiKey}`
|
|
2102
|
-
};
|
|
2103
|
-
if (orgId) {
|
|
2104
|
-
headers["X-Organization-ID"] = orgId;
|
|
2105
|
-
}
|
|
2106
|
-
const response = await this._config.fetch(url, {
|
|
2107
|
-
method: "GET",
|
|
2108
|
-
headers,
|
|
2109
|
-
signal: options?.signal
|
|
2110
|
-
});
|
|
2111
|
-
return response.text();
|
|
2112
|
-
}
|
|
2113
2386
|
/**
|
|
2114
2387
|
* GET /system/timezones
|
|
2115
2388
|
*
|
|
2116
|
-
* Returns the list of
|
|
2389
|
+
* Returns popular timezone groups plus the full list of IANA identifiers.
|
|
2117
2390
|
*/
|
|
2118
2391
|
async timezones(options) {
|
|
2119
2392
|
return this._get("/system/timezones", options);
|
|
@@ -2121,7 +2394,8 @@ var System = class extends BaseResource {
|
|
|
2121
2394
|
/**
|
|
2122
2395
|
* GET /system/timezones/search
|
|
2123
2396
|
*
|
|
2124
|
-
* Searches supported IANA
|
|
2397
|
+
* Searches supported IANA timezones by query string. `query` must be at least
|
|
2398
|
+
* 2 characters (the backend returns 422 otherwise). Returns at most 20 results.
|
|
2125
2399
|
*/
|
|
2126
2400
|
async searchTimezones(query, options) {
|
|
2127
2401
|
return this._get("/system/timezones/search", {
|
|
@@ -2152,10 +2426,14 @@ var Modulex = class {
|
|
|
2152
2426
|
get workflows() {
|
|
2153
2427
|
return this._workflows ?? (this._workflows = new Workflows(this._config));
|
|
2154
2428
|
}
|
|
2155
|
-
/** Workflow execution endpoints (run, resume, cancel, listen). */
|
|
2429
|
+
/** Workflow execution-control endpoints (run, resume, cancel, listen). */
|
|
2156
2430
|
get executions() {
|
|
2157
2431
|
return this._executions ?? (this._executions = new Executions(this._config));
|
|
2158
2432
|
}
|
|
2433
|
+
/** Durable workflow run-history endpoints (list, get persisted runs). */
|
|
2434
|
+
get workflowRuns() {
|
|
2435
|
+
return this._workflowRuns ?? (this._workflowRuns = new WorkflowRuns(this._config));
|
|
2436
|
+
}
|
|
2159
2437
|
/** Workflow deployment endpoints. */
|
|
2160
2438
|
get deployments() {
|
|
2161
2439
|
return this._deployments ?? (this._deployments = new Deployments(this._config));
|
|
@@ -2180,22 +2458,18 @@ var Modulex = class {
|
|
|
2180
2458
|
get schedules() {
|
|
2181
2459
|
return this._schedules ?? (this._schedules = new Schedules(this._config));
|
|
2182
2460
|
}
|
|
2183
|
-
/** Template endpoints. */
|
|
2184
|
-
get templates() {
|
|
2185
|
-
return this._templates ?? (this._templates = new Templates(this._config));
|
|
2186
|
-
}
|
|
2187
2461
|
/** Composer (AI workflow builder) endpoints. */
|
|
2188
2462
|
get composer() {
|
|
2189
2463
|
return this._composer ?? (this._composer = new Composer(this._config));
|
|
2190
2464
|
}
|
|
2465
|
+
/** Assistant (HITL chat agent) endpoints. */
|
|
2466
|
+
get assistant() {
|
|
2467
|
+
return this._assistant ?? (this._assistant = new Assistant(this._config));
|
|
2468
|
+
}
|
|
2191
2469
|
/** Dashboard and analytics endpoints. */
|
|
2192
2470
|
get dashboard() {
|
|
2193
2471
|
return this._dashboard ?? (this._dashboard = new Dashboard(this._config));
|
|
2194
2472
|
}
|
|
2195
|
-
/** Subscription and billing endpoints. */
|
|
2196
|
-
get subscriptions() {
|
|
2197
|
-
return this._subscriptions ?? (this._subscriptions = new Subscriptions(this._config));
|
|
2198
|
-
}
|
|
2199
2473
|
/** Notification endpoints. */
|
|
2200
2474
|
get notifications() {
|
|
2201
2475
|
return this._notifications ?? (this._notifications = new Notifications(this._config));
|