src / types.ts
import {
type ChatCompletionMessageParam,
type ChatCompletionMessageToolCall,
type ChatCompletionTool,
} from "openai/resources/index.js";
/* -------------------------------------------------------------------------- */
/* Wire message types */
/* -------------------------------------------------------------------------- */
/** Assistant message extended with provider-specific extras (e.g. reasoning_content). */
export type OpenAICompatAssistantMessage = {
role: "assistant";
content: string;
tool_calls?: ChatCompletionMessageToolCall[];
[key: string]: unknown;
};
/** Union of wire message shapes accepted by the upstream completions endpoint. */
export type OpenAICompatMessageParam = ChatCompletionMessageParam | OpenAICompatAssistantMessage;
/* -------------------------------------------------------------------------- */
/* Outbound request body */
/* */
/* Precise model of the OpenAI-COMPATIBLE SUPERSET we transmit: the base */
/* completions fields plus provider-specific extensions (top_k, min_p, */
/* reasoning_effort, preserve_thinking, priority, …). `stream: true` is a */
/* literal so the SDK resolves its streaming overload. The trailing index */
/* signature admits future vendor keys without reshaping this type. */
/* -------------------------------------------------------------------------- */
export type ShartiCompletionsBody = {
model: string;
messages: OpenAICompatMessageParam[];
stream: true;
stream_options: { include_usage: true };
// Base sampling / tooling fields
temperature?: number;
top_p?: number;
max_tokens?: number;
seed?: number;
presence_penalty?: number;
frequency_penalty?: number;
tools?: ChatCompletionTool[];
tool_choice?: "auto" | "required" | "none";
parallel_tool_calls?: boolean;
// Provider-specific extensions (OpenAI-compatible superset)
top_k?: number;
min_p?: number;
repetition_penalty?: number;
reasoning_effort?: string;
thinking_token_budget?: number;
preserve_thinking?: boolean;
priority?: string;
timeout?: number;
[key: string]: unknown;
};
/* -------------------------------------------------------------------------- */
/* Upstream stream chunk */
/* */
/* Deliberate structural SUPERSET of the OpenAI chunk plus LM Studio / Splash */
/* extras (native reasoning, timing telemetry). Defined WITHOUT index */
/* signatures so the SDK's concrete ChatCompletionChunk remains assignable */
/* to it — the consumer therefore needs no cast at the boundary. */
/* -------------------------------------------------------------------------- */
export type UpstreamUsage = {
prompt_tokens?: number;
completion_tokens?: number;
total_tokens?: number;
};
export type UpstreamTiming = Record<string, unknown>;
export type UpstreamToolCallDelta = {
index: number;
id?: string;
function?: { name?: string; arguments?: string };
};
export type UpstreamDelta = {
content?: string | null;
tool_calls?: UpstreamToolCallDelta[];
/** Native reasoning channel (provider-specific). */
reasoning_content?: unknown;
};
export type UpstreamChoice = {
delta?: UpstreamDelta;
finish_reason?: string | null;
};
export type UpstreamChunk = {
choices?: UpstreamChoice[];
usage?: UpstreamUsage | null;
timings?: UpstreamTiming;
};
/* -------------------------------------------------------------------------- */
/* Streaming state */
/* -------------------------------------------------------------------------- */
/** Mutable state for a single in-flight tool call while assembling its arguments. */
export type ToolCallState = {
id: string;
name: string | null;
index: number;
arguments: string;
};
/* -------------------------------------------------------------------------- */
/* Aggregated statistics */
/* -------------------------------------------------------------------------- */
/** Metrics gathered from a single completed request stream. */
export type GenerationStats = {
inputTokens: number | null;
outputTokens: number | null;
totalTokens: number | null;
/** Decode throughput (tok/s): server-reported when available, else derived. */
tokensPerSecond: number | null;
timeToFirstTokenSeconds: number | null;
totalTimeSeconds: number | null;
promptPerSecond: number | null;
cachedTokens: number | null;
rawTimings: UpstreamTiming | null;
finishReason: string | null;
};
src / types.ts
import {
type ChatCompletionMessageParam,
type ChatCompletionMessageToolCall,
type ChatCompletionTool,
} from "openai/resources/index.js";
/* -------------------------------------------------------------------------- */
/* Wire message types */
/* -------------------------------------------------------------------------- */
/** Assistant message extended with provider-specific extras (e.g. reasoning_content). */
export type OpenAICompatAssistantMessage = {
role: "assistant";
content: string;
tool_calls?: ChatCompletionMessageToolCall[];
[key: string]: unknown;
};
/** Union of wire message shapes accepted by the upstream completions endpoint. */
export type OpenAICompatMessageParam = ChatCompletionMessageParam | OpenAICompatAssistantMessage;
/* -------------------------------------------------------------------------- */
/* Outbound request body */
/* */
/* Precise model of the OpenAI-COMPATIBLE SUPERSET we transmit: the base */
/* completions fields plus provider-specific extensions (top_k, min_p, */
/* reasoning_effort, preserve_thinking, priority, …). `stream: true` is a */
/* literal so the SDK resolves its streaming overload. The trailing index */
/* signature admits future vendor keys without reshaping this type. */
/* -------------------------------------------------------------------------- */
export type ShartiCompletionsBody = {
model: string;
messages: OpenAICompatMessageParam[];
stream: true;
stream_options: { include_usage: true };
// Base sampling / tooling fields
temperature?: number;
top_p?: number;
max_tokens?: number;
seed?: number;
presence_penalty?: number;
frequency_penalty?: number;
tools?: ChatCompletionTool[];
tool_choice?: "auto" | "required" | "none";
parallel_tool_calls?: boolean;
// Provider-specific extensions (OpenAI-compatible superset)
top_k?: number;
min_p?: number;
repetition_penalty?: number;
reasoning_effort?: string;
thinking_token_budget?: number;
preserve_thinking?: boolean;
priority?: string;
timeout?: number;
[key: string]: unknown;
};
/* -------------------------------------------------------------------------- */
/* Upstream stream chunk */
/* */
/* Deliberate structural SUPERSET of the OpenAI chunk plus LM Studio / Splash */
/* extras (native reasoning, timing telemetry). Defined WITHOUT index */
/* signatures so the SDK's concrete ChatCompletionChunk remains assignable */
/* to it — the consumer therefore needs no cast at the boundary. */
/* -------------------------------------------------------------------------- */
export type UpstreamUsage = {
prompt_tokens?: number;
completion_tokens?: number;
total_tokens?: number;
};
export type UpstreamTiming = Record<string, unknown>;
export type UpstreamToolCallDelta = {
index: number;
id?: string;
function?: { name?: string; arguments?: string };
};
export type UpstreamDelta = {
content?: string | null;
tool_calls?: UpstreamToolCallDelta[];
/** Native reasoning channel (provider-specific). */
reasoning_content?: unknown;
};
export type UpstreamChoice = {
delta?: UpstreamDelta;
finish_reason?: string | null;
};
export type UpstreamChunk = {
choices?: UpstreamChoice[];
usage?: UpstreamUsage | null;
timings?: UpstreamTiming;
};
/* -------------------------------------------------------------------------- */
/* Streaming state */
/* -------------------------------------------------------------------------- */
/** Mutable state for a single in-flight tool call while assembling its arguments. */
export type ToolCallState = {
id: string;
name: string | null;
index: number;
arguments: string;
};
/* -------------------------------------------------------------------------- */
/* Aggregated statistics */
/* -------------------------------------------------------------------------- */
/** Metrics gathered from a single completed request stream. */
export type GenerationStats = {
inputTokens: number | null;
outputTokens: number | null;
totalTokens: number | null;
/** Decode throughput (tok/s): server-reported when available, else derived. */
tokensPerSecond: number | null;
timeToFirstTokenSeconds: number | null;
totalTimeSeconds: number | null;
promptPerSecond: number | null;
cachedTokens: number | null;
rawTimings: UpstreamTiming | null;
finishReason: string | null;
};