( uri: string, mime: string, filename?: string, )
| 157 | } |
| 158 | |
| 159 | function uriToFilePart( |
| 160 | uri: string, |
| 161 | mime: string, |
| 162 | filename?: string, |
| 163 | ): SessionV1.FilePartInput | SessionV1.TextPartInput { |
| 164 | try { |
| 165 | if (uri.startsWith("file://")) { |
| 166 | return { |
| 167 | type: "file", |
| 168 | url: uri, |
| 169 | filename: filename ?? filenameFromUri(uri) ?? "file", |
| 170 | mime, |
| 171 | } |
| 172 | } |
| 173 | if (uri.startsWith("zed://")) { |
| 174 | const pathname = new URL(uri).searchParams.get("path") |
| 175 | if (pathname) { |
| 176 | return { |
| 177 | type: "file", |
| 178 | url: pathToFileURL(pathname).href, |
| 179 | filename: filename ?? (path.basename(pathname) || "file"), |
| 180 | mime, |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | return { type: "text", text: uri } |
| 185 | } catch { |
| 186 | return { type: "text", text: uri } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | function filePartToContentChunks(part: Extract<ReplayPart, { type: "file" }>): ContentChunk[] { |
| 191 | if (part.url.startsWith("file://")) { |
no test coverage detected