ProxyAiDatasource class

AI datasource that routes through the Supabase Edge Function proxy.

System prompts and content retrieval happen server-side. The user's own credential (API key for Claude, OAuth token for OpenAI/Gemini) is forwarded per-request and never stored on the server.

Implemented types

Constructors

ProxyAiDatasource(Dio _dio, {required AiProvider backendProvider, required String functionUrl, required Map<String, String> headersBuilder(), required Future<String?> credentialProvider(), String mode = 'explore', String? topicId, String? sessionId, bool isValidation = false, String? validationTarget, bool isCardGeneration = false, bool isStructuring = false})

Properties

backendProvider → AiProvider
The underlying provider to use on the server (claude, openai, gemini).
final
credentialProvider → Future<String?> Function()
Fetches the user's credential (API key or OAuth token) for the provider.
final
functionUrl → String
Full URL to the ai-proxy Edge Function.
final
hashCode → int
The hash code for this object.
no setterinherited
headersBuilder → Map<String, String> Function()
Auth headers to include with every request.
final
isCardGeneration → bool
Whether this is a card generation request.
final
isStructuring → bool
Whether this request asks the proxy to organize pasted source text into a curriculum. Structuring is always routed through the proxy, never a local key, so the prompt, the 100k-character input cap and the anti-injection sandwich stay server-side instead of needing client parity (audit H5 / M17).
final
isValidation → bool
Whether this is a validation session.
final
mode → String
Chat mode (teach, socratic, quiz, etc.) — sent to proxy for prompt selection.
final
providerName → String
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sessionId → String?
Learning session ID for per-session token-budget enforcement and AI audit logging on the proxy. The proxy validates ownership via RLS, so a foreign sessionId is silently ignored (treated as "no session" for budget purposes) rather than rejected.
final
topicId → String?
Topic ID for content chunk retrieval on the server.
final
validationTarget → String?
Validation target level.
final

Methods

isConfigured() → Future<bool>
Whether the provider is configured (API key stored or OAuth signed in).
override
listModels() → Future<List<AiModel>>
Fetch available models from the provider's API.
override
mapError(DioException e) → AiApiException
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendMessage({required String systemPrompt, required List<Map<String, String>> messages, int maxTokens = 8192}) → Future<String>
Send messages to the AI proxy. The proxy builds the system prompt server-side — systemPrompt is ignored (kept for interface compatibility).
override
streamMessage({required String systemPrompt, required List<Map<String, String>> messages, int maxTokens = 8192}) → Stream<String>
Stream a response from the AI proxy via SSE. systemPrompt is ignored — the proxy builds it server-side.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited