@marktiderman/genesis-chat 0.5.0 → 0.6.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/native.d.ts CHANGED
@@ -1844,6 +1844,45 @@ interface TusUploadOptions {
1844
1844
  /** A uuid for each file's name. Default core's `randomId` (crypto.randomUUID where there is one, else getRandomValues). */
1845
1845
  newId?: () => string;
1846
1846
  bucket?: string;
1847
+ /**
1848
+ * What sends the bytes. Default: Supabase Storage's TUS endpoint, built in (with `fetch`,
1849
+ * `chunkBytes` and `retries` above). An app opts into another by passing it here.
1850
+ */
1851
+ transport?: TusTransport;
1852
+ }
1853
+ /**
1854
+ * Where one file's upload stands: its path and, once the TUS upload is made,
1855
+ * where it lives. A transport keeps it current, so a retry of the same file
1856
+ * resumes rather than starting again.
1857
+ */
1858
+ interface TusUploadRecord {
1859
+ path: string;
1860
+ location?: string | undefined;
1861
+ done?: boolean | undefined;
1862
+ }
1863
+ /** What a transport reads a file's bytes from: exactly `from` to `to`. */
1864
+ interface TusUploadSource {
1865
+ size: number;
1866
+ read(from: number, to: number): Promise<ArrayBuffer>;
1867
+ }
1868
+ /** What a transport is told about the file it sends. */
1869
+ interface TusSendInfo {
1870
+ bucket: string;
1871
+ contentType: string;
1872
+ cacheControl: string;
1873
+ /** The person's headers (`authorization`, and `apikey` when given). Rejects when they're signed out. */
1874
+ headers: () => Promise<Record<string, string>>;
1875
+ }
1876
+ /**
1877
+ * The upload port: what moves a file's bytes to `record.path` in `info.bucket`.
1878
+ * It resolves to the path the object ended at; `renamePath()` gives a fresh
1879
+ * one (ask it at most once) when the path is taken by a send that never
1880
+ * finished. A rejection whose `failure` is `"forbidden"` or `"invalid"`, or a
1881
+ * `ChatError` that isn't transient, is a refusal; anything else is worth
1882
+ * trying again.
1883
+ */
1884
+ interface TusTransport {
1885
+ send(record: TusUploadRecord, source: TusUploadSource, info: TusSendInfo, renamePath: () => string): Promise<string>;
1847
1886
  }
1848
1887
  /** An open file, read a chunk at a time. */
1849
1888
  interface TusFileHandle {
@@ -2089,4 +2128,4 @@ declare function ModerationMarker({ note, mine, testID }: {
2089
2128
  testID?: string;
2090
2129
  }): react.JSX.Element;
2091
2130
 
2092
- export { AT_BOTTOM_POINTS, AppAttachment, type AppAttachmentProps, type AppStateLike, type AudioPlayerLike, type AudioRecorderLike, type AudioStatusLike, type AvailabilityForm, BUILT_IN_KINDS, type BubbleAttachment, type BuildRowsOptions, type ByteSource, CARD_ACTION_TIMEOUT_MS, type CameraViewHandleLike, CardError, type CardRunOptions, type CardRunState, ChatAccessError, type ChatAccessErrorProps, ChatAttachmentCard, type ChatAttachmentCardProps, type ChatAttachmentSlot, type ChatAttachmentSlotProps, ChatAutoRetry, type ChatAutoRetryOptions, ChatAvailabilityScreen, type ChatAvailabilityScreenProps, ChatAwayLine, type ChatAwayLineProps, ChatBroadcastSheet, type ChatBroadcastSheetProps, ChatCardContext, ChatComposer, type ChatComposerHandle, type ChatComposerProps, ChatEmojiPicker, type ChatEmojiPickerProps, ChatEmojiPickerSheet, type ChatEmojiPickerSheetProps, ChatIconButton, type ChatIconButtonProps, ChatInboxScreen, type ChatInboxScreenProps, ChatLinkPreviewCard, type ChatLinkPreviewCardProps, ChatMediaViewer, type ChatMediaViewerProps, type ChatNativeContextValue, type ChatNativeCopy, type ChatNativeCopyOverrides, type ChatNativeModules, ChatNativeProvider, type ChatNativeProviderProps, type ChatOrganiseCopy, type ChatPerson, type ChatPhoto, ChatPhotoViewer, type ChatPhotoViewerProps, ChatScheduleSheet, type ChatScheduleSheetProps, ChatScheduledBar, type ChatScheduledBarProps, ChatScheduledList, type ChatScheduledListProps, ChatSearchScreen, type ChatSearchScreenProps, ChatStartButton, type ChatStartPerson, ChatStartSheet, type ChatStartSheetProps, ChatThreadScreen, type ChatThreadScreenProps, type ChatThreadScreenSlots, type ChatThreadStackOptionsProps, ChatTopicBar, type ChatTopicBarProps, ChatVideoPlayer, type ChatVideoPlayerProps, ChatVideoRecorder, type ChatVideoRecorderProps, type ChatVideoState, type ChunkFileLike, type ChunkedPutOptions, type ClipboardLike, type ComposerAction, type ComposerAttachment, type ComposerDraft, type ComposerState, DISMISS_DISTANCE, DISMISS_VELOCITY, type DayHours, type DraftStorageLike, EMOJI_CATEGORIES, type EmojiCategoryId, type EmojiEntry, type ExpoAudioLike, type ExpoCameraLike, type ExpoVideoLike, type HapticEvent, type HapticsLike, type ImagePickerLike, type JumpTarget, type KeyboardAvoidingLike, MAX_ZOOM, type MediaLibraryLike, type MessageActionContext, type MessageActionId, MessageActionsSheet, type MessageActionsSheetProps, MessageAttachments, MessageBubble, type MessageBubbleProps, type MintedUpload, ModerationMarker, type ModerationNote, type NetInfoLike, type OpenAttachment, type OutboxSend, type PermissionLike, type PickedAssetLike, type PickerResultLike, QUICK_REACTIONS, RECENT_EMOJI_MAX, type RecordedVideo, type RecorderConfig, type RecorderEffect, type RecorderEvent, type RecorderNotice, type RecorderPhase, type RecorderState, type RecorderStateLike, type ReplyTarget, SearchSnippet, type SharingLike, type StartVideoInput, TRANSCRIPT_LINES, TUS_CHUNK_BYTES, type ThreadRow, type TopicMenuAction, type TusUploadOptions, type UseJumpOptions, type UseVoiceRecorderOptions, VIDEO_CHUNK_BYTES, VIDEO_HOLD_MS, VIDEO_MIN_MS, type VideoPlayerLike, type VideoRecorderEffect, type VideoRecorderEvent, type VideoRecorderPhase, type VideoRecorderState, type VideoUploadError, type VideoUploadTask, VideoUploadTray, type VideoUploadTrayProps, type VideoUploads, type VideoViewHandleLike, VoiceNotePlayer, type VoiceNotePlayerProps, VoiceTranscript, type VoiceTranscriptProps, type WebBrowserLike, type WeekHours, activePlaybackId, attachmentKindOf, attachmentPaths, attachmentPreview, availabilityInput, awayLineFor, barsThatFit, base64ToBytes, base64Utf8, broadcastOutcome, broadcastRows, buildThreadRows, canManageTopics, canReactTo, canSend, cardAction, cardTitle, chatNativeCopy, chatOrganiseCopy, chatThreadStackOptions, checkTopicName, chunkedPut, claimPlayback, clearDrafts, clockToDate, composerDisabledReason, composerReducer, createDraftSaver, createTusUpload, createVideoUploads, cycleVideoRate, cycleVoiceNoteRate, dateToClock, defaultScheduleAt, defaultWeek, deviceTimeZone, displayBody, draftKey, emojiEntry, emojiInCategory, emptyComposer, fileFromDataUri, fileSource, filesFromAssets, fill, forgetRecentEmoji, formFrom, formatClock, fullScreenVideo, galleryFor, haptic, hoursFromWeek, idleRecorder, inboxRow, initialVideoRecorder, initials, insertAtSelection, invertedRows, isLocalUri, isOnline, isOpenableHref, isVideoPlaying, linkHost, linkPreviewIds, liveBars, loadDraft, loadRecentEmoji, memoryDraftStorage, messageActionsFor, messagePreview, moderationNote, moderationText, muxPosterUrl, muxStreamUrl, nearBottom, nextOffset, openChatLink, panLimit, pauseChatPlayback, pinchScale, previewToShow, pushRecentEmoji, recentEmojiKey, recordedVideoFile, recorderStep, recordingType, releasePlayback, replyTargetFor, resolveChatCopy, rowIndexOf, rowKey, sameTimeDays, saveRecentEmoji, scheduleInputFrom, scrubSeconds, searchEmoji, shouldDismiss, slotUrl, snippetText, splitCardAttachments, threadListMode, timeZones, toSend, toggleVideo, toggleVideoMute, toggleVoiceNote, topicClosedFor, topicMenuFor, transcriptIsLong, useAwayLine, useCardRuns, useChatAutoRetry, useChatComposer, useChatNative, useChatThreadStackOptions, useJumpToMessage, usePlayingVideo, usePlayingVoiceNote, useScheduleSend, useVideoUploads, useVoiceRecorder, videoRecorderStep, videoSource, videoState, videoUploads, voiceNoteFile, waveformBars, weekFromHours, withDay, withTime };
2131
+ export { AT_BOTTOM_POINTS, AppAttachment, type AppAttachmentProps, type AppStateLike, type AudioPlayerLike, type AudioRecorderLike, type AudioStatusLike, type AvailabilityForm, BUILT_IN_KINDS, type BubbleAttachment, type BuildRowsOptions, type ByteSource, CARD_ACTION_TIMEOUT_MS, type CameraViewHandleLike, CardError, type CardRunOptions, type CardRunState, ChatAccessError, type ChatAccessErrorProps, ChatAttachmentCard, type ChatAttachmentCardProps, type ChatAttachmentSlot, type ChatAttachmentSlotProps, ChatAutoRetry, type ChatAutoRetryOptions, ChatAvailabilityScreen, type ChatAvailabilityScreenProps, ChatAwayLine, type ChatAwayLineProps, ChatBroadcastSheet, type ChatBroadcastSheetProps, ChatCardContext, ChatComposer, type ChatComposerHandle, type ChatComposerProps, ChatEmojiPicker, type ChatEmojiPickerProps, ChatEmojiPickerSheet, type ChatEmojiPickerSheetProps, ChatIconButton, type ChatIconButtonProps, ChatInboxScreen, type ChatInboxScreenProps, ChatLinkPreviewCard, type ChatLinkPreviewCardProps, ChatMediaViewer, type ChatMediaViewerProps, type ChatNativeContextValue, type ChatNativeCopy, type ChatNativeCopyOverrides, type ChatNativeModules, ChatNativeProvider, type ChatNativeProviderProps, type ChatOrganiseCopy, type ChatPerson, type ChatPhoto, ChatPhotoViewer, type ChatPhotoViewerProps, ChatScheduleSheet, type ChatScheduleSheetProps, ChatScheduledBar, type ChatScheduledBarProps, ChatScheduledList, type ChatScheduledListProps, ChatSearchScreen, type ChatSearchScreenProps, ChatStartButton, type ChatStartPerson, ChatStartSheet, type ChatStartSheetProps, ChatThreadScreen, type ChatThreadScreenProps, type ChatThreadScreenSlots, type ChatThreadStackOptionsProps, ChatTopicBar, type ChatTopicBarProps, ChatVideoPlayer, type ChatVideoPlayerProps, ChatVideoRecorder, type ChatVideoRecorderProps, type ChatVideoState, type ChunkFileLike, type ChunkedPutOptions, type ClipboardLike, type ComposerAction, type ComposerAttachment, type ComposerDraft, type ComposerState, DISMISS_DISTANCE, DISMISS_VELOCITY, type DayHours, type DraftStorageLike, EMOJI_CATEGORIES, type EmojiCategoryId, type EmojiEntry, type ExpoAudioLike, type ExpoCameraLike, type ExpoVideoLike, type HapticEvent, type HapticsLike, type ImagePickerLike, type JumpTarget, type KeyboardAvoidingLike, MAX_ZOOM, type MediaLibraryLike, type MessageActionContext, type MessageActionId, MessageActionsSheet, type MessageActionsSheetProps, MessageAttachments, MessageBubble, type MessageBubbleProps, type MintedUpload, ModerationMarker, type ModerationNote, type NetInfoLike, type OpenAttachment, type OutboxSend, type PermissionLike, type PickedAssetLike, type PickerResultLike, QUICK_REACTIONS, RECENT_EMOJI_MAX, type RecordedVideo, type RecorderConfig, type RecorderEffect, type RecorderEvent, type RecorderNotice, type RecorderPhase, type RecorderState, type RecorderStateLike, type ReplyTarget, SearchSnippet, type SharingLike, type StartVideoInput, TRANSCRIPT_LINES, TUS_CHUNK_BYTES, type ThreadRow, type TopicMenuAction, type TusSendInfo, type TusTransport, type TusUploadOptions, type TusUploadRecord, type TusUploadSource, type UseJumpOptions, type UseVoiceRecorderOptions, VIDEO_CHUNK_BYTES, VIDEO_HOLD_MS, VIDEO_MIN_MS, type VideoPlayerLike, type VideoRecorderEffect, type VideoRecorderEvent, type VideoRecorderPhase, type VideoRecorderState, type VideoUploadError, type VideoUploadTask, VideoUploadTray, type VideoUploadTrayProps, type VideoUploads, type VideoViewHandleLike, VoiceNotePlayer, type VoiceNotePlayerProps, VoiceTranscript, type VoiceTranscriptProps, type WebBrowserLike, type WeekHours, activePlaybackId, attachmentKindOf, attachmentPaths, attachmentPreview, availabilityInput, awayLineFor, barsThatFit, base64ToBytes, base64Utf8, broadcastOutcome, broadcastRows, buildThreadRows, canManageTopics, canReactTo, canSend, cardAction, cardTitle, chatNativeCopy, chatOrganiseCopy, chatThreadStackOptions, checkTopicName, chunkedPut, claimPlayback, clearDrafts, clockToDate, composerDisabledReason, composerReducer, createDraftSaver, createTusUpload, createVideoUploads, cycleVideoRate, cycleVoiceNoteRate, dateToClock, defaultScheduleAt, defaultWeek, deviceTimeZone, displayBody, draftKey, emojiEntry, emojiInCategory, emptyComposer, fileFromDataUri, fileSource, filesFromAssets, fill, forgetRecentEmoji, formFrom, formatClock, fullScreenVideo, galleryFor, haptic, hoursFromWeek, idleRecorder, inboxRow, initialVideoRecorder, initials, insertAtSelection, invertedRows, isLocalUri, isOnline, isOpenableHref, isVideoPlaying, linkHost, linkPreviewIds, liveBars, loadDraft, loadRecentEmoji, memoryDraftStorage, messageActionsFor, messagePreview, moderationNote, moderationText, muxPosterUrl, muxStreamUrl, nearBottom, nextOffset, openChatLink, panLimit, pauseChatPlayback, pinchScale, previewToShow, pushRecentEmoji, recentEmojiKey, recordedVideoFile, recorderStep, recordingType, releasePlayback, replyTargetFor, resolveChatCopy, rowIndexOf, rowKey, sameTimeDays, saveRecentEmoji, scheduleInputFrom, scrubSeconds, searchEmoji, shouldDismiss, slotUrl, snippetText, splitCardAttachments, threadListMode, timeZones, toSend, toggleVideo, toggleVideoMute, toggleVoiceNote, topicClosedFor, topicMenuFor, transcriptIsLong, useAwayLine, useCardRuns, useChatAutoRetry, useChatComposer, useChatNative, useChatThreadStackOptions, useJumpToMessage, usePlayingVideo, usePlayingVoiceNote, useScheduleSend, useVideoUploads, useVoiceRecorder, videoRecorderStep, videoSource, videoState, videoUploads, voiceNoteFile, waveformBars, weekFromHours, withDay, withTime };
package/dist/native.js CHANGED
@@ -4868,16 +4868,30 @@ function createTusUpload(options) {
4868
4868
  const newId = options.newId ?? randomId;
4869
4869
  const readFile = options.readFile ?? (async (uri) => (await doFetch(uri)).arrayBuffer());
4870
4870
  const byFile = /* @__PURE__ */ new WeakMap();
4871
- async function headers(extra = {}) {
4871
+ async function auth() {
4872
4872
  const token = await options.getAccessToken();
4873
4873
  if (!token) throw new ChatError("Sign in to send files", "42501", "upload");
4874
4874
  return {
4875
4875
  authorization: `Bearer ${token}`,
4876
- ...options.apikey ? { apikey: options.apikey } : {},
4877
- "tus-resumable": "1.0.0",
4878
- ...extra
4876
+ ...options.apikey ? { apikey: options.apikey } : {}
4879
4877
  };
4880
4878
  }
4879
+ async function headers(extra = {}) {
4880
+ return { ...await auth(), "tus-resumable": "1.0.0", ...extra };
4881
+ }
4882
+ const renamePath = (rec) => `${rec.path.slice(0, rec.path.lastIndexOf("/") + 1)}${newId()}.${rec.path.slice(rec.path.lastIndexOf(".") + 1)}`;
4883
+ async function sendThrough(transport, file, rec, source) {
4884
+ try {
4885
+ const path = await transport.send(rec, source, { bucket, contentType: file.contentType, cacheControl: "3600", headers: auth }, () => renamePath(rec));
4886
+ rec.path = path;
4887
+ rec.done = true;
4888
+ return path;
4889
+ } catch (e) {
4890
+ if (e instanceof ChatError) throw e;
4891
+ const failure = typeof e === "object" && e !== null ? e.failure : void 0;
4892
+ throw new ChatError(e instanceof Error ? e.message : String(e), failure === "forbidden" ? "42501" : failure === "invalid" ? "22023" : void 0, "upload");
4893
+ }
4894
+ }
4881
4895
  async function sourceOf(file) {
4882
4896
  const data = file.data;
4883
4897
  if (typeof data === "string") {
@@ -4947,7 +4961,7 @@ function createTusUpload(options) {
4947
4961
  if (record.done) return record.path;
4948
4962
  const source = await sourceOf(file);
4949
4963
  try {
4950
- return await send(file, record, source);
4964
+ return await (options.transport ? sendThrough(options.transport, file, record, source) : send(file, record, source));
4951
4965
  } finally {
4952
4966
  source.close();
4953
4967
  }
@@ -4992,7 +5006,7 @@ function createTusUpload(options) {
4992
5006
  if (created === "conflict") {
4993
5007
  if (fresh) throw new ChatError("The upload is out of step", void 0, "upload");
4994
5008
  fresh = true;
4995
- rec.path = `${rec.path.slice(0, rec.path.lastIndexOf("/") + 1)}${newId()}.${rec.path.slice(rec.path.lastIndexOf(".") + 1)}`;
5009
+ rec.path = renamePath(rec);
4996
5010
  continue;
4997
5011
  }
4998
5012
  rec.location = created;