@picsart/ai-sdk 1.152.1 → 3.17.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/LICENSE +21 -0
- package/README.md +222 -0
- package/_vendor/pa-model-pricing-sdk/index.d.ts +6 -0
- package/_vendor/pa-model-pricing-sdk/lib/ModelPricingClient.d.ts +30 -0
- package/_vendor/pa-model-pricing-sdk/lib/errors/ModelPricingClientError.d.ts +5 -0
- package/_vendor/pa-model-pricing-sdk/lib/errors/ModelPricingServerError.d.ts +3 -0
- package/_vendor/pa-model-pricing-sdk/lib/errors/ModelPricingUnknownError.d.ts +3 -0
- package/_vendor/pa-model-pricing-sdk/lib/types.d.ts +94 -0
- package/_vendor/workflows-client/index.d.ts +131 -0
- package/_vendor/workflows-types/index.d.ts +9327 -0
- package/index.d.ts +1190 -467
- package/index.js +6086 -2817
- package/package.json +18 -17
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Picsart, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# @picsart/ai-sdk
|
|
2
|
+
|
|
3
|
+
Generate images, videos, and audio with 100+ AI models.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
Interactive guides deployed via GitLab Pages:
|
|
8
|
+
|
|
9
|
+
- [SDK Guide](https://picsart.gitlab.io/web/miniapp-projects/ai-toolkit/sdk_guide.html) -- Usage examples, client setup, model registry, Drive integration, and full API reference
|
|
10
|
+
- [CLI Guide](https://picsart.gitlab.io/web/miniapp-projects/ai-toolkit/cli_guide.html) -- Commands, flags, interactive mode, scripting, batch processing, and troubleshooting
|
|
11
|
+
|
|
12
|
+
Source: [`sdk_guide.html`](sdk_guide.html)
|
|
13
|
+
|
|
14
|
+
Repository: [gitlab.com/picsart/backend/Editor/external-ai-integrations/pa-gen-ai-sdk](https://gitlab.com/picsart/backend/Editor/external-ai-integrations/pa-gen-ai-sdk)
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @picsart/ai-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { createClient, Models, Model, catalog } from '@picsart/ai-sdk'
|
|
24
|
+
|
|
25
|
+
// Create a client — pass your authenticated fetch
|
|
26
|
+
const ai = createClient({
|
|
27
|
+
fetch: myAuthenticatedFetch,
|
|
28
|
+
apiUrl: 'https://api.picsart.com',
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// Generate (Models.* are typed model-id constants)
|
|
32
|
+
const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat on mars' })
|
|
33
|
+
console.log(result.url)
|
|
34
|
+
|
|
35
|
+
// Browse models — the `catalog` accessor
|
|
36
|
+
catalog.all() // every model
|
|
37
|
+
catalog.find({ output: 'video' }) // video models only
|
|
38
|
+
catalog.search('kling') // search by name/id/provider
|
|
39
|
+
|
|
40
|
+
// Model metadata & params — the `Model` accessor
|
|
41
|
+
Model(Models.Flux2Pro).name // 'Flux 2 Pro'
|
|
42
|
+
Model(Models.Flux2Pro).meta() // mode, provider, badges, …
|
|
43
|
+
Model(Models.Flux2Pro).params() // accepted parameters
|
|
44
|
+
Model(Models.Flux2Pro).params().toSchema() // param schema
|
|
45
|
+
|
|
46
|
+
// Validate input (never throws) → { valid, errors? }
|
|
47
|
+
Model(Models.Flux2Pro).validate({ prompt: 'a cat' })
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Drive Integration
|
|
51
|
+
|
|
52
|
+
Auto-save generations to Picsart Drive:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const ai = createClient({
|
|
56
|
+
fetch: myAuthenticatedFetch,
|
|
57
|
+
apiUrl: 'https://api.picsart.com',
|
|
58
|
+
drive: { folder: 'AI Playground' },
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Generates and auto-saves to the root folder
|
|
62
|
+
const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat' })
|
|
63
|
+
// result.drive = { uid: '...', folder: { name: 'AI Playground', uid: '...' } }
|
|
64
|
+
|
|
65
|
+
// Save to a subfolder
|
|
66
|
+
const board = await ai.drive.ensureFolder('Cats')
|
|
67
|
+
const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat' }, { folder: board })
|
|
68
|
+
|
|
69
|
+
// Browse Drive
|
|
70
|
+
const folders = await ai.drive.folders()
|
|
71
|
+
const items = await ai.drive.list()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Text Generation (LLMs)
|
|
75
|
+
|
|
76
|
+
Claude, GPT, and Gemini text models are called with `generateText()`. Single-shot:
|
|
77
|
+
pass a prompt and optional image(s)/video, get text back. They surface in the catalog
|
|
78
|
+
as `mode: 'text'`. Each vendor uses its own native workflow, so capabilities aren't lost
|
|
79
|
+
— Gemini accepts video input, Claude uses the Anthropic-native messages API.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { createClient, Models } from '@picsart/ai-sdk'
|
|
83
|
+
|
|
84
|
+
const ai = createClient({ fetch: myAuthenticatedFetch, apiUrl: 'https://api.picsart.com' })
|
|
85
|
+
|
|
86
|
+
// Text in, text out
|
|
87
|
+
const { text } = await ai.generateText(Models.ClaudeOpus48, { prompt: 'Explain RAG in one line.' })
|
|
88
|
+
console.log(text)
|
|
89
|
+
|
|
90
|
+
// Optional vision input + reasoning level (OpenAI / Gemini)
|
|
91
|
+
const res = await ai.generateText(Models.Gpt55, {
|
|
92
|
+
prompt: 'What is in this image?',
|
|
93
|
+
imageUrls: ['https://cdn.example.com/photo.jpg'],
|
|
94
|
+
thinking: 'high', // 'off' | 'low' | 'medium' | 'high'
|
|
95
|
+
})
|
|
96
|
+
console.log(res.text)
|
|
97
|
+
console.log(res.raw) // full backend response — usage, finish_reason, etc.
|
|
98
|
+
|
|
99
|
+
// Gemini accepts video input
|
|
100
|
+
await ai.generateText(Models.Gemini3Pro, {
|
|
101
|
+
prompt: 'Summarize this clip',
|
|
102
|
+
videoUrl: 'https://cdn.example.com/clip.mp4',
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
// Browse text models
|
|
106
|
+
catalog.find({ output: 'text' })
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
> Thinking level maps per vendor: OpenAI → `reasoning_effort`, Gemini →
|
|
110
|
+
> `thinkingConfig.thinkingLevel` (LOW/HIGH). Claude’s `claude/v1/messages`
|
|
111
|
+
> workflow exposes no thinking knob, so Claude models omit `thinking`.
|
|
112
|
+
|
|
113
|
+
`generateText()` is type-narrowed to text models (`TextModelId`); calling it with an
|
|
114
|
+
image/video model throws, and `generate()` throws on a text model — use the matching
|
|
115
|
+
method for each.
|
|
116
|
+
|
|
117
|
+
## Advanced Lifecycle
|
|
118
|
+
|
|
119
|
+
For progress tracking, cancellation, and job recovery:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Submit without waiting
|
|
123
|
+
const handle = await ai.submit(Models.KlingV3Pro, { prompt: 'a sunset' })
|
|
124
|
+
|
|
125
|
+
// Subscribe to status updates
|
|
126
|
+
for await (const update of ai.subscribe(handle)) {
|
|
127
|
+
console.log(update.status, update.progress?.percent)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Or poll manually
|
|
131
|
+
const status = await ai.status(handle)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Public API
|
|
135
|
+
|
|
136
|
+
The SDK exports 7 symbols:
|
|
137
|
+
|
|
138
|
+
| Export | Type | Description |
|
|
139
|
+
|--------|------|-------------|
|
|
140
|
+
| `createClient` | function | Create an AI client from authenticated fetch |
|
|
141
|
+
| `Models` | object | Model catalog: 108 models + list/search/validate/toSchema |
|
|
142
|
+
| `GenerateResult` | type | `{ url, model, handle, drive? }` |
|
|
143
|
+
| `ClientConfig` | type | `{ fetch, apiUrl, drive? }` |
|
|
144
|
+
| `AuthenticatedFetch` | type | `(url, init?) => Promise<Response>` |
|
|
145
|
+
| `SdkTransport` | type | Advanced: custom transport interface |
|
|
146
|
+
| `WorkflowJobHandle` | type | Job handle for submit/status/cancel |
|
|
147
|
+
|
|
148
|
+
## Package Structure
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
packages/ai-sdk/
|
|
152
|
+
package.json
|
|
153
|
+
tsconfig.json
|
|
154
|
+
tsup.config.ts
|
|
155
|
+
src/
|
|
156
|
+
index.ts # Public API entry (7 exports)
|
|
157
|
+
client/
|
|
158
|
+
types.ts # ClientConfig, GenerateResult, DriveConfig
|
|
159
|
+
transport.ts # Authenticated fetch → SdkTransport
|
|
160
|
+
prepare.ts # Validate input, build payload, parse result
|
|
161
|
+
drive.ts # Drive folder management + file saving
|
|
162
|
+
index.ts # createClient() factory
|
|
163
|
+
core/
|
|
164
|
+
types.ts # ModelDefinition, ParamConfig, GenerationContext
|
|
165
|
+
workflow.ts # Generic polling/execution engine
|
|
166
|
+
contracts.ts # Runtime input validation
|
|
167
|
+
schema.ts # ParamConfig → JSON Schema
|
|
168
|
+
response.ts # Vendor-agnostic result extraction
|
|
169
|
+
pricing.ts # ToolId resolution
|
|
170
|
+
model-registry.ts # Model lookup indexes
|
|
171
|
+
providers.ts # Provider colors, labels, names
|
|
172
|
+
voices.ts # Voice catalogs (ElevenLabs, OpenAI, Gemini)
|
|
173
|
+
helpers.ts # Vendor utilities
|
|
174
|
+
generated/
|
|
175
|
+
model-constants.ts # AUTO-GENERATED: Models object + 108 constants
|
|
176
|
+
model-input-types.ts # AUTO-GENERATED: per-model TypeScript input types
|
|
177
|
+
vendors/
|
|
178
|
+
define.ts # defineModels() framework + params.* helpers
|
|
179
|
+
presets.ts # Reusable paramConfig factories
|
|
180
|
+
catalog/
|
|
181
|
+
index.ts # Aggregation: ALL_MODELS, VENDOR_CATALOGS
|
|
182
|
+
kling.ts # One file per vendor (31 total)
|
|
183
|
+
flux.ts
|
|
184
|
+
...
|
|
185
|
+
__tests__/ # SDK tests
|
|
186
|
+
scripts/ # Build scripts
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Adding a New Model
|
|
190
|
+
|
|
191
|
+
### Standard flow (pass-through payload)
|
|
192
|
+
|
|
193
|
+
When the backend accepts param values as-is (no field renaming needed):
|
|
194
|
+
|
|
195
|
+
1. Add config in `src/vendors/catalog/{vendor}.ts` via `defineModels()`:
|
|
196
|
+
- `buildPayload` is **optional** — omit it and param values pass through as-is
|
|
197
|
+
2. Run `npm run build:model-constants` to regenerate constants
|
|
198
|
+
3. Run `npm run build:model-input-types` to regenerate TypeScript types
|
|
199
|
+
4. Model automatically appears in `catalog.all()` and as the `Models.NewModel` id constant
|
|
200
|
+
|
|
201
|
+
### With payload transforms
|
|
202
|
+
|
|
203
|
+
When the vendor API uses different field names or value formats:
|
|
204
|
+
|
|
205
|
+
1. Define the model config as above (no `buildPayload`)
|
|
206
|
+
2. Run `npm run build:model-input-types` — generates typed input for your model
|
|
207
|
+
3. Create `src/vendors/catalog/{vendor}.payloads.ts`:
|
|
208
|
+
```ts
|
|
209
|
+
import type { ModelInput } from '../../generated/model-input-types.ts';
|
|
210
|
+
import { registerPayloads } from '../define.ts';
|
|
211
|
+
import { SPECS, MODELS } from './{vendor}.ts';
|
|
212
|
+
|
|
213
|
+
registerPayloads({ SPECS, MODELS }, {
|
|
214
|
+
'model-id': (input: ModelInput<'model-id'>) => ({
|
|
215
|
+
prompt: input.prompt,
|
|
216
|
+
aspect_ratio: input.aspectRatio, // rename for vendor API
|
|
217
|
+
}),
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
4. Import the `.payloads.ts` file in `src/vendors/catalog/index.ts` (after the vendor import)
|
|
221
|
+
|
|
222
|
+
See `src/vendors/catalog/imagen.ts` + `src/vendors/catalog/imagen.payloads.ts` for a working example.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ModelPricingClient } from './lib/ModelPricingClient';
|
|
2
|
+
import { ModelPricingClientError } from './lib/errors/ModelPricingClientError';
|
|
3
|
+
import { ModelPricingServerError } from './lib/errors/ModelPricingServerError';
|
|
4
|
+
import { ModelPricingUnknownError } from './lib/errors/ModelPricingUnknownError';
|
|
5
|
+
import { UseCase, PricingUnit, ModelPricingFilters, ModelPricingMetadata, SkuEntry, VendorCostEntry, ModelPricing, ModelPricingListResponse, ModelPricingClientOptions } from './lib/types';
|
|
6
|
+
export { ModelPricingClient, ModelPricingClientError, ModelPricingServerError, ModelPricingUnknownError, UseCase, PricingUnit, ModelPricingFilters, ModelPricingMetadata, SkuEntry, VendorCostEntry, ModelPricing, ModelPricingListResponse, ModelPricingClientOptions, };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ModelPricingClientOptions, ModelPricingFilters, ModelPricing } from './types';
|
|
2
|
+
export declare class ModelPricingClient {
|
|
3
|
+
private readonly options;
|
|
4
|
+
private readonly modelPricingApiBaseUrl;
|
|
5
|
+
private pricing;
|
|
6
|
+
private refreshTimer;
|
|
7
|
+
private readonly defaultHeaders;
|
|
8
|
+
constructor(options: ModelPricingClientOptions);
|
|
9
|
+
/**
|
|
10
|
+
* Loads pricing data and starts the periodic refresh scheduler.
|
|
11
|
+
* Must be called and awaited before getModelPricing.
|
|
12
|
+
*/
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Stops the periodic refresh scheduler.
|
|
16
|
+
*/
|
|
17
|
+
stop(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Returns model pricings matching the given filters from the in-memory cache.
|
|
20
|
+
* Throws if pricing has not been loaded yet — call and await init() first.
|
|
21
|
+
*/
|
|
22
|
+
getModelPricing(filters?: ModelPricingFilters): ModelPricing[];
|
|
23
|
+
private loadAll;
|
|
24
|
+
private applyFilters;
|
|
25
|
+
private toSuccessResponse;
|
|
26
|
+
private throwIfError;
|
|
27
|
+
private wrapError;
|
|
28
|
+
private buildRequestHeaders;
|
|
29
|
+
private _fetch;
|
|
30
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export declare enum UseCase {
|
|
2
|
+
TextToImage = "text-to-image",
|
|
3
|
+
ImageToImage = "image-to-image",
|
|
4
|
+
TextToVideo = "text-to-video",
|
|
5
|
+
ImageToVideo = "image-to-video",
|
|
6
|
+
VideoToVideo = "video-to-video",
|
|
7
|
+
TextToSpeech = "text-to-speech",
|
|
8
|
+
TextToAudio = "text-to-audio",
|
|
9
|
+
SpeechToText = "speech-to-text",
|
|
10
|
+
ImageToAudio = "image-to-audio",
|
|
11
|
+
AudioToAudio = "audio-to-audio",
|
|
12
|
+
SpeechToSpeech = "speech-to-speech",
|
|
13
|
+
ChatCompletions = "chat-completions",
|
|
14
|
+
AudioToVideo = "audio-to-video",
|
|
15
|
+
VideoToAudio = "video-to-audio"
|
|
16
|
+
}
|
|
17
|
+
export declare enum PricingUnit {
|
|
18
|
+
Generation = "generation",
|
|
19
|
+
Megapixel = "megapixel",
|
|
20
|
+
Second = "second",
|
|
21
|
+
ThirtySecond = "30_second",
|
|
22
|
+
Minute = "minute",
|
|
23
|
+
ThousandCharacters = "1k_characters",
|
|
24
|
+
InputTokens = "input_tokens",
|
|
25
|
+
InputTextTokens = "input_text_tokens",
|
|
26
|
+
InputCachedTokens = "input_cached_tokens",
|
|
27
|
+
OutputImageTokens = "output_image_tokens",
|
|
28
|
+
OutputAudioTokens = "output_audio_tokens",
|
|
29
|
+
OutputTextTokens = "output_text_tokens"
|
|
30
|
+
}
|
|
31
|
+
export interface ModelPricingFilters {
|
|
32
|
+
vendor?: string;
|
|
33
|
+
modelId?: string;
|
|
34
|
+
useCase?: UseCase;
|
|
35
|
+
quality?: string;
|
|
36
|
+
audio?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ModelPricingMetadata {
|
|
39
|
+
vendor: string;
|
|
40
|
+
model: string;
|
|
41
|
+
modelId: string;
|
|
42
|
+
useCase: UseCase;
|
|
43
|
+
quality: string;
|
|
44
|
+
audio: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface SkuEntry {
|
|
47
|
+
id: string;
|
|
48
|
+
}
|
|
49
|
+
export interface VendorCostEntry {
|
|
50
|
+
cost: number;
|
|
51
|
+
unit: PricingUnit;
|
|
52
|
+
skus: SkuEntry[];
|
|
53
|
+
}
|
|
54
|
+
export interface ModelPricing {
|
|
55
|
+
id: string;
|
|
56
|
+
operationId: string;
|
|
57
|
+
metadata: ModelPricingMetadata;
|
|
58
|
+
vendorCosts: VendorCostEntry[];
|
|
59
|
+
unit: PricingUnit;
|
|
60
|
+
credits: number;
|
|
61
|
+
costPerUnit: number;
|
|
62
|
+
legacy: boolean;
|
|
63
|
+
created: string;
|
|
64
|
+
updated: string;
|
|
65
|
+
}
|
|
66
|
+
export interface ModelPricingListResponse {
|
|
67
|
+
status: string;
|
|
68
|
+
response: ModelPricing[];
|
|
69
|
+
}
|
|
70
|
+
export interface ModelPricingClientOptions {
|
|
71
|
+
/** Base URL of the model pricing service. */
|
|
72
|
+
baseUrl: string;
|
|
73
|
+
/**
|
|
74
|
+
* Custom fetch implementation.
|
|
75
|
+
* When provided, the client delegates all HTTP calls to this function.
|
|
76
|
+
*/
|
|
77
|
+
fetch?: typeof fetch;
|
|
78
|
+
/**
|
|
79
|
+
* Extra headers to include in every request.
|
|
80
|
+
*/
|
|
81
|
+
headers?: Record<string, string>;
|
|
82
|
+
/**
|
|
83
|
+
* Interval in milliseconds at which the in-memory cache is refreshed by the
|
|
84
|
+
* background scheduler. The cache itself never expires; it is only replaced
|
|
85
|
+
* by a successful refresh. Set 0 to disable the scheduler.
|
|
86
|
+
* @default 600_000 (10 minutes)
|
|
87
|
+
*/
|
|
88
|
+
refreshIntervalMs?: number;
|
|
89
|
+
/**
|
|
90
|
+
* HTTP request timeout in milliseconds.
|
|
91
|
+
* @default 5_000
|
|
92
|
+
*/
|
|
93
|
+
timeoutMs?: number;
|
|
94
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { WorkflowTypes } from '../workflows-types/index';
|
|
2
|
+
export { WorkflowTypes } from '../workflows-types/index';
|
|
3
|
+
|
|
4
|
+
declare enum PicsartStatus {
|
|
5
|
+
SUCCESS = "success",
|
|
6
|
+
ERROR = "error"
|
|
7
|
+
}
|
|
8
|
+
type PicsartResponse = {
|
|
9
|
+
status: PicsartStatus.SUCCESS;
|
|
10
|
+
};
|
|
11
|
+
declare enum WorkflowStatus {
|
|
12
|
+
ACCEPTED = "ACCEPTED",
|
|
13
|
+
FAILED = "FAILED",
|
|
14
|
+
COMPLETED = "COMPLETED",
|
|
15
|
+
IN_PROGRESS = "IN_PROGRESS"
|
|
16
|
+
}
|
|
17
|
+
interface TaskCreditUsage {
|
|
18
|
+
toolId: string;
|
|
19
|
+
price: number;
|
|
20
|
+
amount: number;
|
|
21
|
+
credits: number;
|
|
22
|
+
details?: ToolUsage[];
|
|
23
|
+
}
|
|
24
|
+
interface ToolUsage {
|
|
25
|
+
toolId: string;
|
|
26
|
+
price: number;
|
|
27
|
+
amount: number;
|
|
28
|
+
credits: number;
|
|
29
|
+
}
|
|
30
|
+
type WorkflowApiResponse<R> = {
|
|
31
|
+
id: string;
|
|
32
|
+
status: WorkflowStatus;
|
|
33
|
+
updated: string;
|
|
34
|
+
result: R;
|
|
35
|
+
progress?: WorkflowProgress;
|
|
36
|
+
usage?: TaskCreditUsage;
|
|
37
|
+
events?: WorkflowEvent[];
|
|
38
|
+
};
|
|
39
|
+
type PartialWorkflowResult<R> = {
|
|
40
|
+
status: WorkflowStatus;
|
|
41
|
+
result: R;
|
|
42
|
+
};
|
|
43
|
+
type HistoryResponse<R> = PicsartResponse & {
|
|
44
|
+
response: {
|
|
45
|
+
id: string;
|
|
46
|
+
created: string;
|
|
47
|
+
status: WorkflowStatus;
|
|
48
|
+
params: {
|
|
49
|
+
prompt: string;
|
|
50
|
+
};
|
|
51
|
+
result: (R | null)[];
|
|
52
|
+
}[];
|
|
53
|
+
};
|
|
54
|
+
type WorkflowProgress = {
|
|
55
|
+
percent: number;
|
|
56
|
+
estimatedSecondsLeft?: number;
|
|
57
|
+
};
|
|
58
|
+
type OnPartialResultFn = <R>(result: WorkflowApiResponse<R> | PartialWorkflowResult<R>) => Promise<void> | void;
|
|
59
|
+
type OnProgressFn = (progress: WorkflowProgress) => Promise<void> | void;
|
|
60
|
+
declare enum ExecutionMode {
|
|
61
|
+
ASYNC = "ASYNC",
|
|
62
|
+
SYNC = "SYNC",
|
|
63
|
+
STREAM = "STREAM"
|
|
64
|
+
}
|
|
65
|
+
declare class ExecutionOptions {
|
|
66
|
+
mode?: ExecutionMode;
|
|
67
|
+
remoteSettingName?: string;
|
|
68
|
+
abortSignal?: AbortSignal;
|
|
69
|
+
retriesCount?: number;
|
|
70
|
+
pollingInterval?: number;
|
|
71
|
+
onPartialResult?: OnPartialResultFn;
|
|
72
|
+
onProgress?: OnProgressFn;
|
|
73
|
+
onAccepted?: (id: string) => Promise<void> | void;
|
|
74
|
+
onEvent?: (event: WorkflowEvent) => Promise<void> | void;
|
|
75
|
+
notificationConfig?: INotificationContext;
|
|
76
|
+
headers?: HeadersInit;
|
|
77
|
+
}
|
|
78
|
+
declare class ApiSettings {
|
|
79
|
+
executionMode?: ExecutionMode;
|
|
80
|
+
configId?: string;
|
|
81
|
+
}
|
|
82
|
+
interface WorkflowEvent {
|
|
83
|
+
type: string;
|
|
84
|
+
id?: string;
|
|
85
|
+
}
|
|
86
|
+
interface WorkflowResponse<R> {
|
|
87
|
+
result: R;
|
|
88
|
+
usage?: TaskCreditUsage;
|
|
89
|
+
}
|
|
90
|
+
interface INotificationContext {
|
|
91
|
+
projectId?: string;
|
|
92
|
+
miniappPackageId?: string;
|
|
93
|
+
actions?: INotificationContextAction[];
|
|
94
|
+
}
|
|
95
|
+
interface INotificationContextAction {
|
|
96
|
+
deeplink: string;
|
|
97
|
+
mobileDeeplink: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type getRemoteSettingsFn = (name: string, tag?: string) => Promise<ApiSettings>;
|
|
101
|
+
interface ClientOptions {
|
|
102
|
+
baseUrl?: string;
|
|
103
|
+
fetch?: typeof fetch;
|
|
104
|
+
apiKey?: string;
|
|
105
|
+
identityToken?: string;
|
|
106
|
+
getRemoteSettings?: getRemoteSettingsFn;
|
|
107
|
+
headers?: HeadersInit;
|
|
108
|
+
}
|
|
109
|
+
declare class WorkflowsClient {
|
|
110
|
+
private readonly workflowsApiBaseUrl;
|
|
111
|
+
private readonly defaultHeaders;
|
|
112
|
+
private readonly options;
|
|
113
|
+
private readonly terminalStatuses;
|
|
114
|
+
constructor(options: ClientOptions);
|
|
115
|
+
run<R>(name: string, params: unknown, executionOptions?: ExecutionOptions): Promise<WorkflowResponse<R>>;
|
|
116
|
+
runTypeSafe<N extends keyof WorkflowTypes>(name: N, params: WorkflowTypes[N]['params'], executionOptions?: ExecutionOptions): Promise<WorkflowResponse<WorkflowTypes[N]['result']>>;
|
|
117
|
+
private postTask;
|
|
118
|
+
runPolling<R>(taskName: string, taskId: string, executionOptions?: ExecutionOptions): Promise<WorkflowResponse<R>>;
|
|
119
|
+
private executeTaskSync;
|
|
120
|
+
private getResult;
|
|
121
|
+
private executeTaskStream;
|
|
122
|
+
executionsHistory<R>(taskName: string, offset?: number, limit?: number, isGrouped?: boolean): Promise<HistoryResponse<R>>;
|
|
123
|
+
private toSuccessResponse;
|
|
124
|
+
private throwIfError;
|
|
125
|
+
private getApiSettings;
|
|
126
|
+
private wrapError;
|
|
127
|
+
private buildRequestHeaders;
|
|
128
|
+
private _fetch;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { ExecutionMode, ExecutionOptions, type WorkflowEvent, type WorkflowProgress, type WorkflowResponse, WorkflowStatus, WorkflowsClient };
|