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/worker.d.ts
CHANGED
|
@@ -2881,6 +2881,33 @@ declare function applyAiToolDefaults(toolName: string, params: Record<string, un
|
|
|
2881
2881
|
*/
|
|
2882
2882
|
declare const BUILT_IN_TOOLS: ToolSchema[];
|
|
2883
2883
|
|
|
2884
|
+
/**
|
|
2885
|
+
* App-files limits and failure reading, shared by every caller of the files
|
|
2886
|
+
* API: the browser hook (`client/storage/useR2Files.ts`), the CLI
|
|
2887
|
+
* (`cli/lib/app-files-api.ts`), and the docs that quote them.
|
|
2888
|
+
*
|
|
2889
|
+
* The ceiling is not a product decision made here — it is what the transport
|
|
2890
|
+
* physically allows. An upload crosses Cloudflare's request-body limit before
|
|
2891
|
+
* any worker code runs, and the platform worker then reads the whole body into
|
|
2892
|
+
* a ~128 MiB isolate before writing it to R2. So an oversized upload does not
|
|
2893
|
+
* fail as a friendly JSON error; it fails as a raw Cloudflare HTML page that
|
|
2894
|
+
* every caller here used to feed straight into `JSON.parse` and report as
|
|
2895
|
+
* "Unexpected token '<' … is not valid JSON". That is the bug this module
|
|
2896
|
+
* exists to make impossible.
|
|
2897
|
+
*/
|
|
2898
|
+
/**
|
|
2899
|
+
* The largest single file the app-files API accepts.
|
|
2900
|
+
*
|
|
2901
|
+
* Enforced by the shared upload handler (`server/utils/scoped-r2-files.ts`),
|
|
2902
|
+
* which is the only place it is a real limit — above it the platform worker
|
|
2903
|
+
* risks exhausting its isolate while holding the decoded file and the
|
|
2904
|
+
* multipart envelope together. Callers also check it locally, but only so the
|
|
2905
|
+
* failure is named early; skipping the client check cannot widen what is
|
|
2906
|
+
* accepted. Well above it (~100 MB) Cloudflare rejects the request before the
|
|
2907
|
+
* worker runs at all, which is why callers must read failures as text first.
|
|
2908
|
+
*/
|
|
2909
|
+
declare const MAX_APP_FILE_BYTES: number;
|
|
2910
|
+
|
|
2884
2911
|
/**
|
|
2885
2912
|
* Shared Scoped R2 Files Handler
|
|
2886
2913
|
*
|
|
@@ -2898,6 +2925,7 @@ declare const BUILT_IN_TOOLS: ToolSchema[];
|
|
|
2898
2925
|
* GET /api/files/:key → download (validated against prefix)
|
|
2899
2926
|
* DELETE /api/files/:key → delete (validated against prefix)
|
|
2900
2927
|
*/
|
|
2928
|
+
|
|
2901
2929
|
interface ScopeContext {
|
|
2902
2930
|
userId: string | null;
|
|
2903
2931
|
url: URL;
|
|
@@ -5138,4 +5166,4 @@ interface AppLogsResponse {
|
|
|
5138
5166
|
declare const APP_LOG_EVENT_KEYS: readonly ["id", "timestamp", "level", "eventType", "message", "source", "outcome", "request", "exception"];
|
|
5139
5167
|
type AppLogEventKey = (typeof APP_LOG_EVENT_KEYS)[number];
|
|
5140
5168
|
|
|
5141
|
-
export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, ALLOWED_BINDING_TYPES, APP_ID_RE, APP_LOG_EVENT_KEYS, APP_NAME_RULES, AUTO_PROVISIONABLE_TYPES, AUTO_PROVISION_SENTINEL, type ActionContext, type ActionHandler, type ActionResult, type ActionTools, type ApiWorkerEnv, type AppLogEvent, type AppLogEventKey, type AppLogsResponse, type AppMigrationIdsValidation, type AppNameResolution, type AppNameValidation, type AuthWorkerEnv, Awareness, type AwarenessState, type AwarenessStates, BASE_USERS_SCHEMA, BUILT_IN_TOOLS, type BaseMessage, BaseRoom, CANONICAL_APP_IDENTITY_MIGRATION_ID, CHANNELS_SCHEMA, CHANNEL_INVITATIONS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, CLIENT_LOG_MARKER, CONVERSATION_SCHEMAS, COST_RATES, CanvasRoom, type CanvasShape, type ChatContextConfig, type ChatMessageRow, type ChatRow, type ChatTurn, type ClientErrorKind, type ClientErrorReport, type ClientMessage, type CollectionPermissionSummary, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, type ComposioToolsOptions, 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, DEEPSPACE_AGENT_PROFILES, DEEPSPACE_AI_DEFAULTS, DEEPSPACE_AI_MODELS, DEEPSPACE_MODEL_CATALOG_PROVENANCE, DEFAULT_CONTEXT_CONFIG, DEFAULT_DO_MANIFEST, DEFAULT_QUERY_LIMIT, DEPLOYED_APPS_DEFAULTS, DIRECTORY_SCHEMAS, type DOBindings, type DOManifest, type DOManifestEntry, type DeepSpaceAIEnv, type DeepSpaceAIModel, type DeepSpaceAIModelId, type DeepSpaceAIOptions, type DeepSpaceAIProvider, type DeepSpaceAgentDiagnosticContext, DeepSpaceAgentModelError, type DeepSpaceAgentProfile, DeepSpaceAgentProfileError, type DeepSpaceAgentProfileId, type DeepSpaceAgentStream, type DeepSpaceAgentStreamOptions, type DeepSpaceAgentSupport, type DeepSpaceAuth, type DeepSpaceAuthConfig, type DeepSpaceDocumentationRouteEnv, type DeepSpaceDocumentationRouteOptions, 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, LOG_LEVELS, type LogLevel, 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, REGISTRY_INSTANCE, RESERVED_BINDING_NAMES, RESERVED_COLLECTION_NAMES, RESOURCE_ID_RE, ROLE_ADMIN, ROLE_ANONYMOUS, ROLE_DEFAULT, RecordRoom, type RecordRoomConfig, RegistryClientError, type ResolvedColumn, type ResolvedDeepSpaceAgentModel, type ResolvedPermission, type RolePermissions, type RunMigrationsResult, STRICT_APP_ID_RE, SYSTEM_COLLECTIONS, SYSTEM_MANAGED_COLUMNS, SchemaRegistry, type ScopeContext, type ScopedR2Auth, type ScopedR2Config, type ScopedR2Handler, type ScreenshotEnv, type ScreenshotResult, type ServerMessage, type SharedConnection, type StoredRecord, type Summarizer, type SyncResult, TEST_ACCOUNT_EMAIL_SUFFIX, 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, applyAiToolDefaults, applySlidingWindow, authWorkerFetch, bindingManifestFromOutputConfig, buildCronContext, buildTableSelect, buildUiParts, callRegistry, canCreate, canDelete, canRead, canUpdate, capToolResultSize, captureScreenshot, checkFieldPermissions, clientBuild, coerceValue, collectionTableName, columnId, composioTools, computeDoMigration, computeHmacHex, createChat, createDecoder, createDeepSpaceAI, createDeepSpaceAuth, createEncoder, createScopedR2Handler, dataToColumnValues, decodeJwtPayload, deepSpaceAgentErrorSummary, deleteChatCascade, dispatch, encode, encodeAwarenessMessage, encodeSyncStep1, encodeSyncStep2, encodeUpdate, enqueueJob, getChat, getDeepSpaceAIModel, getGlobalDOSchemas, getGlobalDOType, getMessageType, getRolePermissions, handleAwarenessMessage, handleClientErrorReport, handleSyncMessage, hasContent, isAutoProvision, isOwner, isTestAccountClaims, isTestAccountEmail, isTestAccountTier, lintSchema, listDeepSpaceAgentModels, loadMessages, makeDefaultSummarizer, matchOrigin, meterAi, meterUsage, meterVectorize, noopPermissionContext, parseQuotaLimit, platformCorsPatterns, platformWorkerFetch, prepareMessagesWithCompaction, priceBindingUsageEvent, readVarUint, readVarUint8Array, registerClientErrorRoute, registerDeepSpaceDocumentation, registryErrorJson, registryStub, resolveAppName, resolveColumn, resolveDeepSpaceAgentModel, rowToData, runMigrations, serverBuild, streamDeepSpaceAgent, timingSafeEqualHex, timingSafeEqualStrings, toUint8Array, totalChars, truncateOldToolResults, turnsToCoreMessages, unwrapToolOutput, updateChat, validateAppMigrationIds, validateAppName, validateBindingManifest, validateDoManifest, verifyJwt, workspaceAccountsSchema, workspaceContentSharesSchema, workspaceEmailHandlesSchema, workspaceFormResponsesSchema, workspacePeopleSchema, workspaceProjectsSchema, workspaceTagsSchema, workspaceTasksSchema, workspaceTeamMembersSchema, workspaceTeamsSchema, workspaceTransactionsSchema, writeVarUint, writeVarUint8Array };
|
|
5169
|
+
export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, ALLOWED_BINDING_TYPES, APP_ID_RE, APP_LOG_EVENT_KEYS, APP_NAME_RULES, AUTO_PROVISIONABLE_TYPES, AUTO_PROVISION_SENTINEL, type ActionContext, type ActionHandler, type ActionResult, type ActionTools, type ApiWorkerEnv, type AppLogEvent, type AppLogEventKey, type AppLogsResponse, type AppMigrationIdsValidation, type AppNameResolution, type AppNameValidation, type AuthWorkerEnv, Awareness, type AwarenessState, type AwarenessStates, BASE_USERS_SCHEMA, BUILT_IN_TOOLS, type BaseMessage, BaseRoom, CANONICAL_APP_IDENTITY_MIGRATION_ID, CHANNELS_SCHEMA, CHANNEL_INVITATIONS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, CLIENT_LOG_MARKER, CONVERSATION_SCHEMAS, COST_RATES, CanvasRoom, type CanvasShape, type ChatContextConfig, type ChatMessageRow, type ChatRow, type ChatTurn, type ClientErrorKind, type ClientErrorReport, type ClientMessage, type CollectionPermissionSummary, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, type ComposioToolsOptions, 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, DEEPSPACE_AGENT_PROFILES, DEEPSPACE_AI_DEFAULTS, DEEPSPACE_AI_MODELS, DEEPSPACE_MODEL_CATALOG_PROVENANCE, DEFAULT_CONTEXT_CONFIG, DEFAULT_DO_MANIFEST, DEFAULT_QUERY_LIMIT, DEPLOYED_APPS_DEFAULTS, DIRECTORY_SCHEMAS, type DOBindings, type DOManifest, type DOManifestEntry, type DeepSpaceAIEnv, type DeepSpaceAIModel, type DeepSpaceAIModelId, type DeepSpaceAIOptions, type DeepSpaceAIProvider, type DeepSpaceAgentDiagnosticContext, DeepSpaceAgentModelError, type DeepSpaceAgentProfile, DeepSpaceAgentProfileError, type DeepSpaceAgentProfileId, type DeepSpaceAgentStream, type DeepSpaceAgentStreamOptions, type DeepSpaceAgentSupport, type DeepSpaceAuth, type DeepSpaceAuthConfig, type DeepSpaceDocumentationRouteEnv, type DeepSpaceDocumentationRouteOptions, 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, LOG_LEVELS, type LogLevel, MAX_APP_FILE_BYTES, 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, REGISTRY_INSTANCE, RESERVED_BINDING_NAMES, RESERVED_COLLECTION_NAMES, RESOURCE_ID_RE, ROLE_ADMIN, ROLE_ANONYMOUS, ROLE_DEFAULT, RecordRoom, type RecordRoomConfig, RegistryClientError, type ResolvedColumn, type ResolvedDeepSpaceAgentModel, type ResolvedPermission, type RolePermissions, type RunMigrationsResult, STRICT_APP_ID_RE, SYSTEM_COLLECTIONS, SYSTEM_MANAGED_COLUMNS, SchemaRegistry, type ScopeContext, type ScopedR2Auth, type ScopedR2Config, type ScopedR2Handler, type ScreenshotEnv, type ScreenshotResult, type ServerMessage, type SharedConnection, type StoredRecord, type Summarizer, type SyncResult, TEST_ACCOUNT_EMAIL_SUFFIX, 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, applyAiToolDefaults, applySlidingWindow, authWorkerFetch, bindingManifestFromOutputConfig, buildCronContext, buildTableSelect, buildUiParts, callRegistry, canCreate, canDelete, canRead, canUpdate, capToolResultSize, captureScreenshot, checkFieldPermissions, clientBuild, coerceValue, collectionTableName, columnId, composioTools, computeDoMigration, computeHmacHex, createChat, createDecoder, createDeepSpaceAI, createDeepSpaceAuth, createEncoder, createScopedR2Handler, dataToColumnValues, decodeJwtPayload, deepSpaceAgentErrorSummary, deleteChatCascade, dispatch, encode, encodeAwarenessMessage, encodeSyncStep1, encodeSyncStep2, encodeUpdate, enqueueJob, getChat, getDeepSpaceAIModel, getGlobalDOSchemas, getGlobalDOType, getMessageType, getRolePermissions, handleAwarenessMessage, handleClientErrorReport, handleSyncMessage, hasContent, isAutoProvision, isOwner, isTestAccountClaims, isTestAccountEmail, isTestAccountTier, lintSchema, listDeepSpaceAgentModels, loadMessages, makeDefaultSummarizer, matchOrigin, meterAi, meterUsage, meterVectorize, noopPermissionContext, parseQuotaLimit, platformCorsPatterns, platformWorkerFetch, prepareMessagesWithCompaction, priceBindingUsageEvent, readVarUint, readVarUint8Array, registerClientErrorRoute, registerDeepSpaceDocumentation, registryErrorJson, registryStub, resolveAppName, resolveColumn, resolveDeepSpaceAgentModel, rowToData, runMigrations, serverBuild, streamDeepSpaceAgent, timingSafeEqualHex, timingSafeEqualStrings, toUint8Array, totalChars, truncateOldToolResults, turnsToCoreMessages, unwrapToolOutput, updateChat, validateAppMigrationIds, validateAppName, validateBindingManifest, validateDoManifest, verifyJwt, workspaceAccountsSchema, workspaceContentSharesSchema, workspaceEmailHandlesSchema, workspaceFormResponsesSchema, workspacePeopleSchema, workspaceProjectsSchema, workspaceTagsSchema, workspaceTasksSchema, workspaceTeamMembersSchema, workspaceTeamsSchema, workspaceTransactionsSchema, writeVarUint, writeVarUint8Array };
|
package/dist/worker.js
CHANGED
|
@@ -6240,6 +6240,20 @@ function registryErrorJson(c, err) {
|
|
|
6240
6240
|
throw err;
|
|
6241
6241
|
}
|
|
6242
6242
|
|
|
6243
|
+
// src/shared/app-files.ts
|
|
6244
|
+
var MAX_APP_FILE_BYTES = 25 * 1024 * 1024;
|
|
6245
|
+
function formatBytes(bytes) {
|
|
6246
|
+
if (bytes >= 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
|
|
6247
|
+
if (bytes >= 1024) return `${Math.round(bytes / 1024)} KiB`;
|
|
6248
|
+
return `${bytes} B`;
|
|
6249
|
+
}
|
|
6250
|
+
function encodeKeyPath(key) {
|
|
6251
|
+
return key.split("/").map(encodeURIComponent).join("/");
|
|
6252
|
+
}
|
|
6253
|
+
function oversizeMessage(bytes) {
|
|
6254
|
+
return `That file is ${formatBytes(bytes)}; the limit is ${formatBytes(MAX_APP_FILE_BYTES)} per file.`;
|
|
6255
|
+
}
|
|
6256
|
+
|
|
6243
6257
|
// src/server/utils/scoped-r2-files.ts
|
|
6244
6258
|
var CORS_HEADERS3 = { "Access-Control-Allow-Origin": "*" };
|
|
6245
6259
|
function contentDisposition(originalName) {
|
|
@@ -6256,8 +6270,12 @@ function sanitizeSubpath(raw) {
|
|
|
6256
6270
|
if (segments.some((s) => s === ".." || s === ".")) return null;
|
|
6257
6271
|
return raw;
|
|
6258
6272
|
}
|
|
6259
|
-
function
|
|
6260
|
-
|
|
6273
|
+
function oversize(bytes, slack = 0) {
|
|
6274
|
+
if (bytes <= MAX_APP_FILE_BYTES + slack) return null;
|
|
6275
|
+
return Response.json(
|
|
6276
|
+
{ error: oversizeMessage(bytes), code: "too_large", maxBytes: MAX_APP_FILE_BYTES },
|
|
6277
|
+
{ status: 413, headers: CORS_HEADERS3 }
|
|
6278
|
+
);
|
|
6261
6279
|
}
|
|
6262
6280
|
function isKeyWithinPrefix(key, prefix) {
|
|
6263
6281
|
return key.startsWith(prefix);
|
|
@@ -6348,6 +6366,8 @@ function createScopedR2Handler(config) {
|
|
|
6348
6366
|
}
|
|
6349
6367
|
async function handleUpload(request, url, bucket, prefix, userId, scope) {
|
|
6350
6368
|
try {
|
|
6369
|
+
const declared = oversize(Number(request.headers.get("content-length")), 8 * 1024);
|
|
6370
|
+
if (declared) return declared;
|
|
6351
6371
|
const contentType = request.headers.get("content-type") || "";
|
|
6352
6372
|
let fileData;
|
|
6353
6373
|
let fileName;
|
|
@@ -6358,6 +6378,8 @@ async function handleUpload(request, url, bucket, prefix, userId, scope) {
|
|
|
6358
6378
|
if (!file) {
|
|
6359
6379
|
return Response.json({ error: "No file provided" }, { status: 400, headers: CORS_HEADERS3 });
|
|
6360
6380
|
}
|
|
6381
|
+
const tooBig = oversize(file.size);
|
|
6382
|
+
if (tooBig) return tooBig;
|
|
6361
6383
|
fileData = await file.arrayBuffer();
|
|
6362
6384
|
fileName = formData.get("name")?.toString() || file.name;
|
|
6363
6385
|
mimeType = file.type || "application/octet-stream";
|
|
@@ -6370,6 +6392,8 @@ async function handleUpload(request, url, bucket, prefix, userId, scope) {
|
|
|
6370
6392
|
);
|
|
6371
6393
|
}
|
|
6372
6394
|
const base64Data = body.data.replace(/^data:[^;]+;base64,/, "");
|
|
6395
|
+
const tooBig = oversize(Math.floor(base64Data.length * 3 / 4));
|
|
6396
|
+
if (tooBig) return tooBig;
|
|
6373
6397
|
fileData = Uint8Array.from(atob(base64Data), (c) => c.charCodeAt(0)).buffer;
|
|
6374
6398
|
fileName = body.name;
|
|
6375
6399
|
mimeType = body.mimeType || "application/octet-stream";
|
|
@@ -9072,6 +9096,7 @@ export {
|
|
|
9072
9096
|
GameRoom,
|
|
9073
9097
|
JobRoom,
|
|
9074
9098
|
LOG_LEVELS,
|
|
9099
|
+
MAX_APP_FILE_BYTES,
|
|
9075
9100
|
MESSAGES_SCHEMA,
|
|
9076
9101
|
MSG,
|
|
9077
9102
|
MSG_AWARENESS,
|