chore: fix lint formatting

This commit is contained in:
Peter Steinberger
2026-01-03 14:57:49 +00:00
parent 77c76ca52f
commit 1a00175eb7
9 changed files with 120 additions and 108 deletions

View File

@@ -378,16 +378,16 @@ export async function runEmbeddedPiAgent(params: {
const apiKey = await getApiKeyForModel(model, authStorage);
authStorage.setRuntimeApiKey(model.provider, apiKey);
const thinkingLevel = mapThinkingLevel(params.thinkLevel);
const thinkingLevel = mapThinkingLevel(params.thinkLevel);
logVerbose(
`embedded run start: runId=${params.runId} sessionId=${params.sessionId} provider=${provider} model=${modelId} surface=${params.surface ?? "unknown"}`,
);
logVerbose(
`embedded run start: runId=${params.runId} sessionId=${params.sessionId} provider=${provider} model=${modelId} surface=${params.surface ?? "unknown"}`,
);
await fs.mkdir(resolvedWorkspace, { recursive: true });
await ensureSessionHeader({
sessionFile: params.sessionFile,
sessionId: params.sessionId,
await fs.mkdir(resolvedWorkspace, { recursive: true });
await ensureSessionHeader({
sessionFile: params.sessionFile,
sessionId: params.sessionId,
cwd: resolvedWorkspace,
});
@@ -510,20 +510,23 @@ export async function runEmbeddedPiAgent(params: {
});
let abortWarnTimer: NodeJS.Timeout | undefined;
const abortTimer = setTimeout(() => {
defaultRuntime.warn?.(
`embedded run timeout: runId=${params.runId} sessionId=${params.sessionId} timeoutMs=${params.timeoutMs}`,
);
abortRun();
if (!abortWarnTimer) {
abortWarnTimer = setTimeout(() => {
if (!session.isStreaming) return;
defaultRuntime.warn?.(
`embedded run abort still streaming: runId=${params.runId} sessionId=${params.sessionId}`,
);
}, 10_000);
}
}, Math.max(1, params.timeoutMs));
const abortTimer = setTimeout(
() => {
defaultRuntime.warn?.(
`embedded run timeout: runId=${params.runId} sessionId=${params.sessionId} timeoutMs=${params.timeoutMs}`,
);
abortRun();
if (!abortWarnTimer) {
abortWarnTimer = setTimeout(() => {
if (!session.isStreaming) return;
defaultRuntime.warn?.(
`embedded run abort still streaming: runId=${params.runId} sessionId=${params.sessionId}`,
);
}, 10_000);
}
},
Math.max(1, params.timeoutMs),
);
let messagesSnapshot: AgentMessage[] = [];
let sessionIdUsed = session.sessionId;

View File

@@ -6,13 +6,13 @@ import {
createToolDebouncer,
formatToolAggregate,
} from "../auto-reply/tool-meta.js";
import { logVerbose } from "../globals.js";
import { emitAgentEvent } from "../infra/agent-events.js";
import { splitMediaFromOutput } from "../media/parse.js";
import {
extractAssistantText,
inferToolMetaFromArgs,
} from "./pi-embedded-utils.js";
import { logVerbose } from "../globals.js";
const THINKING_TAG_RE = /<\s*\/?\s*think(?:ing)?\s*>/gi;
const THINKING_OPEN_RE = /<\s*think(?:ing)?\s*>/i;

View File

@@ -144,12 +144,11 @@ function mergePropertySchemas(existing: unknown, incoming: unknown): unknown {
function cleanSchemaForGemini(schema: unknown): unknown {
if (!schema || typeof schema !== "object") return schema;
if (Array.isArray(schema)) return schema.map(cleanSchemaForGemini);
const obj = schema as Record<string, unknown>;
const hasAnyOf = "anyOf" in obj && Array.isArray(obj.anyOf);
const hasConst = "const" in obj;
const cleaned: Record<string, unknown> = {};
for (const [key, value] of Object.entries(obj)) {
// Skip unsupported schema features for Gemini:
// - patternProperties: not in OpenAPI 3.0 subset
@@ -158,44 +157,48 @@ function cleanSchemaForGemini(schema: unknown): unknown {
// Gemini doesn't support patternProperties - skip it
continue;
}
// Convert const to enum (Gemini doesn't support const)
if (key === "const") {
cleaned.enum = [value];
continue;
}
// Skip 'type' if we have 'anyOf' — Gemini doesn't allow both
if (key === "type" && hasAnyOf) {
continue;
}
if (key === "properties" && value && typeof value === "object") {
// Recursively clean nested properties
const props = value as Record<string, unknown>;
cleaned[key] = Object.fromEntries(
Object.entries(props).map(([k, v]) => [k, cleanSchemaForGemini(v)])
Object.entries(props).map(([k, v]) => [k, cleanSchemaForGemini(v)]),
);
} else if (key === "items" && value && typeof value === "object") {
// Recursively clean array items schema
cleaned[key] = cleanSchemaForGemini(value);
} else if (key === "anyOf" && Array.isArray(value)) {
// Clean each anyOf variant
cleaned[key] = value.map(v => cleanSchemaForGemini(v));
cleaned[key] = value.map((v) => cleanSchemaForGemini(v));
} else if (key === "oneOf" && Array.isArray(value)) {
// Clean each oneOf variant
cleaned[key] = value.map(v => cleanSchemaForGemini(v));
cleaned[key] = value.map((v) => cleanSchemaForGemini(v));
} else if (key === "allOf" && Array.isArray(value)) {
// Clean each allOf variant
cleaned[key] = value.map(v => cleanSchemaForGemini(v));
} else if (key === "additionalProperties" && value && typeof value === "object") {
cleaned[key] = value.map((v) => cleanSchemaForGemini(v));
} else if (
key === "additionalProperties" &&
value &&
typeof value === "object"
) {
// Recursively clean additionalProperties schema
cleaned[key] = cleanSchemaForGemini(value);
} else {
cleaned[key] = value;
}
}
return cleaned;
}
@@ -205,16 +208,20 @@ function normalizeToolParameters(tool: AnyAgentTool): AnyAgentTool {
? (tool.parameters as Record<string, unknown>)
: undefined;
if (!schema) return tool;
// If schema already has type + properties (no top-level anyOf to merge),
// still clean it for Gemini compatibility
if ("type" in schema && "properties" in schema && !Array.isArray(schema.anyOf)) {
if (
"type" in schema &&
"properties" in schema &&
!Array.isArray(schema.anyOf)
) {
return {
...tool,
parameters: cleanSchemaForGemini(schema),
};
}
if (!Array.isArray(schema.anyOf)) return tool;
const mergedProperties: Record<string, unknown> = {};
const requiredCounts = new Map<string, number>();

View File

@@ -782,10 +782,7 @@ export async function getReplyFromConfig(
const typingIntervalSeconds =
typeof configuredTypingSeconds === "number" ? configuredTypingSeconds : 6;
const typingIntervalMs = typingIntervalSeconds * 1000;
const typingTtlMs = Math.min(
Math.max(15_000, typingIntervalMs * 5),
60_000,
);
const typingTtlMs = Math.min(Math.max(15_000, typingIntervalMs * 5), 60_000);
const cleanupTyping = () => {
if (typingTtlTimer) {
clearTimeout(typingTtlTimer);

View File

@@ -22,7 +22,7 @@ describe("resolvePythonExecutablePath", () => {
const shim = path.join(shimDir, "python3");
await fs.writeFile(
shim,
`#!/bin/sh\nif [ \"$1\" = \"-c\" ]; then\n echo \"${realPython}\"\n exit 0\nfi\nexit 1\n`,
`#!/bin/sh\nif [ "$1" = "-c" ]; then\n echo "${realPython}"\n exit 0\nfi\nexit 1\n`,
"utf-8",
);
await fs.chmod(shim, 0o755);

View File

@@ -58,7 +58,9 @@ function ensureGcloudOnPath(): boolean {
return false;
}
export async function resolvePythonExecutablePath(): Promise<string | undefined> {
export async function resolvePythonExecutablePath(): Promise<
string | undefined
> {
if (cachedPythonPath !== undefined) {
return cachedPythonPath ?? undefined;
}
@@ -171,7 +173,14 @@ export async function ensureSubscription(
pushEndpoint: string,
) {
const describe = await runGcloudCommand(
["pubsub", "subscriptions", "describe", subscription, "--project", projectId],
[
"pubsub",
"subscriptions",
"describe",
subscription,
"--project",
projectId,
],
30_000,
);
if (describe.code === 0) {

View File

@@ -396,10 +396,12 @@ const SUBSYSTEM_COLORS = [
"magenta",
"red",
] as const;
const SUBSYSTEM_COLOR_OVERRIDES: Record<string, (typeof SUBSYSTEM_COLORS)[number]> =
{
"gmail-watcher": "blue",
};
const SUBSYSTEM_COLOR_OVERRIDES: Record<
string,
(typeof SUBSYSTEM_COLORS)[number]
> = {
"gmail-watcher": "blue",
};
const SUBSYSTEM_PREFIXES_TO_DROP = ["gateway", "providers"] as const;
const SUBSYSTEM_MAX_SEGMENTS = 2;

View File

@@ -190,7 +190,7 @@ export async function monitorWebInbox(options: {
await sock.readMessages([
{ remoteJid, id, participant, fromMe: false },
]);
if (shouldLogVerbose()) {
if (shouldLogVerbose()) {
const suffix = participant ? ` (participant ${participant})` : "";
logVerbose(
`Marked message ${id} as read for ${remoteJid}${suffix}`,