|
|
|
|
@ -2,6 +2,7 @@ import { getChannelPlugin, normalizeChannelId } from "../channels/plugins/index.
|
|
|
|
|
import { normalizeTargetForProvider } from "../infra/outbound/target-normalization.js";
|
|
|
|
|
import { splitMediaFromOutput } from "../media/parse.js";
|
|
|
|
|
import { pluginRegistrationContractRegistry } from "../plugins/contracts/registry.js";
|
|
|
|
|
import { normalizeOptionalString, readStringValue } from "../shared/string-coerce.js";
|
|
|
|
|
import { truncateUtf16Safe } from "../utils.js";
|
|
|
|
|
import { collectTextContentBlocks } from "./content-blocks.js";
|
|
|
|
|
import { type MessagingToolSend } from "./pi-embedded-messaging.js";
|
|
|
|
|
@ -98,12 +99,12 @@ export function sanitizeToolResult(result: unknown): unknown {
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
const entry = item as Record<string, unknown>;
|
|
|
|
|
const type = typeof entry.type === "string" ? entry.type : undefined;
|
|
|
|
|
const type = readStringValue(entry.type);
|
|
|
|
|
if (type === "text" && typeof entry.text === "string") {
|
|
|
|
|
return { ...entry, text: truncateToolText(entry.text) };
|
|
|
|
|
}
|
|
|
|
|
if (type === "image") {
|
|
|
|
|
const data = typeof entry.data === "string" ? entry.data : undefined;
|
|
|
|
|
const data = readStringValue(entry.data);
|
|
|
|
|
const bytes = data ? data.length : undefined;
|
|
|
|
|
const cleaned = { ...entry };
|
|
|
|
|
delete cleaned.data;
|
|
|
|
|
@ -181,7 +182,7 @@ function readToolResultDetails(result: unknown): Record<string, unknown> | undef
|
|
|
|
|
|
|
|
|
|
function readToolResultStatus(result: unknown): string | undefined {
|
|
|
|
|
const status = readToolResultDetails(result)?.status;
|
|
|
|
|
return typeof status === "string" ? status.trim().toLowerCase() : undefined;
|
|
|
|
|
return normalizeOptionalString(status)?.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isExternalToolResult(result: unknown): boolean {
|
|
|
|
|
@ -372,11 +373,11 @@ export function extractToolErrorMessage(result: unknown): string | undefined {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resolveMessageToolTarget(args: Record<string, unknown>): string | undefined {
|
|
|
|
|
const toRaw = typeof args.to === "string" ? args.to : undefined;
|
|
|
|
|
const toRaw = readStringValue(args.to);
|
|
|
|
|
if (toRaw) {
|
|
|
|
|
return toRaw;
|
|
|
|
|
}
|
|
|
|
|
return typeof args.target === "string" ? args.target : undefined;
|
|
|
|
|
return readStringValue(args.target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function extractMessagingToolSend(
|
|
|
|
|
@ -385,8 +386,7 @@ export function extractMessagingToolSend(
|
|
|
|
|
): MessagingToolSend | undefined {
|
|
|
|
|
// Provider docking: new provider tools must implement plugin.actions.extractToolSend.
|
|
|
|
|
const action = typeof args.action === "string" ? args.action.trim() : "";
|
|
|
|
|
const accountIdRaw = typeof args.accountId === "string" ? args.accountId.trim() : undefined;
|
|
|
|
|
const accountId = accountIdRaw ? accountIdRaw : undefined;
|
|
|
|
|
const accountId = normalizeOptionalString(args.accountId);
|
|
|
|
|
if (toolName === "message") {
|
|
|
|
|
if (action !== "send" && action !== "thread-reply") {
|
|
|
|
|
return undefined;
|
|
|
|
|
|