Add attachments, usage limits and automation editing

Attachments upload like the web composer's (signed URL, then bytes) and ride on the next message or a draft's first message; pending names show above the composer and removal deletes the unsent upload. Settings shows provider limit windows, banked reset credits and the last 30 days' usage summary, with a status-line note near a limit and a confirmed reset-credit command. Automations can be created and edited in $EDITOR from a template parsed back against the web form's rules, and deleted behind a confirm. Asks for the diagnostics:read and providers:manage scopes the new RPCs need.
This commit is contained in:
Callum Alpass committed 2026-11-02 20:47:54 +11:00
1 parent 43347d1d58
commit 2b31804f8e
15 files changed
+1049 -23

No files matched your search

+62 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { OrchestrationV2Command, OrchestrationV2ThreadLaunchInput, ProjectId, ProviderInstanceId, ThreadId, RuntimeRequestId } from "@t3tools/contracts";
import { AttachmentCreateUploadUrlInput, AttachmentDeleteInput, OrchestrationV2Command, OrchestrationV2ThreadLaunchInput, ProjectId, ProviderConsumeResetCreditInput, ProviderInstanceId, ScheduledTaskDeleteInput, ThreadId, RuntimeRequestId, UsageSummaryInput, type ChatAttachment } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
@@ -94,4 +94,65 @@ describe("commands tui3 dispatches", () => {
expect(Schema.is(OrchestrationV2ThreadLaunchInput)(payload)).toBe(true);
expect(payload).toMatchObject({ initialMessage: { text: "Fix the flaky test", attachments: [] } });
});
test("attachments ride on a message and on a new thread's first message", async () => {
const attachment = { type: "image", id: "upload-1", name: "shot.png", mimeType: "image/png", sizeBytes: 12 } as ChatAttachment;
const { session, sent } = capturingSession();
await session.sendMessage(threadId, "see this", "auto", undefined, undefined, [attachment]);
expect(isCommand(sent[0])).toBe(true);
expect(sent[0]).toMatchObject({ type: "message.dispatch", attachments: [attachment] });
const launching = new T3Session();
let payload: unknown;
const rpc = { "orchestration.launchThread": (input: unknown) => ((payload = input), Effect.succeed({ threadId: ThreadId.make("new-2") })) };
(launching as unknown as { connection: unknown }).connection = { rpc };
await launching.launchThread({
projectId: ProjectId.make("p1"),
title: "Attached image",
generateTitle: true,
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5" },
runtimeMode: "full-access",
interactionMode: "default",
workspaceStrategy: { type: "root" },
text: "see this",
attachments: [attachment],
});
expect(Schema.is(OrchestrationV2ThreadLaunchInput)(payload)).toBe(true);
expect(payload).toMatchObject({ initialMessage: { attachments: [attachment] } });
});
test("upload mint, delete, usage, reset credit and automation delete payloads validate", async () => {
const session = new T3Session();
const calls = new Map<string, unknown>();
const rpc = new Proxy(
{},
{
get: (_target, method) => (input: unknown) => {
calls.set(String(method), input);
if (method === "attachments.createUploadUrl") return Effect.succeed({ attachmentId: "upload-9", relativeUrl: "/upload?sig=x", expiresAt: 1 });
if (method === "server.getUsageSummary") return Effect.succeed({ buckets: [] });
if (method === "provider.consumeResetCredit") return Effect.succeed({ outcome: "reset" });
return Effect.succeed({});
},
},
);
(session as unknown as { connection: unknown }).connection = { rpc, target: { httpBaseUrl: "http://127.0.0.1:9" } };
const originalFetch = globalThis.fetch;
globalThis.fetch = (async () => new Response(null, { status: 200 })) as unknown as typeof fetch;
try {
const uploaded = await session.uploadAttachment({ type: "image", name: "shot.png", mimeType: "image/png", sizeBytes: 3 }, new Uint8Array([1, 2, 3]));
expect(uploaded).toEqual({ type: "image", id: "upload-9", name: "shot.png", mimeType: "image/png", sizeBytes: 3 });
} finally {
globalThis.fetch = originalFetch;
}
await session.deleteAttachment("upload-9");
await session.usageSummary({ sinceDay: "2026-10-03" as never, untilDay: "2026-11-02" as never, timeZone: "UTC" });
await session.consumeResetCredit({ instanceId: ProviderInstanceId.make("claude-1") });
await session.deleteAutomation("task-1" as never);
expect(Schema.is(AttachmentCreateUploadUrlInput)(calls.get("attachments.createUploadUrl"))).toBe(true);
expect(Schema.is(AttachmentDeleteInput)(calls.get("attachments.delete"))).toBe(true);
expect(Schema.is(UsageSummaryInput)(calls.get("server.getUsageSummary"))).toBe(true);
expect(Schema.is(ProviderConsumeResetCreditInput)(calls.get("provider.consumeResetCredit"))).toBe(true);
expect(Schema.is(ScheduledTaskDeleteInput)(calls.get("scheduledTasks.delete"))).toBe(true);
});
});