@neta-art/cohub 1.25.1 → 1.25.2
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.d.ts +129 -1
- package/dist/index.js +118 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,39 @@ declare class BillingApi {
|
|
|
67
67
|
}>;
|
|
68
68
|
}
|
|
69
69
|
//#endregion
|
|
70
|
+
//#region src/work-runtime.d.ts
|
|
71
|
+
type WorkRuntimeContext = {
|
|
72
|
+
work: {
|
|
73
|
+
id: string;
|
|
74
|
+
slug: string;
|
|
75
|
+
url?: string | null;
|
|
76
|
+
};
|
|
77
|
+
space: {
|
|
78
|
+
id: string;
|
|
79
|
+
name?: string | null;
|
|
80
|
+
};
|
|
81
|
+
viewer?: {
|
|
82
|
+
userUuid: string;
|
|
83
|
+
} | null;
|
|
84
|
+
permissions?: {
|
|
85
|
+
scopes: Permission[];
|
|
86
|
+
workScopes: Permission[];
|
|
87
|
+
viewerScopes: Permission[];
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
declare class WorkRuntimeApi {
|
|
91
|
+
private token;
|
|
92
|
+
context(): Promise<WorkRuntimeContext | null>;
|
|
93
|
+
getAccessToken(options?: {
|
|
94
|
+
forceRefresh?: boolean;
|
|
95
|
+
}): Promise<string | null>;
|
|
96
|
+
requestAuthorization(input: {
|
|
97
|
+
scopes: Permission[];
|
|
98
|
+
reason?: string;
|
|
99
|
+
}): Promise<boolean>;
|
|
100
|
+
}
|
|
101
|
+
declare const createWorkRuntime: () => WorkRuntimeApi;
|
|
102
|
+
//#endregion
|
|
70
103
|
//#region src/apis/explore.d.ts
|
|
71
104
|
declare class ExploreApi {
|
|
72
105
|
private readonly transport;
|
|
@@ -74,6 +107,92 @@ declare class ExploreApi {
|
|
|
74
107
|
spaces(): Promise<ExploreSpacesResponse>;
|
|
75
108
|
}
|
|
76
109
|
//#endregion
|
|
110
|
+
//#region src/apis/works.d.ts
|
|
111
|
+
type WorkTargetType = "file" | "directory" | "port";
|
|
112
|
+
type WorkStatus = "draft" | "published";
|
|
113
|
+
type WorkRecord = {
|
|
114
|
+
id: string;
|
|
115
|
+
spaceId: string;
|
|
116
|
+
userUuid: string;
|
|
117
|
+
slug: string;
|
|
118
|
+
status: WorkStatus;
|
|
119
|
+
targetType: WorkTargetType;
|
|
120
|
+
targetRef: string;
|
|
121
|
+
assetKey: string | null;
|
|
122
|
+
publishedAt: string | null;
|
|
123
|
+
workScopes: Permission[];
|
|
124
|
+
allowedViewerScopes: Permission[];
|
|
125
|
+
meta: Record<string, unknown> | null;
|
|
126
|
+
createdAt: string | null;
|
|
127
|
+
updatedAt: string | null;
|
|
128
|
+
};
|
|
129
|
+
type WorkCreateInput = {
|
|
130
|
+
spaceId: string;
|
|
131
|
+
slug: string;
|
|
132
|
+
status?: WorkStatus;
|
|
133
|
+
targetType: WorkTargetType;
|
|
134
|
+
targetRef: string;
|
|
135
|
+
assetKey?: string | null;
|
|
136
|
+
workScopes?: Permission[];
|
|
137
|
+
allowedViewerScopes?: Permission[];
|
|
138
|
+
meta?: Record<string, unknown> | null;
|
|
139
|
+
};
|
|
140
|
+
type WorkContent = {
|
|
141
|
+
url: string;
|
|
142
|
+
targetType: "port";
|
|
143
|
+
port: string;
|
|
144
|
+
} | {
|
|
145
|
+
url: string;
|
|
146
|
+
targetType: WorkTargetType;
|
|
147
|
+
path: string;
|
|
148
|
+
};
|
|
149
|
+
type WorkSessionResponse = {
|
|
150
|
+
token: string;
|
|
151
|
+
expiresIn: number;
|
|
152
|
+
work: WorkRecord;
|
|
153
|
+
};
|
|
154
|
+
type WorkAuthorizeResponse = {
|
|
155
|
+
token: string;
|
|
156
|
+
expiresIn: number;
|
|
157
|
+
grant: {
|
|
158
|
+
id: string;
|
|
159
|
+
scopes: Permission[];
|
|
160
|
+
expiresAt: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
declare class WorksApi {
|
|
164
|
+
private readonly transport;
|
|
165
|
+
constructor(transport: HttpTransport);
|
|
166
|
+
listBySpace(spaceId: string): Promise<{
|
|
167
|
+
works: WorkRecord[];
|
|
168
|
+
}>;
|
|
169
|
+
getBySlug(username: string, spaceSlug: string, workSlug: string): Promise<{
|
|
170
|
+
work: WorkRecord;
|
|
171
|
+
space: {
|
|
172
|
+
id: string;
|
|
173
|
+
slug: string | null;
|
|
174
|
+
name: string | null;
|
|
175
|
+
userUuid: string;
|
|
176
|
+
publicProfile?: SpacePublicProfile | null;
|
|
177
|
+
};
|
|
178
|
+
owner: {
|
|
179
|
+
userUuid: string;
|
|
180
|
+
username: string | null;
|
|
181
|
+
displayName: string;
|
|
182
|
+
avatarUrl?: string | null;
|
|
183
|
+
};
|
|
184
|
+
content?: WorkContent | null;
|
|
185
|
+
}>;
|
|
186
|
+
create(input: WorkCreateInput): Promise<{
|
|
187
|
+
work: WorkRecord;
|
|
188
|
+
}>;
|
|
189
|
+
createSession(workId: string): Promise<WorkSessionResponse>;
|
|
190
|
+
authorize(workId: string, input: {
|
|
191
|
+
scopes: Permission[];
|
|
192
|
+
reason?: string;
|
|
193
|
+
}): Promise<WorkAuthorizeResponse>;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
77
196
|
//#region src/client.d.ts
|
|
78
197
|
declare class CohubClient {
|
|
79
198
|
readonly spaces: SpacesApi;
|
|
@@ -91,12 +210,21 @@ declare class CohubClient {
|
|
|
91
210
|
readonly explore: ExploreApi;
|
|
92
211
|
readonly invite: PublicInviteApi;
|
|
93
212
|
readonly voice: VoiceApi;
|
|
213
|
+
readonly works: WorksApi;
|
|
94
214
|
private readonly transport;
|
|
95
215
|
private readonly websocketClient;
|
|
216
|
+
private readonly workRuntime;
|
|
96
217
|
constructor(options?: CohubClientOptions);
|
|
218
|
+
context(): Promise<WorkRuntimeContext | null>;
|
|
219
|
+
readonly auth: {
|
|
220
|
+
request: (input: {
|
|
221
|
+
scopes: Permission[];
|
|
222
|
+
reason?: string;
|
|
223
|
+
}) => Promise<boolean>;
|
|
224
|
+
};
|
|
97
225
|
space(spaceId: string): SpaceClient;
|
|
98
226
|
onConnection(handler: (state: WebSocketConnectionState) => void): () => void;
|
|
99
227
|
}
|
|
100
228
|
declare const createCohubClient: (options?: CohubClientOptions) => CohubClient;
|
|
101
229
|
//#endregion
|
|
102
|
-
export { AcceptInvitationResponse, ApiError, type AssistantMessageCommit, BillingApi, BillingCatalog, BillingCatalogProduct, BillingCheckoutActionState, BillingCheckoutResult, BillingCreditExpiryGroup, BillingCreditGrantStatus, BillingCreditStatus, BillingCreditUnit, BillingHistoryPagination, BillingOpenOverageList, BillingOpenOverageStatus, BillingOrderList, BillingOrderStatus, BillingPaymentStatus, BillingPluginStatus, BillingProductBillingInterval, BillingProductCreditBenefit, BillingProductDisplay, BillingProductKind, BillingProductPricing, BillingRedemptionResult, BillingSubscriptionHistoryList, BillingSubscriptionHistoryStatus, BillingSubscriptionSummary, BillingUsageRecordList, BillingUsageRecordStatus, 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, CronJobRecord, 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 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 PublicAssetPurpose, type PublicGenerationDeclaration, type RawHttpResponse, type RealtimeServerEvent, ResourceLabelsResponse, 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, SpaceConfig, SpaceConfigInput, SpaceConfigResponse, SpaceCreateResponse, 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, SpacePublicProfile, SpaceRecord, SpaceRole, SpaceSandboxAutoDestroyPolicy, SpaceSandboxConfig, SpaceSessionsResponse, SpaceUsageHourlyStat, SpaceUsageResponse, SpaceUsageSummary, TaskRunDetailResponse, TaskRunRecord, UserProfile, UserRulesResponse, VoiceApi, type VoiceInputCallbacks, VoiceInputClient, type VoiceInputClientOptions, type VoiceInputCreateOptions, type VoiceInputEvent, type WebSocketConnectionState, WebsocketClient, assertGenerationRequestAllowedByPolicy, createCohubClient, createHttpClient, createSessionGenerationStreamClient, createSessionPatchReducer, createVoiceInputClient, createWebsocketClient, decodeGenerationPolicy, encodeGenerationPolicy, filterGenerationDeclarationsByPolicy, findGenerationModelPolicy, getAllowedGenerationModelIds, normalizeBaseUrl, normalizeGenerationPolicy, normalizeVoiceInputWebsocketUrl, normalizeWebsocketUrl, parseAssistantMessageCommit, parseGenerationPolicyFromEnv, resolveApiBaseUrl, resolveCohubEnvironment, resolveVoiceInputWebsocketUrl, resolveWebsocketUrl };
|
|
230
|
+
export { AcceptInvitationResponse, ApiError, type AssistantMessageCommit, BillingApi, BillingCatalog, BillingCatalogProduct, BillingCheckoutActionState, BillingCheckoutResult, BillingCreditExpiryGroup, BillingCreditGrantStatus, BillingCreditStatus, BillingCreditUnit, BillingHistoryPagination, BillingOpenOverageList, BillingOpenOverageStatus, BillingOrderList, BillingOrderStatus, BillingPaymentStatus, BillingPluginStatus, BillingProductBillingInterval, BillingProductCreditBenefit, BillingProductDisplay, BillingProductKind, BillingProductPricing, BillingRedemptionResult, BillingSubscriptionHistoryList, BillingSubscriptionHistoryStatus, BillingSubscriptionSummary, BillingUsageRecordList, BillingUsageRecordStatus, 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, CronJobRecord, 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 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 PublicAssetPurpose, type PublicGenerationDeclaration, type RawHttpResponse, type RealtimeServerEvent, ResourceLabelsResponse, 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, SpaceConfig, SpaceConfigInput, SpaceConfigResponse, SpaceCreateResponse, 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, SpacePublicProfile, SpaceRecord, SpaceRole, SpaceSandboxAutoDestroyPolicy, SpaceSandboxConfig, SpaceSessionsResponse, SpaceUsageHourlyStat, SpaceUsageResponse, SpaceUsageSummary, TaskRunDetailResponse, TaskRunRecord, UserProfile, UserRulesResponse, VoiceApi, type VoiceInputCallbacks, VoiceInputClient, type VoiceInputClientOptions, type VoiceInputCreateOptions, type VoiceInputEvent, type WebSocketConnectionState, WebsocketClient, type WorkAuthorizeResponse, type WorkCreateInput, type WorkRecord, WorkRuntimeApi, type WorkRuntimeContext, type WorkSessionResponse, type WorkStatus, type WorkTargetType, WorksApi, assertGenerationRequestAllowedByPolicy, createCohubClient, createHttpClient, createSessionGenerationStreamClient, createSessionPatchReducer, createVoiceInputClient, createWebsocketClient, createWorkRuntime, decodeGenerationPolicy, encodeGenerationPolicy, filterGenerationDeclarationsByPolicy, findGenerationModelPolicy, getAllowedGenerationModelIds, normalizeBaseUrl, normalizeGenerationPolicy, normalizeVoiceInputWebsocketUrl, normalizeWebsocketUrl, parseAssistantMessageCommit, parseGenerationPolicyFromEnv, resolveApiBaseUrl, resolveCohubEnvironment, resolveVoiceInputWebsocketUrl, resolveWebsocketUrl };
|
package/dist/index.js
CHANGED
|
@@ -85,6 +85,107 @@ var ExploreApi = class {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
//#endregion
|
|
88
|
+
//#region src/apis/works.ts
|
|
89
|
+
var WorksApi = class {
|
|
90
|
+
transport;
|
|
91
|
+
constructor(transport) {
|
|
92
|
+
this.transport = transport;
|
|
93
|
+
}
|
|
94
|
+
listBySpace(spaceId) {
|
|
95
|
+
return this.transport.request(`/api/works/space/${spaceId}`);
|
|
96
|
+
}
|
|
97
|
+
getBySlug(username, spaceSlug, workSlug) {
|
|
98
|
+
return this.transport.request(`/api/works/by-slug/${encodeURIComponent(username)}/${encodeURIComponent(spaceSlug)}/${encodeURIComponent(workSlug)}`);
|
|
99
|
+
}
|
|
100
|
+
create(input) {
|
|
101
|
+
return this.transport.request("/api/works", {
|
|
102
|
+
method: "POST",
|
|
103
|
+
headers: { "Content-Type": "application/json" },
|
|
104
|
+
body: JSON.stringify(input)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
createSession(workId) {
|
|
108
|
+
return this.transport.request(`/api/works/${workId}/session`, { method: "POST" });
|
|
109
|
+
}
|
|
110
|
+
authorize(workId, input) {
|
|
111
|
+
return this.transport.request(`/api/works/${workId}/authorize`, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: { "Content-Type": "application/json" },
|
|
114
|
+
body: JSON.stringify(input)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/work-runtime.ts
|
|
120
|
+
const isBrowser = () => typeof window !== "undefined" && typeof window.parent !== "undefined";
|
|
121
|
+
const hasParent = () => isBrowser() && window.parent !== window;
|
|
122
|
+
const getParentOrigin = () => {
|
|
123
|
+
if (!isBrowser()) return null;
|
|
124
|
+
const ancestorOrigin = window.location.ancestorOrigins?.[0];
|
|
125
|
+
if (ancestorOrigin) return ancestorOrigin;
|
|
126
|
+
try {
|
|
127
|
+
return document.referrer ? new URL(document.referrer).origin : null;
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
let trustedParentOrigin = null;
|
|
133
|
+
const request = (message, timeoutMs = 1200) => {
|
|
134
|
+
if (!hasParent()) return Promise.resolve(null);
|
|
135
|
+
const requestId = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
const timer = setTimeout(() => {
|
|
138
|
+
window.removeEventListener("message", onMessage);
|
|
139
|
+
resolve(null);
|
|
140
|
+
}, timeoutMs);
|
|
141
|
+
const parentOrigin = trustedParentOrigin ?? getParentOrigin();
|
|
142
|
+
const onMessage = (event) => {
|
|
143
|
+
if (event.source !== window.parent) return;
|
|
144
|
+
if (parentOrigin && event.origin !== parentOrigin) return;
|
|
145
|
+
const data = event.data;
|
|
146
|
+
if (!data || data.requestId !== requestId) return;
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
window.removeEventListener("message", onMessage);
|
|
149
|
+
trustedParentOrigin = event.origin;
|
|
150
|
+
if (data.type === "cohub.work.error") {
|
|
151
|
+
reject(new Error(data.message));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
resolve(data);
|
|
155
|
+
};
|
|
156
|
+
window.addEventListener("message", onMessage);
|
|
157
|
+
window.parent.postMessage({
|
|
158
|
+
...message,
|
|
159
|
+
requestId
|
|
160
|
+
}, parentOrigin ?? "*");
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
var WorkRuntimeApi = class {
|
|
164
|
+
token = null;
|
|
165
|
+
async context() {
|
|
166
|
+
return (await request({ type: "cohub.work.context" }, 8e3))?.context ?? null;
|
|
167
|
+
}
|
|
168
|
+
async getAccessToken(options) {
|
|
169
|
+
if (this.token && !options?.forceRefresh) return this.token;
|
|
170
|
+
const response = await request({
|
|
171
|
+
type: "cohub.work.token",
|
|
172
|
+
forceRefresh: Boolean(options?.forceRefresh)
|
|
173
|
+
}, 2e4);
|
|
174
|
+
this.token = response?.token ?? null;
|
|
175
|
+
return this.token;
|
|
176
|
+
}
|
|
177
|
+
async requestAuthorization(input) {
|
|
178
|
+
const response = await request({
|
|
179
|
+
type: "cohub.work.authorize",
|
|
180
|
+
scopes: input.scopes,
|
|
181
|
+
reason: input.reason
|
|
182
|
+
}, 12e4);
|
|
183
|
+
this.token = response?.token ?? null;
|
|
184
|
+
return Boolean(this.token);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const createWorkRuntime = () => new WorkRuntimeApi();
|
|
188
|
+
//#endregion
|
|
88
189
|
//#region src/client.ts
|
|
89
190
|
var CohubClient = class {
|
|
90
191
|
spaces;
|
|
@@ -102,23 +203,31 @@ var CohubClient = class {
|
|
|
102
203
|
explore;
|
|
103
204
|
invite;
|
|
104
205
|
voice;
|
|
206
|
+
works;
|
|
105
207
|
transport;
|
|
106
208
|
websocketClient;
|
|
209
|
+
workRuntime;
|
|
107
210
|
constructor(options = {}) {
|
|
108
211
|
const apiBaseUrl = resolveApiBaseUrl(options);
|
|
109
|
-
this.
|
|
212
|
+
this.workRuntime = createWorkRuntime();
|
|
213
|
+
const getAccessToken = options.getAccessToken ?? ((tokenOptions) => this.workRuntime.getAccessToken(tokenOptions));
|
|
214
|
+
const resolvedOptions = {
|
|
215
|
+
...options,
|
|
216
|
+
getAccessToken
|
|
217
|
+
};
|
|
218
|
+
this.transport = new HttpTransport(resolvedOptions);
|
|
110
219
|
this.websocketClient = createWebsocketClient({
|
|
111
220
|
url: resolveWebsocketUrl({
|
|
112
221
|
env: options.websocket?.env ?? options.env,
|
|
113
222
|
url: options.websocket?.url
|
|
114
223
|
}),
|
|
115
224
|
...options.websocket,
|
|
116
|
-
getAccessToken: options.websocket?.getAccessToken ??
|
|
225
|
+
getAccessToken: options.websocket?.getAccessToken ?? getAccessToken
|
|
117
226
|
});
|
|
118
227
|
this.voice = new VoiceApi({
|
|
119
228
|
env: options.voice?.env ?? options.env,
|
|
120
229
|
url: options.voice?.url,
|
|
121
|
-
getAccessToken: options.voice?.getAccessToken ??
|
|
230
|
+
getAccessToken: options.voice?.getAccessToken ?? getAccessToken,
|
|
122
231
|
WebSocketImpl: options.voice?.WebSocketImpl,
|
|
123
232
|
connectionTimeoutMs: options.voice?.connectionTimeoutMs,
|
|
124
233
|
idleConnectionTimeoutMs: options.voice?.idleConnectionTimeoutMs
|
|
@@ -137,7 +246,12 @@ var CohubClient = class {
|
|
|
137
246
|
this.cronJobs = new CronJobsApi(this.transport);
|
|
138
247
|
this.explore = new ExploreApi(this.transport);
|
|
139
248
|
this.invite = new PublicInviteApi(this.transport);
|
|
249
|
+
this.works = new WorksApi(this.transport);
|
|
250
|
+
}
|
|
251
|
+
context() {
|
|
252
|
+
return this.workRuntime.context();
|
|
140
253
|
}
|
|
254
|
+
auth = { request: (input) => this.workRuntime.requestAuthorization(input) };
|
|
141
255
|
space(spaceId) {
|
|
142
256
|
return new SpaceClient(spaceId, this.transport, this.websocketClient);
|
|
143
257
|
}
|
|
@@ -419,4 +533,4 @@ function filterGenerationDeclarationsByPolicy(declarations, policy) {
|
|
|
419
533
|
});
|
|
420
534
|
}
|
|
421
535
|
//#endregion
|
|
422
|
-
export { BillingApi, COHUB_ENVIRONMENTS, CohubClient, CohubHttpClient, GenerationPolicyError, HttpError, SessionGenerationStreamClient, SessionPatchReducer, VoiceApi, VoiceInputClient, WebsocketClient, assertGenerationRequestAllowedByPolicy, createCohubClient, createHttpClient, createSessionGenerationStreamClient, createSessionPatchReducer, createVoiceInputClient, createWebsocketClient, decodeGenerationPolicy, encodeGenerationPolicy, filterGenerationDeclarationsByPolicy, findGenerationModelPolicy, getAllowedGenerationModelIds, normalizeBaseUrl, normalizeGenerationPolicy, normalizeVoiceInputWebsocketUrl, normalizeWebsocketUrl, parseAssistantMessageCommit, parseGenerationPolicyFromEnv, resolveApiBaseUrl, resolveCohubEnvironment, resolveVoiceInputWebsocketUrl, resolveWebsocketUrl };
|
|
536
|
+
export { BillingApi, COHUB_ENVIRONMENTS, CohubClient, CohubHttpClient, GenerationPolicyError, HttpError, SessionGenerationStreamClient, SessionPatchReducer, VoiceApi, VoiceInputClient, WebsocketClient, WorkRuntimeApi, WorksApi, assertGenerationRequestAllowedByPolicy, createCohubClient, createHttpClient, createSessionGenerationStreamClient, createSessionPatchReducer, createVoiceInputClient, createWebsocketClient, createWorkRuntime, decodeGenerationPolicy, encodeGenerationPolicy, filterGenerationDeclarationsByPolicy, findGenerationModelPolicy, getAllowedGenerationModelIds, normalizeBaseUrl, normalizeGenerationPolicy, normalizeVoiceInputWebsocketUrl, normalizeWebsocketUrl, parseAssistantMessageCommit, parseGenerationPolicyFromEnv, resolveApiBaseUrl, resolveCohubEnvironment, resolveVoiceInputWebsocketUrl, resolveWebsocketUrl };
|