-
Notifications
You must be signed in to change notification settings - Fork 963
feat(cli): split 'automations prompt' into 'prompt get' and 'prompt set' #3959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4ae861f
e69cfb8
5a95661
ff89de3
72be5df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { isAgentMode, positional } from "@superset/cli-framework"; | ||
| import { command } from "../../../../lib/command"; | ||
|
|
||
| export default command({ | ||
| description: "Print an automation's prompt to stdout", | ||
| args: [positional("id").required().desc("Automation id")], | ||
| run: async ({ ctx, args, options }) => { | ||
| const id = args.id as string; | ||
| const { prompt } = await ctx.api.automation.getPrompt.query({ id }); | ||
| // `--quiet` is intentionally ignored here: it would route through | ||
| // `extractIds` and emit only the UUID (which the caller already has | ||
| // as input), discarding the prompt body. Plain stdout is the right | ||
| // "machine-friendly" output for this command. | ||
| const globals = options as Record<string, unknown>; | ||
| if (globals.json === true || isAgentMode()) { | ||
| return { data: { id, prompt } }; | ||
| } | ||
| // Default: write the raw prompt with no trailing newline so that | ||
| // `prompt get <id> > out.md` round-trips byte-exactly with a | ||
| // subsequent `prompt set <id> --from-file out.md`. | ||
| process.stdout.write(prompt ?? ""); | ||
| return undefined; | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export default { | ||
| description: "Read or write an automation's prompt", | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { readFileSync } from "node:fs"; | ||
| import { positional, string } from "@superset/cli-framework"; | ||
| import { command } from "../../../../lib/command"; | ||
|
|
||
| async function readStdin(): Promise<string> { | ||
| const chunks: Buffer[] = []; | ||
| for await (const chunk of process.stdin) { | ||
| chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk); | ||
| } | ||
| return Buffer.concat(chunks).toString("utf-8"); | ||
| } | ||
|
|
||
| export default command({ | ||
| description: "Replace an automation's prompt from a file or stdin", | ||
| args: [positional("id").required().desc("Automation id")], | ||
| options: { | ||
| fromFile: string() | ||
| .required() | ||
| .desc( | ||
| "Path to a markdown file with the new prompt. Use '-' to read from stdin.", | ||
| ), | ||
| }, | ||
| run: async ({ ctx, args, options }) => { | ||
| const id = args.id as string; | ||
| const next = | ||
| options.fromFile === "-" | ||
| ? await readStdin() | ||
| : readFileSync(options.fromFile, "utf-8"); | ||
|
|
||
| if (!next.trim()) { | ||
| throw new Error("Refusing to write an empty prompt."); | ||
| } | ||
|
|
||
| const result = await ctx.api.automation.setPrompt.mutate({ | ||
| id, | ||
| prompt: next, | ||
| }); | ||
| return { | ||
| data: { id: result.id, name: result.name, length: next.length }, | ||
| message: `Updated prompt for "${result.name}" (${next.length} chars).`, | ||
| }; | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,8 @@ import type { RequestOptions } from "../internal/request-options"; | |
|
|
||
| export class Automations extends APIResource { | ||
| /** | ||
| * List automations in the active organization. | ||
| * List automations in the active organization. Returned rows omit the | ||
| * `prompt` body — fetch one prompt with `getPrompt(id)`. | ||
| * | ||
| * Mirrors `superset automations list`. | ||
| */ | ||
|
|
@@ -17,12 +18,20 @@ export class Automations extends APIResource { | |
| } | ||
|
|
||
| /** | ||
| * Retrieve a single automation by id. | ||
| * Retrieve a single automation by id. The `prompt` body is omitted — | ||
| * fetch it separately with `getPrompt(id)`. | ||
| * | ||
| * Mirrors `superset automations get`. | ||
| */ | ||
| retrieve(id: string, options?: RequestOptions): APIPromise<Automation> { | ||
| return this._client.query<Automation>("automation.get", { id }, options); | ||
| retrieve( | ||
| id: string, | ||
| options?: RequestOptions, | ||
| ): APIPromise<AutomationSummary> { | ||
| return this._client.query<AutomationSummary>( | ||
| "automation.get", | ||
| { id }, | ||
| options, | ||
| ); | ||
| } | ||
|
Comment on lines
+26
to
35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Breaking SDK change: Both the TypeScript API type and the underlying The PR description states "No wire-format/API changes," but the tRPC response shape for 🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
|
|
@@ -125,9 +134,10 @@ export class Automations extends APIResource { | |
| } | ||
|
|
||
| /** | ||
| * Get the prompt for an automation. | ||
| * Get the prompt body (markdown) for an automation. `retrieve` and | ||
| * `list` omit it because it can be large. | ||
| * | ||
| * Mirrors `superset automations prompt --get`. | ||
| * Mirrors `superset automations prompt get`. | ||
| */ | ||
| getPrompt( | ||
| id: string, | ||
|
|
@@ -141,9 +151,10 @@ export class Automations extends APIResource { | |
| } | ||
|
|
||
| /** | ||
| * Update the prompt for an automation. | ||
| * Replace the prompt body for an automation. The new prompt fully | ||
| * overwrites the old one. | ||
| * | ||
| * Mirrors `superset automations prompt`. | ||
| * Mirrors `superset automations prompt set`. | ||
| */ | ||
| setPrompt( | ||
| id: string, | ||
|
|
@@ -165,12 +176,15 @@ export interface AgentConfig { | |
| [key: string]: unknown; | ||
| } | ||
|
|
||
| export interface Automation { | ||
| /** | ||
| * Lean automation row returned by `list` and `retrieve`. The `prompt` | ||
| * body is omitted — call `getPrompt(id)` to fetch it. | ||
| */ | ||
| export interface AutomationSummary { | ||
| id: string; | ||
| organizationId: string; | ||
| ownerUserId: string; | ||
| name: string; | ||
| prompt: string; | ||
| agentConfig: AgentConfig; | ||
| targetHostId: string | null; | ||
| v2ProjectId: string; | ||
|
|
@@ -187,7 +201,15 @@ export interface Automation { | |
| updatedAt: string; | ||
| } | ||
|
|
||
| export type AutomationListResponse = Array<Automation>; | ||
| /** | ||
| * Full automation row including the `prompt` body. Returned by mutations | ||
| * like `create`, `update`, `pause`, `resume`, and `setPrompt`. | ||
| */ | ||
| export interface Automation extends AutomationSummary { | ||
| prompt: string; | ||
| } | ||
|
|
||
| export type AutomationListResponse = Array<AutomationSummary>; | ||
|
|
||
| export interface AutomationCreateParams { | ||
| name: string; | ||
|
|
@@ -252,6 +274,7 @@ export interface AutomationRunDispatched { | |
| export declare namespace Automations { | ||
| export type { | ||
| Automation, | ||
| AutomationSummary, | ||
| AutomationListResponse, | ||
| AutomationCreateParams, | ||
| AutomationUpdateParams, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prompt getis missing its structured output shape for--json/--quiet/ agent modes.The PR description explicitly states that
prompt get"falls back to structured{ id, prompt }output" when--json,--quiet, or an agent-mode env var is active. The current block only documents the raw-text path viaoutput="Markdown", so users scripting againstprompt get --json(the typical machine-readable invocation) have no documented return shape.Also,
"Markdown"is not a TypeScript type name — every otheroutputprop in this file is either a named type ("Automation","Array<AutomationRun>") or an inline literal. Depending on how theCommandcomponent renders theoutputprop, this may appear oddly in the rendered docs.Suggested fix — add the JSON fallback shape inline the same way other commands document multiple output modes:
📝 Proposed documentation update
<Command name="superset automations prompt get <id>" args={[ { name: "id", required: true, description: "Automation ID." }, ]} - output="Markdown" > Print an automation's prompt body to stdout. The output is the raw prompt with no trailing newline added, so `prompt get` and `prompt set` round-trip byte-exactly. +In `--json`, `--quiet`, or agent modes the command falls back to structured output: + +```ts +{ id: string; prompt: string } +``` + ```bash # Read to a file superset automations prompt get aut_… > prompt.md📝 Committable suggestion
🤖 Prompt for AI Agents