fix(sdk): preserve V2Event name for SSE streams (#34171)
This commit is contained in:
@@ -10,6 +10,8 @@ type OpenApiSchema = {
|
||||
readonly enum?: readonly unknown[]
|
||||
readonly properties?: Record<string, OpenApiSchema>
|
||||
readonly required?: readonly string[]
|
||||
readonly contentSchema?: OpenApiSchema
|
||||
readonly contentMediaType?: string
|
||||
}
|
||||
type OpenApiResponse = {
|
||||
readonly description?: string
|
||||
@@ -99,6 +101,21 @@ describe("PublicApi OpenAPI v2 errors", () => {
|
||||
})
|
||||
})
|
||||
|
||||
test("names the v2 event union without the SSE string wrapper collision", () => {
|
||||
const spec = OpenApi.fromApi(PublicApi) as OpenApiSpec
|
||||
|
||||
expect(spec.components.schemas.V2Event1).toBeUndefined()
|
||||
expect(spec.components.schemas.V2Event?.anyOf?.length).toBeGreaterThan(0)
|
||||
expect(spec.components.schemas.V2EventStream).toMatchObject({
|
||||
type: "string",
|
||||
contentMediaType: "application/json",
|
||||
contentSchema: { $ref: "#/components/schemas/V2Event" },
|
||||
})
|
||||
expect(spec.paths["/api/event"]?.get?.responses?.["200"]?.content?.["text/event-stream"]?.schema).toEqual({
|
||||
$ref: "#/components/schemas/V2Event",
|
||||
})
|
||||
})
|
||||
|
||||
test("preserves /api auth responses", () => {
|
||||
const spec = OpenApi.fromApi(PublicApi) as OpenApiSpec
|
||||
|
||||
|
||||
@@ -2766,7 +2766,7 @@ export type SessionHistory = {
|
||||
hasMore: boolean
|
||||
}
|
||||
|
||||
export type SessionDurableEvent1 = string
|
||||
export type SessionDurableEventStream = string
|
||||
|
||||
export type SessionMessagesResponse = {
|
||||
data: Array<SessionMessage>
|
||||
@@ -2847,7 +2847,7 @@ export type QuestionRejected2 = {
|
||||
}
|
||||
}
|
||||
|
||||
export type V2Event1 =
|
||||
export type V2Event =
|
||||
| ModelsDevRefreshed
|
||||
| IntegrationUpdated
|
||||
| IntegrationConnectionUpdated
|
||||
@@ -2937,7 +2937,7 @@ export type V2Event1 =
|
||||
| ServerConnected
|
||||
| GlobalDisposed
|
||||
|
||||
export type V2Event = string
|
||||
export type V2EventStream = string
|
||||
|
||||
export type ForbiddenError = {
|
||||
_tag: "ForbiddenError"
|
||||
@@ -11901,7 +11901,7 @@ export type V2SessionEventsResponses = {
|
||||
200: {
|
||||
id: string
|
||||
event: string
|
||||
data: SessionDurableEvent1
|
||||
data: SessionDurableEventStream
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11260,7 +11260,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"data": {
|
||||
"$ref": "#/components/schemas/SessionDurableEvent1"
|
||||
"$ref": "#/components/schemas/SessionDurableEventStream"
|
||||
}
|
||||
},
|
||||
"required": ["id", "event", "data"],
|
||||
@@ -23732,7 +23732,7 @@
|
||||
"required": ["data", "hasMore"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"SessionDurableEvent1": {
|
||||
"SessionDurableEventStream": {
|
||||
"type": "string",
|
||||
"contentSchema": {
|
||||
"$ref": "#/components/schemas/SessionDurableEvent"
|
||||
@@ -23975,7 +23975,7 @@
|
||||
"required": ["id", "type", "data"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"V2Event1": {
|
||||
"V2Event": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/Models-devRefreshed"
|
||||
@@ -24243,10 +24243,10 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"V2Event": {
|
||||
"V2EventStream": {
|
||||
"type": "string",
|
||||
"contentSchema": {
|
||||
"$ref": "#/components/schemas/V2Event1"
|
||||
"$ref": "#/components/schemas/V2Event"
|
||||
},
|
||||
"contentMediaType": "application/json"
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ import type {
|
||||
SessionMessageAssistantTool,
|
||||
SessionV2Info,
|
||||
SkillV2Info,
|
||||
V2Event1,
|
||||
V2Event,
|
||||
} from "@opencode-ai/sdk/v2"
|
||||
import { createStore, produce } from "solid-js/store"
|
||||
import { createSimpleContext } from "./helper"
|
||||
@@ -121,7 +121,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
||||
},
|
||||
}
|
||||
|
||||
function handleEvent(event: V2Event1) {
|
||||
function handleEvent(event: V2Event) {
|
||||
switch (event.type) {
|
||||
case "catalog.updated":
|
||||
void Promise.all([
|
||||
@@ -408,7 +408,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
||||
...event,
|
||||
data: event.properties,
|
||||
location: { directory: metadata.directory, workspaceID: metadata.workspace },
|
||||
} as V2Event1)
|
||||
} as V2Event)
|
||||
})
|
||||
onCleanup(unsub)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user