style: format PR 223 changes
This commit is contained in:
parent
f01784369d
commit
485481895e
@ -1,14 +1,17 @@
|
|||||||
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import type { ThinkLevel } from "../auto-reply/thinking.js";
|
||||||
import {
|
import {
|
||||||
isRateLimitAssistantError,
|
isRateLimitAssistantError,
|
||||||
pickFallbackThinkingLevel,
|
pickFallbackThinkingLevel,
|
||||||
} from "./pi-embedded-helpers.js";
|
} from "./pi-embedded-helpers.js";
|
||||||
import type { ThinkLevel } from "../auto-reply/thinking.js";
|
|
||||||
|
|
||||||
const asAssistant = (overrides: Partial<AssistantMessage>) =>
|
const asAssistant = (overrides: Partial<AssistantMessage>) =>
|
||||||
({ role: "assistant", stopReason: "error", ...overrides }) as AssistantMessage;
|
({
|
||||||
|
role: "assistant",
|
||||||
|
stopReason: "error",
|
||||||
|
...overrides,
|
||||||
|
}) as AssistantMessage;
|
||||||
|
|
||||||
describe("isRateLimitAssistantError", () => {
|
describe("isRateLimitAssistantError", () => {
|
||||||
it("detects 429 rate limit payloads", () => {
|
it("detects 429 rate limit payloads", () => {
|
||||||
@ -57,8 +60,7 @@ describe("pickFallbackThinkingLevel", () => {
|
|||||||
it("skips already attempted levels", () => {
|
it("skips already attempted levels", () => {
|
||||||
const attempted = new Set<ThinkLevel>(["low", "medium"]);
|
const attempted = new Set<ThinkLevel>(["low", "medium"]);
|
||||||
const next = pickFallbackThinkingLevel({
|
const next = pickFallbackThinkingLevel({
|
||||||
message:
|
message: "Supported values are: 'medium', 'high', and 'xhigh'.",
|
||||||
"Supported values are: 'medium', 'high', and 'xhigh'.",
|
|
||||||
attempted,
|
attempted,
|
||||||
});
|
});
|
||||||
expect(next).toBe("high");
|
expect(next).toBe("high");
|
||||||
|
|||||||
@ -6,7 +6,10 @@ import type {
|
|||||||
AgentToolResult,
|
AgentToolResult,
|
||||||
} from "@mariozechner/pi-agent-core";
|
} from "@mariozechner/pi-agent-core";
|
||||||
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
||||||
import { normalizeThinkLevel, type ThinkLevel } from "../auto-reply/thinking.js";
|
import {
|
||||||
|
normalizeThinkLevel,
|
||||||
|
type ThinkLevel,
|
||||||
|
} from "../auto-reply/thinking.js";
|
||||||
|
|
||||||
import { sanitizeContentBlocksImages } from "./tool-images.js";
|
import { sanitizeContentBlocksImages } from "./tool-images.js";
|
||||||
import type { WorkspaceBootstrapFile } from "./workspace.js";
|
import type { WorkspaceBootstrapFile } from "./workspace.js";
|
||||||
|
|||||||
@ -351,7 +351,8 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
config: params.config,
|
config: params.config,
|
||||||
entries: skillEntries,
|
entries: skillEntries,
|
||||||
});
|
});
|
||||||
const sandboxSessionKey = params.sessionKey?.trim() || params.sessionId;
|
const sandboxSessionKey =
|
||||||
|
params.sessionKey?.trim() || params.sessionId;
|
||||||
const sandbox = await resolveSandboxContext({
|
const sandbox = await resolveSandboxContext({
|
||||||
config: params.config,
|
config: params.config,
|
||||||
sessionKey: sandboxSessionKey,
|
sessionKey: sandboxSessionKey,
|
||||||
@ -370,7 +371,10 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
const bootstrapFiles =
|
const bootstrapFiles =
|
||||||
await loadWorkspaceBootstrapFiles(resolvedWorkspace);
|
await loadWorkspaceBootstrapFiles(resolvedWorkspace);
|
||||||
const contextFiles = buildBootstrapContextFiles(bootstrapFiles);
|
const contextFiles = buildBootstrapContextFiles(bootstrapFiles);
|
||||||
const promptSkills = resolvePromptSkills(skillsSnapshot, skillEntries);
|
const promptSkills = resolvePromptSkills(
|
||||||
|
skillsSnapshot,
|
||||||
|
skillEntries,
|
||||||
|
);
|
||||||
// Tool schemas must be provider-compatible (OpenAI requires top-level `type: "object"`).
|
// Tool schemas must be provider-compatible (OpenAI requires top-level `type: "object"`).
|
||||||
// `createClawdbotCodingTools()` normalizes schemas so the session can pass them through unchanged.
|
// `createClawdbotCodingTools()` normalizes schemas so the session can pass them through unchanged.
|
||||||
const tools = createClawdbotCodingTools({
|
const tools = createClawdbotCodingTools({
|
||||||
@ -615,7 +619,8 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
if (inlineToolResults) {
|
if (inlineToolResults) {
|
||||||
for (const { toolName, meta } of toolMetas) {
|
for (const { toolName, meta } of toolMetas) {
|
||||||
const agg = formatToolAggregate(toolName, meta ? [meta] : []);
|
const agg = formatToolAggregate(toolName, meta ? [meta] : []);
|
||||||
const { text: cleanedText, mediaUrls } = splitMediaFromOutput(agg);
|
const { text: cleanedText, mediaUrls } =
|
||||||
|
splitMediaFromOutput(agg);
|
||||||
if (cleanedText)
|
if (cleanedText)
|
||||||
replyItems.push({ text: cleanedText, media: mediaUrls });
|
replyItems.push({ text: cleanedText, media: mediaUrls });
|
||||||
}
|
}
|
||||||
@ -627,7 +632,8 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
? [extractAssistantText(lastAssistant)]
|
? [extractAssistantText(lastAssistant)]
|
||||||
: []) {
|
: []) {
|
||||||
const { text: cleanedText, mediaUrls } = splitMediaFromOutput(text);
|
const { text: cleanedText, mediaUrls } = splitMediaFromOutput(text);
|
||||||
if (!cleanedText && (!mediaUrls || mediaUrls.length === 0)) continue;
|
if (!cleanedText && (!mediaUrls || mediaUrls.length === 0))
|
||||||
|
continue;
|
||||||
replyItems.push({ text: cleanedText, media: mediaUrls });
|
replyItems.push({ text: cleanedText, media: mediaUrls });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
import { getEnvApiKey } from "@mariozechner/pi-ai";
|
||||||
|
import { discoverAuthStorage } from "@mariozechner/pi-coding-agent";
|
||||||
|
import { resolveClawdbotAgentDir } from "../../agents/agent-paths.js";
|
||||||
import type { ClawdbotConfig } from "../../config/config.js";
|
import type { ClawdbotConfig } from "../../config/config.js";
|
||||||
|
import { resolveOAuthPath } from "../../config/paths.js";
|
||||||
import {
|
import {
|
||||||
type SessionEntry,
|
type SessionEntry,
|
||||||
type SessionScope,
|
type SessionScope,
|
||||||
@ -12,10 +15,6 @@ import { resolveSendPolicy } from "../../sessions/send-policy.js";
|
|||||||
import { normalizeE164 } from "../../utils.js";
|
import { normalizeE164 } from "../../utils.js";
|
||||||
import { resolveHeartbeatSeconds } from "../../web/reconnect.js";
|
import { resolveHeartbeatSeconds } from "../../web/reconnect.js";
|
||||||
import { getWebAuthAgeMs, webAuthExists } from "../../web/session.js";
|
import { getWebAuthAgeMs, webAuthExists } from "../../web/session.js";
|
||||||
import { resolveClawdbotAgentDir } from "../../agents/agent-paths.js";
|
|
||||||
import { resolveOAuthPath } from "../../config/paths.js";
|
|
||||||
import { getEnvApiKey } from "@mariozechner/pi-ai";
|
|
||||||
import { discoverAuthStorage } from "@mariozechner/pi-coding-agent";
|
|
||||||
import {
|
import {
|
||||||
normalizeGroupActivation,
|
normalizeGroupActivation,
|
||||||
parseActivationCommand,
|
parseActivationCommand,
|
||||||
@ -61,7 +60,8 @@ function hasOAuthCredentials(provider: string): boolean {
|
|||||||
if (!entry) return false;
|
if (!entry) return false;
|
||||||
const refresh =
|
const refresh =
|
||||||
entry.refresh ?? entry.refresh_token ?? entry.refreshToken ?? "";
|
entry.refresh ?? entry.refresh_token ?? entry.refreshToken ?? "";
|
||||||
const access = entry.access ?? entry.access_token ?? entry.accessToken ?? "";
|
const access =
|
||||||
|
entry.access ?? entry.access_token ?? entry.accessToken ?? "";
|
||||||
return Boolean(refresh.trim() && access.trim());
|
return Boolean(refresh.trim() && access.trim());
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user