Skip to content
TypeScript

refactor(provider-core): share attachment prompts, notifications, and event loggers (#17330)

Julius Marmingee38b6a188faf
diff --git a/apps/server/scripts/record-grok-acp-replay-fixture.ts b/apps/server/scripts/record-grok-acp-replay-fixture.ts
index a6b88d3024f..23d687eb913 100644
--- a/apps/server/scripts/record-grok-acp-replay-fixture.ts
+++ b/apps/server/scripts/record-grok-acp-replay-fixture.ts
@@ -44,7 +44,7 @@ import { makeReplayServerConfig } from "../src/orchestration-v2/testkit/Provider
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";
-import { buildRuntimeInstructions } from "../src/provider/RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
const wallClock = Clock.Clock.defaultValue();
const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts
index 2767e0e1b41..90255fe75a7 100644
--- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts
+++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts
@@ -98,14 +98,14 @@ import {
t3AcpPromptWithInstructions,
type T3AcpInstructionState,
} from "@t3tools/provider-core/server/orchestrationInstructions";
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
import { type ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests";
import {
type BackgroundWork,
type BackgroundWorkReport,
backgroundWorkNotification,
-} from "../Notification.ts";
+} from "@t3tools/provider-core/server/notification";
import {
makeProviderFailure,
makeProviderRetryTurnItem,
@@ -114,7 +114,7 @@ import { acpSelectionTransition } from "@t3tools/provider-core/server/selectionT
import {
isProviderNativeImageAttachment,
providerMessageTextWithAttachmentPaths,
-} from "../AttachmentPrompt.ts";
+} from "@t3tools/provider-core/server/attachmentPrompt";
import {
makeSubagentChildThread,
makeSubagentConversationArtifacts,
@@ -6781,7 +6781,8 @@ export function makeAcpAdapterV2(
const messageText = providerMessageTextWithAttachmentPaths({
text: turnInput.message.text,
attachments: turnInput.message.attachments,
- attachmentsDir: serverConfig.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
});
const text = t3AcpPromptWithInstructions({
prompt: messageText,
diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
index 0b33327b185..50fab3e191d 100644
--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
@@ -112,7 +112,7 @@ import {
import type { ServerProviderShape } from "@t3tools/provider-core/server/snapshot";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
import { T3_CODE_ORCHESTRATION_INSTRUCTIONS } from "@t3tools/provider-core/server/orchestrationInstructions";
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import {
mcpToolPresentation,
normalizeMcpText,
@@ -124,14 +124,17 @@ import {
makeProviderRetryTurnItem,
} from "@t3tools/provider-core/server/failure";
import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
-import { providerMessageTextWithAttachmentPaths } from "../AttachmentPrompt.ts";
+import { providerMessageTextWithAttachmentPaths } from "@t3tools/provider-core/server/attachmentPrompt";
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
import {
ProviderAdapterDriverCreateError,
type ProviderAdapterDriver,
type ProviderAdapterDriverCreateInput,
} from "@t3tools/provider-core/server/adapterDriver";
-import { type BackgroundWorkReport, backgroundWorkNotification } from "../Notification.ts";
+import {
+ type BackgroundWorkReport,
+ backgroundWorkNotification,
+} from "@t3tools/provider-core/server/notification";
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
import {
makeSubagentChildThread,
@@ -1344,7 +1347,8 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
const textWithAttachmentPaths = providerMessageTextWithAttachmentPaths({
text: input.text,
attachments: input.attachments,
- attachmentsDir: input.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({ attachmentsDir: input.attachmentsDir, attachment }),
});
const dispatch =
diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
index 660e690b588..5318971e89d 100644
--- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
@@ -126,7 +126,7 @@ import {
type ProviderContinuationRequest,
ProviderContinuationRequests,
} from "@t3tools/provider-core/server/continuationRequests";
-import { backgroundWorkNotification } from "../Notification.ts";
+import { backgroundWorkNotification } from "@t3tools/provider-core/server/notification";
import {
makeProviderFailure,
makeProviderFailureTurnItem,
@@ -136,7 +136,7 @@ import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/sel
import {
isProviderNativeImageAttachment,
providerMessageTextWithAttachmentPaths,
-} from "../AttachmentPrompt.ts";
+} from "@t3tools/provider-core/server/attachmentPrompt";
import {
ProviderAdapterEnsureThreadError,
ProviderAdapterForkThreadError,
@@ -3150,7 +3150,8 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi
const text = providerMessageTextWithAttachmentPaths({
text: codexSkillMentionText(turnInput.message.text),
attachments: turnInput.message.attachments,
- attachmentsDir: serverConfig.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
});
if (text.length > 0) {
inputItems.push({
diff --git a/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.ts
index 077cb6ead33..53a1d260cc8 100644
--- a/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.ts
+++ b/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.ts
@@ -55,14 +55,14 @@ import {
} from "../../provider/Drivers/CursorSkills.ts";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
import { t3OrchestrationPromptForFirstRun } from "@t3tools/provider-core/server/orchestrationInstructions";
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
import {
isProviderNativeImageAttachment,
providerMessageTextWithAttachmentPaths,
-} from "../AttachmentPrompt.ts";
+} from "@t3tools/provider-core/server/attachmentPrompt";
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
import {
ProviderAdapterDriverCreateError,
@@ -2133,7 +2133,8 @@ export function makeCursorAdapterV2(
? rawText
: rewriteCursorSkillMentions(rawText, cursorSkillNames),
attachments: turnInput.message.attachments,
- attachmentsDir: serverConfig.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
}),
runOrdinal: turnInput.runOrdinal,
hasT3Mcp: cursorMcpServers(turnInput.threadId) !== undefined,
diff --git a/apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.ts
index b68f90c60a6..30d7073463a 100644
--- a/apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.ts
+++ b/apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.ts
@@ -38,7 +38,7 @@ import * as Stream from "effect/Stream";
import { resolveAttachmentPath } from "../../attachmentStore.ts";
import * as ServerConfig from "../../config.ts";
import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import {
museModelCapabilities,
resolveMuseReasoningEffort,
@@ -71,7 +71,7 @@ import type { EventNdjsonLogger } from "../../provider/EventNdjsonLogger.ts";
import {
providerMessageTextWithAttachmentPaths,
isProviderNativeImageAttachment,
-} from "../AttachmentPrompt.ts";
+} from "@t3tools/provider-core/server/attachmentPrompt";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
import {
ProviderAdapterEnsureThreadError,
@@ -96,7 +96,10 @@ import {
type ProviderAdapterV2TurnInput,
type ProviderAdapterV2TurnMessage,
} from "@t3tools/provider-core/server/ProviderAdapter";
-import { backgroundWorkNotification, type BackgroundWorkReport } from "../Notification.ts";
+import {
+ backgroundWorkNotification,
+ type BackgroundWorkReport,
+} from "@t3tools/provider-core/server/notification";
import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
@@ -1598,7 +1601,11 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
const text = providerMessageTextWithAttachmentPaths({
text: message.text,
attachments: message.attachments,
- attachmentsDir: options.serverConfig.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({
+ attachmentsDir: options.serverConfig.attachmentsDir,
+ attachment,
+ }),
});
if (text) parts.push({ type: "text", text });
for (const attachment of message.attachments)
diff --git a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts
index 5806fc5fb68..6bc194b811a 100644
--- a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts
+++ b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts
@@ -70,6 +70,7 @@ import * as Schema from "effect/Schema";
import * as Semaphore from "effect/Semaphore";
import * as Stream from "effect/Stream";
+import { resolveAttachmentPath } from "../../attachmentStore.ts";
import * as ServerConfig from "../../config.ts";
import { paginate, type OpenCode2StreamEvent } from "../../provider/opencode2/OpenCode2Client.ts";
import * as OpenCode2Server from "../../provider/opencode2/OpenCode2Server.ts";
@@ -78,16 +79,19 @@ import {
type OpenCodeRuntimeError,
} from "../../provider/opencodeRuntime.ts";
import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import { t3OrchestrationSystemPrompt } from "@t3tools/provider-core/server/orchestrationInstructions";
import { SKILL_MENTION_PATTERN } from "@t3tools/shared/composerInlineTokens";
import * as KeyedLock from "@t3tools/shared/KeyedLock";
import { getModelSelectionStringOptionValue, modelSelectionsEqual } from "@t3tools/shared/model";
import { causeErrorTag } from "@t3tools/shared/observability";
-import { providerMessageTextWithAttachmentPaths } from "../AttachmentPrompt.ts";
+import { providerMessageTextWithAttachmentPaths } from "@t3tools/provider-core/server/attachmentPrompt";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
-import { backgroundWorkNotification, type BackgroundWorkReport } from "../Notification.ts";
+import {
+ backgroundWorkNotification,
+ type BackgroundWorkReport,
+} from "@t3tools/provider-core/server/notification";
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
import {
@@ -3212,7 +3216,8 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
providerMessageTextWithAttachmentPaths({
text: turnInput.message.text,
attachments: turnInput.message.attachments,
- attachmentsDir: serverConfig.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
}).trim();
const removeMcp = (mcp: { readonly name: string; readonly directory: string }) =>
@@ -3893,7 +3898,11 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
text: providerMessageTextWithAttachmentPaths({
text: steerInput.message.text,
attachments: steerInput.message.attachments,
- attachmentsDir: serverConfig.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({
+ attachmentsDir: serverConfig.attachmentsDir,
+ attachment,
+ }),
}).trim(),
delivery: "steer",
})
diff --git a/apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.ts
index 8b3216fbaaa..c746bec2180 100644
--- a/apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.ts
+++ b/apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.ts
@@ -66,12 +66,12 @@ import {
} from "../../provider/NativeProtocolLogging.ts";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
import { t3OrchestrationSystemPrompt } from "@t3tools/provider-core/server/orchestrationInstructions";
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import * as OpenCodeRuntime from "../../provider/opencodeRuntime.ts";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
-import { providerMessageTextWithAttachmentPaths } from "../AttachmentPrompt.ts";
+import { providerMessageTextWithAttachmentPaths } from "@t3tools/provider-core/server/attachmentPrompt";
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
import {
ProviderAdapterDriverCreateError,
@@ -2853,7 +2853,8 @@ export function makeOpenCodeAdapterV2(
const text = providerMessageTextWithAttachmentPaths({
text: turnInput.message.text,
attachments: turnInput.message.attachments,
- attachmentsDir: serverConfig.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
}).trim();
const files = OpenCodeRuntime.toOpenCodeFileParts({
attachments: turnInput.message.attachments,
@@ -3356,7 +3357,11 @@ export function makeOpenCodeAdapterV2(
const text = providerMessageTextWithAttachmentPaths({
text: steerInput.message.text,
attachments: steerInput.message.attachments,
- attachmentsDir: serverConfig.attachmentsDir,
+ resolveAttachmentPath: (attachment) =>
+ resolveAttachmentPath({
+ attachmentsDir: serverConfig.attachmentsDir,
+ attachment,
+ }),
}).trim();
const files = OpenCodeRuntime.toOpenCodeFileParts({
attachments: steerInput.message.attachments,
diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts
index a2e45ed21c5..54127e20bc7 100644
--- a/apps/server/src/orchestration-v2/Orchestrator.ts
+++ b/apps/server/src/orchestration-v2/Orchestrator.ts
@@ -85,7 +85,7 @@ import { CheckpointServiceV2 } from "./CheckpointService.ts";
import { CommandPolicyV2, resolveMessageDispatchIntent } from "./CommandPolicy.ts";
import { CommandReceiptStoreV2 } from "./CommandReceiptStore.ts";
import { ContextHandoffServiceV2 } from "./ContextHandoffService.ts";
-import { notificationTurnItem } from "./Notification.ts";
+import { notificationTurnItem } from "@t3tools/provider-core/server/notification";
import { isRestartNoteSource } from "./RestartBackgroundNote.ts";
import { isUndeliveredMailboxSteer } from "./NotificationMailbox.ts";
import { EventSinkV2 } from "./EventSink.ts";
diff --git a/apps/server/src/orchestration-v2/testkit/ReplayRuntimeInstructions.ts b/apps/server/src/orchestration-v2/testkit/ReplayRuntimeInstructions.ts
index 18f87d1f7a4..31fa33f055d 100644
--- a/apps/server/src/orchestration-v2/testkit/ReplayRuntimeInstructions.ts
+++ b/apps/server/src/orchestration-v2/testkit/ReplayRuntimeInstructions.ts
@@ -1,6 +1,6 @@
import type { ProviderDriverKind, ProviderReplayTranscript } from "@t3tools/contracts";
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
/** Adds current runtime context to legacy prompt expectations, keeping outbound matching exact. */
export function materializeReplayTranscriptRuntimeInstructions(
diff --git a/apps/server/src/provider/CodexDeveloperInstructions.ts b/apps/server/src/provider/CodexDeveloperInstructions.ts
index e9cbe27997a..f80aefe98a7 100644
--- a/apps/server/src/provider/CodexDeveloperInstructions.ts
+++ b/apps/server/src/provider/CodexDeveloperInstructions.ts
@@ -1,6 +1,6 @@
import type { ProviderInteractionMode } from "@t3tools/contracts";
import type { V2TurnStartParams__AdditionalContextEntry } from "effect-codex-app-server/schema";
-import { buildRuntimeInstructions } from "./RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import {
T3_CODE_BROWSER_TOOL_INSTRUCTIONS,
diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.ts b/apps/server/src/provider/Drivers/AntigravityDriver.ts
index 238834f63a1..f354dc4b4aa 100644
--- a/apps/server/src/provider/Drivers/AntigravityDriver.ts
+++ b/apps/server/src/provider/Drivers/AntigravityDriver.ts
@@ -60,7 +60,7 @@ import {
type ProviderInstance,
} from "@t3tools/provider-core/server/driver";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
-import { withInstanceIdentity } from "./instanceIdentity.ts";
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
import { discoverAntigravitySkills, resolveAntigravityUserHome } from "./AntigravitySkills.ts";
const DRIVER = ProviderDriverKind.make("antigravity");
diff --git a/apps/server/src/provider/Drivers/ClaudeDriver.ts b/apps/server/src/provider/Drivers/ClaudeDriver.ts
index ab9e6d2e8f2..aea45e37cb9 100644
--- a/apps/server/src/provider/Drivers/ClaudeDriver.ts
+++ b/apps/server/src/provider/Drivers/ClaudeDriver.ts
@@ -50,7 +50,7 @@ import {
type ProviderDriver,
type ProviderInstance,
} from "@t3tools/provider-core/server/driver";
-import { withInstanceIdentity } from "./instanceIdentity.ts";
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
import {
enrichProviderSnapshotWithVersionAdvisory,
diff --git a/apps/server/src/provider/Drivers/CodexDriver.ts b/apps/server/src/provider/Drivers/CodexDriver.ts
index 0d6da5a5dea..b007785a6e8 100644
--- a/apps/server/src/provider/Drivers/CodexDriver.ts
+++ b/apps/server/src/provider/Drivers/CodexDriver.ts
@@ -51,7 +51,7 @@ import { resolveCodexLaunchArgs } from "../codexLaunchArgs.ts";
import { makeManagedServerProvider } from "@t3tools/provider-core/server/managedProvider";
import * as ModelManifest from "../ModelManifest.ts";
import type { ProviderDriver, ProviderInstance } from "@t3tools/provider-core/server/driver";
-import { withInstanceIdentity } from "./instanceIdentity.ts";
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
import {
enrichProviderSnapshotWithVersionAdvisory,
diff --git a/apps/server/src/provider/Drivers/CodexManagedProvider.ts b/apps/server/src/provider/Drivers/CodexManagedProvider.ts
index b7c12ff3391..32d88e64487 100644
--- a/apps/server/src/provider/Drivers/CodexManagedProvider.ts
+++ b/apps/server/src/provider/Drivers/CodexManagedProvider.ts
@@ -21,7 +21,7 @@ import {
type ProviderInstance,
} from "@t3tools/provider-core/server/driver";
import { codexContinuationIdentity } from "./CodexHomeLayout.ts";
-import { withInstanceIdentity } from "./instanceIdentity.ts";
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
import { HttpClient } from "effect/http";
const DRIVER = ProviderDriverKind.make("codex");
diff --git a/apps/server/src/provider/Drivers/CursorDriver.ts b/apps/server/src/provider/Drivers/CursorDriver.ts
index 21bc7a0b7af..cf4d82bcfdb 100644
--- a/apps/server/src/provider/Drivers/CursorDriver.ts
+++ b/apps/server/src/provider/Drivers/CursorDriver.ts
@@ -35,7 +35,7 @@ import {
type ProviderDriver,
type ProviderInstance,
} from "@t3tools/provider-core/server/driver";
-import { withInstanceIdentity } from "./instanceIdentity.ts";
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
import { makeManualOnlyProviderMaintenanceCapabilities } from "@t3tools/provider-core/server/maintenanceResolver";
import {
diff --git a/apps/server/src/provider/Drivers/GrokDriver.ts b/apps/server/src/provider/Drivers/GrokDriver.ts
index 5962c724826..f7226d5f1e9 100644
--- a/apps/server/src/provider/Drivers/GrokDriver.ts
+++ b/apps/server/src/provider/Drivers/GrokDriver.ts
@@ -28,7 +28,7 @@ import {
type ProviderDriver,
type ProviderInstance,
} from "@t3tools/provider-core/server/driver";
-import { withInstanceIdentity } from "./instanceIdentity.ts";
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
import { discoverGrokSkills } from "./GrokSkills.ts";
import {
diff --git a/apps/server/src/provider/Drivers/MuseDriver.ts b/apps/server/src/provider/Drivers/MuseDriver.ts
index e22b22ab0de..16bed1c3dab 100644
--- a/apps/server/src/provider/Drivers/MuseDriver.ts
+++ b/apps/server/src/provider/Drivers/MuseDriver.ts
@@ -35,7 +35,7 @@ import {
makeProviderSnapshotSettingsSource,
type ProviderSnapshotSettings,
} from "@t3tools/provider-core/server/snapshotSettings";
-import { withInstanceIdentity } from "./instanceIdentity.ts";
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
const DRIVER_KIND = ProviderDriverKind.make("muse");
const decodeMuseSettings = Schema.decodeSync(MuseSettings);
diff --git a/apps/server/src/provider/Drivers/OpenCodeDriver.ts b/apps/server/src/provider/Drivers/OpenCodeDriver.ts
index 76a9dcdc7b7..83347d86a87 100644
--- a/apps/server/src/provider/Drivers/OpenCodeDriver.ts
+++ b/apps/server/src/provider/Drivers/OpenCodeDriver.ts
@@ -59,7 +59,7 @@ import {
type ProviderDriver,
type ProviderInstance,
} from "@t3tools/provider-core/server/driver";
-import { withInstanceIdentity } from "./instanceIdentity.ts";
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
import {
enrichProviderSnapshotWithVersionAdvisory,
diff --git a/apps/server/src/provider/EventNdjsonLogger.ts b/apps/server/src/provider/EventNdjsonLogger.ts
index 491119c3cdf..1ec5c46d932 100644
--- a/apps/server/src/provider/EventNdjsonLogger.ts
+++ b/apps/server/src/provider/EventNdjsonLogger.ts
@@ -9,6 +9,7 @@ import * as NodeFS from "node:fs";
import * as NodePath from "node:path";
import type { ThreadId } from "@t3tools/contracts";
+import type { EventNdjsonLogger } from "@t3tools/provider-core/server/ProviderEventLoggers";
import { RotatingFileSink } from "@t3tools/shared/logging";
import { errorTag } from "@t3tools/shared/observability";
import * as Clock from "effect/Clock";
@@ -63,11 +64,7 @@ const transientAcpUpdates = new Set(["agent_message_chunk", "agent_thought_chunk
export type EventNdjsonStream = "native" | "canonical" | "orchestration";
-export interface EventNdjsonLogger {
- readonly filePath: string;
- readonly write: (event: unknown, threadId: ThreadId | null) => Effect.Effect<void>;
- readonly close: () => Effect.Effect<void>;
-}
+export type { EventNdjsonLogger };
export interface EventNdjsonLogStore {
readonly filePath: string;
diff --git a/apps/server/src/provider/ProviderEventLoggers.ts b/apps/server/src/provider/ProviderEventLoggers.ts
index 1cb96058d3b..b31acbef952 100644
--- a/apps/server/src/provider/ProviderEventLoggers.ts
+++ b/apps/server/src/provider/ProviderEventLoggers.ts
@@ -24,39 +24,18 @@
*
* @module provider/ProviderEventLoggers
*/
-import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as ServerConfig from "../config.ts";
import * as ResourceAttribution from "../resourceTelemetry/ResourceAttribution.ts";
-import * as EventNdjsonLogger from "./EventNdjsonLogger.ts";
-
-/**
- * Shared logger pair for native + canonical provider event streams.
- *
- * Service value is intentionally a struct of two optional loggers rather
- * than two parallel tags. Construction site is one place
- * (`layer`); consumers (drivers, `ProviderService`) read one tag and pluck the
- * field they need.
- */
-export class ProviderEventLoggers extends Context.Service<
+import {
+ NoOpProviderEventLoggers,
ProviderEventLoggers,
- {
- readonly native: EventNdjsonLogger.EventNdjsonLogger | undefined;
- readonly canonical: EventNdjsonLogger.EventNdjsonLogger | undefined;
- }
->()("t3/provider/ProviderEventLoggers") {}
+} from "@t3tools/provider-core/server/ProviderEventLoggers";
+import * as EventNdjsonLogger from "./EventNdjsonLogger.ts";
-/**
- * Constant value used by tests / boot layers that want to opt out of native
- * + canonical logging entirely. Keeps the tag non-optional in the type
- * system while letting the runtime treat absence as a no-op.
- */
-export const NoOpProviderEventLoggers: ProviderEventLoggers["Service"] = {
- native: undefined,
- canonical: undefined,
-};
+export { NoOpProviderEventLoggers, ProviderEventLoggers };
/**
* Builds both stream views over one shared store. Setup failures are logged
diff --git a/packages/provider-core/package.json b/packages/provider-core/package.json
index 073faf38144..fa21d1f2efe 100644
--- a/packages/provider-core/package.json
+++ b/packages/provider-core/package.json
@@ -11,6 +11,10 @@
"types": "./src/server/adapterDriver.ts",
"import": "./src/server/adapterDriver.ts"
},
+ "./server/attachmentPrompt": {
+ "types": "./src/server/attachmentPrompt.ts",
+ "import": "./src/server/attachmentPrompt.ts"
+ },
"./server/auth": {
"types": "./src/server/auth.ts",
"import": "./src/server/auth.ts"
@@ -47,6 +51,10 @@
"types": "./src/server/instanceEnvironment.ts",
"import": "./src/server/instanceEnvironment.ts"
},
+ "./server/instanceIdentity": {
+ "types": "./src/server/instanceIdentity.ts",
+ "import": "./src/server/instanceIdentity.ts"
+ },
"./server/maintenance": {
"types": "./src/server/maintenance.ts",
"import": "./src/server/maintenance.ts"
@@ -67,6 +75,10 @@
"types": "./src/server/mcpToolPresentation.ts",
"import": "./src/server/mcpToolPresentation.ts"
},
+ "./server/notification": {
+ "types": "./src/server/notification.ts",
+ "import": "./src/server/notification.ts"
+ },
"./server/orchestrationInstructions": {
"types": "./src/server/orchestrationInstructions.ts",
"import": "./src/server/orchestrationInstructions.ts"
@@ -83,6 +95,10 @@
"types": "./src/server/ProviderAdapter.ts",
"import": "./src/server/ProviderAdapter.ts"
},
+ "./server/ProviderEventLoggers": {
+ "types": "./src/server/ProviderEventLoggers.ts",
+ "import": "./src/server/ProviderEventLoggers.ts"
+ },
"./server/ProviderHost": {
"types": "./src/server/ProviderHost.ts",
"import": "./src/server/ProviderHost.ts"
@@ -91,6 +107,10 @@
"types": "./src/server/randomUuid.ts",
"import": "./src/server/randomUuid.ts"
},
+ "./server/runtimeInstructions": {
+ "types": "./src/server/runtimeInstructions.ts",
+ "import": "./src/server/runtimeInstructions.ts"
+ },
"./server/selectionTransition": {
"types": "./src/server/selectionTransition.ts",
"import": "./src/server/selectionTransition.ts"
diff --git a/packages/provider-core/src/server/ProviderEventLoggers.ts b/packages/provider-core/src/server/ProviderEventLoggers.ts
new file mode 100644
index 00000000000..6341bd96af1
--- /dev/null
+++ b/packages/provider-core/src/server/ProviderEventLoggers.ts
@@ -0,0 +1,30 @@
+/**
+ * Provider event logging as the server offers it to drivers: one stream for
+ * the provider's native protocol frames and one for canonical orchestration
+ * events. Either logger is absent when diagnostics logging could not start.
+ *
+ * @module provider-core/server/ProviderEventLoggers
+ */
+import type { ThreadId } from "@t3tools/contracts";
+import * as Context from "effect/Context";
+import type * as Effect from "effect/Effect";
+
+export interface EventNdjsonLogger {
+ readonly filePath: string;
+ readonly write: (event: unknown, threadId: ThreadId | null) => Effect.Effect<void>;
+ readonly close: () => Effect.Effect<void>;
+}
+
+export class ProviderEventLoggers extends Context.Service<
+ ProviderEventLoggers,
+ {
+ readonly native: EventNdjsonLogger | undefined;
+ readonly canonical: EventNdjsonLogger | undefined;
+ }
+>()("@t3tools/provider-core/server/ProviderEventLoggers") {}
+
+/** Logging turned off: for tests and boot layers that skip diagnostics. */
+export const NoOpProviderEventLoggers: ProviderEventLoggers["Service"] = {
+ native: undefined,
+ canonical: undefined,
+};
diff --git a/apps/server/src/orchestration-v2/AttachmentPrompt.test.ts b/packages/provider-core/src/server/attachmentPrompt.test.ts
similarity index 92%
rename from apps/server/src/orchestration-v2/AttachmentPrompt.test.ts
rename to packages/provider-core/src/server/attachmentPrompt.test.ts
index 03c35bd4ef9..e31c8417f20 100644
--- a/apps/server/src/orchestration-v2/AttachmentPrompt.test.ts
+++ b/packages/provider-core/src/server/attachmentPrompt.test.ts
@@ -9,7 +9,7 @@ import { assert, describe, it } from "@effect/vitest";
import {
isProviderNativeImageAttachment,
providerMessageTextWithAttachmentPaths,
-} from "./AttachmentPrompt.ts";
+} from "./attachmentPrompt.ts";
const document = ChatFileAttachment.make({
id: ChatAttachmentId.make("file-document"),
@@ -26,13 +26,17 @@ const image = ChatImageAttachment.make({
sizeBytes: 456,
});
+// Stands in for the host's resolver, which maps stored attachments to their files.
+const resolveAttachmentPath = (attachment: { readonly id: string; readonly name: string }) =>
+ `/attachments/${attachment.id}${attachment.name.slice(attachment.name.lastIndexOf("."))}`;
+
describe("provider attachment prompts", () => {
it("appends resolvable file paths for documents and images", () => {
assert.equal(
providerMessageTextWithAttachmentPaths({
text: "Review these.",
attachments: [document, image],
- attachmentsDir: "/attachments",
+ resolveAttachmentPath,
}),
'Review these.\n\n[Attached file "spec.pdf" is saved at: /attachments/file-document.pdf]\n' +
'\n[Attached image "diagram.png" is saved at: /attachments/file-image.png]',
@@ -53,7 +57,7 @@ describe("provider attachment prompts", () => {
const text = providerMessageTextWithAttachmentPaths({
text: "Fix this.",
attachments: [captured],
- attachmentsDir: "/attachments",
+ resolveAttachmentPath,
});
assert.include(
@@ -103,7 +107,7 @@ describe("provider attachment prompts", () => {
const text = providerMessageTextWithAttachmentPaths({
text: "Describe this.",
attachments: [captured],
- attachmentsDir: "/attachments",
+ resolveAttachmentPath,
});
assert.include(
@@ -133,7 +137,7 @@ describe("provider attachment prompts", () => {
const text = providerMessageTextWithAttachmentPaths({
text: "Fix this.",
attachments,
- attachmentsDir: "/attachments",
+ resolveAttachmentPath,
});
assert.isAtMost(text.length, PROVIDER_SEND_TURN_MAX_INPUT_CHARS);
diff --git a/apps/server/src/orchestration-v2/AttachmentPrompt.ts b/packages/provider-core/src/server/attachmentPrompt.ts
similarity index 96%
rename from apps/server/src/orchestration-v2/AttachmentPrompt.ts
rename to packages/provider-core/src/server/attachmentPrompt.ts
index 7189ccf763f..1b09911f50d 100644
--- a/apps/server/src/orchestration-v2/AttachmentPrompt.ts
+++ b/packages/provider-core/src/server/attachmentPrompt.ts
@@ -8,8 +8,6 @@ import {
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";
-import { resolveAttachmentPath } from "../attachmentStore.ts";
-
const encodePromptJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
interface SnapShotPromptAccessibilityNode {
@@ -161,7 +159,8 @@ export function isProviderNativeImageAttachment(attachment: ChatAttachment): boo
export function providerMessageTextWithAttachmentPaths(input: {
readonly text: string;
readonly attachments: ReadonlyArray<ChatAttachment>;
- readonly attachmentsDir: string;
+ /** Absolute path of a stored attachment, such as `ProviderHost.resolveAttachmentPath`. */
+ readonly resolveAttachmentPath: (attachment: ChatAttachment) => string | null;
}): string {
let text = input.text;
const appendContext = (context: string | undefined) => {
@@ -171,10 +170,7 @@ export function providerMessageTextWithAttachmentPaths(input: {
};
for (const attachment of input.attachments) {
- const path = resolveAttachmentPath({
- attachmentsDir: input.attachmentsDir,
- attachment,
- });
+ const path = input.resolveAttachmentPath(attachment);
appendContext(
path === null
? undefined
diff --git a/apps/server/src/provider/Drivers/instanceIdentity.ts b/packages/provider-core/src/server/instanceIdentity.ts
similarity index 100%
rename from apps/server/src/provider/Drivers/instanceIdentity.ts
rename to packages/provider-core/src/server/instanceIdentity.ts
diff --git a/apps/server/src/orchestration-v2/Notification.test.ts b/packages/provider-core/src/server/notification.test.ts
similarity index 99%
rename from apps/server/src/orchestration-v2/Notification.test.ts
rename to packages/provider-core/src/server/notification.test.ts
index 197587a786e..a67cab6b7e2 100644
--- a/apps/server/src/orchestration-v2/Notification.test.ts
+++ b/packages/provider-core/src/server/notification.test.ts
@@ -10,7 +10,7 @@ import {
} from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
-import { backgroundWorkNotification, notificationTurnItem } from "./Notification.ts";
+import { backgroundWorkNotification, notificationTurnItem } from "./notification.ts";
const childThreadId = ThreadId.make("thread:child");
diff --git a/apps/server/src/orchestration-v2/Notification.ts b/packages/provider-core/src/server/notification.ts
similarity index 100%
rename from apps/server/src/orchestration-v2/Notification.ts
rename to packages/provider-core/src/server/notification.ts
diff --git a/apps/server/src/provider/RuntimeInstructions.test.ts b/packages/provider-core/src/server/runtimeInstructions.test.ts
similarity index 96%
rename from apps/server/src/provider/RuntimeInstructions.test.ts
rename to packages/provider-core/src/server/runtimeInstructions.test.ts
index 10f8413b5a1..6ad3b027e04 100644
--- a/apps/server/src/provider/RuntimeInstructions.test.ts
+++ b/packages/provider-core/src/server/runtimeInstructions.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vite-plus/test";
-import { buildRuntimeInstructions } from "./RuntimeInstructions.ts";
+import { buildRuntimeInstructions } from "./runtimeInstructions.ts";
describe("buildRuntimeInstructions", () => {
it("requires explicit registration of every PR and stack layer", () => {
diff --git a/apps/server/src/provider/RuntimeInstructions.ts b/packages/provider-core/src/server/runtimeInstructions.ts
similarity index 100%
rename from apps/server/src/provider/RuntimeInstructions.ts
rename to packages/provider-core/src/server/runtimeInstructions.ts