@lunchbox-labs/opencode-tool-inspector 0.2.4 → 0.3.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 +5 -5
- package/dist/tui.d.ts +4 -5
- package/dist/tui.js +1380 -394
- package/package.json +6 -25
- package/dist/agent-text.d.ts +0 -4
- package/dist/agent-text.js +0 -85
- package/dist/agents.d.ts +0 -79
- package/dist/agents.js +0 -244
- package/dist/detail-viewer.d.ts +0 -6
- package/dist/detail-viewer.js +0 -123
- package/dist/schema-text.d.ts +0 -13
- package/dist/schema-text.js +0 -735
- package/dist/tool-detail.d.ts +0 -17
- package/dist/tool-detail.js +0 -41
- package/dist/tools.d.ts +0 -34
- package/dist/tools.js +0 -119
package/dist/tool-detail.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ToolAgentAccess } from "./agents.ts";
|
|
2
|
-
import { type TextLine } from "./schema-text.ts";
|
|
3
|
-
import type { BrowsableTool } from "./tools.ts";
|
|
4
|
-
export interface DetailSection {
|
|
5
|
-
heading: string;
|
|
6
|
-
lines: TextLine[];
|
|
7
|
-
}
|
|
8
|
-
export interface ToolDetail {
|
|
9
|
-
title: string;
|
|
10
|
-
subtitle: string | undefined;
|
|
11
|
-
sections: DetailSection[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The detail view's content. The Agents section is left out when OpenCode's agents couldn't be
|
|
15
|
-
* read.
|
|
16
|
-
*/
|
|
17
|
-
export declare function toolDetail(tool: BrowsableTool, modelLabel: string | undefined, access?: ToolAgentAccess): ToolDetail;
|
package/dist/tool-detail.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { agentAccessLines } from "./agent-text.js";
|
|
2
|
-
import { schemaLines } from "./schema-text.js";
|
|
3
|
-
function muted(text) {
|
|
4
|
-
return [[{ text, tone: "muted" }]];
|
|
5
|
-
}
|
|
6
|
-
function textLines(text) {
|
|
7
|
-
return text
|
|
8
|
-
.trim()
|
|
9
|
-
.split(/\r?\n/)
|
|
10
|
-
.map((line) => [{ text: line, tone: "plain" }]);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* The detail view's content. The Agents section is left out when OpenCode's agents couldn't be
|
|
14
|
-
* read.
|
|
15
|
-
*/
|
|
16
|
-
export function toolDetail(tool, modelLabel, access) {
|
|
17
|
-
const detailsMissing = "OpenCode reported only this tool's name.";
|
|
18
|
-
return {
|
|
19
|
-
title: tool.id,
|
|
20
|
-
subtitle: modelLabel === undefined ? undefined : `As offered to ${modelLabel}`,
|
|
21
|
-
sections: [
|
|
22
|
-
{
|
|
23
|
-
heading: "Input",
|
|
24
|
-
lines: tool.description === undefined && tool.parameters === undefined
|
|
25
|
-
? muted(detailsMissing)
|
|
26
|
-
: schemaLines(tool.parameters),
|
|
27
|
-
},
|
|
28
|
-
...(access === undefined
|
|
29
|
-
? []
|
|
30
|
-
: [{ heading: "Agents", lines: agentAccessLines(access) }]),
|
|
31
|
-
{
|
|
32
|
-
heading: "Description",
|
|
33
|
-
lines: tool.description === undefined
|
|
34
|
-
? muted(detailsMissing)
|
|
35
|
-
: tool.description.trim() === ""
|
|
36
|
-
? muted("No description.")
|
|
37
|
-
: textLines(tool.description),
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
};
|
|
41
|
-
}
|
package/dist/tools.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export interface ModelChoice {
|
|
2
|
-
providerID: string;
|
|
3
|
-
modelID: string;
|
|
4
|
-
}
|
|
5
|
-
/** Where the browsed model came from, since the next prompt may use another. */
|
|
6
|
-
export type ModelSource = "session" | "configured" | "provider default";
|
|
7
|
-
export interface ChosenModel extends ModelChoice {
|
|
8
|
-
source: ModelSource;
|
|
9
|
-
}
|
|
10
|
-
export interface BrowsableTool {
|
|
11
|
-
id: string;
|
|
12
|
-
/** Undefined when OpenCode reported only the tool's id. */
|
|
13
|
-
description: string | undefined;
|
|
14
|
-
parameters: unknown;
|
|
15
|
-
}
|
|
16
|
-
export declare function modelLabel(model: ModelChoice): string;
|
|
17
|
-
export declare function chosenModelLabel(model: ChosenModel): string;
|
|
18
|
-
/** The model of the session's latest user message, which OpenCode resolves tools for on the next prompt. */
|
|
19
|
-
export declare function sessionModel(messages: readonly unknown[]): ModelChoice | undefined;
|
|
20
|
-
/** Parses the `provider/model` form used by the `model` setting. */
|
|
21
|
-
export declare function configuredModel(model: unknown): ModelChoice | undefined;
|
|
22
|
-
/** The first connected provider's default model, which OpenCode falls back to when none is configured. */
|
|
23
|
-
export declare function providerDefaultModel(connectedProviderIds: readonly string[], defaults: unknown): ModelChoice | undefined;
|
|
24
|
-
/** Keeps well-formed entries from OpenCode's tool list, sorted by id. */
|
|
25
|
-
export declare function toolsFromList(response: unknown): BrowsableTool[] | undefined;
|
|
26
|
-
/** Tool ids without details, for when OpenCode can't resolve tools for a model. */
|
|
27
|
-
export declare function toolsFromIds(response: unknown): BrowsableTool[] | undefined;
|
|
28
|
-
/** The first line of a description without its list marker, short enough for one list row. */
|
|
29
|
-
export declare function descriptionSummary(description: string | undefined): string;
|
|
30
|
-
/**
|
|
31
|
-
* The number of top-level input properties, or undefined when the schema has none to count, such
|
|
32
|
-
* as a union beside empty `properties`.
|
|
33
|
-
*/
|
|
34
|
-
export declare function inputCount(parameters: unknown): number | undefined;
|
package/dist/tools.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
const sourceLabels = {
|
|
2
|
-
session: "this session's model",
|
|
3
|
-
configured: "configured model",
|
|
4
|
-
"provider default": "provider default",
|
|
5
|
-
};
|
|
6
|
-
/** OpenCode's placeholder for unknown tool calls, never offered to agents as a real tool. */
|
|
7
|
-
const internalToolIds = new Set(["invalid"]);
|
|
8
|
-
function isRecord(value) {
|
|
9
|
-
return typeof value === "object" && value !== null;
|
|
10
|
-
}
|
|
11
|
-
export function modelLabel(model) {
|
|
12
|
-
return `${model.providerID}/${model.modelID}`;
|
|
13
|
-
}
|
|
14
|
-
export function chosenModelLabel(model) {
|
|
15
|
-
return `${modelLabel(model)} (${sourceLabels[model.source]})`;
|
|
16
|
-
}
|
|
17
|
-
/** The model of the session's latest user message, which OpenCode resolves tools for on the next prompt. */
|
|
18
|
-
export function sessionModel(messages) {
|
|
19
|
-
for (const message of [...messages].reverse()) {
|
|
20
|
-
if (!isRecord(message) || message.role !== "user") {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const model = message.model;
|
|
24
|
-
if (isRecord(model) &&
|
|
25
|
-
typeof model.providerID === "string" &&
|
|
26
|
-
typeof model.modelID === "string" &&
|
|
27
|
-
model.providerID !== "" &&
|
|
28
|
-
model.modelID !== "") {
|
|
29
|
-
return { providerID: model.providerID, modelID: model.modelID };
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
/** Parses the `provider/model` form used by the `model` setting. */
|
|
35
|
-
export function configuredModel(model) {
|
|
36
|
-
if (typeof model !== "string") {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
const separator = model.indexOf("/");
|
|
40
|
-
if (separator <= 0 || separator === model.length - 1) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
providerID: model.slice(0, separator),
|
|
45
|
-
modelID: model.slice(separator + 1),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
/** The first connected provider's default model, which OpenCode falls back to when none is configured. */
|
|
49
|
-
export function providerDefaultModel(connectedProviderIds, defaults) {
|
|
50
|
-
if (!isRecord(defaults)) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
for (const providerID of connectedProviderIds) {
|
|
54
|
-
const modelID = defaults[providerID];
|
|
55
|
-
if (typeof modelID === "string" && modelID !== "") {
|
|
56
|
-
return { providerID, modelID };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
function byId(left, right) {
|
|
62
|
-
return left.id.localeCompare(right.id);
|
|
63
|
-
}
|
|
64
|
-
/** Keeps well-formed entries from OpenCode's tool list, sorted by id. */
|
|
65
|
-
export function toolsFromList(response) {
|
|
66
|
-
if (!Array.isArray(response)) {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
const tools = new Map();
|
|
70
|
-
for (const item of response) {
|
|
71
|
-
if (!isRecord(item) ||
|
|
72
|
-
typeof item.id !== "string" ||
|
|
73
|
-
item.id === "" ||
|
|
74
|
-
internalToolIds.has(item.id)) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
tools.set(item.id, {
|
|
78
|
-
id: item.id,
|
|
79
|
-
description: typeof item.description === "string" ? item.description : undefined,
|
|
80
|
-
parameters: item.parameters,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return [...tools.values()].sort(byId);
|
|
84
|
-
}
|
|
85
|
-
/** Tool ids without details, for when OpenCode can't resolve tools for a model. */
|
|
86
|
-
export function toolsFromIds(response) {
|
|
87
|
-
if (!Array.isArray(response)) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
const ids = new Set(response.filter((id) => typeof id === "string" && id !== "" && !internalToolIds.has(id)));
|
|
91
|
-
return [...ids]
|
|
92
|
-
.map((id) => ({ id, description: undefined, parameters: undefined }))
|
|
93
|
-
.sort(byId);
|
|
94
|
-
}
|
|
95
|
-
const summaryLength = 100;
|
|
96
|
-
/** The first line of a description without its list marker, short enough for one list row. */
|
|
97
|
-
export function descriptionSummary(description) {
|
|
98
|
-
const firstLine = description
|
|
99
|
-
?.split(/\r?\n/)
|
|
100
|
-
.map((line) => line.trim().replace(/^[-*•]\s+/, ""))
|
|
101
|
-
.find((line) => line !== "") ?? "";
|
|
102
|
-
return firstLine.length > summaryLength
|
|
103
|
-
? `${firstLine.slice(0, summaryLength - 1).trimEnd()}…`
|
|
104
|
-
: firstLine;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* The number of top-level input properties, or undefined when the schema has none to count, such
|
|
108
|
-
* as a union beside empty `properties`.
|
|
109
|
-
*/
|
|
110
|
-
export function inputCount(parameters) {
|
|
111
|
-
if (!isRecord(parameters) || !isRecord(parameters.properties)) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
const count = Object.keys(parameters.properties).length;
|
|
115
|
-
return count === 0 &&
|
|
116
|
-
(parameters.anyOf !== undefined || parameters.oneOf !== undefined)
|
|
117
|
-
? undefined
|
|
118
|
-
: count;
|
|
119
|
-
}
|