mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-08-29 04:26:38 +00:00
refactor: apply repository naming contract
Apply the accepted pre-release package, service, type, directory, and role renames as one repository-wide change.
This commit is contained in:
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/context/session-reference/README.md
|
||||
README.md: 145ec112d6b9cce9e9eb1567c60cde41c6d6eb3c
|
||||
README.zh.md: 5d528a296ee77dc64b584d0683395cb4df67936a
|
||||
README.md: 1f7df17f512b109e0e29bebf3f7931516914c368
|
||||
README.zh.md: 380f1c613621a8e1fd5b4ee27b70f40f4072197b
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
`ctx.sessionReferences` prepares bounded, read-only snapshots of other sessions as sourced model-facing context. It consumes `ctx.sessionQuery` and the backend-independent compact checkpoint marker; SQLite FTS is not required. Hosts that support cross-session mentions may opt into the service.
|
||||
`ctx.sessionReferenceResolver` prepares bounded, read-only snapshots of other sessions as sourced model-facing context. It consumes `ctx.sessionQuery` and the backend-independent compact checkpoint marker; SQLite FTS is not required. Hosts that support cross-session mentions may opt into the service.
|
||||
|
||||
## Public API
|
||||
|
||||
@@ -12,7 +12,7 @@ English | [中文](README.zh.md)
|
||||
|
||||
## Snapshot semantics
|
||||
|
||||
Preparation calls `ctx.sessionQuery.readSurface()` once per distinct source and never rereads it after enqueue. It projects only direct-user `user/message`, assistant text, and `user/message` checkpoints carrying the canonical `dsh-compact` source marker from the folded current surface. For a source prompt that already contains baked prefix context, projection reads only its model-hidden display content, preventing recursive snapshot propagation. Shadowed pre-compaction events, tools, reasoning, context, plugin-generated user messages other than marked compact checkpoints, and unfinished assistant chunks are excluded. A compacted source therefore contributes its latest checkpoint plus retained later conversation, not restored shadowed text.
|
||||
Preparation calls `ctx.sessionQuery.readSurface()` once per distinct source and never rereads it after enqueue. It projects only direct-user `user/message`, assistant text, and `user/message` checkpoints carrying the canonical `dsh-compaction` source marker from the folded current surface. For a source prompt that already contains baked prefix context, projection reads only its model-hidden display content, preventing recursive snapshot propagation. Shadowed pre-compaction events, tools, reasoning, context, plugin-generated user messages other than marked compact checkpoints, and unfinished assistant chunks are excluded. A compacted source therefore contributes its latest checkpoint plus retained later conversation, not restored shadowed text.
|
||||
|
||||
The context source is `{ kind: 'session-reference', version: 1, references }`; each reference records its source id and label, capture seq, compact presence, retained/omitted message counts, omitted UTF-8 bytes, and truncation state. When the agent is idle, the standard TUI installs a one-shot `agent/pre-step` wrapper that adds the snapshot only to an `enter` decision containing the claimed direct prompt. While the agent is running, it calls `inject()` immediately before `steer()`, placing both messages in the next-step inbox for the same later claim. The target log therefore records a sourced context `user/message` followed by the readable direct `user/message`. Later source mutation, compaction, or deletion cannot change target replay.
|
||||
|
||||
@@ -24,7 +24,7 @@ The context source is `{ kind: 'session-reference', version: 1, references }`; e
|
||||
| `candidateLimit` | `50` | Default candidate count returned to a host. |
|
||||
| `maxReferenceBytes` | `65536` | Maximum serialized JSON bytes for one reference object. |
|
||||
|
||||
Retention applies `maxReferenceBytes` independently to each source, keeps compact checkpoints and the newest message before dropping older non-checkpoint units, and uses `dsh-retention` head/tail truncation with an exact UTF-8 omission notice. If one source's fixed serialized fields cannot fit, preparation fails with `SESSION_REFERENCE_BUDGET_EXCEEDED` instead of returning a partial context.
|
||||
Retention applies `maxReferenceBytes` independently to each source, keeps compact checkpoints and the newest message before dropping older non-checkpoint units, and uses `dsh-output-retention` head/tail truncation with an exact UTF-8 omission notice. If one source's fixed serialized fields cannot fit, preparation fails with `SESSION_REFERENCE_BUDGET_EXCEEDED` instead of returning a partial context.
|
||||
|
||||
## Model Experience
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
`ctx.sessionReferences` 会把其他会话准备为有界、只读快照,作为带来源信息、面向模型的上下文。它消费 `ctx.sessionQuery` 与后端无关的 compact 检查点标记;不需要 SQLite FTS。支持跨会话 mention 的宿主可以主动启用该服务。
|
||||
`ctx.sessionReferenceResolver` 会把其他会话准备为有界、只读快照,作为带来源信息、面向模型的上下文。它消费 `ctx.sessionQuery` 与后端无关的 compact 检查点标记;不需要 SQLite FTS。支持跨会话 mention 的宿主可以主动启用该服务。
|
||||
|
||||
## 公开 API
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
## 快照语义
|
||||
|
||||
准备阶段会对每个不同源调用一次 `ctx.sessionQuery.readSurface()`,入队后绝不重读。它仅投影折叠后当前表层中的用户直接发出的 `user/message`、assistant 文本,以及 `user/message` 检查点;这类检查点携带规范 `dsh-compact` 源标记。对于已经包含固化前缀上下文的源提示词,投影只读取其对模型隐藏的显示内容,以防止快照递归传播。已遮蔽的压缩(compaction)前事件、工具、推理(reasoning)、上下文、除已标记 compact 检查点外的插件生成 user 消息,以及未完成的 assistant 分片均会被排除。因此,已压缩源只会提供最新检查点及其后保留的会话内容,不会还原已遮蔽的文本。
|
||||
准备阶段会对每个不同源调用一次 `ctx.sessionQuery.readSurface()`,入队后绝不重读。它仅投影折叠后当前表层中的用户直接发出的 `user/message`、assistant 文本,以及 `user/message` 检查点;这类检查点携带规范 `dsh-compaction` 源标记。对于已经包含固化前缀上下文的源提示词,投影只读取其对模型隐藏的显示内容,以防止快照递归传播。已遮蔽的压缩(compaction)前事件、工具、推理(reasoning)、上下文、除已标记 compact 检查点外的插件生成 user 消息,以及未完成的 assistant 分片均会被排除。因此,已压缩源只会提供最新检查点及其后保留的会话内容,不会还原已遮蔽的文本。
|
||||
|
||||
上下文源为 `{ kind: 'session-reference', version: 1, references }`;每条引用会记录其源 id 与 label、捕获 seq、是否存在 compact、已保留/已省略消息数、已省略 UTF-8 字节数与截断状态。agent 空闲时,标准 TUI 会安装一次性的 `agent/pre-step` 包装层,只把快照添加到包含已领取直接提示词的 `enter` 决策。agent 运行时,它会紧接着调用 `inject()` 和 `steer()`,把两条消息放入 next-step inbox,等待后续同一次领取。目标日志因此会先记录一条带来源信息的上下文 `user/message`,再记录可读的直接 `user/message`。后续源变更、压缩或删除都无法改变目标回放。
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
| `candidateLimit` | `50` | 返回给宿主的默认候选数量。 |
|
||||
| `maxReferenceBytes` | `65536` | 一个引用对象的最大序列化 JSON 字节数。 |
|
||||
|
||||
保留会对每个源独立应用 `maxReferenceBytes`,保留 compact 检查点与最新消息,再丢弃较旧的非检查点单元,并使用 `dsh-retention` 头部/尾部截断和精确 UTF-8 省略通知。如果某个源的固定序列化字段本身就超出限额,准备会以 `SESSION_REFERENCE_BUDGET_EXCEEDED` 失败,而不返回部分上下文。
|
||||
保留会对每个源独立应用 `maxReferenceBytes`,保留 compact 检查点与最新消息,再丢弃较旧的非检查点单元,并使用 `dsh-output-retention` 头部/尾部截断和精确 UTF-8 省略通知。如果某个源的固定序列化字段本身就超出限额,准备会以 `SESSION_REFERENCE_BUDGET_EXCEEDED` 失败,而不返回部分上下文。
|
||||
|
||||
## 模型体验
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@deepseek-ai/dsh-session-reference",
|
||||
"description": "Cross-session snapshot references and durable untrusted model context (ctx.sessionReferences)",
|
||||
"description": "Cross-session snapshot references and durable untrusted model context (ctx.sessionReferenceResolver)",
|
||||
"version": "0.0.1-rc.2",
|
||||
"publishConfig": {
|
||||
"access": "restricted"
|
||||
@@ -36,20 +36,20 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/dsh-agent": "workspace:^",
|
||||
"@deepseek-ai/dsh-compact": "workspace:^",
|
||||
"@deepseek-ai/dsh-compaction": "workspace:^",
|
||||
"@deepseek-ai/dsh-invariants": "workspace:^",
|
||||
"@deepseek-ai/dsh-llm": "workspace:^",
|
||||
"@deepseek-ai/dsh-retention": "workspace:^",
|
||||
"@deepseek-ai/dsh-output-retention": "workspace:^",
|
||||
"@deepseek-ai/dsh-session": "workspace:^",
|
||||
"@deepseek-ai/dsh-session-query": "workspace:^",
|
||||
"@deepseek-ai/cordis": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/dsh-agent": "workspace:^",
|
||||
"@deepseek-ai/dsh-compact": "workspace:^",
|
||||
"@deepseek-ai/dsh-compaction": "workspace:^",
|
||||
"@deepseek-ai/dsh-invariants": "workspace:^",
|
||||
"@deepseek-ai/dsh-llm": "workspace:^",
|
||||
"@deepseek-ai/dsh-retention": "workspace:^",
|
||||
"@deepseek-ai/dsh-output-retention": "workspace:^",
|
||||
"@deepseek-ai/dsh-session": "workspace:^",
|
||||
"@deepseek-ai/dsh-session-query": "workspace:^",
|
||||
"@deepseek-ai/cordis": "workspace:^"
|
||||
|
||||
@@ -52,7 +52,7 @@ const PROMPT_SUFFIX = '\n</referenced-sessions>'
|
||||
|
||||
declare module '@deepseek-ai/cordis' {
|
||||
interface Context {
|
||||
sessionReferences: SessionReferenceService
|
||||
sessionReferenceResolver: SessionReferenceResolver
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ interface RenderedSource {
|
||||
}
|
||||
|
||||
/** Exact-read consumer that prepares immutable cross-session message context. */
|
||||
export class SessionReferenceService extends Service {
|
||||
export class SessionReferenceResolver extends Service {
|
||||
static inject = ['sessionQuery']
|
||||
static Config: z<Config> = z.object({
|
||||
maxReferences: z.number().step(1).min(1).max(MAX_REFERENCES).default(MAX_REFERENCES),
|
||||
@@ -78,7 +78,7 @@ export class SessionReferenceService extends Service {
|
||||
private readonly config: Required<Config>
|
||||
|
||||
constructor(ctx: Context, config: Config = {}) {
|
||||
super(ctx, 'sessionReferences')
|
||||
super(ctx, 'sessionReferenceResolver')
|
||||
this.config = {
|
||||
maxReferences: config.maxReferences ?? MAX_REFERENCES,
|
||||
candidateLimit: config.candidateLimit ?? DEFAULT_CANDIDATE_LIMIT,
|
||||
@@ -300,4 +300,4 @@ function cancelled(signal: AbortSignal): SessionReferenceError {
|
||||
return new SessionReferenceError('session reference preparation was cancelled', 'SESSION_REFERENCE_CANCELLED', { cause: signal.reason })
|
||||
}
|
||||
|
||||
export default SessionReferenceService
|
||||
export default SessionReferenceResolver
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/** Current-surface projection and byte-bounded rendering. */
|
||||
|
||||
import { isCompactCheckpointSource } from '@deepseek-ai/dsh-compact'
|
||||
import { isCompactCheckpointSource } from '@deepseek-ai/dsh-compaction'
|
||||
import type { SessionSurfaceSnapshot } from '@deepseek-ai/dsh-session-query'
|
||||
import { assertNever } from '@deepseek-ai/dsh-llm'
|
||||
import { TextRetainer } from '@deepseek-ai/dsh-retention'
|
||||
import { TextRetainer } from '@deepseek-ai/dsh-output-retention'
|
||||
import { stringifyTagSafeJson } from './serialization.ts'
|
||||
import type { ReferencedConversationItem } from './types.ts'
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import type { Agent } from '@deepseek-ai/dsh-agent'
|
||||
import { CompactionId, compactCheckpointSource } from '@deepseek-ai/dsh-compact'
|
||||
import { CompactionId, compactCheckpointSource } from '@deepseek-ai/dsh-compaction'
|
||||
import { createUserMessage, CallId , createMessage, createToolResultMessage } from '@deepseek-ai/dsh-llm'
|
||||
import SessionStore, { Session, SessionId } from '@deepseek-ai/dsh-session'
|
||||
import SessionQueryService from '@deepseek-ai/dsh-session-query'
|
||||
import SessionReferenceService, {
|
||||
import SessionQueryEngine from '@deepseek-ai/dsh-session-query'
|
||||
import SessionReferenceResolver, {
|
||||
decodeSessionReferenceUri,
|
||||
encodeSessionReferenceUri,
|
||||
formatSessionReferenceMention,
|
||||
@@ -15,16 +15,16 @@ import SessionReferenceService, {
|
||||
} from '@deepseek-ai/dsh-session-reference'
|
||||
import { stringifyTagSafeJson } from '../src/serialization.ts'
|
||||
|
||||
class TestSessionQueryService extends SessionQueryService {
|
||||
class TestSessionQueryEngine extends SessionQueryEngine {
|
||||
override searchSessions(
|
||||
..._args: Parameters<SessionQueryService['searchSessions']>
|
||||
): ReturnType<SessionQueryService['searchSessions']> {
|
||||
..._args: Parameters<SessionQueryEngine['searchSessions']>
|
||||
): ReturnType<SessionQueryEngine['searchSessions']> {
|
||||
return Promise.resolve({ items: [] })
|
||||
}
|
||||
|
||||
override searchEvents(
|
||||
...args: Parameters<SessionQueryService['searchEvents']>
|
||||
): ReturnType<SessionQueryService['searchEvents']> {
|
||||
...args: Parameters<SessionQueryEngine['searchEvents']>
|
||||
): ReturnType<SessionQueryEngine['searchEvents']> {
|
||||
return this.readSurface(args[0].sessionId).then(surface => ({
|
||||
session: surface.session,
|
||||
items: [],
|
||||
@@ -35,8 +35,8 @@ class TestSessionQueryService extends SessionQueryService {
|
||||
async function harness(config: Config = {}): Promise<Context> {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionStore)
|
||||
await ctx.plugin(TestSessionQueryService)
|
||||
await ctx.plugin(SessionReferenceService, config)
|
||||
await ctx.plugin(TestSessionQueryEngine)
|
||||
await ctx.plugin(SessionReferenceResolver, config)
|
||||
return ctx
|
||||
}
|
||||
|
||||
@@ -252,19 +252,19 @@ describe('session reference discovery and preparation', () => {
|
||||
source: { kind: 'fallback' },
|
||||
})
|
||||
|
||||
await expect(ctx.sessionReferences.listCandidates(fakeAgent(target))).resolves.toEqual([
|
||||
await expect(ctx.sessionReferenceResolver.listCandidates(fakeAgent(target))).resolves.toEqual([
|
||||
{ sessionId: SessionId('same-later'), label: 'Latest title', cwd: '/same', createdAt: 25 },
|
||||
{ sessionId: SessionId('same'), label: 'same', cwd: '/same', createdAt: 20 },
|
||||
{ sessionId: SessionId('none'), label: 'none', createdAt: 30 },
|
||||
{ sessionId: SessionId('other'), label: 'other', cwd: '/else', createdAt: 40 },
|
||||
])
|
||||
await expect(ctx.sessionReferences.listCandidates(fakeAgent(target), 'els', 1)).resolves.toEqual([
|
||||
await expect(ctx.sessionReferenceResolver.listCandidates(fakeAgent(target), 'els', 1)).resolves.toEqual([
|
||||
{ sessionId: SessionId('other'), label: 'other', cwd: '/else', createdAt: 40 },
|
||||
])
|
||||
await expect(ctx.sessionReferences.listCandidates(fakeAgent(target), 'LATEST', 1)).resolves.toEqual([
|
||||
await expect(ctx.sessionReferenceResolver.listCandidates(fakeAgent(target), 'LATEST', 1)).resolves.toEqual([
|
||||
{ sessionId: SessionId('same-later'), label: 'Latest title', cwd: '/same', createdAt: 25 },
|
||||
])
|
||||
await expect(ctx.sessionReferences.listCandidates(fakeAgent(target), '', 0))
|
||||
await expect(ctx.sessionReferenceResolver.listCandidates(fakeAgent(target), '', 0))
|
||||
.rejects.toThrow(expectCode('SESSION_REFERENCE_INVALID_REFERENCE'))
|
||||
|
||||
let releaseList: (() => void) | undefined
|
||||
@@ -273,7 +273,7 @@ describe('session reference discovery and preparation', () => {
|
||||
return []
|
||||
})
|
||||
const controller = new AbortController()
|
||||
const pending = ctx.sessionReferences.listCandidates(fakeAgent(target), '', undefined, controller.signal)
|
||||
const pending = ctx.sessionReferenceResolver.listCandidates(fakeAgent(target), '', undefined, controller.signal)
|
||||
await vi.waitFor(() => { expect(releaseList).toBeTypeOf('function') })
|
||||
const cancelledList = expect(pending).rejects.toThrow(expectCode('SESSION_REFERENCE_CANCELLED'))
|
||||
controller.abort('autocomplete superseded')
|
||||
@@ -294,7 +294,7 @@ describe('session reference discovery and preparation', () => {
|
||||
reason: new Error('broken title log'),
|
||||
}])
|
||||
|
||||
await expect(ctx.sessionReferences.listCandidates(fakeAgent(target), 'source')).resolves.toEqual([
|
||||
await expect(ctx.sessionReferenceResolver.listCandidates(fakeAgent(target), 'source')).resolves.toEqual([
|
||||
{ sessionId: source.id, label: source.id, createdAt: source.header.createdAt },
|
||||
])
|
||||
|
||||
@@ -306,7 +306,7 @@ describe('session reference discovery and preparation', () => {
|
||||
return []
|
||||
})
|
||||
const controller = new AbortController()
|
||||
const pending = ctx.sessionReferences.listCandidates(fakeAgent(target), 'source', undefined, controller.signal)
|
||||
const pending = ctx.sessionReferenceResolver.listCandidates(fakeAgent(target), 'source', undefined, controller.signal)
|
||||
await vi.waitFor(() => { expect(releaseTitles).toBeTypeOf('function') })
|
||||
expect(titleSignal).toBe(controller.signal)
|
||||
const cancelledTitles = expect(pending).rejects.toThrow(expectCode('SESSION_REFERENCE_CANCELLED'))
|
||||
@@ -323,7 +323,7 @@ describe('session reference discovery and preparation', () => {
|
||||
const source = ctx.sessions.create(SessionId('source'), { meta: { cwd: '/source' } })
|
||||
appendConversation(source)
|
||||
|
||||
const prepared = await ctx.sessionReferences.prepare(
|
||||
const prepared = await ctx.sessionReferenceResolver.prepare(
|
||||
fakeAgent(target),
|
||||
[{ type: 'text', text: 'use @source' }],
|
||||
[{ sessionId: source.id, label: 'source' }],
|
||||
@@ -380,7 +380,7 @@ describe('session reference discovery and preparation', () => {
|
||||
source: { kind: 'user' },
|
||||
}), { surfaceOp: 'append' })
|
||||
|
||||
const prepared = await ctx.sessionReferences.prepare(
|
||||
const prepared = await ctx.sessionReferenceResolver.prepare(
|
||||
fakeAgent(target),
|
||||
[{ type: 'text', text: 'inspect source' }],
|
||||
[{ sessionId: source.id }],
|
||||
@@ -406,7 +406,7 @@ describe('session reference discovery and preparation', () => {
|
||||
{ surfaceOp: 'append' },
|
||||
)
|
||||
|
||||
const prepared = await ctx.sessionReferences.prepare(
|
||||
const prepared = await ctx.sessionReferenceResolver.prepare(
|
||||
fakeAgent(target),
|
||||
[{ type: 'text', text: 'use @source' }],
|
||||
[{ sessionId: source.id }],
|
||||
@@ -435,36 +435,36 @@ describe('session reference discovery and preparation', () => {
|
||||
const agent = fakeAgent(target)
|
||||
const content = [{ type: 'text' as const, text: 'go' }]
|
||||
|
||||
const withoutReferences = await ctx.sessionReferences.prepare(agent, content, [])
|
||||
const withoutReferences = await ctx.sessionReferenceResolver.prepare(agent, content, [])
|
||||
expect(withoutReferences).toEqual({ content })
|
||||
expect(withoutReferences.content).not.toBe(content)
|
||||
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [
|
||||
{ sessionId: one.id, label: 'first' },
|
||||
{ sessionId: one.id, label: 'ignored duplicate' },
|
||||
{ sessionId: two.id },
|
||||
])).resolves.toMatchObject({ additionalContext: { source: { references: [{ label: 'first' }, { label: 'two' }] } } })
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [{ sessionId: target.id }]))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [{ sessionId: target.id }]))
|
||||
.rejects.toThrow(expectCode('SESSION_REFERENCE_SELF_REFERENCE'))
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [null as never]))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [null as never]))
|
||||
.rejects.toThrow(expectCode('SESSION_REFERENCE_INVALID_REFERENCE'))
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [1 as never]))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [1 as never]))
|
||||
.rejects.toThrow(expectCode('SESSION_REFERENCE_INVALID_REFERENCE'))
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [{ sessionId: 1 } as never]))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [{ sessionId: 1 } as never]))
|
||||
.rejects.toThrow(expectCode('SESSION_REFERENCE_INVALID_REFERENCE'))
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [
|
||||
{ sessionId: one.id }, { sessionId: two.id }, { sessionId: SessionId('three') },
|
||||
])).rejects.toThrow(expectCode('SESSION_REFERENCE_TOO_MANY'))
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [
|
||||
{ sessionId: one.id }, { sessionId: SessionId('missing') },
|
||||
])).rejects.toThrow(expectCode('SESSION_REFERENCE_READ_FAILED'))
|
||||
|
||||
const readSurface = vi.spyOn(ctx.sessionQuery, 'readSurface')
|
||||
readSurface.mockRejectedValueOnce('non-error read failure')
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [{ sessionId: one.id }]))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [{ sessionId: one.id }]))
|
||||
.rejects.toThrow(/non-error read failure/)
|
||||
readSurface.mockRejectedValueOnce('non-error signalled read failure')
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [{ sessionId: one.id }], new AbortController().signal))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [{ sessionId: one.id }], new AbortController().signal))
|
||||
.rejects.toThrow(/non-error signalled read failure/)
|
||||
|
||||
const duringRead = new AbortController()
|
||||
@@ -472,7 +472,7 @@ describe('session reference discovery and preparation', () => {
|
||||
duringRead.abort('cancelled during read')
|
||||
throw new Error('read interrupted')
|
||||
})
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [{ sessionId: one.id }], duringRead.signal))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [{ sessionId: one.id }], duringRead.signal))
|
||||
.rejects.toThrow(expectCode('SESSION_REFERENCE_CANCELLED'))
|
||||
|
||||
const snapshot = await ctx.sessionQuery.readSurface(one.id)
|
||||
@@ -482,7 +482,7 @@ describe('session reference discovery and preparation', () => {
|
||||
return snapshot
|
||||
})
|
||||
const hangingRead = new AbortController()
|
||||
const pending = ctx.sessionReferences.prepare(agent, content, [{ sessionId: one.id }], hangingRead.signal)
|
||||
const pending = ctx.sessionReferenceResolver.prepare(agent, content, [{ sessionId: one.id }], hangingRead.signal)
|
||||
await vi.waitFor(() => { expect(releaseRead).toBeTypeOf('function') })
|
||||
const cancelledRead = expect(pending).rejects.toThrow(expectCode('SESSION_REFERENCE_CANCELLED'))
|
||||
hangingRead.abort('cancelled while storage remained pending')
|
||||
@@ -493,7 +493,7 @@ describe('session reference discovery and preparation', () => {
|
||||
|
||||
const abort = new AbortController()
|
||||
abort.abort('host cancelled')
|
||||
await expect(ctx.sessionReferences.prepare(agent, content, [{ sessionId: one.id }], abort.signal))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(agent, content, [{ sessionId: one.id }], abort.signal))
|
||||
.rejects.toThrow(expectCode('SESSION_REFERENCE_CANCELLED'))
|
||||
})
|
||||
|
||||
@@ -519,7 +519,7 @@ describe('session reference discovery and preparation', () => {
|
||||
{ surfaceOp: 'append' },
|
||||
)
|
||||
|
||||
const prepared = await ctx.sessionReferences.prepare(fakeAgent(target), [{ type: 'text', text: 'go' }], [{ sessionId: source.id }])
|
||||
const prepared = await ctx.sessionReferenceResolver.prepare(fakeAgent(target), [{ type: 'text', text: 'go' }], [{ sessionId: source.id }])
|
||||
const context = prepared.additionalContext
|
||||
if (context?.content[0]?.type !== 'text') throw new Error('expected text context')
|
||||
const data = promptData(context.content[0].text) as unknown[]
|
||||
@@ -554,7 +554,7 @@ describe('session reference discovery and preparation', () => {
|
||||
return source
|
||||
})
|
||||
|
||||
const prepared = await ctx.sessionReferences.prepare(
|
||||
const prepared = await ctx.sessionReferenceResolver.prepare(
|
||||
fakeAgent(target),
|
||||
[{ type: 'text', text: 'go' }],
|
||||
sources.map(source => ({ sessionId: source.id })),
|
||||
@@ -572,7 +572,7 @@ describe('session reference discovery and preparation', () => {
|
||||
const ctx = await harness({ maxReferenceBytes: 16 })
|
||||
const target = ctx.sessions.create(SessionId('target'))
|
||||
const source = ctx.sessions.create(SessionId('source'))
|
||||
await expect(ctx.sessionReferences.prepare(fakeAgent(target), [{ type: 'text', text: 'go' }], [{ sessionId: source.id }]))
|
||||
await expect(ctx.sessionReferenceResolver.prepare(fakeAgent(target), [{ type: 'text', text: 'go' }], [{ sessionId: source.id }]))
|
||||
.rejects.toThrow(expectCode('SESSION_REFERENCE_BUDGET_EXCEEDED'))
|
||||
})
|
||||
|
||||
@@ -589,7 +589,7 @@ describe('session reference discovery and preparation', () => {
|
||||
}),
|
||||
{ surfaceOp: 'append' },
|
||||
)
|
||||
const prepared = await ctx.sessionReferences.prepare(
|
||||
const prepared = await ctx.sessionReferenceResolver.prepare(
|
||||
fakeAgent(target),
|
||||
[{ type: 'text', text: 'use @source' }],
|
||||
[{ sessionId: source.id }],
|
||||
@@ -643,19 +643,19 @@ describe('session reference discovery and preparation', () => {
|
||||
it('rejects direct invalid configuration before service publication', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionStore)
|
||||
await ctx.plugin(TestSessionQueryService)
|
||||
expect(() => new SessionReferenceService(ctx, { maxReferences: 0 }))
|
||||
await ctx.plugin(TestSessionQueryEngine)
|
||||
expect(() => new SessionReferenceResolver(ctx, { maxReferences: 0 }))
|
||||
.toThrow(expectCode('SESSION_REFERENCE_INVALID_CONFIG'))
|
||||
|
||||
const oversizedCtx = new Context()
|
||||
await oversizedCtx.plugin(SessionStore)
|
||||
await oversizedCtx.plugin(TestSessionQueryService)
|
||||
expect(() => new SessionReferenceService(oversizedCtx, { maxReferences: 4 }))
|
||||
await oversizedCtx.plugin(TestSessionQueryEngine)
|
||||
expect(() => new SessionReferenceResolver(oversizedCtx, { maxReferences: 4 }))
|
||||
.toThrow(expectCode('SESSION_REFERENCE_INVALID_CONFIG'))
|
||||
|
||||
const defaultCtx = new Context()
|
||||
await defaultCtx.plugin(SessionStore)
|
||||
await defaultCtx.plugin(TestSessionQueryService)
|
||||
expect(() => new SessionReferenceService(defaultCtx)).not.toThrow()
|
||||
await defaultCtx.plugin(TestSessionQueryEngine)
|
||||
expect(() => new SessionReferenceResolver(defaultCtx)).not.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
{ "path": "../../../vendor/cosmokit" },
|
||||
{ "path": "../../../vendor/cordis" },
|
||||
{ "path": "../../../vendor/schemastery" },
|
||||
{ "path": "../../util/retention" },
|
||||
{ "path": "../../util/output-retention" },
|
||||
{ "path": "../../llm/llm" },
|
||||
{ "path": "../../core/session" },
|
||||
{ "path": "../../core/agent" },
|
||||
{ "path": "../../compact/compact" },
|
||||
{ "path": "../../support/invariants" },
|
||||
{ "path": "../../compaction/compaction" },
|
||||
{ "path": "../../runtime-diagnostics/invariants" },
|
||||
{ "path": "../../session-query/session-query" }
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user