@civitai/sdk 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -51,9 +51,12 @@ Both give you:
51
51
  A block's `app` also has `host`, `viewer`, `context`, `settings`, `theme` and
52
52
  `onChange(listener)`. Outside a block they do not exist, and the types say so.
53
53
 
54
- > **Not yet end to end for blocks.** The host still mints a block-scoped JWT,
55
- > which `/api/v1` and the orchestrator do not accept; they take API keys and
56
- > OAuth tokens. Apps with one of those work today, from a browser or a server.
54
+ A block opts in by declaring `auth: "oauth"` in its `block.manifest.json`. The
55
+ host then hands it a real OAuth access token that `/api/v1`, the orchestrator
56
+ and the MCP accept, and consent — including `requestGrants` — goes through the
57
+ host's consent dialog. A block that does not opt in keeps the block-scoped
58
+ token, which those APIs reject; `initialize()` throws a `CivitaiError` saying
59
+ so for a signed-in viewer. Such blocks should stay on `@civitai/app-sdk`.
57
60
 
58
61
  ## Signing in outside civitai.com
59
62
 
package/dist/app/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BridgeError } from '../core/errors.js';
1
+ import { BridgeError, CivitaiError } from '../core/errors.js';
2
2
  import { getTransport } from '../core/get-transport.js';
3
3
  import { createHost, createHostSession } from '../host/index.js';
4
4
  import { createHttp } from '../http/index.js';
@@ -14,6 +14,10 @@ export async function initialize(options = {}) {
14
14
  const transport = options.transport ?? getTransport();
15
15
  await ready(transport, options.timeoutMs ?? DEFAULT_INIT_TIMEOUT_MS, options.signal);
16
16
  const snapshot = () => transport.snapshot.get();
17
+ if (snapshot().viewer !== null && snapshot().token.kind === 'block') {
18
+ throw new CivitaiError('This block receives a block-scoped token, which the Civitai API and the orchestrator ' +
19
+ 'do not accept. Declare `auth: "oauth"` in block.manifest.json to use @civitai/sdk.');
20
+ }
17
21
  return {
18
22
  ...createAppClient(createHostSession(transport), options),
19
23
  host: createHost(transport),
@@ -63,18 +63,22 @@ export interface BlockSettings {
63
63
  publisherSettings: Record<string, unknown>;
64
64
  userSettings: Record<string, unknown>;
65
65
  }
66
+ /** `block` is accepted only by the host; `oauth` also by the API and orchestrator. Older hosts send none. */
67
+ export type TokenKind = 'block' | 'oauth';
66
68
  /** A token on the wire; `expiresAt` is ISO-8601 until the transport parses it. */
67
69
  export interface WrappedToken {
68
70
  raw: string;
69
71
  scopes: string[];
70
72
  expiresAt: string;
71
73
  buzzBudget?: number;
74
+ kind?: TokenKind;
72
75
  }
73
76
  export interface BlockToken {
74
77
  raw: string;
75
78
  scopes: string[];
76
79
  expiresAt: Date;
77
80
  buzzBudget?: number;
81
+ kind?: TokenKind;
78
82
  }
79
83
  /**
80
84
  * The host still sends `blockId` and `appId`; they are build-time identity a
@@ -33,5 +33,6 @@ export function tokenFromWrapped(wrapped) {
33
33
  scopes: wrapped.scopes,
34
34
  expiresAt: new Date(wrapped.expiresAt),
35
35
  buzzBudget: wrapped.buzzBudget,
36
+ kind: wrapped.kind,
36
37
  };
37
38
  }
package/dist/index.d.ts CHANGED
@@ -21,4 +21,4 @@ export type { BridgeErrorCode, BridgeFailureCode } from './core/errors.js';
21
21
  export { getTransport } from './core/get-transport.js';
22
22
  export type { DetectOptions } from './core/get-transport.js';
23
23
  export type { BlockSnapshot, BlockTransport } from './core/transport.js';
24
- export type { BlockCheckpointInfo, BlockContext, BlockSettings, BlockToken, ColorDomain, ModelSlotContext, ModelSlotId, PageSlotContext, PageSlotId, ShowcaseImage, Theme, UnknownSlotContext, ViewerInfo, } from './core/handshake.js';
24
+ export type { BlockCheckpointInfo, BlockContext, BlockSettings, BlockToken, ColorDomain, ModelSlotContext, ModelSlotId, PageSlotContext, PageSlotId, ShowcaseImage, Theme, TokenKind, UnknownSlotContext, ViewerInfo, } from './core/handshake.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civitai/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The Civitai SDK: an app holds a token and calls the Civitai API and the orchestrator; a block asks its host only to show host UI.",
5
5
  "license": "MIT",
6
6
  "type": "module",