nickkao commited on
Commit
97369e8
·
1 Parent(s): d822271

move to npm package

Browse files
bun.lockb CHANGED
Binary files a/bun.lockb and b/bun.lockb differ
 
package.json CHANGED
@@ -17,6 +17,7 @@
17
  "@radix-ui/react-tabs": "^1.0.4",
18
  "class-variance-authority": "^0.7.0",
19
  "clsx": "^2.1.0",
 
20
  "lucide-react": "^0.309.0",
21
  "next": "14.0.3",
22
  "react": "^18",
 
17
  "@radix-ui/react-tabs": "^1.0.4",
18
  "class-variance-authority": "^0.7.0",
19
  "clsx": "^2.1.0",
20
+ "comfydeploy": "^0.0.11",
21
  "lucide-react": "^0.309.0",
22
  "next": "14.0.3",
23
  "react": "^18",
src/app/page.tsx CHANGED
@@ -5,7 +5,6 @@ import { Button } from "@/components/ui/button";
5
  import { Card, CardContent, CardHeader } from "@/components/ui/card";
6
  import { Input } from "@/components/ui/input";
7
  import { Label } from "@/components/ui/label";
8
- import { Skeleton } from "@/components/ui/skeleton";
9
  import {
10
  checkStatus,
11
  generate,
@@ -24,7 +23,6 @@ import {
24
  SelectTrigger,
25
  SelectValue,
26
  } from "@/components/ui/select";
27
- import { Separator } from "@/components/ui/separator";
28
 
29
  import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
30
  import { ImageGenerationResult } from "@/components/ImageGenerationResult";
 
5
  import { Card, CardContent, CardHeader } from "@/components/ui/card";
6
  import { Input } from "@/components/ui/input";
7
  import { Label } from "@/components/ui/label";
 
8
  import {
9
  checkStatus,
10
  generate,
 
23
  SelectTrigger,
24
  SelectValue,
25
  } from "@/components/ui/select";
 
26
 
27
  import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
28
  import { ImageGenerationResult } from "@/components/ImageGenerationResult";
src/lib/comfy-deploy.ts DELETED
@@ -1,133 +0,0 @@
1
- import { z } from "zod";
2
-
3
- const runTypes = z.object({
4
- run_id: z.string(),
5
- });
6
-
7
- const runOutputTypes = z.object({
8
- id: z.string(),
9
- status: z.enum(["success", "failed", "running", "uploading", "not-started"]),
10
- outputs: z.array(
11
- z.object({
12
- data: z.any(),
13
- }),
14
- ),
15
- });
16
-
17
- const uploadFileTypes = z.object({
18
- upload_url: z.string(),
19
- file_id: z.string(),
20
- download_url: z.string(),
21
- });
22
-
23
- export class ComfyDeployClient {
24
- apiBase: string = "https://www.comfydeploy.com/api";
25
- apiToken: string;
26
-
27
- constructor({ apiBase, apiToken }: { apiBase?: string; apiToken: string }) {
28
- if (apiBase) {
29
- this.apiBase = `${apiBase}/api`;
30
- }
31
- this.apiToken = apiToken;
32
- }
33
-
34
- async run({
35
- deployment_id,
36
- inputs,
37
- }: {
38
- deployment_id: string;
39
- inputs?: Record<string, string>;
40
- }) {
41
- return fetch(`${this.apiBase}/run`, {
42
- method: "POST",
43
- headers: {
44
- "Content-Type": "application/json",
45
- authorization: `Bearer ${this.apiToken}`,
46
- },
47
- body: JSON.stringify({
48
- deployment_id: deployment_id,
49
- inputs: inputs,
50
- }),
51
- cache: "no-store",
52
- })
53
- .then((response) => {
54
- console.log('response', response)
55
- return response.json()})
56
- .then((json) => {
57
- console.log('json', json)
58
- return runTypes.parse(json)})
59
- .catch((err) => {
60
- console.error('err', err);
61
- return null;
62
- });
63
- }
64
-
65
- async getRun(run_id: string) {
66
- return await fetch(`${this.apiBase}/run?run_id=${run_id}`, {
67
- method: "GET",
68
- headers: {
69
- "Content-Type": "application/json",
70
- authorization: `Bearer ${this.apiToken}`,
71
- },
72
- cache: "no-store",
73
- })
74
- .then((response) => response.json())
75
- .then((json) => runOutputTypes.parse(json))
76
- .catch((err) => {
77
- console.error(err);
78
- return null;
79
- });
80
- }
81
-
82
- async runSync(props: {
83
- deployment_id: string;
84
- inputs?: Record<string, string>;
85
- }) {
86
- const runResult = await this.run(props);
87
- if (!runResult) return null;
88
-
89
- // 5 minutes
90
- const timeout = 60 * 5;
91
- const interval = 1000;
92
-
93
- let run: Awaited<ReturnType<typeof this.getRun>> = null;
94
- for (let i = 0; i < timeout; i++) {
95
- run = await this.getRun(runResult.run_id);
96
- if (run && run.status == "success") {
97
- break;
98
- }
99
- await new Promise((resolve) => setTimeout(resolve, interval));
100
- }
101
-
102
- if (!run) {
103
- return {
104
- id: runResult.run_id,
105
- };
106
- }
107
-
108
- return run;
109
- }
110
-
111
- async getUploadUrl(type: string, file_size: number) {
112
- const obj = {
113
- type: type,
114
- file_size: file_size.toString(),
115
- };
116
- const url = new URL(`${this.apiBase}/upload-url`);
117
- url.search = new URLSearchParams(obj).toString();
118
-
119
- return await fetch(url.href, {
120
- method: "GET",
121
- headers: {
122
- authorization: `Bearer ${this.apiToken}`,
123
- },
124
- cache: "no-store",
125
- })
126
- .then((response) => response.json())
127
- .then((json) => uploadFileTypes.parse(json))
128
- .catch((err) => {
129
- console.error(err);
130
- return null;
131
- });
132
- }
133
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/server/generate.tsx CHANGED
@@ -1,6 +1,6 @@
1
  "use server"
2
 
3
- import { ComfyDeployClient } from "@/lib/comfy-deploy"
4
 
5
  const client = new ComfyDeployClient({
6
  apiBase: process.env.COMFY_API_URL,
 
1
  "use server"
2
 
3
+ import { ComfyDeployClient } from "comfydeploy"
4
 
5
  const client = new ComfyDeployClient({
6
  apiBase: process.env.COMFY_API_URL,