Skip to content

Commit d916433

Browse files
author
Shaw
committed
Merge branch 'develop' of https://github.com/elizaOS/eliza into feat/benchmarks-trajectory-replay
2 parents 5cb8180 + cbb5ecb commit d916433

14 files changed

Lines changed: 111 additions & 50 deletions

File tree

cloud/apps/api/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"target": "ES2022",
5-
"lib": ["ES2023", "WebWorker", "DOM.Iterable"],
5+
"lib": ["ES2023", "WebWorker", "DOM", "DOM.Iterable"],
66
"module": "ESNext",
77
"moduleResolution": "Bundler",
88
"noEmit": true,
@@ -21,6 +21,8 @@
2121
"@/types/*": ["../../packages/types/*"],
2222
"@/api/*": ["./*"],
2323
"@elizaos/billing": ["../../packages/billing/src/index.ts"],
24+
"@elizaos/core": ["../../../packages/core/src/index.node.ts"],
25+
"@elizaos/core/*": ["../../../packages/core/src/*"],
2426
"@elizaos/plugin-sql": ["../../../plugins/plugin-sql/src/index.ts"],
2527
"drizzle-orm": ["../../../plugins/plugin-sql/node_modules/drizzle-orm"],
2628
"drizzle-orm/*": ["../../../plugins/plugin-sql/node_modules/drizzle-orm/*"],

cloud/apps/frontend/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"skipLibCheck": true,
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
15-
"allowImportingTsExtensions": false,
15+
"allowImportingTsExtensions": true,
1616
"types": ["vite/client", "node"],
1717
"composite": false,
1818
"declaration": false,
@@ -25,6 +25,8 @@
2525
"@/packages/*": ["../../packages/*"],
2626
"@elizaos/billing": ["../../packages/billing/src/index.ts"],
2727
"@elizaos/cloud-ui": ["../../packages/ui/src/index.ts"],
28+
"@elizaos/core": ["../../../packages/core/src/index.node.ts"],
29+
"@elizaos/core/*": ["../../../packages/core/src/*"],
2830
"@elizaos/plugin-sql": ["../../../plugins/plugin-sql/src/index.ts"],
2931
"@/*": ["./src/*"]
3032
}

cloud/packages/tests/unit/advertising-provider-contracts.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("advertising provider contracts", () => {
5757
status: 200,
5858
headers: { "content-type": "application/json" },
5959
});
60-
}) as typeof fetch;
60+
}) as unknown as typeof fetch;
6161

6262
const { googleAdsProvider } = await import(
6363
`../../lib/services/advertising/providers/google.ts?case=${Date.now()}`
@@ -112,7 +112,7 @@ describe("advertising provider contracts", () => {
112112
status: 200,
113113
headers: { "content-type": "application/json" },
114114
});
115-
}) as typeof fetch;
115+
}) as unknown as typeof fetch;
116116

117117
const { metaAdsProvider } = await import(
118118
`../../lib/services/advertising/providers/meta.ts?case=${Date.now()}`
@@ -144,7 +144,7 @@ describe("advertising provider contracts", () => {
144144
status: 200,
145145
headers: { "content-type": "application/json" },
146146
});
147-
}) as typeof fetch;
147+
}) as unknown as typeof fetch;
148148

149149
const { tiktokAdsProvider } = await import(
150150
`../../lib/services/advertising/providers/tiktok.ts?case=${Date.now()}`

cloud/packages/tests/unit/x402-payment-requests.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function paymentFixture(overrides: Partial<Record<string, unknown>> = {}) {
3636
};
3737
}
3838

39+
type TestPayment = ReturnType<typeof paymentFixture>;
40+
3941
async function loadService() {
4042
const mod = await import(
4143
new URL(
@@ -44,8 +46,8 @@ async function loadService() {
4446
).href
4547
);
4648
return mod.x402PaymentRequestsService as {
47-
toView: (payment: ReturnType<typeof paymentFixture>) => Record<string, unknown>;
48-
toPublicView: (payment: ReturnType<typeof paymentFixture>) => Record<string, unknown>;
49+
toView: (paymentRequest: TestPayment) => Record<string, unknown>;
50+
toPublicView: (paymentRequest: TestPayment) => Record<string, unknown>;
4951
settle: (
5052
id: string,
5153
paymentPayloadInput: unknown,

packages/agent/src/external-modules.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ declare module "@elizaos/plugin-openai";
335335
declare module "@elizaos/plugin-shell";
336336
declare module "@elizaos/plugin-x402" {
337337
import type {
338+
IAgentRuntime,
338339
PaymentEnabledRoute,
339340
Route,
340341
RouteRequest,
341342
RouteResponse,
342-
IAgentRuntime,
343343
} from "@elizaos/core";
344344

345345
export interface X402StartupValidationResult {

packages/agent/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
"@elizaos/capacitor-contacts": [
4141
"../native-plugins/contacts/src/index.ts"
4242
],
43+
"@elizaos/capacitor-llama": [
44+
"../native-plugins/llama/src/index.ts"
45+
],
4346
"@elizaos/capacitor-phone": [
4447
"../native-plugins/phone/src/index.ts"
4548
],
@@ -161,7 +164,8 @@
161164
"@elizaos/plugin-discord-local/*": [
162165
"../../plugins/plugin-discord-local/src/*"
163166
],
164-
"@elizaos/*": ["../../node_modules/@elizaos/*"]
167+
"@elizaos/*": ["../../node_modules/@elizaos/*"],
168+
"puppeteer-core": ["./node_modules/puppeteer-core"]
165169
}
166170
},
167171
"include": [

plugins/plugin-agent-orchestrator/__tests__/unit/session-log-reader.test.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ function makeFixtureJsonl(): string {
8080
type: "tool_use",
8181
id: "toolu-grep-1",
8282
name: "Grep",
83-
input: { pattern: "openExternalUrl", output_mode: "files_with_matches" },
83+
input: {
84+
pattern: "openExternalUrl",
85+
output_mode: "files_with_matches",
86+
},
8487
},
8588
],
8689
stop_reason: "tool_use",
@@ -133,14 +136,14 @@ function makeFixtureJsonl(): string {
133136
sessionId: "session-fixture-1",
134137
},
135138
];
136-
return lines.map((l) => JSON.stringify(l)).join("\n") + "\n{not json}\n";
139+
return `${lines.map((l) => JSON.stringify(l)).join("\n")}\n{not json}\n`;
137140
}
138141

139142
describe("session-log-reader: path resolution", () => {
140143
it("encodes Claude Code project dir paths (/ and . → -)", () => {
141-
expect(
142-
encodeClaudeCodeProjectDir("/Users/x/.milady/workspaces/abc"),
143-
).toBe("-Users-x--milady-workspaces-abc");
144+
expect(encodeClaudeCodeProjectDir("/Users/x/.milady/workspaces/abc")).toBe(
145+
"-Users-x--milady-workspaces-abc",
146+
);
144147
});
145148

146149
it("returns both canonical and workspace-local candidates", () => {
@@ -175,12 +178,22 @@ describe("session-log-reader: path resolution", () => {
175178
encodeClaudeCodeProjectDir(workdir),
176179
);
177180
await mkdir(projectsDir, { recursive: true });
178-
const older = join(projectsDir, "00000000-0000-0000-0000-000000000001.jsonl");
179-
const newer = join(projectsDir, "00000000-0000-0000-0000-000000000002.jsonl");
181+
const older = join(
182+
projectsDir,
183+
"00000000-0000-0000-0000-000000000001.jsonl",
184+
);
185+
const newer = join(
186+
projectsDir,
187+
"00000000-0000-0000-0000-000000000002.jsonl",
188+
);
180189
await writeFile(older, "");
181190
await new Promise((r) => setTimeout(r, 10));
182191
await writeFile(newer, "");
183-
const located = await findClaudeCodeSessionLogFile(workdir, undefined, home);
192+
const located = await findClaudeCodeSessionLogFile(
193+
workdir,
194+
undefined,
195+
home,
196+
);
184197
expect(located?.filePath).toBe(newer);
185198
});
186199
});
@@ -302,7 +315,9 @@ describe("session-log-reader: normalization", () => {
302315
],
303316
},
304317
});
305-
const events = [parseSessionLogLine(raw)!];
318+
const parsed = parseSessionLogLine(raw);
319+
if (!parsed) throw new Error("expected session log event");
320+
const events = [parsed];
306321
const steps = normalizeSessionEvents(events, "p");
307322
expect(steps).toHaveLength(1);
308323
expect(steps[0].toolError).toBe(true);

plugins/plugin-agent-orchestrator/src/services/pty-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ import {
8989
toPiCommand,
9090
} from "./pty-types.js";
9191
import {
92-
mergeSessionLogIntoTrajectory,
9392
type MergeSessionLogResult,
93+
mergeSessionLogIntoTrajectory,
9494
} from "./session-log-merger.js";
9595
import { readClaudeCodeSession } from "./session-log-reader.js";
9696
import { CLAUDE_SKILL_ESSENTIALS } from "./skill-essentials.js";

plugins/plugin-agent-orchestrator/src/services/session-log-merger.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
*/
2929

3030
import {
31-
type IAgentRuntime,
3231
annotateActiveTrajectoryStep,
32+
type IAgentRuntime,
3333
resolveTrajectoryLogger,
3434
} from "@elizaos/core";
3535
import type {
@@ -81,8 +81,11 @@ function buildChildTrajectoryId(parentStepId: string): string {
8181
}
8282

8383
function isLlmStep(step: NormalizedTrajectoryStep): boolean {
84-
return step.kind === "reasoning" || step.kind === "text" ||
85-
step.kind === "tool_call";
84+
return (
85+
step.kind === "reasoning" ||
86+
step.kind === "text" ||
87+
step.kind === "tool_call"
88+
);
8689
}
8790

8891
function buildLlmDetails(
@@ -118,9 +121,7 @@ function buildLlmDetails(
118121
};
119122
}
120123

121-
function buildToolResultScript(
122-
step: NormalizedTrajectoryStep,
123-
): string {
124+
function buildToolResultScript(step: NormalizedTrajectoryStep): string {
124125
// The trajectory step `script` field is the natural place to land tool
125126
// result payloads — it's already used elsewhere for action exec output.
126127
// Cap is enforced inside the storage layer; we hand the full string
@@ -173,7 +174,7 @@ export async function mergeSessionLogIntoTrajectory(
173174
}
174175

175176
const childTrajectoryId = buildChildTrajectoryId(parentStepId);
176-
await trajectoryLogger.startTrajectory(childTrajectoryId, {
177+
const startOptions = {
177178
agentId: runtime.agentId,
178179
source: "claude-code-session",
179180
metadata: {
@@ -186,7 +187,8 @@ export async function mergeSessionLogIntoTrajectory(
186187
totalUsage: capture.totalUsage,
187188
models: capture.models,
188189
},
189-
});
190+
};
191+
await trajectoryLogger.startTrajectory(childTrajectoryId, startOptions);
190192

191193
let stepsWritten = 0;
192194
for (const step of capture.steps) {
@@ -196,8 +198,8 @@ export async function mergeSessionLogIntoTrajectory(
196198
// the well-known fields and trust the schema-derived consumer.
197199
trajectoryLogger.logLlmCall({
198200
stepId: step.stepId,
199-
...(details as never),
200-
});
201+
...details,
202+
} as Parameters<NonNullable<typeof trajectoryLogger.logLlmCall>>[0]);
201203
stepsWritten += 1;
202204
continue;
203205
}
@@ -212,7 +214,6 @@ export async function mergeSessionLogIntoTrajectory(
212214
script: buildToolResultScript(step),
213215
});
214216
stepsWritten += 1;
215-
continue;
216217
}
217218
}
218219

plugins/plugin-agent-orchestrator/src/services/session-log-reader.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @module services/session-log-reader
3636
*/
3737

38-
import { readFile, readdir, stat } from "node:fs/promises";
38+
import { readdir, readFile, stat } from "node:fs/promises";
3939
import { homedir } from "node:os";
4040
import { join } from "node:path";
4141

@@ -229,7 +229,10 @@ export function buildSessionLogCandidates(
229229
): CandidateSessionLogPath[] {
230230
const encoded = encodeClaudeCodeProjectDir(workdir);
231231
return [
232-
{ dir: join(home, ".claude", "projects", encoded), label: "claude-projects" },
232+
{
233+
dir: join(home, ".claude", "projects", encoded),
234+
label: "claude-projects",
235+
},
233236
{
234237
dir: join(workdir, ".claude", "session-logs"),
235238
label: "workspace-local",
@@ -244,9 +247,7 @@ interface SessionLogReaderLogger {
244247

245248
const NOOP_LOGGER: SessionLogReaderLogger = {};
246249

247-
async function listSessionLogFilesIn(
248-
dir: string,
249-
): Promise<string[]> {
250+
async function listSessionLogFilesIn(dir: string): Promise<string[]> {
250251
try {
251252
const entries = await readdir(dir, { withFileTypes: true });
252253
const files: string[] = [];
@@ -362,6 +363,30 @@ function asNullableString(value: unknown): string | null {
362363
return typeof value === "string" ? value : null;
363364
}
364365

366+
function isClaudeCodeAssistantEvent(
367+
event: ClaudeCodeSessionEvent,
368+
): event is ClaudeCodeAssistantEvent {
369+
if (event.type !== "assistant") return false;
370+
const message = (event as { message?: unknown }).message;
371+
return (
372+
isRecord(message) &&
373+
message.role === "assistant" &&
374+
Array.isArray(message.content)
375+
);
376+
}
377+
378+
function isClaudeCodeUserEvent(
379+
event: ClaudeCodeSessionEvent,
380+
): event is ClaudeCodeUserEvent {
381+
if (event.type !== "user") return false;
382+
const message = (event as { message?: unknown }).message;
383+
return (
384+
isRecord(message) &&
385+
message.role === "user" &&
386+
(typeof message.content === "string" || Array.isArray(message.content))
387+
);
388+
}
389+
365390
/**
366391
* Parse one JSONL line into a typed event. Returns `null` when the line is
367392
* blank, malformed, or lacks the required `type` field. We don't throw —
@@ -483,7 +508,11 @@ function flattenToolResultContent(
483508
return parts.join("\n");
484509
}
485510

486-
function makeChildStepId(parentStepId: string, uuid: string, idx: number): string {
511+
function makeChildStepId(
512+
parentStepId: string,
513+
uuid: string,
514+
idx: number,
515+
): string {
487516
// Compose a stable, parent-scoped child id. Keeping the parent step prefix
488517
// makes it easy to grep + group child rows back to the parent in BI tools.
489518
const suffix = uuid && uuid.length > 0 ? uuid.slice(0, 12) : `n${idx}`;
@@ -505,7 +534,7 @@ export function normalizeSessionEvents(
505534
let idx = 0;
506535

507536
for (const event of events) {
508-
if (event.type === "assistant") {
537+
if (isClaudeCodeAssistantEvent(event)) {
509538
const ts = parseTimestamp(event.timestamp);
510539
const model = event.message.model;
511540
const usage = event.message.usage;
@@ -561,7 +590,7 @@ export function normalizeSessionEvents(
561590
continue;
562591
}
563592

564-
if (event.type === "user") {
593+
if (isClaudeCodeUserEvent(event)) {
565594
const ts = parseTimestamp(event.timestamp);
566595
const content = event.message.content;
567596
if (typeof content === "string") continue;
@@ -587,25 +616,21 @@ export function normalizeSessionEvents(
587616
return out;
588617
}
589618

590-
function aggregateUsage(
591-
events: ClaudeCodeSessionEvent[],
592-
): ClaudeCodeUsage {
619+
function aggregateUsage(events: ClaudeCodeSessionEvent[]): ClaudeCodeUsage {
593620
const total: ClaudeCodeUsage = {};
594621
for (const event of events) {
595-
if (event.type !== "assistant") continue;
622+
if (!isClaudeCodeAssistantEvent(event)) continue;
596623
const usage = event.message.usage;
597624
if (!usage) continue;
598625
if (typeof usage.input_tokens === "number") {
599626
total.input_tokens = (total.input_tokens ?? 0) + usage.input_tokens;
600627
}
601628
if (typeof usage.output_tokens === "number") {
602-
total.output_tokens =
603-
(total.output_tokens ?? 0) + usage.output_tokens;
629+
total.output_tokens = (total.output_tokens ?? 0) + usage.output_tokens;
604630
}
605631
if (typeof usage.cache_read_input_tokens === "number") {
606632
total.cache_read_input_tokens =
607-
(total.cache_read_input_tokens ?? 0) +
608-
usage.cache_read_input_tokens;
633+
(total.cache_read_input_tokens ?? 0) + usage.cache_read_input_tokens;
609634
}
610635
if (typeof usage.cache_creation_input_tokens === "number") {
611636
total.cache_creation_input_tokens =

0 commit comments

Comments
 (0)