ModelPart
CORE · type · Type contract
One streamed response part: assistant text or a function-call fragment.
Import
ts
import type { ModelPart } from '@jangts/agent-core';js
/** @typedef {import('@jangts/agent-core').ModelPart} ModelPart */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
Type: ModelPart
Type expression
ts
type ModelPart = string | FunctionCallDelta;Union branch structure
Optional shapes of ModelPart: choose one shape; required fields for each branch are listed separately.
Branch 1
string
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
type | "function-call-delta" | Required | See the type definition and usage context. |
index | number | Required | Index of the call within the response; deltas with the same index belong together. |
id | string | undefined | Optional | Provider call id, usually delivered once with the first delta. |
name | string | undefined | Optional | Function name, usually delivered once with the first delta. |
arguments | string | undefined | Optional | Raw JSON argument fragment; concatenating all fragments yields the full arguments. |
Examples
- Model tools and transports: typed selection only after full validation: A tool definition provides a Schema and resolver; a transport translates wire output into the unified model selection contract.
- Compatible Provider and custom Providers: Support owns the common Chat Completions HTTP/SSE lifecycle; an App can substitute its own ChatProvider.
- Support: the aggregate entry for recommended usage: Support aggregates recommended construction, policies, and same-source configuration generation; Core execution does not depend on this namespace.
Declare two selectable tools
Beginner · Node.js
ts
import { ModelToolRegistry } from '@jangts/agent-core';
const inputSchema = { jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value: unknown) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new Error('需要空对象');
return {};
} };
const tools = new ModelToolRegistry([
{ id: 'greet', description: '回答问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '查询状态', inputSchema, resolve: () => 'status' },
]).seal();
console.log(tools.resolve({ toolId: 'status', input: {} }, { stageId: 'recognize' }));js
import { ModelToolRegistry } from '@jangts/agent-core';
const inputSchema = { jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
throw new Error('需要空对象');
return {};
} };
const tools = new ModelToolRegistry([
{ id: 'greet', description: '回答问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '查询状态', inputSchema, resolve: () => 'status' },
]).seal();
console.log(tools.resolve({ toolId: 'status', input: {} }, { stageId: 'recognize' }));Project an allowed subset to only one stage
Configuration · Node.js
ts
import { ModelToolRegistry, Support } from '@jangts/agent-core';
const schema = Support.defineSchema({ jsonSchema: { type: 'object', properties: {} },
parse(value: unknown) { if (!value || typeof value !== 'object' || Array.isArray(value)) throw new TypeError('需要对象'); return {}; } });
const registry = new ModelToolRegistry([
{ id: 'greet', description: '问候', inputSchema: schema, resolve: () => 'greet' },
{ id: 'status', description: '状态', inputSchema: schema, resolve: () => 'status' },
]).seal();
const readOnly = registry.select(['status']);
const transport = Support.createModelTransport({ id: 'recognize', tools: readOnly });
console.log(transport.id, readOnly.ids());js
import { ModelToolRegistry, Support } from '@jangts/agent-core';
const schema = Support.defineSchema({ jsonSchema: { type: 'object', properties: {} },
parse(value) { if (!value || typeof value !== 'object' || Array.isArray(value))
throw new TypeError('需要对象'); return {}; } });
const registry = new ModelToolRegistry([
{ id: 'greet', description: '问候', inputSchema: schema, resolve: () => 'greet' },
{ id: 'status', description: '状态', inputSchema: schema, resolve: () => 'status' },
]).seal();
const readOnly = registry.select(['status']);
const transport = Support.createModelTransport({ id: 'recognize', tools: readOnly });
console.log(transport.id, readOnly.ids());