Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ there stays yours.
what the person sends: their words, their attachments and the page they ask from, never T3
Code's own instructions. The web client is Buddy's one conversation: one thread with its days
beside it, no thread list, forks or rollbacks, and a message sent during a turn steers it. In
Buddy's bubble it talks to the page around it through the bubble's `lazurio.buddy.*` messages.
Buddy's bubble it talks to the page around it through the bubble's `lazurio.buddy.*` messages,
and that page travels with the person's message as a chip they can remove.
- **Updates from this repository.** The server offers the newest release of this repository and
installs it with the Update button, and `t3 update` and the install scripts take it from here
too. `T3CODE_RELEASE_REPOSITORY=owner/name` picks another repository's releases. After the
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/lazurio-fork-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ jobs:
apps/web/public/assets/avatar.webp
apps/web/src/routes/__root.tsx
apps/web/src/routes/_chat.index.tsx
# The page Buddy is asked from (root decision 0210, plan DEV-6676): in Buddy's surface
# the host page's last valid context is a chip above the composer, which the person can
# remove. While it is there, a message carries the page as a `lazurio-page` record
# with a reference in its text (ChatView.tsx, above), which Buddy's T3 Code projects
# as the Czech block (row 23). Composer and sent messages show the reference as a page
# chip where T3 would call an unknown context unavailable
# (composerContextPresentation.tsx, and MessagesTimeline.tsx, above). Its code lives
# in apps/web/src/lazurio/ (buddySurfacePage.ts, BuddySurfacePageChip.tsx).
apps/web/src/components/composerContextPresentation.tsx
)
unexpected="$(git diff --name-only "$UPSTREAM_SHA..HEAD" |
grep -E '^(apps|packages|scripts)/' |
Expand Down
49 changes: 36 additions & 13 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,13 @@ import {
LazurioRightPanelSurfaces,
useLazurioThreadTabs,
} from "../lazurio/LazurioEnvironmentBrowser";
import { BuddyThreadDetailsPanel, useBuddySurfaceMode } from "../lazurio/BuddySurface";
import {
BuddyThreadDetailsPanel,
useBuddyPage,
useBuddySurfaceMode,
} from "../lazurio/BuddySurface";
import { BuddyPageChip } from "../lazurio/BuddySurfacePageChip";
import { withPageRecord, withPageReference } from "../lazurio/buddySurfacePage";
import { addBrowserSurface } from "./preview/addBrowserSurface";
import { ThreadPreviewMiniPlayer } from "./preview/ThreadPreviewMiniPlayer";
import { usePreviewSession } from "./preview/usePreviewSession";
Expand Down Expand Up @@ -1256,6 +1262,8 @@ export default function ChatView(props: ChatViewProps) {
// Lazurio overlay (plan DEV-6676): in Buddy's one conversation a follow-up steers by default,
// and queueing is the explicit alternative.
const buddySurface = useBuddySurfaceMode() === true;
// The page Buddy is asked from travels with the person's next message (buddySurfacePage.ts).
const buddyPage = useBuddyPage(environmentId);
const environmentSettings = useEnvironmentSettings(environmentId);
const settings = buddySurface
? { ...environmentSettings, followUpBehavior: "steer" as const }
Expand Down Expand Up @@ -6616,20 +6624,28 @@ export default function ChatView(props: ChatViewProps) {
promptForSend,
)
.trim();
// Lazurio overlay (plan DEV-6676): the page joins only the text that is sent, where its record
// joins too. A failed send gives the composer back messageTextForSend, the person's own words,
// so a retry carries the page the chip shows then, or none once the person removed it.
const pageTextForSend = withPageReference(messageTextForSend, buddyPage.record).trim();
// Records bind attachments by the id each side knows: the local id for the optimistic
// row, the upload id (or local id on the data-URL path) on the wire; the server
// rebinds them to the persisted id.
const buildOutgoingMessageContext = (attachmentIds: ReadonlyArray<string>) =>
buildMessageContext({
terminalContexts: composerTerminalContextsSnapshot,
reviewComments: composerReviewCommentsSnapshot,
previewAnnotations: composerPreviewAnnotationsSnapshot,
threadContexts: composerThreadContextsSnapshot,
attachments: composerAttachmentsSnapshot.map((attachment, index) => ({
attachment,
attachmentId: attachmentIds[index] ?? attachment.id,
})),
});
withPageRecord(
buildMessageContext({
terminalContexts: composerTerminalContextsSnapshot,
reviewComments: composerReviewCommentsSnapshot,
previewAnnotations: composerPreviewAnnotationsSnapshot,
threadContexts: composerThreadContextsSnapshot,
attachments: composerAttachmentsSnapshot.map((attachment, index) => ({
attachment,
attachmentId: attachmentIds[index] ?? attachment.id,
})),
}),
buddyPage.record,
pageTextForSend,
);
const outgoingMessageContext = buildOutgoingMessageContext(
composerAttachmentsSnapshot.map((attachment) => attachment.id),
);
Expand All @@ -6652,7 +6668,7 @@ export default function ChatView(props: ChatViewProps) {
model: ctxSelectedModel,
models: ctxSelectedProviderModels,
effort: ctxSelectedPromptEffort,
text: messageTextForSend || ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
text: pageTextForSend || ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
});
if (composerRef.current?.validateProviderInput(outgoingMessageText) === false) {
return;
Expand Down Expand Up @@ -6705,7 +6721,7 @@ export default function ChatView(props: ChatViewProps) {
model: selection.model,
models: provider.models,
effort: providerState.promptEffort,
text: messageTextForSend || ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
text: pageTextForSend || ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
});
if (composerRef.current?.validateProviderInput(text) === false) return;
multipleTargets.push({
Expand Down Expand Up @@ -8456,6 +8472,13 @@ export default function ChatView(props: ChatViewProps) {
}
/>
) : null}
{buddyPage.record === null || queuedRunEdit.isEditing ? null : (
<BuddyPageChip
label={buddyPage.record.label}
removeLabel={buddyPage.removeLabel}
onRemove={buddyPage.remove}
/>
)}
{!composerMounted ? null : (
<ChatComposer
canOperateThread={canOperateThread}
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
useBuddyDayLines,
useBuddySurfaceMode,
} from "../../lazurio/BuddySurface";
import { buddyPageReferenceChip } from "../../lazurio/BuddySurfacePageChip";
import { notificationChildThreadId } from "@t3tools/client-runtime/state/thread-execution";
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
import {
Expand Down Expand Up @@ -4584,7 +4585,11 @@ const userMessageContextPresentationRegistry = createContextPresentationRegistry
),
},
],
fallback: (_kind, _record, context) => <UnavailableUserMessageContextChip {...context} />,
// Lazurio overlay (plan DEV-6676): the page Buddy was asked from is a context of its own.
fallback: (kind, _record, context) =>
buddyPageReferenceChip(kind, context.reference.label, context.copyMarkdown) ?? (
<UnavailableUserMessageContextChip {...context} />
),
});

function UserMessageContextReferenceChip(props: {
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/components/composerContextPresentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type { TerminalContextDraft } from "~/lib/terminalContext";
import type { ReviewCommentContext } from "~/reviewCommentContext";
import { ComposerPendingTerminalContextChip } from "./chat/ComposerPendingTerminalContexts";
import { ThreadContextChip } from "./ThreadContextChip";
import { buddyPageReferenceChip } from "~/lazurio/BuddySurfacePageChip";
import {
createContextPresentationRegistry,
type ContextPresentationCapability,
Expand Down Expand Up @@ -448,7 +449,9 @@ const composerContextPresentationRegistry = createContextPresentationRegistry<
),
},
],
fallback: (_kind, _entry, context) => <UnresolvedContextChip label={context.label} />,
// Lazurio overlay (plan DEV-6676): the page Buddy was asked from is a context of its own.
fallback: (kind, _entry, context) =>
buddyPageReferenceChip(kind, context.label) ?? <UnresolvedContextChip label={context.label} />,
});

export function ComposerContextReferenceChip(props: {
Expand Down
27 changes: 27 additions & 0 deletions apps/web/src/lazurio/BuddySurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Spinner } from "~/components/ui/spinner";
import { useMediaQuery } from "~/hooks/useMediaQuery";
import { primaryServerConfigAtom } from "~/state/server";
import { usePrimaryEnvironmentId } from "~/state/environments";
import { pageRecordOf } from "./buddySurfacePage";
import { prefersCzech } from "./threadTabs";
import { useBuddyFrame } from "./useBuddyFrame";

Expand Down Expand Up @@ -74,6 +75,7 @@ const TEXT = {
notReady: "Buddy se teprve instaluje.",
failed: "Buddyho se nepodařilo otevřít.",
retry: "Zkusit znovu",
removePage: "Neposílat stránku",
},
en: {
fullscreen: "Full screen",
Expand All @@ -86,9 +88,34 @@ const TEXT = {
notReady: "Buddy is still being set up.",
failed: "Buddy could not be opened.",
retry: "Try again",
removePage: "Don't send the page",
},
} as const;

const NO_REMOVED_PAGES: ReadonlySet<string> = new Set();

/**
* The page the next message in Buddy's composer carries: the last valid page context of the host,
* unless the person removed that page's chip, which stays removed while the surface is open.
* Another page shows its own chip. None outside Buddy's T3 Code or in a thread of another
* Environment than Buddy's.
*/
export function useBuddyPage(environmentId: string) {
const buddy = useBuddySurfaceMode(environmentId) === true;
const { context } = useBuddyFrame(buddy);
const text = useCzech(buddy) ? TEXT.cs : TEXT.en;
const [removed, setRemoved] = useState<ReadonlySet<string>>(NO_REMOVED_PAGES);
const page = context === null ? null : pageRecordOf(context);
const record = page !== null && !removed.has(page.contextId) ? page : null;
return {
record,
removeLabel: text.removePage,
remove: () => {
if (page !== null) setRemoved((current) => new Set([...current, page.contextId]));
},
};
}

const localDayOf = (date: Date) =>
`${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;

Expand Down
43 changes: 43 additions & 0 deletions apps/web/src/lazurio/BuddySurfacePageChip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Lazurio overlay (root decision 0210, plan DEV-6676): the chip of the page Buddy is asked from
* (buddySurfacePage.ts). Above Buddy's composer it shows the page the next message will carry, with
* a button that leaves it out; in the person's sent messages it stands where their text refers to
* the page, where T3 would otherwise call it unavailable context.
*/
import { MapPinIcon, XIcon } from "lucide-react";
import type { ReactElement } from "react";

import { ContextChip, ContextChipAction, ContextChipLabel } from "~/components/ContextChip";
import { LAZURIO_PAGE_KIND } from "./buddySurfacePage";

/** A page reference's chip in a message; none for any other kind. */
export function buddyPageReferenceChip(
kind: string,
label: string,
copyMarkdown?: string,
): ReactElement | undefined {
return kind === LAZURIO_PAGE_KIND ? (
<ContextChip data-markdown-copy={copyMarkdown}>
<MapPinIcon aria-hidden />
<ContextChipLabel>{label}</ContextChipLabel>
</ContextChip>
) : undefined;
}

export function BuddyPageChip(props: {
readonly label: string;
readonly removeLabel: string;
readonly onRemove: () => void;
}) {
return (
<div className="flex min-w-0 px-3 pt-2" data-lazurio-buddy-page>
<ContextChip>
<MapPinIcon aria-hidden />
<ContextChipLabel>{props.label}</ContextChipLabel>
<ContextChipAction aria-label={props.removeLabel} onClick={props.onRemove}>
<XIcon />
</ContextChipAction>
</ContextChip>
</div>
);
}
64 changes: 64 additions & 0 deletions apps/web/src/lazurio/buddySurfacePage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { OrchestrationMessageContext } from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import { describe, expect, it } from "vite-plus/test";

import { pageRecordOf, withPageRecord, withPageReference } from "./buddySurfacePage";
import type { BuddyContext } from "./buddySurfaceProtocol";

const context = (overrides: Partial<BuddyContext> = {}): BuddyContext => ({
lang: "cs",
theme: "light",
environment: { id: "mattycus", kind: "personal", name: "Mattyčus" },
organization: null,
app: "apps",
page: { path: "/apps" },
guide: null,
...overrides,
});

const encodeContext = Schema.encodeUnknownSync(OrchestrationMessageContext);
const decodeContext = Schema.decodeUnknownSync(OrchestrationMessageContext);

describe("the page Buddy is asked from", () => {
it("is one record per page, with the facts Buddy's T3 Code reads", () => {
const record = pageRecordOf(context());
expect(record).toMatchObject({
version: 1,
kind: "lazurio-page",
label: "Apps /apps",
payload: {
v: 1,
environment: { id: "mattycus", kind: "personal", name: "Mattyčus" },
organization: null,
app: "apps",
page: { path: "/apps" },
},
});
expect(pageRecordOf(context())?.contextId).toBe(record?.contextId);
expect(pageRecordOf(context({ page: { path: "/apps/chat" } }))?.contextId).not.toBe(
record?.contextId,
);
expect(pageRecordOf(context({ app: null, lang: "en" }))?.label).toBe("Mattyčus /apps");
expect(pageRecordOf(context({ environment: null }))).toBeNull();
});

it("travels with a message the person wrote, and is a valid message context", () => {
const record = pageRecordOf(context());
const text = withPageReference("Co tu vidím?", record);
expect(text).toMatch(/^Co tu vidím\? \[Apps \/apps\]\(t3-context:\/\/v1\/lazurio-page\//);
const sent = withPageRecord(undefined, record, text);
expect(sent?.records).toEqual([record]);
// The wire schema keeps it as a context record of its own kind.
expect(decodeContext(encodeContext(sent)).records).toEqual([record]);
// Once per message, even when asked twice.
expect(withPageRecord(sent, record, text)).toBe(sent);
});

it("stays out of an empty message and of a message that does not refer to it", () => {
const record = pageRecordOf(context());
expect(withPageReference(" ", record)).toBe(" ");
expect(withPageReference("Ahoj", null)).toBe("Ahoj");
expect(withPageRecord(undefined, record, "Ahoj")).toBeUndefined();
expect(withPageRecord(undefined, null, "Ahoj")).toBeUndefined();
});
});
Loading
Loading