@fork-api/chat-sdk 0.1.132 → 0.1.134
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/dist/index.cjs +6 -6
- package/dist/index.d.cts +103 -8
- package/dist/index.d.ts +103 -8
- package/dist/index.js +6 -6
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -87,7 +87,6 @@ type ForkChatTargetInput = {
|
|
|
87
87
|
};
|
|
88
88
|
type ForkChatPanelOptions = ForkChatTargetInput;
|
|
89
89
|
type ForkChatInterfaceProps = ForkChatTargetInput & {
|
|
90
|
-
examplePrompts?: string[];
|
|
91
90
|
/**
|
|
92
91
|
* When true, render the panel flat inside its container instead of as a
|
|
93
92
|
* fixed-position side drawer. Suppresses the body-margin push and the
|
|
@@ -163,6 +162,10 @@ interface PreviewSessionPayload {
|
|
|
163
162
|
};
|
|
164
163
|
target_user_id: string;
|
|
165
164
|
operator_id: number;
|
|
165
|
+
container_id?: string | null;
|
|
166
|
+
/** Human-readable container label for preview UI. Older sessions may not
|
|
167
|
+
* have this; callers should fall back to target_user_id. */
|
|
168
|
+
container_name?: string | null;
|
|
166
169
|
/** Seeded from activate(); the SDK updates it when authoring creates a
|
|
167
170
|
* new fork. Null when the operator just landed and hasn't authored. */
|
|
168
171
|
fork_id: string | null;
|
|
@@ -182,9 +185,8 @@ declare function ForkChatInterface(props: ForkChatInterfaceProps): react_jsx_run
|
|
|
182
185
|
interface ForkBoundaryUIProps {
|
|
183
186
|
boundaryId: string;
|
|
184
187
|
title?: string;
|
|
185
|
-
examplePrompts?: string[];
|
|
186
188
|
}
|
|
187
|
-
declare function ForkBoundaryUI({ boundaryId, title
|
|
189
|
+
declare function ForkBoundaryUI({ boundaryId, title }: ForkBoundaryUIProps): react_jsx_runtime.JSX.Element;
|
|
188
190
|
|
|
189
191
|
declare function forkable<TProps extends object>(definition: ForkBoundaryDefinition<TProps>): {
|
|
190
192
|
(props: TProps): react_jsx_runtime.JSX.Element;
|
|
@@ -197,9 +199,8 @@ interface ForkUIProps {
|
|
|
197
199
|
slotId: string;
|
|
198
200
|
title?: string;
|
|
199
201
|
slotLabel?: string;
|
|
200
|
-
examplePrompts?: string[];
|
|
201
202
|
}
|
|
202
|
-
declare function ForkUI({ slotId, title, slotLabel
|
|
203
|
+
declare function ForkUI({ slotId, title, slotLabel }: ForkUIProps): react_jsx_runtime.JSX.Element;
|
|
203
204
|
|
|
204
205
|
declare function ForkButton({ onClick }: {
|
|
205
206
|
onClick?: () => void;
|
|
@@ -214,7 +215,6 @@ interface ForkPanelProps {
|
|
|
214
215
|
targetId?: string;
|
|
215
216
|
targetLabel?: string;
|
|
216
217
|
historyMode?: "slot" | "boundary" | "none";
|
|
217
|
-
examplePrompts?: string[];
|
|
218
218
|
onSubmit: (prompt: string, targetId: string, containerId?: string | null) => void;
|
|
219
219
|
onUndo?: (targetId: string) => Promise<any>;
|
|
220
220
|
onClose: () => void;
|
|
@@ -231,7 +231,7 @@ interface ForkPanelProps {
|
|
|
231
231
|
*/
|
|
232
232
|
embedded?: boolean;
|
|
233
233
|
}
|
|
234
|
-
declare function ForkPanel({ state, fork, events, error, slotId, targetId, targetLabel, historyMode,
|
|
234
|
+
declare function ForkPanel({ state, fork, events, error, slotId, targetId, targetLabel, historyMode, onSubmit, onUndo, onClose, baseUrl, apiKey, userId, userHash, appId, embedded, }: ForkPanelProps): react_jsx_runtime.JSX.Element;
|
|
235
235
|
|
|
236
236
|
declare function useFork(): {
|
|
237
237
|
state: ForkState;
|
|
@@ -307,4 +307,99 @@ declare function useForkChatPanel(options: ForkChatPanelOptions): {
|
|
|
307
307
|
close: () => void;
|
|
308
308
|
};
|
|
309
309
|
|
|
310
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Containers v2 — SDK-side manifest client.
|
|
312
|
+
*
|
|
313
|
+
* Resolves every slot + module fork for an end-user in a single round trip
|
|
314
|
+
* (vs. the per-slot fan-out the legacy /api/v1/forks/active path does), and
|
|
315
|
+
* provides stale-while-revalidate caching against localStorage so repeat
|
|
316
|
+
* visits paint with zero network latency.
|
|
317
|
+
*
|
|
318
|
+
* ForkProvider uses this for the normal end-user runtime path and for
|
|
319
|
+
* container-bound previews. Legacy preview sessions without a container still
|
|
320
|
+
* use the preview-aware overlay endpoints.
|
|
321
|
+
*
|
|
322
|
+
* Usage sketch:
|
|
323
|
+
*
|
|
324
|
+
* const cached = readCachedManifest(tenantId, appId, userId);
|
|
325
|
+
* if (cached) renderFrom(cached); // instant first paint
|
|
326
|
+
* loadManifest({...}).then((fresh) => {
|
|
327
|
+
* if (etagDiffers(cached, fresh)) renderFrom(fresh);
|
|
328
|
+
* writeCachedManifest(tenantId, appId, userId, fresh);
|
|
329
|
+
* });
|
|
330
|
+
*
|
|
331
|
+
* See §14 of docs/containers-independent-plan.html for the budget this
|
|
332
|
+
* module is built to hit (p99 ≤ 50ms cold, ≤ 30ms warm; perceptual instant
|
|
333
|
+
* on repeat visits).
|
|
334
|
+
*/
|
|
335
|
+
interface ManifestEntry {
|
|
336
|
+
forkId: string;
|
|
337
|
+
/** Immutable, build-keyed URL — safe to cache forever in the browser. */
|
|
338
|
+
bundleUrl: string | null;
|
|
339
|
+
/** Pre-v2 bundle URL (mutable). Kept around so a partial-rollback SDK
|
|
340
|
+
* can still resolve forks that don't have a build_id yet. */
|
|
341
|
+
legacyBundleUrl: string | null;
|
|
342
|
+
buildId: string | null;
|
|
343
|
+
updatedAt: string;
|
|
344
|
+
}
|
|
345
|
+
interface ManifestModuleEntry {
|
|
346
|
+
forkId: string;
|
|
347
|
+
/** Immutable, build-keyed module URL when available. */
|
|
348
|
+
moduleUrl: string | null;
|
|
349
|
+
/** Pre-v2 module URL from module_overrides.module_url. */
|
|
350
|
+
legacyModuleUrl: string | null;
|
|
351
|
+
/** Back-compat aliases while API and SDK versions overlap. */
|
|
352
|
+
bundleUrl?: string | null;
|
|
353
|
+
legacyBundleUrl?: string | null;
|
|
354
|
+
cssUrls: string[];
|
|
355
|
+
integrity?: string;
|
|
356
|
+
metadata?: Record<string, unknown>;
|
|
357
|
+
buildId: string | null;
|
|
358
|
+
updatedAt: string;
|
|
359
|
+
}
|
|
360
|
+
interface Manifest {
|
|
361
|
+
containerId: string | null;
|
|
362
|
+
slots: Record<string, ManifestEntry>;
|
|
363
|
+
modules: Record<string, ManifestModuleEntry>;
|
|
364
|
+
generatedAt: string;
|
|
365
|
+
/** Server-supplied ETag (from response header). Used to short-circuit the
|
|
366
|
+
* background refresh when nothing's changed. */
|
|
367
|
+
etag?: string;
|
|
368
|
+
}
|
|
369
|
+
interface LoadManifestInput {
|
|
370
|
+
/** Base URL of the Fork API. Pass without trailing slash. */
|
|
371
|
+
baseUrl: string;
|
|
372
|
+
/** Publishable key (pk_fork_…) — passed as Bearer. */
|
|
373
|
+
apiKey: string;
|
|
374
|
+
appId: string;
|
|
375
|
+
/** Verified user id. The server requires either this or a userHash. */
|
|
376
|
+
userId: string;
|
|
377
|
+
/** Optional userHash for HMAC verification. */
|
|
378
|
+
userHash?: string;
|
|
379
|
+
/** Authorized explicit container lookup, used for container-bound previews. */
|
|
380
|
+
containerId?: string;
|
|
381
|
+
/** Additional trusted headers, e.g. preview session headers. */
|
|
382
|
+
extraHeaders?: Record<string, string>;
|
|
383
|
+
/** Previous manifest, if any — its etag is sent as If-None-Match. */
|
|
384
|
+
previous?: Manifest;
|
|
385
|
+
/** AbortSignal for cancellation. */
|
|
386
|
+
signal?: AbortSignal;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Fetch the manifest. Returns null when the server replies 304 Not Modified
|
|
390
|
+
* (caller keeps the previous manifest). Throws on network/HTTP errors.
|
|
391
|
+
*/
|
|
392
|
+
declare function loadManifest(input: LoadManifestInput): Promise<Manifest | null>;
|
|
393
|
+
/** Read a previously-cached manifest. Returns null if absent or corrupted. */
|
|
394
|
+
declare function readCachedManifest(tenantId: string, appId: string, userId: string): Manifest | null;
|
|
395
|
+
/** Write a manifest to the cache. Best-effort — quota errors are swallowed. */
|
|
396
|
+
declare function writeCachedManifest(tenantId: string, appId: string, userId: string, manifest: Manifest): void;
|
|
397
|
+
/** Clear the cached manifest for a (tenant, app, user). */
|
|
398
|
+
declare function clearCachedManifest(tenantId: string, appId: string, userId: string): void;
|
|
399
|
+
/**
|
|
400
|
+
* Compare the resolved fork ids + build ids of two manifests. Returns true
|
|
401
|
+
* when anything user-visible has changed (so the caller should hot-swap).
|
|
402
|
+
*/
|
|
403
|
+
declare function manifestDiffers(a: Manifest | null, b: Manifest | null): boolean;
|
|
404
|
+
|
|
405
|
+
export { type Fork, type ForkBoundaryDefinition, ForkBoundaryUI, ForkButton, ForkChatInterface, type ForkChatInterfaceProps, type ForkChatPanelOptions, type ForkChatTarget, type ForkEvent, ForkPanel, ForkProvider, type ForkProviderProps, type ForkSharedRegistry, ForkSlot, type ForkSlotProps, type ForkState, ForkUI, type LoadManifestInput, type Manifest, type ManifestEntry, type ManifestModuleEntry, type PreviewSessionPayload, clearCachedManifest, forkable, loadManifest, manifestDiffers, readCachedManifest, registerForkShared, useBoundaryFork, useFork, useForkChatPanel, usePreviewSession, writeCachedManifest };
|
package/dist/index.d.ts
CHANGED
|
@@ -87,7 +87,6 @@ type ForkChatTargetInput = {
|
|
|
87
87
|
};
|
|
88
88
|
type ForkChatPanelOptions = ForkChatTargetInput;
|
|
89
89
|
type ForkChatInterfaceProps = ForkChatTargetInput & {
|
|
90
|
-
examplePrompts?: string[];
|
|
91
90
|
/**
|
|
92
91
|
* When true, render the panel flat inside its container instead of as a
|
|
93
92
|
* fixed-position side drawer. Suppresses the body-margin push and the
|
|
@@ -163,6 +162,10 @@ interface PreviewSessionPayload {
|
|
|
163
162
|
};
|
|
164
163
|
target_user_id: string;
|
|
165
164
|
operator_id: number;
|
|
165
|
+
container_id?: string | null;
|
|
166
|
+
/** Human-readable container label for preview UI. Older sessions may not
|
|
167
|
+
* have this; callers should fall back to target_user_id. */
|
|
168
|
+
container_name?: string | null;
|
|
166
169
|
/** Seeded from activate(); the SDK updates it when authoring creates a
|
|
167
170
|
* new fork. Null when the operator just landed and hasn't authored. */
|
|
168
171
|
fork_id: string | null;
|
|
@@ -182,9 +185,8 @@ declare function ForkChatInterface(props: ForkChatInterfaceProps): react_jsx_run
|
|
|
182
185
|
interface ForkBoundaryUIProps {
|
|
183
186
|
boundaryId: string;
|
|
184
187
|
title?: string;
|
|
185
|
-
examplePrompts?: string[];
|
|
186
188
|
}
|
|
187
|
-
declare function ForkBoundaryUI({ boundaryId, title
|
|
189
|
+
declare function ForkBoundaryUI({ boundaryId, title }: ForkBoundaryUIProps): react_jsx_runtime.JSX.Element;
|
|
188
190
|
|
|
189
191
|
declare function forkable<TProps extends object>(definition: ForkBoundaryDefinition<TProps>): {
|
|
190
192
|
(props: TProps): react_jsx_runtime.JSX.Element;
|
|
@@ -197,9 +199,8 @@ interface ForkUIProps {
|
|
|
197
199
|
slotId: string;
|
|
198
200
|
title?: string;
|
|
199
201
|
slotLabel?: string;
|
|
200
|
-
examplePrompts?: string[];
|
|
201
202
|
}
|
|
202
|
-
declare function ForkUI({ slotId, title, slotLabel
|
|
203
|
+
declare function ForkUI({ slotId, title, slotLabel }: ForkUIProps): react_jsx_runtime.JSX.Element;
|
|
203
204
|
|
|
204
205
|
declare function ForkButton({ onClick }: {
|
|
205
206
|
onClick?: () => void;
|
|
@@ -214,7 +215,6 @@ interface ForkPanelProps {
|
|
|
214
215
|
targetId?: string;
|
|
215
216
|
targetLabel?: string;
|
|
216
217
|
historyMode?: "slot" | "boundary" | "none";
|
|
217
|
-
examplePrompts?: string[];
|
|
218
218
|
onSubmit: (prompt: string, targetId: string, containerId?: string | null) => void;
|
|
219
219
|
onUndo?: (targetId: string) => Promise<any>;
|
|
220
220
|
onClose: () => void;
|
|
@@ -231,7 +231,7 @@ interface ForkPanelProps {
|
|
|
231
231
|
*/
|
|
232
232
|
embedded?: boolean;
|
|
233
233
|
}
|
|
234
|
-
declare function ForkPanel({ state, fork, events, error, slotId, targetId, targetLabel, historyMode,
|
|
234
|
+
declare function ForkPanel({ state, fork, events, error, slotId, targetId, targetLabel, historyMode, onSubmit, onUndo, onClose, baseUrl, apiKey, userId, userHash, appId, embedded, }: ForkPanelProps): react_jsx_runtime.JSX.Element;
|
|
235
235
|
|
|
236
236
|
declare function useFork(): {
|
|
237
237
|
state: ForkState;
|
|
@@ -307,4 +307,99 @@ declare function useForkChatPanel(options: ForkChatPanelOptions): {
|
|
|
307
307
|
close: () => void;
|
|
308
308
|
};
|
|
309
309
|
|
|
310
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Containers v2 — SDK-side manifest client.
|
|
312
|
+
*
|
|
313
|
+
* Resolves every slot + module fork for an end-user in a single round trip
|
|
314
|
+
* (vs. the per-slot fan-out the legacy /api/v1/forks/active path does), and
|
|
315
|
+
* provides stale-while-revalidate caching against localStorage so repeat
|
|
316
|
+
* visits paint with zero network latency.
|
|
317
|
+
*
|
|
318
|
+
* ForkProvider uses this for the normal end-user runtime path and for
|
|
319
|
+
* container-bound previews. Legacy preview sessions without a container still
|
|
320
|
+
* use the preview-aware overlay endpoints.
|
|
321
|
+
*
|
|
322
|
+
* Usage sketch:
|
|
323
|
+
*
|
|
324
|
+
* const cached = readCachedManifest(tenantId, appId, userId);
|
|
325
|
+
* if (cached) renderFrom(cached); // instant first paint
|
|
326
|
+
* loadManifest({...}).then((fresh) => {
|
|
327
|
+
* if (etagDiffers(cached, fresh)) renderFrom(fresh);
|
|
328
|
+
* writeCachedManifest(tenantId, appId, userId, fresh);
|
|
329
|
+
* });
|
|
330
|
+
*
|
|
331
|
+
* See §14 of docs/containers-independent-plan.html for the budget this
|
|
332
|
+
* module is built to hit (p99 ≤ 50ms cold, ≤ 30ms warm; perceptual instant
|
|
333
|
+
* on repeat visits).
|
|
334
|
+
*/
|
|
335
|
+
interface ManifestEntry {
|
|
336
|
+
forkId: string;
|
|
337
|
+
/** Immutable, build-keyed URL — safe to cache forever in the browser. */
|
|
338
|
+
bundleUrl: string | null;
|
|
339
|
+
/** Pre-v2 bundle URL (mutable). Kept around so a partial-rollback SDK
|
|
340
|
+
* can still resolve forks that don't have a build_id yet. */
|
|
341
|
+
legacyBundleUrl: string | null;
|
|
342
|
+
buildId: string | null;
|
|
343
|
+
updatedAt: string;
|
|
344
|
+
}
|
|
345
|
+
interface ManifestModuleEntry {
|
|
346
|
+
forkId: string;
|
|
347
|
+
/** Immutable, build-keyed module URL when available. */
|
|
348
|
+
moduleUrl: string | null;
|
|
349
|
+
/** Pre-v2 module URL from module_overrides.module_url. */
|
|
350
|
+
legacyModuleUrl: string | null;
|
|
351
|
+
/** Back-compat aliases while API and SDK versions overlap. */
|
|
352
|
+
bundleUrl?: string | null;
|
|
353
|
+
legacyBundleUrl?: string | null;
|
|
354
|
+
cssUrls: string[];
|
|
355
|
+
integrity?: string;
|
|
356
|
+
metadata?: Record<string, unknown>;
|
|
357
|
+
buildId: string | null;
|
|
358
|
+
updatedAt: string;
|
|
359
|
+
}
|
|
360
|
+
interface Manifest {
|
|
361
|
+
containerId: string | null;
|
|
362
|
+
slots: Record<string, ManifestEntry>;
|
|
363
|
+
modules: Record<string, ManifestModuleEntry>;
|
|
364
|
+
generatedAt: string;
|
|
365
|
+
/** Server-supplied ETag (from response header). Used to short-circuit the
|
|
366
|
+
* background refresh when nothing's changed. */
|
|
367
|
+
etag?: string;
|
|
368
|
+
}
|
|
369
|
+
interface LoadManifestInput {
|
|
370
|
+
/** Base URL of the Fork API. Pass without trailing slash. */
|
|
371
|
+
baseUrl: string;
|
|
372
|
+
/** Publishable key (pk_fork_…) — passed as Bearer. */
|
|
373
|
+
apiKey: string;
|
|
374
|
+
appId: string;
|
|
375
|
+
/** Verified user id. The server requires either this or a userHash. */
|
|
376
|
+
userId: string;
|
|
377
|
+
/** Optional userHash for HMAC verification. */
|
|
378
|
+
userHash?: string;
|
|
379
|
+
/** Authorized explicit container lookup, used for container-bound previews. */
|
|
380
|
+
containerId?: string;
|
|
381
|
+
/** Additional trusted headers, e.g. preview session headers. */
|
|
382
|
+
extraHeaders?: Record<string, string>;
|
|
383
|
+
/** Previous manifest, if any — its etag is sent as If-None-Match. */
|
|
384
|
+
previous?: Manifest;
|
|
385
|
+
/** AbortSignal for cancellation. */
|
|
386
|
+
signal?: AbortSignal;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Fetch the manifest. Returns null when the server replies 304 Not Modified
|
|
390
|
+
* (caller keeps the previous manifest). Throws on network/HTTP errors.
|
|
391
|
+
*/
|
|
392
|
+
declare function loadManifest(input: LoadManifestInput): Promise<Manifest | null>;
|
|
393
|
+
/** Read a previously-cached manifest. Returns null if absent or corrupted. */
|
|
394
|
+
declare function readCachedManifest(tenantId: string, appId: string, userId: string): Manifest | null;
|
|
395
|
+
/** Write a manifest to the cache. Best-effort — quota errors are swallowed. */
|
|
396
|
+
declare function writeCachedManifest(tenantId: string, appId: string, userId: string, manifest: Manifest): void;
|
|
397
|
+
/** Clear the cached manifest for a (tenant, app, user). */
|
|
398
|
+
declare function clearCachedManifest(tenantId: string, appId: string, userId: string): void;
|
|
399
|
+
/**
|
|
400
|
+
* Compare the resolved fork ids + build ids of two manifests. Returns true
|
|
401
|
+
* when anything user-visible has changed (so the caller should hot-swap).
|
|
402
|
+
*/
|
|
403
|
+
declare function manifestDiffers(a: Manifest | null, b: Manifest | null): boolean;
|
|
404
|
+
|
|
405
|
+
export { type Fork, type ForkBoundaryDefinition, ForkBoundaryUI, ForkButton, ForkChatInterface, type ForkChatInterfaceProps, type ForkChatPanelOptions, type ForkChatTarget, type ForkEvent, ForkPanel, ForkProvider, type ForkProviderProps, type ForkSharedRegistry, ForkSlot, type ForkSlotProps, type ForkState, ForkUI, type LoadManifestInput, type Manifest, type ManifestEntry, type ManifestModuleEntry, type PreviewSessionPayload, clearCachedManifest, forkable, loadManifest, manifestDiffers, readCachedManifest, registerForkShared, useBoundaryFork, useFork, useForkChatPanel, usePreviewSession, writeCachedManifest };
|