- dictation.ts: Uint8Array cast for getByteTimeDomainData - user-help-vibe.test.ts + user-profile-harvest.test.ts: computerHost 'evo' → null - executor-utils.ts: import AgentRunRequest from adapter-kit, MessageBlock from contracts - pi-model-config.ts: import AgentToolExecutionResult from adapter-kit Results: apps/web 0 TS errors (was 4), packages/adapters 15→6 errors
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import type { AgentRunRequest } from "@rakazo/adapter-kit";
|
|
import type { MessageBlock } from "@rakazo/contracts";
|
|
import { isAttachmentImageMimeType } from "@rakazo/contracts";
|
|
import type { ExecutorDeps } from "./executor-types.js";
|
|
|
|
/** Filter connection rows to active/connected providers. */
|
|
export function selectRunConnections<
|
|
T extends { connectorId: string; provider: string; status: string },
|
|
>(rows: T[], connectedComposioProviders: string[]): T[] {
|
|
const activeKeys = new Set(connectedComposioProviders.map((provider) => `composio:${provider}`));
|
|
return rows.filter(
|
|
(row) =>
|
|
row.status !== "revoked" &&
|
|
(row.status === "connected" || activeKeys.has(`${row.connectorId}:${row.provider}`)),
|
|
);
|
|
}
|
|
|
|
/** Load image artifacts for the current turn. */
|
|
export async function loadCurrentTurnImages(
|
|
deps: ExecutorDeps,
|
|
blocks: MessageBlock[] | undefined,
|
|
context: {
|
|
operationId: string;
|
|
traceId: string;
|
|
spaceId: string;
|
|
userId: string;
|
|
botId: string;
|
|
runId: string;
|
|
signal: AbortSignal;
|
|
},
|
|
) {
|
|
if (!deps.artifacts || !blocks?.length) return undefined;
|
|
const imageBlocks = blocks.filter(
|
|
(block): block is Extract<MessageBlock, { kind: "image" }> => block.kind === "image",
|
|
);
|
|
if (!imageBlocks.length) return undefined;
|
|
|
|
const rows = await deps.prisma.artifact.findMany({
|
|
where: {
|
|
id: { in: imageBlocks.map((block) => block.artifactId) },
|
|
spaceId: context.spaceId,
|
|
userId: context.userId,
|
|
},
|
|
});
|
|
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
const images: NonNullable<AgentRunRequest["currentTurnImages"]> = [];
|
|
|
|
for (const block of imageBlocks) {
|
|
const row = byId.get(block.artifactId);
|
|
if (!row || !isAttachmentImageMimeType(block.mimeType)) continue;
|
|
try {
|
|
const bytes = await deps.artifacts.get(row.storageKey, context);
|
|
images.push({
|
|
name: block.name,
|
|
mimeType: block.mimeType as "image/jpeg" | "image/png" | "image/webp" | "image/gif",
|
|
data: bytes,
|
|
});
|
|
} catch (error) {
|
|
if (context.signal.aborted) throw error;
|
|
}
|
|
}
|
|
|
|
return images.length ? images : undefined;
|
|
}
|