autotel-terminal 28.0.0 → 29.0.1
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/package.json +3 -4
- package/src/ai/catalog.test.ts +0 -18
- package/src/ai/catalog.ts +0 -16
- package/src/ai/provider.test.ts +0 -47
- package/src/ai/provider.ts +0 -124
- package/src/ai/stream.ts +0 -44
- package/src/ai/system-prompt.ts +0 -37
- package/src/ai/tools.test.ts +0 -36
- package/src/ai/tools.ts +0 -278
- package/src/ai/types.ts +0 -22
- package/src/cli-stream.ts +0 -23
- package/src/cli.integration.test.ts +0 -320
- package/src/cli.ts +0 -240
- package/src/index.tsx +0 -2242
- package/src/lib/dashboard-keymap.test.ts +0 -118
- package/src/lib/dashboard-keymap.ts +0 -123
- package/src/lib/error-model.test.ts +0 -122
- package/src/lib/error-model.ts +0 -66
- package/src/lib/export-model.test.ts +0 -52
- package/src/lib/export-model.ts +0 -61
- package/src/lib/filters.test.ts +0 -107
- package/src/lib/filters.ts +0 -105
- package/src/lib/format.test.ts +0 -188
- package/src/lib/format.ts +0 -149
- package/src/lib/log-model.ts +0 -113
- package/src/lib/recording-regression.test.ts +0 -32
- package/src/lib/service-colors.test.ts +0 -22
- package/src/lib/service-colors.ts +0 -32
- package/src/lib/stats-model.test.ts +0 -94
- package/src/lib/stats-model.ts +0 -122
- package/src/lib/topology-model.test.ts +0 -101
- package/src/lib/topology-model.ts +0 -100
- package/src/lib/topology-render.test.ts +0 -319
- package/src/lib/topology-render.ts +0 -96
- package/src/lib/trace-model.test.ts +0 -276
- package/src/lib/trace-model.ts +0 -240
- package/src/listen.ts +0 -84
- package/src/log-stream.ts +0 -65
- package/src/otlp-http-json.test.ts +0 -561
- package/src/otlp-http-json.ts +0 -354
- package/src/span-stream.ts +0 -197
- package/src/streaming-processor.ts +0 -113
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autotel-terminal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "29.0.1",
|
|
4
4
|
"description": "Terminal dashboard for autotel traces using react-ink",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
26
|
-
"src",
|
|
27
26
|
"README.md",
|
|
28
27
|
"skills"
|
|
29
28
|
],
|
|
@@ -55,7 +54,7 @@
|
|
|
55
54
|
"peerDependencies": {
|
|
56
55
|
"@opentelemetry/api": "^1.9.1",
|
|
57
56
|
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
58
|
-
"autotel": "4.1
|
|
57
|
+
"autotel": "4.2.1"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
|
61
60
|
"@arethetypeswrong/cli": "^0.18.3",
|
|
@@ -72,7 +71,7 @@
|
|
|
72
71
|
"typescript": "^6.0.3",
|
|
73
72
|
"typescript-eslint": "^8.60.1",
|
|
74
73
|
"vitest": "^4.1.8",
|
|
75
|
-
"autotel": "4.1
|
|
74
|
+
"autotel": "4.2.1"
|
|
76
75
|
},
|
|
77
76
|
"repository": {
|
|
78
77
|
"type": "git",
|
package/src/ai/catalog.test.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { catalog } from './catalog';
|
|
3
|
-
|
|
4
|
-
describe('AI catalog', () => {
|
|
5
|
-
it('exports a catalog with component definitions', () => {
|
|
6
|
-
expect(catalog).toBeDefined();
|
|
7
|
-
expect(typeof catalog.prompt).toBe('function');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('generates a system prompt describing available components', () => {
|
|
11
|
-
const prompt = catalog.prompt({
|
|
12
|
-
system: 'You are a test assistant',
|
|
13
|
-
});
|
|
14
|
-
expect(prompt).toContain('Table');
|
|
15
|
-
expect(prompt).toContain('Badge');
|
|
16
|
-
expect(prompt).toContain('BarChart');
|
|
17
|
-
});
|
|
18
|
-
});
|
package/src/ai/catalog.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { defineCatalog } from '@json-render/core';
|
|
2
|
-
import { schema } from '@json-render/ink/schema';
|
|
3
|
-
import {
|
|
4
|
-
standardComponentDefinitions,
|
|
5
|
-
standardActionDefinitions,
|
|
6
|
-
} from '@json-render/ink/catalog';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Catalog with all standard Ink components.
|
|
10
|
-
* The system prompt restricts the AI to the telemetry-relevant ones
|
|
11
|
-
* (Table, KeyValue, Badge, BarChart, Text, Box, Heading, Divider, Card).
|
|
12
|
-
*/
|
|
13
|
-
export const catalog = defineCatalog(schema, {
|
|
14
|
-
components: standardComponentDefinitions,
|
|
15
|
-
actions: standardActionDefinitions,
|
|
16
|
-
});
|
package/src/ai/provider.test.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
createAIModel,
|
|
4
|
-
resolveConfig,
|
|
5
|
-
resolveConfigWithAutoDetect,
|
|
6
|
-
} from './provider';
|
|
7
|
-
|
|
8
|
-
describe('AI provider config', () => {
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
delete process.env.AI_PROVIDER;
|
|
11
|
-
delete process.env.AI_MODEL;
|
|
12
|
-
delete process.env.AI_API_KEY;
|
|
13
|
-
delete process.env.AI_BASE_URL;
|
|
14
|
-
delete process.env.OPENAI_API_KEY;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('uses OPENAI_API_KEY when openai is explicitly selected', () => {
|
|
18
|
-
process.env.OPENAI_API_KEY = 'openai-secret';
|
|
19
|
-
|
|
20
|
-
expect(resolveConfig({ provider: 'openai' })).toMatchObject({
|
|
21
|
-
provider: 'openai',
|
|
22
|
-
model: 'gpt-4o',
|
|
23
|
-
apiKey: 'openai-secret',
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('uses OPENAI_API_KEY when auto-detect resolves to openai', async () => {
|
|
28
|
-
process.env.OPENAI_API_KEY = 'openai-secret';
|
|
29
|
-
|
|
30
|
-
const result = await resolveConfigWithAutoDetect(
|
|
31
|
-
{},
|
|
32
|
-
{ detectOllama: async () => false },
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
expect(result).toMatchObject({
|
|
36
|
-
provider: 'openai',
|
|
37
|
-
model: 'gpt-4o',
|
|
38
|
-
apiKey: 'openai-secret',
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('throws for unsupported provider values', async () => {
|
|
43
|
-
await expect(
|
|
44
|
-
createAIModel({ provider: 'invalid' as never, model: 'test-model' }),
|
|
45
|
-
).rejects.toThrow(/unsupported provider/i);
|
|
46
|
-
});
|
|
47
|
-
});
|
package/src/ai/provider.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type { LanguageModel } from 'ai';
|
|
2
|
-
import type { AIConfig, AIProviderType } from './types';
|
|
3
|
-
|
|
4
|
-
export async function detectOllama(
|
|
5
|
-
baseUrl = 'http://127.0.0.1:11434',
|
|
6
|
-
): Promise<boolean> {
|
|
7
|
-
try {
|
|
8
|
-
const res = await fetch(`${baseUrl}/api/tags`, {
|
|
9
|
-
signal: AbortSignal.timeout(1000),
|
|
10
|
-
});
|
|
11
|
-
return res.ok;
|
|
12
|
-
} catch {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function resolveConfig(
|
|
18
|
-
options: Partial<AIConfig> = {},
|
|
19
|
-
): AIConfig | null {
|
|
20
|
-
const provider: AIProviderType | undefined =
|
|
21
|
-
options.provider ??
|
|
22
|
-
(process.env.AI_PROVIDER as AIProviderType | undefined) ??
|
|
23
|
-
undefined;
|
|
24
|
-
|
|
25
|
-
const model = options.model ?? process.env.AI_MODEL;
|
|
26
|
-
const apiKey =
|
|
27
|
-
options.apiKey ??
|
|
28
|
-
process.env.AI_API_KEY ??
|
|
29
|
-
(provider === 'openai' ? process.env.OPENAI_API_KEY : undefined);
|
|
30
|
-
const baseUrl = options.baseUrl ?? process.env.AI_BASE_URL;
|
|
31
|
-
|
|
32
|
-
if (provider) {
|
|
33
|
-
return {
|
|
34
|
-
provider,
|
|
35
|
-
model: model ?? (provider === 'ollama' ? 'granite4' : 'gpt-4o'),
|
|
36
|
-
apiKey,
|
|
37
|
-
baseUrl,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Will be resolved async in resolveConfigWithAutoDetect
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const defaultAutoDetectDeps = { detectOllama };
|
|
46
|
-
|
|
47
|
-
export async function resolveConfigWithAutoDetect(
|
|
48
|
-
options: Partial<AIConfig> = {},
|
|
49
|
-
deps: { detectOllama: typeof detectOllama } = defaultAutoDetectDeps,
|
|
50
|
-
): Promise<AIConfig | null> {
|
|
51
|
-
const config = resolveConfig(options);
|
|
52
|
-
if (config) return config;
|
|
53
|
-
|
|
54
|
-
// Auto-detect: check Ollama first
|
|
55
|
-
const ollamaUrl =
|
|
56
|
-
options.baseUrl ?? process.env.AI_BASE_URL ?? 'http://127.0.0.1:11434';
|
|
57
|
-
if (await deps.detectOllama(ollamaUrl)) {
|
|
58
|
-
return {
|
|
59
|
-
provider: 'ollama',
|
|
60
|
-
model: options.model ?? process.env.AI_MODEL ?? 'granite4',
|
|
61
|
-
baseUrl: ollamaUrl,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Check for OpenAI key
|
|
66
|
-
const openaiKey =
|
|
67
|
-
options.apiKey ?? process.env.AI_API_KEY ?? process.env.OPENAI_API_KEY;
|
|
68
|
-
if (openaiKey) {
|
|
69
|
-
return {
|
|
70
|
-
provider: 'openai',
|
|
71
|
-
model: options.model ?? process.env.AI_MODEL ?? 'gpt-4o',
|
|
72
|
-
apiKey: openaiKey,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export type AIModelResult = {
|
|
80
|
-
model: LanguageModel;
|
|
81
|
-
providerType: AIProviderType;
|
|
82
|
-
config: AIConfig;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export async function createAIModel(config: AIConfig): Promise<AIModelResult> {
|
|
86
|
-
switch (config.provider) {
|
|
87
|
-
case 'ollama': {
|
|
88
|
-
const { createOllama } = await import('ai-sdk-ollama');
|
|
89
|
-
const ollama = createOllama({
|
|
90
|
-
baseURL: config.baseUrl ?? 'http://127.0.0.1:11434',
|
|
91
|
-
});
|
|
92
|
-
return { model: ollama(config.model), providerType: 'ollama', config };
|
|
93
|
-
}
|
|
94
|
-
case 'openai': {
|
|
95
|
-
const { createOpenAI } = await import('@ai-sdk/openai');
|
|
96
|
-
const openai = createOpenAI({
|
|
97
|
-
apiKey: config.apiKey,
|
|
98
|
-
...(config.baseUrl ? { baseURL: config.baseUrl } : {}),
|
|
99
|
-
});
|
|
100
|
-
return { model: openai(config.model), providerType: 'openai', config };
|
|
101
|
-
}
|
|
102
|
-
case 'openai-compatible': {
|
|
103
|
-
const { createOpenAICompatible } =
|
|
104
|
-
await import('@ai-sdk/openai-compatible');
|
|
105
|
-
const provider = createOpenAICompatible({
|
|
106
|
-
baseURL: config.baseUrl ?? 'http://127.0.0.1:11434/v1',
|
|
107
|
-
name: 'custom',
|
|
108
|
-
...(config.apiKey
|
|
109
|
-
? { headers: { Authorization: `Bearer ${config.apiKey}` } }
|
|
110
|
-
: {}),
|
|
111
|
-
});
|
|
112
|
-
return {
|
|
113
|
-
model: provider(config.model),
|
|
114
|
-
providerType: 'openai-compatible',
|
|
115
|
-
config,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
default: {
|
|
119
|
-
throw new Error(
|
|
120
|
-
`Unsupported provider: "${config.provider}". Expected "ollama", "openai", or "openai-compatible".`,
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
package/src/ai/stream.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider-aware streamText wrapper.
|
|
3
|
-
*
|
|
4
|
-
* When the provider is Ollama, uses ai-sdk-ollama's streamText which has
|
|
5
|
-
* enhanced response synthesis for tool calling (Ollama models often return
|
|
6
|
-
* empty text after tool execution — the enhanced version detects this and
|
|
7
|
-
* synthesizes a response from tool results).
|
|
8
|
-
*
|
|
9
|
-
* For all other providers, uses the standard ai SDK streamText.
|
|
10
|
-
*/
|
|
11
|
-
import type { LanguageModel } from 'ai';
|
|
12
|
-
import type { AIProviderType } from './types';
|
|
13
|
-
|
|
14
|
-
type StreamTextParams = {
|
|
15
|
-
model: LanguageModel;
|
|
16
|
-
system?: string;
|
|
17
|
-
messages: Array<{ role: 'user' | 'assistant'; content: string }>;
|
|
18
|
-
tools?: Record<string, unknown>;
|
|
19
|
-
maxSteps?: number;
|
|
20
|
-
abortSignal?: AbortSignal;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type StreamResult = {
|
|
24
|
-
textStream: AsyncIterable<string>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export async function providerStreamText(
|
|
28
|
-
providerType: AIProviderType,
|
|
29
|
-
params: StreamTextParams,
|
|
30
|
-
): Promise<StreamResult> {
|
|
31
|
-
if (providerType === 'ollama') {
|
|
32
|
-
const mod = await import('ai-sdk-ollama');
|
|
33
|
-
// ai-sdk-ollama's streamText has enhanced synthesis for tool calling
|
|
34
|
-
const result = await mod.streamText(
|
|
35
|
-
params as Parameters<typeof mod.streamText>[0],
|
|
36
|
-
);
|
|
37
|
-
return result as unknown as StreamResult;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const mod = await import('ai');
|
|
41
|
-
return mod.streamText(
|
|
42
|
-
params as Parameters<typeof mod.streamText>[0],
|
|
43
|
-
) as unknown as StreamResult;
|
|
44
|
-
}
|
package/src/ai/system-prompt.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export function buildSystemPrompt(
|
|
2
|
-
viewMode: string,
|
|
3
|
-
contextJson: string,
|
|
4
|
-
): string {
|
|
5
|
-
return `You are an OpenTelemetry expert assistant analyzing live telemetry data from a running application.
|
|
6
|
-
The user is viewing their ${viewMode} dashboard in a terminal TUI.
|
|
7
|
-
|
|
8
|
-
You have tools to query the telemetry data precisely. Use them to answer questions:
|
|
9
|
-
- getOverviewStats: high-level stats (spans, errors, latency)
|
|
10
|
-
- listServices: all services with error rates and p95
|
|
11
|
-
- findSlowestSpans: find slow spans, optionally by service
|
|
12
|
-
- findErrorTraces: find traces with errors
|
|
13
|
-
- getTraceDetail: deep dive into a specific trace
|
|
14
|
-
- searchSpans: search spans by name
|
|
15
|
-
- searchLogs: search logs by message content
|
|
16
|
-
- renderUI: display rich terminal UI (tables, charts, badges)
|
|
17
|
-
|
|
18
|
-
## Workflow
|
|
19
|
-
1. Use data tools first to gather data
|
|
20
|
-
2. Use renderUI to display structured results as tables, charts, or cards
|
|
21
|
-
3. Add a brief text explanation after the rendered UI
|
|
22
|
-
|
|
23
|
-
## When to use renderUI
|
|
24
|
-
Use renderUI for tables, comparisons, and metrics. Do NOT use it for short text answers.
|
|
25
|
-
|
|
26
|
-
renderUI spec format: { root: "id", elements: { "id": { type: "ComponentName", props: {...}, children: [] } } }
|
|
27
|
-
|
|
28
|
-
Components: Table (columns, rows), KeyValue (label, value), Badge (label, variant: success/error/warning/info), BarChart (data: [{label,value}]), Card (title, children), Heading (text), Divider, Text (text, color, bold), Box (flexDirection, children).
|
|
29
|
-
|
|
30
|
-
Table example: { type: "Table", props: { columns: [{ header: "Name", key: "name" }], rows: [{ name: "api" }] }, children: [] }
|
|
31
|
-
|
|
32
|
-
Keep text responses under 300 words.
|
|
33
|
-
Use specific span names, durations, and attribute values from the data.
|
|
34
|
-
|
|
35
|
-
Current dashboard summary:
|
|
36
|
-
${contextJson}`;
|
|
37
|
-
}
|
package/src/ai/tools.test.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createTelemetryTools } from './tools';
|
|
3
|
-
|
|
4
|
-
const tools = createTelemetryTools({
|
|
5
|
-
spans: [],
|
|
6
|
-
logs: [],
|
|
7
|
-
traces: [],
|
|
8
|
-
stats: { total: 0, errors: 0, avg: 0, p95: 0 },
|
|
9
|
-
serviceStats: [],
|
|
10
|
-
errorSummaries: [],
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('renderUI tool schema', () => {
|
|
14
|
-
it('rejects specs that do not match the Ink renderer contract', () => {
|
|
15
|
-
const invalidSpec = {
|
|
16
|
-
spec: {
|
|
17
|
-
root: 'root',
|
|
18
|
-
elements: {
|
|
19
|
-
root: {
|
|
20
|
-
type: 'DefinitelyNotARealComponent',
|
|
21
|
-
props: { text: 'hello' },
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const schema = (
|
|
28
|
-
tools.renderUI as {
|
|
29
|
-
parameters?: { safeParse: (data: unknown) => { success: boolean } };
|
|
30
|
-
}
|
|
31
|
-
).parameters;
|
|
32
|
-
const result = schema?.safeParse(invalidSpec);
|
|
33
|
-
|
|
34
|
-
expect(result?.success).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
});
|
package/src/ai/tools.ts
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import { tool } from 'ai';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import type { TerminalSpanEvent } from '../span-stream';
|
|
4
|
-
import type { TerminalLogEvent } from '../lib/log-model';
|
|
5
|
-
import type { TraceSummary, SpanStats } from '../lib/trace-model';
|
|
6
|
-
import type { ServiceStats } from '../lib/stats-model';
|
|
7
|
-
import type { ErrorSummary } from '../lib/error-model';
|
|
8
|
-
import type { InkSpec } from './types';
|
|
9
|
-
import { validateSpec } from '@json-render/core';
|
|
10
|
-
import { standardComponentDefinitions } from '@json-render/ink/catalog';
|
|
11
|
-
|
|
12
|
-
/** Valid component names from the Ink catalog */
|
|
13
|
-
const COMPONENT_NAMES = Object.keys(standardComponentDefinitions) as [
|
|
14
|
-
string,
|
|
15
|
-
...string[],
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
// Helper: zod v4 schemas need to be cast for ai SDK v6's tool() which expects zod v3 types
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
const t: (...args: any[]) => any = tool;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Snapshot of dashboard state passed to tools at query time.
|
|
24
|
-
* Tools read from this — they don't mutate dashboard state.
|
|
25
|
-
*/
|
|
26
|
-
export type ToolContext = {
|
|
27
|
-
spans: TerminalSpanEvent[];
|
|
28
|
-
logs: TerminalLogEvent[];
|
|
29
|
-
traces: TraceSummary[];
|
|
30
|
-
stats: SpanStats;
|
|
31
|
-
serviceStats: ServiceStats[];
|
|
32
|
-
errorSummaries: ErrorSummary[];
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export function createTelemetryTools(
|
|
36
|
-
ctx: ToolContext,
|
|
37
|
-
onRenderUI?: (spec: InkSpec) => void,
|
|
38
|
-
) {
|
|
39
|
-
return {
|
|
40
|
-
getOverviewStats: t({
|
|
41
|
-
description:
|
|
42
|
-
'Get high-level stats: total spans, error count, average duration, p95 duration, and service count.',
|
|
43
|
-
parameters: z.object({}),
|
|
44
|
-
execute: async () => ({
|
|
45
|
-
totalSpans: ctx.stats.total,
|
|
46
|
-
errors: ctx.stats.errors,
|
|
47
|
-
avgMs: Math.round(ctx.stats.avg),
|
|
48
|
-
p95Ms: Math.round(ctx.stats.p95),
|
|
49
|
-
serviceCount: ctx.serviceStats.length,
|
|
50
|
-
traceCount: ctx.traces.length,
|
|
51
|
-
}),
|
|
52
|
-
}),
|
|
53
|
-
|
|
54
|
-
listServices: t({
|
|
55
|
-
description:
|
|
56
|
-
'List all services with their span counts, error counts, and p95 latencies.',
|
|
57
|
-
parameters: z.object({}),
|
|
58
|
-
execute: async () =>
|
|
59
|
-
ctx.serviceStats.map((s) => ({
|
|
60
|
-
serviceName: s.serviceName,
|
|
61
|
-
total: s.total,
|
|
62
|
-
errors: s.errors,
|
|
63
|
-
avgMs: Math.round(s.avgMs),
|
|
64
|
-
p95Ms: Math.round(s.p95Ms),
|
|
65
|
-
})),
|
|
66
|
-
}),
|
|
67
|
-
|
|
68
|
-
findSlowestSpans: t({
|
|
69
|
-
description:
|
|
70
|
-
'Find the slowest spans, optionally filtered by service name. Returns span name, duration, status, and key attributes.',
|
|
71
|
-
parameters: z.object({
|
|
72
|
-
service: z.string().optional().describe('Filter by service name'),
|
|
73
|
-
limit: z.number().optional().describe('Max results (default 10)'),
|
|
74
|
-
}),
|
|
75
|
-
execute: async ({
|
|
76
|
-
service,
|
|
77
|
-
limit,
|
|
78
|
-
}: {
|
|
79
|
-
service?: string;
|
|
80
|
-
limit?: number;
|
|
81
|
-
}) => {
|
|
82
|
-
const max = limit ?? 10;
|
|
83
|
-
let filtered = ctx.spans;
|
|
84
|
-
if (service) {
|
|
85
|
-
filtered = filtered.filter(
|
|
86
|
-
(s) => (s.attributes?.['service.name'] as string) === service,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
return filtered
|
|
90
|
-
.toSorted((a, b) => b.durationMs - a.durationMs)
|
|
91
|
-
.slice(0, max)
|
|
92
|
-
.map((s) => ({
|
|
93
|
-
name: s.name,
|
|
94
|
-
durationMs: Math.round(s.durationMs),
|
|
95
|
-
status: s.status,
|
|
96
|
-
service: (s.attributes?.['service.name'] as string) ?? 'unknown',
|
|
97
|
-
route: s.attributes?.['http.route'] as string | undefined,
|
|
98
|
-
traceId: s.traceId.slice(0, 8),
|
|
99
|
-
}));
|
|
100
|
-
},
|
|
101
|
-
}),
|
|
102
|
-
|
|
103
|
-
findErrorTraces: t({
|
|
104
|
-
description:
|
|
105
|
-
'Find traces that contain errors, with root span name, service, route, and error count.',
|
|
106
|
-
parameters: z.object({
|
|
107
|
-
service: z.string().optional().describe('Filter by service name'),
|
|
108
|
-
limit: z.number().optional().describe('Max results (default 10)'),
|
|
109
|
-
}),
|
|
110
|
-
execute: async ({
|
|
111
|
-
service,
|
|
112
|
-
limit,
|
|
113
|
-
}: {
|
|
114
|
-
service?: string;
|
|
115
|
-
limit?: number;
|
|
116
|
-
}) => {
|
|
117
|
-
const max = limit ?? 10;
|
|
118
|
-
let errors = ctx.errorSummaries;
|
|
119
|
-
if (service) {
|
|
120
|
-
errors = errors.filter((e) => e.serviceName === service);
|
|
121
|
-
}
|
|
122
|
-
return errors.slice(0, max).map((e) => ({
|
|
123
|
-
traceId: e.traceId.slice(0, 8),
|
|
124
|
-
rootName: e.rootName,
|
|
125
|
-
serviceName: e.serviceName,
|
|
126
|
-
route: e.route,
|
|
127
|
-
errorCount: e.errorCount,
|
|
128
|
-
}));
|
|
129
|
-
},
|
|
130
|
-
}),
|
|
131
|
-
|
|
132
|
-
getTraceDetail: t({
|
|
133
|
-
description:
|
|
134
|
-
'Get full detail of a specific trace by trace ID prefix. Returns all spans with their parent relationships, durations, and attributes.',
|
|
135
|
-
parameters: z.object({
|
|
136
|
-
traceIdPrefix: z
|
|
137
|
-
.string()
|
|
138
|
-
.describe('First 8+ characters of the trace ID'),
|
|
139
|
-
}),
|
|
140
|
-
execute: async ({ traceIdPrefix }: { traceIdPrefix: string }) => {
|
|
141
|
-
const trace = ctx.traces.find((t) =>
|
|
142
|
-
t.traceId.startsWith(traceIdPrefix),
|
|
143
|
-
);
|
|
144
|
-
if (!trace) {
|
|
145
|
-
return { error: `No trace found matching ${traceIdPrefix}` };
|
|
146
|
-
}
|
|
147
|
-
const traceLogs = ctx.logs.filter((l) => l.traceId === trace.traceId);
|
|
148
|
-
return {
|
|
149
|
-
traceId: trace.traceId.slice(0, 16),
|
|
150
|
-
rootName: trace.rootName,
|
|
151
|
-
durationMs: Math.round(trace.durationMs),
|
|
152
|
-
hasError: trace.hasError,
|
|
153
|
-
spanCount: trace.spanCount,
|
|
154
|
-
spans: trace.spans.map((s) => ({
|
|
155
|
-
name: s.name,
|
|
156
|
-
durationMs: Math.round(s.durationMs),
|
|
157
|
-
status: s.status,
|
|
158
|
-
kind: s.kind,
|
|
159
|
-
parentSpanId: s.parentSpanId?.slice(0, 8),
|
|
160
|
-
attrs: Object.fromEntries(
|
|
161
|
-
Object.entries(s.attributes ?? {}).filter(([k]) =>
|
|
162
|
-
[
|
|
163
|
-
'http.method',
|
|
164
|
-
'http.route',
|
|
165
|
-
'http.status_code',
|
|
166
|
-
'db.operation',
|
|
167
|
-
'db.system',
|
|
168
|
-
'service.name',
|
|
169
|
-
'error.message',
|
|
170
|
-
'error.type',
|
|
171
|
-
].includes(k),
|
|
172
|
-
),
|
|
173
|
-
),
|
|
174
|
-
})),
|
|
175
|
-
logs: traceLogs.slice(0, 10).map((l) => ({
|
|
176
|
-
level: l.level,
|
|
177
|
-
message: l.message.slice(0, 100),
|
|
178
|
-
})),
|
|
179
|
-
};
|
|
180
|
-
},
|
|
181
|
-
}),
|
|
182
|
-
|
|
183
|
-
searchSpans: t({
|
|
184
|
-
description:
|
|
185
|
-
'Search spans by name pattern (case-insensitive substring match). Returns matching spans with details.',
|
|
186
|
-
parameters: z.object({
|
|
187
|
-
query: z.string().describe('Search string to match against span names'),
|
|
188
|
-
limit: z.number().optional().describe('Max results (default 20)'),
|
|
189
|
-
}),
|
|
190
|
-
execute: async ({ query, limit }: { query: string; limit?: number }) => {
|
|
191
|
-
const max = limit ?? 20;
|
|
192
|
-
const q = query.toLowerCase();
|
|
193
|
-
return ctx.spans
|
|
194
|
-
.filter((s) => s.name.toLowerCase().includes(q))
|
|
195
|
-
.slice(0, max)
|
|
196
|
-
.map((s) => ({
|
|
197
|
-
name: s.name,
|
|
198
|
-
durationMs: Math.round(s.durationMs),
|
|
199
|
-
status: s.status,
|
|
200
|
-
traceId: s.traceId.slice(0, 8),
|
|
201
|
-
service: (s.attributes?.['service.name'] as string) ?? 'unknown',
|
|
202
|
-
}));
|
|
203
|
-
},
|
|
204
|
-
}),
|
|
205
|
-
|
|
206
|
-
searchLogs: t({
|
|
207
|
-
description:
|
|
208
|
-
'Search logs by message content (case-insensitive). Returns matching log entries.',
|
|
209
|
-
parameters: z.object({
|
|
210
|
-
query: z
|
|
211
|
-
.string()
|
|
212
|
-
.describe('Search string to match against log messages'),
|
|
213
|
-
level: z
|
|
214
|
-
.enum(['debug', 'info', 'warn', 'error'])
|
|
215
|
-
.optional()
|
|
216
|
-
.describe('Filter by log level'),
|
|
217
|
-
limit: z.number().optional().describe('Max results (default 20)'),
|
|
218
|
-
}),
|
|
219
|
-
execute: async ({
|
|
220
|
-
query,
|
|
221
|
-
level,
|
|
222
|
-
limit,
|
|
223
|
-
}: {
|
|
224
|
-
query: string;
|
|
225
|
-
level?: string;
|
|
226
|
-
limit?: number;
|
|
227
|
-
}) => {
|
|
228
|
-
const max = limit ?? 20;
|
|
229
|
-
const q = query.toLowerCase();
|
|
230
|
-
let filtered = ctx.logs.filter((l) =>
|
|
231
|
-
l.message.toLowerCase().includes(q),
|
|
232
|
-
);
|
|
233
|
-
if (level) {
|
|
234
|
-
filtered = filtered.filter((l) => l.level === level);
|
|
235
|
-
}
|
|
236
|
-
return filtered.slice(0, max).map((l) => ({
|
|
237
|
-
level: l.level,
|
|
238
|
-
message: l.message.slice(0, 200),
|
|
239
|
-
traceId: l.traceId?.slice(0, 8),
|
|
240
|
-
attrs: l.attributes,
|
|
241
|
-
}));
|
|
242
|
-
},
|
|
243
|
-
}),
|
|
244
|
-
|
|
245
|
-
renderUI: t({
|
|
246
|
-
description:
|
|
247
|
-
'Render rich terminal UI (tables, charts, badges) to display structured data. Use this when showing tabular data, comparisons, or metrics — not for short text answers. Available components: Table (columns + rows), KeyValue (key-value pairs), Badge (status labels: default/info/success/warning/error), BarChart (horizontal bars with labels), Card (grouped content with title), Heading (section title), Divider (separator), Text (styled text), Box (layout container).',
|
|
248
|
-
parameters: z.object({
|
|
249
|
-
spec: z
|
|
250
|
-
.object({
|
|
251
|
-
root: z.string().describe('ID of the root element'),
|
|
252
|
-
elements: z
|
|
253
|
-
.record(
|
|
254
|
-
z.string(),
|
|
255
|
-
z.object({
|
|
256
|
-
type: z.enum(COMPONENT_NAMES).describe('Component name'),
|
|
257
|
-
props: z.record(z.string(), z.unknown()).optional(),
|
|
258
|
-
children: z.array(z.string()).describe('Child element keys'),
|
|
259
|
-
}),
|
|
260
|
-
)
|
|
261
|
-
.describe('Map of element ID to component definition'),
|
|
262
|
-
})
|
|
263
|
-
.describe('json-render spec defining the UI to display'),
|
|
264
|
-
}),
|
|
265
|
-
execute: async ({ spec }: { spec: InkSpec }) => {
|
|
266
|
-
const validation = validateSpec(spec);
|
|
267
|
-
if (!validation.valid) {
|
|
268
|
-
return {
|
|
269
|
-
rendered: false,
|
|
270
|
-
error: validation.issues.map((i) => i.message).join('; '),
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
onRenderUI?.(spec);
|
|
274
|
-
return { rendered: true };
|
|
275
|
-
},
|
|
276
|
-
}),
|
|
277
|
-
};
|
|
278
|
-
}
|
package/src/ai/types.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type AIProviderType = 'ollama' | 'openai' | 'openai-compatible';
|
|
2
|
-
|
|
3
|
-
export type AIConfig = {
|
|
4
|
-
provider: AIProviderType;
|
|
5
|
-
model: string;
|
|
6
|
-
apiKey?: string;
|
|
7
|
-
baseUrl?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type ChatMessage = {
|
|
11
|
-
role: 'user' | 'assistant';
|
|
12
|
-
content: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type AIState =
|
|
16
|
-
| { status: 'unconfigured' }
|
|
17
|
-
| { status: 'idle' }
|
|
18
|
-
| { status: 'streaming'; abortController: AbortController }
|
|
19
|
-
| { status: 'error'; message: string };
|
|
20
|
-
|
|
21
|
-
/** json-render spec for rich AI output — re-export from @json-render/ink */
|
|
22
|
-
export type { InkSpec } from '@json-render/ink';
|
package/src/cli-stream.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { TerminalSpanEvent, TerminalSpanStream } from './span-stream';
|
|
2
|
-
|
|
3
|
-
type Subscriber = (event: TerminalSpanEvent) => void;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In-memory stream implementation for standalone CLI ingestion.
|
|
7
|
-
*/
|
|
8
|
-
export class CliTerminalSpanStream implements TerminalSpanStream {
|
|
9
|
-
#subscribers = new Set<Subscriber>();
|
|
10
|
-
|
|
11
|
-
onSpanEnd(callback: Subscriber): () => void {
|
|
12
|
-
this.#subscribers.add(callback);
|
|
13
|
-
return () => {
|
|
14
|
-
this.#subscribers.delete(callback);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
push(event: TerminalSpanEvent): void {
|
|
19
|
-
for (const subscriber of this.#subscribers) {
|
|
20
|
-
subscriber(event);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|