@uploadista/flow-images-replicate 0.0.3 → 0.0.4

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.
@@ -1,5 +1,22 @@
1
1
 
2
2
  
3
- > @uploadista/flow-images-replicate@0.0.2 build /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/flow/images/replicate
4
- > tsc -b
3
+ > @uploadista/flow-images-replicate@0.0.3 build /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/flow/images/replicate
4
+ > tsdown
5
5
 
6
+ ℹ tsdown v0.15.9 powered by rolldown v1.0.0-beta.44
7
+ ℹ Using tsdown config: /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/flow/images/replicate/tsdown.config.ts
8
+ ℹ entry: src/index.ts
9
+ ℹ tsconfig: tsconfig.json
10
+ ℹ Build start
11
+ ℹ Cleaning 7 files
12
+ ℹ [CJS] dist/index.cjs 2.77 kB │ gzip: 1.31 kB
13
+ ℹ [CJS] 1 files, total: 2.77 kB
14
+ ℹ [ESM] dist/index.js 2.15 kB │ gzip: 1.08 kB
15
+ ℹ [ESM] dist/index.js.map 8.68 kB │ gzip: 2.65 kB
16
+ ℹ [ESM] dist/index.d.ts.map 0.51 kB │ gzip: 0.31 kB
17
+ ℹ [ESM] dist/index.d.ts 1.44 kB │ gzip: 0.61 kB
18
+ ℹ [ESM] 4 files, total: 12.78 kB
19
+ ℹ [CJS] dist/index.d.cts.map 0.51 kB │ gzip: 0.31 kB
20
+ ℹ [CJS] dist/index.d.cts 1.44 kB │ gzip: 0.61 kB
21
+ ℹ [CJS] 2 files, total: 1.95 kB
22
+ ✔ Build complete in 13631ms
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@uploadista/core/errors`);c=s(c);let l=require(`@uploadista/core/flow`);l=s(l);let u=require(`effect`);u=s(u);let d=require(`replicate`);d=s(d);const f=(e,t)=>{let n=typeof e==`string`,r=n?e:null,i=n?null:e.credentialProvider,a=n?!1:e.useCredentialProviderService,o=(n?t?.removeBackgroundModelId:e.removeBackgroundModelId)||`lucataco/remove-bg:95fcc2a26d3899cd6c2691c900465aaeff466285a65c14638cc5f36f34befaf1`,s=(n?t?.describeImageModelId:e.describeImageModelId)||`zsxkib/blip-3:499bec581d8f64060fd695ec0c34d7595c6824c4118259aa8b0788e0d2d903e1`,f=e=>r?u.Effect.succeed(r):a?u.Effect.gen(function*(){let t=yield*u.Effect.serviceOption(l.CredentialProvider);if(u.Option.isNone(t))return yield*u.Effect.fail(c.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:Error(`Credential provider service not found`)}));{let n=yield*t.value.getCredential({clientId:e.clientId,serviceType:`replicate`});if(typeof n==`object`&&n&&`apiKey`in n&&typeof n.apiKey==`string`)return n.apiKey}return yield*u.Effect.fail(c.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:Error(`Invalid credential format from service`)}))}):i?u.Effect.gen(function*(){return(yield*i({...e,serviceType:`replicate`})).apiKey}):u.Effect.fail(c.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:Error(`No API credentials configured`)}));return u.Layer.succeed(l.ImageAiPlugin,l.ImageAiPlugin.of({removeBackground:(e,t)=>u.Effect.gen(function*(){let n=yield*f(t);return{outputUrl:(yield*u.Effect.tryPromise({try:async()=>{let t=new d.default({auth:n}),r={image:e};return console.log(`input`,r),await t.run(o,{input:r})},catch:e=>(console.log(`error`,e),c.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:e}))})).url()}}),describeImage:(e,t)=>u.Effect.gen(function*(){let n=yield*f(t);return{description:yield*u.Effect.tryPromise({try:async()=>await new d.default({auth:n}).run(s,{input:{image:e,top_k:50,top_p:1,caption:!1,question:`What is shown in the image?`,do_sample:!1,num_beams:1,temperature:1,system_prompt:`A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.`,length_penalty:1,max_new_tokens:768,repetition_penalty:1}}),catch:e=>c.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:e})})}})}))};exports.imageAiPlugin=f;
@@ -1,18 +1,20 @@
1
1
  import { UploadistaError } from "@uploadista/core/errors";
2
- import { type ImageAiContext, ImageAiPlugin } from "@uploadista/core/flow";
2
+ import { ImageAiContext, ImageAiPlugin } from "@uploadista/core/flow";
3
3
  import { Effect, Layer } from "effect";
4
+
5
+ //#region src/image-ai-plugin.d.ts
4
6
  type ModelId = `${string}/${string}` | `${string}/${string}:${string}`;
5
7
  type ReplicateCredentials = {
6
- apiKey: string;
8
+ apiKey: string;
7
9
  };
8
10
  type CredentialProvider = (context: ImageAiContext & {
9
- serviceType: "replicate";
11
+ serviceType: "replicate";
10
12
  }) => Effect.Effect<ReplicateCredentials, UploadistaError>;
11
13
  type PluginConfig = string | {
12
- credentialProvider?: CredentialProvider;
13
- useCredentialProviderService?: boolean;
14
- removeBackgroundModelId?: ModelId;
15
- describeImageModelId?: ModelId;
14
+ credentialProvider?: CredentialProvider;
15
+ useCredentialProviderService?: boolean;
16
+ removeBackgroundModelId?: ModelId;
17
+ describeImageModelId?: ModelId;
16
18
  };
17
19
  /**
18
20
  * Create the Replicate ImageAI plugin
@@ -34,9 +36,10 @@ type PluginConfig = string | {
34
36
  * useCredentialProviderService: true
35
37
  * })
36
38
  */
37
- export declare const imageAiPlugin: (config: PluginConfig, options?: {
38
- removeBackgroundModelId?: ModelId;
39
- describeImageModelId?: ModelId;
39
+ declare const imageAiPlugin: (config: PluginConfig, options?: {
40
+ removeBackgroundModelId?: ModelId;
41
+ describeImageModelId?: ModelId;
40
42
  }) => Layer.Layer<ImageAiPlugin, never, never>;
41
- export {};
42
- //# sourceMappingURL=image-ai-plugin.d.ts.map
43
+ //#endregion
44
+ export { imageAiPlugin };
45
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/image-ai-plugin.ts"],"sourcesContent":[],"mappings":";;;;;KASK,OAAA;KAMA,oBAAA;EANA,MAAA,EAAA,MAAO;AAAA,CAAA;AAMa,KAKpB,kBAAA,GAAkB,CAAA,OAAA,EACZ,cADY,GAAA;EACZ,WAAA,EAAA,WAAA;CACQ,EAAA,GAAd,MAAA,CAAO,MAAO,CAAA,oBAAA,EAAsB,eAAtB,CAAA;KAGd,YAAA,GAHoC,MAAA,GAAA;EAApC,kBAAO,CAAA,EAMe,kBANf;EAAM,4BAAA,CAAA,EAAA,OAAA;EAGb,uBAAY,CAAA,EAKe,OALf;EAGU,oBAAA,CAAA,EAGE,OAHF;CAEK;;;AAwBhC;;;;;;;;;;;;;;;;;;cAAa,wBACH;4BAEoB;yBACH;MACxB,KAAA,CAAA,MAAA"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,45 @@
1
- export * from "./image-ai-plugin";
1
+ import { UploadistaError } from "@uploadista/core/errors";
2
+ import { ImageAiContext, ImageAiPlugin } from "@uploadista/core/flow";
3
+ import { Effect, Layer } from "effect";
4
+
5
+ //#region src/image-ai-plugin.d.ts
6
+ type ModelId = `${string}/${string}` | `${string}/${string}:${string}`;
7
+ type ReplicateCredentials = {
8
+ apiKey: string;
9
+ };
10
+ type CredentialProvider$1 = (context: ImageAiContext & {
11
+ serviceType: "replicate";
12
+ }) => Effect.Effect<ReplicateCredentials, UploadistaError>;
13
+ type PluginConfig = string | {
14
+ credentialProvider?: CredentialProvider$1;
15
+ useCredentialProviderService?: boolean;
16
+ removeBackgroundModelId?: ModelId;
17
+ describeImageModelId?: ModelId;
18
+ };
19
+ /**
20
+ * Create the Replicate ImageAI plugin
21
+ * Supports both static credentials (OSS) and dynamic credential providers (SaaS)
22
+ *
23
+ * @example
24
+ * // Static credentials (OSS)
25
+ * imageAiPlugin(process.env.REPLICATE_API_TOKEN)
26
+ *
27
+ * @example
28
+ * // Dynamic credentials with function (SaaS)
29
+ * imageAiPlugin({
30
+ * credentialProvider: (context) => Effect.succeed({ apiKey: "..." })
31
+ * })
32
+ *
33
+ * @example
34
+ * // Dynamic credentials with Effect service (SaaS)
35
+ * imageAiPlugin({
36
+ * useCredentialProviderService: true
37
+ * })
38
+ */
39
+ declare const imageAiPlugin: (config: PluginConfig, options?: {
40
+ removeBackgroundModelId?: ModelId;
41
+ describeImageModelId?: ModelId;
42
+ }) => Layer.Layer<ImageAiPlugin, never, never>;
43
+ //#endregion
44
+ export { imageAiPlugin };
2
45
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/image-ai-plugin.ts"],"sourcesContent":[],"mappings":";;;;;KASK,OAAA;KAMA,oBAAA;EANA,MAAA,EAAA,MAAO;AAAA,CAAA;AAMa,KAKpB,oBAAA,GAAA,CAAkB,OAAA,EACZ,cADY,GAAA;EACZ,WAAA,EAAA,WAAA;CACQ,EAAA,GAAd,MAAA,CAAO,MAAO,CAAA,oBAAA,EAAsB,eAAtB,CAAA;KAGd,YAAA,GAHoC,MAAA,GAAA;EAApC,kBAAO,CAAA,EAMe,oBANf;EAAM,4BAAA,CAAA,EAAA,OAAA;EAGb,uBAAY,CAAA,EAKe,OALf;EAGU,oBAAA,CAAA,EAGE,OAHF;CAEK;;;AAwBhC;;;;;;;;;;;;;;;;;;cAAa,wBACH;4BAEoB;yBACH;MACxB,KAAA,CAAA,MAAA"}
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- export * from "./image-ai-plugin";
1
+ import{UploadistaError as e}from"@uploadista/core/errors";import{CredentialProvider as t,ImageAiPlugin as n}from"@uploadista/core/flow";import{Effect as r,Layer as i,Option as a}from"effect";import o from"replicate";const s=(s,c)=>{let l=typeof s==`string`,u=l?s:null,d=l?null:s.credentialProvider,f=l?!1:s.useCredentialProviderService,p=(l?c?.removeBackgroundModelId:s.removeBackgroundModelId)||`lucataco/remove-bg:95fcc2a26d3899cd6c2691c900465aaeff466285a65c14638cc5f36f34befaf1`,m=(l?c?.describeImageModelId:s.describeImageModelId)||`zsxkib/blip-3:499bec581d8f64060fd695ec0c34d7595c6824c4118259aa8b0788e0d2d903e1`,h=n=>u?r.succeed(u):f?r.gen(function*(){let i=yield*r.serviceOption(t);if(a.isNone(i))return yield*r.fail(e.fromCode(`UNKNOWN_ERROR`,{cause:Error(`Credential provider service not found`)}));{let e=yield*i.value.getCredential({clientId:n.clientId,serviceType:`replicate`});if(typeof e==`object`&&e&&`apiKey`in e&&typeof e.apiKey==`string`)return e.apiKey}return yield*r.fail(e.fromCode(`UNKNOWN_ERROR`,{cause:Error(`Invalid credential format from service`)}))}):d?r.gen(function*(){return(yield*d({...n,serviceType:`replicate`})).apiKey}):r.fail(e.fromCode(`UNKNOWN_ERROR`,{cause:Error(`No API credentials configured`)}));return i.succeed(n,n.of({removeBackground:(t,n)=>r.gen(function*(){let i=yield*h(n);return{outputUrl:(yield*r.tryPromise({try:async()=>{let e=new o({auth:i}),n={image:t};return console.log(`input`,n),await e.run(p,{input:n})},catch:t=>(console.log(`error`,t),e.fromCode(`UNKNOWN_ERROR`,{cause:t}))})).url()}}),describeImage:(t,n)=>r.gen(function*(){let i=yield*h(n);return{description:yield*r.tryPromise({try:async()=>await new o({auth:i}).run(m,{input:{image:t,top_k:50,top_p:1,caption:!1,question:`What is shown in the image?`,do_sample:!1,num_beams:1,temperature:1,system_prompt:`A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.`,length_penalty:1,max_new_tokens:768,repetition_penalty:1}}),catch:t=>e.fromCode(`UNKNOWN_ERROR`,{cause:t})})}})}))};export{s as imageAiPlugin};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["CredentialProviderService"],"sources":["../src/image-ai-plugin.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n CredentialProvider as CredentialProviderService,\n type ImageAiContext,\n ImageAiPlugin,\n} from \"@uploadista/core/flow\";\nimport { Effect, Layer, Option } from \"effect\";\nimport Replicate from \"replicate\";\n\ntype ModelId = `${string}/${string}` | `${string}/${string}:${string}`;\n\ntype RemoveBackgroundOutput = {\n url: () => string;\n};\n\ntype ReplicateCredentials = {\n apiKey: string;\n};\n\n// Credential provider function type\ntype CredentialProvider = (\n context: ImageAiContext & { serviceType: \"replicate\" },\n) => Effect.Effect<ReplicateCredentials, UploadistaError>;\n\n// Plugin configuration can be either a static API key or options with credential provider or service\ntype PluginConfig =\n | string\n | {\n credentialProvider?: CredentialProvider;\n useCredentialProviderService?: boolean;\n removeBackgroundModelId?: ModelId;\n describeImageModelId?: ModelId;\n };\n\n/**\n * Create the Replicate ImageAI plugin\n * Supports both static credentials (OSS) and dynamic credential providers (SaaS)\n *\n * @example\n * // Static credentials (OSS)\n * imageAiPlugin(process.env.REPLICATE_API_TOKEN)\n *\n * @example\n * // Dynamic credentials with function (SaaS)\n * imageAiPlugin({\n * credentialProvider: (context) => Effect.succeed({ apiKey: \"...\" })\n * })\n *\n * @example\n * // Dynamic credentials with Effect service (SaaS)\n * imageAiPlugin({\n * useCredentialProviderService: true\n * })\n */\nexport const imageAiPlugin = (\n config: PluginConfig,\n options?: {\n removeBackgroundModelId?: ModelId;\n describeImageModelId?: ModelId;\n },\n) => {\n // Parse configuration\n const isStatic = typeof config === \"string\";\n const staticApiKey = isStatic ? config : null;\n const credentialProvider = isStatic ? null : config.credentialProvider;\n const useCredentialProviderService = isStatic\n ? false\n : config.useCredentialProviderService;\n\n // Model IDs can come from either the config object or the options parameter\n const removeBackgroundModelId =\n (isStatic\n ? options?.removeBackgroundModelId\n : config.removeBackgroundModelId) ||\n \"lucataco/remove-bg:95fcc2a26d3899cd6c2691c900465aaeff466285a65c14638cc5f36f34befaf1\";\n const describeImageModelId =\n (isStatic ? options?.describeImageModelId : config.describeImageModelId) ||\n \"zsxkib/blip-3:499bec581d8f64060fd695ec0c34d7595c6824c4118259aa8b0788e0d2d903e1\";\n\n // Helper to get API token (either static, from provider function, or from service)\n const getApiToken = (context: ImageAiContext) => {\n if (staticApiKey) {\n return Effect.succeed(staticApiKey);\n }\n if (useCredentialProviderService) {\n return Effect.gen(function* () {\n const credentialProviderService = yield* Effect.serviceOption(\n CredentialProviderService,\n );\n\n if (Option.isNone(credentialProviderService)) {\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: new Error(\"Credential provider service not found\"),\n }),\n );\n } else {\n const credentials =\n yield* credentialProviderService.value.getCredential({\n clientId: context.clientId,\n serviceType: \"replicate\",\n });\n\n if (\n typeof credentials === \"object\" &&\n credentials !== null &&\n \"apiKey\" in credentials &&\n typeof credentials.apiKey === \"string\"\n ) {\n return credentials.apiKey;\n }\n }\n\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: new Error(\"Invalid credential format from service\"),\n }),\n );\n });\n }\n if (credentialProvider) {\n return Effect.gen(function* () {\n const credentials = yield* credentialProvider({\n ...context,\n serviceType: \"replicate\",\n });\n return credentials.apiKey;\n });\n }\n return Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: new Error(\"No API credentials configured\"),\n }),\n );\n };\n\n return Layer.succeed(\n ImageAiPlugin,\n ImageAiPlugin.of({\n removeBackground: (inputUrl, context) => {\n return Effect.gen(function* () {\n // Get API token (static or from credential provider)\n const apiToken = yield* getApiToken(context);\n\n const output = yield* Effect.tryPromise({\n try: async () => {\n const replicate = new Replicate({\n auth: apiToken,\n });\n\n const input = {\n image: inputUrl,\n };\n\n console.log(\"input\", input);\n\n return (await replicate.run(removeBackgroundModelId, {\n input,\n })) as RemoveBackgroundOutput;\n },\n catch: (error) => {\n console.log(\"error\", error);\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: error,\n });\n },\n });\n return { outputUrl: output.url() };\n });\n },\n describeImage: (inputUrl, context) => {\n return Effect.gen(function* () {\n // Get API token (static or from credential provider)\n const apiToken = yield* getApiToken(context);\n\n const output = yield* Effect.tryPromise({\n try: async () => {\n const replicate = new Replicate({\n auth: apiToken,\n });\n\n return (await replicate.run(describeImageModelId, {\n input: {\n image: inputUrl,\n top_k: 50,\n top_p: 1,\n caption: false,\n question: \"What is shown in the image?\",\n do_sample: false,\n num_beams: 1,\n temperature: 1,\n system_prompt:\n \"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\",\n length_penalty: 1,\n max_new_tokens: 768,\n repetition_penalty: 1,\n },\n })) as unknown as string;\n },\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: error,\n });\n },\n });\n return { description: output };\n });\n },\n }),\n );\n};\n"],"mappings":"wNAsDA,MAAa,GACX,EACA,IAIG,CAEH,IAAM,EAAW,OAAO,GAAW,SAC7B,EAAe,EAAW,EAAS,KACnC,EAAqB,EAAW,KAAO,EAAO,mBAC9C,EAA+B,EACjC,GACA,EAAO,6BAGL,GACH,EACG,GAAS,wBACT,EAAO,0BACX,sFACI,GACH,EAAW,GAAS,qBAAuB,EAAO,uBACnD,iFAGI,EAAe,GACf,EACK,EAAO,QAAQ,EAAa,CAEjC,EACK,EAAO,IAAI,WAAa,CAC7B,IAAM,EAA4B,MAAO,EAAO,cAC9CA,EACD,CAED,GAAI,EAAO,OAAO,EAA0B,CAC1C,OAAO,MAAO,EAAO,KACnB,EAAgB,SAAS,gBAAiB,CACxC,MAAW,MAAM,wCAAwC,CAC1D,CAAC,CACH,CACI,CACL,IAAM,EACJ,MAAO,EAA0B,MAAM,cAAc,CACnD,SAAU,EAAQ,SAClB,YAAa,YACd,CAAC,CAEJ,GACE,OAAO,GAAgB,UACvB,GACA,WAAY,GACZ,OAAO,EAAY,QAAW,SAE9B,OAAO,EAAY,OAIvB,OAAO,MAAO,EAAO,KACnB,EAAgB,SAAS,gBAAiB,CACxC,MAAW,MAAM,yCAAyC,CAC3D,CAAC,CACH,EACD,CAEA,EACK,EAAO,IAAI,WAAa,CAK7B,OAJoB,MAAO,EAAmB,CAC5C,GAAG,EACH,YAAa,YACd,CAAC,EACiB,QACnB,CAEG,EAAO,KACZ,EAAgB,SAAS,gBAAiB,CACxC,MAAW,MAAM,gCAAgC,CAClD,CAAC,CACH,CAGH,OAAO,EAAM,QACX,EACA,EAAc,GAAG,CACf,kBAAmB,EAAU,IACpB,EAAO,IAAI,WAAa,CAE7B,IAAM,EAAW,MAAO,EAAY,EAAQ,CAyB5C,MAAO,CAAE,WAvBM,MAAO,EAAO,WAAW,CACtC,IAAK,SAAY,CACf,IAAM,EAAY,IAAI,EAAU,CAC9B,KAAM,EACP,CAAC,CAEI,EAAQ,CACZ,MAAO,EACR,CAID,OAFA,QAAQ,IAAI,QAAS,EAAM,CAEnB,MAAM,EAAU,IAAI,EAAyB,CACnD,QACD,CAAC,EAEJ,MAAQ,IACN,QAAQ,IAAI,QAAS,EAAM,CACpB,EAAgB,SAAS,gBAAiB,CAC/C,MAAO,EACR,CAAC,EAEL,CAAC,EACyB,KAAK,CAAE,EAClC,CAEJ,eAAgB,EAAU,IACjB,EAAO,IAAI,WAAa,CAE7B,IAAM,EAAW,MAAO,EAAY,EAAQ,CAgC5C,MAAO,CAAE,YA9BM,MAAO,EAAO,WAAW,CACtC,IAAK,SAKK,MAJU,IAAI,EAAU,CAC9B,KAAM,EACP,CAAC,CAEsB,IAAI,EAAsB,CAChD,MAAO,CACL,MAAO,EACP,MAAO,GACP,MAAO,EACP,QAAS,GACT,SAAU,8BACV,UAAW,GACX,UAAW,EACX,YAAa,EACb,cACE,6JACF,eAAgB,EAChB,eAAgB,IAChB,mBAAoB,EACrB,CACF,CAAC,CAEJ,MAAQ,GACC,EAAgB,SAAS,gBAAiB,CAC/C,MAAO,EACR,CAAC,CAEL,CAAC,CAC4B,EAC9B,CAEL,CAAC,CACH"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadista/flow-images-replicate",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "description": "Replicate image AI processing service for Uploadista Flow",
6
6
  "license": "MIT",
7
7
  "author": "Uploadista",
@@ -16,14 +16,15 @@
16
16
  "replicate": "1.3.0",
17
17
  "effect": "3.18.4",
18
18
  "zod": "4.1.12",
19
- "@uploadista/core": "0.0.3"
19
+ "@uploadista/core": "0.0.4"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "24.8.1",
23
- "@uploadista/typescript-config": "0.0.3"
23
+ "tsdown": "0.15.9",
24
+ "@uploadista/typescript-config": "0.0.4"
24
25
  },
25
26
  "scripts": {
26
- "build": "tsc -b",
27
+ "build": "tsdown",
27
28
  "format": "biome format --write ./src",
28
29
  "lint": "biome lint --write ./src",
29
30
  "check": "biome check --write ./src"
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ index: "src/index.ts",
6
+ },
7
+ minify: true,
8
+ format: ["esm", "cjs"],
9
+ dts: true,
10
+ outDir: "dist",
11
+ });
@@ -1 +0,0 @@
1
- {"version":3,"file":"image-ai-plugin.d.ts","sourceRoot":"","sources":["../src/image-ai-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAEL,KAAK,cAAc,EACnB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AAG/C,KAAK,OAAO,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AAMvE,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF,KAAK,kBAAkB,GAAG,CACxB,OAAO,EAAE,cAAc,GAAG;IAAE,WAAW,EAAE,WAAW,CAAA;CAAE,KACnD,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;AAG1D,KAAK,YAAY,GACb,MAAM,GACN;IACE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEN;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,YAAY,EACpB,UAAU;IACR,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,6CAuJF,CAAC"}
@@ -1,147 +0,0 @@
1
- import { UploadistaError } from "@uploadista/core/errors";
2
- import { CredentialProvider as CredentialProviderService, ImageAiPlugin, } from "@uploadista/core/flow";
3
- import { Effect, Layer, Option } from "effect";
4
- import Replicate from "replicate";
5
- /**
6
- * Create the Replicate ImageAI plugin
7
- * Supports both static credentials (OSS) and dynamic credential providers (SaaS)
8
- *
9
- * @example
10
- * // Static credentials (OSS)
11
- * imageAiPlugin(process.env.REPLICATE_API_TOKEN)
12
- *
13
- * @example
14
- * // Dynamic credentials with function (SaaS)
15
- * imageAiPlugin({
16
- * credentialProvider: (context) => Effect.succeed({ apiKey: "..." })
17
- * })
18
- *
19
- * @example
20
- * // Dynamic credentials with Effect service (SaaS)
21
- * imageAiPlugin({
22
- * useCredentialProviderService: true
23
- * })
24
- */
25
- export const imageAiPlugin = (config, options) => {
26
- // Parse configuration
27
- const isStatic = typeof config === "string";
28
- const staticApiKey = isStatic ? config : null;
29
- const credentialProvider = isStatic ? null : config.credentialProvider;
30
- const useCredentialProviderService = isStatic
31
- ? false
32
- : config.useCredentialProviderService;
33
- // Model IDs can come from either the config object or the options parameter
34
- const removeBackgroundModelId = (isStatic
35
- ? options?.removeBackgroundModelId
36
- : config.removeBackgroundModelId) ||
37
- "lucataco/remove-bg:95fcc2a26d3899cd6c2691c900465aaeff466285a65c14638cc5f36f34befaf1";
38
- const describeImageModelId = (isStatic ? options?.describeImageModelId : config.describeImageModelId) ||
39
- "zsxkib/blip-3:499bec581d8f64060fd695ec0c34d7595c6824c4118259aa8b0788e0d2d903e1";
40
- // Helper to get API token (either static, from provider function, or from service)
41
- const getApiToken = (context) => {
42
- if (staticApiKey) {
43
- return Effect.succeed(staticApiKey);
44
- }
45
- if (useCredentialProviderService) {
46
- return Effect.gen(function* () {
47
- const credentialProviderService = yield* Effect.serviceOption(CredentialProviderService);
48
- if (Option.isNone(credentialProviderService)) {
49
- return yield* Effect.fail(UploadistaError.fromCode("UNKNOWN_ERROR", {
50
- cause: new Error("Credential provider service not found"),
51
- }));
52
- }
53
- else {
54
- const credentials = yield* credentialProviderService.value.getCredential({
55
- clientId: context.clientId,
56
- serviceType: "replicate",
57
- });
58
- if (typeof credentials === "object" &&
59
- credentials !== null &&
60
- "apiKey" in credentials &&
61
- typeof credentials.apiKey === "string") {
62
- return credentials.apiKey;
63
- }
64
- }
65
- return yield* Effect.fail(UploadistaError.fromCode("UNKNOWN_ERROR", {
66
- cause: new Error("Invalid credential format from service"),
67
- }));
68
- });
69
- }
70
- if (credentialProvider) {
71
- return Effect.gen(function* () {
72
- const credentials = yield* credentialProvider({
73
- ...context,
74
- serviceType: "replicate",
75
- });
76
- return credentials.apiKey;
77
- });
78
- }
79
- return Effect.fail(UploadistaError.fromCode("UNKNOWN_ERROR", {
80
- cause: new Error("No API credentials configured"),
81
- }));
82
- };
83
- return Layer.succeed(ImageAiPlugin, ImageAiPlugin.of({
84
- removeBackground: (inputUrl, context) => {
85
- return Effect.gen(function* () {
86
- // Get API token (static or from credential provider)
87
- const apiToken = yield* getApiToken(context);
88
- const output = yield* Effect.tryPromise({
89
- try: async () => {
90
- const replicate = new Replicate({
91
- auth: apiToken,
92
- });
93
- const input = {
94
- image: inputUrl,
95
- };
96
- console.log("input", input);
97
- return (await replicate.run(removeBackgroundModelId, {
98
- input,
99
- }));
100
- },
101
- catch: (error) => {
102
- console.log("error", error);
103
- return UploadistaError.fromCode("UNKNOWN_ERROR", {
104
- cause: error,
105
- });
106
- },
107
- });
108
- return { outputUrl: output.url() };
109
- });
110
- },
111
- describeImage: (inputUrl, context) => {
112
- return Effect.gen(function* () {
113
- // Get API token (static or from credential provider)
114
- const apiToken = yield* getApiToken(context);
115
- const output = yield* Effect.tryPromise({
116
- try: async () => {
117
- const replicate = new Replicate({
118
- auth: apiToken,
119
- });
120
- return (await replicate.run(describeImageModelId, {
121
- input: {
122
- image: inputUrl,
123
- top_k: 50,
124
- top_p: 1,
125
- caption: false,
126
- question: "What is shown in the image?",
127
- do_sample: false,
128
- num_beams: 1,
129
- temperature: 1,
130
- system_prompt: "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.",
131
- length_penalty: 1,
132
- max_new_tokens: 768,
133
- repetition_penalty: 1,
134
- },
135
- }));
136
- },
137
- catch: (error) => {
138
- return UploadistaError.fromCode("UNKNOWN_ERROR", {
139
- cause: error,
140
- });
141
- },
142
- });
143
- return { description: output };
144
- });
145
- },
146
- }));
147
- };