autotel-terminal 47.0.2 → 47.1.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/README.md +35 -0
- package/dist/cli.cjs +20 -11
- package/dist/cli.js +20 -11
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +1 -1
- package/dist/{src-dzZzhFoh.js → src-84DOR7P-.js} +104 -41
- package/dist/{src-BxNcIs34.cjs → src-Bg41oGDJ.cjs} +104 -41
- package/package.json +20 -6
package/README.md
CHANGED
|
@@ -57,8 +57,29 @@ Port 4319 is used by default to avoid clashing with the standard OTLP port (4318
|
|
|
57
57
|
-t, --title <title> Dashboard title (env: AUTOTEL_TERMINAL_TITLE)
|
|
58
58
|
-h, --help Show help message
|
|
59
59
|
-v, --version Show version number
|
|
60
|
+
--model <spec> AI assistant model (env: AI_MODEL), see below
|
|
61
|
+
--base-url <url> Endpoint for the model (env: AI_BASE_URL)
|
|
62
|
+
--ai-api-key <key> API key, overriding the provider's own variable (env: AI_API_KEY)
|
|
60
63
|
```
|
|
61
64
|
|
|
65
|
+
### AI assistant: bring your own model
|
|
66
|
+
|
|
67
|
+
Press `a` in the dashboard to ask questions about the telemetry. There is no
|
|
68
|
+
default remote model and no shared key: you pick the model, and its provider
|
|
69
|
+
reads its own key from the environment.
|
|
70
|
+
|
|
71
|
+
| `--model` | Provider | Key | Install |
|
|
72
|
+
| ------------------------------------------------------------- | ----------------------- | -------------------------------------------- | --------------------------- |
|
|
73
|
+
| `openai/gpt-5` (or `gateway:openai/gpt-5`) | Vercel AI Gateway | `AI_GATEWAY_API_KEY`, or a Vercel OIDC token | nothing extra |
|
|
74
|
+
| `openai:gpt-5` | OpenAI | `OPENAI_API_KEY` | `@ai-sdk/openai` |
|
|
75
|
+
| `openai-compatible:qwen3 --base-url http://localhost:1234/v1` | Any OpenAI-style server | `AI_API_KEY` if it needs one | `@ai-sdk/openai-compatible` |
|
|
76
|
+
| `ollama:granite4` | Local Ollama | none | `ai-sdk-ollama` |
|
|
77
|
+
|
|
78
|
+
With no model set, a local Ollama is used when one answers (model `granite4`);
|
|
79
|
+
otherwise the assistant stays off. A provider whose package is missing says
|
|
80
|
+
which package to install. `--ai-provider`/`--ai-model` and `AI_PROVIDER`/`AI_MODEL`
|
|
81
|
+
still work.
|
|
82
|
+
|
|
62
83
|
### OTLP Endpoints
|
|
63
84
|
|
|
64
85
|
| Endpoint | Signal | Description |
|
|
@@ -273,9 +294,23 @@ interface TerminalOptions {
|
|
|
273
294
|
|
|
274
295
|
/** Enable colors (default: true if TTY) */
|
|
275
296
|
colors?: boolean;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* AI assistant model: any AI SDK model, used as-is, or a `--model` spec
|
|
300
|
+
* string. Unset: a local Ollama if one answers, else no assistant.
|
|
301
|
+
*/
|
|
302
|
+
ai?: { model?: LanguageModel | string; apiKey?: string; baseUrl?: string };
|
|
276
303
|
}
|
|
277
304
|
```
|
|
278
305
|
|
|
306
|
+
Any AI SDK provider works, since the model is passed in:
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
310
|
+
|
|
311
|
+
renderTerminal({ ai: { model: anthropic('claude-sonnet-5-5') } }, stream);
|
|
312
|
+
```
|
|
313
|
+
|
|
279
314
|
**Example:**
|
|
280
315
|
|
|
281
316
|
```typescript
|
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-Bg41oGDJ.cjs');
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_http = require("node:http");
|
|
5
5
|
let node_path = require("node:path");
|
|
@@ -317,13 +317,21 @@ Options:
|
|
|
317
317
|
-v, --version Show version number
|
|
318
318
|
|
|
319
319
|
AI Options:
|
|
320
|
-
--
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
320
|
+
--model <spec> Model for the assistant (env: AI_MODEL):
|
|
321
|
+
ollama:<id> local Ollama
|
|
322
|
+
openai:<id> reads OPENAI_API_KEY
|
|
323
|
+
openai-compatible:<id> any OpenAI-style server, with --base-url
|
|
324
|
+
<provider>/<id> Vercel AI Gateway, reads AI_GATEWAY_API_KEY
|
|
325
|
+
(or gateway:<provider>/<id>)
|
|
326
|
+
--base-url <url> Endpoint URL (env: AI_BASE_URL)
|
|
327
|
+
--ai-api-key <key> API key, overriding the provider's own variable (env: AI_API_KEY)
|
|
328
|
+
--ai-provider <provider> Provider, with --model naming just the id (env: AI_PROVIDER)
|
|
329
|
+
--ai-model, --ai-base-url Aliases of --model and --base-url
|
|
324
330
|
|
|
325
|
-
|
|
326
|
-
|
|
331
|
+
With no model set, a local Ollama is used when it answers; otherwise the
|
|
332
|
+
assistant stays off. The non-gateway providers are optional packages:
|
|
333
|
+
install ai-sdk-ollama, @ai-sdk/openai or @ai-sdk/openai-compatible to use one.
|
|
334
|
+
Press 'a' in the dashboard to toggle AI.
|
|
327
335
|
|
|
328
336
|
Endpoints:
|
|
329
337
|
POST /v1/traces Receive OTLP JSON trace data
|
|
@@ -333,8 +341,9 @@ Endpoints:
|
|
|
333
341
|
|
|
334
342
|
Examples:
|
|
335
343
|
npx autotel-terminal
|
|
336
|
-
npx autotel-terminal --
|
|
337
|
-
|
|
344
|
+
npx autotel-terminal --model ollama:granite4
|
|
345
|
+
AI_GATEWAY_API_KEY=... npx autotel-terminal --model openai/gpt-5
|
|
346
|
+
npx autotel-terminal --model openai-compatible:qwen3 --base-url http://localhost:1234/v1
|
|
338
347
|
` + "\n");
|
|
339
348
|
}
|
|
340
349
|
function printVersion() {
|
|
@@ -385,7 +394,7 @@ function parseArgs(argv) {
|
|
|
385
394
|
i++;
|
|
386
395
|
continue;
|
|
387
396
|
}
|
|
388
|
-
if (arg === "--ai-model" && next) {
|
|
397
|
+
if ((arg === "--model" || arg === "--ai-model") && next) {
|
|
389
398
|
options.ai.model = next;
|
|
390
399
|
i++;
|
|
391
400
|
continue;
|
|
@@ -395,7 +404,7 @@ function parseArgs(argv) {
|
|
|
395
404
|
i++;
|
|
396
405
|
continue;
|
|
397
406
|
}
|
|
398
|
-
if (arg === "--ai-base-url" && next) {
|
|
407
|
+
if ((arg === "--base-url" || arg === "--ai-base-url") && next) {
|
|
399
408
|
options.ai.baseUrl = next;
|
|
400
409
|
i++;
|
|
401
410
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as getTerminalLogStream, i as renderTerminal } from "./src-
|
|
2
|
+
import { a as getTerminalLogStream, i as renderTerminal } from "./src-84DOR7P-.js";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
import path from "node:path";
|
|
@@ -316,13 +316,21 @@ Options:
|
|
|
316
316
|
-v, --version Show version number
|
|
317
317
|
|
|
318
318
|
AI Options:
|
|
319
|
-
--
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
319
|
+
--model <spec> Model for the assistant (env: AI_MODEL):
|
|
320
|
+
ollama:<id> local Ollama
|
|
321
|
+
openai:<id> reads OPENAI_API_KEY
|
|
322
|
+
openai-compatible:<id> any OpenAI-style server, with --base-url
|
|
323
|
+
<provider>/<id> Vercel AI Gateway, reads AI_GATEWAY_API_KEY
|
|
324
|
+
(or gateway:<provider>/<id>)
|
|
325
|
+
--base-url <url> Endpoint URL (env: AI_BASE_URL)
|
|
326
|
+
--ai-api-key <key> API key, overriding the provider's own variable (env: AI_API_KEY)
|
|
327
|
+
--ai-provider <provider> Provider, with --model naming just the id (env: AI_PROVIDER)
|
|
328
|
+
--ai-model, --ai-base-url Aliases of --model and --base-url
|
|
323
329
|
|
|
324
|
-
|
|
325
|
-
|
|
330
|
+
With no model set, a local Ollama is used when it answers; otherwise the
|
|
331
|
+
assistant stays off. The non-gateway providers are optional packages:
|
|
332
|
+
install ai-sdk-ollama, @ai-sdk/openai or @ai-sdk/openai-compatible to use one.
|
|
333
|
+
Press 'a' in the dashboard to toggle AI.
|
|
326
334
|
|
|
327
335
|
Endpoints:
|
|
328
336
|
POST /v1/traces Receive OTLP JSON trace data
|
|
@@ -332,8 +340,9 @@ Endpoints:
|
|
|
332
340
|
|
|
333
341
|
Examples:
|
|
334
342
|
npx autotel-terminal
|
|
335
|
-
npx autotel-terminal --
|
|
336
|
-
|
|
343
|
+
npx autotel-terminal --model ollama:granite4
|
|
344
|
+
AI_GATEWAY_API_KEY=... npx autotel-terminal --model openai/gpt-5
|
|
345
|
+
npx autotel-terminal --model openai-compatible:qwen3 --base-url http://localhost:1234/v1
|
|
337
346
|
` + "\n");
|
|
338
347
|
}
|
|
339
348
|
function printVersion() {
|
|
@@ -384,7 +393,7 @@ function parseArgs(argv) {
|
|
|
384
393
|
i++;
|
|
385
394
|
continue;
|
|
386
395
|
}
|
|
387
|
-
if (arg === "--ai-model" && next) {
|
|
396
|
+
if ((arg === "--model" || arg === "--ai-model") && next) {
|
|
388
397
|
options.ai.model = next;
|
|
389
398
|
i++;
|
|
390
399
|
continue;
|
|
@@ -394,7 +403,7 @@ function parseArgs(argv) {
|
|
|
394
403
|
i++;
|
|
395
404
|
continue;
|
|
396
405
|
}
|
|
397
|
-
if (arg === "--ai-base-url" && next) {
|
|
406
|
+
if ((arg === "--base-url" || arg === "--ai-base-url") && next) {
|
|
398
407
|
options.ai.baseUrl = next;
|
|
399
408
|
i++;
|
|
400
409
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-Bg41oGDJ.cjs');
|
|
3
3
|
let autotel_exporters = require("autotel/exporters");
|
|
4
4
|
let autotel = require("autotel");
|
|
5
5
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReadableSpan, ReadableSpan as ReadableSpan$1, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
2
2
|
import { Context } from "@opentelemetry/api";
|
|
3
|
+
import { LanguageModel } from "ai";
|
|
3
4
|
import "@json-render/ink";
|
|
4
5
|
import { SpanKind, SpanStatusCode } from "autotel";
|
|
5
6
|
import { PrettyConsoleExporter, PrettyConsoleExporterOptions } from "autotel/exporters";
|
|
@@ -141,13 +142,22 @@ interface TerminalSpanStream {
|
|
|
141
142
|
export declare function createTerminalSpanStream(processor: StreamingSpanProcessor): TerminalSpanStream;
|
|
142
143
|
//#endregion
|
|
143
144
|
//#region src/ai/types.d.ts
|
|
144
|
-
type AIProviderType = 'ollama' | 'openai' | 'openai-compatible';
|
|
145
|
+
type AIProviderType = 'ollama' | 'openai' | 'openai-compatible' | 'gateway';
|
|
145
146
|
type AIConfig = {
|
|
146
147
|
provider: AIProviderType;
|
|
147
148
|
model: string;
|
|
148
149
|
apiKey?: string;
|
|
149
150
|
baseUrl?: string;
|
|
150
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* The `ai` option of `renderTerminal`. `model` is either any AI SDK model,
|
|
154
|
+
* used as-is (`openai('gpt-5')`, `gateway('openai/gpt-5')`, an Ollama model),
|
|
155
|
+
* or a spec string: `ollama:<id>`, `openai:<id>`, `openai-compatible:<id>`
|
|
156
|
+
* (with `baseUrl`), or a gateway id (`openai/gpt-5`, optionally `gateway:`).
|
|
157
|
+
*/
|
|
158
|
+
type AIOptions = Partial<Omit<AIConfig, 'model'>> & {
|
|
159
|
+
model?: string | Exclude<LanguageModel, string>;
|
|
160
|
+
};
|
|
151
161
|
//#endregion
|
|
152
162
|
//#region src/lib/log-model.d.ts
|
|
153
163
|
/**
|
|
@@ -242,9 +252,11 @@ export interface TerminalOptions {
|
|
|
242
252
|
*/
|
|
243
253
|
colors?: boolean;
|
|
244
254
|
/**
|
|
245
|
-
* AI assistant
|
|
255
|
+
* AI assistant model: any AI SDK model (`{ model: openai('gpt-5') }`), or a
|
|
256
|
+
* spec (`{ model: 'ollama:granite4' }`). Uses a local Ollama when it answers
|
|
257
|
+
* and nothing is set; otherwise the assistant stays off.
|
|
246
258
|
*/
|
|
247
|
-
ai?:
|
|
259
|
+
ai?: AIOptions;
|
|
248
260
|
}
|
|
249
261
|
/**
|
|
250
262
|
* Render the terminal dashboard
|
|
@@ -270,4 +282,4 @@ export interface TerminalOptions {
|
|
|
270
282
|
*/
|
|
271
283
|
export declare function renderTerminal(options?: TerminalOptions, stream?: TerminalSpanStream): void;
|
|
272
284
|
//#endregion
|
|
273
|
-
export { PrettyConsoleExporter, type PrettyConsoleExporterOptions, type ReadableSpan, type SpanEvent, SpanKind, type SpanLink, SpanStatusCode, type TerminalLogEvent, type TerminalLogStream, type TerminalSpanEvent, type TerminalSpanStream };
|
|
285
|
+
export { type AIOptions, PrettyConsoleExporter, type PrettyConsoleExporterOptions, type ReadableSpan, type SpanEvent, SpanKind, type SpanLink, SpanStatusCode, type TerminalLogEvent, type TerminalLogStream, type TerminalSpanEvent, type TerminalSpanStream };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SpanKind, SpanStatusCode } from "autotel";
|
|
2
|
+
import { LanguageModel } from "ai";
|
|
2
3
|
import "@json-render/ink";
|
|
3
4
|
import { PrettyConsoleExporter, PrettyConsoleExporterOptions } from "autotel/exporters";
|
|
4
5
|
import { ReadableSpan, ReadableSpan as ReadableSpan$1, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
@@ -141,13 +142,22 @@ interface TerminalSpanStream {
|
|
|
141
142
|
export declare function createTerminalSpanStream(processor: StreamingSpanProcessor): TerminalSpanStream;
|
|
142
143
|
//#endregion
|
|
143
144
|
//#region src/ai/types.d.ts
|
|
144
|
-
type AIProviderType = 'ollama' | 'openai' | 'openai-compatible';
|
|
145
|
+
type AIProviderType = 'ollama' | 'openai' | 'openai-compatible' | 'gateway';
|
|
145
146
|
type AIConfig = {
|
|
146
147
|
provider: AIProviderType;
|
|
147
148
|
model: string;
|
|
148
149
|
apiKey?: string;
|
|
149
150
|
baseUrl?: string;
|
|
150
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* The `ai` option of `renderTerminal`. `model` is either any AI SDK model,
|
|
154
|
+
* used as-is (`openai('gpt-5')`, `gateway('openai/gpt-5')`, an Ollama model),
|
|
155
|
+
* or a spec string: `ollama:<id>`, `openai:<id>`, `openai-compatible:<id>`
|
|
156
|
+
* (with `baseUrl`), or a gateway id (`openai/gpt-5`, optionally `gateway:`).
|
|
157
|
+
*/
|
|
158
|
+
type AIOptions = Partial<Omit<AIConfig, 'model'>> & {
|
|
159
|
+
model?: string | Exclude<LanguageModel, string>;
|
|
160
|
+
};
|
|
151
161
|
//#endregion
|
|
152
162
|
//#region src/lib/log-model.d.ts
|
|
153
163
|
/**
|
|
@@ -242,9 +252,11 @@ export interface TerminalOptions {
|
|
|
242
252
|
*/
|
|
243
253
|
colors?: boolean;
|
|
244
254
|
/**
|
|
245
|
-
* AI assistant
|
|
255
|
+
* AI assistant model: any AI SDK model (`{ model: openai('gpt-5') }`), or a
|
|
256
|
+
* spec (`{ model: 'ollama:granite4' }`). Uses a local Ollama when it answers
|
|
257
|
+
* and nothing is set; otherwise the assistant stays off.
|
|
246
258
|
*/
|
|
247
|
-
ai?:
|
|
259
|
+
ai?: AIOptions;
|
|
248
260
|
}
|
|
249
261
|
/**
|
|
250
262
|
* Render the terminal dashboard
|
|
@@ -270,4 +282,4 @@ export interface TerminalOptions {
|
|
|
270
282
|
*/
|
|
271
283
|
export declare function renderTerminal(options?: TerminalOptions, stream?: TerminalSpanStream): void;
|
|
272
284
|
//#endregion
|
|
273
|
-
export { PrettyConsoleExporter, type PrettyConsoleExporterOptions, type ReadableSpan, type SpanEvent, SpanKind, type SpanLink, SpanStatusCode, type TerminalLogEvent, type TerminalLogStream, type TerminalSpanEvent, type TerminalSpanStream };
|
|
285
|
+
export { type AIOptions, PrettyConsoleExporter, type PrettyConsoleExporterOptions, type ReadableSpan, type SpanEvent, SpanKind, type SpanLink, SpanStatusCode, type TerminalLogEvent, type TerminalLogStream, type TerminalSpanEvent, type TerminalSpanStream };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as getTerminalLogStream, i as renderTerminal, n as SpanKind, o as createTerminalSpanStream, r as SpanStatusCode, s as StreamingSpanProcessor, t as PrettyConsoleExporter } from "./src-
|
|
1
|
+
import { a as getTerminalLogStream, i as renderTerminal, n as SpanKind, o as createTerminalSpanStream, r as SpanStatusCode, s as StreamingSpanProcessor, t as PrettyConsoleExporter } from "./src-84DOR7P-.js";
|
|
2
2
|
|
|
3
3
|
export { PrettyConsoleExporter, SpanKind, SpanStatusCode, StreamingSpanProcessor, createTerminalSpanStream, getTerminalLogStream, renderTerminal };
|
|
@@ -856,6 +856,16 @@ function exportTraceToJson(trace, logs) {
|
|
|
856
856
|
|
|
857
857
|
//#endregion
|
|
858
858
|
//#region src/ai/provider.ts
|
|
859
|
+
const PROVIDERS = [
|
|
860
|
+
"ollama",
|
|
861
|
+
"openai",
|
|
862
|
+
"openai-compatible",
|
|
863
|
+
"gateway"
|
|
864
|
+
];
|
|
865
|
+
/** The local model used when Ollama is chosen or detected without one named. */
|
|
866
|
+
const OLLAMA_DEFAULT_MODEL = "granite4";
|
|
867
|
+
/** How to configure a model, for the unconfigured view and error messages. */
|
|
868
|
+
const MODEL_HINT = "Pass --model (ollama:<id>, openai:<id>, openai-compatible:<id> with --base-url, or a gateway id like openai/gpt-5), set AI_MODEL, or start Ollama locally.";
|
|
859
869
|
async function detectOllama(baseUrl = "http://127.0.0.1:11434") {
|
|
860
870
|
try {
|
|
861
871
|
return (await fetch(`${baseUrl}/api/tags`, { signal: AbortSignal.timeout(1e3) })).ok;
|
|
@@ -863,73 +873,128 @@ async function detectOllama(baseUrl = "http://127.0.0.1:11434") {
|
|
|
863
873
|
return false;
|
|
864
874
|
}
|
|
865
875
|
}
|
|
876
|
+
/**
|
|
877
|
+
* `ollama:qwen2:latest` → ollama + `qwen2:latest`. Only a known provider
|
|
878
|
+
* prefix is split off; anything else is a gateway id (`openai/gpt-5`).
|
|
879
|
+
*/
|
|
880
|
+
function parseModelSpec(spec) {
|
|
881
|
+
const colon = spec.indexOf(":");
|
|
882
|
+
const prefix = colon === -1 ? "" : spec.slice(0, colon);
|
|
883
|
+
const provider = PROVIDERS.find((p) => p === prefix);
|
|
884
|
+
return provider ? {
|
|
885
|
+
provider,
|
|
886
|
+
model: spec.slice(colon + 1)
|
|
887
|
+
} : {
|
|
888
|
+
provider: "gateway",
|
|
889
|
+
model: spec
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* The config named by options and env, or null when nothing is named.
|
|
894
|
+
* A model with a provider prefix (`openai:gpt-5`) names its own provider.
|
|
895
|
+
* Otherwise `provider` + `model` (and `AI_PROVIDER` + `AI_MODEL`) still work,
|
|
896
|
+
* and a model without a provider is read as a gateway id. Only Ollama has a
|
|
897
|
+
* default model: a remote provider must be told which model to bill.
|
|
898
|
+
*/
|
|
866
899
|
function resolveConfig(options = {}) {
|
|
867
|
-
const
|
|
868
|
-
const
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
900
|
+
const rawModel = options.model ?? process.env.AI_MODEL;
|
|
901
|
+
const spec = rawModel === void 0 ? void 0 : parseModelSpec(rawModel);
|
|
902
|
+
const prefixed = spec !== void 0 && spec.model !== rawModel;
|
|
903
|
+
let provider = prefixed ? spec.provider : options.provider ?? process.env.AI_PROVIDER;
|
|
904
|
+
let model = prefixed ? spec.model : rawModel;
|
|
905
|
+
if (!provider && spec) ({provider, model} = spec);
|
|
906
|
+
if (!provider) return null;
|
|
907
|
+
model ??= provider === "ollama" ? OLLAMA_DEFAULT_MODEL : void 0;
|
|
908
|
+
if (!model) throw new Error(`No model named for ${provider}. ${MODEL_HINT}`);
|
|
909
|
+
return {
|
|
872
910
|
provider,
|
|
873
|
-
model
|
|
874
|
-
apiKey,
|
|
875
|
-
baseUrl
|
|
911
|
+
model,
|
|
912
|
+
apiKey: options.apiKey ?? process.env.AI_API_KEY,
|
|
913
|
+
baseUrl: options.baseUrl ?? process.env.AI_BASE_URL
|
|
876
914
|
};
|
|
877
|
-
return null;
|
|
878
915
|
}
|
|
879
916
|
const defaultAutoDetectDeps = { detectOllama };
|
|
917
|
+
/** {@link resolveConfig}, falling back to a local Ollama when one answers. */
|
|
880
918
|
async function resolveConfigWithAutoDetect(options = {}, deps = defaultAutoDetectDeps) {
|
|
881
919
|
const config = resolveConfig(options);
|
|
882
920
|
if (config) return config;
|
|
883
921
|
const ollamaUrl = options.baseUrl ?? process.env.AI_BASE_URL ?? "http://127.0.0.1:11434";
|
|
884
922
|
if (await deps.detectOllama(ollamaUrl)) return {
|
|
885
923
|
provider: "ollama",
|
|
886
|
-
model:
|
|
924
|
+
model: OLLAMA_DEFAULT_MODEL,
|
|
887
925
|
baseUrl: ollamaUrl
|
|
888
926
|
};
|
|
889
|
-
const openaiKey = options.apiKey ?? process.env.AI_API_KEY ?? process.env.OPENAI_API_KEY;
|
|
890
|
-
if (openaiKey) return {
|
|
891
|
-
provider: "openai",
|
|
892
|
-
model: options.model ?? process.env.AI_MODEL ?? "gpt-4o",
|
|
893
|
-
apiKey: openaiKey
|
|
894
|
-
};
|
|
895
927
|
return null;
|
|
896
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* Imports an optional provider package, turning "not installed" into an
|
|
931
|
+
* error that names the package to add.
|
|
932
|
+
*/
|
|
933
|
+
async function loadProvider(pkg, load) {
|
|
934
|
+
try {
|
|
935
|
+
return await load();
|
|
936
|
+
} catch (error) {
|
|
937
|
+
const code = error?.code;
|
|
938
|
+
if (!((code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && String(error.message).includes(pkg))) throw error;
|
|
939
|
+
throw new Error(`This model needs ${pkg}, which is not installed. Run: npm install ${pkg}`, { cause: error });
|
|
940
|
+
}
|
|
941
|
+
}
|
|
897
942
|
async function createAIModel(config) {
|
|
898
943
|
switch (config.provider) {
|
|
899
944
|
case "ollama": {
|
|
900
|
-
const { createOllama } = await import("ai-sdk-ollama");
|
|
945
|
+
const { createOllama } = await loadProvider("ai-sdk-ollama", () => import("ai-sdk-ollama"));
|
|
901
946
|
return {
|
|
902
947
|
model: createOllama({ baseURL: config.baseUrl ?? "http://127.0.0.1:11434" })(config.model),
|
|
903
|
-
providerType: "ollama"
|
|
904
|
-
config
|
|
948
|
+
providerType: "ollama"
|
|
905
949
|
};
|
|
906
950
|
}
|
|
907
951
|
case "openai": {
|
|
908
|
-
const { createOpenAI } = await import("@ai-sdk/openai");
|
|
952
|
+
const { createOpenAI } = await loadProvider("@ai-sdk/openai", () => import("@ai-sdk/openai"));
|
|
909
953
|
return {
|
|
910
954
|
model: createOpenAI({
|
|
911
|
-
apiKey: config.apiKey,
|
|
955
|
+
...config.apiKey ? { apiKey: config.apiKey } : {},
|
|
912
956
|
...config.baseUrl ? { baseURL: config.baseUrl } : {}
|
|
913
957
|
})(config.model),
|
|
914
|
-
providerType: "openai"
|
|
915
|
-
config
|
|
958
|
+
providerType: "openai"
|
|
916
959
|
};
|
|
917
960
|
}
|
|
918
961
|
case "openai-compatible": {
|
|
919
|
-
const { createOpenAICompatible } = await import("@ai-sdk/openai-compatible");
|
|
962
|
+
const { createOpenAICompatible } = await loadProvider("@ai-sdk/openai-compatible", () => import("@ai-sdk/openai-compatible"));
|
|
920
963
|
return {
|
|
921
964
|
model: createOpenAICompatible({
|
|
922
965
|
baseURL: config.baseUrl ?? "http://127.0.0.1:11434/v1",
|
|
923
966
|
name: "custom",
|
|
924
|
-
...config.apiKey ? {
|
|
967
|
+
...config.apiKey ? { apiKey: config.apiKey } : {}
|
|
925
968
|
})(config.model),
|
|
926
|
-
providerType: "openai-compatible"
|
|
927
|
-
|
|
969
|
+
providerType: "openai-compatible"
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
case "gateway": {
|
|
973
|
+
const { createGateway, gateway } = await import("ai");
|
|
974
|
+
return {
|
|
975
|
+
model: (config.apiKey ? createGateway({ apiKey: config.apiKey }) : gateway)(config.model),
|
|
976
|
+
providerType: "gateway"
|
|
928
977
|
};
|
|
929
978
|
}
|
|
930
|
-
default: throw new Error(`Unsupported provider: "${config.provider}". Expected
|
|
979
|
+
default: throw new Error(`Unsupported provider: "${String(config.provider)}". Expected one of ${PROVIDERS.join(", ")}.`);
|
|
931
980
|
}
|
|
932
981
|
}
|
|
982
|
+
/**
|
|
983
|
+
* The model the dashboard talks to: the caller's own AI SDK model as-is, else
|
|
984
|
+
* one built from a spec, env or a detected Ollama. Null when none is set.
|
|
985
|
+
*/
|
|
986
|
+
async function resolveAIModel(options = {}, deps = defaultAutoDetectDeps) {
|
|
987
|
+
const { model, ...rest } = options;
|
|
988
|
+
if (model !== void 0 && typeof model !== "string") return {
|
|
989
|
+
model,
|
|
990
|
+
providerType: model.provider.startsWith("ollama") ? "ollama" : "custom"
|
|
991
|
+
};
|
|
992
|
+
const config = await resolveConfigWithAutoDetect({
|
|
993
|
+
...rest,
|
|
994
|
+
model
|
|
995
|
+
}, deps);
|
|
996
|
+
return config ? createAIModel(config) : null;
|
|
997
|
+
}
|
|
933
998
|
|
|
934
999
|
//#endregion
|
|
935
1000
|
//#region src/ai/system-prompt.ts
|
|
@@ -1233,18 +1298,16 @@ function Dashboard({ title, showStats, maxSpans, colors, stream, logStream, aiCo
|
|
|
1233
1298
|
const aiAbortRef = useRef(null);
|
|
1234
1299
|
useEffect(() => {
|
|
1235
1300
|
let cancelled = false;
|
|
1236
|
-
|
|
1237
|
-
if (cancelled || !
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
});
|
|
1247
|
-
}
|
|
1301
|
+
resolveAIModel(aiConfig).then((result) => {
|
|
1302
|
+
if (cancelled || !result) return;
|
|
1303
|
+
aiModelRef.current = result;
|
|
1304
|
+
setAiState({ status: "idle" });
|
|
1305
|
+
}, (error) => {
|
|
1306
|
+
if (cancelled) return;
|
|
1307
|
+
setAiState({
|
|
1308
|
+
status: "error",
|
|
1309
|
+
message: error instanceof Error ? error.message : String(error)
|
|
1310
|
+
});
|
|
1248
1311
|
});
|
|
1249
1312
|
return () => {
|
|
1250
1313
|
cancelled = true;
|
|
@@ -2040,7 +2103,7 @@ function Dashboard({ title, showStats, maxSpans, colors, stream, logStream, aiCo
|
|
|
2040
2103
|
}),
|
|
2041
2104
|
/* @__PURE__ */ jsx(Text, {
|
|
2042
2105
|
dimColor: true,
|
|
2043
|
-
children: "
|
|
2106
|
+
children: "Pass --model (ollama:<id>, openai:<id>, openai-compatible:<id> with --base-url, or a gateway id like openai/gpt-5), set AI_MODEL, or start Ollama locally."
|
|
2044
2107
|
}),
|
|
2045
2108
|
/* @__PURE__ */ jsx(Text, {
|
|
2046
2109
|
dimColor: true,
|
|
@@ -884,6 +884,16 @@ function exportTraceToJson(trace, logs) {
|
|
|
884
884
|
|
|
885
885
|
//#endregion
|
|
886
886
|
//#region src/ai/provider.ts
|
|
887
|
+
const PROVIDERS = [
|
|
888
|
+
"ollama",
|
|
889
|
+
"openai",
|
|
890
|
+
"openai-compatible",
|
|
891
|
+
"gateway"
|
|
892
|
+
];
|
|
893
|
+
/** The local model used when Ollama is chosen or detected without one named. */
|
|
894
|
+
const OLLAMA_DEFAULT_MODEL = "granite4";
|
|
895
|
+
/** How to configure a model, for the unconfigured view and error messages. */
|
|
896
|
+
const MODEL_HINT = "Pass --model (ollama:<id>, openai:<id>, openai-compatible:<id> with --base-url, or a gateway id like openai/gpt-5), set AI_MODEL, or start Ollama locally.";
|
|
887
897
|
async function detectOllama(baseUrl = "http://127.0.0.1:11434") {
|
|
888
898
|
try {
|
|
889
899
|
return (await fetch(`${baseUrl}/api/tags`, { signal: AbortSignal.timeout(1e3) })).ok;
|
|
@@ -891,73 +901,128 @@ async function detectOllama(baseUrl = "http://127.0.0.1:11434") {
|
|
|
891
901
|
return false;
|
|
892
902
|
}
|
|
893
903
|
}
|
|
904
|
+
/**
|
|
905
|
+
* `ollama:qwen2:latest` → ollama + `qwen2:latest`. Only a known provider
|
|
906
|
+
* prefix is split off; anything else is a gateway id (`openai/gpt-5`).
|
|
907
|
+
*/
|
|
908
|
+
function parseModelSpec(spec) {
|
|
909
|
+
const colon = spec.indexOf(":");
|
|
910
|
+
const prefix = colon === -1 ? "" : spec.slice(0, colon);
|
|
911
|
+
const provider = PROVIDERS.find((p) => p === prefix);
|
|
912
|
+
return provider ? {
|
|
913
|
+
provider,
|
|
914
|
+
model: spec.slice(colon + 1)
|
|
915
|
+
} : {
|
|
916
|
+
provider: "gateway",
|
|
917
|
+
model: spec
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* The config named by options and env, or null when nothing is named.
|
|
922
|
+
* A model with a provider prefix (`openai:gpt-5`) names its own provider.
|
|
923
|
+
* Otherwise `provider` + `model` (and `AI_PROVIDER` + `AI_MODEL`) still work,
|
|
924
|
+
* and a model without a provider is read as a gateway id. Only Ollama has a
|
|
925
|
+
* default model: a remote provider must be told which model to bill.
|
|
926
|
+
*/
|
|
894
927
|
function resolveConfig(options = {}) {
|
|
895
|
-
const
|
|
896
|
-
const
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
|
|
928
|
+
const rawModel = options.model ?? process.env.AI_MODEL;
|
|
929
|
+
const spec = rawModel === void 0 ? void 0 : parseModelSpec(rawModel);
|
|
930
|
+
const prefixed = spec !== void 0 && spec.model !== rawModel;
|
|
931
|
+
let provider = prefixed ? spec.provider : options.provider ?? process.env.AI_PROVIDER;
|
|
932
|
+
let model = prefixed ? spec.model : rawModel;
|
|
933
|
+
if (!provider && spec) ({provider, model} = spec);
|
|
934
|
+
if (!provider) return null;
|
|
935
|
+
model ??= provider === "ollama" ? OLLAMA_DEFAULT_MODEL : void 0;
|
|
936
|
+
if (!model) throw new Error(`No model named for ${provider}. ${MODEL_HINT}`);
|
|
937
|
+
return {
|
|
900
938
|
provider,
|
|
901
|
-
model
|
|
902
|
-
apiKey,
|
|
903
|
-
baseUrl
|
|
939
|
+
model,
|
|
940
|
+
apiKey: options.apiKey ?? process.env.AI_API_KEY,
|
|
941
|
+
baseUrl: options.baseUrl ?? process.env.AI_BASE_URL
|
|
904
942
|
};
|
|
905
|
-
return null;
|
|
906
943
|
}
|
|
907
944
|
const defaultAutoDetectDeps = { detectOllama };
|
|
945
|
+
/** {@link resolveConfig}, falling back to a local Ollama when one answers. */
|
|
908
946
|
async function resolveConfigWithAutoDetect(options = {}, deps = defaultAutoDetectDeps) {
|
|
909
947
|
const config = resolveConfig(options);
|
|
910
948
|
if (config) return config;
|
|
911
949
|
const ollamaUrl = options.baseUrl ?? process.env.AI_BASE_URL ?? "http://127.0.0.1:11434";
|
|
912
950
|
if (await deps.detectOllama(ollamaUrl)) return {
|
|
913
951
|
provider: "ollama",
|
|
914
|
-
model:
|
|
952
|
+
model: OLLAMA_DEFAULT_MODEL,
|
|
915
953
|
baseUrl: ollamaUrl
|
|
916
954
|
};
|
|
917
|
-
const openaiKey = options.apiKey ?? process.env.AI_API_KEY ?? process.env.OPENAI_API_KEY;
|
|
918
|
-
if (openaiKey) return {
|
|
919
|
-
provider: "openai",
|
|
920
|
-
model: options.model ?? process.env.AI_MODEL ?? "gpt-4o",
|
|
921
|
-
apiKey: openaiKey
|
|
922
|
-
};
|
|
923
955
|
return null;
|
|
924
956
|
}
|
|
957
|
+
/**
|
|
958
|
+
* Imports an optional provider package, turning "not installed" into an
|
|
959
|
+
* error that names the package to add.
|
|
960
|
+
*/
|
|
961
|
+
async function loadProvider(pkg, load) {
|
|
962
|
+
try {
|
|
963
|
+
return await load();
|
|
964
|
+
} catch (error) {
|
|
965
|
+
const code = error?.code;
|
|
966
|
+
if (!((code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && String(error.message).includes(pkg))) throw error;
|
|
967
|
+
throw new Error(`This model needs ${pkg}, which is not installed. Run: npm install ${pkg}`, { cause: error });
|
|
968
|
+
}
|
|
969
|
+
}
|
|
925
970
|
async function createAIModel(config) {
|
|
926
971
|
switch (config.provider) {
|
|
927
972
|
case "ollama": {
|
|
928
|
-
const { createOllama } = await import("ai-sdk-ollama");
|
|
973
|
+
const { createOllama } = await loadProvider("ai-sdk-ollama", () => import("ai-sdk-ollama"));
|
|
929
974
|
return {
|
|
930
975
|
model: createOllama({ baseURL: config.baseUrl ?? "http://127.0.0.1:11434" })(config.model),
|
|
931
|
-
providerType: "ollama"
|
|
932
|
-
config
|
|
976
|
+
providerType: "ollama"
|
|
933
977
|
};
|
|
934
978
|
}
|
|
935
979
|
case "openai": {
|
|
936
|
-
const { createOpenAI } = await import("@ai-sdk/openai");
|
|
980
|
+
const { createOpenAI } = await loadProvider("@ai-sdk/openai", () => import("@ai-sdk/openai"));
|
|
937
981
|
return {
|
|
938
982
|
model: createOpenAI({
|
|
939
|
-
apiKey: config.apiKey,
|
|
983
|
+
...config.apiKey ? { apiKey: config.apiKey } : {},
|
|
940
984
|
...config.baseUrl ? { baseURL: config.baseUrl } : {}
|
|
941
985
|
})(config.model),
|
|
942
|
-
providerType: "openai"
|
|
943
|
-
config
|
|
986
|
+
providerType: "openai"
|
|
944
987
|
};
|
|
945
988
|
}
|
|
946
989
|
case "openai-compatible": {
|
|
947
|
-
const { createOpenAICompatible } = await import("@ai-sdk/openai-compatible");
|
|
990
|
+
const { createOpenAICompatible } = await loadProvider("@ai-sdk/openai-compatible", () => import("@ai-sdk/openai-compatible"));
|
|
948
991
|
return {
|
|
949
992
|
model: createOpenAICompatible({
|
|
950
993
|
baseURL: config.baseUrl ?? "http://127.0.0.1:11434/v1",
|
|
951
994
|
name: "custom",
|
|
952
|
-
...config.apiKey ? {
|
|
995
|
+
...config.apiKey ? { apiKey: config.apiKey } : {}
|
|
953
996
|
})(config.model),
|
|
954
|
-
providerType: "openai-compatible"
|
|
955
|
-
|
|
997
|
+
providerType: "openai-compatible"
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
case "gateway": {
|
|
1001
|
+
const { createGateway, gateway } = await import("ai");
|
|
1002
|
+
return {
|
|
1003
|
+
model: (config.apiKey ? createGateway({ apiKey: config.apiKey }) : gateway)(config.model),
|
|
1004
|
+
providerType: "gateway"
|
|
956
1005
|
};
|
|
957
1006
|
}
|
|
958
|
-
default: throw new Error(`Unsupported provider: "${config.provider}". Expected
|
|
1007
|
+
default: throw new Error(`Unsupported provider: "${String(config.provider)}". Expected one of ${PROVIDERS.join(", ")}.`);
|
|
959
1008
|
}
|
|
960
1009
|
}
|
|
1010
|
+
/**
|
|
1011
|
+
* The model the dashboard talks to: the caller's own AI SDK model as-is, else
|
|
1012
|
+
* one built from a spec, env or a detected Ollama. Null when none is set.
|
|
1013
|
+
*/
|
|
1014
|
+
async function resolveAIModel(options = {}, deps = defaultAutoDetectDeps) {
|
|
1015
|
+
const { model, ...rest } = options;
|
|
1016
|
+
if (model !== void 0 && typeof model !== "string") return {
|
|
1017
|
+
model,
|
|
1018
|
+
providerType: model.provider.startsWith("ollama") ? "ollama" : "custom"
|
|
1019
|
+
};
|
|
1020
|
+
const config = await resolveConfigWithAutoDetect({
|
|
1021
|
+
...rest,
|
|
1022
|
+
model
|
|
1023
|
+
}, deps);
|
|
1024
|
+
return config ? createAIModel(config) : null;
|
|
1025
|
+
}
|
|
961
1026
|
|
|
962
1027
|
//#endregion
|
|
963
1028
|
//#region src/ai/system-prompt.ts
|
|
@@ -1261,18 +1326,16 @@ function Dashboard({ title, showStats, maxSpans, colors, stream, logStream, aiCo
|
|
|
1261
1326
|
const aiAbortRef = (0, react.useRef)(null);
|
|
1262
1327
|
(0, react.useEffect)(() => {
|
|
1263
1328
|
let cancelled = false;
|
|
1264
|
-
|
|
1265
|
-
if (cancelled || !
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1329
|
+
resolveAIModel(aiConfig).then((result) => {
|
|
1330
|
+
if (cancelled || !result) return;
|
|
1331
|
+
aiModelRef.current = result;
|
|
1332
|
+
setAiState({ status: "idle" });
|
|
1333
|
+
}, (error) => {
|
|
1334
|
+
if (cancelled) return;
|
|
1335
|
+
setAiState({
|
|
1336
|
+
status: "error",
|
|
1337
|
+
message: error instanceof Error ? error.message : String(error)
|
|
1338
|
+
});
|
|
1276
1339
|
});
|
|
1277
1340
|
return () => {
|
|
1278
1341
|
cancelled = true;
|
|
@@ -2068,7 +2131,7 @@ function Dashboard({ title, showStats, maxSpans, colors, stream, logStream, aiCo
|
|
|
2068
2131
|
}),
|
|
2069
2132
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ink.Text, {
|
|
2070
2133
|
dimColor: true,
|
|
2071
|
-
children: "
|
|
2134
|
+
children: "Pass --model (ollama:<id>, openai:<id>, openai-compatible:<id> with --base-url, or a gateway id like openai/gpt-5), set AI_MODEL, or start Ollama locally."
|
|
2072
2135
|
}),
|
|
2073
2136
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ink.Text, {
|
|
2074
2137
|
dimColor: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autotel-terminal",
|
|
3
|
-
"version": "47.0
|
|
3
|
+
"version": "47.1.0",
|
|
4
4
|
"description": "Terminal dashboard for autotel traces using react-ink",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -42,27 +42,41 @@
|
|
|
42
42
|
"author": "Jag Reehal<jag@jagreehal.com> (https://jagreehal.com)",
|
|
43
43
|
"license": "Apache-2.0",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ai-sdk/openai": "^4.0.78",
|
|
46
|
-
"@ai-sdk/openai-compatible": "^3.0.57",
|
|
47
45
|
"@json-render/core": "^0.21.0",
|
|
48
46
|
"@json-render/ink": "^0.21.0",
|
|
49
47
|
"ai": "^7.0.118",
|
|
50
|
-
"ai-sdk-ollama": "^4.3.0",
|
|
51
48
|
"ink": "^7.1.1",
|
|
52
49
|
"react": "^19.3.0",
|
|
53
50
|
"zod": "4.6.5"
|
|
54
51
|
},
|
|
55
52
|
"peerDependencies": {
|
|
53
|
+
"@ai-sdk/openai": "^4.0.78",
|
|
54
|
+
"@ai-sdk/openai-compatible": "^3.0.57",
|
|
56
55
|
"@opentelemetry/api": "^1.9.1",
|
|
57
56
|
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
58
|
-
"
|
|
57
|
+
"ai-sdk-ollama": "^4.3.0",
|
|
58
|
+
"autotel": "8.1.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"@ai-sdk/openai": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"@ai-sdk/openai-compatible": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"ai-sdk-ollama": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
59
70
|
},
|
|
60
71
|
"devDependencies": {
|
|
72
|
+
"@ai-sdk/openai": "^4.0.78",
|
|
73
|
+
"@ai-sdk/openai-compatible": "^3.0.57",
|
|
61
74
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
62
75
|
"@opentelemetry/api": "^1.9.1",
|
|
63
76
|
"@types/node": "^26.6.3",
|
|
64
77
|
"@types/react": "^19.3.0",
|
|
65
|
-
"
|
|
78
|
+
"ai-sdk-ollama": "^4.3.0",
|
|
79
|
+
"autotel": "8.1.0",
|
|
66
80
|
"prettier": "^3.9.9",
|
|
67
81
|
"rimraf": "^6.1.3",
|
|
68
82
|
"tsdown": "^0.23.0",
|