1e16b0d5d2
- Add packages/ai: AgentController (streaming + budget), SuggestionBuilder, NoteBuilder, AIStore (Dexie/IndexedDB), SuggestionMutation - Fix createUlid to use monotonicFactory for reliable listSessions sort tiebreaker - Extend outline system prompt with setting + characters context - Add dexie dependency to packages/ai - 188 tests passing (core 47, ui 5, editor 30, ai 71, exporters 22, web 13)
106 lines
2.8 KiB
TypeScript
106 lines
2.8 KiB
TypeScript
/**
|
|
* `@pubscript/ai` — the AI provider layer for PubScript.
|
|
*
|
|
* A self-contained, SSE-based provider abstraction that talks to any
|
|
* OpenAI-compatible endpoint with streaming, thinking/reasoning params, and
|
|
* the token-budget engine from `packages/core`. See CHUNK#8.md.
|
|
*
|
|
* Public API:
|
|
* - `streamCompletion`, `collectStream`, `complete` — the completion client.
|
|
* - `measureBudget`, `enforceBudget` — budget helpers.
|
|
* - `discoverLocalProviders` — local provider discovery.
|
|
* - `getProvider` — resolve a provider config into an adapter.
|
|
* - `normalizeThinking` — thinking-param mapping.
|
|
* - Re-exports of the token budget engine from `packages/core`.
|
|
* - All types and error classes.
|
|
*/
|
|
|
|
// Completion client
|
|
export {
|
|
streamCompletion,
|
|
collectStream,
|
|
complete,
|
|
measureBudget,
|
|
enforceBudget,
|
|
} from "./client.js";
|
|
export type { MeasuredBudget, StreamResult } from "./client.js";
|
|
|
|
// Agent orchestration (CHUNK #9)
|
|
export {
|
|
AgentController,
|
|
isRateLimitError,
|
|
DEFAULT_MAX_RETRIES,
|
|
DEFAULT_RETRY_BACKOFF_MS,
|
|
} from "./agent.js";
|
|
export type { AgentStatus, AgentCallbacks, AgentOptions } from "./agent.js";
|
|
|
|
// Suggestion + note builders
|
|
export { SuggestionBuilder } from "./suggestions.js";
|
|
export type {
|
|
SuggestionKind,
|
|
SuggestionContext,
|
|
SuggestionPrompt,
|
|
SuggestionResult,
|
|
} from "./suggestions.js";
|
|
|
|
export { NoteBuilder } from "./notes.js";
|
|
export type { NoteKind, NoteContext, NotePrompt, NoteResult } from "./notes.js";
|
|
|
|
// Suggestion mutation (apply/revert)
|
|
export { SuggestionMutation } from "./suggestion-mutation.js";
|
|
export type { MutationResult } from "./suggestion-mutation.js";
|
|
|
|
// AIStore — session/message/suggestion/note persistence (CHUNK #9)
|
|
export {
|
|
AIStore,
|
|
createIndexedDBPersistence,
|
|
createInMemoryPersistence,
|
|
} from "./ai-session.js";
|
|
export type { AISessionPersistence, SessionRow } from "./ai-session.js";
|
|
|
|
// Provider adapters + factory
|
|
export { getProvider } from "./providers/adapters.js";
|
|
|
|
// Thinking-param mapping
|
|
export { normalizeThinking, reasoningBudgetTokens } from "./thinking.js";
|
|
|
|
// Local provider discovery
|
|
export {
|
|
discoverLocalProviders,
|
|
LOCAL_ENDPOINTS,
|
|
} from "./discover.js";
|
|
export type { DetectedModel, DetectedProvider } from "./discover.js";
|
|
|
|
// Token budget engine (re-exported from core)
|
|
export {
|
|
countTokens,
|
|
allocateBudget,
|
|
DEFAULT_BUDGET,
|
|
} from "./budget.js";
|
|
export type { Budget } from "./budget.js";
|
|
|
|
// Types
|
|
export type {
|
|
ProviderKind,
|
|
ThinkingConfig,
|
|
ThinkingEffort,
|
|
ProviderConfig,
|
|
ResolvedProvider,
|
|
Message,
|
|
CallOptions,
|
|
CompletionUsage,
|
|
StreamEventType,
|
|
StreamChunk,
|
|
CompleteResult,
|
|
ProviderAdapter,
|
|
} from "./providers/types.js";
|
|
|
|
// Errors
|
|
export {
|
|
ProviderError,
|
|
ProviderAuthError,
|
|
ProviderRateLimitError,
|
|
BudgetExceededError,
|
|
UnknownProviderError,
|
|
} from "./errors.js";
|