mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-27 00:33:34 +00:00
refactor(plugin-sdk): share auth, routing, and stream/account helpers
This commit is contained in:
@@ -17,10 +17,32 @@ export function buildZeroUsage(): Usage {
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantMessageWithZeroUsage(params: {
|
||||
export function buildUsageWithNoCost(params: {
|
||||
input?: number;
|
||||
output?: number;
|
||||
cacheRead?: number;
|
||||
cacheWrite?: number;
|
||||
totalTokens?: number;
|
||||
}): Usage {
|
||||
const input = params.input ?? 0;
|
||||
const output = params.output ?? 0;
|
||||
const cacheRead = params.cacheRead ?? 0;
|
||||
const cacheWrite = params.cacheWrite ?? 0;
|
||||
return {
|
||||
input,
|
||||
output,
|
||||
cacheRead,
|
||||
cacheWrite,
|
||||
totalTokens: params.totalTokens ?? input + output,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantMessage(params: {
|
||||
model: StreamModelDescriptor;
|
||||
content: AssistantMessage["content"];
|
||||
stopReason: StopReason;
|
||||
usage: Usage;
|
||||
timestamp?: number;
|
||||
}): AssistantMessage {
|
||||
return {
|
||||
@@ -30,11 +52,26 @@ export function buildAssistantMessageWithZeroUsage(params: {
|
||||
api: params.model.api,
|
||||
provider: params.model.provider,
|
||||
model: params.model.id,
|
||||
usage: buildZeroUsage(),
|
||||
usage: params.usage,
|
||||
timestamp: params.timestamp ?? Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAssistantMessageWithZeroUsage(params: {
|
||||
model: StreamModelDescriptor;
|
||||
content: AssistantMessage["content"];
|
||||
stopReason: StopReason;
|
||||
timestamp?: number;
|
||||
}): AssistantMessage {
|
||||
return buildAssistantMessage({
|
||||
model: params.model,
|
||||
content: params.content,
|
||||
stopReason: params.stopReason,
|
||||
usage: buildZeroUsage(),
|
||||
timestamp: params.timestamp,
|
||||
});
|
||||
}
|
||||
|
||||
export function buildStreamErrorAssistantMessage(params: {
|
||||
model: StreamModelDescriptor;
|
||||
errorMessage: string;
|
||||
|
||||
Reference in New Issue
Block a user