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
@@ -1,80 +1,153 @@
1
- import { analysisCommands, } from "./analysis.js";
2
- import { apiDeployerCommands, } from "./api-deployer.js";
3
- import { apiServiceCommands, } from "./api-service.js";
4
- import { appCommands, } from "./app.js";
5
- import { bundleCommands, } from "./bundle.js";
6
- import { businessAppCommands, } from "./business-app.js";
7
- import { codeEnvCommands, } from "./code-env.js";
8
- import { codeCommands, } from "./code.js";
9
- import { connectionCommands, } from "./connection.js";
10
- import { continuousActivityCommands, } from "./continuous-activity.js";
11
- import { dashboardCommands, } from "./dashboard.js";
12
- import { dataQualityCommands, } from "./data-quality.js";
13
- import { datasetCommands, } from "./dataset.js";
14
- import { discussionCommands, } from "./discussion.js";
15
- import { doctorCommands, } from "./doctor.js";
16
- import { flowZoneCommands, } from "./flow-zone.js";
17
- import { folderCommands, } from "./folder.js";
18
- import { futureCommands, } from "./future.js";
19
- import { insightCommands, } from "./insight.js";
20
- import { jobCommands, } from "./job.js";
21
- import { meaningCommands, } from "./meaning.js";
22
- import { metricsCommands, } from "./metrics.js";
23
- import { mlTaskCommands, } from "./ml-task.js";
24
- import { modelEvaluationStoreCommands, } from "./model-evaluation-store.js";
25
- import { notebookCommands, } from "./notebook.js";
26
- import { projectDeployerCommands, } from "./project-deployer.js";
27
- import { projectGitCommands, } from "./project-git.js";
28
- import { projectLibraryCommands, } from "./project-library.js";
29
- import { projectCommands, } from "./project.js";
30
- import { recipeCommands, } from "./recipe.js";
31
- import { savedModelCommands, } from "./saved-model.js";
32
- import { scenarioCommands, } from "./scenario.js";
33
- import { sqlCommands, } from "./sql.js";
34
- import { statisticsCommands, } from "./statistics.js";
35
- import { streamingEndpointCommands, } from "./streaming-endpoint.js";
36
- import { variableCommands, } from "./variable.js";
37
- import { webappCommands, } from "./webapp.js";
38
- import { wikiCommands, } from "./wiki.js";
39
- import { workspaceCommands, } from "./workspace.js";
1
+ // Bun caches these synchronous module loads. Enumerating resource names stays
2
+ // cheap; looking up one resource loads only its command definitions.
40
3
  export const commands = {
41
- project: projectCommands,
42
- analysis: analysisCommands,
43
- "ml-task": mlTaskCommands,
44
- "saved-model": savedModelCommands,
45
- "model-evaluation-store": modelEvaluationStoreCommands,
46
- app: appCommands,
47
- "business-app": businessAppCommands,
48
- webapp: webappCommands,
49
- "api-service": apiServiceCommands,
50
- "api-deployer": apiDeployerCommands,
51
- bundle: bundleCommands,
52
- "project-deployer": projectDeployerCommands,
53
- "project-git": projectGitCommands,
54
- "project-library": projectLibraryCommands,
55
- "streaming-endpoint": streamingEndpointCommands,
56
- "continuous-activity": continuousActivityCommands,
57
- statistics: statisticsCommands,
58
- discussion: discussionCommands,
59
- meaning: meaningCommands,
60
- workspace: workspaceCommands,
61
- metrics: metricsCommands,
62
- doctor: doctorCommands,
63
- wiki: wikiCommands,
64
- dashboard: dashboardCommands,
65
- insight: insightCommands,
66
- "data-quality": dataQualityCommands,
67
- future: futureCommands,
68
- "flow-zone": flowZoneCommands,
69
- dataset: datasetCommands,
70
- recipe: recipeCommands,
71
- job: jobCommands,
72
- scenario: scenarioCommands,
73
- folder: folderCommands,
74
- variable: variableCommands,
75
- connection: connectionCommands,
76
- "code-env": codeEnvCommands,
77
- sql: sqlCommands,
78
- code: codeCommands,
79
- notebook: notebookCommands,
4
+ get "project"() {
5
+ return require("./project.js").projectCommands;
6
+ },
7
+ get "analysis"() {
8
+ return require("./analysis.js").analysisCommands;
9
+ },
10
+ get "ml-task"() {
11
+ return require("./ml-task.js").mlTaskCommands;
12
+ },
13
+ get "saved-model"() {
14
+ return require("./saved-model.js").savedModelCommands;
15
+ },
16
+ get "model-evaluation-store"() {
17
+ return require("./model-evaluation-store.js")
18
+ .modelEvaluationStoreCommands;
19
+ },
20
+ get "app"() {
21
+ return require("./app.js").appCommands;
22
+ },
23
+ get "business-app"() {
24
+ return require("./business-app.js").businessAppCommands;
25
+ },
26
+ get "webapp"() {
27
+ return require("./webapp.js").webappCommands;
28
+ },
29
+ get "api-service"() {
30
+ return require("./api-service.js").apiServiceCommands;
31
+ },
32
+ get "api-deployer"() {
33
+ return require("./api-deployer.js").apiDeployerCommands;
34
+ },
35
+ get "bundle"() {
36
+ return require("./bundle.js").bundleCommands;
37
+ },
38
+ get "project-deployer"() {
39
+ return require("./project-deployer.js")
40
+ .projectDeployerCommands;
41
+ },
42
+ get "project-git"() {
43
+ return require("./project-git.js").projectGitCommands;
44
+ },
45
+ get "project-folder"() {
46
+ return require("./project-folder.js")
47
+ .projectFolderCommands;
48
+ },
49
+ get "project-library"() {
50
+ return require("./project-library.js")
51
+ .projectLibraryCommands;
52
+ },
53
+ get "streaming-endpoint"() {
54
+ return require("./streaming-endpoint.js")
55
+ .streamingEndpointCommands;
56
+ },
57
+ get "continuous-activity"() {
58
+ return require("./continuous-activity.js")
59
+ .continuousActivityCommands;
60
+ },
61
+ get "statistics"() {
62
+ return require("./statistics.js").statisticsCommands;
63
+ },
64
+ get "discussion"() {
65
+ return require("./discussion.js").discussionCommands;
66
+ },
67
+ get "meaning"() {
68
+ return require("./meaning.js").meaningCommands;
69
+ },
70
+ get "workspace"() {
71
+ return require("./workspace.js").workspaceCommands;
72
+ },
73
+ get "metrics"() {
74
+ return require("./metrics.js").metricsCommands;
75
+ },
76
+ get "doctor"() {
77
+ return require("./doctor.js").doctorCommands;
78
+ },
79
+ get "wiki"() {
80
+ return require("./wiki.js").wikiCommands;
81
+ },
82
+ get "dashboard"() {
83
+ return require("./dashboard.js").dashboardCommands;
84
+ },
85
+ get "insight"() {
86
+ return require("./insight.js").insightCommands;
87
+ },
88
+ get "data-quality"() {
89
+ return require("./data-quality.js").dataQualityCommands;
90
+ },
91
+ get "future"() {
92
+ return require("./future.js").futureCommands;
93
+ },
94
+ get "flow-zone"() {
95
+ return require("./flow-zone.js").flowZoneCommands;
96
+ },
97
+ get "dataset"() {
98
+ return require("./dataset.js").datasetCommands;
99
+ },
100
+ get "recipe"() {
101
+ return require("./recipe.js").recipeCommands;
102
+ },
103
+ get "job"() {
104
+ return require("./job.js").jobCommands;
105
+ },
106
+ get "scenario"() {
107
+ return require("./scenario.js").scenarioCommands;
108
+ },
109
+ get "folder"() {
110
+ return require("./folder.js").folderCommands;
111
+ },
112
+ get "variable"() {
113
+ return require("./variable.js").variableCommands;
114
+ },
115
+ get "connection"() {
116
+ return require("./connection.js").connectionCommands;
117
+ },
118
+ get "code-env"() {
119
+ return require("./code-env.js").codeEnvCommands;
120
+ },
121
+ get "sql"() {
122
+ return require("./sql.js").sqlCommands;
123
+ },
124
+ get "code"() {
125
+ return require("./code.js").codeCommands;
126
+ },
127
+ get "notebook"() {
128
+ return require("./notebook.js").notebookCommands;
129
+ },
130
+ get "user"() {
131
+ return require("./user.js").userCommands;
132
+ },
133
+ get "group"() {
134
+ return require("./group.js").groupCommands;
135
+ },
136
+ get "plugin"() {
137
+ return require("./plugin.js").pluginCommands;
138
+ },
139
+ get "llm"() {
140
+ return require("./llm.js").llmCommands;
141
+ },
142
+ get "knowledge-bank"() {
143
+ return require("./knowledge-bank.js")
144
+ .knowledgeBankCommands;
145
+ },
146
+ get "macro"() {
147
+ return require("./macro.js").macroCommands;
148
+ },
149
+ get "data-collection"() {
150
+ return require("./data-collection.js")
151
+ .dataCollectionCommands;
152
+ },
80
153
  };
@@ -0,0 +1,2 @@
1
+ import type { CommandMeta } from "../types.js";
2
+ export declare const knowledgeBankCommands: Record<string, CommandMeta>;
@@ -0,0 +1,80 @@
1
+ import { requiredJsonInput, } from "../coerce.js";
2
+ import { executionMode, } from "../flags.js";
3
+ import { planResult, } from "../output.js";
4
+ import { requireArgs, UsageError, } from "../usage.js";
5
+ const KB_PLAN_EXIT_CODES = { usage: 1, error: 2, transient: 3, };
6
+ const KB_SEARCH_USAGE = "dss knowledge-bank search <knowledgeBankId> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]";
7
+ const KB_CLEAR_USAGE = "dss knowledge-bank clear <knowledgeBankId> [--dry-run] [--project-key KEY]";
8
+ /**
9
+ * Validate a search body before any execution mode: the same check runs for
10
+ * live, --plan, and --dry-run so planning can never succeed for a body the
11
+ * live call would reject.
12
+ */
13
+ function requireKnowledgeBankSearchBody(flags) {
14
+ const body = requiredJsonInput(flags, "--data, --data-file, or --stdin is required (search body with a query string).");
15
+ const query = body["query"];
16
+ if (typeof query !== "string" || query.trim().length === 0) {
17
+ throw new UsageError(`query is required and must be a non-empty string.\nUsage: ${KB_SEARCH_USAGE}`, "invalid_flag_value");
18
+ }
19
+ return body;
20
+ }
21
+ function requireNonEmptyPositional(value, usage) {
22
+ if (value.trim().length === 0) {
23
+ throw new UsageError(`knowledgeBankId must be a non-empty string.\nUsage: ${usage}`, "invalid_flag_value");
24
+ }
25
+ return value;
26
+ }
27
+ export const knowledgeBankCommands = {
28
+ search: {
29
+ handler: async (c, a, f) => {
30
+ const knowledgeBankId = requireNonEmptyPositional(a[0], KB_SEARCH_USAGE);
31
+ const body = requireKnowledgeBankSearchBody(f);
32
+ const projectKey = f["project-key"];
33
+ if (executionMode(f).dryRun) {
34
+ return planResult("knowledge-bank", "search", {
35
+ asyncKind: "none",
36
+ method: "POST",
37
+ endpoint: `/public/api/projects/${encodeURIComponent(projectKey ?? c.resolveProjectKey(undefined))}/knowledge-banks/${encodeURIComponent(knowledgeBankId)}/search`,
38
+ identifiers: { knowledgeBankId, },
39
+ payload: body,
40
+ idempotency: "none",
41
+ exitCodesOnFailure: KB_PLAN_EXIT_CODES,
42
+ plannedAndDryRun: true,
43
+ });
44
+ }
45
+ return c.knowledgeBanks.search(knowledgeBankId, body, projectKey);
46
+ },
47
+ usage: KB_SEARCH_USAGE,
48
+ description: "Search a knowledge bank for documents matching a query. Runs retrieval against the backing vector store. Body: { query, params?: { maxDocuments, searchType, similarityThreshold, mmrK, mmrDiversity, useAdvancedReranking, rrfRankConstant, rrfRankWindowSize } }.",
49
+ examples: [
50
+ 'dss knowledge-bank search my-kb --data \'{"query":"Hello, world!"}\'',
51
+ 'dss knowledge-bank search my-kb --data \'{"query":"refund policy","params":{"maxDocuments":5,"searchType":"SIMILARITY"}}\' --dry-run',
52
+ ],
53
+ },
54
+ clear: {
55
+ handler: async (c, a, f) => {
56
+ requireArgs(a, 1, KB_CLEAR_USAGE);
57
+ const knowledgeBankId = requireNonEmptyPositional(a[0], KB_CLEAR_USAGE);
58
+ const projectKey = f["project-key"];
59
+ if (executionMode(f).dryRun) {
60
+ return planResult("knowledge-bank", "clear", {
61
+ asyncKind: "none",
62
+ method: "POST",
63
+ endpoint: `/public/api/projects/${encodeURIComponent(projectKey ?? c.resolveProjectKey(undefined))}/knowledge-banks/${encodeURIComponent(knowledgeBankId)}/clear`,
64
+ identifiers: { knowledgeBankId, },
65
+ idempotency: "convergent",
66
+ exitCodesOnFailure: KB_PLAN_EXIT_CODES,
67
+ plannedAndDryRun: true,
68
+ });
69
+ }
70
+ await c.knowledgeBanks.clear(knowledgeBankId, projectKey);
71
+ return { cleared: knowledgeBankId, resource: "knowledge-bank", };
72
+ },
73
+ usage: KB_CLEAR_USAGE,
74
+ description: "DESTRUCTIVE: clear all data from a knowledge bank. The stored content is removed and cannot be recovered from this command.",
75
+ examples: [
76
+ "dss knowledge-bank clear my-kb --dry-run",
77
+ "dss knowledge-bank clear my-kb",
78
+ ],
79
+ },
80
+ };
@@ -0,0 +1,2 @@
1
+ import type { CommandMeta } from "../types.js";
2
+ export declare const llmCommands: Record<string, CommandMeta>;
@@ -0,0 +1,93 @@
1
+ import { requiredJsonInput, } from "../coerce.js";
2
+ import { executionMode, } from "../flags.js";
3
+ import { planResult, } from "../output.js";
4
+ import { UsageError, } from "../usage.js";
5
+ const LLM_PLAN_EXIT_CODES = { usage: 1, error: 2, transient: 3, };
6
+ const LLM_LIST_USAGE = "dss llm list [--purpose GENERIC_COMPLETION|TEXT_EMBEDDING_EXTRACTION|IMAGE_GENERATION|NAME] [--project-key KEY]";
7
+ const LLM_COMPLETIONS_USAGE = "dss llm completions (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]";
8
+ const LLM_EMBEDDINGS_USAGE = "dss llm embeddings (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]";
9
+ /**
10
+ * Validate a completions/embeddings payload before any execution mode: the
11
+ * same check runs for live, --plan, and --dry-run so planning can never
12
+ * succeed for a body the live call would reject.
13
+ */
14
+ function requireLlmInferenceBody(flags, usage) {
15
+ const body = requiredJsonInput(flags, "--data, --data-file, or --stdin is required (LLM request body with llmId and queries).");
16
+ const llmId = body["llmId"];
17
+ if (typeof llmId !== "string" || llmId.trim().length === 0) {
18
+ throw new UsageError(`llmId is required and must be a non-empty string (e.g. "openai:openai1:gpt-4").\nUsage: ${usage}`, "invalid_flag_value");
19
+ }
20
+ const queries = body["queries"];
21
+ if (!Array.isArray(queries) || queries.length === 0) {
22
+ throw new UsageError(`queries is required and must be a non-empty array of query objects.\nUsage: ${usage}`, "invalid_flag_value");
23
+ }
24
+ return body;
25
+ }
26
+ export const llmCommands = {
27
+ list: {
28
+ handler: (c, _a, f) => {
29
+ const purpose = f["purpose"];
30
+ return c.llms.list({
31
+ purpose,
32
+ projectKey: f["project-key"],
33
+ });
34
+ },
35
+ usage: LLM_LIST_USAGE,
36
+ description: "List LLMs available in a project (includes Retrieval-Augmented Generation ones). Does not invoke any LLM.",
37
+ examples: ["dss llm list", "dss llm list --purpose TEXT_EMBEDDING_EXTRACTION",],
38
+ },
39
+ completions: {
40
+ handler: async (c, _a, f) => {
41
+ const body = requireLlmInferenceBody(f, LLM_COMPLETIONS_USAGE);
42
+ const projectKey = f["project-key"];
43
+ if (executionMode(f).dryRun) {
44
+ return planResult("llm", "completions", {
45
+ asyncKind: "none",
46
+ method: "POST",
47
+ endpoint: `/public/api/projects/${encodeURIComponent(projectKey ?? c.resolveProjectKey(undefined))}/llms/completions`,
48
+ identifiers: {
49
+ llmId: typeof body["llmId"] === "string" ? body["llmId"] : undefined,
50
+ },
51
+ payload: body,
52
+ idempotency: "none",
53
+ exitCodesOnFailure: LLM_PLAN_EXIT_CODES,
54
+ plannedAndDryRun: true,
55
+ });
56
+ }
57
+ return c.llms.completions(body, projectKey);
58
+ },
59
+ usage: LLM_COMPLETIONS_USAGE,
60
+ description: "Perform completions on an LLM. COST-BEARING: invokes the LLM provider and may incur charges. Body: { llmId, queries: [{ messages: [...] }], settings?: {...} }.",
61
+ examples: [
62
+ 'dss llm completions --data \'{"llmId":"openai:openai1:gpt-4","queries":[{"messages":[{"role":"user","content":"Hello"}]}]}\'',
63
+ 'dss llm completions --data \'{"llmId":"openai:openai1:gpt-4","queries":[...],"settings":{"temperature":0.9}}\' --dry-run',
64
+ ],
65
+ },
66
+ embeddings: {
67
+ handler: async (c, _a, f) => {
68
+ const body = requireLlmInferenceBody(f, LLM_EMBEDDINGS_USAGE);
69
+ const projectKey = f["project-key"];
70
+ if (executionMode(f).dryRun) {
71
+ return planResult("llm", "embeddings", {
72
+ asyncKind: "none",
73
+ method: "POST",
74
+ endpoint: `/public/api/projects/${encodeURIComponent(projectKey ?? c.resolveProjectKey(undefined))}/llms/embeddings`,
75
+ identifiers: {
76
+ llmId: typeof body["llmId"] === "string" ? body["llmId"] : undefined,
77
+ },
78
+ payload: body,
79
+ idempotency: "none",
80
+ exitCodesOnFailure: LLM_PLAN_EXIT_CODES,
81
+ plannedAndDryRun: true,
82
+ });
83
+ }
84
+ return c.llms.embeddings(body, projectKey);
85
+ },
86
+ usage: LLM_EMBEDDINGS_USAGE,
87
+ description: 'Perform embeddings on an LLM. COST-BEARING: invokes the LLM provider and may incur charges. Body: { llmId, queries: [{ text: "..." }] }.',
88
+ examples: [
89
+ 'dss llm embeddings --data \'{"llmId":"openai:openai1:ada002-text-embedding","queries":[{"text":"Who wrote Beethoven 9th?"}]}\'',
90
+ 'dss llm embeddings --data \'{"llmId":"x","queries":[{"text":"y"}]}\' --dry-run',
91
+ ],
92
+ },
93
+ };
@@ -0,0 +1,2 @@
1
+ import type { CommandMeta } from "../types.js";
2
+ export declare const macroCommands: Record<string, CommandMeta>;
@@ -0,0 +1,221 @@
1
+ import { macroResultMaxBytes, } from "../../resources/macros.js";
2
+ import { jsonInput, num, } from "../coerce.js";
3
+ import { executionMode, } from "../flags.js";
4
+ import { encodedProjectEndpoint, } from "../output.js";
5
+ import { requireArgs, UsageError, } from "../usage.js";
6
+ const MACRO_RUN_USAGE = "dss macro run <macro_id> [--wait] [--timeout MS (default 120000)] [--poll-interval MS] [--data JSON] [--dry-run] [--project-key KEY]";
7
+ /**
8
+ * Flags accepted by run/run-and-wait; validated identically for live, dry-run,
9
+ * and --plan so a plan that would fail cannot be "fixed" by dropping flags.
10
+ * Returns undefined rather than a partial options object so callers can spread
11
+ * it only when the macro actually has parameters.
12
+ */
13
+ function macroWaitOptionsFromFlags(flags) {
14
+ const timeoutMs = num(flags["timeout"], "--timeout");
15
+ const pollIntervalMs = num(flags["poll-interval"], "--poll-interval");
16
+ if (timeoutMs !== undefined && timeoutMs < 0) {
17
+ throw new UsageError("--timeout must be >= 0.", "invalid_flag_value", undefined, {
18
+ flag: "--timeout",
19
+ });
20
+ }
21
+ if (pollIntervalMs !== undefined && pollIntervalMs < 1) {
22
+ throw new UsageError("--poll-interval must be >= 1.", "invalid_flag_value", undefined, { flag: "--poll-interval", });
23
+ }
24
+ return { timeoutMs, pollIntervalMs, };
25
+ }
26
+ /**
27
+ * Macro parameter payload from --data/--data-file/--stdin. The JSON object is
28
+ * passed through as the POST body: `{ "params": {...}, "adminParams": {...} }`.
29
+ * Values may carry credentials; the plan redacts nothing beyond DSS's own
30
+ * response echo, so callers must not log payloads.
31
+ */
32
+ function macroRunParamsFromFlags(flags) {
33
+ const input = jsonInput(flags);
34
+ if (input === undefined)
35
+ return {};
36
+ const body = {};
37
+ if (input["params"] !== undefined) {
38
+ if (input["params"] === null || typeof input["params"] !== "object") {
39
+ throw new UsageError("Macro run payload params must be an object keyed by macro parameter names.", "invalid_flag_value", undefined, { flag: "--data", });
40
+ }
41
+ body.params = input["params"];
42
+ }
43
+ if (input["adminParams"] !== undefined) {
44
+ if (input["adminParams"] === null || typeof input["adminParams"] !== "object") {
45
+ throw new UsageError("Macro run payload adminParams must be an object.", "invalid_flag_value", undefined, { flag: "--data", });
46
+ }
47
+ body.adminParams = input["adminParams"];
48
+ }
49
+ return body;
50
+ }
51
+ /** Exact POST body a run will send; empty object when no parameters. */
52
+ function macroRunDryRunPayload(runParams) {
53
+ const payload = {};
54
+ if (runParams.params !== undefined)
55
+ payload["params"] = runParams.params;
56
+ if (runParams.adminParams !== undefined)
57
+ payload["adminParams"] = runParams.adminParams;
58
+ return payload;
59
+ }
60
+ /**
61
+ * Reject blank/whitespace positional ids as a usage error BEFORE any request:
62
+ * an empty macro/run id would hit the list route or an unresolvable path.
63
+ */
64
+ function requireNotBlankId(value, usage) {
65
+ if (value.trim().length === 0) {
66
+ throw new UsageError(`Macro/run id must be non-empty. Usage: ${usage}`);
67
+ }
68
+ }
69
+ export const macroCommands = {
70
+ list: {
71
+ handler: (c, _a, f) => c.macros.list(f["project-key"]),
72
+ usage: "dss macro list [--project-key KEY]",
73
+ description: "List the macros (runnables) available in a project.",
74
+ examples: ["dss macro list",],
75
+ },
76
+ get: {
77
+ handler: (c, a, f) => {
78
+ requireArgs(a, 1, "dss macro get <macro_id>");
79
+ requireNotBlankId(a[0], "dss macro get <macro_id>");
80
+ return c.macros.definition(a[0], {
81
+ projectKey: f["project-key"],
82
+ });
83
+ },
84
+ usage: "dss macro get <macro_id> [--project-key KEY]",
85
+ description: "Get a macro's definition: parameters, result type, owning plugin, labels.",
86
+ examples: ["dss macro get compute_orders",],
87
+ },
88
+ run: {
89
+ handler: async (c, a, f) => {
90
+ requireArgs(a, 1, "dss macro run <macro_id>");
91
+ const pk = f["project-key"];
92
+ const waitOptions = macroWaitOptionsFromFlags(f);
93
+ const runParams = macroRunParamsFromFlags(f);
94
+ if (executionMode(f).dryRun) {
95
+ return {
96
+ dryRun: true,
97
+ action: "run",
98
+ resource: "macro",
99
+ id: a[0],
100
+ ...waitOptions,
101
+ ...(runParams.params !== undefined ? { params: runParams.params, } : {}),
102
+ ...(runParams.adminParams !== undefined
103
+ ? { adminParams: runParams.adminParams, }
104
+ : {}),
105
+ endpoint: encodedProjectEndpoint(c, pk, `/runnables/${encodeURIComponent(a[0])}?wait=false`),
106
+ method: "POST",
107
+ payload: macroRunDryRunPayload(runParams),
108
+ warning: "Macro runs execute arbitrary plugin code on the DSS backend; review the macro definition before running.",
109
+ };
110
+ }
111
+ if (f["wait"] === true) {
112
+ return c.macros.runAndWait(a[0], {
113
+ ...waitOptions,
114
+ ...runParams,
115
+ projectKey: pk,
116
+ });
117
+ }
118
+ return c.macros.run(a[0], { ...runParams, projectKey: pk, });
119
+ },
120
+ usage: MACRO_RUN_USAGE,
121
+ description: "Start a macro run. Macros execute arbitrary plugin code and are classified destructive. --wait polls to completion and exits 4 on failure; without it only the runId is returned. --data JSON may carry { params: {...}, adminParams: {...} } for parameterized macros.",
122
+ examples: [
123
+ "dss macro run compute_orders",
124
+ "dss macro run compute_orders --wait",
125
+ 'dss macro run compute_orders --data \'{"params":{"region":"EU"}}\'',
126
+ "dss macro run compute_orders --wait --timeout 300000",
127
+ ],
128
+ },
129
+ "run-and-wait": {
130
+ handler: async (c, a, f) => {
131
+ requireArgs(a, 1, "dss macro run-and-wait <macro_id>");
132
+ const pk = f["project-key"];
133
+ const waitOptions = macroWaitOptionsFromFlags(f);
134
+ const runParams = macroRunParamsFromFlags(f);
135
+ if (executionMode(f).dryRun) {
136
+ return {
137
+ dryRun: true,
138
+ action: "run-and-wait",
139
+ resource: "macro",
140
+ id: a[0],
141
+ ...waitOptions,
142
+ ...(runParams.params !== undefined ? { params: runParams.params, } : {}),
143
+ ...(runParams.adminParams !== undefined
144
+ ? { adminParams: runParams.adminParams, }
145
+ : {}),
146
+ endpoint: encodedProjectEndpoint(c, pk, `/runnables/${encodeURIComponent(a[0])}?wait=false`),
147
+ method: "POST",
148
+ payload: macroRunDryRunPayload(runParams),
149
+ warning: "Macro runs execute arbitrary plugin code on the DSS backend; review the macro definition before running.",
150
+ };
151
+ }
152
+ return c.macros.runAndWait(a[0], {
153
+ ...waitOptions,
154
+ ...runParams,
155
+ projectKey: pk,
156
+ });
157
+ },
158
+ usage: "dss macro run-and-wait <macro_id> [--timeout MS (default 120000)] [--poll-interval MS] [--data JSON] [--dry-run] [--project-key KEY]",
159
+ description: "Run a macro and poll its state until it finishes. Exits 4 on failure; returns { success: false, timedOut: true } on timeout.",
160
+ examples: [
161
+ "dss macro run-and-wait compute_orders",
162
+ "dss macro run-and-wait compute_orders --timeout 60000 --poll-interval 500",
163
+ ],
164
+ },
165
+ abort: {
166
+ handler: async (c, a, f) => {
167
+ requireArgs(a, 2, "dss macro abort <macro_id> <run_id>");
168
+ requireNotBlankId(a[0], "dss macro abort <macro_id> <run_id>");
169
+ requireNotBlankId(a[1], "dss macro abort <macro_id> <run_id>");
170
+ const pk = f["project-key"];
171
+ if (executionMode(f).dryRun) {
172
+ return {
173
+ dryRun: true,
174
+ action: "abort",
175
+ resource: "macro",
176
+ id: a[0],
177
+ runId: a[1],
178
+ endpoint: encodedProjectEndpoint(c, pk, `/runnables/${encodeURIComponent(a[0])}/abort/${encodeURIComponent(a[1])}`),
179
+ method: "POST",
180
+ };
181
+ }
182
+ await c.macros.abort(a[0], a[1], pk);
183
+ return { aborted: a[1], runId: a[1], resource: "macro", };
184
+ },
185
+ usage: "dss macro abort <macro_id> <run_id> [--dry-run] [--project-key KEY]",
186
+ description: "Request abort of a running macro run.",
187
+ examples: ["dss macro abort compute_orders run_42",],
188
+ },
189
+ state: {
190
+ handler: (c, a, f) => {
191
+ requireArgs(a, 2, "dss macro state <macro_id> <run_id>");
192
+ requireNotBlankId(a[0], "dss macro state <macro_id> <run_id>");
193
+ requireNotBlankId(a[1], "dss macro state <macro_id> <run_id>");
194
+ return c.macros.state(a[0], a[1], {
195
+ projectKey: f["project-key"],
196
+ });
197
+ },
198
+ usage: "dss macro state <macro_id> <run_id> [--project-key KEY]",
199
+ description: "Get the poll state of a macro run: running flag, progress stack, failure details.",
200
+ examples: ["dss macro state compute_orders run_42",],
201
+ },
202
+ result: {
203
+ handler: async (c, a, f) => {
204
+ requireArgs(a, 2, "dss macro result <macro_id> <run_id>");
205
+ requireNotBlankId(a[0], "dss macro result <macro_id> <run_id>");
206
+ requireNotBlankId(a[1], "dss macro result <macro_id> <run_id>");
207
+ const pk = f["project-key"];
208
+ const maxBytes = num(f["max-bytes"], "--max-bytes");
209
+ if (maxBytes !== undefined && (maxBytes < 1 || !Number.isInteger(maxBytes))) {
210
+ throw new UsageError("--max-bytes must be a positive integer.", "invalid_flag_value", undefined, { flag: "--max-bytes", });
211
+ }
212
+ return c.macros.result(a[0], a[1], {
213
+ projectKey: pk,
214
+ maxBytes: macroResultMaxBytes(maxBytes),
215
+ });
216
+ },
217
+ usage: "dss macro result <macro_id> <run_id> [--max-bytes N (default 8388608)] [--project-key KEY]",
218
+ description: "Download a macro run's result. Text/HTML bodies print as a JSON string (stdout stays one JSON document, embedded newlines escaped); JSON bodies print as the parsed object.",
219
+ examples: ["dss macro result compute_orders run_42", "dss macro result m r --max-bytes 1024",],
220
+ },
221
+ };