@hautechai/sdk 1.0.3 → 1.0.5
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/.github/workflows/release.yaml +4 -53
- package/CHANGELOG.md +1 -1
- package/dist/autogenerated/api.d.ts +11397 -0
- package/dist/autogenerated/api.js +11002 -0
- package/dist/autogenerated/base.d.ts +66 -0
- package/dist/autogenerated/base.js +59 -0
- package/dist/autogenerated/common.d.ts +65 -0
- package/dist/autogenerated/common.js +133 -0
- package/dist/autogenerated/configuration.d.ts +91 -0
- package/dist/autogenerated/configuration.js +39 -0
- package/dist/autogenerated/index.d.ts +13 -0
- package/dist/autogenerated/index.js +15 -0
- package/dist/autogenerated/permissions.d.ts +94 -0
- package/dist/autogenerated/permissions.js +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/sdk/access/index.d.ts +20 -0
- package/dist/sdk/access/index.js +23 -0
- package/dist/sdk/accounts/index.d.ts +16 -0
- package/dist/sdk/accounts/index.js +25 -0
- package/dist/sdk/api.d.ts +20 -0
- package/dist/sdk/api.js +33 -0
- package/dist/sdk/balances/index.d.ts +12 -0
- package/dist/sdk/balances/index.js +19 -0
- package/dist/sdk/collections/index.d.ts +33 -0
- package/dist/sdk/collections/index.js +34 -0
- package/dist/sdk/errors/index.d.ts +3 -0
- package/dist/sdk/errors/index.js +6 -0
- package/dist/sdk/groups/index.d.ts +24 -0
- package/dist/sdk/groups/index.js +31 -0
- package/dist/sdk/images/index.d.ts +17 -0
- package/dist/sdk/images/index.js +35 -0
- package/dist/sdk/index.d.ts +1585 -0
- package/dist/sdk/index.js +69 -0
- package/dist/sdk/listeners/index.d.ts +28 -0
- package/dist/sdk/listeners/index.js +104 -0
- package/dist/sdk/operations/index.d.ts +199 -0
- package/dist/sdk/operations/index.js +133 -0
- package/dist/sdk/pipelines/index.d.ts +1189 -0
- package/dist/sdk/pipelines/index.js +208 -0
- package/dist/sdk/pipelines/pipelines.d.ts +0 -0
- package/dist/sdk/pipelines/pipelines.js +1 -0
- package/dist/sdk/poses/index.d.ts +20 -0
- package/dist/sdk/poses/index.js +24 -0
- package/dist/sdk/stacks/index.d.ts +29 -0
- package/dist/sdk/stacks/index.js +32 -0
- package/dist/sdk/storage/index.d.ts +18 -0
- package/dist/sdk/storage/index.js +27 -0
- package/dist/sdk/transformers.d.ts +7 -0
- package/dist/sdk/transformers.js +6 -0
- package/dist/sdk/utils/index.d.ts +10 -0
- package/dist/sdk/utils/index.js +6 -0
- package/dist/sdk/videos/index.d.ts +11 -0
- package/dist/sdk/videos/index.js +15 -0
- package/dist/token/index.d.ts +15 -0
- package/dist/token/index.js +65 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.js +5 -0
- package/package.json +1 -1
- package/scripts/up-versions.sh +4 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import access from './access';
|
|
2
|
+
import accounts from './accounts';
|
|
3
|
+
import balances from './balances';
|
|
4
|
+
import collections from './collections';
|
|
5
|
+
import groups from './groups';
|
|
6
|
+
import images from './images';
|
|
7
|
+
import { decodeJwt } from 'jose';
|
|
8
|
+
import operations from './operations';
|
|
9
|
+
import pipelines from './pipelines';
|
|
10
|
+
import stacks from './stacks';
|
|
11
|
+
import storage from './storage';
|
|
12
|
+
import utils from './utils';
|
|
13
|
+
import { OperationsListener } from './listeners';
|
|
14
|
+
import { getAPI, getBaseUrl } from './api';
|
|
15
|
+
import { OperationsApi } from '../autogenerated';
|
|
16
|
+
import poses from './poses';
|
|
17
|
+
import videos from './videos';
|
|
18
|
+
const replaceProtocol = (url, protocol) => {
|
|
19
|
+
const parsed = new URL(url);
|
|
20
|
+
parsed.protocol = protocol;
|
|
21
|
+
return parsed.toString();
|
|
22
|
+
};
|
|
23
|
+
export const createSDK = (options) => {
|
|
24
|
+
let token = undefined;
|
|
25
|
+
const authToken = async () => {
|
|
26
|
+
if (token) {
|
|
27
|
+
const decoded = decodeJwt(token);
|
|
28
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
29
|
+
if (decoded.exp && decoded.exp > currentTime)
|
|
30
|
+
return token;
|
|
31
|
+
}
|
|
32
|
+
token = await options.authToken();
|
|
33
|
+
return token;
|
|
34
|
+
};
|
|
35
|
+
const optionsWithTokenRefresher = { ...options, authToken };
|
|
36
|
+
const operationsListener = new OperationsListener({
|
|
37
|
+
ws: (options.useWebsocket ?? true)
|
|
38
|
+
? {
|
|
39
|
+
endpoint: (() => {
|
|
40
|
+
const baseUrl = getBaseUrl(options);
|
|
41
|
+
return replaceProtocol(baseUrl, baseUrl.startsWith('https') ? 'wss' : 'ws');
|
|
42
|
+
})(),
|
|
43
|
+
token: authToken,
|
|
44
|
+
}
|
|
45
|
+
: null,
|
|
46
|
+
// TODO: Refactor the API initialization
|
|
47
|
+
operations: () => getAPI(OperationsApi, optionsWithTokenRefresher),
|
|
48
|
+
allowPollingFallback: options.allowPollingFallback ?? true,
|
|
49
|
+
});
|
|
50
|
+
operationsListener.subscribe();
|
|
51
|
+
return {
|
|
52
|
+
access: access(optionsWithTokenRefresher),
|
|
53
|
+
accounts: accounts(optionsWithTokenRefresher),
|
|
54
|
+
balances: balances(optionsWithTokenRefresher),
|
|
55
|
+
collections: collections(optionsWithTokenRefresher),
|
|
56
|
+
groups: groups(optionsWithTokenRefresher),
|
|
57
|
+
images: images(optionsWithTokenRefresher),
|
|
58
|
+
videos: videos(optionsWithTokenRefresher),
|
|
59
|
+
operations: operations(optionsWithTokenRefresher, operationsListener),
|
|
60
|
+
pipelines: pipelines(optionsWithTokenRefresher),
|
|
61
|
+
stacks: stacks(optionsWithTokenRefresher),
|
|
62
|
+
storage: storage(optionsWithTokenRefresher),
|
|
63
|
+
utils: utils(optionsWithTokenRefresher),
|
|
64
|
+
poses: poses(optionsWithTokenRefresher),
|
|
65
|
+
close: async () => {
|
|
66
|
+
await operationsListener.close();
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OperationEntity, OperationsApi } from '../../autogenerated';
|
|
2
|
+
import { w3cwebsocket as WebSocketClient } from 'websocket';
|
|
3
|
+
export declare class OperationsListener {
|
|
4
|
+
useWebsocket: {
|
|
5
|
+
endpoint: string;
|
|
6
|
+
token: () => string | Promise<string>;
|
|
7
|
+
} | null;
|
|
8
|
+
ws: WebSocketClient | null;
|
|
9
|
+
operations: () => Promise<OperationsApi>;
|
|
10
|
+
allowPollingFallback: boolean;
|
|
11
|
+
constructor({ ws, operations, allowPollingFallback, }: {
|
|
12
|
+
ws: {
|
|
13
|
+
endpoint: string;
|
|
14
|
+
token: () => string | Promise<string>;
|
|
15
|
+
} | null;
|
|
16
|
+
operations: () => Promise<OperationsApi>;
|
|
17
|
+
allowPollingFallback: boolean;
|
|
18
|
+
});
|
|
19
|
+
operationsStore: Record<string, OperationEntity>;
|
|
20
|
+
getOperation(id: string): Promise<OperationEntity | null>;
|
|
21
|
+
private updateOperation;
|
|
22
|
+
subscribe(): Promise<void>;
|
|
23
|
+
onOpen(): void;
|
|
24
|
+
websocketEnabled(): boolean;
|
|
25
|
+
onMessage(msg: string): void;
|
|
26
|
+
onClose(number: number, reason: string): void;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { w3cwebsocket as WebSocketClient } from 'websocket';
|
|
2
|
+
import { HautechError } from '../errors';
|
|
3
|
+
// This is pretty much a dirty solution until we need to rework this part.
|
|
4
|
+
export class OperationsListener {
|
|
5
|
+
constructor({ ws, operations, allowPollingFallback = false, }) {
|
|
6
|
+
this.useWebsocket = null;
|
|
7
|
+
this.ws = null;
|
|
8
|
+
this.operationsStore = {};
|
|
9
|
+
if (!ws)
|
|
10
|
+
allowPollingFallback = true;
|
|
11
|
+
if (ws) {
|
|
12
|
+
this.useWebsocket = {
|
|
13
|
+
endpoint: ws?.endpoint,
|
|
14
|
+
token: ws?.token,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
this.operations = operations;
|
|
18
|
+
this.allowPollingFallback = allowPollingFallback;
|
|
19
|
+
}
|
|
20
|
+
async getOperation(id) {
|
|
21
|
+
const fallbackToPolling = this.allowPollingFallback && !(this.ws?.readyState === WebSocketClient.OPEN);
|
|
22
|
+
if (!this.operationsStore[id] || fallbackToPolling) {
|
|
23
|
+
const api = await this.operations();
|
|
24
|
+
const operation = await api.operationsControllerGetOperationV1(id);
|
|
25
|
+
if (operation.status == 200)
|
|
26
|
+
this.updateOperation(id, operation.data);
|
|
27
|
+
}
|
|
28
|
+
return this.operationsStore[id] || null;
|
|
29
|
+
}
|
|
30
|
+
updateOperation(id, operation) {
|
|
31
|
+
const stored = this.operationsStore[id];
|
|
32
|
+
if (!stored || stored.updatedAt < operation.updatedAt) {
|
|
33
|
+
this.operationsStore[id] = operation;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async subscribe() {
|
|
37
|
+
if (!this.useWebsocket)
|
|
38
|
+
return;
|
|
39
|
+
try {
|
|
40
|
+
const token = await this.useWebsocket.token();
|
|
41
|
+
this.ws = new WebSocketClient(this.useWebsocket.endpoint, ['1', token]);
|
|
42
|
+
this.ws.onopen = () => {
|
|
43
|
+
this.onOpen();
|
|
44
|
+
};
|
|
45
|
+
this.ws.onerror = (err) => {
|
|
46
|
+
console.error('HautechAI SDK encountered a WebSocket error: ', err);
|
|
47
|
+
};
|
|
48
|
+
this.ws.onmessage = (msg) => {
|
|
49
|
+
if (typeof msg.data === 'string') {
|
|
50
|
+
this.onMessage(msg.data);
|
|
51
|
+
}
|
|
52
|
+
else if (msg.data instanceof Buffer) {
|
|
53
|
+
this.onMessage(msg.data.toString('utf8'));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.onMessage(Buffer.from(msg.data).toString('utf8'));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
this.ws.onclose = (event) => {
|
|
60
|
+
this.onClose(event.code, event.reason);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
throw new HautechError(`SDK failed to open websocket: ${err}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
onOpen() {
|
|
68
|
+
if (!this.ws)
|
|
69
|
+
throw new HautechError('Semantics error: this is a bug.');
|
|
70
|
+
this.ws.send(JSON.stringify({
|
|
71
|
+
event: 'subscribe',
|
|
72
|
+
data: {
|
|
73
|
+
channel: 'own_resources',
|
|
74
|
+
},
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
websocketEnabled() {
|
|
78
|
+
return this.ws?.readyState === WebSocketClient.OPEN;
|
|
79
|
+
}
|
|
80
|
+
onMessage(msg) {
|
|
81
|
+
if (!this.ws)
|
|
82
|
+
throw new HautechError('Semantics error: this is a bug.');
|
|
83
|
+
const { event, data } = JSON.parse(msg);
|
|
84
|
+
switch (event) {
|
|
85
|
+
case 'subscription:created':
|
|
86
|
+
break;
|
|
87
|
+
case 'operation:created':
|
|
88
|
+
case 'operation:updated':
|
|
89
|
+
this.updateOperation(data.id, data);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
onClose(number, reason) {
|
|
94
|
+
if (!this.ws)
|
|
95
|
+
throw new HautechError('Semantics error: this is a bug.');
|
|
96
|
+
// Reset dirty state.
|
|
97
|
+
this.operationsStore = {};
|
|
98
|
+
this.ws = null;
|
|
99
|
+
}
|
|
100
|
+
async close() {
|
|
101
|
+
this.ws?.close();
|
|
102
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { AnimateKling16ProV1Input, AnimateKling16ProV1Response, AnimateKling21V1Input, AnimateKling21V1Response, CompositeV1Input, CompositeV1Response, ContrastV1Input, ContrastV1Response, CropV1Input, CropV1Response, CutV1Input, CutV1Response, EditFluxKontextDevV1Input, EditFluxKontextDevV1Response, GiseleVtonV1Input, GPTV1Input, GptV1Response, GPTV2Input, GptV2Response, HauteLindaV1Response, HauteNaomiV1Response, ImagineKateV1Response, KateImagineV1Input, KateInpaintV1Input, LindaHauteV1Input, MathV1Input, MathV1Response, NaomiHauteV1Input, NegateImageV1Input, NegateImageV1Response, NoiseV1Input, NoiseV1Response, ObjectDetectionV1Input, ObjectDetectionV1Response, OperationEntity, OperationEntityStatusEnum, PoseEstimationV1Input, PoseEstimationV1Response, ResizeV1Input, ResizeV1Response, SegmentAnythingEmbeddingsV1Input, SegmentAnythingEmbeddingsV1Response, SegmentAnythingMaskV1Input, SegmentAnythingMaskV1Response, StringsTemplateV1Input, StringsTemplateV1Response, TranslateV1Input, TranslateV1Response, UpscaleV1Input, UpscaleV1Response, VtonGiseleV1Response } from '../../autogenerated';
|
|
2
|
+
import { ListProps, ListResponse, SDKOptions } from '../../types';
|
|
3
|
+
import { OperationMetadata } from '../index';
|
|
4
|
+
import { OperationsListener } from '../listeners';
|
|
5
|
+
import { AddMetadata } from '../utils';
|
|
6
|
+
type OperationEntityWithMetadata = AddMetadata<OperationEntity, OperationMetadata>;
|
|
7
|
+
type Waited<T extends OperationEntityWithMetadata> = T & ({
|
|
8
|
+
status: typeof OperationEntityStatusEnum.Failed;
|
|
9
|
+
output: null;
|
|
10
|
+
} | {
|
|
11
|
+
status: typeof OperationEntityStatusEnum.Pending;
|
|
12
|
+
output: null;
|
|
13
|
+
} | {
|
|
14
|
+
status: typeof OperationEntityStatusEnum.Finished;
|
|
15
|
+
output: NonNullable<T['output']>;
|
|
16
|
+
});
|
|
17
|
+
declare const operations: (options: SDKOptions, operationsListener: OperationsListener) => {
|
|
18
|
+
run: {
|
|
19
|
+
animate: {
|
|
20
|
+
kling_1_6_pro: {
|
|
21
|
+
v1: (props: {
|
|
22
|
+
input: AnimateKling16ProV1Input;
|
|
23
|
+
metadata?: any;
|
|
24
|
+
}) => Promise<AnimateKling16ProV1Response>;
|
|
25
|
+
};
|
|
26
|
+
kling_2_1: {
|
|
27
|
+
v1: (props: {
|
|
28
|
+
input: AnimateKling21V1Input;
|
|
29
|
+
metadata?: any;
|
|
30
|
+
}) => Promise<AnimateKling21V1Response>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
edit: {
|
|
34
|
+
flux_kontext_dev: {
|
|
35
|
+
v1: (props: {
|
|
36
|
+
input: EditFluxKontextDevV1Input;
|
|
37
|
+
metadata?: any;
|
|
38
|
+
}) => Promise<EditFluxKontextDevV1Response>;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
haute: {
|
|
42
|
+
linda: {
|
|
43
|
+
v1: (props: {
|
|
44
|
+
input: LindaHauteV1Input;
|
|
45
|
+
metadata?: any;
|
|
46
|
+
}) => Promise<HauteLindaV1Response>;
|
|
47
|
+
};
|
|
48
|
+
naomi: {
|
|
49
|
+
v1: (props: {
|
|
50
|
+
input: NaomiHauteV1Input;
|
|
51
|
+
metadata?: any;
|
|
52
|
+
}) => Promise<HauteNaomiV1Response>;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
inpaint: {
|
|
56
|
+
kate: {
|
|
57
|
+
v1: (props: {
|
|
58
|
+
input: KateInpaintV1Input;
|
|
59
|
+
metadata?: any;
|
|
60
|
+
}) => Promise<ImagineKateV1Response>;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
gpt: {
|
|
64
|
+
v1: (props: {
|
|
65
|
+
input: GPTV1Input;
|
|
66
|
+
metadata?: any;
|
|
67
|
+
}) => Promise<GptV1Response>;
|
|
68
|
+
v2: (props: {
|
|
69
|
+
input: GPTV2Input;
|
|
70
|
+
metadata?: any;
|
|
71
|
+
}) => Promise<GptV2Response>;
|
|
72
|
+
};
|
|
73
|
+
math: {
|
|
74
|
+
v1: (props: {
|
|
75
|
+
input: MathV1Input;
|
|
76
|
+
metadata?: any;
|
|
77
|
+
}) => Promise<MathV1Response>;
|
|
78
|
+
};
|
|
79
|
+
translate: {
|
|
80
|
+
v1: (props: {
|
|
81
|
+
input: TranslateV1Input;
|
|
82
|
+
metadata?: any;
|
|
83
|
+
}) => Promise<TranslateV1Response>;
|
|
84
|
+
};
|
|
85
|
+
imagine: {
|
|
86
|
+
kate: {
|
|
87
|
+
v1: (props: {
|
|
88
|
+
input: KateImagineV1Input;
|
|
89
|
+
metadata?: any;
|
|
90
|
+
}) => Promise<ImagineKateV1Response>;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
upscale: {
|
|
94
|
+
v1: (props: {
|
|
95
|
+
input: UpscaleV1Input;
|
|
96
|
+
metadata?: any;
|
|
97
|
+
}) => Promise<UpscaleV1Response>;
|
|
98
|
+
};
|
|
99
|
+
objectDetection: {
|
|
100
|
+
v1: (props: {
|
|
101
|
+
input: ObjectDetectionV1Input;
|
|
102
|
+
metadata?: any;
|
|
103
|
+
}) => Promise<ObjectDetectionV1Response>;
|
|
104
|
+
};
|
|
105
|
+
segmentAnything: {
|
|
106
|
+
embeddings: {
|
|
107
|
+
v1: (props: {
|
|
108
|
+
input: SegmentAnythingEmbeddingsV1Input;
|
|
109
|
+
metadata?: any;
|
|
110
|
+
}) => Promise<SegmentAnythingEmbeddingsV1Response>;
|
|
111
|
+
};
|
|
112
|
+
mask: {
|
|
113
|
+
v1: (props: {
|
|
114
|
+
input: SegmentAnythingMaskV1Input;
|
|
115
|
+
metadata?: any;
|
|
116
|
+
}) => Promise<SegmentAnythingMaskV1Response>;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
poseEstimation: {
|
|
120
|
+
v1: (props: {
|
|
121
|
+
input: PoseEstimationV1Input;
|
|
122
|
+
metadata?: any;
|
|
123
|
+
}) => Promise<PoseEstimationV1Response>;
|
|
124
|
+
};
|
|
125
|
+
cut: {
|
|
126
|
+
v1: (props: {
|
|
127
|
+
input: CutV1Input;
|
|
128
|
+
metadata?: any;
|
|
129
|
+
}) => Promise<CutV1Response>;
|
|
130
|
+
};
|
|
131
|
+
crop: {
|
|
132
|
+
v1: (props: {
|
|
133
|
+
input: CropV1Input;
|
|
134
|
+
metadata?: any;
|
|
135
|
+
}) => Promise<CropV1Response>;
|
|
136
|
+
};
|
|
137
|
+
noise: {
|
|
138
|
+
v1: (props: {
|
|
139
|
+
input: NoiseV1Input;
|
|
140
|
+
metadata?: any;
|
|
141
|
+
}) => Promise<NoiseV1Response>;
|
|
142
|
+
};
|
|
143
|
+
contrast: {
|
|
144
|
+
v1: (props: {
|
|
145
|
+
input: ContrastV1Input;
|
|
146
|
+
metadata?: any;
|
|
147
|
+
}) => Promise<ContrastV1Response>;
|
|
148
|
+
};
|
|
149
|
+
composite: {
|
|
150
|
+
v1: (props: {
|
|
151
|
+
input: CompositeV1Input;
|
|
152
|
+
metadata?: any;
|
|
153
|
+
}) => Promise<CompositeV1Response>;
|
|
154
|
+
};
|
|
155
|
+
vton: {
|
|
156
|
+
gisele: {
|
|
157
|
+
v1: (props: {
|
|
158
|
+
input: GiseleVtonV1Input;
|
|
159
|
+
metadata?: any;
|
|
160
|
+
}) => Promise<VtonGiseleV1Response>;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
negateImage: {
|
|
164
|
+
v1: (props: {
|
|
165
|
+
input: NegateImageV1Input;
|
|
166
|
+
metadata?: any;
|
|
167
|
+
}) => Promise<NegateImageV1Response>;
|
|
168
|
+
};
|
|
169
|
+
resize: {
|
|
170
|
+
v1: (props: {
|
|
171
|
+
input: ResizeV1Input;
|
|
172
|
+
metadata?: any;
|
|
173
|
+
}) => Promise<ResizeV1Response>;
|
|
174
|
+
};
|
|
175
|
+
strings: {
|
|
176
|
+
template: {
|
|
177
|
+
v1: (props: {
|
|
178
|
+
input: StringsTemplateV1Input;
|
|
179
|
+
metadata?: any;
|
|
180
|
+
}) => Promise<StringsTemplateV1Response>;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
get: (props: {
|
|
185
|
+
id: string;
|
|
186
|
+
}) => Promise<OperationEntityWithMetadata | undefined>;
|
|
187
|
+
getMany: (props: {
|
|
188
|
+
ids: string[];
|
|
189
|
+
}) => Promise<OperationEntityWithMetadata[]>;
|
|
190
|
+
list: (props?: ListProps) => Promise<ListResponse<OperationEntityWithMetadata>>;
|
|
191
|
+
updateMetadata: (props: {
|
|
192
|
+
id: string;
|
|
193
|
+
metadata?: any;
|
|
194
|
+
}) => Promise<void>;
|
|
195
|
+
wait: <T extends OperationEntityWithMetadata | {
|
|
196
|
+
id: string;
|
|
197
|
+
}, N extends number | undefined = undefined>(props: T, timeoutMs?: N) => Promise<Waited<T extends OperationEntityWithMetadata ? T : OperationEntityWithMetadata> | (N extends undefined ? never : null)>;
|
|
198
|
+
};
|
|
199
|
+
export default operations;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { OperationsApi, } from '../../autogenerated';
|
|
2
|
+
import { useAutogeneratedAPI } from '../api';
|
|
3
|
+
import { transformToListResponse } from '../transformers';
|
|
4
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
const operations = (options, operationsListener) => {
|
|
6
|
+
const api = useAutogeneratedAPI({ API: OperationsApi, options });
|
|
7
|
+
const createOperation = (callMethod) => (props) => api.call({ run: (methods) => callMethod(methods, props) });
|
|
8
|
+
return {
|
|
9
|
+
run: {
|
|
10
|
+
animate: {
|
|
11
|
+
kling_1_6_pro: {
|
|
12
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunAnimateKling16ProV1V1(props)),
|
|
13
|
+
},
|
|
14
|
+
kling_2_1: {
|
|
15
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunAnimateKling21V1V1(props)),
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
edit: {
|
|
19
|
+
flux_kontext_dev: {
|
|
20
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunEditFluxKontextDevV1V1(props)),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
haute: {
|
|
24
|
+
linda: {
|
|
25
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunHauteLindaV1V1(props)),
|
|
26
|
+
},
|
|
27
|
+
naomi: {
|
|
28
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunHauteNaomiV1V1(props)),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
inpaint: {
|
|
32
|
+
kate: {
|
|
33
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunInpaintKateV1V1(props)),
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
gpt: {
|
|
37
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunGptV1V1(props)),
|
|
38
|
+
v2: createOperation((methods, props) => methods.operationsControllerRunGptV2V1(props)),
|
|
39
|
+
},
|
|
40
|
+
math: {
|
|
41
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunMathV1V1(props)),
|
|
42
|
+
},
|
|
43
|
+
translate: {
|
|
44
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunTranslateV1V1(props)),
|
|
45
|
+
},
|
|
46
|
+
imagine: {
|
|
47
|
+
kate: {
|
|
48
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunImagineKateV1V1(props)),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
upscale: {
|
|
52
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunUpscaleV1V1(props)),
|
|
53
|
+
},
|
|
54
|
+
objectDetection: {
|
|
55
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunObjectDetectionV1V1(props)),
|
|
56
|
+
},
|
|
57
|
+
segmentAnything: {
|
|
58
|
+
embeddings: {
|
|
59
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunSegmentAnythingEmbeddingsV1V1(props)),
|
|
60
|
+
},
|
|
61
|
+
mask: {
|
|
62
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunSegmentAnythingMaskV1V1(props)),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
poseEstimation: {
|
|
66
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunPoseEstimationV1V1(props)),
|
|
67
|
+
},
|
|
68
|
+
cut: {
|
|
69
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunCutV1V1(props)),
|
|
70
|
+
},
|
|
71
|
+
crop: {
|
|
72
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunCropV1V1(props)),
|
|
73
|
+
},
|
|
74
|
+
noise: {
|
|
75
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunNoiseV1V1(props)),
|
|
76
|
+
},
|
|
77
|
+
contrast: {
|
|
78
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunContrastV1V1(props)),
|
|
79
|
+
},
|
|
80
|
+
composite: {
|
|
81
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunCompositeV1V1(props)),
|
|
82
|
+
},
|
|
83
|
+
vton: {
|
|
84
|
+
gisele: {
|
|
85
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunVtonGiseleV1V1(props)),
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
negateImage: {
|
|
89
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunNegateImageV1V1(props)),
|
|
90
|
+
},
|
|
91
|
+
resize: {
|
|
92
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunResizeV1V1(props)),
|
|
93
|
+
},
|
|
94
|
+
strings: {
|
|
95
|
+
template: {
|
|
96
|
+
v1: createOperation((methods, props) => methods.operationsControllerRunStringsTemplateV1V1(props)),
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
get: (props) => api.callWithReturningUndefinedOn404({
|
|
101
|
+
run: (methods) => methods.operationsControllerGetOperationV1(props.id),
|
|
102
|
+
}),
|
|
103
|
+
getMany: (props) => api.call({
|
|
104
|
+
run: (methods) => methods.operationsControllerGetOperationsV1({ ids: props.ids }),
|
|
105
|
+
}),
|
|
106
|
+
list: (props = {}) => api.call({
|
|
107
|
+
run: (methods) => methods.operationsControllerListOperationsV1(props.orderBy, props.limit, props.cursor),
|
|
108
|
+
transform: transformToListResponse,
|
|
109
|
+
}),
|
|
110
|
+
updateMetadata: async (props) => api.call({
|
|
111
|
+
run: (methods) => methods.operationsControllerUpdateMetadataV1(props.id, { overwrite: props.metadata }),
|
|
112
|
+
}),
|
|
113
|
+
wait: async (props, timeoutMs) => {
|
|
114
|
+
const deadline = timeoutMs ? Date.now() + timeoutMs : undefined;
|
|
115
|
+
const delay = operationsListener.websocketEnabled() ? 50 : 1000;
|
|
116
|
+
const poll = async (id) => {
|
|
117
|
+
const operation = await operationsListener.getOperation(id);
|
|
118
|
+
if (operation?.status !== 'pending')
|
|
119
|
+
return operation;
|
|
120
|
+
return null;
|
|
121
|
+
};
|
|
122
|
+
while (!deadline || Date.now() < deadline) {
|
|
123
|
+
const polled = await poll(props.id);
|
|
124
|
+
if (polled)
|
|
125
|
+
return polled;
|
|
126
|
+
await sleep(delay);
|
|
127
|
+
}
|
|
128
|
+
//@ts-expect-error - can't be reached if timeoutMs is defined.
|
|
129
|
+
return null;
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
export default operations;
|