dataiku-sdk 3.2.0 → 3.3.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.
Files changed (120) hide show
  1. package/README.md +149 -46
  2. package/dist/build-metadata.json +1 -1
  3. package/dist/packages/types/src/index.d.ts +102 -0
  4. package/dist/packages/types/src/index.js +76 -0
  5. package/dist/src/cli/commands/app.js +57 -15
  6. package/dist/src/cli/commands/bundle.js +1 -1
  7. package/dist/src/cli/commands/code-env.js +13 -7
  8. package/dist/src/cli/commands/connection.d.ts +9 -0
  9. package/dist/src/cli/commands/connection.js +267 -1
  10. package/dist/src/cli/commands/data-collection.d.ts +2 -0
  11. package/dist/src/cli/commands/data-collection.js +164 -0
  12. package/dist/src/cli/commands/dataset.js +161 -32
  13. package/dist/src/cli/commands/future.js +2 -2
  14. package/dist/src/cli/commands/group.d.ts +2 -0
  15. package/dist/src/cli/commands/group.js +109 -0
  16. package/dist/src/cli/commands/index.js +151 -78
  17. package/dist/src/cli/commands/knowledge-bank.d.ts +2 -0
  18. package/dist/src/cli/commands/knowledge-bank.js +80 -0
  19. package/dist/src/cli/commands/llm.d.ts +2 -0
  20. package/dist/src/cli/commands/llm.js +93 -0
  21. package/dist/src/cli/commands/macro.d.ts +2 -0
  22. package/dist/src/cli/commands/macro.js +221 -0
  23. package/dist/src/cli/commands/ml-task.js +18 -6
  24. package/dist/src/cli/commands/notebook.js +6 -2
  25. package/dist/src/cli/commands/plugin.d.ts +2 -0
  26. package/dist/src/cli/commands/plugin.js +799 -0
  27. package/dist/src/cli/commands/project-folder.d.ts +2 -0
  28. package/dist/src/cli/commands/project-folder.js +197 -0
  29. package/dist/src/cli/commands/project-git.js +14 -54
  30. package/dist/src/cli/commands/project.js +52 -6
  31. package/dist/src/cli/commands/recipe.js +36 -1
  32. package/dist/src/cli/commands/saved-model.d.ts +5 -0
  33. package/dist/src/cli/commands/saved-model.js +388 -1
  34. package/dist/src/cli/commands/scenario.js +138 -1
  35. package/dist/src/cli/commands/user.d.ts +8 -0
  36. package/dist/src/cli/commands/user.js +296 -0
  37. package/dist/src/cli/contract.d.ts +1 -2
  38. package/dist/src/cli/contract.js +1089 -103
  39. package/dist/src/cli/flags.js +30 -1
  40. package/dist/src/cli/helpers/app-successor.d.ts +19 -4
  41. package/dist/src/cli/helpers/app-successor.js +90 -30
  42. package/dist/src/cli/helpers/cleanup.js +3 -1
  43. package/dist/src/cli/helpers/flow-zone.js +1 -2
  44. package/dist/src/cli/output.d.ts +1 -1
  45. package/dist/src/cli/output.js +23 -10
  46. package/dist/src/cli/usage.d.ts +1 -0
  47. package/dist/src/cli/usage.js +47 -1
  48. package/dist/src/cli.js +147 -41
  49. package/dist/src/client.d.ts +83 -5
  50. package/dist/src/client.js +185 -29
  51. package/dist/src/errors.d.ts +3 -0
  52. package/dist/src/errors.js +2 -0
  53. package/dist/src/index.d.ts +16 -7
  54. package/dist/src/index.js +11 -2
  55. package/dist/src/resources/analyses.js +1 -8
  56. package/dist/src/resources/applications.d.ts +8 -6
  57. package/dist/src/resources/applications.js +21 -21
  58. package/dist/src/resources/base.d.ts +4 -0
  59. package/dist/src/resources/base.js +15 -0
  60. package/dist/src/resources/bundles.d.ts +9 -4
  61. package/dist/src/resources/bundles.js +10 -5
  62. package/dist/src/resources/connections.d.ts +78 -1
  63. package/dist/src/resources/connections.js +132 -1
  64. package/dist/src/resources/data-collections.d.ts +118 -0
  65. package/dist/src/resources/data-collections.js +49 -0
  66. package/dist/src/resources/datasets.d.ts +69 -0
  67. package/dist/src/resources/datasets.js +99 -1
  68. package/dist/src/resources/futures.d.ts +4 -1
  69. package/dist/src/resources/futures.js +38 -6
  70. package/dist/src/resources/groups.d.ts +47 -0
  71. package/dist/src/resources/groups.js +56 -0
  72. package/dist/src/resources/jobs.d.ts +8 -13
  73. package/dist/src/resources/jobs.js +41 -16
  74. package/dist/src/resources/knowledge-banks.d.ts +58 -0
  75. package/dist/src/resources/knowledge-banks.js +61 -0
  76. package/dist/src/resources/llms.d.ts +92 -0
  77. package/dist/src/resources/llms.js +62 -0
  78. package/dist/src/resources/macros.d.ts +121 -0
  79. package/dist/src/resources/macros.js +231 -0
  80. package/dist/src/resources/ml-tasks.d.ts +37 -2
  81. package/dist/src/resources/ml-tasks.js +100 -20
  82. package/dist/src/resources/model-evaluation-stores.js +1 -8
  83. package/dist/src/resources/notebooks.d.ts +43 -7
  84. package/dist/src/resources/notebooks.js +53 -13
  85. package/dist/src/resources/plugins.d.ts +265 -0
  86. package/dist/src/resources/plugins.js +458 -0
  87. package/dist/src/resources/project-folders.d.ts +71 -0
  88. package/dist/src/resources/project-folders.js +57 -0
  89. package/dist/src/resources/project-git.d.ts +6 -0
  90. package/dist/src/resources/project-git.js +69 -42
  91. package/dist/src/resources/project-library.d.ts +0 -1
  92. package/dist/src/resources/project-library.js +1 -17
  93. package/dist/src/resources/projects.d.ts +19 -1
  94. package/dist/src/resources/projects.js +27 -1
  95. package/dist/src/resources/recipes.d.ts +15 -1
  96. package/dist/src/resources/recipes.js +73 -6
  97. package/dist/src/resources/saved-models.d.ts +134 -1
  98. package/dist/src/resources/saved-models.js +214 -6
  99. package/dist/src/resources/scenarios.d.ts +105 -0
  100. package/dist/src/resources/scenarios.js +232 -106
  101. package/dist/src/resources/sql.js +5 -1
  102. package/dist/src/resources/users.d.ts +129 -0
  103. package/dist/src/resources/users.js +128 -0
  104. package/dist/src/resources/webapps.d.ts +15 -2
  105. package/dist/src/resources/webapps.js +18 -4
  106. package/dist/src/schemas.d.ts +2 -2
  107. package/dist/src/schemas.js +1 -1
  108. package/dist/src/utils/deep-merge.d.ts +1 -1
  109. package/dist/src/utils/polling.d.ts +20 -0
  110. package/dist/src/utils/polling.js +27 -0
  111. package/dist/src/utils/response-file.js +1 -1
  112. package/dist/src/utils/secret-sanitize.d.ts +54 -0
  113. package/dist/src/utils/secret-sanitize.js +101 -0
  114. package/package.json +6 -5
  115. package/packages/types/dist/index.d.ts +102 -0
  116. package/packages/types/dist/index.js +76 -0
  117. package/plugin.json +1 -1
  118. package/skills/dataiku-dss/SKILL.md +7 -5
  119. package/skills/dataiku-dss/references/app-releases.md +8 -7
  120. package/skills/dataiku-dss/references/discovery.md +4 -4
@@ -712,6 +712,104 @@ export class DatasetsResource extends BaseResource {
712
712
  const dsEnc = encodeURIComponent(datasetName);
713
713
  return this.client.get(`/public/api/projects/${this.enc(projectKey)}/datasets/${dsEnc}/metadata`);
714
714
  }
715
+ /**
716
+ * Replace dataset metadata with the given object (faithful PUT per the DSS
717
+ * API contract: the caller GETs the metadata, edits it, and PUTs the full
718
+ * object back — no partial merge is applied client-side). `label`,
719
+ * `description`, `tags`, and `custom` are the documented writable fields;
720
+ * any additional server-provided metadata fields present in the object are
721
+ * preserved verbatim.
722
+ */
723
+ async updateMetadata(datasetName, metadata, projectKey) {
724
+ if (metadata === null || Array.isArray(metadata)) {
725
+ throw new ClientValidationError("metadata must be a JSON object.");
726
+ }
727
+ const dsEnc = encodeURIComponent(datasetName);
728
+ return this.client.put(`/public/api/projects/${this.enc(projectKey)}/datasets/${dsEnc}/metadata`, metadata);
729
+ }
730
+ /**
731
+ * Create a managed dataset through the dedicated
732
+ * `POST /projects/{projectKey}/datasets/managed` endpoint. DSS handles the
733
+ * format/storage details: you select the name, the connection, and optional
734
+ * type/format/partitioning options. The endpoint answers `204` with no
735
+ * body; the returned settings echo what was sent.
736
+ */
737
+ async createManaged(opts, projectKey) {
738
+ const name = typeof opts.name === "string" ? opts.name.trim() : "";
739
+ if (name === "") {
740
+ throw new ClientValidationError("name must be a non-empty dataset name.");
741
+ }
742
+ const connection = typeof opts.connection === "string" ? opts.connection.trim() : "";
743
+ if (connection === "") {
744
+ throw new ClientValidationError("connection must be a non-empty connection name.");
745
+ }
746
+ if (opts.partitioningOptionId !== undefined && opts.copyPartitioningFrom !== undefined) {
747
+ throw new ClientValidationError("Pass either partitioningOptionId or copyPartitioningFrom, not both.");
748
+ }
749
+ if (opts.copyPartitioningFrom !== undefined
750
+ && (typeof opts.copyPartitioningFrom.ref !== "string"
751
+ || opts.copyPartitioningFrom.ref.trim() === "")) {
752
+ throw new ClientValidationError("copyPartitioningFrom.ref must be a non-empty dataset or folder name.");
753
+ }
754
+ const pk = this.resolveProjectKey(projectKey);
755
+ const creationSettings = { connectionId: connection, };
756
+ if (opts.typeOptionId !== undefined)
757
+ creationSettings.typeOptionId = opts.typeOptionId;
758
+ if (opts.formatOptionId !== undefined || opts.partitioningOptionId !== undefined
759
+ || opts.copyPartitioningFrom !== undefined) {
760
+ const specificSettings = {};
761
+ if (opts.formatOptionId !== undefined) {
762
+ specificSettings.formatOptionId = opts.formatOptionId;
763
+ }
764
+ if (opts.partitioningOptionId !== undefined) {
765
+ specificSettings.partitioningOptionId = opts.partitioningOptionId;
766
+ }
767
+ else if (opts.copyPartitioningFrom !== undefined) {
768
+ const code = opts.copyPartitioningFrom.type === "FOLDER" ? "folder" : "dataset";
769
+ specificSettings.partitioningOptionId = `copy:${code}:${opts.copyPartitioningFrom.ref.trim()}`;
770
+ }
771
+ creationSettings.specificSettings = specificSettings;
772
+ }
773
+ await this.client.post(`/public/api/projects/${encodeURIComponent(pk)}/datasets/managed`, { name, creationSettings, });
774
+ return { datasetName: name, projectKey: pk, creationSettings, };
775
+ }
776
+ /**
777
+ * Get the full info object for a dataset (type, parameters, last build
778
+ * information, schema, etc.). The server returns a complex opaque object;
779
+ * it is surfaced without validation.
780
+ */
781
+ async info(datasetName, projectKey) {
782
+ const dsEnc = encodeURIComponent(datasetName);
783
+ return this.client.get(`/public/api/projects/${this.enc(projectKey)}/datasets/${dsEnc}/info`);
784
+ }
785
+ /**
786
+ * Get the full column lineage (auto-computed and manual) of a column in
787
+ * this dataset. Relations with datasets from both local and foreign
788
+ * projects are included.
789
+ *
790
+ * Route per the official Python client:
791
+ * `GET /projects/{projectKey}/datasets/{datasetName}/column-lineage`
792
+ * with query `columnName` (required) and `maxDatasetCount` (optional,
793
+ * positive integer — the docs page renders a merged project-scoped path,
794
+ * but DSS's own client and route registry use this per-dataset form).
795
+ */
796
+ async getColumnLineage(datasetName, column, opts = {}) {
797
+ const trimmed = typeof column === "string" ? column.trim() : "";
798
+ if (trimmed === "") {
799
+ throw new ClientValidationError("column must be a non-empty column name.");
800
+ }
801
+ const maxDatasetCount = opts.maxDatasetCount;
802
+ if (maxDatasetCount !== undefined
803
+ && (!Number.isSafeInteger(maxDatasetCount) || maxDatasetCount <= 0)) {
804
+ throw new ClientValidationError("maxDatasetCount must be a positive integer.");
805
+ }
806
+ const dsEnc = encodeURIComponent(datasetName);
807
+ const params = [`columnName=${encodeURIComponent(trimmed)}`,];
808
+ if (maxDatasetCount !== undefined) {
809
+ params.push(`maxDatasetCount=${encodeURIComponent(String(maxDatasetCount))}`);
810
+ }
811
+ return this.client.get(`/public/api/projects/${this.enc(opts?.projectKey)}/datasets/${dsEnc}/column-lineage?${params.join("&")}`);
812
+ }
715
813
  /**
716
814
  * Download dataset rows as a gzipped (or .csv) file, capped at `limit` rows
717
815
  * (default 100k). Returns the written path, the number of data rows written,
@@ -746,7 +844,7 @@ export class DatasetsResource extends BaseResource {
746
844
  : undefined;
747
845
  const shouldGzip = filePath.endsWith(".gz");
748
846
  const stats = { rows: 0, truncated: false, };
749
- const nodeStream = Readable.fromWeb(res.body);
847
+ const nodeStream = Readable.from(res.body, { objectMode: false, });
750
848
  const csvTransform = tsvToCsvTransform(limit, stats, onHeader, opts?.rawData !== true);
751
849
  fs.mkdirSync(nodePath.dirname(filePath), { recursive: true, });
752
850
  const fileOut = fs.createWriteStream(filePath);
@@ -5,10 +5,13 @@ export interface FutureWaitOptions {
5
5
  timeoutMs?: number;
6
6
  }
7
7
  export declare class FuturesResource extends BaseResource {
8
- get(futureId: string): Promise<FutureState>;
8
+ get(futureId: string, opts?: {
9
+ timeoutMs?: number;
10
+ }): Promise<FutureState>;
9
11
  peek(futureId: string): Promise<FutureState>;
10
12
  state(futureId: string, opts?: {
11
13
  peek?: boolean;
14
+ timeoutMs?: number;
12
15
  }): Promise<FutureState>;
13
16
  abort(futureId: string): Promise<void>;
14
17
  wait(futureId: string, opts?: FutureWaitOptions): Promise<FutureWaitResult>;
@@ -1,4 +1,5 @@
1
1
  import { FutureStateSchema, FutureWaitResultSchema, } from "../schemas.js";
2
+ import { computeNextPollDelayMs, isRequestDeadlineError, } from "../utils/polling.js";
2
3
  import { BaseResource, } from "./base.js";
3
4
  const DEFAULT_POLL_INTERVAL_MS = 2_000;
4
5
  const DEFAULT_TIMEOUT_MS = 120_000;
@@ -23,8 +24,8 @@ function waitState(state) {
23
24
  return "RUNNING";
24
25
  }
25
26
  export class FuturesResource extends BaseResource {
26
- async get(futureId) {
27
- return this.state(futureId, { peek: false, });
27
+ async get(futureId, opts = {}) {
28
+ return this.state(futureId, { peek: false, timeoutMs: opts.timeoutMs, });
28
29
  }
29
30
  async peek(futureId) {
30
31
  return this.state(futureId, { peek: true, });
@@ -32,14 +33,18 @@ export class FuturesResource extends BaseResource {
32
33
  async state(futureId, opts = {}) {
33
34
  const params = new URLSearchParams();
34
35
  params.set("peek", String(opts.peek === true));
35
- const raw = await this.client.get(`/public/api/futures/${encodeURIComponent(futureId)}?${params.toString()}`);
36
+ const raw = await this.client.get(`/public/api/futures/${encodeURIComponent(futureId)}?${params.toString()}`, { timeoutMs: opts.timeoutMs, });
36
37
  return this.client.safeParse(FutureStateSchema, raw, "futures.state");
37
38
  }
38
39
  async abort(futureId) {
39
40
  await this.client.del(`/public/api/futures/${encodeURIComponent(futureId)}`);
40
41
  }
41
42
  async wait(futureId, opts = {}) {
42
- const baseIntervalMs = Math.max(1, opts.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);
43
+ // Adaptive backoff is the default; an explicit pollIntervalMs is an
44
+ // exact contract the caller chose, so it is never adapted.
45
+ const explicitIntervalMs = opts.pollIntervalMs;
46
+ const baseIntervalMs = Math.max(1, explicitIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);
47
+ const adaptiveEnabled = explicitIntervalMs === undefined;
43
48
  // A caller's budget is never rounded up to a whole poll interval: a 5ms
44
49
  // wait must answer in about 5ms. One state observation always happens
45
50
  // regardless, because the poll precedes the deadline check.
@@ -48,7 +53,29 @@ export class FuturesResource extends BaseResource {
48
53
  let pollCount = 0;
49
54
  while (true) {
50
55
  pollCount += 1;
51
- const state = await this.get(futureId);
56
+ // One state observation always happens, even when the budget is
57
+ // already spent (the poll precedes the deadline check); only the
58
+ // requests issued while budget remains are bounded by the remaining
59
+ // time, so a stalled status endpoint can never defeat the deadline.
60
+ const remainingMs = timeoutMs - (Date.now() - startedAt);
61
+ let state;
62
+ try {
63
+ state = await this.get(futureId, remainingMs > 0 ? { timeoutMs: remainingMs, } : undefined);
64
+ }
65
+ catch (error) {
66
+ // The poll budget ran out mid-request: report the structured
67
+ // timeout instead of letting the transport deadline error escape.
68
+ if (!isRequestDeadlineError(error, startedAt + timeoutMs))
69
+ throw error;
70
+ return this.client.safeParse(FutureWaitResultSchema, {
71
+ futureId,
72
+ state: "RUNNING",
73
+ elapsedMs: Date.now() - startedAt,
74
+ pollCount,
75
+ success: false,
76
+ timedOut: true,
77
+ }, "futures.wait");
78
+ }
52
79
  const elapsedMs = Date.now() - startedAt;
53
80
  const status = waitState(state);
54
81
  if (isFinished(state)) {
@@ -85,7 +112,12 @@ export class FuturesResource extends BaseResource {
85
112
  }
86
113
  // Only the remaining budget is slept: a longer sleep would report an
87
114
  // elapsed time the caller never authorized.
88
- await sleep(Math.min(baseIntervalMs, timeoutMs - elapsedMs));
115
+ const nextDelayMs = computeNextPollDelayMs({
116
+ pollCount,
117
+ baseIntervalMs,
118
+ adaptiveEnabled,
119
+ });
120
+ await sleep(Math.min(nextDelayMs, timeoutMs - elapsedMs));
89
121
  }
90
122
  }
91
123
  }
@@ -0,0 +1,47 @@
1
+ import { BaseResource } from "./base.js";
2
+ /**
3
+ * A DSS group as returned by the admin Security endpoints. The documented
4
+ * attributes below are stable; DSS may return undocumented extra attributes
5
+ * (per the API docs they must not be modified on update), so they are preserved
6
+ * under `Record<string, unknown>` and are never stripped by this SDK.
7
+ */
8
+ export interface DssGroup extends Record<string, unknown> {
9
+ name?: string;
10
+ description?: string;
11
+ /** Whether this group gives administrative rights on DSS. */
12
+ admin?: boolean;
13
+ sourceType?: string;
14
+ }
15
+ /**
16
+ * Body of `POST /admin/groups` (create) and the editable subset of the PUT
17
+ * body. DSS requires `name` on create; `admin` and `description` are optional.
18
+ */
19
+ export interface GroupCreateRequest extends Record<string, unknown> {
20
+ name: string;
21
+ description?: string;
22
+ admin?: boolean;
23
+ }
24
+ export declare class GroupsResource extends BaseResource {
25
+ /** Retrieves the list of DSS groups (Admin required). */
26
+ list(): Promise<DssGroup[]>;
27
+ /**
28
+ * Retrieves a Group object describing a DSS user group, used for access
29
+ * control on connections and projects (Admin required).
30
+ */
31
+ get(groupName: string): Promise<DssGroup>;
32
+ /**
33
+ * Creates a group (Admin required). DSS answers with
34
+ * `{msg: "Created group <name>"}`; the raw server record is returned as-is.
35
+ */
36
+ create(body: GroupCreateRequest): Promise<Record<string, unknown>>;
37
+ /**
38
+ * Updates a group (Admin required). Per the docs the body MUST have been
39
+ * obtained from a prior GET at the same URL; undocumented attributes should
40
+ * be passed through unmodified. DSS answers with `{msg: "Edited group ..."}`.
41
+ */
42
+ update(groupName: string, body: DssGroup): Promise<Record<string, unknown>>;
43
+ /** Deletes a DSS users group (Admin required). */
44
+ delete(groupName: string): Promise<{
45
+ deleted: string;
46
+ }>;
47
+ }
@@ -0,0 +1,56 @@
1
+ import { ClientValidationError, } from "../errors.js";
2
+ import { BaseResource, requireArrayResponse, requireNonEmpty, } from "./base.js";
3
+ function validateGroupBody(body, method) {
4
+ if (body === null || body === undefined || typeof body !== "object" || Array.isArray(body)) {
5
+ throw new ClientValidationError(`${method}: body must be a Group object.`);
6
+ }
7
+ const record = body;
8
+ if (record.admin !== undefined && typeof record.admin !== "boolean") {
9
+ throw new ClientValidationError(`${method}: admin must be a boolean.`);
10
+ }
11
+ return record;
12
+ }
13
+ export class GroupsResource extends BaseResource {
14
+ /** Retrieves the list of DSS groups (Admin required). */
15
+ async list() {
16
+ const raw = await this.client.get("/public/api/admin/groups");
17
+ return requireArrayResponse(raw, "groups.list");
18
+ }
19
+ /**
20
+ * Retrieves a Group object describing a DSS user group, used for access
21
+ * control on connections and projects (Admin required).
22
+ */
23
+ async get(groupName) {
24
+ const enc = requireNonEmpty(groupName, "groupName").trim();
25
+ return this.client.get(`/public/api/admin/groups/${encodeURIComponent(enc)}`);
26
+ }
27
+ /**
28
+ * Creates a group (Admin required). DSS answers with
29
+ * `{msg: "Created group <name>"}`; the raw server record is returned as-is.
30
+ */
31
+ async create(body) {
32
+ if (body === null || body === undefined || typeof body !== "object" || Array.isArray(body)
33
+ || typeof body.name !== "string"
34
+ || body.name.trim().length === 0) {
35
+ throw new ClientValidationError("groups.create: body.name is required.");
36
+ }
37
+ validateGroupBody(body, "groups.create");
38
+ return this.client.post("/public/api/admin/groups", body);
39
+ }
40
+ /**
41
+ * Updates a group (Admin required). Per the docs the body MUST have been
42
+ * obtained from a prior GET at the same URL; undocumented attributes should
43
+ * be passed through unmodified. DSS answers with `{msg: "Edited group ..."}`.
44
+ */
45
+ async update(groupName, body) {
46
+ const enc = requireNonEmpty(groupName, "groupName").trim();
47
+ const validated = validateGroupBody(body, "groups.update");
48
+ return this.client.put(`/public/api/admin/groups/${encodeURIComponent(enc)}`, validated);
49
+ }
50
+ /** Deletes a DSS users group (Admin required). */
51
+ async delete(groupName) {
52
+ const enc = requireNonEmpty(groupName, "groupName").trim();
53
+ await this.client.del(`/public/api/admin/groups/${encodeURIComponent(enc)}`);
54
+ return { deleted: enc, };
55
+ }
56
+ }
@@ -1,6 +1,13 @@
1
1
  import type { BuildMode, JobSummary, JobWaitResult } from "../schemas.js";
2
2
  import { BaseResource } from "./base.js";
3
- export type JobBuildTargetType = "DATASET" | "MANAGED_FOLDER";
3
+ /**
4
+ * Buildable target kinds. DATASET and MANAGED_FOLDER are user-selectable;
5
+ * MODEL_EVALUATION_STORE appears as a recipe output role and is a valid job
6
+ * target per the official client (recipe.run object_type_map maps
7
+ * COMPUTABLE_MODEL_EVALUATION_STORE to MODEL_EVALUATION_STORE before
8
+ * JobDefinition.with_output).
9
+ */
10
+ export type JobBuildTargetType = "DATASET" | "MANAGED_FOLDER" | "MODEL_EVALUATION_STORE";
4
11
  export type JobLogFilter = "stdout" | "stderr" | "user" | "errors";
5
12
  export interface JobLogProgress {
6
13
  lastProgressLine?: string;
@@ -46,17 +53,6 @@ export interface JobBuildAndWaitOptions extends JobBuildOptions {
46
53
  logId?: string;
47
54
  summary?: boolean;
48
55
  }
49
- interface ComputeNextPollDelayMsOptions {
50
- pollCount: number;
51
- baseIntervalMs: number;
52
- adaptiveEnabled: boolean;
53
- }
54
- /**
55
- * Compute the next poll delay.
56
- * When adaptive polling is enabled, the interval doubles every 3 polls,
57
- * capped at MAX_POLL_INTERVAL_MS (or baseIntervalMs if it's larger).
58
- */
59
- export declare function computeNextPollDelayMs({ pollCount, baseIntervalMs, adaptiveEnabled, }: ComputeNextPollDelayMsOptions): number;
60
56
  export declare function parseJobLogProgress(log: string, elapsedMs?: number): JobLogProgress | undefined;
61
57
  export declare class JobsResource extends BaseResource {
62
58
  /** List jobs in a project. */
@@ -146,4 +142,3 @@ export declare class JobsResource extends BaseResource {
146
142
  /** Request a job abort. */
147
143
  abort(jobId: string, projectKey?: string): Promise<void>;
148
144
  }
149
- export {};
@@ -1,8 +1,8 @@
1
1
  import { DataikuError, } from "../errors.js";
2
2
  import { JobSummaryArraySchema, } from "../schemas.js";
3
+ import { computeNextPollDelayMs, isRequestDeadlineError, } from "../utils/polling.js";
3
4
  import { BaseResource, } from "./base.js";
4
5
  const DEFAULT_POLL_INTERVAL_MS = 2_000;
5
- const MAX_POLL_INTERVAL_MS = 10_000;
6
6
  const DEFAULT_TIMEOUT_MS = 120_000;
7
7
  const DEFAULT_MAX_LOG_LINES = 500;
8
8
  /**
@@ -26,19 +26,6 @@ function isTerminalState(state) {
26
26
  function isSuccessfulTerminalState(state) {
27
27
  return (state ?? "").toUpperCase() === "DONE";
28
28
  }
29
- /**
30
- * Compute the next poll delay.
31
- * When adaptive polling is enabled, the interval doubles every 3 polls,
32
- * capped at MAX_POLL_INTERVAL_MS (or baseIntervalMs if it's larger).
33
- */
34
- export function computeNextPollDelayMs({ pollCount, baseIntervalMs, adaptiveEnabled, }) {
35
- if (!adaptiveEnabled) {
36
- return baseIntervalMs;
37
- }
38
- const step = Math.max(0, Math.floor((pollCount - 1) / 3));
39
- const interval = baseIntervalMs * 2 ** step;
40
- return Math.min(interval, Math.max(baseIntervalMs, MAX_POLL_INTERVAL_MS));
41
- }
42
29
  function sleep(ms) {
43
30
  return new Promise((resolve) => setTimeout(resolve, ms));
44
31
  }
@@ -48,7 +35,10 @@ function jobBuildOutput(target, defaultProjectKey, defaultPartition, defaultTarg
48
35
  const projectKey = target.projectKey ?? defaultProjectKey;
49
36
  const partition = target.partition ?? defaultPartition;
50
37
  const output = { projectKey, id: target.id, type: targetType, };
51
- if (targetType === "DATASET") {
38
+ if (targetType === "DATASET" || targetType === "MODEL_EVALUATION_STORE") {
39
+ // MES targets follow the plain {projectKey, id, type} shape (official
40
+ // JobDefinition.with_output sends the name/id plus object type, with no
41
+ // managed-folder indirection).
52
42
  if (partition !== undefined)
53
43
  output.partition = partition;
54
44
  }
@@ -294,12 +284,47 @@ export class JobsResource extends BaseResource {
294
284
  const jobEnc = encodeURIComponent(jobId);
295
285
  const baseIntervalMs = Math.max(1, opts?.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);
296
286
  const adaptivePolling = opts?.pollIntervalMs === undefined;
287
+ // Pre-existing contract: the effective budget is never below one poll
288
+ // interval, so a single observation always fits inside it.
297
289
  const timeout = Math.max(baseIntervalMs, opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS);
298
290
  const startedAt = Date.now();
299
291
  let pollCount = 0;
300
292
  while (true) {
301
293
  pollCount += 1;
302
- const j = await this.client.get(`/public/api/projects/${projectEnc}/jobs/${jobEnc}/`);
294
+ // One status observation always happens, even when the budget is
295
+ // already spent (the poll precedes the deadline check); only the
296
+ // requests issued while budget remains are bounded by the remaining
297
+ // time, so a stalled status endpoint can never defeat the deadline.
298
+ const elapsedBefore = Date.now() - startedAt;
299
+ const remainingMs = timeout - elapsedBefore;
300
+ let j;
301
+ try {
302
+ j = await this.client.get(`/public/api/projects/${projectEnc}/jobs/${jobEnc}/`, remainingMs > 0
303
+ ? { timeoutMs: remainingMs, }
304
+ : undefined);
305
+ }
306
+ catch (error) {
307
+ // The poll budget ran out mid-request: report the documented
308
+ // structured timeout instead of letting the transport deadline
309
+ // error escape the loop.
310
+ if (!isRequestDeadlineError(error, startedAt + timeout))
311
+ throw error;
312
+ return {
313
+ success: false,
314
+ jobId,
315
+ state: "unknown",
316
+ type: "unknown",
317
+ elapsedMs: Date.now() - startedAt,
318
+ pollCount,
319
+ timedOut: true,
320
+ progress: {
321
+ done: 0,
322
+ failed: 0,
323
+ running: 0,
324
+ total: null,
325
+ },
326
+ };
327
+ }
303
328
  const bs = j.baseStatus ?? {};
304
329
  const def = bs.def ?? {};
305
330
  const gs = j.globalState ?? {};
@@ -0,0 +1,58 @@
1
+ import { BaseResource } from "./base.js";
2
+ /** Search algorithm for knowledge-bank search, per the DSS 15 REST schema. */
3
+ export type KnowledgeBankSearchType = "SIMILARITY" | "SIMILARITY_THRESHOLD" | "MMR" | "HYBRID" | (string & {});
4
+ /**
5
+ * Optional search parameters, documented in the DSS 15 REST reference for
6
+ * `POST /projects/{projectKey}/knowledge-banks/{knowledgeBankId}/search`.
7
+ * Which knobs apply depends on the backing vector store.
8
+ */
9
+ export interface KnowledgeBankSearchParams {
10
+ /** Maximum number of documents to return (default 10). */
11
+ maxDocuments?: number;
12
+ /** Search algorithm. Defaults to SIMILARITY. */
13
+ searchType?: KnowledgeBankSearchType;
14
+ /** Similarity threshold; only applied for SIMILARITY_THRESHOLD. */
15
+ similarityThreshold?: number;
16
+ /** Documents considered before selection; only applied for MMR. */
17
+ mmrK?: number;
18
+ /** 0..1 balance of diversity (0) vs relevancy (1); only applied for MMR. */
19
+ mmrDiversity?: number;
20
+ /** Proprietary rerankers; only valid for Azure AI and ElasticSearch stores. */
21
+ useAdvancedReranking?: boolean;
22
+ /** Weight of lower-ranked documents; only valid for ElasticSearch stores. */
23
+ rrfRankConstant?: number;
24
+ /** Documents considered per search type; only valid for ElasticSearch stores. */
25
+ rrfRankWindowSize?: number;
26
+ [key: string]: unknown;
27
+ }
28
+ /** Request body for knowledge-bank search. */
29
+ export interface KnowledgeBankSearchBody {
30
+ query: string;
31
+ params?: KnowledgeBankSearchParams;
32
+ }
33
+ /** One retrieved knowledge-bank document. Metadata is server-defined. */
34
+ export interface KnowledgeBankDocument extends Record<string, unknown> {
35
+ /** Document text content. */
36
+ text?: string;
37
+ /** Arbitrary server-defined metadata map. */
38
+ metadata?: Record<string, unknown>;
39
+ /** Relevance score in [0, 1] as returned by the backend. */
40
+ score?: number;
41
+ }
42
+ /** Response envelope of the knowledge-bank search endpoint. */
43
+ export interface KnowledgeBankSearchResult extends Record<string, unknown> {
44
+ documents?: KnowledgeBankDocument[];
45
+ }
46
+ export declare class KnowledgeBanksResource extends BaseResource {
47
+ /**
48
+ * Search a knowledge bank for documents matching a query string.
49
+ * Requires READ_CONF.
50
+ */
51
+ search(knowledgeBankId: string, body: KnowledgeBankSearchBody, projectKey?: string): Promise<KnowledgeBankSearchResult>;
52
+ /**
53
+ * Clear all data from a knowledge bank. DESTRUCTIVE: the stored knowledge
54
+ * bank content is removed and cannot be recovered from this call. Requires
55
+ * WRITE_CONF.
56
+ */
57
+ clear(knowledgeBankId: string, projectKey?: string): Promise<void>;
58
+ }
@@ -0,0 +1,61 @@
1
+ import { ClientValidationError, } from "../errors.js";
2
+ import { BaseResource, requireNonEmpty, } from "./base.js";
3
+ export class KnowledgeBanksResource extends BaseResource {
4
+ /**
5
+ * Search a knowledge bank for documents matching a query string.
6
+ * Requires READ_CONF.
7
+ */
8
+ async search(knowledgeBankId, body, projectKey) {
9
+ const id = encodeURIComponent(requireNonEmpty(knowledgeBankId, "knowledgeBankId"));
10
+ const payload = validateKnowledgeBankSearchBody(body);
11
+ return this.client.post(`/public/api/projects/${this.enc(projectKey)}/knowledge-banks/${id}/search`, payload);
12
+ }
13
+ /**
14
+ * Clear all data from a knowledge bank. DESTRUCTIVE: the stored knowledge
15
+ * bank content is removed and cannot be recovered from this call. Requires
16
+ * WRITE_CONF.
17
+ */
18
+ async clear(knowledgeBankId, projectKey) {
19
+ const id = encodeURIComponent(requireNonEmpty(knowledgeBankId, "knowledgeBankId"));
20
+ await this.client.post(`/public/api/projects/${this.enc(projectKey)}/knowledge-banks/${id}/clear`, {});
21
+ }
22
+ }
23
+ /**
24
+ * Validate a knowledge-bank search body on the client boundary: `query` must
25
+ * be a non-empty string and `params`, when present, an object. Documented
26
+ * params are checked for type; unknown fields pass through untouched.
27
+ */
28
+ function validateKnowledgeBankSearchBody(body) {
29
+ if (body === null || typeof body !== "object" || Array.isArray(body)) {
30
+ throw new ClientValidationError("knowledgeBanks.search body must be an object with a query string.");
31
+ }
32
+ const query = requireNonEmpty(body.query, "query");
33
+ const payload = { query, };
34
+ const params = body.params;
35
+ if (params !== undefined) {
36
+ if (params === null || typeof params !== "object" || Array.isArray(params)) {
37
+ throw new ClientValidationError("knowledgeBanks.search params must be an object.");
38
+ }
39
+ const searchParams = { ...params, };
40
+ validateSearchParamNumber(searchParams, "maxDocuments");
41
+ validateSearchParamNumber(searchParams, "similarityThreshold");
42
+ validateSearchParamNumber(searchParams, "mmrK");
43
+ validateSearchParamNumber(searchParams, "mmrDiversity");
44
+ validateSearchParamNumber(searchParams, "rrfRankConstant");
45
+ validateSearchParamNumber(searchParams, "rrfRankWindowSize");
46
+ const reranking = searchParams["useAdvancedReranking"];
47
+ if (reranking !== undefined && typeof reranking !== "boolean") {
48
+ throw new ClientValidationError("knowledgeBanks.search params.useAdvancedReranking must be a boolean.");
49
+ }
50
+ payload["params"] = searchParams;
51
+ }
52
+ return payload;
53
+ }
54
+ function validateSearchParamNumber(params, name) {
55
+ const value = params[name];
56
+ if (value === undefined)
57
+ return;
58
+ if (typeof value !== "number" || !Number.isFinite(value)) {
59
+ throw new ClientValidationError(`knowledgeBanks.search params.${name} must be a finite number.`);
60
+ }
61
+ }
@@ -0,0 +1,92 @@
1
+ import { BaseResource } from "./base.js";
2
+ /**
3
+ * Usage purpose of an LLM as documented in the DSS 15 REST reference
4
+ * (`GET /projects/{projectKey}/llms/{?purpose}`). The list is open: DSS
5
+ * versions may add purposes, so unknown server-provided values stay usable.
6
+ */
7
+ export type LlmPurpose = "GENERIC_COMPLETION" | "TEXT_EMBEDDING_EXTRACTION" | "IMAGE_GENERATION" | (string & {});
8
+ /** One entry of the LLM list endpoint. The rest of the object is server-defined. */
9
+ export interface LlmDescriptor extends Record<string, unknown> {
10
+ /** Fully-qualified LLM id, e.g. `openai:openai1:gpt-4`. Contains colons. */
11
+ id?: string;
12
+ /** Backend type, e.g. `OPENAI`, `BEDROCK`, `HUGGINGFACE_TRANSFORMER_LOCAL`. */
13
+ type?: string;
14
+ /** DSS connection backing the LLM, e.g. `openai1`. */
15
+ connection?: string;
16
+ /** Model name as configured on the connection. */
17
+ model?: string;
18
+ /** True when the LLM supports prompt-based interactions. */
19
+ promptDriven?: boolean;
20
+ }
21
+ /** Per-query settings block documented for the completions endpoint. */
22
+ export interface LlmCompletionSettings {
23
+ temperature?: number;
24
+ maxOutputTokens?: number;
25
+ topP?: number;
26
+ [key: string]: unknown;
27
+ }
28
+ /**
29
+ * One completions query. The documented shape is a chat `messages` array; the
30
+ * full documented request field set (roles, contents) is server-defined, so
31
+ * the object is left open rather than fake-strictly modeled.
32
+ */
33
+ export interface LlmCompletionQuery extends Record<string, unknown> {
34
+ messages?: Array<Record<string, unknown>>;
35
+ }
36
+ /** One embeddings query. `text` is the documented input field. */
37
+ export interface LlmEmbeddingQuery extends Record<string, unknown> {
38
+ text?: string;
39
+ }
40
+ /** One completion result. Fields are the documented stable set plus extras. */
41
+ export interface LlmCompletionResponse extends Record<string, unknown> {
42
+ ok?: boolean;
43
+ text?: string;
44
+ promptTokens?: number;
45
+ completionTokens?: number;
46
+ totalTokens?: number;
47
+ /** Cost estimate in cost units, per DSS LLM Mesh accounting. */
48
+ estimatedCost?: number;
49
+ }
50
+ /** One embedding result. Fields are the documented stable set plus extras. */
51
+ export interface LlmEmbeddingResponse extends Record<string, unknown> {
52
+ ok?: boolean;
53
+ /** Embedding vector as returned by the backend. */
54
+ embedding?: number[];
55
+ promptTokens?: number;
56
+ estimatedCost?: number;
57
+ }
58
+ /** Response envelope of the completions endpoint. */
59
+ export interface LlmCompletionsResult extends Record<string, unknown> {
60
+ responses?: LlmCompletionResponse[];
61
+ }
62
+ /** Response envelope of the embeddings endpoint. */
63
+ export interface LlmEmbeddingsResult extends Record<string, unknown> {
64
+ responses?: LlmEmbeddingResponse[];
65
+ }
66
+ export declare class LlmsResource extends BaseResource {
67
+ /**
68
+ * List the LLMs available in a project, including Retrieval-Augmented
69
+ * Generation ones. Requires READ_CONF.
70
+ */
71
+ list(options?: {
72
+ purpose?: LlmPurpose;
73
+ projectKey?: string;
74
+ }): Promise<LlmDescriptor[]>;
75
+ /**
76
+ * Perform completions on an LLM. This call is cost-bearing: it invokes an
77
+ * external LLM provider and may incur charges.
78
+ */
79
+ completions(body: {
80
+ llmId: string;
81
+ queries: LlmCompletionQuery[];
82
+ settings?: LlmCompletionSettings;
83
+ }, projectKey?: string): Promise<LlmCompletionsResult>;
84
+ /**
85
+ * Perform embeddings on an LLM. This call is cost-bearing: it invokes an
86
+ * external LLM provider and may incur charges.
87
+ */
88
+ embeddings(body: {
89
+ llmId: string;
90
+ queries: LlmEmbeddingQuery[];
91
+ }, projectKey?: string): Promise<LlmEmbeddingsResult>;
92
+ }