fix(core): add session correlation header (#36842)
Co-authored-by: Dustin Deus <deusdustin@gmail.com>
This commit is contained in:
parent
9b8282ad3d
commit
aa8fc4234d
3 changed files with 26 additions and 2 deletions
|
|
@ -51,6 +51,7 @@ import { AgentNotFoundError, StepFailedError } from "../error"
|
||||||
import { toSessionError } from "../to-session-error"
|
import { toSessionError } from "../to-session-error"
|
||||||
import { SessionRunnerRetry } from "./retry"
|
import { SessionRunnerRetry } from "./retry"
|
||||||
import { PluginSupervisor } from "../../plugin/supervisor"
|
import { PluginSupervisor } from "../../plugin/supervisor"
|
||||||
|
import { Flag } from "../../flag/flag"
|
||||||
|
|
||||||
type StepTokens = {
|
type StepTokens = {
|
||||||
readonly input: number
|
readonly input: number
|
||||||
|
|
@ -197,6 +198,13 @@ const layer = Layer.effect(
|
||||||
const promptCacheKey = /^ses_[0-9a-f]{64}$/.test(session.id) ? session.id.slice(4) : session.id
|
const promptCacheKey = /^ses_[0-9a-f]{64}$/.test(session.id) ? session.id.slice(4) : session.id
|
||||||
const request = LLM.request({
|
const request = LLM.request({
|
||||||
model,
|
model,
|
||||||
|
http: {
|
||||||
|
headers: {
|
||||||
|
"x-opencode-project": session.projectID,
|
||||||
|
"x-opencode-session": session.id,
|
||||||
|
"x-opencode-client": Flag.OPENCODE_CLIENT,
|
||||||
|
},
|
||||||
|
},
|
||||||
providerOptions: { openai: { promptCacheKey } },
|
providerOptions: { openai: { promptCacheKey } },
|
||||||
system: [agentInfo.system ? agentInfo.system : SessionRunnerSystemPrompt.provider(model), history.initial]
|
system: [agentInfo.system ? agentInfo.system : SessionRunnerSystemPrompt.provider(model), history.initial]
|
||||||
.filter((part): part is string => part !== undefined && part.length > 0)
|
.filter((part): part is string => part !== undefined && part.length > 0)
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
||||||
import { LayerNodePlatform } from "@opencode-ai/core/effect/app-node-platform"
|
import { LayerNodePlatform } from "@opencode-ai/core/effect/app-node-platform"
|
||||||
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
||||||
import { EventV2 } from "@opencode-ai/core/event"
|
import { EventV2 } from "@opencode-ai/core/event"
|
||||||
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||||
import { PermissionV2 } from "@opencode-ai/core/permission"
|
import { PermissionV2 } from "@opencode-ai/core/permission"
|
||||||
import { EventTable } from "@opencode-ai/core/event/sql"
|
import { EventTable } from "@opencode-ai/core/event/sql"
|
||||||
import { Project } from "@opencode-ai/core/project"
|
import { Project } from "@opencode-ai/core/project"
|
||||||
|
|
@ -3043,6 +3044,21 @@ describe("SessionRunnerLLM", () => {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
it.effect("adds session correlation headers to model requests", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const session = yield* setup
|
||||||
|
yield* admit(session, "Run correlated request")
|
||||||
|
|
||||||
|
yield* session.resume(sessionID)
|
||||||
|
|
||||||
|
expect(requests[0]?.http?.headers).toEqual({
|
||||||
|
"x-opencode-project": Project.ID.global,
|
||||||
|
"x-opencode-session": sessionID,
|
||||||
|
"x-opencode-client": Flag.OPENCODE_CLIENT,
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
it.effect("runs different sessions concurrently", () =>
|
it.effect("runs different sessions concurrently", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const session = yield* setup
|
const session = yield* setup
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import type {
|
||||||
SkillInfo,
|
SkillInfo,
|
||||||
OpenCodeEvent,
|
OpenCodeEvent,
|
||||||
} from "@opencode-ai/client"
|
} from "@opencode-ai/client"
|
||||||
import type { Data } from "@opencode-ai/plugin/v2/tui/context"
|
import type { Plugin } from "@opencode-ai/plugin/v2/tui"
|
||||||
import { createStore, produce, reconcile } from "solid-js/store"
|
import { createStore, produce, reconcile } from "solid-js/store"
|
||||||
import { createSimpleContext } from "./helper"
|
import { createSimpleContext } from "./helper"
|
||||||
import { useClient } from "./client"
|
import { useClient } from "./client"
|
||||||
|
|
@ -1108,7 +1108,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
result satisfies Data
|
result satisfies Plugin.Context["data"]
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
if (bootstrapping) return bootstrapping
|
if (bootstrapping) return bootstrapping
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue