mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
`insights/mount.py` is explicit: `/v1/` is the mount and `/api/` is the older spelling, kept on the wire for released CLI builds and personal-API-key holders and rewritten once at the edge by `ApiRewriteMiddleware`. Our own frontend was still on the older spelling: the orval clients were generated two days before the mount moved and the move did not regenerate them, so 70 files and 2323 paths said `/api/`. That is not only a spelling. `prepareUrl` in `lib/api.ts` rewrites `/v1/*` to the selected region's host in OAuth mode and nothing else, because that is what the cloud CORS allowlist covers — so every generated call quietly stayed same-origin, and `getExportsContentRetrieveUrl` builds an `<img src>` that never reaches `lib/api.ts` at all. The clients are regenerated from a spec that needs postgres, the datastore and Django, so this is the path strings only, which is the whole of what the mount move changes in them: orval copies paths verbatim from the spec, and the spec takes them from the URLconf. Doc comments carried the same stale prefix and move with them; their Python docstrings already say `/v1/`. The two frozen OAuth client-metadata paths are identifiers rather than API surface and appear in none of these files. The Slack task prompt told the agent to POST to `$INSIGHTS_API_URL/api/projects/...`, which is a live request path, not prose.
149 lines
5.7 KiB
TypeScript
Generated
149 lines
5.7 KiB
TypeScript
Generated
import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
|
|
/**
|
|
* Auto-generated from the Django backend OpenAPI schema.
|
|
* To modify these types, update the Django serializers or views, then run:
|
|
* insightscli build:openapi
|
|
* Questions or issues? #team-devex on Slack
|
|
*
|
|
* Insights API - generated
|
|
* OpenAPI spec version: 1.0.0
|
|
*/
|
|
import type {
|
|
PaginatedWizardSessionDTOListApi,
|
|
UpsertWizardSessionRequestApi,
|
|
WizardSessionDTOApi,
|
|
WizardSessionsLatestRetrieveParams,
|
|
WizardSessionsListParams,
|
|
WizardSessionsStreamRetrieveParams,
|
|
} from './api.schemas'
|
|
|
|
export const getWizardSessionsListUrl = (projectId: string, params?: WizardSessionsListParams) => {
|
|
const normalizedParams = new URLSearchParams()
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
})
|
|
|
|
const stringifiedParams = normalizedParams.toString()
|
|
|
|
return stringifiedParams.length > 0
|
|
? `/v1/projects/${projectId}/wizard/sessions/?${stringifiedParams}`
|
|
: `/v1/projects/${projectId}/wizard/sessions/`
|
|
}
|
|
|
|
/**
|
|
* List wizard sessions for the project, ordered by started_at desc. This should only be called by the Insights Wizard. Optional filters: ?workflow_id=<id> and ?skill_id=<id>.
|
|
*/
|
|
export const wizardSessionsList = async (
|
|
projectId: string,
|
|
params?: WizardSessionsListParams,
|
|
options?: RequestInit
|
|
): Promise<PaginatedWizardSessionDTOListApi> => {
|
|
return apiMutator<PaginatedWizardSessionDTOListApi>(getWizardSessionsListUrl(projectId, params), {
|
|
...options,
|
|
method: 'GET',
|
|
})
|
|
}
|
|
|
|
export const getWizardSessionsCreateUrl = (projectId: string) => {
|
|
return `/v1/projects/${projectId}/wizard/sessions/`
|
|
}
|
|
|
|
/**
|
|
* Upsert a wizard session. The `session_id` key is the idempotency anchor — reposting the same `session_id` replaces the existing row. Returns 201 on create, 200 on update.
|
|
*/
|
|
export const wizardSessionsCreate = async (
|
|
projectId: string,
|
|
upsertWizardSessionRequestApi: UpsertWizardSessionRequestApi,
|
|
options?: RequestInit
|
|
): Promise<WizardSessionDTOApi> => {
|
|
return apiMutator<WizardSessionDTOApi>(getWizardSessionsCreateUrl(projectId), {
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(upsertWizardSessionRequestApi),
|
|
})
|
|
}
|
|
|
|
export const getWizardSessionsRetrieveUrl = (projectId: string, sessionId: string) => {
|
|
return `/v1/projects/${projectId}/wizard/sessions/${sessionId}/`
|
|
}
|
|
|
|
/**
|
|
* Retrieve a single wizard session by its session_id.
|
|
*/
|
|
export const wizardSessionsRetrieve = async (
|
|
projectId: string,
|
|
sessionId: string,
|
|
options?: RequestInit
|
|
): Promise<WizardSessionDTOApi> => {
|
|
return apiMutator<WizardSessionDTOApi>(getWizardSessionsRetrieveUrl(projectId, sessionId), {
|
|
...options,
|
|
method: 'GET',
|
|
})
|
|
}
|
|
|
|
export const getWizardSessionsLatestRetrieveUrl = (projectId: string, params: WizardSessionsLatestRetrieveParams) => {
|
|
const normalizedParams = new URLSearchParams()
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
})
|
|
|
|
const stringifiedParams = normalizedParams.toString()
|
|
|
|
return stringifiedParams.length > 0
|
|
? `/v1/projects/${projectId}/wizard/sessions/latest/?${stringifiedParams}`
|
|
: `/v1/projects/${projectId}/wizard/sessions/latest/`
|
|
}
|
|
|
|
/**
|
|
* Return the single most-recent wizard session for a workflow (and optional skill), or 204 if none exists. Unlike `list`, this is a point lookup the app shell uses to decide whether to open the live SSE stream — it never returns a collection, and 'no run' is a 204 rather than a 404 so clients don't conflate it with a missing endpoint.
|
|
*/
|
|
export const wizardSessionsLatestRetrieve = async (
|
|
projectId: string,
|
|
params: WizardSessionsLatestRetrieveParams,
|
|
options?: RequestInit
|
|
): Promise<WizardSessionDTOApi | void> => {
|
|
return apiMutator<WizardSessionDTOApi | void>(getWizardSessionsLatestRetrieveUrl(projectId, params), {
|
|
...options,
|
|
method: 'GET',
|
|
})
|
|
}
|
|
|
|
export const getWizardSessionsStreamRetrieveUrl = (projectId: string, params: WizardSessionsStreamRetrieveParams) => {
|
|
const normalizedParams = new URLSearchParams()
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
})
|
|
|
|
const stringifiedParams = normalizedParams.toString()
|
|
|
|
return stringifiedParams.length > 0
|
|
? `/v1/projects/${projectId}/wizard/sessions/stream/?${stringifiedParams}`
|
|
: `/v1/projects/${projectId}/wizard/sessions/stream/`
|
|
}
|
|
|
|
/**
|
|
* Server-Sent Events stream of wizard session updates for a (workflow_id, skill_id) pair. On connect, the current latest session (if any) is emitted as the first event; subsequent upserts are streamed in real time. The server closes the connection after 900 seconds with an `event: end` line so the client (EventSource) can reconnect.
|
|
*
|
|
* **SDK consumers**: do not call the generated fetch wrapper for this path — it will buffer the entire infinite stream. Use the URL builder (`getWizardSessionsStreamRetrieveUrl`) with the browser's `EventSource` API instead.
|
|
*/
|
|
export const wizardSessionsStreamRetrieve = async (
|
|
projectId: string,
|
|
params: WizardSessionsStreamRetrieveParams,
|
|
options?: RequestInit
|
|
): Promise<string> => {
|
|
return apiMutator<string>(getWizardSessionsStreamRetrieveUrl(projectId, params), {
|
|
...options,
|
|
method: 'GET',
|
|
})
|
|
}
|