deepspace 0.10.3 → 0.12.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/CHANGELOG.md +53 -0
- package/dist/cli.js +656 -238
- package/dist/cli.js.map +1 -1
- package/dist/index.js +53 -5
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +29 -1
- package/dist/server.js +27 -2
- package/dist/server.js.map +1 -1
- package/dist/worker.d.ts +29 -1
- package/dist/worker.js +27 -2
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/server.d.ts
CHANGED
|
@@ -152,6 +152,33 @@ declare function applyAiToolDefaults(toolName: string, params: Record<string, un
|
|
|
152
152
|
*/
|
|
153
153
|
declare const BUILT_IN_TOOLS: ToolSchema[];
|
|
154
154
|
|
|
155
|
+
/**
|
|
156
|
+
* App-files limits and failure reading, shared by every caller of the files
|
|
157
|
+
* API: the browser hook (`client/storage/useR2Files.ts`), the CLI
|
|
158
|
+
* (`cli/lib/app-files-api.ts`), and the docs that quote them.
|
|
159
|
+
*
|
|
160
|
+
* The ceiling is not a product decision made here — it is what the transport
|
|
161
|
+
* physically allows. An upload crosses Cloudflare's request-body limit before
|
|
162
|
+
* any worker code runs, and the platform worker then reads the whole body into
|
|
163
|
+
* a ~128 MiB isolate before writing it to R2. So an oversized upload does not
|
|
164
|
+
* fail as a friendly JSON error; it fails as a raw Cloudflare HTML page that
|
|
165
|
+
* every caller here used to feed straight into `JSON.parse` and report as
|
|
166
|
+
* "Unexpected token '<' … is not valid JSON". That is the bug this module
|
|
167
|
+
* exists to make impossible.
|
|
168
|
+
*/
|
|
169
|
+
/**
|
|
170
|
+
* The largest single file the app-files API accepts.
|
|
171
|
+
*
|
|
172
|
+
* Enforced by the shared upload handler (`server/utils/scoped-r2-files.ts`),
|
|
173
|
+
* which is the only place it is a real limit — above it the platform worker
|
|
174
|
+
* risks exhausting its isolate while holding the decoded file and the
|
|
175
|
+
* multipart envelope together. Callers also check it locally, but only so the
|
|
176
|
+
* failure is named early; skipping the client check cannot widen what is
|
|
177
|
+
* accepted. Well above it (~100 MB) Cloudflare rejects the request before the
|
|
178
|
+
* worker runs at all, which is why callers must read failures as text first.
|
|
179
|
+
*/
|
|
180
|
+
declare const MAX_APP_FILE_BYTES: number;
|
|
181
|
+
|
|
155
182
|
/**
|
|
156
183
|
* Shared Scoped R2 Files Handler
|
|
157
184
|
*
|
|
@@ -169,6 +196,7 @@ declare const BUILT_IN_TOOLS: ToolSchema[];
|
|
|
169
196
|
* GET /api/files/:key → download (validated against prefix)
|
|
170
197
|
* DELETE /api/files/:key → delete (validated against prefix)
|
|
171
198
|
*/
|
|
199
|
+
|
|
172
200
|
interface ScopeContext {
|
|
173
201
|
userId: string | null;
|
|
174
202
|
url: URL;
|
|
@@ -4515,4 +4543,4 @@ declare class RefundError extends Error {
|
|
|
4515
4543
|
constructor(message: string, status: number);
|
|
4516
4544
|
}
|
|
4517
4545
|
|
|
4518
|
-
export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, ALLOWED_BINDING_TYPES, APP_ID_RE, 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 ComposioToolsOptions, 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, DEFAULT_QUERY_LIMIT, DEPLOYED_APPS_DEFAULTS, DIRECTORY_SCHEMAS, type DOBindings, type DOManifest, type DOManifestEntry, type DebugApiContext, type DeepSpaceAIEnv, type DeepSpaceAIOptions, type DeepSpaceAgentDiagnosticContext, DeepSpaceAgentModelError, DeepSpaceAgentProfileError, type DeepSpaceAgentStream, type DeepSpaceAgentStreamOptions, 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, REGISTRY_INSTANCE, RESERVED_BINDING_NAMES, RESERVED_COLLECTION_NAMES, RESOURCE_ID_RE, type RecordContext, RecordRoom, type RecordRoomConfig, RefundError, type RefundOpts, type RefundResult, RegistryClientError, type ResolvedColumn, type ResolvedPermission, type RolePermissions, type RunMigrationsResult, STRICT_APP_ID_RE, SYSTEM_COLLECTION_SCHEMAS, SYSTEM_MANAGED_COLUMNS, SchemaRegistry, type ScopeContext, type ScopedR2Auth, type ScopedR2Config, type ScopedR2Handler, type ScreenshotEnv, type ScreenshotResult, type SharedConnection, type StoredRecord, SubscriptionAuthError, type SubscriptionContext, type SubscriptionRead, SubscriptionRequiredError, type SubscriptionStatus, type Summarizer, TEST_ACCOUNT_EMAIL_SUFFIX, 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, applyAiToolDefaults, applySlidingWindow, authWorkerFetch, bindingManifestFromOutputConfig, broadcastChange, broadcastYjsUpdate, buildCronContext, buildTableSelect, buildUiParts, callRegistry, canCreate, canDelete, canRead, canUpdate, cancelSubscription, capToolResultSize, captureScreenshot, checkFieldPermissions, coerceValue, collectionTableName, columnId, composioTools, computeDoMigration, computeHmacHex, createChat, createDeepSpaceAI, createDeepSpaceAuth, createScopedR2Handler, dataToColumnValues, decodeJwtPayload, deepSpaceAgentErrorSummary, 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, isTestAccountClaims, isTestAccountEmail, isTestAccountTier, lintSchema, loadMessages, makeDefaultSummarizer, matchOrigin, meterAi, meterUsage, meterVectorize, noopPermissionContext, parseQuotaLimit, platformCorsPatterns, platformWorkerFetch, prepareMessagesWithCompaction, priceBindingUsageEvent, putRecord, readRecord, recordMatchesSubscription, refundInvoice, registerUser, registryErrorJson, registryStub, requireSubscription, resolveAppName, resolveColumn, rowToData, runMigrations, saveYjsDoc, streamDeepSpaceAgent, timingSafeEqualHex, timingSafeEqualStrings, totalChars, truncateOldToolResults, turnsToCoreMessages, unwrapToolOutput, updateChat, validateAppName, validateBindingManifest, validateDoManifest, verifyJwt, workspaceAccountsSchema, workspaceContentSharesSchema, workspaceEmailHandlesSchema, workspaceFormResponsesSchema, workspacePeopleSchema, workspaceProjectsSchema, workspaceTagsSchema, workspaceTasksSchema, workspaceTeamMembersSchema, workspaceTeamsSchema, workspaceTransactionsSchema };
|
|
4546
|
+
export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, ALLOWED_BINDING_TYPES, APP_ID_RE, 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 ComposioToolsOptions, 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, DEFAULT_QUERY_LIMIT, DEPLOYED_APPS_DEFAULTS, DIRECTORY_SCHEMAS, type DOBindings, type DOManifest, type DOManifestEntry, type DebugApiContext, type DeepSpaceAIEnv, type DeepSpaceAIOptions, type DeepSpaceAgentDiagnosticContext, DeepSpaceAgentModelError, DeepSpaceAgentProfileError, type DeepSpaceAgentStream, type DeepSpaceAgentStreamOptions, 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, MAX_APP_FILE_BYTES, 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, REGISTRY_INSTANCE, RESERVED_BINDING_NAMES, RESERVED_COLLECTION_NAMES, RESOURCE_ID_RE, type RecordContext, RecordRoom, type RecordRoomConfig, RefundError, type RefundOpts, type RefundResult, RegistryClientError, type ResolvedColumn, type ResolvedPermission, type RolePermissions, type RunMigrationsResult, STRICT_APP_ID_RE, SYSTEM_COLLECTION_SCHEMAS, SYSTEM_MANAGED_COLUMNS, SchemaRegistry, type ScopeContext, type ScopedR2Auth, type ScopedR2Config, type ScopedR2Handler, type ScreenshotEnv, type ScreenshotResult, type SharedConnection, type StoredRecord, SubscriptionAuthError, type SubscriptionContext, type SubscriptionRead, SubscriptionRequiredError, type SubscriptionStatus, type Summarizer, TEST_ACCOUNT_EMAIL_SUFFIX, 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, applyAiToolDefaults, applySlidingWindow, authWorkerFetch, bindingManifestFromOutputConfig, broadcastChange, broadcastYjsUpdate, buildCronContext, buildTableSelect, buildUiParts, callRegistry, canCreate, canDelete, canRead, canUpdate, cancelSubscription, capToolResultSize, captureScreenshot, checkFieldPermissions, coerceValue, collectionTableName, columnId, composioTools, computeDoMigration, computeHmacHex, createChat, createDeepSpaceAI, createDeepSpaceAuth, createScopedR2Handler, dataToColumnValues, decodeJwtPayload, deepSpaceAgentErrorSummary, 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, isTestAccountClaims, isTestAccountEmail, isTestAccountTier, lintSchema, loadMessages, makeDefaultSummarizer, matchOrigin, meterAi, meterUsage, meterVectorize, noopPermissionContext, parseQuotaLimit, platformCorsPatterns, platformWorkerFetch, prepareMessagesWithCompaction, priceBindingUsageEvent, putRecord, readRecord, recordMatchesSubscription, refundInvoice, registerUser, registryErrorJson, registryStub, requireSubscription, resolveAppName, resolveColumn, rowToData, runMigrations, saveYjsDoc, streamDeepSpaceAgent, timingSafeEqualHex, timingSafeEqualStrings, totalChars, truncateOldToolResults, turnsToCoreMessages, unwrapToolOutput, updateChat, validateAppName, validateBindingManifest, validateDoManifest, verifyJwt, workspaceAccountsSchema, workspaceContentSharesSchema, workspaceEmailHandlesSchema, workspaceFormResponsesSchema, workspacePeopleSchema, workspaceProjectsSchema, workspaceTagsSchema, workspaceTasksSchema, workspaceTeamMembersSchema, workspaceTeamsSchema, workspaceTransactionsSchema };
|
package/dist/server.js
CHANGED
|
@@ -174,6 +174,20 @@ var BUILT_IN_TOOLS = [
|
|
|
174
174
|
}
|
|
175
175
|
];
|
|
176
176
|
|
|
177
|
+
// src/shared/app-files.ts
|
|
178
|
+
var MAX_APP_FILE_BYTES = 25 * 1024 * 1024;
|
|
179
|
+
function formatBytes(bytes) {
|
|
180
|
+
if (bytes >= 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
|
|
181
|
+
if (bytes >= 1024) return `${Math.round(bytes / 1024)} KiB`;
|
|
182
|
+
return `${bytes} B`;
|
|
183
|
+
}
|
|
184
|
+
function encodeKeyPath(key) {
|
|
185
|
+
return key.split("/").map(encodeURIComponent).join("/");
|
|
186
|
+
}
|
|
187
|
+
function oversizeMessage(bytes) {
|
|
188
|
+
return `That file is ${formatBytes(bytes)}; the limit is ${formatBytes(MAX_APP_FILE_BYTES)} per file.`;
|
|
189
|
+
}
|
|
190
|
+
|
|
177
191
|
// src/server/utils/scoped-r2-files.ts
|
|
178
192
|
var CORS_HEADERS = { "Access-Control-Allow-Origin": "*" };
|
|
179
193
|
function contentDisposition(originalName) {
|
|
@@ -190,8 +204,12 @@ function sanitizeSubpath(raw) {
|
|
|
190
204
|
if (segments.some((s) => s === ".." || s === ".")) return null;
|
|
191
205
|
return raw;
|
|
192
206
|
}
|
|
193
|
-
function
|
|
194
|
-
|
|
207
|
+
function oversize(bytes, slack = 0) {
|
|
208
|
+
if (bytes <= MAX_APP_FILE_BYTES + slack) return null;
|
|
209
|
+
return Response.json(
|
|
210
|
+
{ error: oversizeMessage(bytes), code: "too_large", maxBytes: MAX_APP_FILE_BYTES },
|
|
211
|
+
{ status: 413, headers: CORS_HEADERS }
|
|
212
|
+
);
|
|
195
213
|
}
|
|
196
214
|
function isKeyWithinPrefix(key, prefix) {
|
|
197
215
|
return key.startsWith(prefix);
|
|
@@ -282,6 +300,8 @@ function createScopedR2Handler(config) {
|
|
|
282
300
|
}
|
|
283
301
|
async function handleUpload(request, url, bucket, prefix, userId, scope) {
|
|
284
302
|
try {
|
|
303
|
+
const declared = oversize(Number(request.headers.get("content-length")), 8 * 1024);
|
|
304
|
+
if (declared) return declared;
|
|
285
305
|
const contentType = request.headers.get("content-type") || "";
|
|
286
306
|
let fileData;
|
|
287
307
|
let fileName;
|
|
@@ -292,6 +312,8 @@ async function handleUpload(request, url, bucket, prefix, userId, scope) {
|
|
|
292
312
|
if (!file) {
|
|
293
313
|
return Response.json({ error: "No file provided" }, { status: 400, headers: CORS_HEADERS });
|
|
294
314
|
}
|
|
315
|
+
const tooBig = oversize(file.size);
|
|
316
|
+
if (tooBig) return tooBig;
|
|
295
317
|
fileData = await file.arrayBuffer();
|
|
296
318
|
fileName = formData.get("name")?.toString() || file.name;
|
|
297
319
|
mimeType = file.type || "application/octet-stream";
|
|
@@ -304,6 +326,8 @@ async function handleUpload(request, url, bucket, prefix, userId, scope) {
|
|
|
304
326
|
);
|
|
305
327
|
}
|
|
306
328
|
const base64Data = body.data.replace(/^data:[^;]+;base64,/, "");
|
|
329
|
+
const tooBig = oversize(Math.floor(base64Data.length * 3 / 4));
|
|
330
|
+
if (tooBig) return tooBig;
|
|
307
331
|
fileData = Uint8Array.from(atob(base64Data), (c) => c.charCodeAt(0)).buffer;
|
|
308
332
|
fileName = body.name;
|
|
309
333
|
mimeType = body.mimeType || "application/octet-stream";
|
|
@@ -7662,6 +7686,7 @@ export {
|
|
|
7662
7686
|
GLOBAL_DO_TYPE_NAMES,
|
|
7663
7687
|
GameRoom,
|
|
7664
7688
|
JobRoom,
|
|
7689
|
+
MAX_APP_FILE_BYTES,
|
|
7665
7690
|
MESSAGES_SCHEMA,
|
|
7666
7691
|
PresenceRoom,
|
|
7667
7692
|
REACTIONS_SCHEMA,
|