@5y/cli 0.0.0-stage → 0.1.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/lib/output.mjs ADDED
@@ -0,0 +1,105 @@
1
+ /** Exit codes from spec §8.2. */
2
+ export const EXIT = Object.freeze({
3
+ OK: 0,
4
+ USAGE: 2,
5
+ AUTH: 3,
6
+ BUSINESS: 4,
7
+ UPSTREAM: 5,
8
+ });
9
+
10
+ export class CliError extends Error {
11
+ constructor({
12
+ code = 'INTERNAL',
13
+ message = 'unknown error',
14
+ retryable = false,
15
+ requestId = null,
16
+ exitCode = EXIT.BUSINESS,
17
+ details = undefined,
18
+ } = {}) {
19
+ super(message);
20
+ this.name = 'CliError';
21
+ this.code = code;
22
+ this.retryable = Boolean(retryable);
23
+ this.requestId = requestId;
24
+ this.exitCode = exitCode;
25
+ this.details = details;
26
+ }
27
+ }
28
+
29
+ export class UsageError extends Error {
30
+ constructor(message) {
31
+ super(message);
32
+ this.name = 'UsageError';
33
+ }
34
+ }
35
+
36
+ /** Progress / diagnostics always go to stderr. */
37
+ export function log(message) {
38
+ process.stderr.write(`[5y] ${message}\n`);
39
+ }
40
+
41
+ /** stdout contract: exactly one line of JSON. */
42
+ export function emitSuccess(payload = {}) {
43
+ process.stdout.write(`${JSON.stringify({ ok: true, ...payload })}\n`);
44
+ }
45
+
46
+ export function emitFailure(err) {
47
+ const error = {
48
+ code: err.code || 'INTERNAL',
49
+ message: err.message || String(err),
50
+ retryable: Boolean(err.retryable),
51
+ };
52
+ if (err.requestId) error.request_id = err.requestId;
53
+ if (err.details !== undefined) error.details = err.details;
54
+ process.stdout.write(`${JSON.stringify({ ok: false, error })}\n`);
55
+ }
56
+
57
+ export function exitCodeForStatus(status) {
58
+ if (status === 401 || status === 403) return EXIT.AUTH;
59
+ if (status === 429 || status >= 500) return EXIT.UPSTREAM;
60
+ if (status >= 400) return EXIT.BUSINESS;
61
+ return EXIT.OK;
62
+ }
63
+
64
+ export function defaultErrorCode(status) {
65
+ switch (status) {
66
+ case 401:
67
+ return 'UNAUTHORIZED';
68
+ case 402:
69
+ return 'INSUFFICIENT_CREDITS';
70
+ case 403:
71
+ return 'FORBIDDEN_SCOPE';
72
+ case 404:
73
+ return 'NOT_FOUND';
74
+ case 409:
75
+ return 'CONFLICT';
76
+ case 422:
77
+ return 'INVALID_PARAMS';
78
+ case 429:
79
+ return 'RATE_LIMITED';
80
+ case 500:
81
+ return 'INTERNAL';
82
+ case 502:
83
+ return 'UPSTREAM_UNAVAILABLE';
84
+ default:
85
+ return status >= 500 ? 'UPSTREAM_UNAVAILABLE' : 'REQUEST_FAILED';
86
+ }
87
+ }
88
+
89
+ export function sleep(ms) {
90
+ return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
91
+ }
92
+
93
+ export function retryBaseMs() {
94
+ const raw = Number(process.env['5Y_RETRY_BASE_MS']);
95
+ return Number.isFinite(raw) && raw >= 0 ? raw : 1000;
96
+ }
97
+
98
+ /** 1st retry waits base, then 2x, then 4x (default 1s / 2s / 4s). */
99
+ export function retryDelay(attempt, retryAfterHeader) {
100
+ if (retryAfterHeader !== undefined && retryAfterHeader !== null) {
101
+ const seconds = Number(retryAfterHeader);
102
+ if (Number.isFinite(seconds) && seconds >= 0) return Math.round(seconds * 1000);
103
+ }
104
+ return retryBaseMs() * 2 ** attempt;
105
+ }
@@ -0,0 +1,6 @@
1
+ import { createRequire } from 'node:module';
2
+
3
+ const require = createRequire(import.meta.url);
4
+ const pkg = require('../package.json');
5
+
6
+ export const VERSION = pkg.version;
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@5y/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "5y open API CLI — generate images/videos and manage assets from Codex / Claude Code / WorkBuddy",
5
+ "type": "module",
6
+ "bin": {
7
+ "5y": "bin/5y.mjs"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "lib"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "scripts": {
17
+ "test": "node --test test/*.test.mjs"
18
+ },
19
+ "dependencies": {},
20
+ "license": "UNLICENSED",
21
+ "keywords": [
22
+ "5y",
23
+ "cli",
24
+ "image-generation",
25
+ "video-generation",
26
+ "ai-agent"
27
+ ],
28
+ "homepage": "https://5y.com.cn",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://g.k601.cn/aquarium/5y.git",
32
+ "directory": "cli"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "author": "5y"
38
+ }