* feat(generation): changeOutlineType total constructor for valid type switches Switching a scene outline's type in the editor only flipped `type` and left the new type without its required config, so applyOutlineFallbacks silently downgraded interactive/pbl back to slide. changeOutlineType returns a new outline that strips foreign per-type config and seeds the target type's required config from the shared fields, valid by construction. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * i18n(generation): keys for interactive widget kind and PBL project config Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(editor): make outline type changes take effect with config forms TypePill now builds a valid outline via changeOutlineType (replace, not partial-merge) so a type switch drops stale config and seeds the new type's required config — no longer silently downgraded to slide by applyOutlineFallbacks. Adds InteractiveConfigDisclosure (widget kind + concept) and PblConfigDisclosure (topic / description / target skills), mirroring QuizConfigDisclosure, so users can configure interactive and PBL scenes that previously had no input UI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(editor): move type-specific config under the type pill The quiz/interactive/PBL config disclosure rendered as a detached chip at the bottom-left of the card, reading like a stray key point. Pin it to the bottom-right of the key-points row instead, so it sits directly under the TypePill it configures (type top-right -> its config bottom-right, same edge), with key points flowing on the left. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(editor): cascade type config as a connected segment left of the type pill Replace the standalone config chip with a cascading control in the header: the type-specific config (quiz count / interactive widget kind / PBL project) renders as a themed segment joined to the left of the TypePill, the two clipped into one rounded pill split by a hairline divider. Reads as a single 'config › type' cascade and groups the config with the selector it refines. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(editor): address cross-review — preserve widget config, drop stale fields - changeOutlineType: preserve an existing procedural-skill widget config instead of replacing it with a seeded simulation (codex P2 — task-engine fields were silently dropped on Interactive re-select). - InteractiveConfigDisclosure.setWidgetType: reset widgetOutline to the shared concept only, so switching widget kind drops the previous kind's fields (claude P2 — language/gameType/etc. leaked across kinds). - i18n locale-coverage test now also checks ko-KR and pt-BR. - Drop a redundant WidgetType cast; add tests for procedural-skill preservation and pbl targetSkills dedupe/cap. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(editor): round 2 cross-review nits — procedural-skill label + skill a11y - InteractiveConfigDisclosure: when an outline carries a preserved procedural-skill widget, surface it as the current (selected) kind with its own label instead of mislabeling it 'Simulation', and make a same-kind re-select a no-op so its task-engine fields are never silently clobbered. - PBL target-skill remove button uses a dedicated removeSkill aria-label. - Add widgetProceduralSkill / removeSkill i18n keys (8 locales) + test coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(generation): make re-selecting the current outline type a no-op changeOutlineType rebuilt the outline on every type-menu click, so re-selecting the already-current type dropped fields it doesn't re-seed — legacy interactiveConfig, or a partial pblConfig whose projectTopic is empty — turning a harmless click into data loss. Short-circuit same-type selections to return the outline untouched (codex P2). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(format): prettier --write files left unformatted on main These 14 agent/edit files (not part of this PR's feature) fail the repo-wide `prettier . --check` in the required Lint job — they landed on main unformatted, turning main's CI (and therefore this PR after a branch update) red. Formatting them here unblocks the required check; pure formatting, no logic changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(lint): suppress intentional set-state-in-effect in reasoning timer The reasoning timer does a deliberate one-shot setState in its effect to show the right elapsed value before the first 1s interval tick. main's CI fails the required Lint job on the new react-hooks/set-state-in-effect rule here; suppress it with a justification (no behavior change). Unblocks the required check. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
170 lines
6.2 KiB
TypeScript
170 lines
6.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { ThreadMessageLike } from '@assistant-ui/react';
|
|
import { serializeThread, deserializeThread } from '@/lib/agent/client/serialize-thread';
|
|
|
|
describe('serializeThread / deserializeThread', () => {
|
|
it('round-trips text user + assistant turns', () => {
|
|
const messages: ThreadMessageLike[] = [
|
|
{ role: 'user', id: 'u1', content: [{ type: 'text', text: 'hello' }] },
|
|
{ role: 'assistant', id: 'a1', content: [{ type: 'text', text: 'hi there' }] },
|
|
];
|
|
const restored = deserializeThread(serializeThread(messages));
|
|
expect(restored).toHaveLength(2);
|
|
expect(restored[0].role).toBe('user');
|
|
expect((restored[0].content as unknown as { text: string }[])[0].text).toBe('hello');
|
|
expect((restored[1].content as unknown as { text: string }[])[0].text).toBe('hi there');
|
|
expect(restored[1].status).toEqual({ type: 'complete', reason: 'stop' });
|
|
// assistant-ui throws if a user message carries a status — it must be unset.
|
|
expect(restored[0].status).toBeUndefined();
|
|
});
|
|
|
|
it('keeps tool-call metadata but strips heavy result element data', () => {
|
|
const messages: ThreadMessageLike[] = [
|
|
{
|
|
role: 'assistant',
|
|
id: 'a1',
|
|
content: [
|
|
{
|
|
type: 'tool-call',
|
|
toolCallId: 'tc1',
|
|
toolName: 'regenerate_scene',
|
|
args: { sceneId: 's1', instruction: 'condense' },
|
|
result: {
|
|
content: [{ type: 'text', text: 'done' }],
|
|
details: {
|
|
sceneId: 's1',
|
|
content: {
|
|
elements: [
|
|
{ id: 'e1', type: 'image', src: 'data:image/png;base64,AAAA…huge' },
|
|
{ id: 'e2', type: 'text', content: 'x'.repeat(5000) },
|
|
],
|
|
},
|
|
actions: [{ type: 'speech', extra: 'dropme' }],
|
|
},
|
|
},
|
|
},
|
|
] as ThreadMessageLike['content'],
|
|
},
|
|
];
|
|
const slim = serializeThread(messages);
|
|
const part = slim[0].content[0];
|
|
expect(part.type).toBe('tool-call');
|
|
if (part.type !== 'tool-call') throw new Error('expected tool-call');
|
|
expect(part.toolName).toBe('regenerate_scene');
|
|
expect(part.args).toEqual({ sceneId: 's1', instruction: 'condense' });
|
|
// element count preserved, element payload (incl base64) dropped
|
|
expect(part.result?.details?.content).toEqual({ elements: [{}, {}] });
|
|
const json = JSON.stringify(slim);
|
|
expect(json).not.toContain('base64');
|
|
expect(json.length).toBeLessThan(400);
|
|
// action types kept, extra fields dropped
|
|
expect(part.result?.details?.actions).toEqual([{ type: 'speech' }]);
|
|
});
|
|
|
|
it('preserves details.content === null (failure marker)', () => {
|
|
const messages: ThreadMessageLike[] = [
|
|
{
|
|
role: 'assistant',
|
|
id: 'a1',
|
|
content: [
|
|
{
|
|
type: 'tool-call',
|
|
toolCallId: 'tc1',
|
|
toolName: 'regenerate_scene',
|
|
args: { sceneId: 's1' },
|
|
result: {
|
|
content: [{ type: 'text', text: 'refused' }],
|
|
details: { sceneId: 's1', content: null },
|
|
},
|
|
},
|
|
] as ThreadMessageLike['content'],
|
|
},
|
|
];
|
|
const part = serializeThread(messages)[0].content[0];
|
|
if (part.type !== 'tool-call') throw new Error('expected tool-call');
|
|
expect(part.result?.details?.content).toBeNull();
|
|
});
|
|
|
|
it('round-trips a reasoning part with its duration', () => {
|
|
const messages: ThreadMessageLike[] = [
|
|
{
|
|
role: 'assistant',
|
|
id: 'a1',
|
|
content: [
|
|
{ type: 'reasoning', text: 'let me think' },
|
|
{ type: 'text', text: 'answer' },
|
|
] as ThreadMessageLike['content'],
|
|
},
|
|
];
|
|
const slim = serializeThread(messages, () => 1500);
|
|
expect(slim[0].content[0]).toEqual({
|
|
type: 'reasoning',
|
|
text: 'let me think',
|
|
durationMs: 1500,
|
|
});
|
|
const restored = deserializeThread(slim);
|
|
const parts = restored[0].content as unknown as { type: string; text?: string }[];
|
|
expect(parts[0]).toEqual({ type: 'reasoning', text: 'let me think' });
|
|
expect(parts[1]).toEqual({ type: 'text', text: 'answer' });
|
|
});
|
|
|
|
it('preserves edit_interactive_html success markers (html applied + editCount)', () => {
|
|
const messages: ThreadMessageLike[] = [
|
|
{
|
|
role: 'assistant',
|
|
id: 'a1',
|
|
content: [
|
|
{
|
|
type: 'tool-call',
|
|
toolCallId: 'tc1',
|
|
toolName: 'edit_interactive_html',
|
|
args: { sceneId: 's1' },
|
|
result: { details: { sceneId: 's1', html: '<html>…huge 745kb…</html>', editCount: 3 } },
|
|
},
|
|
] as ThreadMessageLike['content'],
|
|
},
|
|
];
|
|
const slim = serializeThread(messages);
|
|
const part = slim[0].content[0];
|
|
if (part.type !== 'tool-call') throw new Error('expected tool-call');
|
|
// html replaced by a non-null placeholder (success survives, payload dropped)
|
|
expect(typeof part.result?.details?.html).toBe('string');
|
|
expect(part.result?.details?.editCount).toBe(3);
|
|
expect(JSON.stringify(slim).length).toBeLessThan(300);
|
|
});
|
|
|
|
it('preserves edit_interactive_html refusal (html === null)', () => {
|
|
const messages: ThreadMessageLike[] = [
|
|
{
|
|
role: 'assistant',
|
|
id: 'a1',
|
|
content: [
|
|
{
|
|
type: 'tool-call',
|
|
toolCallId: 'tc1',
|
|
toolName: 'edit_interactive_html',
|
|
args: { sceneId: 's1' },
|
|
result: { details: { sceneId: 's1', html: null, editCount: 0 } },
|
|
},
|
|
] as ThreadMessageLike['content'],
|
|
},
|
|
];
|
|
const part = serializeThread(messages)[0].content[0];
|
|
if (part.type !== 'tool-call') throw new Error('expected tool-call');
|
|
expect(part.result?.details?.html).toBeNull();
|
|
});
|
|
|
|
it('drops messages with no renderable content', () => {
|
|
const messages: ThreadMessageLike[] = [
|
|
{ role: 'assistant', id: 'a1', content: [] },
|
|
{ role: 'user', id: 'u1', content: [{ type: 'text', text: 'kept' }] },
|
|
];
|
|
expect(serializeThread(messages)).toHaveLength(1);
|
|
});
|
|
|
|
it('deserialize handles undefined / empty', () => {
|
|
expect(deserializeThread(undefined)).toEqual([]);
|
|
expect(deserializeThread([])).toEqual([]);
|
|
});
|
|
});
|