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/server.d.ts
CHANGED
|
@@ -357,52 +357,6 @@ interface ActionContext<TEnv = Record<string, unknown>> {
|
|
|
357
357
|
}
|
|
358
358
|
type ActionHandler<TEnv = Record<string, unknown>> = (ctx: ActionContext<TEnv>) => Promise<ActionResult>;
|
|
359
359
|
|
|
360
|
-
/**
|
|
361
|
-
* Cron System — Server-Side Scheduled Tasks
|
|
362
|
-
*
|
|
363
|
-
* Provides CronContext for miniapp cron handlers and buildCronContext
|
|
364
|
-
* to construct it from worker environment bindings.
|
|
365
|
-
*
|
|
366
|
-
* CronContext gives handlers access to:
|
|
367
|
-
* - records: Query/create/update/delete via RecordRoom tools API
|
|
368
|
-
* - integrations: Call platform integration endpoints (billed to owner)
|
|
369
|
-
* - ownerUserId: The app owner's user ID
|
|
370
|
-
*/
|
|
371
|
-
/** Context passed to cron handler functions */
|
|
372
|
-
interface CronContext {
|
|
373
|
-
/** RecordRoom data access (queries the DO directly via tools API) */
|
|
374
|
-
records: {
|
|
375
|
-
query(collection: string, opts?: {
|
|
376
|
-
where?: Record<string, unknown>;
|
|
377
|
-
limit?: number;
|
|
378
|
-
}): Promise<any[]>;
|
|
379
|
-
create(collection: string, data: Record<string, unknown>): Promise<any>;
|
|
380
|
-
update(collection: string, recordId: string, data: Record<string, unknown>): Promise<any>;
|
|
381
|
-
delete(collection: string, recordId: string): Promise<any>;
|
|
382
|
-
};
|
|
383
|
-
/** Call platform integration endpoints, billed to owner */
|
|
384
|
-
integrations: {
|
|
385
|
-
call(endpoint: string, params: Record<string, unknown>): Promise<any>;
|
|
386
|
-
};
|
|
387
|
-
/** App owner's user ID */
|
|
388
|
-
ownerUserId: string;
|
|
389
|
-
}
|
|
390
|
-
/** Environment bindings needed by buildCronContext */
|
|
391
|
-
interface CronEnv {
|
|
392
|
-
RECORD_ROOMS: DurableObjectNamespace;
|
|
393
|
-
INTERNAL_STORAGE_HMAC_SECRET?: string;
|
|
394
|
-
/** Override API base URL for local dev or custom platform deployments. */
|
|
395
|
-
API_BASE_URL?: string;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Build a CronContext from worker environment bindings.
|
|
399
|
-
*
|
|
400
|
-
* @param env - Worker environment with RECORD_ROOMS DO namespace and HMAC secret
|
|
401
|
-
* @param ownerUserId - App owner's user ID (for RBAC and billing)
|
|
402
|
-
* @param roomId - RecordRoom ID (defaults to 'default')
|
|
403
|
-
*/
|
|
404
|
-
declare function buildCronContext(env: CronEnv, ownerUserId: string, roomId?: string): CronContext;
|
|
405
|
-
|
|
406
360
|
/**
|
|
407
361
|
* Upstream worker proxy helpers.
|
|
408
362
|
*
|
|
@@ -490,6 +444,61 @@ declare function platformWorkerFetch(env: PlatformWorkerEnv, pathOrRequest: stri
|
|
|
490
444
|
*/
|
|
491
445
|
declare function authWorkerFetch(env: AuthWorkerEnv, path: string, init?: RequestInit): Promise<Response>;
|
|
492
446
|
|
|
447
|
+
/**
|
|
448
|
+
* Cron System — Server-Side Scheduled Tasks
|
|
449
|
+
*
|
|
450
|
+
* Provides CronContext for miniapp cron handlers and buildCronContext
|
|
451
|
+
* to construct it from worker environment bindings.
|
|
452
|
+
*
|
|
453
|
+
* CronContext gives handlers access to:
|
|
454
|
+
* - records: Query/create/update/delete via RecordRoom tools API
|
|
455
|
+
* - integrations: Call platform integration endpoints, billed to the app owner
|
|
456
|
+
* - ownerUserId: The app owner's user ID
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
/** Context passed to cron handler functions */
|
|
460
|
+
interface CronContext {
|
|
461
|
+
/** RecordRoom data access (queries the DO directly via tools API) */
|
|
462
|
+
records: {
|
|
463
|
+
query(collection: string, opts?: {
|
|
464
|
+
where?: Record<string, unknown>;
|
|
465
|
+
limit?: number;
|
|
466
|
+
}): Promise<any[]>;
|
|
467
|
+
create(collection: string, data: Record<string, unknown>): Promise<any>;
|
|
468
|
+
update(collection: string, recordId: string, data: Record<string, unknown>): Promise<any>;
|
|
469
|
+
delete(collection: string, recordId: string): Promise<any>;
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* Call a platform integration endpoint (e.g. "openai/chat-completion",
|
|
473
|
+
* "freepik/text-to-image-classic"). Billed to the app owner — the same
|
|
474
|
+
* APP_OWNER_JWT the rest of the SDK uses for server-side billed calls.
|
|
475
|
+
*/
|
|
476
|
+
integrations: {
|
|
477
|
+
call(endpoint: string, params?: Record<string, unknown>): Promise<any>;
|
|
478
|
+
};
|
|
479
|
+
/** App owner's user ID */
|
|
480
|
+
ownerUserId: string;
|
|
481
|
+
}
|
|
482
|
+
/** Environment bindings needed by buildCronContext */
|
|
483
|
+
interface CronEnv extends ApiWorkerEnv {
|
|
484
|
+
RECORD_ROOMS: DurableObjectNamespace;
|
|
485
|
+
/**
|
|
486
|
+
* Long-lived app-owner JWT minted at deploy time. Required for
|
|
487
|
+
* `integrations.call()` so the call is billed to the app owner.
|
|
488
|
+
* Optional here so apps that don't use integrations from cron can omit
|
|
489
|
+
* it without a type error; missing-at-call-time throws a clear message.
|
|
490
|
+
*/
|
|
491
|
+
APP_OWNER_JWT?: string;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Build a CronContext from worker environment bindings.
|
|
495
|
+
*
|
|
496
|
+
* @param env - Worker environment with RECORD_ROOMS DO namespace, APP_OWNER_JWT, and an api-worker transport (API_WORKER binding or API_WORKER_URL)
|
|
497
|
+
* @param ownerUserId - App owner's user ID (for RBAC and billing)
|
|
498
|
+
* @param roomId - RecordRoom ID (defaults to 'default')
|
|
499
|
+
*/
|
|
500
|
+
declare function buildCronContext(env: CronEnv, ownerUserId: string, roomId?: string): CronContext;
|
|
501
|
+
|
|
493
502
|
/**
|
|
494
503
|
* AI provider helpers — create Vercel AI SDK providers that route through
|
|
495
504
|
* the DeepSpace API worker proxy for per-user billing.
|
|
@@ -1034,6 +1043,7 @@ declare const MSG: {
|
|
|
1034
1043
|
readonly USER_LIST: "user.list";
|
|
1035
1044
|
readonly SET_ROLE: "user.set_role";
|
|
1036
1045
|
readonly USER_UPDATE: "user.update";
|
|
1046
|
+
readonly AUTH: "auth";
|
|
1037
1047
|
readonly YJS_JOIN: "yjs.join";
|
|
1038
1048
|
readonly YJS_LEAVE: "yjs.leave";
|
|
1039
1049
|
readonly ACK: "records.ack";
|
|
@@ -1188,6 +1198,8 @@ type ServerMessage = BaseMessage<typeof MSG.QUERY_RESULT, {
|
|
|
1188
1198
|
error: string;
|
|
1189
1199
|
}> | BaseMessage<typeof MSG.RESUBSCRIBE, EmptyPayload> | BaseMessage<typeof MSG.LIST_SCHEMAS, {
|
|
1190
1200
|
schemas: unknown;
|
|
1201
|
+
}> | BaseMessage<typeof MSG.AUTH, {
|
|
1202
|
+
canWrite: boolean;
|
|
1191
1203
|
}> | BaseMessage<typeof MSG.USER_INFO, unknown> | BaseMessage<typeof MSG.USER_LIST, {
|
|
1192
1204
|
users: unknown[];
|
|
1193
1205
|
}> | BaseMessage<typeof MSG.YJS_JOIN, {
|
|
@@ -1766,6 +1778,8 @@ interface GameInput {
|
|
|
1766
1778
|
}
|
|
1767
1779
|
interface GameAttachment extends UserAttachment {
|
|
1768
1780
|
joinedAt: string;
|
|
1781
|
+
/** True for member/admin roles; false for viewers, unauthenticated anon, spectators. */
|
|
1782
|
+
canWrite: boolean;
|
|
1769
1783
|
}
|
|
1770
1784
|
declare abstract class GameRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1771
1785
|
private config;
|
|
@@ -1863,6 +1877,8 @@ interface Viewport {
|
|
|
1863
1877
|
}
|
|
1864
1878
|
interface CanvasAttachment extends UserAttachment {
|
|
1865
1879
|
viewport: Viewport | null;
|
|
1880
|
+
/** True for member/admin roles; false for viewers and unauthenticated anon. */
|
|
1881
|
+
canWrite: boolean;
|
|
1866
1882
|
}
|
|
1867
1883
|
declare class CanvasRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1868
1884
|
private doc;
|
|
@@ -1975,13 +1991,17 @@ interface CronExecution {
|
|
|
1975
1991
|
durationMs: number;
|
|
1976
1992
|
error?: string;
|
|
1977
1993
|
}
|
|
1994
|
+
interface CronAttachment extends UserAttachment {
|
|
1995
|
+
/** True for member/admin roles; false for viewers and unauthenticated anon. */
|
|
1996
|
+
canWrite: boolean;
|
|
1997
|
+
}
|
|
1978
1998
|
declare abstract class CronRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1979
1999
|
private tasks;
|
|
1980
2000
|
private initialized;
|
|
1981
2001
|
constructor(state: DurableObjectState, env: unknown, config: CronRoomConfig);
|
|
1982
2002
|
private ensureInitialized;
|
|
1983
2003
|
fetch(request: Request): Promise<Response>;
|
|
1984
|
-
protected onConnect(ws: WebSocket, user: UserAttachment):
|
|
2004
|
+
protected onConnect(ws: WebSocket, user: UserAttachment): CronAttachment;
|
|
1985
2005
|
protected onMessage(ws: WebSocket, user: UserAttachment, message: {
|
|
1986
2006
|
type: string;
|
|
1987
2007
|
[key: string]: unknown;
|
|
@@ -2300,7 +2320,7 @@ declare const ALLOWED_BINDING_TYPES: Set<string>;
|
|
|
2300
2320
|
*
|
|
2301
2321
|
* Includes:
|
|
2302
2322
|
* - Static-asset + service bindings the platform sets up automatically.
|
|
2303
|
-
* - SDK-managed env (auth, identity, owner JWT
|
|
2323
|
+
* - SDK-managed env (auth, identity, owner JWT).
|
|
2304
2324
|
* - The auto-attached cost-tracking AE dataset (`USAGE_EVENTS`).
|
|
2305
2325
|
*
|
|
2306
2326
|
* DO binding names (RECORD_ROOMS, YJS_ROOMS, etc.) are NOT in this set
|
|
@@ -2922,22 +2942,6 @@ interface VerifyOutcome {
|
|
|
2922
2942
|
debug?: TokenDebugInfo;
|
|
2923
2943
|
error?: unknown;
|
|
2924
2944
|
}
|
|
2925
|
-
interface InternalSignature {
|
|
2926
|
-
timestamp: string;
|
|
2927
|
-
signature: string;
|
|
2928
|
-
}
|
|
2929
|
-
interface VerifyInternalSignatureInput {
|
|
2930
|
-
secret: string | undefined;
|
|
2931
|
-
timestamp: string | null | undefined;
|
|
2932
|
-
signature: string | null | undefined;
|
|
2933
|
-
payload: string;
|
|
2934
|
-
maxSkewMs?: number;
|
|
2935
|
-
}
|
|
2936
|
-
interface SignInternalPayloadInput {
|
|
2937
|
-
secret: string;
|
|
2938
|
-
payload: string;
|
|
2939
|
-
timestamp?: string;
|
|
2940
|
-
}
|
|
2941
2945
|
|
|
2942
2946
|
/**
|
|
2943
2947
|
* JWT verification for DeepSpace workers.
|
|
@@ -2958,17 +2962,12 @@ interface SignInternalPayloadInput {
|
|
|
2958
2962
|
declare function verifyJwt(config: JwtVerifierConfig, token: string | null | undefined): Promise<VerifyOutcome>;
|
|
2959
2963
|
|
|
2960
2964
|
/**
|
|
2961
|
-
* HMAC
|
|
2962
|
-
*
|
|
2963
|
-
*
|
|
2965
|
+
* HMAC primitives used by the per-app identity tokens (APP_IDENTITY_TOKEN)
|
|
2966
|
+
* minted at deploy time and verified on every /internal/* call into the
|
|
2967
|
+
* platform worker. Auth-provider-agnostic.
|
|
2964
2968
|
*/
|
|
2965
|
-
|
|
2966
|
-
declare const DEFAULT_MAX_SKEW_MS: number;
|
|
2967
2969
|
declare function computeHmacHex(secret: string, payload: string): Promise<string>;
|
|
2968
2970
|
declare function timingSafeEqualHex(a: string, b: string): Promise<boolean>;
|
|
2969
|
-
declare function signInternalPayload({ secret, payload, timestamp, }: SignInternalPayloadInput): Promise<InternalSignature>;
|
|
2970
|
-
declare function verifyInternalSignature({ secret, timestamp, signature, payload, maxSkewMs, }: VerifyInternalSignatureInput): Promise<boolean>;
|
|
2971
|
-
declare function buildInternalPayload(body: unknown): string;
|
|
2972
2971
|
|
|
2973
2972
|
declare function decodeJwtPayload(token: string | null | undefined): TokenDebugInfo | undefined;
|
|
2974
2973
|
|
|
@@ -3972,4 +3971,4 @@ declare class RefundError extends Error {
|
|
|
3972
3971
|
constructor(message: string, status: number);
|
|
3973
3972
|
}
|
|
3974
3973
|
|
|
3975
|
-
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, BASE_USERS_SCHEMA, BUILT_IN_TOOLS, BaseRoom, CHANNELS_SCHEMA, CHANNEL_INVITATIONS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, CONVERSATION_SCHEMAS, COST_RATES, CancelSubscriptionError, type CancelSubscriptionOpts, type CancelSubscriptionResult, CanvasRoom, type CanvasShape, type ChatContextConfig, type ChatMessageRow, type ChatRow, type ChatTurn, type CollectionPermissionSummary, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, 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,
|
|
3974
|
+
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, BASE_USERS_SCHEMA, BUILT_IN_TOOLS, BaseRoom, CHANNELS_SCHEMA, CHANNEL_INVITATIONS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, CONVERSATION_SCHEMAS, COST_RATES, CancelSubscriptionError, type CancelSubscriptionOpts, type CancelSubscriptionResult, CanvasRoom, type CanvasShape, type ChatContextConfig, type ChatMessageRow, type ChatRow, type ChatTurn, type CollectionPermissionSummary, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, 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 DebugApiContext, 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 Job, type JobContext, JobRoom, type JobRoomConfig, type JobStatus, type JwtClaims, type JwtVerifierConfig, MESSAGES_SCHEMA, type MutateActionData, type PermissionAnalysis, type PermissionContext, type PermissionLevel, type PermissionSource, type PlanInfo, type PlatformWorkerEnv, type Player, type PrefixResult, type PresencePeer, PresenceRoom, type QueryActionData, REACTIONS_SCHEMA, READ_RECEIPTS_SCHEMA, RESERVED_BINDING_NAMES, RESERVED_COLLECTION_NAMES, type RecordContext, RecordRoom, type RecordRoomConfig, RefundError, type RefundOpts, type RefundResult, type ResolvedColumn, type ResolvedPermission, type RolePermissions, type RunMigrationsResult, SYSTEM_COLLECTION_SCHEMAS, SYSTEM_MANAGED_COLUMNS, SchemaRegistry, type ScopeContext, type ScopedR2Auth, type ScopedR2Config, type ScopedR2Handler, type ScreenshotEnv, type ScreenshotOptions, type ScreenshotResult, type SharedConnection, type StoredRecord, SubscriptionAuthError, type SubscriptionContext, type SubscriptionRead, SubscriptionRequiredError, type SubscriptionStatus, type Summarizer, type TokenDebugInfo, type ToolResult, type ToolSchema, type ToolsApiContext, USERS_COLUMNS, type User, type UserAttachment, type UserContext, VOTING_SCHEMAS, type ValidationError, type VerifiedAuth, type VerifyOutcome, type VerifyResult, type Viewport, WORKSPACE_SCHEMAS, type YjsContext, YjsRoom, analyzePermissions, apiWorkerFetch, appendMessage, applySlidingWindow, authWorkerFetch, bindingManifestFromOutputConfig, broadcastChange, broadcastYjsUpdate, buildCronContext, buildTableSelect, buildUiParts, canCreate, canDelete, canRead, canUpdate, cancelSubscription, capToolResultSize, captureScreenshot, checkFieldPermissions, coerceValue, collectionTableName, columnId, computeDoMigration, computeHmacHex, createChat, createDeepSpaceAI, createDeepSpaceAuth, createScopedR2Handler, dataToColumnValues, decodeJwtPayload, deleteChatCascade, deleteRecord, enqueueJob, executeQuery, getAllUsers, getChat, getGlobalDOSchemas, getGlobalDOType, getOrCreateYjsDoc, getRecord, getRolePermissions, getSubscription, getUser, getYjsDocKey, handleApiRequest, handleDelete, handlePut, handleSetRole, handleSubscribe, handleToolsRequest, handleUnsubscribe, handleUserList, handleUserUpdate, handleYjsBinaryMessage, handleYjsJoin, handleYjsLeave, isAutoProvision, isOwner, lintSchema, loadMessages, makeDefaultSummarizer, meterAi, meterUsage, meterVectorize, noopPermissionContext, platformWorkerFetch, prepareMessagesWithCompaction, priceBindingUsageEvent, putRecord, readRecord, recordMatchesSubscription, refundInvoice, registerUser, requireSubscription, resolveAppName, resolveColumn, rowToData, runMigrations, saveYjsDoc, timingSafeEqualHex, totalChars, truncateOldToolResults, turnsToCoreMessages, unwrapToolOutput, updateChat, validateAppName, validateBindingManifest, validateDoManifest, verifyJwt, workspaceAccountsSchema, workspaceContentSharesSchema, workspaceEmailHandlesSchema, workspaceFormResponsesSchema, workspacePeopleSchema, workspaceProjectsSchema, workspaceTagsSchema, workspaceTasksSchema, workspaceTeamMembersSchema, workspaceTeamsSchema, workspaceTransactionsSchema };
|