Spaces:
Configuration error

File size: 897 Bytes
2d63f96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function isSaveFilePickerSupported(): boolean {
  return typeof window !== "undefined" && "showSaveFilePicker" in window;
}

export async function downloadTrajectory(
  conversationId: string,
  data: unknown[] | null,
): Promise<void> {
  if (!isSaveFilePickerSupported()) {
    throw new Error(
      "Your browser doesn't support downloading files. Please use Chrome, Edge, or another browser that supports the File System Access API.",
    );
  }
  const options: SaveFilePickerOptions = {
    suggestedName: `trajectory-${conversationId}.json`,
    types: [
      {
        description: "JSON File",
        accept: {
          "application/json": [".json"],
        },
      },
    ],
  };

  const fileHandle = await window.showSaveFilePicker(options);
  const writable = await fileHandle.createWritable();
  await writable.write(JSON.stringify(data, null, 2));
  await writable.close();
}