mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-28 13:12:59 +08:00
Session V4 reserves developer-role messages for incremental model-visible session changes. The role, tool addition/removal blocks, and deferred-loading marker need a durable representation before independent provider and UI integrations can emit or consume them. Known developer events must match an open turn and step; unsupported providers and UI consumers fail explicitly. Request headers already capture full tool definitions. Persisting another ToolSchema in each addition would duplicate Session information and create two definitions that could drift. Additions therefore store toolName, and the containing developer event uses headerSeq to select one earlier known request/header for all its additions. A same-name replacement keeps its historical definition identity through restart, fork and surface changes. Removals require no definition copy, and ordinary developer messages omit headerSeq. Generic sourceEventSeqs remains independent derivation metadata. The rejected inline tool field is optional never with @persistenceReserved. The schema extractor retains that uninhabited slot, so permitting a future value requires a format bump instead of being mistaken for compatible optional metadata. Unrelated optional fields remain additive and readable. Native and Session admission reject missing, forward, non-header, unknown, ambiguous and incomplete referenced definitions, and reject the retired inline tool field. Validate complete schema fields only for referenced definitions, preserving unrelated header behavior and extra JSON metadata. Unknown ignorable records remain opaque. Empty developer nodes retain their surface position without producing a message or shadowing the system head. No automatic emitter, provider activation, UI implementation, or speculative public resolver is added. Keep the core-owned developer source binding beside the introduced role, including the request-only type rejection and attribution round trips. Update consumer guards, SDK/snapshot handling, bilingual owner documentation, and the same unreleased V4 acknowledgement. Keep earlier tool/source migration work and its documentation in the parent. Preserve the existing recorded Cordis inspection generation from the original developer change. Integration keeps the final source layer as the sole parent and preserves master's Messages input filtering, empty-user omission, empty tool results, and system-update placement. Developer/deferred guards still run before conversion. Native V4 admission, header references, reservation declarations, and generic tooling match the validated marker candidate. Parent-owned fixture and generator fixes remain in the parent. Earlier feature validation passed full build, full lint, 41 doc-sync gates, and 16 hygiene gates. The unchanged native implementation retains that evidence. The focused Session/V4/request-input run passes 884 tests across 38 files with 100% statement, branch, function and line coverage for the V3-to-V4 package and Session surface. Consumer tests pass 482 with one existing skip; tool, message and optional-field tests pass 146. Cordis inspection and compaction replays pass in both source and built modes (two cases per mode). Ten invalid referenced-definition/unknown-header controls failed before their scoped guards and pass after them. Reservation validation: the actual generated developer root records tool as optional primitive never. Widening it requires a bump, while traceId remains additive and preserved; all 85 focused reader/classifier tests pass. Final-parent validation: 205 tests across eight provider, type, catalog, Session and native-format files pass. The preserved parent fixture verifies Messages input-history replay; runtime/declaration and parent-owned-file comparisons show no loss during the final rebase. Co-authored-by: Tianyi Cui <53024+tianyicui@users.noreply.github.com>
113 lines
6.2 KiB
TypeScript
113 lines
6.2 KiB
TypeScript
/** Compile request-only inputs against the actual LLM and durable write interfaces. */
|
|
import { resolve } from 'node:path'
|
|
import ts from 'typescript'
|
|
import { expect, it } from 'vitest'
|
|
|
|
const root = resolve(import.meta.dirname, '..')
|
|
const probePath = resolve(import.meta.dirname, '__request_input_probe.ts')
|
|
|
|
const probe = `
|
|
import type { Agent } from '@deepseek-ai/dsh-agent'
|
|
import type { Session } from '@deepseek-ai/dsh-session'
|
|
import type { SessionTitleLlmRequestEventData } from '@deepseek-ai/dsh-session-title-llm'
|
|
import { createUserMessage, projectFilesToText, projectImagesForTextModel, projectOffloadedImages } from '@deepseek-ai/dsh-llm'
|
|
import type { GenerateOptions, Message, MessageId, MessageSource, RequestMessage, RequestUserInput } from '@deepseek-ai/dsh-llm'
|
|
|
|
declare const session: Session
|
|
declare const agent: Agent
|
|
declare const durable: Message
|
|
declare const id: MessageId
|
|
declare const source: MessageSource
|
|
declare const title: SessionTitleLlmRequestEventData
|
|
const input: RequestUserInput = { role: 'user', content: [{ type: 'text', text: 'request' }] }
|
|
const request: GenerateOptions = { provider: 'test', model: 'test', messages: [durable, input] }
|
|
const files: readonly RequestMessage[] = projectFilesToText([input], () => undefined)
|
|
const images: readonly RequestMessage[] = projectImagesForTextModel([input])
|
|
const offloaded: readonly RequestMessage[] = projectOffloadedImages([input], () => 'offloaded')
|
|
const durableProjection: readonly Message[] = projectImagesForTextModel([durable])
|
|
const existing: RequestMessage = durable
|
|
type IsAny<T> = 0 extends (1 & T) ? true : false
|
|
const requestIsAny: IsAny<RequestMessage> = false
|
|
const messageIsAny: IsAny<Message> = false
|
|
const inputIsAny: IsAny<RequestUserInput> = false
|
|
// @ts-expect-error -- request inputs cannot provide identity without attribution.
|
|
const onlyId: RequestMessage = { role: 'user', content: [], id }
|
|
// @ts-expect-error -- request inputs cannot provide attribution without identity.
|
|
const onlySource: RequestMessage = { role: 'user', content: [], source }
|
|
// @ts-expect-error -- exact optional fields reject explicitly undefined identity.
|
|
const undefinedId: RequestUserInput = { ...input, id: undefined }
|
|
// @ts-expect-error -- exact optional fields reject explicitly undefined attribution.
|
|
const undefinedSource: RequestUserInput = { ...input, source: undefined }
|
|
// @ts-expect-error -- only user inputs have a request-only alternative.
|
|
const assistant: RequestMessage = { role: 'assistant', content: [] }
|
|
// @ts-expect-error -- system prompts retain their durable identity and source.
|
|
const system: RequestMessage = { role: 'system', content: [] }
|
|
// @ts-expect-error -- developer instructions retain their durable identity and source.
|
|
const developer: RequestMessage = { role: 'developer', content: [] }
|
|
// @ts-expect-error -- tool results retain their durable identity and correlation.
|
|
const tool: RequestMessage = { role: 'tool', content: [] }
|
|
// @ts-expect-error -- constructing a durable user message requires its source.
|
|
createUserMessage(input)
|
|
// @ts-expect-error -- Session writes require a durable user message.
|
|
session.append('user/message', input, { surfaceOp: 'append' })
|
|
// @ts-expect-error -- followups enter durable Session history.
|
|
agent.followup(input)
|
|
// @ts-expect-error -- injected context enters durable Session history.
|
|
agent.inject(input)
|
|
// @ts-expect-error -- title requests record their exact durable messages.
|
|
const titleMessages: SessionTitleLlmRequestEventData['messages'] = [input]
|
|
// @ts-expect-error -- the title event cannot write a request-only input.
|
|
session.append('session/title-llm-request', { ...title, messages: [input] })
|
|
// @ts-expect-error -- image projections retain request-only inputs and cannot manufacture identity.
|
|
const projectedDurable: Message = images[0]!
|
|
// @ts-expect-error -- adding an id to a request input does not create a durable message.
|
|
session.append('user/message', { ...input, id }, { surfaceOp: 'append' })
|
|
// @ts-expect-error -- adding a source to a request input does not create a durable message.
|
|
session.append('user/message', { ...input, source }, { surfaceOp: 'append' })
|
|
const narrowed = [{ role: 'user', content: [{ type: 'text', text: 'fixed' }] }] as const
|
|
// @ts-expect-error -- projections may replace content and cannot preserve narrower content types.
|
|
const narrowedProjection: typeof narrowed = projectImagesForTextModel(narrowed)
|
|
void [request, files, images, offloaded, durableProjection, existing]
|
|
`
|
|
|
|
it('accepts mixed requests and rejects lightweight inputs at durable message writes', { timeout: 60_000 }, () => {
|
|
const parsed = ts.getParsedCommandLineOfConfigFile(resolve(root, 'tsconfig.host.json'), {}, {
|
|
...ts.sys,
|
|
onUnRecoverableConfigFileDiagnostic(diagnostic) {
|
|
throw new Error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'))
|
|
},
|
|
})
|
|
expect(parsed).toBeDefined()
|
|
const options: ts.CompilerOptions = {
|
|
...parsed!.options,
|
|
composite: false,
|
|
incremental: false,
|
|
noEmit: true,
|
|
declaration: false,
|
|
declarationMap: false,
|
|
noUnusedLocals: false,
|
|
noUnusedParameters: false,
|
|
}
|
|
const base = ts.createCompilerHost(options, true)
|
|
const host: ts.CompilerHost = {
|
|
...base,
|
|
fileExists: path => resolve(path) === probePath || base.fileExists(path),
|
|
readFile: path => resolve(path) === probePath ? probe : base.readFile(path),
|
|
getSourceFile(path, languageVersion, onError, shouldCreateNewSourceFile) {
|
|
return resolve(path) === probePath
|
|
? ts.createSourceFile(path, probe, languageVersion, true)
|
|
: base.getSourceFile(path, languageVersion, onError, shouldCreateNewSourceFile)
|
|
},
|
|
}
|
|
const program = ts.createProgram([probePath], options, host)
|
|
for (const path of ['packages/llm/llm/src/types.ts', 'packages/core/session/src/index.ts', 'packages/session/session-title-llm/src/index.ts']) {
|
|
expect(program.getSourceFile(resolve(root, path)), path).toBeDefined()
|
|
}
|
|
const source = program.getSourceFile(probePath)!
|
|
const diagnostics = [...program.getSyntacticDiagnostics(source), ...program.getSemanticDiagnostics(source)]
|
|
expect(diagnostics.map((diagnostic) => {
|
|
const line = source.getLineAndCharacterOfPosition(diagnostic.start ?? 0).line + 1
|
|
return `${line}: ${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}`
|
|
})).toEqual([])
|
|
})
|