refactor(provider-core): share attachment prompts, notifications, and event loggers (#17330)
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
d81afa0a6f
commit
e38b6a188f
30 files changed
+138
-84
No files matched your search
@@ -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));
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
NoOpProviderEventLoggers,
|
||||
ProviderEventLoggers,
|
||||
} from "@t3tools/provider-core/server/ProviderEventLoggers";
|
||||
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<
|
||||
ProviderEventLoggers,
|
||||
{
|
||||
readonly native: EventNdjsonLogger.EventNdjsonLogger | undefined;
|
||||
readonly canonical: EventNdjsonLogger.EventNdjsonLogger | undefined;
|
||||
}
|
||||
>()("t3/provider/ProviderEventLoggers") {}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
+9
-5
@@ -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);
|
||||
+3
-7
@@ -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
|
||||
File renamed without changes.
+1
-1
@@ -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");
|
||||
|
||||
File renamed without changes.
+1
-1
@@ -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", () => {
|
||||
File renamed without changes.
Reference in new issue
Block a user