Open History to see the last commit
1import { ProviderInstanceId, ThreadId, type ServerProvider } from "@t3tools/contracts";
2import { expect, it } from "@effect/vitest";
3
4import { type AgentThread, agentToolProperties, handoffSettings } from "./ProviderDimensions.ts";
5
6const provider = (
7 instanceId: string,
8 driver: string,
9 models: ReadonlyArray<{ slug: string; isCustom: boolean }>,
10 auth: Record<string, string> = {},
11) =>
12 ({
13 instanceId: ProviderInstanceId.make(instanceId),
14 driver,
15 auth: { status: "authenticated", ...auth },
16 models,
17 }) as unknown as ServerProvider;
18
19const providers = [
20 provider("work-codex", "codex", [{ slug: "gpt-5.5", isCustom: false }]),
21 provider("azure-codex", "codex", [{ slug: "gpt-acme-finetune", isCustom: false }], {
22 endpoint: "https://acme.example.com",
23 }),
24 provider("claudeAgent", "claudeAgent", [
25 { slug: "claude-opus-5-5", isCustom: false },
26 { slug: "my-private-finetune", isCustom: true },
27 ]),
28 provider("opencode", "opencode", [{ slug: "ollama/acme-internal", isCustom: false }]),
29];
30
31const thread = (
32 instanceId: string,
33 model: string,
34 overrides: Partial<AgentThread> = {},
35): AgentThread => ({
36 modelSelection: { instanceId: ProviderInstanceId.make(instanceId), model },
37 runtimeMode: "full-access",
38 interactionMode: "default",
39 createdBy: "user",
40 creationSource: "web",
41 lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: ThreadId.make("t") },
42 ...overrides,
43});
44
45it("omits custom, user-configured, endpoint-served, and unknown models and instance names", () => {
46 expect(
47 agentToolProperties({
48 tool: "t3_thread_send",
49 providers,
50 caller: thread("claudeAgent", "my-private-finetune"),
51 targets: [
52 thread("opencode", "ollama/acme-internal"),
53 thread("removed-instance", "gpt-5.5"),
54 thread("azure-codex", "gpt-acme-finetune"),
55 ],
56 outcome: { outcome: "ok" },
57 }).map(({ callerProvider, callerModel, targetProvider, targetModel }) => ({
58 callerProvider,
59 callerModel,
60 targetProvider,
61 targetModel,
62 })),
63 ).toEqual([
64 {
65 callerProvider: "claudeAgent",
66 callerModel: undefined,
67 targetProvider: "opencode",
68 targetModel: undefined,
69 },
70 {
71 callerProvider: "claudeAgent",
72 callerModel: undefined,
73 targetProvider: "unknown",
74 targetModel: undefined,
75 },
76 {
77 callerProvider: "claudeAgent",
78 callerModel: undefined,
79 targetProvider: "codex",
80 targetModel: undefined,
81 },
82 ]);
83});
84
85it("drops input strings outside the schema's literals, since rejected calls are recorded too", () => {
86 expect(handoffSettings("delegate_task", { mode: "/home/me/secret" }, undefined)).toEqual({
87 targetChosen: false,
88 mode: "async",
89 });
90 expect(
91 handoffSettings("t3_thread_launch", { workspaceStrategy: { type: "/home/me/secret" } }, {}),
92 ).toEqual({ targetChosen: false, workspace: "root" });
93});
94
95it("records the binding the saved scheduled task resolved to, and none for failures", () => {
96 expect(handoffSettings("schedule_task", {}, { boundThreadId: null })).toEqual({
97 bindToCurrentThread: false,
98 });
99 expect(
100 handoffSettings(
101 "schedule_task",
102 { bindToCurrentThread: true },
103 { _tag: "OrchestratorMcpFailure", code: "invalid_request", message: "Different project." },
104 ),
105 ).toEqual({});
106});