@@ -0,0 +1,25 @@
|
||||
// The platform service's readiness, on its own so the status read can ask it without the search service
|
||||
// (`KNOWLEDGE_READINESS`): the search adapter answers the same way, from here.
|
||||
|
||||
import { type Knowledge, KnowledgeError } from "@conusai-kit/platform"
|
||||
import type { KnowledgeReadiness } from "../core/ports.js"
|
||||
import { refusalOfReason, stateOfRefusal } from "./refusals.js"
|
||||
|
||||
/**
|
||||
* The platform's managed service answers for itself. A refusal is the service's answer, as a typed code
|
||||
* the page shows in the reader's language; a failure to ask it is its being unavailable.
|
||||
*/
|
||||
export const platformKnowledgeReadiness = (client: Pick<Knowledge, "readiness">): KnowledgeReadiness => ({
|
||||
async readiness() {
|
||||
try {
|
||||
const answer = await client.readiness()
|
||||
return { state: answer.state, reasons: [...answer.reasons] }
|
||||
} catch (error) {
|
||||
if (error instanceof KnowledgeError) {
|
||||
const refusal = refusalOfReason(error.reason)
|
||||
return { state: stateOfRefusal(refusal), reasons: [], ...(refusal === undefined ? {} : { refusal }) }
|
||||
}
|
||||
return { state: "unavailable", reasons: [], refusal: "runtime_unavailable" }
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user