GigaChat: use resolved profile metadata in compaction
This commit is contained in:
parent
b7a637f189
commit
1f5a3933c8
@ -47,6 +47,7 @@ const {
|
|||||||
authStorage: { setRuntimeApiKey: vi.fn() },
|
authStorage: { setRuntimeApiKey: vi.fn() },
|
||||||
modelRegistry: {},
|
modelRegistry: {},
|
||||||
})),
|
})),
|
||||||
|
ensureAuthProfileStoreMock: vi.fn(),
|
||||||
sessionCompactImpl: vi.fn(async () => ({
|
sessionCompactImpl: vi.fn(async () => ({
|
||||||
summary: "summary",
|
summary: "summary",
|
||||||
firstKeptEntryId: "entry-1",
|
firstKeptEntryId: "entry-1",
|
||||||
@ -324,6 +325,7 @@ vi.mock("./sandbox-info.js", () => ({
|
|||||||
vi.mock("./model.js", () => ({
|
vi.mock("./model.js", () => ({
|
||||||
buildModelAliasLines: vi.fn(() => []),
|
buildModelAliasLines: vi.fn(() => []),
|
||||||
resolveModel: resolveModelMock,
|
resolveModel: resolveModelMock,
|
||||||
|
resolveModelAsync: resolveModelMock,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("./session-manager-cache.js", () => ({
|
vi.mock("./session-manager-cache.js", () => ({
|
||||||
@ -345,6 +347,7 @@ vi.mock("./utils.js", () => ({
|
|||||||
|
|
||||||
import { getApiProvider, unregisterApiProviders } from "@mariozechner/pi-ai";
|
import { getApiProvider, unregisterApiProviders } from "@mariozechner/pi-ai";
|
||||||
import { getCustomApiRegistrySourceId } from "../custom-api-registry.js";
|
import { getCustomApiRegistrySourceId } from "../custom-api-registry.js";
|
||||||
|
import { getApiKeyForModel } from "../model-auth.js";
|
||||||
import { compactEmbeddedPiSessionDirect, compactEmbeddedPiSession } from "./compact.js";
|
import { compactEmbeddedPiSessionDirect, compactEmbeddedPiSession } from "./compact.js";
|
||||||
|
|
||||||
const TEST_SESSION_ID = "session-1";
|
const TEST_SESSION_ID = "session-1";
|
||||||
@ -874,6 +877,74 @@ describe("compactEmbeddedPiSessionDirect hooks", () => {
|
|||||||
|
|
||||||
expect(result.ok).toBe(true);
|
expect(result.ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses metadata from the resolved GigaChat auth profile during compaction", async () => {
|
||||||
|
resolveModelMock.mockReturnValue({
|
||||||
|
model: {
|
||||||
|
provider: "gigachat",
|
||||||
|
api: "openai-completions",
|
||||||
|
id: "GigaChat-2-Max",
|
||||||
|
input: ["text"],
|
||||||
|
baseUrl: "https://gigachat.devices.sberbank.ru/api/v1",
|
||||||
|
},
|
||||||
|
error: null,
|
||||||
|
authStorage: { setRuntimeApiKey: vi.fn() },
|
||||||
|
modelRegistry: {},
|
||||||
|
} as never);
|
||||||
|
vi.mocked(getApiKeyForModel).mockResolvedValueOnce({
|
||||||
|
apiKey: "test",
|
||||||
|
mode: "api_key",
|
||||||
|
profileId: "gigachat:business",
|
||||||
|
});
|
||||||
|
ensureAuthProfileStoreMock.mockReturnValue({
|
||||||
|
profiles: {
|
||||||
|
"gigachat:default": {
|
||||||
|
type: "api_key",
|
||||||
|
provider: "gigachat",
|
||||||
|
metadata: {
|
||||||
|
authMode: "oauth",
|
||||||
|
insecureTls: "false",
|
||||||
|
scope: "GIGACHAT_API_PERS",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"gigachat:business": {
|
||||||
|
type: "api_key",
|
||||||
|
provider: "gigachat",
|
||||||
|
metadata: {
|
||||||
|
authMode: "basic",
|
||||||
|
insecureTls: "true",
|
||||||
|
scope: "GIGACHAT_API_B2B",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
sessionCompactImpl.mockImplementation(async () => {
|
||||||
|
expect(createGigachatStreamFnMock).toHaveBeenCalledWith({
|
||||||
|
baseUrl: "https://gigachat.devices.sberbank.ru/api/v1",
|
||||||
|
authMode: "basic",
|
||||||
|
insecureTls: true,
|
||||||
|
scope: "GIGACHAT_API_B2B",
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
summary: "summary",
|
||||||
|
firstKeptEntryId: "entry-1",
|
||||||
|
tokensBefore: 120,
|
||||||
|
details: { ok: true },
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await compactEmbeddedPiSessionDirect({
|
||||||
|
sessionId: "session-1",
|
||||||
|
sessionKey: "agent:main:session-1",
|
||||||
|
sessionFile: "/tmp/session.jsonl",
|
||||||
|
workspaceDir: "/tmp",
|
||||||
|
provider: "gigachat",
|
||||||
|
model: "GigaChat-2-Max",
|
||||||
|
customInstructions: "focus on decisions",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.ok).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("compactEmbeddedPiSession hooks (ownsCompaction engine)", () => {
|
describe("compactEmbeddedPiSession hooks (ownsCompaction engine)", () => {
|
||||||
|
|||||||
@ -805,7 +805,8 @@ export async function compactEmbeddedPiSessionDirect(
|
|||||||
process.env.GIGACHAT_BASE_URL?.trim() ??
|
process.env.GIGACHAT_BASE_URL?.trim() ??
|
||||||
"https://gigachat.devices.sberbank.ru/api/v1";
|
"https://gigachat.devices.sberbank.ru/api/v1";
|
||||||
const gigachatStore = ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
|
const gigachatStore = ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
|
||||||
const profileId = authProfileId?.trim() || "gigachat:default";
|
const profileId =
|
||||||
|
apiKeyInfo?.profileId?.trim() || authProfileId?.trim() || "gigachat:default";
|
||||||
const gigachatCred =
|
const gigachatCred =
|
||||||
gigachatStore.profiles[profileId] ?? gigachatStore.profiles["gigachat:default"];
|
gigachatStore.profiles[profileId] ?? gigachatStore.profiles["gigachat:default"];
|
||||||
const gigachatMeta = gigachatCred?.type === "api_key" ? gigachatCred.metadata : undefined;
|
const gigachatMeta = gigachatCred?.type === "api_key" ? gigachatCred.metadata : undefined;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user