Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,17 @@ export async function dispatchSlashCommand(
return true;
}

// If input starts with "/" but no command matched, show unknown command feedback
// If input starts with "/" but no built-in command matched, check if an
// extension owns this command before showing an error. Returning false
// lets the caller (input-controller) fall through to session.prompt() which
// routes extension commands correctly.
if (text.startsWith("/")) {
const spaceIdx = text.indexOf(" ");
const commandName = spaceIdx === -1 ? text.slice(1) : text.slice(1, spaceIdx);
const extensionRunner = ctx.session.extensionRunner;
if (extensionRunner?.getCommand(commandName)) {
return false; // handled by extension system
}
const command = text.split(/\s/)[0];
ctx.showError(`Unknown command: ${command}. Type /help for available commands.`);
return true;
Expand Down
5 changes: 4 additions & 1 deletion src/resources/extensions/ollama/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
*/

import { importExtensionModule, type ExtensionAPI } from "@gsd/pi-coding-agent";
import type { OpenAICompletionsCompat } from "@gsd/pi-ai";
import type { OpenAICompletionsCompat, Model } from "@gsd/pi-ai";
import { streamOpenAICompletions } from "@gsd/pi-ai";
import * as client from "./ollama-client.js";
import { discoverModels, getOllamaOpenAIBaseUrl } from "./ollama-discovery.js";
import { registerOllamaCommands } from "./ollama-commands.js";
Expand Down Expand Up @@ -74,6 +75,8 @@ async function probeAndRegister(pi: ExtensionAPI): Promise<boolean> {
authMode: "none",
baseUrl,
api: "openai-completions",
streamSimple: (model, context, options) =>
streamOpenAICompletions(model as Model<"openai-completions">, context, { ...options, apiKey: "ollama" }),
isReady: () => true,
models: models.map((m) => ({
id: m.id,
Expand Down
41 changes: 28 additions & 13 deletions src/resources/extensions/ollama/ollama-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

import type { ExtensionAPI } from "@gsd/pi-coding-agent";
import { Text } from "@gsd/pi-tui";
import * as client from "./ollama-client.js";
import { discoverModels, formatModelForDisplay } from "./ollama-discovery.js";
import { formatModelSize } from "./model-capabilities.js";
Expand Down Expand Up @@ -100,10 +99,18 @@ async function handleStatus(ctx: any): Promise<void> {
}

await ctx.ui.custom(
(tui: any, theme: any, _kb: any, done: (r: undefined) => void) => {
const text = new Text(lines.map((l) => theme.fg("fg", l)).join("\n"), 0, 0);
setTimeout(() => done(undefined), 0);
return text;
(_tui: any, theme: any, _kb: any, done: (r: undefined) => void) => {
function handleInput(_data: string) {
done(undefined);
}
function render(width: number): string[] {
return [
...lines.map((l) => theme.fg("text", l)),
"",
theme.fg("dim", " Press any key to dismiss"),
];
}
return { render, handleInput, invalidate: () => {} };
},
);
}
Expand All @@ -127,10 +134,14 @@ async function handleList(ctx: any): Promise<void> {
}

await ctx.ui.custom(
(tui: any, theme: any, _kb: any, done: (r: undefined) => void) => {
const text = new Text(lines.map((l) => theme.fg("fg", l)).join("\n"), 0, 0);
setTimeout(() => done(undefined), 0);
return text;
(_tui: any, theme: any, _kb: any, done: (r: undefined) => void) => {
function handleInput(_data: string) {
done(undefined);
}
function render(width: number): string[] {
return lines.map((l) => theme.fg("text", l));
}
return { render, handleInput, invalidate: () => {} };
},
);
}
Expand Down Expand Up @@ -233,10 +244,14 @@ async function handlePs(ctx: any): Promise<void> {
}

await ctx.ui.custom(
(tui: any, theme: any, _kb: any, done: (r: undefined) => void) => {
const text = new Text(lines.map((l) => theme.fg("fg", l)).join("\n"), 0, 0);
setTimeout(() => done(undefined), 0);
return text;
(_tui: any, theme: any, _kb: any, done: (r: undefined) => void) => {
function handleInput(_data: string) {
done(undefined);
}
function render(width: number): string[] {
return lines.map((l) => theme.fg("text", l));
}
return { render, handleInput, invalidate: () => {} };
},
);
} catch (err) {
Expand Down
Loading