@sahan-sac/ai-core 0.3.0 → 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/CHANGELOG.md +21 -0
- package/README.md +123 -120
- package/dist/adapters.d.ts +1 -1
- package/dist/adapters.js +17 -609
- package/dist/availability.js +9 -458
- package/dist/chunk-BK4B76LD.js +621 -0
- package/dist/chunk-BL4J2JNX.js +48 -0
- package/dist/chunk-MRNQPHWI.js +194 -0
- package/dist/chunk-PMC3UWQ2.js +10 -0
- package/dist/chunk-RBSLNDFW.js +61 -0
- package/dist/chunk-SI7JE5BG.js +126 -0
- package/dist/env.d.ts +13 -0
- package/dist/env.js +6 -102
- package/dist/image.js +14 -236
- package/dist/index.js +5 -102
- package/dist/log.js +3 -6
- package/dist/models.js +9 -51
- package/dist/providers.d.ts +31 -1
- package/dist/providers.js +22 -582
- package/dist/vertex.js +4 -43
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @sahan-sac/ai-core
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 396e692: Three more free-tier adapters:
|
|
8
|
+
- `groq`: Groq free plan, keyed by `GROQ_API_KEY`. Default models `openai/gpt-oss-120b` for the blog and `openai/gpt-oss-20b` for chat.
|
|
9
|
+
- `mistral`: Mistral free Experiment plan, keyed by `MISTRAL_API_KEY`. This plan may train on prompts, so the adapter runs in the blog chain only unless `AI_PROVIDER_ORDER_CHAT` lists it.
|
|
10
|
+
- `cloudflare`: Cloudflare Workers AI, with 10,000 free neurons a day. Needs `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_AI_API_TOKEN`.
|
|
11
|
+
|
|
12
|
+
None of them is paid, so none needs `AI_ALLOW_PAID`. Each model can be overridden per purpose. Adapters gain an optional `defaultPurposes`.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 1570cf6: A provider that answers 402 (no credits, or an empty prepaid wallet) now cools down for 30 minutes instead of being retried on every request, so an unfunded account costs one probe per window rather than a failed round trip each time. `cooldownFor` is exported.
|
|
17
|
+
|
|
18
|
+
## 0.3.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 5e7f3cb: The build shares modules between subpaths (code splitting) instead of copying them into each one. Before, a class imported from two subpaths was two different classes, so `instanceof` failed (for example `EmailGuardError` from `@sahan-sac/email-kit/guards` against an error thrown through `./layout`), and module-level state such as caches existed once per subpath.
|
|
23
|
+
|
|
3
24
|
## 0.3.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,120 +1,123 @@
|
|
|
1
|
-
# @sahan-sac/ai-core
|
|
2
|
-
|
|
3
|
-
The AI layer shared by `@sahan-sac/blog-kit` and `@sahan-sac/chat-kit`: a free-by-default provider chain with automatic fallback, a provider registry you can configure and extend from the environment, model resolution, image generation (NVIDIA FLUX, then paid Gemini/Vertex), and prompt-injection guards.
|
|
4
|
-
|
|
5
|
-
Headless and framework-agnostic: no Prisma, no Next.js APIs, no React. Everything takes a parsed env or config object; only `aiEnvFromProcess()` reads `process.env`.
|
|
6
|
-
|
|
7
|
-
## How a request is answered
|
|
8
|
-
|
|
9
|
-
Two patterns, kept separate:
|
|
10
|
-
|
|
11
|
-
- **Adapters.** Every provider is wrapped as an `AiProvider` with one `generate(prompt, options)` that returns `{ ok: true, text }` or a classified failure (`http_429`, `timeout`, `truncated`, `invalid_output`, ...). It never throws. Built in: Gemini, OpenRouter (two keys), NVIDIA, OpenAI, Anthropic (Claude), DeepSeek, xAI (Grok), Perplexity, one custom OpenAI-compatible endpoint (vLLM, Ollama, LiteLLM, a gateway), and Vertex AI.
|
|
12
|
-
- **Chain of responsibility.** `createAiService({ providers })` hands the prompt to the first provider. On any retryable failure it passes the prompt to the next one, until one answers, a non-retryable failure stops it, the deadline passes, or the caller aborts. On top of that:
|
|
13
|
-
- a provider that timed out or was rate limited cools down and moves behind the healthy ones;
|
|
14
|
-
- optional hedging starts the next provider while a slow one is still running, and the first valid answer wins;
|
|
15
|
-
- an `accept` check turns a malformed reply into a failure, so the chain moves on.
|
|
16
|
-
|
|
17
|
-
The registry (`@sahan-sac/ai-core/adapters`) decides which adapters form a chain and in what order:
|
|
18
|
-
|
|
19
|
-
1. `AI_PROVIDER_ORDER_BLOG` or `AI_PROVIDER_ORDER_CHAT` for that purpose, else `AI_PROVIDER_ORDER`, else the default order: `gemini, openrouter, openrouter-2, nvidia, openai, anthropic, deepseek, xai, perplexity, custom, vertex`.
|
|
20
|
-
2. An adapter runs only when its variables are set. A paid adapter also needs `AI_ALLOW_PAID=true`, even when it is listed.
|
|
21
|
-
3. **Explicit order:** only the listed ids run, in that order. Speed never reorders them; cooling still does.
|
|
22
|
-
4. **Default order:** paid adapters are last resorts, and the free ones are reordered by observed speed.
|
|
23
|
-
|
|
24
|
-
## Subpaths
|
|
25
|
-
|
|
26
|
-
| Import | What |
|
|
27
|
-
| --- | --- |
|
|
28
|
-
| `@sahan-sac/ai-core/env` | `aiEnvSchema` (zod), `parseAiEnv(source)`, `aiEnvFromProcess()`, `AiEnv` |
|
|
29
|
-
| `@sahan-sac/ai-core/adapters` | `BUILTIN_ADAPTERS`, `ProviderAdapter`, `realProviders(env, purpose, fetch?, adapters?)`, `chainPlan`, `providerStatuses` (why each adapter is in or out, for health screens), `checkProvider` / `checkChain` (manual checks), `configuredOrder`, `PAID_TEXT_MODELS` |
|
|
30
|
-
| `@sahan-sac/ai-core/providers` | `createAiService` (the chain), `sharedAiHealth`, `realProviders` (re-exported), the provider factories: `geminiProvider`, `openRouterProvider`, `nvidiaProvider`, `openAiCompatibleProvider`, `anthropicProvider`, `vertexProvider` |
|
|
31
|
-
| `@sahan-sac/ai-core/availability` | `textAiConfigured(env, purpose?)`, `blogAiEnabled`, `blogAiImagesEnabled`, `chatbotEnabled` |
|
|
32
|
-
| `@sahan-sac/ai-core/models` | `textModels`, `imageModels`, verified free defaults, `paidAllowed`, `vertexConfigured` |
|
|
33
|
-
| `@sahan-sac/ai-core/image` | `imageConfigFromEnv`, `generateImage` |
|
|
34
|
-
| `@sahan-sac/ai-core/vertex` | `getVertexAccessToken` (service-account JWT exchange, cached) |
|
|
35
|
-
| `@sahan-sac/ai-core/guard` | `wrapUserData(text, maxLength?)`, `guidanceSection`, `mergeGuidance`, `looksLikeLeak`, `ModelPrompt` |
|
|
36
|
-
| `@sahan-sac/ai-core/log` | `AiLogger`, `consoleAiLogger` |
|
|
37
|
-
|
|
38
|
-
`providers`, `adapters`, `image` and `vertex` reach `server-only` code: use them from server code only.
|
|
39
|
-
|
|
40
|
-
## Environment
|
|
41
|
-
|
|
42
|
-
Spread the schema into your own env module so the names never drift:
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
import { aiEnvSchema } from "@sahan-sac/ai-core/env";
|
|
46
|
-
|
|
47
|
-
const schema = z.object({ ...aiEnvSchema.shape, DATABASE_URL: z.string() });
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
| Variable | Default | Meaning |
|
|
51
|
-
| --- | --- | --- |
|
|
52
|
-
| `ENABLE_BLOG_AI` | `false` | Blog AI assistant (also needs a blog text provider) |
|
|
53
|
-
| `ENABLE_CHATBOT` | `true` | Chatbot (also needs a chat text provider); `false`/`0`/`no`/`off` turns it off |
|
|
54
|
-
| `AI_ALLOW_PAID` | `false` | Lets paid providers join the chains: OpenAI, Anthropic, DeepSeek, xAI, Perplexity, the custom endpoint (unless `AI_CUSTOM_FREE`), Vertex text and images, Gemini images |
|
|
55
|
-
| `AI_PROVIDER_ORDER`, `AI_PROVIDER_ORDER_BLOG`, `AI_PROVIDER_ORDER_CHAT` | built-in order | Comma-separated adapter ids; only the listed ones run, in that order |
|
|
56
|
-
| `GEMINI_API_KEY`, `OPENROUTER_API_KEY`, `OPENROUTER_API_KEY_2`, `NVIDIA_API_KEY` | unset | Free text providers; `NVIDIA_API_KEY` is also the free image provider |
|
|
57
|
-
| `OPENROUTER_BASE_URL`, `OPENROUTER_ALLOW_PAID_MODELS` | OpenRouter API, `false` | OpenRouter settings |
|
|
58
|
-
| `OPENAI_API_KEY`, `OPENAI_BASE_URL` | unset, OpenAI API | OpenAI (paid); the base URL also points it at any OpenAI-compatible gateway |
|
|
59
|
-
| `ANTHROPIC_API_KEY`, `ANTHROPIC_BASE_URL` | unset, Anthropic API | Anthropic Messages API over REST (paid) |
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
# @sahan-sac/ai-core
|
|
2
|
+
|
|
3
|
+
The AI layer shared by `@sahan-sac/blog-kit` and `@sahan-sac/chat-kit`: a free-by-default provider chain with automatic fallback, a provider registry you can configure and extend from the environment, model resolution, image generation (NVIDIA FLUX, then paid Gemini/Vertex), and prompt-injection guards.
|
|
4
|
+
|
|
5
|
+
Headless and framework-agnostic: no Prisma, no Next.js APIs, no React. Everything takes a parsed env or config object; only `aiEnvFromProcess()` reads `process.env`.
|
|
6
|
+
|
|
7
|
+
## How a request is answered
|
|
8
|
+
|
|
9
|
+
Two patterns, kept separate:
|
|
10
|
+
|
|
11
|
+
- **Adapters.** Every provider is wrapped as an `AiProvider` with one `generate(prompt, options)` that returns `{ ok: true, text }` or a classified failure (`http_429`, `timeout`, `truncated`, `invalid_output`, ...). It never throws. Built in: Gemini, OpenRouter (two keys), NVIDIA, OpenAI, Anthropic (Claude), DeepSeek, xAI (Grok), Perplexity, one custom OpenAI-compatible endpoint (vLLM, Ollama, LiteLLM, a gateway), and Vertex AI.
|
|
12
|
+
- **Chain of responsibility.** `createAiService({ providers })` hands the prompt to the first provider. On any retryable failure it passes the prompt to the next one, until one answers, a non-retryable failure stops it, the deadline passes, or the caller aborts. On top of that:
|
|
13
|
+
- a provider that timed out or was rate limited cools down and moves behind the healthy ones;
|
|
14
|
+
- optional hedging starts the next provider while a slow one is still running, and the first valid answer wins;
|
|
15
|
+
- an `accept` check turns a malformed reply into a failure, so the chain moves on.
|
|
16
|
+
|
|
17
|
+
The registry (`@sahan-sac/ai-core/adapters`) decides which adapters form a chain and in what order:
|
|
18
|
+
|
|
19
|
+
1. `AI_PROVIDER_ORDER_BLOG` or `AI_PROVIDER_ORDER_CHAT` for that purpose, else `AI_PROVIDER_ORDER`, else the default order: `gemini, openrouter, openrouter-2, nvidia, openai, anthropic, deepseek, xai, perplexity, custom, vertex`.
|
|
20
|
+
2. An adapter runs only when its variables are set. A paid adapter also needs `AI_ALLOW_PAID=true`, even when it is listed.
|
|
21
|
+
3. **Explicit order:** only the listed ids run, in that order. Speed never reorders them; cooling still does.
|
|
22
|
+
4. **Default order:** paid adapters are last resorts, and the free ones are reordered by observed speed.
|
|
23
|
+
|
|
24
|
+
## Subpaths
|
|
25
|
+
|
|
26
|
+
| Import | What |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `@sahan-sac/ai-core/env` | `aiEnvSchema` (zod), `parseAiEnv(source)`, `aiEnvFromProcess()`, `AiEnv` |
|
|
29
|
+
| `@sahan-sac/ai-core/adapters` | `BUILTIN_ADAPTERS`, `ProviderAdapter`, `realProviders(env, purpose, fetch?, adapters?)`, `chainPlan`, `providerStatuses` (why each adapter is in or out, for health screens), `checkProvider` / `checkChain` (manual checks), `configuredOrder`, `PAID_TEXT_MODELS` |
|
|
30
|
+
| `@sahan-sac/ai-core/providers` | `createAiService` (the chain), `sharedAiHealth`, `realProviders` (re-exported), the provider factories: `geminiProvider`, `openRouterProvider`, `nvidiaProvider`, `openAiCompatibleProvider`, `anthropicProvider`, `vertexProvider` |
|
|
31
|
+
| `@sahan-sac/ai-core/availability` | `textAiConfigured(env, purpose?)`, `blogAiEnabled`, `blogAiImagesEnabled`, `chatbotEnabled` |
|
|
32
|
+
| `@sahan-sac/ai-core/models` | `textModels`, `imageModels`, verified free defaults, `paidAllowed`, `vertexConfigured` |
|
|
33
|
+
| `@sahan-sac/ai-core/image` | `imageConfigFromEnv`, `generateImage` |
|
|
34
|
+
| `@sahan-sac/ai-core/vertex` | `getVertexAccessToken` (service-account JWT exchange, cached) |
|
|
35
|
+
| `@sahan-sac/ai-core/guard` | `wrapUserData(text, maxLength?)`, `guidanceSection`, `mergeGuidance`, `looksLikeLeak`, `ModelPrompt` |
|
|
36
|
+
| `@sahan-sac/ai-core/log` | `AiLogger`, `consoleAiLogger` |
|
|
37
|
+
|
|
38
|
+
`providers`, `adapters`, `image` and `vertex` reach `server-only` code: use them from server code only.
|
|
39
|
+
|
|
40
|
+
## Environment
|
|
41
|
+
|
|
42
|
+
Spread the schema into your own env module so the names never drift:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { aiEnvSchema } from "@sahan-sac/ai-core/env";
|
|
46
|
+
|
|
47
|
+
const schema = z.object({ ...aiEnvSchema.shape, DATABASE_URL: z.string() });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
| Variable | Default | Meaning |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| `ENABLE_BLOG_AI` | `false` | Blog AI assistant (also needs a blog text provider) |
|
|
53
|
+
| `ENABLE_CHATBOT` | `true` | Chatbot (also needs a chat text provider); `false`/`0`/`no`/`off` turns it off |
|
|
54
|
+
| `AI_ALLOW_PAID` | `false` | Lets paid providers join the chains: OpenAI, Anthropic, DeepSeek, xAI, Perplexity, the custom endpoint (unless `AI_CUSTOM_FREE`), Vertex text and images, Gemini images |
|
|
55
|
+
| `AI_PROVIDER_ORDER`, `AI_PROVIDER_ORDER_BLOG`, `AI_PROVIDER_ORDER_CHAT` | built-in order | Comma-separated adapter ids; only the listed ones run, in that order |
|
|
56
|
+
| `GEMINI_API_KEY`, `OPENROUTER_API_KEY`, `OPENROUTER_API_KEY_2`, `NVIDIA_API_KEY` | unset | Free text providers; `NVIDIA_API_KEY` is also the free image provider |
|
|
57
|
+
| `OPENROUTER_BASE_URL`, `OPENROUTER_ALLOW_PAID_MODELS` | OpenRouter API, `false` | OpenRouter settings |
|
|
58
|
+
| `OPENAI_API_KEY`, `OPENAI_BASE_URL` | unset, OpenAI API | OpenAI (paid); the base URL also points it at any OpenAI-compatible gateway |
|
|
59
|
+
| `ANTHROPIC_API_KEY`, `ANTHROPIC_BASE_URL` | unset, Anthropic API | Anthropic Messages API over REST (paid) |
|
|
60
|
+
| `GROQ_API_KEY` | unset | Groq free plan (no card). Models `openai/gpt-oss-120b` (blog) and `openai/gpt-oss-20b` (chat); override with `GROQ_MODEL` or `BLOG_`/`CHAT_` variants |
|
|
61
|
+
| `MISTRAL_API_KEY` | unset | Mistral free (Experiment) plan, which may train on prompts. Blog chain only, unless `AI_PROVIDER_ORDER_CHAT` lists `mistral` |
|
|
62
|
+
| `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_AI_API_TOKEN` | unset | Cloudflare Workers AI, 10,000 free neurons a day. Models `@cf/openai/gpt-oss-120b` / `-20b`; override with `CLOUDFLARE_AI_MODEL` |
|
|
63
|
+
| `DEEPSEEK_API_KEY`, `XAI_API_KEY`, `PERPLEXITY_API_KEY` | unset | Paid OpenAI-compatible providers |
|
|
64
|
+
| `AI_CUSTOM_BASE_URL`, `AI_CUSTOM_MODEL`, `AI_CUSTOM_API_KEY`, `AI_CUSTOM_NAME`, `AI_CUSTOM_FREE` | unset, `false` | One custom OpenAI-compatible endpoint. The key is optional for a local server. Paid unless `AI_CUSTOM_FREE=true` |
|
|
65
|
+
| `GOOGLE_CLIENT_EMAIL`, `GOOGLE_PRIVATE_KEY`, `GOOGLE_CLOUD_PROJECT` | unset | Vertex service account (paid). Keep the key on one line with literal `\n` |
|
|
66
|
+
| `GOOGLE_TOKEN_URI` | Google's token endpoint | Override only for testing |
|
|
67
|
+
| `BLOG_<P>_MODEL`, `CHAT_<P>_MODEL`, `<P>_MODEL` | built-in defaults | Model per provider `<P>` (`GEMINI`, `OPENROUTER`, `NVIDIA`, `VERTEX`, `OPENAI`, `ANTHROPIC`, `DEEPSEEK`, `XAI`, `PERPLEXITY`): purpose variable, then provider-wide, then default. Paid-provider names change often, so set them |
|
|
68
|
+
| `IMAGE_*_MODEL`, `IMAGEN_MODEL` | verified free defaults | Image models |
|
|
69
|
+
|
|
70
|
+
## Example
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { chatbotEnabled } from "@sahan-sac/ai-core/availability";
|
|
74
|
+
import { aiEnvFromProcess } from "@sahan-sac/ai-core/env";
|
|
75
|
+
import { createAiService, realProviders, sharedAiHealth } from "@sahan-sac/ai-core/providers";
|
|
76
|
+
|
|
77
|
+
const env = aiEnvFromProcess();
|
|
78
|
+
if (chatbotEnabled(env)) {
|
|
79
|
+
const ai = createAiService({ providers: realProviders(env, "chat"), health: sharedAiHealth, timeoutMs: 12_000, deadlineMs: 20_000 });
|
|
80
|
+
const result = await ai.generate({ system: "You are helpful.", user: "Hello" }, { maxTokens: 200, signal: request.signal });
|
|
81
|
+
// result.provider: who answered; result.attempts: every provider tried, with its error class.
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Pass the request's `signal` so a client that disconnects stops the chain: every running attempt is aborted, no further provider starts, and the result is `{ ok: false, errorClass: "aborted" }`. An aborted attempt is not logged or cooled down.
|
|
86
|
+
|
|
87
|
+
## Your own adapter
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { BUILTIN_ADAPTERS, realProviders, type ProviderAdapter } from "@sahan-sac/ai-core/adapters";
|
|
91
|
+
import { openAiCompatibleProvider } from "@sahan-sac/ai-core/providers";
|
|
92
|
+
|
|
93
|
+
const groq: ProviderAdapter = {
|
|
94
|
+
id: "groq",
|
|
95
|
+
label: "Groq",
|
|
96
|
+
paid: () => false,
|
|
97
|
+
missing: () => (process.env.GROQ_API_KEY ? [] : ["GROQ_API_KEY"]),
|
|
98
|
+
create: ({ fetch }) =>
|
|
99
|
+
openAiCompatibleProvider({ name: "groq", apiKey: process.env.GROQ_API_KEY!, baseUrl: "https://api.groq.com/openai/v1", model: "llama-3.3-70b-versatile", fetch }),
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const providers = realProviders(env, "chat", undefined, [...BUILTIN_ADAPTERS, groq]);
|
|
103
|
+
// Default order: the built-ins, then groq. Or list it: AI_PROVIDER_ORDER=groq,gemini
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
For a settings screen, `providerStatuses(env, purpose)` reports each adapter's state: `active` (with its position), `not_configured` (with the missing variable names, never values), `needs_paid`, `not_in_order` or `unknown`.
|
|
107
|
+
|
|
108
|
+
## Manual checks
|
|
109
|
+
|
|
110
|
+
Reachability for an AI provider means a real prompt, which spends tokens, so run it only when an operator asks:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { checkChain, checkProvider } from "@sahan-sac/ai-core/adapters";
|
|
114
|
+
|
|
115
|
+
await checkProvider(env, "anthropic"); // { id, ok, provider, ms } or { ok: false, errorClass: "http_401", ... }
|
|
116
|
+
await checkChain(env, "blog"); // the whole chain once: who answered, and `attempts` for every fall-through
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`checkProvider` ignores the order and `AI_ALLOW_PAID` (the operator asked for that provider) and answers `not_configured` without a call when a variable is missing. `checkChain` uses a fresh health record, so a failed check never cools a provider down for real traffic.
|
|
120
|
+
|
|
121
|
+
## Owner guidance
|
|
122
|
+
|
|
123
|
+
`guidanceSection(text)` appends the site owner's standing guidance (voice, facts, do and don't) after a prompt's fixed rules; it returns `""` for empty text and caps the length. `mergeGuidance(global, perFeature)` joins the layers. Guidance steers the model but never overrides the rules above it or how fenced data is treated.
|
package/dist/adapters.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './env.js';
|
|
2
2
|
import './models.js';
|
|
3
|
-
export { A as AdapterContext, a as AdapterState, b as AdapterStatus, B as BUILTIN_ADAPTERS, C as CHECK_PROMPT, D as DEFAULT_ORDER, P as PAID_TEXT_MODELS, c as ProviderAdapter, d as ProviderCheck, e as chainPlan, f as checkChain, g as checkProvider, h as configuredOrder, p as providerStatuses, realProviders } from './providers.js';
|
|
3
|
+
export { A as AdapterContext, a as AdapterState, b as AdapterStatus, B as BUILTIN_ADAPTERS, C as CHECK_PROMPT, D as DEFAULT_ORDER, F as FREE_TEXT_MODELS, P as PAID_TEXT_MODELS, c as ProviderAdapter, d as ProviderCheck, e as chainPlan, f as checkChain, g as checkProvider, h as configuredOrder, p as providerStatuses, realProviders } from './providers.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import './guard.js';
|
|
6
6
|
import './log.js';
|