deepspace 0.3.10 → 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 +331 -115
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +199 -16
- package/dist/index.js +354 -166
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +242 -73
- package/dist/server.js +985 -374
- package/dist/server.js.map +1 -1
- package/dist/worker.d.ts +322 -73
- package/dist/worker.js +961 -343
- package/dist/worker.js.map +1 -1
- package/features/admin-page/feature.json +29 -0
- package/features/admin-page/src/AdminPage.tsx +292 -0
- package/features/admin-page/src/admin-schema.ts +20 -0
- package/features/ai-chat/feature.json +41 -0
- package/features/ai-chat/src/AiChatPage.tsx +692 -0
- package/features/ai-chat/src/ChatPanel.tsx +1098 -0
- package/features/ai-chat/src/ai-chat-schema.ts +11 -0
- package/features/canvas/feature.json +45 -0
- package/features/canvas/src/CanvasEditorPage.tsx +87 -0
- package/features/canvas/src/CanvasListPage.tsx +202 -0
- package/features/canvas/src/canvas-schema.ts +33 -0
- package/features/canvas/src/components/CanvasToolbar.tsx +170 -0
- package/features/canvas/src/components/CanvasView.tsx +369 -0
- package/features/canvas/src/components/ShapeRenderer.tsx +114 -0
- package/features/cron/feature.json +33 -0
- package/features/cron/src/CronLogPage.tsx +100 -0
- package/features/cron/src/cron.ts +25 -0
- package/features/docs/feature.json +96 -0
- package/features/docs/src/DocsEditorPage.tsx +1012 -0
- package/features/docs/src/DocsListPage.tsx +951 -0
- package/features/docs/src/DocsOutlinePanel.tsx +68 -0
- package/features/docs/src/DocsPresence.tsx +138 -0
- package/features/docs/src/InviteDialog.tsx +336 -0
- package/features/docs/src/LibrarySidebar.tsx +464 -0
- package/features/docs/src/docs-favorites.ts +18 -0
- package/features/docs/src/docs-library-types.ts +15 -0
- package/features/docs/src/docs-schema.ts +80 -0
- package/features/docs/src/docs-ui.css +309 -0
- package/features/docs/src/editor/DocEditorSurface.tsx +257 -0
- package/features/docs/src/editor/DocsTiptapToolbar.tsx +560 -0
- package/features/docs/src/editor/useDocEditor.ts +206 -0
- package/features/docs/src/use-yjs-room-with-awareness.ts +285 -0
- package/features/file-attachments/feature.json +42 -0
- package/features/file-attachments/src/AttachmentsPage.tsx +864 -0
- package/features/file-attachments/src/attachments-constants.ts +9 -0
- package/features/file-attachments/src/attachments-schema.ts +45 -0
- package/features/file-attachments/src/useFilePreview.ts +471 -0
- package/features/file-attachments/src/useMimeTypeDetection.ts +138 -0
- package/features/file-manager/feature.json +24 -0
- package/features/file-manager/src/FileManagerPage.tsx +330 -0
- package/features/integration-test/feature.json +18 -0
- package/features/integration-test/src/IntegrationTestPage.tsx +423 -0
- package/features/integration-test/src/integration.spec.ts +42 -0
- package/features/items/feature.json +33 -0
- package/features/items/src/ItemsPage.tsx +325 -0
- package/features/items/src/items-constants.ts +10 -0
- package/features/items/src/items-schema.ts +27 -0
- package/features/kanban/feature.json +18 -0
- package/features/kanban/src/Kanban.tsx +283 -0
- package/features/landing/feature.json +62 -0
- package/features/landing/src/LandingPage.tsx +627 -0
- package/features/landing/src/primitives.tsx +389 -0
- package/features/landing/src/sections/FAQSection.tsx +110 -0
- package/features/landing/src/sections/FeaturesGridSection.tsx +311 -0
- package/features/landing/src/sections/HowItWorksSection.tsx +62 -0
- package/features/landing/src/sections/LogoCloudSection.tsx +58 -0
- package/features/landing/src/sections/ShowcaseSection.tsx +63 -0
- package/features/landing/src/sections/StatsSection.tsx +31 -0
- package/features/landing/src/sections/TeamSection.tsx +86 -0
- package/features/landing/src/sections/TestimonialsSection.tsx +68 -0
- package/features/landing/src/sections/VideoSection.tsx +71 -0
- package/features/leaderboard/feature.json +33 -0
- package/features/leaderboard/src/LeaderboardPage.tsx +372 -0
- package/features/leaderboard/src/leaderboard-constants.ts +21 -0
- package/features/leaderboard/src/leaderboard-schema.ts +36 -0
- package/features/messaging/feature.json +111 -0
- package/features/messaging/src/ChatMultiPage.tsx +300 -0
- package/features/messaging/src/ChatPage.tsx +75 -0
- package/features/messaging/src/components/chat/ChatHeader.tsx +76 -0
- package/features/messaging/src/components/chat/MessageActionSheet.tsx +168 -0
- package/features/messaging/src/components/chat/MessageInput.tsx +65 -0
- package/features/messaging/src/components/chat/MessageItem.tsx +352 -0
- package/features/messaging/src/components/chat/MessageList.tsx +248 -0
- package/features/messaging/src/components/chat/ReactionPicker.tsx +2 -0
- package/features/messaging/src/components/chat/ThreadPanel.tsx +107 -0
- package/features/messaging/src/components/chat/UserProfilePopover.tsx +158 -0
- package/features/messaging/src/components/chat-multi/AddMemberModal.tsx +188 -0
- package/features/messaging/src/components/chat-multi/BrowseGroupsModal.tsx +163 -0
- package/features/messaging/src/components/chat-multi/ChannelListItem.tsx +147 -0
- package/features/messaging/src/components/chat-multi/ChannelSettingsPanel.tsx +344 -0
- package/features/messaging/src/components/chat-multi/ChannelSidebar.tsx +460 -0
- package/features/messaging/src/components/chat-multi/CreateGroupModal.tsx +190 -0
- package/features/messaging/src/components/chat-multi/InvitationList.tsx +149 -0
- package/features/messaging/src/components/chat-multi/NewMessageModal.tsx +159 -0
- package/features/messaging/src/hooks/useChatChannel.ts +64 -0
- package/features/messaging/src/hooks/useLongPress.ts +74 -0
- package/features/messaging/src/hooks/useMultiChannel.ts +142 -0
- package/features/messaging/src/messaging-schema.ts +25 -0
- package/features/presence-test/feature.json +21 -0
- package/features/presence-test/src/PresenceTestPage.tsx +120 -0
- package/features/sidebar/feature.json +19 -0
- package/features/sidebar/src/AppSidebar.tsx +558 -0
- package/features/tasks/feature.json +33 -0
- package/features/tasks/src/TasksPage.tsx +598 -0
- package/features/tasks/src/tasks-constants.ts +43 -0
- package/features/tasks/src/tasks-schema.ts +56 -0
- package/features/testing/feature.json +49 -0
- package/features/testing/src/TestPage.tsx +145 -0
- package/features/testing/src/cpu-burn-action.ts +51 -0
- package/features/testing/src/subrequest-burn-action.ts +53 -0
- package/features/testing/src/test-schema.ts +23 -0
- package/features/topbar/feature.json +18 -0
- package/features/topbar/src/Topbar.tsx +353 -0
- package/features/tree/feature.json +26 -0
- package/features/tree/src/TreeSidebar.tsx +607 -0
- package/features/tree/src/tree-constants.ts +68 -0
- package/features/tree/src/tree-hooks.ts +258 -0
- package/package.json +4 -2
- package/scripts/add-feature.cjs +654 -0
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";
|
|
@@ -65,6 +66,10 @@ declare const MSG: {
|
|
|
65
66
|
readonly CRON_PAUSE: "cron.pause";
|
|
66
67
|
readonly CRON_RESUME: "cron.resume";
|
|
67
68
|
readonly CRON_STATUS: "cron.status";
|
|
69
|
+
readonly JOB_ENQUEUE: "job.enqueue";
|
|
70
|
+
readonly JOB_CANCEL: "job.cancel";
|
|
71
|
+
readonly JOB_RETRY: "job.retry";
|
|
72
|
+
readonly JOB_UPDATE: "job.update";
|
|
68
73
|
readonly PRESENCE_SYNC: "presence.sync";
|
|
69
74
|
readonly PRESENCE_JOIN: "presence.join";
|
|
70
75
|
readonly PRESENCE_LEAVE: "presence.leave";
|
|
@@ -231,6 +236,15 @@ type ClientMessage = BaseMessage<typeof MSG.SUBSCRIBE, {
|
|
|
231
236
|
taskName: string;
|
|
232
237
|
}> | BaseMessage<typeof MSG.CRON_RESUME, {
|
|
233
238
|
taskName: string;
|
|
239
|
+
}> | BaseMessage<typeof MSG.JOB_ENQUEUE, {
|
|
240
|
+
requestId: string;
|
|
241
|
+
type: string;
|
|
242
|
+
payload?: unknown;
|
|
243
|
+
maxAttempts?: number;
|
|
244
|
+
}> | BaseMessage<typeof MSG.JOB_CANCEL, {
|
|
245
|
+
jobId: string;
|
|
246
|
+
}> | BaseMessage<typeof MSG.JOB_RETRY, {
|
|
247
|
+
jobId: string;
|
|
234
248
|
}> | BaseMessage<typeof MSG.PRESENCE_UPDATE, Record<string, unknown>> | BaseMessage<typeof MSG.GW_SCOPE_CONNECT, {
|
|
235
249
|
scopeType: string;
|
|
236
250
|
scopeId: string;
|
|
@@ -267,6 +281,8 @@ type ServerMessage = BaseMessage<typeof MSG.QUERY_RESULT, {
|
|
|
267
281
|
error: string;
|
|
268
282
|
}> | BaseMessage<typeof MSG.RESUBSCRIBE, EmptyPayload> | BaseMessage<typeof MSG.LIST_SCHEMAS, {
|
|
269
283
|
schemas: unknown;
|
|
284
|
+
}> | BaseMessage<typeof MSG.AUTH, {
|
|
285
|
+
canWrite: boolean;
|
|
270
286
|
}> | BaseMessage<typeof MSG.USER_INFO, unknown> | BaseMessage<typeof MSG.USER_LIST, {
|
|
271
287
|
users: unknown[];
|
|
272
288
|
}> | BaseMessage<typeof MSG.YJS_JOIN, {
|
|
@@ -326,6 +342,12 @@ type ServerMessage = BaseMessage<typeof MSG.QUERY_RESULT, {
|
|
|
326
342
|
}> | BaseMessage<typeof MSG.CRON_STATUS, {
|
|
327
343
|
tasks: unknown;
|
|
328
344
|
recentHistory: unknown;
|
|
345
|
+
}> | BaseMessage<typeof MSG.JOB_UPDATE, {
|
|
346
|
+
kind: 'snapshot' | 'enqueued' | 'progress' | 'succeeded' | 'failed' | 'canceled' | 'retried';
|
|
347
|
+
job?: unknown;
|
|
348
|
+
jobs?: unknown[];
|
|
349
|
+
/** Echoes the enqueue requestId when the update is the enqueue ack. */
|
|
350
|
+
requestId?: string;
|
|
329
351
|
}> | BaseMessage<typeof MSG.PRESENCE_SYNC, {
|
|
330
352
|
peers: unknown[];
|
|
331
353
|
}> | BaseMessage<typeof MSG.PRESENCE_JOIN, {
|
|
@@ -497,6 +519,27 @@ declare const clientBuild: {
|
|
|
497
519
|
readonly taskName: string;
|
|
498
520
|
};
|
|
499
521
|
};
|
|
522
|
+
jobEnqueue: (requestId: string, type: string, payload?: unknown, maxAttempts?: number) => {
|
|
523
|
+
readonly type: "job.enqueue";
|
|
524
|
+
readonly payload: {
|
|
525
|
+
readonly requestId: string;
|
|
526
|
+
readonly type: string;
|
|
527
|
+
readonly payload: unknown;
|
|
528
|
+
readonly maxAttempts: number | undefined;
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
jobCancel: (jobId: string) => {
|
|
532
|
+
readonly type: "job.cancel";
|
|
533
|
+
readonly payload: {
|
|
534
|
+
readonly jobId: string;
|
|
535
|
+
};
|
|
536
|
+
};
|
|
537
|
+
jobRetry: (jobId: string) => {
|
|
538
|
+
readonly type: "job.retry";
|
|
539
|
+
readonly payload: {
|
|
540
|
+
readonly jobId: string;
|
|
541
|
+
};
|
|
542
|
+
};
|
|
500
543
|
presenceUpdate: (state: Record<string, unknown>) => {
|
|
501
544
|
readonly type: "presence.update";
|
|
502
545
|
readonly payload: Record<string, unknown>;
|
|
@@ -719,6 +762,56 @@ declare const serverBuild: {
|
|
|
719
762
|
readonly recentHistory: unknown;
|
|
720
763
|
};
|
|
721
764
|
};
|
|
765
|
+
jobSnapshot: (jobs: unknown[]) => {
|
|
766
|
+
readonly type: "job.update";
|
|
767
|
+
readonly payload: {
|
|
768
|
+
readonly kind: "snapshot";
|
|
769
|
+
readonly jobs: unknown[];
|
|
770
|
+
};
|
|
771
|
+
};
|
|
772
|
+
jobEnqueued: (job: unknown, requestId?: string) => {
|
|
773
|
+
readonly type: "job.update";
|
|
774
|
+
readonly payload: {
|
|
775
|
+
readonly kind: "enqueued";
|
|
776
|
+
readonly job: unknown;
|
|
777
|
+
readonly requestId: string | undefined;
|
|
778
|
+
};
|
|
779
|
+
};
|
|
780
|
+
jobProgress: (job: unknown) => {
|
|
781
|
+
readonly type: "job.update";
|
|
782
|
+
readonly payload: {
|
|
783
|
+
readonly kind: "progress";
|
|
784
|
+
readonly job: unknown;
|
|
785
|
+
};
|
|
786
|
+
};
|
|
787
|
+
jobSucceeded: (job: unknown) => {
|
|
788
|
+
readonly type: "job.update";
|
|
789
|
+
readonly payload: {
|
|
790
|
+
readonly kind: "succeeded";
|
|
791
|
+
readonly job: unknown;
|
|
792
|
+
};
|
|
793
|
+
};
|
|
794
|
+
jobFailed: (job: unknown) => {
|
|
795
|
+
readonly type: "job.update";
|
|
796
|
+
readonly payload: {
|
|
797
|
+
readonly kind: "failed";
|
|
798
|
+
readonly job: unknown;
|
|
799
|
+
};
|
|
800
|
+
};
|
|
801
|
+
jobCanceled: (job: unknown) => {
|
|
802
|
+
readonly type: "job.update";
|
|
803
|
+
readonly payload: {
|
|
804
|
+
readonly kind: "canceled";
|
|
805
|
+
readonly job: unknown;
|
|
806
|
+
};
|
|
807
|
+
};
|
|
808
|
+
jobRetried: (job: unknown) => {
|
|
809
|
+
readonly type: "job.update";
|
|
810
|
+
readonly payload: {
|
|
811
|
+
readonly kind: "retried";
|
|
812
|
+
readonly job: unknown;
|
|
813
|
+
};
|
|
814
|
+
};
|
|
722
815
|
presenceSync: (peers: unknown[]) => {
|
|
723
816
|
readonly type: "presence.sync";
|
|
724
817
|
readonly payload: {
|
|
@@ -1413,6 +1506,8 @@ interface GameInput {
|
|
|
1413
1506
|
}
|
|
1414
1507
|
interface GameAttachment extends UserAttachment {
|
|
1415
1508
|
joinedAt: string;
|
|
1509
|
+
/** True for member/admin roles; false for viewers, unauthenticated anon, spectators. */
|
|
1510
|
+
canWrite: boolean;
|
|
1416
1511
|
}
|
|
1417
1512
|
declare abstract class GameRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1418
1513
|
private config;
|
|
@@ -1510,6 +1605,8 @@ interface Viewport {
|
|
|
1510
1605
|
}
|
|
1511
1606
|
interface CanvasAttachment extends UserAttachment {
|
|
1512
1607
|
viewport: Viewport | null;
|
|
1608
|
+
/** True for member/admin roles; false for viewers and unauthenticated anon. */
|
|
1609
|
+
canWrite: boolean;
|
|
1513
1610
|
}
|
|
1514
1611
|
declare class CanvasRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1515
1612
|
private doc;
|
|
@@ -1622,13 +1719,17 @@ interface CronExecution {
|
|
|
1622
1719
|
durationMs: number;
|
|
1623
1720
|
error?: string;
|
|
1624
1721
|
}
|
|
1722
|
+
interface CronAttachment extends UserAttachment {
|
|
1723
|
+
/** True for member/admin roles; false for viewers and unauthenticated anon. */
|
|
1724
|
+
canWrite: boolean;
|
|
1725
|
+
}
|
|
1625
1726
|
declare abstract class CronRoom<E = Record<string, unknown>> extends BaseRoom<E> {
|
|
1626
1727
|
private tasks;
|
|
1627
1728
|
private initialized;
|
|
1628
1729
|
constructor(state: DurableObjectState, env: unknown, config: CronRoomConfig);
|
|
1629
1730
|
private ensureInitialized;
|
|
1630
1731
|
fetch(request: Request): Promise<Response>;
|
|
1631
|
-
protected onConnect(ws: WebSocket, user: UserAttachment):
|
|
1732
|
+
protected onConnect(ws: WebSocket, user: UserAttachment): CronAttachment;
|
|
1632
1733
|
protected onMessage(ws: WebSocket, user: UserAttachment, message: {
|
|
1633
1734
|
type: string;
|
|
1634
1735
|
[key: string]: unknown;
|
|
@@ -1646,6 +1747,166 @@ declare abstract class CronRoom<E = Record<string, unknown>> extends BaseRoom<E>
|
|
|
1646
1747
|
protected abstract onTask(taskName: string): void | Promise<void>;
|
|
1647
1748
|
}
|
|
1648
1749
|
|
|
1750
|
+
/**
|
|
1751
|
+
* JobRoom — Per-app durable background-job execution Durable Object.
|
|
1752
|
+
*
|
|
1753
|
+
* Solves the "long job dies when the response goes out" problem on
|
|
1754
|
+
* Cloudflare Workers. `ctx.waitUntil` only gets 30s after a response;
|
|
1755
|
+
* jobs that need minutes-to-hours live here instead: rows in SQLite,
|
|
1756
|
+
* picked up by DO alarms (15-min wall budget per tick), resumable
|
|
1757
|
+
* across ticks via `ctx.continue` for the rare longer cases.
|
|
1758
|
+
*
|
|
1759
|
+
* Lifecycle: queued → running → succeeded | failed | canceled
|
|
1760
|
+
*
|
|
1761
|
+
* Crash recovery: if an isolate is recycled mid-run, the row stays at
|
|
1762
|
+
* `running`. On next init, rows older than ~16 min are either retried
|
|
1763
|
+
* (if attempts left) or marked failed.
|
|
1764
|
+
*
|
|
1765
|
+
* See the abstract `onJob` method below for the subclass contract.
|
|
1766
|
+
* Message types: job.*
|
|
1767
|
+
*/
|
|
1768
|
+
|
|
1769
|
+
type JobStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'canceled';
|
|
1770
|
+
/**
|
|
1771
|
+
* Job record exposed to `onJob` handlers and clients. Payloads are typed
|
|
1772
|
+
* as `unknown` at the SDK layer; subclasses narrow via a generic param.
|
|
1773
|
+
*/
|
|
1774
|
+
interface Job<P = unknown> {
|
|
1775
|
+
id: string;
|
|
1776
|
+
type: string;
|
|
1777
|
+
status: JobStatus;
|
|
1778
|
+
payload: P;
|
|
1779
|
+
result?: unknown;
|
|
1780
|
+
error?: string;
|
|
1781
|
+
progress?: number;
|
|
1782
|
+
progressMessage?: string;
|
|
1783
|
+
attempts: number;
|
|
1784
|
+
maxAttempts: number;
|
|
1785
|
+
enqueuedAt: string;
|
|
1786
|
+
startedAt?: string | null;
|
|
1787
|
+
completedAt?: string | null;
|
|
1788
|
+
enqueuedBy?: string | null;
|
|
1789
|
+
/** Set when a previous run called `ctx.continue(state)`. */
|
|
1790
|
+
resumeFrom?: unknown;
|
|
1791
|
+
}
|
|
1792
|
+
interface JobContext {
|
|
1793
|
+
/** Set progress (0..1) with an optional message. Broadcasts. */
|
|
1794
|
+
progress(value: number, message?: string): void;
|
|
1795
|
+
/**
|
|
1796
|
+
* Save a resumable checkpoint and re-run `onJob` on the next alarm
|
|
1797
|
+
* with `job.resumeFrom = state`. The return value of `onJob` is
|
|
1798
|
+
* ignored once `continue` has been called.
|
|
1799
|
+
*/
|
|
1800
|
+
continue(state: unknown, options?: {
|
|
1801
|
+
afterMs?: number;
|
|
1802
|
+
}): void;
|
|
1803
|
+
/**
|
|
1804
|
+
* Fires when a JOB_CANCEL arrives while this job is running in this
|
|
1805
|
+
* isolate. Cross-isolate cancels still mark the row `canceled` but
|
|
1806
|
+
* can't fire this signal.
|
|
1807
|
+
*/
|
|
1808
|
+
signal: AbortSignal;
|
|
1809
|
+
}
|
|
1810
|
+
interface JobRoomConfig {
|
|
1811
|
+
/** Default for jobs enqueued without explicit `maxAttempts`. Default 1 (no auto-retry). */
|
|
1812
|
+
defaultMaxAttempts?: number;
|
|
1813
|
+
/** TTL for terminal rows (succeeded/failed/canceled) in ms. Default 24h. */
|
|
1814
|
+
retentionMs?: number;
|
|
1815
|
+
/** Job count in the initial snapshot to a new subscriber. Default 100. */
|
|
1816
|
+
snapshotLimit?: number;
|
|
1817
|
+
/** Delay before a failed attempt is retried, in ms. Default 1000. */
|
|
1818
|
+
retryBackoffMs?: number;
|
|
1819
|
+
}
|
|
1820
|
+
declare abstract class JobRoom<E = Record<string, unknown>, P = unknown, R = unknown> extends BaseRoom<E> {
|
|
1821
|
+
private initialized;
|
|
1822
|
+
private readonly defaultMaxAttempts;
|
|
1823
|
+
private readonly retentionMs;
|
|
1824
|
+
private readonly snapshotLimit;
|
|
1825
|
+
private readonly retryBackoffMs;
|
|
1826
|
+
/** In-flight jobs in this isolate; lets same-isolate JOB_CANCEL fire the signal. */
|
|
1827
|
+
private readonly inFlight;
|
|
1828
|
+
/** Set by `ctx.continue` inside `executeJob`; reset before every run. */
|
|
1829
|
+
private continueState;
|
|
1830
|
+
constructor(state: DurableObjectState, env: unknown, config?: JobRoomConfig);
|
|
1831
|
+
private ensureInitialized;
|
|
1832
|
+
fetch(request: Request): Promise<Response>;
|
|
1833
|
+
protected onConnect(ws: WebSocket, user: UserAttachment): UserAttachment;
|
|
1834
|
+
protected onMessage(ws: WebSocket, user: UserAttachment, message: {
|
|
1835
|
+
type: string;
|
|
1836
|
+
[key: string]: unknown;
|
|
1837
|
+
}): Promise<void>;
|
|
1838
|
+
protected onAlarm(): Promise<void>;
|
|
1839
|
+
/**
|
|
1840
|
+
* One internal endpoint, `POST /enqueue`, used by the `enqueueJob`
|
|
1841
|
+
* helper at the bottom of this file. The room is not meant to be
|
|
1842
|
+
* reachable from the public internet; callers route through the app
|
|
1843
|
+
* worker (or call `this.enqueue(...)` directly from a subclass).
|
|
1844
|
+
*
|
|
1845
|
+
* Subclasses overriding `onRequest` should call `super.onRequest(req)`
|
|
1846
|
+
* for paths they don't handle.
|
|
1847
|
+
*/
|
|
1848
|
+
protected onRequest(request: Request): Promise<Response>;
|
|
1849
|
+
/**
|
|
1850
|
+
* Synchronously persist a new job and arm the alarm. Returns the new
|
|
1851
|
+
* job. This is the in-isolate path — useful for a subclass `onJob`
|
|
1852
|
+
* that wants to chain follow-up work without paying a fetch hop:
|
|
1853
|
+
*
|
|
1854
|
+
* protected async onJob(job: Job, ctx: JobContext) {
|
|
1855
|
+
* // ... do work ...
|
|
1856
|
+
* if (needsFollowup) this.enqueue('followup', { parent: job.id })
|
|
1857
|
+
* }
|
|
1858
|
+
*
|
|
1859
|
+
* Workers code that lives outside the DO isolate (HTTP routes, cron
|
|
1860
|
+
* tasks, server actions) cannot call this directly — they must go
|
|
1861
|
+
* through the `enqueueJob` helper at the bottom of this file, which
|
|
1862
|
+
* routes via the DO's `/enqueue` HTTP endpoint.
|
|
1863
|
+
*/
|
|
1864
|
+
enqueue(type: string, payload?: unknown, options?: {
|
|
1865
|
+
maxAttempts?: number;
|
|
1866
|
+
enqueuedBy?: string;
|
|
1867
|
+
}): Job;
|
|
1868
|
+
private insertJob;
|
|
1869
|
+
private cancelJob;
|
|
1870
|
+
private retryJob;
|
|
1871
|
+
/**
|
|
1872
|
+
* Drain due jobs in FIFO order. All due jobs share the alarm's
|
|
1873
|
+
* 15-min wall budget (a CF property, not a per-job allocation).
|
|
1874
|
+
*/
|
|
1875
|
+
private drainDueJobs;
|
|
1876
|
+
private executeJob;
|
|
1877
|
+
private makeContext;
|
|
1878
|
+
private readStatus;
|
|
1879
|
+
private scheduleNextAlarm;
|
|
1880
|
+
private recoverStuckRunning;
|
|
1881
|
+
private pruneExpired;
|
|
1882
|
+
private getRecentJobs;
|
|
1883
|
+
private getJobById;
|
|
1884
|
+
/**
|
|
1885
|
+
* Run a single job. Return a value for success; throw for failure
|
|
1886
|
+
* (retried until attempts >= maxAttempts). Use `ctx.progress` for
|
|
1887
|
+
* progress, `ctx.continue(state)` to span multiple alarms, and
|
|
1888
|
+
* `ctx.signal` to honor client cancellations.
|
|
1889
|
+
*/
|
|
1890
|
+
protected abstract onJob(job: Job<P>, ctx: JobContext): Promise<R | void> | R | void;
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Enqueue a job from worker code that has the DO namespace. Routed by
|
|
1894
|
+
* `roomId` (typically `app:<APP_NAME>`; pass different ids for sharded
|
|
1895
|
+
* queues). Returns the new jobId; throws on failure.
|
|
1896
|
+
*
|
|
1897
|
+
* const jobId = await enqueueJob(
|
|
1898
|
+
* env.JOB_ROOMS,
|
|
1899
|
+
* `app:${env.APP_NAME}`,
|
|
1900
|
+
* 'ai-summarize',
|
|
1901
|
+
* { text },
|
|
1902
|
+
* { maxAttempts: 3 },
|
|
1903
|
+
* )
|
|
1904
|
+
*/
|
|
1905
|
+
declare function enqueueJob(namespace: DurableObjectNamespace, roomId: string, type: string, payload?: unknown, options?: {
|
|
1906
|
+
maxAttempts?: number;
|
|
1907
|
+
enqueuedBy?: string;
|
|
1908
|
+
}): Promise<string>;
|
|
1909
|
+
|
|
1649
1910
|
/**
|
|
1650
1911
|
* DO Manifest — Dynamic Durable Object binding declarations.
|
|
1651
1912
|
*
|
|
@@ -1787,7 +2048,7 @@ declare const ALLOWED_BINDING_TYPES: Set<string>;
|
|
|
1787
2048
|
*
|
|
1788
2049
|
* Includes:
|
|
1789
2050
|
* - Static-asset + service bindings the platform sets up automatically.
|
|
1790
|
-
* - SDK-managed env (auth, identity, owner JWT
|
|
2051
|
+
* - SDK-managed env (auth, identity, owner JWT).
|
|
1791
2052
|
* - The auto-attached cost-tracking AE dataset (`USAGE_EVENTS`).
|
|
1792
2053
|
*
|
|
1793
2054
|
* DO binding names (RECORD_ROOMS, YJS_ROOMS, etc.) are NOT in this set
|
|
@@ -2430,52 +2691,6 @@ interface ActionContext<TEnv = Record<string, unknown>> {
|
|
|
2430
2691
|
}
|
|
2431
2692
|
type ActionHandler<TEnv = Record<string, unknown>> = (ctx: ActionContext<TEnv>) => Promise<ActionResult>;
|
|
2432
2693
|
|
|
2433
|
-
/**
|
|
2434
|
-
* Cron System — Server-Side Scheduled Tasks
|
|
2435
|
-
*
|
|
2436
|
-
* Provides CronContext for miniapp cron handlers and buildCronContext
|
|
2437
|
-
* to construct it from worker environment bindings.
|
|
2438
|
-
*
|
|
2439
|
-
* CronContext gives handlers access to:
|
|
2440
|
-
* - records: Query/create/update/delete via RecordRoom tools API
|
|
2441
|
-
* - integrations: Call platform integration endpoints (billed to owner)
|
|
2442
|
-
* - ownerUserId: The app owner's user ID
|
|
2443
|
-
*/
|
|
2444
|
-
/** Context passed to cron handler functions */
|
|
2445
|
-
interface CronContext {
|
|
2446
|
-
/** RecordRoom data access (queries the DO directly via tools API) */
|
|
2447
|
-
records: {
|
|
2448
|
-
query(collection: string, opts?: {
|
|
2449
|
-
where?: Record<string, unknown>;
|
|
2450
|
-
limit?: number;
|
|
2451
|
-
}): Promise<any[]>;
|
|
2452
|
-
create(collection: string, data: Record<string, unknown>): Promise<any>;
|
|
2453
|
-
update(collection: string, recordId: string, data: Record<string, unknown>): Promise<any>;
|
|
2454
|
-
delete(collection: string, recordId: string): Promise<any>;
|
|
2455
|
-
};
|
|
2456
|
-
/** Call platform integration endpoints, billed to owner */
|
|
2457
|
-
integrations: {
|
|
2458
|
-
call(endpoint: string, params: Record<string, unknown>): Promise<any>;
|
|
2459
|
-
};
|
|
2460
|
-
/** App owner's user ID */
|
|
2461
|
-
ownerUserId: string;
|
|
2462
|
-
}
|
|
2463
|
-
/** Environment bindings needed by buildCronContext */
|
|
2464
|
-
interface CronEnv {
|
|
2465
|
-
RECORD_ROOMS: DurableObjectNamespace;
|
|
2466
|
-
INTERNAL_STORAGE_HMAC_SECRET?: string;
|
|
2467
|
-
/** Override API base URL for local dev or custom platform deployments. */
|
|
2468
|
-
API_BASE_URL?: string;
|
|
2469
|
-
}
|
|
2470
|
-
/**
|
|
2471
|
-
* Build a CronContext from worker environment bindings.
|
|
2472
|
-
*
|
|
2473
|
-
* @param env - Worker environment with RECORD_ROOMS DO namespace and HMAC secret
|
|
2474
|
-
* @param ownerUserId - App owner's user ID (for RBAC and billing)
|
|
2475
|
-
* @param roomId - RecordRoom ID (defaults to 'default')
|
|
2476
|
-
*/
|
|
2477
|
-
declare function buildCronContext(env: CronEnv, ownerUserId: string, roomId?: string): CronContext;
|
|
2478
|
-
|
|
2479
2694
|
/**
|
|
2480
2695
|
* Upstream worker proxy helpers.
|
|
2481
2696
|
*
|
|
@@ -2563,6 +2778,61 @@ declare function platformWorkerFetch(env: PlatformWorkerEnv, pathOrRequest: stri
|
|
|
2563
2778
|
*/
|
|
2564
2779
|
declare function authWorkerFetch(env: AuthWorkerEnv, path: string, init?: RequestInit): Promise<Response>;
|
|
2565
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
|
+
|
|
2566
2836
|
/**
|
|
2567
2837
|
* AI provider helpers — create Vercel AI SDK providers that route through
|
|
2568
2838
|
* the DeepSpace API worker proxy for per-user billing.
|
|
@@ -3122,22 +3392,6 @@ interface VerifyOutcome {
|
|
|
3122
3392
|
debug?: TokenDebugInfo;
|
|
3123
3393
|
error?: unknown;
|
|
3124
3394
|
}
|
|
3125
|
-
interface InternalSignature {
|
|
3126
|
-
timestamp: string;
|
|
3127
|
-
signature: string;
|
|
3128
|
-
}
|
|
3129
|
-
interface VerifyInternalSignatureInput {
|
|
3130
|
-
secret: string | undefined;
|
|
3131
|
-
timestamp: string | null | undefined;
|
|
3132
|
-
signature: string | null | undefined;
|
|
3133
|
-
payload: string;
|
|
3134
|
-
maxSkewMs?: number;
|
|
3135
|
-
}
|
|
3136
|
-
interface SignInternalPayloadInput {
|
|
3137
|
-
secret: string;
|
|
3138
|
-
payload: string;
|
|
3139
|
-
timestamp?: string;
|
|
3140
|
-
}
|
|
3141
3395
|
|
|
3142
3396
|
/**
|
|
3143
3397
|
* JWT verification for DeepSpace workers.
|
|
@@ -3158,17 +3412,12 @@ interface SignInternalPayloadInput {
|
|
|
3158
3412
|
declare function verifyJwt(config: JwtVerifierConfig, token: string | null | undefined): Promise<VerifyOutcome>;
|
|
3159
3413
|
|
|
3160
3414
|
/**
|
|
3161
|
-
* HMAC
|
|
3162
|
-
*
|
|
3163
|
-
*
|
|
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.
|
|
3164
3418
|
*/
|
|
3165
|
-
|
|
3166
|
-
declare const DEFAULT_MAX_SKEW_MS: number;
|
|
3167
3419
|
declare function computeHmacHex(secret: string, payload: string): Promise<string>;
|
|
3168
3420
|
declare function timingSafeEqualHex(a: string, b: string): Promise<boolean>;
|
|
3169
|
-
declare function signInternalPayload({ secret, payload, timestamp, }: SignInternalPayloadInput): Promise<InternalSignature>;
|
|
3170
|
-
declare function verifyInternalSignature({ secret, timestamp, signature, payload, maxSkewMs, }: VerifyInternalSignatureInput): Promise<boolean>;
|
|
3171
|
-
declare function buildInternalPayload(body: unknown): string;
|
|
3172
3421
|
|
|
3173
3422
|
declare function decodeJwtPayload(token: string | null | undefined): TokenDebugInfo | undefined;
|
|
3174
3423
|
|
|
@@ -4026,4 +4275,4 @@ type DeepSpaceAuth = ReturnType<typeof createDeepSpaceAuth>;
|
|
|
4026
4275
|
/** Collections that bypass schema checks (permissive access) */
|
|
4027
4276
|
declare const SYSTEM_COLLECTIONS: Set<string>;
|
|
4028
4277
|
|
|
4029
|
-
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 };
|