dataiku-sdk 3.1.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.
- package/README.md +253 -38
- 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/auth.js +1 -1
- package/dist/src/cli/coerce.js +11 -2
- package/dist/src/cli/commands/analysis.js +4 -3
- package/dist/src/cli/commands/api-service.js +5 -3
- package/dist/src/cli/commands/app.js +61 -18
- package/dist/src/cli/commands/bundle.js +3 -2
- package/dist/src/cli/commands/code-env.js +23 -16
- package/dist/src/cli/commands/connection.d.ts +9 -0
- package/dist/src/cli/commands/connection.js +267 -1
- package/dist/src/cli/commands/dashboard.js +7 -6
- 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/data-quality.js +9 -8
- package/dist/src/cli/commands/dataset.js +170 -40
- package/dist/src/cli/commands/doctor.js +4 -2
- package/dist/src/cli/commands/flow-zone.js +9 -8
- package/dist/src/cli/commands/folder.js +9 -8
- package/dist/src/cli/commands/future.js +4 -3
- 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/insight.js +8 -7
- package/dist/src/cli/commands/job.js +4 -3
- 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/meaning.js +5 -4
- package/dist/src/cli/commands/ml-task.js +21 -8
- package/dist/src/cli/commands/model-evaluation-store.js +4 -3
- package/dist/src/cli/commands/notebook.js +17 -12
- 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 +14 -54
- package/dist/src/cli/commands/project-library.js +7 -6
- package/dist/src/cli/commands/project.js +55 -8
- package/dist/src/cli/commands/recipe.js +50 -14
- package/dist/src/cli/commands/saved-model.d.ts +5 -0
- package/dist/src/cli/commands/saved-model.js +392 -4
- package/dist/src/cli/commands/scenario.js +147 -9
- package/dist/src/cli/commands/sql.js +3 -2
- package/dist/src/cli/commands/statistics.js +7 -6
- package/dist/src/cli/commands/user.d.ts +8 -0
- package/dist/src/cli/commands/user.js +296 -0
- package/dist/src/cli/commands/variable.js +2 -1
- package/dist/src/cli/commands/webapp.js +2 -1
- package/dist/src/cli/commands/wiki.js +7 -6
- package/dist/src/cli/contract.d.ts +2 -3
- package/dist/src/cli/contract.js +1167 -163
- package/dist/src/cli/flags.d.ts +4 -0
- package/dist/src/cli/flags.js +50 -2
- 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.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 +225 -95
- package/dist/src/client.d.ts +86 -6
- package/dist/src/client.js +263 -50
- package/dist/src/errors.d.ts +3 -0
- package/dist/src/errors.js +4 -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 +99 -1
- package/dist/src/resources/folders.js +2 -1
- package/dist/src/resources/futures.d.ts +4 -1
- package/dist/src/resources/futures.js +38 -6
- 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 +41 -16
- 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 +100 -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 +265 -0
- package/dist/src/resources/plugins.js +458 -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 +6 -0
- package/dist/src/resources/project-git.js +69 -42
- 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 +19 -3
- package/dist/src/resources/projects.js +30 -18
- 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/skill.d.ts +13 -4
- package/dist/src/skill.js +75 -24
- package/dist/src/utils/deep-merge.d.ts +1 -1
- package/dist/src/utils/polling.d.ts +20 -0
- package/dist/src/utils/polling.js +27 -0
- package/dist/src/utils/response-file.d.ts +2 -0
- package/dist/src/utils/response-file.js +34 -0
- package/dist/src/utils/secret-sanitize.d.ts +54 -0
- package/dist/src/utils/secret-sanitize.js +101 -0
- package/package.json +8 -5
- 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 +47 -225
- package/skills/dataiku-dss/references/app-releases.md +28 -0
- package/skills/dataiku-dss/references/authentication.md +39 -0
- package/skills/dataiku-dss/references/coding.md +8 -0
- package/skills/dataiku-dss/references/discovery.md +30 -0
- package/skills/dataiku-dss/references/flow-maps.md +12 -0
- package/skills/dataiku-dss/references/mutations.md +33 -0
- package/skills/dataiku-dss/references/troubleshooting.md +29 -0
|
@@ -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
|
-
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { MacroDefinition, MacroRunStart, MacroState, MacroSummary, MacroWaitResult } from "../schemas.js";
|
|
2
|
+
import { BaseResource } from "./base.js";
|
|
3
|
+
export interface MacroRunOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Server-side wait: when true the POST call blocks until the run finishes
|
|
6
|
+
* (docs: `POST /runnables/{runnableType}?wait=true`). Default false.
|
|
7
|
+
*/
|
|
8
|
+
wait?: boolean;
|
|
9
|
+
projectKey?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Macro parameter values keyed by the param names declared in the macro
|
|
12
|
+
* definition (`params` array). Sent as the POST body. Values must be
|
|
13
|
+
* JSON-serializable primitives or structures matching the declared types.
|
|
14
|
+
*/
|
|
15
|
+
params?: Record<string, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Admin-only parameter values keyed by the adminParams names declared in
|
|
18
|
+
* the macro definition. Sent as the POST body's adminParams entry.
|
|
19
|
+
*/
|
|
20
|
+
adminParams?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface MacroWaitOptions {
|
|
23
|
+
pollIntervalMs?: number;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
projectKey?: string;
|
|
26
|
+
/** Macro parameter values (see {@link MacroRunOptions.params}). */
|
|
27
|
+
params?: Record<string, unknown>;
|
|
28
|
+
/** Admin-only parameter values (see {@link MacroRunOptions.adminParams}). */
|
|
29
|
+
adminParams?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
export interface MacroResultOptions {
|
|
32
|
+
projectKey?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Cap on the number of bytes buffered from the result body. Macro results
|
|
35
|
+
* can be arbitrary documents (HTML, text, JSON); the default 8 MiB guards
|
|
36
|
+
* against oversized bodies while remaining generous for typical reports.
|
|
37
|
+
*/
|
|
38
|
+
maxBytes?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Normalize a byte cap coming from user input (CLI `--max-bytes`) into the
|
|
42
|
+
* inclusive range [1, 2 GiB], rejecting non-integers before any DSS request.
|
|
43
|
+
*/
|
|
44
|
+
export declare function macroResultMaxBytes(maxBytes: number | undefined): number;
|
|
45
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Run result of {@link MacrosResource.run} when the caller opted into
|
|
48
|
+
* `wait: false` (the default): a run id for abort/state/result tracking.
|
|
49
|
+
*/
|
|
50
|
+
export type MacroRunHandle = MacroRunStart;
|
|
51
|
+
/**
|
|
52
|
+
* When `wait: true`, DSS blocks server-side until the run finishes and then
|
|
53
|
+
* returns the run id plus the terminal poll state (resultType, errors, …).
|
|
54
|
+
*/
|
|
55
|
+
export type MacroRunWaitedResult = MacroRunStart & {
|
|
56
|
+
state?: MacroState;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Error payload surfaced by DSS on a failed macro run, from either
|
|
60
|
+
* `resultError` or `storedError` in the poll state.
|
|
61
|
+
*/
|
|
62
|
+
export interface MacroRunFailure {
|
|
63
|
+
source: "resultError" | "storedError";
|
|
64
|
+
details: unknown;
|
|
65
|
+
}
|
|
66
|
+
declare function macroRunFailure(state: Record<string, unknown>): MacroRunFailure | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* DSS Macros — the plugin "runnable" surface under
|
|
69
|
+
* `/public/api/projects/{pk}/runnables`.
|
|
70
|
+
*
|
|
71
|
+
* A macro run executes arbitrary plugin code on the DSS backend with
|
|
72
|
+
* side effects that DSS cannot predict; every method here that starts or
|
|
73
|
+
* stops a run is a write. Result bodies may be plain text or HTML rather
|
|
74
|
+
* than JSON, so {@link MacrosResource.result} returns the raw body.
|
|
75
|
+
*/
|
|
76
|
+
export declare class MacrosResource extends BaseResource {
|
|
77
|
+
/**
|
|
78
|
+
* List the macros (runnables) available in a project. The official client
|
|
79
|
+
* lists at `/runnables/` (trailing slash): the slashless path 404s on live
|
|
80
|
+
* DSS 15, while get/run/state/result stay slashless.
|
|
81
|
+
*/
|
|
82
|
+
list(projectKey?: string): Promise<MacroSummary[]>;
|
|
83
|
+
/** Get the definition of a macro: params, result type, owning plugin. */
|
|
84
|
+
definition(runnableType: string, opts?: {
|
|
85
|
+
projectKey?: string;
|
|
86
|
+
}): Promise<MacroDefinition>;
|
|
87
|
+
/**
|
|
88
|
+
* Start a macro run. Executes arbitrary plugin code: classify as
|
|
89
|
+
* destructive. With `wait: true` the server call blocks until completion
|
|
90
|
+
* and the resolved state is attached to the returned run handle.
|
|
91
|
+
*/
|
|
92
|
+
run(runnableType: string, opts?: MacroRunOptions): Promise<MacroRunHandle | MacroRunWaitedResult>;
|
|
93
|
+
/** Request abort of a running macro run (204 response). */
|
|
94
|
+
abort(runnableType: string, runId: string, projectKey?: string): Promise<void>;
|
|
95
|
+
/** Get the poll state of a macro run (running flag, progress, errors). */
|
|
96
|
+
state(runnableType: string, runId: string, opts?: {
|
|
97
|
+
projectKey?: string;
|
|
98
|
+
/**
|
|
99
|
+
* TOTAL duration budget in ms for this state GET, measured from
|
|
100
|
+
* call start (bounds fetch, retries, backoff, and body read).
|
|
101
|
+
* Polling loops pass their remaining wait budget so a stalled
|
|
102
|
+
* state endpoint cannot outlive the wait deadline.
|
|
103
|
+
*/
|
|
104
|
+
timeoutMs?: number;
|
|
105
|
+
}): Promise<MacroState>;
|
|
106
|
+
/**
|
|
107
|
+
* Download the result of a macro run. Macro results are documents of the
|
|
108
|
+
* macro's declared `resultType` (HTML, text, JSON, …) and are frequently
|
|
109
|
+
* NOT JSON: the raw body is returned verbatim. JSON bodies are returned
|
|
110
|
+
* as parsed values so programmatic callers can read fields directly.
|
|
111
|
+
*/
|
|
112
|
+
result(runnableType: string, runId: string, opts?: MacroResultOptions): Promise<unknown>;
|
|
113
|
+
/**
|
|
114
|
+
* Run a macro and poll its state until it finishes or times out, using a
|
|
115
|
+
* bounded client-side loop on the state endpoint. Returns
|
|
116
|
+
* `{ success: false, timedOut: true }` on timeout rather than throwing.
|
|
117
|
+
*/
|
|
118
|
+
runAndWait(runnableType: string, opts?: MacroWaitOptions): Promise<MacroWaitResult>;
|
|
119
|
+
private base;
|
|
120
|
+
}
|
|
121
|
+
export { isRecord as isMacroStateRecord, macroRunFailure, };
|