@civitai/app-sdk 0.1.0 → 0.6.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.
@@ -1,77 +0,0 @@
1
- import { getWorkflow as sdkGetWorkflow, submitWorkflow as sdkSubmitWorkflow, } from '@civitai/client';
2
- class WorkflowError extends Error {
3
- status;
4
- detail;
5
- name = 'WorkflowError';
6
- constructor(message, status, detail) {
7
- super(message);
8
- this.status = status;
9
- this.detail = detail;
10
- }
11
- }
12
- function unwrap(result) {
13
- if (result.error || !result.data) {
14
- const status = result.response?.status;
15
- const detail = result.error && typeof result.error === 'object' && 'detail' in result.error
16
- ? result.error.detail
17
- : result.error;
18
- throw new WorkflowError(`Civitai workflow request failed${status ? ` (HTTP ${status})` : ''}`, status, detail);
19
- }
20
- return result.data;
21
- }
22
- /**
23
- * Cost preview ("what if") — runs the workflow validation/pricing pipeline
24
- * without committing any Buzz. Use this to show the user "this will cost X
25
- * Buzz" before they confirm submission.
26
- *
27
- * NOTE: per Civitai's docs, `whatif=true` validates and prices but does not
28
- * apply per-app spending caps to the response — a successful whatif can still
29
- * be denied at submit time if the user has set tight caps or insufficient
30
- * funds. Treat `whatif` as "this is the price" not "this is approved."
31
- */
32
- export async function estimateCost(client, body) {
33
- const result = await sdkSubmitWorkflow({
34
- client,
35
- body,
36
- query: { whatif: true },
37
- });
38
- const workflow = unwrap(result);
39
- return { total: workflow?.cost?.total ?? 0, raw: workflow };
40
- }
41
- /** Submit a workflow for real execution. Debits the token-owner's Buzz. */
42
- export async function submitWorkflow(client, body) {
43
- const result = await sdkSubmitWorkflow({ client, body });
44
- return unwrap(result);
45
- }
46
- export async function getWorkflow(client, workflowId) {
47
- const result = await sdkGetWorkflow({
48
- client,
49
- path: { workflowId },
50
- });
51
- return unwrap(result);
52
- }
53
- const TERMINAL_STATUSES = new Set(['Succeeded', 'Failed', 'Canceled']);
54
- /**
55
- * Poll a workflow until it reaches a terminal status (`Succeeded`, `Failed`,
56
- * `Canceled`) or the timeout elapses. Returns the final snapshot.
57
- */
58
- export async function pollWorkflow(client, workflowId, opts = {}) {
59
- const interval = opts.intervalMs ?? 2000;
60
- const timeout = opts.timeoutMs ?? 5 * 60 * 1000;
61
- const deadline = Date.now() + timeout;
62
- while (true) {
63
- if (opts.signal?.aborted)
64
- throw new Error('pollWorkflow aborted');
65
- const snapshot = await getWorkflow(client, workflowId);
66
- opts.onTick?.(snapshot);
67
- if (snapshot.status && TERMINAL_STATUSES.has(String(snapshot.status))) {
68
- return snapshot;
69
- }
70
- if (Date.now() >= deadline) {
71
- throw new Error(`pollWorkflow timed out after ${timeout}ms (last status: ${String(snapshot.status)})`);
72
- }
73
- await new Promise((resolve) => setTimeout(resolve, interval));
74
- }
75
- }
76
- export { WorkflowError };
77
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,IAAI,cAAc,EAC7B,cAAc,IAAI,iBAAiB,GAIpC,MAAM,iBAAiB,CAAC;AAmBzB,MAAM,aAAc,SAAQ,KAAK;IAIpB;IACA;IAJO,IAAI,GAAG,eAAe,CAAC;IACzC,YACE,OAAe,EACN,MAA0B,EAC1B,MAAe;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,WAAM,GAAN,MAAM,CAAoB;QAC1B,WAAM,GAAN,MAAM,CAAS;IAG1B,CAAC;CACF;AAED,SAAS,MAAM,CAAI,MAA0D;IAC3E,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC;QACvC,MAAM,MAAM,GACV,MAAM,CAAC,KAAK,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,MAAM,CAAC,KAAK;YAC1E,CAAC,CAAE,MAA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