dataiku-sdk 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -46
- package/dist/build-metadata.json +1 -1
- package/dist/packages/types/src/index.d.ts +102 -0
- package/dist/packages/types/src/index.js +76 -0
- package/dist/src/cli/commands/app.js +57 -15
- package/dist/src/cli/commands/bundle.js +1 -1
- package/dist/src/cli/commands/code-env.js +13 -7
- package/dist/src/cli/commands/code.js +1 -1
- package/dist/src/cli/commands/connection.d.ts +9 -0
- package/dist/src/cli/commands/connection.js +267 -1
- package/dist/src/cli/commands/data-collection.d.ts +2 -0
- package/dist/src/cli/commands/data-collection.js +164 -0
- package/dist/src/cli/commands/dataset.js +162 -33
- package/dist/src/cli/commands/future.js +2 -2
- package/dist/src/cli/commands/group.d.ts +2 -0
- package/dist/src/cli/commands/group.js +109 -0
- package/dist/src/cli/commands/index.js +151 -78
- package/dist/src/cli/commands/job.js +4 -2
- package/dist/src/cli/commands/knowledge-bank.d.ts +2 -0
- package/dist/src/cli/commands/knowledge-bank.js +80 -0
- package/dist/src/cli/commands/llm.d.ts +2 -0
- package/dist/src/cli/commands/llm.js +93 -0
- package/dist/src/cli/commands/macro.d.ts +2 -0
- package/dist/src/cli/commands/macro.js +221 -0
- package/dist/src/cli/commands/ml-task.js +18 -6
- package/dist/src/cli/commands/notebook.js +6 -2
- package/dist/src/cli/commands/plugin.d.ts +2 -0
- package/dist/src/cli/commands/plugin.js +799 -0
- package/dist/src/cli/commands/project-folder.d.ts +2 -0
- package/dist/src/cli/commands/project-folder.js +197 -0
- package/dist/src/cli/commands/project-git.js +15 -55
- package/dist/src/cli/commands/project.js +52 -6
- package/dist/src/cli/commands/recipe.js +36 -1
- package/dist/src/cli/commands/saved-model.d.ts +5 -0
- package/dist/src/cli/commands/saved-model.js +388 -1
- package/dist/src/cli/commands/scenario.js +139 -2
- package/dist/src/cli/commands/user.d.ts +8 -0
- package/dist/src/cli/commands/user.js +296 -0
- package/dist/src/cli/contract.d.ts +1 -2
- package/dist/src/cli/contract.js +1098 -297
- package/dist/src/cli/flags.js +30 -1
- package/dist/src/cli/helpers/app-successor.d.ts +19 -4
- package/dist/src/cli/helpers/app-successor.js +90 -30
- package/dist/src/cli/helpers/cleanup.js +3 -1
- package/dist/src/cli/helpers/flow-zone.js +1 -2
- package/dist/src/cli/output-schemas.d.ts +24 -0
- package/dist/src/cli/output-schemas.js +233 -0
- package/dist/src/cli/output.d.ts +1 -1
- package/dist/src/cli/output.js +23 -10
- package/dist/src/cli/usage.d.ts +1 -0
- package/dist/src/cli/usage.js +47 -1
- package/dist/src/cli.js +147 -41
- package/dist/src/client.d.ts +92 -5
- package/dist/src/client.js +202 -31
- package/dist/src/errors.d.ts +3 -0
- package/dist/src/errors.js +8 -4
- package/dist/src/generated/action-output-schemas.json +1735 -0
- package/dist/src/index.d.ts +16 -7
- package/dist/src/index.js +11 -2
- package/dist/src/resources/analyses.js +1 -8
- package/dist/src/resources/applications.d.ts +8 -6
- package/dist/src/resources/applications.js +21 -21
- package/dist/src/resources/base.d.ts +4 -0
- package/dist/src/resources/base.js +15 -0
- package/dist/src/resources/bundles.d.ts +9 -4
- package/dist/src/resources/bundles.js +10 -5
- package/dist/src/resources/connections.d.ts +78 -1
- package/dist/src/resources/connections.js +132 -1
- package/dist/src/resources/data-collections.d.ts +118 -0
- package/dist/src/resources/data-collections.js +49 -0
- package/dist/src/resources/datasets.d.ts +69 -0
- package/dist/src/resources/datasets.js +136 -5
- package/dist/src/resources/flow-zones.d.ts +6 -2
- package/dist/src/resources/flow-zones.js +6 -3
- package/dist/src/resources/futures.d.ts +6 -1
- package/dist/src/resources/futures.js +68 -22
- package/dist/src/resources/groups.d.ts +47 -0
- package/dist/src/resources/groups.js +56 -0
- package/dist/src/resources/jobs.d.ts +8 -13
- package/dist/src/resources/jobs.js +71 -34
- package/dist/src/resources/knowledge-banks.d.ts +58 -0
- package/dist/src/resources/knowledge-banks.js +61 -0
- package/dist/src/resources/llms.d.ts +92 -0
- package/dist/src/resources/llms.js +62 -0
- package/dist/src/resources/macros.d.ts +121 -0
- package/dist/src/resources/macros.js +231 -0
- package/dist/src/resources/ml-tasks.d.ts +37 -2
- package/dist/src/resources/ml-tasks.js +109 -20
- package/dist/src/resources/model-evaluation-stores.js +1 -8
- package/dist/src/resources/notebooks.d.ts +43 -7
- package/dist/src/resources/notebooks.js +53 -13
- package/dist/src/resources/plugins.d.ts +263 -0
- package/dist/src/resources/plugins.js +455 -0
- package/dist/src/resources/project-folders.d.ts +71 -0
- package/dist/src/resources/project-folders.js +57 -0
- package/dist/src/resources/project-git.d.ts +12 -12
- package/dist/src/resources/project-git.js +84 -82
- package/dist/src/resources/project-library.d.ts +0 -1
- package/dist/src/resources/project-library.js +1 -17
- package/dist/src/resources/projects.d.ts +23 -3
- package/dist/src/resources/projects.js +60 -34
- package/dist/src/resources/recipes.d.ts +15 -1
- package/dist/src/resources/recipes.js +73 -6
- package/dist/src/resources/saved-models.d.ts +134 -1
- package/dist/src/resources/saved-models.js +214 -6
- package/dist/src/resources/scenarios.d.ts +105 -0
- package/dist/src/resources/scenarios.js +232 -106
- package/dist/src/resources/sql.js +5 -1
- package/dist/src/resources/users.d.ts +129 -0
- package/dist/src/resources/users.js +128 -0
- package/dist/src/resources/webapps.d.ts +15 -2
- package/dist/src/resources/webapps.js +18 -4
- package/dist/src/schemas.d.ts +2 -2
- package/dist/src/schemas.js +1 -1
- package/dist/src/utils/deep-merge.d.ts +1 -1
- package/dist/src/utils/git-reference.d.ts +12 -0
- package/dist/src/utils/git-reference.js +38 -0
- package/dist/src/utils/polling.d.ts +20 -0
- package/dist/src/utils/polling.js +27 -0
- package/dist/src/utils/response-file.js +1 -1
- package/dist/src/utils/secret-sanitize.d.ts +54 -0
- package/dist/src/utils/secret-sanitize.js +101 -0
- package/package.json +9 -8
- package/packages/types/dist/index.d.ts +102 -0
- package/packages/types/dist/index.js +76 -0
- package/plugin.json +1 -1
- package/skills/dataiku-dss/SKILL.md +11 -7
- package/skills/dataiku-dss/references/app-releases.md +8 -8
- package/skills/dataiku-dss/references/authentication.md +6 -6
- package/skills/dataiku-dss/references/discovery.md +4 -4
- package/skills/dataiku-dss/references/mutations.md +1 -1
- package/skills/dataiku-dss/references/troubleshooting.md +2 -2
|
@@ -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
|
-
|
|
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,73 @@ 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;
|
|
292
|
+
let lastJ;
|
|
300
293
|
while (true) {
|
|
294
|
+
const elapsedBeforeMs = Date.now() - startedAt;
|
|
295
|
+
// The first observation always happens, even when the budget is
|
|
296
|
+
// already spent. A later poll is never started after the deadline:
|
|
297
|
+
// the loop reports the structured timeout from the last observed
|
|
298
|
+
// state instead of issuing a request the budget cannot cover.
|
|
299
|
+
if (lastJ !== undefined && elapsedBeforeMs >= timeout) {
|
|
300
|
+
const bs = lastJ.baseStatus ?? {};
|
|
301
|
+
const def = bs.def ?? {};
|
|
302
|
+
const gs = lastJ.globalState ?? {};
|
|
303
|
+
return {
|
|
304
|
+
success: false,
|
|
305
|
+
jobId,
|
|
306
|
+
state: bs.state ?? "unknown",
|
|
307
|
+
type: def.type ?? "unknown",
|
|
308
|
+
elapsedMs: elapsedBeforeMs,
|
|
309
|
+
pollCount,
|
|
310
|
+
timedOut: true,
|
|
311
|
+
progress: {
|
|
312
|
+
done: gs.done ?? 0,
|
|
313
|
+
failed: gs.failed ?? 0,
|
|
314
|
+
running: gs.running ?? 0,
|
|
315
|
+
total: gs.total ?? null,
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
301
319
|
pollCount += 1;
|
|
302
|
-
|
|
320
|
+
// Requests issued while budget remains are bounded by the remaining
|
|
321
|
+
// time; a spent budget still issues exactly one transport attempt
|
|
322
|
+
// (no retries, client requestTimeoutMs cap) so the first observation
|
|
323
|
+
// reaches the server instead of failing before any attempt.
|
|
324
|
+
const remainingMs = timeout - elapsedBeforeMs;
|
|
325
|
+
let j;
|
|
326
|
+
try {
|
|
327
|
+
j = await this.client.get(`/public/api/projects/${projectEnc}/jobs/${jobEnc}/`, remainingMs > 0
|
|
328
|
+
? { timeoutMs: remainingMs, }
|
|
329
|
+
: { noRetry: true, });
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
// The poll budget ran out mid-request: report the documented
|
|
333
|
+
// structured timeout instead of letting the transport deadline
|
|
334
|
+
// error escape the loop.
|
|
335
|
+
if (!isRequestDeadlineError(error, startedAt + timeout))
|
|
336
|
+
throw error;
|
|
337
|
+
return {
|
|
338
|
+
success: false,
|
|
339
|
+
jobId,
|
|
340
|
+
state: "unknown",
|
|
341
|
+
type: "unknown",
|
|
342
|
+
elapsedMs: Date.now() - startedAt,
|
|
343
|
+
pollCount,
|
|
344
|
+
timedOut: true,
|
|
345
|
+
progress: {
|
|
346
|
+
done: 0,
|
|
347
|
+
failed: 0,
|
|
348
|
+
running: 0,
|
|
349
|
+
total: null,
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
lastJ = j;
|
|
303
354
|
const bs = j.baseStatus ?? {};
|
|
304
355
|
const def = bs.def ?? {};
|
|
305
356
|
const gs = j.globalState ?? {};
|
|
@@ -362,24 +413,10 @@ export class JobsResource extends BaseResource {
|
|
|
362
413
|
...(removed !== undefined ? { removed, } : {}),
|
|
363
414
|
};
|
|
364
415
|
}
|
|
365
|
-
// Timeout —
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
jobId,
|
|
370
|
-
state,
|
|
371
|
-
type: def.type ?? "unknown",
|
|
372
|
-
elapsedMs,
|
|
373
|
-
pollCount,
|
|
374
|
-
timedOut: true,
|
|
375
|
-
progress: {
|
|
376
|
-
done: gs.done ?? 0,
|
|
377
|
-
failed: gs.failed ?? 0,
|
|
378
|
-
running: gs.running ?? 0,
|
|
379
|
-
total: gs.total ?? null,
|
|
380
|
-
},
|
|
381
|
-
};
|
|
382
|
-
}
|
|
416
|
+
// Timeout — the guard at the top of the loop returns the failure
|
|
417
|
+
// result from this observation without issuing another request.
|
|
418
|
+
if (elapsedMs >= timeout)
|
|
419
|
+
continue;
|
|
383
420
|
const nextDelayMs = computeNextPollDelayMs({
|
|
384
421
|
pollCount,
|
|
385
422
|
baseIntervalMs,
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ClientValidationError, } from "../errors.js";
|
|
2
|
+
import { BaseResource, requireNonEmpty, } from "./base.js";
|
|
3
|
+
export class LlmsResource extends BaseResource {
|
|
4
|
+
/**
|
|
5
|
+
* List the LLMs available in a project, including Retrieval-Augmented
|
|
6
|
+
* Generation ones. Requires READ_CONF.
|
|
7
|
+
*/
|
|
8
|
+
async list(options = {}) {
|
|
9
|
+
const params = new URLSearchParams();
|
|
10
|
+
if (options.purpose !== undefined) {
|
|
11
|
+
params.set("purpose", requireNonEmpty(options.purpose, "purpose"));
|
|
12
|
+
}
|
|
13
|
+
const query = params.size > 0 ? `?${params.toString()}` : "";
|
|
14
|
+
return this.client.get(`/public/api/projects/${this.enc(options.projectKey)}/llms/${query}`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Perform completions on an LLM. This call is cost-bearing: it invokes an
|
|
18
|
+
* external LLM provider and may incur charges.
|
|
19
|
+
*/
|
|
20
|
+
async completions(body, projectKey) {
|
|
21
|
+
const payload = validateLlmInferenceBody(body, "completions");
|
|
22
|
+
return this.client.post(`/public/api/projects/${this.enc(projectKey)}/llms/completions`, payload);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Perform embeddings on an LLM. This call is cost-bearing: it invokes an
|
|
26
|
+
* external LLM provider and may incur charges.
|
|
27
|
+
*/
|
|
28
|
+
async embeddings(body, projectKey) {
|
|
29
|
+
const payload = validateLlmInferenceBody(body, "embeddings");
|
|
30
|
+
return this.client.post(`/public/api/projects/${this.enc(projectKey)}/llms/embeddings`, payload);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validate a completions/embeddings request body on the client boundary:
|
|
35
|
+
* `llmId` must be a non-empty string and `queries` a non-empty array of
|
|
36
|
+
* objects. Unknown documented fields pass through untouched.
|
|
37
|
+
*/
|
|
38
|
+
function validateLlmInferenceBody(body, action) {
|
|
39
|
+
if (body === null || typeof body !== "object" || Array.isArray(body)) {
|
|
40
|
+
throw new ClientValidationError(`llms.${action} body must be an object with llmId and queries.`);
|
|
41
|
+
}
|
|
42
|
+
const llmId = requireNonEmpty(body.llmId, "llmId");
|
|
43
|
+
if (!Array.isArray(body.queries) || body.queries.length === 0) {
|
|
44
|
+
throw new ClientValidationError(`llms.${action} queries must be a non-empty array of query objects.`, "validation_failed", 'Pass at least one query, e.g. queries: [{ messages: [...] }] for completions or [{ text: "..." }] for embeddings.');
|
|
45
|
+
}
|
|
46
|
+
for (const [index, query,] of body.queries.entries()) {
|
|
47
|
+
if (query === null || typeof query !== "object" || Array.isArray(query)) {
|
|
48
|
+
throw new ClientValidationError(`llms.${action} queries[${index}] must be an object.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const payload = {
|
|
52
|
+
llmId,
|
|
53
|
+
queries: body.queries,
|
|
54
|
+
};
|
|
55
|
+
if (body.settings !== undefined) {
|
|
56
|
+
if (body.settings === null || typeof body.settings !== "object" || Array.isArray(body.settings)) {
|
|
57
|
+
throw new ClientValidationError("llms.completions settings must be an object.");
|
|
58
|
+
}
|
|
59
|
+
payload["settings"] = body.settings;
|
|
60
|
+
}
|
|
61
|
+
return payload;
|
|
62
|
+
}
|