@neta-art/cohub 2.2.1 → 2.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/dist/chunks/http.d.ts +246 -47
- package/dist/chunks/http.js +91 -2
- package/dist/chunks/websocket.d.ts +1 -1
- package/dist/http.d.ts +2 -2
- package/dist/index.d.ts +3 -52
- package/dist/index.js +228 -51
- package/package.json +1 -1
package/dist/chunks/http.d.ts
CHANGED
|
@@ -2,50 +2,6 @@ import { n as CohubEnvironment } from "./environment.js";
|
|
|
2
2
|
import { C as ContentBlock, S as Usage, _ as SessionForkRecord, a as WebsocketClientOptions, b as SessionTurnIndexItem, d as RealtimePatchOperation, g as SessionBindingRecord$1, h as MessageRecord, m as SpacePublicEndpoints, p as SessionTurnPatchEvent, r as WebsocketClient, s as WebsocketEventPayload, v as SessionRecord$1, x as SessionTurnRecord } from "./websocket.js";
|
|
3
3
|
import { a as VoiceInputCreateOptions } from "./voice-input.js";
|
|
4
4
|
|
|
5
|
-
//#region src/transport.d.ts
|
|
6
|
-
type Fetch = typeof globalThis.fetch;
|
|
7
|
-
type RequestInitWithFetch = RequestInit & {
|
|
8
|
-
fetch?: Fetch;
|
|
9
|
-
};
|
|
10
|
-
type RawHttpResponse = {
|
|
11
|
-
response: Response;
|
|
12
|
-
blob(): Promise<Blob>;
|
|
13
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
14
|
-
text(): Promise<string>;
|
|
15
|
-
json(): Promise<unknown>;
|
|
16
|
-
};
|
|
17
|
-
type CohubClientOptions = {
|
|
18
|
-
env?: CohubEnvironment;
|
|
19
|
-
baseUrl?: string;
|
|
20
|
-
getAccessToken?: (options?: {
|
|
21
|
-
forceRefresh?: boolean;
|
|
22
|
-
}) => Promise<string | null> | string | null;
|
|
23
|
-
onUnauthorized?: () => Promise<void> | void;
|
|
24
|
-
setStoredAuthToken?: (token: string) => void;
|
|
25
|
-
clearStoredAuthToken?: () => void;
|
|
26
|
-
fetch?: Fetch;
|
|
27
|
-
websocket?: WebsocketClientOptions;
|
|
28
|
-
voice?: VoiceInputCreateOptions;
|
|
29
|
-
};
|
|
30
|
-
declare class HttpError extends Error {
|
|
31
|
-
readonly status: number;
|
|
32
|
-
readonly body: unknown;
|
|
33
|
-
readonly code: string | null;
|
|
34
|
-
constructor(message: string, status: number, body: unknown);
|
|
35
|
-
}
|
|
36
|
-
declare class HttpTransport {
|
|
37
|
-
private readonly baseUrl;
|
|
38
|
-
private readonly fetcher;
|
|
39
|
-
private readonly getAccessToken?;
|
|
40
|
-
private readonly onUnauthorized?;
|
|
41
|
-
constructor(options?: CohubClientOptions);
|
|
42
|
-
private withAuthorization;
|
|
43
|
-
private send;
|
|
44
|
-
request<T>(path: string, init?: RequestInitWithFetch): Promise<T>;
|
|
45
|
-
raw(path: string, init?: RequestInitWithFetch): Promise<RawHttpResponse>;
|
|
46
|
-
blob(path: string, init?: RequestInitWithFetch): Promise<Blob>;
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
5
|
//#region ../protocol/src/gateway/types.d.ts
|
|
50
6
|
type DiscordChannelConfig = {
|
|
51
7
|
inbound?: {
|
|
@@ -767,7 +723,9 @@ type SpaceSandboxAutoDestroyPolicy = {
|
|
|
767
723
|
} | {
|
|
768
724
|
mode: "never";
|
|
769
725
|
};
|
|
726
|
+
type SpaceSandboxProvider = "cloud" | "local";
|
|
770
727
|
type SpaceSandboxConfig = {
|
|
728
|
+
provider?: SpaceSandboxProvider;
|
|
771
729
|
autoDestroy: SpaceSandboxAutoDestroyPolicy;
|
|
772
730
|
};
|
|
773
731
|
type SpaceConfig = {
|
|
@@ -819,6 +777,7 @@ type SpaceBootstrapSource = {
|
|
|
819
777
|
};
|
|
820
778
|
type SpaceConfigInput = {
|
|
821
779
|
sandbox?: {
|
|
780
|
+
provider?: SpaceSandboxProvider;
|
|
822
781
|
autoDestroy?: SpaceSandboxAutoDestroyPolicy;
|
|
823
782
|
};
|
|
824
783
|
};
|
|
@@ -1088,7 +1047,7 @@ type CreateSpacePromptInput = {
|
|
|
1088
1047
|
provider?: string | null;
|
|
1089
1048
|
clientMessageId?: string | null;
|
|
1090
1049
|
generationPolicy?: GenerationPolicy | null;
|
|
1091
|
-
intent?: "followup" | "steer" | null;
|
|
1050
|
+
intent?: "followup" | "steer" | "compact" | null;
|
|
1092
1051
|
accessMode?: PromptAccessMode | null;
|
|
1093
1052
|
env?: Record<string, string> | null;
|
|
1094
1053
|
labelRefs?: string[];
|
|
@@ -1238,7 +1197,7 @@ type LabelAssignmentRecord = {
|
|
|
1238
1197
|
scopeId: string;
|
|
1239
1198
|
resourceType: LabelResourceType;
|
|
1240
1199
|
resourceRef: string;
|
|
1241
|
-
rank: number;
|
|
1200
|
+
rank: number | null;
|
|
1242
1201
|
source: LabelSource;
|
|
1243
1202
|
createdBy: string | null;
|
|
1244
1203
|
meta: Record<string, unknown> | null;
|
|
@@ -1257,10 +1216,17 @@ type LabelAssignmentPageInfo = {
|
|
|
1257
1216
|
hasMore: boolean;
|
|
1258
1217
|
nextCursor: string | null;
|
|
1259
1218
|
};
|
|
1219
|
+
type PatchResourceLabelsInput = {
|
|
1220
|
+
addLabelRefs?: string[];
|
|
1221
|
+
removeLabelRefs?: string[];
|
|
1222
|
+
};
|
|
1260
1223
|
type ResourceLabelsResponse = {
|
|
1261
1224
|
labels: LabelListItem[];
|
|
1262
1225
|
assignments: LabelAssignmentRecord[];
|
|
1263
1226
|
};
|
|
1227
|
+
type PatchResourceLabelsResponse = ResourceLabelsResponse & {
|
|
1228
|
+
changed: boolean;
|
|
1229
|
+
};
|
|
1264
1230
|
type SpaceModListItem = {
|
|
1265
1231
|
id: string;
|
|
1266
1232
|
spaceId: string;
|
|
@@ -1389,6 +1355,202 @@ type AcceptInvitationResponse = {
|
|
|
1389
1355
|
spaceName: string;
|
|
1390
1356
|
role: SpaceRole;
|
|
1391
1357
|
};
|
|
1358
|
+
type ReferenceResourceType = "space" | "session" | "checkpoint" | "user" | "file" | "tool";
|
|
1359
|
+
/**
|
|
1360
|
+
* Resource types usable as a query `source`. Only these have an owning space to
|
|
1361
|
+
* authorize against; user/file/tool appear only as reference targets.
|
|
1362
|
+
*/
|
|
1363
|
+
type ReferenceQueryableType = "space" | "session" | "checkpoint";
|
|
1364
|
+
type ReferenceKind = "session_fork" | "space_fork" | "checkpoint_fork" | "mention" | "tool_call" | "mod" | "participant";
|
|
1365
|
+
type ReferenceDirection = "out" | "in" | "both";
|
|
1366
|
+
type ReferenceRecord = {
|
|
1367
|
+
kind: ReferenceKind;
|
|
1368
|
+
sourceType: ReferenceResourceType;
|
|
1369
|
+
sourceId: string;
|
|
1370
|
+
sourceTurnId: string | null;
|
|
1371
|
+
targetType: ReferenceResourceType;
|
|
1372
|
+
targetId: string;
|
|
1373
|
+
spaceId: string;
|
|
1374
|
+
sessionId: string | null;
|
|
1375
|
+
count: number;
|
|
1376
|
+
createdAt: string;
|
|
1377
|
+
updatedAt: string;
|
|
1378
|
+
meta: Record<string, unknown> | null;
|
|
1379
|
+
};
|
|
1380
|
+
type ReferenceQueryResponse = {
|
|
1381
|
+
source: string;
|
|
1382
|
+
direction: ReferenceDirection;
|
|
1383
|
+
references: ReferenceRecord[];
|
|
1384
|
+
};
|
|
1385
|
+
type ReferenceAggregateGroupBy = "kind" | "targetType" | "sourceType" | "day";
|
|
1386
|
+
type ReferenceAggregateGroup = {
|
|
1387
|
+
group: string;
|
|
1388
|
+
references: number;
|
|
1389
|
+
total: number;
|
|
1390
|
+
};
|
|
1391
|
+
type ReferenceAggregateResponse = {
|
|
1392
|
+
space: string;
|
|
1393
|
+
groupBy: ReferenceAggregateGroupBy;
|
|
1394
|
+
groups: ReferenceAggregateGroup[];
|
|
1395
|
+
};
|
|
1396
|
+
//#endregion
|
|
1397
|
+
//#region src/work-runtime.d.ts
|
|
1398
|
+
type WorkRuntimeContext = {
|
|
1399
|
+
work: {
|
|
1400
|
+
id: string;
|
|
1401
|
+
slug: string;
|
|
1402
|
+
url?: string | null;
|
|
1403
|
+
};
|
|
1404
|
+
space: {
|
|
1405
|
+
id: string;
|
|
1406
|
+
name?: string | null;
|
|
1407
|
+
};
|
|
1408
|
+
viewer?: {
|
|
1409
|
+
userUuid: string;
|
|
1410
|
+
} | null;
|
|
1411
|
+
permissions?: {
|
|
1412
|
+
scopes: Permission[];
|
|
1413
|
+
workScopes: Permission[];
|
|
1414
|
+
viewerScopes: Permission[];
|
|
1415
|
+
};
|
|
1416
|
+
};
|
|
1417
|
+
type WorkRuntimeCheckoutStatus = "success" | "failed" | "cancel" | null;
|
|
1418
|
+
type WorkRuntimeCheckoutState = {
|
|
1419
|
+
status: WorkRuntimeCheckoutStatus;
|
|
1420
|
+
orderId: string | null;
|
|
1421
|
+
};
|
|
1422
|
+
/**
|
|
1423
|
+
* Options for a single work runtime transport request.
|
|
1424
|
+
*/
|
|
1425
|
+
type WorkRuntimeRequestOptions = {
|
|
1426
|
+
/** How long to wait for a matching response before resolving with null. */timeoutMs?: number; /** When set, re-posts the request on this interval until a response arrives. */
|
|
1427
|
+
retryIntervalMs?: number;
|
|
1428
|
+
};
|
|
1429
|
+
/**
|
|
1430
|
+
* Transport layer for {@link WorkRuntimeApi}. Decoupled so the same API can run
|
|
1431
|
+
* over either the iframe parent bridge (bridge mode) or a popup broker window
|
|
1432
|
+
* (broker mode). The transport is responsible for posting the request and
|
|
1433
|
+
* resolving with the first matching response (or null on timeout).
|
|
1434
|
+
*/
|
|
1435
|
+
interface WorkRuntimeTransport {
|
|
1436
|
+
request<T>(message: Record<string, unknown>, options?: WorkRuntimeRequestOptions): Promise<T | null>;
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Bridge-mode transport: posts messages to `window.parent` (the Cohub host
|
|
1440
|
+
* embedding the work in an iframe) and listens for the matching reply.
|
|
1441
|
+
* Behaviorally identical to the previous module-level `request()` helper.
|
|
1442
|
+
*/
|
|
1443
|
+
declare class ParentBridgeTransport implements WorkRuntimeTransport {
|
|
1444
|
+
private trustedParentOrigin;
|
|
1445
|
+
request<T>(message: Record<string, unknown>, options?: WorkRuntimeRequestOptions): Promise<T | null>;
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Broker-mode transport for standalone-deployed works. Opens a popup window to
|
|
1449
|
+
* the Cohub auth broker page, performs a ready-handshake, sends the request via
|
|
1450
|
+
* postMessage, and resolves with the broker's response. The popup is closed
|
|
1451
|
+
* after a single request is fulfilled (one-shot, per §7.2 of the plan).
|
|
1452
|
+
*
|
|
1453
|
+
* Non-interactive messages (`context`, `checkout-state`) are answered locally
|
|
1454
|
+
* without opening a popup — the work already knows its own workId, and
|
|
1455
|
+
* checkout state is not available on the work's own origin in broker mode.
|
|
1456
|
+
*/
|
|
1457
|
+
declare class PopupBrokerTransport implements WorkRuntimeTransport {
|
|
1458
|
+
private readonly brokerOrigin;
|
|
1459
|
+
private readonly workId;
|
|
1460
|
+
constructor(config: {
|
|
1461
|
+
brokerOrigin: string;
|
|
1462
|
+
workId: string;
|
|
1463
|
+
});
|
|
1464
|
+
request<T>(message: Record<string, unknown>, options?: WorkRuntimeRequestOptions): Promise<T | null>;
|
|
1465
|
+
}
|
|
1466
|
+
declare class WorkRuntimeApi {
|
|
1467
|
+
private token;
|
|
1468
|
+
private readonly transport;
|
|
1469
|
+
private readonly tokenStorageKey;
|
|
1470
|
+
constructor(transport?: WorkRuntimeTransport, workId?: string);
|
|
1471
|
+
private readStoredToken;
|
|
1472
|
+
private writeStoredToken;
|
|
1473
|
+
context(): Promise<WorkRuntimeContext | null>;
|
|
1474
|
+
getAccessToken(options?: {
|
|
1475
|
+
forceRefresh?: boolean;
|
|
1476
|
+
}): Promise<string | null>;
|
|
1477
|
+
requestAuthorization(input: {
|
|
1478
|
+
scopes: Permission[];
|
|
1479
|
+
reason?: string;
|
|
1480
|
+
}): Promise<boolean>;
|
|
1481
|
+
purchase(input: {
|
|
1482
|
+
productKey: string;
|
|
1483
|
+
}): Promise<{
|
|
1484
|
+
providerKey: string | null;
|
|
1485
|
+
checkoutUrl: string | null;
|
|
1486
|
+
checkoutUsable: boolean;
|
|
1487
|
+
status: string | null;
|
|
1488
|
+
message: string | null;
|
|
1489
|
+
orderId: string;
|
|
1490
|
+
productKey: string;
|
|
1491
|
+
} | null>;
|
|
1492
|
+
checkoutState(): Promise<WorkRuntimeCheckoutState | null>;
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Configuration for the work runtime mode.
|
|
1496
|
+
*/
|
|
1497
|
+
type WorkRuntimeModeConfig = {
|
|
1498
|
+
/** Explicit mode selection. When omitted, auto-detection is used. */mode?: "bridge" | "broker"; /** Cohub origin for the broker page (e.g. "https://cohub.run"). */
|
|
1499
|
+
brokerOrigin?: string; /** The work's public id. Required for broker mode. */
|
|
1500
|
+
workId?: string;
|
|
1501
|
+
};
|
|
1502
|
+
/**
|
|
1503
|
+
* Resolves the appropriate transport based on the work mode configuration.
|
|
1504
|
+
* Auto-detection: inside an iframe → bridge; standalone with broker config →
|
|
1505
|
+
* broker; otherwise → bridge (returns null for non-work contexts).
|
|
1506
|
+
*/
|
|
1507
|
+
declare function resolveWorkTransport(config?: WorkRuntimeModeConfig): WorkRuntimeTransport;
|
|
1508
|
+
declare const createWorkRuntime: (transport?: WorkRuntimeTransport, workId?: string) => WorkRuntimeApi;
|
|
1509
|
+
//#endregion
|
|
1510
|
+
//#region src/transport.d.ts
|
|
1511
|
+
type Fetch = typeof globalThis.fetch;
|
|
1512
|
+
type RequestInitWithFetch = RequestInit & {
|
|
1513
|
+
fetch?: Fetch;
|
|
1514
|
+
};
|
|
1515
|
+
type RawHttpResponse = {
|
|
1516
|
+
response: Response;
|
|
1517
|
+
blob(): Promise<Blob>;
|
|
1518
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
1519
|
+
text(): Promise<string>;
|
|
1520
|
+
json(): Promise<unknown>;
|
|
1521
|
+
};
|
|
1522
|
+
type CohubClientOptions = {
|
|
1523
|
+
env?: CohubEnvironment;
|
|
1524
|
+
baseUrl?: string;
|
|
1525
|
+
getAccessToken?: (options?: {
|
|
1526
|
+
forceRefresh?: boolean;
|
|
1527
|
+
}) => Promise<string | null> | string | null;
|
|
1528
|
+
onUnauthorized?: () => Promise<void> | void;
|
|
1529
|
+
setStoredAuthToken?: (token: string) => void;
|
|
1530
|
+
clearStoredAuthToken?: () => void;
|
|
1531
|
+
fetch?: Fetch;
|
|
1532
|
+
websocket?: WebsocketClientOptions;
|
|
1533
|
+
voice?: VoiceInputCreateOptions; /** Work runtime mode configuration (bridge vs broker). */
|
|
1534
|
+
work?: WorkRuntimeModeConfig;
|
|
1535
|
+
};
|
|
1536
|
+
declare class HttpError extends Error {
|
|
1537
|
+
readonly status: number;
|
|
1538
|
+
readonly body: unknown;
|
|
1539
|
+
readonly code: string | null;
|
|
1540
|
+
constructor(message: string, status: number, body: unknown);
|
|
1541
|
+
}
|
|
1542
|
+
declare class HttpTransport {
|
|
1543
|
+
private readonly baseUrl;
|
|
1544
|
+
private readonly fetcher;
|
|
1545
|
+
private readonly getAccessToken?;
|
|
1546
|
+
private readonly onUnauthorized?;
|
|
1547
|
+
constructor(options?: CohubClientOptions);
|
|
1548
|
+
private withAuthorization;
|
|
1549
|
+
private send;
|
|
1550
|
+
request<T>(path: string, init?: RequestInitWithFetch): Promise<T>;
|
|
1551
|
+
raw(path: string, init?: RequestInitWithFetch): Promise<RawHttpResponse>;
|
|
1552
|
+
blob(path: string, init?: RequestInitWithFetch): Promise<Blob>;
|
|
1553
|
+
}
|
|
1392
1554
|
//#endregion
|
|
1393
1555
|
//#region src/apis/channels.d.ts
|
|
1394
1556
|
declare class ChannelsApi {
|
|
@@ -1560,6 +1722,35 @@ declare class SearchApi {
|
|
|
1560
1722
|
}, customFetch?: Fetch): Promise<GlobalSearchResponse>;
|
|
1561
1723
|
}
|
|
1562
1724
|
//#endregion
|
|
1725
|
+
//#region src/apis/references.d.ts
|
|
1726
|
+
type ReferenceResourceSelector = `${ReferenceQueryableType}:${string}` | {
|
|
1727
|
+
type: ReferenceQueryableType;
|
|
1728
|
+
id: string;
|
|
1729
|
+
};
|
|
1730
|
+
/**
|
|
1731
|
+
* Neutral access to the resource reference index. `query` lists references
|
|
1732
|
+
* touching a resource; `aggregate` returns grouped counts for a space. Callers
|
|
1733
|
+
* assemble collaboration graphs, lineage views, rankings, or trends from the
|
|
1734
|
+
* returned data.
|
|
1735
|
+
*/
|
|
1736
|
+
declare class ReferencesApi {
|
|
1737
|
+
private readonly transport;
|
|
1738
|
+
constructor(transport: HttpTransport);
|
|
1739
|
+
query(input: {
|
|
1740
|
+
source: ReferenceResourceSelector;
|
|
1741
|
+
direction?: ReferenceDirection;
|
|
1742
|
+
kinds?: ReferenceKind[];
|
|
1743
|
+
days?: number;
|
|
1744
|
+
limit?: number;
|
|
1745
|
+
}, customFetch?: Fetch): Promise<ReferenceQueryResponse>;
|
|
1746
|
+
aggregate(input: {
|
|
1747
|
+
spaceId: string;
|
|
1748
|
+
groupBy?: ReferenceAggregateGroupBy;
|
|
1749
|
+
kinds?: ReferenceKind[];
|
|
1750
|
+
days?: number;
|
|
1751
|
+
}, customFetch?: Fetch): Promise<ReferenceAggregateResponse>;
|
|
1752
|
+
}
|
|
1753
|
+
//#endregion
|
|
1563
1754
|
//#region src/apis/session-access.d.ts
|
|
1564
1755
|
declare class SessionAccessApi {
|
|
1565
1756
|
private readonly transport;
|
|
@@ -2072,6 +2263,7 @@ declare class SpaceEnvApi {
|
|
|
2072
2263
|
}>;
|
|
2073
2264
|
}
|
|
2074
2265
|
type SpaceSandboxRecord = {
|
|
2266
|
+
provider?: "cloud" | "local";
|
|
2075
2267
|
status: string | null;
|
|
2076
2268
|
runtimeStatus?: string | null;
|
|
2077
2269
|
podName?: string | null;
|
|
@@ -2151,6 +2343,7 @@ declare class SpaceLabelsApi {
|
|
|
2151
2343
|
labels: LabelListItem[];
|
|
2152
2344
|
assignments: LabelAssignmentRecord[];
|
|
2153
2345
|
}>;
|
|
2346
|
+
patchResourceLabels(resourceType: LabelResourceType, resourceRef: string, input: PatchResourceLabelsInput): Promise<PatchResourceLabelsResponse>;
|
|
2154
2347
|
setResourceLabels(resourceType: LabelResourceType, resourceRef: string, labelRefs: string[]): Promise<{
|
|
2155
2348
|
labels: LabelListItem[];
|
|
2156
2349
|
assignments: LabelAssignmentRecord[];
|
|
@@ -2506,6 +2699,11 @@ declare class WorksApi {
|
|
|
2506
2699
|
works: WorkRecord[];
|
|
2507
2700
|
}>;
|
|
2508
2701
|
get(id: string): Promise<WorkDetailResponse>;
|
|
2702
|
+
/**
|
|
2703
|
+
* Loads a published work's metadata + owner info by id (public access model).
|
|
2704
|
+
* Used by the standalone work auth broker page.
|
|
2705
|
+
*/
|
|
2706
|
+
getPublicById(id: string): Promise<WorkDetailResponse>;
|
|
2509
2707
|
getBySlug(username: string, spaceSlug: string, workSlug: string): Promise<WorkDetailResponse>;
|
|
2510
2708
|
create(input: WorkCreateInput): Promise<{
|
|
2511
2709
|
work: WorkRecord;
|
|
@@ -2609,6 +2807,7 @@ declare class CohubHttpClient {
|
|
|
2609
2807
|
readonly publicAssets: PublicAssetsApi;
|
|
2610
2808
|
readonly sessionAccess: SessionAccessApi;
|
|
2611
2809
|
readonly search: SearchApi;
|
|
2810
|
+
readonly references: ReferencesApi;
|
|
2612
2811
|
readonly tasks: TasksApi;
|
|
2613
2812
|
readonly cronJobs: CronJobsApi;
|
|
2614
2813
|
readonly invite: PublicInviteApi;
|
|
@@ -2620,4 +2819,4 @@ declare class CohubHttpClient {
|
|
|
2620
2819
|
}
|
|
2621
2820
|
declare const createHttpClient: (options?: CohubClientOptions) => CohubHttpClient;
|
|
2622
2821
|
//#endregion
|
|
2623
|
-
export { parseAssistantMessageCommit as $,
|
|
2822
|
+
export { parseAssistantMessageCommit as $, GenerationContentBlock as $i, PatchResourceLabelsInput as $n, SpaceFsFileKind as $r, BillingCreditStatus as $t, TasksApi as A, SpaceUsageResponse as Ai, CronJobRecord as An, SpaceBootstrapSource as Ar, WorkRuntimeCheckoutState as At, GenerationStreamCommitEvent as B, PublicGenerationDeclaration as Bi, JsonObject as Bn, SpaceCommerceProductCreditBenefit as Br, BatchUserProfilesResponse as Bt, WorkStatus as C, SpaceRecord as Ci, CreateInvitationResponse as Cn, SessionTurnResponse as Cr, Fetch as Ct, WorkVisibility as D, SpaceSandboxProvider as Di, CreateSpacePromptResponse as Dn, SessionTurnsPaginatedResponse as Dr, ParentBridgeTransport as Dt, WorkVersionRecord as E, SpaceSandboxConfig as Ei, CreateSpacePromptInput as En, SessionTurnWindowResponse as Er, RawHttpResponse as Et, SpaceEventName as F, UserRulesResponse as Fi, ExploreSpacesResponse as Fn, SpaceCommerceCreditsBenefit as Fr, WorkRuntimeTransport as Ft, GenerationStreamLifecycleEvent as G, assertGenerationRequestAllowedByPolicy as Gi, LabelAssignmentRecord as Gn, SpaceDefaultResponse as Gr, BillingBalanceActivityStatus as Gt, GenerationStreamEvent as H, GenerationParameterConstraint as Hi, JsonValue as Hn, SpaceConfigInput as Hr, BillingBalanceActivity as Ht, SpacesApi as I, CreateGenerationTaskRequest as Ii, GlobalSearchResponse as In, SpaceCommerceFeatureBenefit as Ir, createWorkRuntime as It, GenerationStreamSubscribeOptions as J, filterGenerationDeclarationsByPolicy as Ji, LabelResourceType as Jn, SpaceFsCompleteUploadResponse as Jr, BillingCheckoutActionState as Jt, GenerationStreamOutOfSyncEvent as K, decodeGenerationPolicy as Ki, LabelListItem as Kn, SpaceEnvInput as Kr, BillingCatalog as Kt, WebSocketConnectionState as L, CreateGenerationTaskResponse as Li, GlobalSearchResult as Ln, SpaceCommerceOrder as Lr, resolveWorkTransport as Lt, SessionSubscriptionHandlers as M, TaskRunDetailResponse as Mi, CursorPageInfo as Mn, SpaceCheckpointDetailResponse as Mr, WorkRuntimeContext as Mt, SpaceChannelBindingRecord as N, TaskRunRecord as Ni, ExploreSection as Nn, SpaceCommerceBenefit as Nr, WorkRuntimeModeConfig as Nt, WorksApi as O, SpaceSessionsResponse as Oi, CreateSpaceSessionInput as On, SpaceAccess as Or, PopupBrokerTransport as Ot, SpaceClient as P, UserProfile as Pi, ExploreSpaceItem as Pn, SpaceCommerceBuyerProfile as Pr, WorkRuntimeRequestOptions as Pt, createSessionGenerationStreamClient as Q, parseGenerationPolicyFromEnv as Qi, ModelCatalogEntry as Qn, SpaceFsEntry as Qr, BillingCreditGrantStatus as Qt, PublicInviteApi as R, GenerationTaskResult as Ri, GlobalSearchType as Rn, SpaceCommerceProduct as Rr, AcceptInvitationResponse as Rt, WorkSessionResponse as S, SpacePublicProfile as Si, CreateInvitationInput as Sn, SessionTurnIndexResponse as Sr, CohubClientOptions as St, WorkUpdateInput as T, SpaceSandboxAutoDestroyPolicy as Ti, CreateSpaceModInput as Tn, SessionTurnStreamSnapshotResponse as Tr, HttpTransport as Tt, GenerationStreamFinalizedEvent as U, GenerationPolicy as Ui, LabelAssignmentListItem as Un, SpaceConfigResponse as Ur, BillingBalanceActivityKind as Ut, GenerationStreamErrorEvent as V, GenerationModelPolicy as Vi, JsonPrimitive as Vn, SpaceConfig as Vr, BillingAccessWarning as Vt, GenerationStreamIntermediateMessage as W, GenerationPolicyError as Wi, LabelAssignmentPageInfo as Wn, SpaceCreateResponse as Wr, BillingBalanceActivityList as Wt, GenerationStreamTurnUpdatedEvent as X, getAllowedGenerationModelIds as Xi, LabelSource as Xn, SpaceFsCreateUploadResponse as Xr, BillingConversionIntent as Xt, GenerationStreamSubscriptionHandlers as Y, findGenerationModelPolicy as Yi, LabelScopeType as Yn, SpaceFsCreateUploadInput as Yr, BillingCheckoutResult as Yt, SessionGenerationStreamClient as Z, normalizeGenerationPolicy as Zi, MeResponse as Zn, SpaceFsEncoding as Zr, BillingCreditExpiryGroup as Zt, WorkPresentationMeta as _, SpaceMember as _i, CanvasNodeRecord as _n, SessionBindingRecord as _r, PromptsApi as _t, WorkCommerceCreditConsumeResponse as a, SpaceFsReadFilesResponse as ai, BillingProductCreditBenefit as an, PublicUserProfile as ar, createSessionPatchReducer as at, WorkRecord as b, SpacePresenceSnapshot as bi, Channel as bn, SessionMessagesResponse as br, CronJobsApi as bt, WorkCommerceEntitlementsResponse as c, SpaceFsUploadEntry as ci, BillingProductPricing as cn, ReferenceAggregateResponse as cr, ReferencesApi as ct, WorkCommercePurchaseResponse as d, SpaceFsUploadPlanEntryInput as di, BillingSubscriptionHistoryStatus as dn, ReferenceQueryResponse as dr, CreatePublicAssetUploadResponse as dt, ChannelConfig as ea, SpaceFsFileResponse as ei, BillingCreditUnit as en, PatchResourceLabelsResponse as er, SessionPatchApplyInput as et, WorkAuthorizeResponse as f, SpaceFsUploadProgress as fi, BillingSubscriptionSummary as fn, ReferenceQueryableType as fr, PublicAssetMimeType as ft, WorkMeta as g, SpaceListItem as gi, CanvasNodeInput as gn, SendMessageCronJobPayload as gr, UploadPublicAssetInput as gt, WorkGetResponse as h, SpaceInvitation as hi, CanvasDocumentRecord as hn, ResourceLabelsResponse as hr, UploadChatImageAttachmentInput as ht, WorkCommerceCheckoutStatus as i, SpaceFsReadFilesInput as ii, BillingProductBillingInterval as in, PromptTemplateCatalogResponse as ir, SessionPatchStatus as it, SessionEventName as j, SpaceUsageSummary as ji, CronJobUpdatePatch as jn, SpaceChannelBindingInput as jr, WorkRuntimeCheckoutStatus as jt, UserApi as k, SpaceUsageHourlyStat as ki, CronJobPayload as kn, SpaceAccessPolicy as kr, WorkRuntimeApi as kt, WorkCommerceOrder as l, SpaceFsUploadError as li, BillingRedemptionResult as ln, ReferenceDirection as lr, SearchApi as lt, WorkDetailResponse as m, SpaceFsWriteFileInput as mi, CanvasCreateInput as mn, ReferenceResourceType as mr, PublicAssetsApi as mt, createHttpClient as n, SpaceFsPreparingFile as ni, BillingPaymentStatus as nn, PromptAccessMode as nr, SessionPatchReducer as nt, WorkCommerceCreditConsumeStatus as o, SpaceFsTreeResponse as oi, BillingProductDisplay as on, ReferenceAggregateGroup as or, SessionAccessApi as ot, WorkCreateInput as p, SpaceFsUploadResponse as pi, CanvasBootstrapResponse as pn, ReferenceRecord as pr, PublicAssetPurpose as pt, GenerationStreamStateEvent as q, encodeGenerationPolicy as qi, LabelRecord as qn, SpaceFsCompleteUploadInput as qr, BillingCatalogProduct as qt, WorkCommerceApi as r, SpaceFsReadFilesError as ri, BillingPluginStatus as rn, PromptTemplateCatalogEntry as rr, SessionPatchState as rt, WorkCommerceEntitlement as s, SpaceFsUploadDestination as si, BillingProductKind as sn, ReferenceAggregateGroupBy as sr, ReferenceResourceSelector as st, CohubHttpClient as t, DiscordChannelConfig as ta, SpaceFsMoveInput as ti, BillingHistoryPagination as tn, Permission as tr, SessionPatchApplyResult as tt, WorkCommerceProductResolveResponse as u, SpaceFsUploadPlanEntry as ui, BillingSubscriptionHistoryList as un, ReferenceKind as ur, CreatePublicAssetUploadInput as ut, WorkPublicOwnerRecord as v, SpaceMeta as vi, CanvasSemanticOp as vn, SessionMessageResponse as vr, ModelsApi as vt, WorkTargetType as w, SpaceRole as wi, CreateSpaceInput as wn, SessionTurnSignedUrlsResponse as wr, HttpError as wt, WorkResolveResponse as x, SpacePresenceUser as xi, CheckpointRecord as xn, SessionRecord as xr, ChannelsApi as xt, WorkPublicSpaceRecord as y, SpaceModListItem as yi, CanvasTransactionInput as yn, SessionMessagesPaginatedResponse as yr, GenerationsApi as yt, AssistantMessageCommit as z, ListGenerationModelsResponse as zi, InvitationDetail as zn, SpaceCommerceProductBenefitBinding as zr, ApiError as zt };
|
package/dist/chunks/http.js
CHANGED
|
@@ -236,6 +236,36 @@ var SearchApi = class {
|
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
238
|
//#endregion
|
|
239
|
+
//#region src/apis/references.ts
|
|
240
|
+
const toSelector = (ref) => typeof ref === "string" ? ref : `${ref.type}:${ref.id}`;
|
|
241
|
+
/**
|
|
242
|
+
* Neutral access to the resource reference index. `query` lists references
|
|
243
|
+
* touching a resource; `aggregate` returns grouped counts for a space. Callers
|
|
244
|
+
* assemble collaboration graphs, lineage views, rankings, or trends from the
|
|
245
|
+
* returned data.
|
|
246
|
+
*/
|
|
247
|
+
var ReferencesApi = class {
|
|
248
|
+
transport;
|
|
249
|
+
constructor(transport) {
|
|
250
|
+
this.transport = transport;
|
|
251
|
+
}
|
|
252
|
+
query(input, customFetch) {
|
|
253
|
+
const params = new URLSearchParams({ source: toSelector(input.source) });
|
|
254
|
+
if (input.direction) params.set("direction", input.direction);
|
|
255
|
+
if (input.kinds && input.kinds.length > 0) params.set("kinds", input.kinds.join(","));
|
|
256
|
+
if (input.days !== void 0) params.set("days", String(input.days));
|
|
257
|
+
if (input.limit !== void 0) params.set("limit", String(input.limit));
|
|
258
|
+
return this.transport.request(`/api/references?${params.toString()}`, { fetch: customFetch });
|
|
259
|
+
}
|
|
260
|
+
aggregate(input, customFetch) {
|
|
261
|
+
const params = new URLSearchParams({ space: input.spaceId });
|
|
262
|
+
if (input.groupBy) params.set("groupBy", input.groupBy);
|
|
263
|
+
if (input.kinds && input.kinds.length > 0) params.set("kinds", input.kinds.join(","));
|
|
264
|
+
if (input.days !== void 0) params.set("days", String(input.days));
|
|
265
|
+
return this.transport.request(`/api/references/aggregate?${params.toString()}`, { fetch: customFetch });
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
//#endregion
|
|
239
269
|
//#region src/apis/session-access.ts
|
|
240
270
|
var SessionAccessApi = class {
|
|
241
271
|
transport;
|
|
@@ -882,6 +912,48 @@ function getIntermediateMessageKey(message) {
|
|
|
882
912
|
return null;
|
|
883
913
|
}
|
|
884
914
|
}
|
|
915
|
+
function getToolUseIds(content) {
|
|
916
|
+
return content.filter((block) => block.type === "tool_use").map((block) => block.id);
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Root cause (each_key_duplicate): assistant_intermediate messages persisted via
|
|
920
|
+
* `session.message.persisted` never carried `meta.messageOrdinal` (the agent only
|
|
921
|
+
* attached it to the `stream_update`/`session.turn.patch` payload, not to the
|
|
922
|
+
* persisted message meta). `messageRecordToIntermediate` then falls back to
|
|
923
|
+
* `messageId`/`message.id` (a DB UUID) for those records, while the stream-snapshot
|
|
924
|
+
* REST API re-numbers messages by array index (`ordinal:N`). The same logical
|
|
925
|
+
* message ends up under two incompatible dedupe keys when a snapshot-recovery path
|
|
926
|
+
* (ordinal-keyed) and a persisted-message path (id-keyed) both feed into the same
|
|
927
|
+
* intermediateMessages array — producing duplicate entries that crash Svelte's
|
|
928
|
+
* `{#each ... (id)}` in ProcessCard/ToolCallList with each_key_duplicate.
|
|
929
|
+
*
|
|
930
|
+
* The backend fix (apps/agent/src/persistence.ts) now always writes messageOrdinal
|
|
931
|
+
* into persisted meta so both paths share one key space going forward. This
|
|
932
|
+
* cross-key pass stays as defense-in-depth for any message that still lacks an
|
|
933
|
+
* ordinal (e.g. data persisted before the backend fix, or future gaps): if two
|
|
934
|
+
* entries land under different dedupe keys but share a tool_use.id, they are the
|
|
935
|
+
* same logical message and must be merged into one.
|
|
936
|
+
*/
|
|
937
|
+
function mergeMessagesSharingToolUseId(messages) {
|
|
938
|
+
const indexByToolUseId = /* @__PURE__ */ new Map();
|
|
939
|
+
const merged = [];
|
|
940
|
+
for (const message of messages) {
|
|
941
|
+
const toolUseIds = getToolUseIds(message.content ?? []);
|
|
942
|
+
const existingIndex = toolUseIds.map((id) => indexByToolUseId.get(id)).find((idx) => idx != null);
|
|
943
|
+
if (existingIndex == null) {
|
|
944
|
+
const newIndex = merged.length;
|
|
945
|
+
merged.push(message);
|
|
946
|
+
for (const id of toolUseIds) indexByToolUseId.set(id, newIndex);
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
merged[existingIndex] = {
|
|
950
|
+
...merged[existingIndex],
|
|
951
|
+
...message
|
|
952
|
+
};
|
|
953
|
+
for (const id of toolUseIds) indexByToolUseId.set(id, existingIndex);
|
|
954
|
+
}
|
|
955
|
+
return merged;
|
|
956
|
+
}
|
|
885
957
|
function compactIntermediateMessages(messages) {
|
|
886
958
|
const merged = [];
|
|
887
959
|
const indexByKey = /* @__PURE__ */ new Map();
|
|
@@ -902,7 +974,7 @@ function compactIntermediateMessages(messages) {
|
|
|
902
974
|
...message
|
|
903
975
|
};
|
|
904
976
|
}
|
|
905
|
-
return merged;
|
|
977
|
+
return mergeMessagesSharingToolUseId(merged);
|
|
906
978
|
}
|
|
907
979
|
function normalizeSnapshotIntermediateMessages(messages) {
|
|
908
980
|
return compactIntermediateMessages(messages.filter((message) => Array.isArray(message.content)).map((message) => ({
|
|
@@ -2003,6 +2075,14 @@ var SpaceLabelsApi = class {
|
|
|
2003
2075
|
const params = new URLSearchParams({ resourceRef });
|
|
2004
2076
|
return this.transport.request(`/api/spaces/${this.spaceId}/resources/${resourceType}/labels?${params.toString()}`);
|
|
2005
2077
|
}
|
|
2078
|
+
patchResourceLabels(resourceType, resourceRef, input) {
|
|
2079
|
+
const params = new URLSearchParams({ resourceRef });
|
|
2080
|
+
return this.transport.request(`/api/spaces/${this.spaceId}/resources/${resourceType}/labels?${params.toString()}`, {
|
|
2081
|
+
method: "PATCH",
|
|
2082
|
+
headers: { "Content-Type": "application/json" },
|
|
2083
|
+
body: JSON.stringify(input)
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2006
2086
|
setResourceLabels(resourceType, resourceRef, labelRefs) {
|
|
2007
2087
|
const params = new URLSearchParams({ resourceRef });
|
|
2008
2088
|
return this.transport.request(`/api/spaces/${this.spaceId}/resources/${resourceType}/labels?${params.toString()}`, {
|
|
@@ -2397,6 +2477,13 @@ var WorksApi = class {
|
|
|
2397
2477
|
get(id) {
|
|
2398
2478
|
return this.transport.request(`/api/works/${id}`);
|
|
2399
2479
|
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Loads a published work's metadata + owner info by id (public access model).
|
|
2482
|
+
* Used by the standalone work auth broker page.
|
|
2483
|
+
*/
|
|
2484
|
+
getPublicById(id) {
|
|
2485
|
+
return this.transport.request(`/api/works/${id}/public`);
|
|
2486
|
+
}
|
|
2400
2487
|
getBySlug(username, spaceSlug, workSlug) {
|
|
2401
2488
|
return this.transport.request(`/api/works/by-slug/${encodeURIComponent(username)}/${encodeURIComponent(spaceSlug)}/${encodeURIComponent(workSlug)}`);
|
|
2402
2489
|
}
|
|
@@ -2481,6 +2568,7 @@ var CohubHttpClient = class {
|
|
|
2481
2568
|
publicAssets;
|
|
2482
2569
|
sessionAccess;
|
|
2483
2570
|
search;
|
|
2571
|
+
references;
|
|
2484
2572
|
tasks;
|
|
2485
2573
|
cronJobs;
|
|
2486
2574
|
invite;
|
|
@@ -2499,6 +2587,7 @@ var CohubHttpClient = class {
|
|
|
2499
2587
|
this.publicAssets = new PublicAssetsApi(this.transport);
|
|
2500
2588
|
this.sessionAccess = new SessionAccessApi(this.transport);
|
|
2501
2589
|
this.search = new SearchApi(this.transport);
|
|
2590
|
+
this.references = new ReferencesApi(this.transport);
|
|
2502
2591
|
this.tasks = new TasksApi(this.transport);
|
|
2503
2592
|
this.cronJobs = new CronJobsApi(this.transport);
|
|
2504
2593
|
this.invite = new PublicInviteApi(this.transport);
|
|
@@ -2511,4 +2600,4 @@ var CohubHttpClient = class {
|
|
|
2511
2600
|
};
|
|
2512
2601
|
const createHttpClient = (options) => new CohubHttpClient(options);
|
|
2513
2602
|
//#endregion
|
|
2514
|
-
export {
|
|
2603
|
+
export { GenerationsApi as C, ModelsApi as S, ChannelsApi as T, SessionAccessApi as _, UserApi as a, PublicAssetsApi as b, SpacesApi as c, createSessionGenerationStreamClient as d, parseAssistantMessageCommit as f, HttpTransport as g, HttpError as h, WorksApi as i, PublicInviteApi as l, createSessionPatchReducer as m, createHttpClient as n, TasksApi as o, SessionPatchReducer as p, WorkCommerceApi as r, SpaceClient as s, CohubHttpClient as t, SessionGenerationStreamClient as u, ReferencesApi as v, CronJobsApi as w, PromptsApi as x, SearchApi as y };
|
|
@@ -64,7 +64,7 @@ type Usage = {
|
|
|
64
64
|
//#endregion
|
|
65
65
|
//#region ../protocol/src/model/turn.d.ts
|
|
66
66
|
type SessionTurnStatus = "queued" | "running" | "abort_requested" | "completed" | "failed" | "interrupted" | "merged" | "cancelled";
|
|
67
|
-
type SessionTurnIntent = "steer" | "followup";
|
|
67
|
+
type SessionTurnIntent = "steer" | "followup" | "compact";
|
|
68
68
|
type SessionTurnSummary = {
|
|
69
69
|
text?: string | null;
|
|
70
70
|
finishReason?: "completed" | "failed" | "interrupted" | "merged" | "cancelled";
|
package/dist/http.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { C as ContentBlock, _ as SessionForkRecord, b as SessionTurnIndexItem, h as MessageRecord, x as SessionTurnRecord, y as SessionTurnSegmentRecord } from "./chunks/websocket.js";
|
|
2
|
-
import { $n as
|
|
3
|
-
export { AcceptInvitationResponse, ApiError, BatchUserProfilesResponse, BillingAccessWarning, BillingBalanceActivity, BillingBalanceActivityKind, BillingBalanceActivityList, BillingBalanceActivityStatus, BillingCatalog, BillingCatalogProduct, BillingCheckoutActionState, BillingCheckoutResult, BillingConversionIntent, BillingCreditExpiryGroup, BillingCreditGrantStatus, BillingCreditStatus, BillingCreditUnit, BillingHistoryPagination, BillingPaymentStatus, BillingPluginStatus, BillingProductBillingInterval, BillingProductCreditBenefit, BillingProductDisplay, BillingProductKind, BillingProductPricing, BillingRedemptionResult, BillingSubscriptionHistoryList, BillingSubscriptionHistoryStatus, BillingSubscriptionSummary, CanvasBootstrapResponse, CanvasCreateInput, CanvasDocumentRecord, CanvasNodeInput, CanvasNodeRecord, CanvasSemanticOp, CanvasTransactionInput, Channel, type ChannelConfig, CheckpointRecord, type CohubClientOptions, CohubHttpClient, type ContentBlock, type CreateGenerationTaskRequest, type CreateGenerationTaskResponse, CreateInvitationInput, CreateInvitationResponse, CreateSpaceInput, CreateSpaceModInput, CreateSpacePromptInput, CreateSpacePromptResponse, CreateSpaceSessionInput, CronJobPayload, CronJobRecord, CronJobUpdatePatch, CursorPageInfo, type DiscordChannelConfig, ExploreSection, ExploreSpaceItem, ExploreSpacesResponse, type Fetch, type GenerationContentBlock, type GenerationPolicy, type GenerationTaskResult, GlobalSearchResponse, GlobalSearchResult, GlobalSearchType, HttpError, HttpTransport, InvitationDetail, JsonObject, JsonPrimitive, JsonValue, LabelAssignmentListItem, LabelAssignmentPageInfo, LabelAssignmentRecord, LabelListItem, LabelRecord, LabelResourceType, LabelScopeType, LabelSource, type ListGenerationModelsResponse, MeResponse, type MessageRecord, ModelCatalogEntry, Permission, PromptAccessMode, PromptTemplateCatalogEntry, PromptTemplateCatalogResponse, type PublicGenerationDeclaration, PublicUserProfile, ResourceLabelsResponse, SendMessageCronJobPayload, SessionBindingRecord, type SessionForkRecord, SessionMessageResponse, SessionMessagesPaginatedResponse, SessionMessagesResponse, SessionRecord, type SessionTurnIndexItem, SessionTurnIndexResponse, type SessionTurnRecord, SessionTurnResponse, type SessionTurnSegmentRecord, SessionTurnSignedUrlsResponse, SessionTurnStreamSnapshotResponse, SessionTurnWindowResponse, SessionTurnsPaginatedResponse, SpaceAccess, SpaceAccessPolicy, SpaceBootstrapSource, SpaceChannelBindingInput, SpaceCheckpointDetailResponse, SpaceCommerceBenefit, SpaceCommerceBuyerProfile, SpaceCommerceCreditsBenefit, SpaceCommerceFeatureBenefit, SpaceCommerceOrder, SpaceCommerceProduct, SpaceCommerceProductBenefitBinding, SpaceCommerceProductCreditBenefit, SpaceConfig, SpaceConfigInput, SpaceConfigResponse, SpaceCreateResponse, SpaceDefaultResponse, SpaceEnvInput, SpaceFsCompleteUploadInput, SpaceFsCompleteUploadResponse, SpaceFsCreateUploadInput, SpaceFsCreateUploadResponse, SpaceFsEncoding, SpaceFsEntry, SpaceFsFileKind, SpaceFsFileResponse, SpaceFsMoveInput, SpaceFsPreparingFile, SpaceFsReadFilesError, SpaceFsReadFilesInput, SpaceFsReadFilesResponse, SpaceFsTreeResponse, SpaceFsUploadDestination, SpaceFsUploadEntry, SpaceFsUploadError, SpaceFsUploadPlanEntry, SpaceFsUploadPlanEntryInput, SpaceFsUploadProgress, SpaceFsUploadResponse, SpaceFsWriteFileInput, SpaceInvitation, SpaceListItem, SpaceMember, SpaceMeta, SpaceModListItem, SpacePresenceSnapshot, SpacePresenceUser, SpacePublicProfile, SpaceRecord, SpaceRole, SpaceSandboxAutoDestroyPolicy, SpaceSandboxConfig, SpaceSessionsResponse, SpaceUsageHourlyStat, SpaceUsageResponse, SpaceUsageSummary, TaskRunDetailResponse, TaskRunRecord, UserProfile, UserRulesResponse, createHttpClient };
|
|
2
|
+
import { $i as GenerationContentBlock, $n as PatchResourceLabelsInput, $r as SpaceFsFileKind, $t as BillingCreditStatus, Ai as SpaceUsageResponse, An as CronJobRecord, Ar as SpaceBootstrapSource, Bi as PublicGenerationDeclaration, Bn as JsonObject, Br as SpaceCommerceProductCreditBenefit, Bt as BatchUserProfilesResponse, Ci as SpaceRecord, Cn as CreateInvitationResponse, Cr as SessionTurnResponse, Ct as Fetch, Di as SpaceSandboxProvider, Dn as CreateSpacePromptResponse, Dr as SessionTurnsPaginatedResponse, Ei as SpaceSandboxConfig, En as CreateSpacePromptInput, Er as SessionTurnWindowResponse, Fi as UserRulesResponse, Fn as ExploreSpacesResponse, Fr as SpaceCommerceCreditsBenefit, Gn as LabelAssignmentRecord, Gr as SpaceDefaultResponse, Gt as BillingBalanceActivityStatus, Hn as JsonValue, Hr as SpaceConfigInput, Ht as BillingBalanceActivity, Ii as CreateGenerationTaskRequest, In as GlobalSearchResponse, Ir as SpaceCommerceFeatureBenefit, Jn as LabelResourceType, Jr as SpaceFsCompleteUploadResponse, Jt as BillingCheckoutActionState, Kn as LabelListItem, Kr as SpaceEnvInput, Kt as BillingCatalog, Li as CreateGenerationTaskResponse, Ln as GlobalSearchResult, Lr as SpaceCommerceOrder, Mi as TaskRunDetailResponse, Mn as CursorPageInfo, Mr as SpaceCheckpointDetailResponse, Ni as TaskRunRecord, Nn as ExploreSection, Nr as SpaceCommerceBenefit, Oi as SpaceSessionsResponse, On as CreateSpaceSessionInput, Or as SpaceAccess, Pi as UserProfile, Pn as ExploreSpaceItem, Pr as SpaceCommerceBuyerProfile, Qn as ModelCatalogEntry, Qr as SpaceFsEntry, Qt as BillingCreditGrantStatus, Ri as GenerationTaskResult, Rn as GlobalSearchType, Rr as SpaceCommerceProduct, Rt as AcceptInvitationResponse, Si as SpacePublicProfile, Sn as CreateInvitationInput, Sr as SessionTurnIndexResponse, St as CohubClientOptions, Ti as SpaceSandboxAutoDestroyPolicy, Tn as CreateSpaceModInput, Tr as SessionTurnStreamSnapshotResponse, Tt as HttpTransport, Ui as GenerationPolicy, Un as LabelAssignmentListItem, Ur as SpaceConfigResponse, Ut as BillingBalanceActivityKind, Vn as JsonPrimitive, Vr as SpaceConfig, Vt as BillingAccessWarning, Wn as LabelAssignmentPageInfo, Wr as SpaceCreateResponse, Wt as BillingBalanceActivityList, Xn as LabelSource, Xr as SpaceFsCreateUploadResponse, Xt as BillingConversionIntent, Yn as LabelScopeType, Yr as SpaceFsCreateUploadInput, Yt as BillingCheckoutResult, Zn as MeResponse, Zr as SpaceFsEncoding, Zt as BillingCreditExpiryGroup, _i as SpaceMember, _n as CanvasNodeRecord, _r as SessionBindingRecord, ai as SpaceFsReadFilesResponse, an as BillingProductCreditBenefit, ar as PublicUserProfile, bi as SpacePresenceSnapshot, bn as Channel, br as SessionMessagesResponse, ci as SpaceFsUploadEntry, cn as BillingProductPricing, cr as ReferenceAggregateResponse, di as SpaceFsUploadPlanEntryInput, dn as BillingSubscriptionHistoryStatus, dr as ReferenceQueryResponse, ea as ChannelConfig, ei as SpaceFsFileResponse, en as BillingCreditUnit, er as PatchResourceLabelsResponse, fi as SpaceFsUploadProgress, fn as BillingSubscriptionSummary, fr as ReferenceQueryableType, gi as SpaceListItem, gn as CanvasNodeInput, gr as SendMessageCronJobPayload, hi as SpaceInvitation, hn as CanvasDocumentRecord, hr as ResourceLabelsResponse, ii as SpaceFsReadFilesInput, in as BillingProductBillingInterval, ir as PromptTemplateCatalogResponse, ji as SpaceUsageSummary, jn as CronJobUpdatePatch, jr as SpaceChannelBindingInput, ki as SpaceUsageHourlyStat, kn as CronJobPayload, kr as SpaceAccessPolicy, li as SpaceFsUploadError, ln as BillingRedemptionResult, lr as ReferenceDirection, mi as SpaceFsWriteFileInput, mn as CanvasCreateInput, mr as ReferenceResourceType, n as createHttpClient, ni as SpaceFsPreparingFile, nn as BillingPaymentStatus, nr as PromptAccessMode, oi as SpaceFsTreeResponse, on as BillingProductDisplay, or as ReferenceAggregateGroup, pi as SpaceFsUploadResponse, pn as CanvasBootstrapResponse, pr as ReferenceRecord, qn as LabelRecord, qr as SpaceFsCompleteUploadInput, qt as BillingCatalogProduct, ri as SpaceFsReadFilesError, rn as BillingPluginStatus, rr as PromptTemplateCatalogEntry, si as SpaceFsUploadDestination, sn as BillingProductKind, sr as ReferenceAggregateGroupBy, t as CohubHttpClient, ta as DiscordChannelConfig, ti as SpaceFsMoveInput, tn as BillingHistoryPagination, tr as Permission, ui as SpaceFsUploadPlanEntry, un as BillingSubscriptionHistoryList, ur as ReferenceKind, vi as SpaceMeta, vn as CanvasSemanticOp, vr as SessionMessageResponse, wi as SpaceRole, wn as CreateSpaceInput, wr as SessionTurnSignedUrlsResponse, wt as HttpError, xi as SpacePresenceUser, xn as CheckpointRecord, xr as SessionRecord, yi as SpaceModListItem, yn as CanvasTransactionInput, yr as SessionMessagesPaginatedResponse, zi as ListGenerationModelsResponse, zn as InvitationDetail, zr as SpaceCommerceProductBenefitBinding, zt as ApiError } from "./chunks/http.js";
|
|
3
|
+
export { AcceptInvitationResponse, ApiError, BatchUserProfilesResponse, BillingAccessWarning, BillingBalanceActivity, BillingBalanceActivityKind, BillingBalanceActivityList, BillingBalanceActivityStatus, BillingCatalog, BillingCatalogProduct, BillingCheckoutActionState, BillingCheckoutResult, BillingConversionIntent, BillingCreditExpiryGroup, BillingCreditGrantStatus, BillingCreditStatus, BillingCreditUnit, BillingHistoryPagination, BillingPaymentStatus, BillingPluginStatus, BillingProductBillingInterval, BillingProductCreditBenefit, BillingProductDisplay, BillingProductKind, BillingProductPricing, BillingRedemptionResult, BillingSubscriptionHistoryList, BillingSubscriptionHistoryStatus, BillingSubscriptionSummary, CanvasBootstrapResponse, CanvasCreateInput, CanvasDocumentRecord, CanvasNodeInput, CanvasNodeRecord, CanvasSemanticOp, CanvasTransactionInput, Channel, type ChannelConfig, CheckpointRecord, type CohubClientOptions, CohubHttpClient, type ContentBlock, type CreateGenerationTaskRequest, type CreateGenerationTaskResponse, CreateInvitationInput, CreateInvitationResponse, CreateSpaceInput, CreateSpaceModInput, CreateSpacePromptInput, CreateSpacePromptResponse, CreateSpaceSessionInput, CronJobPayload, CronJobRecord, CronJobUpdatePatch, CursorPageInfo, type DiscordChannelConfig, ExploreSection, ExploreSpaceItem, ExploreSpacesResponse, type Fetch, type GenerationContentBlock, type GenerationPolicy, type GenerationTaskResult, GlobalSearchResponse, GlobalSearchResult, GlobalSearchType, HttpError, HttpTransport, InvitationDetail, JsonObject, JsonPrimitive, JsonValue, LabelAssignmentListItem, LabelAssignmentPageInfo, LabelAssignmentRecord, LabelListItem, LabelRecord, LabelResourceType, LabelScopeType, LabelSource, type ListGenerationModelsResponse, MeResponse, type MessageRecord, ModelCatalogEntry, PatchResourceLabelsInput, PatchResourceLabelsResponse, Permission, PromptAccessMode, PromptTemplateCatalogEntry, PromptTemplateCatalogResponse, type PublicGenerationDeclaration, PublicUserProfile, ReferenceAggregateGroup, ReferenceAggregateGroupBy, ReferenceAggregateResponse, ReferenceDirection, ReferenceKind, ReferenceQueryResponse, ReferenceQueryableType, ReferenceRecord, ReferenceResourceType, ResourceLabelsResponse, SendMessageCronJobPayload, SessionBindingRecord, type SessionForkRecord, SessionMessageResponse, SessionMessagesPaginatedResponse, SessionMessagesResponse, SessionRecord, type SessionTurnIndexItem, SessionTurnIndexResponse, type SessionTurnRecord, SessionTurnResponse, type SessionTurnSegmentRecord, SessionTurnSignedUrlsResponse, SessionTurnStreamSnapshotResponse, SessionTurnWindowResponse, SessionTurnsPaginatedResponse, SpaceAccess, SpaceAccessPolicy, SpaceBootstrapSource, SpaceChannelBindingInput, SpaceCheckpointDetailResponse, SpaceCommerceBenefit, SpaceCommerceBuyerProfile, SpaceCommerceCreditsBenefit, SpaceCommerceFeatureBenefit, SpaceCommerceOrder, SpaceCommerceProduct, SpaceCommerceProductBenefitBinding, SpaceCommerceProductCreditBenefit, SpaceConfig, SpaceConfigInput, SpaceConfigResponse, SpaceCreateResponse, SpaceDefaultResponse, SpaceEnvInput, SpaceFsCompleteUploadInput, SpaceFsCompleteUploadResponse, SpaceFsCreateUploadInput, SpaceFsCreateUploadResponse, SpaceFsEncoding, SpaceFsEntry, SpaceFsFileKind, SpaceFsFileResponse, SpaceFsMoveInput, SpaceFsPreparingFile, SpaceFsReadFilesError, SpaceFsReadFilesInput, SpaceFsReadFilesResponse, SpaceFsTreeResponse, SpaceFsUploadDestination, SpaceFsUploadEntry, SpaceFsUploadError, SpaceFsUploadPlanEntry, SpaceFsUploadPlanEntryInput, SpaceFsUploadProgress, SpaceFsUploadResponse, SpaceFsWriteFileInput, SpaceInvitation, SpaceListItem, SpaceMember, SpaceMeta, SpaceModListItem, SpacePresenceSnapshot, SpacePresenceUser, SpacePublicProfile, SpaceRecord, SpaceRole, SpaceSandboxAutoDestroyPolicy, SpaceSandboxConfig, SpaceSandboxProvider, SpaceSessionsResponse, SpaceUsageHourlyStat, SpaceUsageResponse, SpaceUsageSummary, TaskRunDetailResponse, TaskRunRecord, UserProfile, UserRulesResponse, createHttpClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as normalizeWebsocketUrl, c as resolveVoiceInputWebsocketUrl, i as normalizeVoiceInputWebsocketUrl, l as resolveWebsocketUrl, n as CohubEnvironment, o as resolveApiBaseUrl, r as normalizeBaseUrl, s as resolveCohubEnvironment, t as COHUB_ENVIRONMENTS } from "./chunks/environment.js";
|
|
2
2
|
import { C as ContentBlock, _ as SessionForkRecord, b as SessionTurnIndexItem, c as createWebsocketClient, f as RealtimeServerEvent, h as MessageRecord, l as ChannelEnvelope, r as WebsocketClient, u as LabelAssignmentsUpdatedEvent, x as SessionTurnRecord, y as SessionTurnSegmentRecord } from "./chunks/websocket.js";
|
|
3
3
|
import { a as VoiceInputCreateOptions, i as VoiceInputClientOptions, l as createVoiceInputClient, n as VoiceInputCallbacks, o as VoiceInputEvent, r as VoiceInputClient, t as VoiceApi } from "./chunks/voice-input.js";
|
|
4
|
-
import { $ as parseAssistantMessageCommit, $n as
|
|
4
|
+
import { $ as parseAssistantMessageCommit, $i as GenerationContentBlock, $n as PatchResourceLabelsInput, $r as SpaceFsFileKind, $t as BillingCreditStatus, A as TasksApi, Ai as SpaceUsageResponse, An as CronJobRecord, Ar as SpaceBootstrapSource, At as WorkRuntimeCheckoutState, B as GenerationStreamCommitEvent, Bi as PublicGenerationDeclaration, Bn as JsonObject, Br as SpaceCommerceProductCreditBenefit, Bt as BatchUserProfilesResponse, C as WorkStatus, Ci as SpaceRecord, Cn as CreateInvitationResponse, Cr as SessionTurnResponse, Ct as Fetch, D as WorkVisibility, Di as SpaceSandboxProvider, Dn as CreateSpacePromptResponse, Dr as SessionTurnsPaginatedResponse, Dt as ParentBridgeTransport, E as WorkVersionRecord, Ei as SpaceSandboxConfig, En as CreateSpacePromptInput, Er as SessionTurnWindowResponse, Et as RawHttpResponse, F as SpaceEventName, Fi as UserRulesResponse, Fn as ExploreSpacesResponse, Fr as SpaceCommerceCreditsBenefit, Ft as WorkRuntimeTransport, G as GenerationStreamLifecycleEvent, Gi as assertGenerationRequestAllowedByPolicy, Gn as LabelAssignmentRecord, Gr as SpaceDefaultResponse, Gt as BillingBalanceActivityStatus, H as GenerationStreamEvent, Hi as GenerationParameterConstraint, Hn as JsonValue, Hr as SpaceConfigInput, Ht as BillingBalanceActivity, I as SpacesApi, Ii as CreateGenerationTaskRequest, In as GlobalSearchResponse, Ir as SpaceCommerceFeatureBenefit, It as createWorkRuntime, J as GenerationStreamSubscribeOptions, Ji as filterGenerationDeclarationsByPolicy, Jn as LabelResourceType, Jr as SpaceFsCompleteUploadResponse, Jt as BillingCheckoutActionState, K as GenerationStreamOutOfSyncEvent, Ki as decodeGenerationPolicy, Kn as LabelListItem, Kr as SpaceEnvInput, Kt as BillingCatalog, L as WebSocketConnectionState, Li as CreateGenerationTaskResponse, Ln as GlobalSearchResult, Lr as SpaceCommerceOrder, Lt as resolveWorkTransport, M as SessionSubscriptionHandlers, Mi as TaskRunDetailResponse, Mn as CursorPageInfo, Mr as SpaceCheckpointDetailResponse, Mt as WorkRuntimeContext, N as SpaceChannelBindingRecord, Ni as TaskRunRecord, Nn as ExploreSection, Nr as SpaceCommerceBenefit, Nt as WorkRuntimeModeConfig, O as WorksApi, Oi as SpaceSessionsResponse, On as CreateSpaceSessionInput, Or as SpaceAccess, Ot as PopupBrokerTransport, P as SpaceClient, Pi as UserProfile, Pn as ExploreSpaceItem, Pr as SpaceCommerceBuyerProfile, Pt as WorkRuntimeRequestOptions, Q as createSessionGenerationStreamClient, Qi as parseGenerationPolicyFromEnv, Qn as ModelCatalogEntry, Qr as SpaceFsEntry, Qt as BillingCreditGrantStatus, R as PublicInviteApi, Ri as GenerationTaskResult, Rn as GlobalSearchType, Rr as SpaceCommerceProduct, Rt as AcceptInvitationResponse, S as WorkSessionResponse, Si as SpacePublicProfile, Sn as CreateInvitationInput, Sr as SessionTurnIndexResponse, St as CohubClientOptions, T as WorkUpdateInput, Ti as SpaceSandboxAutoDestroyPolicy, Tn as CreateSpaceModInput, Tr as SessionTurnStreamSnapshotResponse, Tt as HttpTransport, U as GenerationStreamFinalizedEvent, Ui as GenerationPolicy, Un as LabelAssignmentListItem, Ur as SpaceConfigResponse, Ut as BillingBalanceActivityKind, V as GenerationStreamErrorEvent, Vi as GenerationModelPolicy, Vn as JsonPrimitive, Vr as SpaceConfig, Vt as BillingAccessWarning, W as GenerationStreamIntermediateMessage, Wi as GenerationPolicyError, Wn as LabelAssignmentPageInfo, Wr as SpaceCreateResponse, Wt as BillingBalanceActivityList, X as GenerationStreamTurnUpdatedEvent, Xi as getAllowedGenerationModelIds, Xn as LabelSource, Xr as SpaceFsCreateUploadResponse, Xt as BillingConversionIntent, Y as GenerationStreamSubscriptionHandlers, Yi as findGenerationModelPolicy, Yn as LabelScopeType, Yr as SpaceFsCreateUploadInput, Yt as BillingCheckoutResult, Z as SessionGenerationStreamClient, Zi as normalizeGenerationPolicy, Zn as MeResponse, Zr as SpaceFsEncoding, Zt as BillingCreditExpiryGroup, _ as WorkPresentationMeta, _i as SpaceMember, _n as CanvasNodeRecord, _r as SessionBindingRecord, _t as PromptsApi, a as WorkCommerceCreditConsumeResponse, ai as SpaceFsReadFilesResponse, an as BillingProductCreditBenefit, ar as PublicUserProfile, at as createSessionPatchReducer, b as WorkRecord, bi as SpacePresenceSnapshot, bn as Channel, br as SessionMessagesResponse, bt as CronJobsApi, c as WorkCommerceEntitlementsResponse, ci as SpaceFsUploadEntry, cn as BillingProductPricing, cr as ReferenceAggregateResponse, ct as ReferencesApi, d as WorkCommercePurchaseResponse, di as SpaceFsUploadPlanEntryInput, dn as BillingSubscriptionHistoryStatus, dr as ReferenceQueryResponse, dt as CreatePublicAssetUploadResponse, ea as ChannelConfig, ei as SpaceFsFileResponse, en as BillingCreditUnit, er as PatchResourceLabelsResponse, et as SessionPatchApplyInput, f as WorkAuthorizeResponse, fi as SpaceFsUploadProgress, fn as BillingSubscriptionSummary, fr as ReferenceQueryableType, ft as PublicAssetMimeType, g as WorkMeta, gi as SpaceListItem, gn as CanvasNodeInput, gr as SendMessageCronJobPayload, gt as UploadPublicAssetInput, h as WorkGetResponse, hi as SpaceInvitation, hn as CanvasDocumentRecord, hr as ResourceLabelsResponse, ht as UploadChatImageAttachmentInput, i as WorkCommerceCheckoutStatus, ii as SpaceFsReadFilesInput, in as BillingProductBillingInterval, ir as PromptTemplateCatalogResponse, it as SessionPatchStatus, j as SessionEventName, ji as SpaceUsageSummary, jn as CronJobUpdatePatch, jr as SpaceChannelBindingInput, jt as WorkRuntimeCheckoutStatus, k as UserApi, ki as SpaceUsageHourlyStat, kn as CronJobPayload, kr as SpaceAccessPolicy, kt as WorkRuntimeApi, l as WorkCommerceOrder, li as SpaceFsUploadError, ln as BillingRedemptionResult, lr as ReferenceDirection, lt as SearchApi, m as WorkDetailResponse, mi as SpaceFsWriteFileInput, mn as CanvasCreateInput, mr as ReferenceResourceType, mt as PublicAssetsApi, n as createHttpClient, ni as SpaceFsPreparingFile, nn as BillingPaymentStatus, nr as PromptAccessMode, nt as SessionPatchReducer, o as WorkCommerceCreditConsumeStatus, oi as SpaceFsTreeResponse, on as BillingProductDisplay, or as ReferenceAggregateGroup, ot as SessionAccessApi, p as WorkCreateInput, pi as SpaceFsUploadResponse, pn as CanvasBootstrapResponse, pr as ReferenceRecord, pt as PublicAssetPurpose, q as GenerationStreamStateEvent, qi as encodeGenerationPolicy, qn as LabelRecord, qr as SpaceFsCompleteUploadInput, qt as BillingCatalogProduct, r as WorkCommerceApi, ri as SpaceFsReadFilesError, rn as BillingPluginStatus, rr as PromptTemplateCatalogEntry, rt as SessionPatchState, s as WorkCommerceEntitlement, si as SpaceFsUploadDestination, sn as BillingProductKind, sr as ReferenceAggregateGroupBy, st as ReferenceResourceSelector, t as CohubHttpClient, ta as DiscordChannelConfig, ti as SpaceFsMoveInput, tn as BillingHistoryPagination, tr as Permission, tt as SessionPatchApplyResult, u as WorkCommerceProductResolveResponse, ui as SpaceFsUploadPlanEntry, un as BillingSubscriptionHistoryList, ur as ReferenceKind, ut as CreatePublicAssetUploadInput, v as WorkPublicOwnerRecord, vi as SpaceMeta, vn as CanvasSemanticOp, vr as SessionMessageResponse, vt as ModelsApi, w as WorkTargetType, wi as SpaceRole, wn as CreateSpaceInput, wr as SessionTurnSignedUrlsResponse, wt as HttpError, x as WorkResolveResponse, xi as SpacePresenceUser, xn as CheckpointRecord, xr as SessionRecord, xt as ChannelsApi, y as WorkPublicSpaceRecord, yi as SpaceModListItem, yn as CanvasTransactionInput, yr as SessionMessagesPaginatedResponse, yt as GenerationsApi, z as AssistantMessageCommit, zi as ListGenerationModelsResponse, zn as InvitationDetail, zr as SpaceCommerceProductBenefitBinding, zt as ApiError } from "./chunks/http.js";
|
|
5
5
|
|
|
6
6
|
//#region src/apis/billing.d.ts
|
|
7
7
|
declare class BillingApi {
|
|
@@ -52,56 +52,6 @@ declare class BillingApi {
|
|
|
52
52
|
}>;
|
|
53
53
|
}
|
|
54
54
|
//#endregion
|
|
55
|
-
//#region src/work-runtime.d.ts
|
|
56
|
-
type WorkRuntimeContext = {
|
|
57
|
-
work: {
|
|
58
|
-
id: string;
|
|
59
|
-
slug: string;
|
|
60
|
-
url?: string | null;
|
|
61
|
-
};
|
|
62
|
-
space: {
|
|
63
|
-
id: string;
|
|
64
|
-
name?: string | null;
|
|
65
|
-
};
|
|
66
|
-
viewer?: {
|
|
67
|
-
userUuid: string;
|
|
68
|
-
} | null;
|
|
69
|
-
permissions?: {
|
|
70
|
-
scopes: Permission[];
|
|
71
|
-
workScopes: Permission[];
|
|
72
|
-
viewerScopes: Permission[];
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
type WorkRuntimeCheckoutStatus = "success" | "failed" | "cancel" | null;
|
|
76
|
-
type WorkRuntimeCheckoutState = {
|
|
77
|
-
status: WorkRuntimeCheckoutStatus;
|
|
78
|
-
orderId: string | null;
|
|
79
|
-
};
|
|
80
|
-
declare class WorkRuntimeApi {
|
|
81
|
-
private token;
|
|
82
|
-
context(): Promise<WorkRuntimeContext | null>;
|
|
83
|
-
getAccessToken(options?: {
|
|
84
|
-
forceRefresh?: boolean;
|
|
85
|
-
}): Promise<string | null>;
|
|
86
|
-
requestAuthorization(input: {
|
|
87
|
-
scopes: Permission[];
|
|
88
|
-
reason?: string;
|
|
89
|
-
}): Promise<boolean>;
|
|
90
|
-
purchase(input: {
|
|
91
|
-
productKey: string;
|
|
92
|
-
}): Promise<{
|
|
93
|
-
providerKey: string | null;
|
|
94
|
-
checkoutUrl: string | null;
|
|
95
|
-
checkoutUsable: boolean;
|
|
96
|
-
status: string | null;
|
|
97
|
-
message: string | null;
|
|
98
|
-
orderId: string;
|
|
99
|
-
productKey: string;
|
|
100
|
-
} | null>;
|
|
101
|
-
checkoutState(): Promise<WorkRuntimeCheckoutState | null>;
|
|
102
|
-
}
|
|
103
|
-
declare const createWorkRuntime: () => WorkRuntimeApi;
|
|
104
|
-
//#endregion
|
|
105
55
|
//#region src/apis/explore.d.ts
|
|
106
56
|
declare class ExploreApi {
|
|
107
57
|
private readonly transport;
|
|
@@ -131,6 +81,7 @@ declare class CohubClient {
|
|
|
131
81
|
readonly publicAssets: PublicAssetsApi;
|
|
132
82
|
readonly sessionAccess: SessionAccessApi;
|
|
133
83
|
readonly search: SearchApi;
|
|
84
|
+
readonly references: ReferencesApi;
|
|
134
85
|
readonly tasks: TasksApi;
|
|
135
86
|
readonly cronJobs: CronJobsApi;
|
|
136
87
|
readonly explore: ExploreApi;
|
|
@@ -190,4 +141,4 @@ declare function isHttpErrorCode(error: unknown, code: string): error is HttpErr
|
|
|
190
141
|
code: string;
|
|
191
142
|
};
|
|
192
143
|
//#endregion
|
|
193
|
-
export { AcceptInvitationResponse, ApiError, type AssistantMessageCommit, BatchUserProfilesResponse, BillingAccessWarning, BillingApi, BillingBalanceActivity, BillingBalanceActivityKind, BillingBalanceActivityList, BillingBalanceActivityStatus, BillingCatalog, BillingCatalogProduct, BillingCheckoutActionState, BillingCheckoutResult, BillingConversionIntent, BillingCreditExpiryGroup, BillingCreditGrantStatus, BillingCreditStatus, BillingCreditUnit, BillingHistoryPagination, BillingPaymentStatus, BillingPluginStatus, BillingProductBillingInterval, BillingProductCreditBenefit, BillingProductDisplay, BillingProductKind, BillingProductPricing, BillingRedemptionResult, BillingSubscriptionHistoryList, BillingSubscriptionHistoryStatus, BillingSubscriptionSummary, COHUB_ENVIRONMENTS, CanvasBootstrapResponse, CanvasCreateInput, CanvasDocumentRecord, CanvasNodeInput, CanvasNodeRecord, CanvasSemanticOp, CanvasTransactionInput, Channel, type ChannelConfig, type ChannelEnvelope, CheckpointRecord, CohubClient, type CohubClientOptions, type CohubEnvironment, CohubHttpClient, type ContentBlock, type CreateGenerationTaskRequest, type CreateGenerationTaskResponse, CreateInvitationInput, CreateInvitationResponse, type CreatePublicAssetUploadInput, type CreatePublicAssetUploadResponse, CreateSpaceInput, CreateSpaceModInput, CreateSpacePromptInput, CreateSpacePromptResponse, CreateSpaceSessionInput, CronJobPayload, CronJobRecord, CronJobUpdatePatch, CursorPageInfo, type DiscordChannelConfig, ExploreSection, ExploreSpaceItem, ExploreSpacesResponse, type Fetch, type GenerationContentBlock, type GenerationModelPolicy, type GenerationParameterConstraint, type GenerationPolicy, GenerationPolicyError, type GenerationStreamCommitEvent, type GenerationStreamErrorEvent, type GenerationStreamEvent, type GenerationStreamFinalizedEvent, type GenerationStreamIntermediateMessage, type GenerationStreamLifecycleEvent, type GenerationStreamOutOfSyncEvent, type GenerationStreamStateEvent, type GenerationStreamSubscribeOptions, type GenerationStreamSubscriptionHandlers, type GenerationStreamTurnUpdatedEvent, type GenerationTaskResult, GlobalSearchResponse, GlobalSearchResult, GlobalSearchType, HttpError, InvitationDetail, JsonObject, JsonPrimitive, JsonValue, LabelAssignmentListItem, LabelAssignmentPageInfo, LabelAssignmentRecord, type LabelAssignmentsUpdatedEvent, LabelListItem, LabelRecord, LabelResourceType, LabelScopeType, LabelSource, type ListGenerationModelsResponse, MeResponse, type MessageRecord, ModelCatalogEntry, Permission, PromptAccessMode, PromptTemplateCatalogEntry, PromptTemplateCatalogResponse, type PublicAssetMimeType, type PublicAssetPurpose, type PublicGenerationDeclaration, PublicUserProfile, type RawHttpResponse, type RealtimeServerEvent, ResourceLabelsResponse, SendMessageCronJobPayload, SessionBindingRecord, type SessionEventName, type SessionForkRecord, SessionGenerationStreamClient, SessionMessageResponse, SessionMessagesPaginatedResponse, SessionMessagesResponse, type SessionPatchApplyInput, type SessionPatchApplyResult, SessionPatchReducer, type SessionPatchState, type SessionPatchStatus, SessionRecord, type SessionSubscriptionHandlers, type SessionTurnIndexItem, SessionTurnIndexResponse, type SessionTurnRecord, SessionTurnResponse, type SessionTurnSegmentRecord, SessionTurnSignedUrlsResponse, SessionTurnStreamSnapshotResponse, SessionTurnWindowResponse, SessionTurnsPaginatedResponse, SpaceAccess, SpaceAccessPolicy, SpaceBootstrapSource, SpaceChannelBindingInput, type SpaceChannelBindingRecord, SpaceCheckpointDetailResponse, SpaceCommerceBenefit, SpaceCommerceBuyerProfile, SpaceCommerceCreditsBenefit, SpaceCommerceFeatureBenefit, SpaceCommerceOrder, SpaceCommerceProduct, SpaceCommerceProductBenefitBinding, SpaceCommerceProductCreditBenefit, SpaceConfig, SpaceConfigInput, SpaceConfigResponse, SpaceCreateResponse, SpaceDefaultResponse, SpaceEnvInput, type SpaceEventName, SpaceFsCompleteUploadInput, SpaceFsCompleteUploadResponse, SpaceFsCreateUploadInput, SpaceFsCreateUploadResponse, SpaceFsEncoding, SpaceFsEntry, SpaceFsFileKind, SpaceFsFileResponse, SpaceFsMoveInput, SpaceFsPreparingFile, SpaceFsReadFilesError, SpaceFsReadFilesInput, SpaceFsReadFilesResponse, SpaceFsTreeResponse, SpaceFsUploadDestination, SpaceFsUploadEntry, SpaceFsUploadError, SpaceFsUploadPlanEntry, SpaceFsUploadPlanEntryInput, SpaceFsUploadProgress, SpaceFsUploadResponse, SpaceFsWriteFileInput, SpaceInvitation, SpaceListItem, SpaceMember, SpaceMeta, SpaceModListItem, SpacePresenceSnapshot, SpacePresenceUser, SpacePublicProfile, SpaceRecord, SpaceRole, SpaceSandboxAutoDestroyPolicy, SpaceSandboxConfig, SpaceSessionsResponse, SpaceUsageHourlyStat, SpaceUsageResponse, SpaceUsageSummary, TaskRunDetailResponse, TaskRunRecord, type UploadChatImageAttachmentInput, type UploadPublicAssetInput, UserProfile, UserRulesResponse, UsersApi, VoiceApi, type VoiceInputCallbacks, VoiceInputClient, type VoiceInputClientOptions, type VoiceInputCreateOptions, type VoiceInputEvent, type WebSocketConnectionState, WebsocketClient, type WorkAuthorizeResponse, WorkCommerceApi, type WorkCommerceCheckoutStatus, type WorkCommerceCreditConsumeResponse, type WorkCommerceCreditConsumeStatus, type WorkCommerceEntitlement, type WorkCommerceEntitlementsResponse, type WorkCommerceOrder, type WorkCommerceProductResolveResponse, type WorkCommercePurchaseResponse, type WorkCreateInput, type WorkDetailResponse, type WorkGetResponse, type WorkMeta, type WorkPresentationMeta, type WorkPublicOwnerRecord, type WorkPublicSpaceRecord, type WorkRecord, type WorkResolveResponse, WorkRuntimeApi, type WorkRuntimeCheckoutState, type WorkRuntimeCheckoutStatus, type WorkRuntimeContext, type WorkSessionResponse, type WorkStatus, type WorkTargetType, type WorkUpdateInput, type WorkVersionRecord, type WorkVisibility, WorksApi, assertGenerationRequestAllowedByPolicy, createCohubClient, createHttpClient, createSessionGenerationStreamClient, createSessionPatchReducer, createVoiceInputClient, createWebsocketClient, createWorkRuntime, decodeGenerationPolicy, encodeGenerationPolicy, filterGenerationDeclarationsByPolicy, findGenerationModelPolicy, getAllowedGenerationModelIds, isHttpErrorCode, normalizeBaseUrl, normalizeGenerationPolicy, normalizeVoiceInputWebsocketUrl, normalizeWebsocketUrl, parseAssistantMessageCommit, parseGenerationPolicyFromEnv, resolveApiBaseUrl, resolveCohubEnvironment, resolveVoiceInputWebsocketUrl, resolveWebsocketUrl };
|
|
144
|
+
export { AcceptInvitationResponse, ApiError, type AssistantMessageCommit, BatchUserProfilesResponse, BillingAccessWarning, BillingApi, BillingBalanceActivity, BillingBalanceActivityKind, BillingBalanceActivityList, BillingBalanceActivityStatus, BillingCatalog, BillingCatalogProduct, BillingCheckoutActionState, BillingCheckoutResult, BillingConversionIntent, BillingCreditExpiryGroup, BillingCreditGrantStatus, BillingCreditStatus, BillingCreditUnit, BillingHistoryPagination, BillingPaymentStatus, BillingPluginStatus, BillingProductBillingInterval, BillingProductCreditBenefit, BillingProductDisplay, BillingProductKind, BillingProductPricing, BillingRedemptionResult, BillingSubscriptionHistoryList, BillingSubscriptionHistoryStatus, BillingSubscriptionSummary, COHUB_ENVIRONMENTS, CanvasBootstrapResponse, CanvasCreateInput, CanvasDocumentRecord, CanvasNodeInput, CanvasNodeRecord, CanvasSemanticOp, CanvasTransactionInput, Channel, type ChannelConfig, type ChannelEnvelope, CheckpointRecord, CohubClient, type CohubClientOptions, type CohubEnvironment, CohubHttpClient, type ContentBlock, type CreateGenerationTaskRequest, type CreateGenerationTaskResponse, CreateInvitationInput, CreateInvitationResponse, type CreatePublicAssetUploadInput, type CreatePublicAssetUploadResponse, CreateSpaceInput, CreateSpaceModInput, CreateSpacePromptInput, CreateSpacePromptResponse, CreateSpaceSessionInput, CronJobPayload, CronJobRecord, CronJobUpdatePatch, CursorPageInfo, type DiscordChannelConfig, ExploreSection, ExploreSpaceItem, ExploreSpacesResponse, type Fetch, type GenerationContentBlock, type GenerationModelPolicy, type GenerationParameterConstraint, type GenerationPolicy, GenerationPolicyError, type GenerationStreamCommitEvent, type GenerationStreamErrorEvent, type GenerationStreamEvent, type GenerationStreamFinalizedEvent, type GenerationStreamIntermediateMessage, type GenerationStreamLifecycleEvent, type GenerationStreamOutOfSyncEvent, type GenerationStreamStateEvent, type GenerationStreamSubscribeOptions, type GenerationStreamSubscriptionHandlers, type GenerationStreamTurnUpdatedEvent, type GenerationTaskResult, GlobalSearchResponse, GlobalSearchResult, GlobalSearchType, HttpError, InvitationDetail, JsonObject, JsonPrimitive, JsonValue, LabelAssignmentListItem, LabelAssignmentPageInfo, LabelAssignmentRecord, type LabelAssignmentsUpdatedEvent, LabelListItem, LabelRecord, LabelResourceType, LabelScopeType, LabelSource, type ListGenerationModelsResponse, MeResponse, type MessageRecord, ModelCatalogEntry, ParentBridgeTransport, PatchResourceLabelsInput, PatchResourceLabelsResponse, Permission, PopupBrokerTransport, PromptAccessMode, PromptTemplateCatalogEntry, PromptTemplateCatalogResponse, type PublicAssetMimeType, type PublicAssetPurpose, type PublicGenerationDeclaration, PublicUserProfile, type RawHttpResponse, type RealtimeServerEvent, ReferenceAggregateGroup, ReferenceAggregateGroupBy, ReferenceAggregateResponse, ReferenceDirection, ReferenceKind, ReferenceQueryResponse, ReferenceQueryableType, ReferenceRecord, type ReferenceResourceSelector, ReferenceResourceType, ReferencesApi, ResourceLabelsResponse, SendMessageCronJobPayload, SessionBindingRecord, type SessionEventName, type SessionForkRecord, SessionGenerationStreamClient, SessionMessageResponse, SessionMessagesPaginatedResponse, SessionMessagesResponse, type SessionPatchApplyInput, type SessionPatchApplyResult, SessionPatchReducer, type SessionPatchState, type SessionPatchStatus, SessionRecord, type SessionSubscriptionHandlers, type SessionTurnIndexItem, SessionTurnIndexResponse, type SessionTurnRecord, SessionTurnResponse, type SessionTurnSegmentRecord, SessionTurnSignedUrlsResponse, SessionTurnStreamSnapshotResponse, SessionTurnWindowResponse, SessionTurnsPaginatedResponse, SpaceAccess, SpaceAccessPolicy, SpaceBootstrapSource, SpaceChannelBindingInput, type SpaceChannelBindingRecord, SpaceCheckpointDetailResponse, SpaceCommerceBenefit, SpaceCommerceBuyerProfile, SpaceCommerceCreditsBenefit, SpaceCommerceFeatureBenefit, SpaceCommerceOrder, SpaceCommerceProduct, SpaceCommerceProductBenefitBinding, SpaceCommerceProductCreditBenefit, SpaceConfig, SpaceConfigInput, SpaceConfigResponse, SpaceCreateResponse, SpaceDefaultResponse, SpaceEnvInput, type SpaceEventName, SpaceFsCompleteUploadInput, SpaceFsCompleteUploadResponse, SpaceFsCreateUploadInput, SpaceFsCreateUploadResponse, SpaceFsEncoding, SpaceFsEntry, SpaceFsFileKind, SpaceFsFileResponse, SpaceFsMoveInput, SpaceFsPreparingFile, SpaceFsReadFilesError, SpaceFsReadFilesInput, SpaceFsReadFilesResponse, SpaceFsTreeResponse, SpaceFsUploadDestination, SpaceFsUploadEntry, SpaceFsUploadError, SpaceFsUploadPlanEntry, SpaceFsUploadPlanEntryInput, SpaceFsUploadProgress, SpaceFsUploadResponse, SpaceFsWriteFileInput, SpaceInvitation, SpaceListItem, SpaceMember, SpaceMeta, SpaceModListItem, SpacePresenceSnapshot, SpacePresenceUser, SpacePublicProfile, SpaceRecord, SpaceRole, SpaceSandboxAutoDestroyPolicy, SpaceSandboxConfig, SpaceSandboxProvider, SpaceSessionsResponse, SpaceUsageHourlyStat, SpaceUsageResponse, SpaceUsageSummary, TaskRunDetailResponse, TaskRunRecord, type UploadChatImageAttachmentInput, type UploadPublicAssetInput, UserProfile, UserRulesResponse, UsersApi, VoiceApi, type VoiceInputCallbacks, VoiceInputClient, type VoiceInputClientOptions, type VoiceInputCreateOptions, type VoiceInputEvent, type WebSocketConnectionState, WebsocketClient, type WorkAuthorizeResponse, WorkCommerceApi, type WorkCommerceCheckoutStatus, type WorkCommerceCreditConsumeResponse, type WorkCommerceCreditConsumeStatus, type WorkCommerceEntitlement, type WorkCommerceEntitlementsResponse, type WorkCommerceOrder, type WorkCommerceProductResolveResponse, type WorkCommercePurchaseResponse, type WorkCreateInput, type WorkDetailResponse, type WorkGetResponse, type WorkMeta, type WorkPresentationMeta, type WorkPublicOwnerRecord, type WorkPublicSpaceRecord, type WorkRecord, type WorkResolveResponse, WorkRuntimeApi, type WorkRuntimeCheckoutState, type WorkRuntimeCheckoutStatus, type WorkRuntimeContext, type WorkRuntimeModeConfig, type WorkRuntimeRequestOptions, type WorkRuntimeTransport, type WorkSessionResponse, type WorkStatus, type WorkTargetType, type WorkUpdateInput, type WorkVersionRecord, type WorkVisibility, WorksApi, assertGenerationRequestAllowedByPolicy, createCohubClient, createHttpClient, createSessionGenerationStreamClient, createSessionPatchReducer, createVoiceInputClient, createWebsocketClient, createWorkRuntime, decodeGenerationPolicy, encodeGenerationPolicy, filterGenerationDeclarationsByPolicy, findGenerationModelPolicy, getAllowedGenerationModelIds, isHttpErrorCode, normalizeBaseUrl, normalizeGenerationPolicy, normalizeVoiceInputWebsocketUrl, normalizeWebsocketUrl, parseAssistantMessageCommit, parseGenerationPolicyFromEnv, resolveApiBaseUrl, resolveCohubEnvironment, resolveVoiceInputWebsocketUrl, resolveWebsocketUrl, resolveWorkTransport };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as GenerationsApi, S as ModelsApi, T as ChannelsApi, _ as SessionAccessApi, a as UserApi, b as PublicAssetsApi, c as SpacesApi, d as createSessionGenerationStreamClient, f as parseAssistantMessageCommit, g as HttpTransport, h as HttpError, i as WorksApi, l as PublicInviteApi, m as createSessionPatchReducer, n as createHttpClient, o as TasksApi, p as SessionPatchReducer, r as WorkCommerceApi, s as SpaceClient, t as CohubHttpClient, u as SessionGenerationStreamClient, v as ReferencesApi, w as CronJobsApi, x as PromptsApi, y as SearchApi } from "./chunks/http.js";
|
|
2
2
|
import { a as resolveApiBaseUrl, c as resolveWebsocketUrl, i as normalizeWebsocketUrl, n as normalizeBaseUrl, o as resolveCohubEnvironment, r as normalizeVoiceInputWebsocketUrl, s as resolveVoiceInputWebsocketUrl, t as COHUB_ENVIRONMENTS } from "./chunks/environment.js";
|
|
3
3
|
import { WebsocketClient, createWebsocketClient } from "./websocket.js";
|
|
4
4
|
import { VoiceApi, VoiceInputClient, createVoiceInputClient } from "./voice-input.js";
|
|
@@ -109,84 +109,258 @@ const getParentOrigin = () => {
|
|
|
109
109
|
return null;
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
const generateRequestId = () => globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
113
|
+
/**
|
|
114
|
+
* Bridge-mode transport: posts messages to `window.parent` (the Cohub host
|
|
115
|
+
* embedding the work in an iframe) and listens for the matching reply.
|
|
116
|
+
* Behaviorally identical to the previous module-level `request()` helper.
|
|
117
|
+
*/
|
|
118
|
+
var ParentBridgeTransport = class {
|
|
119
|
+
trustedParentOrigin = null;
|
|
120
|
+
request(message, options) {
|
|
121
|
+
const timeoutMs = options?.timeoutMs ?? 1200;
|
|
122
|
+
const retryIntervalMs = options?.retryIntervalMs;
|
|
123
|
+
if (!hasParent()) return Promise.resolve(null);
|
|
124
|
+
const requestId = generateRequestId();
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
let retryTimer = null;
|
|
127
|
+
const parentOrigin = this.trustedParentOrigin ?? getParentOrigin();
|
|
128
|
+
const postRequest = () => {
|
|
129
|
+
try {
|
|
130
|
+
window.parent.postMessage({
|
|
131
|
+
...message,
|
|
132
|
+
requestId
|
|
133
|
+
}, parentOrigin ?? "*");
|
|
134
|
+
} catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const cleanup = () => {
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
if (retryTimer) clearInterval(retryTimer);
|
|
141
|
+
window.removeEventListener("message", onMessage);
|
|
142
|
+
};
|
|
143
|
+
const timer = setTimeout(() => {
|
|
144
|
+
cleanup();
|
|
145
|
+
resolve(null);
|
|
146
|
+
}, timeoutMs);
|
|
147
|
+
const onMessage = (event) => {
|
|
148
|
+
if (event.source !== window.parent) return;
|
|
149
|
+
if (parentOrigin && event.origin !== parentOrigin) return;
|
|
150
|
+
const data = event.data;
|
|
151
|
+
if (!data || data.requestId !== requestId) return;
|
|
152
|
+
cleanup();
|
|
153
|
+
this.trustedParentOrigin = event.origin;
|
|
154
|
+
if (data.type === "cohub.work.error") {
|
|
155
|
+
reject(new Error(data.message));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
resolve(data);
|
|
159
|
+
};
|
|
160
|
+
window.addEventListener("message", onMessage);
|
|
161
|
+
postRequest();
|
|
162
|
+
if (retryIntervalMs) retryTimer = setInterval(postRequest, retryIntervalMs);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Broker-mode transport for standalone-deployed works. Opens a popup window to
|
|
168
|
+
* the Cohub auth broker page, performs a ready-handshake, sends the request via
|
|
169
|
+
* postMessage, and resolves with the broker's response. The popup is closed
|
|
170
|
+
* after a single request is fulfilled (one-shot, per §7.2 of the plan).
|
|
171
|
+
*
|
|
172
|
+
* Non-interactive messages (`context`, `checkout-state`) are answered locally
|
|
173
|
+
* without opening a popup — the work already knows its own workId, and
|
|
174
|
+
* checkout state is not available on the work's own origin in broker mode.
|
|
175
|
+
*/
|
|
176
|
+
var PopupBrokerTransport = class {
|
|
177
|
+
brokerOrigin;
|
|
178
|
+
workId;
|
|
179
|
+
constructor(config) {
|
|
180
|
+
this.brokerOrigin = config.brokerOrigin;
|
|
181
|
+
this.workId = config.workId;
|
|
182
|
+
}
|
|
183
|
+
request(message, options) {
|
|
184
|
+
if (message.type === "cohub.work.context") return Promise.resolve({
|
|
185
|
+
type: "cohub.work.context.result",
|
|
186
|
+
context: {
|
|
187
|
+
work: {
|
|
188
|
+
id: this.workId,
|
|
189
|
+
slug: "",
|
|
190
|
+
url: null
|
|
191
|
+
},
|
|
192
|
+
space: { id: "" },
|
|
193
|
+
permissions: {
|
|
194
|
+
scopes: [],
|
|
195
|
+
workScopes: [],
|
|
196
|
+
viewerScopes: []
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
if (message.type === "cohub.work.checkout-state") return Promise.resolve({
|
|
201
|
+
type: "cohub.work.checkout-state.result",
|
|
202
|
+
status: null,
|
|
203
|
+
orderId: null
|
|
204
|
+
});
|
|
205
|
+
const timeoutMs = options?.timeoutMs ?? 12e4;
|
|
206
|
+
const requestId = generateRequestId();
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
if (typeof window === "undefined" || typeof window.open !== "function") {
|
|
209
|
+
resolve(null);
|
|
126
210
|
return;
|
|
127
211
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
const timer = setTimeout(() => {
|
|
135
|
-
cleanup();
|
|
136
|
-
resolve(null);
|
|
137
|
-
}, timeoutMs);
|
|
138
|
-
const onMessage = (event) => {
|
|
139
|
-
if (event.source !== window.parent) return;
|
|
140
|
-
if (parentOrigin && event.origin !== parentOrigin) return;
|
|
141
|
-
const data = event.data;
|
|
142
|
-
if (!data || data.requestId !== requestId) return;
|
|
143
|
-
cleanup();
|
|
144
|
-
trustedParentOrigin = event.origin;
|
|
145
|
-
if (data.type === "cohub.work.error") {
|
|
146
|
-
reject(new Error(data.message));
|
|
212
|
+
const workOrigin = window.location.origin;
|
|
213
|
+
const brokerUrl = `${this.brokerOrigin}/work-auth?work=${encodeURIComponent(this.workId)}&origin=${encodeURIComponent(workOrigin)}`;
|
|
214
|
+
const popup = window.open(brokerUrl, "cohub-work-auth", "popup,width=480,height=640");
|
|
215
|
+
if (!popup) {
|
|
216
|
+
reject(/* @__PURE__ */ new Error("Failed to open authorization window. Please allow popups for this site."));
|
|
147
217
|
return;
|
|
148
218
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
219
|
+
let ready = false;
|
|
220
|
+
let settled = false;
|
|
221
|
+
let timer = null;
|
|
222
|
+
let closeChecker = null;
|
|
223
|
+
const finish = (fn) => {
|
|
224
|
+
if (settled) return;
|
|
225
|
+
settled = true;
|
|
226
|
+
if (timer) clearTimeout(timer);
|
|
227
|
+
if (closeChecker) clearInterval(closeChecker);
|
|
228
|
+
window.removeEventListener("message", onMessage);
|
|
229
|
+
try {
|
|
230
|
+
popup.close();
|
|
231
|
+
} catch {}
|
|
232
|
+
fn();
|
|
233
|
+
};
|
|
234
|
+
timer = setTimeout(() => {
|
|
235
|
+
finish(() => {
|
|
236
|
+
if (!ready) reject(/* @__PURE__ */ new Error("Authorization window did not respond in time."));
|
|
237
|
+
else resolve(null);
|
|
238
|
+
});
|
|
239
|
+
}, timeoutMs);
|
|
240
|
+
const onMessage = (event) => {
|
|
241
|
+
if (event.source !== popup) return;
|
|
242
|
+
if (event.origin !== this.brokerOrigin) return;
|
|
243
|
+
const data = event.data;
|
|
244
|
+
if (!data) return;
|
|
245
|
+
if (data.type === "cohub.work.broker.ready" && !ready) {
|
|
246
|
+
ready = true;
|
|
247
|
+
try {
|
|
248
|
+
popup.postMessage({
|
|
249
|
+
...message,
|
|
250
|
+
requestId
|
|
251
|
+
}, this.brokerOrigin);
|
|
252
|
+
} catch {
|
|
253
|
+
finish(() => reject(/* @__PURE__ */ new Error("Failed to send request to authorization window.")));
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (data.requestId !== requestId) return;
|
|
258
|
+
finish(() => {
|
|
259
|
+
if (data.type === "cohub.work.error") {
|
|
260
|
+
reject(new Error(data.message));
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
resolve(data);
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
window.addEventListener("message", onMessage);
|
|
267
|
+
closeChecker = setInterval(() => {
|
|
268
|
+
if (popup.closed) finish(() => {
|
|
269
|
+
if (!ready) reject(/* @__PURE__ */ new Error("Authorization window was closed."));
|
|
270
|
+
else resolve(null);
|
|
271
|
+
});
|
|
272
|
+
}, 500);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
155
275
|
};
|
|
276
|
+
const TOKEN_STORAGE_PREFIX = "cohub:work-token";
|
|
156
277
|
var WorkRuntimeApi = class {
|
|
157
278
|
token = null;
|
|
279
|
+
transport;
|
|
280
|
+
tokenStorageKey;
|
|
281
|
+
constructor(transport = new ParentBridgeTransport(), workId) {
|
|
282
|
+
this.transport = transport;
|
|
283
|
+
this.tokenStorageKey = workId ? `${TOKEN_STORAGE_PREFIX}:${workId}` : null;
|
|
284
|
+
this.token = this.readStoredToken();
|
|
285
|
+
}
|
|
286
|
+
readStoredToken() {
|
|
287
|
+
if (!this.tokenStorageKey || typeof localStorage === "undefined") return null;
|
|
288
|
+
try {
|
|
289
|
+
return localStorage.getItem(this.tokenStorageKey);
|
|
290
|
+
} catch {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
writeStoredToken(token) {
|
|
295
|
+
if (!this.tokenStorageKey || typeof localStorage === "undefined") return;
|
|
296
|
+
try {
|
|
297
|
+
if (token) localStorage.setItem(this.tokenStorageKey, token);
|
|
298
|
+
else localStorage.removeItem(this.tokenStorageKey);
|
|
299
|
+
} catch {}
|
|
300
|
+
}
|
|
158
301
|
async context() {
|
|
159
|
-
return (await request({ type: "cohub.work.context" },
|
|
302
|
+
return (await this.transport.request({ type: "cohub.work.context" }, {
|
|
303
|
+
timeoutMs: 8e3,
|
|
304
|
+
retryIntervalMs: 250
|
|
305
|
+
}))?.context ?? null;
|
|
160
306
|
}
|
|
161
307
|
async getAccessToken(options) {
|
|
162
308
|
if (this.token && !options?.forceRefresh) return this.token;
|
|
163
|
-
|
|
309
|
+
if (options?.forceRefresh) {
|
|
310
|
+
this.token = null;
|
|
311
|
+
this.writeStoredToken(null);
|
|
312
|
+
}
|
|
313
|
+
const response = await this.transport.request({
|
|
164
314
|
type: "cohub.work.token",
|
|
165
315
|
forceRefresh: Boolean(options?.forceRefresh)
|
|
166
|
-
}, 2e4);
|
|
316
|
+
}, { timeoutMs: 2e4 });
|
|
167
317
|
this.token = response?.token ?? null;
|
|
318
|
+
this.writeStoredToken(this.token);
|
|
168
319
|
return this.token;
|
|
169
320
|
}
|
|
170
321
|
async requestAuthorization(input) {
|
|
171
|
-
const response = await request({
|
|
322
|
+
const response = await this.transport.request({
|
|
172
323
|
type: "cohub.work.authorize",
|
|
173
324
|
scopes: input.scopes,
|
|
174
325
|
reason: input.reason
|
|
175
|
-
}, 12e4);
|
|
326
|
+
}, { timeoutMs: 12e4 });
|
|
176
327
|
this.token = response?.token ?? null;
|
|
328
|
+
this.writeStoredToken(this.token);
|
|
177
329
|
return Boolean(this.token);
|
|
178
330
|
}
|
|
179
331
|
async purchase(input) {
|
|
180
|
-
return (await request({
|
|
332
|
+
return (await this.transport.request({
|
|
181
333
|
type: "cohub.work.purchase",
|
|
182
334
|
productKey: input.productKey
|
|
183
|
-
}, 12e4))?.checkout ?? null;
|
|
335
|
+
}, { timeoutMs: 12e4 }))?.checkout ?? null;
|
|
184
336
|
}
|
|
185
337
|
async checkoutState() {
|
|
186
|
-
return await request({ type: "cohub.work.checkout-state" },
|
|
338
|
+
return await this.transport.request({ type: "cohub.work.checkout-state" }, {
|
|
339
|
+
timeoutMs: 8e3,
|
|
340
|
+
retryIntervalMs: 250
|
|
341
|
+
}) ?? null;
|
|
187
342
|
}
|
|
188
343
|
};
|
|
189
|
-
|
|
344
|
+
/**
|
|
345
|
+
* Resolves the appropriate transport based on the work mode configuration.
|
|
346
|
+
* Auto-detection: inside an iframe → bridge; standalone with broker config →
|
|
347
|
+
* broker; otherwise → bridge (returns null for non-work contexts).
|
|
348
|
+
*/
|
|
349
|
+
function resolveWorkTransport(config) {
|
|
350
|
+
const explicitMode = config?.mode;
|
|
351
|
+
const brokerOrigin = config?.brokerOrigin;
|
|
352
|
+
const workId = config?.workId;
|
|
353
|
+
const hasBrokerConfig = Boolean(brokerOrigin && workId);
|
|
354
|
+
const createBroker = () => brokerOrigin && workId ? new PopupBrokerTransport({
|
|
355
|
+
brokerOrigin,
|
|
356
|
+
workId
|
|
357
|
+
}) : new ParentBridgeTransport();
|
|
358
|
+
if (explicitMode === "bridge") return new ParentBridgeTransport();
|
|
359
|
+
if (explicitMode === "broker") return createBroker();
|
|
360
|
+
if (typeof window !== "undefined" && window.parent !== window) return new ParentBridgeTransport();
|
|
361
|
+
return hasBrokerConfig ? createBroker() : new ParentBridgeTransport();
|
|
362
|
+
}
|
|
363
|
+
const createWorkRuntime = (transport, workId) => new WorkRuntimeApi(transport, workId);
|
|
190
364
|
//#endregion
|
|
191
365
|
//#region src/client.ts
|
|
192
366
|
var CohubClient = class {
|
|
@@ -201,6 +375,7 @@ var CohubClient = class {
|
|
|
201
375
|
publicAssets;
|
|
202
376
|
sessionAccess;
|
|
203
377
|
search;
|
|
378
|
+
references;
|
|
204
379
|
tasks;
|
|
205
380
|
cronJobs;
|
|
206
381
|
explore;
|
|
@@ -213,7 +388,8 @@ var CohubClient = class {
|
|
|
213
388
|
workRuntime;
|
|
214
389
|
constructor(options = {}) {
|
|
215
390
|
const apiBaseUrl = resolveApiBaseUrl(options);
|
|
216
|
-
|
|
391
|
+
const workTransport = resolveWorkTransport(options.work);
|
|
392
|
+
this.workRuntime = createWorkRuntime(workTransport, options.work?.workId);
|
|
217
393
|
const getAccessToken = options.getAccessToken ?? ((tokenOptions) => this.workRuntime.getAccessToken(tokenOptions));
|
|
218
394
|
const resolvedOptions = {
|
|
219
395
|
...options,
|
|
@@ -247,6 +423,7 @@ var CohubClient = class {
|
|
|
247
423
|
this.publicAssets = new PublicAssetsApi(this.transport);
|
|
248
424
|
this.sessionAccess = new SessionAccessApi(this.transport);
|
|
249
425
|
this.search = new SearchApi(this.transport);
|
|
426
|
+
this.references = new ReferencesApi(this.transport);
|
|
250
427
|
this.tasks = new TasksApi(this.transport);
|
|
251
428
|
this.cronJobs = new CronJobsApi(this.transport);
|
|
252
429
|
this.explore = new ExploreApi(this.transport);
|
|
@@ -574,4 +751,4 @@ function filterGenerationDeclarationsByPolicy(declarations, policy) {
|
|
|
574
751
|
});
|
|
575
752
|
}
|
|
576
753
|
//#endregion
|
|
577
|
-
export { BillingApi, COHUB_ENVIRONMENTS, CohubClient, CohubHttpClient, GenerationPolicyError, HttpError, SessionGenerationStreamClient, SessionPatchReducer, UsersApi, VoiceApi, VoiceInputClient, WebsocketClient, WorkCommerceApi, WorkRuntimeApi, WorksApi, assertGenerationRequestAllowedByPolicy, createCohubClient, createHttpClient, createSessionGenerationStreamClient, createSessionPatchReducer, createVoiceInputClient, createWebsocketClient, createWorkRuntime, decodeGenerationPolicy, encodeGenerationPolicy, filterGenerationDeclarationsByPolicy, findGenerationModelPolicy, getAllowedGenerationModelIds, isHttpErrorCode, normalizeBaseUrl, normalizeGenerationPolicy, normalizeVoiceInputWebsocketUrl, normalizeWebsocketUrl, parseAssistantMessageCommit, parseGenerationPolicyFromEnv, resolveApiBaseUrl, resolveCohubEnvironment, resolveVoiceInputWebsocketUrl, resolveWebsocketUrl };
|
|
754
|
+
export { BillingApi, COHUB_ENVIRONMENTS, CohubClient, CohubHttpClient, GenerationPolicyError, HttpError, ParentBridgeTransport, PopupBrokerTransport, ReferencesApi, SessionGenerationStreamClient, SessionPatchReducer, UsersApi, VoiceApi, VoiceInputClient, WebsocketClient, WorkCommerceApi, WorkRuntimeApi, WorksApi, assertGenerationRequestAllowedByPolicy, createCohubClient, createHttpClient, createSessionGenerationStreamClient, createSessionPatchReducer, createVoiceInputClient, createWebsocketClient, createWorkRuntime, decodeGenerationPolicy, encodeGenerationPolicy, filterGenerationDeclarationsByPolicy, findGenerationModelPolicy, getAllowedGenerationModelIds, isHttpErrorCode, normalizeBaseUrl, normalizeGenerationPolicy, normalizeVoiceInputWebsocketUrl, normalizeWebsocketUrl, parseAssistantMessageCommit, parseGenerationPolicyFromEnv, resolveApiBaseUrl, resolveCohubEnvironment, resolveVoiceInputWebsocketUrl, resolveWebsocketUrl, resolveWorkTransport };
|