@getmodus/sdk 0.5.0 → 0.7.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.
@@ -216,7 +216,7 @@ function formatConfigForLog(config) {
216
216
  }
217
217
 
218
218
  // src/_http.ts
219
- var USER_AGENT = `modus-typescript/${"0.5.0"} (node/${process.version}; ${process.platform})`;
219
+ var USER_AGENT = `modus-typescript/${"0.7.0"} (node/${process.version}; ${process.platform})`;
220
220
  function buildUrl(baseUrl, path, params) {
221
221
  const url = new URL(path.startsWith("/") ? path : `/${path}`, baseUrl);
222
222
  if (params) {
@@ -592,6 +592,86 @@ var OPERATIONS = {
592
592
  requestSchema: "CreateSavedQueryDto",
593
593
  responseSchema: "CreatedContextItemResponseDto"
594
594
  },
595
+ "ContextFilesController_finalize": {
596
+ method: "POST",
597
+ path: "/api/v1/context/files/{uploadId}/finalize",
598
+ service: "modus-api",
599
+ serverUrl: "https://api.getmodus.com",
600
+ pathParams: ["uploadId"],
601
+ queryParams: [],
602
+ requestSchema: "FinalizeUploadDto",
603
+ responseSchema: "FileUploadResourceDto"
604
+ },
605
+ "ContextFilesController_finalizeMany": {
606
+ method: "POST",
607
+ path: "/api/v1/context/files/finalize",
608
+ service: "modus-api",
609
+ serverUrl: "https://api.getmodus.com",
610
+ pathParams: [],
611
+ queryParams: [],
612
+ requestSchema: "BulkFinalizeDto",
613
+ responseSchema: "BulkFinalizeResponseDto"
614
+ },
615
+ "ContextFilesController_get": {
616
+ method: "GET",
617
+ path: "/api/v1/context/files/{uploadId}",
618
+ service: "modus-api",
619
+ serverUrl: "https://api.getmodus.com",
620
+ pathParams: ["uploadId"],
621
+ queryParams: [],
622
+ requestSchema: null,
623
+ responseSchema: "FileUploadResourceDto"
624
+ },
625
+ "ContextFilesController_list": {
626
+ method: "GET",
627
+ path: "/api/v1/context/files",
628
+ service: "modus-api",
629
+ serverUrl: "https://api.getmodus.com",
630
+ pathParams: [],
631
+ queryParams: ["pageToken", "pageSize"],
632
+ requestSchema: null,
633
+ responseSchema: "ListFilesResponseDto"
634
+ },
635
+ "ContextFilesController_uploadFromUrl": {
636
+ method: "POST",
637
+ path: "/api/v1/context/files/uploadFromUrl",
638
+ service: "modus-api",
639
+ serverUrl: "https://api.getmodus.com",
640
+ pathParams: [],
641
+ queryParams: [],
642
+ requestSchema: "UploadFromUrlDto",
643
+ responseSchema: "FileUploadResourceDto"
644
+ },
645
+ "ContextFilesController_uploadFromUrls": {
646
+ method: "POST",
647
+ path: "/api/v1/context/files/uploadFromUrls",
648
+ service: "modus-api",
649
+ serverUrl: "https://api.getmodus.com",
650
+ pathParams: [],
651
+ queryParams: [],
652
+ requestSchema: "BulkUploadFromUrlsDto",
653
+ responseSchema: "BulkUploadFromUrlsResponseDto"
654
+ },
655
+ "ContextFilesController_uploadUrl": {
656
+ method: "POST",
657
+ path: "/api/v1/context/files/uploadUrl",
658
+ service: "modus-api",
659
+ serverUrl: "https://api.getmodus.com",
660
+ pathParams: [],
661
+ queryParams: [],
662
+ requestSchema: "UploadUrlDto",
663
+ responseSchema: "UploadUrlResponseDto"
664
+ },
665
+ "ContextFilesController_uploadUrls": {
666
+ method: "POST",
667
+ path: "/api/v1/context/files/uploadUrls",
668
+ service: "modus-api",
669
+ serverUrl: "https://api.getmodus.com",
670
+ pathParams: [],
671
+ queryParams: [],
672
+ requestSchema: "BulkUploadUrlsDto",
673
+ responseSchema: "BulkUploadUrlsResponseDto"
674
+ },
595
675
  "ContextItemsController_delete": {
596
676
  method: "DELETE",
597
677
  path: "/api/v1/context/items/{uid}",
@@ -672,6 +752,16 @@ var OPERATIONS = {
672
752
  requestSchema: "CreateCustomContextItemDto",
673
753
  responseSchema: "CreatedCustomContextItemResponseDto"
674
754
  },
755
+ "CustomContextItemsController_createRelations": {
756
+ method: "POST",
757
+ path: "/api/v1/context/custom-items/relations",
758
+ service: "modus-api",
759
+ serverUrl: "https://api.getmodus.com",
760
+ pathParams: [],
761
+ queryParams: [],
762
+ requestSchema: "BatchCreateCustomContextItemRelationsDto",
763
+ responseSchema: "BatchCreateCustomContextItemRelationsResponseDto"
764
+ },
675
765
  "CustomContextItemsController_delete": {
676
766
  method: "DELETE",
677
767
  path: "/api/v1/context/custom-items/{uid}",
@@ -712,6 +802,196 @@ var OPERATIONS = {
712
802
  requestSchema: "UpdateCustomContextItemDto",
713
803
  responseSchema: null
714
804
  },
805
+ "DashboardsController_acceptOwnership": {
806
+ method: "POST",
807
+ path: "/api/v1/context/dashboards/{dashboardId}/transfer-ownership/accept",
808
+ service: "modus-api",
809
+ serverUrl: "https://api.getmodus.com",
810
+ pathParams: ["dashboardId"],
811
+ queryParams: [],
812
+ requestSchema: null,
813
+ responseSchema: "DashboardDto"
814
+ },
815
+ "DashboardsController_cancelOwnership": {
816
+ method: "DELETE",
817
+ path: "/api/v1/context/dashboards/{dashboardId}/transfer-ownership",
818
+ service: "modus-api",
819
+ serverUrl: "https://api.getmodus.com",
820
+ pathParams: ["dashboardId"],
821
+ queryParams: [],
822
+ requestSchema: null,
823
+ responseSchema: "DashboardDto"
824
+ },
825
+ "DashboardsController_create": {
826
+ method: "POST",
827
+ path: "/api/v1/context/dashboards",
828
+ service: "modus-api",
829
+ serverUrl: "https://api.getmodus.com",
830
+ pathParams: [],
831
+ queryParams: [],
832
+ requestSchema: "CreateDashboardDto",
833
+ responseSchema: "DashboardDto"
834
+ },
835
+ "DashboardsController_createElement": {
836
+ method: "POST",
837
+ path: "/api/v1/context/dashboards/{dashboardId}/elements",
838
+ service: "modus-api",
839
+ serverUrl: "https://api.getmodus.com",
840
+ pathParams: ["dashboardId"],
841
+ queryParams: [],
842
+ requestSchema: "CreateDashboardElementDto",
843
+ responseSchema: "DashboardElementResponseDto"
844
+ },
845
+ "DashboardsController_delete": {
846
+ method: "DELETE",
847
+ path: "/api/v1/context/dashboards/{dashboardId}",
848
+ service: "modus-api",
849
+ serverUrl: "https://api.getmodus.com",
850
+ pathParams: ["dashboardId"],
851
+ queryParams: [],
852
+ requestSchema: null,
853
+ responseSchema: null
854
+ },
855
+ "DashboardsController_get": {
856
+ method: "GET",
857
+ path: "/api/v1/context/dashboards/{dashboardId}",
858
+ service: "modus-api",
859
+ serverUrl: "https://api.getmodus.com",
860
+ pathParams: ["dashboardId"],
861
+ queryParams: ["view"],
862
+ requestSchema: null,
863
+ responseSchema: "DashboardDto"
864
+ },
865
+ "DashboardsController_getElement": {
866
+ method: "GET",
867
+ path: "/api/v1/context/dashboards/{dashboardId}/elements/{elementId}",
868
+ service: "modus-api",
869
+ serverUrl: "https://api.getmodus.com",
870
+ pathParams: ["dashboardId", "elementId"],
871
+ queryParams: [],
872
+ requestSchema: null,
873
+ responseSchema: "DashboardElementResponseDto"
874
+ },
875
+ "DashboardsController_getVersion": {
876
+ method: "GET",
877
+ path: "/api/v1/context/dashboards/{dashboardId}/versions/{versionId}",
878
+ service: "modus-api",
879
+ serverUrl: "https://api.getmodus.com",
880
+ pathParams: ["dashboardId", "versionId"],
881
+ queryParams: [],
882
+ requestSchema: null,
883
+ responseSchema: "DashboardDto"
884
+ },
885
+ "DashboardsController_list": {
886
+ method: "GET",
887
+ path: "/api/v1/context/dashboards",
888
+ service: "modus-api",
889
+ serverUrl: "https://api.getmodus.com",
890
+ pathParams: [],
891
+ queryParams: ["view"],
892
+ requestSchema: null,
893
+ responseSchema: "ListDashboardsResponseDto"
894
+ },
895
+ "DashboardsController_listDraftSnapshots": {
896
+ method: "GET",
897
+ path: "/api/v1/context/dashboards/{dashboardId}/draft-snapshots",
898
+ service: "modus-api",
899
+ serverUrl: "https://api.getmodus.com",
900
+ pathParams: ["dashboardId"],
901
+ queryParams: [],
902
+ requestSchema: null,
903
+ responseSchema: "ListDashboardDraftSnapshotsResponseDto"
904
+ },
905
+ "DashboardsController_listElements": {
906
+ method: "GET",
907
+ path: "/api/v1/context/dashboards/{dashboardId}/elements",
908
+ service: "modus-api",
909
+ serverUrl: "https://api.getmodus.com",
910
+ pathParams: ["dashboardId"],
911
+ queryParams: [],
912
+ requestSchema: null,
913
+ responseSchema: "DashboardElementsListResponseDto"
914
+ },
915
+ "DashboardsController_listVersions": {
916
+ method: "GET",
917
+ path: "/api/v1/context/dashboards/{dashboardId}/versions",
918
+ service: "modus-api",
919
+ serverUrl: "https://api.getmodus.com",
920
+ pathParams: ["dashboardId"],
921
+ queryParams: [],
922
+ requestSchema: null,
923
+ responseSchema: "ListDashboardVersionsResponseDto"
924
+ },
925
+ "DashboardsController_publish": {
926
+ method: "POST",
927
+ path: "/api/v1/context/dashboards/{dashboardId}/publish",
928
+ service: "modus-api",
929
+ serverUrl: "https://api.getmodus.com",
930
+ pathParams: ["dashboardId"],
931
+ queryParams: [],
932
+ requestSchema: "PublishDashboardDto",
933
+ responseSchema: "PublishDashboardResponseDto"
934
+ },
935
+ "DashboardsController_restore": {
936
+ method: "POST",
937
+ path: "/api/v1/context/dashboards/{dashboardId}/versions/{versionId}/restore",
938
+ service: "modus-api",
939
+ serverUrl: "https://api.getmodus.com",
940
+ pathParams: ["dashboardId", "versionId"],
941
+ queryParams: [],
942
+ requestSchema: null,
943
+ responseSchema: "DashboardDto"
944
+ },
945
+ "DashboardsController_transferOwnership": {
946
+ method: "POST",
947
+ path: "/api/v1/context/dashboards/{dashboardId}/transfer-ownership",
948
+ service: "modus-api",
949
+ serverUrl: "https://api.getmodus.com",
950
+ pathParams: ["dashboardId"],
951
+ queryParams: [],
952
+ requestSchema: "TransferDashboardOwnershipDto",
953
+ responseSchema: "DashboardDto"
954
+ },
955
+ "DashboardsController_updateAccess": {
956
+ method: "PATCH",
957
+ path: "/api/v1/context/dashboards/{dashboardId}/access",
958
+ service: "modus-api",
959
+ serverUrl: "https://api.getmodus.com",
960
+ pathParams: ["dashboardId"],
961
+ queryParams: [],
962
+ requestSchema: "UpdateDashboardAccessDto",
963
+ responseSchema: "DashboardDto"
964
+ },
965
+ "DashboardsController_updateDraft": {
966
+ method: "PATCH",
967
+ path: "/api/v1/context/dashboards/{dashboardId}/draft",
968
+ service: "modus-api",
969
+ serverUrl: "https://api.getmodus.com",
970
+ pathParams: ["dashboardId"],
971
+ queryParams: [],
972
+ requestSchema: "UpdateDashboardDraftDto",
973
+ responseSchema: "DashboardDto"
974
+ },
975
+ "DashboardsController_updateElement": {
976
+ method: "PATCH",
977
+ path: "/api/v1/context/dashboards/{dashboardId}/elements/{elementId}",
978
+ service: "modus-api",
979
+ serverUrl: "https://api.getmodus.com",
980
+ pathParams: ["dashboardId", "elementId"],
981
+ queryParams: [],
982
+ requestSchema: "UpdateDashboardElementDto",
983
+ responseSchema: "DashboardDto"
984
+ },
985
+ "DashboardsController_updateLayout": {
986
+ method: "PATCH",
987
+ path: "/api/v1/context/dashboards/{dashboardId}/layout",
988
+ service: "modus-api",
989
+ serverUrl: "https://api.getmodus.com",
990
+ pathParams: ["dashboardId"],
991
+ queryParams: [],
992
+ requestSchema: "UpdateDashboardLayoutDto",
993
+ responseSchema: "DashboardDto"
994
+ },
715
995
  "EvaluationsController_getConfig": {
716
996
  method: "GET",
717
997
  path: "/api/v1/scopes/{id}/evaluations/config",
@@ -762,6 +1042,16 @@ var OPERATIONS = {
762
1042
  requestSchema: "UpdateEvaluationConfigDto",
763
1043
  responseSchema: "EvaluationConfigDto"
764
1044
  },
1045
+ "IngestedDataController_upload": {
1046
+ method: "POST",
1047
+ path: "/api/v1/ingested-data",
1048
+ service: "modus-api",
1049
+ serverUrl: "https://api.getmodus.com",
1050
+ pathParams: [],
1051
+ queryParams: [],
1052
+ requestSchema: "CreateIngestedDataDto",
1053
+ responseSchema: "CreatedIngestedDataResponseDto"
1054
+ },
765
1055
  "MemberGroupsController_list": {
766
1056
  method: "GET",
767
1057
  path: "/api/v1/users/member-groups",
@@ -818,7 +1108,7 @@ var OPERATIONS = {
818
1108
  service: "modus-api",
819
1109
  serverUrl: "https://api.getmodus.com",
820
1110
  pathParams: [],
821
- queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "timeframe", "includeTools", "kind"],
1111
+ queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "sourceRef", "timeframe", "includeTools", "kind"],
822
1112
  requestSchema: null,
823
1113
  responseSchema: "ListConversationsResponseDto"
824
1114
  },
@@ -968,7 +1258,7 @@ var OPERATIONS = {
968
1258
  service: "modus-api",
969
1259
  serverUrl: "https://api.getmodus.com",
970
1260
  pathParams: ["id"],
971
- queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "timeframe", "includeTools"],
1261
+ queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "sourceRef", "timeframe", "includeTools"],
972
1262
  requestSchema: null,
973
1263
  responseSchema: "ListConversationsResponseDto"
974
1264
  },
@@ -1521,12 +1811,28 @@ var WRITE_BODY_ALLOWED_KEYS = {
1521
1811
  ContextCreatorsController_createLink: ["url", "title", "isCrawl", "pageLimit"],
1522
1812
  ContextCreatorsController_createNote: ["title", "content"],
1523
1813
  ContextCreatorsController_createSavedQuery: ["name", "connectionId", "query", "description", "path"],
1814
+ ContextFilesController_finalize: ["fileName", "folderPath"],
1815
+ ContextFilesController_finalizeMany: ["uploads"],
1816
+ ContextFilesController_uploadFromUrl: ["url", "fileName", "folderPath"],
1817
+ ContextFilesController_uploadFromUrls: ["urls"],
1818
+ ContextFilesController_uploadUrl: ["fileName", "contentType", "fileSize"],
1819
+ ContextFilesController_uploadUrls: ["files"],
1524
1820
  ContextItemsController_lookup: ["contextType", "dataPath", "contentProjection"],
1525
1821
  ContextItemsController_update: ["contextType", "content", "description", "userFeedback", "topics"],
1526
1822
  CustomContextItemsController_batchCreate: ["items"],
1527
1823
  CustomContextItemsController_create: ["kind", "sourceId", "sourceName", "collectionId", "collectionName", "externalId", "fieldName", "name", "entityType", "description", "content", "url", "attributes", "dataType", "value", "samples", "raw", "topics", "idempotencyKey", "access"],
1824
+ CustomContextItemsController_createRelations: ["relations"],
1528
1825
  CustomContextItemsController_update: ["name", "entityType", "description", "content", "url", "attributes", "dataType", "value", "samples", "raw", "topics"],
1826
+ DashboardsController_create: ["title", "description", "definition", "access"],
1827
+ DashboardsController_createElement: ["expectedRevision", "kind", "title", "layout"],
1828
+ DashboardsController_publish: ["expectedRevision"],
1829
+ DashboardsController_transferOwnership: ["newOwnerUserId"],
1830
+ DashboardsController_updateAccess: ["visibility", "groupPermissions", "sharedWith"],
1831
+ DashboardsController_updateDraft: ["expectedRevision", "title", "description", "definition"],
1832
+ DashboardsController_updateElement: ["expectedRevision", "patch"],
1833
+ DashboardsController_updateLayout: ["expectedRevision", "elements"],
1529
1834
  EvaluationsController_updateConfig: ["enabled", "cadence", "judgeModel", "judgeGuidance", "notifications"],
1835
+ IngestedDataController_upload: ["integration_type", "request", "response"],
1530
1836
  ModusChatController_chat: ["message", "model"],
1531
1837
  ModusContextController_compose: ["message", "limit"],
1532
1838
  ModusRunsController_create: ["message", "sessionId", "organizationId", "version", "fileThreadId", "config", "attachments", "userContext", "source", "runId", "subordinateSkillIds"],
@@ -1755,6 +2061,13 @@ var ManagementWorkflowsResource = class {
1755
2061
  * @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
1756
2062
  * @param options.includeVariation - Include variation payload on each list row.
1757
2063
  * @returns A page of workflows.
2064
+ * @example
2065
+ * ```ts
2066
+ * const mgmt = new ModusManagement()
2067
+ * for await (const wf of (await mgmt.workflows.list({ search: 'digest' })).autoPagingIter()) {
2068
+ * console.log(wf.id, wf.name, wf.status)
2069
+ * }
2070
+ * ```
1758
2071
  */
1759
2072
  list(options = {}) {
1760
2073
  const pageSize = options.pageSize ?? 25;
@@ -1787,6 +2100,12 @@ var ManagementWorkflowsResource = class {
1787
2100
  * @param workflowId - Workflow id.
1788
2101
  * @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
1789
2102
  * @returns The workflow.
2103
+ * @example
2104
+ * ```ts
2105
+ * const mgmt = new ModusManagement()
2106
+ * const wf = await mgmt.workflows.get('weekly-digest')
2107
+ * console.log(wf.name, wf.status)
2108
+ * ```
1790
2109
  */
1791
2110
  async get(workflowId, options = {}) {
1792
2111
  validateId(workflowId, "workflow_id");
@@ -1816,7 +2135,8 @@ var ManagementWorkflowsResource = class {
1816
2135
  * @returns The created workflow (draft).
1817
2136
  * @example
1818
2137
  * ```ts
1819
- * const wf = await mgmt.workflows.create({ name: 'Daily report', type: WorkflowType.Task })
2138
+ * const mgmt = new ModusManagement()
2139
+ * const wf = await mgmt.workflows.create({ name: 'Daily report', type: 'task' })
1820
2140
  * ```
1821
2141
  */
1822
2142
  async create(options) {
@@ -1844,6 +2164,11 @@ var ManagementWorkflowsResource = class {
1844
2164
  * @param options.guardrails - Guardrail labels to set. Fetches the current workflow first to merge. Pass `[]` to clear all.
1845
2165
  * @param options.updateMask - Comma-separated field names to update or clear.
1846
2166
  * @returns The updated workflow.
2167
+ * @example
2168
+ * ```ts
2169
+ * const mgmt = new ModusManagement()
2170
+ * const wf = await mgmt.workflows.update('PLACEHOLDER_WORKFLOW_ID', { description: 'Runs every morning' })
2171
+ * ```
1847
2172
  */
1848
2173
  async update(workflowId, options = {}) {
1849
2174
  validateId(workflowId, "workflow_id");
@@ -1879,8 +2204,9 @@ var ManagementWorkflowsResource = class {
1879
2204
  * @returns The published workflow.
1880
2205
  * @example
1881
2206
  * ```ts
1882
- * await mgmt.workflows.update(workflowId, { description: 'Runs every morning' })
1883
- * const published = await mgmt.workflows.deploy(workflowId)
2207
+ * const mgmt = new ModusManagement()
2208
+ * await mgmt.workflows.update('PLACEHOLDER_WORKFLOW_ID', { description: 'Runs every morning' })
2209
+ * const published = await mgmt.workflows.deploy('PLACEHOLDER_WORKFLOW_ID')
1884
2210
  * ```
1885
2211
  */
1886
2212
  async deploy(workflowId) {
@@ -1913,6 +2239,11 @@ var ManagementWorkflowsResource = class {
1913
2239
  *
1914
2240
  * @param workflowId - Workflow id.
1915
2241
  * @returns Resolves when the workflow is deleted.
2242
+ * @example
2243
+ * ```ts
2244
+ * const mgmt = new ModusManagement()
2245
+ * await mgmt.workflows.delete('PLACEHOLDER_WORKFLOW_ID')
2246
+ * ```
1916
2247
  */
1917
2248
  async delete(workflowId) {
1918
2249
  validateId(workflowId, "workflow_id");
@@ -2018,6 +2349,12 @@ var CustomContextItemsResource = class {
2018
2349
  * @param options.searchQuery - Free-text search filter.
2019
2350
  * @param options.topics - Filter to items tagged with any of these topics.
2020
2351
  * @returns A page of custom context items.
2352
+ * @example
2353
+ * ```ts
2354
+ * const client = new Modus()
2355
+ * const page = await client.context.customItems.list({ pageSize: 25 })
2356
+ * for (const item of page.items) console.log(item.uid, item.contextType)
2357
+ * ```
2021
2358
  */
2022
2359
  list(options = {}) {
2023
2360
  const pageSize = options.pageSize ?? 25;
@@ -2046,6 +2383,11 @@ var CustomContextItemsResource = class {
2046
2383
  * @param uid - Item uid.
2047
2384
  * @returns The custom context item.
2048
2385
  * @throws {NotFoundError} When no item matches the uid.
2386
+ * @example
2387
+ * ```ts
2388
+ * const client = new Modus()
2389
+ * const item = await client.context.customItems.get('PLACEHOLDER_UID')
2390
+ * ```
2049
2391
  */
2050
2392
  async get(uid) {
2051
2393
  return parseContextItem(
@@ -2066,6 +2408,7 @@ var CustomContextItemsResource = class {
2066
2408
  *
2067
2409
  * @example
2068
2410
  * ```ts
2411
+ * const client = new Modus()
2069
2412
  * const created = await client.context.customItems.create({
2070
2413
  * kind: 'entity',
2071
2414
  * sourceId: 'my-source',
@@ -2089,6 +2432,7 @@ var CustomContextItemsResource = class {
2089
2432
  *
2090
2433
  * @example
2091
2434
  * ```ts
2435
+ * const client = new Modus()
2092
2436
  * const created = await client.context.customItems.batchCreate([
2093
2437
  * { kind: 'field', sourceId: 'src', fieldName: 'region', dataType: 'string' },
2094
2438
  * { kind: 'field', sourceId: 'src', fieldName: 'amount', dataType: 'number' },
@@ -2106,12 +2450,45 @@ var CustomContextItemsResource = class {
2106
2450
  const items = data.contextItems;
2107
2451
  return Array.isArray(items) ? items.map(parseCreatedCustomContextItem) : [];
2108
2452
  }
2453
+ /**
2454
+ * Create or update typed relations between context items.
2455
+ *
2456
+ * @param relations - Relations with source and target item uids, a snake_case type, and optional content.
2457
+ * @returns Number of relations created or updated.
2458
+ * @example
2459
+ * ```ts
2460
+ * const client = new Modus()
2461
+ * await client.context.customItems.createRelations([{
2462
+ * fromUid: 'SOURCE_UID',
2463
+ * toUid: 'TARGET_UID',
2464
+ * relationType: 'depends_on',
2465
+ * }])
2466
+ * ```
2467
+ */
2468
+ async createRelations(relations) {
2469
+ const data = asRecord(
2470
+ await invokeWithRetry(
2471
+ this.config,
2472
+ this.http,
2473
+ "CustomContextItemsController_createRelations",
2474
+ { jsonBody: { relations } }
2475
+ )
2476
+ );
2477
+ return data.upsertedCount;
2478
+ }
2109
2479
  /**
2110
2480
  * Update a custom context item.
2111
2481
  *
2112
2482
  * @param uid - Item uid.
2113
2483
  * @param input - Fields to change (kind and hierarchy ids cannot be changed).
2114
2484
  * @returns The updated item uid.
2485
+ * @example
2486
+ * ```ts
2487
+ * const client = new Modus()
2488
+ * await client.context.customItems.update('PLACEHOLDER_UID', {
2489
+ * description: 'Updated summary',
2490
+ * })
2491
+ * ```
2115
2492
  */
2116
2493
  async update(uid, input) {
2117
2494
  return asRecord(
@@ -2126,6 +2503,11 @@ var CustomContextItemsResource = class {
2126
2503
  *
2127
2504
  * @param uid - Item uid.
2128
2505
  * @returns Deletion confirmation with uid and context type.
2506
+ * @example
2507
+ * ```ts
2508
+ * const client = new Modus()
2509
+ * const result = await client.context.customItems.delete('PLACEHOLDER_UID')
2510
+ * ```
2129
2511
  */
2130
2512
  async delete(uid) {
2131
2513
  return parseDeletion(
@@ -2219,60 +2601,1065 @@ async function resolveAndUpdateLink(items, uid, options) {
2219
2601
  });
2220
2602
  }
2221
2603
 
2222
- // src/management/context/items.ts
2223
- function contextListParams(pageSize, pageToken, contextType) {
2224
- const extra = {};
2225
- if (contextType !== void 0) extra.contextTypes = [contextType];
2226
- return aipListParams(pageSize, pageToken, extra);
2227
- }
2228
- function parseContextItem2(raw) {
2229
- return raw;
2230
- }
2231
- var ManagementContextItemsResource = class {
2232
- constructor(http, config) {
2604
+ // src/management/context/dashboards.ts
2605
+ var ManagementDashboardElementsResource = class {
2606
+ /** @internal */
2607
+ constructor(http, config, dashboardId) {
2233
2608
  this.http = http;
2234
2609
  this.config = config;
2610
+ this.dashboardId = dashboardId;
2235
2611
  }
2236
2612
  /**
2237
- * List context items in the knowledge base.
2613
+ * List every tile and filter on the dashboard draft.
2238
2614
  *
2239
- * @param options.pageSize - Items per page (default 25).
2240
- * @param options.pageToken - Token from a previous page's `nextPageToken`.
2241
- * @param options.contextType - Filter to one context type (for example `"note"`).
2242
- * @returns A page of context items.
2615
+ * @returns Each element's id, kind, title and grid position, plus the current
2616
+ * `draftRevision` to pass as `expectedRevision` on the next change.
2617
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2618
+ * @example
2619
+ * ```ts
2620
+ * const listed = await mgmt.context.dashboards.elements('DASHBOARD_ID').list()
2621
+ * listed.elements.map((element) => element.id)
2622
+ * ```
2243
2623
  */
2244
- list(options = {}) {
2245
- const pageSize = options.pageSize ?? 25;
2246
- validatePageSize(pageSize);
2247
- return this.listPage(pageSize, options.pageToken, options.contextType);
2248
- }
2249
- async listPage(pageSize, pageToken, contextType) {
2250
- const data = asRecord(
2251
- await invokeWithRetry(this.config, this.http, "ContextItemsController_list", {
2252
- query: contextListParams(pageSize, pageToken, contextType)
2624
+ async list() {
2625
+ return asRecord(
2626
+ await invokeWithRetry(this.config, this.http, "DashboardsController_listElements", {
2627
+ pathParams: { dashboardId: this.dashboardId }
2253
2628
  })
2254
2629
  );
2255
- return buildAipPage(
2256
- data,
2257
- "contextItems",
2258
- parseContextItem2,
2259
- (token) => this.listPage(pageSize, token, contextType)
2260
- );
2261
2630
  }
2262
2631
  /**
2263
- * Retrieve one context item by uid.
2632
+ * Get the full draft settings of one tile or filter.
2264
2633
  *
2265
- * @param uid - Context item uid.
2266
- * @returns The context item.
2634
+ * @param elementId - Id of the tile or filter, as returned by `list()`.
2635
+ * @returns The element's settings and the current `draftRevision`.
2636
+ * @throws NotFoundError - The dashboard or the element does not exist, or you cannot
2637
+ * edit the dashboard.
2638
+ * @example
2639
+ * ```ts
2640
+ * const result = await mgmt.context.dashboards.elements('DASHBOARD_ID').get('ELEMENT_ID')
2641
+ * result.element.title
2642
+ * ```
2267
2643
  */
2268
- async get(uid) {
2269
- const data = await invokeWithRetry(this.config, this.http, "ContextItemsController_get", {
2270
- pathParams: { uid }
2271
- });
2272
- return parseContextItem2(data);
2644
+ async get(elementId) {
2645
+ validateId(elementId, "elementId");
2646
+ return asRecord(
2647
+ await invokeWithRetry(this.config, this.http, "DashboardsController_getElement", {
2648
+ pathParams: { dashboardId: this.dashboardId, elementId }
2649
+ })
2650
+ );
2273
2651
  }
2274
2652
  /**
2275
- * Update a context item.
2653
+ * Add a blank tile or filter to the dashboard draft.
2654
+ *
2655
+ * Modus assigns the new element's id; configure it afterwards with `update()`.
2656
+ *
2657
+ * @param input.expectedRevision - The `draftRevision` your change is based on.
2658
+ * @param input.kind - `chart`, `kpi`, `table`, `markdown` or `filter`.
2659
+ * @param input.title - Title shown on the element.
2660
+ * @param input.layout - Grid position with `x` (0-11), `y`, `w` (1-12) and `h`.
2661
+ * @returns The created element and the new `draftRevision`.
2662
+ * @throws ConflictError - The draft changed since `expectedRevision`; list the
2663
+ * elements again and retry with the new revision.
2664
+ * @example
2665
+ * ```ts
2666
+ * const created = await mgmt.context.dashboards.elements('DASHBOARD_ID').create({
2667
+ * expectedRevision: 3,
2668
+ * kind: 'chart',
2669
+ * title: 'Sales by region',
2670
+ * layout: { x: 0, y: 4, w: 6, h: 4 },
2671
+ * })
2672
+ * ```
2673
+ */
2674
+ async create(input) {
2675
+ return asRecord(
2676
+ await invokeWithRetry(this.config, this.http, "DashboardsController_createElement", {
2677
+ pathParams: { dashboardId: this.dashboardId },
2678
+ jsonBody: {
2679
+ expectedRevision: input.expectedRevision,
2680
+ kind: input.kind,
2681
+ title: input.title,
2682
+ layout: input.layout
2683
+ }
2684
+ })
2685
+ );
2686
+ }
2687
+ /**
2688
+ * Change settings of one tile or filter on the dashboard draft.
2689
+ *
2690
+ * @param elementId - Id of the tile or filter to change.
2691
+ * @param input.expectedRevision - The `draftRevision` your change is based on.
2692
+ * @param input.patch - The settings to change, for example `{ title: 'Sales' }`
2693
+ * or `{ defaultValue: null }`. `null` clears a setting that supports clearing.
2694
+ * @returns The whole dashboard after the change, including the new `draftRevision`.
2695
+ * @throws ConflictError - The draft changed since `expectedRevision`.
2696
+ * @throws NotFoundError - The dashboard or the element does not exist, or you cannot
2697
+ * edit the dashboard.
2698
+ * @example
2699
+ * ```ts
2700
+ * const dashboard = await mgmt.context.dashboards
2701
+ * .elements('DASHBOARD_ID')
2702
+ * .update('ELEMENT_ID', { expectedRevision: 3, patch: { title: 'Revenue' } })
2703
+ * ```
2704
+ */
2705
+ async update(elementId, input) {
2706
+ validateId(elementId, "elementId");
2707
+ return asRecord(
2708
+ await invokeWithRetry(this.config, this.http, "DashboardsController_updateElement", {
2709
+ pathParams: { dashboardId: this.dashboardId, elementId },
2710
+ jsonBody: { expectedRevision: input.expectedRevision, patch: input.patch }
2711
+ })
2712
+ );
2713
+ }
2714
+ };
2715
+ var ManagementDashboardsResource = class {
2716
+ /** @internal */
2717
+ constructor(http, config) {
2718
+ this.http = http;
2719
+ this.config = config;
2720
+ }
2721
+ /**
2722
+ * List dashboards with their full definitions.
2723
+ *
2724
+ * @param options.view - `active` (default) lists published dashboards you can open;
2725
+ * `draft` lists the drafts of dashboards you can edit.
2726
+ * @returns Every matching dashboard. The list is not paginated.
2727
+ * @example
2728
+ * ```ts
2729
+ * const drafts = await mgmt.context.dashboards.list({ view: 'draft' })
2730
+ * drafts.map((dashboard) => [dashboard.id, dashboard.draftRevision])
2731
+ * ```
2732
+ */
2733
+ async list(options = {}) {
2734
+ const data = asRecord(
2735
+ await invokeWithRetry(this.config, this.http, "DashboardsController_list", {
2736
+ query: { view: options.view }
2737
+ })
2738
+ );
2739
+ return data.dashboards;
2740
+ }
2741
+ /**
2742
+ * Get one dashboard with its full definition.
2743
+ *
2744
+ * @param dashboardId - Id of the dashboard.
2745
+ * @param options.view - `active` (default) returns the published version; `draft`
2746
+ * returns the working draft and requires edit access.
2747
+ * @returns The dashboard, including `draftRevision` for the next change.
2748
+ * @throws NotFoundError - The dashboard does not exist or you cannot open it.
2749
+ * @example
2750
+ * ```ts
2751
+ * const draft = await mgmt.context.dashboards.get('DASHBOARD_ID', { view: 'draft' })
2752
+ * draft.draftRevision
2753
+ * ```
2754
+ */
2755
+ async get(dashboardId, options = {}) {
2756
+ validateId(dashboardId, "dashboardId");
2757
+ return asRecord(
2758
+ await invokeWithRetry(this.config, this.http, "DashboardsController_get", {
2759
+ pathParams: { dashboardId },
2760
+ query: { view: options.view }
2761
+ })
2762
+ );
2763
+ }
2764
+ /**
2765
+ * Create a dashboard draft.
2766
+ *
2767
+ * The new dashboard is not visible to others until you `publish()` it.
2768
+ *
2769
+ * @param input.title - Dashboard title.
2770
+ * @param input.definition - Tiles, filters and layout, for example
2771
+ * `{ tiles: [], filters: [] }`. Element ids must be unique.
2772
+ * @param input.description - Optional dashboard description.
2773
+ * @param input.access - Optional `visibility`, `groupPermissions` and `sharedWith`.
2774
+ * Defaults to private.
2775
+ * @returns The created dashboard in its draft view.
2776
+ * @throws ModusError - The definition or access settings are invalid.
2777
+ * @example
2778
+ * ```ts
2779
+ * const dashboard = await mgmt.context.dashboards.create({
2780
+ * title: 'Revenue',
2781
+ * definition: { tiles: [], filters: [] },
2782
+ * })
2783
+ * dashboard.id
2784
+ * ```
2785
+ */
2786
+ async create(input) {
2787
+ return asRecord(
2788
+ await invokeWithRetry(this.config, this.http, "DashboardsController_create", {
2789
+ jsonBody: {
2790
+ title: input.title,
2791
+ description: input.description,
2792
+ definition: input.definition,
2793
+ access: input.access
2794
+ }
2795
+ })
2796
+ );
2797
+ }
2798
+ /**
2799
+ * Replace the whole draft definition, and optionally the title and description.
2800
+ *
2801
+ * @param dashboardId - Id of the dashboard.
2802
+ * @param input.expectedRevision - The `draftRevision` your change is based on.
2803
+ * @param input.definition - The complete new definition. Tiles and filters left
2804
+ * out are removed.
2805
+ * @param input.title - New title; unchanged when omitted.
2806
+ * @param input.description - New description; unchanged when omitted.
2807
+ * @returns The dashboard draft after the change, including the new `draftRevision`.
2808
+ * @throws ConflictError - The draft changed since `expectedRevision`; get the draft
2809
+ * again and retry with the new revision.
2810
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2811
+ * @example
2812
+ * ```ts
2813
+ * const draft = await mgmt.context.dashboards.get('DASHBOARD_ID', { view: 'draft' })
2814
+ * await mgmt.context.dashboards.updateDraft('DASHBOARD_ID', {
2815
+ * expectedRevision: draft.draftRevision,
2816
+ * definition: draft.definition,
2817
+ * title: 'Revenue',
2818
+ * })
2819
+ * ```
2820
+ */
2821
+ async updateDraft(dashboardId, input) {
2822
+ validateId(dashboardId, "dashboardId");
2823
+ return asRecord(
2824
+ await invokeWithRetry(this.config, this.http, "DashboardsController_updateDraft", {
2825
+ pathParams: { dashboardId },
2826
+ jsonBody: {
2827
+ expectedRevision: input.expectedRevision,
2828
+ title: input.title,
2829
+ description: input.description,
2830
+ definition: input.definition
2831
+ }
2832
+ })
2833
+ );
2834
+ }
2835
+ /**
2836
+ * Publish the draft as a new version that everyone with access sees.
2837
+ *
2838
+ * Alert workflows defined on the dashboard are updated to match.
2839
+ *
2840
+ * @param dashboardId - Id of the dashboard.
2841
+ * @param input.expectedRevision - The `draftRevision` you reviewed and want to publish.
2842
+ * @returns The published `dashboard` and the new `version`.
2843
+ * @throws ConflictError - The draft changed since `expectedRevision`.
2844
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2845
+ * @example
2846
+ * ```ts
2847
+ * const result = await mgmt.context.dashboards.publish('DASHBOARD_ID', { expectedRevision: 4 })
2848
+ * result.version.versionNumber
2849
+ * ```
2850
+ */
2851
+ async publish(dashboardId, input) {
2852
+ validateId(dashboardId, "dashboardId");
2853
+ return asRecord(
2854
+ await invokeWithRetry(this.config, this.http, "DashboardsController_publish", {
2855
+ pathParams: { dashboardId },
2856
+ jsonBody: { expectedRevision: input.expectedRevision }
2857
+ })
2858
+ );
2859
+ }
2860
+ /**
2861
+ * Delete a dashboard and the alert workflows defined on it.
2862
+ *
2863
+ * A deleted dashboard cannot be restored.
2864
+ *
2865
+ * @param dashboardId - Id of the dashboard.
2866
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2867
+ * @example
2868
+ * ```ts
2869
+ * await mgmt.context.dashboards.delete('DASHBOARD_ID')
2870
+ * ```
2871
+ */
2872
+ async delete(dashboardId) {
2873
+ validateId(dashboardId, "dashboardId");
2874
+ await invokeWithRetry(this.config, this.http, "DashboardsController_delete", {
2875
+ pathParams: { dashboardId }
2876
+ });
2877
+ }
2878
+ /**
2879
+ * List the published versions of a dashboard, newest first.
2880
+ *
2881
+ * @param dashboardId - Id of the dashboard.
2882
+ * @returns Every published version with its full definition. Definitions are
2883
+ * returned as stored, so older versions may lack newer fields. The list is
2884
+ * not paginated.
2885
+ * @throws NotFoundError - The dashboard does not exist or you cannot open it.
2886
+ * @example
2887
+ * ```ts
2888
+ * const versions = await mgmt.context.dashboards.listVersions('DASHBOARD_ID')
2889
+ * versions.map((version) => [version.uid, version.versionNumber])
2890
+ * ```
2891
+ */
2892
+ async listVersions(dashboardId) {
2893
+ validateId(dashboardId, "dashboardId");
2894
+ const data = asRecord(
2895
+ await invokeWithRetry(this.config, this.http, "DashboardsController_listVersions", {
2896
+ pathParams: { dashboardId }
2897
+ })
2898
+ );
2899
+ return data.versions;
2900
+ }
2901
+ /**
2902
+ * Get a dashboard as it was in one version.
2903
+ *
2904
+ * @param dashboardId - Id of the dashboard.
2905
+ * @param versionId - Id of the version, as returned by `listVersions()`.
2906
+ * @returns The dashboard with that version's definition.
2907
+ * @throws NotFoundError - The dashboard or the version does not exist, or you cannot
2908
+ * open the dashboard.
2909
+ * @example
2910
+ * ```ts
2911
+ * const old = await mgmt.context.dashboards.getVersion('DASHBOARD_ID', 'VERSION_ID')
2912
+ * old.selectedVersion.versionNumber
2913
+ * ```
2914
+ */
2915
+ async getVersion(dashboardId, versionId) {
2916
+ validateId(dashboardId, "dashboardId");
2917
+ validateId(versionId, "versionId");
2918
+ return asRecord(
2919
+ await invokeWithRetry(this.config, this.http, "DashboardsController_getVersion", {
2920
+ pathParams: { dashboardId, versionId }
2921
+ })
2922
+ );
2923
+ }
2924
+ /**
2925
+ * Replace the draft with the content of an earlier version.
2926
+ *
2927
+ * The draft being replaced is kept as a draft snapshot. Call `publish()`
2928
+ * afterwards to make the restored content visible.
2929
+ *
2930
+ * @param dashboardId - Id of the dashboard.
2931
+ * @param versionId - Id of the version or draft snapshot to restore.
2932
+ * @returns The dashboard draft after the restore.
2933
+ * @throws NotFoundError - The dashboard or the version does not exist, or you cannot
2934
+ * edit the dashboard.
2935
+ * @example
2936
+ * ```ts
2937
+ * await mgmt.context.dashboards.restoreVersion('DASHBOARD_ID', 'VERSION_ID')
2938
+ * ```
2939
+ */
2940
+ async restoreVersion(dashboardId, versionId) {
2941
+ validateId(dashboardId, "dashboardId");
2942
+ validateId(versionId, "versionId");
2943
+ return asRecord(
2944
+ await invokeWithRetry(this.config, this.http, "DashboardsController_restore", {
2945
+ pathParams: { dashboardId, versionId }
2946
+ })
2947
+ );
2948
+ }
2949
+ /**
2950
+ * List recent snapshots of the dashboard draft, newest first.
2951
+ *
2952
+ * @param dashboardId - Id of the dashboard.
2953
+ * @returns Up to 100 snapshots with their id, author and time. Pass an id to
2954
+ * `restoreVersion()` to bring that draft back.
2955
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2956
+ * @example
2957
+ * ```ts
2958
+ * const snapshots = await mgmt.context.dashboards.listDraftSnapshots('DASHBOARD_ID')
2959
+ * snapshots.map((snapshot) => snapshot.uid)
2960
+ * ```
2961
+ */
2962
+ async listDraftSnapshots(dashboardId) {
2963
+ validateId(dashboardId, "dashboardId");
2964
+ const data = asRecord(
2965
+ await invokeWithRetry(this.config, this.http, "DashboardsController_listDraftSnapshots", {
2966
+ pathParams: { dashboardId }
2967
+ })
2968
+ );
2969
+ return data.snapshots;
2970
+ }
2971
+ /**
2972
+ * Replace who can open and edit a dashboard.
2973
+ *
2974
+ * All three settings are required and replace the current ones.
2975
+ *
2976
+ * @param dashboardId - Id of the dashboard.
2977
+ * @param input.visibility - `shared` (the owner plus the groups in
2978
+ * `groupPermissions`) or `private` (the owner plus the users in `sharedWith`).
2979
+ * @param input.groupPermissions - Group id to `{ use, manage }`. Used only when shared.
2980
+ * @param input.sharedWith - Users such as `{ email: 'ana@example.com', permission: 'use' }`.
2981
+ * Used only when private.
2982
+ * @returns The dashboard with its new access settings.
2983
+ * @throws NotFoundError - The dashboard does not exist or you cannot edit it.
2984
+ * @throws ModusError - A group, user or permission is invalid.
2985
+ * @example
2986
+ * ```ts
2987
+ * await mgmt.context.dashboards.updateAccess('DASHBOARD_ID', {
2988
+ * visibility: 'private',
2989
+ * groupPermissions: {},
2990
+ * sharedWith: [{ email: 'ana@example.com', permission: 'use' }],
2991
+ * })
2992
+ * ```
2993
+ */
2994
+ async updateAccess(dashboardId, input) {
2995
+ validateId(dashboardId, "dashboardId");
2996
+ return asRecord(
2997
+ await invokeWithRetry(this.config, this.http, "DashboardsController_updateAccess", {
2998
+ pathParams: { dashboardId },
2999
+ jsonBody: {
3000
+ visibility: input.visibility,
3001
+ groupPermissions: input.groupPermissions,
3002
+ sharedWith: input.sharedWith
3003
+ }
3004
+ })
3005
+ );
3006
+ }
3007
+ /**
3008
+ * Ask another member of your organization to take ownership of a dashboard.
3009
+ *
3010
+ * Only the owner can request a transfer. Ownership moves when the recipient
3011
+ * calls `acceptOwnershipTransfer()`.
3012
+ *
3013
+ * @param dashboardId - Id of the dashboard.
3014
+ * @param input.newOwnerUserId - User id of the member who should become the owner.
3015
+ * @returns The dashboard with `pendingOwnershipTransfer` set.
3016
+ * @throws PermissionDeniedError - You are not the owner.
3017
+ * @throws NotFoundError - The dashboard does not exist or you cannot open it.
3018
+ * @example
3019
+ * ```ts
3020
+ * await mgmt.context.dashboards.requestOwnershipTransfer('DASHBOARD_ID', {
3021
+ * newOwnerUserId: 'USER_ID',
3022
+ * })
3023
+ * ```
3024
+ */
3025
+ async requestOwnershipTransfer(dashboardId, input) {
3026
+ validateId(dashboardId, "dashboardId");
3027
+ validateId(input.newOwnerUserId, "newOwnerUserId");
3028
+ return asRecord(
3029
+ await invokeWithRetry(this.config, this.http, "DashboardsController_transferOwnership", {
3030
+ pathParams: { dashboardId },
3031
+ jsonBody: { newOwnerUserId: input.newOwnerUserId }
3032
+ })
3033
+ );
3034
+ }
3035
+ /**
3036
+ * Accept a pending ownership transfer and become the dashboard owner.
3037
+ *
3038
+ * Only the requested recipient can accept.
3039
+ *
3040
+ * @param dashboardId - Id of the dashboard.
3041
+ * @returns The dashboard with you as its owner.
3042
+ * @throws NotFoundError - The dashboard does not exist, or it has no pending transfer
3043
+ * addressed to you.
3044
+ * @example
3045
+ * ```ts
3046
+ * await mgmt.context.dashboards.acceptOwnershipTransfer('DASHBOARD_ID')
3047
+ * ```
3048
+ */
3049
+ async acceptOwnershipTransfer(dashboardId) {
3050
+ validateId(dashboardId, "dashboardId");
3051
+ return asRecord(
3052
+ await invokeWithRetry(this.config, this.http, "DashboardsController_acceptOwnership", {
3053
+ pathParams: { dashboardId }
3054
+ })
3055
+ );
3056
+ }
3057
+ /**
3058
+ * Cancel a pending ownership transfer.
3059
+ *
3060
+ * Only the owner can cancel.
3061
+ *
3062
+ * @param dashboardId - Id of the dashboard.
3063
+ * @returns The dashboard with no pending transfer.
3064
+ * @throws NotFoundError - The dashboard does not exist, you cannot open it, or you are
3065
+ * not the owner.
3066
+ * @example
3067
+ * ```ts
3068
+ * await mgmt.context.dashboards.cancelOwnershipTransfer('DASHBOARD_ID')
3069
+ * ```
3070
+ */
3071
+ async cancelOwnershipTransfer(dashboardId) {
3072
+ validateId(dashboardId, "dashboardId");
3073
+ return asRecord(
3074
+ await invokeWithRetry(this.config, this.http, "DashboardsController_cancelOwnership", {
3075
+ pathParams: { dashboardId }
3076
+ })
3077
+ );
3078
+ }
3079
+ /**
3080
+ * Work with the tiles and filters of one dashboard draft.
3081
+ *
3082
+ * @param dashboardId - Id of the dashboard.
3083
+ * @returns A resource bound to that dashboard.
3084
+ * @example
3085
+ * ```ts
3086
+ * await mgmt.context.dashboards.elements('DASHBOARD_ID').list()
3087
+ * ```
3088
+ */
3089
+ elements(dashboardId) {
3090
+ validateId(dashboardId, "dashboardId");
3091
+ return new ManagementDashboardElementsResource(this.http, this.config, dashboardId);
3092
+ }
3093
+ /**
3094
+ * Move or resize several tiles and filters in one change.
3095
+ *
3096
+ * @param dashboardId - Id of the dashboard.
3097
+ * @param input.expectedRevision - The `draftRevision` your change is based on.
3098
+ * @param input.elements - Every element to place, each with `elementId` and its
3099
+ * final `layout`.
3100
+ * @returns The whole dashboard after the change, including the new `draftRevision`.
3101
+ * @throws ConflictError - The draft changed since `expectedRevision`.
3102
+ * @example
3103
+ * ```ts
3104
+ * await mgmt.context.dashboards.updateLayout('DASHBOARD_ID', {
3105
+ * expectedRevision: 3,
3106
+ * elements: [{ elementId: 'ELEMENT_ID', layout: { x: 0, y: 0, w: 12, h: 2 } }],
3107
+ * })
3108
+ * ```
3109
+ */
3110
+ async updateLayout(dashboardId, input) {
3111
+ validateId(dashboardId, "dashboardId");
3112
+ return asRecord(
3113
+ await invokeWithRetry(this.config, this.http, "DashboardsController_updateLayout", {
3114
+ pathParams: { dashboardId },
3115
+ jsonBody: { expectedRevision: input.expectedRevision, elements: input.elements }
3116
+ })
3117
+ );
3118
+ }
3119
+ };
3120
+
3121
+ // src/management/context/files.ts
3122
+ var import_promises = require("fs/promises");
3123
+ var import_node_path = require("path");
3124
+ var MAX_BULK_UPLOAD_FILES = 100;
3125
+ var DEFAULT_LIST_PAGE_SIZE = 50;
3126
+ var DEFAULT_PUT_TIMEOUT_MS = 6e4;
3127
+ var DEFAULT_POLL_INTERVAL_MS = 500;
3128
+ var DEFAULT_UPLOAD_TIMEOUT_MS = 12e4;
3129
+ var DEFAULT_CONCURRENCY = 10;
3130
+ var STATUS_ORDER = { pending: 0, processing: 1, ready: 2 };
3131
+ var WAIT_UNTIL_VALUES = /* @__PURE__ */ new Set(["processing", "ready"]);
3132
+ var DEFER_CONTENT_TYPE_TO_SERVER = "application/octet-stream";
3133
+ function validateWaitUntil(waitUntil) {
3134
+ if (!WAIT_UNTIL_VALUES.has(waitUntil)) {
3135
+ throw new Error(`waitUntil must be one of ${[...WAIT_UNTIL_VALUES].join(", ")}, got ${waitUntil}`);
3136
+ }
3137
+ }
3138
+ function validateBulkSize(count, name) {
3139
+ if (count === 0) throw new Error(`${name} must not be empty`);
3140
+ if (count > MAX_BULK_UPLOAD_FILES) {
3141
+ throw new Error(`${name} must have at most ${MAX_BULK_UPLOAD_FILES} entries, got ${count}`);
3142
+ }
3143
+ }
3144
+ function statusSatisfies(status, waitUntil) {
3145
+ if (status === "failed") return true;
3146
+ return (STATUS_ORDER[status] ?? 0) >= STATUS_ORDER[waitUntil];
3147
+ }
3148
+ function sleep2(ms) {
3149
+ return new Promise((resolve) => setTimeout(resolve, ms));
3150
+ }
3151
+ function chunked(items, size) {
3152
+ const out = [];
3153
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
3154
+ return out;
3155
+ }
3156
+ async function mapWithConcurrency(items, concurrency, worker, onItemDone) {
3157
+ const results = new Array(items.length);
3158
+ let cursor = 0;
3159
+ async function run() {
3160
+ for (; ; ) {
3161
+ const index = cursor++;
3162
+ if (index >= items.length) return;
3163
+ const result = await worker(items[index]);
3164
+ results[index] = result;
3165
+ onItemDone?.(result);
3166
+ }
3167
+ }
3168
+ await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, run));
3169
+ return results;
3170
+ }
3171
+ async function walkFiles(root, recursive) {
3172
+ const out = [];
3173
+ async function walk(dir) {
3174
+ const entries = await (0, import_promises.readdir)(dir, { withFileTypes: true });
3175
+ entries.sort((a, b) => a.name.localeCompare(b.name));
3176
+ for (const entry of entries) {
3177
+ if (entry.name.startsWith(".") || entry.isSymbolicLink()) continue;
3178
+ const full = (0, import_node_path.join)(dir, entry.name);
3179
+ if (entry.isDirectory()) {
3180
+ if (recursive) await walk(full);
3181
+ } else if (entry.isFile()) {
3182
+ out.push(full);
3183
+ }
3184
+ }
3185
+ }
3186
+ await walk(root);
3187
+ return out;
3188
+ }
3189
+ async function putBytes(fetchImpl, url, data, contentType, timeoutMs) {
3190
+ const response = await fetchImpl(url, {
3191
+ method: "PUT",
3192
+ body: data,
3193
+ headers: { "Content-Type": contentType },
3194
+ signal: AbortSignal.timeout(timeoutMs)
3195
+ });
3196
+ if (!response.ok) {
3197
+ const text = await response.text().catch(() => "");
3198
+ throw new ModusError(`Upload PUT to presigned URL failed with HTTP ${response.status}.`, {
3199
+ statusCode: response.status,
3200
+ body: text ? text.slice(0, 500) : void 0
3201
+ });
3202
+ }
3203
+ }
3204
+ function createSlotsPayload(files) {
3205
+ return {
3206
+ files: files.map((f) => ({ fileName: f.fileName, contentType: f.contentType, fileSize: f.fileSize }))
3207
+ };
3208
+ }
3209
+ function uploadFromUrlsPayload(urls) {
3210
+ return {
3211
+ urls: urls.map((u) => ({
3212
+ url: u.url,
3213
+ ...u.fileName !== void 0 ? { fileName: u.fileName } : {},
3214
+ ...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
3215
+ }))
3216
+ };
3217
+ }
3218
+ function assignSlots(batch, result, failed) {
3219
+ const failedIndices = new Set(result.failed.map((f) => f.index));
3220
+ for (const f of result.failed) {
3221
+ failed.push({ path: batch[f.index]?.path ?? "", error: f.error });
3222
+ }
3223
+ const remaining = batch.filter((_, i) => !failedIndices.has(i));
3224
+ const uploaded = result.uploaded;
3225
+ if (uploaded.length < remaining.length) {
3226
+ for (const file of remaining.slice(uploaded.length)) {
3227
+ failed.push({ path: file.path, error: "Server returned fewer upload slots than requested files." });
3228
+ }
3229
+ }
3230
+ const paired = Math.min(remaining.length, uploaded.length);
3231
+ const assignments = [];
3232
+ for (let i = 0; i < paired; i++) {
3233
+ assignments.push({ ...remaining[i], slot: uploaded[i] });
3234
+ }
3235
+ return assignments;
3236
+ }
3237
+ var ManagementContextFilesResource = class {
3238
+ /** @internal */
3239
+ constructor(http, config) {
3240
+ this.http = http;
3241
+ this.config = config;
3242
+ }
3243
+ /**
3244
+ * Get a presigned S3 PUT URL for one file.
3245
+ *
3246
+ * @param input.fileName - Original file name — used to build the S3 object key.
3247
+ * @param input.contentType - MIME type. Allowed categories: PDF, images, text,
3248
+ * Office/OpenDocument documents, audio, and video.
3249
+ * @param input.fileSize - File size in bytes. Rejected above 50MB.
3250
+ * @returns Presigned upload slot. PUT the raw bytes to `uploadUrl` within 15
3251
+ * minutes, then call `finalize(slot.uploadId, slot.fileName)`. Pass the
3252
+ * slot's own `fileName` rather than your local basename — the server may
3253
+ * sanitize the requested name when it mints the key, and finalization
3254
+ * re-derives the key from `uploadId` and `fileName`.
3255
+ */
3256
+ async createUploadUrl(input) {
3257
+ return asRecord(
3258
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadUrl", {
3259
+ jsonBody: { fileName: input.fileName, contentType: input.contentType, fileSize: input.fileSize }
3260
+ })
3261
+ );
3262
+ }
3263
+ /**
3264
+ * Get presigned S3 PUT URLs for up to 100 files in one call.
3265
+ *
3266
+ * @param files - Files to create upload slots for (max 100).
3267
+ * @returns Slots for every file that passed validation, plus per-index
3268
+ * failures (bad MIME type, oversize) for the rest — never a partial 4xx.
3269
+ */
3270
+ async createUploadUrls(files) {
3271
+ validateBulkSize(files.length, "files");
3272
+ return asRecord(
3273
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadUrls", {
3274
+ jsonBody: createSlotsPayload(files)
3275
+ })
3276
+ );
3277
+ }
3278
+ /**
3279
+ * Fetch one file from a URL and land it as durable context.
3280
+ *
3281
+ * @param url - Source URL to fetch (SSRF-guarded, 50MB cap, same MIME
3282
+ * allow-list as `createUploadUrl`).
3283
+ * @param options.fileName - Override file name. Inferred from the URL path when omitted.
3284
+ * @returns File upload resource with status `processing` — parsing continues async.
3285
+ */
3286
+ async uploadFromUrl(url, options = {}) {
3287
+ return asRecord(
3288
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrl", {
3289
+ jsonBody: {
3290
+ url,
3291
+ ...options.fileName !== void 0 ? { fileName: options.fileName } : {},
3292
+ ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {}
3293
+ }
3294
+ })
3295
+ );
3296
+ }
3297
+ /**
3298
+ * Fetch up to 100 files from URLs in one call.
3299
+ *
3300
+ * @param urls - URLs to fetch and upload (max 100).
3301
+ * @returns File upload resources for every URL that landed, plus per-index
3302
+ * failures for the rest — never a partial 4xx.
3303
+ */
3304
+ async uploadFromUrls(urls) {
3305
+ validateBulkSize(urls.length, "urls");
3306
+ return asRecord(
3307
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrls", {
3308
+ jsonBody: uploadFromUrlsPayload(urls)
3309
+ })
3310
+ );
3311
+ }
3312
+ /**
3313
+ * Fetch one file upload by its id.
3314
+ *
3315
+ * @param uploadId - Upload id returned by `createUploadUrl` / `uploadFromUrl`.
3316
+ * @returns The file upload resource, including its processing `status`.
3317
+ */
3318
+ async get(uploadId) {
3319
+ validateId(uploadId, "uploadId");
3320
+ return asRecord(
3321
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_get", {
3322
+ pathParams: { uploadId }
3323
+ })
3324
+ );
3325
+ }
3326
+ /**
3327
+ * List durable file uploads.
3328
+ *
3329
+ * @param options.pageSize - Items per page (default 50).
3330
+ * @param options.pageToken - Opaque token from a previous page's `nextPageToken`.
3331
+ * @returns Page of file uploads. Uploads that only have a pending row (not yet
3332
+ * landed) aren't included here — use `get(uploadId)` for those.
3333
+ */
3334
+ list(options = {}) {
3335
+ const pageSize = options.pageSize ?? DEFAULT_LIST_PAGE_SIZE;
3336
+ validatePageSize(pageSize, 200);
3337
+ return this.listPage(pageSize, options.pageToken);
3338
+ }
3339
+ async listPage(pageSize, pageToken) {
3340
+ const data = asRecord(
3341
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_list", {
3342
+ query: aipListParams(pageSize, pageToken)
3343
+ })
3344
+ );
3345
+ return buildAipPage(data, "files", (raw) => raw, (token) => this.listPage(pageSize, token));
3346
+ }
3347
+ /**
3348
+ * Turn a file already PUT to a presigned URL into durable context.
3349
+ *
3350
+ * Call this once the PUT completes. The server locates the object from
3351
+ * `uploadId` + `fileName` and validates the bytes that actually arrived.
3352
+ * Safe to retry — a second call returns the same resource.
3353
+ *
3354
+ * @param uploadId - Upload id returned by `createUploadUrl`.
3355
+ * @param fileName - File name returned alongside it.
3356
+ * @returns The file upload resource, status `"processing"`.
3357
+ */
3358
+ async finalize(uploadId, fileName, options = {}) {
3359
+ validateId(uploadId, "uploadId");
3360
+ return asRecord(
3361
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_finalize", {
3362
+ pathParams: { uploadId },
3363
+ jsonBody: { fileName, ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {} }
3364
+ })
3365
+ );
3366
+ }
3367
+ /**
3368
+ * Finalize up to 100 uploads in one call.
3369
+ *
3370
+ * What makes directory upload cheap: 2000 files cost 20 requests here rather
3371
+ * than 2000.
3372
+ *
3373
+ * @param uploads - Uploads to finalize (max 100).
3374
+ * @returns Resources for every upload that finalized, plus per-index
3375
+ * failures for the rest — never a partial 4xx.
3376
+ */
3377
+ async finalizeMany(uploads) {
3378
+ validateBulkSize(uploads.length, "uploads");
3379
+ return asRecord(
3380
+ await invokeWithRetry(this.config, this.http, "ContextFilesController_finalizeMany", {
3381
+ jsonBody: {
3382
+ uploads: uploads.map((u) => ({
3383
+ uploadId: u.uploadId,
3384
+ fileName: u.fileName,
3385
+ ...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
3386
+ }))
3387
+ }
3388
+ })
3389
+ );
3390
+ }
3391
+ /**
3392
+ * Upload an explicit list of local files.
3393
+ *
3394
+ * Same machinery as `uploadDir`, without the directory walk — use it when
3395
+ * the caller already knows which files to send.
3396
+ *
3397
+ * @param paths - Paths to local files.
3398
+ * @param options.concurrency - Max concurrent PUTs (default 10).
3399
+ * @param options.waitUntil - `"processing"` (default) or `"ready"`.
3400
+ * @param options.onProgress - Optional progress callback after each file.
3401
+ */
3402
+ async uploadFiles(paths, options = {}) {
3403
+ return this.uploadPaths(paths.map((input) => typeof input === "string" ? { path: input } : input), options);
3404
+ }
3405
+ /**
3406
+ * Upload a local file and wait for it to reach `"processing"` or `"ready"`.
3407
+ *
3408
+ * Gets a presigned URL, PUTs the file bytes, then polls `get()` until the
3409
+ * upload leaves `"pending"` (or reaches `"ready"`/`"failed"`).
3410
+ *
3411
+ * @param path - Path to a local file.
3412
+ * @param options.waitUntil - `"processing"` (parsing started, default) or
3413
+ * `"ready"` (parsing finished).
3414
+ * @param options.pollIntervalMs - Milliseconds between status polls.
3415
+ * @param options.timeoutMs - Max milliseconds to wait before raising.
3416
+ * @returns The file upload resource once it reaches `waitUntil` (or `"failed"`).
3417
+ * @throws {ModusError} If the PUT fails, or polling times out.
3418
+ */
3419
+ async upload(path, options = {}) {
3420
+ const waitUntil = options.waitUntil ?? "processing";
3421
+ validateWaitUntil(waitUntil);
3422
+ const fileStat = await (0, import_promises.stat)(path);
3423
+ if (!fileStat.isFile()) throw new Error(`Not a file: ${path}`);
3424
+ const fileName = path.split(/[/\\]/).pop();
3425
+ const slot = await this.createUploadUrl({
3426
+ fileName,
3427
+ contentType: DEFER_CONTENT_TYPE_TO_SERVER,
3428
+ fileSize: fileStat.size
3429
+ });
3430
+ const data = await (0, import_promises.readFile)(path);
3431
+ await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
3432
+ const finalized = await this.finalize(slot.uploadId, slot.fileName);
3433
+ if (statusSatisfies(finalized.status, waitUntil)) return finalized;
3434
+ return this.pollUntil(
3435
+ slot.uploadId,
3436
+ waitUntil,
3437
+ options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
3438
+ options.timeoutMs ?? DEFAULT_UPLOAD_TIMEOUT_MS
3439
+ );
3440
+ }
3441
+ async pollUntil(uploadId, waitUntil, pollIntervalMs, timeoutMs) {
3442
+ const deadline = Date.now() + timeoutMs;
3443
+ for (; ; ) {
3444
+ const item = await this.get(uploadId);
3445
+ if (statusSatisfies(item.status, waitUntil)) return item;
3446
+ if (Date.now() >= deadline) {
3447
+ throw new ModusError(
3448
+ `Timed out after ${timeoutMs}ms waiting for upload ${JSON.stringify(uploadId)} to reach status ${JSON.stringify(waitUntil)}; last status was ${JSON.stringify(item.status)}.`
3449
+ );
3450
+ }
3451
+ await sleep2(pollIntervalMs);
3452
+ }
3453
+ }
3454
+ /**
3455
+ * Upload every file in a local directory.
3456
+ *
3457
+ * Walks `path` (skipping hidden files/directories and symlinks), pages
3458
+ * through `createUploadUrls()` in batches of up to 100, then PUTs and polls
3459
+ * each file with up to `concurrency` in flight at once. A failure on one
3460
+ * file does not stop the others — check `result.failed`.
3461
+ *
3462
+ * @param path - Path to a local directory.
3463
+ * @param options.recursive - Recurse into subdirectories (default `true`).
3464
+ * @param options.concurrency - Max concurrent PUT+poll operations (default 10).
3465
+ * @param options.waitUntil - `"processing"` (default) or `"ready"` — same as `upload()`.
3466
+ * @param options.onProgress - Optional progress callback after each file.
3467
+ * @returns `UploadDirResult` with every successful `FileUpload` and every
3468
+ * per-file failure (slot creation or PUT/poll), each tagged with its local path.
3469
+ */
3470
+ async uploadDir(path, options = {}) {
3471
+ const waitUntil = options.waitUntil ?? "processing";
3472
+ validateWaitUntil(waitUntil);
3473
+ const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
3474
+ if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
3475
+ const dirStat = await (0, import_promises.stat)(path);
3476
+ if (!dirStat.isDirectory()) throw new Error(`Not a directory: ${path}`);
3477
+ const files = await walkFiles(path, options.recursive ?? true);
3478
+ return this.uploadPaths(files.map((file) => {
3479
+ const folderPath = (0, import_node_path.relative)(path, (0, import_node_path.dirname)(file)).replace(/\\/g, "/");
3480
+ return { path: file, ...folderPath.length > 0 ? { folderPath } : {} };
3481
+ }), options);
3482
+ }
3483
+ /** Shared body of `uploadFiles` and `uploadDir`: presign in batches of 100,
3484
+ * PUT with bounded concurrency, then bulk-finalize the batch. */
3485
+ async uploadPaths(files, options) {
3486
+ const waitUntil = options.waitUntil ?? "processing";
3487
+ validateWaitUntil(waitUntil);
3488
+ const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
3489
+ if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
3490
+ const uploaded = [];
3491
+ const failed = [];
3492
+ const total = files.length;
3493
+ let completed = 0;
3494
+ const emit = () => {
3495
+ completed += 1;
3496
+ options.onProgress?.({
3497
+ completed,
3498
+ total,
3499
+ succeeded: uploaded.length,
3500
+ failed: failed.length
3501
+ });
3502
+ };
3503
+ for (const batch of chunked(files, MAX_BULK_UPLOAD_FILES)) {
3504
+ const failedBefore = failed.length;
3505
+ const slots = await this.createSlots(batch, failed);
3506
+ for (let reported = failedBefore + 1; reported <= failed.length; reported += 1) {
3507
+ completed += 1;
3508
+ options.onProgress?.({ completed, total, succeeded: uploaded.length, failed: reported });
3509
+ }
3510
+ await this.uploadBatch(slots, waitUntil, concurrency, (result) => {
3511
+ if ("error" in result) failed.push(result);
3512
+ else uploaded.push(result);
3513
+ emit();
3514
+ });
3515
+ }
3516
+ return { uploaded, failed };
3517
+ }
3518
+ async createSlots(batch, failed) {
3519
+ const readable = [];
3520
+ const inputs = [];
3521
+ for (const file of batch) {
3522
+ try {
3523
+ const fileStat = await (0, import_promises.stat)(file.path);
3524
+ const fileName = file.path.split(/[/\\]/).pop();
3525
+ inputs.push({ fileName, contentType: DEFER_CONTENT_TYPE_TO_SERVER, fileSize: fileStat.size });
3526
+ readable.push(file);
3527
+ } catch (error) {
3528
+ const message = error instanceof Error ? error.message : String(error);
3529
+ failed.push({ path: file.path, error: message });
3530
+ }
3531
+ }
3532
+ if (inputs.length === 0) return [];
3533
+ const result = await this.createUploadUrls(inputs);
3534
+ return assignSlots(readable, result, failed);
3535
+ }
3536
+ async uploadBatch(slots, waitUntil, concurrency, onOutcome) {
3537
+ if (slots.length === 0) return [];
3538
+ const out = [];
3539
+ const put = await mapWithConcurrency(
3540
+ slots,
3541
+ concurrency,
3542
+ async ({ path, folderPath, slot }) => {
3543
+ try {
3544
+ const data = await (0, import_promises.readFile)(path);
3545
+ await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
3546
+ return { landed: { path, ...folderPath !== void 0 ? { folderPath } : {}, slot } };
3547
+ } catch (error) {
3548
+ const message = error instanceof Error ? error.message : String(error);
3549
+ return { failure: { path, error: message } };
3550
+ }
3551
+ },
3552
+ (outcome) => {
3553
+ if ("failure" in outcome) {
3554
+ out.push(outcome.failure);
3555
+ onOutcome?.(outcome.failure);
3556
+ }
3557
+ }
3558
+ );
3559
+ const landed = [];
3560
+ for (const entry of put) {
3561
+ if ("failure" in entry) {
3562
+ continue;
3563
+ }
3564
+ landed.push(entry.landed);
3565
+ }
3566
+ if (landed.length === 0) return out;
3567
+ const result = await this.finalizeMany(
3568
+ landed.map(({ slot, folderPath }) => ({
3569
+ uploadId: slot.uploadId,
3570
+ fileName: slot.fileName,
3571
+ ...folderPath !== void 0 ? { folderPath } : {}
3572
+ }))
3573
+ );
3574
+ const failedIndices = new Set(result.failed.map((f) => f.index));
3575
+ for (const f of result.failed) {
3576
+ const failure = { path: landed[f.index]?.path ?? "", error: f.error };
3577
+ out.push(failure);
3578
+ onOutcome?.(failure);
3579
+ }
3580
+ const finalized = result.finalized;
3581
+ const remaining = landed.filter((_, i) => !failedIndices.has(i));
3582
+ if (waitUntil !== "ready") {
3583
+ for (const item of finalized) {
3584
+ out.push(item);
3585
+ onOutcome?.(item);
3586
+ }
3587
+ return out;
3588
+ }
3589
+ await mapWithConcurrency(
3590
+ remaining,
3591
+ concurrency,
3592
+ async ({ path, slot }) => {
3593
+ try {
3594
+ return await this.pollUntil(slot.uploadId, waitUntil, DEFAULT_POLL_INTERVAL_MS, DEFAULT_UPLOAD_TIMEOUT_MS);
3595
+ } catch (error) {
3596
+ const message = error instanceof Error ? error.message : String(error);
3597
+ return { path, error: message };
3598
+ }
3599
+ },
3600
+ (item) => {
3601
+ out.push(item);
3602
+ onOutcome?.(item);
3603
+ }
3604
+ );
3605
+ return out;
3606
+ }
3607
+ };
3608
+
3609
+ // src/management/context/items.ts
3610
+ function contextListParams(pageSize, pageToken, contextType) {
3611
+ const extra = {};
3612
+ if (contextType !== void 0) extra.contextTypes = [contextType];
3613
+ return aipListParams(pageSize, pageToken, extra);
3614
+ }
3615
+ function parseContextItem2(raw) {
3616
+ return raw;
3617
+ }
3618
+ var ManagementContextItemsResource = class {
3619
+ constructor(http, config) {
3620
+ this.http = http;
3621
+ this.config = config;
3622
+ }
3623
+ /**
3624
+ * List context items in the knowledge base.
3625
+ *
3626
+ * @param options.pageSize - Items per page (default 25).
3627
+ * @param options.pageToken - Token from a previous page's `nextPageToken`.
3628
+ * @param options.contextType - Filter to one context type (for example `"note"`).
3629
+ * @returns A page of context items.
3630
+ */
3631
+ list(options = {}) {
3632
+ const pageSize = options.pageSize ?? 25;
3633
+ validatePageSize(pageSize);
3634
+ return this.listPage(pageSize, options.pageToken, options.contextType);
3635
+ }
3636
+ async listPage(pageSize, pageToken, contextType) {
3637
+ const data = asRecord(
3638
+ await invokeWithRetry(this.config, this.http, "ContextItemsController_list", {
3639
+ query: contextListParams(pageSize, pageToken, contextType)
3640
+ })
3641
+ );
3642
+ return buildAipPage(
3643
+ data,
3644
+ "contextItems",
3645
+ parseContextItem2,
3646
+ (token) => this.listPage(pageSize, token, contextType)
3647
+ );
3648
+ }
3649
+ /**
3650
+ * Retrieve one context item by uid.
3651
+ *
3652
+ * @param uid - Context item uid.
3653
+ * @returns The context item.
3654
+ */
3655
+ async get(uid) {
3656
+ const data = await invokeWithRetry(this.config, this.http, "ContextItemsController_get", {
3657
+ pathParams: { uid }
3658
+ });
3659
+ return parseContextItem2(data);
3660
+ }
3661
+ /**
3662
+ * Update a context item.
2276
3663
  *
2277
3664
  * Only the fields you pass are changed. To clear a field, name it in
2278
3665
  * `updateMask` and leave its argument unset.
@@ -2329,6 +3716,8 @@ var ManagementContextResource = class {
2329
3716
  this.config = config;
2330
3717
  this.items = new ManagementContextItemsResource(http, config);
2331
3718
  this.customItems = new CustomContextItemsResource(http, config);
3719
+ this.files = new ManagementContextFilesResource(http, config);
3720
+ this.dashboards = new ManagementDashboardsResource(http, config);
2332
3721
  }
2333
3722
  /**
2334
3723
  * Add a free-form text note to the knowledge base.
@@ -2338,6 +3727,7 @@ var ManagementContextResource = class {
2338
3727
  * @returns The created context item.
2339
3728
  * @example
2340
3729
  * ```ts
3730
+ * const mgmt = new ModusManagement()
2341
3731
  * const note = await mgmt.context.createNote('Runbook', '# Steps\n1. Check logs')
2342
3732
  * ```
2343
3733
  */
@@ -2355,6 +3745,14 @@ var ManagementContextResource = class {
2355
3745
  * @param options.body - New markdown body.
2356
3746
  * @param options.existing - Optional cached item to avoid a GET.
2357
3747
  * @returns The updated context item.
3748
+ * @example
3749
+ * ```ts
3750
+ * const mgmt = new ModusManagement()
3751
+ * const item = await mgmt.context.updateNote('PLACEHOLDER_UID', {
3752
+ * title: 'Runbook',
3753
+ * body: '# Steps\n1. Check logs\n2. Escalate',
3754
+ * })
3755
+ * ```
2358
3756
  */
2359
3757
  updateNote(uid, options) {
2360
3758
  return resolveAndUpdateNote(this.items, uid, options);
@@ -2367,6 +3765,14 @@ var ManagementContextResource = class {
2367
3765
  * @param options.query - SQL text.
2368
3766
  * @param options.path - Optional hierarchy path segments.
2369
3767
  * @returns The created context item.
3768
+ * @example
3769
+ * ```ts
3770
+ * const mgmt = new ModusManagement()
3771
+ * const query = await mgmt.context.createSavedQuery('Monthly ARR', {
3772
+ * connectionId: 'conn_warehouse',
3773
+ * query: 'select * from arr_monthly',
3774
+ * })
3775
+ * ```
2370
3776
  */
2371
3777
  createSavedQuery(name, options) {
2372
3778
  return this.create(
@@ -2388,6 +3794,14 @@ var ManagementContextResource = class {
2388
3794
  * @param options.query - New SQL text.
2389
3795
  * @param options.existing - Optional cached item to avoid a GET.
2390
3796
  * @returns The updated context item.
3797
+ * @example
3798
+ * ```ts
3799
+ * const mgmt = new ModusManagement()
3800
+ * const item = await mgmt.context.updateSavedQuery('PLACEHOLDER_UID', {
3801
+ * name: 'Monthly ARR',
3802
+ * query: 'select sum(amount) from arr_monthly',
3803
+ * })
3804
+ * ```
2391
3805
  */
2392
3806
  updateSavedQuery(uid, options) {
2393
3807
  return resolveAndUpdateSavedQuery(this.items, uid, options);
@@ -2400,6 +3814,13 @@ var ManagementContextResource = class {
2400
3814
  * @param options.isCrawl - When true, crawl linked pages into context.
2401
3815
  * @param options.pageLimit - Maximum pages to crawl when `isCrawl` is true.
2402
3816
  * @returns The created context item.
3817
+ * @example
3818
+ * ```ts
3819
+ * const mgmt = new ModusManagement()
3820
+ * const link = await mgmt.context.createLink('https://docs.example.com/runbook', {
3821
+ * title: 'Ops runbook',
3822
+ * })
3823
+ * ```
2403
3824
  */
2404
3825
  createLink(url, options = {}) {
2405
3826
  return this.create(
@@ -2422,6 +3843,13 @@ var ManagementContextResource = class {
2422
3843
  * @param options.url - New URL.
2423
3844
  * @param options.existing - Optional cached item to avoid a GET.
2424
3845
  * @returns The updated context item.
3846
+ * @example
3847
+ * ```ts
3848
+ * const mgmt = new ModusManagement()
3849
+ * const item = await mgmt.context.updateLink('PLACEHOLDER_UID', {
3850
+ * title: 'Ops runbook (2025)',
3851
+ * })
3852
+ * ```
2425
3853
  */
2426
3854
  updateLink(uid, options) {
2427
3855
  return resolveAndUpdateLink(this.items, uid, options);
@@ -2453,26 +3881,44 @@ var ScopeConversationsResource = class {
2453
3881
  *
2454
3882
  * @param options.pageSize - Items per page (default 25).
2455
3883
  * @param options.pageToken - Opaque token from a previous page.
2456
- * @returns Page of conversation list items.
3884
+ * @param options.source - Restrict to conversations started from this UI surface
3885
+ * (e.g. `"context_chat"`, `"dashboard_copilot"`, `"slack"`).
3886
+ * @param options.sourceRef - Narrow `source` to one instance of that surface — for
3887
+ * `"dashboard_copilot"`, a dashboard id. Requires `source`; the API throws an
3888
+ * `UnprocessableError` (422) if sent on its own. Conversations recorded before
3889
+ * this filter shipped carry no instance key and never match it.
3890
+ * @returns Page of conversation list items (`threadId`, `firstMessage`, `messageCount`).
3891
+ *
3892
+ * @example
3893
+ * ```ts
3894
+ * for await (const row of (
3895
+ * await client.scopes.conversations(scopeId).list({ pageSize: 10 })
3896
+ * ).autoPagingIter()) {
3897
+ * console.log(row.threadId, row.firstMessage, row.messageCount)
3898
+ * }
3899
+ * ```
2457
3900
  */
2458
3901
  list(options = {}) {
2459
3902
  const pageSize = options.pageSize ?? 25;
2460
3903
  validatePageSize(pageSize);
2461
- return this.listPage(pageSize, options.pageToken);
3904
+ return this.listPage(pageSize, options.pageToken, options.source, options.sourceRef);
2462
3905
  }
2463
- async listPage(pageSize, pageToken) {
3906
+ async listPage(pageSize, pageToken, source, sourceRef) {
2464
3907
  validateId(this.scopeId, "scope_id");
3908
+ const extra = {};
3909
+ if (source !== void 0) extra.source = source;
3910
+ if (sourceRef !== void 0) extra.sourceRef = sourceRef;
2465
3911
  const data = asRecord(
2466
3912
  await invokeWithRetry(this.config, this.http, "ScopeConversationsController_list", {
2467
3913
  pathParams: { id: this.scopeId },
2468
- query: aipListParams(pageSize, pageToken)
3914
+ query: aipListParams(pageSize, pageToken, extra)
2469
3915
  })
2470
3916
  );
2471
3917
  return buildAipPage(
2472
3918
  data,
2473
3919
  "conversations",
2474
3920
  parseListItem,
2475
- (token) => this.listPage(pageSize, token)
3921
+ (token) => this.listPage(pageSize, token, source, sourceRef)
2476
3922
  );
2477
3923
  }
2478
3924
  /**
@@ -2481,7 +3927,15 @@ var ScopeConversationsResource = class {
2481
3927
  * @param threadId - Conversation thread id.
2482
3928
  * @param options.messageLimit - Maximum messages to return (1–100).
2483
3929
  * @param options.beforeMessageIndex - Return messages before this index (requires messageLimit).
2484
- * @returns Conversation with messages.
3930
+ * @returns Conversation with `messages` (`type`, `content`).
3931
+ *
3932
+ * @example
3933
+ * ```ts
3934
+ * const thread = await client.scopes.conversations(scopeId).get(row.threadId)
3935
+ * for (const msg of thread.messages) {
3936
+ * console.log(msg.type, String(msg.content).slice(0, 80))
3937
+ * }
3938
+ * ```
2485
3939
  */
2486
3940
  async get(threadId, options = {}) {
2487
3941
  validateId(this.scopeId, "scope_id");
@@ -2790,7 +4244,14 @@ var ManagementScopesResource = class {
2790
4244
  * @param options.search - Case-insensitive substring filter on the scope name.
2791
4245
  * @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
2792
4246
  * @param options.managerId - Return only scopes supervised by this manager scope id.
2793
- * @returns A page of scopes.
4247
+ * @returns A page of scopes — use `.autoPagingIter()` for all pages.
4248
+ * @example
4249
+ * ```ts
4250
+ * const mgmt = new ModusManagement()
4251
+ * for await (const scope of (await mgmt.scopes.list()).autoPagingIter()) {
4252
+ * console.log(scope.id, scope.name, scope.status)
4253
+ * }
4254
+ * ```
2794
4255
  */
2795
4256
  list(options = {}) {
2796
4257
  const pageSize = options.pageSize ?? 25;
@@ -2822,6 +4283,12 @@ var ManagementScopesResource = class {
2822
4283
  * @param scopeId - Scope id.
2823
4284
  * @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
2824
4285
  * @returns The scope.
4286
+ * @example
4287
+ * ```ts
4288
+ * const mgmt = new ModusManagement()
4289
+ * const scope = await mgmt.scopes.get('PLACEHOLDER_SCOPE_ID')
4290
+ * console.log(scope.name, scope.status)
4291
+ * ```
2825
4292
  */
2826
4293
  async get(scopeId, options = {}) {
2827
4294
  validateId(scopeId, "scope_id");
@@ -2844,7 +4311,9 @@ var ManagementScopesResource = class {
2844
4311
  * @returns The created scope (draft).
2845
4312
  * @example
2846
4313
  * ```ts
4314
+ * const mgmt = new ModusManagement()
2847
4315
  * const scope = await mgmt.scopes.create({ name: 'Support assistant', model: 'claude-sonnet-5' })
4316
+ * console.log(scope.id, scope.name)
2848
4317
  * ```
2849
4318
  */
2850
4319
  async create(options) {
@@ -2875,6 +4344,13 @@ var ManagementScopesResource = class {
2875
4344
  * @param options.guardrails - Guardrail labels to set. Fetches the current scope first to merge. Pass `[]` to clear all.
2876
4345
  * @param options.updateMask - Comma-separated field names to update or clear.
2877
4346
  * @returns The updated scope.
4347
+ * @example
4348
+ * ```ts
4349
+ * const mgmt = new ModusManagement()
4350
+ * const scope = await mgmt.scopes.update('PLACEHOLDER_SCOPE_ID', {
4351
+ * description: 'Answers billing questions for enterprise customers.',
4352
+ * })
4353
+ * ```
2878
4354
  */
2879
4355
  async update(scopeId, options = {}) {
2880
4356
  validateId(scopeId, "scope_id");
@@ -2916,8 +4392,10 @@ var ManagementScopesResource = class {
2916
4392
  * @returns The published scope.
2917
4393
  * @example
2918
4394
  * ```ts
2919
- * await mgmt.scopes.update(scopeId, { instructions: ['Be concise.'] })
2920
- * const published = await mgmt.scopes.deploy(scopeId)
4395
+ * const mgmt = new ModusManagement()
4396
+ * const scope = await mgmt.scopes.create({ name: 'Support assistant' })
4397
+ * const published = await mgmt.scopes.deploy(scope.id)
4398
+ * console.log(published.status)
2921
4399
  * ```
2922
4400
  */
2923
4401
  async deploy(scopeId) {
@@ -2935,6 +4413,11 @@ var ManagementScopesResource = class {
2935
4413
  *
2936
4414
  * @param scopeId - Scope id.
2937
4415
  * @returns Resolves when the scope is deleted.
4416
+ * @example
4417
+ * ```ts
4418
+ * const mgmt = new ModusManagement()
4419
+ * await mgmt.scopes.delete('PLACEHOLDER_SCOPE_ID')
4420
+ * ```
2938
4421
  */
2939
4422
  async delete(scopeId) {
2940
4423
  validateId(scopeId, "scope_id");