deepspace 0.6.2 → 0.7.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 +14 -0
- package/dist/cli.js +353 -80
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +124 -1
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -1
- package/dist/worker.d.ts +146 -1
- package/dist/worker.js +105 -0
- package/dist/worker.js.map +1 -1
- package/features/ai-chat/src/ChatPanel.tsx +56 -18
- package/package.json +1 -1
- package/dist/testing.d.ts +0 -115
package/dist/index.d.ts
CHANGED
|
@@ -4641,4 +4641,127 @@ interface UseCheckoutReturn {
|
|
|
4641
4641
|
}
|
|
4642
4642
|
declare function useCheckout(opts?: UseCheckoutOpts): UseCheckoutReturn;
|
|
4643
4643
|
|
|
4644
|
-
|
|
4644
|
+
/**
|
|
4645
|
+
* Client-side error reporter (opt-in) — the browser half of client-side error
|
|
4646
|
+
* reporting.
|
|
4647
|
+
*
|
|
4648
|
+
* // src/main.tsx (or your root)
|
|
4649
|
+
* import { installClientErrorReporter } from 'deepspace'
|
|
4650
|
+
* installClientErrorReporter()
|
|
4651
|
+
*
|
|
4652
|
+
* Hooks `window` 'error' + 'unhandledrejection' and forwards each to the app's
|
|
4653
|
+
* own Worker (see `registerClientErrorRoute` in 'deepspace/worker'), where it
|
|
4654
|
+
* lands in Workers Logs and shows up in `deepspace logs` tagged CLIENT.
|
|
4655
|
+
*
|
|
4656
|
+
* Best-effort by contract: it dedupes, caps how many it sends per page load,
|
|
4657
|
+
* and NEVER throws — a broken reporter must not break the app it watches.
|
|
4658
|
+
*/
|
|
4659
|
+
interface ClientErrorReporterOptions {
|
|
4660
|
+
/** Override the ingestion path (default `/_deepspace/client-errors`). */
|
|
4661
|
+
endpoint?: string;
|
|
4662
|
+
/** Max reports sent per page load — a runaway loop can't flood (default 50). */
|
|
4663
|
+
maxReports?: number;
|
|
4664
|
+
}
|
|
4665
|
+
/**
|
|
4666
|
+
* Install global handlers that forward uncaught browser errors to the app's
|
|
4667
|
+
* Worker. No-op outside a browser. Returns an uninstall function.
|
|
4668
|
+
*/
|
|
4669
|
+
declare function installClientErrorReporter(options?: ClientErrorReporterOptions): () => void;
|
|
4670
|
+
/**
|
|
4671
|
+
* Manually report a caught error — e.g. from a React error boundary's
|
|
4672
|
+
* `componentDidCatch`. No-op outside a browser; never throws. Unlike the
|
|
4673
|
+
* auto-installed handlers this has no client-side dedupe/cap — it relies on the
|
|
4674
|
+
* ingestion route's per-isolate throttle — so call it from boundaries (which
|
|
4675
|
+
* unmount rather than loop), not a hot path.
|
|
4676
|
+
*/
|
|
4677
|
+
declare function reportClientError(error: unknown, options?: ClientErrorReporterOptions & {
|
|
4678
|
+
componentStack?: string;
|
|
4679
|
+
}): void;
|
|
4680
|
+
|
|
4681
|
+
type ClientErrorKind = 'error' | 'unhandledrejection' | 'react';
|
|
4682
|
+
/** A sanitized, capped browser-error report — the wire + log-line payload. */
|
|
4683
|
+
interface ClientErrorReport {
|
|
4684
|
+
kind: ClientErrorKind;
|
|
4685
|
+
message: string;
|
|
4686
|
+
name?: string;
|
|
4687
|
+
stack?: string;
|
|
4688
|
+
/** Page URL where it fired (href or the script filename). */
|
|
4689
|
+
url?: string;
|
|
4690
|
+
line?: number;
|
|
4691
|
+
col?: number;
|
|
4692
|
+
}
|
|
4693
|
+
|
|
4694
|
+
/**
|
|
4695
|
+
* `deepspace logs` wire DTO — the single source of truth for the whitelisted
|
|
4696
|
+
* shape the platform telemetry reader emits and every consumer reads.
|
|
4697
|
+
*
|
|
4698
|
+
* The producer is `platform/deploy-worker/src/lib/workers-logs.ts` (which
|
|
4699
|
+
* rebuilds each event field-by-field from a raw Cloudflare row — see the
|
|
4700
|
+
* security invariant there). The consumers are the CLI tail
|
|
4701
|
+
* (`cli/commands/logs.ts`), the dashboard Logs panel
|
|
4702
|
+
* (`apps/dashboard/src/lib/types.ts`), and the e2e whitelist assertion
|
|
4703
|
+
* (`tests/e2e/tests/logs.spec.ts`). This module used to be hand-mirrored in
|
|
4704
|
+
* all four places; `source` was added to three of them and missed in the
|
|
4705
|
+
* e2e whitelist, so it now lives here once and they import it.
|
|
4706
|
+
*
|
|
4707
|
+
* Isomorphic — no DOM, no Hono, no platform types — so it re-exports cleanly
|
|
4708
|
+
* from both `deepspace` (client) and `deepspace/worker` and is safe to import
|
|
4709
|
+
* from the private deploy-worker.
|
|
4710
|
+
*/
|
|
4711
|
+
declare const LOG_LEVELS: readonly ["debug", "log", "info", "warn", "error"];
|
|
4712
|
+
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
4713
|
+
/** One log / request / exception event, rebuilt field-by-field from a CF row. */
|
|
4714
|
+
interface AppLogEvent {
|
|
4715
|
+
/** `$metadata.id` — unique per event; the client's dedupe key. */
|
|
4716
|
+
id: string;
|
|
4717
|
+
/** Unix ms. */
|
|
4718
|
+
timestamp: number;
|
|
4719
|
+
level: LogLevel;
|
|
4720
|
+
eventType: 'log' | 'request' | 'exception' | 'other';
|
|
4721
|
+
message: string;
|
|
4722
|
+
/**
|
|
4723
|
+
* Present (= `'client'`) only for a browser-forwarded error the app's own
|
|
4724
|
+
* Worker re-logged via `registerClientErrorRoute`. Absent means the log was
|
|
4725
|
+
* emitted server-side — there is no explicit `'server'` value, so consumers
|
|
4726
|
+
* branch on `source === 'client'`, never on a truthy/other check.
|
|
4727
|
+
*/
|
|
4728
|
+
source?: 'client';
|
|
4729
|
+
/** Invocation outcome (`ok`, `exception`, `exceededCpu`, …) when present. */
|
|
4730
|
+
outcome?: string;
|
|
4731
|
+
request?: {
|
|
4732
|
+
method: string;
|
|
4733
|
+
path: string;
|
|
4734
|
+
status?: number;
|
|
4735
|
+
};
|
|
4736
|
+
exception?: {
|
|
4737
|
+
name: string;
|
|
4738
|
+
message: string;
|
|
4739
|
+
stack?: string;
|
|
4740
|
+
};
|
|
4741
|
+
}
|
|
4742
|
+
interface AppLogsResponse {
|
|
4743
|
+
/** Ascending by timestamp (CF returns newest-first; the reader flips). */
|
|
4744
|
+
events: AppLogEvent[];
|
|
4745
|
+
/** Max event timestamp in ms — pass back as `since` to poll; null when empty. */
|
|
4746
|
+
cursor: number | null;
|
|
4747
|
+
/** True when the window returned `limit` events (older events were cut). */
|
|
4748
|
+
truncated: boolean;
|
|
4749
|
+
pollIntervalMs: number;
|
|
4750
|
+
}
|
|
4751
|
+
/**
|
|
4752
|
+
* Runtime tuple of every key a whitelisted `AppLogEvent` may carry — the
|
|
4753
|
+
* canonical whitelist the e2e suite mirrors when asserting no event leaks a key
|
|
4754
|
+
* outside this set. The two type-level assertions below fail compilation if
|
|
4755
|
+
* this tuple and the `AppLogEvent` interface disagree in either direction, so
|
|
4756
|
+
* adding an interface field forces a matching key here.
|
|
4757
|
+
*
|
|
4758
|
+
* NOTE: the e2e spec keeps its OWN copy of this set (it can't import the SDK —
|
|
4759
|
+
* `@deepspace/e2e` has no `deepspace` dependency), kept in step by a comment,
|
|
4760
|
+
* not by these compile-time guards. So this tuple hardens the code copies
|
|
4761
|
+
* (deploy-worker/CLI/dashboard, which import it), while the e2e mirror remains a
|
|
4762
|
+
* knowingly-accepted duplicate.
|
|
4763
|
+
*/
|
|
4764
|
+
declare const APP_LOG_EVENT_KEYS: readonly ["id", "timestamp", "level", "eventType", "message", "source", "outcome", "request", "exception"];
|
|
4765
|
+
type AppLogEventKey = (typeof APP_LOG_EVENT_KEYS)[number];
|
|
4766
|
+
|
|
4767
|
+
export { APP_LOG_EVENT_KEYS, ASYNC_RESOURCE_DEFAULTS, type AdHocChargeOpts, type AiStreamAction, type AiStreamChunk, type AppLogEvent, type AppLogEventKey, type AppLogsResponse, type AsyncResourceDefaults, type AsyncResourceState, type AsyncResourceStatus, AuthGate, type AuthGateProps, AuthOverlay, Awareness, type AwarenessState, type AwarenessStates, type BaseMessage, type CanvasShapeClient, type Channel, type ChannelInvitation, type ChannelMember, type ChargeOnceOpts, type ChargeOnceResult, type ClientErrorKind, type ClientErrorReport, type ClientErrorReporterOptions, type ClientMessage, type CollectionSchema, type ConnectionAttachment, type ConnectionStatus, type ContentSegment, type ConversationObject, type CronHistoryEntry, type CronTaskState, DEEPSPACE_THEME_PROPERTIES, DEFAULT_USER_COLORS, DeepSpaceAuthProvider, type DeepSpaceThemeConfig, DeepSpaceThemeProvider, type DeepSpaceThemeProviderProps, type DeriveLoadStateInput, ENV, type Environment, type FetchUserProfile, type FileAttachment, type GamePlayer, type GroupedReaction, GuestBanner, type HandlerContext, type InboxEntry, type IntegrationResponse, type JobStatusView, type JobView, LOG_LEVELS, type LinkPreviewData, type LoadState, type LoadStateAuthInput, type LoadStateStatusInput, type LogLevel, MSG, MSG_AWARENESS, MSG_SYNC, MSG_SYNC_STEP1, MSG_SYNC_STEP2, MSG_SYNC_UPDATE, MSG_YJS_AWARENESS, MSG_YJS_SYNC, type MemberRecord, type Message, type MessageHandlers, type MessageRecord, type MsgType, type PagedResourceFetchArgs, type PagedResourcePage, type PagedResourceState, type PagedResourceStatus, type PlanInfo, PlatformContext, type PlatformContextValue, PlatformProvider, type PlatformWSOptions, type PlatformWSResult, type PresencePeerClient, PricingTable, type PricingTablePlan, type PricingTablePrice, type ProductChargeOpts, type ProtocolMessage, type Purchase, type Query, type R2FileInfo, type R2Scope, type R2UploadResult, ROLES, ROLE_ADMIN, ROLE_ANONYMOUS, ROLE_CONFIG, ROLE_DEFAULT, type Reaction, type ReactionRecord, type ReadCursorRecord, type ReadReceipt, type RecordData, RecordProvider, type RecordProviderProps, RecordScope, type RequestOptions, type Role, type RoomUser, type ScopeEntry, ScopeRegistryProvider, type ServerMessage, SignedIn, SignedOut, type SubscribeOpts, type SubscribeResult, type SubscriptionState, type SubscriptionStatus, type SyncResult, type UseAsyncResourceOptions, type UseAuthProfileReadyOptions, type UseAuthReadyOptions, type UseAuthStatusOptions, type UseCanvasResult, type UseCheckoutOpts, type UseCronMonitorResult, type UseGameRoomResult, type UseJobsResult, type UsePagedResourceOptions, type UsePresenceRoomResult, type UseR2FilesReturn, type UseVoiceAgentOptions, type UseVoiceAgentResult, type UseYjsFieldResult, type UseYjsRoomResult, type UseYjsTextResult, type User, type UserCredits, type UserInfo, type UserKarma, type UserProfile, type ViewportClient, type VoiceStatus, type VoiceTranscriptEntry, type WriteError, applyDeepSpaceTheme, applyUIThemeTokens, authClient, canAutoLoadPagedResource, clampPagedResourceItems, clearAuthToken, clearDeepSpaceTheme, clientBuild, createDecoder, createEncoder, decodeAiStreamChunk, deriveLoadState, detectEnvironment, dispatch, encode, encodeAwarenessMessage, encodeSyncStep1, encodeSyncStep2, encodeUpdate, formatFileSize, formatFullTimestamp, formatMessageTime, getApiUrl, getAuthToken, getAuthUrl, getConversationDisplayName, getConversationParticipantIds, getEnvironmentConfig, getMessageType, getPagedResourceCooldownMs, getPlatformWorkerUrl, getThreadCounts, getUserColor, groupReactionsForMessage, handleAwarenessMessage, handleSyncMessage, hasContent, installClientErrorReporter, integration, isAsyncResourceSlow, isDMConversation, isDarkColor, isImageFile, isLocalDev, isProduction, parseMessageMetadata, parseSseLine, readThemeFromDOM, readVarUint, readVarUint8Array, reportClientError, resetEnvironmentCache, serverBuild, shouldGroupMessages, signIn, signOut, toConnectionStatus, toUint8Array, useAsyncResource, useAuth, useAuthProfileReady, useAuthReady, useAuthStatus, useAuthUser, useCanvas, useChannelMembers, useChannels, useCheckout, useCommunities, useConversation, useConversations, useCronMonitor, useDisplayName, useGameRoom, useInbox, useIsDarkTheme, useJobs, useMessages, useMutations, usePagedResource, usePlatform, usePlatformWS, usePosts, usePresence, usePresenceRoom, useQuery, useR2Files, useReactions, useReadReceipts, useRecordContext, useSession, useSubscription, useUser, useUserLookup, useUsers, useVoiceAgent, useYjsField, useYjsRoom, useYjsText, writeVarUint, writeVarUint8Array };
|
package/dist/index.js
CHANGED
|
@@ -6031,7 +6031,152 @@ function useCheckout(opts) {
|
|
|
6031
6031
|
refresh
|
|
6032
6032
|
};
|
|
6033
6033
|
}
|
|
6034
|
+
|
|
6035
|
+
// src/shared/client-errors.ts
|
|
6036
|
+
var CLIENT_ERROR_PATH = "/_deepspace/client-errors";
|
|
6037
|
+
var CLIENT_ERROR_CAPS = {
|
|
6038
|
+
message: 1024,
|
|
6039
|
+
stack: 4096,
|
|
6040
|
+
name: 256,
|
|
6041
|
+
url: 512
|
|
6042
|
+
};
|
|
6043
|
+
function capText(value, max) {
|
|
6044
|
+
if (typeof value !== "string") return void 0;
|
|
6045
|
+
return value.length > max ? value.slice(0, max) : value;
|
|
6046
|
+
}
|
|
6047
|
+
function finiteNumber(value) {
|
|
6048
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
6049
|
+
}
|
|
6050
|
+
function normalizeClientErrorReport(raw) {
|
|
6051
|
+
if (typeof raw !== "object" || raw === null) return null;
|
|
6052
|
+
const o = raw;
|
|
6053
|
+
const kind = o.kind === "unhandledrejection" || o.kind === "react" ? o.kind : "error";
|
|
6054
|
+
const message = capText(o.message, CLIENT_ERROR_CAPS.message) ?? "";
|
|
6055
|
+
const name = capText(o.name, CLIENT_ERROR_CAPS.name);
|
|
6056
|
+
const stack = capText(o.stack, CLIENT_ERROR_CAPS.stack);
|
|
6057
|
+
const url = capText(o.url, CLIENT_ERROR_CAPS.url);
|
|
6058
|
+
const line = finiteNumber(o.line);
|
|
6059
|
+
const col = finiteNumber(o.col);
|
|
6060
|
+
if (!message && !stack) return null;
|
|
6061
|
+
const report = { kind, message: message || (name ?? "Error") };
|
|
6062
|
+
if (name) report.name = name;
|
|
6063
|
+
if (stack) report.stack = stack;
|
|
6064
|
+
if (url) report.url = url;
|
|
6065
|
+
if (line !== void 0) report.line = line;
|
|
6066
|
+
if (col !== void 0) report.col = col;
|
|
6067
|
+
return report;
|
|
6068
|
+
}
|
|
6069
|
+
|
|
6070
|
+
// src/client/errors.ts
|
|
6071
|
+
function stripQuery(u) {
|
|
6072
|
+
if (!u) return void 0;
|
|
6073
|
+
try {
|
|
6074
|
+
const parsed = new URL(u, window.location?.href);
|
|
6075
|
+
return parsed.origin + parsed.pathname;
|
|
6076
|
+
} catch {
|
|
6077
|
+
return void 0;
|
|
6078
|
+
}
|
|
6079
|
+
}
|
|
6080
|
+
function post(endpoint, report) {
|
|
6081
|
+
try {
|
|
6082
|
+
void fetch(endpoint, {
|
|
6083
|
+
method: "POST",
|
|
6084
|
+
keepalive: true,
|
|
6085
|
+
headers: { "Content-Type": "application/json" },
|
|
6086
|
+
body: JSON.stringify(report)
|
|
6087
|
+
}).catch(() => {
|
|
6088
|
+
});
|
|
6089
|
+
} catch {
|
|
6090
|
+
}
|
|
6091
|
+
}
|
|
6092
|
+
var installed = false;
|
|
6093
|
+
function installClientErrorReporter(options = {}) {
|
|
6094
|
+
if (typeof window === "undefined" || installed) return () => {
|
|
6095
|
+
};
|
|
6096
|
+
installed = true;
|
|
6097
|
+
const endpoint = options.endpoint ?? CLIENT_ERROR_PATH;
|
|
6098
|
+
const maxReports = options.maxReports ?? 50;
|
|
6099
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6100
|
+
let sent = 0;
|
|
6101
|
+
const send = (raw) => {
|
|
6102
|
+
const report = normalizeClientErrorReport(raw);
|
|
6103
|
+
if (!report) return;
|
|
6104
|
+
const key = `${report.kind}:${report.name ?? ""}:${report.message}`;
|
|
6105
|
+
if (seen.has(key)) return;
|
|
6106
|
+
if (sent >= maxReports) return;
|
|
6107
|
+
seen.add(key);
|
|
6108
|
+
sent += 1;
|
|
6109
|
+
post(endpoint, report);
|
|
6110
|
+
};
|
|
6111
|
+
const onError = (event) => {
|
|
6112
|
+
try {
|
|
6113
|
+
const err = event.error;
|
|
6114
|
+
send({
|
|
6115
|
+
kind: "error",
|
|
6116
|
+
name: err?.name,
|
|
6117
|
+
message: err?.message ?? event.message,
|
|
6118
|
+
stack: err?.stack,
|
|
6119
|
+
url: stripQuery(event.filename || window.location?.href),
|
|
6120
|
+
line: event.lineno,
|
|
6121
|
+
col: event.colno
|
|
6122
|
+
});
|
|
6123
|
+
} catch {
|
|
6124
|
+
}
|
|
6125
|
+
};
|
|
6126
|
+
const onRejection = (event) => {
|
|
6127
|
+
try {
|
|
6128
|
+
const reason = event.reason;
|
|
6129
|
+
const isError = reason instanceof Error;
|
|
6130
|
+
send({
|
|
6131
|
+
kind: "unhandledrejection",
|
|
6132
|
+
name: isError ? reason.name : void 0,
|
|
6133
|
+
message: isError ? reason.message : String(reason),
|
|
6134
|
+
stack: isError ? reason.stack : void 0,
|
|
6135
|
+
url: stripQuery(window.location?.href)
|
|
6136
|
+
});
|
|
6137
|
+
} catch {
|
|
6138
|
+
}
|
|
6139
|
+
};
|
|
6140
|
+
window.addEventListener("error", onError);
|
|
6141
|
+
window.addEventListener("unhandledrejection", onRejection);
|
|
6142
|
+
return () => {
|
|
6143
|
+
window.removeEventListener("error", onError);
|
|
6144
|
+
window.removeEventListener("unhandledrejection", onRejection);
|
|
6145
|
+
installed = false;
|
|
6146
|
+
};
|
|
6147
|
+
}
|
|
6148
|
+
function reportClientError(error, options = {}) {
|
|
6149
|
+
if (typeof window === "undefined") return;
|
|
6150
|
+
try {
|
|
6151
|
+
const isError = error instanceof Error;
|
|
6152
|
+
const report = normalizeClientErrorReport({
|
|
6153
|
+
kind: "react",
|
|
6154
|
+
name: isError ? error.name : void 0,
|
|
6155
|
+
message: isError ? error.message : String(error),
|
|
6156
|
+
stack: (isError ? error.stack : void 0) ?? options.componentStack,
|
|
6157
|
+
url: stripQuery(window.location?.href)
|
|
6158
|
+
});
|
|
6159
|
+
if (!report) return;
|
|
6160
|
+
post(options.endpoint ?? CLIENT_ERROR_PATH, report);
|
|
6161
|
+
} catch {
|
|
6162
|
+
}
|
|
6163
|
+
}
|
|
6164
|
+
|
|
6165
|
+
// src/shared/log-events.ts
|
|
6166
|
+
var LOG_LEVELS = ["debug", "log", "info", "warn", "error"];
|
|
6167
|
+
var APP_LOG_EVENT_KEYS = [
|
|
6168
|
+
"id",
|
|
6169
|
+
"timestamp",
|
|
6170
|
+
"level",
|
|
6171
|
+
"eventType",
|
|
6172
|
+
"message",
|
|
6173
|
+
"source",
|
|
6174
|
+
"outcome",
|
|
6175
|
+
"request",
|
|
6176
|
+
"exception"
|
|
6177
|
+
];
|
|
6034
6178
|
export {
|
|
6179
|
+
APP_LOG_EVENT_KEYS,
|
|
6035
6180
|
ASYNC_RESOURCE_DEFAULTS,
|
|
6036
6181
|
AuthGate,
|
|
6037
6182
|
AuthOverlay,
|
|
@@ -6042,6 +6187,7 @@ export {
|
|
|
6042
6187
|
DeepSpaceThemeProvider,
|
|
6043
6188
|
ENV,
|
|
6044
6189
|
GuestBanner,
|
|
6190
|
+
LOG_LEVELS,
|
|
6045
6191
|
MSG,
|
|
6046
6192
|
MSG_AWARENESS,
|
|
6047
6193
|
MSG_SYNC,
|
|
@@ -6100,6 +6246,7 @@ export {
|
|
|
6100
6246
|
handleAwarenessMessage,
|
|
6101
6247
|
handleSyncMessage,
|
|
6102
6248
|
hasContent,
|
|
6249
|
+
installClientErrorReporter,
|
|
6103
6250
|
integration,
|
|
6104
6251
|
isAsyncResourceSlow,
|
|
6105
6252
|
isDMConversation,
|
|
@@ -6112,6 +6259,7 @@ export {
|
|
|
6112
6259
|
readThemeFromDOM,
|
|
6113
6260
|
readVarUint,
|
|
6114
6261
|
readVarUint8Array,
|
|
6262
|
+
reportClientError,
|
|
6115
6263
|
resetEnvironmentCache,
|
|
6116
6264
|
serverBuild,
|
|
6117
6265
|
shouldGroupMessages,
|