Skip to content

feat(provider): forward sessionOptions (systemPrompt, model, allowedTools, maxTurns) to runtime#23

Draft
DaniAkash wants to merge 1 commit into
mainfrom
feat/provider-session-options
Draft

feat(provider): forward sessionOptions (systemPrompt, model, allowedTools, maxTurns) to runtime#23
DaniAkash wants to merge 1 commit into
mainfrom
feat/provider-session-options

Conversation

@DaniAkash
Copy link
Copy Markdown
Owner

⚠️ Draft — waiting on upstream

This PR is pre-implementation against the documented upstream shape. It will not pass typecheck until openclaw/acpx#309 merges and a corresponding acpx release ships (expected as 0.8.0 based on the documented type signatures, matching the version assumed by #17 and #19).

Do not mark ready / merge until:

  1. feat(runtime): accept sessionOptions on ensureSession openclaw/acpx#309 is merged.
  2. acpx@0.8.0 (or whatever version lands the sessionOptions field) is published to npm.
  3. Locally: bun install resolves the new acpx, then bun run typecheck passes — confirming upstream's published types match the documented shape.
  4. Verified the published runtime.d.ts exposes sessionOptions?: SessionAgentOptions on AcpRuntimeEnsureInput plus the SessionAgentOptions + SystemPromptOption re-exports. If upstream renamed during review, update src/types.ts, src/provider.ts, and src/index.ts to match.

Summary

Hosts can now set a per-session systemPrompt (or model / allowedTools / maxTurns) on a fresh ACP session through the provider — no need to bypass the runtime.

```ts
const provider = createAcpxProvider({
agent: 'claude',
sessionOptions: {
systemPrompt: 'You are an expert Rust reviewer. Be terse.',
// model: 'claude-opus-4-7',
// allowedTools: ['read', 'edit'],
// maxTurns: 5,
},
})
```

`{ append: '…' }` is also supported when you want to extend the agent's default prompt instead of replacing it. System prompts are fixed at `session/new` time — to switch prompts for the same workspace, use a distinct `sessionKey` or close the prior session first. Reused persistent records ignore `sessionOptions` by design.

This unblocks AI-SDK consumers that want per-conversation system prompts (chat apps, evaluation harnesses, scoped agents). The matching runtime change at openclaw/acpx#309 opens `AcpRuntime.ensureSession` to accept `sessionOptions`; this PR exposes that on `AcpxProviderSettings` and threads it through `ensureHandle`.

Files changed

File Change
`src/types.ts` Re-export `SessionAgentOptions` + `SystemPromptOption` from `acpx/runtime`; add `sessionOptions?: SessionAgentOptions` to `AcpxProviderSettings` with the inline doc explaining the reuse-vs-fresh semantics
`src/provider.ts` Thread `this.settings.sessionOptions` from `ensureHandle` into `runtime.ensureSession(...)` (one line)
`src/index.ts` Re-export the two new types
`src/mcp-servers.ts` Drive-by: `export` the `RuntimeMcpServer` type so fallow's "private type leak" check passes (a regression introduced in #22 — fallow currently fails on main)
`README.md` New `### System prompts and per-session agent options` subsection under `## Persistent sessions`, covering string + `{ append }` forms, the fresh-vs-reused semantics, and the cross-agent caveat
`test/unit/session-options.test.ts` NEW — three tests: `systemPrompt` string forwards through, `{ append }` + `model` + `allowedTools` + `maxTurns` round-trip, omitting `sessionOptions` keeps the runtime call clean
`package.json` Version `0.0.3` → `0.1.0`; `acpx` peer-dep + dev-dep `>=0.6.1` → `>=0.8.0`

Test plan

Check Status Why
`bun run typecheck` 6 errors All from missing upstream types (`sessionOptions` on `AcpRuntimeEnsureInput`, `SessionAgentOptions` / `SystemPromptOption` from `acpx/runtime`) — expected, will go green when `acpx@0.8.0` publishes
`bun run lint` ✅ clean
`bun run fallow` ✅ exit 0 Drive-by `export` of `RuntimeMcpServer` was required to get this green
`bun test` ✅ 198 pass / 15 skip / 0 fail / 300 expect() TS types are erased at runtime; the 3 new tests are part of the 198
`bun run build` ✅ ESM + .d.ts (~32 KB) bunup's esbuild path strips types without re-checking

Coordination with #17 and #19

Three drafts now target the same upstream `acpx@0.8.0` release: #17, #19, and this PR. All three bump `version` to `0.1.0` and `acpx` to `>=0.8.0`. Whichever lands second and third needs to bump its version one step further (`0.1.0` → `0.2.0` → `0.3.0`, etc.) and resolve the `package.json` conflict on `version` + the dep range.

Known issue: dev-dep won't resolve from a clean install

The dev-dep range `acpx >=0.8.0` doesn't have a matching version published yet. `bun install` from a fresh checkout of this branch will fail. This is expected for the draft phase. Branch exists for review, not for fresh installs.

When upstream lands, the resolver will pick up `acpx@0.8.0` automatically and everything goes green.

Surfaces sessionOptions on AcpxProviderSettings and threads it through
ensureHandle into AcpRuntime.ensureSession. Lets AI SDK consumers set a
per-session systemPrompt (or model/allowedTools/maxTurns) on a fresh
ACP session without bypassing the runtime.

System prompts are applied at session/new time and persisted onto the
underlying record. Reusing an existing persistent session ignores
sessionOptions by design; callers who want a different prompt should
use a distinct sessionKey or close the prior session first.

Re-exports SessionAgentOptions and SystemPromptOption from acpx/runtime.

Drive-by: export RuntimeMcpServer type from mcp-servers.ts so the
exported toRuntimeMcpServers signature no longer references a same-file
private type (fixes a fallow regression introduced in #22).

Bumps acpx peer-dep floor to >=0.8.0 and bumps the package to 0.1.0.
Requires the matching runtime change from openclaw/acpx#309.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant