@brotu/ai 0.1.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 (53) hide show
  1. package/CATALOG.md +387 -0
  2. package/LICENSE +21 -0
  3. package/README.md +115 -0
  4. package/dist/adapters/byteplus.adapter.d.ts +51 -0
  5. package/dist/adapters/byteplus.adapter.d.ts.map +1 -0
  6. package/dist/adapters/elevenlabs.adapter.d.ts +48 -0
  7. package/dist/adapters/elevenlabs.adapter.d.ts.map +1 -0
  8. package/dist/adapters/estimate.d.ts +10 -0
  9. package/dist/adapters/estimate.d.ts.map +1 -0
  10. package/dist/adapters/google.adapter.d.ts +52 -0
  11. package/dist/adapters/google.adapter.d.ts.map +1 -0
  12. package/dist/adapters/kling.adapter.d.ts +57 -0
  13. package/dist/adapters/kling.adapter.d.ts.map +1 -0
  14. package/dist/adapters/openai.adapter.d.ts +40 -0
  15. package/dist/adapters/openai.adapter.d.ts.map +1 -0
  16. package/dist/adapters/qwen.adapter.d.ts +53 -0
  17. package/dist/adapters/qwen.adapter.d.ts.map +1 -0
  18. package/dist/catalog.cjs +988 -0
  19. package/dist/catalog.d.ts +27 -0
  20. package/dist/catalog.d.ts.map +1 -0
  21. package/dist/catalog.js +20 -0
  22. package/dist/chunk-GKLTQ55S.js +1176 -0
  23. package/dist/client.d.ts +86 -0
  24. package/dist/client.d.ts.map +1 -0
  25. package/dist/constants/model.types.d.ts +118 -0
  26. package/dist/constants/model.types.d.ts.map +1 -0
  27. package/dist/helpers/result.d.ts +54 -0
  28. package/dist/helpers/result.d.ts.map +1 -0
  29. package/dist/index.cjs +3568 -0
  30. package/dist/index.d.ts +29 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +2386 -0
  33. package/dist/lib/jobs.d.ts +46 -0
  34. package/dist/lib/jobs.d.ts.map +1 -0
  35. package/dist/lib/storage.d.ts +33 -0
  36. package/dist/lib/storage.d.ts.map +1 -0
  37. package/dist/ports/content-generator.port.d.ts +170 -0
  38. package/dist/ports/content-generator.port.d.ts.map +1 -0
  39. package/dist/providers/byteplus.models.d.ts +51 -0
  40. package/dist/providers/byteplus.models.d.ts.map +1 -0
  41. package/dist/providers/elevenlabs.models.d.ts +27 -0
  42. package/dist/providers/elevenlabs.models.d.ts.map +1 -0
  43. package/dist/providers/google.models.d.ts +42 -0
  44. package/dist/providers/google.models.d.ts.map +1 -0
  45. package/dist/providers/kling.models.d.ts +159 -0
  46. package/dist/providers/kling.models.d.ts.map +1 -0
  47. package/dist/providers/openai.models.d.ts +27 -0
  48. package/dist/providers/openai.models.d.ts.map +1 -0
  49. package/dist/providers/qwen.models.d.ts +88 -0
  50. package/dist/providers/qwen.models.d.ts.map +1 -0
  51. package/dist/types.d.ts +55 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/package.json +72 -0
@@ -0,0 +1,86 @@
1
+ import { getModel } from "./catalog";
2
+ import type { AIModelConfig } from "./constants/model.types";
3
+ import { type AIError, type Generation, type Result } from "./helpers/result";
4
+ import { type Job, type JobSnapshot } from "./lib/jobs";
5
+ import type { AudioGenerationParams, CostEstimate, GenerationOutput, GenerationParams, GenerationType, ImageGenerationParams, TextGenerationParams, VideoGenerationParams } from "./ports/content-generator.port";
6
+ import { type AvatarInput, type ImageOmniInput, type MotionControlInput, type OmniVideoInput, type OutpaintingInput } from "./providers/kling.models";
7
+ import type { BrotuAIOptions } from "./types";
8
+ /** Providers this package ships an adapter for. */
9
+ export declare const NATIVE_PROVIDERS: readonly ["byteplus", "elevenlabs", "google", "kling", "openai", "qwen"];
10
+ export interface BrotuAI {
11
+ image: {
12
+ /** Queue the work and return a handle. Only the submit is awaited. */
13
+ submit(params: ImageGenerationParams): Promise<Result<Job>>;
14
+ /** submit + wait. Convenient, but holds the call open for the whole run. */
15
+ generate(params: ImageGenerationParams): Promise<Result<Generation>>;
16
+ };
17
+ video: {
18
+ submit(params: VideoGenerationParams): Promise<Result<Job>>;
19
+ generate(params: VideoGenerationParams): Promise<Result<Generation>>;
20
+ };
21
+ text: {
22
+ submit(params: TextGenerationParams): Promise<Result<Job>>;
23
+ generate(params: TextGenerationParams): Promise<Result<Generation>>;
24
+ };
25
+ /** Speech synthesis. `prompt` is the text to speak. */
26
+ audio: {
27
+ submit(params: AudioGenerationParams): Promise<Result<Job>>;
28
+ generate(params: AudioGenerationParams): Promise<Result<Generation>>;
29
+ };
30
+ jobs: {
31
+ /** Ask once. Returns straight away, settled or not. */
32
+ poll(job: Job): Promise<Result<JobSnapshot>>;
33
+ /** Poll until the job settles or `timeoutMs` passes. */
34
+ wait(job: Job, options?: {
35
+ timeoutMs?: number;
36
+ }): Promise<Result<Generation>>;
37
+ };
38
+ /**
39
+ * Google capabilities with no portable equivalent. Present only when a google
40
+ * key is configured.
41
+ */
42
+ google?: {
43
+ /**
44
+ * Generate a video, then keep refining it by talking to the result. Pass
45
+ * the returned `interactionId` back as `previousInteractionId` and the
46
+ * model edits what it made instead of starting over — nothing else in the
47
+ * catalog works this way.
48
+ */
49
+ omniVideo(input: VideoGenerationParams & {
50
+ previousInteractionId?: string;
51
+ }): Promise<Result<{
52
+ interactionId?: string;
53
+ outputs: GenerationOutput[];
54
+ }>>;
55
+ };
56
+ /**
57
+ * Kling capabilities with no portable equivalent. They sit under the provider
58
+ * name because motion transfer and canvas expansion are not things another
59
+ * vendor implements the same way, and a shared signature would be a lie.
60
+ * Present only when a kling key is configured.
61
+ */
62
+ kling?: {
63
+ /** Put your character into another video's movement. */
64
+ motionControl(input: MotionControlInput): Promise<Result<Job>>;
65
+ /** The multimodal superset: frames, references, reference video, elements. */
66
+ omniVideo(input: OmniVideoInput): Promise<Result<Job>>;
67
+ /** A portrait plus an audio track becomes a talking head. */
68
+ avatar(input: AvatarInput): Promise<Result<Job>>;
69
+ /** Extend an image's canvas in any direction. */
70
+ outpainting(input: OutpaintingInput): Promise<Result<Job>>;
71
+ /** Compose or edit across up to ten references. */
72
+ imageOmni(input: ImageOmniInput): Promise<Result<Job>>;
73
+ };
74
+ /** Models runnable with the keys given to this client. */
75
+ models(): AIModelConfig[];
76
+ /**
77
+ * What this generation will be billed for, before running it. Always reports
78
+ * the billable units; reports USD only where the catalog carries a verified
79
+ * rate, and `usd: null` otherwise.
80
+ */
81
+ estimateCost(type: GenerationType, params: GenerationParams): Promise<Result<CostEstimate>>;
82
+ }
83
+ export declare function brotuClient(options: BrotuAIOptions): BrotuAI;
84
+ export type { AIError, Generation, Result };
85
+ export { getModel };
86
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAEN,QAAQ,EAGR,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACN,KAAK,OAAO,EAGZ,KAAK,UAAU,EAEf,KAAK,MAAM,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEN,KAAK,GAAG,EACR,KAAK,WAAW,EAEhB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACX,qBAAqB,EAErB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAEhB,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,cAAc,EAEnB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,mDAAmD;AACnD,eAAO,MAAM,gBAAgB,YAC5B,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,MAAM,CACG,CAAC;AAOX,MAAM,WAAW,OAAO;IACvB,KAAK,EAAE;QACN,sEAAsE;QACtE,MAAM,CAAC,MAAM,EAAE,qBAAq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GAAG;YAAE,qBAAqB,CAAC,EAAE,MAAM,CAAA;SAAE,GAC/D,OAAO,CAAC,MAAM,CAAC;YAAE,aAAa,CAAC,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,gBAAgB,EAAE,CAAA;SAAE,CAAC,CAAC,CAAC;KAC5E,CAAC;IACF;;;;;OAKG;IACH,KAAK,CAAC,EAAE;QACP,wDAAwD;QACxD,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/D,8EAA8E;QAC9E,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACvD,6DAA6D;QAC7D,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACjD,iDAAiD;QACjD,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3D,mDAAmD;QACnD,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;KACvD,CAAC;IACF,0DAA0D;IAC1D,MAAM,IAAI,aAAa,EAAE,CAAC;IAC1B;;;;OAIG;IACH,YAAY,CACX,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,gBAAgB,GACtB,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;CACjC;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAqX5D;AAED,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,118 @@
1
+ /** What a provider counts when it bills. */
2
+ export type BillingUnit = "second" | "image" | "request"
3
+ /** Text-to-speech, billed on the input text. */
4
+ | "character"
5
+ /** Text models, where the total is only known after generating. */
6
+ | "token";
7
+ export type AIModelCategory = "video" | "image" | "text" | "audio";
8
+ export type AIInputType = "text_only" | "image_required" | "image_optional" | "video_required";
9
+ export type AICreditUnit = "image" | "request" | "second" | "character" | "token";
10
+ export interface AIRuntimePricingTier {
11
+ creditsPerUnit: number;
12
+ creditUnit: AICreditUnit;
13
+ durationSeconds?: number;
14
+ resolution?: string;
15
+ withAudio?: boolean;
16
+ renderingSpeed?: "turbo" | "balanced" | "quality";
17
+ }
18
+ export type VideoQualityTier = "480p" | "580p" | "720p" | "768p" | "1080p" | "4k";
19
+ export type VideoMultishotMode = "off" | "extend" | "native";
20
+ export interface MotionControlCapability {
21
+ characterOrientations?: Array<"video" | "image">;
22
+ defaultCharacterOrientation?: "video" | "image";
23
+ backgroundSources?: Array<"video" | "image">;
24
+ defaultBackgroundSource?: "video" | "image";
25
+ modeValueByResolution?: Record<string, string>;
26
+ animateModes?: Array<{
27
+ value: string;
28
+ label?: string;
29
+ modelId: string;
30
+ }>;
31
+ defaultAnimateMode?: string;
32
+ supportsPrompt?: boolean;
33
+ }
34
+ export interface VideoCapabilities {
35
+ startFrame?: boolean;
36
+ endFrame?: boolean;
37
+ multishot?: {
38
+ mode: VideoMultishotMode;
39
+ maxShots?: number;
40
+ minShotDuration?: number;
41
+ maxShotDuration?: number;
42
+ maxTotalDuration?: number;
43
+ };
44
+ characterRef?: boolean;
45
+ motionControl?: boolean;
46
+ motionControlSettings?: MotionControlCapability;
47
+ refVideo?: boolean;
48
+ qualityTiers?: VideoQualityTier[];
49
+ elements?: {
50
+ max: number;
51
+ minImagesPerElement: number;
52
+ maxImagesPerElement: number;
53
+ };
54
+ referenceVideo?: {
55
+ minImages: number;
56
+ maxImages: number;
57
+ };
58
+ promptEnhance?: boolean;
59
+ vibeMode?: {
60
+ modes: string[];
61
+ defaultMode: string;
62
+ };
63
+ nsfwFiltered?: boolean;
64
+ multimodalReference?: {
65
+ images?: {
66
+ maxItems: number;
67
+ maxFileSizeMB?: number;
68
+ };
69
+ videos?: {
70
+ maxItems: number;
71
+ maxDurationSeconds?: number;
72
+ maxFileSizeMB?: number;
73
+ };
74
+ audios?: {
75
+ maxItems: number;
76
+ maxDurationSeconds?: number;
77
+ maxFileSizeMB?: number;
78
+ };
79
+ };
80
+ audioToggle?: boolean;
81
+ }
82
+ export type NodeTypeCapability = "text" | "image_gen" | "video_gen" | "copy_gen" | "image_upscale" | "image_upload" | "video_upload" | "image_bg_remove" | "video_upscale" | "variations" | "scene_planner";
83
+ export interface AIModelConfig {
84
+ id: string;
85
+ name: string;
86
+ category: AIModelCategory;
87
+ inputType: AIInputType;
88
+ nodeTypes: NodeTypeCapability[];
89
+ creditsPerUnit: number;
90
+ creditUnit: AICreditUnit;
91
+ maxDuration?: number;
92
+ minDuration?: number;
93
+ durationOptions?: number[];
94
+ supportedResolutions?: string[];
95
+ supportedAspectRatios?: string[];
96
+ maxInputImages?: number;
97
+ isDefault?: boolean;
98
+ endpoint?: string;
99
+ runtimePricingTiers?: AIRuntimePricingTier[];
100
+ videoCapabilities?: VideoCapabilities;
101
+ isNew?: boolean;
102
+ addedAt?: number;
103
+ tierRequired?: "starter" | "pro";
104
+ provider?: string;
105
+ /**
106
+ * The provider's own rate, when it has been verified. Left unset rather than
107
+ * guessed: an invented price is worse than a visible gap.
108
+ */
109
+ pricing?: {
110
+ unit: BillingUnit;
111
+ /** Flat rate, used when the resolution is unknown or not priced apart. */
112
+ usdPerUnit: number;
113
+ /** Rates that differ by resolution, which most video vendors do. */
114
+ byResolution?: Record<string, number>;
115
+ };
116
+ description?: string;
117
+ }
118
+ //# sourceMappingURL=model.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.types.d.ts","sourceRoot":"","sources":["../../src/constants/model.types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,MAAM,WAAW,GACpB,QAAQ,GACR,OAAO,GACP,SAAS;AACX,gDAAgD;GAC9C,WAAW;A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AC1E,UAAU,EAAE,MAAM,CAAC;QACnB,oEAAoE;QACpE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACtC,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,54 @@
1
+ import type { GenerationOutput } from "../ports/content-generator.port";
2
+ export type AIErrorCode =
3
+ /** The model id is not in the catalog. */
4
+ "unknown_model"
5
+ /** The model's provider has no API key configured on this client. */
6
+ | "missing_key"
7
+ /** No adapter ships for that provider. */
8
+ | "unsupported_provider"
9
+ /** The request never made sense — wrong params for this model. */
10
+ | "invalid_request"
11
+ /** The provider accepted it and then failed, or rejected it outright. */
12
+ | "provider_error"
13
+ /** The job outlived the wait. It may still finish; poll it again later. */
14
+ | "timeout";
15
+ export interface AIError {
16
+ code: AIErrorCode;
17
+ message: string;
18
+ provider?: string;
19
+ model?: string;
20
+ /** Whatever the provider actually said, for logging. */
21
+ cause?: unknown;
22
+ }
23
+ /**
24
+ * Every public call returns this. Nothing throws.
25
+ *
26
+ * Errors that arrive as values are errors you cannot forget to handle: the type
27
+ * makes `data` unusable until you have narrowed on `error`. It also removes a
28
+ * whole class of bug this SDK hit repeatedly while being built — a rejection
29
+ * thrown synchronously instead of returned, slipping past the caller's catch.
30
+ */
31
+ export type Result<T> = {
32
+ data: T;
33
+ error: null;
34
+ } | {
35
+ data: null;
36
+ error: AIError;
37
+ };
38
+ export declare function ok<T>(data: T): Result<T>;
39
+ export declare function fail<T>(error: AIError): Result<T>;
40
+ /** Turn a thrown value into an error result, since adapters may still throw. */
41
+ export declare function failFrom<T>(code: AIErrorCode, cause: unknown, context?: {
42
+ provider?: string;
43
+ model?: string;
44
+ }): Result<T>;
45
+ /** A finished generation. Success is the envelope's job, not a field in here. */
46
+ export interface Generation {
47
+ outputs: GenerationOutput[];
48
+ provider: string;
49
+ model: string;
50
+ processingTimeMs: number;
51
+ /** The tags the request carried, handed straight back. */
52
+ metadata?: Record<string, string>;
53
+ }
54
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/helpers/result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,MAAM,MAAM,WAAW;AACtB,0CAA0C;AACxC,eAAe;AACjB,qEAAqE;GACnE,aAAa;AACf,0CAA0C;GACxC,sBAAsB;AACxB,kEAAkE;GAChE,iBAAiB;AACnB,yEAAyE;GACvE,gBAAgB;AAClB,2EAA2E;GACzE,SAAS,CAAC;AAEb,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IACjB;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAElC,wBAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAExC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAEjD;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,CAAC,EACzB,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7C,MAAM,CAAC,CAAC,CAAC,CAOX;AAED,iFAAiF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