mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
feat(teams): unify team model, snapshot sharing, and PNG memory parity (#1846)
Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
@@ -1016,6 +1016,7 @@ export async function createManagedAgent(input: CreateManagedAgentInput) {
|
||||
input: {
|
||||
name: input.name,
|
||||
personaId: input.personaId,
|
||||
teamId: input.teamId,
|
||||
relayUrl: input.relayUrl,
|
||||
acpCommand: input.acpCommand,
|
||||
agentCommand: input.agentCommand,
|
||||
|
||||
255
desktop/src/shared/api/tauriTeams.snapshotImport.test.mjs
Normal file
255
desktop/src/shared/api/tauriTeams.snapshotImport.test.mjs
Normal file
@@ -0,0 +1,255 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
deriveImportPhase,
|
||||
getProfileSyncFailures,
|
||||
deriveImportToast,
|
||||
buildTeamSnapshotSendArgs,
|
||||
} from "../../features/agents/ui/teamSnapshotImport.lib.ts";
|
||||
|
||||
// Behavior tests for the team snapshot import dialog flow and the send-encode
|
||||
// contract. These import and exercise the actual production functions used by
|
||||
// TeamSnapshotImportDialog, useTeamActions, and TeamSnapshotSendDialog.
|
||||
|
||||
// ── Factories ────────────────────────────────────────────────────────────────
|
||||
|
||||
function makeMemberResult(overrides = {}) {
|
||||
return {
|
||||
displayName: "Agent A",
|
||||
pubkey: "aabb".repeat(16),
|
||||
personaId: "persona-uuid-1",
|
||||
memoryWritten: 0,
|
||||
memoryTotal: 0,
|
||||
memoryErrors: [],
|
||||
profileSyncError: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function makeImportResult(overrides = {}) {
|
||||
const { members: memberOverrides, team: teamOverrides, ...rest } = overrides;
|
||||
return {
|
||||
team: {
|
||||
id: "team-uuid",
|
||||
name: "Test Team",
|
||||
description: "A test team",
|
||||
personaIds: ["persona-uuid-1"],
|
||||
instructions: "Be helpful",
|
||||
isBuiltin: false,
|
||||
sourceDir: null,
|
||||
isSymlink: false,
|
||||
symlinkTarget: null,
|
||||
version: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
...teamOverrides,
|
||||
},
|
||||
personaIds: ["persona-uuid-1"],
|
||||
members: [makeMemberResult()],
|
||||
...rest,
|
||||
...(memberOverrides !== undefined ? { members: memberOverrides } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
// ── deriveImportPhase ────────────────────────────────────────────────────────
|
||||
|
||||
test("deriveImportPhase_returns_result_when_result_present", () => {
|
||||
const result = makeImportResult();
|
||||
assert.equal(deriveImportPhase(result, false), "result");
|
||||
});
|
||||
|
||||
test("deriveImportPhase_returns_result_even_when_confirming", () => {
|
||||
// result takes precedence over isConfirming
|
||||
const result = makeImportResult();
|
||||
assert.equal(deriveImportPhase(result, true), "result");
|
||||
});
|
||||
|
||||
test("deriveImportPhase_returns_confirming_when_inflight", () => {
|
||||
assert.equal(deriveImportPhase(null, true), "confirming");
|
||||
});
|
||||
|
||||
test("deriveImportPhase_returns_preview_when_idle", () => {
|
||||
assert.equal(deriveImportPhase(null, false), "preview");
|
||||
});
|
||||
|
||||
test("deriveImportPhase_confirm_failure_returns_to_preview", () => {
|
||||
// When confirm throws, result stays null and isConfirming resets to false
|
||||
assert.equal(deriveImportPhase(null, false), "preview");
|
||||
});
|
||||
|
||||
// ── getProfileSyncFailures ───────────────────────────────────────────────────
|
||||
|
||||
test("getProfileSyncFailures_returns_members_with_errors", () => {
|
||||
const members = [
|
||||
makeMemberResult({ displayName: "A", profileSyncError: "relay timeout" }),
|
||||
makeMemberResult({
|
||||
displayName: "B",
|
||||
pubkey: "ccdd".repeat(16),
|
||||
profileSyncError: null,
|
||||
}),
|
||||
];
|
||||
const failures = getProfileSyncFailures(members);
|
||||
assert.equal(failures.length, 1);
|
||||
assert.equal(failures[0].displayName, "A");
|
||||
assert.equal(failures[0].profileSyncError, "relay timeout");
|
||||
});
|
||||
|
||||
test("getProfileSyncFailures_returns_empty_when_all_ok", () => {
|
||||
const members = [
|
||||
makeMemberResult({ profileSyncError: null }),
|
||||
makeMemberResult({
|
||||
displayName: "B",
|
||||
pubkey: "ccdd".repeat(16),
|
||||
profileSyncError: null,
|
||||
}),
|
||||
];
|
||||
assert.equal(getProfileSyncFailures(members).length, 0);
|
||||
});
|
||||
|
||||
test("getProfileSyncFailures_returns_all_when_all_failed", () => {
|
||||
const members = [
|
||||
makeMemberResult({ displayName: "A", profileSyncError: "relay rejected" }),
|
||||
makeMemberResult({
|
||||
displayName: "B",
|
||||
pubkey: "ccdd".repeat(16),
|
||||
profileSyncError: "network error",
|
||||
}),
|
||||
];
|
||||
assert.equal(getProfileSyncFailures(members).length, 2);
|
||||
});
|
||||
|
||||
// ── deriveImportToast ────────────────────────────────────────────────────────
|
||||
|
||||
test("deriveImportToast_success_when_no_failures", () => {
|
||||
const result = makeImportResult();
|
||||
const toast = deriveImportToast(result);
|
||||
assert.equal(toast.type, "notice");
|
||||
assert.match(toast.message, /Imported Test Team with 1 member\./);
|
||||
});
|
||||
|
||||
test("deriveImportToast_error_when_profile_sync_fails", () => {
|
||||
const result = makeImportResult({
|
||||
members: [makeMemberResult({ profileSyncError: "relay timeout" })],
|
||||
});
|
||||
const toast = deriveImportToast(result);
|
||||
assert.equal(toast.type, "error");
|
||||
assert.match(toast.message, /Test Team imported, but/);
|
||||
assert.match(toast.message, /failed to sync profile/);
|
||||
});
|
||||
|
||||
test("deriveImportToast_error_when_memory_errors_only", () => {
|
||||
const result = makeImportResult({
|
||||
members: [
|
||||
makeMemberResult({
|
||||
memoryTotal: 2,
|
||||
memoryWritten: 0,
|
||||
memoryErrors: ["err1", "err2"],
|
||||
profileSyncError: null,
|
||||
}),
|
||||
],
|
||||
});
|
||||
const toast = deriveImportToast(result);
|
||||
assert.equal(toast.type, "error");
|
||||
assert.match(toast.message, /2 memory entr/);
|
||||
assert.doesNotMatch(toast.message, /sync profile/);
|
||||
});
|
||||
|
||||
test("deriveImportToast_error_composes_both_failure_types", () => {
|
||||
const result = makeImportResult({
|
||||
members: [
|
||||
makeMemberResult({
|
||||
memoryTotal: 3,
|
||||
memoryWritten: 1,
|
||||
memoryErrors: ["slug err 1", "slug err 2"],
|
||||
profileSyncError: "relay timeout",
|
||||
}),
|
||||
],
|
||||
});
|
||||
const toast = deriveImportToast(result);
|
||||
assert.equal(toast.type, "error");
|
||||
assert.match(toast.message, /2 memory entr/);
|
||||
assert.match(toast.message, /failed to sync profile/);
|
||||
assert.match(toast.message, / and /);
|
||||
});
|
||||
|
||||
test("deriveImportToast_plural_members", () => {
|
||||
const result = makeImportResult({
|
||||
members: [
|
||||
makeMemberResult(),
|
||||
makeMemberResult({
|
||||
displayName: "Agent B",
|
||||
pubkey: "ccdd".repeat(16),
|
||||
personaId: "persona-uuid-2",
|
||||
}),
|
||||
],
|
||||
});
|
||||
const toast = deriveImportToast(result);
|
||||
assert.equal(toast.type, "notice");
|
||||
assert.match(toast.message, /with 2 members\./);
|
||||
});
|
||||
|
||||
test("deriveImportToast_singular_member", () => {
|
||||
const result = makeImportResult();
|
||||
const toast = deriveImportToast(result);
|
||||
assert.match(toast.message, /with 1 member\./);
|
||||
});
|
||||
|
||||
// ── Mixed success/failure across members ─────────────────────────────────────
|
||||
|
||||
test("mixed_member_outcomes_memory_errors_and_profile_sync", () => {
|
||||
const result = makeImportResult({
|
||||
members: [
|
||||
makeMemberResult({
|
||||
displayName: "Agent A",
|
||||
memoryWritten: 3,
|
||||
memoryTotal: 3,
|
||||
memoryErrors: [],
|
||||
profileSyncError: "relay timeout",
|
||||
}),
|
||||
makeMemberResult({
|
||||
displayName: "Agent B",
|
||||
pubkey: "ccdd".repeat(16),
|
||||
personaId: "persona-uuid-2",
|
||||
memoryWritten: 0,
|
||||
memoryTotal: 2,
|
||||
memoryErrors: ["err1", "err2"],
|
||||
profileSyncError: null,
|
||||
}),
|
||||
makeMemberResult({
|
||||
displayName: "Agent C",
|
||||
pubkey: "eeff".repeat(16),
|
||||
personaId: "persona-uuid-3",
|
||||
memoryWritten: 1,
|
||||
memoryTotal: 1,
|
||||
memoryErrors: [],
|
||||
profileSyncError: null,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const failures = getProfileSyncFailures(result.members);
|
||||
assert.equal(failures.length, 1);
|
||||
assert.equal(failures[0].displayName, "Agent A");
|
||||
|
||||
const toast = deriveImportToast(result);
|
||||
assert.equal(toast.type, "error");
|
||||
assert.match(toast.message, /2 memory entr/);
|
||||
assert.match(toast.message, /1 member failed to sync profile/);
|
||||
});
|
||||
|
||||
// ── buildTeamSnapshotSendArgs ────────────────────────────────────────────────
|
||||
|
||||
test("buildTeamSnapshotSendArgs_always_uses_png_format", () => {
|
||||
const args = buildTeamSnapshotSendArgs("team-123", "core");
|
||||
assert.equal(args.id, "team-123");
|
||||
assert.equal(args.memoryLevel, "core");
|
||||
assert.equal(args.format, "png");
|
||||
});
|
||||
|
||||
test("buildTeamSnapshotSendArgs_passes_through_memory_level", () => {
|
||||
for (const level of ["none", "core", "everything"]) {
|
||||
const args = buildTeamSnapshotSendArgs("t", level);
|
||||
assert.equal(args.memoryLevel, level);
|
||||
assert.equal(args.format, "png", `format must be png for level "${level}"`);
|
||||
}
|
||||
});
|
||||
@@ -9,6 +9,7 @@ type RawTeam = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
instructions?: string | null;
|
||||
persona_ids: string[];
|
||||
is_builtin?: boolean;
|
||||
source_dir?: string | null;
|
||||
@@ -24,6 +25,7 @@ function fromRawTeam(team: RawTeam): AgentTeam {
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
description: team.description,
|
||||
instructions: team.instructions ?? null,
|
||||
personaIds: team.persona_ids,
|
||||
isBuiltin: team.is_builtin ?? false,
|
||||
sourceDir: team.source_dir ?? null,
|
||||
@@ -45,6 +47,7 @@ export async function createTeam(input: CreateTeamInput): Promise<AgentTeam> {
|
||||
input: {
|
||||
name: input.name,
|
||||
description: input.description,
|
||||
instructions: input.instructions,
|
||||
personaIds: input.personaIds,
|
||||
},
|
||||
}),
|
||||
@@ -58,6 +61,7 @@ export async function updateTeam(input: UpdateTeamInput): Promise<AgentTeam> {
|
||||
id: input.id,
|
||||
name: input.name,
|
||||
description: input.description,
|
||||
instructions: input.instructions,
|
||||
personaIds: input.personaIds,
|
||||
},
|
||||
}),
|
||||
@@ -68,53 +72,130 @@ export async function deleteTeam(id: string): Promise<void> {
|
||||
await invokeTauri("delete_team", { id });
|
||||
}
|
||||
|
||||
export type ParsedTeamPreview = {
|
||||
name: string;
|
||||
description: string | null;
|
||||
personas: Array<{
|
||||
display_name: string;
|
||||
system_prompt: string;
|
||||
avatar_url: string | null;
|
||||
}>;
|
||||
// ── Team snapshot types ─────────────────────────────────────────────────────
|
||||
|
||||
export type SnapshotFormat = "json" | "png";
|
||||
export type SnapshotMemoryLevel = "none" | "core" | "everything";
|
||||
|
||||
export type EncodedTeamSnapshotPayload = {
|
||||
fileBytes: number[];
|
||||
fileName: string;
|
||||
};
|
||||
|
||||
export async function exportTeamToJson(id: string): Promise<boolean> {
|
||||
return invokeTauri<boolean>("export_team_to_json", { id });
|
||||
}
|
||||
export type TeamSnapshotMemberPreview = {
|
||||
displayName: string;
|
||||
systemPrompt: string | null;
|
||||
avatarUrl: string | null;
|
||||
hasSourceAllowlist: boolean;
|
||||
sourceAllowlistCount: number;
|
||||
};
|
||||
|
||||
export async function parseTeamFile(
|
||||
fileBytes: number[],
|
||||
fileName: string,
|
||||
): Promise<ParsedTeamPreview> {
|
||||
return invokeTauri<ParsedTeamPreview>("parse_team_file", {
|
||||
fileBytes,
|
||||
fileName,
|
||||
export type TeamSnapshotImportPreview = {
|
||||
name: string;
|
||||
description: string | null;
|
||||
instructions: string | null;
|
||||
members: TeamSnapshotMemberPreview[];
|
||||
hasSourceAllowlist: boolean;
|
||||
};
|
||||
|
||||
export type TeamSnapshotImportConfirm = {
|
||||
fileBytes: number[];
|
||||
keepAllowlist: boolean;
|
||||
};
|
||||
|
||||
export type TeamSnapshotImportMemberResult = {
|
||||
displayName: string;
|
||||
pubkey: string;
|
||||
personaId: string;
|
||||
memoryWritten: number;
|
||||
memoryTotal: number;
|
||||
memoryErrors: string[];
|
||||
profileSyncError: string | null;
|
||||
};
|
||||
|
||||
/** Wire shape of the nested `TeamRecord` — Rust has no `rename_all` so fields
|
||||
* arrive in snake_case, matching the existing `RawTeam` convention. */
|
||||
type RawTeamRecord = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
persona_ids: string[];
|
||||
instructions: string | null;
|
||||
is_builtin: boolean;
|
||||
source_dir: string | null;
|
||||
is_symlink: boolean;
|
||||
symlink_target: string | null;
|
||||
version: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
/** Raw wire shape of the import result — outer struct is camelCase,
|
||||
* but the nested `team` field is snake_case (no `rename_all` on TeamRecord). */
|
||||
type RawTeamSnapshotImportResult = {
|
||||
team: RawTeamRecord;
|
||||
personaIds: string[];
|
||||
members: TeamSnapshotImportMemberResult[];
|
||||
};
|
||||
|
||||
export type TeamSnapshotImportResult = {
|
||||
team: AgentTeam;
|
||||
personaIds: string[];
|
||||
members: TeamSnapshotImportMemberResult[];
|
||||
};
|
||||
|
||||
// ── Team snapshot commands ───────────────────────────────────────────────────
|
||||
|
||||
export async function exportTeamSnapshot(
|
||||
id: string,
|
||||
memoryLevel: SnapshotMemoryLevel,
|
||||
format: SnapshotFormat,
|
||||
): Promise<boolean> {
|
||||
return invokeTauri<boolean>("export_team_snapshot", {
|
||||
id,
|
||||
memoryLevel,
|
||||
format,
|
||||
});
|
||||
}
|
||||
|
||||
export type SyncResult = {
|
||||
personas_added: string[];
|
||||
personas_removed: string[];
|
||||
personas_updated: string[];
|
||||
metadata_changed: boolean;
|
||||
};
|
||||
|
||||
export async function pickTeamDirectory(): Promise<string | null> {
|
||||
return invokeTauri<string | null>("pick_team_directory");
|
||||
}
|
||||
|
||||
export async function installTeamFromDirectory(
|
||||
path: string,
|
||||
symlink?: boolean,
|
||||
): Promise<AgentTeam> {
|
||||
return fromRawTeam(
|
||||
await invokeTauri<RawTeam>("install_team_from_directory", {
|
||||
path,
|
||||
symlink: symlink ?? false,
|
||||
}),
|
||||
export async function encodeTeamSnapshotForSend(
|
||||
id: string,
|
||||
memoryLevel: SnapshotMemoryLevel,
|
||||
format: SnapshotFormat,
|
||||
): Promise<EncodedTeamSnapshotPayload> {
|
||||
return invokeTauri<EncodedTeamSnapshotPayload>(
|
||||
"encode_team_snapshot_for_send",
|
||||
{
|
||||
id,
|
||||
memoryLevel,
|
||||
format,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function syncTeamDirectory(teamId: string): Promise<SyncResult> {
|
||||
return invokeTauri<SyncResult>("sync_team_directory", { teamId });
|
||||
export async function previewTeamSnapshotImport(
|
||||
fileBytes: number[],
|
||||
fileName: string,
|
||||
): Promise<TeamSnapshotImportPreview> {
|
||||
return invokeTauri<TeamSnapshotImportPreview>(
|
||||
"preview_team_snapshot_import",
|
||||
{
|
||||
fileBytes,
|
||||
fileName,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function confirmTeamSnapshotImport(
|
||||
input: TeamSnapshotImportConfirm,
|
||||
): Promise<TeamSnapshotImportResult> {
|
||||
const raw = await invokeTauri<RawTeamSnapshotImportResult>(
|
||||
"confirm_team_snapshot_import",
|
||||
{ input },
|
||||
);
|
||||
return {
|
||||
team: fromRawTeam(raw.team),
|
||||
personaIds: raw.personaIds,
|
||||
members: raw.members,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -476,6 +476,8 @@ export type RelayMeshConfig = {
|
||||
export type CreateManagedAgentInput = {
|
||||
name: string;
|
||||
personaId?: string;
|
||||
/** Team this instance was deployed from; controls runtime team instructions. */
|
||||
teamId?: string;
|
||||
relayUrl?: string;
|
||||
acpCommand?: string;
|
||||
agentCommand?: string;
|
||||
@@ -813,6 +815,7 @@ export type AgentTeam = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
instructions: string | null;
|
||||
personaIds: string[];
|
||||
isBuiltin: boolean;
|
||||
/** Absolute path to the team's backing directory (if directory-backed). */
|
||||
@@ -830,6 +833,7 @@ export type AgentTeam = {
|
||||
export type CreateTeamInput = {
|
||||
name: string;
|
||||
description?: string;
|
||||
instructions?: string;
|
||||
personaIds: string[];
|
||||
};
|
||||
|
||||
@@ -837,6 +841,7 @@ export type UpdateTeamInput = {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
instructions?: string;
|
||||
personaIds: string[];
|
||||
};
|
||||
// ── Channel Template types ─────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user