@opengeni/react-native 2.0.2-canary.38686408778001 → 2.0.2-canary.38798506700001

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.
@@ -1,4 +1,4 @@
1
- import type { FileAsset, ResourceRef } from "@opengeni/sdk";
1
+ import type { FileAsset, ResourceRef, SendMessageInput } from "@opengeni/sdk";
2
2
  import type { FileAttachmentClientLike } from "@opengeni/react/session";
3
3
  import type { NativeCryptoAdapter, NativeFileAdapter, NativePickedFile } from "./adapters.js";
4
4
  export type NativeAttachmentStatus = "preparing" | "uploading" | "ready" | "failed";
@@ -27,6 +27,11 @@ export interface NativeFileAttachmentsResult {
27
27
  addFiles(files: NativePickedFile[]): Promise<void>;
28
28
  retry(id: string): Promise<void>;
29
29
  remove(id: string): void;
30
+ /**
31
+ * Remove only ready files whose durable ids a send captured. Files added
32
+ * while that send was in flight stay queued for the next message.
33
+ */
34
+ removeReadyFiles(fileIds: Iterable<string>): void;
30
35
  clear(): void;
31
36
  clearError(): void;
32
37
  /** Show already-uploaded files (a restored draft) as ready attachments. */
@@ -42,6 +47,20 @@ export declare function projectNativeAttachmentScopeState(scopeMatches: boolean,
42
47
  attachments: NativeAttachment[];
43
48
  error: Error | null;
44
49
  };
50
+ /** Drop the ready attachments whose durable file ids are in `fileIds`. */
51
+ export declare function removeReadyNativeAttachments(current: NativeAttachment[], fileIds: Iterable<string>): NativeAttachment[];
52
+ /**
53
+ * Composer callbacks that keep the attachment tray in step with sends. An
54
+ * ordinary Send is acknowledged locally (`onSubmitted`), so its files leave
55
+ * the tray at once; waiting for server acceptance left them visible and a
56
+ * second tap re-sent the same files as a file-only message. Steer and
57
+ * recovered sends only report acceptance (`onSent`). Both remove exactly the
58
+ * files that send captured.
59
+ */
60
+ export declare function nativeComposerAttachmentCallbacks(attachments: Pick<NativeFileAttachmentsResult, "removeReadyFiles">): {
61
+ onSubmitted: (text: string, input: SendMessageInput) => void;
62
+ onSent: (text: string, input: SendMessageInput) => void;
63
+ };
45
64
  export declare function runNativeAttachmentPicker(input: {
46
65
  generation: number;
47
66
  currentGeneration(): number;
package/dist/index.js CHANGED
@@ -22,6 +22,23 @@ function sameNativeAttachmentScope(left, right) {
22
22
  function projectNativeAttachmentScopeState(scopeMatches, attachments, error) {
23
23
  return scopeMatches ? { attachments, error } : { attachments: [], error: null };
24
24
  }
25
+ function removeReadyNativeAttachments(current, fileIds) {
26
+ const sent = new Set(fileIds);
27
+ if (sent.size === 0) return current;
28
+ const kept = current.filter(
29
+ (entry) => !(entry.status === "ready" && entry.file && sent.has(entry.file.id))
30
+ );
31
+ return kept.length === current.length ? current : kept;
32
+ }
33
+ function sentFileIds(input) {
34
+ return (input.resources ?? []).flatMap(
35
+ (resource) => resource.kind === "file" ? [resource.fileId] : []
36
+ );
37
+ }
38
+ function nativeComposerAttachmentCallbacks(attachments) {
39
+ const removeSent = (_text, input) => attachments.removeReadyFiles(sentFileIds(input));
40
+ return { onSubmitted: removeSent, onSent: removeSent };
41
+ }
25
42
  async function runNativeAttachmentPicker(input) {
26
43
  try {
27
44
  const files = await input.pick();
@@ -243,6 +260,11 @@ function useNativeFileAttachments(input) {
243
260
  setAttachments([]);
244
261
  setError(null);
245
262
  }, []);
263
+ const removeReadyFiles = useCallback((fileIds) => {
264
+ const sent = [...fileIds];
265
+ if (sent.length === 0) return;
266
+ setAttachments((current) => removeReadyNativeAttachments(current, sent));
267
+ }, []);
246
268
  const clearError = useCallback(() => setError(null), []);
247
269
  const restoreReady = useCallback((files) => {
248
270
  const restored = [...files];
@@ -287,6 +309,7 @@ function useNativeFileAttachments(input) {
287
309
  addFiles,
288
310
  retry,
289
311
  remove,
312
+ removeReadyFiles,
290
313
  clear,
291
314
  clearError,
292
315
  restoreReady
@@ -375,7 +398,7 @@ function useOpenGeniNativeSession(input) {
375
398
  sendDestination: () => (session.session?.activeTurnId ?? null) !== null || queue.queue.length > 0 ? "queue" : "chat",
376
399
  sendExtras: () => ({ resources: attachments.readyResources }),
377
400
  sendBlocked: () => attachments.hasUnresolved,
378
- onSent: () => attachments.clear()
401
+ ...nativeComposerAttachmentCallbacks(attachments)
379
402
  });
380
403
  const control = useSessionControl(input.sessionId, {
381
404
  client: input.client,