src / adapter.ts
/**
* Thin adapter from SDK ChatMessage objects to the plain CanonMessage shape
* the pure logic operates on. Kept minimal: everything interesting is tested
* against CanonMessage directly.
*/
import { ChatMessage, LMStudioClient } from "@lmstudio/sdk";
import { CanonMessage } from "./view";
export function toCanon(m: ChatMessage, client: LMStudioClient): CanonMessage {
let files: string[] | undefined;
try {
if (m.hasFiles()) files = m.getFiles(client).map((f) => f.name);
} catch {
files = ["<unreadable attachment>"];
}
return {
role: m.getRole(),
text: m.getText(),
toolCalls: m.getToolCallRequests().map((r) => ({
name: r.name,
args: JSON.stringify(r.arguments ?? {}),
})),
toolResults: m.getToolCallResults().map((r) => ({ content: r.content })),
files,
};
}
src / adapter.ts
/**
* Thin adapter from SDK ChatMessage objects to the plain CanonMessage shape
* the pure logic operates on. Kept minimal: everything interesting is tested
* against CanonMessage directly.
*/
import { ChatMessage, LMStudioClient } from "@lmstudio/sdk";
import { CanonMessage } from "./view";
export function toCanon(m: ChatMessage, client: LMStudioClient): CanonMessage {
let files: string[] | undefined;
try {
if (m.hasFiles()) files = m.getFiles(client).map((f) => f.name);
} catch {
files = ["<unreadable attachment>"];
}
return {
role: m.getRole(),
text: m.getText(),
toolCalls: m.getToolCallRequests().map((r) => ({
name: r.name,
args: JSON.stringify(r.arguments ?? {}),
})),
toolResults: m.getToolCallResults().map((r) => ({ content: r.content })),
files,
};
}