@getmodus/sdk 0.6.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.
- package/CHANGELOG.md +84 -4
- package/README.md +9 -1
- package/dist/{chunk-HEHHN4D6.js → chunk-JMFT5KO5.js} +330 -11
- package/dist/chunk-JMFT5KO5.js.map +1 -0
- package/dist/{conversations-BRg8gEKX.d.cts → conversations-B0_jmEuT.d.cts} +10469 -3196
- package/dist/{conversations-BRg8gEKX.d.ts → conversations-B0_jmEuT.d.ts} +10469 -3196
- package/dist/index.cjs +618 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +372 -54
- package/dist/index.d.ts +372 -54
- package/dist/index.js +290 -49
- package/dist/index.js.map +1 -1
- package/dist/management/index.cjs +1134 -44
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +600 -9
- package/dist/management/index.d.ts +600 -9
- package/dist/management/index.js +807 -36
- package/dist/management/index.js.map +1 -1
- package/package.json +2 -3
- package/dist/chunk-HEHHN4D6.js.map +0 -1
|
@@ -216,7 +216,7 @@ function formatConfigForLog(config) {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// src/_http.ts
|
|
219
|
-
var USER_AGENT = `modus-typescript/${"0.
|
|
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,26 @@ 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
|
+
},
|
|
595
615
|
"ContextFilesController_get": {
|
|
596
616
|
method: "GET",
|
|
597
617
|
path: "/api/v1/context/files/{uploadId}",
|
|
@@ -732,6 +752,16 @@ var OPERATIONS = {
|
|
|
732
752
|
requestSchema: "CreateCustomContextItemDto",
|
|
733
753
|
responseSchema: "CreatedCustomContextItemResponseDto"
|
|
734
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
|
+
},
|
|
735
765
|
"CustomContextItemsController_delete": {
|
|
736
766
|
method: "DELETE",
|
|
737
767
|
path: "/api/v1/context/custom-items/{uid}",
|
|
@@ -772,6 +802,196 @@ var OPERATIONS = {
|
|
|
772
802
|
requestSchema: "UpdateCustomContextItemDto",
|
|
773
803
|
responseSchema: null
|
|
774
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
|
+
},
|
|
775
995
|
"EvaluationsController_getConfig": {
|
|
776
996
|
method: "GET",
|
|
777
997
|
path: "/api/v1/scopes/{id}/evaluations/config",
|
|
@@ -822,6 +1042,16 @@ var OPERATIONS = {
|
|
|
822
1042
|
requestSchema: "UpdateEvaluationConfigDto",
|
|
823
1043
|
responseSchema: "EvaluationConfigDto"
|
|
824
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
|
+
},
|
|
825
1055
|
"MemberGroupsController_list": {
|
|
826
1056
|
method: "GET",
|
|
827
1057
|
path: "/api/v1/users/member-groups",
|
|
@@ -878,7 +1108,7 @@ var OPERATIONS = {
|
|
|
878
1108
|
service: "modus-api",
|
|
879
1109
|
serverUrl: "https://api.getmodus.com",
|
|
880
1110
|
pathParams: [],
|
|
881
|
-
queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "timeframe", "includeTools", "kind"],
|
|
1111
|
+
queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "sourceRef", "timeframe", "includeTools", "kind"],
|
|
882
1112
|
requestSchema: null,
|
|
883
1113
|
responseSchema: "ListConversationsResponseDto"
|
|
884
1114
|
},
|
|
@@ -1028,7 +1258,7 @@ var OPERATIONS = {
|
|
|
1028
1258
|
service: "modus-api",
|
|
1029
1259
|
serverUrl: "https://api.getmodus.com",
|
|
1030
1260
|
pathParams: ["id"],
|
|
1031
|
-
queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "timeframe", "includeTools"],
|
|
1261
|
+
queryParams: ["pageToken", "page", "pageSize", "userId", "toolName", "source", "sourceRef", "timeframe", "includeTools"],
|
|
1032
1262
|
requestSchema: null,
|
|
1033
1263
|
responseSchema: "ListConversationsResponseDto"
|
|
1034
1264
|
},
|
|
@@ -1581,7 +1811,9 @@ var WRITE_BODY_ALLOWED_KEYS = {
|
|
|
1581
1811
|
ContextCreatorsController_createLink: ["url", "title", "isCrawl", "pageLimit"],
|
|
1582
1812
|
ContextCreatorsController_createNote: ["title", "content"],
|
|
1583
1813
|
ContextCreatorsController_createSavedQuery: ["name", "connectionId", "query", "description", "path"],
|
|
1584
|
-
|
|
1814
|
+
ContextFilesController_finalize: ["fileName", "folderPath"],
|
|
1815
|
+
ContextFilesController_finalizeMany: ["uploads"],
|
|
1816
|
+
ContextFilesController_uploadFromUrl: ["url", "fileName", "folderPath"],
|
|
1585
1817
|
ContextFilesController_uploadFromUrls: ["urls"],
|
|
1586
1818
|
ContextFilesController_uploadUrl: ["fileName", "contentType", "fileSize"],
|
|
1587
1819
|
ContextFilesController_uploadUrls: ["files"],
|
|
@@ -1589,8 +1821,18 @@ var WRITE_BODY_ALLOWED_KEYS = {
|
|
|
1589
1821
|
ContextItemsController_update: ["contextType", "content", "description", "userFeedback", "topics"],
|
|
1590
1822
|
CustomContextItemsController_batchCreate: ["items"],
|
|
1591
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"],
|
|
1592
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"],
|
|
1593
1834
|
EvaluationsController_updateConfig: ["enabled", "cadence", "judgeModel", "judgeGuidance", "notifications"],
|
|
1835
|
+
IngestedDataController_upload: ["integration_type", "request", "response"],
|
|
1594
1836
|
ModusChatController_chat: ["message", "model"],
|
|
1595
1837
|
ModusContextController_compose: ["message", "limit"],
|
|
1596
1838
|
ModusRunsController_create: ["message", "sessionId", "organizationId", "version", "fileThreadId", "config", "attachments", "userContext", "source", "runId", "subordinateSkillIds"],
|
|
@@ -1819,6 +2061,13 @@ var ManagementWorkflowsResource = class {
|
|
|
1819
2061
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
1820
2062
|
* @param options.includeVariation - Include variation payload on each list row.
|
|
1821
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
|
+
* ```
|
|
1822
2071
|
*/
|
|
1823
2072
|
list(options = {}) {
|
|
1824
2073
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -1851,6 +2100,12 @@ var ManagementWorkflowsResource = class {
|
|
|
1851
2100
|
* @param workflowId - Workflow id.
|
|
1852
2101
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
1853
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
|
+
* ```
|
|
1854
2109
|
*/
|
|
1855
2110
|
async get(workflowId, options = {}) {
|
|
1856
2111
|
validateId(workflowId, "workflow_id");
|
|
@@ -1880,7 +2135,8 @@ var ManagementWorkflowsResource = class {
|
|
|
1880
2135
|
* @returns The created workflow (draft).
|
|
1881
2136
|
* @example
|
|
1882
2137
|
* ```ts
|
|
1883
|
-
* const
|
|
2138
|
+
* const mgmt = new ModusManagement()
|
|
2139
|
+
* const wf = await mgmt.workflows.create({ name: 'Daily report', type: 'task' })
|
|
1884
2140
|
* ```
|
|
1885
2141
|
*/
|
|
1886
2142
|
async create(options) {
|
|
@@ -1908,6 +2164,11 @@ var ManagementWorkflowsResource = class {
|
|
|
1908
2164
|
* @param options.guardrails - Guardrail labels to set. Fetches the current workflow first to merge. Pass `[]` to clear all.
|
|
1909
2165
|
* @param options.updateMask - Comma-separated field names to update or clear.
|
|
1910
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
|
+
* ```
|
|
1911
2172
|
*/
|
|
1912
2173
|
async update(workflowId, options = {}) {
|
|
1913
2174
|
validateId(workflowId, "workflow_id");
|
|
@@ -1943,8 +2204,9 @@ var ManagementWorkflowsResource = class {
|
|
|
1943
2204
|
* @returns The published workflow.
|
|
1944
2205
|
* @example
|
|
1945
2206
|
* ```ts
|
|
1946
|
-
*
|
|
1947
|
-
*
|
|
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')
|
|
1948
2210
|
* ```
|
|
1949
2211
|
*/
|
|
1950
2212
|
async deploy(workflowId) {
|
|
@@ -1977,6 +2239,11 @@ var ManagementWorkflowsResource = class {
|
|
|
1977
2239
|
*
|
|
1978
2240
|
* @param workflowId - Workflow id.
|
|
1979
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
|
+
* ```
|
|
1980
2247
|
*/
|
|
1981
2248
|
async delete(workflowId) {
|
|
1982
2249
|
validateId(workflowId, "workflow_id");
|
|
@@ -2082,6 +2349,12 @@ var CustomContextItemsResource = class {
|
|
|
2082
2349
|
* @param options.searchQuery - Free-text search filter.
|
|
2083
2350
|
* @param options.topics - Filter to items tagged with any of these topics.
|
|
2084
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
|
+
* ```
|
|
2085
2358
|
*/
|
|
2086
2359
|
list(options = {}) {
|
|
2087
2360
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -2110,6 +2383,11 @@ var CustomContextItemsResource = class {
|
|
|
2110
2383
|
* @param uid - Item uid.
|
|
2111
2384
|
* @returns The custom context item.
|
|
2112
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
|
+
* ```
|
|
2113
2391
|
*/
|
|
2114
2392
|
async get(uid) {
|
|
2115
2393
|
return parseContextItem(
|
|
@@ -2130,6 +2408,7 @@ var CustomContextItemsResource = class {
|
|
|
2130
2408
|
*
|
|
2131
2409
|
* @example
|
|
2132
2410
|
* ```ts
|
|
2411
|
+
* const client = new Modus()
|
|
2133
2412
|
* const created = await client.context.customItems.create({
|
|
2134
2413
|
* kind: 'entity',
|
|
2135
2414
|
* sourceId: 'my-source',
|
|
@@ -2153,6 +2432,7 @@ var CustomContextItemsResource = class {
|
|
|
2153
2432
|
*
|
|
2154
2433
|
* @example
|
|
2155
2434
|
* ```ts
|
|
2435
|
+
* const client = new Modus()
|
|
2156
2436
|
* const created = await client.context.customItems.batchCreate([
|
|
2157
2437
|
* { kind: 'field', sourceId: 'src', fieldName: 'region', dataType: 'string' },
|
|
2158
2438
|
* { kind: 'field', sourceId: 'src', fieldName: 'amount', dataType: 'number' },
|
|
@@ -2170,12 +2450,45 @@ var CustomContextItemsResource = class {
|
|
|
2170
2450
|
const items = data.contextItems;
|
|
2171
2451
|
return Array.isArray(items) ? items.map(parseCreatedCustomContextItem) : [];
|
|
2172
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
|
+
}
|
|
2173
2479
|
/**
|
|
2174
2480
|
* Update a custom context item.
|
|
2175
2481
|
*
|
|
2176
2482
|
* @param uid - Item uid.
|
|
2177
2483
|
* @param input - Fields to change (kind and hierarchy ids cannot be changed).
|
|
2178
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
|
+
* ```
|
|
2179
2492
|
*/
|
|
2180
2493
|
async update(uid, input) {
|
|
2181
2494
|
return asRecord(
|
|
@@ -2190,6 +2503,11 @@ var CustomContextItemsResource = class {
|
|
|
2190
2503
|
*
|
|
2191
2504
|
* @param uid - Item uid.
|
|
2192
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
|
+
* ```
|
|
2193
2511
|
*/
|
|
2194
2512
|
async delete(uid) {
|
|
2195
2513
|
return parseDeletion(
|
|
@@ -2283,6 +2601,523 @@ async function resolveAndUpdateLink(items, uid, options) {
|
|
|
2283
2601
|
});
|
|
2284
2602
|
}
|
|
2285
2603
|
|
|
2604
|
+
// src/management/context/dashboards.ts
|
|
2605
|
+
var ManagementDashboardElementsResource = class {
|
|
2606
|
+
/** @internal */
|
|
2607
|
+
constructor(http, config, dashboardId) {
|
|
2608
|
+
this.http = http;
|
|
2609
|
+
this.config = config;
|
|
2610
|
+
this.dashboardId = dashboardId;
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* List every tile and filter on the dashboard draft.
|
|
2614
|
+
*
|
|
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
|
+
* ```
|
|
2623
|
+
*/
|
|
2624
|
+
async list() {
|
|
2625
|
+
return asRecord(
|
|
2626
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_listElements", {
|
|
2627
|
+
pathParams: { dashboardId: this.dashboardId }
|
|
2628
|
+
})
|
|
2629
|
+
);
|
|
2630
|
+
}
|
|
2631
|
+
/**
|
|
2632
|
+
* Get the full draft settings of one tile or filter.
|
|
2633
|
+
*
|
|
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
|
+
* ```
|
|
2643
|
+
*/
|
|
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
|
+
);
|
|
2651
|
+
}
|
|
2652
|
+
/**
|
|
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
|
+
|
|
2286
3121
|
// src/management/context/files.ts
|
|
2287
3122
|
var import_promises = require("fs/promises");
|
|
2288
3123
|
var import_node_path = require("path");
|
|
@@ -2318,14 +3153,16 @@ function chunked(items, size) {
|
|
|
2318
3153
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
2319
3154
|
return out;
|
|
2320
3155
|
}
|
|
2321
|
-
async function mapWithConcurrency(items, concurrency, worker) {
|
|
3156
|
+
async function mapWithConcurrency(items, concurrency, worker, onItemDone) {
|
|
2322
3157
|
const results = new Array(items.length);
|
|
2323
3158
|
let cursor = 0;
|
|
2324
3159
|
async function run() {
|
|
2325
3160
|
for (; ; ) {
|
|
2326
3161
|
const index = cursor++;
|
|
2327
3162
|
if (index >= items.length) return;
|
|
2328
|
-
|
|
3163
|
+
const result = await worker(items[index]);
|
|
3164
|
+
results[index] = result;
|
|
3165
|
+
onItemDone?.(result);
|
|
2329
3166
|
}
|
|
2330
3167
|
}
|
|
2331
3168
|
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, run));
|
|
@@ -2371,25 +3208,29 @@ function createSlotsPayload(files) {
|
|
|
2371
3208
|
}
|
|
2372
3209
|
function uploadFromUrlsPayload(urls) {
|
|
2373
3210
|
return {
|
|
2374
|
-
urls: urls.map((u) =>
|
|
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
|
+
}))
|
|
2375
3216
|
};
|
|
2376
3217
|
}
|
|
2377
3218
|
function assignSlots(batch, result, failed) {
|
|
2378
3219
|
const failedIndices = new Set(result.failed.map((f) => f.index));
|
|
2379
3220
|
for (const f of result.failed) {
|
|
2380
|
-
failed.push({ path: batch[f.index], error: f.error });
|
|
3221
|
+
failed.push({ path: batch[f.index]?.path ?? "", error: f.error });
|
|
2381
3222
|
}
|
|
2382
3223
|
const remaining = batch.filter((_, i) => !failedIndices.has(i));
|
|
2383
3224
|
const uploaded = result.uploaded;
|
|
2384
3225
|
if (uploaded.length < remaining.length) {
|
|
2385
|
-
for (const
|
|
2386
|
-
failed.push({ path, error: "Server returned fewer upload slots than requested files." });
|
|
3226
|
+
for (const file of remaining.slice(uploaded.length)) {
|
|
3227
|
+
failed.push({ path: file.path, error: "Server returned fewer upload slots than requested files." });
|
|
2387
3228
|
}
|
|
2388
3229
|
}
|
|
2389
3230
|
const paired = Math.min(remaining.length, uploaded.length);
|
|
2390
3231
|
const assignments = [];
|
|
2391
3232
|
for (let i = 0; i < paired; i++) {
|
|
2392
|
-
assignments.push({
|
|
3233
|
+
assignments.push({ ...remaining[i], slot: uploaded[i] });
|
|
2393
3234
|
}
|
|
2394
3235
|
return assignments;
|
|
2395
3236
|
}
|
|
@@ -2407,7 +3248,10 @@ var ManagementContextFilesResource = class {
|
|
|
2407
3248
|
* Office/OpenDocument documents, audio, and video.
|
|
2408
3249
|
* @param input.fileSize - File size in bytes. Rejected above 50MB.
|
|
2409
3250
|
* @returns Presigned upload slot. PUT the raw bytes to `uploadUrl` within 15
|
|
2410
|
-
* minutes, then
|
|
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`.
|
|
2411
3255
|
*/
|
|
2412
3256
|
async createUploadUrl(input) {
|
|
2413
3257
|
return asRecord(
|
|
@@ -2442,7 +3286,11 @@ var ManagementContextFilesResource = class {
|
|
|
2442
3286
|
async uploadFromUrl(url, options = {}) {
|
|
2443
3287
|
return asRecord(
|
|
2444
3288
|
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrl", {
|
|
2445
|
-
jsonBody:
|
|
3289
|
+
jsonBody: {
|
|
3290
|
+
url,
|
|
3291
|
+
...options.fileName !== void 0 ? { fileName: options.fileName } : {},
|
|
3292
|
+
...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {}
|
|
3293
|
+
}
|
|
2446
3294
|
})
|
|
2447
3295
|
);
|
|
2448
3296
|
}
|
|
@@ -2496,6 +3344,64 @@ var ManagementContextFilesResource = class {
|
|
|
2496
3344
|
);
|
|
2497
3345
|
return buildAipPage(data, "files", (raw) => raw, (token) => this.listPage(pageSize, token));
|
|
2498
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
|
+
}
|
|
2499
3405
|
/**
|
|
2500
3406
|
* Upload a local file and wait for it to reach `"processing"` or `"ready"`.
|
|
2501
3407
|
*
|
|
@@ -2523,6 +3429,8 @@ var ManagementContextFilesResource = class {
|
|
|
2523
3429
|
});
|
|
2524
3430
|
const data = await (0, import_promises.readFile)(path);
|
|
2525
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;
|
|
2526
3434
|
return this.pollUntil(
|
|
2527
3435
|
slot.uploadId,
|
|
2528
3436
|
waitUntil,
|
|
@@ -2555,6 +3463,7 @@ var ManagementContextFilesResource = class {
|
|
|
2555
3463
|
* @param options.recursive - Recurse into subdirectories (default `true`).
|
|
2556
3464
|
* @param options.concurrency - Max concurrent PUT+poll operations (default 10).
|
|
2557
3465
|
* @param options.waitUntil - `"processing"` (default) or `"ready"` — same as `upload()`.
|
|
3466
|
+
* @param options.onProgress - Optional progress callback after each file.
|
|
2558
3467
|
* @returns `UploadDirResult` with every successful `FileUpload` and every
|
|
2559
3468
|
* per-file failure (slot creation or PUT/poll), each tagged with its local path.
|
|
2560
3469
|
*/
|
|
@@ -2565,49 +3474,135 @@ var ManagementContextFilesResource = class {
|
|
|
2565
3474
|
if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
|
|
2566
3475
|
const dirStat = await (0, import_promises.stat)(path);
|
|
2567
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}`);
|
|
2568
3490
|
const uploaded = [];
|
|
2569
3491
|
const failed = [];
|
|
2570
|
-
const
|
|
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
|
+
};
|
|
2571
3503
|
for (const batch of chunked(files, MAX_BULK_UPLOAD_FILES)) {
|
|
3504
|
+
const failedBefore = failed.length;
|
|
2572
3505
|
const slots = await this.createSlots(batch, failed);
|
|
2573
|
-
|
|
2574
|
-
|
|
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) => {
|
|
2575
3511
|
if ("error" in result) failed.push(result);
|
|
2576
3512
|
else uploaded.push(result);
|
|
2577
|
-
|
|
3513
|
+
emit();
|
|
3514
|
+
});
|
|
2578
3515
|
}
|
|
2579
3516
|
return { uploaded, failed };
|
|
2580
3517
|
}
|
|
2581
3518
|
async createSlots(batch, failed) {
|
|
2582
3519
|
const readable = [];
|
|
2583
3520
|
const inputs = [];
|
|
2584
|
-
for (const
|
|
3521
|
+
for (const file of batch) {
|
|
2585
3522
|
try {
|
|
2586
|
-
const fileStat = await (0, import_promises.stat)(path);
|
|
2587
|
-
const fileName = path.split(/[/\\]/).pop();
|
|
3523
|
+
const fileStat = await (0, import_promises.stat)(file.path);
|
|
3524
|
+
const fileName = file.path.split(/[/\\]/).pop();
|
|
2588
3525
|
inputs.push({ fileName, contentType: DEFER_CONTENT_TYPE_TO_SERVER, fileSize: fileStat.size });
|
|
2589
|
-
readable.push(
|
|
3526
|
+
readable.push(file);
|
|
2590
3527
|
} catch (error) {
|
|
2591
3528
|
const message = error instanceof Error ? error.message : String(error);
|
|
2592
|
-
failed.push({ path, error: message });
|
|
3529
|
+
failed.push({ path: file.path, error: message });
|
|
2593
3530
|
}
|
|
2594
3531
|
}
|
|
2595
3532
|
if (inputs.length === 0) return [];
|
|
2596
3533
|
const result = await this.createUploadUrls(inputs);
|
|
2597
3534
|
return assignSlots(readable, result, failed);
|
|
2598
3535
|
}
|
|
2599
|
-
async uploadBatch(slots, waitUntil, concurrency) {
|
|
3536
|
+
async uploadBatch(slots, waitUntil, concurrency, onOutcome) {
|
|
2600
3537
|
if (slots.length === 0) return [];
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
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
|
+
}
|
|
2609
3557
|
}
|
|
2610
|
-
|
|
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;
|
|
2611
3606
|
}
|
|
2612
3607
|
};
|
|
2613
3608
|
|
|
@@ -2722,6 +3717,7 @@ var ManagementContextResource = class {
|
|
|
2722
3717
|
this.items = new ManagementContextItemsResource(http, config);
|
|
2723
3718
|
this.customItems = new CustomContextItemsResource(http, config);
|
|
2724
3719
|
this.files = new ManagementContextFilesResource(http, config);
|
|
3720
|
+
this.dashboards = new ManagementDashboardsResource(http, config);
|
|
2725
3721
|
}
|
|
2726
3722
|
/**
|
|
2727
3723
|
* Add a free-form text note to the knowledge base.
|
|
@@ -2731,6 +3727,7 @@ var ManagementContextResource = class {
|
|
|
2731
3727
|
* @returns The created context item.
|
|
2732
3728
|
* @example
|
|
2733
3729
|
* ```ts
|
|
3730
|
+
* const mgmt = new ModusManagement()
|
|
2734
3731
|
* const note = await mgmt.context.createNote('Runbook', '# Steps\n1. Check logs')
|
|
2735
3732
|
* ```
|
|
2736
3733
|
*/
|
|
@@ -2748,6 +3745,14 @@ var ManagementContextResource = class {
|
|
|
2748
3745
|
* @param options.body - New markdown body.
|
|
2749
3746
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
2750
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
|
+
* ```
|
|
2751
3756
|
*/
|
|
2752
3757
|
updateNote(uid, options) {
|
|
2753
3758
|
return resolveAndUpdateNote(this.items, uid, options);
|
|
@@ -2760,6 +3765,14 @@ var ManagementContextResource = class {
|
|
|
2760
3765
|
* @param options.query - SQL text.
|
|
2761
3766
|
* @param options.path - Optional hierarchy path segments.
|
|
2762
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
|
+
* ```
|
|
2763
3776
|
*/
|
|
2764
3777
|
createSavedQuery(name, options) {
|
|
2765
3778
|
return this.create(
|
|
@@ -2781,6 +3794,14 @@ var ManagementContextResource = class {
|
|
|
2781
3794
|
* @param options.query - New SQL text.
|
|
2782
3795
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
2783
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
|
+
* ```
|
|
2784
3805
|
*/
|
|
2785
3806
|
updateSavedQuery(uid, options) {
|
|
2786
3807
|
return resolveAndUpdateSavedQuery(this.items, uid, options);
|
|
@@ -2793,6 +3814,13 @@ var ManagementContextResource = class {
|
|
|
2793
3814
|
* @param options.isCrawl - When true, crawl linked pages into context.
|
|
2794
3815
|
* @param options.pageLimit - Maximum pages to crawl when `isCrawl` is true.
|
|
2795
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
|
+
* ```
|
|
2796
3824
|
*/
|
|
2797
3825
|
createLink(url, options = {}) {
|
|
2798
3826
|
return this.create(
|
|
@@ -2815,6 +3843,13 @@ var ManagementContextResource = class {
|
|
|
2815
3843
|
* @param options.url - New URL.
|
|
2816
3844
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
2817
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
|
+
* ```
|
|
2818
3853
|
*/
|
|
2819
3854
|
updateLink(uid, options) {
|
|
2820
3855
|
return resolveAndUpdateLink(this.items, uid, options);
|
|
@@ -2846,26 +3881,44 @@ var ScopeConversationsResource = class {
|
|
|
2846
3881
|
*
|
|
2847
3882
|
* @param options.pageSize - Items per page (default 25).
|
|
2848
3883
|
* @param options.pageToken - Opaque token from a previous page.
|
|
2849
|
-
* @
|
|
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
|
+
* ```
|
|
2850
3900
|
*/
|
|
2851
3901
|
list(options = {}) {
|
|
2852
3902
|
const pageSize = options.pageSize ?? 25;
|
|
2853
3903
|
validatePageSize(pageSize);
|
|
2854
|
-
return this.listPage(pageSize, options.pageToken);
|
|
3904
|
+
return this.listPage(pageSize, options.pageToken, options.source, options.sourceRef);
|
|
2855
3905
|
}
|
|
2856
|
-
async listPage(pageSize, pageToken) {
|
|
3906
|
+
async listPage(pageSize, pageToken, source, sourceRef) {
|
|
2857
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;
|
|
2858
3911
|
const data = asRecord(
|
|
2859
3912
|
await invokeWithRetry(this.config, this.http, "ScopeConversationsController_list", {
|
|
2860
3913
|
pathParams: { id: this.scopeId },
|
|
2861
|
-
query: aipListParams(pageSize, pageToken)
|
|
3914
|
+
query: aipListParams(pageSize, pageToken, extra)
|
|
2862
3915
|
})
|
|
2863
3916
|
);
|
|
2864
3917
|
return buildAipPage(
|
|
2865
3918
|
data,
|
|
2866
3919
|
"conversations",
|
|
2867
3920
|
parseListItem,
|
|
2868
|
-
(token) => this.listPage(pageSize, token)
|
|
3921
|
+
(token) => this.listPage(pageSize, token, source, sourceRef)
|
|
2869
3922
|
);
|
|
2870
3923
|
}
|
|
2871
3924
|
/**
|
|
@@ -2874,7 +3927,15 @@ var ScopeConversationsResource = class {
|
|
|
2874
3927
|
* @param threadId - Conversation thread id.
|
|
2875
3928
|
* @param options.messageLimit - Maximum messages to return (1–100).
|
|
2876
3929
|
* @param options.beforeMessageIndex - Return messages before this index (requires messageLimit).
|
|
2877
|
-
* @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
|
+
* ```
|
|
2878
3939
|
*/
|
|
2879
3940
|
async get(threadId, options = {}) {
|
|
2880
3941
|
validateId(this.scopeId, "scope_id");
|
|
@@ -3183,7 +4244,14 @@ var ManagementScopesResource = class {
|
|
|
3183
4244
|
* @param options.search - Case-insensitive substring filter on the scope name.
|
|
3184
4245
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
3185
4246
|
* @param options.managerId - Return only scopes supervised by this manager scope id.
|
|
3186
|
-
* @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
|
+
* ```
|
|
3187
4255
|
*/
|
|
3188
4256
|
list(options = {}) {
|
|
3189
4257
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -3215,6 +4283,12 @@ var ManagementScopesResource = class {
|
|
|
3215
4283
|
* @param scopeId - Scope id.
|
|
3216
4284
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
3217
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
|
+
* ```
|
|
3218
4292
|
*/
|
|
3219
4293
|
async get(scopeId, options = {}) {
|
|
3220
4294
|
validateId(scopeId, "scope_id");
|
|
@@ -3237,7 +4311,9 @@ var ManagementScopesResource = class {
|
|
|
3237
4311
|
* @returns The created scope (draft).
|
|
3238
4312
|
* @example
|
|
3239
4313
|
* ```ts
|
|
4314
|
+
* const mgmt = new ModusManagement()
|
|
3240
4315
|
* const scope = await mgmt.scopes.create({ name: 'Support assistant', model: 'claude-sonnet-5' })
|
|
4316
|
+
* console.log(scope.id, scope.name)
|
|
3241
4317
|
* ```
|
|
3242
4318
|
*/
|
|
3243
4319
|
async create(options) {
|
|
@@ -3268,6 +4344,13 @@ var ManagementScopesResource = class {
|
|
|
3268
4344
|
* @param options.guardrails - Guardrail labels to set. Fetches the current scope first to merge. Pass `[]` to clear all.
|
|
3269
4345
|
* @param options.updateMask - Comma-separated field names to update or clear.
|
|
3270
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
|
+
* ```
|
|
3271
4354
|
*/
|
|
3272
4355
|
async update(scopeId, options = {}) {
|
|
3273
4356
|
validateId(scopeId, "scope_id");
|
|
@@ -3309,8 +4392,10 @@ var ManagementScopesResource = class {
|
|
|
3309
4392
|
* @returns The published scope.
|
|
3310
4393
|
* @example
|
|
3311
4394
|
* ```ts
|
|
3312
|
-
*
|
|
3313
|
-
* const
|
|
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)
|
|
3314
4399
|
* ```
|
|
3315
4400
|
*/
|
|
3316
4401
|
async deploy(scopeId) {
|
|
@@ -3328,6 +4413,11 @@ var ManagementScopesResource = class {
|
|
|
3328
4413
|
*
|
|
3329
4414
|
* @param scopeId - Scope id.
|
|
3330
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
|
+
* ```
|
|
3331
4421
|
*/
|
|
3332
4422
|
async delete(scopeId) {
|
|
3333
4423
|
validateId(scopeId, "scope_id");
|