Skip to content

Commit 8f868c0

Browse files
authored
Summarize completedTx in tool calll response (#1985)
* WIP tx-analysis * Add real implementation * Remove test data and scripts * Refine tx summary * Remove long pointless README * Remove accidental `mise.toml` * Remove JournalMock from tests * Remove unused analysis * Format and lint * PR feedback
1 parent bb73d11 commit 8f868c0

File tree

5 files changed

+538
-4
lines changed

5 files changed

+538
-4
lines changed

packages/runner/src/builtins/llm-dialog.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import { ID, NAME, type Recipe, TYPE } from "../builder/types.ts";
2020
import type { Action } from "../scheduler.ts";
2121
import type { IRuntime } from "../runtime.ts";
2222
import type { IExtendedStorageTransaction } from "../storage/interface.ts";
23+
import {
24+
debugTransactionWrites,
25+
formatTransactionSummary,
26+
} from "../storage/transaction-summary.ts";
2327
import { parseLink } from "../link-utils.ts";
2428
// Avoid importing from @commontools/charm to prevent circular deps in tests
2529

@@ -811,8 +815,13 @@ async function invokeToolCall(
811815
...toolCall.input,
812816
result, // doesn't HAVE to be used, but can be
813817
}, (completedTx: IExtendedStorageTransaction) => {
814-
resolve(result.withTx(completedTx).get()); // withTx likely superfluous
815-
}); // TODO(bf): why any needed?
818+
logger.info("Handler tx:", debugTransactionWrites(completedTx));
819+
820+
const summary = formatTransactionSummary(completedTx, space);
821+
const value = result.withTx(completedTx).get();
822+
823+
resolve({ value, summary });
824+
});
816825
} else {
817826
throw new Error("Tool has neither pattern nor handler");
818827
}

packages/runner/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export type {
1919
IExtendedStorageTransaction,
2020
MemorySpace,
2121
} from "./storage/interface.ts";
22+
export {
23+
debugTransactionWrites,
24+
formatTransactionSummary,
25+
summarizeTransaction,
26+
type TransactionSummary,
27+
} from "./storage/transaction-summary.ts";
2228
export { convertCellsToLinks, isCell, isStream } from "./cell.ts";
2329
export {
2430
getCellOrThrow,

0 commit comments

Comments
 (0)