Files
zeekay 40d120dbf7 refactor(api): say /v1/ in the Python callers
Every first-party Python caller and test now names the mount the API actually
answers on. Mechanical: URL literals only, and only where the /api/ was ours --
a preceding word character means it was a module path like insights/api/ or a
third-party host like slack.com/api/, and those are untouched.

Left saying /api/, each for a reason rather than for safety:
- products/warehouse_sources/.../sources/** is a catalogue of vendor endpoints
- services/llm-gateway deploys separately and is under a code freeze, so moving
  its two calls would break it during the skew
- the mcp_store and Slack/Teams redirect_uris are registered with third parties
  and must byte-match what was registered
- the Wizard and Raycast client-metadata paths are OAuth client_ids
- /api/surveys and /api/feature_flag/local_evaluation are SDK aliases the
  ingress routes to the Rust fleets, held by released SDK versions

Test URLconfs moved with the requests that call them, and the Datastore
user-selection fixtures now carry the leading slash that request.path has.
2026-08-08 18:38:44 -07:00

93 lines
3.2 KiB
TypeScript

import { getCurrentTeamId } from 'lib/utils/getAppContext'
import { apiMutator } from '../../../frontend/src/lib/api-orval-mutator'
import {
businessKnowledgeSourcesCreate,
businessKnowledgeSourcesDestroy,
businessKnowledgeSourcesList,
businessKnowledgeSourcesPartialUpdate,
businessKnowledgeSourcesRefreshCreate,
businessKnowledgeSourcesTextRetrieve,
} from './generated/api'
import type { CrawlModeEnumApi, KnowledgeSourceApi } from './generated/api.schemas'
export type { KnowledgeSourceApi as KnowledgeSourceDTOApi }
// TODO: replace with generated types once the backend exposes URL source serializers
export type RefreshIntervalValue = 'manual' | '1h' | '6h' | '24h' | '7d'
export type RefreshIntervalOption = { value: RefreshIntervalValue; label: string }
export interface CreateUrlSourcePayload {
name: string
url: string
source_type: 'url'
crawl_mode: CrawlModeEnumApi
include_globs?: string[]
exclude_globs?: string[]
max_pages?: number
max_depth?: number
refresh_interval?: RefreshIntervalValue
always_include?: boolean
}
export interface UpdateSourcePayload {
name?: string
text?: string
url?: string
crawl_mode?: CrawlModeEnumApi
include_globs?: string[]
exclude_globs?: string[]
max_pages?: number
max_depth?: number
refresh_interval?: RefreshIntervalValue
always_include?: boolean
}
export async function listSources(): Promise<KnowledgeSourceApi[]> {
const response = await businessKnowledgeSourcesList(String(getCurrentTeamId()), { limit: 1000 })
return response.results
}
export async function getSourceText(id: string): Promise<{ id: string; text: string }> {
const response = await businessKnowledgeSourcesTextRetrieve(String(getCurrentTeamId()), id)
return { id, text: response.text ?? '' }
}
export async function createTextSource(
name: string,
text: string,
always_include: boolean = false
): Promise<KnowledgeSourceApi> {
return await businessKnowledgeSourcesCreate(String(getCurrentTeamId()), { name, text, always_include })
}
export async function createUrlSource(payload: CreateUrlSourcePayload): Promise<KnowledgeSourceApi> {
return await businessKnowledgeSourcesCreate(
String(getCurrentTeamId()),
payload as unknown as Parameters<typeof businessKnowledgeSourcesCreate>[1]
)
}
export async function createFileSource(formData: FormData): Promise<KnowledgeSourceApi> {
return await apiMutator<KnowledgeSourceApi>(`/v1/projects/${getCurrentTeamId()}/business_knowledge/sources/`, {
method: 'POST',
body: formData,
})
}
export async function updateSource(id: string, payload: UpdateSourcePayload): Promise<KnowledgeSourceApi> {
return await businessKnowledgeSourcesPartialUpdate(
String(getCurrentTeamId()),
id,
payload as Parameters<typeof businessKnowledgeSourcesPartialUpdate>[2]
)
}
export async function deleteSource(id: string): Promise<void> {
await businessKnowledgeSourcesDestroy(String(getCurrentTeamId()), id)
}
export async function refreshSource(id: string): Promise<KnowledgeSourceApi> {
return await businessKnowledgeSourcesRefreshCreate(String(getCurrentTeamId()), id)
}