@draht/ai 2026.3.2-7 → 2026.3.2-8
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/README.md +28 -28
- package/dist/models.generated.d.ts +0 -17
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.generated.js +2 -19
- package/dist/models.generated.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @draht/ai
|
|
2
2
|
|
|
3
3
|
Unified LLM API with automatic model discovery, provider configuration, token and cost tracking, and simple context persistence and hand-off to other models mid-session.
|
|
4
4
|
|
|
@@ -69,15 +69,15 @@ Unified LLM API with automatic model discovery, provider configuration, token an
|
|
|
69
69
|
## Installation
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
|
|
72
|
+
bun add @draht/ai
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
TypeBox exports are re-exported from `@
|
|
75
|
+
TypeBox exports are re-exported from `@draht/ai`: `Type`, `Static`, and `TSchema`.
|
|
76
76
|
|
|
77
77
|
## Quick Start
|
|
78
78
|
|
|
79
79
|
```typescript
|
|
80
|
-
import { Type, getModel, stream, complete, Context, Tool, StringEnum } from '@
|
|
80
|
+
import { Type, getModel, stream, complete, Context, Tool, StringEnum } from '@draht/ai';
|
|
81
81
|
|
|
82
82
|
// Fully typed with auto-complete support for both providers and models
|
|
83
83
|
const model = getModel('openai', 'gpt-4o-mini');
|
|
@@ -203,7 +203,7 @@ Tools enable LLMs to interact with external systems. This library uses TypeBox s
|
|
|
203
203
|
### Defining Tools
|
|
204
204
|
|
|
205
205
|
```typescript
|
|
206
|
-
import { Type, Tool, StringEnum } from '@
|
|
206
|
+
import { Type, Tool, StringEnum } from '@draht/ai';
|
|
207
207
|
|
|
208
208
|
// Define tool parameters with TypeBox
|
|
209
209
|
const weatherTool: Tool = {
|
|
@@ -329,7 +329,7 @@ When using `agentLoop`, tool arguments are automatically validated against your
|
|
|
329
329
|
When implementing your own tool execution loop with `stream()` or `complete()`, use `validateToolCall` to validate arguments before passing them to your tools:
|
|
330
330
|
|
|
331
331
|
```typescript
|
|
332
|
-
import { stream, validateToolCall, Tool } from '@
|
|
332
|
+
import { stream, validateToolCall, Tool } from '@draht/ai';
|
|
333
333
|
|
|
334
334
|
const tools: Tool[] = [weatherTool, calculatorTool];
|
|
335
335
|
const s = stream(model, { messages, tools });
|
|
@@ -383,7 +383,7 @@ Models with vision capabilities can process images. You can check if a model sup
|
|
|
383
383
|
|
|
384
384
|
```typescript
|
|
385
385
|
import { readFileSync } from 'fs';
|
|
386
|
-
import { getModel, complete } from '@
|
|
386
|
+
import { getModel, complete } from '@draht/ai';
|
|
387
387
|
|
|
388
388
|
const model = getModel('openai', 'gpt-4o-mini');
|
|
389
389
|
|
|
@@ -420,7 +420,7 @@ Many models support thinking/reasoning capabilities where they can show their in
|
|
|
420
420
|
### Unified Interface (streamSimple/completeSimple)
|
|
421
421
|
|
|
422
422
|
```typescript
|
|
423
|
-
import { getModel, streamSimple, completeSimple } from '@
|
|
423
|
+
import { getModel, streamSimple, completeSimple } from '@draht/ai';
|
|
424
424
|
|
|
425
425
|
// Many models across providers support thinking/reasoning
|
|
426
426
|
const model = getModel('anthropic', 'claude-sonnet-4-20250514');
|
|
@@ -458,7 +458,7 @@ for (const block of response.content) {
|
|
|
458
458
|
For fine-grained control, use the provider-specific options:
|
|
459
459
|
|
|
460
460
|
```typescript
|
|
461
|
-
import { getModel, complete } from '@
|
|
461
|
+
import { getModel, complete } from '@draht/ai';
|
|
462
462
|
|
|
463
463
|
// OpenAI Reasoning (o1, o3, gpt-5)
|
|
464
464
|
const openaiModel = getModel('openai', 'gpt-5-mini');
|
|
@@ -545,7 +545,7 @@ if (message.stopReason === 'error' || message.stopReason === 'aborted') {
|
|
|
545
545
|
The abort signal allows you to cancel in-progress requests. Aborted requests have `stopReason === 'aborted'`:
|
|
546
546
|
|
|
547
547
|
```typescript
|
|
548
|
-
import { getModel, stream } from '@
|
|
548
|
+
import { getModel, stream } from '@draht/ai';
|
|
549
549
|
|
|
550
550
|
const model = getModel('openai', 'gpt-4o-mini');
|
|
551
551
|
const controller = new AbortController();
|
|
@@ -641,7 +641,7 @@ A **provider** offers models through a specific API. For example:
|
|
|
641
641
|
### Querying Providers and Models
|
|
642
642
|
|
|
643
643
|
```typescript
|
|
644
|
-
import { getProviders, getModels, getModel } from '@
|
|
644
|
+
import { getProviders, getModels, getModel } from '@draht/ai';
|
|
645
645
|
|
|
646
646
|
// Get all available providers
|
|
647
647
|
const providers = getProviders();
|
|
@@ -667,7 +667,7 @@ console.log(`Using ${model.name} via ${model.api} API`);
|
|
|
667
667
|
You can create custom models for local inference servers or custom endpoints:
|
|
668
668
|
|
|
669
669
|
```typescript
|
|
670
|
-
import { Model, stream } from '@
|
|
670
|
+
import { Model, stream } from '@draht/ai';
|
|
671
671
|
|
|
672
672
|
// Example: Ollama using OpenAI-compatible API
|
|
673
673
|
const ollamaModel: Model<'openai-completions'> = {
|
|
@@ -761,7 +761,7 @@ If `compat` is not set, the library falls back to URL-based detection. If `compa
|
|
|
761
761
|
Models are typed by their API, which keeps the model metadata accurate. Provider-specific option types are enforced when you call the provider functions directly. The generic `stream` and `complete` functions accept `StreamOptions` with additional provider fields.
|
|
762
762
|
|
|
763
763
|
```typescript
|
|
764
|
-
import { streamAnthropic, type AnthropicOptions } from '@
|
|
764
|
+
import { streamAnthropic, type AnthropicOptions } from '@draht/ai';
|
|
765
765
|
|
|
766
766
|
// TypeScript knows this is an Anthropic model
|
|
767
767
|
const claude = getModel('anthropic', 'claude-sonnet-4-20250514');
|
|
@@ -790,7 +790,7 @@ When messages from one provider are sent to a different provider, the library au
|
|
|
790
790
|
### Example: Multi-Provider Conversation
|
|
791
791
|
|
|
792
792
|
```typescript
|
|
793
|
-
import { getModel, complete, Context } from '@
|
|
793
|
+
import { getModel, complete, Context } from '@draht/ai';
|
|
794
794
|
|
|
795
795
|
// Start with Claude
|
|
796
796
|
const claude = getModel('anthropic', 'claude-sonnet-4-20250514');
|
|
@@ -835,7 +835,7 @@ This enables flexible workflows where you can:
|
|
|
835
835
|
The `Context` object can be easily serialized and deserialized using standard JSON methods, making it simple to persist conversations, implement chat history, or transfer contexts between services:
|
|
836
836
|
|
|
837
837
|
```typescript
|
|
838
|
-
import { Context, getModel, complete } from '@
|
|
838
|
+
import { Context, getModel, complete } from '@draht/ai';
|
|
839
839
|
|
|
840
840
|
// Create and use a context
|
|
841
841
|
const context: Context = {
|
|
@@ -872,7 +872,7 @@ const continuation = await complete(newModel, restored);
|
|
|
872
872
|
The library supports browser environments. You must pass the API key explicitly since environment variables are not available in browsers:
|
|
873
873
|
|
|
874
874
|
```typescript
|
|
875
|
-
import { getModel, complete } from '@
|
|
875
|
+
import { getModel, complete } from '@draht/ai';
|
|
876
876
|
|
|
877
877
|
// API key must be passed explicitly in browser
|
|
878
878
|
const model = getModel('anthropic', 'claude-3-5-haiku-20241022');
|
|
@@ -923,17 +923,17 @@ const response = await complete(model, context, {
|
|
|
923
923
|
|
|
924
924
|
#### Antigravity Version Override
|
|
925
925
|
|
|
926
|
-
Set `
|
|
926
|
+
Set `DRAHT_AI_ANTIGRAVITY_VERSION` to override the Antigravity User-Agent version when Google updates their requirements:
|
|
927
927
|
|
|
928
928
|
```bash
|
|
929
|
-
export
|
|
929
|
+
export DRAHT_AI_ANTIGRAVITY_VERSION="1.23.0"
|
|
930
930
|
```
|
|
931
931
|
|
|
932
932
|
#### Cache Retention
|
|
933
933
|
|
|
934
|
-
Set `
|
|
934
|
+
Set `DRAHT_CACHE_RETENTION=long` to extend prompt cache retention:
|
|
935
935
|
|
|
936
|
-
| Provider | Default | With `
|
|
936
|
+
| Provider | Default | With `DRAHT_CACHE_RETENTION=long` |
|
|
937
937
|
|----------|---------|-------------------------------|
|
|
938
938
|
| Anthropic | 5 minutes | 1 hour |
|
|
939
939
|
| OpenAI | in-memory | 24 hours |
|
|
@@ -945,7 +945,7 @@ This only affects direct API calls to `api.anthropic.com` and `api.openai.com`.
|
|
|
945
945
|
### Checking Environment Variables
|
|
946
946
|
|
|
947
947
|
```typescript
|
|
948
|
-
import { getEnvApiKey } from '@
|
|
948
|
+
import { getEnvApiKey } from '@draht/ai';
|
|
949
949
|
|
|
950
950
|
// Check if an API key is set in environment variables
|
|
951
951
|
const key = getEnvApiKey('openai'); // checks OPENAI_API_KEY
|
|
@@ -985,7 +985,7 @@ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
|
|
|
985
985
|
```
|
|
986
986
|
|
|
987
987
|
```typescript
|
|
988
|
-
import { getModel, complete } from '@
|
|
988
|
+
import { getModel, complete } from '@draht/ai';
|
|
989
989
|
|
|
990
990
|
(async () => {
|
|
991
991
|
const model = getModel('google-vertex', 'gemini-2.5-flash');
|
|
@@ -1006,9 +1006,9 @@ Official docs: [Application Default Credentials](https://cloud.google.com/docs/a
|
|
|
1006
1006
|
The quickest way to authenticate:
|
|
1007
1007
|
|
|
1008
1008
|
```bash
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1009
|
+
bunx @draht/ai login # interactive provider selection
|
|
1010
|
+
bunx @draht/ai login anthropic # login to specific provider
|
|
1011
|
+
bunx @draht/ai list # list available providers
|
|
1012
1012
|
```
|
|
1013
1013
|
|
|
1014
1014
|
Credentials are saved to `auth.json` in the current directory.
|
|
@@ -1033,13 +1033,13 @@ import {
|
|
|
1033
1033
|
// Types
|
|
1034
1034
|
type OAuthProvider, // 'anthropic' | 'openai-codex' | 'github-copilot' | 'google-gemini-cli' | 'google-antigravity'
|
|
1035
1035
|
type OAuthCredentials,
|
|
1036
|
-
} from '@
|
|
1036
|
+
} from '@draht/ai';
|
|
1037
1037
|
```
|
|
1038
1038
|
|
|
1039
1039
|
### Login Flow Example
|
|
1040
1040
|
|
|
1041
1041
|
```typescript
|
|
1042
|
-
import { loginGitHubCopilot } from '@
|
|
1042
|
+
import { loginGitHubCopilot } from '@draht/ai';
|
|
1043
1043
|
import { writeFileSync } from 'fs';
|
|
1044
1044
|
|
|
1045
1045
|
const credentials = await loginGitHubCopilot({
|
|
@@ -1063,7 +1063,7 @@ writeFileSync('auth.json', JSON.stringify(auth, null, 2));
|
|
|
1063
1063
|
Use `getOAuthApiKey()` to get an API key, automatically refreshing if expired:
|
|
1064
1064
|
|
|
1065
1065
|
```typescript
|
|
1066
|
-
import { getModel, complete, getOAuthApiKey } from '@
|
|
1066
|
+
import { getModel, complete, getOAuthApiKey } from '@draht/ai';
|
|
1067
1067
|
import { readFileSync, writeFileSync } from 'fs';
|
|
1068
1068
|
|
|
1069
1069
|
// Load your stored credentials
|
|
@@ -6694,23 +6694,6 @@ export declare const MODELS: {
|
|
|
6694
6694
|
contextWindow: number;
|
|
6695
6695
|
maxTokens: number;
|
|
6696
6696
|
};
|
|
6697
|
-
readonly "arcee-ai/trinity-mini": {
|
|
6698
|
-
id: string;
|
|
6699
|
-
name: string;
|
|
6700
|
-
api: "openai-completions";
|
|
6701
|
-
provider: string;
|
|
6702
|
-
baseUrl: string;
|
|
6703
|
-
reasoning: true;
|
|
6704
|
-
input: "text"[];
|
|
6705
|
-
cost: {
|
|
6706
|
-
input: number;
|
|
6707
|
-
output: number;
|
|
6708
|
-
cacheRead: number;
|
|
6709
|
-
cacheWrite: number;
|
|
6710
|
-
};
|
|
6711
|
-
contextWindow: number;
|
|
6712
|
-
maxTokens: number;
|
|
6713
|
-
};
|
|
6714
6697
|
readonly "arcee-ai/trinity-mini:free": {
|
|
6715
6698
|
id: string;
|
|
6716
6699
|
name: string;
|