2026-04-06 16:43:04 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2026 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2026-04-06 19:31:18 +00:00
|
|
|
import type { Content } from '@google/genai';
|
|
|
|
|
import type { Episode } from './types.js';
|
|
|
|
|
import { toIr, setMapperConfig } from './toIr.js';
|
|
|
|
|
import { fromIr } from './fromIr.js';
|
2026-04-06 16:43:04 +00:00
|
|
|
|
|
|
|
|
export class IrMapper {
|
|
|
|
|
static setConfig(cfg: { charsPerToken?: number }) {
|
2026-04-06 19:31:18 +00:00
|
|
|
setMapperConfig(cfg);
|
2026-04-06 16:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Translates a flat Gemini Content[] array into our rich Episodic Intermediate Representation.
|
|
|
|
|
* Groups adjacent function calls and responses into unified ToolExecution nodes.
|
|
|
|
|
*/
|
|
|
|
|
static toIr(history: readonly Content[]): Episode[] {
|
2026-04-06 19:31:18 +00:00
|
|
|
return toIr(history);
|
2026-04-06 16:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Re-serializes the Episodic IR back into a flat Gemini Content[] array.
|
|
|
|
|
*/
|
|
|
|
|
static fromIr(episodes: Episode[]): Content[] {
|
2026-04-06 19:31:18 +00:00
|
|
|
return fromIr(episodes);
|
2026-04-06 16:43:04 +00:00
|
|
|
}
|
|
|
|
|
}
|