@moikapy/origen 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts DELETED
@@ -1,58 +0,0 @@
1
- /**
2
- * @moikapy/origen — Multi-Provider Agent Engine
3
- *
4
- * Generic agent harness with Soul.md personas, streaming, tool calling.
5
- * Supports OpenRouter, Ollama, Anthropic, Google, and any OpenAI-compatible API.
6
- *
7
- * Domain-specific tools live in their own packages (e.g., @moikapy/scholar-tools).
8
- *
9
- * Usage:
10
- * import { streamOrigen } from "@moikapy/origen";
11
- * import { allBibleTools, buildScholarPrompt } from "@moikapy/scholar-tools";
12
- *
13
- * const config = {
14
- * systemPrompt: buildScholarPrompt(),
15
- * tools: allBibleTools(),
16
- * getD1: async () => myD1,
17
- * model: "openrouter/free",
18
- * getApiKey: async (provider) => resolveKey(provider),
19
- * };
20
- */
21
-
22
- export type {
23
- D1Like,
24
- D1Provider,
25
- ReadingContext,
26
- Citation,
27
- UsageInfo,
28
- ModelConfig as OrigenModelConfig,
29
- } from "./types";
30
-
31
- export {
32
- MODELS,
33
- DEFAULT_MODEL_ID,
34
- DEFAULT_MODEL,
35
- THINKING_MODELS,
36
- supportsThinking,
37
- isOllamaModel,
38
- getModelsByProvider,
39
- getModelsForUI,
40
- type ModelId,
41
- type ModelConfig,
42
- type UIModelConfig,
43
- } from "./models";
44
-
45
- export {
46
- streamOrigen,
47
- callOrigen,
48
- checkAuth,
49
- checkOpenRouterAuth,
50
- type AgentConfig,
51
- type OrigenTool,
52
- type AuthCheckResult,
53
- type AgentResponse,
54
- type StreamEvent,
55
- } from "./agent";
56
-
57
- export { resolveModel, createEventStream } from "./adapter";
58
- export type { ModelResolutionOptions } from "./adapter";
package/src/models.ts DELETED
@@ -1,143 +0,0 @@
1
- /**
2
- * Origen model configuration.
3
- *
4
- * Delegates to pi-ai's model registry for known providers (OpenRouter, Anthropic, Google, etc.)
5
- * Plus custom entries for Ollama and free-tier aliases.
6
- */
7
-
8
- import { getModel } from "@mariozechner/pi-ai";
9
- import type { Model, Api } from "@mariozechner/pi-ai";
10
- export type { Model as ProviderModel, Api } from "@mariozechner/pi-ai";
11
-
12
- // ── Model registry ────────────────────────────────────────────────────
13
-
14
- export interface ModelConfig {
15
- name: string;
16
- description: string;
17
- free: boolean;
18
- }
19
-
20
- /** UI-facing model config — safe to send to the client. Strips internal fields. */
21
- export type UIModelConfig = ModelConfig;
22
-
23
- /** Get models as a simple UI map (name, description, free). No internal fields. */
24
- export function getModelsForUI(): Record<string, UIModelConfig> {
25
- const uiModels: Record<string, UIModelConfig> = {};
26
- for (const [id, config] of Object.entries(MODELS)) {
27
- uiModels[id] = { name: config.name, description: config.description, free: config.free };
28
- }
29
- return uiModels;
30
- }
31
-
32
- // Build MODELS map from pi-ai registry + custom entries
33
- function buildModels(): Record<string, ModelConfig> {
34
- const models: Record<string, ModelConfig> = {};
35
-
36
- // ── OpenRouter (free tier) ───────────────────────────
37
- models["openrouter/free"] = {
38
- name: "Free (Auto)",
39
- description: "Free — auto-selects best free model for your request",
40
- free: true,
41
- };
42
- models["google/gemma-4-31b-it:free"] = {
43
- name: "Gemma 4 31B",
44
- description: "Free — great quality for Bible study",
45
- free: true,
46
- };
47
- models["nvidia/nemotron-3-super-120b-a12b:free"] = {
48
- name: "Nemotron 3 Super",
49
- description: "Free — large model, strong reasoning",
50
- free: true,
51
- };
52
- models["deepseek/deepseek-r1:free"] = {
53
- name: "DeepSeek R1 (Free)",
54
- description: "Free — reasoning with thinking support",
55
- free: true,
56
- };
57
-
58
- models["qwen/qwen3-coder:free"] = {
59
- name: "Qwen3 Coder",
60
- description: "Free — 480B parameters, excellent tool use",
61
- free: true,
62
- };
63
-
64
- // ── OpenRouter (premium) ─────────────────────────────
65
- models["openrouter/auto"] = {
66
- name: "Auto (All)",
67
- description: "Auto-selects best model (requires credits)",
68
- free: false,
69
- };
70
- models["anthropic/claude-sonnet-4"] = {
71
- name: "Claude Sonnet 4",
72
- description: "Premium — excellent quality + reasoning (requires credits)",
73
- free: false,
74
- };
75
- models["google/gemini-2.5-flash-preview"] = {
76
- name: "Gemini 2.5 Flash",
77
- description: "Premium — fast with thinking (requires credits)",
78
- free: false,
79
- };
80
-
81
- // ── Ollama (local, always free) ──────────────────────
82
- models["ollama/llama3"] = {
83
- name: "Llama 3 (Ollama)",
84
- description: "Local — Meta's Llama 3, requires Ollama",
85
- free: true,
86
- };
87
- models["ollama/gemma3"] = {
88
- name: "Gemma 3 (Ollama)",
89
- description: "Local — Google's Gemma 3, requires Ollama",
90
- free: true,
91
- };
92
- models["ollama/mistral"] = {
93
- name: "Mistral (Ollama)",
94
- description: "Local — Mistral's 7B model, requires Ollama",
95
- free: true,
96
- };
97
- models["ollama/qwen3"] = {
98
- name: "Qwen 3 (Ollama)",
99
- description: "Local — Alibaba's Qwen 3, requires Ollama",
100
- free: true,
101
- };
102
- models["ollama/deepseek-r1"] = {
103
- name: "DeepSeek R1 (Ollama)",
104
- description: "Local — reasoning model, requires Ollama",
105
- free: true,
106
- };
107
-
108
- return models;
109
- }
110
-
111
- export const MODELS: Record<string, ModelConfig> = buildModels();
112
- export type ModelId = keyof typeof MODELS;
113
-
114
- /** Default model — free router, works with $0 credits */
115
- export const DEFAULT_MODEL_ID: ModelId = "openrouter/free";
116
-
117
- /** Backward compat alias */
118
- export const DEFAULT_MODEL: ModelId = DEFAULT_MODEL_ID;
119
-
120
- /** Models that support extended thinking */
121
- export const THINKING_MODELS: ReadonlySet<ModelId> = new Set<ModelId>([
122
- "anthropic/claude-sonnet-4",
123
- "deepseek/deepseek-r1:free",
124
- "google/gemini-2.5-flash-preview",
125
- "ollama/deepseek-r1",
126
- ]);
127
-
128
- /** Check if a model supports extended thinking */
129
- export function supportsThinking(model: ModelId): boolean {
130
- return THINKING_MODELS.has(model);
131
- }
132
-
133
- /** Check if a model is an Ollama model */
134
- export function isOllamaModel(model: ModelId): boolean {
135
- return (model as string).startsWith("ollama/");
136
- }
137
-
138
- /** Get all model IDs for a specific provider prefix */
139
- export function getModelsByProvider(provider: string): ModelId[] {
140
- return (Object.keys(MODELS) as ModelId[]).filter((id) =>
141
- (id as string).startsWith(`${provider}/`)
142
- );
143
- }
package/src/types.ts DELETED
@@ -1,59 +0,0 @@
1
- /**
2
- * Origen types — no runtime deps, safe for client + server.
3
- */
4
-
5
- /** D1-compatible database interface for tool execution */
6
- export interface D1Like {
7
- prepare(sql: string): {
8
- bind(...params: unknown[]): {
9
- all(): Promise<{ results?: Record<string, unknown>[] }>;
10
- first(): Promise<Record<string, unknown> | null>;
11
- run(): Promise<{ meta?: { changes: number; last_row_id: number } }>;
12
- };
13
- };
14
- }
15
-
16
- /** Function that provides a D1 instance to tool executors */
17
- export type D1Provider = () => Promise<D1Like>;
18
-
19
- /** Chat context passed from the UI (what the user is reading) */
20
- export interface ReadingContext {
21
- translation: string;
22
- bookCode: string;
23
- chapter: number;
24
- selectedVerses?: number[];
25
- }
26
-
27
- /** Agent message with optional metadata */
28
- export interface AgentMessage {
29
- role: "user" | "assistant" | "system";
30
- content: string;
31
- }
32
-
33
- /** SSE events streamed from the agent to the UI */
34
- export type StreamEvent =
35
- | { type: "thinking"; content: string }
36
- | { type: "tool_call"; name: string; args: Record<string, unknown> }
37
- | { type: "tool_result"; name: string; result: string }
38
- | { type: "text"; content: string }
39
- | { type: "done"; message: string; citations: Citation[]; usage?: UsageInfo }
40
- | { type: "error"; message: string };
41
-
42
- export interface Citation {
43
- book: string;
44
- chapter: number;
45
- verse: number;
46
- }
47
-
48
- export interface UsageInfo {
49
- promptTokens?: number;
50
- completionTokens?: number;
51
- totalCost?: number;
52
- }
53
-
54
- /** Model configuration entry */
55
- export interface ModelConfig {
56
- name: string;
57
- description: string;
58
- free: boolean;
59
- }