Skip to content

Commit 55e85e4

Browse files
committed
refactor: remove httpExtra from various function signatures and contexts for cleaner code
1 parent 4ae0b7b commit 55e85e4

5 files changed

Lines changed: 148 additions & 313 deletions

File tree

agent/simpleAgent.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
logger,
55
type AdminUser,
66
type CompletionAdapter,
7-
type HttpExtra,
87
type IAdminForth,
98
} from "adminforth";
109
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
@@ -28,7 +27,6 @@ export const contextSchema = z.object({
2827
turnId: z.string(),
2928
abortSignal: z.custom<AbortSignal>().optional(),
3029
currentPage: z.custom<CurrentPageContext>().optional(),
31-
httpExtra: z.custom<Pick<HttpExtra, "headers" | "cookies">>().optional(),
3230
emitToolCallEvent: z.custom<ToolCallEventSink>(),
3331
});
3432

@@ -235,7 +233,6 @@ export async function callAgent(params: {
235233
sessionId: string;
236234
turnId: string;
237235
currentPage?: CurrentPageContext;
238-
httpExtra?: Pick<HttpExtra, "headers" | "cookies">;
239236
userTimeZone: string;
240237
abortSignal?: AbortSignal;
241238
emitToolCallEvent: ToolCallEventSink;
@@ -255,7 +252,6 @@ export async function callAgent(params: {
255252
sessionId,
256253
turnId,
257254
currentPage,
258-
httpExtra,
259255
userTimeZone,
260256
abortSignal,
261257
emitToolCallEvent,
@@ -303,7 +299,6 @@ export async function callAgent(params: {
303299
turnId,
304300
abortSignal,
305301
currentPage,
306-
httpExtra,
307302
emitToolCallEvent,
308303
},
309304
});

agent/toolCallEvents.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { randomUUID } from "crypto";
22
import YAML from "yaml";
3-
import { serializeUnknownError } from "../apiBasedTools.js";
43

54
export type ToolCallEvent =
65
| {
@@ -61,6 +60,36 @@ function sanitizeToolCallOutputForDebug(output: unknown) {
6160
);
6261
}
6362

63+
function serializeErrorForDebug(error: unknown): unknown {
64+
if (!(error instanceof Error)) {
65+
return error;
66+
}
67+
68+
const errorWithCause = error as Error & { cause?: unknown };
69+
const serialized: Record<string, unknown> = {
70+
name: error.name,
71+
message: error.message,
72+
};
73+
74+
if (error.stack) {
75+
serialized.stack = error.stack;
76+
}
77+
78+
if (errorWithCause.cause !== undefined) {
79+
serialized.cause = serializeErrorForDebug(errorWithCause.cause);
80+
}
81+
82+
for (const key of Object.getOwnPropertyNames(error)) {
83+
if (key in serialized) {
84+
continue;
85+
}
86+
87+
serialized[key] = (error as unknown as Record<string, unknown>)[key];
88+
}
89+
90+
return serialized;
91+
}
92+
6493
export function createToolCallTracker(params: {
6594
emit: ToolCallEventSink;
6695
toolCallId?: string;
@@ -99,7 +128,7 @@ export function createToolCallTracker(params: {
99128
phase: "end",
100129
durationMs: Date.now() - startedAt,
101130
output: null,
102-
error: YAML.stringify(serializeUnknownError(error)).trimEnd(),
131+
error: YAML.stringify(serializeErrorForDebug(error)).trimEnd(),
103132
});
104133
},
105134
};

agent/tools/apiTool.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export function createApiTool(toolName: string, apiBasedTool: ApiBasedTool) {
5252
return apiBasedTool.call({
5353
adminUser: runtime.context.adminUser,
5454
abortSignal: runtime.context.abortSignal,
55-
httpExtra: runtime.context.httpExtra,
5655
inputs: normalizedInput,
5756
userTimeZone: runtime.context.userTimeZone,
5857
});

0 commit comments

Comments
 (0)