@civitai/app-sdk 0.1.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.
Files changed (46) hide show
  1. package/README.md +100 -0
  2. package/dist/client/index.d.ts +23 -0
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/client/index.js +19 -0
  5. package/dist/client/index.js.map +1 -0
  6. package/dist/cookies/index.d.ts +27 -0
  7. package/dist/cookies/index.d.ts.map +1 -0
  8. package/dist/cookies/index.js +85 -0
  9. package/dist/cookies/index.js.map +1 -0
  10. package/dist/index.d.ts +6 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +5 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/oauth/authorize.d.ts +15 -0
  15. package/dist/oauth/authorize.d.ts.map +1 -0
  16. package/dist/oauth/authorize.js +18 -0
  17. package/dist/oauth/authorize.js.map +1 -0
  18. package/dist/oauth/index.d.ts +4 -0
  19. package/dist/oauth/index.d.ts.map +1 -0
  20. package/dist/oauth/index.js +4 -0
  21. package/dist/oauth/index.js.map +1 -0
  22. package/dist/oauth/pkce.d.ts +10 -0
  23. package/dist/oauth/pkce.d.ts.map +1 -0
  24. package/dist/oauth/pkce.js +15 -0
  25. package/dist/oauth/pkce.js.map +1 -0
  26. package/dist/oauth/token.d.ts +37 -0
  27. package/dist/oauth/token.d.ts.map +1 -0
  28. package/dist/oauth/token.js +89 -0
  29. package/dist/oauth/token.js.map +1 -0
  30. package/dist/orchestrator/index.d.ts +119 -0
  31. package/dist/orchestrator/index.d.ts.map +1 -0
  32. package/dist/orchestrator/index.js +155 -0
  33. package/dist/orchestrator/index.js.map +1 -0
  34. package/dist/scopes/index.d.ts +59 -0
  35. package/dist/scopes/index.d.ts.map +1 -0
  36. package/dist/scopes/index.js +155 -0
  37. package/dist/scopes/index.js.map +1 -0
  38. package/dist/types.d.ts +21 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +2 -0
  41. package/dist/types.js.map +1 -0
  42. package/dist/workflows/index.d.ts +52 -0
  43. package/dist/workflows/index.d.ts.map +1 -0
  44. package/dist/workflows/index.js +77 -0
  45. package/dist/workflows/index.js.map +1 -0
  46. package/package.json +71 -0
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Orchestrator glue — types, constants, and fetch-based helpers shared by every
3
+ * starter's BFF. Client + server safe: no Node-only imports, no `process.env`
4
+ * access. All configuration flows through the `OrchestratorClient` value that
5
+ * the caller builds.
6
+ */
7
+ export declare const DEFAULT_ORCHESTRATOR_BASE_URL = "https://orchestration.civitai.com";
8
+ /** Default SDXL base model. Replace per starter / per call as needed. */
9
+ export declare const DEFAULT_MODEL_AIR = "urn:air:sdxl:checkpoint:civitai:101055@128078";
10
+ /**
11
+ * Terminal orchestrator statuses (lowercase — matches what the API returns).
12
+ */
13
+ export declare const TERMINAL_STATUSES: readonly ["succeeded", "failed", "expired", "canceled"];
14
+ export type TerminalStatus = (typeof TERMINAL_STATUSES)[number];
15
+ /**
16
+ * Orchestrator workflow status. Lowercase — matches what the orchestrator
17
+ * actually returns. Forward-compat: open-ended string union so unknown
18
+ * statuses don't break typing.
19
+ */
20
+ export type WorkflowStatus = 'unassigned' | 'pending' | 'processing' | 'succeeded' | 'failed' | 'expired' | 'canceled' | (string & {});
21
+ export interface GenerateInput {
22
+ prompt: string;
23
+ negativePrompt?: string;
24
+ /** AIR URN, e.g. `urn:air:sdxl:checkpoint:civitai:101055@128078`. */
25
+ model?: string;
26
+ width?: number;
27
+ height?: number;
28
+ steps?: number;
29
+ cfgScale?: number;
30
+ seed?: number;
31
+ quantity?: number;
32
+ }
33
+ export interface WorkflowSnapshot {
34
+ id: string;
35
+ status: WorkflowStatus;
36
+ cost?: {
37
+ total?: number;
38
+ };
39
+ steps?: Array<{
40
+ output?: {
41
+ /** Canonical image array. Each item has `url` + `available: boolean`. */
42
+ images?: Array<{
43
+ url?: string;
44
+ available?: boolean;
45
+ }>;
46
+ /** Legacy/alternative — some workflow types still emit `blobs[]`. */
47
+ blobs?: Array<{
48
+ url?: string;
49
+ type?: string;
50
+ mimeType?: string;
51
+ }>;
52
+ };
53
+ }>;
54
+ [key: string]: unknown;
55
+ }
56
+ /**
57
+ * Minimal orchestrator client config — just the base URL and the user's
58
+ * access token. Build one with {@link createOrchestratorClient} and pass it
59
+ * to the per-call helpers below.
60
+ */
61
+ export interface OrchestratorClient {
62
+ baseUrl: string;
63
+ accessToken: string;
64
+ }
65
+ export declare class OrchestratorError extends Error {
66
+ readonly status: number;
67
+ readonly body: unknown;
68
+ readonly name = "OrchestratorError";
69
+ constructor(message: string, status: number, body: unknown);
70
+ }
71
+ export interface CreateOrchestratorClientOptions {
72
+ /** OAuth access token (or personal API key — same Bearer scheme). */
73
+ accessToken: string;
74
+ /** Orchestrator base URL. Defaults to Civitai's prod orchestrator. */
75
+ baseUrl?: string;
76
+ }
77
+ export declare function createOrchestratorClient(opts: CreateOrchestratorClientOptions): OrchestratorClient;
78
+ /**
79
+ * Internal raw-fetch helper. Logs the failing response to console.error and
80
+ * throws {@link OrchestratorError} on non-2xx. Exported so callers can build
81
+ * their own orchestrator routes without duplicating this code.
82
+ */
83
+ export declare function callOrchestrator(client: OrchestratorClient, path: string, init?: RequestInit): Promise<unknown>;
84
+ export interface BuildTextToImageBodyOptions {
85
+ /** Optional workflow tags — useful for attribution / debugging. */
86
+ tags?: string[];
87
+ }
88
+ /**
89
+ * Build a `textToImage` workflow body from a {@link GenerateInput}. Mirrors
90
+ * the shape every starter's existing `buildWorkflowBody` produced.
91
+ */
92
+ export declare function buildTextToImageBody(input: GenerateInput, opts?: BuildTextToImageBodyOptions): unknown;
93
+ /**
94
+ * Cost preview ("what if") — runs the workflow validation/pricing pipeline
95
+ * without committing any Buzz.
96
+ */
97
+ export declare function estimateWorkflow(client: OrchestratorClient, body: unknown): Promise<WorkflowSnapshot>;
98
+ /** Submit a workflow for real execution. Debits the token-owner's Buzz. */
99
+ export declare function submitWorkflow(client: OrchestratorClient, body: unknown): Promise<WorkflowSnapshot>;
100
+ export declare function getWorkflow(client: OrchestratorClient, workflowId: string): Promise<WorkflowSnapshot>;
101
+ export interface PollWorkflowOptions {
102
+ /** Polling interval in ms. Default 1000. */
103
+ intervalMs?: number;
104
+ /** Max total time to poll in ms. Default 30000. */
105
+ timeoutMs?: number;
106
+ /** Optional abort signal — checked between ticks. */
107
+ signal?: AbortSignal;
108
+ }
109
+ /**
110
+ * Server-side long-poll helper. Re-fetches the workflow every `intervalMs`
111
+ * until it reaches a terminal status, the timeout elapses, or the signal
112
+ * aborts. Returns the latest snapshot regardless of which condition tripped —
113
+ * callers inspect {@link isTerminal} on the result to decide what to do.
114
+ */
115
+ export declare function pollWorkflow(client: OrchestratorClient, workflowId: string, opts?: PollWorkflowOptions): Promise<WorkflowSnapshot>;
116
+ export declare function isTerminal(snap: WorkflowSnapshot | null | undefined): boolean;
117
+ /** Pull every available image URL out of a workflow snapshot. */
118
+ export declare function extractImageUrls(snap: WorkflowSnapshot | null | undefined): string[];
119
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/orchestrator/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,eAAO,MAAM,6BAA6B,sCAAsC,CAAC;AAEjF,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,kDAAkD,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,iBAAiB,yDAA0D,CAAC;AACzF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAIhE;;;;GAIG;AACH,MAAM,MAAM,cAAc,GACtB,YAAY,GACZ,SAAS,GACT,YAAY,GACZ,WAAW,GACX,QAAQ,GACR,SAAS,GACT,UAAU,GACV,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE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,CAAC,CAY3B;AAID,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAG7E;AAED,iEAAiE;AACjE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAcpF"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Orchestrator glue — types, constants, and fetch-based helpers shared by every
3
+ * starter's BFF. Client + server safe: no Node-only imports, no `process.env`
4
+ * access. All configuration flows through the `OrchestratorClient` value that
5
+ * the caller builds.
6
+ */
7
+ // ---------- Constants -------------------------------------------------------
8
+ export const DEFAULT_ORCHESTRATOR_BASE_URL = 'https://orchestration.civitai.com';
9
+ /** Default SDXL base model. Replace per starter / per call as needed. */
10
+ export const DEFAULT_MODEL_AIR = 'urn:air:sdxl:checkpoint:civitai:101055@128078';
11
+ /**
12
+ * Terminal orchestrator statuses (lowercase — matches what the API returns).
13
+ */
14
+ export const TERMINAL_STATUSES = ['succeeded', 'failed', 'expired', 'canceled'];
15
+ export class OrchestratorError extends Error {
16
+ status;
17
+ body;
18
+ name = 'OrchestratorError';
19
+ constructor(message, status, body) {
20
+ super(message);
21
+ this.status = status;
22
+ this.body = body;
23
+ }
24
+ }
25
+ export function createOrchestratorClient(opts) {
26
+ return {
27
+ baseUrl: opts.baseUrl ?? DEFAULT_ORCHESTRATOR_BASE_URL,
28
+ accessToken: opts.accessToken,
29
+ };
30
+ }
31
+ // ---------- Raw HTTP --------------------------------------------------------
32
+ /**
33
+ * Internal raw-fetch helper. Logs the failing response to console.error and
34
+ * throws {@link OrchestratorError} on non-2xx. Exported so callers can build
35
+ * their own orchestrator routes without duplicating this code.
36
+ */
37
+ export async function callOrchestrator(client, path, init = {}) {
38
+ const { headers, ...rest } = init;
39
+ const res = await fetch(`${client.baseUrl}${path}`, {
40
+ ...rest,
41
+ headers: {
42
+ 'content-type': 'application/json',
43
+ Authorization: `Bearer ${client.accessToken}`,
44
+ ...headers,
45
+ },
46
+ });
47
+ const text = await res.text();
48
+ let body = null;
49
+ try {
50
+ body = text ? JSON.parse(text) : null;
51
+ }
52
+ catch {
53
+ body = text;
54
+ }
55
+ if (!res.ok) {
56
+ console.error(`[orchestrator] ${init.method ?? 'GET'} ${path} -> ${res.status} ${res.statusText}\n` +
57
+ ` raw body: ${text.length ? text.slice(0, 500) : '(empty)'}`);
58
+ throw new OrchestratorError(`HTTP ${res.status}`, res.status, body);
59
+ }
60
+ return body;
61
+ }
62
+ /**
63
+ * Build a `textToImage` workflow body from a {@link GenerateInput}. Mirrors
64
+ * the shape every starter's existing `buildWorkflowBody` produced.
65
+ */
66
+ export function buildTextToImageBody(input, opts = {}) {
67
+ const body = {
68
+ steps: [
69
+ {
70
+ $type: 'textToImage',
71
+ name: 'step_0',
72
+ timeout: '00:10:00',
73
+ input: {
74
+ prompt: input.prompt,
75
+ negativePrompt: input.negativePrompt,
76
+ model: input.model ?? DEFAULT_MODEL_AIR,
77
+ width: input.width ?? 1024,
78
+ height: input.height ?? 1024,
79
+ steps: input.steps ?? 25,
80
+ cfgScale: input.cfgScale ?? 5,
81
+ seed: input.seed,
82
+ quantity: input.quantity ?? 1,
83
+ },
84
+ },
85
+ ],
86
+ };
87
+ if (opts.tags && opts.tags.length > 0)
88
+ body.tags = opts.tags;
89
+ return body;
90
+ }
91
+ // ---------- Workflow endpoints ---------------------------------------------
92
+ /**
93
+ * Cost preview ("what if") — runs the workflow validation/pricing pipeline
94
+ * without committing any Buzz.
95
+ */
96
+ export function estimateWorkflow(client, body) {
97
+ return callOrchestrator(client, '/v2/consumer/workflows?whatif=true', {
98
+ method: 'POST',
99
+ body: JSON.stringify(body),
100
+ });
101
+ }
102
+ /** Submit a workflow for real execution. Debits the token-owner's Buzz. */
103
+ export function submitWorkflow(client, body) {
104
+ return callOrchestrator(client, '/v2/consumer/workflows', {
105
+ method: 'POST',
106
+ body: JSON.stringify(body),
107
+ });
108
+ }
109
+ export function getWorkflow(client, workflowId) {
110
+ return callOrchestrator(client, `/v2/consumer/workflows/${encodeURIComponent(workflowId)}`, { method: 'GET' });
111
+ }
112
+ /**
113
+ * Server-side long-poll helper. Re-fetches the workflow every `intervalMs`
114
+ * until it reaches a terminal status, the timeout elapses, or the signal
115
+ * aborts. Returns the latest snapshot regardless of which condition tripped —
116
+ * callers inspect {@link isTerminal} on the result to decide what to do.
117
+ */
118
+ export async function pollWorkflow(client, workflowId, opts = {}) {
119
+ const interval = opts.intervalMs ?? 1000;
120
+ const timeout = opts.timeoutMs ?? 30_000;
121
+ const deadline = Date.now() + timeout;
122
+ let snapshot = await getWorkflow(client, workflowId);
123
+ while (!isTerminal(snapshot) && Date.now() + interval <= deadline) {
124
+ if (opts.signal?.aborted)
125
+ break;
126
+ await new Promise((r) => setTimeout(r, interval));
127
+ snapshot = await getWorkflow(client, workflowId);
128
+ }
129
+ return snapshot;
130
+ }
131
+ // ---------- Snapshot inspection --------------------------------------------
132
+ export function isTerminal(snap) {
133
+ if (!snap?.status)
134
+ return false;
135
+ return TERMINAL_STATUSES.includes(String(snap.status));
136
+ }
137
+ /** Pull every available image URL out of a workflow snapshot. */
138
+ export function extractImageUrls(snap) {
139
+ if (!snap?.steps)
140
+ return [];
141
+ const out = [];
142
+ for (const step of snap.steps) {
143
+ for (const img of step.output?.images ?? []) {
144
+ if (img.available && img.url)
145
+ out.push(img.url);
146
+ }
147
+ for (const blob of step.output?.blobs ?? []) {
148
+ if (blob.url && (blob.mimeType ?? blob.type ?? '').startsWith('image/')) {
149
+ out.push(blob.url);
150
+ }
151
+ }
152
+ }
153
+ return out;
154
+ }
155
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/orchestrator/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAE/E,MAAM,CAAC,MAAM,6BAA6B,GAAG,mCAAmC,CAAC;AAEjF,yEAAyE;AACzE,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YACrB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Token Scope — Bitwise flags for API key and OAuth token permissions.
3
+ *
4
+ * Each scope is a power of 2 so they can be combined with bitwise OR.
5
+ * Use `hasScope(tokenScope, TokenScope.ModelsWrite)` to check.
6
+ *
7
+ * Buzz spending is implicit in the scopes that require it:
8
+ * - AIServicesWrite (generation, training, scanning)
9
+ * - BountiesWrite (bounty creation)
10
+ * - SocialTip (tipping)
11
+ */
12
+ export declare const TokenScope: {
13
+ readonly None: 0;
14
+ readonly UserRead: number;
15
+ readonly UserWrite: number;
16
+ readonly ModelsRead: number;
17
+ readonly ModelsWrite: number;
18
+ readonly ModelsDelete: number;
19
+ readonly MediaRead: number;
20
+ readonly MediaWrite: number;
21
+ readonly MediaDelete: number;
22
+ readonly ArticlesRead: number;
23
+ readonly ArticlesWrite: number;
24
+ readonly ArticlesDelete: number;
25
+ readonly BountiesRead: number;
26
+ readonly BountiesWrite: number;
27
+ readonly BountiesDelete: number;
28
+ readonly AIServicesRead: number;
29
+ readonly AIServicesWrite: number;
30
+ readonly BuzzRead: number;
31
+ readonly CollectionsRead: number;
32
+ readonly CollectionsWrite: number;
33
+ readonly SocialWrite: number;
34
+ readonly SocialTip: number;
35
+ readonly NotificationsRead: number;
36
+ readonly NotificationsWrite: number;
37
+ readonly VaultRead: number;
38
+ readonly VaultWrite: number;
39
+ readonly Full: number;
40
+ };
41
+ export type TokenScopeKey = Exclude<keyof typeof TokenScope, 'None' | 'Full'>;
42
+ export type TokenScopeValue = (typeof TokenScope)[keyof typeof TokenScope];
43
+ export declare const tokenScopeLabels: Record<number, string>;
44
+ export declare const TokenScopePresets: {
45
+ readonly ReadOnly: number;
46
+ readonly Creator: number;
47
+ readonly AIServices: number;
48
+ readonly Full: number;
49
+ };
50
+ export type TokenScopePresetKey = keyof typeof TokenScopePresets;
51
+ /** True if the given bitmask grants the named scope. */
52
+ export declare function hasScope(bitmask: number, scope: number): boolean;
53
+ /** Return the list of named scopes contained in a bitmask. */
54
+ export declare function scopesFromBitmask(bitmask: number): TokenScopeKey[];
55
+ /** Combine a list of named scopes into a single bitmask. */
56
+ export declare function bitmaskFromScopes(scopes: readonly TokenScopeKey[]): number;
57
+ /** Human-readable label for a tokenScope bitmask (matches the Civitai UI). */
58
+ export declare function getScopeLabel(tokenScope: number | null | undefined): string;
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scopes/index.ts"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDb,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,OAAO,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAC9E,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAE3E,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA0BnD,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;CA+BpB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAEjE,wDAAwD;AACxD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CASlE;AAED,4DAA4D;AAC5D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,CAI1E;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAO3E"}
@@ -0,0 +1,155 @@
1
+ // TODO(scopes-codegen): Replace this hand-copied file with a build-time
2
+ // codegen step that fetches scope metadata from
3
+ // `${CIVITAI_BASE_URL}/.well-known/openid-configuration` (and/or a
4
+ // scopes-specific endpoint). The discovery endpoint already exposes scope
5
+ // values; once Civitai publishes a stable scope-label feed we can drop the
6
+ // labels copy too. Until then this file is the source of truth for the SDK
7
+ // and must stay in sync with `src/shared/constants/token-scope.constants.ts`
8
+ // in the main `civitai/civitai` repo.
9
+ /**
10
+ * Token Scope — Bitwise flags for API key and OAuth token permissions.
11
+ *
12
+ * Each scope is a power of 2 so they can be combined with bitwise OR.
13
+ * Use `hasScope(tokenScope, TokenScope.ModelsWrite)` to check.
14
+ *
15
+ * Buzz spending is implicit in the scopes that require it:
16
+ * - AIServicesWrite (generation, training, scanning)
17
+ * - BountiesWrite (bounty creation)
18
+ * - SocialTip (tipping)
19
+ */
20
+ export const TokenScope = {
21
+ None: 0,
22
+ // Account & Profile
23
+ UserRead: 1 << 0,
24
+ UserWrite: 1 << 1,
25
+ // Models & Resources
26
+ ModelsRead: 1 << 2,
27
+ ModelsWrite: 1 << 3,
28
+ ModelsDelete: 1 << 4,
29
+ // Media & Posts (images, videos, posts)
30
+ MediaRead: 1 << 5,
31
+ MediaWrite: 1 << 6,
32
+ MediaDelete: 1 << 7,
33
+ // Articles
34
+ ArticlesRead: 1 << 8,
35
+ ArticlesWrite: 1 << 9,
36
+ ArticlesDelete: 1 << 10,
37
+ // Bounties (write implicitly allows buzz spend for bounty creation)
38
+ BountiesRead: 1 << 11,
39
+ BountiesWrite: 1 << 12,
40
+ BountiesDelete: 1 << 13,
41
+ // AI Services — generation, training, scanning, all orchestrator requests
42
+ // Write implicitly allows buzz spend for orchestrator usage
43
+ AIServicesRead: 1 << 14,
44
+ AIServicesWrite: 1 << 15,
45
+ // Buzz (Currency)
46
+ BuzzRead: 1 << 16,
47
+ // Collections & Interactions
48
+ CollectionsRead: 1 << 17,
49
+ CollectionsWrite: 1 << 18,
50
+ SocialWrite: 1 << 19,
51
+ SocialTip: 1 << 20,
52
+ // Notifications
53
+ NotificationsRead: 1 << 21,
54
+ NotificationsWrite: 1 << 22,
55
+ // Vault
56
+ VaultRead: 1 << 23,
57
+ VaultWrite: 1 << 24,
58
+ // All scopes
59
+ Full: (1 << 25) - 1,
60
+ };
61
+ export const tokenScopeLabels = {
62
+ [TokenScope.UserRead]: 'Read profile & settings',
63
+ [TokenScope.UserWrite]: 'Update profile & settings',
64
+ [TokenScope.ModelsRead]: 'Browse & download models',
65
+ [TokenScope.ModelsWrite]: 'Upload & edit models',
66
+ [TokenScope.ModelsDelete]: 'Delete models',
67
+ [TokenScope.MediaRead]: 'View images, videos & posts',
68
+ [TokenScope.MediaWrite]: 'Upload media & create posts',
69
+ [TokenScope.MediaDelete]: 'Delete media & posts',
70
+ [TokenScope.ArticlesRead]: 'Read articles',
71
+ [TokenScope.ArticlesWrite]: 'Create & edit articles',
72
+ [TokenScope.ArticlesDelete]: 'Delete articles',
73
+ [TokenScope.BountiesRead]: 'View bounties',
74
+ [TokenScope.BountiesWrite]: 'Create & manage bounties',
75
+ [TokenScope.BountiesDelete]: 'Delete bounties',
76
+ [TokenScope.AIServicesRead]: 'View generation & training history',
77
+ [TokenScope.AIServicesWrite]: 'Generate, train & scan',
78
+ [TokenScope.BuzzRead]: 'View buzz balance & history',
79
+ [TokenScope.CollectionsRead]: 'View collections',
80
+ [TokenScope.CollectionsWrite]: 'Manage collections',
81
+ [TokenScope.SocialWrite]: 'Follow, react, comment & review',
82
+ [TokenScope.SocialTip]: 'Tip other users',
83
+ [TokenScope.NotificationsRead]: 'Read notifications',
84
+ [TokenScope.NotificationsWrite]: 'Manage notification preferences',
85
+ [TokenScope.VaultRead]: 'View vault',
86
+ [TokenScope.VaultWrite]: 'Manage vault',
87
+ };
88
+ export const TokenScopePresets = {
89
+ ReadOnly: TokenScope.UserRead |
90
+ TokenScope.ModelsRead |
91
+ TokenScope.MediaRead |
92
+ TokenScope.ArticlesRead |
93
+ TokenScope.BountiesRead |
94
+ TokenScope.BuzzRead |
95
+ TokenScope.CollectionsRead |
96
+ TokenScope.AIServicesRead |
97
+ TokenScope.NotificationsRead |
98
+ TokenScope.VaultRead,
99
+ Creator: TokenScope.UserRead |
100
+ TokenScope.ModelsRead |
101
+ TokenScope.MediaRead |
102
+ TokenScope.ArticlesRead |
103
+ TokenScope.BountiesRead |
104
+ TokenScope.BuzzRead |
105
+ TokenScope.CollectionsRead |
106
+ TokenScope.AIServicesRead |
107
+ TokenScope.NotificationsRead |
108
+ TokenScope.VaultRead |
109
+ TokenScope.ModelsWrite |
110
+ TokenScope.MediaWrite |
111
+ TokenScope.ArticlesWrite |
112
+ TokenScope.BountiesWrite |
113
+ TokenScope.CollectionsWrite |
114
+ TokenScope.SocialWrite,
115
+ AIServices: TokenScope.AIServicesWrite | TokenScope.AIServicesRead | TokenScope.BuzzRead,
116
+ Full: TokenScope.Full,
117
+ };
118
+ /** True if the given bitmask grants the named scope. */
119
+ export function hasScope(bitmask, scope) {
120
+ return (bitmask & scope) === scope;
121
+ }
122
+ /** Return the list of named scopes contained in a bitmask. */
123
+ export function scopesFromBitmask(bitmask) {
124
+ const out = [];
125
+ for (const [name, bit] of Object.entries(TokenScope)) {
126
+ if (name === 'None' || name === 'Full')
127
+ continue;
128
+ if (typeof bit === 'number' && bit !== 0 && (bitmask & bit) === bit) {
129
+ out.push(name);
130
+ }
131
+ }
132
+ return out;
133
+ }
134
+ /** Combine a list of named scopes into a single bitmask. */
135
+ export function bitmaskFromScopes(scopes) {
136
+ let mask = 0;
137
+ for (const s of scopes)
138
+ mask |= TokenScope[s];
139
+ return mask;
140
+ }
141
+ /** Human-readable label for a tokenScope bitmask (matches the Civitai UI). */
142
+ export function getScopeLabel(tokenScope) {
143
+ if (tokenScope == null)
144
+ return 'Legacy';
145
+ if (tokenScope === TokenScope.Full)
146
+ return 'Full Access';
147
+ if (tokenScope === TokenScopePresets.ReadOnly)
148
+ return 'Read Only';
149
+ if (tokenScope === TokenScopePresets.Creator)
150
+ return 'Creator';
151
+ if (tokenScope === TokenScopePresets.AIServices)
152
+ return 'AI Services';
153
+ return 'Custom';
154
+ }
155
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scopes/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,gDAAgD;AAChD,mEAAmE;AACnE,0EAA0E;AAC1E,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,sCAAsC;AAEtC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,CAAC;IAEP,oBAAoB;IACpB,QAAQ,EAAE,CAAC,IAAI,CAAC;IAChB,SAAS,EAAE,CAAC,IAAI,CAAC;IAEjB,qBAAqB;IACrB,UAAU,EAAE,CAAC,IAAI,CAAC;IAClB,WAAW,EAAE,CAAC,IAAI,CAAC;IACnB,YAAY,EAAE,CAAC,IAAI,CAAC;IAEpB,wCAAwC;IACxC,SAAS,EAAE,CAAC,IAAI,CAAC;IACjB,UAAU,EAAE,CAAC,IAAI,CAAC;IAClB,WAAW,EAAE,CAAC,IAAI,CAAC;IAEnB,WAAW;IACX,YAAY,EAAE,CAAC,IAAI,CAAC;IACpB,aAAa,EAAE,CAAC,IAAI,CAAC;IACrB,cAAc,EAAE,CAAC,IAAI,EAAE;IAEvB,oEAAoE;IACpE,YAAY,EAAE,CAAC,IAAI,EAAE;IACrB,aAAa,EAAE,CAAC,IAAI,EAAE;IACtB,cAAc,EAAE,CAAC,IAAI,EAAE;IAEvB,0EAA0E;IAC1E,4DAA4D;IAC5D,cAAc,EAAE,CAAC,IAAI,EAAE;IACvB,eAAe,EAAE,CAAC,IAAI,EAAE;IAExB,kBAAkB;IAClB,QAAQ,EAAE,CAAC,IAAI,EAAE;IAEjB,6BAA6B;IAC7B,eAAe,EAAE,CAAC,IAAI,EAAE;IACxB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BAAiB,CAAC,UAAU;QAAE,OAAO,aAAa,CAAC;IACtE,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,21 @@
1
+ export interface OAuthTokens {
2
+ access_token: string;
3
+ refresh_token?: string;
4
+ expires_at: number;
5
+ scope: number;
6
+ token_type?: string;
7
+ }
8
+ export interface OAuthTokenResponse {
9
+ access_token: string;
10
+ refresh_token?: string;
11
+ expires_in?: number;
12
+ scope?: string | number;
13
+ token_type?: string;
14
+ }
15
+ export interface OAuthClientConfig {
16
+ clientId: string;
17
+ clientSecret?: string;
18
+ redirectUri: string;
19
+ baseUrl?: string;
20
+ }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ import { type SubmitWorkflowData, type Workflow } from '@civitai/client';
2
+ import type { AppClient } from '../client/index.js';
3
+ /**
4
+ * Thin wrappers around the orchestrator's workflow endpoints with conventions
5
+ * suited to third-party app starters. All calls use the user's OAuth token
6
+ * (or API key) carried by the `AppClient` — the orchestrator debits Buzz
7
+ * from whoever owns that token.
8
+ */
9
+ export type WorkflowBody = NonNullable<SubmitWorkflowData['body']>;
10
+ export interface CostEstimate {
11
+ /** Buzz cost. Pulled from the workflow's `cost.total` field. */
12
+ total: number;
13
+ /** Full workflow response (validation result, queue placement, etc.). */
14
+ raw: Workflow;
15
+ }
16
+ declare class WorkflowError extends Error {
17
+ readonly status: number | undefined;
18
+ readonly detail: unknown;
19
+ readonly name = "WorkflowError";
20
+ constructor(message: string, status: number | undefined, detail: unknown);
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 declare function estimateCost(client: AppClient, body: WorkflowBody): Promise<CostEstimate>;
33
+ /** Submit a workflow for real execution. Debits the token-owner's Buzz. */
34
+ export declare function submitWorkflow(client: AppClient, body: WorkflowBody): Promise<Workflow>;
35
+ export declare function getWorkflow(client: AppClient, workflowId: string): Promise<Workflow>;
36
+ export interface PollWorkflowOptions {
37
+ /** Polling interval in ms. Default 2000. */
38
+ intervalMs?: number;
39
+ /** Max total time to poll in ms. Default 5 minutes. */
40
+ timeoutMs?: number;
41
+ /** Optional progress callback fired on every poll tick. */
42
+ onTick?: (snapshot: Workflow) => void;
43
+ /** Optional abort signal. */
44
+ signal?: AbortSignal;
45
+ }
46
+ /**
47
+ * Poll a workflow until it reaches a terminal status (`Succeeded`, `Failed`,
48
+ * `Canceled`) or the timeout elapses. Returns the final snapshot.
49
+ */
50
+ export declare function pollWorkflow(client: AppClient, workflowId: string, opts?: PollWorkflowOptions): Promise<Workflow>;
51
+ export { WorkflowError };
52
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;;;;GAKG;AAEH,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC3B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,GAAG,EAAE,QAAQ,CAAC;CACf;AAED,cAAM,aAAc,SAAQ,KAAK;IAI7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO;IAJ1B,SAAkB,IAAI,mBAAmB;gBAEvC,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,OAAO;CAI3B;AAkBD;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAQ/F;AAED,2EAA2E;AAC3E,wBAAsB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG7F;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAM1F;AAED,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