Skip to main content

ai-python-ui-adapter

Use when connecting AI SDK for Python streams to AI SDK UI useChat clients.

소스 정보

저장소
vercel-labs/seal
최근 소스 활동
2026년 7월 17일 17:25
감지된 SKILL.md 언어
영어
스타
8
포크
3

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
ai-python-ui-adapter
description
Use when connecting AI SDK for Python streams to AI SDK UI useChat clients.
metadata
{"sdk-version":"0.2.1"}
# ai-python-ui-adapter Frontend: ```tsx const chat = useChat({ transport: new DefaultChatTransport({ api: "/api/chat" }), sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses, }); ``` Use `chat.sendMessage(...)` to send user input. Use `chat.addToolApprovalResponse(...)` from approval buttons. Backend request: ```python class ChatRequest(pydantic.BaseModel): messages: list[ai.agents.ui.ai_sdk.UIMessage] messages, approvals = ai.agents.ui.ai_sdk.to_messages(request.messages) ai.agents.ui.ai_sdk.apply_approvals(approvals) ``` Backend stream: ```python async def body(): async with agent.run(model, messages) as stream: async def events(): async for event in stream: if ( isinstance(event, ai.events.HookEvent) and event.hook.status == "pending" ): ai.defer_hook(event.hook) yield event async for chunk in ai.agents.ui.ai_sdk.to_sse(events()): yield chunk return StreamingResponse( body(), headers=ai.agents.ui.ai_sdk.UI_MESSAGE_STREAM_HEADERS, ) ``` The adapter handles `UIMessage` parsing, message IDs, tool state, approvals, subagent `MessageBundle` values, and AI SDK UI stream events. You handle the HTTP route, auth, storage, session lookup, frontend rendering, and when to defer hooks. For saved UI history, use: ```python ui_messages = ai.agents.ui.ai_sdk.to_ui_messages(messages) ```
GitHub에서 보기