deepspace 0.3.11 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +258 -120
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +39 -15
- package/dist/index.js +76 -45
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +72 -73
- package/dist/server.js +368 -337
- package/dist/server.js.map +1 -1
- package/dist/worker.d.ts +72 -73
- package/dist/worker.js +422 -391
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/worker.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ declare const MSG: {
|
|
|
37
37
|
readonly USER_LIST: "user.list";
|
|
38
38
|
readonly SET_ROLE: "user.set_role";
|
|
39
39
|
readonly USER_UPDATE: "user.update";
|
|
40
|
+
readonly AUTH: "auth";
|
|
40
41
|
readonly YJS_JOIN: "yjs.join";
|
|
41
42
|
readonly YJS_LEAVE: "yjs.leave";
|
|
42
43
|
readonly ACK: "records.ack";
|
|
@@ -280,6 +281,8 @@ type ServerMessage = BaseMessage<typeof MSG.QUERY_RESULT, {
|
|
|
280
281
|
error: string;
|
|
281
282
|
}> | BaseMessage<typeof MSG.RESUBSCRIBE, EmptyPayload> | BaseMessage<typeof MSG.LIST_SCHEMAS, {
|
|
282
283
|
schemas: unknown;
|
|
284
|
+
}> | BaseMessage<typeof MSG.AUTH, {
|
|
285
|
+
canWrite: boolean;
|
|
283
286
|
}> | BaseMessage<typeof MSG.USER_INFO, unknown> | BaseMessage<typeof MSG.USER_LIST, {
|
|
284
287
|
users: unknown[];
|
|
285
288
|
}> | BaseMessage<typeof MSG.YJS_JOIN, {
|
|
@@ -1503,6 +1506,8 @@ interface GameInput {
|
|
|
1503
1506
|
}
|
|
1504
1507
|
interface GameAttachment extends UserAttachment {
|
|
1505
1508
|
joinedAt: string;
|
|
1509
|
+
/** True for member/admin roles; false for viewers, unauthenticated anon, spectators. */
|
|
1510
|
+
canWrite: boolean;
|
|
1506
1511
|
}
|
|
1507
1512
|
declare abstract class GameRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1508
1513
|
private config;
|
|
@@ -1600,6 +1605,8 @@ interface Viewport {
|
|
|
1600
1605
|
}
|
|
1601
1606
|
interface CanvasAttachment extends UserAttachment {
|
|
1602
1607
|
viewport: Viewport | null;
|
|
1608
|
+
/** True for member/admin roles; false for viewers and unauthenticated anon. */
|
|
1609
|
+
canWrite: boolean;
|
|
1603
1610
|
}
|
|
1604
1611
|
declare class CanvasRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1605
1612
|
private doc;
|
|
@@ -1712,13 +1719,17 @@ interface CronExecution {
|
|
|
1712
1719
|
durationMs: number;
|
|
1713
1720
|
error?: string;
|
|
1714
1721
|
}
|
|
1722
|
+
interface CronAttachment extends UserAttachment {
|
|
1723
|
+
/** True for member/admin roles; false for viewers and unauthenticated anon. */
|
|
1724
|
+
canWrite: boolean;
|
|
1725
|
+
}
|
|
1715
1726
|
declare abstract class CronRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1716
1727
|
private tasks;
|
|
1717
1728
|
private initialized;
|
|
1718
1729
|
constructor(state: DurableObjectState, env: unknown, config: CronRoomConfig);
|
|
1719
1730
|
private ensureInitialized;
|
|
1720
1731
|
fetch(request: Request): Promise<Response>;
|
|
1721
|
-
protected onConnect(ws: WebSocket, user: UserAttachment):
|
|
1732
|
+
protected onConnect(ws: WebSocket, user: UserAttachment): CronAttachment;
|
|
1722
1733
|
protected onMessage(ws: WebSocket, user: UserAttachment, message: {
|
|
1723
1734
|
type: string;
|
|
1724
1735
|
[key: string]: unknown;
|
|
@@ -2037,7 +2048,7 @@ declare const ALLOWED_BINDING_TYPES: Set<string>;
|
|
|
2037
2048
|
*
|
|
2038
2049
|
* Includes:
|
|
2039
2050
|
* - Static-asset + service bindings the platform sets up automatically.
|
|
2040
|
-
* - SDK-managed env (auth, identity, owner JWT
|
|
2051
|
+
* - SDK-managed env (auth, identity, owner JWT).
|
|
2041
2052
|
* - The auto-attached cost-tracking AE dataset (`USAGE_EVENTS`).
|
|
2042
2053
|
*
|
|
2043
2054
|
* DO binding names (RECORD_ROOMS, YJS_ROOMS, etc.) are NOT in this set
|
|
@@ -2680,52 +2691,6 @@ interface ActionContext<TEnv = Record<string, unknown>> {
|
|
|
2680
2691
|
}
|
|
2681
2692
|
type ActionHandler<TEnv = Record<string, unknown>> = (ctx: ActionContext<TEnv>) => Promise<ActionResult>;
|
|
2682
2693
|
|
|
2683
|
-
/**
|
|
2684
|
-
* Cron System — Server-Side Scheduled Tasks
|
|
2685
|
-
*
|
|
2686
|
-
* Provides CronContext for miniapp cron handlers and buildCronContext
|
|
2687
|
-
* to construct it from worker environment bindings.
|
|
2688
|
-
*
|
|
2689
|
-
* CronContext gives handlers access to:
|
|
2690
|
-
* - records: Query/create/update/delete via RecordRoom tools API
|
|
2691
|
-
* - integrations: Call platform integration endpoints (billed to owner)
|
|
2692
|
-
* - ownerUserId: The app owner's user ID
|
|
2693
|
-
*/
|
|
2694
|
-
/** Context passed to cron handler functions */
|
|
2695
|
-
interface CronContext {
|
|
2696
|
-
/** RecordRoom data access (queries the DO directly via tools API) */
|
|
2697
|
-
records: {
|
|
2698
|
-
query(collection: string, opts?: {
|
|
2699
|
-
where?: Record<string, unknown>;
|
|
2700
|
-
limit?: number;
|
|
2701
|
-
}): Promise<any[]>;
|
|
2702
|
-
create(collection: string, data: Record<string, unknown>): Promise<any>;
|
|
2703
|
-
update(collection: string, recordId: string, data: Record<string, unknown>): Promise<any>;
|
|
2704
|
-
delete(collection: string, recordId: string): Promise<any>;
|
|
2705
|
-
};
|
|
2706
|
-
/** Call platform integration endpoints, billed to owner */
|
|
2707
|
-
integrations: {
|
|
2708
|
-
call(endpoint: string, params: Record<string, unknown>): Promise<any>;
|
|
2709
|
-
};
|
|
2710
|
-
/** App owner's user ID */
|
|
2711
|
-
ownerUserId: string;
|
|
2712
|
-
}
|
|
2713
|
-
/** Environment bindings needed by buildCronContext */
|
|
2714
|
-
interface CronEnv {
|
|
2715
|
-
RECORD_ROOMS: DurableObjectNamespace;
|
|
2716
|
-
INTERNAL_STORAGE_HMAC_SECRET?: string;
|
|
2717
|
-
/** Override API base URL for local dev or custom platform deployments. */
|
|
2718
|
-
API_BASE_URL?: string;
|
|
2719
|
-
}
|
|
2720
|
-
/**
|
|
2721
|
-
* Build a CronContext from worker environment bindings.
|
|
2722
|
-
*
|
|
2723
|
-
* @param env - Worker environment with RECORD_ROOMS DO namespace and HMAC secret
|
|
2724
|
-
* @param ownerUserId - App owner's user ID (for RBAC and billing)
|
|
2725
|
-
* @param roomId - RecordRoom ID (defaults to 'default')
|
|
2726
|
-
*/
|
|
2727
|
-
declare function buildCronContext(env: CronEnv, ownerUserId: string, roomId?: string): CronContext;
|
|
2728
|
-
|
|
2729
2694
|
/**
|
|
2730
2695
|
* Upstream worker proxy helpers.
|
|
2731
2696
|
*
|
|
@@ -2813,6 +2778,61 @@ declare function platformWorkerFetch(env: PlatformWorkerEnv, pathOrRequest: stri
|
|
|
2813
2778
|
*/
|
|
2814
2779
|
declare function authWorkerFetch(env: AuthWorkerEnv, path: string, init?: RequestInit): Promise<Response>;
|
|
2815
2780
|
|
|
2781
|
+
/**
|
|
2782
|
+
* Cron System — Server-Side Scheduled Tasks
|
|
2783
|
+
*
|
|
2784
|
+
* Provides CronContext for miniapp cron handlers and buildCronContext
|
|
2785
|
+
* to construct it from worker environment bindings.
|
|
2786
|
+
*
|
|
2787
|
+
* CronContext gives handlers access to:
|
|
2788
|
+
* - records: Query/create/update/delete via RecordRoom tools API
|
|
2789
|
+
* - integrations: Call platform integration endpoints, billed to the app owner
|
|
2790
|
+
* - ownerUserId: The app owner's user ID
|
|
2791
|
+
*/
|
|
2792
|
+
|
|
2793
|
+
/** Context passed to cron handler functions */
|
|
2794
|
+
interface CronContext {
|
|
2795
|
+
/** RecordRoom data access (queries the DO directly via tools API) */
|
|
2796
|
+
records: {
|
|
2797
|
+
query(collection: string, opts?: {
|
|
2798
|
+
where?: Record<string, unknown>;
|
|
2799
|
+
limit?: number;
|
|
2800
|
+
}): Promise<any[]>;
|
|
2801
|
+
create(collection: string, data: Record<string, unknown>): Promise<any>;
|
|
2802
|
+
update(collection: string, recordId: string, data: Record<string, unknown>): Promise<any>;
|
|
2803
|
+
delete(collection: string, recordId: string): Promise<any>;
|
|
2804
|
+
};
|
|
2805
|
+
/**
|
|
2806
|
+
* Call a platform integration endpoint (e.g. "openai/chat-completion",
|
|
2807
|
+
* "freepik/text-to-image-classic"). Billed to the app owner — the same
|
|
2808
|
+
* APP_OWNER_JWT the rest of the SDK uses for server-side billed calls.
|
|
2809
|
+
*/
|
|
2810
|
+
integrations: {
|
|
2811
|
+
call(endpoint: string, params?: Record<string, unknown>): Promise<any>;
|
|
2812
|
+
};
|
|
2813
|
+
/** App owner's user ID */
|
|
2814
|
+
ownerUserId: string;
|
|
2815
|
+
}
|
|
2816
|
+
/** Environment bindings needed by buildCronContext */
|
|
2817
|
+
interface CronEnv extends ApiWorkerEnv {
|
|
2818
|
+
RECORD_ROOMS: DurableObjectNamespace;
|
|
2819
|
+
/**
|
|
2820
|
+
* Long-lived app-owner JWT minted at deploy time. Required for
|
|
2821
|
+
* `integrations.call()` so the call is billed to the app owner.
|
|
2822
|
+
* Optional here so apps that don't use integrations from cron can omit
|
|
2823
|
+
* it without a type error; missing-at-call-time throws a clear message.
|
|
2824
|
+
*/
|
|
2825
|
+
APP_OWNER_JWT?: string;
|
|
2826
|
+
}
|
|
2827
|
+
/**
|
|
2828
|
+
* Build a CronContext from worker environment bindings.
|
|
2829
|
+
*
|
|
2830
|
+
* @param env - Worker environment with RECORD_ROOMS DO namespace, APP_OWNER_JWT, and an api-worker transport (API_WORKER binding or API_WORKER_URL)
|
|
2831
|
+
* @param ownerUserId - App owner's user ID (for RBAC and billing)
|
|
2832
|
+
* @param roomId - RecordRoom ID (defaults to 'default')
|
|
2833
|
+
*/
|
|
2834
|
+
declare function buildCronContext(env: CronEnv, ownerUserId: string, roomId?: string): CronContext;
|
|
2835
|
+
|
|
2816
2836
|
/**
|
|
2817
2837
|
* AI provider helpers — create Vercel AI SDK providers that route through
|
|
2818
2838
|
* the DeepSpace API worker proxy for per-user billing.
|
|
@@ -3372,22 +3392,6 @@ interface VerifyOutcome {
|
|
|
3372
3392
|
debug?: TokenDebugInfo;
|
|
3373
3393
|
error?: unknown;
|
|
3374
3394
|
}
|
|
3375
|
-
interface InternalSignature {
|
|
3376
|
-
timestamp: string;
|
|
3377
|
-
signature: string;
|
|
3378
|
-
}
|
|
3379
|
-
interface VerifyInternalSignatureInput {
|
|
3380
|
-
secret: string | undefined;
|
|
3381
|
-
timestamp: string | null | undefined;
|
|
3382
|
-
signature: string | null | undefined;
|
|
3383
|
-
payload: string;
|
|
3384
|
-
maxSkewMs?: number;
|
|
3385
|
-
}
|
|
3386
|
-
interface SignInternalPayloadInput {
|
|
3387
|
-
secret: string;
|
|
3388
|
-
payload: string;
|
|
3389
|
-
timestamp?: string;
|
|
3390
|
-
}
|
|
3391
3395
|
|
|
3392
3396
|
/**
|
|
3393
3397
|
* JWT verification for DeepSpace workers.
|
|
@@ -3408,17 +3412,12 @@ interface SignInternalPayloadInput {
|
|
|
3408
3412
|
declare function verifyJwt(config: JwtVerifierConfig, token: string | null | undefined): Promise<VerifyOutcome>;
|
|
3409
3413
|
|
|
3410
3414
|
/**
|
|
3411
|
-
* HMAC
|
|
3412
|
-
*
|
|
3413
|
-
*
|
|
3415
|
+
* HMAC primitives used by the per-app identity tokens (APP_IDENTITY_TOKEN)
|
|
3416
|
+
* minted at deploy time and verified on every /internal/* call into the
|
|
3417
|
+
* platform worker. Auth-provider-agnostic.
|
|
3414
3418
|
*/
|
|
3415
|
-
|
|
3416
|
-
declare const DEFAULT_MAX_SKEW_MS: number;
|
|
3417
3419
|
declare function computeHmacHex(secret: string, payload: string): Promise<string>;
|
|
3418
3420
|
declare function timingSafeEqualHex(a: string, b: string): Promise<boolean>;
|
|
3419
|
-
declare function signInternalPayload({ secret, payload, timestamp, }: SignInternalPayloadInput): Promise<InternalSignature>;
|
|
3420
|
-
declare function verifyInternalSignature({ secret, timestamp, signature, payload, maxSkewMs, }: VerifyInternalSignatureInput): Promise<boolean>;
|
|
3421
|
-
declare function buildInternalPayload(body: unknown): string;
|
|
3422
3421
|
|
|
3423
3422
|
declare function decodeJwtPayload(token: string | null | undefined): TokenDebugInfo | undefined;
|
|
3424
3423
|
|
|
@@ -4276,4 +4275,4 @@ type DeepSpaceAuth = ReturnType<typeof createDeepSpaceAuth>;
|
|
|
4276
4275
|
/** Collections that bypass schema checks (permissive access) */
|
|
4277
4276
|
declare const SYSTEM_COLLECTIONS: Set<string>;
|
|
4278
4277
|
|
|
4279
|
-
export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, ALLOWED_BINDING_TYPES, APP_NAME_RULES, AUTO_PROVISIONABLE_TYPES, AUTO_PROVISION_SENTINEL, type ActionContext, type ActionHandler, type ActionResult, type ActionTools, type ApiWorkerEnv, type AppNameResolution, type AppNameValidation, type AuthWorkerEnv, Awareness, type AwarenessState, type AwarenessStates, BASE_USERS_SCHEMA, BUILT_IN_TOOLS, type BaseMessage, BaseRoom, CHANNELS_SCHEMA, CHANNEL_INVITATIONS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, CONVERSATION_SCHEMAS, COST_RATES, CanvasRoom, type CanvasShape, type ChatContextConfig, type ChatMessageRow, type ChatRow, type ChatTurn, type ClientMessage, type CollectionPermissionSummary, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, type ConnectionAttachment, type ConvMemberData, type ConvMessageData, type ConvReactionData, type ConvReadCursorData, type ConvVoteData, type ConversationStateData, type CronContext, type CronExecution, CronRoom, type CronRoomConfig, type CronTask, type CustomBinding, type CustomBindingManifest, DEFAULT_CONTEXT_CONFIG, DEFAULT_DO_MANIFEST,
|
|
4278
|
+
export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, ALLOWED_BINDING_TYPES, APP_NAME_RULES, AUTO_PROVISIONABLE_TYPES, AUTO_PROVISION_SENTINEL, type ActionContext, type ActionHandler, type ActionResult, type ActionTools, type ApiWorkerEnv, type AppNameResolution, type AppNameValidation, type AuthWorkerEnv, Awareness, type AwarenessState, type AwarenessStates, BASE_USERS_SCHEMA, BUILT_IN_TOOLS, type BaseMessage, BaseRoom, CHANNELS_SCHEMA, CHANNEL_INVITATIONS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, CONVERSATION_SCHEMAS, COST_RATES, CanvasRoom, type CanvasShape, type ChatContextConfig, type ChatMessageRow, type ChatRow, type ChatTurn, type ClientMessage, type CollectionPermissionSummary, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, type ConnectionAttachment, type ConvMemberData, type ConvMessageData, type ConvReactionData, type ConvReadCursorData, type ConvVoteData, type ConversationStateData, type CronContext, type CronExecution, CronRoom, type CronRoomConfig, type CronTask, type CustomBinding, type CustomBindingManifest, DEFAULT_CONTEXT_CONFIG, DEFAULT_DO_MANIFEST, DIRECTORY_SCHEMAS, type DOBindings, type DOManifest, type DOManifestEntry, type DeepSpaceAIEnv, type DeepSpaceAIOptions, type DeepSpaceAuth, type DeepSpaceAuthConfig, type DirectoryCommunityData, type DirectoryConversationData, type DirectoryMembershipData, type DirectoryPostData, type DoMigrationDirective, type DoMigrationPlan, type ExistingDOBinding, GLOBAL_DO_TYPES, GLOBAL_DO_TYPE_NAMES, type GameInput, GameRoom, type GameRoomConfig, type GetActionData, type GlobalDOType, type HandlerContext, type Job, type JobContext, JobRoom, type JobRoomConfig, type JobStatus, type JwtClaims, type JwtVerifierConfig, MESSAGES_SCHEMA, MSG, MSG_AWARENESS, MSG_SYNC, MSG_SYNC_STEP1, MSG_SYNC_STEP2, MSG_SYNC_UPDATE, MSG_YJS_AWARENESS, MSG_YJS_SYNC, type MessageHandlers, type MsgType, type MutateActionData, type PermissionAnalysis, type PermissionContext, type PermissionLevel, type PermissionSource, type PlatformWorkerEnv, type Player, type PrefixResult, type PresencePeer, PresenceRoom, type ProtocolMessage, type QueryActionData, REACTIONS_SCHEMA, READ_RECEIPTS_SCHEMA, RESERVED_BINDING_NAMES, RESERVED_COLLECTION_NAMES, ROLE_ADMIN, ROLE_ANONYMOUS, ROLE_DEFAULT, RecordRoom, type RecordRoomConfig, type ResolvedColumn, type ResolvedPermission, type RolePermissions, type RunMigrationsResult, SYSTEM_COLLECTIONS, SYSTEM_MANAGED_COLUMNS, SchemaRegistry, type ScopeContext, type ScopedR2Auth, type ScopedR2Config, type ScopedR2Handler, type ScreenshotEnv, type ScreenshotOptions, type ScreenshotResult, type ServerMessage, type SharedConnection, type StoredRecord, type Summarizer, type SyncResult, type TokenDebugInfo, type ToolResult, type ToolSchema, USERS_COLUMNS, type User, type UserAttachment, VOTING_SCHEMAS, type ValidationError, type VerifiedAuth, type VerifyOutcome, type VerifyResult, type Viewport, WORKSPACE_SCHEMAS, YjsRoom, analyzePermissions, apiWorkerFetch, appendMessage, applySlidingWindow, authWorkerFetch, bindingManifestFromOutputConfig, buildCronContext, buildTableSelect, buildUiParts, canCreate, canDelete, canRead, canUpdate, capToolResultSize, captureScreenshot, checkFieldPermissions, clientBuild, coerceValue, collectionTableName, columnId, computeDoMigration, computeHmacHex, createChat, createDecoder, createDeepSpaceAI, createDeepSpaceAuth, createEncoder, createScopedR2Handler, dataToColumnValues, decodeJwtPayload, deleteChatCascade, dispatch, encode, encodeAwarenessMessage, encodeSyncStep1, encodeSyncStep2, encodeUpdate, enqueueJob, getChat, getGlobalDOSchemas, getGlobalDOType, getMessageType, getRolePermissions, handleAwarenessMessage, handleSyncMessage, hasContent, isAutoProvision, isOwner, lintSchema, loadMessages, makeDefaultSummarizer, meterAi, meterUsage, meterVectorize, noopPermissionContext, platformWorkerFetch, prepareMessagesWithCompaction, priceBindingUsageEvent, readVarUint, readVarUint8Array, resolveAppName, resolveColumn, rowToData, runMigrations, serverBuild, timingSafeEqualHex, toUint8Array, totalChars, truncateOldToolResults, turnsToCoreMessages, unwrapToolOutput, updateChat, validateAppName, validateBindingManifest, validateDoManifest, verifyJwt, workspaceAccountsSchema, workspaceContentSharesSchema, workspaceEmailHandlesSchema, workspaceFormResponsesSchema, workspacePeopleSchema, workspaceProjectsSchema, workspaceTagsSchema, workspaceTasksSchema, workspaceTeamMembersSchema, workspaceTeamsSchema, workspaceTransactionsSchema, writeVarUint, writeVarUint8Array };
|