A test-only cordis.yml under examples/jsonrpc-agent boots the headless app through the Loader; a scripted model delegates once to the SDK backend, whose child is a COMPLETE second harness runtime (own cordis.yml, jsonrpc serving surface, scripted cwd-echo model, own JSONL persistence). Asserts the parent tool result AND the child's own persisted transcript both carry the parent session's workspace cwd; child launch resolves through the shared example-launch resolver so src/lib modes both hold.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import type { Context } from 'cordis'
|
|
import type { GenerateOptions, StreamChunk } from '@deepseek-ai/dsh-llm'
|
|
import { LlmAdapter } from '@deepseek-ai/dsh-llm'
|
|
|
|
/**
|
|
* Scripted model for the CHILD runtime: answers every request with its own
|
|
* process cwd, so the driving e2e can prove the parent session's workspace
|
|
* reached the child process across the SDK wire. `options` carries the
|
|
* request; the reply depends only on process state.
|
|
*/
|
|
class CwdEchoAdapter extends LlmAdapter {
|
|
async * stream(options: GenerateOptions): AsyncIterable<StreamChunk> {
|
|
void options
|
|
const reply = `child cwd: ${process.cwd()}`
|
|
yield { type: 'block-start', index: 0, blockType: 'text' }
|
|
yield { type: 'text-delta', index: 0, text: reply }
|
|
yield { type: 'block-end', index: 0, block: { type: 'text', text: reply } }
|
|
yield { type: 'usage', usage: { inputTokens: 3, outputTokens: reply.length } }
|
|
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
}
|
|
}
|
|
|
|
export const name = 'child-mock-llm'
|
|
export const inject = ['llm']
|
|
|
|
/**
|
|
* Register the cwd-echo adapter under the `mock` provider.
|
|
* @param ctx - the plugin context supplying `ctx.llm`.
|
|
*/
|
|
export function apply(ctx: Context): void {
|
|
ctx.llm.registerAdapter(['mock'], new CwdEchoAdapter())
|
|
}
|