(
userId: string,
messageId?: string,
options: BuildIntegrationToolSchemasOptions = { schemaSurface: 'copilot' },
workspaceId?: string
)
| 104 | * workspace's `allowedIntegrations` allowlist. |
| 105 | */ |
| 106 | export async function buildIntegrationToolSchemas( |
| 107 | userId: string, |
| 108 | messageId?: string, |
| 109 | options: BuildIntegrationToolSchemasOptions = { schemaSurface: 'copilot' }, |
| 110 | workspaceId?: string |
| 111 | ): Promise<ToolSchema[]> { |
| 112 | const schemaSurface = options.schemaSurface ?? 'copilot' |
| 113 | const cacheKey = getIntegrationToolSchemaCacheKey(userId, workspaceId, schemaSurface) |
| 114 | const cached = integrationToolSchemaCache.get(cacheKey) |
| 115 | if (cached) { |
| 116 | return cloneToolSchemas(await cached.promise) |
| 117 | } |
| 118 | |
| 119 | const promise = buildIntegrationToolSchemasUncached( |
| 120 | userId, |
| 121 | messageId, |
| 122 | { schemaSurface }, |
| 123 | workspaceId |
| 124 | ).catch((error) => { |
| 125 | integrationToolSchemaCache.delete(cacheKey) |
| 126 | throw error |
| 127 | }) |
| 128 | |
| 129 | integrationToolSchemaCache.set(cacheKey, { |
| 130 | promise, |
| 131 | }) |
| 132 | |
| 133 | return cloneToolSchemas(await promise) |
| 134 | } |
| 135 | |
| 136 | async function buildIntegrationToolSchemasUncached( |
| 137 | userId: string, |
no test coverage detected