bazaar.it 0.1.0 → 0.2.1
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 +485 -3
- package/bin/baz.js +6 -1
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +109 -0
- package/dist/commands/capabilities.d.ts +2 -0
- package/dist/commands/capabilities.js +44 -0
- package/dist/commands/context.d.ts +13 -0
- package/dist/commands/context.js +498 -0
- package/dist/commands/export.d.ts +2 -0
- package/dist/commands/export.js +360 -0
- package/dist/commands/logs.d.ts +2 -0
- package/dist/commands/logs.js +180 -0
- package/dist/commands/loop.d.ts +2 -0
- package/dist/commands/loop.js +538 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +143 -0
- package/dist/commands/media.d.ts +2 -0
- package/dist/commands/media.js +362 -0
- package/dist/commands/project.d.ts +2 -0
- package/dist/commands/project.js +786 -0
- package/dist/commands/prompt.d.ts +2 -0
- package/dist/commands/prompt.js +540 -0
- package/dist/commands/recipe.d.ts +15 -0
- package/dist/commands/recipe.js +607 -0
- package/dist/commands/review.d.ts +17 -0
- package/dist/commands/review.js +345 -0
- package/dist/commands/scenes.d.ts +2 -0
- package/dist/commands/scenes.js +481 -0
- package/dist/commands/share.d.ts +2 -0
- package/dist/commands/share.js +226 -0
- package/dist/commands/state.d.ts +2 -0
- package/dist/commands/state.js +171 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +219 -0
- package/dist/commands/template.d.ts +2 -0
- package/dist/commands/template.js +123 -0
- package/dist/commands/verify.d.ts +2 -0
- package/dist/commands/verify.js +150 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +124 -0
- package/dist/lib/api.d.ts +188 -0
- package/dist/lib/api.js +719 -0
- package/dist/lib/banner.d.ts +12 -0
- package/dist/lib/banner.js +69 -0
- package/dist/lib/config.d.ts +33 -0
- package/dist/lib/config.js +99 -0
- package/dist/lib/output.d.ts +52 -0
- package/dist/lib/output.js +162 -0
- package/dist/lib/project-state.d.ts +52 -0
- package/dist/lib/project-state.js +178 -0
- package/dist/lib/sse.d.ts +168 -0
- package/dist/lib/sse.js +227 -0
- package/dist/lib/version.d.ts +1 -0
- package/dist/lib/version.js +3 -0
- package/dist/repl.d.ts +4 -0
- package/dist/repl.js +764 -0
- package/package.json +32 -5
package/dist/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { loadConfig } from './lib/config.js';
|
|
5
|
+
import { showBanner } from './lib/banner.js';
|
|
6
|
+
import { projectCommand } from './commands/project.js';
|
|
7
|
+
import { promptCommand } from './commands/prompt.js';
|
|
8
|
+
import { scenesCommand } from './commands/scenes.js';
|
|
9
|
+
import { authCommand } from './commands/auth.js';
|
|
10
|
+
import { exportCommand } from './commands/export.js';
|
|
11
|
+
import { statusCommand } from './commands/status.js';
|
|
12
|
+
import { mediaCommand } from './commands/media.js';
|
|
13
|
+
import { logsCommand } from './commands/logs.js';
|
|
14
|
+
import { recipeCommand } from './commands/recipe.js';
|
|
15
|
+
import { reviewCommand } from './commands/review.js';
|
|
16
|
+
import { contextCommand } from './commands/context.js';
|
|
17
|
+
import { capabilitiesCommand } from './commands/capabilities.js';
|
|
18
|
+
import { loopCommand } from './commands/loop.js';
|
|
19
|
+
import { stateCommand } from './commands/state.js';
|
|
20
|
+
import { verifyCommand } from './commands/verify.js';
|
|
21
|
+
import { mcpCommand } from './commands/mcp.js';
|
|
22
|
+
import { templateCommand } from './commands/template.js';
|
|
23
|
+
import { shareCommand } from './commands/share.js';
|
|
24
|
+
import { startRepl } from './repl.js';
|
|
25
|
+
import { CLI_VERSION } from './lib/version.js';
|
|
26
|
+
// Check for interactive mode
|
|
27
|
+
const args = process.argv.slice(2);
|
|
28
|
+
const agentModeEnv = process.env.BAZ_AGENT === '1';
|
|
29
|
+
const isInteractive = args.includes('-i') || args.includes('--interactive') || args.length === 0;
|
|
30
|
+
// Agent auto-mode: default to JSON + compact + events-only in non-interactive mode
|
|
31
|
+
if (agentModeEnv && !isInteractive) {
|
|
32
|
+
if (!args.includes('--json')) {
|
|
33
|
+
process.argv.push('--json');
|
|
34
|
+
}
|
|
35
|
+
if (!args.includes('--compact')) {
|
|
36
|
+
process.argv.push('--compact');
|
|
37
|
+
}
|
|
38
|
+
// Auto-enable events-only for streaming commands (skip text/thinking token firehose)
|
|
39
|
+
// Note: prompt.ts also checks agentModeEnv directly as a fallback
|
|
40
|
+
if (!args.includes('--events-only') && !args.includes('--no-events-only')) {
|
|
41
|
+
process.argv.push('--events-only');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// If interactive mode (no args or -i flag), start REPL
|
|
45
|
+
if (isInteractive && !args.includes('--help') && !args.includes('-h') && !args.includes('--version') && !args.includes('-v')) {
|
|
46
|
+
startRepl().catch((err) => {
|
|
47
|
+
console.error(chalk.red(`Fatal error: ${err.message}`));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Command mode - show banner for help
|
|
53
|
+
const showHelp = args.includes('--help') || args.includes('-h');
|
|
54
|
+
if (showHelp) {
|
|
55
|
+
try {
|
|
56
|
+
const config = loadConfig();
|
|
57
|
+
showBanner(CLI_VERSION, {
|
|
58
|
+
hasApiKey: Boolean(config.apiKey),
|
|
59
|
+
apiUrl: config.apiUrl,
|
|
60
|
+
activeProject: config.activeProjectId,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
showBanner(CLI_VERSION);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
runCommandMode();
|
|
68
|
+
}
|
|
69
|
+
function runCommandMode() {
|
|
70
|
+
const program = new Command();
|
|
71
|
+
program
|
|
72
|
+
.name('baz')
|
|
73
|
+
.description('AI-powered video generation from your terminal')
|
|
74
|
+
.version(CLI_VERSION, '-v, --version', 'Show version')
|
|
75
|
+
.option('-i, --interactive', 'Start interactive REPL mode')
|
|
76
|
+
.option('--json', 'Output as JSON')
|
|
77
|
+
.option('--compact', 'Compact JSON output (no whitespace, saves tokens)')
|
|
78
|
+
.option('--verbose', 'Show detailed output')
|
|
79
|
+
.option('--config <path>', 'Custom config file path')
|
|
80
|
+
.option('--api-url <url>', 'Override API URL')
|
|
81
|
+
.option('--project-id <id>', 'Override active project');
|
|
82
|
+
// Register commands
|
|
83
|
+
program.addCommand(authCommand);
|
|
84
|
+
program.addCommand(projectCommand);
|
|
85
|
+
program.addCommand(promptCommand);
|
|
86
|
+
program.addCommand(scenesCommand);
|
|
87
|
+
program.addCommand(exportCommand);
|
|
88
|
+
program.addCommand(mediaCommand);
|
|
89
|
+
program.addCommand(logsCommand);
|
|
90
|
+
program.addCommand(statusCommand);
|
|
91
|
+
program.addCommand(recipeCommand);
|
|
92
|
+
program.addCommand(reviewCommand);
|
|
93
|
+
program.addCommand(contextCommand);
|
|
94
|
+
program.addCommand(capabilitiesCommand);
|
|
95
|
+
program.addCommand(loopCommand);
|
|
96
|
+
program.addCommand(stateCommand);
|
|
97
|
+
program.addCommand(verifyCommand);
|
|
98
|
+
program.addCommand(mcpCommand);
|
|
99
|
+
program.addCommand(templateCommand);
|
|
100
|
+
program.addCommand(shareCommand);
|
|
101
|
+
// Global error handler
|
|
102
|
+
program.exitOverride((err) => {
|
|
103
|
+
// Handle help display - commander throws with various codes
|
|
104
|
+
if (err.code === 'commander.help' ||
|
|
105
|
+
err.code === 'commander.helpDisplayed' ||
|
|
106
|
+
err.message?.includes('outputHelp')) {
|
|
107
|
+
process.exit(0);
|
|
108
|
+
}
|
|
109
|
+
// Handle version display
|
|
110
|
+
if (err.code === 'commander.version') {
|
|
111
|
+
process.exit(0);
|
|
112
|
+
}
|
|
113
|
+
console.error(chalk.red(`Error: ${err.message}`));
|
|
114
|
+
process.exit(1);
|
|
115
|
+
});
|
|
116
|
+
// Parse and run
|
|
117
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
118
|
+
console.error(chalk.red(`Fatal error: ${err.message}`));
|
|
119
|
+
if (program.opts().verbose) {
|
|
120
|
+
console.error(err.stack);
|
|
121
|
+
}
|
|
122
|
+
process.exit(1);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { Config } from './config.js';
|
|
2
|
+
import { type StopReason } from './sse.js';
|
|
3
|
+
/**
|
|
4
|
+
* Error codes for better CLI error handling
|
|
5
|
+
* These map to semantic exit codes for agent consumption
|
|
6
|
+
*/
|
|
7
|
+
export declare const ErrorCodes: {
|
|
8
|
+
readonly AUTH_MISSING: "AUTH_MISSING";
|
|
9
|
+
readonly AUTH_INVALID: "AUTH_INVALID";
|
|
10
|
+
readonly AUTH_EXPIRED: "AUTH_EXPIRED";
|
|
11
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
12
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
13
|
+
readonly VALIDATION: "VALIDATION";
|
|
14
|
+
readonly RATE_LIMIT: "RATE_LIMIT";
|
|
15
|
+
readonly BALANCE: "BALANCE";
|
|
16
|
+
readonly CAPACITY: "CAPACITY";
|
|
17
|
+
readonly CONTENT_FILTER: "CONTENT_FILTER";
|
|
18
|
+
readonly SERVER: "SERVER";
|
|
19
|
+
readonly NETWORK: "NETWORK";
|
|
20
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
21
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
22
|
+
};
|
|
23
|
+
export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
24
|
+
/**
|
|
25
|
+
* Error categories for agent decision-making
|
|
26
|
+
*/
|
|
27
|
+
export type ErrorCategory = 'auth' | 'validation' | 'transient' | 'resource' | 'semantic' | 'fatal';
|
|
28
|
+
/**
|
|
29
|
+
* Map error codes to categories
|
|
30
|
+
*/
|
|
31
|
+
export declare function getErrorCategory(code: ErrorCode): ErrorCategory;
|
|
32
|
+
/**
|
|
33
|
+
* Map error codes to exit codes for agent consumption
|
|
34
|
+
* Based on research: 0=success, 10=transient, 11=capacity, 12=semantic, 13=auth, 64-66=validation, 1=fatal
|
|
35
|
+
*/
|
|
36
|
+
export declare function getExitCode(code: ErrorCode): number;
|
|
37
|
+
/**
|
|
38
|
+
* Check if error is retryable
|
|
39
|
+
*/
|
|
40
|
+
export declare function isRetryable(code: ErrorCode): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Check if error is transient (temporary)
|
|
43
|
+
*/
|
|
44
|
+
export declare function isTransient(code: ErrorCode): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Custom API error with agent-friendly metadata
|
|
47
|
+
* Includes: code, category, retryable, transient, suggestion, retryAfter
|
|
48
|
+
*/
|
|
49
|
+
export declare class ApiError extends Error {
|
|
50
|
+
code: ErrorCode;
|
|
51
|
+
category: ErrorCategory;
|
|
52
|
+
retryable: boolean;
|
|
53
|
+
transient: boolean;
|
|
54
|
+
exitCode: number;
|
|
55
|
+
statusCode?: number;
|
|
56
|
+
details?: string;
|
|
57
|
+
suggestion?: string;
|
|
58
|
+
retryAfter?: number;
|
|
59
|
+
constructor(message: string, code: ErrorCode, options?: {
|
|
60
|
+
statusCode?: number;
|
|
61
|
+
details?: string;
|
|
62
|
+
suggestion?: string;
|
|
63
|
+
retryAfter?: number;
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Convert to JSON for agent consumption
|
|
67
|
+
*/
|
|
68
|
+
toJSON(): {
|
|
69
|
+
details?: string | undefined;
|
|
70
|
+
suggestion?: string | undefined;
|
|
71
|
+
retryAfter?: number | undefined;
|
|
72
|
+
type: string;
|
|
73
|
+
code: ErrorCode;
|
|
74
|
+
errorType: ErrorCode;
|
|
75
|
+
message: string;
|
|
76
|
+
category: ErrorCategory;
|
|
77
|
+
retryable: boolean;
|
|
78
|
+
transient: boolean;
|
|
79
|
+
exitCode: number;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Make a tRPC-style API request
|
|
84
|
+
*
|
|
85
|
+
* Since we're calling the server directly without the tRPC client,
|
|
86
|
+
* we use the HTTP batch format.
|
|
87
|
+
*/
|
|
88
|
+
export declare function apiRequest<T = unknown>(config: Config, procedure: string, input?: unknown): Promise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Upload result type
|
|
91
|
+
*/
|
|
92
|
+
export interface UploadResult {
|
|
93
|
+
url: string;
|
|
94
|
+
key: string;
|
|
95
|
+
size: number;
|
|
96
|
+
type: string;
|
|
97
|
+
originalName: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Upload an image and return the URL (backward compatible)
|
|
101
|
+
*/
|
|
102
|
+
export declare function uploadImage(config: Config, options: {
|
|
103
|
+
projectId: string;
|
|
104
|
+
buffer: Buffer;
|
|
105
|
+
filename: string;
|
|
106
|
+
}): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Upload any media file (image, video, audio) and return full result
|
|
109
|
+
*/
|
|
110
|
+
export declare function uploadMedia(config: Config, options: {
|
|
111
|
+
projectId: string;
|
|
112
|
+
buffer: Buffer;
|
|
113
|
+
filename: string;
|
|
114
|
+
mimeType: string;
|
|
115
|
+
}): Promise<UploadResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Fetch a URL and extract content (for --url flag)
|
|
118
|
+
*/
|
|
119
|
+
export declare function fetchUrlContent(url: string): Promise<{
|
|
120
|
+
content: string;
|
|
121
|
+
title?: string;
|
|
122
|
+
type: 'html' | 'text' | 'json' | 'unknown';
|
|
123
|
+
}>;
|
|
124
|
+
/**
|
|
125
|
+
* Stream a generation request (SSE)
|
|
126
|
+
*/
|
|
127
|
+
export declare function streamGeneration(config: Config, options: {
|
|
128
|
+
projectId: string;
|
|
129
|
+
prompt: string;
|
|
130
|
+
mode?: 'agent' | 'agent-max' | 'multi-scene';
|
|
131
|
+
imageUrls?: string[];
|
|
132
|
+
onEvent?: (event: StreamEvent) => void;
|
|
133
|
+
/** Include raw SSE data and timestamps in events (for bots/debugging) */
|
|
134
|
+
includeRaw?: boolean;
|
|
135
|
+
/** Plan mode: create recipe without executing (for handshake protocol) */
|
|
136
|
+
planOnly?: boolean;
|
|
137
|
+
/** Requirements to verify against after execution */
|
|
138
|
+
requirements?: string;
|
|
139
|
+
/** Per-run budget in USD (default: server decides, typically $5) */
|
|
140
|
+
budgetUsd?: number;
|
|
141
|
+
/** Model override (default: claude-sonnet-4-5 for CLI) */
|
|
142
|
+
modelOverride?: string;
|
|
143
|
+
}): Promise<StreamResult>;
|
|
144
|
+
export interface StreamEvent {
|
|
145
|
+
type: 'thinking' | 'tool_use' | 'code_gen' | 'compile' | 'scene_created' | 'scene_updated' | 'error' | 'complete' | 'text' | 'recipe_created' | 'workflow_created' | 'video_plan_created' | 'awaiting_approval' | 'ready' | 'asset_generated' | 'raw';
|
|
146
|
+
message?: string;
|
|
147
|
+
sceneId?: string;
|
|
148
|
+
sceneName?: string;
|
|
149
|
+
tool?: string;
|
|
150
|
+
summary?: string;
|
|
151
|
+
stopReason?: StopReason;
|
|
152
|
+
action?: 'start' | 'complete';
|
|
153
|
+
budgetUsd?: number;
|
|
154
|
+
model?: string;
|
|
155
|
+
assetUrl?: string;
|
|
156
|
+
assetType?: string;
|
|
157
|
+
costUsd?: number;
|
|
158
|
+
budget?: {
|
|
159
|
+
budgetUsd: number;
|
|
160
|
+
totalBilledUsd: number;
|
|
161
|
+
remainingUsd: number;
|
|
162
|
+
};
|
|
163
|
+
recipeName?: string;
|
|
164
|
+
recipeDescription?: string;
|
|
165
|
+
recipeId?: string;
|
|
166
|
+
executionId?: string;
|
|
167
|
+
workflowName?: string;
|
|
168
|
+
workflowDescription?: string;
|
|
169
|
+
videoPlanSummary?: string;
|
|
170
|
+
timestamp?: string;
|
|
171
|
+
raw?: unknown;
|
|
172
|
+
continue?: boolean;
|
|
173
|
+
errorType?: string;
|
|
174
|
+
errorCategory?: ErrorCategory;
|
|
175
|
+
retryable?: boolean;
|
|
176
|
+
transient?: boolean;
|
|
177
|
+
retryAfter?: number;
|
|
178
|
+
suggestion?: string;
|
|
179
|
+
}
|
|
180
|
+
export interface StreamResult {
|
|
181
|
+
success: boolean;
|
|
182
|
+
scenesCreated: string[];
|
|
183
|
+
scenesUpdated: string[];
|
|
184
|
+
errors: string[];
|
|
185
|
+
summary?: string;
|
|
186
|
+
stopReason?: StopReason;
|
|
187
|
+
continue: boolean;
|
|
188
|
+
}
|