@getmodus/sdk 0.6.0 → 0.8.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.
@@ -201,6 +201,7 @@ function createModusConfig(options = {}) {
201
201
  }),
202
202
  timeoutMs: resolveTimeoutMs(options.timeoutMs) ?? DEFAULT_TIMEOUT_MS,
203
203
  maxRetries,
204
+ defaultHeaders: Object.freeze({ ...options.defaultHeaders }),
204
205
  fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
205
206
  });
206
207
  }
@@ -216,7 +217,7 @@ function formatConfigForLog(config) {
216
217
  }
217
218
 
218
219
  // src/_http.ts
219
- var USER_AGENT = `modus-typescript/${"0.6.0"} (node/${process.version}; ${process.platform})`;
220
+ var USER_AGENT = `modus-typescript/${"0.8.0"} (node/${process.version}; ${process.platform})`;
220
221
  function buildUrl(baseUrl, path, params) {
221
222
  const url = new URL(path.startsWith("/") ? path : `/${path}`, baseUrl);
222
223
  if (params) {
@@ -231,6 +232,15 @@ function buildUrl(baseUrl, path, params) {
231
232
  }
232
233
  return url.toString();
233
234
  }
235
+ function mergeHeaders(...layers) {
236
+ const merged = /* @__PURE__ */ new Map();
237
+ for (const layer of layers) {
238
+ for (const [name, value] of Object.entries(layer ?? {})) {
239
+ merged.set(name.toLowerCase(), [name, value]);
240
+ }
241
+ }
242
+ return Object.fromEntries(merged.values());
243
+ }
234
244
  function headersToRecord(headers) {
235
245
  const out = {};
236
246
  headers.forEach((value, key) => {
@@ -336,12 +346,15 @@ var HttpClient = class {
336
346
  this.config = config;
337
347
  }
338
348
  defaultHeaders() {
339
- return {
340
- ...authHeaders(this.config.apiKey),
341
- Accept: "application/json",
342
- "Content-Type": "application/json",
343
- "User-Agent": USER_AGENT
344
- };
349
+ return mergeHeaders(
350
+ {
351
+ Accept: "application/json",
352
+ "Content-Type": "application/json",
353
+ "User-Agent": USER_AGENT,
354
+ "X-Modus-Client": "sdk"
355
+ },
356
+ this.config.defaultHeaders
357
+ );
345
358
  }
346
359
  async request(method, path, options = {}) {
347
360
  const baseUrl = options.baseUrl ?? this.config.baseUrl;
@@ -349,7 +362,7 @@ var HttpClient = class {
349
362
  try {
350
363
  const response = await this.config.fetch(url, {
351
364
  method,
352
- headers: { ...this.defaultHeaders(), ...options.headers },
365
+ headers: mergeHeaders(this.defaultHeaders(), options.headers, authHeaders(this.config.apiKey)),
353
366
  body: options.json !== void 0 ? JSON.stringify(options.json) : void 0,
354
367
  signal: AbortSignal.timeout(this.config.timeoutMs)
355
368
  });
@@ -388,11 +401,12 @@ var HttpClient = class {
388
401
  method,
389
402
  // Agent-service negotiates SSE vs JSON polling on Accept; JSON-only
390
403
  // Accept returns {"runId","status":"pending"} instead of token SSE.
391
- headers: {
392
- ...this.defaultHeaders(),
393
- ...options.headers,
394
- Accept: "text/event-stream"
395
- },
404
+ headers: mergeHeaders(
405
+ this.defaultHeaders(),
406
+ options.headers,
407
+ { Accept: "text/event-stream" },
408
+ authHeaders(this.config.apiKey)
409
+ ),
396
410
  body: options.json !== void 0 ? JSON.stringify(options.json) : void 0,
397
411
  signal: AbortSignal.timeout(this.config.timeoutMs)
398
412
  });
@@ -592,6 +606,26 @@ var OPERATIONS = {
592
606
  requestSchema: "CreateSavedQueryDto",
593
607
  responseSchema: "CreatedContextItemResponseDto"
594
608
  },
609
+ "ContextFilesController_finalize": {
610
+ method: "POST",
611
+ path: "/api/v1/context/files/{uploadId}/finalize",
612
+ service: "modus-api",
613
+ serverUrl: "https://api.getmodus.com",
614
+ pathParams: ["uploadId"],
615
+ queryParams: [],
616
+ requestSchema: "FinalizeUploadDto",
617
+ responseSchema: "FileUploadResourceDto"
618
+ },
619
+ "ContextFilesController_finalizeMany": {
620
+ method: "POST",
621
+ path: "/api/v1/context/files/finalize",
622
+ service: "modus-api",
623
+ serverUrl: "https://api.getmodus.com",
624
+ pathParams: [],
625
+ queryParams: [],
626
+ requestSchema: "BulkFinalizeDto",
627
+ responseSchema: "BulkFinalizeResponseDto"
628
+ },
595
629
  "ContextFilesController_get": {
596
630
  method: "GET",
597
631
  path: "/api/v1/context/files/{uploadId}",
@@ -678,7 +712,7 @@ var OPERATIONS = {
678
712
  service: "modus-api",
679
713
  serverUrl: "https://api.getmodus.com",
680
714
  pathParams: [],
681
- queryParams: ["pageToken", "pageSize", "contextTypes", "verificationStatuses", "searchQuery", "topics"],
715
+ queryParams: ["pageToken", "pageSize", "contextTypes", "verificationStatuses", "searchQuery", "topics", "connectionIds", "parentUids", "ancestorUids"],
682
716
  requestSchema: null,
683
717
  responseSchema: "ListContextItemsResponseDto"
684
718
  },
@@ -702,6 +736,16 @@ var OPERATIONS = {
702
736
  requestSchema: "LookupContextItemDto",
703
737
  responseSchema: "LookupContextItemResponseDto"
704
738
  },
739
+ "ContextItemsController_move": {
740
+ method: "POST",
741
+ path: "/api/v1/context/items/{uid}/move",
742
+ service: "modus-api",
743
+ serverUrl: "https://api.getmodus.com",
744
+ pathParams: ["uid"],
745
+ queryParams: [],
746
+ requestSchema: "MoveContextItemDto",
747
+ responseSchema: "MoveContextItemResponseDto"
748
+ },
705
749
  "ContextItemsController_update": {
706
750
  method: "PATCH",
707
751
  path: "/api/v1/context/items/{uid}",
@@ -732,6 +776,16 @@ var OPERATIONS = {
732
776
  requestSchema: "CreateCustomContextItemDto",
733
777
  responseSchema: "CreatedCustomContextItemResponseDto"
734
778
  },
779
+ "CustomContextItemsController_createRelations": {
780
+ method: "POST",
781
+ path: "/api/v1/context/custom-items/relations",
782
+ service: "modus-api",
783
+ serverUrl: "https://api.getmodus.com",
784
+ pathParams: [],
785
+ queryParams: [],
786
+ requestSchema: "BatchCreateCustomContextItemRelationsDto",
787
+ responseSchema: "BatchCreateCustomContextItemRelationsResponseDto"
788
+ },
735
789
  "CustomContextItemsController_delete": {
736
790
  method: "DELETE",
737
791
  path: "/api/v1/context/custom-items/{uid}",
@@ -772,6 +826,196 @@ var OPERATIONS = {
772
826
  requestSchema: "UpdateCustomContextItemDto",
773
827
  responseSchema: null
774
828
  },
829
+ "DashboardsController_acceptOwnership": {
830
+ method: "POST",
831
+ path: "/api/v1/context/dashboards/{dashboardId}/transfer-ownership/accept",
832
+ service: "modus-api",
833
+ serverUrl: "https://api.getmodus.com",
834
+ pathParams: ["dashboardId"],
835
+ queryParams: [],
836
+ requestSchema: null,
837
+ responseSchema: "DashboardDto"
838
+ },
839
+ "DashboardsController_cancelOwnership": {
840
+ method: "DELETE",
841
+ path: "/api/v1/context/dashboards/{dashboardId}/transfer-ownership",
842
+ service: "modus-api",
843
+ serverUrl: "https://api.getmodus.com",
844
+ pathParams: ["dashboardId"],
845
+ queryParams: [],
846
+ requestSchema: null,
847
+ responseSchema: "DashboardDto"
848
+ },
849
+ "DashboardsController_create": {
850
+ method: "POST",
851
+ path: "/api/v1/context/dashboards",
852
+ service: "modus-api",
853
+ serverUrl: "https://api.getmodus.com",
854
+ pathParams: [],
855
+ queryParams: [],
856
+ requestSchema: "CreateDashboardDto",
857
+ responseSchema: "DashboardDto"
858
+ },
859
+ "DashboardsController_createElement": {
860
+ method: "POST",
861
+ path: "/api/v1/context/dashboards/{dashboardId}/elements",
862
+ service: "modus-api",
863
+ serverUrl: "https://api.getmodus.com",
864
+ pathParams: ["dashboardId"],
865
+ queryParams: [],
866
+ requestSchema: "CreateDashboardElementDto",
867
+ responseSchema: "DashboardElementResponseDto"
868
+ },
869
+ "DashboardsController_delete": {
870
+ method: "DELETE",
871
+ path: "/api/v1/context/dashboards/{dashboardId}",
872
+ service: "modus-api",
873
+ serverUrl: "https://api.getmodus.com",
874
+ pathParams: ["dashboardId"],
875
+ queryParams: [],
876
+ requestSchema: null,
877
+ responseSchema: null
878
+ },
879
+ "DashboardsController_get": {
880
+ method: "GET",
881
+ path: "/api/v1/context/dashboards/{dashboardId}",
882
+ service: "modus-api",
883
+ serverUrl: "https://api.getmodus.com",
884
+ pathParams: ["dashboardId"],
885
+ queryParams: ["view"],
886
+ requestSchema: null,
887
+ responseSchema: "DashboardDto"
888
+ },
889
+ "DashboardsController_getElement": {
890
+ method: "GET",
891
+ path: "/api/v1/context/dashboards/{dashboardId}/elements/{elementId}",
892
+ service: "modus-api",
893
+ serverUrl: "https://api.getmodus.com",
894
+ pathParams: ["dashboardId", "elementId"],
895
+ queryParams: [],
896
+ requestSchema: null,
897
+ responseSchema: "DashboardElementResponseDto"
898
+ },
899
+ "DashboardsController_getVersion": {
900
+ method: "GET",
901
+ path: "/api/v1/context/dashboards/{dashboardId}/versions/{versionId}",
902
+ service: "modus-api",
903
+ serverUrl: "https://api.getmodus.com",
904
+ pathParams: ["dashboardId", "versionId"],
905
+ queryParams: [],
906
+ requestSchema: null,
907
+ responseSchema: "DashboardDto"
908
+ },
909
+ "DashboardsController_list": {
910
+ method: "GET",
911
+ path: "/api/v1/context/dashboards",
912
+ service: "modus-api",
913
+ serverUrl: "https://api.getmodus.com",
914
+ pathParams: [],
915
+ queryParams: ["view"],
916
+ requestSchema: null,
917
+ responseSchema: "ListDashboardsResponseDto"
918
+ },
919
+ "DashboardsController_listDraftSnapshots": {
920
+ method: "GET",
921
+ path: "/api/v1/context/dashboards/{dashboardId}/draft-snapshots",
922
+ service: "modus-api",
923
+ serverUrl: "https://api.getmodus.com",
924
+ pathParams: ["dashboardId"],
925
+ queryParams: [],
926
+ requestSchema: null,
927
+ responseSchema: "ListDashboardDraftSnapshotsResponseDto"
928
+ },
929
+ "DashboardsController_listElements": {
930
+ method: "GET",
931
+ path: "/api/v1/context/dashboards/{dashboardId}/elements",
932
+ service: "modus-api",
933
+ serverUrl: "https://api.getmodus.com",
934
+ pathParams: ["dashboardId"],
935
+ queryParams: [],
936
+ requestSchema: null,
937
+ responseSchema: "DashboardElementsListResponseDto"
938
+ },
939
+ "DashboardsController_listVersions": {
940
+ method: "GET",
941
+ path: "/api/v1/context/dashboards/{dashboardId}/versions",
942
+ service: "modus-api",
943
+ serverUrl: "https://api.getmodus.com",
944
+ pathParams: ["dashboardId"],
945
+ queryParams: [],
946
+ requestSchema: null,
947
+ responseSchema: "ListDashboardVersionsResponseDto"
948
+ },
949
+ "DashboardsController_publish": {
950
+ method: "POST",
951
+ path: "/api/v1/context/dashboards/{dashboardId}/publish",
952
+ service: "modus-api",
953
+ serverUrl: "https://api.getmodus.com",
954
+ pathParams: ["dashboardId"],
955
+ queryParams: [],
956
+ requestSchema: "PublishDashboardDto",
957
+ responseSchema: "PublishDashboardResponseDto"
958
+ },
959
+ "DashboardsController_restore": {
960
+ method: "POST",
961
+ path: "/api/v1/context/dashboards/{dashboardId}/versions/{versionId}/restore",
962
+ service: "modus-api",
963
+ serverUrl: "https://api.getmodus.com",
964
+ pathParams: ["dashboardId", "versionId"],
965
+ queryParams: [],
966
+ requestSchema: null,
967
+ responseSchema: "DashboardDto"
968
+ },
969
+ "DashboardsController_transferOwnership": {
970
+ method: "POST",
971
+ path: "/api/v1/context/dashboards/{dashboardId}/transfer-ownership",
972
+ service: "modus-api",
973
+ serverUrl: "https://api.getmodus.com",
974
+ pathParams: ["dashboardId"],
975
+ queryParams: [],
976
+ requestSchema: "TransferDashboardOwnershipDto",
977
+ responseSchema: "DashboardDto"
978
+ },
979
+ "DashboardsController_updateAccess": {
980
+ method: "PATCH",
981
+ path: "/api/v1/context/dashboards/{dashboardId}/access",
982
+ service: "modus-api",
983
+ serverUrl: "https://api.getmodus.com",
984
+ pathParams: ["dashboardId"],
985
+ queryParams: [],
986
+ requestSchema: "UpdateDashboardAccessDto",
987
+ responseSchema: "DashboardDto"
988
+ },
989
+ "DashboardsController_updateDraft": {
990
+ method: "PATCH",
991
+ path: "/api/v1/context/dashboards/{dashboardId}/draft",
992
+ service: "modus-api",
993
+ serverUrl: "https://api.getmodus.com",
994
+ pathParams: ["dashboardId"],
995
+ queryParams: [],
996
+ requestSchema: "UpdateDashboardDraftDto",
997
+ responseSchema: "DashboardDto"
998
+ },
999
+ "DashboardsController_updateElement": {
1000
+ method: "PATCH",
1001
+ path: "/api/v1/context/dashboards/{dashboardId}/elements/{elementId}",
1002
+ service: "modus-api",
1003
+ serverUrl: "https://api.getmodus.com",
1004
+ pathParams: ["dashboardId", "elementId"],
1005
+ queryParams: [],
1006
+ requestSchema: "UpdateDashboardElementDto",
1007
+ responseSchema: "DashboardDto"
1008
+ },
1009
+ "DashboardsController_updateLayout": {
1010
+ method: "PATCH",
1011
+ path: "/api/v1/context/dashboards/{dashboardId}/layout",
1012
+ service: "modus-api",
1013
+ serverUrl: "https://api.getmodus.com",
1014
+ pathParams: ["dashboardId"],
1015
+ queryParams: [],
1016
+ requestSchema: "UpdateDashboardLayoutDto",
1017
+ responseSchema: "DashboardDto"
1018
+ },
775
1019
  "EvaluationsController_getConfig": {
776
1020
  method: "GET",
777
1021
  path: "/api/v1/scopes/{id}/evaluations/config",
@@ -822,6 +1066,16 @@ var OPERATIONS = {
822
1066
  requestSchema: "UpdateEvaluationConfigDto",
823
1067
  responseSchema: "EvaluationConfigDto"
824
1068
  },
1069
+ "IngestedDataController_upload": {
1070
+ method: "POST",
1071
+ path: "/api/v1/ingested-data",
1072
+ service: "modus-api",
1073
+ serverUrl: "https://api.getmodus.com",
1074
+ pathParams: [],
1075
+ queryParams: [],
1076
+ requestSchema: "CreateIngestedDataDto",
1077
+ responseSchema: "CreatedIngestedDataResponseDto"
1078
+ },
825
1079
  "MemberGroupsController_list": {
826
1080
  method: "GET",
827
1081
  path: "/api/v1/users/member-groups",
@@ -878,7 +1132,7 @@ var OPERATIONS = {
878
1132
  service: "modus-api",
879
1133
  serverUrl: "https://api.getmodus.com",
880
1134
  pathParams: [],
881
- queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "timeframe", "includeTools", "kind"],
1135
+ queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "sourceRef", "timeframe", "includeTools", "kind"],
882
1136
  requestSchema: null,
883
1137
  responseSchema: "ListConversationsResponseDto"
884
1138
  },
@@ -1028,10 +1282,50 @@ var OPERATIONS = {
1028
1282
  service: "modus-api",
1029
1283
  serverUrl: "https://api.getmodus.com",
1030
1284
  pathParams: ["id"],
1031
- queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "timeframe", "includeTools"],
1285
+ queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "sourceRef", "timeframe", "includeTools"],
1032
1286
  requestSchema: null,
1033
1287
  responseSchema: "ListConversationsResponseDto"
1034
1288
  },
1289
+ "ScopeInterfacesController_add": {
1290
+ method: "POST",
1291
+ path: "/api/v1/scopes/{id}/interfaces",
1292
+ service: "modus-api",
1293
+ serverUrl: "https://api.getmodus.com",
1294
+ pathParams: ["id"],
1295
+ queryParams: [],
1296
+ requestSchema: "AddScopeInterfaceDto",
1297
+ responseSchema: "ScopeInterfaceDto"
1298
+ },
1299
+ "ScopeInterfacesController_delete": {
1300
+ method: "DELETE",
1301
+ path: "/api/v1/scopes/{id}/interfaces/{interfaceId}",
1302
+ service: "modus-api",
1303
+ serverUrl: "https://api.getmodus.com",
1304
+ pathParams: ["id", "interfaceId"],
1305
+ queryParams: [],
1306
+ requestSchema: null,
1307
+ responseSchema: null
1308
+ },
1309
+ "ScopeInterfacesController_list": {
1310
+ method: "GET",
1311
+ path: "/api/v1/scopes/{id}/interfaces",
1312
+ service: "modus-api",
1313
+ serverUrl: "https://api.getmodus.com",
1314
+ pathParams: ["id"],
1315
+ queryParams: [],
1316
+ requestSchema: null,
1317
+ responseSchema: "ListScopeInterfacesResponseDto"
1318
+ },
1319
+ "ScopeInterfacesController_update": {
1320
+ method: "PATCH",
1321
+ path: "/api/v1/scopes/{id}/interfaces/{interfaceId}",
1322
+ service: "modus-api",
1323
+ serverUrl: "https://api.getmodus.com",
1324
+ pathParams: ["id", "interfaceId"],
1325
+ queryParams: ["updateMask"],
1326
+ requestSchema: "UpdateScopeInterfaceDto",
1327
+ responseSchema: "ScopeInterfaceDto"
1328
+ },
1035
1329
  "ScopeMemoriesController_delete": {
1036
1330
  method: "DELETE",
1037
1331
  path: "/api/v1/scopes/{id}/memories/{memoryId}",
@@ -1581,16 +1875,29 @@ var WRITE_BODY_ALLOWED_KEYS = {
1581
1875
  ContextCreatorsController_createLink: ["url", "title", "isCrawl", "pageLimit"],
1582
1876
  ContextCreatorsController_createNote: ["title", "content"],
1583
1877
  ContextCreatorsController_createSavedQuery: ["name", "connectionId", "query", "description", "path"],
1584
- ContextFilesController_uploadFromUrl: ["url", "fileName"],
1878
+ ContextFilesController_finalize: ["fileName", "folderPath"],
1879
+ ContextFilesController_finalizeMany: ["uploads"],
1880
+ ContextFilesController_uploadFromUrl: ["url", "fileName", "folderPath"],
1585
1881
  ContextFilesController_uploadFromUrls: ["urls"],
1586
1882
  ContextFilesController_uploadUrl: ["fileName", "contentType", "fileSize"],
1587
1883
  ContextFilesController_uploadUrls: ["files"],
1588
1884
  ContextItemsController_lookup: ["contextType", "dataPath", "contentProjection"],
1885
+ ContextItemsController_move: ["destinationFolderUid"],
1589
1886
  ContextItemsController_update: ["contextType", "content", "description", "userFeedback", "topics"],
1590
1887
  CustomContextItemsController_batchCreate: ["items"],
1591
1888
  CustomContextItemsController_create: ["kind", "sourceId", "sourceName", "collectionId", "collectionName", "externalId", "fieldName", "name", "entityType", "description", "content", "url", "attributes", "dataType", "value", "samples", "raw", "topics", "idempotencyKey", "access"],
1889
+ CustomContextItemsController_createRelations: ["relations"],
1592
1890
  CustomContextItemsController_update: ["name", "entityType", "description", "content", "url", "attributes", "dataType", "value", "samples", "raw", "topics"],
1891
+ DashboardsController_create: ["title", "description", "definition", "access"],
1892
+ DashboardsController_createElement: ["expectedRevision", "kind", "title", "layout"],
1893
+ DashboardsController_publish: ["expectedRevision"],
1894
+ DashboardsController_transferOwnership: ["newOwnerUserId"],
1895
+ DashboardsController_updateAccess: ["visibility", "groupPermissions", "sharedWith"],
1896
+ DashboardsController_updateDraft: ["expectedRevision", "title", "description", "definition"],
1897
+ DashboardsController_updateElement: ["expectedRevision", "patch"],
1898
+ DashboardsController_updateLayout: ["expectedRevision", "elements"],
1593
1899
  EvaluationsController_updateConfig: ["enabled", "cadence", "judgeModel", "judgeGuidance", "notifications"],
1900
+ IngestedDataController_upload: ["integration_type", "request", "response"],
1594
1901
  ModusChatController_chat: ["message", "model"],
1595
1902
  ModusContextController_compose: ["message", "limit"],
1596
1903
  ModusRunsController_create: ["message", "sessionId", "organizationId", "version", "fileThreadId", "config", "attachments", "userContext", "source", "runId", "subordinateSkillIds"],
@@ -1601,11 +1908,13 @@ var WRITE_BODY_ALLOWED_KEYS = {
1601
1908
  RunLifecycleController_interrupt: [],
1602
1909
  ScopeChatController_chat: ["message", "model"],
1603
1910
  ScopeContextController_compose: ["message", "limit"],
1911
+ ScopeInterfacesController_add: ["type", "name", "config"],
1912
+ ScopeInterfacesController_update: ["name", "config"],
1604
1913
  ScopeMemoriesController_search: ["query", "userId", "limit"],
1605
1914
  ScopeMemoriesController_update: ["memory", "metadata"],
1606
1915
  ScopeRunsController_create: ["message", "sessionId", "organizationId", "version", "fileThreadId", "config", "attachments", "userContext", "source", "runId", "subordinateSkillIds"],
1607
1916
  ScopesController_acceptOwnershipTransfer: [],
1608
- ScopesController_create: ["name", "description", "expectedOutput", "instructions", "toolset", "model", "connectionSet", "contextSelections", "interfaces", "accessConfig"],
1917
+ ScopesController_create: ["name", "description", "expectedOutput", "instructions", "toolset", "model", "connectionSet", "contextSelections", "includeOwnLearnings", "interfaces", "accessConfig"],
1609
1918
  ScopesController_deploy: [],
1610
1919
  ScopesController_patchMcpConfig: ["config"],
1611
1920
  ScopesController_requestOwnershipTransfer: ["newOwnerUserId"],
@@ -1819,6 +2128,13 @@ var ManagementWorkflowsResource = class {
1819
2128
  * @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
1820
2129
  * @param options.includeVariation - Include variation payload on each list row.
1821
2130
  * @returns A page of workflows.
2131
+ * @example
2132
+ * ```ts
2133
+ * const mgmt = new ModusManagement()
2134
+ * for await (const wf of (await mgmt.workflows.list({ search: 'digest' })).autoPagingIter()) {
2135
+ * console.log(wf.id, wf.name, wf.status)
2136
+ * }
2137
+ * ```
1822
2138
  */
1823
2139
  list(options = {}) {
1824
2140
  const pageSize = options.pageSize ?? 25;
@@ -1851,6 +2167,12 @@ var ManagementWorkflowsResource = class {
1851
2167
  * @param workflowId - Workflow id.
1852
2168
  * @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
1853
2169
  * @returns The workflow.
2170
+ * @example
2171
+ * ```ts
2172
+ * const mgmt = new ModusManagement()
2173
+ * const wf = await mgmt.workflows.get('weekly-digest')
2174
+ * console.log(wf.name, wf.status)
2175
+ * ```
1854
2176
  */
1855
2177
  async get(workflowId, options = {}) {
1856
2178
  validateId(workflowId, "workflow_id");
@@ -1880,7 +2202,8 @@ var ManagementWorkflowsResource = class {
1880
2202
  * @returns The created workflow (draft).
1881
2203
  * @example
1882
2204
  * ```ts
1883
- * const wf = await mgmt.workflows.create({ name: 'Daily report', type: WorkflowType.Task })
2205
+ * const mgmt = new ModusManagement()
2206
+ * const wf = await mgmt.workflows.create({ name: 'Daily report', type: 'task' })
1884
2207
  * ```
1885
2208
  */
1886
2209
  async create(options) {
@@ -1908,6 +2231,11 @@ var ManagementWorkflowsResource = class {
1908
2231
  * @param options.guardrails - Guardrail labels to set. Fetches the current workflow first to merge. Pass `[]` to clear all.
1909
2232
  * @param options.updateMask - Comma-separated field names to update or clear.
1910
2233
  * @returns The updated workflow.
2234
+ * @example
2235
+ * ```ts
2236
+ * const mgmt = new ModusManagement()
2237
+ * const wf = await mgmt.workflows.update('PLACEHOLDER_WORKFLOW_ID', { description: 'Runs every morning' })
2238
+ * ```
1911
2239
  */
1912
2240
  async update(workflowId, options = {}) {
1913
2241
  validateId(workflowId, "workflow_id");
@@ -1943,8 +2271,9 @@ var ManagementWorkflowsResource = class {
1943
2271
  * @returns The published workflow.
1944
2272
  * @example
1945
2273
  * ```ts
1946
- * await mgmt.workflows.update(workflowId, { description: 'Runs every morning' })
1947
- * const published = await mgmt.workflows.deploy(workflowId)
2274
+ * const mgmt = new ModusManagement()
2275
+ * await mgmt.workflows.update('PLACEHOLDER_WORKFLOW_ID', { description: 'Runs every morning' })
2276
+ * const published = await mgmt.workflows.deploy('PLACEHOLDER_WORKFLOW_ID')
1948
2277
  * ```
1949
2278
  */
1950
2279
  async deploy(workflowId) {
@@ -1977,6 +2306,11 @@ var ManagementWorkflowsResource = class {
1977
2306
  *
1978
2307
  * @param workflowId - Workflow id.
1979
2308
  * @returns Resolves when the workflow is deleted.
2309
+ * @example
2310
+ * ```ts
2311
+ * const mgmt = new ModusManagement()
2312
+ * await mgmt.workflows.delete('PLACEHOLDER_WORKFLOW_ID')
2313
+ * ```
1980
2314
  */
1981
2315
  async delete(workflowId) {
1982
2316
  validateId(workflowId, "workflow_id");
@@ -2082,6 +2416,12 @@ var CustomContextItemsResource = class {
2082
2416
  * @param options.searchQuery - Free-text search filter.
2083
2417
  * @param options.topics - Filter to items tagged with any of these topics.
2084
2418
  * @returns A page of custom context items.
2419
+ * @example
2420
+ * ```ts
2421
+ * const client = new Modus()
2422
+ * const page = await client.context.customItems.list({ pageSize: 25 })
2423
+ * for (const item of page.items) console.log(item.uid, item.contextType)
2424
+ * ```
2085
2425
  */
2086
2426
  list(options = {}) {
2087
2427
  const pageSize = options.pageSize ?? 25;
@@ -2110,6 +2450,11 @@ var CustomContextItemsResource = class {
2110
2450
  * @param uid - Item uid.
2111
2451
  * @returns The custom context item.
2112
2452
  * @throws {NotFoundError} When no item matches the uid.
2453
+ * @example
2454
+ * ```ts
2455
+ * const client = new Modus()
2456
+ * const item = await client.context.customItems.get('PLACEHOLDER_UID')
2457
+ * ```
2113
2458
  */
2114
2459
  async get(uid) {
2115
2460
  return parseContextItem(
@@ -2130,6 +2475,7 @@ var CustomContextItemsResource = class {
2130
2475
  *
2131
2476
  * @example
2132
2477
  * ```ts
2478
+ * const client = new Modus()
2133
2479
  * const created = await client.context.customItems.create({
2134
2480
  * kind: 'entity',
2135
2481
  * sourceId: 'my-source',
@@ -2153,6 +2499,7 @@ var CustomContextItemsResource = class {
2153
2499
  *
2154
2500
  * @example
2155
2501
  * ```ts
2502
+ * const client = new Modus()
2156
2503
  * const created = await client.context.customItems.batchCreate([
2157
2504
  * { kind: 'field', sourceId: 'src', fieldName: 'region', dataType: 'string' },
2158
2505
  * { kind: 'field', sourceId: 'src', fieldName: 'amount', dataType: 'number' },
@@ -2170,12 +2517,45 @@ var CustomContextItemsResource = class {
2170
2517
  const items = data.contextItems;
2171
2518
  return Array.isArray(items) ? items.map(parseCreatedCustomContextItem) : [];
2172
2519
  }
2520
+ /**
2521
+ * Create or update typed relations between context items.
2522
+ *
2523
+ * @param relations - Relations with source and target item uids, a snake_case type, and optional content.
2524
+ * @returns Number of relations created or updated.
2525
+ * @example
2526
+ * ```ts
2527
+ * const client = new Modus()
2528
+ * await client.context.customItems.createRelations([{
2529
+ * fromUid: 'SOURCE_UID',
2530
+ * toUid: 'TARGET_UID',
2531
+ * relationType: 'depends_on',
2532
+ * }])
2533
+ * ```
2534
+ */
2535
+ async createRelations(relations) {
2536
+ const data = asRecord(
2537
+ await invokeWithRetry(
2538
+ this.config,
2539
+ this.http,
2540
+ "CustomContextItemsController_createRelations",
2541
+ { jsonBody: { relations } }
2542
+ )
2543
+ );
2544
+ return data.upsertedCount;
2545
+ }
2173
2546
  /**
2174
2547
  * Update a custom context item.
2175
2548
  *
2176
2549
  * @param uid - Item uid.
2177
2550
  * @param input - Fields to change (kind and hierarchy ids cannot be changed).
2178
2551
  * @returns The updated item uid.
2552
+ * @example
2553
+ * ```ts
2554
+ * const client = new Modus()
2555
+ * await client.context.customItems.update('PLACEHOLDER_UID', {
2556
+ * description: 'Updated summary',
2557
+ * })
2558
+ * ```
2179
2559
  */
2180
2560
  async update(uid, input) {
2181
2561
  return asRecord(
@@ -2190,6 +2570,11 @@ var CustomContextItemsResource = class {
2190
2570
  *
2191
2571
  * @param uid - Item uid.
2192
2572
  * @returns Deletion confirmation with uid and context type.
2573
+ * @example
2574
+ * ```ts
2575
+ * const client = new Modus()
2576
+ * const result = await client.context.customItems.delete('PLACEHOLDER_UID')
2577
+ * ```
2193
2578
  */
2194
2579
  async delete(uid) {
2195
2580
  return parseDeletion(
@@ -2283,49 +2668,574 @@ async function resolveAndUpdateLink(items, uid, options) {
2283
2668
  });
2284
2669
  }
2285
2670
 
2286
- // src/management/context/files.ts
2287
- var import_promises = require("fs/promises");
2288
- var import_node_path = require("path");
2289
- var MAX_BULK_UPLOAD_FILES = 100;
2290
- var DEFAULT_LIST_PAGE_SIZE = 50;
2291
- var DEFAULT_PUT_TIMEOUT_MS = 6e4;
2292
- var DEFAULT_POLL_INTERVAL_MS = 500;
2293
- var DEFAULT_UPLOAD_TIMEOUT_MS = 12e4;
2294
- var DEFAULT_CONCURRENCY = 10;
2295
- var STATUS_ORDER = { pending: 0, processing: 1, ready: 2 };
2296
- var WAIT_UNTIL_VALUES = /* @__PURE__ */ new Set(["processing", "ready"]);
2297
- var DEFER_CONTENT_TYPE_TO_SERVER = "application/octet-stream";
2298
- function validateWaitUntil(waitUntil) {
2299
- if (!WAIT_UNTIL_VALUES.has(waitUntil)) {
2300
- throw new Error(`waitUntil must be one of ${[...WAIT_UNTIL_VALUES].join(", ")}, got ${waitUntil}`);
2671
+ // src/management/context/dashboards.ts
2672
+ var ManagementDashboardElementsResource = class {
2673
+ /** @internal */
2674
+ constructor(http, config, dashboardId) {
2675
+ this.http = http;
2676
+ this.config = config;
2677
+ this.dashboardId = dashboardId;
2301
2678
  }
2302
- }
2303
- function validateBulkSize(count, name) {
2304
- if (count === 0) throw new Error(`${name} must not be empty`);
2305
- if (count > MAX_BULK_UPLOAD_FILES) {
2306
- throw new Error(`${name} must have at most ${MAX_BULK_UPLOAD_FILES} entries, got ${count}`);
2679
+ /**
2680
+ * List every tile and filter on the dashboard draft.
2681
+ *
2682
+ * @returns Each element's id, kind, title and grid position, plus the current
2683
+ * `draftRevision` to pass as `expectedRevision` on the next change.
2684
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2685
+ * @example
2686
+ * ```ts
2687
+ * const listed = await mgmt.context.dashboards.elements('DASHBOARD_ID').list()
2688
+ * listed.elements.map((element) => element.id)
2689
+ * ```
2690
+ */
2691
+ async list() {
2692
+ return asRecord(
2693
+ await invokeWithRetry(this.config, this.http, "DashboardsController_listElements", {
2694
+ pathParams: { dashboardId: this.dashboardId }
2695
+ })
2696
+ );
2307
2697
  }
2308
- }
2309
- function statusSatisfies(status, waitUntil) {
2310
- if (status === "failed") return true;
2311
- return (STATUS_ORDER[status] ?? 0) >= STATUS_ORDER[waitUntil];
2312
- }
2313
- function sleep2(ms) {
2314
- return new Promise((resolve) => setTimeout(resolve, ms));
2315
- }
2316
- function chunked(items, size) {
2317
- const out = [];
2318
- for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
2319
- return out;
2320
- }
2321
- async function mapWithConcurrency(items, concurrency, worker) {
2322
- const results = new Array(items.length);
2698
+ /**
2699
+ * Get the full draft settings of one tile or filter.
2700
+ *
2701
+ * @param elementId - Id of the tile or filter, as returned by `list()`.
2702
+ * @returns The element's settings and the current `draftRevision`.
2703
+ * @throws NotFoundError - The dashboard or the element does not exist, or you cannot
2704
+ * edit the dashboard.
2705
+ * @example
2706
+ * ```ts
2707
+ * const result = await mgmt.context.dashboards.elements('DASHBOARD_ID').get('ELEMENT_ID')
2708
+ * result.element.title
2709
+ * ```
2710
+ */
2711
+ async get(elementId) {
2712
+ validateId(elementId, "elementId");
2713
+ return asRecord(
2714
+ await invokeWithRetry(this.config, this.http, "DashboardsController_getElement", {
2715
+ pathParams: { dashboardId: this.dashboardId, elementId }
2716
+ })
2717
+ );
2718
+ }
2719
+ /**
2720
+ * Add a blank tile or filter to the dashboard draft.
2721
+ *
2722
+ * Modus assigns the new element's id; configure it afterwards with `update()`.
2723
+ *
2724
+ * @param input.expectedRevision - The `draftRevision` your change is based on.
2725
+ * @param input.kind - `chart`, `kpi`, `table`, `markdown` or `filter`.
2726
+ * @param input.title - Title shown on the element.
2727
+ * @param input.layout - Grid position with `x` (0-11), `y`, `w` (1-12) and `h`.
2728
+ * @returns The created element and the new `draftRevision`.
2729
+ * @throws ConflictError - The draft changed since `expectedRevision`; list the
2730
+ * elements again and retry with the new revision.
2731
+ * @example
2732
+ * ```ts
2733
+ * const created = await mgmt.context.dashboards.elements('DASHBOARD_ID').create({
2734
+ * expectedRevision: 3,
2735
+ * kind: 'chart',
2736
+ * title: 'Sales by region',
2737
+ * layout: { x: 0, y: 4, w: 6, h: 4 },
2738
+ * })
2739
+ * ```
2740
+ */
2741
+ async create(input) {
2742
+ return asRecord(
2743
+ await invokeWithRetry(this.config, this.http, "DashboardsController_createElement", {
2744
+ pathParams: { dashboardId: this.dashboardId },
2745
+ jsonBody: {
2746
+ expectedRevision: input.expectedRevision,
2747
+ kind: input.kind,
2748
+ title: input.title,
2749
+ layout: input.layout
2750
+ }
2751
+ })
2752
+ );
2753
+ }
2754
+ /**
2755
+ * Change settings of one tile or filter on the dashboard draft.
2756
+ *
2757
+ * @param elementId - Id of the tile or filter to change.
2758
+ * @param input.expectedRevision - The `draftRevision` your change is based on.
2759
+ * @param input.patch - The settings to change, for example `{ title: 'Sales' }`
2760
+ * or `{ defaultValue: null }`. `null` clears a setting that supports clearing.
2761
+ * @returns The whole dashboard after the change, including the new `draftRevision`.
2762
+ * @throws ConflictError - The draft changed since `expectedRevision`.
2763
+ * @throws NotFoundError - The dashboard or the element does not exist, or you cannot
2764
+ * edit the dashboard.
2765
+ * @example
2766
+ * ```ts
2767
+ * const dashboard = await mgmt.context.dashboards
2768
+ * .elements('DASHBOARD_ID')
2769
+ * .update('ELEMENT_ID', { expectedRevision: 3, patch: { title: 'Revenue' } })
2770
+ * ```
2771
+ */
2772
+ async update(elementId, input) {
2773
+ validateId(elementId, "elementId");
2774
+ return asRecord(
2775
+ await invokeWithRetry(this.config, this.http, "DashboardsController_updateElement", {
2776
+ pathParams: { dashboardId: this.dashboardId, elementId },
2777
+ jsonBody: { expectedRevision: input.expectedRevision, patch: input.patch }
2778
+ })
2779
+ );
2780
+ }
2781
+ };
2782
+ var ManagementDashboardsResource = class {
2783
+ /** @internal */
2784
+ constructor(http, config) {
2785
+ this.http = http;
2786
+ this.config = config;
2787
+ }
2788
+ /**
2789
+ * List dashboards with their full definitions.
2790
+ *
2791
+ * @param options.view - `active` (default) lists published dashboards you can open;
2792
+ * `draft` lists the drafts of dashboards you can edit.
2793
+ * @returns Every matching dashboard. The list is not paginated.
2794
+ * @example
2795
+ * ```ts
2796
+ * const drafts = await mgmt.context.dashboards.list({ view: 'draft' })
2797
+ * drafts.map((dashboard) => [dashboard.id, dashboard.draftRevision])
2798
+ * ```
2799
+ */
2800
+ async list(options = {}) {
2801
+ const data = asRecord(
2802
+ await invokeWithRetry(this.config, this.http, "DashboardsController_list", {
2803
+ query: { view: options.view }
2804
+ })
2805
+ );
2806
+ return data.dashboards;
2807
+ }
2808
+ /**
2809
+ * Get one dashboard with its full definition.
2810
+ *
2811
+ * @param dashboardId - Id of the dashboard.
2812
+ * @param options.view - `active` (default) returns the published version; `draft`
2813
+ * returns the working draft and requires edit access.
2814
+ * @returns The dashboard, including `draftRevision` for the next change.
2815
+ * @throws NotFoundError - The dashboard does not exist or you cannot open it.
2816
+ * @example
2817
+ * ```ts
2818
+ * const draft = await mgmt.context.dashboards.get('DASHBOARD_ID', { view: 'draft' })
2819
+ * draft.draftRevision
2820
+ * ```
2821
+ */
2822
+ async get(dashboardId, options = {}) {
2823
+ validateId(dashboardId, "dashboardId");
2824
+ return asRecord(
2825
+ await invokeWithRetry(this.config, this.http, "DashboardsController_get", {
2826
+ pathParams: { dashboardId },
2827
+ query: { view: options.view }
2828
+ })
2829
+ );
2830
+ }
2831
+ /**
2832
+ * Create a dashboard draft.
2833
+ *
2834
+ * The new dashboard is not visible to others until you `publish()` it.
2835
+ *
2836
+ * @param input.title - Dashboard title.
2837
+ * @param input.definition - Tiles, filters and layout, for example
2838
+ * `{ tiles: [], filters: [] }`. Element ids must be unique.
2839
+ * @param input.description - Optional dashboard description.
2840
+ * @param input.access - Optional `visibility`, `groupPermissions` and `sharedWith`.
2841
+ * Defaults to private.
2842
+ * @returns The created dashboard in its draft view.
2843
+ * @throws ModusError - The definition or access settings are invalid.
2844
+ * @example
2845
+ * ```ts
2846
+ * const dashboard = await mgmt.context.dashboards.create({
2847
+ * title: 'Revenue',
2848
+ * definition: { tiles: [], filters: [] },
2849
+ * })
2850
+ * dashboard.id
2851
+ * ```
2852
+ */
2853
+ async create(input) {
2854
+ return asRecord(
2855
+ await invokeWithRetry(this.config, this.http, "DashboardsController_create", {
2856
+ jsonBody: {
2857
+ title: input.title,
2858
+ description: input.description,
2859
+ definition: input.definition,
2860
+ access: input.access
2861
+ }
2862
+ })
2863
+ );
2864
+ }
2865
+ /**
2866
+ * Replace the whole draft definition, and optionally the title and description.
2867
+ *
2868
+ * @param dashboardId - Id of the dashboard.
2869
+ * @param input.expectedRevision - The `draftRevision` your change is based on.
2870
+ * @param input.definition - The complete new definition. Tiles and filters left
2871
+ * out are removed.
2872
+ * @param input.title - New title; unchanged when omitted.
2873
+ * @param input.description - New description; unchanged when omitted.
2874
+ * @returns The dashboard draft after the change, including the new `draftRevision`.
2875
+ * @throws ConflictError - The draft changed since `expectedRevision`; get the draft
2876
+ * again and retry with the new revision.
2877
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2878
+ * @example
2879
+ * ```ts
2880
+ * const draft = await mgmt.context.dashboards.get('DASHBOARD_ID', { view: 'draft' })
2881
+ * await mgmt.context.dashboards.updateDraft('DASHBOARD_ID', {
2882
+ * expectedRevision: draft.draftRevision,
2883
+ * definition: draft.definition,
2884
+ * title: 'Revenue',
2885
+ * })
2886
+ * ```
2887
+ */
2888
+ async updateDraft(dashboardId, input) {
2889
+ validateId(dashboardId, "dashboardId");
2890
+ return asRecord(
2891
+ await invokeWithRetry(this.config, this.http, "DashboardsController_updateDraft", {
2892
+ pathParams: { dashboardId },
2893
+ jsonBody: {
2894
+ expectedRevision: input.expectedRevision,
2895
+ title: input.title,
2896
+ description: input.description,
2897
+ definition: input.definition
2898
+ }
2899
+ })
2900
+ );
2901
+ }
2902
+ /**
2903
+ * Publish the draft as a new version that everyone with access sees.
2904
+ *
2905
+ * Alert workflows defined on the dashboard are updated to match.
2906
+ *
2907
+ * @param dashboardId - Id of the dashboard.
2908
+ * @param input.expectedRevision - The `draftRevision` you reviewed and want to publish.
2909
+ * @returns The published `dashboard` and the new `version`.
2910
+ * @throws ConflictError - The draft changed since `expectedRevision`.
2911
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2912
+ * @example
2913
+ * ```ts
2914
+ * const result = await mgmt.context.dashboards.publish('DASHBOARD_ID', { expectedRevision: 4 })
2915
+ * result.version.versionNumber
2916
+ * ```
2917
+ */
2918
+ async publish(dashboardId, input) {
2919
+ validateId(dashboardId, "dashboardId");
2920
+ return asRecord(
2921
+ await invokeWithRetry(this.config, this.http, "DashboardsController_publish", {
2922
+ pathParams: { dashboardId },
2923
+ jsonBody: { expectedRevision: input.expectedRevision }
2924
+ })
2925
+ );
2926
+ }
2927
+ /**
2928
+ * Delete a dashboard and the alert workflows defined on it.
2929
+ *
2930
+ * A deleted dashboard cannot be restored.
2931
+ *
2932
+ * @param dashboardId - Id of the dashboard.
2933
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2934
+ * @example
2935
+ * ```ts
2936
+ * await mgmt.context.dashboards.delete('DASHBOARD_ID')
2937
+ * ```
2938
+ */
2939
+ async delete(dashboardId) {
2940
+ validateId(dashboardId, "dashboardId");
2941
+ await invokeWithRetry(this.config, this.http, "DashboardsController_delete", {
2942
+ pathParams: { dashboardId }
2943
+ });
2944
+ }
2945
+ /**
2946
+ * List the published versions of a dashboard, newest first.
2947
+ *
2948
+ * @param dashboardId - Id of the dashboard.
2949
+ * @returns Every published version with its full definition. Definitions are
2950
+ * returned as stored, so older versions may lack newer fields. The list is
2951
+ * not paginated.
2952
+ * @throws NotFoundError - The dashboard does not exist or you cannot open it.
2953
+ * @example
2954
+ * ```ts
2955
+ * const versions = await mgmt.context.dashboards.listVersions('DASHBOARD_ID')
2956
+ * versions.map((version) => [version.uid, version.versionNumber])
2957
+ * ```
2958
+ */
2959
+ async listVersions(dashboardId) {
2960
+ validateId(dashboardId, "dashboardId");
2961
+ const data = asRecord(
2962
+ await invokeWithRetry(this.config, this.http, "DashboardsController_listVersions", {
2963
+ pathParams: { dashboardId }
2964
+ })
2965
+ );
2966
+ return data.versions;
2967
+ }
2968
+ /**
2969
+ * Get a dashboard as it was in one version.
2970
+ *
2971
+ * @param dashboardId - Id of the dashboard.
2972
+ * @param versionId - Id of the version, as returned by `listVersions()`.
2973
+ * @returns The dashboard with that version's definition.
2974
+ * @throws NotFoundError - The dashboard or the version does not exist, or you cannot
2975
+ * open the dashboard.
2976
+ * @example
2977
+ * ```ts
2978
+ * const old = await mgmt.context.dashboards.getVersion('DASHBOARD_ID', 'VERSION_ID')
2979
+ * old.selectedVersion.versionNumber
2980
+ * ```
2981
+ */
2982
+ async getVersion(dashboardId, versionId) {
2983
+ validateId(dashboardId, "dashboardId");
2984
+ validateId(versionId, "versionId");
2985
+ return asRecord(
2986
+ await invokeWithRetry(this.config, this.http, "DashboardsController_getVersion", {
2987
+ pathParams: { dashboardId, versionId }
2988
+ })
2989
+ );
2990
+ }
2991
+ /**
2992
+ * Replace the draft with the content of an earlier version.
2993
+ *
2994
+ * The draft being replaced is kept as a draft snapshot. Call `publish()`
2995
+ * afterwards to make the restored content visible.
2996
+ *
2997
+ * @param dashboardId - Id of the dashboard.
2998
+ * @param versionId - Id of the version or draft snapshot to restore.
2999
+ * @returns The dashboard draft after the restore.
3000
+ * @throws NotFoundError - The dashboard or the version does not exist, or you cannot
3001
+ * edit the dashboard.
3002
+ * @example
3003
+ * ```ts
3004
+ * await mgmt.context.dashboards.restoreVersion('DASHBOARD_ID', 'VERSION_ID')
3005
+ * ```
3006
+ */
3007
+ async restoreVersion(dashboardId, versionId) {
3008
+ validateId(dashboardId, "dashboardId");
3009
+ validateId(versionId, "versionId");
3010
+ return asRecord(
3011
+ await invokeWithRetry(this.config, this.http, "DashboardsController_restore", {
3012
+ pathParams: { dashboardId, versionId }
3013
+ })
3014
+ );
3015
+ }
3016
+ /**
3017
+ * List recent snapshots of the dashboard draft, newest first.
3018
+ *
3019
+ * @param dashboardId - Id of the dashboard.
3020
+ * @returns Up to 100 snapshots with their id, author and time. Pass an id to
3021
+ * `restoreVersion()` to bring that draft back.
3022
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
3023
+ * @example
3024
+ * ```ts
3025
+ * const snapshots = await mgmt.context.dashboards.listDraftSnapshots('DASHBOARD_ID')
3026
+ * snapshots.map((snapshot) => snapshot.uid)
3027
+ * ```
3028
+ */
3029
+ async listDraftSnapshots(dashboardId) {
3030
+ validateId(dashboardId, "dashboardId");
3031
+ const data = asRecord(
3032
+ await invokeWithRetry(this.config, this.http, "DashboardsController_listDraftSnapshots", {
3033
+ pathParams: { dashboardId }
3034
+ })
3035
+ );
3036
+ return data.snapshots;
3037
+ }
3038
+ /**
3039
+ * Replace who can open and edit a dashboard.
3040
+ *
3041
+ * All three settings are required and replace the current ones.
3042
+ *
3043
+ * @param dashboardId - Id of the dashboard.
3044
+ * @param input.visibility - `shared` (the owner plus the groups in
3045
+ * `groupPermissions`) or `private` (the owner plus the users in `sharedWith`).
3046
+ * @param input.groupPermissions - Group id to `{ use, manage }`. Used only when shared.
3047
+ * @param input.sharedWith - Users such as `{ email: 'ana@example.com', permission: 'use' }`.
3048
+ * Used only when private.
3049
+ * @returns The dashboard with its new access settings.
3050
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
3051
+ * @throws ModusError - A group, user or permission is invalid.
3052
+ * @example
3053
+ * ```ts
3054
+ * await mgmt.context.dashboards.updateAccess('DASHBOARD_ID', {
3055
+ * visibility: 'private',
3056
+ * groupPermissions: {},
3057
+ * sharedWith: [{ email: 'ana@example.com', permission: 'use' }],
3058
+ * })
3059
+ * ```
3060
+ */
3061
+ async updateAccess(dashboardId, input) {
3062
+ validateId(dashboardId, "dashboardId");
3063
+ return asRecord(
3064
+ await invokeWithRetry(this.config, this.http, "DashboardsController_updateAccess", {
3065
+ pathParams: { dashboardId },
3066
+ jsonBody: {
3067
+ visibility: input.visibility,
3068
+ groupPermissions: input.groupPermissions,
3069
+ sharedWith: input.sharedWith
3070
+ }
3071
+ })
3072
+ );
3073
+ }
3074
+ /**
3075
+ * Ask another member of your organization to take ownership of a dashboard.
3076
+ *
3077
+ * Only the owner can request a transfer. Ownership moves when the recipient
3078
+ * calls `acceptOwnershipTransfer()`.
3079
+ *
3080
+ * @param dashboardId - Id of the dashboard.
3081
+ * @param input.newOwnerUserId - User id of the member who should become the owner.
3082
+ * @returns The dashboard with `pendingOwnershipTransfer` set.
3083
+ * @throws PermissionDeniedError - You are not the owner.
3084
+ * @throws NotFoundError - The dashboard does not exist or you cannot open it.
3085
+ * @example
3086
+ * ```ts
3087
+ * await mgmt.context.dashboards.requestOwnershipTransfer('DASHBOARD_ID', {
3088
+ * newOwnerUserId: 'USER_ID',
3089
+ * })
3090
+ * ```
3091
+ */
3092
+ async requestOwnershipTransfer(dashboardId, input) {
3093
+ validateId(dashboardId, "dashboardId");
3094
+ validateId(input.newOwnerUserId, "newOwnerUserId");
3095
+ return asRecord(
3096
+ await invokeWithRetry(this.config, this.http, "DashboardsController_transferOwnership", {
3097
+ pathParams: { dashboardId },
3098
+ jsonBody: { newOwnerUserId: input.newOwnerUserId }
3099
+ })
3100
+ );
3101
+ }
3102
+ /**
3103
+ * Accept a pending ownership transfer and become the dashboard owner.
3104
+ *
3105
+ * Only the requested recipient can accept.
3106
+ *
3107
+ * @param dashboardId - Id of the dashboard.
3108
+ * @returns The dashboard with you as its owner.
3109
+ * @throws NotFoundError - The dashboard does not exist, or it has no pending transfer
3110
+ * addressed to you.
3111
+ * @example
3112
+ * ```ts
3113
+ * await mgmt.context.dashboards.acceptOwnershipTransfer('DASHBOARD_ID')
3114
+ * ```
3115
+ */
3116
+ async acceptOwnershipTransfer(dashboardId) {
3117
+ validateId(dashboardId, "dashboardId");
3118
+ return asRecord(
3119
+ await invokeWithRetry(this.config, this.http, "DashboardsController_acceptOwnership", {
3120
+ pathParams: { dashboardId }
3121
+ })
3122
+ );
3123
+ }
3124
+ /**
3125
+ * Cancel a pending ownership transfer.
3126
+ *
3127
+ * Only the owner can cancel.
3128
+ *
3129
+ * @param dashboardId - Id of the dashboard.
3130
+ * @returns The dashboard with no pending transfer.
3131
+ * @throws NotFoundError - The dashboard does not exist, you cannot open it, or you are
3132
+ * not the owner.
3133
+ * @example
3134
+ * ```ts
3135
+ * await mgmt.context.dashboards.cancelOwnershipTransfer('DASHBOARD_ID')
3136
+ * ```
3137
+ */
3138
+ async cancelOwnershipTransfer(dashboardId) {
3139
+ validateId(dashboardId, "dashboardId");
3140
+ return asRecord(
3141
+ await invokeWithRetry(this.config, this.http, "DashboardsController_cancelOwnership", {
3142
+ pathParams: { dashboardId }
3143
+ })
3144
+ );
3145
+ }
3146
+ /**
3147
+ * Work with the tiles and filters of one dashboard draft.
3148
+ *
3149
+ * @param dashboardId - Id of the dashboard.
3150
+ * @returns A resource bound to that dashboard.
3151
+ * @example
3152
+ * ```ts
3153
+ * await mgmt.context.dashboards.elements('DASHBOARD_ID').list()
3154
+ * ```
3155
+ */
3156
+ elements(dashboardId) {
3157
+ validateId(dashboardId, "dashboardId");
3158
+ return new ManagementDashboardElementsResource(this.http, this.config, dashboardId);
3159
+ }
3160
+ /**
3161
+ * Move or resize several tiles and filters in one change.
3162
+ *
3163
+ * @param dashboardId - Id of the dashboard.
3164
+ * @param input.expectedRevision - The `draftRevision` your change is based on.
3165
+ * @param input.elements - Every element to place, each with `elementId` and its
3166
+ * final `layout`.
3167
+ * @returns The whole dashboard after the change, including the new `draftRevision`.
3168
+ * @throws ConflictError - The draft changed since `expectedRevision`.
3169
+ * @example
3170
+ * ```ts
3171
+ * await mgmt.context.dashboards.updateLayout('DASHBOARD_ID', {
3172
+ * expectedRevision: 3,
3173
+ * elements: [{ elementId: 'ELEMENT_ID', layout: { x: 0, y: 0, w: 12, h: 2 } }],
3174
+ * })
3175
+ * ```
3176
+ */
3177
+ async updateLayout(dashboardId, input) {
3178
+ validateId(dashboardId, "dashboardId");
3179
+ return asRecord(
3180
+ await invokeWithRetry(this.config, this.http, "DashboardsController_updateLayout", {
3181
+ pathParams: { dashboardId },
3182
+ jsonBody: { expectedRevision: input.expectedRevision, elements: input.elements }
3183
+ })
3184
+ );
3185
+ }
3186
+ };
3187
+
3188
+ // src/management/context/files.ts
3189
+ var import_promises = require("fs/promises");
3190
+ var import_node_path = require("path");
3191
+ var MAX_BULK_UPLOAD_FILES = 100;
3192
+ var DEFAULT_LIST_PAGE_SIZE = 50;
3193
+ var DEFAULT_PUT_TIMEOUT_MS = 6e4;
3194
+ var DEFAULT_POLL_INTERVAL_MS = 500;
3195
+ var DEFAULT_UPLOAD_TIMEOUT_MS = 12e4;
3196
+ var DEFAULT_CONCURRENCY = 10;
3197
+ var STATUS_ORDER = { pending: 0, processing: 1, ready: 2 };
3198
+ var WAIT_UNTIL_VALUES = /* @__PURE__ */ new Set(["processing", "ready"]);
3199
+ var DEFER_CONTENT_TYPE_TO_SERVER = "application/octet-stream";
3200
+ function validateWaitUntil(waitUntil) {
3201
+ if (!WAIT_UNTIL_VALUES.has(waitUntil)) {
3202
+ throw new Error(`waitUntil must be one of ${[...WAIT_UNTIL_VALUES].join(", ")}, got ${waitUntil}`);
3203
+ }
3204
+ }
3205
+ function validateBulkSize(count, name) {
3206
+ if (count === 0) throw new Error(`${name} must not be empty`);
3207
+ if (count > MAX_BULK_UPLOAD_FILES) {
3208
+ throw new Error(`${name} must have at most ${MAX_BULK_UPLOAD_FILES} entries, got ${count}`);
3209
+ }
3210
+ }
3211
+ function statusSatisfies(status, waitUntil) {
3212
+ if (status === "failed") return true;
3213
+ return (STATUS_ORDER[status] ?? 0) >= STATUS_ORDER[waitUntil];
3214
+ }
3215
+ function sleep2(ms) {
3216
+ return new Promise((resolve) => setTimeout(resolve, ms));
3217
+ }
3218
+ function chunked(items, size) {
3219
+ const out = [];
3220
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
3221
+ return out;
3222
+ }
3223
+ function joinDestination(prefix, relative2) {
3224
+ const head = prefix === void 0 || prefix.length === 0 ? void 0 : prefix;
3225
+ const tail = relative2 === void 0 || relative2.length === 0 ? void 0 : relative2;
3226
+ if (head !== void 0 && tail !== void 0) return `${head}/${tail}`;
3227
+ return head ?? tail;
3228
+ }
3229
+ async function mapWithConcurrency(items, concurrency, worker, onItemDone) {
3230
+ const results = new Array(items.length);
2323
3231
  let cursor = 0;
2324
3232
  async function run() {
2325
3233
  for (; ; ) {
2326
3234
  const index = cursor++;
2327
3235
  if (index >= items.length) return;
2328
- results[index] = await worker(items[index]);
3236
+ const result = await worker(items[index]);
3237
+ results[index] = result;
3238
+ onItemDone?.(result);
2329
3239
  }
2330
3240
  }
2331
3241
  await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, run));
@@ -2349,11 +3259,11 @@ async function walkFiles(root, recursive) {
2349
3259
  await walk(root);
2350
3260
  return out;
2351
3261
  }
2352
- async function putBytes(fetchImpl, url, data, contentType, timeoutMs) {
2353
- const response = await fetchImpl(url, {
3262
+ async function putBytes(fetchImpl, slot, data, timeoutMs) {
3263
+ const response = await fetchImpl(slot.uploadUrl, {
2354
3264
  method: "PUT",
2355
3265
  body: data,
2356
- headers: { "Content-Type": contentType },
3266
+ headers: { "Content-Type": slot.contentType, ...slot.headers },
2357
3267
  signal: AbortSignal.timeout(timeoutMs)
2358
3268
  });
2359
3269
  if (!response.ok) {
@@ -2371,25 +3281,29 @@ function createSlotsPayload(files) {
2371
3281
  }
2372
3282
  function uploadFromUrlsPayload(urls) {
2373
3283
  return {
2374
- urls: urls.map((u) => u.fileName !== void 0 ? { url: u.url, fileName: u.fileName } : { url: u.url })
3284
+ urls: urls.map((u) => ({
3285
+ url: u.url,
3286
+ ...u.fileName !== void 0 ? { fileName: u.fileName } : {},
3287
+ ...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
3288
+ }))
2375
3289
  };
2376
3290
  }
2377
3291
  function assignSlots(batch, result, failed) {
2378
3292
  const failedIndices = new Set(result.failed.map((f) => f.index));
2379
3293
  for (const f of result.failed) {
2380
- failed.push({ path: batch[f.index], error: f.error });
3294
+ failed.push({ path: batch[f.index]?.path ?? "", error: f.error });
2381
3295
  }
2382
3296
  const remaining = batch.filter((_, i) => !failedIndices.has(i));
2383
3297
  const uploaded = result.uploaded;
2384
3298
  if (uploaded.length < remaining.length) {
2385
- for (const path of remaining.slice(uploaded.length)) {
2386
- failed.push({ path, error: "Server returned fewer upload slots than requested files." });
3299
+ for (const file of remaining.slice(uploaded.length)) {
3300
+ failed.push({ path: file.path, error: "Server returned fewer upload slots than requested files." });
2387
3301
  }
2388
3302
  }
2389
3303
  const paired = Math.min(remaining.length, uploaded.length);
2390
3304
  const assignments = [];
2391
3305
  for (let i = 0; i < paired; i++) {
2392
- assignments.push({ path: remaining[i], slot: uploaded[i] });
3306
+ assignments.push({ ...remaining[i], slot: uploaded[i] });
2393
3307
  }
2394
3308
  return assignments;
2395
3309
  }
@@ -2407,7 +3321,10 @@ var ManagementContextFilesResource = class {
2407
3321
  * Office/OpenDocument documents, audio, and video.
2408
3322
  * @param input.fileSize - File size in bytes. Rejected above 50MB.
2409
3323
  * @returns Presigned upload slot. PUT the raw bytes to `uploadUrl` within 15
2410
- * minutes, then poll `get(uploadId)` — there is no separate finalize call.
3324
+ * minutes, sending `headers` unchanged, then call `finalize(slot.uploadId, slot.fileName)`. Pass the
3325
+ * slot's own `fileName` rather than your local basename — the server may
3326
+ * sanitize the requested name when it mints the key, and finalization
3327
+ * re-derives the key from `uploadId` and `fileName`.
2411
3328
  */
2412
3329
  async createUploadUrl(input) {
2413
3330
  return asRecord(
@@ -2437,12 +3354,17 @@ var ManagementContextFilesResource = class {
2437
3354
  * @param url - Source URL to fetch (SSRF-guarded, 50MB cap, same MIME
2438
3355
  * allow-list as `createUploadUrl`).
2439
3356
  * @param options.fileName - Override file name. Inferred from the URL path when omitted.
3357
+ * @param options.folderPath - Root-relative folder to upload under.
2440
3358
  * @returns File upload resource with status `processing` — parsing continues async.
2441
3359
  */
2442
3360
  async uploadFromUrl(url, options = {}) {
2443
3361
  return asRecord(
2444
3362
  await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrl", {
2445
- jsonBody: options.fileName !== void 0 ? { url, fileName: options.fileName } : { url }
3363
+ jsonBody: {
3364
+ url,
3365
+ ...options.fileName !== void 0 ? { fileName: options.fileName } : {},
3366
+ ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {}
3367
+ }
2446
3368
  })
2447
3369
  );
2448
3370
  }
@@ -2496,19 +3418,94 @@ var ManagementContextFilesResource = class {
2496
3418
  );
2497
3419
  return buildAipPage(data, "files", (raw) => raw, (token) => this.listPage(pageSize, token));
2498
3420
  }
3421
+ /**
3422
+ * Turn a file already PUT to a presigned URL into durable context.
3423
+ *
3424
+ * Call this once the PUT completes. The server locates the object from
3425
+ * `uploadId` + `fileName` and validates the bytes that actually arrived.
3426
+ * Safe to retry — a second call returns the same resource.
3427
+ *
3428
+ * @param uploadId - Upload id returned by `createUploadUrl`.
3429
+ * @param fileName - File name returned alongside it.
3430
+ * @returns The file upload resource, status `"processing"`.
3431
+ */
3432
+ async finalize(uploadId, fileName, options = {}) {
3433
+ validateId(uploadId, "uploadId");
3434
+ return asRecord(
3435
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_finalize", {
3436
+ pathParams: { uploadId },
3437
+ jsonBody: { fileName, ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {} }
3438
+ })
3439
+ );
3440
+ }
3441
+ /**
3442
+ * Finalize up to 100 uploads in one call.
3443
+ *
3444
+ * What makes directory upload cheap: 2000 files cost 20 requests here rather
3445
+ * than 2000.
3446
+ *
3447
+ * @param uploads - Uploads to finalize (max 100).
3448
+ * @returns Resources for every upload that finalized, plus per-index
3449
+ * failures for the rest — never a partial 4xx.
3450
+ */
3451
+ async finalizeMany(uploads) {
3452
+ validateBulkSize(uploads.length, "uploads");
3453
+ return asRecord(
3454
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_finalizeMany", {
3455
+ jsonBody: {
3456
+ uploads: uploads.map((u) => ({
3457
+ uploadId: u.uploadId,
3458
+ fileName: u.fileName,
3459
+ ...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
3460
+ }))
3461
+ }
3462
+ })
3463
+ );
3464
+ }
3465
+ /**
3466
+ * Upload an explicit list of local files.
3467
+ *
3468
+ * Same machinery as `uploadDir`, without the directory walk — use it when
3469
+ * the caller already knows which files to send.
3470
+ *
3471
+ * @param paths - Paths to local files.
3472
+ * @param options.concurrency - Max concurrent PUTs (default 10).
3473
+ * @param options.waitUntil - `"processing"` (default) or `"ready"`.
3474
+ * @param options.onProgress - Optional progress callback after each file.
3475
+ * @param options.folderPath - Root-relative folder to upload under. Nested
3476
+ * files keep their existing relative folder labels under this prefix.
3477
+ * @example
3478
+ * ```ts
3479
+ * const mgmt = new ModusManagement()
3480
+ * const result = await mgmt.context.files.uploadFiles(
3481
+ * ['./q3.pdf', './notes.md'],
3482
+ * { folderPath: 'reports/2026' },
3483
+ * )
3484
+ * ```
3485
+ */
3486
+ async uploadFiles(paths, options = {}) {
3487
+ return this.uploadPaths(paths.map((input) => typeof input === "string" ? { path: input } : input), options);
3488
+ }
2499
3489
  /**
2500
3490
  * Upload a local file and wait for it to reach `"processing"` or `"ready"`.
2501
3491
  *
2502
- * Gets a presigned URL, PUTs the file bytes, then polls `get()` until the
2503
- * upload leaves `"pending"` (or reaches `"ready"`/`"failed"`).
3492
+ * Gets a presigned URL, PUTs the file bytes, then polls `get()`
3493
+ * until the upload leaves `"pending"` (or reaches `"ready"`/`"failed"`).
2504
3494
  *
2505
3495
  * @param path - Path to a local file.
2506
3496
  * @param options.waitUntil - `"processing"` (parsing started, default) or
2507
3497
  * `"ready"` (parsing finished).
2508
3498
  * @param options.pollIntervalMs - Milliseconds between status polls.
2509
3499
  * @param options.timeoutMs - Max milliseconds to wait before raising.
3500
+ * @param options.folderPath - Root-relative folder to upload under. Example:
3501
+ * `{ folderPath: 'reports/2026' }` places `./report.pdf` at `reports/2026`.
2510
3502
  * @returns The file upload resource once it reaches `waitUntil` (or `"failed"`).
2511
3503
  * @throws {ModusError} If the PUT fails, or polling times out.
3504
+ * @example
3505
+ * ```ts
3506
+ * const mgmt = new ModusManagement()
3507
+ * const file = await mgmt.context.files.upload('./report.pdf', { folderPath: 'reports/2026' })
3508
+ * ```
2512
3509
  */
2513
3510
  async upload(path, options = {}) {
2514
3511
  const waitUntil = options.waitUntil ?? "processing";
@@ -2522,7 +3519,11 @@ var ManagementContextFilesResource = class {
2522
3519
  fileSize: fileStat.size
2523
3520
  });
2524
3521
  const data = await (0, import_promises.readFile)(path);
2525
- await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
3522
+ await putBytes(this.config.fetch, slot, data, DEFAULT_PUT_TIMEOUT_MS);
3523
+ const finalized = await this.finalize(slot.uploadId, slot.fileName, {
3524
+ ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {}
3525
+ });
3526
+ if (statusSatisfies(finalized.status, waitUntil)) return finalized;
2526
3527
  return this.pollUntil(
2527
3528
  slot.uploadId,
2528
3529
  waitUntil,
@@ -2555,8 +3556,18 @@ var ManagementContextFilesResource = class {
2555
3556
  * @param options.recursive - Recurse into subdirectories (default `true`).
2556
3557
  * @param options.concurrency - Max concurrent PUT+poll operations (default 10).
2557
3558
  * @param options.waitUntil - `"processing"` (default) or `"ready"` — same as `upload()`.
3559
+ * @param options.onProgress - Optional progress callback after each file.
3560
+ * @param options.folderPath - Root-relative folder to upload under. Nested
3561
+ * files keep their path relative to `path` under this prefix. Example:
3562
+ * `uploadDir('./docs', { folderPath: 'reports' })` places `./docs/a.txt` at
3563
+ * `reports` and `./docs/nested/b.txt` at `reports/nested`.
2558
3564
  * @returns `UploadDirResult` with every successful `FileUpload` and every
2559
3565
  * per-file failure (slot creation or PUT/poll), each tagged with its local path.
3566
+ * @example
3567
+ * ```ts
3568
+ * const mgmt = new ModusManagement()
3569
+ * const result = await mgmt.context.files.uploadDir('./docs', { folderPath: 'reports' })
3570
+ * ```
2560
3571
  */
2561
3572
  async uploadDir(path, options = {}) {
2562
3573
  const waitUntil = options.waitUntil ?? "processing";
@@ -2565,56 +3576,155 @@ var ManagementContextFilesResource = class {
2565
3576
  if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
2566
3577
  const dirStat = await (0, import_promises.stat)(path);
2567
3578
  if (!dirStat.isDirectory()) throw new Error(`Not a directory: ${path}`);
3579
+ const files = await walkFiles(path, options.recursive ?? true);
3580
+ return this.uploadPaths(files.map((file) => {
3581
+ const folderPath = (0, import_node_path.relative)(path, (0, import_node_path.dirname)(file)).replace(/\\/g, "/");
3582
+ return { path: file, ...folderPath.length > 0 ? { folderPath } : {} };
3583
+ }), options);
3584
+ }
3585
+ /** Shared body of `uploadFiles` and `uploadDir`: presign in batches of 100,
3586
+ * PUT with bounded concurrency, then bulk-finalize the batch. */
3587
+ async uploadPaths(files, options) {
3588
+ const waitUntil = options.waitUntil ?? "processing";
3589
+ validateWaitUntil(waitUntil);
3590
+ const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
3591
+ if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
3592
+ const prefixed = files.map((file) => {
3593
+ const folderPath = joinDestination(options.folderPath, file.folderPath);
3594
+ return { path: file.path, ...folderPath !== void 0 ? { folderPath } : {} };
3595
+ });
2568
3596
  const uploaded = [];
2569
3597
  const failed = [];
2570
- const files = await walkFiles(path, options.recursive ?? true);
2571
- for (const batch of chunked(files, MAX_BULK_UPLOAD_FILES)) {
3598
+ const total = files.length;
3599
+ let completed = 0;
3600
+ const emit = () => {
3601
+ completed += 1;
3602
+ options.onProgress?.({
3603
+ completed,
3604
+ total,
3605
+ succeeded: uploaded.length,
3606
+ failed: failed.length
3607
+ });
3608
+ };
3609
+ for (const batch of chunked(prefixed, MAX_BULK_UPLOAD_FILES)) {
3610
+ const failedBefore = failed.length;
2572
3611
  const slots = await this.createSlots(batch, failed);
2573
- const results = await this.uploadBatch(slots, waitUntil, concurrency);
2574
- for (const result of results) {
3612
+ for (let reported = failedBefore + 1; reported <= failed.length; reported += 1) {
3613
+ completed += 1;
3614
+ options.onProgress?.({ completed, total, succeeded: uploaded.length, failed: reported });
3615
+ }
3616
+ await this.uploadBatch(slots, waitUntil, concurrency, (result) => {
2575
3617
  if ("error" in result) failed.push(result);
2576
3618
  else uploaded.push(result);
2577
- }
3619
+ emit();
3620
+ });
2578
3621
  }
2579
3622
  return { uploaded, failed };
2580
3623
  }
2581
3624
  async createSlots(batch, failed) {
2582
3625
  const readable = [];
2583
3626
  const inputs = [];
2584
- for (const path of batch) {
3627
+ for (const file of batch) {
2585
3628
  try {
2586
- const fileStat = await (0, import_promises.stat)(path);
2587
- const fileName = path.split(/[/\\]/).pop();
3629
+ const fileStat = await (0, import_promises.stat)(file.path);
3630
+ const fileName = file.path.split(/[/\\]/).pop();
2588
3631
  inputs.push({ fileName, contentType: DEFER_CONTENT_TYPE_TO_SERVER, fileSize: fileStat.size });
2589
- readable.push(path);
3632
+ readable.push(file);
2590
3633
  } catch (error) {
2591
3634
  const message = error instanceof Error ? error.message : String(error);
2592
- failed.push({ path, error: message });
3635
+ failed.push({ path: file.path, error: message });
2593
3636
  }
2594
3637
  }
2595
3638
  if (inputs.length === 0) return [];
2596
3639
  const result = await this.createUploadUrls(inputs);
2597
3640
  return assignSlots(readable, result, failed);
2598
3641
  }
2599
- async uploadBatch(slots, waitUntil, concurrency) {
3642
+ async uploadBatch(slots, waitUntil, concurrency, onOutcome) {
2600
3643
  if (slots.length === 0) return [];
2601
- return mapWithConcurrency(slots, concurrency, async ({ path, slot }) => {
2602
- try {
2603
- const data = await (0, import_promises.readFile)(path);
2604
- await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
2605
- return await this.pollUntil(slot.uploadId, waitUntil, DEFAULT_POLL_INTERVAL_MS, DEFAULT_UPLOAD_TIMEOUT_MS);
2606
- } catch (error) {
2607
- const message = error instanceof Error ? error.message : String(error);
2608
- return { path, error: message };
3644
+ const out = [];
3645
+ const put = await mapWithConcurrency(
3646
+ slots,
3647
+ concurrency,
3648
+ async ({ path, folderPath, slot }) => {
3649
+ try {
3650
+ const data = await (0, import_promises.readFile)(path);
3651
+ await putBytes(this.config.fetch, slot, data, DEFAULT_PUT_TIMEOUT_MS);
3652
+ return { landed: { path, ...folderPath !== void 0 ? { folderPath } : {}, slot } };
3653
+ } catch (error) {
3654
+ const message = error instanceof Error ? error.message : String(error);
3655
+ return { failure: { path, error: message } };
3656
+ }
3657
+ },
3658
+ (outcome) => {
3659
+ if ("failure" in outcome) {
3660
+ out.push(outcome.failure);
3661
+ onOutcome?.(outcome.failure);
3662
+ }
2609
3663
  }
2610
- });
3664
+ );
3665
+ const landed = [];
3666
+ for (const entry of put) {
3667
+ if ("failure" in entry) {
3668
+ continue;
3669
+ }
3670
+ landed.push(entry.landed);
3671
+ }
3672
+ if (landed.length === 0) return out;
3673
+ const result = await this.finalizeMany(
3674
+ landed.map(({ slot, folderPath }) => ({
3675
+ uploadId: slot.uploadId,
3676
+ fileName: slot.fileName,
3677
+ ...folderPath !== void 0 ? { folderPath } : {}
3678
+ }))
3679
+ );
3680
+ const failedIndices = new Set(result.failed.map((f) => f.index));
3681
+ for (const f of result.failed) {
3682
+ const failure = { path: landed[f.index]?.path ?? "", error: f.error };
3683
+ out.push(failure);
3684
+ onOutcome?.(failure);
3685
+ }
3686
+ const finalized = result.finalized;
3687
+ const remaining = landed.filter((_, i) => !failedIndices.has(i));
3688
+ if (waitUntil !== "ready") {
3689
+ for (const item of finalized) {
3690
+ out.push(item);
3691
+ onOutcome?.(item);
3692
+ }
3693
+ return out;
3694
+ }
3695
+ await mapWithConcurrency(
3696
+ remaining,
3697
+ concurrency,
3698
+ async ({ path, slot }) => {
3699
+ try {
3700
+ return await this.pollUntil(slot.uploadId, waitUntil, DEFAULT_POLL_INTERVAL_MS, DEFAULT_UPLOAD_TIMEOUT_MS);
3701
+ } catch (error) {
3702
+ const message = error instanceof Error ? error.message : String(error);
3703
+ return { path, error: message };
3704
+ }
3705
+ },
3706
+ (item) => {
3707
+ out.push(item);
3708
+ onOutcome?.(item);
3709
+ }
3710
+ );
3711
+ return out;
2611
3712
  }
2612
3713
  };
2613
3714
 
2614
3715
  // src/management/context/items.ts
2615
- function contextListParams(pageSize, pageToken, contextType) {
3716
+ function contextListParams(pageSize, pageToken, filters = {}) {
2616
3717
  const extra = {};
2617
- if (contextType !== void 0) extra.contextTypes = [contextType];
3718
+ if (filters.contextType !== void 0) extra.contextTypes = [filters.contextType];
3719
+ if (filters.parentUids !== void 0) {
3720
+ extra.parentUids = filters.parentUids.length === 0 ? "" : [...filters.parentUids];
3721
+ }
3722
+ if (filters.ancestorUids !== void 0) {
3723
+ extra.ancestorUids = filters.ancestorUids.length === 0 ? "" : [...filters.ancestorUids];
3724
+ }
3725
+ if (filters.connectionIds !== void 0) {
3726
+ extra.connectionIds = filters.connectionIds.length === 0 ? "" : [...filters.connectionIds];
3727
+ }
2618
3728
  return aipListParams(pageSize, pageToken, extra);
2619
3729
  }
2620
3730
  function parseContextItem2(raw) {
@@ -2631,24 +3741,48 @@ var ManagementContextItemsResource = class {
2631
3741
  * @param options.pageSize - Items per page (default 25).
2632
3742
  * @param options.pageToken - Token from a previous page's `nextPageToken`.
2633
3743
  * @param options.contextType - Filter to one context type (for example `"note"`).
3744
+ * @param options.parentUids - Exact ordered native ancestry chain for direct
3745
+ * children. Omit to leave parent unrestricted; pass `[]` for the known-empty
3746
+ * root. Native UIDs are exact tokens; for a folder's children send ancestry
3747
+ * UIDs plus the last `dataPath` token, not the hashed context-item `uid`.
3748
+ * @param options.ancestorUids - Ordered UID ancestry prefix for strict
3749
+ * descendants. Omit to leave unrestricted; pass `[]` for every item with
3750
+ * non-null ancestry.
3751
+ * @param options.connectionIds - Restrict to these connection ids. Omit to
3752
+ * leave unfiltered; pass `[]` to match none. The Files root is
3753
+ * `connectionIds: ['files']` with `parentUids: []`.
2634
3754
  * @returns A page of context items.
3755
+ *
3756
+ * @example
3757
+ * ```ts
3758
+ * const rootFiles = await mgmt.context.items.list({
3759
+ * connectionIds: ['files'],
3760
+ * contextType: 'file_upload',
3761
+ * parentUids: [],
3762
+ * })
3763
+ * ```
2635
3764
  */
2636
3765
  list(options = {}) {
2637
3766
  const pageSize = options.pageSize ?? 25;
2638
3767
  validatePageSize(pageSize);
2639
- return this.listPage(pageSize, options.pageToken, options.contextType);
3768
+ return this.listPage(pageSize, options.pageToken, {
3769
+ contextType: options.contextType,
3770
+ parentUids: options.parentUids,
3771
+ ancestorUids: options.ancestorUids,
3772
+ connectionIds: options.connectionIds
3773
+ });
2640
3774
  }
2641
- async listPage(pageSize, pageToken, contextType) {
3775
+ async listPage(pageSize, pageToken, filters) {
2642
3776
  const data = asRecord(
2643
3777
  await invokeWithRetry(this.config, this.http, "ContextItemsController_list", {
2644
- query: contextListParams(pageSize, pageToken, contextType)
3778
+ query: contextListParams(pageSize, pageToken, filters)
2645
3779
  })
2646
3780
  );
2647
3781
  return buildAipPage(
2648
3782
  data,
2649
3783
  "contextItems",
2650
3784
  parseContextItem2,
2651
- (token) => this.listPage(pageSize, token, contextType)
3785
+ (token) => this.listPage(pageSize, token, filters)
2652
3786
  );
2653
3787
  }
2654
3788
  /**
@@ -2700,7 +3834,7 @@ var ManagementContextItemsResource = class {
2700
3834
  return this.get(uid);
2701
3835
  }
2702
3836
  /**
2703
- * Delete a context item.
3837
+ * Delete a context item. Deleting a Files folder also deletes all its contents.
2704
3838
  *
2705
3839
  * @param uid - Context item uid.
2706
3840
  * @returns Deletion confirmation details.
@@ -2711,6 +3845,44 @@ var ManagementContextItemsResource = class {
2711
3845
  });
2712
3846
  return data;
2713
3847
  }
3848
+ /**
3849
+ * Move a live file or Files folder.
3850
+ *
3851
+ * Pass `destinationFolderUid: null` to move to the Files root. The
3852
+ * destination folder must already exist. Same-parent moves succeed as a
3853
+ * no-op. Does not rename or merge folders.
3854
+ *
3855
+ * @param uid - Stored context-item uid of the file or folder to move.
3856
+ * @param options.destinationFolderUid - Stored context-item uid of the
3857
+ * destination folder, or `null` for the Files root.
3858
+ * @returns How many items changed parent (`0` is a successful no-op).
3859
+ * @throws {NotFoundError} The source is missing or not visible.
3860
+ * @throws {ModusError} The destination is missing, not a Files folder, or
3861
+ * the move would create a cycle (HTTP 400).
3862
+ * @throws {PermissionDeniedError} The destination exists but is not writable
3863
+ * for this caller.
3864
+ * @throws {ConflictError} A sibling with the same name already exists.
3865
+ *
3866
+ * @example
3867
+ * ```ts
3868
+ * const moved = await mgmt.context.items.move('PLACEHOLDER_UID', {
3869
+ * destinationFolderUid: 'PLACEHOLDER_FOLDER_UID',
3870
+ * })
3871
+ * console.log(moved.movedItems)
3872
+ * ```
3873
+ */
3874
+ async move(uid, options) {
3875
+ const data = await invokeWithRetry(
3876
+ this.config,
3877
+ this.http,
3878
+ "ContextItemsController_move",
3879
+ {
3880
+ pathParams: { uid },
3881
+ jsonBody: { destinationFolderUid: options.destinationFolderUid }
3882
+ }
3883
+ );
3884
+ return data;
3885
+ }
2714
3886
  };
2715
3887
 
2716
3888
  // src/management/context/context.ts
@@ -2722,6 +3894,7 @@ var ManagementContextResource = class {
2722
3894
  this.items = new ManagementContextItemsResource(http, config);
2723
3895
  this.customItems = new CustomContextItemsResource(http, config);
2724
3896
  this.files = new ManagementContextFilesResource(http, config);
3897
+ this.dashboards = new ManagementDashboardsResource(http, config);
2725
3898
  }
2726
3899
  /**
2727
3900
  * Add a free-form text note to the knowledge base.
@@ -2731,6 +3904,7 @@ var ManagementContextResource = class {
2731
3904
  * @returns The created context item.
2732
3905
  * @example
2733
3906
  * ```ts
3907
+ * const mgmt = new ModusManagement()
2734
3908
  * const note = await mgmt.context.createNote('Runbook', '# Steps\n1. Check logs')
2735
3909
  * ```
2736
3910
  */
@@ -2748,6 +3922,14 @@ var ManagementContextResource = class {
2748
3922
  * @param options.body - New markdown body.
2749
3923
  * @param options.existing - Optional cached item to avoid a GET.
2750
3924
  * @returns The updated context item.
3925
+ * @example
3926
+ * ```ts
3927
+ * const mgmt = new ModusManagement()
3928
+ * const item = await mgmt.context.updateNote('PLACEHOLDER_UID', {
3929
+ * title: 'Runbook',
3930
+ * body: '# Steps\n1. Check logs\n2. Escalate',
3931
+ * })
3932
+ * ```
2751
3933
  */
2752
3934
  updateNote(uid, options) {
2753
3935
  return resolveAndUpdateNote(this.items, uid, options);
@@ -2760,6 +3942,14 @@ var ManagementContextResource = class {
2760
3942
  * @param options.query - SQL text.
2761
3943
  * @param options.path - Optional hierarchy path segments.
2762
3944
  * @returns The created context item.
3945
+ * @example
3946
+ * ```ts
3947
+ * const mgmt = new ModusManagement()
3948
+ * const query = await mgmt.context.createSavedQuery('Monthly ARR', {
3949
+ * connectionId: 'conn_warehouse',
3950
+ * query: 'select * from arr_monthly',
3951
+ * })
3952
+ * ```
2763
3953
  */
2764
3954
  createSavedQuery(name, options) {
2765
3955
  return this.create(
@@ -2781,6 +3971,14 @@ var ManagementContextResource = class {
2781
3971
  * @param options.query - New SQL text.
2782
3972
  * @param options.existing - Optional cached item to avoid a GET.
2783
3973
  * @returns The updated context item.
3974
+ * @example
3975
+ * ```ts
3976
+ * const mgmt = new ModusManagement()
3977
+ * const item = await mgmt.context.updateSavedQuery('PLACEHOLDER_UID', {
3978
+ * name: 'Monthly ARR',
3979
+ * query: 'select sum(amount) from arr_monthly',
3980
+ * })
3981
+ * ```
2784
3982
  */
2785
3983
  updateSavedQuery(uid, options) {
2786
3984
  return resolveAndUpdateSavedQuery(this.items, uid, options);
@@ -2793,6 +3991,13 @@ var ManagementContextResource = class {
2793
3991
  * @param options.isCrawl - When true, crawl linked pages into context.
2794
3992
  * @param options.pageLimit - Maximum pages to crawl when `isCrawl` is true.
2795
3993
  * @returns The created context item.
3994
+ * @example
3995
+ * ```ts
3996
+ * const mgmt = new ModusManagement()
3997
+ * const link = await mgmt.context.createLink('https://docs.example.com/runbook', {
3998
+ * title: 'Ops runbook',
3999
+ * })
4000
+ * ```
2796
4001
  */
2797
4002
  createLink(url, options = {}) {
2798
4003
  return this.create(
@@ -2815,6 +4020,13 @@ var ManagementContextResource = class {
2815
4020
  * @param options.url - New URL.
2816
4021
  * @param options.existing - Optional cached item to avoid a GET.
2817
4022
  * @returns The updated context item.
4023
+ * @example
4024
+ * ```ts
4025
+ * const mgmt = new ModusManagement()
4026
+ * const item = await mgmt.context.updateLink('PLACEHOLDER_UID', {
4027
+ * title: 'Ops runbook (2025)',
4028
+ * })
4029
+ * ```
2818
4030
  */
2819
4031
  updateLink(uid, options) {
2820
4032
  return resolveAndUpdateLink(this.items, uid, options);
@@ -2846,26 +4058,44 @@ var ScopeConversationsResource = class {
2846
4058
  *
2847
4059
  * @param options.pageSize - Items per page (default 25).
2848
4060
  * @param options.pageToken - Opaque token from a previous page.
2849
- * @returns Page of conversation list items.
4061
+ * @param options.source - Restrict to conversations started from this UI surface
4062
+ * (e.g. `"context_chat"`, `"dashboard_copilot"`, `"slack"`).
4063
+ * @param options.sourceRef - Narrow `source` to one instance of that surface — for
4064
+ * `"dashboard_copilot"`, a dashboard id. Requires `source`; the API throws an
4065
+ * `UnprocessableError` (422) if sent on its own. Conversations recorded before
4066
+ * this filter shipped carry no instance key and never match it.
4067
+ * @returns Page of conversation list items (`threadId`, `firstMessage`, `messageCount`).
4068
+ *
4069
+ * @example
4070
+ * ```ts
4071
+ * for await (const row of (
4072
+ * await client.scopes.conversations(scopeId).list({ pageSize: 10 })
4073
+ * ).autoPagingIter()) {
4074
+ * console.log(row.threadId, row.firstMessage, row.messageCount)
4075
+ * }
4076
+ * ```
2850
4077
  */
2851
4078
  list(options = {}) {
2852
4079
  const pageSize = options.pageSize ?? 25;
2853
4080
  validatePageSize(pageSize);
2854
- return this.listPage(pageSize, options.pageToken);
4081
+ return this.listPage(pageSize, options.pageToken, options.source, options.sourceRef);
2855
4082
  }
2856
- async listPage(pageSize, pageToken) {
4083
+ async listPage(pageSize, pageToken, source, sourceRef) {
2857
4084
  validateId(this.scopeId, "scope_id");
4085
+ const extra = {};
4086
+ if (source !== void 0) extra.source = source;
4087
+ if (sourceRef !== void 0) extra.sourceRef = sourceRef;
2858
4088
  const data = asRecord(
2859
4089
  await invokeWithRetry(this.config, this.http, "ScopeConversationsController_list", {
2860
4090
  pathParams: { id: this.scopeId },
2861
- query: aipListParams(pageSize, pageToken)
4091
+ query: aipListParams(pageSize, pageToken, extra)
2862
4092
  })
2863
4093
  );
2864
4094
  return buildAipPage(
2865
4095
  data,
2866
4096
  "conversations",
2867
4097
  parseListItem,
2868
- (token) => this.listPage(pageSize, token)
4098
+ (token) => this.listPage(pageSize, token, source, sourceRef)
2869
4099
  );
2870
4100
  }
2871
4101
  /**
@@ -2874,7 +4104,15 @@ var ScopeConversationsResource = class {
2874
4104
  * @param threadId - Conversation thread id.
2875
4105
  * @param options.messageLimit - Maximum messages to return (1–100).
2876
4106
  * @param options.beforeMessageIndex - Return messages before this index (requires messageLimit).
2877
- * @returns Conversation with messages.
4107
+ * @returns Conversation with `messages` (`type`, `content`).
4108
+ *
4109
+ * @example
4110
+ * ```ts
4111
+ * const thread = await client.scopes.conversations(scopeId).get(row.threadId)
4112
+ * for (const msg of thread.messages) {
4113
+ * console.log(msg.type, String(msg.content).slice(0, 80))
4114
+ * }
4115
+ * ```
2878
4116
  */
2879
4117
  async get(threadId, options = {}) {
2880
4118
  validateId(this.scopeId, "scope_id");
@@ -3060,6 +4298,65 @@ var ScopeEvaluationsResource = class {
3060
4298
  }
3061
4299
  };
3062
4300
 
4301
+ // src/management/scopes/interfaces.ts
4302
+ var ScopeInterfacesResource = class {
4303
+ constructor(http, config, scopeId) {
4304
+ this.http = http;
4305
+ this.config = config;
4306
+ this.scopeId = scopeId;
4307
+ }
4308
+ /** List the Slack and Microsoft Teams interfaces on this scope. */
4309
+ async list() {
4310
+ validateId(this.scopeId, "scope_id");
4311
+ const data = await invokeWithRetry(this.config, this.http, "ScopeInterfacesController_list", {
4312
+ pathParams: { id: this.scopeId }
4313
+ });
4314
+ return data.interfaces;
4315
+ }
4316
+ /**
4317
+ * Add a Slack or Microsoft Teams interface to this scope.
4318
+ *
4319
+ * @param options - Interface type, optional name and config.
4320
+ * @returns The created interface.
4321
+ */
4322
+ async create(options) {
4323
+ validateId(this.scopeId, "scope_id");
4324
+ return await invokeWithRetry(this.config, this.http, "ScopeInterfacesController_add", {
4325
+ pathParams: { id: this.scopeId },
4326
+ jsonBody: omitUndefined(options)
4327
+ });
4328
+ }
4329
+ /**
4330
+ * Update an interface on this scope.
4331
+ *
4332
+ * @param interfaceId - Interface id.
4333
+ * @param options - Updated name and/or config.
4334
+ * @param updateMask - Optional comma-separated field names to update.
4335
+ * @returns The updated interface.
4336
+ */
4337
+ async update(interfaceId, options, updateMask) {
4338
+ validateId(this.scopeId, "scope_id");
4339
+ validateId(interfaceId, "interface_id");
4340
+ return await invokeWithRetry(this.config, this.http, "ScopeInterfacesController_update", {
4341
+ pathParams: { id: this.scopeId, interfaceId },
4342
+ query: updateMaskQuery(updateMask),
4343
+ jsonBody: updateMask === void 0 ? omitUndefined(options) : options
4344
+ });
4345
+ }
4346
+ /**
4347
+ * Remove an interface from this scope.
4348
+ *
4349
+ * @param interfaceId - Interface id.
4350
+ */
4351
+ async delete(interfaceId) {
4352
+ validateId(this.scopeId, "scope_id");
4353
+ validateId(interfaceId, "interface_id");
4354
+ await invokeWithRetry(this.config, this.http, "ScopeInterfacesController_delete", {
4355
+ pathParams: { id: this.scopeId, interfaceId }
4356
+ });
4357
+ }
4358
+ };
4359
+
3063
4360
  // src/management/scopes/supervision.ts
3064
4361
  var ScopeSupervisionResource = class {
3065
4362
  constructor(http, config, scopeId) {
@@ -3175,6 +4472,15 @@ var ManagementScopesResource = class {
3175
4472
  supervision(scopeId) {
3176
4473
  return new ScopeSupervisionResource(this.http, this.config, scopeId);
3177
4474
  }
4475
+ /**
4476
+ * Slack and Microsoft Teams interfaces for a scope.
4477
+ *
4478
+ * @param scopeId - Scope id.
4479
+ * @returns An interfaces resource scoped to the scope.
4480
+ */
4481
+ interfaces(scopeId) {
4482
+ return new ScopeInterfacesResource(this.http, this.config, scopeId);
4483
+ }
3178
4484
  /**
3179
4485
  * List scopes in the organization.
3180
4486
  *
@@ -3183,7 +4489,14 @@ var ManagementScopesResource = class {
3183
4489
  * @param options.search - Case-insensitive substring filter on the scope name.
3184
4490
  * @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
3185
4491
  * @param options.managerId - Return only scopes supervised by this manager scope id.
3186
- * @returns A page of scopes.
4492
+ * @returns A page of scopes — use `.autoPagingIter()` for all pages.
4493
+ * @example
4494
+ * ```ts
4495
+ * const mgmt = new ModusManagement()
4496
+ * for await (const scope of (await mgmt.scopes.list()).autoPagingIter()) {
4497
+ * console.log(scope.id, scope.name, scope.status)
4498
+ * }
4499
+ * ```
3187
4500
  */
3188
4501
  list(options = {}) {
3189
4502
  const pageSize = options.pageSize ?? 25;
@@ -3215,6 +4528,12 @@ var ManagementScopesResource = class {
3215
4528
  * @param scopeId - Scope id.
3216
4529
  * @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
3217
4530
  * @returns The scope.
4531
+ * @example
4532
+ * ```ts
4533
+ * const mgmt = new ModusManagement()
4534
+ * const scope = await mgmt.scopes.get('PLACEHOLDER_SCOPE_ID')
4535
+ * console.log(scope.name, scope.status)
4536
+ * ```
3218
4537
  */
3219
4538
  async get(scopeId, options = {}) {
3220
4539
  validateId(scopeId, "scope_id");
@@ -3233,11 +4552,14 @@ var ManagementScopesResource = class {
3233
4552
  * @param options.instructions - Optional system instructions.
3234
4553
  * @param options.model - Optional model id.
3235
4554
  * @param options.toolset - Optional tool selection for the scope.
4555
+ * @param options.includeOwnLearnings - Whether the scope reads what is taught while using it. Defaults to true.
3236
4556
  * @param options.guardrails - Runtime guardrail labels (for example `"no-pii"`). Omit to create with no guardrails.
3237
4557
  * @returns The created scope (draft).
3238
4558
  * @example
3239
4559
  * ```ts
4560
+ * const mgmt = new ModusManagement()
3240
4561
  * const scope = await mgmt.scopes.create({ name: 'Support assistant', model: 'claude-sonnet-5' })
4562
+ * console.log(scope.id, scope.name)
3241
4563
  * ```
3242
4564
  */
3243
4565
  async create(options) {
@@ -3250,6 +4572,7 @@ var ManagementScopesResource = class {
3250
4572
  model: options.model,
3251
4573
  connectionSet: options.connectionSet,
3252
4574
  contextSelections: options.contextSelections,
4575
+ includeOwnLearnings: options.includeOwnLearnings,
3253
4576
  interfaces: options.interfaces,
3254
4577
  accessConfig: accessConfigBodyForCreate(options.guardrails)
3255
4578
  });
@@ -3268,6 +4591,13 @@ var ManagementScopesResource = class {
3268
4591
  * @param options.guardrails - Guardrail labels to set. Fetches the current scope first to merge. Pass `[]` to clear all.
3269
4592
  * @param options.updateMask - Comma-separated field names to update or clear.
3270
4593
  * @returns The updated scope.
4594
+ * @example
4595
+ * ```ts
4596
+ * const mgmt = new ModusManagement()
4597
+ * const scope = await mgmt.scopes.update('PLACEHOLDER_SCOPE_ID', {
4598
+ * description: 'Answers billing questions for enterprise customers.',
4599
+ * })
4600
+ * ```
3271
4601
  */
3272
4602
  async update(scopeId, options = {}) {
3273
4603
  validateId(scopeId, "scope_id");
@@ -3309,8 +4639,10 @@ var ManagementScopesResource = class {
3309
4639
  * @returns The published scope.
3310
4640
  * @example
3311
4641
  * ```ts
3312
- * await mgmt.scopes.update(scopeId, { instructions: ['Be concise.'] })
3313
- * const published = await mgmt.scopes.deploy(scopeId)
4642
+ * const mgmt = new ModusManagement()
4643
+ * const scope = await mgmt.scopes.create({ name: 'Support assistant' })
4644
+ * const published = await mgmt.scopes.deploy(scope.id)
4645
+ * console.log(published.status)
3314
4646
  * ```
3315
4647
  */
3316
4648
  async deploy(scopeId) {
@@ -3328,6 +4660,11 @@ var ManagementScopesResource = class {
3328
4660
  *
3329
4661
  * @param scopeId - Scope id.
3330
4662
  * @returns Resolves when the scope is deleted.
4663
+ * @example
4664
+ * ```ts
4665
+ * const mgmt = new ModusManagement()
4666
+ * await mgmt.scopes.delete('PLACEHOLDER_SCOPE_ID')
4667
+ * ```
3331
4668
  */
3332
4669
  async delete(scopeId) {
3333
4670
  validateId(scopeId, "scope_id");