Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/server/src/provider/openrouter/OpenRouterRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,37 @@ describe("withOpenRouterAdapterIdentity", () => {
expect(listed.map((entry) => entry.provider)).toEqual([OPENROUTER_DRIVER_KIND]);
}),
);

it.effect("hands the wrapped adapter its own provider on startSession input", () =>
Effect.gen(function* () {
const claudeKind = ProviderDriverKind.make("claudeAgent");
const seen: Array<unknown> = [];
const base = {
provider: claudeKind,
streamEvents: Stream.empty,
startSession: (input: { provider?: string }) => {
seen.push(input.provider);
// Mirrors ClaudeAdapter, which rejects a foreign provider outright.
return input.provider !== undefined && input.provider !== claudeKind
? Effect.die(`Expected provider '${claudeKind}' but received '${input.provider}'.`)
: Effect.succeed({ provider: claudeKind, threadId: "thread-1" });
},
listSessions: () => Effect.succeed([]),
} as unknown as ProviderAdapterShape<never>;

const decorated = withOpenRouterAdapterIdentity(base);

const started = yield* decorated.startSession({
provider: OPENROUTER_DRIVER_KIND,
threadId: "thread-1",
} as never) as Effect.Effect<{ provider: string }>;

expect(seen).toEqual([claudeKind]);
expect(started.provider).toBe(OPENROUTER_DRIVER_KIND);

// An input with no provider stays untouched.
yield* decorated.startSession({ threadId: "thread-2" } as never);
expect(seen).toEqual([claudeKind, undefined]);
}),
);
});
11 changes: 10 additions & 1 deletion apps/server/src/provider/openrouter/OpenRouterRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,16 @@ export function withOpenRouterAdapterIdentity<E>(
...event,
provider: OPENROUTER_DRIVER_KIND,
})),
startSession: (input) => Effect.map(adapter.startSession(input), restampSession),
// Orchestration addresses this adapter as `openrouter`, but the wrapped
// Claude adapter rejects any `startSession` input whose provider is not
// its own kind. Translate on the way in, restamp on the way out.
startSession: (input) =>
Effect.map(
adapter.startSession(
input.provider === undefined ? input : { ...input, provider: adapter.provider },
),
restampSession,
),
listSessions: () =>
Effect.map(adapter.listSessions(), (sessions) => sessions.map(restampSession)),
};
Expand Down
Loading