( item: ValidOpenResourceParams, context: ExecutionContext )
| 17 | const VALID_OPEN_RESOURCE_TYPES = new Set(Object.values(MothershipResourceType)) |
| 18 | |
| 19 | async function resolveResource( |
| 20 | item: ValidOpenResourceParams, |
| 21 | context: ExecutionContext |
| 22 | ): Promise<MothershipResource | { error: string }> { |
| 23 | const resourceType = item.type |
| 24 | let resourceId = item.id ?? '' |
| 25 | let title: string = resourceType |
| 26 | |
| 27 | if (resourceType === 'file') { |
| 28 | if (!context.workspaceId) |
| 29 | return { error: 'Opening a workspace file requires workspace context.' } |
| 30 | const fileRef = item.path || item.id || '' |
| 31 | const record = item.path |
| 32 | ? await resolveWorkspaceFileReference(context.workspaceId, item.path) |
| 33 | : item.id |
| 34 | ? await getWorkspaceFile(context.workspaceId, item.id) |
| 35 | : null |
| 36 | if (!record) return { error: `No workspace file found for "${fileRef}".` } |
| 37 | resourceId = record.id |
| 38 | title = record.name |
| 39 | return { |
| 40 | type: resourceType, |
| 41 | id: resourceId, |
| 42 | title, |
| 43 | path: canonicalWorkspaceFilePath({ folderPath: record.folderPath, name: record.name }), |
| 44 | } |
| 45 | } |
| 46 | if (resourceType === 'workflow') { |
| 47 | if (!item.id) return { error: 'workflow resources require `id`.' } |
| 48 | const wf = await getWorkflowById(item.id) |
| 49 | if (!wf) return { error: `No workflow with id "${item.id}".` } |
| 50 | if (context.workspaceId && wf.workspaceId !== context.workspaceId) |
| 51 | return { error: `Workflow not found in the current workspace.` } |
| 52 | resourceId = wf.id |
| 53 | title = wf.name |
| 54 | } |
| 55 | if (resourceType === 'table') { |
| 56 | if (!item.id) return { error: 'table resources require `id`.' } |
| 57 | const tbl = await getTableById(item.id) |
| 58 | if (!tbl) return { error: `No table with id "${item.id}".` } |
| 59 | if (context.workspaceId && tbl.workspaceId !== context.workspaceId) |
| 60 | return { error: `Table not found in the current workspace.` } |
| 61 | resourceId = tbl.id |
| 62 | title = tbl.name |
| 63 | } |
| 64 | if (resourceType === 'knowledgebase') { |
| 65 | if (!item.id) return { error: 'knowledgebase resources require `id`.' } |
| 66 | const kb = await getKnowledgeBaseById(item.id) |
| 67 | if (!kb) return { error: `No knowledge base with id "${item.id}".` } |
| 68 | if (context.workspaceId && kb.workspaceId !== context.workspaceId) |
| 69 | return { error: `Knowledge base not found in the current workspace.` } |
| 70 | resourceId = kb.id |
| 71 | title = kb.name |
| 72 | } |
| 73 | if (resourceType === 'log') { |
| 74 | if (!item.id) return { error: 'log resources require `id`.' } |
| 75 | const logRecord = await getLogById(item.id) |
| 76 | if (!logRecord) return { error: `No log with id "${item.id}".` } |
no test coverage detected