@agent-media/core 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.
- package/LICENSE +176 -0
- package/dist/config/index.d.ts +49 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +51 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/index.d.ts +47 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +111 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/result/index.d.ts +48 -0
- package/dist/result/index.d.ts.map +1 -0
- package/dist/result/index.js +65 -0
- package/dist/result/index.js.map +1 -0
- package/dist/types/index.d.ts +155 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default output directory name
|
|
3
|
+
*/
|
|
4
|
+
export declare const DEFAULT_OUTPUT_DIR = ".agent-media";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for agent-media
|
|
7
|
+
*/
|
|
8
|
+
export interface AgentMediaConfig {
|
|
9
|
+
/** Base output directory */
|
|
10
|
+
outputDir: string;
|
|
11
|
+
/** API keys for providers */
|
|
12
|
+
apiKeys: {
|
|
13
|
+
fal?: string;
|
|
14
|
+
replicate?: string;
|
|
15
|
+
runpod?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get configuration from environment variables and defaults
|
|
20
|
+
*/
|
|
21
|
+
export declare function getConfig(): AgentMediaConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Ensure the output directory exists
|
|
24
|
+
*/
|
|
25
|
+
export declare function ensureOutputDir(outputDir: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Generate a unique output filename
|
|
28
|
+
*/
|
|
29
|
+
export declare function generateOutputFilename(extension: string, prefix?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get the full output path for a file
|
|
32
|
+
*/
|
|
33
|
+
export declare function getOutputPath(outputDir: string, filename: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Merged configuration result
|
|
36
|
+
*/
|
|
37
|
+
export interface MergedConfig {
|
|
38
|
+
outputDir: string;
|
|
39
|
+
provider?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Merge CLI options with config defaults
|
|
43
|
+
* CLI options take precedence over environment config
|
|
44
|
+
*/
|
|
45
|
+
export declare function mergeConfig(config: AgentMediaConfig, cliOptions: {
|
|
46
|
+
out?: string;
|
|
47
|
+
provider?: string;
|
|
48
|
+
}): MergedConfig;
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,OAAO,EAAE;QACP,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,gBAAgB,CAY5C;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,MAAM,SAAW,GAChB,MAAM,CAIR;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,MAAM,CAER;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,gBAAgB,EACxB,UAAU,EAAE;IACV,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,YAAY,CAKd"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Default output directory name
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_OUTPUT_DIR = '.agent-media';
|
|
7
|
+
/**
|
|
8
|
+
* Get configuration from environment variables and defaults
|
|
9
|
+
*/
|
|
10
|
+
export function getConfig() {
|
|
11
|
+
const outputDir = process.env['AGENT_MEDIA_DIR'] ?? join(process.cwd(), DEFAULT_OUTPUT_DIR);
|
|
12
|
+
return {
|
|
13
|
+
outputDir: resolve(outputDir),
|
|
14
|
+
apiKeys: {
|
|
15
|
+
fal: process.env['FAL_API_KEY'],
|
|
16
|
+
replicate: process.env['REPLICATE_API_TOKEN'],
|
|
17
|
+
runpod: process.env['RUNPOD_API_KEY'],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Ensure the output directory exists
|
|
23
|
+
*/
|
|
24
|
+
export async function ensureOutputDir(outputDir) {
|
|
25
|
+
await mkdir(outputDir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generate a unique output filename
|
|
29
|
+
*/
|
|
30
|
+
export function generateOutputFilename(extension, prefix = 'output') {
|
|
31
|
+
const timestamp = Date.now();
|
|
32
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
33
|
+
return `${prefix}_${timestamp}_${random}.${extension}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the full output path for a file
|
|
37
|
+
*/
|
|
38
|
+
export function getOutputPath(outputDir, filename) {
|
|
39
|
+
return join(outputDir, filename);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Merge CLI options with config defaults
|
|
43
|
+
* CLI options take precedence over environment config
|
|
44
|
+
*/
|
|
45
|
+
export function mergeConfig(config, cliOptions) {
|
|
46
|
+
return {
|
|
47
|
+
outputDir: cliOptions.out ? resolve(cliOptions.out) : config.outputDir,
|
|
48
|
+
provider: cliOptions.provider,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51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;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,SAAiB,EACjB,QAAgB;IAEhB,OAAO,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAUD;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,MAAwB,EACxB,UAGC;IAED,OAAO;QACL,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS;QACtE,QAAQ,EAAE,UAAU,CAAC,QAAQ;KAC9B,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { MediaType, ImageAction, ImageFormat, MediaInput, ResizeOptions, ConvertOptions, RemoveBackgroundOptions, GenerateOptions, ExtendOptions, EditOptions, ActionOptions, MediaError, MediaSuccessResult, MediaErrorResult, MediaResult, ActionContext, MediaProvider, } from './types/index.js';
|
|
2
|
+
export { ProviderRegistry, detectProviderFromEnv, resolveProvider, executeAction, globalRegistry, } from './provider/index.js';
|
|
3
|
+
export { DEFAULT_OUTPUT_DIR, getConfig, ensureOutputDir, generateOutputFilename, getOutputPath, mergeConfig, } from './config/index.js';
|
|
4
|
+
export type { AgentMediaConfig, MergedConfig } from './config/index.js';
|
|
5
|
+
export { ErrorCodes, createSuccess, createError, isSuccess, isError, formatResult, printResult, } from './result/index.js';
|
|
6
|
+
export type { ErrorCode } from './result/index.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,SAAS,EACT,WAAW,EACX,WAAW,EACX,UAAU,EACV,aAAa,EACb,cAAc,EACd,uBAAuB,EACvB,eAAe,EACf,aAAa,EACb,WAAW,EACX,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,aAAa,GACd,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,cAAc,GACf,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGxE,OAAO,EACL,UAAU,EACV,aAAa,EACb,WAAW,EACX,SAAS,EACT,OAAO,EACP,YAAY,EACZ,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Provider
|
|
2
|
+
export { ProviderRegistry, detectProviderFromEnv, resolveProvider, executeAction, globalRegistry, } from './provider/index.js';
|
|
3
|
+
// Config
|
|
4
|
+
export { DEFAULT_OUTPUT_DIR, getConfig, ensureOutputDir, generateOutputFilename, getOutputPath, mergeConfig, } from './config/index.js';
|
|
5
|
+
// Result
|
|
6
|
+
export { ErrorCodes, createSuccess, createError, isSuccess, isError, formatResult, printResult, } from './result/index.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqBA,WAAW;AACX,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B,SAAS;AACT,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAG3B,SAAS;AACT,OAAO,EACL,UAAU,EACV,aAAa,EACb,WAAW,EACX,SAAS,EACT,OAAO,EACP,YAAY,EACZ,WAAW,GACZ,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { MediaProvider, MediaResult, ActionOptions, ActionContext } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Registry for managing media providers
|
|
4
|
+
*/
|
|
5
|
+
export declare class ProviderRegistry {
|
|
6
|
+
private providers;
|
|
7
|
+
/**
|
|
8
|
+
* Register a provider
|
|
9
|
+
*/
|
|
10
|
+
register(provider: MediaProvider): void;
|
|
11
|
+
/**
|
|
12
|
+
* Get a provider by name
|
|
13
|
+
*/
|
|
14
|
+
get(name: string): MediaProvider | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get all registered provider names
|
|
17
|
+
*/
|
|
18
|
+
getProviderNames(): string[];
|
|
19
|
+
/**
|
|
20
|
+
* Check if a provider exists
|
|
21
|
+
*/
|
|
22
|
+
has(name: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Find providers that support a given action
|
|
25
|
+
*/
|
|
26
|
+
findSupportingProviders(action: string): MediaProvider[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Detect provider from environment variables
|
|
30
|
+
*/
|
|
31
|
+
export declare function detectProviderFromEnv(): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve which provider to use based on:
|
|
34
|
+
* 1. Explicit CLI flag (highest priority)
|
|
35
|
+
* 2. Environment variable auto-detection
|
|
36
|
+
* 3. Fallback to local provider
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveProvider(registry: ProviderRegistry, action: string, explicitProvider?: string): MediaProvider | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Execute an action using the resolved provider
|
|
41
|
+
*/
|
|
42
|
+
export declare function executeAction(registry: ProviderRegistry, actionConfig: ActionOptions, context: ActionContext): Promise<MediaResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Global provider registry instance
|
|
45
|
+
*/
|
|
46
|
+
export declare const globalRegistry: ProviderRegistry;
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAYlG;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAyC;IAE1D;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAIvC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAI5C;;OAEG;IACH,gBAAgB,IAAI,MAAM,EAAE;IAI5B;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;OAEG;IACH,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE;CAKzD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,GAAG,SAAS,CAO1D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,MAAM,EACd,gBAAgB,CAAC,EAAE,MAAM,GACxB,aAAa,GAAG,SAAS,CAkC3B;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,YAAY,EAAE,aAAa,EAC3B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,WAAW,CAAC,CAqBtB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,kBAAyB,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createError } from '../result/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Environment variable to provider mapping for auto-detection
|
|
4
|
+
*/
|
|
5
|
+
const ENV_PROVIDER_MAP = {
|
|
6
|
+
FAL_API_KEY: 'fal',
|
|
7
|
+
REPLICATE_API_TOKEN: 'replicate',
|
|
8
|
+
RUNPOD_API_KEY: 'runpod',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Registry for managing media providers
|
|
12
|
+
*/
|
|
13
|
+
export class ProviderRegistry {
|
|
14
|
+
providers = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* Register a provider
|
|
17
|
+
*/
|
|
18
|
+
register(provider) {
|
|
19
|
+
this.providers.set(provider.name, provider);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get a provider by name
|
|
23
|
+
*/
|
|
24
|
+
get(name) {
|
|
25
|
+
return this.providers.get(name);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get all registered provider names
|
|
29
|
+
*/
|
|
30
|
+
getProviderNames() {
|
|
31
|
+
return Array.from(this.providers.keys());
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if a provider exists
|
|
35
|
+
*/
|
|
36
|
+
has(name) {
|
|
37
|
+
return this.providers.has(name);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Find providers that support a given action
|
|
41
|
+
*/
|
|
42
|
+
findSupportingProviders(action) {
|
|
43
|
+
return Array.from(this.providers.values()).filter((p) => p.supports(action));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Detect provider from environment variables
|
|
48
|
+
*/
|
|
49
|
+
export function detectProviderFromEnv() {
|
|
50
|
+
for (const [envVar, providerName] of Object.entries(ENV_PROVIDER_MAP)) {
|
|
51
|
+
if (process.env[envVar]) {
|
|
52
|
+
return providerName;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolve which provider to use based on:
|
|
59
|
+
* 1. Explicit CLI flag (highest priority)
|
|
60
|
+
* 2. Environment variable auto-detection
|
|
61
|
+
* 3. Fallback to local provider
|
|
62
|
+
*/
|
|
63
|
+
export function resolveProvider(registry, action, explicitProvider) {
|
|
64
|
+
// 1. Explicit provider selection (highest priority)
|
|
65
|
+
if (explicitProvider) {
|
|
66
|
+
const provider = registry.get(explicitProvider);
|
|
67
|
+
if (provider && provider.supports(action)) {
|
|
68
|
+
return provider;
|
|
69
|
+
}
|
|
70
|
+
// If explicit provider doesn't support action, return undefined
|
|
71
|
+
// Let the caller handle the error
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
// 2. Auto-detect from environment variables
|
|
75
|
+
const envProvider = detectProviderFromEnv();
|
|
76
|
+
if (envProvider) {
|
|
77
|
+
const provider = registry.get(envProvider);
|
|
78
|
+
if (provider && provider.supports(action)) {
|
|
79
|
+
return provider;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// 3. Fallback to local provider
|
|
83
|
+
const localProvider = registry.get('local');
|
|
84
|
+
if (localProvider && localProvider.supports(action)) {
|
|
85
|
+
return localProvider;
|
|
86
|
+
}
|
|
87
|
+
// 4. Find any provider that supports the action
|
|
88
|
+
const supportingProviders = registry.findSupportingProviders(action);
|
|
89
|
+
if (supportingProviders.length > 0) {
|
|
90
|
+
return supportingProviders[0];
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Execute an action using the resolved provider
|
|
96
|
+
*/
|
|
97
|
+
export async function executeAction(registry, actionConfig, context) {
|
|
98
|
+
const provider = resolveProvider(registry, actionConfig.action, context.provider);
|
|
99
|
+
if (!provider) {
|
|
100
|
+
if (context.provider) {
|
|
101
|
+
return createError('PROVIDER_NOT_FOUND', `Provider '${context.provider}' not found or does not support action '${actionConfig.action}'`);
|
|
102
|
+
}
|
|
103
|
+
return createError('NO_PROVIDER', `No provider available for action '${actionConfig.action}'`);
|
|
104
|
+
}
|
|
105
|
+
return provider.execute(actionConfig, context);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Global provider registry instance
|
|
109
|
+
*/
|
|
110
|
+
export const globalRegistry = new ProviderRegistry();
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,WAAW,EAAE,KAAK;IAClB,mBAAmB,EAAE,WAAW;IAChC,cAAc,EAAE,QAAQ;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACnB,SAAS,GAA+B,IAAI,GAAG,EAAE,CAAC;IAE1D;;OAEG;IACH,QAAQ,CAAC,QAAuB;QAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,uBAAuB,CAAC,MAAc;QACpC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACtD,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CACnB,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IAC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,CAAC;QACnC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAA0B,EAC1B,YAA2B,EAC3B,OAAsB;IAEtB,MAAM,QAAQ,GAAG,eAAe,CAC9B,QAAQ,EACR,YAAY,CAAC,MAAM,EACnB,OAAO,CAAC,QAAQ,CACjB,CAAC;IAEF,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO,WAAW,CAChB,oBAAoB,EACpB,aAAa,OAAO,CAAC,QAAQ,2CAA2C,YAAY,CAAC,MAAM,GAAG,CAC/F,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,CAChB,aAAa,EACb,qCAAqC,YAAY,CAAC,MAAM,GAAG,CAC5D,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { MediaType, MediaSuccessResult, MediaErrorResult, MediaResult } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Common error codes
|
|
4
|
+
*/
|
|
5
|
+
export declare const ErrorCodes: {
|
|
6
|
+
readonly INVALID_INPUT: "INVALID_INPUT";
|
|
7
|
+
readonly FILE_NOT_FOUND: "FILE_NOT_FOUND";
|
|
8
|
+
readonly INVALID_FORMAT: "INVALID_FORMAT";
|
|
9
|
+
readonly PROVIDER_NOT_FOUND: "PROVIDER_NOT_FOUND";
|
|
10
|
+
readonly NO_PROVIDER: "NO_PROVIDER";
|
|
11
|
+
readonly PROVIDER_ERROR: "PROVIDER_ERROR";
|
|
12
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
13
|
+
readonly API_ERROR: "API_ERROR";
|
|
14
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
15
|
+
};
|
|
16
|
+
export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
17
|
+
/**
|
|
18
|
+
* Create a success result
|
|
19
|
+
*/
|
|
20
|
+
export declare function createSuccess(params: {
|
|
21
|
+
mediaType: MediaType;
|
|
22
|
+
action: string;
|
|
23
|
+
provider: string;
|
|
24
|
+
outputPath: string;
|
|
25
|
+
mime: string;
|
|
26
|
+
bytes: number;
|
|
27
|
+
}): MediaSuccessResult;
|
|
28
|
+
/**
|
|
29
|
+
* Create an error result
|
|
30
|
+
*/
|
|
31
|
+
export declare function createError(code: string, message: string): MediaErrorResult;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a result is successful
|
|
34
|
+
*/
|
|
35
|
+
export declare function isSuccess(result: MediaResult): result is MediaSuccessResult;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a result is an error
|
|
38
|
+
*/
|
|
39
|
+
export declare function isError(result: MediaResult): result is MediaErrorResult;
|
|
40
|
+
/**
|
|
41
|
+
* Format a result as JSON string for stdout
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatResult(result: MediaResult): string;
|
|
44
|
+
/**
|
|
45
|
+
* Print result to stdout (for CLI)
|
|
46
|
+
*/
|
|
47
|
+
export declare function printResult(result: MediaResult): void;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/result/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;CAUb,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAErE;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,kBAAkB,CAUrB;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,gBAAgB,CAQlB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,IAAI,kBAAkB,CAE3E;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,IAAI,gBAAgB,CAEvE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAExD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAErD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common error codes
|
|
3
|
+
*/
|
|
4
|
+
export const ErrorCodes = {
|
|
5
|
+
INVALID_INPUT: 'INVALID_INPUT',
|
|
6
|
+
FILE_NOT_FOUND: 'FILE_NOT_FOUND',
|
|
7
|
+
INVALID_FORMAT: 'INVALID_FORMAT',
|
|
8
|
+
PROVIDER_NOT_FOUND: 'PROVIDER_NOT_FOUND',
|
|
9
|
+
NO_PROVIDER: 'NO_PROVIDER',
|
|
10
|
+
PROVIDER_ERROR: 'PROVIDER_ERROR',
|
|
11
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
12
|
+
API_ERROR: 'API_ERROR',
|
|
13
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Create a success result
|
|
17
|
+
*/
|
|
18
|
+
export function createSuccess(params) {
|
|
19
|
+
return {
|
|
20
|
+
ok: true,
|
|
21
|
+
media_type: params.mediaType,
|
|
22
|
+
action: params.action,
|
|
23
|
+
provider: params.provider,
|
|
24
|
+
output_path: params.outputPath,
|
|
25
|
+
mime: params.mime,
|
|
26
|
+
bytes: params.bytes,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create an error result
|
|
31
|
+
*/
|
|
32
|
+
export function createError(code, message) {
|
|
33
|
+
return {
|
|
34
|
+
ok: false,
|
|
35
|
+
error: {
|
|
36
|
+
code,
|
|
37
|
+
message,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if a result is successful
|
|
43
|
+
*/
|
|
44
|
+
export function isSuccess(result) {
|
|
45
|
+
return result.ok === true;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if a result is an error
|
|
49
|
+
*/
|
|
50
|
+
export function isError(result) {
|
|
51
|
+
return result.ok === false;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Format a result as JSON string for stdout
|
|
55
|
+
*/
|
|
56
|
+
export function formatResult(result) {
|
|
57
|
+
return JSON.stringify(result, null, 2);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Print result to stdout (for CLI)
|
|
61
|
+
*/
|
|
62
|
+
export function printResult(result) {
|
|
63
|
+
console.log(formatResult(result));
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/result/index.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa,EAAE,eAAe;IAC9B,cAAc,EAAE,gBAAgB;IAChC,cAAc,EAAE,gBAAgB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
+
export type MediaType = 'image' | 'video' | 'audio';
|
|
5
|
+
/**
|
|
6
|
+
* Supported image actions
|
|
7
|
+
*/
|
|
8
|
+
export type ImageAction = 'resize' | 'convert' | 'remove-background' | 'generate' | 'extend' | 'edit';
|
|
9
|
+
/**
|
|
10
|
+
* Supported image formats
|
|
11
|
+
*/
|
|
12
|
+
export type ImageFormat = 'png' | 'jpg' | 'jpeg' | 'webp';
|
|
13
|
+
/**
|
|
14
|
+
* Input source for media operations
|
|
15
|
+
*/
|
|
16
|
+
export interface MediaInput {
|
|
17
|
+
/** Local file path or URL */
|
|
18
|
+
source: string;
|
|
19
|
+
/** Whether the source is a URL */
|
|
20
|
+
isUrl: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for resize action
|
|
24
|
+
*/
|
|
25
|
+
export interface ResizeOptions {
|
|
26
|
+
input: MediaInput;
|
|
27
|
+
width?: number;
|
|
28
|
+
height?: number;
|
|
29
|
+
/** Maintain aspect ratio (default: true) */
|
|
30
|
+
maintainAspectRatio?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options for convert action
|
|
34
|
+
*/
|
|
35
|
+
export interface ConvertOptions {
|
|
36
|
+
input: MediaInput;
|
|
37
|
+
format: ImageFormat;
|
|
38
|
+
/** Quality for lossy formats (1-100, default: 80) */
|
|
39
|
+
quality?: number;
|
|
40
|
+
/** DPI/density for output image (default: 72) */
|
|
41
|
+
dpi?: number;
|
|
42
|
+
/** Target width in pixels (for rasterizing vector formats like SVG) */
|
|
43
|
+
width?: number;
|
|
44
|
+
/** Target height in pixels (for rasterizing vector formats like SVG) */
|
|
45
|
+
height?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for remove-background action
|
|
49
|
+
*/
|
|
50
|
+
export interface RemoveBackgroundOptions {
|
|
51
|
+
input: MediaInput;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options for generate action
|
|
55
|
+
*/
|
|
56
|
+
export interface GenerateOptions {
|
|
57
|
+
prompt: string;
|
|
58
|
+
width?: number;
|
|
59
|
+
height?: number;
|
|
60
|
+
/** Number of images to generate (default: 1) */
|
|
61
|
+
count?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Options for extend action
|
|
65
|
+
*/
|
|
66
|
+
export interface ExtendOptions {
|
|
67
|
+
input: MediaInput;
|
|
68
|
+
/** Padding size in pixels to add on all sides */
|
|
69
|
+
padding: number;
|
|
70
|
+
/** Background color for the extended area (hex, e.g., "#E4ECF8"). Also flattens any transparency to this color. */
|
|
71
|
+
color: string;
|
|
72
|
+
/** DPI/density for output image metadata */
|
|
73
|
+
dpi?: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Options for edit action (image-to-image with prompt)
|
|
77
|
+
*/
|
|
78
|
+
export interface EditOptions {
|
|
79
|
+
input: MediaInput;
|
|
80
|
+
/** Text prompt describing the desired edit */
|
|
81
|
+
prompt: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Union type for all action options
|
|
85
|
+
*/
|
|
86
|
+
export type ActionOptions = {
|
|
87
|
+
action: 'resize';
|
|
88
|
+
options: ResizeOptions;
|
|
89
|
+
} | {
|
|
90
|
+
action: 'convert';
|
|
91
|
+
options: ConvertOptions;
|
|
92
|
+
} | {
|
|
93
|
+
action: 'remove-background';
|
|
94
|
+
options: RemoveBackgroundOptions;
|
|
95
|
+
} | {
|
|
96
|
+
action: 'generate';
|
|
97
|
+
options: GenerateOptions;
|
|
98
|
+
} | {
|
|
99
|
+
action: 'extend';
|
|
100
|
+
options: ExtendOptions;
|
|
101
|
+
} | {
|
|
102
|
+
action: 'edit';
|
|
103
|
+
options: EditOptions;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Structured error information
|
|
107
|
+
*/
|
|
108
|
+
export interface MediaError {
|
|
109
|
+
code: string;
|
|
110
|
+
message: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Successful result from a media operation
|
|
114
|
+
*/
|
|
115
|
+
export interface MediaSuccessResult {
|
|
116
|
+
ok: true;
|
|
117
|
+
media_type: MediaType;
|
|
118
|
+
action: string;
|
|
119
|
+
provider: string;
|
|
120
|
+
output_path: string;
|
|
121
|
+
mime: string;
|
|
122
|
+
bytes: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Failed result from a media operation
|
|
126
|
+
*/
|
|
127
|
+
export interface MediaErrorResult {
|
|
128
|
+
ok: false;
|
|
129
|
+
error: MediaError;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Result from a media operation
|
|
133
|
+
*/
|
|
134
|
+
export type MediaResult = MediaSuccessResult | MediaErrorResult;
|
|
135
|
+
/**
|
|
136
|
+
* Context for executing an action
|
|
137
|
+
*/
|
|
138
|
+
export interface ActionContext {
|
|
139
|
+
/** Output directory for results */
|
|
140
|
+
outputDir: string;
|
|
141
|
+
/** Explicitly selected provider (overrides auto-detection) */
|
|
142
|
+
provider?: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Provider interface that all media providers must implement
|
|
146
|
+
*/
|
|
147
|
+
export interface MediaProvider {
|
|
148
|
+
/** Unique name of the provider */
|
|
149
|
+
name: string;
|
|
150
|
+
/** Check if this provider supports the given action */
|
|
151
|
+
supports(action: string): boolean;
|
|
152
|
+
/** Execute an action and return the result */
|
|
153
|
+
execute(actionConfig: ActionOptions, context: ActionContext): Promise<MediaResult>;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,SAAS,G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AAC;IAClB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IAEb,uDAAuD;IACvD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAElC,8CAA8C;IAC9C,OAAO,CACL,YAAY,EAAE,aAAa,EAC3B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agent-media/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core types and utilities for agent-media toolkit",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/TimPietrusky/agent-media.git",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./types": {
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"import": "./dist/types/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./provider": {
|
|
24
|
+
"types": "./dist/provider/index.d.ts",
|
|
25
|
+
"import": "./dist/provider/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./config": {
|
|
28
|
+
"types": "./dist/config/index.d.ts",
|
|
29
|
+
"import": "./dist/config/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./result": {
|
|
32
|
+
"types": "./dist/result/index.d.ts",
|
|
33
|
+
"import": "./dist/result/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^22.0.0",
|
|
41
|
+
"typescript": "^5.7.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
47
|
+
}
|
|
48
|
+
}
|