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';
|
2026-04-07 23:49:27 +00:00
|
|
|
import type { Episode, ConcreteNode } from './types.js';
|
2026-04-06 19:48:44 +00:00
|
|
|
import { toIr } from './toIr.js';
|
2026-04-06 19:31:18 +00:00
|
|
|
import { fromIr } from './fromIr.js';
|
2026-04-06 19:48:44 +00:00
|
|
|
import type { ContextTokenCalculator } from '../utils/contextTokenCalculator.js';
|
2026-04-06 16:43:04 +00:00
|
|
|
|
|
|
|
|
export class IrMapper {
|
|
|
|
|
/**
|
|
|
|
|
* Translates a flat Gemini Content[] array into our rich Episodic Intermediate Representation.
|
|
|
|
|
* Groups adjacent function calls and responses into unified ToolExecution nodes.
|
|
|
|
|
*/
|
2026-04-07 04:46:04 +00:00
|
|
|
static toIr(
|
|
|
|
|
history: readonly Content[],
|
|
|
|
|
tokenCalculator: ContextTokenCalculator,
|
|
|
|
|
): Episode[] {
|
2026-04-06 19:48:44 +00:00
|
|
|
return toIr(history, tokenCalculator);
|
2026-04-06 16:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-07 23:49:27 +00:00
|
|
|
* Re-serializes a flat array of ConcreteNodes back into a flat Gemini Content[] array.
|
2026-04-06 16:43:04 +00:00
|
|
|
*/
|
2026-04-08 04:37:17 +00:00
|
|
|
static fromIr(ship: readonly ConcreteNode[]): Content[] {
|
2026-04-07 23:49:27 +00:00
|
|
|
return fromIr(ship);
|
2026-04-06 16:43:04 +00:00
|
|
|
}
|
|
|
|
|
}
|