mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-03 22:59:38 +08:00
* Add unified asset use tool with bounded media reads * Track asset tool actions across MCP transports --------- Co-authored-by: 罗高 <luogao@users.noreply.github.com>
38 lines
2.2 KiB
TypeScript
38 lines
2.2 KiB
TypeScript
import type { Modality } from './gateway.ts';
|
|
|
|
/** A reference always pins immutable bytes, never the asset's changing current version. */
|
|
export type AssetReference = { assetId: string; versionId: string };
|
|
export type AssetVersion = {
|
|
id: string; createdAt: number; source: 'upload' | 'generated'; filename: string; name?: string;
|
|
mimeType: string; bytes: number; sha256: string; width?: number; height?: number; duration?: number;
|
|
prompt?: string; model?: string; parameters?: Record<string, unknown>;
|
|
references: AssetReference[]; parentVersionId?: string; jobId?: string; conversationId?: string;
|
|
requestId?: string; requestHash?: string;
|
|
};
|
|
export type LibraryAsset = {
|
|
id: string; name: string; modality: Modality; createdAt: number; updatedAt: number;
|
|
currentVersionId: string; versions: AssetVersion[]; trashedAt?: number;
|
|
};
|
|
export type LibraryGeneration = {
|
|
assetId?: string; title?: string; parentVersionId?: string;
|
|
references?: AssetReference[]; conversationId?: string;
|
|
};
|
|
export type AssetListInput = {
|
|
modality?: Modality; source?: 'upload' | 'generated'; query?: string; trash?: boolean;
|
|
sort?: 'newest' | 'oldest' | 'name'; offset?: number; limit?: number;
|
|
};
|
|
export const assetVersion = (asset: LibraryAsset, versionId = asset.currentVersionId) => asset.versions.find(version => version.id === versionId);
|
|
export const assetMediaUrl = (assetId: string, versionId: string) => `/motion-api/assets/${encodeURIComponent(assetId)}/versions/${encodeURIComponent(versionId)}/file`;
|
|
|
|
export type AssetReadContent = { type: 'text'; text: string } | { type: 'image' | 'audio'; mimeType: string; data: string };
|
|
export type AssetReadResult = {
|
|
assetId: string; versionId: string; modality: Modality; version: AssetVersion;
|
|
previews: { mimeType: string; bytes: number; width?: number; height?: number; timestamp?: number; start?: number; duration?: number }[];
|
|
content: AssetReadContent[];
|
|
};
|
|
/** Media belongs in native content, never duplicated in JSON metadata or persisted chat messages. */
|
|
export function assetReadToolResult(value: AssetReadResult) {
|
|
const { content, ...metadata } = value;
|
|
return { content: [{ type: 'text' as const, text: JSON.stringify(metadata) }, ...content], structuredContent: metadata };
|
|
}
|