@@ -27,6 +27,7 @@ import {
2727 RunId,
2828 ThreadId,
2929 type OrchestrationV2ProviderThread,
30+ type ProviderOptionDescriptor,
3031} from "@t3tools/contracts";
3132import { GrokSettings } from "@t3tools/provider-grok/settings";
3233import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -58,7 +59,11 @@ import type * as EffectAcpSchema from "effect-acp/compat";
5859import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
5960import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
6061import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
61- import { ACP_SESSION_MODE_OPTION_ID } from "@t3tools/provider-acp/server/sessionConfig";
62+ import {
63+ ACP_EMPTY_OPTION_VALUE,
64+ ACP_SESSION_MODE_OPTION_ID,
65+ acpProviderOptionDescriptors,
66+ } from "@t3tools/provider-acp/server/sessionConfig";
6267import {
6368 extractXAiAcpSubagentEndNotice,
6469 extractXAiAcpSubagentUpdate,
@@ -3644,6 +3649,105 @@ describe("AcpAdapterV2", () => {
36443649 }).pipe(Effect.provide(layerTest), Effect.scoped),
36453650 );
36463651
3652+ it.effect("keeps an agent's empty-valued default choice selectable", () =>
3653+ Effect.gen(function* () {
3654+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
3655+ const path = yield* Path.Path;
3656+ const selfInvocation = yield* resolveSelfInvocation();
3657+ const mockAgentPath = yield* path.fromFileUrl(
3658+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
3659+ );
3660+ const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
3661+ const instanceId = ProviderInstanceId.make("acp-test");
3662+ let agentDescriptor: ProviderOptionDescriptor | undefined;
3663+ const adapter = yield* makeAcpAdapterV2({
3664+ instanceId,
3665+ flavor: {
3666+ driver: ACP_TEST_DRIVER,
3667+ capabilities: AcpProviderCapabilitiesV2,
3668+ makeRuntime: makeMockRuntime({
3669+ childProcessSpawner,
3670+ mockAgentPath,
3671+ environment: { T3_ACP_EMIT_EMPTY_DEFAULT_AGENT_OPTION: "1" },
3672+ protocolEvents,
3673+ }),
3674+ onSessionConfigurationUpdate: (configOptions, modeState) =>
3675+ Effect.sync(() => {
3676+ agentDescriptor = acpProviderOptionDescriptors({ configOptions, modeState }).find(
3677+ (descriptor) => descriptor.id === "agent",
3678+ );
3679+ }),
3680+ },
3681+ selfInvocation,
3682+ });
3683+ const threadId = ThreadId.make("thread-acp-empty-default-agent");
3684+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
3685+ runtimeMode: "full-access",
3686+ interactionMode: "default",
3687+ cwd: process.cwd(),
3688+ });
3689+ const customAgentSelection = {
3690+ instanceId,
3691+ model: "default",
3692+ options: [{ id: "agent", value: "example" }],
3693+ } satisfies ModelSelection;
3694+ const runtime = yield* adapter.openSession({
3695+ threadId,
3696+ providerSessionId: ProviderSessionId.make("provider-session-acp-empty-default-agent"),
3697+ modelSelection: customAgentSelection,
3698+ runtimePolicy,
3699+ });
3700+ const providerThread = yield* runtime.ensureThread({
3701+ threadId,
3702+ modelSelection: customAgentSelection,
3703+ runtimePolicy,
3704+ });
3705+ assert.deepEqual(agentDescriptor, {
3706+ id: "agent",
3707+ label: "Agent",
3708+ type: "select",
3709+ options: [
3710+ { id: ACP_EMPTY_OPTION_VALUE, label: "Copilot" },
3711+ { id: "example", label: "example" },
3712+ ],
3713+ currentValue: "example",
3714+ });
3715+
3716+ yield* runtime.startTurn(
3717+ makeTurnInput({
3718+ threadId,
3719+ providerThread,
3720+ instanceId,
3721+ runtimePolicy,
3722+ modelSelection: {
3723+ instanceId,
3724+ model: "default",
3725+ options: [{ id: "agent", value: ACP_EMPTY_OPTION_VALUE }],
3726+ },
3727+ now: yield* DateTime.now,
3728+ }),
3729+ );
3730+ yield* runtime.events.pipe(
3731+ Stream.filter((event) => event.type === "turn.terminal"),
3732+ Stream.runHead,
3733+ );
3734+
3735+ assert.equal(
3736+ agentDescriptor?.type === "select" ? agentDescriptor.currentValue : undefined,
3737+ ACP_EMPTY_OPTION_VALUE,
3738+ );
3739+ const sentAgentValues = Array.from(yield* Queue.takeAll(protocolEvents))
3740+ .filter(
3741+ (event) =>
3742+ event.direction === "outgoing" &&
3743+ rawProtocolMethod(event) === "session/set_config_option" &&
3744+ rawProtocolRequestParam(event, "configId") === "agent",
3745+ )
3746+ .map((event) => rawProtocolRequestParam(event, "value"));
3747+ assert.deepEqual(sentAgentValues, ["example", ""]);
3748+ }).pipe(Effect.provide(layerTest), Effect.scoped),
3749+ );
3750+
36473751 it.live("terminalizes an empty successful foreground Bash tool when the turn completes", () =>
36483752 Effect.gen(function* () {
36493753 const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
0 commit comments