ContextSelection
SUPPORT · type · 类型合同
Selection is independent of ownership; omitted selection preserves ordered execution.
导入
ts
import type { ContextSelection } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ContextSelection} ContextSelection */其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/context。
定义
类型: ContextSelection
类型表达式
ts
type ContextSelection = | { mode: 'sequence' }
/** Apply only steps of the given kind. */
| { mode: 'fixed'; kind: ContextReduction['kind'] }
/** maxTrimLossRatio is a JSON-character reduction heuristic, not semantic information loss. */
| { mode: 'auto'; maxTrimLossRatio?: number; reserveCalls?: number }
/** Ask a registered model selector; `reserveCalls` keeps calls for later stages. */
| ({ mode: 'model'; reserveCalls?: number } & ContextHandlerReference);联合分支结构
ContextSelection的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
mode | "sequence" | 必需 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
mode | "fixed" | 必需 | 见类型定义及调用场景。 |
kind | "trim" | "compress" | 必需 | 见类型定义及调用场景。 |
分支 3
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
mode | "auto" | 必需 | 见类型定义及调用场景。 |
maxTrimLossRatio | number | undefined | 可省略 | 见类型定义及调用场景。 |
reserveCalls | number | undefined | 可省略 | 见类型定义及调用场景。 |
分支 4
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
mode | "model" | 必需 | 见类型定义及调用场景。 |
reserveCalls | number | undefined | 可省略 | 见类型定义及调用场景。 |
handlerId | string | 必需 | 只读。Registered handler id; an unknown id is rejected before execution. |
使用示例
- 选择缩减步骤:顺序、固定、自动或模型:一套类型化策略表达多种场景,保留精确参数与 App 自定义选择。
按已登记顺序处理
入门 · Node.js
ts
import { Support } from '@jangts/agent-core';
Support.validateContextSelection({ mode: 'sequence' }, []);
console.log(Object.keys(Support.contextSelectionCatalog));js
import { Support } from '@jangts/agent-core';
Support.validateContextSelection({ mode: 'sequence' }, []);
console.log(Object.keys(Support.contextSelectionCatalog));按场景选择策略并精确覆盖
配置 · Node.js
ts
import { Support } from '@jangts/agent-core';
const localOnly = { mode: 'fixed' as const, kind: 'trim' as const };
const preserveMore = { mode: 'auto' as const, maxTrimLossRatio: 0.1, reserveCalls: 2 };
Support.validateContextSelection(localOnly, []);
Support.validateContextSelection(preserveMore, []);
console.log(localOnly, preserveMore);js
import { Support } from '@jangts/agent-core';
const localOnly = { mode: 'fixed', kind: 'trim' };
const preserveMore = { mode: 'auto', maxTrimLossRatio: 0.1, reserveCalls: 2 };
Support.validateContextSelection(localOnly, []);
Support.validateContextSelection(preserveMore, []);
console.log(localOnly, preserveMore);