MCPcopy Create free account
hub / github.com/anomalyco/opencode / uriToFilePart

Function uriToFilePart

packages/opencode/src/acp/content.ts:159–188  ·  view source on GitHub ↗
(
  uri: string,
  mime: string,
  filename?: string,
)

Source from the content-addressed store, hash-verified

157}
158
159function 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
190function filePartToContentChunks(part: Extract<ReplayPart, { type: "file" }>): ContentChunk[] {
191 if (part.url.startsWith("file://")) {

Callers 1

resourceLinkToPartFunction · 0.85

Calls 2

filenameFromUriFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected