refactor(provider-acp): move the shared ACP adapter into its own package (#17354)
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
b5e4f1e0b0
commit
664bd5e524
70 files changed
+673
-553
No files matched your search
@@ -38,6 +38,7 @@
|
||||
"@napi-rs/keyring": "^1.3.0",
|
||||
"@noble/hashes": "catalog:",
|
||||
"@opencode-ai/sdk": "^1.3.15",
|
||||
"@t3tools/provider-acp": "workspace:*",
|
||||
"@t3tools/provider-core": "workspace:*",
|
||||
"@t3tools/provider-cursor": "workspace:*",
|
||||
"@t3tools/provider-muse": "workspace:*",
|
||||
|
||||
@@ -24,14 +24,15 @@ import * as Schema from "effect/Schema";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
import type * as EffectAcpProtocol from "effect-acp/protocol";
|
||||
|
||||
import * as ServerConfig from "../src/config.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { layerTestProviderHost } from "@t3tools/provider-testing/host";
|
||||
import {
|
||||
GROK_DEFAULT_INSTANCE_ID,
|
||||
GROK_PROVIDER,
|
||||
grokLaunchRuntimeMode,
|
||||
makeGrokAdapterV2,
|
||||
} from "../src/orchestration-v2/Adapters/GrokAdapterV2.ts";
|
||||
import { ACP_PROTOCOL } from "../src/orchestration-v2/Adapters/AcpAdapterV2.ts";
|
||||
import { ACP_PROTOCOL } from "@t3tools/provider-acp/server/adapter";
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
import type { ProviderAdapterV2SessionRuntime } from "@t3tools/provider-core/server/ProviderAdapter";
|
||||
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
|
||||
@@ -40,7 +41,6 @@ import { provideDeterministicTestRuntime } from "../src/orchestration-v2/testkit
|
||||
import { ORCHESTRATOR_REPLAY_FIXTURES } from "../src/orchestration-v2/testkit/fixtures/index.ts";
|
||||
import { materializeFixtureInput } from "../src/orchestration-v2/testkit/fixtures/shared.ts";
|
||||
import { runOrchestratorV2Scenario } from "../src/orchestration-v2/testkit/OrchestratorScenario.ts";
|
||||
import { makeReplayServerConfig } from "../src/orchestration-v2/testkit/ProviderReplayHarness.ts";
|
||||
import * as ProviderReplayHarness from "../src/orchestration-v2/testkit/ProviderReplayHarness.ts";
|
||||
import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace";
|
||||
import { makeGrokAcpRuntime } from "../src/provider/acp/GrokAcpSupport.ts";
|
||||
@@ -455,7 +455,7 @@ const recordScenario = Effect.fn("recordGrokScenario")(function* (fixtureName: s
|
||||
crypto: yield* Crypto.Crypto,
|
||||
fileSystem: yield* FileSystem.FileSystem,
|
||||
idAllocator: yield* IdAllocator.IdAllocatorV2,
|
||||
serverConfig: yield* ServerConfig.ServerConfig,
|
||||
host: yield* ProviderHost.ProviderHost,
|
||||
selfInvocation: yield* resolveSelfInvocation(),
|
||||
continuationRequests: yield* ProviderContinuationRequests.ProviderContinuationRequests,
|
||||
// Production's runtime factory, with the protocol logger teeing raw lines.
|
||||
@@ -496,10 +496,7 @@ const recordScenario = Effect.fn("recordGrokScenario")(function* (fixtureName: s
|
||||
).pipe(
|
||||
Layer.provide(
|
||||
Layer.mergeAll(
|
||||
Layer.effect(
|
||||
ServerConfig.ServerConfig,
|
||||
makeReplayServerConfig(`grok-record-${fixtureName}`),
|
||||
).pipe(Layer.provide(NodeServices.layer)),
|
||||
layerTestProviderHost().pipe(Layer.provide(NodeServices.layer)),
|
||||
NodeServices.layer,
|
||||
IdAllocator.layer,
|
||||
),
|
||||
|
||||
@@ -7,6 +7,7 @@ import * as Cause from "effect/Cause";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { discardResponseBody, responsePayloads } from "@t3tools/shared/mcpResponsePayloads";
|
||||
|
||||
/**
|
||||
* Stdio-to-HTTP bridge for T3's MCP endpoint.
|
||||
@@ -63,58 +64,6 @@ function protocolVersionOf(entry: unknown): string | null {
|
||||
return typeof version === "string" && version.length > 0 ? version : null;
|
||||
}
|
||||
|
||||
async function* sseDataLines(response: Response): AsyncGenerator<string> {
|
||||
if (response.body === null) return;
|
||||
const decoder = new TextDecoder();
|
||||
let buffered = "";
|
||||
for await (const chunk of response.body) {
|
||||
buffered += decoder.decode(chunk as Uint8Array, { stream: true });
|
||||
let separatorIndex = buffered.search(/\n\n|\r\n\r\n/u);
|
||||
while (separatorIndex !== -1) {
|
||||
const rawEvent = buffered.slice(0, separatorIndex);
|
||||
buffered = buffered.slice(separatorIndex).replace(/^(?:\r?\n){2}/u, "");
|
||||
const data = rawEvent
|
||||
.split(/\r?\n/u)
|
||||
.filter((line) => line.startsWith("data:"))
|
||||
.map((line) => line.slice("data:".length).trimStart())
|
||||
.join("\n");
|
||||
if (data.length > 0) yield data;
|
||||
separatorIndex = buffered.search(/\n\n|\r\n\r\n/u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const discardResponseBody = (response: Response): Effect.Effect<void> =>
|
||||
Effect.promise(() => response.body?.cancel().catch(() => undefined) ?? Promise.resolve());
|
||||
|
||||
/**
|
||||
* Every JSON-RPC payload carried by a response, in arrival order: nothing for
|
||||
* notification acknowledgements, each SSE `data:` event as it streams in, or
|
||||
* the single JSON body.
|
||||
*/
|
||||
export function responsePayloads(response: Response): Stream.Stream<unknown, AcpMcpBridgeError> {
|
||||
if (response.status === 202 || response.status === 204) {
|
||||
return Stream.unwrap(discardResponseBody(response).pipe(Effect.as(Stream.empty)));
|
||||
}
|
||||
const contentType = response.headers.get("content-type") ?? "";
|
||||
if (contentType.includes("text/event-stream")) {
|
||||
return Stream.fromAsyncIterable(sseDataLines(response), bridgeError).pipe(
|
||||
Stream.mapEffect((data) => Effect.try({ try: () => JSON.parse(data), catch: bridgeError })),
|
||||
);
|
||||
}
|
||||
return Stream.unwrap(
|
||||
Effect.tryPromise({ try: () => response.text(), catch: bridgeError }).pipe(
|
||||
Effect.flatMap((text) =>
|
||||
text.trim().length === 0
|
||||
? Effect.succeed(Stream.empty)
|
||||
: Effect.try({ try: () => JSON.parse(text) as unknown, catch: bridgeError }).pipe(
|
||||
Effect.map((payload) => Stream.fromIterable([payload])),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export interface AcpMcpToolCallOptions {
|
||||
readonly endpoint: string;
|
||||
readonly authorization: string;
|
||||
@@ -164,7 +113,7 @@ export function callAcpMcpTool(
|
||||
new AcpMcpBridgeError(`T3 Code MCP endpoint responded with HTTP ${response.status}.`),
|
||||
);
|
||||
}
|
||||
const payloads = yield* Stream.runCollect(responsePayloads(response));
|
||||
const payloads = yield* Stream.runCollect(responsePayloads(response, bridgeError));
|
||||
for (const payload of payloads) {
|
||||
protocolVersion = protocolVersionOf(payload) ?? protocolVersion;
|
||||
}
|
||||
@@ -271,7 +220,7 @@ export function runAcpMcpStdioBridge(options: AcpMcpStdioBridgeOptions): Effect.
|
||||
}
|
||||
return yield* discardResponseBody(response);
|
||||
}
|
||||
yield* Stream.runForEach(responsePayloads(response), handleServerPayload);
|
||||
yield* Stream.runForEach(responsePayloads(response, bridgeError), handleServerPayload);
|
||||
}).pipe(
|
||||
Effect.catchCause((cause) => {
|
||||
if (envelope.id === undefined) return Effect.void;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -13,9 +13,9 @@ import * as Stream from "effect/Stream";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import type { ProviderReplayGate } from "@t3tools/provider-testing/replayGate";
|
||||
import { ACP_PROTOCOL, type AcpAdapterV2RuntimeInput } from "./AcpAdapterV2.ts";
|
||||
import { ACP_PROTOCOL, type AcpAdapterV2RuntimeInput } from "@t3tools/provider-acp/server/adapter";
|
||||
|
||||
export const AcpReplayTranscript = Schema.Struct({
|
||||
provider: ProviderDriverKind,
|
||||
|
||||
@@ -14,15 +14,16 @@ import { HttpClient, HttpClientResponse } from "effect/http";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { layerTestProviderHost } from "@t3tools/provider-testing/host";
|
||||
import * as ServerSettings from "../../serverSettings.ts";
|
||||
import type {
|
||||
AcpRegistryAvailableCommands,
|
||||
AcpRegistryLiveConfiguration,
|
||||
} from "../../provider/acp/AcpRegistryProbe.ts";
|
||||
import * as AcpRegistrySupport from "../../provider/acp/AcpRegistrySupport.ts";
|
||||
import { ACP_SESSION_MODE_OPTION_ID } from "../../provider/acp/AcpSessionConfig.ts";
|
||||
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
|
||||
import { ACP_SESSION_MODE_OPTION_ID } from "@t3tools/provider-acp/server/sessionConfig";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
import {
|
||||
decodeAcpReplayTranscript,
|
||||
@@ -43,9 +44,7 @@ const decodeAcpRegistryAdapterSettings = Schema.decodeUnknownEffect(
|
||||
AcpRegistryAdapterV2Driver.configSchema,
|
||||
);
|
||||
|
||||
const layerServerConfig = ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-acp-registry-v2-adapter-",
|
||||
}).pipe(Layer.provide(NodeServices.layer));
|
||||
const layerHost = layerTestProviderHost().pipe(Layer.provide(NodeServices.layer));
|
||||
|
||||
const layerRegistry = Layer.succeed(
|
||||
HttpClient.HttpClient,
|
||||
@@ -86,7 +85,7 @@ const layerRegistry = Layer.succeed(
|
||||
const layerTest = Layer.mergeAll(
|
||||
NodeServices.layer,
|
||||
IdAllocator.layer,
|
||||
layerServerConfig,
|
||||
layerHost,
|
||||
layerRegistry,
|
||||
ServerSettings.layerTest(),
|
||||
);
|
||||
@@ -202,7 +201,7 @@ describe("AcpRegistryAdapterV2", () => {
|
||||
fileSystem,
|
||||
idAllocator: yield* IdAllocator.IdAllocatorV2,
|
||||
resolver: { resolve: () => Effect.die("the runtime is injected") },
|
||||
serverConfig: yield* ServerConfig.ServerConfig,
|
||||
host: yield* ProviderHost.ProviderHost,
|
||||
makeRuntime: makeAcpReplayRuntime({
|
||||
transcript,
|
||||
statusPath,
|
||||
@@ -272,7 +271,7 @@ describe("AcpRegistryAdapterV2", () => {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocator.IdAllocatorV2;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const mockAgentPath = yield* path.fromFileUrl(
|
||||
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
|
||||
);
|
||||
@@ -291,7 +290,7 @@ describe("AcpRegistryAdapterV2", () => {
|
||||
fileSystem,
|
||||
idAllocator,
|
||||
resolver: { resolve: () => Effect.die("the runtime is injected") },
|
||||
serverConfig,
|
||||
host,
|
||||
makeRuntime: (input) =>
|
||||
Effect.gen(function* () {
|
||||
clientCapabilities = input.clientCapabilities;
|
||||
@@ -348,13 +347,13 @@ describe("AcpRegistryAdapterV2", () => {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocator.IdAllocatorV2;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const mockAgentPath = yield* path.fromFileUrl(
|
||||
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
|
||||
);
|
||||
const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
|
||||
cacheDir: serverConfig.providerStatusCacheDir,
|
||||
toolsDir: serverConfig.baseDir + "/tools",
|
||||
cacheDir: host.paths.providerStatusCacheDir,
|
||||
toolsDir: host.paths.baseDir + "/tools",
|
||||
registryUrl,
|
||||
});
|
||||
const settings = yield* decodeAcpRegistryAdapterSettings({
|
||||
@@ -429,7 +428,7 @@ describe("AcpRegistryAdapterV2", () => {
|
||||
})),
|
||||
),
|
||||
},
|
||||
serverConfig,
|
||||
host,
|
||||
});
|
||||
const threadId = ThreadId.make("thread-acp-registry-fixture");
|
||||
const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({
|
||||
|
||||
@@ -9,12 +9,12 @@ import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { layerTestProviderHost } from "@t3tools/provider-testing/host";
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts";
|
||||
import type { ProviderReplayGate } from "@t3tools/provider-testing/replayGate";
|
||||
import type { OrchestratorV2ProviderReplayHarness } from "../testkit/ProviderReplayHarness.ts";
|
||||
import { makeReplayServerConfig } from "../testkit/ProviderReplayHarness.ts";
|
||||
import {
|
||||
type AcpReplayTranscript,
|
||||
AcpReplayTranscriptDecodeError,
|
||||
@@ -37,10 +37,7 @@ function layerAcpRegistryProviderAdapterRegistryReplay(
|
||||
transcript: AcpReplayTranscript,
|
||||
options: { readonly replayGate?: ProviderReplayGate } = {},
|
||||
) {
|
||||
const layerServerConfig = Layer.effect(
|
||||
ServerConfig.ServerConfig,
|
||||
makeReplayServerConfig(`acp-registry-${transcript.scenario}`).pipe(Effect.orDie),
|
||||
).pipe(Layer.provide(NodeServices.layer));
|
||||
const layerHost = layerTestProviderHost().pipe(Layer.provide(NodeServices.layer));
|
||||
|
||||
return ProviderAdapterRegistry.layerFromAdaptersEffect(
|
||||
Effect.gen(function* () {
|
||||
@@ -49,7 +46,7 @@ function layerAcpRegistryProviderAdapterRegistryReplay(
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
const idAllocator = yield* IdAllocator.IdAllocatorV2;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const replayGate = options.replayGate;
|
||||
const replayDir = yield* fileSystem
|
||||
.makeTempDirectory({
|
||||
@@ -71,7 +68,7 @@ function layerAcpRegistryProviderAdapterRegistryReplay(
|
||||
resolver: {
|
||||
resolve: () => Effect.die("ACP registry resolver must not run during replay"),
|
||||
},
|
||||
serverConfig,
|
||||
host,
|
||||
selfInvocation: yield* resolveSelfInvocation(),
|
||||
makeRuntime: makeAcpReplayRuntime({
|
||||
transcript,
|
||||
@@ -86,7 +83,7 @@ function layerAcpRegistryProviderAdapterRegistryReplay(
|
||||
return [adapter];
|
||||
}),
|
||||
).pipe(
|
||||
Layer.provide(Layer.mergeAll(layerServerConfig, NodeServices.layer, IdAllocator.layer)),
|
||||
Layer.provide(Layer.mergeAll(layerHost, NodeServices.layer, IdAllocator.layer)),
|
||||
// Held inbound lines must not outlive the scenario and wedge teardown.
|
||||
Layer.merge(
|
||||
Layer.effectDiscard(
|
||||
|
||||
@@ -21,7 +21,7 @@ import type * as Scope from "effect/Scope";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import {
|
||||
normalizeAcpRegistryCommands,
|
||||
normalizeAcpRegistryLiveConfiguration,
|
||||
@@ -29,8 +29,8 @@ import {
|
||||
} from "../../provider/acp/AcpRegistryProbe.ts";
|
||||
import * as AcpRegistrySupport from "../../provider/acp/AcpRegistrySupport.ts";
|
||||
import * as AcpRegistryRuntimeCoordinator from "../../provider/acp/AcpRegistryRuntimeCoordinator.ts";
|
||||
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
|
||||
import { makeAcpNativeLoggerFactory } from "../../provider/acp/AcpNativeLogging.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import { makeAcpNativeLoggerFactory } from "@t3tools/provider-acp/server/nativeLogging";
|
||||
import * as ProviderEventLoggers from "../../provider/ProviderEventLoggers.ts";
|
||||
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
@@ -46,7 +46,7 @@ import {
|
||||
type AcpAdapterV2ExtensionContext,
|
||||
type AcpAdapterV2Flavor,
|
||||
type AcpAdapterV2RuntimeInput,
|
||||
} from "./AcpAdapterV2.ts";
|
||||
} from "@t3tools/provider-acp/server/adapter";
|
||||
|
||||
export const ACP_REGISTRY_PROVIDER = ProviderDriverKind.make("acpRegistry");
|
||||
export const ACP_REGISTRY_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(ACP_REGISTRY_PROVIDER);
|
||||
@@ -65,7 +65,7 @@ export interface AcpRegistryAdapterV2Options {
|
||||
readonly idAllocator: IdAllocator.IdAllocatorV2["Service"];
|
||||
readonly resolver: Pick<AcpRegistrySupport.AcpRegistryCatalog["Service"], "resolve">;
|
||||
readonly runtimeCoordinator?: AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator["Service"];
|
||||
readonly serverConfig: ServerConfig.ServerConfig["Service"];
|
||||
readonly host: ProviderHost.ProviderHostShape;
|
||||
readonly nativeLogging?: Parameters<typeof makeAcpAdapterV2>[0]["nativeLogging"];
|
||||
readonly makeRuntime?: (
|
||||
input: AcpAdapterV2RuntimeInput,
|
||||
@@ -243,7 +243,7 @@ export function makeAcpRegistryAdapterV2(options: AcpRegistryAdapterV2Options) {
|
||||
crypto: options.crypto,
|
||||
fileSystem: options.fileSystem,
|
||||
idAllocator: options.idAllocator,
|
||||
serverConfig: options.serverConfig,
|
||||
host: options.host,
|
||||
selfInvocation: options.selfInvocation,
|
||||
// Per-agent exception (see the note above registerMistralVibeAcpExtensions):
|
||||
// Devin runs commands through client terminals and has no ask mode over
|
||||
@@ -269,7 +269,7 @@ export type AcpRegistryAdapterV2DriverEnv =
|
||||
| IdAllocator.IdAllocatorV2
|
||||
| Path.Path
|
||||
| ProviderEventLoggers.ProviderEventLoggers
|
||||
| ServerConfig.ServerConfig;
|
||||
| ProviderHost.ProviderHost;
|
||||
|
||||
export const AcpRegistryAdapterV2Driver: ProviderAdapterDriver<
|
||||
AcpRegistrySettings,
|
||||
@@ -287,7 +287,7 @@ export const AcpRegistryAdapterV2Driver: ProviderAdapterDriver<
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocator.IdAllocatorV2;
|
||||
const providerEventLoggers = yield* ProviderEventLoggers.ProviderEventLoggers;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const makeNativeLogger = yield* makeAcpNativeLoggerFactory();
|
||||
const resolver = yield* AcpRegistrySupport.AcpRegistryCatalog;
|
||||
const runtimeCoordinator = yield* Effect.serviceOption(
|
||||
@@ -305,7 +305,7 @@ export const AcpRegistryAdapterV2Driver: ProviderAdapterDriver<
|
||||
...(Option.isSome(runtimeCoordinator)
|
||||
? { runtimeCoordinator: runtimeCoordinator.value }
|
||||
: {}),
|
||||
serverConfig,
|
||||
host,
|
||||
selfInvocation,
|
||||
nativeLogging: (threadId) =>
|
||||
makeNativeLogger({
|
||||
|
||||
@@ -22,8 +22,9 @@ import * as Stream from "effect/Stream";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import type * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { layerTestProviderHost } from "@t3tools/provider-testing/host";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import { makeAntigravityAcpRuntime } from "../../provider/acp/AntigravityAcpSupport.ts";
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/ProviderAdapter";
|
||||
@@ -38,7 +39,7 @@ const flavor = makeAntigravityAcpAdapterFlavor({
|
||||
fileSystem: undefined as never,
|
||||
path: undefined as never,
|
||||
idAllocator: undefined as never,
|
||||
serverConfig: undefined as never,
|
||||
host: undefined as never,
|
||||
selfInvocation: undefined as never,
|
||||
makeRuntime: () => Effect.die("not spawned in this test"),
|
||||
withProcess: (_stop, task) => task,
|
||||
@@ -129,9 +130,7 @@ describe("AntigravityAdapterV2 flavor", () => {
|
||||
const layerSession = Layer.mergeAll(
|
||||
NodeServices.layer,
|
||||
IdAllocator.layer,
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-antigravity-v2-adapter-" }).pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
),
|
||||
layerTestProviderHost().pipe(Layer.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
describe("AntigravityAdapterV2 client file system", () => {
|
||||
@@ -140,7 +139,7 @@ describe("AntigravityAdapterV2 client file system", () => {
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const mockAgentPath = yield* path.fromFileUrl(
|
||||
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
|
||||
);
|
||||
@@ -157,7 +156,7 @@ describe("AntigravityAdapterV2 client file system", () => {
|
||||
fileSystem,
|
||||
path,
|
||||
idAllocator: yield* IdAllocator.IdAllocatorV2,
|
||||
serverConfig,
|
||||
host,
|
||||
makeRuntime: (input) =>
|
||||
makeAntigravityAcpRuntime({
|
||||
...input,
|
||||
@@ -193,7 +192,7 @@ describe("AntigravityAdapterV2 client file system", () => {
|
||||
});
|
||||
const outsideFile = path.join(outside, "secret.txt");
|
||||
yield* fileSystem.writeFileString(outsideFile, "secret");
|
||||
const attachment = path.join(serverConfig.attachmentsDir, "pasted.txt");
|
||||
const attachment = path.join(host.paths.attachmentsDir, "pasted.txt");
|
||||
yield* fileSystem.writeFileString(attachment, "pasted");
|
||||
|
||||
const threadId = ThreadId.make("thread-antigravity-containment");
|
||||
@@ -294,7 +293,7 @@ describe("AntigravityAdapterV2 workspace changes", () => {
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
const mockAgentPath = yield* path.fromFileUrl(
|
||||
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
|
||||
@@ -309,7 +308,7 @@ describe("AntigravityAdapterV2 workspace changes", () => {
|
||||
fileSystem,
|
||||
path,
|
||||
idAllocator: yield* IdAllocator.IdAllocatorV2,
|
||||
serverConfig,
|
||||
host,
|
||||
makeRuntime: (input) =>
|
||||
makeAntigravityAcpRuntime({
|
||||
...input,
|
||||
@@ -431,7 +430,7 @@ describe("AntigravityAdapterV2 client file system under restrictive policies", (
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
const mockAgentPath = yield* path.fromFileUrl(
|
||||
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
|
||||
@@ -459,7 +458,7 @@ describe("AntigravityAdapterV2 client file system under restrictive policies", (
|
||||
fileSystem,
|
||||
path,
|
||||
idAllocator: yield* IdAllocator.IdAllocatorV2,
|
||||
serverConfig,
|
||||
host,
|
||||
makeRuntime: (input) =>
|
||||
makeAntigravityAcpRuntime({
|
||||
...input,
|
||||
|
||||
@@ -14,9 +14,9 @@ import * as Exit from "effect/Exit";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import type { ServerConfig } from "../../config.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import type { AntigravityAuth } from "../../provider/AntigravityAuth.ts";
|
||||
import type * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import {
|
||||
antigravityPermissionMode,
|
||||
applyAntigravityAcpModelSelection,
|
||||
@@ -40,7 +40,7 @@ import {
|
||||
makeAcpAdapterV2,
|
||||
type AcpAdapterV2Flavor,
|
||||
type AcpAdapterV2RuntimeInput,
|
||||
} from "./AcpAdapterV2.ts";
|
||||
} from "@t3tools/provider-acp/server/adapter";
|
||||
|
||||
const ANTIGRAVITY_PROVIDER = ProviderDriverKind.make("antigravity");
|
||||
|
||||
@@ -68,7 +68,7 @@ export interface AntigravityAdapterV2Options {
|
||||
readonly fileSystem: FileSystem.FileSystem;
|
||||
readonly path: Path.Path;
|
||||
readonly idAllocator: IdAllocatorV2["Service"];
|
||||
readonly serverConfig: ServerConfig["Service"];
|
||||
readonly host: ProviderHost.ProviderHostShape;
|
||||
/** Spawns the official agent with the instance's Google profile. */
|
||||
readonly makeRuntime: (
|
||||
input: Omit<AntigravityAcpRuntimeInput, "spawn" | "childProcessSpawner">,
|
||||
@@ -125,9 +125,7 @@ export function makeAntigravityAcpAdapterFlavor(
|
||||
// the turn text references. It is a leaf directory of uploads. A session
|
||||
// without a workspace gets no workspace root rather than the server's cwd.
|
||||
const antigravityClientFileRoots = (cwd: string | null) =>
|
||||
cwd === null
|
||||
? [options.serverConfig.attachmentsDir]
|
||||
: [cwd, options.serverConfig.attachmentsDir];
|
||||
cwd === null ? [options.host.paths.attachmentsDir] : [cwd, options.host.paths.attachmentsDir];
|
||||
const makeRuntime = (input: AcpAdapterV2RuntimeInput) =>
|
||||
Effect.gen(function* () {
|
||||
// AcpAdapterV2 owns the runtime scope; sign-in and sign-out stop the
|
||||
@@ -139,7 +137,7 @@ export function makeAntigravityAcpAdapterFlavor(
|
||||
options.makeRuntime({
|
||||
...input,
|
||||
clientFileSystem: true,
|
||||
additionalDirectories: [options.serverConfig.attachmentsDir],
|
||||
additionalDirectories: [options.host.paths.attachmentsDir],
|
||||
}),
|
||||
)
|
||||
.pipe(Effect.provideService(Scope.Scope, scope));
|
||||
@@ -233,7 +231,7 @@ export function makeAntigravityAdapterV2(options: AntigravityAdapterV2Options) {
|
||||
crypto: options.crypto,
|
||||
fileSystem: options.fileSystem,
|
||||
idAllocator: options.idAllocator,
|
||||
serverConfig: options.serverConfig,
|
||||
host: options.host,
|
||||
selfInvocation: options.selfInvocation,
|
||||
...(options.nativeLogging === undefined ? {} : { nativeLogging: options.nativeLogging }),
|
||||
...(options.continuationRequests === undefined
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type * as AcpSchema from "effect-acp/compat";
|
||||
import type { AcpToolCallState } from "../../provider/acp/AcpRuntimeModel.ts";
|
||||
import type { AcpAdapterV2SubagentUpdate } from "./AcpAdapterV2.ts";
|
||||
import type { AcpToolCallState } from "@t3tools/provider-acp/server/runtimeModel";
|
||||
import type { AcpAdapterV2SubagentUpdate } from "@t3tools/provider-acp/server/adapter";
|
||||
|
||||
function record(value: unknown): Record<string, unknown> | undefined {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value)
|
||||
|
||||
@@ -22,7 +22,8 @@ import * as Schema from "effect/Schema";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { layerTestProviderHost } from "@t3tools/provider-testing/host";
|
||||
import * as ProjectStore from "../ProjectStore.ts";
|
||||
import { buildInitialGrokProviderSnapshot } from "../../provider/GrokProvider.ts";
|
||||
import type { ProviderInstance } from "@t3tools/provider-core/server/driver";
|
||||
@@ -30,13 +31,13 @@ import * as ProviderInstanceRegistry from "../../provider/ProviderInstanceRegist
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/ProviderAdapter";
|
||||
import * as RuntimePolicy from "../RuntimePolicy.ts";
|
||||
import { acpPermissionDisposition } from "../../provider/acp/AcpClientPolicy.ts";
|
||||
import { acpPermissionDisposition } from "@t3tools/provider-acp/server/clientPolicy";
|
||||
import {
|
||||
AcpProviderCapabilitiesV2,
|
||||
acpCompletedTurnShouldTerminalizeTool,
|
||||
acpSubagentStatusBlocksTurnSettlement,
|
||||
acpSupportsImagePrompts,
|
||||
} from "./AcpAdapterV2.ts";
|
||||
} from "@t3tools/provider-acp/server/adapter";
|
||||
import {
|
||||
makeGrokAcpAdapterFlavor,
|
||||
makeGrokAdapterV2,
|
||||
@@ -311,10 +312,8 @@ describe("Grok permission prompts", () => {
|
||||
});
|
||||
|
||||
describe("Grok launch permission mode", () => {
|
||||
const layerServerConfig = ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-grok-v2-launch-",
|
||||
}).pipe(Layer.provide(NodeServices.layer));
|
||||
const layerTest = Layer.mergeAll(NodeServices.layer, IdAllocator.layer, layerServerConfig);
|
||||
const layerHost = layerTestProviderHost().pipe(Layer.provide(NodeServices.layer));
|
||||
const layerTest = Layer.mergeAll(NodeServices.layer, IdAllocator.layer, layerHost);
|
||||
|
||||
// Opens a session through the adapter's own Grok runtime factory and returns
|
||||
// the argv it tried to launch. The spawn fails after recording, so no
|
||||
@@ -342,7 +341,7 @@ describe("Grok launch permission mode", () => {
|
||||
crypto: yield* Crypto.Crypto,
|
||||
fileSystem: yield* FileSystem.FileSystem,
|
||||
idAllocator: yield* IdAllocator.IdAllocatorV2,
|
||||
serverConfig: yield* ServerConfig.ServerConfig,
|
||||
host: yield* ProviderHost.ProviderHost,
|
||||
selfInvocation: yield* resolveSelfInvocation(),
|
||||
});
|
||||
yield* adapter
|
||||
|
||||
@@ -10,7 +10,8 @@ import { ChildProcessSpawner } from "effect/process";
|
||||
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
|
||||
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
|
||||
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { layerTestProviderHost } from "@t3tools/provider-testing/host";
|
||||
import {
|
||||
GROK_ACP_CANCEL_META,
|
||||
GROK_ACP_INITIALIZE_META,
|
||||
@@ -21,7 +22,6 @@ import * as ProviderContinuationRequests from "@t3tools/provider-core/server/con
|
||||
import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts";
|
||||
import type { ProviderReplayGate } from "@t3tools/provider-testing/replayGate";
|
||||
import type { OrchestratorV2ProviderReplayHarness } from "../testkit/ProviderReplayHarness.ts";
|
||||
import { makeReplayServerConfig } from "../testkit/ProviderReplayHarness.ts";
|
||||
import {
|
||||
type AcpReplayTranscript,
|
||||
AcpReplayTranscriptDecodeError,
|
||||
@@ -37,10 +37,7 @@ function layerGrokProviderAdapterRegistryReplay(
|
||||
transcript: AcpReplayTranscript,
|
||||
options: { readonly replayGate?: ProviderReplayGate } = {},
|
||||
) {
|
||||
const layerServerConfig = Layer.effect(
|
||||
ServerConfig.ServerConfig,
|
||||
makeReplayServerConfig(`grok-${transcript.scenario}`).pipe(Effect.orDie),
|
||||
).pipe(Layer.provide(NodeServices.layer));
|
||||
const layerHost = layerTestProviderHost().pipe(Layer.provide(NodeServices.layer));
|
||||
|
||||
return ProviderAdapterRegistry.layerFromAdaptersEffect(
|
||||
Effect.gen(function* () {
|
||||
@@ -50,7 +47,7 @@ function layerGrokProviderAdapterRegistryReplay(
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
const hostPlatform = yield* HostProcessPlatform;
|
||||
const idAllocator = yield* IdAllocator.IdAllocatorV2;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
// Same queue the continuation worker drains when the fixture runs it.
|
||||
const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
|
||||
const replayGate = options.replayGate;
|
||||
@@ -72,7 +69,7 @@ function layerGrokProviderAdapterRegistryReplay(
|
||||
crypto,
|
||||
fileSystem,
|
||||
idAllocator,
|
||||
serverConfig,
|
||||
host,
|
||||
selfInvocation: yield* resolveSelfInvocation(),
|
||||
// Same wrapping as makeGrokAcpRuntime: client type and Ctrl+C cancel
|
||||
// metadata and the x.ai prompt-completion race, so replay sends what
|
||||
@@ -102,7 +99,7 @@ function layerGrokProviderAdapterRegistryReplay(
|
||||
return [adapter];
|
||||
}),
|
||||
).pipe(
|
||||
Layer.provide(Layer.mergeAll(layerServerConfig, NodeServices.layer, IdAllocator.layer)),
|
||||
Layer.provide(Layer.mergeAll(layerHost, NodeServices.layer, IdAllocator.layer)),
|
||||
// Held inbound lines must not outlive the scenario and wedge teardown.
|
||||
Layer.merge(
|
||||
Layer.effectDiscard(
|
||||
|
||||
@@ -23,8 +23,8 @@ import type * as Scope from "effect/Scope";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import { makeAcpNativeLoggerFactory } from "../../provider/acp/AcpNativeLogging.ts";
|
||||
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { makeAcpNativeLoggerFactory } from "@t3tools/provider-acp/server/nativeLogging";
|
||||
import {
|
||||
applyGrokAcpModelSelection,
|
||||
currentGrokModelIdFromSessionSetup,
|
||||
@@ -54,8 +54,8 @@ import {
|
||||
XAiExitPlanModeRequest,
|
||||
} from "../../provider/acp/XAiAcpExtension.ts";
|
||||
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
|
||||
import { acpPermissionDisposition } from "../../provider/acp/AcpClientPolicy.ts";
|
||||
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
|
||||
import { acpPermissionDisposition } from "@t3tools/provider-acp/server/clientPolicy";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import * as ProviderEventLoggers from "../../provider/ProviderEventLoggers.ts";
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
|
||||
@@ -71,7 +71,7 @@ import {
|
||||
type AcpAdapterV2ExtensionContext,
|
||||
type AcpAdapterV2Flavor,
|
||||
type AcpAdapterV2RuntimeInput,
|
||||
} from "./AcpAdapterV2.ts";
|
||||
} from "@t3tools/provider-acp/server/adapter";
|
||||
|
||||
export const GROK_PROVIDER = ProviderDriverKind.make("grok");
|
||||
const GROK_DRIVER_KIND = GROK_PROVIDER;
|
||||
@@ -117,7 +117,7 @@ export interface GrokAdapterV2Options {
|
||||
readonly selfInvocation: SelfInvocation;
|
||||
readonly fileSystem: FileSystem.FileSystem;
|
||||
readonly idAllocator: IdAllocator.IdAllocatorV2["Service"];
|
||||
readonly serverConfig: ServerConfig.ServerConfig["Service"];
|
||||
readonly host: ProviderHost.ProviderHostShape;
|
||||
readonly nativeLogging?: Parameters<typeof makeAcpAdapterV2>[0]["nativeLogging"];
|
||||
readonly continuationRequests?: Parameters<typeof makeAcpAdapterV2>[0]["continuationRequests"];
|
||||
readonly testHooks?: Parameters<typeof makeAcpAdapterV2>[0]["testHooks"];
|
||||
@@ -337,7 +337,7 @@ export function makeGrokAdapterV2(options: GrokAdapterV2Options) {
|
||||
crypto: options.crypto,
|
||||
fileSystem: options.fileSystem,
|
||||
idAllocator: options.idAllocator,
|
||||
serverConfig: options.serverConfig,
|
||||
host: options.host,
|
||||
selfInvocation: options.selfInvocation,
|
||||
...(options.nativeLogging === undefined ? {} : { nativeLogging: options.nativeLogging }),
|
||||
...(options.continuationRequests === undefined
|
||||
@@ -354,7 +354,7 @@ export type GrokAdapterV2DriverEnv =
|
||||
| IdAllocator.IdAllocatorV2
|
||||
| Path.Path
|
||||
| ProviderEventLoggers.ProviderEventLoggers
|
||||
| ServerConfig.ServerConfig;
|
||||
| ProviderHost.ProviderHost;
|
||||
|
||||
export const GrokAdapterV2Driver: ProviderAdapterDriver<GrokSettings, GrokAdapterV2DriverEnv> = {
|
||||
driverKind: GROK_DRIVER_KIND,
|
||||
@@ -370,7 +370,7 @@ export const GrokAdapterV2Driver: ProviderAdapterDriver<GrokSettings, GrokAdapte
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocator.IdAllocatorV2;
|
||||
const providerEventLoggers = yield* ProviderEventLoggers.ProviderEventLoggers;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
|
||||
const makeNativeLogger = yield* makeAcpNativeLoggerFactory();
|
||||
return makeGrokAdapterV2({
|
||||
@@ -382,7 +382,7 @@ export const GrokAdapterV2Driver: ProviderAdapterDriver<GrokSettings, GrokAdapte
|
||||
crypto,
|
||||
fileSystem,
|
||||
idAllocator,
|
||||
serverConfig,
|
||||
host,
|
||||
selfInvocation,
|
||||
continuationRequests,
|
||||
nativeLogging: (threadId) =>
|
||||
@@ -417,7 +417,7 @@ const layer: Layer.Layer<
|
||||
| FileSystem.FileSystem
|
||||
| IdAllocator.IdAllocatorV2
|
||||
| ProviderEventLoggers.ProviderEventLoggers
|
||||
| ServerConfig.ServerConfig
|
||||
| ProviderHost.ProviderHost
|
||||
> = Layer.effect(
|
||||
ProviderAdapter.ProviderAdapterV2,
|
||||
Effect.gen(function* () {
|
||||
@@ -429,7 +429,7 @@ const layer: Layer.Layer<
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocator.IdAllocatorV2;
|
||||
const providerEventLoggers = yield* ProviderEventLoggers.ProviderEventLoggers;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost.ProviderHost;
|
||||
const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
|
||||
const makeNativeLogger = yield* makeAcpNativeLoggerFactory();
|
||||
return makeGrokAdapterV2({
|
||||
@@ -441,7 +441,7 @@ const layer: Layer.Layer<
|
||||
crypto,
|
||||
fileSystem,
|
||||
idAllocator,
|
||||
serverConfig,
|
||||
host,
|
||||
selfInvocation,
|
||||
continuationRequests,
|
||||
nativeLogging: (threadId) =>
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ProviderInstanceId,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import { AcpProviderCapabilitiesV2 } from "./Adapters/AcpAdapterV2.ts";
|
||||
import { AcpProviderCapabilitiesV2 } from "@t3tools/provider-acp/server/adapter";
|
||||
import { acpSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
|
||||
|
||||
const selection = (model: string, effort = "medium"): ModelSelection => ({
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
CodexProviderCapabilitiesV2,
|
||||
canReuseCodexContextUsage,
|
||||
} from "../Adapters/CodexAdapterV2.ts";
|
||||
import { AcpProviderCapabilitiesV2 } from "../Adapters/AcpAdapterV2.ts";
|
||||
import { AcpProviderCapabilitiesV2 } from "@t3tools/provider-acp/server/adapter";
|
||||
import { CursorProviderCapabilitiesV2 } from "@t3tools/provider-cursor/testing";
|
||||
import * as EventSink from "../EventSink.ts";
|
||||
import * as EventStore from "../EventStore.ts";
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
type AntigravityAuth,
|
||||
type AntigravityAuthRuntime,
|
||||
} from "./AntigravityAuth.ts";
|
||||
import type { AcpSessionRuntimeStartResult } from "./acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
|
||||
const instanceId = ProviderInstanceId.make("antigravity-auth-test");
|
||||
const owner = "t3-auth-session-owner";
|
||||
@@ -31,7 +31,7 @@ const initialized = {
|
||||
authMethods: [{ id: "oauth-personal", name: "Log in with Google" }],
|
||||
agentCapabilities: { auth: { logout: {} } },
|
||||
} satisfies AcpSchema.InitializeResponse;
|
||||
const started: AcpSessionRuntimeStartResult = {
|
||||
const started: AcpSessionRuntime.AcpSessionRuntimeStartResult = {
|
||||
sessionId: "native-session",
|
||||
initializeResult: initialized,
|
||||
sessionSetupResult: {
|
||||
|
||||
@@ -19,7 +19,7 @@ import * as Stream from "effect/Stream";
|
||||
import * as SubscriptionRef from "effect/SubscriptionRef";
|
||||
import * as AcpErrors from "effect-acp/errors";
|
||||
|
||||
import type { AcpSessionRuntime, AcpSessionRuntimeStartResult } from "./acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import {
|
||||
parseAntigravityAuthorizationUrl,
|
||||
type AntigravityAuthorizationUrl,
|
||||
@@ -66,19 +66,19 @@ export interface AntigravityAuth {
|
||||
}
|
||||
|
||||
export type AntigravityAuthRuntime = Pick<
|
||||
AcpSessionRuntime["Service"],
|
||||
AcpSessionRuntime.AcpSessionRuntime["Service"],
|
||||
"initialize" | "start" | "request"
|
||||
>;
|
||||
|
||||
export interface AntigravityAuthOptions<
|
||||
Runtime extends AntigravityAuthRuntime = AcpSessionRuntime["Service"],
|
||||
Runtime extends AntigravityAuthRuntime = AcpSessionRuntime.AcpSessionRuntime["Service"],
|
||||
> {
|
||||
readonly instanceId: ProviderInstanceId;
|
||||
readonly makeRuntime: (input: {
|
||||
readonly onAuthorizationUrl?: (url: string) => Effect.Effect<void, AcpErrors.AcpError>;
|
||||
}) => Effect.Effect<Runtime, AcpErrors.AcpError | ProviderSetupError, Scope.Scope>;
|
||||
readonly onAuthenticated: (
|
||||
result: AcpSessionRuntimeStartResult,
|
||||
result: AcpSessionRuntime.AcpSessionRuntimeStartResult,
|
||||
runtime: Runtime,
|
||||
) => Effect.Effect<void>;
|
||||
readonly onSignedOut: Effect.Effect<void>;
|
||||
|
||||
@@ -23,7 +23,7 @@ import * as ServerConfig from "../config.ts";
|
||||
import * as ServerSettings from "../serverSettings.ts";
|
||||
import * as ProviderHostLive from "./ProviderHostLive.ts";
|
||||
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
|
||||
import type { AcpSessionRuntimeStartResult } from "./acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import {
|
||||
buildAntigravityModelsFromSession,
|
||||
makeAntigravityProvider,
|
||||
@@ -98,7 +98,7 @@ const started = {
|
||||
initializeResult,
|
||||
sessionSetupResult,
|
||||
modelConfigId: "model",
|
||||
} satisfies AcpSessionRuntimeStartResult;
|
||||
} satisfies AcpSessionRuntime.AcpSessionRuntimeStartResult;
|
||||
|
||||
const commands = [
|
||||
{ name: "plan", description: "Create a plan", input: { type: "text", hint: "What to plan" } },
|
||||
|
||||
@@ -18,7 +18,7 @@ import * as SubscriptionRef from "effect/SubscriptionRef";
|
||||
import type * as EffectAcpErrors from "effect-acp/errors";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
|
||||
import type { AcpSessionRuntimeStartResult } from "./acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import { makeManagedServerProvider } from "@t3tools/provider-core/server/managedProvider";
|
||||
import {
|
||||
makeManualOnlyProviderMaintenanceCapabilities,
|
||||
@@ -38,7 +38,7 @@ const AUTH_UNCHECKED_MESSAGE =
|
||||
"Antigravity is installed. Google account access is not checked yet.";
|
||||
|
||||
type SessionSetupResult = Pick<
|
||||
AcpSessionRuntimeStartResult["sessionSetupResult"],
|
||||
AcpSessionRuntime.AcpSessionRuntimeStartResult["sessionSetupResult"],
|
||||
"configOptions" | "models"
|
||||
>;
|
||||
|
||||
@@ -256,7 +256,7 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
|
||||
});
|
||||
|
||||
const onSessionStarted = Effect.fn("AntigravityProvider.onSessionStarted")(function* (
|
||||
started: AcpSessionRuntimeStartResult,
|
||||
started: AcpSessionRuntime.AcpSessionRuntimeStartResult,
|
||||
cwd?: string,
|
||||
) {
|
||||
const before = yield* SubscriptionRef.get(metadata);
|
||||
|
||||
@@ -22,7 +22,6 @@ import * as Semaphore from "effect/Semaphore";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
|
||||
import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost";
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import {
|
||||
AcpRegistryAdapterV2Driver,
|
||||
type AcpRegistryAdapterV2DriverEnv,
|
||||
@@ -489,7 +488,6 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const hostEnvironment = yield* HostProcessEnvironment;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost;
|
||||
const continuationIdentity = defaultProviderContinuationIdentity({
|
||||
driverKind: DRIVER_KIND,
|
||||
@@ -528,7 +526,7 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
|
||||
};
|
||||
const confirmedAuthentication =
|
||||
yield* AcpRegistryAuthenticationState.makeAcpRegistryAuthenticationState({
|
||||
cacheDir: serverConfig.providerStatusCacheDir,
|
||||
cacheDir: host.paths.providerStatusCacheDir,
|
||||
instanceId,
|
||||
settings: effectiveConfig,
|
||||
environment,
|
||||
@@ -573,7 +571,7 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
|
||||
const enrichProvider = checkAcpRegistryProviderStatus(
|
||||
{
|
||||
...readinessInput,
|
||||
cwd: serverConfig.cwd,
|
||||
cwd: host.paths.cwd,
|
||||
},
|
||||
probeAcpRegistryConfiguration,
|
||||
).pipe(
|
||||
@@ -768,7 +766,7 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
|
||||
const controller = yield* AcpRegistryAuth.makeAcpRegistryAuth({
|
||||
instanceId,
|
||||
settings: effectiveConfig,
|
||||
cwd: serverConfig.cwd,
|
||||
cwd: host.paths.cwd,
|
||||
environment: processEnvironment,
|
||||
onChanged: (authenticated) =>
|
||||
confirmedAuthentication
|
||||
|
||||
@@ -19,7 +19,6 @@ import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
||||
import type { AcpError } from "effect-acp/errors";
|
||||
|
||||
import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost";
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import {
|
||||
isAntigravityTextGenerationAvailable,
|
||||
makeAntigravityTextGeneration,
|
||||
@@ -40,7 +39,7 @@ import {
|
||||
makeAntigravityAcpRuntime,
|
||||
type AntigravityAcpRuntimeInput,
|
||||
} from "../acp/AntigravityAcpSupport.ts";
|
||||
import type { AcpSessionRuntime, AcpSessionRuntimeStartResult } from "../acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import type { ServerProviderDraft } from "@t3tools/provider-core/server/snapshotProbe";
|
||||
import {
|
||||
removeAntigravityRuntimeTempDirs,
|
||||
@@ -49,7 +48,7 @@ import {
|
||||
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
|
||||
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
|
||||
import { makeAntigravityAdapterV2 } from "../../orchestration-v2/Adapters/AntigravityAdapterV2.ts";
|
||||
import { makeAcpNativeLoggerFactory } from "../acp/AcpNativeLogging.ts";
|
||||
import { makeAcpNativeLoggerFactory } from "@t3tools/provider-acp/server/nativeLogging";
|
||||
import { ProviderDriverError } from "../Errors.ts";
|
||||
import { makeAntigravityProvider } from "../AntigravityProvider.ts";
|
||||
import * as ProviderEventLoggers from "../ProviderEventLoggers.ts";
|
||||
@@ -76,8 +75,7 @@ export type AntigravityDriverEnv =
|
||||
| IdAllocator.IdAllocatorV2
|
||||
| ModelManifest.ModelManifest
|
||||
| Path.Path
|
||||
| ProviderEventLoggers.ProviderEventLoggers
|
||||
| ServerConfig.ServerConfig;
|
||||
| ProviderEventLoggers.ProviderEventLoggers;
|
||||
|
||||
/** Each instance owns its Google profile. Executable releases are shared by the environment. */
|
||||
export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityDriverEnv> = {
|
||||
@@ -91,7 +89,7 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const host = yield* ProviderHost;
|
||||
const selfInvocation = yield* resolveSelfInvocation();
|
||||
const installation = yield* AntigravityInstallation.AntigravityInstallation;
|
||||
const loggers = yield* ProviderEventLoggers.ProviderEventLoggers;
|
||||
@@ -110,7 +108,7 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
|
||||
const processEnvironment = mergeProviderInstanceEnvironment(environment);
|
||||
const userHome = resolveAntigravityUserHome(yield* HostProcessPlatform, processEnvironment);
|
||||
const directories = yield* resolveAntigravityInstanceDirectories(
|
||||
serverConfig.stateDir,
|
||||
host.paths.stateDir,
|
||||
instanceId,
|
||||
).pipe(
|
||||
Effect.provideService(Crypto.Crypto, crypto),
|
||||
@@ -158,7 +156,7 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
|
||||
const makeRuntime = Effect.fn("AntigravityDriver.makeRuntime")(function* (
|
||||
input: Omit<AntigravityAcpRuntimeInput, "spawn" | "childProcessSpawner">,
|
||||
): Effect.fn.Return<
|
||||
AcpSessionRuntime["Service"],
|
||||
AcpSessionRuntime.AcpSessionRuntime["Service"],
|
||||
AcpError | ProviderSetupError,
|
||||
Scope.Scope
|
||||
> {
|
||||
@@ -303,8 +301,8 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
|
||||
});
|
||||
|
||||
const publishCatalog = (
|
||||
started: AcpSessionRuntimeStartResult,
|
||||
runtime: Pick<AcpSessionRuntime["Service"], "getEvents" | "drainEvents">,
|
||||
started: AcpSessionRuntime.AcpSessionRuntimeStartResult,
|
||||
runtime: Pick<AcpSessionRuntime.AcpSessionRuntime["Service"], "getEvents" | "drainEvents">,
|
||||
): Effect.Effect<void> =>
|
||||
Effect.gen(function* () {
|
||||
yield* provider.onSessionStarted(started);
|
||||
@@ -405,7 +403,7 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
|
||||
fileSystem,
|
||||
path,
|
||||
idAllocator,
|
||||
serverConfig,
|
||||
host,
|
||||
selfInvocation,
|
||||
makeRuntime,
|
||||
withProcess: authFlow.withProcess,
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
makeGrokAcpRuntime,
|
||||
resolveGrokAcpBaseModelId,
|
||||
} from "./acp/GrokAcpSupport.ts";
|
||||
import { sessionModelStateFromInitialize } from "./acp/AcpRuntimeModel.ts";
|
||||
import { sessionModelStateFromInitialize } from "@t3tools/provider-acp/server/runtimeModel";
|
||||
import { discoverGrokSkills } from "./Drivers/GrokSkills.ts";
|
||||
|
||||
const GROK_PRESENTATION = {
|
||||
|
||||
@@ -22,7 +22,7 @@ import * as SubscriptionRef from "effect/SubscriptionRef";
|
||||
|
||||
import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts";
|
||||
import * as ProviderSessionManager from "../orchestration-v2/ProviderSessionManager.ts";
|
||||
import { AcpProviderCapabilitiesV2 } from "../orchestration-v2/Adapters/AcpAdapterV2.ts";
|
||||
import { AcpProviderCapabilitiesV2 } from "@t3tools/provider-acp/server/adapter";
|
||||
import type { ProviderInstance } from "@t3tools/provider-core/server/driver";
|
||||
import * as ProviderAuthService from "./ProviderAuthService.ts";
|
||||
import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
|
||||
|
||||
@@ -31,6 +31,7 @@ export const layer = Layer.effect(
|
||||
baseDir: config.baseDir,
|
||||
stateDir: config.stateDir,
|
||||
providerStatusCacheDir: config.providerStatusCacheDir,
|
||||
attachmentsDir: config.attachmentsDir,
|
||||
},
|
||||
settings: {
|
||||
get: serverSettings.getSettings,
|
||||
|
||||
@@ -17,7 +17,7 @@ import * as TestClock from "effect/testing/TestClock";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { describe, expect } from "vite-plus/test";
|
||||
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import type * as EffectAcpProtocol from "effect-acp/protocol";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { AcpRequestError } from "effect-acp/errors";
|
||||
import * as PtyAdapter from "../../terminal/PtyAdapter.ts";
|
||||
import { makeAcpRegistryAuth } from "./AcpRegistryAuth.ts";
|
||||
import * as AcpRegistrySupport from "./AcpRegistrySupport.ts";
|
||||
import type { AcpSessionRuntime } from "./AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
|
||||
const decodeSettings = Schema.decodeSync(AcpRegistrySettings);
|
||||
const instanceId = ProviderInstanceId.make("acp-auth-test");
|
||||
@@ -101,7 +101,7 @@ const makeHarness = (
|
||||
authMethods: [{ ...method, name: `${method.name} ${version}` }],
|
||||
};
|
||||
let elicitation:
|
||||
| Parameters<AcpSessionRuntime["Service"]["handleElicitation"]>[0]
|
||||
| Parameters<AcpSessionRuntime.AcpSessionRuntime["Service"]["handleElicitation"]>[0]
|
||||
| undefined;
|
||||
return {
|
||||
initialize: () => Effect.succeed(initialized),
|
||||
|
||||
@@ -20,7 +20,7 @@ import * as ProviderAuthFlow from "../ProviderAuthFlow.ts";
|
||||
import { normalizeAcpRegistryAuthMethods, normalizeAcpRegistryWebUrl } from "./AcpRegistryProbe.ts";
|
||||
import * as AcpRegistrySupport from "./AcpRegistrySupport.ts";
|
||||
import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts";
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
|
||||
type Runtime = Pick<
|
||||
AcpSessionRuntime.AcpSessionRuntime["Service"],
|
||||
|
||||
@@ -12,7 +12,7 @@ import * as Schema from "effect/Schema";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import type { AcpSessionRuntimeStartResult } from "./AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import {
|
||||
acpRegistryProbeFailure,
|
||||
acpRegistryProbeResult,
|
||||
@@ -68,7 +68,7 @@ describe("ACP Registry probe", () => {
|
||||
],
|
||||
},
|
||||
modelConfigId: "model",
|
||||
} satisfies AcpSessionRuntimeStartResult);
|
||||
} satisfies AcpSessionRuntime.AcpSessionRuntimeStartResult);
|
||||
|
||||
expect(result).toEqual({
|
||||
instanceId,
|
||||
@@ -186,7 +186,7 @@ describe("ACP Registry probe", () => {
|
||||
],
|
||||
},
|
||||
modelConfigId: "model",
|
||||
} satisfies AcpSessionRuntimeStartResult);
|
||||
} satisfies AcpSessionRuntime.AcpSessionRuntimeStartResult);
|
||||
|
||||
expect(result.models).toEqual([
|
||||
{ id: "sonnet", name: "Sonnet", description: "Balanced" },
|
||||
@@ -216,7 +216,7 @@ describe("ACP Registry probe", () => {
|
||||
],
|
||||
},
|
||||
modelConfigId: "model",
|
||||
} satisfies AcpSessionRuntimeStartResult);
|
||||
} satisfies AcpSessionRuntime.AcpSessionRuntimeStartResult);
|
||||
|
||||
expect(result.models).toEqual([{ id: "valid", name: "Valid", description: null }]);
|
||||
expect(result.currentModelId).toBeNull();
|
||||
@@ -270,7 +270,7 @@ describe("ACP Registry probe", () => {
|
||||
],
|
||||
},
|
||||
modelConfigId: "model",
|
||||
} satisfies AcpSessionRuntimeStartResult);
|
||||
} satisfies AcpSessionRuntime.AcpSessionRuntimeStartResult);
|
||||
|
||||
expect(result.models).toEqual([
|
||||
{ id: codexModel, name: "GPT-6.1 Sol", description: null },
|
||||
@@ -312,7 +312,7 @@ describe("ACP Registry probe", () => {
|
||||
],
|
||||
},
|
||||
modelConfigId: "model",
|
||||
} satisfies AcpSessionRuntimeStartResult);
|
||||
} satisfies AcpSessionRuntime.AcpSessionRuntimeStartResult);
|
||||
|
||||
expect(result.models).toHaveLength(256);
|
||||
expect(result.currentModelId).toBeNull();
|
||||
|
||||
@@ -25,10 +25,10 @@ import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
|
||||
import * as PtyAdapter from "../../terminal/PtyAdapter.ts";
|
||||
import * as AcpRegistrySupport from "./AcpRegistrySupport.ts";
|
||||
import { parseSessionModeState } from "./AcpRuntimeModel.ts";
|
||||
import { acpProviderOptionDescriptors } from "./AcpSessionConfig.ts";
|
||||
import { parseSessionModeState } from "@t3tools/provider-acp/server/runtimeModel";
|
||||
import { acpProviderOptionDescriptors } from "@t3tools/provider-acp/server/sessionConfig";
|
||||
import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts";
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
|
||||
const MAX_AUTH_METHODS = 32;
|
||||
const MAX_MODELS = 256;
|
||||
|
||||
@@ -43,7 +43,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
||||
|
||||
import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";
|
||||
import * as ServerSettings from "../../serverSettings.ts";
|
||||
import type { AcpSpawnInput } from "./AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
|
||||
const ACP_REGISTRY_URL = "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json";
|
||||
|
||||
@@ -444,7 +444,7 @@ export function resolveAcpRegistryDistribution(input: {
|
||||
export interface ResolvedAcpRegistryAgent {
|
||||
readonly agent?: AcpRegistryAgent;
|
||||
readonly distribution: AcpRegistryDistributionKind | "local";
|
||||
readonly spawn: AcpSpawnInput;
|
||||
readonly spawn: AcpSessionRuntime.AcpSpawnInput;
|
||||
}
|
||||
|
||||
export type AcpRegistryInspection =
|
||||
|
||||
@@ -11,29 +11,7 @@ import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Scope from "effect/Scope";
|
||||
|
||||
import {
|
||||
capturePosixOwnershipLedger,
|
||||
isSafeCgroupPath,
|
||||
makeLinuxCgroupController,
|
||||
makePosixProcessTreeController,
|
||||
observePosixOwnershipLedger,
|
||||
observePosixOwnershipLedgerContinuously,
|
||||
parseCgroup2Mount,
|
||||
parseCgroup2Mounts,
|
||||
parseUnifiedCgroupPath,
|
||||
posixProcessIsZombie,
|
||||
resolveLinuxCgroupTargetCommand,
|
||||
signalLinuxCgroupRootTerm,
|
||||
sweepStaleLinuxCgroupSiblings,
|
||||
terminateLinuxCgroupLease,
|
||||
terminatePosixOwnedProcessTree,
|
||||
wrapCommandForLinuxCgroup,
|
||||
type AcpOwnedPosixProcess,
|
||||
type AcpLinuxCgroupLease,
|
||||
type AcpPosixOwnershipRoot,
|
||||
type AcpPosixProcessIdentity,
|
||||
type AcpPosixProcessTreeController,
|
||||
} from "./AcpSessionRuntime.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
|
||||
const threadSpawnHelperSource = NodeURL.fileURLToPath(
|
||||
new URL("../../../scripts/acp-thread-spawn-helper.c", import.meta.url),
|
||||
@@ -46,7 +24,7 @@ const identity = (
|
||||
sid: number,
|
||||
startTime = String(pid),
|
||||
state = "S",
|
||||
): AcpPosixProcessIdentity => ({
|
||||
): AcpSessionRuntime.AcpPosixProcessIdentity => ({
|
||||
executable: `/proc/${pid}/exe`,
|
||||
pgid,
|
||||
pid,
|
||||
@@ -57,16 +35,16 @@ const identity = (
|
||||
});
|
||||
|
||||
function makeController(input: {
|
||||
readonly processes: ReadonlyArray<AcpPosixProcessIdentity>;
|
||||
readonly processes: ReadonlyArray<AcpSessionRuntime.AcpPosixProcessIdentity>;
|
||||
readonly onProcess?: (
|
||||
processes: Map<number, AcpPosixProcessIdentity>,
|
||||
processes: Map<number, AcpSessionRuntime.AcpPosixProcessIdentity>,
|
||||
pid: number,
|
||||
signal: NodeJS.Signals,
|
||||
) => void;
|
||||
}) {
|
||||
const processes = new Map(input.processes.map((process) => [process.pid, process]));
|
||||
const signals: Array<string> = [];
|
||||
const controller: AcpPosixProcessTreeController = {
|
||||
const controller: AcpSessionRuntime.AcpPosixProcessTreeController = {
|
||||
childPidsOf: (pid) =>
|
||||
[...processes.values()]
|
||||
.filter((process) => process.ppid === pid)
|
||||
@@ -96,19 +74,23 @@ function processExists(pid: number): boolean {
|
||||
|
||||
describe("terminatePosixOwnedProcessTree", () => {
|
||||
it("parses unified cgroup paths and escaped cgroup2 mountinfo", () => {
|
||||
expect(parseUnifiedCgroupPath("0::/user.slice/app.scope\n")).toBe("/user.slice/app.scope");
|
||||
expect(parseUnifiedCgroupPath("0::/one\n0::/two\n")).toBeUndefined();
|
||||
expect(isSafeCgroupPath("/user.slice/app.scope")).toBe(true);
|
||||
expect(isSafeCgroupPath("/user.slice/../escape")).toBe(false);
|
||||
expect(isSafeCgroupPath("/user.slice/app.scope (deleted)")).toBe(false);
|
||||
expect(AcpSessionRuntime.parseUnifiedCgroupPath("0::/user.slice/app.scope\n")).toBe(
|
||||
"/user.slice/app.scope",
|
||||
);
|
||||
expect(AcpSessionRuntime.parseUnifiedCgroupPath("0::/one\n0::/two\n")).toBeUndefined();
|
||||
expect(AcpSessionRuntime.isSafeCgroupPath("/user.slice/app.scope")).toBe(true);
|
||||
expect(AcpSessionRuntime.isSafeCgroupPath("/user.slice/../escape")).toBe(false);
|
||||
expect(AcpSessionRuntime.isSafeCgroupPath("/user.slice/app.scope (deleted)")).toBe(false);
|
||||
expect(
|
||||
parseCgroup2Mount(
|
||||
AcpSessionRuntime.parseCgroup2Mount(
|
||||
"42 31 0:37 /user.slice /sys/fs/cgroup/user\\040mount rw - cgroup2 cgroup2 rw\n",
|
||||
),
|
||||
).toEqual({ mountPoint: "/sys/fs/cgroup/user mount", root: "/user.slice" });
|
||||
expect(parseCgroup2Mount("42 31 0:37 / /sys/fs/cgroup rw - tmpfs tmpfs rw\n")).toBeUndefined();
|
||||
expect(
|
||||
parseCgroup2Mounts(
|
||||
AcpSessionRuntime.parseCgroup2Mount("42 31 0:37 / /sys/fs/cgroup rw - tmpfs tmpfs rw\n"),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
AcpSessionRuntime.parseCgroup2Mounts(
|
||||
"41 31 0:36 /other /sys/fs/cgroup/other rw - cgroup2 cgroup2 rw\n" +
|
||||
"42 31 0:37 /user.slice /sys/fs/cgroup/user rw - cgroup2 cgroup2 rw\n",
|
||||
),
|
||||
@@ -140,7 +122,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
const unrelated = writeSibling("other-lease", "0");
|
||||
const isProcessAlive = (pid: number) => pid === process.pid || pid === liveForeignPid;
|
||||
try {
|
||||
sweepStaleLinuxCgroupSiblings(parent, {
|
||||
AcpSessionRuntime.sweepStaleLinuxCgroupSiblings(parent, {
|
||||
isProcessAlive,
|
||||
readPopulated: (path) => populatedByPath.get(path),
|
||||
remove: (path) => {
|
||||
@@ -155,7 +137,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
expect(NodeFS.existsSync(unrelated)).toBe(true);
|
||||
// Missing populated state must not remove a sibling.
|
||||
writeSibling(`t3-acp-${deadPid}-eeee`, null);
|
||||
sweepStaleLinuxCgroupSiblings(parent, {
|
||||
AcpSessionRuntime.sweepStaleLinuxCgroupSiblings(parent, {
|
||||
isProcessAlive,
|
||||
readPopulated: (path) => populatedByPath.get(path),
|
||||
remove: (path) => {
|
||||
@@ -174,7 +156,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
it.live("preserves exact argv and strips wrapper-only environment before exec", () =>
|
||||
Effect.gen(function* () {
|
||||
if ((yield* HostProcessPlatform) !== "linux") return;
|
||||
const lease = makeLinuxCgroupController().create();
|
||||
const lease = AcpSessionRuntime.makeLinuxCgroupController().create();
|
||||
if (lease === undefined) return;
|
||||
const scratchRoot = NodePath.join(process.cwd(), "tmp");
|
||||
NodeFS.mkdirSync(scratchRoot, { recursive: true });
|
||||
@@ -192,17 +174,27 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
NodeFS.symlinkSync(process.execPath, bareGrok);
|
||||
NodeFS.symlinkSync(process.execPath, NodePath.join(relativeBin, "grok"));
|
||||
NodeFS.symlinkSync(process.execPath, NodePath.join(validBin, "grok"));
|
||||
expect(resolveLinuxCgroupTargetCommand("grok", scratch, { PATH: scratch })).toBe(bareGrok);
|
||||
expect(resolveLinuxCgroupTargetCommand("grok", scratch, { PATH: "" })).toBe(bareGrok);
|
||||
expect(
|
||||
AcpSessionRuntime.resolveLinuxCgroupTargetCommand("grok", scratch, { PATH: scratch }),
|
||||
).toBe(bareGrok);
|
||||
expect(AcpSessionRuntime.resolveLinuxCgroupTargetCommand("grok", scratch, { PATH: "" })).toBe(
|
||||
bareGrok,
|
||||
);
|
||||
// Undefined PATH uses Node's default search path (/usr/bin:/bin), not cwd alone
|
||||
// (bareGrok lives only in cwd / PATH=scratch).
|
||||
expect(resolveLinuxCgroupTargetCommand("grok", scratch, { PATH: undefined })).toBeUndefined();
|
||||
expect(resolveLinuxCgroupTargetCommand("node", scratch, { PATH: undefined })).toBeDefined();
|
||||
expect(resolveLinuxCgroupTargetCommand("grok", scratch, { PATH: "relative-bin" })).toBe(
|
||||
NodePath.join(relativeBin, "grok"),
|
||||
);
|
||||
expect(
|
||||
resolveLinuxCgroupTargetCommand("grok", scratch, {
|
||||
AcpSessionRuntime.resolveLinuxCgroupTargetCommand("grok", scratch, { PATH: undefined }),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
AcpSessionRuntime.resolveLinuxCgroupTargetCommand("node", scratch, { PATH: undefined }),
|
||||
).toBeDefined();
|
||||
expect(
|
||||
AcpSessionRuntime.resolveLinuxCgroupTargetCommand("grok", scratch, {
|
||||
PATH: "relative-bin",
|
||||
}),
|
||||
).toBe(NodePath.join(relativeBin, "grok"));
|
||||
expect(
|
||||
AcpSessionRuntime.resolveLinuxCgroupTargetCommand("grok", scratch, {
|
||||
PATH: `directory-bin${NodePath.delimiter}valid-bin`,
|
||||
}),
|
||||
).toBe(NodePath.join(validBin, "grok"));
|
||||
@@ -214,7 +206,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
" wrapper: process.env.T3_ACP_CGROUP_WRAPPER,",
|
||||
"}));",
|
||||
].join("\n");
|
||||
const wrapped = wrapCommandForLinuxCgroup(lease, linkedNode, [
|
||||
const wrapped = AcpSessionRuntime.wrapCommandForLinuxCgroup(lease, linkedNode, [
|
||||
"-e",
|
||||
target,
|
||||
outputPath,
|
||||
@@ -236,7 +228,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
'{"args":["space value","single\'quote","double\\"quote"]}',
|
||||
);
|
||||
} finally {
|
||||
yield* terminateLinuxCgroupLease(lease).pipe(Effect.ignore);
|
||||
yield* AcpSessionRuntime.terminateLinuxCgroupLease(lease).pipe(Effect.ignore);
|
||||
NodeFS.rmSync(scratch, { recursive: true, force: true });
|
||||
}
|
||||
}),
|
||||
@@ -251,9 +243,11 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
const outputPath = NodePath.join(scratch, "argv output");
|
||||
NodeFS.mkdirSync(leasePath);
|
||||
NodeFS.writeFileSync(NodePath.join(leasePath, "cgroup.procs"), "");
|
||||
const relativePath = parseUnifiedCgroupPath(NodeFS.readFileSync("/proc/self/cgroup", "utf8"));
|
||||
const relativePath = AcpSessionRuntime.parseUnifiedCgroupPath(
|
||||
NodeFS.readFileSync("/proc/self/cgroup", "utf8"),
|
||||
);
|
||||
expect(relativePath).toBeDefined();
|
||||
const lease: AcpLinuxCgroupLease = {
|
||||
const lease: AcpSessionRuntime.AcpLinuxCgroupLease = {
|
||||
contains: () => false,
|
||||
exists: () => true,
|
||||
path: leasePath,
|
||||
@@ -264,7 +258,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
};
|
||||
const packagedExecPath = vi.spyOn(process, "execPath", "get").mockReturnValue("/bin/sh");
|
||||
try {
|
||||
const wrapped = wrapCommandForLinuxCgroup(lease, "/bin/sh", [
|
||||
const wrapped = AcpSessionRuntime.wrapCommandForLinuxCgroup(lease, "/bin/sh", [
|
||||
"-c",
|
||||
'printf "%s\\n" "$0" "$1" "$2" "$3" "${ELECTRON_RUN_AS_NODE-}" "${T3_ACP_CGROUP_WRAPPER-}" > "$4"',
|
||||
"packaged-target",
|
||||
@@ -289,7 +283,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
/^\d+\n$/,
|
||||
);
|
||||
|
||||
const mismatch = wrapCommandForLinuxCgroup(
|
||||
const mismatch = AcpSessionRuntime.wrapCommandForLinuxCgroup(
|
||||
{ ...lease, relativePath: "/not-the-current-cgroup" },
|
||||
"/bin/sh",
|
||||
["-c", 'printf executed > "$0"', outputPath],
|
||||
@@ -301,7 +295,11 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
expect(mismatchResult.status, mismatchResult.stderr).toBe(126);
|
||||
expect(NodeFS.existsSync(outputPath)).toBe(false);
|
||||
|
||||
const missingTarget = wrapCommandForLinuxCgroup(lease, "/nonexistent-t3-probe", []);
|
||||
const missingTarget = AcpSessionRuntime.wrapCommandForLinuxCgroup(
|
||||
lease,
|
||||
"/nonexistent-t3-probe",
|
||||
[],
|
||||
);
|
||||
const missingTargetResult = NodeChildProcess.spawnSync(
|
||||
missingTarget.command,
|
||||
missingTarget.args,
|
||||
@@ -319,12 +317,12 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
it.live("kills a post-TERM detached double fork without touching an unrelated sentinel", () =>
|
||||
Effect.gen(function* () {
|
||||
if ((yield* HostProcessPlatform) !== "linux") return;
|
||||
const controller = makeLinuxCgroupController();
|
||||
const controller = AcpSessionRuntime.makeLinuxCgroupController();
|
||||
const lease = controller.create();
|
||||
if (lease === undefined) return;
|
||||
expect(parseUnifiedCgroupPath(NodeFS.readFileSync("/proc/self/cgroup", "utf8"))).not.toBe(
|
||||
lease.relativePath,
|
||||
);
|
||||
expect(
|
||||
AcpSessionRuntime.parseUnifiedCgroupPath(NodeFS.readFileSync("/proc/self/cgroup", "utf8")),
|
||||
).not.toBe(lease.relativePath);
|
||||
const scratchRoot = NodePath.join(process.cwd(), "tmp");
|
||||
NodeFS.mkdirSync(scratchRoot, { recursive: true });
|
||||
const scratch = NodeFS.mkdtempSync(NodePath.join(scratchRoot, "acp-cgroup-kill-"));
|
||||
@@ -349,7 +347,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
"});",
|
||||
"setInterval(() => {}, 1000);",
|
||||
].join("\n");
|
||||
const wrapped = wrapCommandForLinuxCgroup(lease, process.execPath, [
|
||||
const wrapped = AcpSessionRuntime.wrapCommandForLinuxCgroup(lease, process.execPath, [
|
||||
"-e",
|
||||
providerProgram,
|
||||
readyPath,
|
||||
@@ -386,7 +384,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
}
|
||||
}).pipe(Effect.timeout("2 seconds"));
|
||||
expect(processExists(detachedChildPid)).toBe(true);
|
||||
yield* terminateLinuxCgroupLease(lease);
|
||||
yield* AcpSessionRuntime.terminateLinuxCgroupLease(lease);
|
||||
expect(processExists(sentinel.pid!)).toBe(true);
|
||||
yield* Effect.gen(function* () {
|
||||
while (processExists(detachedChildPid!)) yield* Effect.sleep("10 millis");
|
||||
@@ -397,11 +395,11 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
expect(replacement?.path).not.toBe(lease.path);
|
||||
if (replacement !== undefined) {
|
||||
NodeFS.mkdirSync(NodePath.join(replacement.path, "nested"));
|
||||
yield* terminateLinuxCgroupLease(replacement);
|
||||
yield* AcpSessionRuntime.terminateLinuxCgroupLease(replacement);
|
||||
expect(NodeFS.existsSync(replacement.path)).toBe(false);
|
||||
}
|
||||
} finally {
|
||||
yield* terminateLinuxCgroupLease(lease).pipe(Effect.ignore);
|
||||
yield* AcpSessionRuntime.terminateLinuxCgroupLease(lease).pipe(Effect.ignore);
|
||||
try {
|
||||
process.kill(-provider.pid!, "SIGKILL");
|
||||
} catch {
|
||||
@@ -430,7 +428,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
let killCalls = 0;
|
||||
let populated = false;
|
||||
let removeCalls = 0;
|
||||
const lease: AcpLinuxCgroupLease = {
|
||||
const lease: AcpSessionRuntime.AcpLinuxCgroupLease = {
|
||||
contains: () => false,
|
||||
exists: () => exists,
|
||||
path: "/test/t3-acp-repopulation",
|
||||
@@ -457,11 +455,11 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
},
|
||||
};
|
||||
|
||||
yield* terminateLinuxCgroupLease(lease);
|
||||
yield* AcpSessionRuntime.terminateLinuxCgroupLease(lease);
|
||||
expect(killCalls).toBeGreaterThanOrEqual(3);
|
||||
expect(removeCalls).toBe(3);
|
||||
expect(exists).toBe(false);
|
||||
yield* terminateLinuxCgroupLease(lease);
|
||||
yield* AcpSessionRuntime.terminateLinuxCgroupLease(lease);
|
||||
expect(removeCalls).toBe(3);
|
||||
}),
|
||||
);
|
||||
@@ -471,7 +469,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
const removeError = Object.assign(new Error("cgroup remains busy"), {
|
||||
code: "EBUSY",
|
||||
});
|
||||
const lease: AcpLinuxCgroupLease = {
|
||||
const lease: AcpSessionRuntime.AcpLinuxCgroupLease = {
|
||||
contains: () => false,
|
||||
exists: () => true,
|
||||
path: "/test/t3-acp-busy",
|
||||
@@ -483,7 +481,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const error = yield* Effect.flip(terminateLinuxCgroupLease(lease));
|
||||
const error = yield* Effect.flip(AcpSessionRuntime.terminateLinuxCgroupLease(lease));
|
||||
expect(error.detail).toBe("Failed to remove ACP cgroup /test/t3-acp-busy");
|
||||
expect(error.cause).toBe(removeError);
|
||||
}),
|
||||
@@ -493,13 +491,16 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
const fixture = makeController({
|
||||
processes: [server(), identity(100, process.pid, 100, 100, "owned")],
|
||||
});
|
||||
const ownedRoot: AcpOwnedPosixProcess = {
|
||||
const ownedRoot: AcpSessionRuntime.AcpOwnedPosixProcess = {
|
||||
...identity(100, process.pid, 100, 100, "owned"),
|
||||
parentExecutable: server().executable,
|
||||
parentStartTime: server().startTime,
|
||||
};
|
||||
const root: AcpPosixOwnershipRoot = { captureAttempted: true, value: ownedRoot };
|
||||
const lease: AcpLinuxCgroupLease = {
|
||||
const root: AcpSessionRuntime.AcpPosixOwnershipRoot = {
|
||||
captureAttempted: true,
|
||||
value: ownedRoot,
|
||||
};
|
||||
const lease: AcpSessionRuntime.AcpLinuxCgroupLease = {
|
||||
contains: () => true,
|
||||
exists: () => true,
|
||||
path: "/test/t3-acp-root",
|
||||
@@ -508,19 +509,19 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
populated: () => true,
|
||||
remove: () => undefined,
|
||||
};
|
||||
signalLinuxCgroupRootTerm({ controller: fixture.controller, lease, root });
|
||||
AcpSessionRuntime.signalLinuxCgroupRootTerm({ controller: fixture.controller, lease, root });
|
||||
expect(fixture.signals).toEqual(["process:100:SIGTERM"]);
|
||||
|
||||
const reused = makeController({
|
||||
processes: [server(), identity(100, process.pid, 100, 100, "reused")],
|
||||
});
|
||||
signalLinuxCgroupRootTerm({ controller: reused.controller, lease, root });
|
||||
AcpSessionRuntime.signalLinuxCgroupRootTerm({ controller: reused.controller, lease, root });
|
||||
expect(reused.signals).toEqual([]);
|
||||
|
||||
const migrated = makeController({
|
||||
processes: [server(), identity(100, process.pid, 100, 100, "owned")],
|
||||
});
|
||||
signalLinuxCgroupRootTerm({
|
||||
AcpSessionRuntime.signalLinuxCgroupRootTerm({
|
||||
controller: migrated.controller,
|
||||
lease: { ...lease, contains: () => false },
|
||||
root,
|
||||
@@ -565,9 +566,9 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
}).pipe(Effect.timeout("2 seconds"));
|
||||
const [workerTid, childPid] = published;
|
||||
expect(workerTid).not.toBe(helper.pid);
|
||||
expect(makePosixProcessTreeController("linux").childrenOf(helper.pid!)).toContainEqual(
|
||||
expect.objectContaining({ pid: childPid, ppid: helper.pid }),
|
||||
);
|
||||
expect(
|
||||
AcpSessionRuntime.makePosixProcessTreeController("linux").childrenOf(helper.pid!),
|
||||
).toContainEqual(expect.objectContaining({ pid: childPid, ppid: helper.pid }));
|
||||
} finally {
|
||||
try {
|
||||
process.kill(-helper.pid!, "SIGKILL");
|
||||
@@ -585,11 +586,11 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
const fixture = makeController({
|
||||
processes: [server(), identity(100, process.pid, 100, 100), beforeExec],
|
||||
});
|
||||
const frontier = new Map<number, AcpOwnedPosixProcess>();
|
||||
const frontier = new Map<number, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const childQueues = new Map<number, Array<number>>();
|
||||
const ledger = new Map<string, AcpOwnedPosixProcess>();
|
||||
const root: AcpPosixOwnershipRoot = { value: undefined };
|
||||
observePosixOwnershipLedger({
|
||||
const ledger = new Map<string, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const root: AcpSessionRuntime.AcpPosixOwnershipRoot = { value: undefined };
|
||||
AcpSessionRuntime.observePosixOwnershipLedger({
|
||||
childQueues,
|
||||
controller: fixture.controller,
|
||||
frontier,
|
||||
@@ -598,7 +599,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
rootPid: 100,
|
||||
});
|
||||
fixture.processes.set(110, { ...beforeExec, executable: "/usr/bin/bash" });
|
||||
observePosixOwnershipLedger({
|
||||
AcpSessionRuntime.observePosixOwnershipLedger({
|
||||
childQueues,
|
||||
controller: fixture.controller,
|
||||
frontier,
|
||||
@@ -610,7 +611,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
expect([...ledger.values()].find((process) => process.pid === 110)?.executable).toBe(
|
||||
"/usr/bin/bash",
|
||||
);
|
||||
yield* terminatePosixOwnedProcessTree({
|
||||
yield* AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller: fixture.controller,
|
||||
grace: 0,
|
||||
ledger,
|
||||
@@ -623,13 +624,13 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
|
||||
it("never adopts a replacement PID after initial root capture failed", () => {
|
||||
const fixture = makeController({ processes: [server()] });
|
||||
const frontier = new Map<number, AcpOwnedPosixProcess>();
|
||||
const frontier = new Map<number, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const childQueues = new Map<number, Array<number>>();
|
||||
const ledger = new Map<string, AcpOwnedPosixProcess>();
|
||||
const root: AcpPosixOwnershipRoot = { value: undefined };
|
||||
const ledger = new Map<string, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const root: AcpSessionRuntime.AcpPosixOwnershipRoot = { value: undefined };
|
||||
const capture = () => {
|
||||
try {
|
||||
observePosixOwnershipLedger({
|
||||
AcpSessionRuntime.observePosixOwnershipLedger({
|
||||
childQueues,
|
||||
controller: fixture.controller,
|
||||
frontier,
|
||||
@@ -663,7 +664,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
const fixture = makeController({
|
||||
processes: [server(), identity(100, process.pid, 100, 100)],
|
||||
});
|
||||
const controller: AcpPosixProcessTreeController = {
|
||||
const controller: AcpSessionRuntime.AcpPosixProcessTreeController = {
|
||||
...fixture.controller,
|
||||
childPidsOf: (pid) => {
|
||||
childListReads += 1;
|
||||
@@ -678,10 +679,10 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
return fixture.controller.snapshot();
|
||||
},
|
||||
};
|
||||
const frontier = new Map<number, AcpOwnedPosixProcess>();
|
||||
const frontier = new Map<number, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const childQueues = new Map<number, Array<number>>();
|
||||
const ledger = new Map<string, AcpOwnedPosixProcess>();
|
||||
const root: AcpPosixOwnershipRoot = { value: undefined };
|
||||
const ledger = new Map<string, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const root: AcpSessionRuntime.AcpPosixOwnershipRoot = { value: undefined };
|
||||
for (let index = 0; index < 5_000; index += 1) {
|
||||
const tombstone = identity(100_000 + index, 1, 100_000 + index, 100_000 + index);
|
||||
ledger.set(`${tombstone.pid}:${tombstone.startTime}`, {
|
||||
@@ -690,7 +691,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
parentStartTime: "",
|
||||
});
|
||||
}
|
||||
observePosixOwnershipLedger({
|
||||
AcpSessionRuntime.observePosixOwnershipLedger({
|
||||
childQueues,
|
||||
controller,
|
||||
frontier,
|
||||
@@ -714,7 +715,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
) {
|
||||
childListReads = 0;
|
||||
identityCalls = 0;
|
||||
observePosixOwnershipLedger({
|
||||
AcpSessionRuntime.observePosixOwnershipLedger({
|
||||
childQueues,
|
||||
controller,
|
||||
frontier,
|
||||
@@ -732,7 +733,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
);
|
||||
expect(missing, `missing after ${passes} passes`).toEqual([]);
|
||||
expect(passes).toBeGreaterThan(2);
|
||||
yield* terminatePosixOwnedProcessTree({
|
||||
yield* AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller,
|
||||
grace: 0,
|
||||
ledger,
|
||||
@@ -751,7 +752,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
const fixture = makeController({
|
||||
processes: [server(), identity(100, process.pid, 100, 100), identity(110, 100, 110, 110)],
|
||||
});
|
||||
const controller: AcpPosixProcessTreeController = {
|
||||
const controller: AcpSessionRuntime.AcpPosixProcessTreeController = {
|
||||
...fixture.controller,
|
||||
childPidsOf: (pid) => {
|
||||
childrenCalls += 1;
|
||||
@@ -767,16 +768,16 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
},
|
||||
};
|
||||
const scope = yield* Scope.make();
|
||||
const frontier = new Map<number, AcpOwnedPosixProcess>();
|
||||
const frontier = new Map<number, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const childQueues = new Map<number, Array<number>>();
|
||||
let ledgerValuesCalls = 0;
|
||||
const ledger = new (class extends Map<string, AcpOwnedPosixProcess> {
|
||||
override values(): MapIterator<AcpOwnedPosixProcess> {
|
||||
const ledger = new (class extends Map<string, AcpSessionRuntime.AcpOwnedPosixProcess> {
|
||||
override values(): MapIterator<AcpSessionRuntime.AcpOwnedPosixProcess> {
|
||||
ledgerValuesCalls += 1;
|
||||
return super.values();
|
||||
}
|
||||
})();
|
||||
const root: AcpPosixOwnershipRoot = { value: undefined };
|
||||
const root: AcpSessionRuntime.AcpPosixOwnershipRoot = { value: undefined };
|
||||
for (let index = 0; index < 5_000; index += 1) {
|
||||
const tombstone = identity(10_000 + index, 1, 10_000 + index, 10_000 + index);
|
||||
ledger.set(`${tombstone.pid}:${tombstone.startTime}`, {
|
||||
@@ -785,7 +786,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
parentStartTime: "",
|
||||
});
|
||||
}
|
||||
yield* observePosixOwnershipLedgerContinuously({
|
||||
yield* AcpSessionRuntime.observePosixOwnershipLedgerContinuously({
|
||||
childQueues,
|
||||
controller,
|
||||
frontier,
|
||||
@@ -831,7 +832,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
},
|
||||
});
|
||||
|
||||
yield* terminatePosixOwnedProcessTree({
|
||||
yield* AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller: fixture.controller,
|
||||
grace: 0,
|
||||
rootPid: 100,
|
||||
@@ -865,7 +866,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
},
|
||||
});
|
||||
|
||||
yield* terminatePosixOwnedProcessTree({
|
||||
yield* AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller: fixture.controller,
|
||||
grace: 0,
|
||||
rootPid: 100,
|
||||
@@ -893,7 +894,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
});
|
||||
|
||||
const result = yield* Effect.exit(
|
||||
terminatePosixOwnedProcessTree({
|
||||
AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller: fixture.controller,
|
||||
grace: 0,
|
||||
rootPid: 100,
|
||||
@@ -913,9 +914,13 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
|
||||
it.live("does not treat zombie residual entries as teardown survivors", () =>
|
||||
Effect.gen(function* () {
|
||||
expect(posixProcessIsZombie({ ...identity(1, 0, 1, 1), state: "Z" })).toBe(true);
|
||||
expect(posixProcessIsZombie({ ...identity(1, 0, 1, 1), state: "S" })).toBe(false);
|
||||
const withoutState: AcpPosixProcessIdentity = {
|
||||
expect(AcpSessionRuntime.posixProcessIsZombie({ ...identity(1, 0, 1, 1), state: "Z" })).toBe(
|
||||
true,
|
||||
);
|
||||
expect(AcpSessionRuntime.posixProcessIsZombie({ ...identity(1, 0, 1, 1), state: "S" })).toBe(
|
||||
false,
|
||||
);
|
||||
const withoutState: AcpSessionRuntime.AcpPosixProcessIdentity = {
|
||||
executable: "/proc/1/exe",
|
||||
pgid: 1,
|
||||
pid: 1,
|
||||
@@ -923,7 +928,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
sid: 1,
|
||||
startTime: "1",
|
||||
};
|
||||
expect(posixProcessIsZombie(withoutState)).toBe(false);
|
||||
expect(AcpSessionRuntime.posixProcessIsZombie(withoutState)).toBe(false);
|
||||
|
||||
const root = identity(100, process.pid, 100, 100);
|
||||
const zombieChild = identity(110, 100, 110, 110, "110", "Z");
|
||||
@@ -936,7 +941,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
processes.set(pid, { ...current, state: "Z" });
|
||||
},
|
||||
});
|
||||
yield* terminatePosixOwnedProcessTree({
|
||||
yield* AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller: fixture.controller,
|
||||
grace: 0,
|
||||
rootPid: 100,
|
||||
@@ -948,19 +953,19 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
);
|
||||
|
||||
it("admits a live child after a free PID was previously reserved by a dead entry", () => {
|
||||
const staleChild: AcpOwnedPosixProcess = {
|
||||
const staleChild: AcpSessionRuntime.AcpOwnedPosixProcess = {
|
||||
...identity(200, 100, 200, 200, "stale-child"),
|
||||
parentExecutable: `/proc/100/exe`,
|
||||
parentStartTime: "100",
|
||||
};
|
||||
const liveChild = identity(200, 100, 200, 200, "live-child");
|
||||
const root = identity(100, process.pid, 100, 100);
|
||||
const ownedRoot: AcpOwnedPosixProcess = {
|
||||
const ownedRoot: AcpSessionRuntime.AcpOwnedPosixProcess = {
|
||||
...root,
|
||||
parentExecutable: `/proc/${process.pid}/exe`,
|
||||
parentStartTime: "server",
|
||||
};
|
||||
const ledger = new Map<string, AcpOwnedPosixProcess>([
|
||||
const ledger = new Map<string, AcpSessionRuntime.AcpOwnedPosixProcess>([
|
||||
[`100:${root.startTime}`, ownedRoot],
|
||||
[`200:${staleChild.startTime}`, staleChild],
|
||||
]);
|
||||
@@ -969,7 +974,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
}).controller;
|
||||
|
||||
// First capture: PID 200 is free, so the dead reservation is dropped.
|
||||
capturePosixOwnershipLedger({
|
||||
AcpSessionRuntime.capturePosixOwnershipLedger({
|
||||
controller,
|
||||
ledger,
|
||||
rootPid: 100,
|
||||
@@ -978,7 +983,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
expect([...ledger.values()].some((entry) => entry.pid === 200)).toBe(false);
|
||||
|
||||
// Second capture: a new process reuses PID 200 under the owned parent.
|
||||
capturePosixOwnershipLedger({
|
||||
AcpSessionRuntime.capturePosixOwnershipLedger({
|
||||
controller: makeController({ processes: [server(), root, liveChild] }).controller,
|
||||
ledger,
|
||||
rootPid: 100,
|
||||
@@ -990,24 +995,24 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
});
|
||||
|
||||
it("admits a live child when a stale ledger entry still occupies the reused PID", () => {
|
||||
const staleChild: AcpOwnedPosixProcess = {
|
||||
const staleChild: AcpSessionRuntime.AcpOwnedPosixProcess = {
|
||||
...identity(200, 100, 200, 200, "stale-child"),
|
||||
parentExecutable: `/proc/100/exe`,
|
||||
parentStartTime: "100",
|
||||
};
|
||||
const liveChild = identity(200, 100, 200, 200, "live-child");
|
||||
const root = identity(100, process.pid, 100, 100);
|
||||
const ownedRoot: AcpOwnedPosixProcess = {
|
||||
const ownedRoot: AcpSessionRuntime.AcpOwnedPosixProcess = {
|
||||
...root,
|
||||
parentExecutable: `/proc/${process.pid}/exe`,
|
||||
parentStartTime: "server",
|
||||
};
|
||||
const ledger = new Map<string, AcpOwnedPosixProcess>([
|
||||
const ledger = new Map<string, AcpSessionRuntime.AcpOwnedPosixProcess>([
|
||||
[`100:${root.startTime}`, ownedRoot],
|
||||
[`200:${staleChild.startTime}`, staleChild],
|
||||
]);
|
||||
|
||||
capturePosixOwnershipLedger({
|
||||
AcpSessionRuntime.capturePosixOwnershipLedger({
|
||||
controller: makeController({ processes: [server(), root, liveChild] }).controller,
|
||||
ledger,
|
||||
rootPid: 100,
|
||||
@@ -1040,7 +1045,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
},
|
||||
});
|
||||
|
||||
yield* terminatePosixOwnedProcessTree({
|
||||
yield* AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller: fixture.controller,
|
||||
grace: 0,
|
||||
rootPid: 100,
|
||||
@@ -1064,7 +1069,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
},
|
||||
});
|
||||
let snapshotCalls = 0;
|
||||
const controller: AcpPosixProcessTreeController = {
|
||||
const controller: AcpSessionRuntime.AcpPosixProcessTreeController = {
|
||||
...fixture.controller,
|
||||
snapshot: () => {
|
||||
snapshotCalls += 1;
|
||||
@@ -1076,7 +1081,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
};
|
||||
|
||||
const error = yield* Effect.flip(
|
||||
terminatePosixOwnedProcessTree({
|
||||
AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller,
|
||||
discoveryPasses: 2,
|
||||
grace: 0,
|
||||
@@ -1092,10 +1097,10 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
it.live("retains the ledger across root exit and an explicit failure for finalizer retry", () =>
|
||||
Effect.gen(function* () {
|
||||
let ignoreSignals = true;
|
||||
const ledger = new Map<string, AcpOwnedPosixProcess>();
|
||||
const frontier = new Map<number, AcpOwnedPosixProcess>();
|
||||
const ledger = new Map<string, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const frontier = new Map<number, AcpSessionRuntime.AcpOwnedPosixProcess>();
|
||||
const childQueues = new Map<number, Array<number>>();
|
||||
const root: AcpPosixOwnershipRoot = { value: undefined };
|
||||
const root: AcpSessionRuntime.AcpPosixOwnershipRoot = { value: undefined };
|
||||
const fixture = makeController({
|
||||
processes: [
|
||||
server(),
|
||||
@@ -1108,7 +1113,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
if (!ignoreSignals) processes.delete(pid);
|
||||
},
|
||||
});
|
||||
observePosixOwnershipLedger({
|
||||
AcpSessionRuntime.observePosixOwnershipLedger({
|
||||
childQueues,
|
||||
controller: fixture.controller,
|
||||
frontier,
|
||||
@@ -1118,7 +1123,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
});
|
||||
|
||||
const explicit = yield* Effect.exit(
|
||||
terminatePosixOwnedProcessTree({
|
||||
AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller: fixture.controller,
|
||||
grace: 0,
|
||||
ledger,
|
||||
@@ -1130,7 +1135,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
expect(fixture.processes.has(111)).toBe(true);
|
||||
|
||||
fixture.processes.set(112, identity(112, 110, 112, 112));
|
||||
observePosixOwnershipLedger({
|
||||
AcpSessionRuntime.observePosixOwnershipLedger({
|
||||
childQueues,
|
||||
controller: fixture.controller,
|
||||
frontier,
|
||||
@@ -1139,7 +1144,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
rootPid: 100,
|
||||
});
|
||||
ignoreSignals = false;
|
||||
yield* terminatePosixOwnedProcessTree({
|
||||
yield* AcpSessionRuntime.terminatePosixOwnedProcessTree({
|
||||
controller: fixture.controller,
|
||||
grace: 0,
|
||||
ledger,
|
||||
@@ -1153,7 +1158,7 @@ describe("terminatePosixOwnedProcessTree", () => {
|
||||
|
||||
it("fails closed where a stable POSIX identity provider is unavailable", () => {
|
||||
try {
|
||||
makePosixProcessTreeController("darwin");
|
||||
AcpSessionRuntime.makePosixProcessTreeController("darwin");
|
||||
throw new Error("Expected Darwin process ownership to fail closed");
|
||||
} catch (error) {
|
||||
expect(error).toMatchObject({
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
makeAntigravityStderrHandler,
|
||||
makeAntigravityStdoutTransform,
|
||||
} from "../antigravityAuthSupport.ts";
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import { normalizeAntigravitySessionUpdate } from "./AntigravityProtocol.ts";
|
||||
|
||||
export interface AntigravityAcpRuntimeInput extends Omit<
|
||||
|
||||
@@ -17,7 +17,10 @@ import {
|
||||
sanitizeAntigravityToolPayload,
|
||||
selectAntigravityPermissionOptionId,
|
||||
} from "./AntigravityProtocol.ts";
|
||||
import { mergeToolCallState, parseSessionUpdateEvent } from "./AcpRuntimeModel.ts";
|
||||
import {
|
||||
mergeToolCallState,
|
||||
parseSessionUpdateEvent,
|
||||
} from "@t3tools/provider-acp/server/runtimeModel";
|
||||
|
||||
const isSessionNotification = Schema.is(AcpWireSchema.SessionNotification);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import * as Schema from "effect/Schema";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
import * as AcpWireSchema from "effect-acp/schema-v1";
|
||||
|
||||
import type { AcpToolCallState } from "./AcpRuntimeModel.ts";
|
||||
import type { AcpToolCallState } from "@t3tools/provider-acp/server/runtimeModel";
|
||||
|
||||
const TOOL_TEXT_LIMIT = 8_000;
|
||||
const TOOL_TEXT_TRUNCATED = "[Earlier output truncated]\n\n";
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as EffectAcpErrors from "effect-acp/errors";
|
||||
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
|
||||
import { normalizeModelSlug } from "@t3tools/shared/model";
|
||||
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import { makeXAiPromptCompletionRuntime } from "./XAiAcpExtension.ts";
|
||||
|
||||
const GROK_API_KEY_ENV = "XAI_API_KEY";
|
||||
|
||||
@@ -34,12 +34,12 @@ import {
|
||||
xAiSubagentFinishedNotice,
|
||||
XAiAskUserQuestionRequest,
|
||||
} from "./XAiAcpExtension.ts";
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import {
|
||||
type AcpToolCallState,
|
||||
mergeToolCallState,
|
||||
parseSessionUpdateEvent,
|
||||
} from "./AcpRuntimeModel.ts";
|
||||
} from "@t3tools/provider-acp/server/runtimeModel";
|
||||
|
||||
const decodeXAiAskUserQuestionRequest = Schema.decodeUnknownSync(XAiAskUserQuestionRequest);
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import * as Schema from "effect/Schema";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
|
||||
import type * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import type { AcpToolCallState } from "./AcpRuntimeModel.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import type { AcpToolCallState } from "@t3tools/provider-acp/server/runtimeModel";
|
||||
|
||||
const xAiStopReasonMissingMetaKey = "xAiStopReasonMissing";
|
||||
export const xAiRateLimitedErrorCode = -32003;
|
||||
|
||||
@@ -17,7 +17,7 @@ import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
||||
import * as AcpErrors from "effect-acp/errors";
|
||||
|
||||
import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";
|
||||
import type { AcpSpawnInput } from "./acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import {
|
||||
antigravityUserSkillDirectories,
|
||||
resolveAntigravityUserHome,
|
||||
@@ -440,7 +440,7 @@ export function buildAntigravityAcpSpawnInput(input: {
|
||||
readonly auth?: AntigravityAuthConfig;
|
||||
/** Per-process temp directory. Defaults to the profile's shared temp directory. */
|
||||
readonly runtimeTempDirectory?: string;
|
||||
}): AcpSpawnInput {
|
||||
}): AcpSessionRuntime.AcpSpawnInput {
|
||||
return {
|
||||
command: input.installation.executablePath,
|
||||
args: input.profile.platform === "linux" ? ["--uid="] : [],
|
||||
|
||||
@@ -20,7 +20,7 @@ import { type AcpError, AcpRequestError } from "effect-acp/errors";
|
||||
import type * as AcpSchema from "effect-acp/compat";
|
||||
import { expect } from "vite-plus/test";
|
||||
|
||||
import type { AcpSessionRuntimeEvent } from "../provider/acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import { removeAntigravitySessionFiles } from "../provider/acp/AntigravitySessionFiles.ts";
|
||||
|
||||
import {
|
||||
@@ -121,7 +121,7 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
|
||||
|
||||
const makeRuntime: AntigravityTextGenerationOptions["makeRuntime"] = (cwd) =>
|
||||
Effect.gen(function* () {
|
||||
const events = yield* Queue.unbounded<AcpSessionRuntimeEvent>();
|
||||
const events = yield* Queue.unbounded<AcpSessionRuntime.AcpSessionRuntimeEvent>();
|
||||
state.workspaces.push(cwd);
|
||||
expect(yield* fs.readDirectory(cwd).pipe(Effect.orDie)).toEqual([]);
|
||||
yield* Effect.addFinalizer(() =>
|
||||
|
||||
@@ -13,7 +13,7 @@ import { type AcpError, AcpRequestError } from "effect-acp/errors";
|
||||
|
||||
import { applyAntigravityAcpModelSelection } from "../provider/acp/AntigravityAcpSupport.ts";
|
||||
import { removeAntigravitySessionFiles } from "../provider/acp/AntigravitySessionFiles.ts";
|
||||
import type { AcpSessionRuntime } from "../provider/acp/AcpSessionRuntime.ts";
|
||||
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
|
||||
import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations";
|
||||
|
||||
const ANTIGRAVITY_TIMEOUT_MS = 180_000;
|
||||
@@ -25,7 +25,7 @@ const decodeConfiguration = Schema.decodeEffect(Schema.fromJsonString(Configurat
|
||||
const decodeConfigurationObject = Schema.decodeUnknownEffect(Configuration);
|
||||
|
||||
type AntigravityTextRuntime = Pick<
|
||||
AcpSessionRuntime["Service"],
|
||||
AcpSessionRuntime.AcpSessionRuntime["Service"],
|
||||
| "start"
|
||||
| "setMode"
|
||||
| "getConfigOptions"
|
||||
|
||||
@@ -10,7 +10,7 @@ whether a turn runs. This page lists the decisions and evidence a new driver nee
|
||||
- **ACP agents** start as [ACP Registry](../user/providers-acp.md) entries, which follow the ACP
|
||||
spec with no per-agent handling. An agent gets a dedicated driver only when it needs behavior the
|
||||
spec does not cover, and then it is a small flavor over the
|
||||
[shared ACP adapter](../../apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts), like Grok
|
||||
[shared ACP adapter](../../packages/provider-acp/src/server/adapter.ts), like Grok
|
||||
and Antigravity. Never add agent-id checks to the generic registry adapter.
|
||||
- **Other protocols** get a native adapter that implements
|
||||
[`ProviderAdapterV2`](../../packages/provider-core/src/server/ProviderAdapter.ts), like Codex,
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
"tc": "vp run -r --concurrency-limit 2 typecheck",
|
||||
"lint": "vp lint --report-unused-disable-directives",
|
||||
"knip": "knip --preprocessor ./scripts/knip-schemas.ts",
|
||||
"knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",
|
||||
"knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",
|
||||
"knip:production": "knip --production --preprocessor ./scripts/knip-schemas.ts",
|
||||
"lint:mobile": "node scripts/mobile-native-static-check.ts",
|
||||
"test": "vp run -r test",
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "@t3tools/provider-acp",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./server/AcpSessionRuntime": {
|
||||
"types": "./src/server/AcpSessionRuntime.ts",
|
||||
"import": "./src/server/AcpSessionRuntime.ts"
|
||||
},
|
||||
"./server/adapter": {
|
||||
"types": "./src/server/adapter.ts",
|
||||
"import": "./src/server/adapter.ts"
|
||||
},
|
||||
"./server/clientPolicy": {
|
||||
"types": "./src/server/clientPolicy.ts",
|
||||
"import": "./src/server/clientPolicy.ts"
|
||||
},
|
||||
"./server/clientTerminals": {
|
||||
"types": "./src/server/clientTerminals.ts",
|
||||
"import": "./src/server/clientTerminals.ts"
|
||||
},
|
||||
"./server/coreRuntimeEvents": {
|
||||
"types": "./src/server/coreRuntimeEvents.ts",
|
||||
"import": "./src/server/coreRuntimeEvents.ts"
|
||||
},
|
||||
"./server/mcpOverAcpBridge": {
|
||||
"types": "./src/server/mcpOverAcpBridge.ts",
|
||||
"import": "./src/server/mcpOverAcpBridge.ts"
|
||||
},
|
||||
"./server/nativeLogging": {
|
||||
"types": "./src/server/nativeLogging.ts",
|
||||
"import": "./src/server/nativeLogging.ts"
|
||||
},
|
||||
"./server/runtimeModel": {
|
||||
"types": "./src/server/runtimeModel.ts",
|
||||
"import": "./src/server/runtimeModel.ts"
|
||||
},
|
||||
"./server/sessionConfig": {
|
||||
"types": "./src/server/sessionConfig.ts",
|
||||
"import": "./src/server/sessionConfig.ts"
|
||||
},
|
||||
"./server/stderr": {
|
||||
"types": "./src/server/stderr.ts",
|
||||
"import": "./src/server/stderr.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vp test run --config ../../vite.config.ts --dir ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/provider-core": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"diff": "8.0.3",
|
||||
"effect": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"@types/node": "catalog:",
|
||||
"effect-acp": "workspace:*",
|
||||
"vite-plus": "catalog:"
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -30,7 +30,7 @@ import { resolveSpawnCommand } from "@t3tools/shared/shell";
|
||||
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
|
||||
|
||||
import { signalProcessGroup } from "@t3tools/provider-core/server/processGroup";
|
||||
import { appendAcpStderrTail, sanitizeAcpStderrExcerpt } from "./AcpStderr.ts";
|
||||
import { appendAcpStderrTail, sanitizeAcpStderrExcerpt } from "./stderr.ts";
|
||||
import {
|
||||
collectSessionConfigOptionValues,
|
||||
decideToolCallUpdateEmission,
|
||||
@@ -47,7 +47,7 @@ import {
|
||||
type AcpParsedSessionEvent,
|
||||
type AcpSessionModeState,
|
||||
type AcpToolCallState,
|
||||
} from "./AcpRuntimeModel.ts";
|
||||
} from "./runtimeModel.ts";
|
||||
|
||||
const MAX_SHOWN_TOOL_CALL_IDS = 256;
|
||||
|
||||
@@ -1329,7 +1329,7 @@ export class AcpSessionRuntime extends Context.Service<
|
||||
payload: unknown,
|
||||
) => Effect.Effect<void, EffectAcpErrors.AcpError>;
|
||||
}
|
||||
>()("t3/provider/acp/AcpSessionRuntime") {
|
||||
>()("@t3tools/provider-acp/server/AcpSessionRuntime") {
|
||||
static layer(
|
||||
options: AcpSessionRuntimeOptions,
|
||||
): Layer.Layer<
|
||||
+11
-19
@@ -57,12 +57,8 @@ import type * as EffectAcpProtocol from "effect-acp/protocol";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
|
||||
import { formatReadToolLabel, formatSearchToolLabel } from "@t3tools/shared/toolActivity";
|
||||
import { resolveAttachmentPath } from "../../attachmentStore.ts";
|
||||
import * as ServerConfig from "../../config.ts";
|
||||
import {
|
||||
makeAcpMcpOverAcpBridge,
|
||||
type AcpMcpOverAcpBridge,
|
||||
} from "../../mcp/AcpMcpOverAcpBridge.ts";
|
||||
import type * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
|
||||
import { makeAcpMcpOverAcpBridge, type AcpMcpOverAcpBridge } from "./mcpOverAcpBridge.ts";
|
||||
import { mcpToolPresentation } from "@t3tools/provider-core/server/mcpToolPresentation";
|
||||
import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
|
||||
import {
|
||||
@@ -78,7 +74,7 @@ import {
|
||||
type AcpAgentTerminalState,
|
||||
type AcpSessionModeState,
|
||||
type AcpToolCallState,
|
||||
} from "../../provider/acp/AcpRuntimeModel.ts";
|
||||
} from "./runtimeModel.ts";
|
||||
import {
|
||||
acpClientExecuteDisposition,
|
||||
acpMcpToolApprovalElicitationDisposition,
|
||||
@@ -86,14 +82,14 @@ import {
|
||||
type AcpPermissionDisposition,
|
||||
makeAcpClientPolicyGrants,
|
||||
unknownRecord,
|
||||
} from "../../provider/acp/AcpClientPolicy.ts";
|
||||
} from "./clientPolicy.ts";
|
||||
import {
|
||||
makeAcpClientTerminals,
|
||||
resolveEmbeddedTerminalContent,
|
||||
type AcpClientTerminals,
|
||||
} from "../../provider/acp/AcpClientTerminals.ts";
|
||||
import { ACP_SESSION_MODE_OPTION_ID } from "../../provider/acp/AcpSessionConfig.ts";
|
||||
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
|
||||
} from "./clientTerminals.ts";
|
||||
import { ACP_SESSION_MODE_OPTION_ID } from "./sessionConfig.ts";
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import {
|
||||
t3AcpPromptWithInstructions,
|
||||
type T3AcpInstructionState,
|
||||
@@ -487,7 +483,7 @@ export interface AcpAdapterV2Options {
|
||||
readonly crypto: Crypto.Crypto;
|
||||
readonly fileSystem: FileSystem.FileSystem;
|
||||
readonly idAllocator: IdAllocator.IdAllocatorV2Shape;
|
||||
readonly serverConfig: ServerConfig.ServerConfig["Service"];
|
||||
readonly host: ProviderHost.ProviderHostShape;
|
||||
/** How agents spawn this install's `acp-mcp-bridge`; see `resolveSelfInvocation`. */
|
||||
readonly selfInvocation: SelfInvocation;
|
||||
/**
|
||||
@@ -1497,7 +1493,7 @@ function shouldPersistToolUpdate(
|
||||
export function makeAcpAdapterV2(
|
||||
options: AcpAdapterV2Options,
|
||||
): ProviderAdapter.ProviderAdapterV2Shape {
|
||||
const { flavor, fileSystem, idAllocator, serverConfig, selfInvocation: self } = options;
|
||||
const { flavor, fileSystem, idAllocator, host, selfInvocation: self } = options;
|
||||
const driver = flavor.driver;
|
||||
const continuationRequests = options.continuationRequests;
|
||||
const postSettleContinuationEnabled =
|
||||
@@ -6781,8 +6777,7 @@ export function makeAcpAdapterV2(
|
||||
const messageText = providerMessageTextWithAttachmentPaths({
|
||||
text: turnInput.message.text,
|
||||
attachments: turnInput.message.attachments,
|
||||
resolveAttachmentPath: (attachment) =>
|
||||
resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
|
||||
resolveAttachmentPath: host.resolveAttachmentPath,
|
||||
});
|
||||
const text = t3AcpPromptWithInstructions({
|
||||
prompt: messageText,
|
||||
@@ -6804,10 +6799,7 @@ export function makeAcpAdapterV2(
|
||||
});
|
||||
}
|
||||
for (const attachment of imageAttachments) {
|
||||
const path = resolveAttachmentPath({
|
||||
attachmentsDir: serverConfig.attachmentsDir,
|
||||
attachment: attachment as ChatAttachment,
|
||||
});
|
||||
const path = host.resolveAttachmentPath(attachment as ChatAttachment);
|
||||
if (path === null) {
|
||||
return yield* new ProviderAdapter.ProviderAdapterProtocolError({
|
||||
driver,
|
||||
+1
-1
@@ -13,7 +13,7 @@ import {
|
||||
acpPermissionDisposition,
|
||||
makeAcpClientPolicyGrants,
|
||||
type AcpRuntimePolicy,
|
||||
} from "./AcpClientPolicy.ts";
|
||||
} from "./clientPolicy.ts";
|
||||
|
||||
function permissionRequest(
|
||||
kind: NonNullable<EffectAcpSchema.RequestPermissionRequest["toolCall"]["kind"]>,
|
||||
File renamed without changes.
+1
-1
@@ -8,7 +8,7 @@ import {
|
||||
makeAcpClientTerminals,
|
||||
resolveEmbeddedTerminalContent,
|
||||
type AcpClientTerminals,
|
||||
} from "./AcpClientTerminals.ts";
|
||||
} from "./clientTerminals.ts";
|
||||
|
||||
const withTerminals = <A, E>(use: (terminals: AcpClientTerminals) => Effect.Effect<A, E>) =>
|
||||
Effect.gen(function* () {
|
||||
File renamed without changes.
+1
-1
@@ -8,7 +8,7 @@ import {
|
||||
makeAcpRequestOpenedEvent,
|
||||
makeAcpRequestResolvedEvent,
|
||||
makeAcpToolCallEvent,
|
||||
} from "./AcpCoreRuntimeEvents.ts";
|
||||
} from "./coreRuntimeEvents.ts";
|
||||
|
||||
describe("AcpCoreRuntimeEvents", () => {
|
||||
it("maps ACP permission requests to canonical runtime events", () => {
|
||||
+1
-1
@@ -17,7 +17,7 @@ import {
|
||||
type AcpPlanUpdate,
|
||||
type AcpToolCallState,
|
||||
canonicalItemTypeFromAcpToolKind,
|
||||
} from "./AcpRuntimeModel.ts";
|
||||
} from "./runtimeModel.ts";
|
||||
|
||||
type AcpAdapterRawSource = Extract<
|
||||
RuntimeEventRawSource,
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { describe, expect, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
|
||||
import { makeAcpMcpOverAcpBridge } from "./AcpMcpOverAcpBridge.ts";
|
||||
import { makeAcpMcpOverAcpBridge } from "./mcpOverAcpBridge.ts";
|
||||
|
||||
describe("AcpMcpOverAcpBridge", () => {
|
||||
it.effect("forwards authenticated MCP requests and closes the negotiated session", () =>
|
||||
+2
-2
@@ -5,7 +5,7 @@ import * as Semaphore from "effect/Semaphore";
|
||||
import * as Stream from "effect/Stream";
|
||||
import type * as AcpSchema from "effect-acp/compat";
|
||||
|
||||
import { responsePayloads } from "./AcpMcpStdioBridge.ts";
|
||||
import { responsePayloads } from "@t3tools/shared/mcpResponsePayloads";
|
||||
|
||||
const MAX_CONNECTIONS = 16;
|
||||
const MAX_MESSAGE_BYTES = 8 * 1024 * 1024;
|
||||
@@ -133,7 +133,7 @@ export const makeAcpMcpOverAcpBridge = Effect.fn("AcpMcpOverAcpBridge.make")(fun
|
||||
new AcpMcpOverAcpError(`T3 Code MCP endpoint responded with HTTP ${response.status}.`),
|
||||
);
|
||||
}
|
||||
const payloads = [...(yield* Stream.runCollect(responsePayloads(response)))];
|
||||
const payloads = [...(yield* Stream.runCollect(responsePayloads(response, bridgeError)))];
|
||||
for (const payload of payloads) {
|
||||
connection.protocolVersion = protocolVersionOf(payload) ?? connection.protocolVersion;
|
||||
}
|
||||
+3
-3
@@ -8,8 +8,8 @@ import * as Logger from "effect/Logger";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as AcpErrors from "effect-acp/errors";
|
||||
|
||||
import type { EventNdjsonLogger } from "../EventNdjsonLogger.ts";
|
||||
import { makeAcpNativeLoggerFactory } from "./AcpNativeLogging.ts";
|
||||
import type * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
|
||||
import { makeAcpNativeLoggerFactory } from "./nativeLogging.ts";
|
||||
|
||||
const nodeServicesIt = it.layer(NodeServices.layer);
|
||||
const encodeUnknownJson = Schema.encodeUnknownSync(Schema.fromJsonString(Schema.Unknown));
|
||||
@@ -18,7 +18,7 @@ nodeServicesIt("ACP native logging", (it) => {
|
||||
it.effect("records bounded request and protocol diagnostics without raw payloads", () =>
|
||||
Effect.gen(function* () {
|
||||
const records: Array<unknown> = [];
|
||||
const nativeEventLogger: EventNdjsonLogger = {
|
||||
const nativeEventLogger: ProviderEventLoggers.EventNdjsonLogger = {
|
||||
filePath: "/tmp/provider-native.ndjson",
|
||||
write: (event) => Effect.sync(() => void records.push(event)),
|
||||
close: () => Effect.void,
|
||||
+2
-2
@@ -6,7 +6,7 @@ import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import type * as EffectAcpProtocol from "effect-acp/protocol";
|
||||
|
||||
import type { EventNdjsonLogger } from "../EventNdjsonLogger.ts";
|
||||
import type * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
|
||||
import {
|
||||
structuralProtocolMethod,
|
||||
summarizeNativeProtocolPayload,
|
||||
@@ -121,7 +121,7 @@ function filterTransientProtocolLog(
|
||||
export const makeAcpNativeLoggerFactory = Effect.fn("makeAcpNativeLoggerFactory")(function* () {
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
return (input: {
|
||||
readonly nativeEventLogger: EventNdjsonLogger | undefined;
|
||||
readonly nativeEventLogger: ProviderEventLoggers.EventNdjsonLogger | undefined;
|
||||
readonly provider: ProviderDriverKind;
|
||||
readonly threadId: ThreadId;
|
||||
readonly verboseProtocolLogging?: boolean;
|
||||
+1
-1
@@ -19,7 +19,7 @@ import {
|
||||
syntheticLoadSessionResponseFromInitialize,
|
||||
toolCallProgressLength,
|
||||
type AcpToolCallState,
|
||||
} from "./AcpRuntimeModel.ts";
|
||||
} from "./runtimeModel.ts";
|
||||
|
||||
describe("AcpRuntimeModel", () => {
|
||||
it("parses session mode state from typed ACP session setup responses", () => {
|
||||
File renamed without changes.
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
|
||||
import { ACP_SESSION_MODE_OPTION_ID, acpProviderOptionDescriptors } from "./AcpSessionConfig.ts";
|
||||
import { ACP_SESSION_MODE_OPTION_ID, acpProviderOptionDescriptors } from "./sessionConfig.ts";
|
||||
|
||||
describe("acpProviderOptionDescriptors", () => {
|
||||
it("maps non-model select options and excludes model and collaboration categories", () => {
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import type { ProviderOptionChoice, ProviderOptionDescriptor } from "@t3tools/contracts";
|
||||
import type * as EffectAcpSchema from "effect-acp/compat";
|
||||
|
||||
import type { AcpSessionModeState } from "./AcpRuntimeModel.ts";
|
||||
import type { AcpSessionModeState } from "./runtimeModel.ts";
|
||||
|
||||
/**
|
||||
* Maps ACP session configuration and session modes onto T3's provider option
|
||||
+1
-1
@@ -4,7 +4,7 @@ import {
|
||||
ACP_STDERR_TAIL_MAX_CHARS,
|
||||
appendAcpStderrTail,
|
||||
sanitizeAcpStderrExcerpt,
|
||||
} from "./AcpStderr.ts";
|
||||
} from "./stderr.ts";
|
||||
|
||||
describe("AcpStderr", () => {
|
||||
it("keeps a bounded tail of stderr chunks", () => {
|
||||
File renamed without changes.
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -32,6 +32,8 @@ export interface ProviderHostPaths {
|
||||
readonly stateDir: string;
|
||||
/** Scratch space for provider probes and generated helper files. */
|
||||
readonly providerStatusCacheDir: string;
|
||||
/** Where chat attachments are stored; agents that sandbox file reads must be granted it. */
|
||||
readonly attachmentsDir: string;
|
||||
}
|
||||
|
||||
/** One opaque credential blob in the server's secret store. Only the provider decodes it. */
|
||||
|
||||
@@ -109,6 +109,7 @@ function layerProviderHost(input: {
|
||||
baseDir: "/t3",
|
||||
stateDir: "/t3/userdata",
|
||||
providerStatusCacheDir: "/t3/caches",
|
||||
attachmentsDir: "/t3/userdata/attachments",
|
||||
},
|
||||
settings: input.settings ?? {
|
||||
get: Effect.succeed(DEFAULT_SERVER_SETTINGS),
|
||||
|
||||
@@ -42,7 +42,13 @@ export const layerTestProviderHost = (
|
||||
const settings = options.settings ?? DEFAULT_SERVER_SETTINGS;
|
||||
const credentials = new Map<string, Uint8Array>();
|
||||
return ProviderHost.ProviderHost.of({
|
||||
paths: { cwd: options.cwd ?? process.cwd(), baseDir, stateDir, providerStatusCacheDir },
|
||||
paths: {
|
||||
cwd: options.cwd ?? process.cwd(),
|
||||
baseDir,
|
||||
stateDir,
|
||||
providerStatusCacheDir,
|
||||
attachmentsDir,
|
||||
},
|
||||
settings: {
|
||||
get: Effect.succeed(settings),
|
||||
changes: Stream.empty,
|
||||
|
||||
@@ -466,6 +466,10 @@
|
||||
"./atomicWrite": {
|
||||
"types": "./src/atomicWrite.ts",
|
||||
"import": "./src/atomicWrite.ts"
|
||||
},
|
||||
"./mcpResponsePayloads": {
|
||||
"types": "./src/mcpResponsePayloads.ts",
|
||||
"import": "./src/mcpResponsePayloads.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
// MCP responses carry opaque JSON-RPC that callers relay verbatim.
|
||||
// @effect-diagnostics preferSchemaOverJson:off
|
||||
/**
|
||||
* Reads the JSON-RPC payloads of a response from an MCP streamable-HTTP
|
||||
* endpoint. Used on the ACP bridge fast path, so it imports only effect core.
|
||||
*
|
||||
* @module mcpResponsePayloads
|
||||
*/
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
async function* sseDataLines(response: Response): AsyncGenerator<string> {
|
||||
if (response.body === null) return;
|
||||
const decoder = new TextDecoder();
|
||||
let buffered = "";
|
||||
for await (const chunk of response.body) {
|
||||
buffered += decoder.decode(chunk as Uint8Array, { stream: true });
|
||||
let separatorIndex = buffered.search(/\n\n|\r\n\r\n/u);
|
||||
while (separatorIndex !== -1) {
|
||||
const rawEvent = buffered.slice(0, separatorIndex);
|
||||
buffered = buffered.slice(separatorIndex).replace(/^(?:\r?\n){2}/u, "");
|
||||
const data = rawEvent
|
||||
.split(/\r?\n/u)
|
||||
.filter((line) => line.startsWith("data:"))
|
||||
.map((line) => line.slice("data:".length).trimStart())
|
||||
.join("\n");
|
||||
if (data.length > 0) yield data;
|
||||
separatorIndex = buffered.search(/\n\n|\r\n\r\n/u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const discardResponseBody = (response: Response): Effect.Effect<void> =>
|
||||
Effect.promise(() => response.body?.cancel().catch(() => undefined) ?? Promise.resolve());
|
||||
|
||||
/**
|
||||
* Every JSON-RPC payload carried by a response, in arrival order: nothing for
|
||||
* notification acknowledgements, each SSE `data:` event as it streams in, or
|
||||
* the single JSON body.
|
||||
*/
|
||||
export function responsePayloads<E>(
|
||||
response: Response,
|
||||
onError: (cause: unknown) => E,
|
||||
): Stream.Stream<unknown, E> {
|
||||
if (response.status === 202 || response.status === 204) {
|
||||
return Stream.unwrap(discardResponseBody(response).pipe(Effect.as(Stream.empty)));
|
||||
}
|
||||
const contentType = response.headers.get("content-type") ?? "";
|
||||
if (contentType.includes("text/event-stream")) {
|
||||
return Stream.fromAsyncIterable(sseDataLines(response), onError).pipe(
|
||||
Stream.mapEffect((data) => Effect.try({ try: () => JSON.parse(data), catch: onError })),
|
||||
);
|
||||
}
|
||||
return Stream.unwrap(
|
||||
Effect.tryPromise({ try: () => response.text(), catch: onError }).pipe(
|
||||
Effect.flatMap((text) =>
|
||||
text.trim().length === 0
|
||||
? Effect.succeed(Stream.empty)
|
||||
: Effect.try({ try: () => JSON.parse(text) as unknown, catch: onError }).pipe(
|
||||
Effect.map((payload) => Stream.fromIterable([payload])),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Generated
+37
@@ -600,6 +600,9 @@ importers:
|
||||
'@opencode-ai/sdk':
|
||||
specifier: ^1.3.15
|
||||
version: 1.15.13
|
||||
'@t3tools/provider-acp':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-acp
|
||||
'@t3tools/provider-core':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/provider-core
|
||||
@@ -1092,6 +1095,40 @@ importers:
|
||||
specifier: 1.0.0
|
||||
version: 1.0.0(@types/[email protected])(@vitest/[email protected]([email protected]))([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
|
||||
packages/provider-acp:
|
||||
dependencies:
|
||||
'@t3tools/contracts':
|
||||
specifier: workspace:*
|
||||
version: link:../contracts
|
||||
'@t3tools/provider-core':
|
||||
specifier: workspace:*
|
||||
version: link:../provider-core
|
||||
'@t3tools/shared':
|
||||
specifier: workspace:*
|
||||
version: link:../shared
|
||||
diff:
|
||||
specifier: 8.0.3
|
||||
version: 8.0.3
|
||||
effect:
|
||||
specifier: 4.0.1
|
||||
version: 4.0.1(patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f)
|
||||
devDependencies:
|
||||
'@effect/platform-node':
|
||||
specifier: 4.0.1
|
||||
version: 4.0.1([email protected])([email protected](patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f))([email protected])([email protected])
|
||||
'@effect/vitest':
|
||||
specifier: 4.0.1
|
||||
version: 4.0.1(patch_hash=359f6fb2f7b3ec145bb72208edb9034f02489791aa2491a55cdbd69bd56ee0d2)(@types/[email protected])(@vitest/[email protected])([email protected])([email protected](patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f))([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
'@types/node':
|
||||
specifier: 24.12.4
|
||||
version: 24.12.4
|
||||
effect-acp:
|
||||
specifier: workspace:*
|
||||
version: link:../effect-acp
|
||||
vite-plus:
|
||||
specifier: 1.0.0
|
||||
version: 1.0.0(@types/[email protected])(@vitest/[email protected]([email protected]))([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
|
||||
packages/provider-core:
|
||||
dependencies:
|
||||
'@t3tools/contracts':
|
||||
|
||||
@@ -31,6 +31,7 @@ const workspaceFiles = [
|
||||
"packages/provider-core/package.json",
|
||||
"packages/provider-testing/package.json",
|
||||
"packages/provider-pi/package.json",
|
||||
"packages/provider-acp/package.json",
|
||||
"packages/provider-cursor/package.json",
|
||||
"packages/provider-muse/package.json",
|
||||
"packages/provider-opencode/package.json",
|
||||
|
||||
Reference in new issue
Block a user