mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-11 02:46:29 +00:00
A plugin registers a component with addComposerItem and reads and changes the composer through useComposer(): provider, model, mode, thinking, options, prompt, attachments and agent metadata. The agent, draft and New workspace composers provide the same ComposerInput and ComposerAgent halves, so a command reaches the right model without the plugin knowing which composer it sits in. Toggle, Select and Action are drawn by one ComposerControl renderer that the thinking select and provider option controls now use too. Controls sit in the toolbar when there is room and become rows in the existing overflow sheet otherwise, so on a phone they appear in the overflow. Plugin items count in the density presence so the composer condenses to make room. Model and mode stay specialized but share the trigger, density and overflow. Draft metadata is kept locally, sent at creation and reset when the prompt is sent. PluginAgentSnapshot.metadata, deferred from the metadata phase, lands here. The unused provider badge is removed. vitest resolves @floating-ui/react-native to its ESM build: the CJS entry requires the real react-native, whose Flow sources do not parse.
202 lines
5.1 KiB
TypeScript
202 lines
5.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
COMPOSER_TOOLBAR_GEOMETRY,
|
|
resolveComposerControlDensity,
|
|
resolveComposerControlPresentation,
|
|
resolveComposerToolbarGlyphSize,
|
|
} from "./layout";
|
|
|
|
describe("composer control layout", () => {
|
|
it("removes labels in priority order as the toolbar narrows", () => {
|
|
expect(resolveComposerControlPresentation("full")).toEqual({
|
|
showCarets: true,
|
|
showThinkingLabel: true,
|
|
showModeLabel: true,
|
|
aggregateFeatures: false,
|
|
});
|
|
expect(resolveComposerControlPresentation("condensed")).toEqual({
|
|
showCarets: false,
|
|
showThinkingLabel: false,
|
|
showModeLabel: true,
|
|
aggregateFeatures: true,
|
|
});
|
|
expect(resolveComposerControlPresentation("tight")).toEqual({
|
|
showCarets: false,
|
|
showThinkingLabel: false,
|
|
showModeLabel: false,
|
|
aggregateFeatures: true,
|
|
});
|
|
});
|
|
|
|
it("uses local available width and hysteresis to avoid density churn", () => {
|
|
const controls = {
|
|
hasModel: true,
|
|
hasThinking: true,
|
|
hasMode: true,
|
|
features: [{ type: "toggle" as const }],
|
|
pluginItems: 0,
|
|
fontScale: 1,
|
|
};
|
|
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
availableWidth: 420,
|
|
currentDensity: "full",
|
|
controls,
|
|
}),
|
|
).toBe("full");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
availableWidth: 380,
|
|
currentDensity: "full",
|
|
controls,
|
|
}),
|
|
).toBe("condensed");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
availableWidth: 290,
|
|
currentDensity: "condensed",
|
|
controls,
|
|
}),
|
|
).toBe("condensed");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
availableWidth: 280,
|
|
currentDensity: "condensed",
|
|
controls,
|
|
}),
|
|
).toBe("tight");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
availableWidth: 300,
|
|
currentDensity: "tight",
|
|
controls,
|
|
}),
|
|
).toBe("tight");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
availableWidth: 312,
|
|
currentDensity: "tight",
|
|
controls,
|
|
}),
|
|
).toBe("condensed");
|
|
});
|
|
|
|
it("budgets extra features and larger text before restoring full labels", () => {
|
|
const base = {
|
|
availableWidth: 430,
|
|
currentDensity: "condensed" as const,
|
|
};
|
|
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
...base,
|
|
controls: {
|
|
hasModel: true,
|
|
hasThinking: true,
|
|
hasMode: true,
|
|
features: [{ type: "toggle" }],
|
|
pluginItems: 0,
|
|
fontScale: 1,
|
|
},
|
|
}),
|
|
).toBe("full");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
...base,
|
|
controls: {
|
|
hasModel: true,
|
|
hasThinking: true,
|
|
hasMode: true,
|
|
features: [{ type: "toggle" }, { type: "select", label: "Tools" }],
|
|
pluginItems: 0,
|
|
fontScale: 1,
|
|
},
|
|
}),
|
|
).toBe("condensed");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
...base,
|
|
controls: {
|
|
hasModel: true,
|
|
hasThinking: true,
|
|
hasMode: true,
|
|
features: [{ type: "toggle" }],
|
|
pluginItems: 0,
|
|
fontScale: 1.25,
|
|
},
|
|
}),
|
|
).toBe("condensed");
|
|
});
|
|
|
|
it("condenses before a labeled feature would overflow", () => {
|
|
const base = {
|
|
availableWidth: 430,
|
|
currentDensity: "full" as const,
|
|
controls: {
|
|
hasModel: true,
|
|
hasThinking: true,
|
|
hasMode: true,
|
|
pluginItems: 0,
|
|
fontScale: 1,
|
|
},
|
|
};
|
|
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
...base,
|
|
controls: { ...base.controls, features: [{ type: "toggle" }] },
|
|
}),
|
|
).toBe("full");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
...base,
|
|
controls: {
|
|
...base.controls,
|
|
features: [{ type: "select", label: "A much longer localized feature label" }],
|
|
},
|
|
}),
|
|
).toBe("condensed");
|
|
});
|
|
|
|
it("condenses to make room for plugin items and keeps them in the overflow", () => {
|
|
const base = {
|
|
availableWidth: 430,
|
|
currentDensity: "full" as const,
|
|
controls: {
|
|
hasModel: true,
|
|
hasThinking: true,
|
|
hasMode: true,
|
|
features: [],
|
|
fontScale: 1,
|
|
},
|
|
};
|
|
|
|
expect(
|
|
resolveComposerControlDensity({ ...base, controls: { ...base.controls, pluginItems: 0 } }),
|
|
).toBe("full");
|
|
expect(
|
|
resolveComposerControlDensity({ ...base, controls: { ...base.controls, pluginItems: 2 } }),
|
|
).toBe("condensed");
|
|
expect(
|
|
resolveComposerControlDensity({
|
|
...base,
|
|
availableWidth: 250,
|
|
controls: { ...base.controls, pluginItems: 2 },
|
|
}),
|
|
).toBe("tight");
|
|
});
|
|
|
|
it("gives every toolbar control one shell and one platform glyph envelope", () => {
|
|
expect(COMPOSER_TOOLBAR_GEOMETRY).toEqual({
|
|
controlSize: 28,
|
|
controlGap: 4,
|
|
iconLabelGap: 4,
|
|
labelPadding: 8,
|
|
caretSize: 14,
|
|
});
|
|
expect(resolveComposerToolbarGlyphSize("web")).toBe(16);
|
|
expect(resolveComposerToolbarGlyphSize("native")).toBe(20);
|
|
});
|
|
});
|