egaki 0.5.0 → 0.7.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/CHANGELOG.md +188 -0
- package/dist/cli/cache-utils.d.ts +33 -0
- package/dist/cli/cache-utils.d.ts.map +1 -0
- package/dist/cli/cache-utils.js +157 -0
- package/dist/cli/cached-generate.d.ts +105 -0
- package/dist/cli/cached-generate.d.ts.map +1 -0
- package/dist/cli/cached-generate.js +208 -0
- package/dist/cli/cached-generate.test.d.ts +11 -0
- package/dist/cli/cached-generate.test.d.ts.map +1 -0
- package/dist/cli/cached-generate.test.js +431 -0
- package/dist/cli/cartesia-provider.d.ts +16 -0
- package/dist/cli/cartesia-provider.d.ts.map +1 -0
- package/dist/cli/cartesia-provider.js +184 -0
- package/dist/cli/chatgpt-auth.d.ts.map +1 -0
- package/dist/cli/cli.d.ts +4 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +1329 -0
- package/dist/cli/clone-generate.d.ts +26 -0
- package/dist/cli/clone-generate.d.ts.map +1 -0
- package/dist/cli/clone-generate.js +148 -0
- package/dist/{credentials.d.ts → cli/credentials.d.ts} +11 -2
- package/dist/cli/credentials.d.ts.map +1 -0
- package/dist/{credentials.js → cli/credentials.js} +88 -5
- package/dist/cli/elevenlabs-speech-provider.d.ts +26 -0
- package/dist/cli/elevenlabs-speech-provider.d.ts.map +1 -0
- package/dist/cli/elevenlabs-speech-provider.js +199 -0
- package/dist/cli/generate.d.ts +140 -0
- package/dist/cli/generate.d.ts.map +1 -0
- package/dist/cli/generate.js +604 -0
- package/dist/cli/generate.test.d.ts +2 -0
- package/dist/cli/generate.test.d.ts.map +1 -0
- package/dist/cli/generate.test.js +131 -0
- package/dist/cli/login.d.ts.map +1 -0
- package/dist/{login.js → cli/login.js} +45 -4
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +7 -0
- package/dist/cli/model-catalog.d.ts +141 -0
- package/dist/cli/model-catalog.d.ts.map +1 -0
- package/dist/cli/model-catalog.js +2135 -0
- package/dist/{models.d.ts → cli/models.d.ts} +16 -9
- package/dist/cli/models.d.ts.map +1 -0
- package/dist/cli/models.js +313 -0
- package/dist/cli/open-browser.d.ts.map +1 -0
- package/dist/cli/openai-speech-provider.d.ts +3 -0
- package/dist/cli/openai-speech-provider.d.ts.map +1 -0
- package/dist/cli/openai-speech-provider.js +28 -0
- package/dist/cli/separation-generate.d.ts +34 -0
- package/dist/cli/separation-generate.d.ts.map +1 -0
- package/dist/cli/separation-generate.js +117 -0
- package/dist/cli/speech-catalog.d.ts +35 -0
- package/dist/cli/speech-catalog.d.ts.map +1 -0
- package/dist/cli/speech-catalog.js +195 -0
- package/dist/cli/speech-generate.d.ts +86 -0
- package/dist/cli/speech-generate.d.ts.map +1 -0
- package/dist/cli/speech-generate.js +156 -0
- package/dist/cli/speech-models.d.ts +8 -0
- package/dist/cli/speech-models.d.ts.map +1 -0
- package/dist/cli/speech-models.js +109 -0
- package/dist/cli/speech-provider.test.d.ts +2 -0
- package/dist/cli/speech-provider.test.d.ts.map +1 -0
- package/dist/cli/speech-provider.test.js +197 -0
- package/dist/cli/subscription.d.ts.map +1 -0
- package/dist/cli/transcription-catalog.d.ts +35 -0
- package/dist/cli/transcription-catalog.d.ts.map +1 -0
- package/dist/cli/transcription-catalog.js +192 -0
- package/dist/cli/transcription-generate.d.ts +62 -0
- package/dist/cli/transcription-generate.d.ts.map +1 -0
- package/dist/cli/transcription-generate.js +144 -0
- package/dist/cli/transcription-models.d.ts +9 -0
- package/dist/cli/transcription-models.d.ts.map +1 -0
- package/dist/cli/transcription-models.js +100 -0
- package/dist/cli/transcription-providers.d.ts +22 -0
- package/dist/cli/transcription-providers.d.ts.map +1 -0
- package/dist/cli/transcription-providers.js +290 -0
- package/dist/cli/video-model-catalog.d.ts +2 -0
- package/dist/cli/video-model-catalog.d.ts.map +1 -0
- package/dist/cli/video-model-catalog.js +5 -0
- package/dist/cli/xai-auth.d.ts +29 -0
- package/dist/cli/xai-auth.d.ts.map +1 -0
- package/dist/cli/xai-auth.js +325 -0
- package/dist/vite/angled-screen.d.ts +57 -0
- package/dist/vite/angled-screen.d.ts.map +1 -0
- package/dist/vite/angled-screen.js +115 -0
- package/dist/vite/app.d.ts +51 -0
- package/dist/vite/app.d.ts.map +1 -0
- package/dist/vite/app.js +150 -0
- package/dist/vite/bands-shader.d.ts +47 -0
- package/dist/vite/bands-shader.d.ts.map +1 -0
- package/dist/vite/bands-shader.js +267 -0
- package/dist/vite/code-block.d.ts +107 -0
- package/dist/vite/code-block.d.ts.map +1 -0
- package/dist/vite/code-block.js +641 -0
- package/dist/vite/components.d.ts +36 -0
- package/dist/vite/components.d.ts.map +1 -0
- package/dist/vite/components.js +113 -0
- package/dist/vite/dispersion-rings-shader.d.ts +44 -0
- package/dist/vite/dispersion-rings-shader.d.ts.map +1 -0
- package/dist/vite/dispersion-rings-shader.js +282 -0
- package/dist/vite/easing-curves.d.ts +129 -0
- package/dist/vite/easing-curves.d.ts.map +1 -0
- package/dist/vite/easing-curves.js +584 -0
- package/dist/vite/easing-curves.test.d.ts +2 -0
- package/dist/vite/easing-curves.test.d.ts.map +1 -0
- package/dist/vite/easing-curves.test.js +200 -0
- package/dist/vite/generated-media-client.d.ts +35 -0
- package/dist/vite/generated-media-client.d.ts.map +1 -0
- package/dist/vite/generated-media-client.js +76 -0
- package/dist/vite/keyframes.d.ts +129 -0
- package/dist/vite/keyframes.d.ts.map +1 -0
- package/dist/vite/keyframes.js +194 -0
- package/dist/vite/layout-editor.d.ts +45 -0
- package/dist/vite/layout-editor.d.ts.map +1 -0
- package/dist/vite/layout-editor.js +587 -0
- package/dist/vite/layout-transition.d.ts +136 -0
- package/dist/vite/layout-transition.d.ts.map +1 -0
- package/dist/vite/layout-transition.js +581 -0
- package/dist/vite/liquid-gradient-shader.d.ts +62 -0
- package/dist/vite/liquid-gradient-shader.d.ts.map +1 -0
- package/dist/vite/liquid-gradient-shader.js +413 -0
- package/dist/vite/mdx-client.d.ts +15 -0
- package/dist/vite/mdx-client.d.ts.map +1 -0
- package/dist/vite/mdx-client.js +265 -0
- package/dist/vite/mdx-parse.d.ts +102 -0
- package/dist/vite/mdx-parse.d.ts.map +1 -0
- package/dist/vite/mdx-parse.js +251 -0
- package/dist/vite/mdx-provided-components.d.ts +18 -0
- package/dist/vite/mdx-provided-components.d.ts.map +1 -0
- package/dist/vite/mdx-provided-components.js +14 -0
- package/dist/vite/mdx-video.d.ts +327 -0
- package/dist/vite/mdx-video.d.ts.map +1 -0
- package/dist/vite/mdx-video.js +596 -0
- package/dist/vite/mdx-video.test.d.ts +9 -0
- package/dist/vite/mdx-video.test.d.ts.map +1 -0
- package/dist/vite/mdx-video.test.js +1945 -0
- package/dist/vite/media-components.d.ts +45 -0
- package/dist/vite/media-components.d.ts.map +1 -0
- package/dist/vite/media-components.js +355 -0
- package/dist/vite/media-duration-store.d.ts +66 -0
- package/dist/vite/media-duration-store.d.ts.map +1 -0
- package/dist/vite/media-duration-store.js +204 -0
- package/dist/vite/player-page.d.ts +35 -0
- package/dist/vite/player-page.d.ts.map +1 -0
- package/dist/vite/player-page.js +720 -0
- package/dist/vite/render-client.d.ts +18 -0
- package/dist/vite/render-client.d.ts.map +1 -0
- package/dist/vite/render-client.js +67 -0
- package/dist/vite/sdk.d.ts +221 -0
- package/dist/vite/sdk.d.ts.map +1 -0
- package/dist/vite/sdk.js +355 -0
- package/dist/vite/server-components.d.ts +55 -0
- package/dist/vite/server-components.d.ts.map +1 -0
- package/dist/vite/server-components.js +156 -0
- package/dist/vite/server-mdx.d.ts +74 -0
- package/dist/vite/server-mdx.d.ts.map +1 -0
- package/dist/vite/server-mdx.js +259 -0
- package/dist/vite/shader-renderer.d.ts +48 -0
- package/dist/vite/shader-renderer.d.ts.map +1 -0
- package/dist/vite/shader-renderer.js +411 -0
- package/dist/vite/store-hooks.d.ts +12 -0
- package/dist/vite/store-hooks.d.ts.map +1 -0
- package/dist/vite/store-hooks.js +93 -0
- package/dist/vite/store.d.ts +75 -0
- package/dist/vite/store.d.ts.map +1 -0
- package/dist/vite/store.js +52 -0
- package/dist/vite/store.test.d.ts +6 -0
- package/dist/vite/store.test.d.ts.map +1 -0
- package/dist/vite/store.test.js +172 -0
- package/dist/vite/tweakpane-hook.d.ts +94 -0
- package/dist/vite/tweakpane-hook.d.ts.map +1 -0
- package/dist/vite/tweakpane-hook.js +450 -0
- package/dist/vite/vite-plugin.d.ts +28 -0
- package/dist/vite/vite-plugin.d.ts.map +1 -0
- package/dist/vite/vite-plugin.js +538 -0
- package/dist/vite/wave-gradient-shader.d.ts +41 -0
- package/dist/vite/wave-gradient-shader.d.ts.map +1 -0
- package/dist/vite/wave-gradient-shader.js +207 -0
- package/package.json +103 -25
- package/skills/egaki/SKILL.md +162 -1
- package/src/cli/cache-utils.ts +169 -0
- package/src/cli/cached-generate.test.ts +531 -0
- package/src/cli/cached-generate.ts +348 -0
- package/src/cli/cartesia-provider.ts +249 -0
- package/src/cli/cli.ts +1818 -0
- package/src/cli/clone-generate.ts +202 -0
- package/src/{credentials.ts → cli/credentials.ts} +90 -7
- package/src/cli/elevenlabs-speech-provider.ts +243 -0
- package/src/cli/generate.test.ts +166 -0
- package/src/cli/generate.ts +912 -0
- package/src/{login.ts → cli/login.ts} +48 -3
- package/src/cli/main.ts +8 -0
- package/src/cli/model-catalog.ts +2336 -0
- package/src/cli/models.ts +408 -0
- package/src/cli/openai-speech-provider.ts +34 -0
- package/src/cli/separation-generate.ts +187 -0
- package/src/cli/speech-catalog.ts +253 -0
- package/src/cli/speech-generate.ts +275 -0
- package/src/cli/speech-models.ts +146 -0
- package/src/cli/speech-provider.test.ts +226 -0
- package/src/cli/transcription-catalog.ts +250 -0
- package/src/cli/transcription-generate.ts +214 -0
- package/src/cli/transcription-models.ts +136 -0
- package/src/cli/transcription-providers.ts +427 -0
- package/src/cli/video-model-catalog.ts +14 -0
- package/src/cli/xai-auth.ts +396 -0
- package/src/vite/angled-screen.tsx +214 -0
- package/src/vite/app.tsx +197 -0
- package/src/vite/bands-shader.tsx +319 -0
- package/src/vite/code-block.tsx +939 -0
- package/src/vite/components.tsx +278 -0
- package/src/vite/dispersion-rings-shader.tsx +331 -0
- package/src/vite/easing-curves.test.ts +232 -0
- package/src/vite/easing-curves.ts +743 -0
- package/src/vite/generated-media-client.tsx +121 -0
- package/src/vite/keyframes.tsx +347 -0
- package/src/vite/layout-editor.tsx +709 -0
- package/src/vite/layout-transition.tsx +706 -0
- package/src/vite/liquid-gradient-shader.tsx +474 -0
- package/src/vite/mdx-client.tsx +420 -0
- package/src/vite/mdx-parse.ts +343 -0
- package/src/vite/mdx-provided-components.ts +19 -0
- package/src/vite/mdx-video.test.tsx +2219 -0
- package/src/vite/mdx-video.tsx +976 -0
- package/src/vite/media-components.tsx +473 -0
- package/src/vite/media-duration-store.ts +225 -0
- package/src/vite/motion-timing.ts +194 -0
- package/src/vite/player-page.tsx +1107 -0
- package/src/vite/render-client.ts +84 -0
- package/src/vite/sdk.ts +598 -0
- package/src/vite/server-components.tsx +241 -0
- package/src/vite/server-mdx.ts +285 -0
- package/src/vite/shader-renderer.tsx +535 -0
- package/src/vite/store-hooks.ts +117 -0
- package/src/vite/store.test.ts +202 -0
- package/src/vite/store.ts +115 -0
- package/src/vite/styles.css +21 -0
- package/src/vite/tweakpane-hook.tsx +593 -0
- package/src/vite/virtual-modules.d.ts +30 -0
- package/src/vite/vite-plugin.ts +584 -0
- package/src/vite/wave-gradient-shader.tsx +253 -0
- package/README.md +0 -266
- package/dist/antigravity-auth.d.ts +0 -15
- package/dist/antigravity-auth.d.ts.map +0 -1
- package/dist/antigravity-auth.js +0 -544
- package/dist/antigravity-image.d.ts +0 -11
- package/dist/antigravity-image.d.ts.map +0 -1
- package/dist/antigravity-image.js +0 -285
- package/dist/chatgpt-auth.d.ts.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -968
- package/dist/credentials.d.ts.map +0 -1
- package/dist/gateway-model-candidates.generated.d.ts +0 -11
- package/dist/gateway-model-candidates.generated.d.ts.map +0 -1
- package/dist/gateway-model-candidates.generated.js +0 -64
- package/dist/login.d.ts.map +0 -1
- package/dist/model-catalog.d.ts +0 -42
- package/dist/model-catalog.d.ts.map +0 -1
- package/dist/model-catalog.js +0 -1001
- package/dist/models.d.ts.map +0 -1
- package/dist/models.js +0 -246
- package/dist/open-browser.d.ts.map +0 -1
- package/dist/subscription.d.ts.map +0 -1
- package/dist/video-model-catalog.d.ts +0 -52
- package/dist/video-model-catalog.d.ts.map +0 -1
- package/dist/video-model-catalog.js +0 -306
- package/src/cli.ts +0 -1378
- package/src/model-catalog.ts +0 -1077
- package/src/models.ts +0 -309
- package/src/video-model-catalog.ts +0 -363
- /package/dist/{chatgpt-auth.d.ts → cli/chatgpt-auth.d.ts} +0 -0
- /package/dist/{chatgpt-auth.js → cli/chatgpt-auth.js} +0 -0
- /package/dist/{login.d.ts → cli/login.d.ts} +0 -0
- /package/dist/{open-browser.d.ts → cli/open-browser.d.ts} +0 -0
- /package/dist/{open-browser.js → cli/open-browser.js} +0 -0
- /package/dist/{subscription.d.ts → cli/subscription.d.ts} +0 -0
- /package/dist/{subscription.js → cli/subscription.js} +0 -0
- /package/src/{chatgpt-auth.ts → cli/chatgpt-auth.ts} +0 -0
- /package/src/{open-browser.ts → cli/open-browser.ts} +0 -0
- /package/src/{subscription.ts → cli/subscription.ts} +0 -0
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import type { ImageModel, LanguageModel } from 'ai';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type
|
|
2
|
+
import { type ImageModelEntry, type VideoModelEntry, type AnyModelEntry } from './model-catalog.js';
|
|
3
|
+
export type { ImageModelEntry, VideoModelEntry, AnyModelEntry };
|
|
4
|
+
/** @deprecated Use ImageModelEntry instead */
|
|
5
|
+
export type ModelEntry = ImageModelEntry;
|
|
6
|
+
/**
|
|
7
|
+
* Validation error for user-facing input issues (wrong model, missing key, etc.).
|
|
8
|
+
* CLI prints just the message; provider/runtime errors get full stack + details.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ValidationError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
6
13
|
export declare const IMAGE_MODELS: [string, ...string[]];
|
|
7
14
|
export declare const VIDEO_MODELS: [string, ...string[]];
|
|
8
15
|
export declare const DEFAULT_MODEL = "nano-banana-pro-preview";
|
|
9
16
|
export declare const DEFAULT_VIDEO_MODEL = "veo-3.1-fast-generate-001";
|
|
10
|
-
export declare function getModelConfig(modelId: string): AnyModelEntry;
|
|
11
|
-
export declare function ensureProviderKey(providerName: string):
|
|
17
|
+
export declare function getModelConfig(modelId: string): Error | AnyModelEntry;
|
|
18
|
+
export declare function ensureProviderKey(providerName: string): Error | undefined;
|
|
12
19
|
/**
|
|
13
20
|
* ChatGPT OAuth image generation goes through the Codex backend instead of the
|
|
14
21
|
* OpenAI Image API, so OpenAI image models need the custom responses path.
|
|
15
22
|
*/
|
|
16
23
|
export declare function shouldUseResponsesApi(modelId: string): boolean;
|
|
17
|
-
export declare function createImageModel(modelId: string): Promise<ImageModel>;
|
|
18
|
-
export declare function createTextModel(modelId: string): Promise<LanguageModel>;
|
|
19
|
-
export declare function createVideoModel(modelId: string): Promise<any>;
|
|
24
|
+
export declare function createImageModel(modelId: string): Promise<Error | ImageModel>;
|
|
25
|
+
export declare function createTextModel(modelId: string): Promise<Error | LanguageModel>;
|
|
26
|
+
export declare function createVideoModel(modelId: string): Promise<Error | any>;
|
|
20
27
|
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/cli/models.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAWnD,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,CAAA;AAC/D,8CAA8C;AAC9C,MAAM,MAAM,UAAU,GAAG,eAAe,CAAA;AAExC;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,YAAY,EAA+B,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;AAC7E,eAAO,MAAM,YAAY,EAAqC,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;AAYnF,eAAO,MAAM,aAAa,4BAA4B,CAAA;AACtD,eAAO,MAAM,mBAAmB,8BAA8B,CAAA;AAE9D,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,aAAa,CAMrE;AAyHD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAsBzE;AAoCD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAI9D;AAgED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,UAAU,CAAC,CAyBnF;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,aAAa,CAAC,CA2BrF;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,GAAG,CAAC,CA6B5E"}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import pc from 'picocolors';
|
|
2
|
+
import { PROVIDERS, EGAKI_GATEWAY_URL, shouldUseChatGptBackend, shouldUseXaiOAuth, getXaiAuth, saveXaiAuth, } from './credentials.js';
|
|
3
|
+
import { getValidXaiAuth } from './xai-auth.js';
|
|
4
|
+
import { CATALOG, VIDEO_CATALOG, findModel, findVideoModel, findAnyModel, } from './model-catalog.js';
|
|
5
|
+
/**
|
|
6
|
+
* Validation error for user-facing input issues (wrong model, missing key, etc.).
|
|
7
|
+
* CLI prints just the message; provider/runtime errors get full stack + details.
|
|
8
|
+
*/
|
|
9
|
+
export class ValidationError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'ValidationError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export const IMAGE_MODELS = CATALOG.map((m) => m.id);
|
|
16
|
+
export const VIDEO_MODELS = VIDEO_CATALOG.map((m) => m.id);
|
|
17
|
+
/**
|
|
18
|
+
* Strip provider prefix from a model ID (e.g. "vertex/imagen-4.0-generate-001" → "imagen-4.0-generate-001").
|
|
19
|
+
* Provider SDKs expect bare model IDs, but the catalog uses prefixed IDs for routing.
|
|
20
|
+
*/
|
|
21
|
+
function stripProviderPrefix(modelId) {
|
|
22
|
+
const slash = modelId.indexOf('/');
|
|
23
|
+
if (slash === -1)
|
|
24
|
+
return modelId;
|
|
25
|
+
return modelId.slice(slash + 1);
|
|
26
|
+
}
|
|
27
|
+
export const DEFAULT_MODEL = 'nano-banana-pro-preview';
|
|
28
|
+
export const DEFAULT_VIDEO_MODEL = 'veo-3.1-fast-generate-001';
|
|
29
|
+
export function getModelConfig(modelId) {
|
|
30
|
+
const entry = findAnyModel(modelId);
|
|
31
|
+
if (!entry) {
|
|
32
|
+
return new ValidationError(`Unknown model: ${modelId}`);
|
|
33
|
+
}
|
|
34
|
+
return entry;
|
|
35
|
+
}
|
|
36
|
+
// Vertex is the only provider that uses a prefix (vertex/model-id) in the catalog
|
|
37
|
+
// but expects a bare model ID in its SDK. Replicate and fal use slashes as part
|
|
38
|
+
// of the actual model name (e.g. fal-ai/flux/schnell, black-forest-labs/flux-1.1-pro).
|
|
39
|
+
// stripProviderPrefix is called inside the Vertex lambdas only.
|
|
40
|
+
const PROVIDER_SDKS = {
|
|
41
|
+
google: {
|
|
42
|
+
image: async (id) => (await import('@ai-sdk/google')).google.image(id),
|
|
43
|
+
text: async (id) => (await import('@ai-sdk/google')).google(id),
|
|
44
|
+
video: async (id) => (await import('@ai-sdk/google')).google.video(id),
|
|
45
|
+
},
|
|
46
|
+
vertex: {
|
|
47
|
+
image: async (id) => (await import('@ai-sdk/google-vertex')).vertex.image(stripProviderPrefix(id)),
|
|
48
|
+
text: async (id) => (await import('@ai-sdk/google-vertex')).vertex(stripProviderPrefix(id)),
|
|
49
|
+
video: async (id) => (await import('@ai-sdk/google-vertex')).vertex.video(stripProviderPrefix(id)),
|
|
50
|
+
},
|
|
51
|
+
openai: {
|
|
52
|
+
image: async (id) => (await import('@ai-sdk/openai')).openai.image(id),
|
|
53
|
+
},
|
|
54
|
+
replicate: {
|
|
55
|
+
image: async (id) => (await import('@ai-sdk/replicate')).replicate.image(id),
|
|
56
|
+
},
|
|
57
|
+
fal: {
|
|
58
|
+
image: async (id) => (await import('@ai-sdk/fal')).fal.image(id),
|
|
59
|
+
video: async (id) => (await import('@ai-sdk/fal')).fal.video(id),
|
|
60
|
+
},
|
|
61
|
+
xai: {
|
|
62
|
+
image: async (id) => {
|
|
63
|
+
const xaiProvider = await getXaiProviderInstance();
|
|
64
|
+
if (xaiProvider instanceof Error)
|
|
65
|
+
return xaiProvider;
|
|
66
|
+
return xaiProvider.image(id);
|
|
67
|
+
},
|
|
68
|
+
video: async (id) => {
|
|
69
|
+
const xaiProvider = await getXaiProviderInstance();
|
|
70
|
+
if (xaiProvider instanceof Error)
|
|
71
|
+
return xaiProvider;
|
|
72
|
+
return xaiProvider.video(id);
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
// Providers routed exclusively through the egaki gateway (no direct SDK).
|
|
76
|
+
// They only need catalog entries and gateway routing, no local SDK factory.
|
|
77
|
+
// bfl, recraft, klingai, alibaba — all handled by the gateway fallback.
|
|
78
|
+
};
|
|
79
|
+
// ─── xAI provider instance ───────────────────────────────────────────────────
|
|
80
|
+
// Creates an @ai-sdk/xai provider instance with either a direct API key or
|
|
81
|
+
// OAuth tokens from the Grok Build subscription. OAuth tokens are injected via
|
|
82
|
+
// a custom fetch that replaces the Authorization header on every request.
|
|
83
|
+
async function getXaiProviderInstance() {
|
|
84
|
+
const { createXai } = await import('@ai-sdk/xai');
|
|
85
|
+
// Direct API key path (env or stored)
|
|
86
|
+
if (!shouldUseXaiOAuth()) {
|
|
87
|
+
return createXai({
|
|
88
|
+
apiKey: process.env['XAI_API_KEY'],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// OAuth path: inject bearer token via custom fetch
|
|
92
|
+
const storedAuth = getXaiAuth();
|
|
93
|
+
if (!storedAuth) {
|
|
94
|
+
return new ValidationError('Missing xAI OAuth tokens. Please run `egaki login` and select xAI Grok Build.');
|
|
95
|
+
}
|
|
96
|
+
const auth = await getValidXaiAuth(storedAuth, saveXaiAuth);
|
|
97
|
+
if (auth instanceof Error) {
|
|
98
|
+
return auth;
|
|
99
|
+
}
|
|
100
|
+
return createXai({
|
|
101
|
+
// Dummy key to satisfy the SDK's apiKey requirement; the custom fetch
|
|
102
|
+
// overrides the Authorization header with the real OAuth token.
|
|
103
|
+
apiKey: 'xai-oauth-placeholder',
|
|
104
|
+
fetch: async (input, init) => {
|
|
105
|
+
const headers = new Headers(input instanceof Request ? input.headers : undefined);
|
|
106
|
+
if (init?.headers) {
|
|
107
|
+
const initHeaders = new Headers(init.headers);
|
|
108
|
+
initHeaders.forEach((value, key) => headers.set(key, value));
|
|
109
|
+
}
|
|
110
|
+
headers.set('authorization', `Bearer ${auth.access}`);
|
|
111
|
+
return fetch(input, { ...init, headers });
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// ─── key checking ────────────────────────────────────────────────────────────
|
|
116
|
+
function hasEgakiKey() {
|
|
117
|
+
const info = PROVIDERS['egaki'];
|
|
118
|
+
if (!info)
|
|
119
|
+
return false;
|
|
120
|
+
return Boolean(process.env[info.envVar]);
|
|
121
|
+
}
|
|
122
|
+
function hasDirectProviderKey(providerName) {
|
|
123
|
+
const info = PROVIDERS[providerName];
|
|
124
|
+
if (!info)
|
|
125
|
+
return false;
|
|
126
|
+
if (Boolean(process.env[info.envVar]))
|
|
127
|
+
return true;
|
|
128
|
+
// xAI OAuth counts as having a direct provider key since we use @ai-sdk/xai directly
|
|
129
|
+
if (providerName === 'xai' && shouldUseXaiOAuth())
|
|
130
|
+
return true;
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
// Check that the provider's API key or OAuth login is available before making API calls.
|
|
134
|
+
// Returns an Error with a user-friendly message if no key is found.
|
|
135
|
+
export function ensureProviderKey(providerName) {
|
|
136
|
+
if (hasDirectProviderKey(providerName))
|
|
137
|
+
return undefined;
|
|
138
|
+
// Vertex models require a direct key — the upstream Vercel AI Gateway
|
|
139
|
+
// does not support vertex/ routing, so egaki gateway can't proxy them.
|
|
140
|
+
if (providerName === 'vertex') {
|
|
141
|
+
return new ValidationError('Vertex models require a direct Google Cloud API key. ' +
|
|
142
|
+
'Run: egaki login --provider vertex --key <key>. ' +
|
|
143
|
+
'Get a key at https://console.cloud.google.com/apis/credentials');
|
|
144
|
+
}
|
|
145
|
+
if (hasEgakiKey())
|
|
146
|
+
return undefined;
|
|
147
|
+
const info = PROVIDERS[providerName];
|
|
148
|
+
const label = info?.label || providerName;
|
|
149
|
+
return new ValidationError(`Missing API key for ${label}. ` +
|
|
150
|
+
'Use an Egaki subscription (egaki subscribe) or configure a provider key directly (egaki login).' +
|
|
151
|
+
(info ? ` ${info.hint}` : ''));
|
|
152
|
+
}
|
|
153
|
+
// ─── gateway model factories ─────────────────────────────────────────────────
|
|
154
|
+
async function createGatewayImageModel(modelId, provider) {
|
|
155
|
+
const { createGateway } = await import('ai');
|
|
156
|
+
const gateway = createGateway({
|
|
157
|
+
apiKey: process.env['EGAKI_API_KEY'],
|
|
158
|
+
baseURL: EGAKI_GATEWAY_URL,
|
|
159
|
+
});
|
|
160
|
+
const bareId = stripProviderPrefix(modelId);
|
|
161
|
+
return gateway.image(`${provider}/${bareId}`);
|
|
162
|
+
}
|
|
163
|
+
async function createGatewayTextModel(modelId, provider) {
|
|
164
|
+
const { createGateway } = await import('ai');
|
|
165
|
+
const gateway = createGateway({
|
|
166
|
+
apiKey: process.env['EGAKI_API_KEY'],
|
|
167
|
+
baseURL: EGAKI_GATEWAY_URL,
|
|
168
|
+
});
|
|
169
|
+
const bareId = stripProviderPrefix(modelId);
|
|
170
|
+
return gateway(`${provider}/${bareId}`);
|
|
171
|
+
}
|
|
172
|
+
async function createGatewayVideoModel(modelId, provider) {
|
|
173
|
+
const { createGateway } = await import('ai');
|
|
174
|
+
const gateway = createGateway({
|
|
175
|
+
apiKey: process.env['EGAKI_API_KEY'],
|
|
176
|
+
baseURL: EGAKI_GATEWAY_URL,
|
|
177
|
+
});
|
|
178
|
+
const bareId = stripProviderPrefix(modelId);
|
|
179
|
+
return gateway.video(`${provider}/${bareId}`);
|
|
180
|
+
}
|
|
181
|
+
// ─── ChatGPT OAuth routing ───────────────────────────────────────────────────
|
|
182
|
+
/**
|
|
183
|
+
* ChatGPT OAuth image generation goes through the Codex backend instead of the
|
|
184
|
+
* OpenAI Image API, so OpenAI image models need the custom responses path.
|
|
185
|
+
*/
|
|
186
|
+
export function shouldUseResponsesApi(modelId) {
|
|
187
|
+
const config = findModel(modelId);
|
|
188
|
+
if (!config)
|
|
189
|
+
return false;
|
|
190
|
+
return config.provider === 'openai' && config.strategy === 'image' && shouldUseChatGptBackend();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Determine which auth source will be used for a given provider.
|
|
194
|
+
* Returns the auth type for logging. Does NOT check if the key is valid.
|
|
195
|
+
*/
|
|
196
|
+
function resolveAuthSource(providerName) {
|
|
197
|
+
const info = PROVIDERS[providerName];
|
|
198
|
+
// xAI has special OAuth handling
|
|
199
|
+
if (providerName === 'xai') {
|
|
200
|
+
if (process.env['XAI_API_KEY'] && !shouldUseXaiOAuth()) {
|
|
201
|
+
return { type: 'api-key', label: 'XAI_API_KEY' };
|
|
202
|
+
}
|
|
203
|
+
if (shouldUseXaiOAuth()) {
|
|
204
|
+
return { type: 'oauth', label: 'xAI Grok Build OAuth' };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// ChatGPT OAuth
|
|
208
|
+
if (providerName === 'openai' && shouldUseChatGptBackend()) {
|
|
209
|
+
return { type: 'oauth', label: 'ChatGPT OAuth' };
|
|
210
|
+
}
|
|
211
|
+
// Direct provider env var
|
|
212
|
+
if (info && process.env[info.envVar]) {
|
|
213
|
+
return { type: 'api-key', label: info.envVar };
|
|
214
|
+
}
|
|
215
|
+
// Egaki gateway
|
|
216
|
+
if (hasEgakiKey()) {
|
|
217
|
+
return { type: 'egaki-gateway' };
|
|
218
|
+
}
|
|
219
|
+
// Should not reach here if ensureProviderKey passed
|
|
220
|
+
return { type: 'api-key', label: 'unknown' };
|
|
221
|
+
}
|
|
222
|
+
function logAuthSource(source) {
|
|
223
|
+
switch (source.type) {
|
|
224
|
+
case 'api-key':
|
|
225
|
+
console.error(pc.dim(`Auth: ${source.label}`));
|
|
226
|
+
break;
|
|
227
|
+
case 'oauth':
|
|
228
|
+
console.error(pc.dim(`Auth: ${source.label}`));
|
|
229
|
+
break;
|
|
230
|
+
case 'egaki-gateway':
|
|
231
|
+
console.error(pc.dim('Auth: Egaki subscription (gateway)'));
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// ─── public model factories ──────────────────────────────────────────────────
|
|
236
|
+
// Priority for xAI: explicit XAI_API_KEY > xai-oauth tokens > egaki gateway > error.
|
|
237
|
+
// Priority for others: direct provider key > egaki gateway > error.
|
|
238
|
+
// Uses PROVIDER_SDKS map for direct provider creation, eliminating switch blocks.
|
|
239
|
+
export async function createImageModel(modelId) {
|
|
240
|
+
const config = getModelConfig(modelId);
|
|
241
|
+
if (config instanceof Error)
|
|
242
|
+
return config;
|
|
243
|
+
const keyError = ensureProviderKey(config.provider);
|
|
244
|
+
if (keyError)
|
|
245
|
+
return keyError;
|
|
246
|
+
const authSource = resolveAuthSource(config.provider);
|
|
247
|
+
logAuthSource(authSource);
|
|
248
|
+
if (hasDirectProviderKey(config.provider)) {
|
|
249
|
+
const factory = PROVIDER_SDKS[config.provider]?.image;
|
|
250
|
+
if (factory) {
|
|
251
|
+
const result = await factory(modelId);
|
|
252
|
+
if (result instanceof Error)
|
|
253
|
+
return result;
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
return new ValidationError(`Direct image generation is not supported for provider: ${config.provider}.`);
|
|
257
|
+
}
|
|
258
|
+
if (hasEgakiKey()) {
|
|
259
|
+
return createGatewayImageModel(modelId, config.provider);
|
|
260
|
+
}
|
|
261
|
+
return new ValidationError(`No API key available for provider: ${config.provider}`);
|
|
262
|
+
}
|
|
263
|
+
export async function createTextModel(modelId) {
|
|
264
|
+
const config = getModelConfig(modelId);
|
|
265
|
+
if (config instanceof Error)
|
|
266
|
+
return config;
|
|
267
|
+
if (config.strategy !== 'text') {
|
|
268
|
+
return new ValidationError(`Model ${modelId} is not a text model`);
|
|
269
|
+
}
|
|
270
|
+
const keyError = ensureProviderKey(config.provider);
|
|
271
|
+
if (keyError)
|
|
272
|
+
return keyError;
|
|
273
|
+
const authSource = resolveAuthSource(config.provider);
|
|
274
|
+
logAuthSource(authSource);
|
|
275
|
+
if (hasDirectProviderKey(config.provider)) {
|
|
276
|
+
const factory = PROVIDER_SDKS[config.provider]?.text;
|
|
277
|
+
if (factory) {
|
|
278
|
+
return factory(modelId);
|
|
279
|
+
}
|
|
280
|
+
return new ValidationError(`Text+image generation is not supported for provider: ${config.provider}`);
|
|
281
|
+
}
|
|
282
|
+
if (hasEgakiKey()) {
|
|
283
|
+
return createGatewayTextModel(modelId, config.provider);
|
|
284
|
+
}
|
|
285
|
+
return new ValidationError(`No API key available for provider: ${config.provider}`);
|
|
286
|
+
}
|
|
287
|
+
export async function createVideoModel(modelId) {
|
|
288
|
+
const config = getModelConfig(modelId);
|
|
289
|
+
if (config instanceof Error)
|
|
290
|
+
return config;
|
|
291
|
+
if (config.strategy !== 'video') {
|
|
292
|
+
return new ValidationError(`Model ${modelId} is not a video model`);
|
|
293
|
+
}
|
|
294
|
+
const keyError = ensureProviderKey(config.provider);
|
|
295
|
+
if (keyError)
|
|
296
|
+
return keyError;
|
|
297
|
+
const authSource = resolveAuthSource(config.provider);
|
|
298
|
+
logAuthSource(authSource);
|
|
299
|
+
if (hasDirectProviderKey(config.provider)) {
|
|
300
|
+
const factory = PROVIDER_SDKS[config.provider]?.video;
|
|
301
|
+
if (factory) {
|
|
302
|
+
const result = await factory(modelId);
|
|
303
|
+
if (result instanceof Error)
|
|
304
|
+
return result;
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
return new ValidationError(`Direct video generation is not supported for provider: ${config.provider}. Use an egaki subscription instead.`);
|
|
308
|
+
}
|
|
309
|
+
if (hasEgakiKey()) {
|
|
310
|
+
return createGatewayVideoModel(modelId, config.provider);
|
|
311
|
+
}
|
|
312
|
+
return new ValidationError(`No API key available for provider: ${config.provider}`);
|
|
313
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-browser.d.ts","sourceRoot":"","sources":["../../src/cli/open-browser.ts"],"names":[],"mappings":"AAyBA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAsBrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-speech-provider.d.ts","sourceRoot":"","sources":["../../src/cli/openai-speech-provider.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAA+C,MAAM,sBAAsB,CAAA;AAEvG,wBAAgB,0BAA0B,IAAI,cAAc,CAyB3D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// OpenAI speech provider for egaki.
|
|
2
|
+
// Wraps the Vercel AI SDK @ai-sdk/openai since OpenAI TTS has no
|
|
3
|
+
// timestamp support. Returns audio only, timestamps are always undefined.
|
|
4
|
+
import { experimental_generateSpeech as aiGenerateSpeech, } from 'ai';
|
|
5
|
+
export function createOpenAISpeechProvider() {
|
|
6
|
+
return {
|
|
7
|
+
async generate(options) {
|
|
8
|
+
const { openai } = await import('@ai-sdk/openai');
|
|
9
|
+
const model = openai.speech(options.modelId);
|
|
10
|
+
const result = await aiGenerateSpeech({
|
|
11
|
+
model,
|
|
12
|
+
text: options.text,
|
|
13
|
+
...(options.voice ? { voice: options.voice } : {}),
|
|
14
|
+
...(options.outputFormat ? { outputFormat: options.outputFormat } : {}),
|
|
15
|
+
...(options.instructions ? { instructions: options.instructions } : {}),
|
|
16
|
+
...(options.speed != null ? { speed: options.speed } : {}),
|
|
17
|
+
...(options.language ? { language: options.language } : {}),
|
|
18
|
+
...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
audio: result.audio.uint8Array,
|
|
22
|
+
mediaType: result.audio.mediaType || 'audio/mpeg',
|
|
23
|
+
// OpenAI TTS does not support word timestamps
|
|
24
|
+
timestamps: undefined,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type StemName = 'vocals' | 'drums' | 'bass' | 'other' | 'guitar' | 'piano';
|
|
2
|
+
export type DemucsModel = 'htdemucs' | 'htdemucs_ft' | 'htdemucs_6s' | 'hdemucs_mmi' | 'mdx' | 'mdx_extra' | 'mdx_q' | 'mdx_extra_q';
|
|
3
|
+
export interface SeparateAudioOptions {
|
|
4
|
+
/** Raw audio bytes to separate. */
|
|
5
|
+
audio: Uint8Array;
|
|
6
|
+
/** Which stems to extract. Default: ['vocals', 'other'] */
|
|
7
|
+
stems?: StemName[];
|
|
8
|
+
/** Demucs model variant. Default: 'htdemucs_6s' */
|
|
9
|
+
model?: DemucsModel;
|
|
10
|
+
/** Output format: 'mp3' or 'wav'. Default: 'mp3' */
|
|
11
|
+
outputFormat?: 'mp3' | 'wav';
|
|
12
|
+
/** Number of random shifts for quality (higher = better but slower). Default: 1 */
|
|
13
|
+
shifts?: number;
|
|
14
|
+
/** Segment overlap 0.0-1.0 (higher = better quality). Default: 0.25 */
|
|
15
|
+
overlap?: number;
|
|
16
|
+
/** Original filename for display/logging. */
|
|
17
|
+
filename?: string;
|
|
18
|
+
/** Progress callback for queue updates. */
|
|
19
|
+
onProgress?: (message: string) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface StemResult {
|
|
22
|
+
name: StemName;
|
|
23
|
+
url: string;
|
|
24
|
+
contentType: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SeparateAudioResult {
|
|
27
|
+
stems: StemResult[];
|
|
28
|
+
model: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function validateStems(stems: StemName[], model: DemucsModel): Error | void;
|
|
31
|
+
export declare function separateAudioUncached(opts: SeparateAudioOptions): Promise<Error | SeparateAudioResult>;
|
|
32
|
+
/** Download a stem from its URL and return the bytes. */
|
|
33
|
+
export declare function downloadStem(url: string): Promise<Error | Uint8Array>;
|
|
34
|
+
//# sourceMappingURL=separation-generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"separation-generate.d.ts","sourceRoot":"","sources":["../../src/cli/separation-generate.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEjF,MAAM,MAAM,WAAW,GACnB,UAAU,GACV,aAAa,GACb,aAAa,GACb,aAAa,GACb,KAAK,GACL,WAAW,GACX,OAAO,GACP,aAAa,CAAA;AAEjB,MAAM,WAAW,oBAAoB;IACnC,mCAAmC;IACnC,KAAK,EAAE,UAAU,CAAA;IACjB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAA;IAClB,mDAAmD;IACnD,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,oDAAoD;IACpD,YAAY,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IAC5B,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACvC;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,QAAQ,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;CACd;AAQD,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,WAAW,GAAG,KAAK,GAAG,IAAI,CAejF;AAID,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,oBAAoB,GACzB,OAAO,CAAC,KAAK,GAAG,mBAAmB,CAAC,CA0FtC;AAID,yDAAyD;AACzD,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,UAAU,CAAC,CAU3E"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Audio separation using fal.ai's Demucs API.
|
|
2
|
+
// Splits audio into stems (vocals, drums, bass, guitar, piano, other).
|
|
3
|
+
// Returns Error | Result (errore style) instead of throwing.
|
|
4
|
+
//
|
|
5
|
+
// Uses @fal-ai/client directly since Demucs is a fal-specific API
|
|
6
|
+
// with no Vercel AI SDK wrapper. Requires FAL_KEY env var or
|
|
7
|
+
// egaki login --provider fal.
|
|
8
|
+
import { fal } from '@fal-ai/client';
|
|
9
|
+
import { injectCredentialsToEnv } from './credentials.js';
|
|
10
|
+
// ─── validation ─────────────────────────────────────────────────────────────
|
|
11
|
+
const ALL_STEMS = ['vocals', 'drums', 'bass', 'other', 'guitar', 'piano'];
|
|
12
|
+
const FOUR_STEM_MODELS = ['htdemucs', 'htdemucs_ft', 'hdemucs_mmi', 'mdx', 'mdx_extra', 'mdx_q', 'mdx_extra_q'];
|
|
13
|
+
const SIX_STEM_ONLY = ['guitar', 'piano'];
|
|
14
|
+
export function validateStems(stems, model) {
|
|
15
|
+
for (const s of stems) {
|
|
16
|
+
if (!ALL_STEMS.includes(s)) {
|
|
17
|
+
return new Error(`Unknown stem: "${s}". Valid stems: ${ALL_STEMS.join(', ')}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (FOUR_STEM_MODELS.includes(model)) {
|
|
21
|
+
const invalid = stems.filter((s) => SIX_STEM_ONLY.includes(s));
|
|
22
|
+
if (invalid.length > 0) {
|
|
23
|
+
return new Error(`Stems ${invalid.join(', ')} are only available with htdemucs_6s model. ` +
|
|
24
|
+
`Current model: ${model}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// ─── main function ──────────────────────────────────────────────────────────
|
|
29
|
+
export async function separateAudioUncached(opts) {
|
|
30
|
+
injectCredentialsToEnv();
|
|
31
|
+
const falKey = process.env['FAL_KEY'];
|
|
32
|
+
if (!falKey) {
|
|
33
|
+
return new Error('FAL_KEY not found. Run: egaki login --provider fal\n' +
|
|
34
|
+
'Get your key at https://fal.ai/dashboard/keys');
|
|
35
|
+
}
|
|
36
|
+
fal.config({ credentials: falKey });
|
|
37
|
+
const model = opts.model ?? 'htdemucs_6s';
|
|
38
|
+
const stems = opts.stems ?? ['vocals', 'other'];
|
|
39
|
+
const outputFormat = opts.outputFormat ?? 'mp3';
|
|
40
|
+
const validationError = validateStems(stems, model);
|
|
41
|
+
if (validationError)
|
|
42
|
+
return validationError;
|
|
43
|
+
if (opts.audio.length === 0) {
|
|
44
|
+
return new Error('No audio data provided');
|
|
45
|
+
}
|
|
46
|
+
// Upload the audio file to fal storage so the API can access it
|
|
47
|
+
const file = new File([Buffer.from(opts.audio)], opts.filename ?? 'audio.mp3', { type: 'audio/mpeg' });
|
|
48
|
+
opts.onProgress?.('Uploading audio to fal.ai...');
|
|
49
|
+
let audioUrl;
|
|
50
|
+
try {
|
|
51
|
+
audioUrl = await fal.storage.upload(file);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
return new Error(`Failed to upload audio: ${err instanceof Error ? err.message : String(err)}`);
|
|
55
|
+
}
|
|
56
|
+
opts.onProgress?.('Audio uploaded. Starting separation...');
|
|
57
|
+
let result;
|
|
58
|
+
try {
|
|
59
|
+
result = await fal.subscribe('fal-ai/demucs', {
|
|
60
|
+
input: {
|
|
61
|
+
audio_url: audioUrl,
|
|
62
|
+
model,
|
|
63
|
+
stems,
|
|
64
|
+
shifts: opts.shifts ?? 1,
|
|
65
|
+
overlap: opts.overlap ?? 0.25,
|
|
66
|
+
output_format: outputFormat,
|
|
67
|
+
},
|
|
68
|
+
logs: true,
|
|
69
|
+
onQueueUpdate: (update) => {
|
|
70
|
+
if (update.status === 'IN_PROGRESS') {
|
|
71
|
+
const u = update;
|
|
72
|
+
if (u.logs) {
|
|
73
|
+
for (const log of u.logs) {
|
|
74
|
+
opts.onProgress?.(log.message);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
return new Error(`Separation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
83
|
+
}
|
|
84
|
+
// Extract the requested stems from the result
|
|
85
|
+
const resultStems = [];
|
|
86
|
+
for (const stemName of stems) {
|
|
87
|
+
const stemData = result.data[stemName];
|
|
88
|
+
if (stemData?.url) {
|
|
89
|
+
resultStems.push({
|
|
90
|
+
name: stemName,
|
|
91
|
+
url: stemData.url,
|
|
92
|
+
contentType: stemData.content_type ?? `audio/${outputFormat}`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (resultStems.length === 0) {
|
|
97
|
+
return new Error('No stems returned from the API. Check model and stem names.');
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
stems: resultStems,
|
|
101
|
+
model,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// ─── download helper ────────────────────────────────────────────────────────
|
|
105
|
+
/** Download a stem from its URL and return the bytes. */
|
|
106
|
+
export async function downloadStem(url) {
|
|
107
|
+
try {
|
|
108
|
+
const response = await fetch(url);
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
return new Error(`Failed to download stem: HTTP ${response.status}`);
|
|
111
|
+
}
|
|
112
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
return new Error(`Failed to download stem: ${err instanceof Error ? err.message : String(err)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ProviderOption } from './model-catalog.js';
|
|
2
|
+
export type PerCharacterCost = {
|
|
3
|
+
type: 'per-character';
|
|
4
|
+
/** USD per 1 million characters */
|
|
5
|
+
perMillionChars: number;
|
|
6
|
+
};
|
|
7
|
+
export type SpeechModelCost = PerCharacterCost;
|
|
8
|
+
export type SpeechModelFeatures = {
|
|
9
|
+
/** Supported output audio formats */
|
|
10
|
+
outputFormats: string[];
|
|
11
|
+
/** Whether the model supports voice instructions / style prompts */
|
|
12
|
+
instructions: boolean;
|
|
13
|
+
/** Whether speed control is supported */
|
|
14
|
+
speed: boolean;
|
|
15
|
+
/** Whether language selection is supported */
|
|
16
|
+
language: boolean;
|
|
17
|
+
/** Max input characters per request (0 = unknown/unlimited) */
|
|
18
|
+
maxChars: number;
|
|
19
|
+
/** Built-in voice names (not exhaustive for providers with voice libraries) */
|
|
20
|
+
defaultVoices: string[];
|
|
21
|
+
};
|
|
22
|
+
export type SpeechModelEntry = {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
provider: string;
|
|
27
|
+
strategy: 'speech';
|
|
28
|
+
released: string;
|
|
29
|
+
cost: SpeechModelCost;
|
|
30
|
+
features: SpeechModelFeatures;
|
|
31
|
+
providerOptions?: ProviderOption[];
|
|
32
|
+
};
|
|
33
|
+
export declare const SPEECH_CATALOG: SpeechModelEntry[];
|
|
34
|
+
export declare function findSpeechModel(modelId: string): SpeechModelEntry | undefined;
|
|
35
|
+
//# sourceMappingURL=speech-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speech-catalog.d.ts","sourceRoot":"","sources":["../../src/cli/speech-catalog.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAIxD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,eAAe,CAAA;IACrB,mCAAmC;IACnC,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAAA;AAI9C,MAAM,MAAM,mBAAmB,GAAG;IAChC,qCAAqC;IACrC,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,oEAAoE;IACpE,YAAY,EAAE,OAAO,CAAA;IACrB,yCAAyC;IACzC,KAAK,EAAE,OAAO,CAAA;IACd,8CAA8C;IAC9C,QAAQ,EAAE,OAAO,CAAA;IACjB,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAA;IAChB,+EAA+E;IAC/E,aAAa,EAAE,MAAM,EAAE,CAAA;CACxB,CAAA;AAID,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,eAAe,CAAA;IACrB,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,eAAe,CAAC,EAAE,cAAc,EAAE,CAAA;CACnC,CAAA;AAqBD,eAAO,MAAM,cAAc,EAAE,gBAAgB,EA8K5C,CAAA;AAID,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAE7E"}
|