( value: unknown, workspaceId: string, paramId: string )
| 97 | } |
| 98 | |
| 99 | async function resolveCopilotFileReference( |
| 100 | value: unknown, |
| 101 | workspaceId: string, |
| 102 | paramId: string |
| 103 | ): Promise<UserFile | unknown> { |
| 104 | if (isUserFile(value)) { |
| 105 | return value |
| 106 | } |
| 107 | |
| 108 | const referenceId = |
| 109 | typeof value === 'string' |
| 110 | ? value |
| 111 | : value && |
| 112 | typeof value === 'object' && |
| 113 | typeof (value as Record<string, unknown>).id === 'string' |
| 114 | ? ((value as Record<string, unknown>).id as string) |
| 115 | : null |
| 116 | |
| 117 | if (!referenceId) { |
| 118 | return value |
| 119 | } |
| 120 | |
| 121 | const fileRecord = await resolveWorkspaceFileReference(workspaceId, referenceId) |
| 122 | if (!fileRecord) { |
| 123 | throw new Error( |
| 124 | `Could not resolve workspace file reference "${referenceId}" for parameter "${paramId}"` |
| 125 | ) |
| 126 | } |
| 127 | |
| 128 | const resolvedFile = toUserFileFromWorkspaceRecord(fileRecord) |
| 129 | if (!value || typeof value !== 'object') { |
| 130 | return resolvedFile |
| 131 | } |
| 132 | |
| 133 | const candidate = value as Record<string, unknown> |
| 134 | return { |
| 135 | ...resolvedFile, |
| 136 | context: typeof candidate.context === 'string' ? candidate.context : resolvedFile.context, |
| 137 | base64: typeof candidate.base64 === 'string' ? candidate.base64 : undefined, |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | async function normalizeCopilotFileParams( |
| 142 | tool: ToolConfig, |
no test coverage detected