@xiaozhiclaw/qlogicagent-core 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,7 +35,7 @@ export interface ContextEnvelope {
35
35
  itemId: string;
36
36
  anchors: ContextAnchor[];
37
37
  }
38
- /** Thinking block from Anthropic Messages API (DeepSeek, Claude, etc.) */
38
+ /** Transport-supplied signed reasoning, preserved for subsequent model rounds. */
39
39
  export interface ThinkingBlock {
40
40
  thinking: string;
41
41
  signature: string;
@@ -68,11 +68,11 @@ export interface ChatMessage {
68
68
  name?: string;
69
69
  /** Tool-result error flag propagated so every transport can signal failure to the model. */
70
70
  is_error?: boolean;
71
- /** OpenAI-chat reasoning content (GLM/DeepSeek) carried across tool-call rounds on the assistant message. */
71
+ /** Transport-supplied reasoning carried across tool-call rounds. */
72
72
  reasoning_content?: string;
73
- /** Anthropic tool_reference metadata for tool_result blocks. */
73
+ /** Transport-supplied result references. */
74
74
  toolReferences?: string[];
75
- /** Anthropic thinking blocks — must be passed back to API in subsequent requests. */
75
+ /** Original signed reasoning, passed back unchanged through the transport. */
76
76
  thinkingBlocks?: ThinkingBlock[];
77
77
  /** Image URLs for vision-capable models. */
78
78
  imageUrls?: string[];
@@ -86,14 +86,9 @@ export interface ChatMessage {
86
86
  mcpIsError?: boolean;
87
87
  /** Image detail level: 'auto' | 'low' | 'high' | 'xhigh'. */
88
88
  imageDetail?: "auto" | "low" | "high" | "xhigh";
89
- /** Max image pixels budget (Volcengine image_pixel_limit). */
90
- imagePixelLimit?: {
91
- minPixels?: number;
92
- maxPixels?: number;
93
- };
94
89
  /** Video URLs for video-understanding models. */
95
90
  videoUrls?: string[];
96
- /** Per-video fps for video understanding (0.2-5, default 1). */
91
+ /** Sampling hint interpreted and validated by the injected transport. */
97
92
  videoFps?: number;
98
93
  /** Audio format hint: 'mp3' | 'wav' | 'aac' | 'm4a'. */
99
94
  audioFormat?: "mp3" | "wav" | "aac" | "m4a";
@@ -105,17 +100,9 @@ export interface ChatMessage {
105
100
  mimeType?: string;
106
101
  size?: number;
107
102
  }>;
108
- /** UI-facing structured blocks persisted with transcripts; ignored by model transports. */
109
- blocks?: Array<Record<string, unknown>>;
110
- /**
111
- * Structured attachment entries (product UI: element/browserView/file/image/…),
112
- * persisted with the transcript and surfaced to the UI as chips. Opaque to the agent and ignored
113
- * by model transports — the model-facing context is derived product-side and appended transiently
114
- * to the LLM message, never stored here.
115
- */
116
- attachmentEntries?: Array<Record<string, unknown>>;
117
103
  }
118
- export type ToolCapabilityCategory = "business" | "skill" | "mcp" | "orchestration";
104
+ /** Product vocabulary; Core neither classifies tools nor restricts new categories. */
105
+ export type ToolCapabilityCategory = string;
119
106
  export interface LocalizedToolText {
120
107
  key: string;
121
108
  fallback: string;
@@ -129,7 +116,7 @@ export interface ToolIdentity {
129
116
  schemaVersion: 1;
130
117
  wireName: string;
131
118
  logicalName: string;
132
- family: "business" | "skill" | "mcp" | "orchestration";
119
+ family: string;
133
120
  owner: "product";
134
121
  serverId?: string;
135
122
  capabilityId: string;
@@ -3,11 +3,12 @@ export interface ToolCallExecutionEvidence {
3
3
  sequence: number;
4
4
  callId: string;
5
5
  name: string;
6
- identity: ToolIdentity;
6
+ /** Product-authored identity only; absence is not inferred from a wire name. */
7
+ identity?: ToolIdentity;
7
8
  status: "running" | "succeeded" | "failed" | "blocked";
8
9
  arguments?: string;
9
10
  error?: string;
10
- failureKind?: "policy_blocked" | "semantic_quality_failed" | "timeout" | "mcp_start_failed" | "mcp_unavailable" | "tool_execution_failed";
11
+ failureKind?: "policy_blocked" | "tool_execution_failed";
11
12
  }
12
13
  export declare function classifyToolFailureKind(result: {
13
14
  blocked?: boolean;
@@ -0,0 +1,26 @@
1
+ /** Execution and model controls supplied by the SaaS product. Credentials belong to its injected transport. */
2
+ export interface TurnConfig {
3
+ model?: string;
4
+ /** Undefined means no Core-imposed round ceiling. */
5
+ maxRounds?: number;
6
+ temperature?: number;
7
+ contextWindowTokens?: number;
8
+ maxOutputTokens?: number;
9
+ toolChoice?: "auto" | "none" | "required";
10
+ /** Zero or undefined uses maxRounds. */
11
+ maxTurns?: number;
12
+ /** Zero permits unlimited concurrent tool execution. */
13
+ maxConcurrentTools?: number;
14
+ streamRequired?: boolean;
15
+ reasoning?: {
16
+ effort: "auto" | "minimal" | "low" | "medium" | "high" | "xhigh";
17
+ includeEncryptedReasoning?: boolean;
18
+ };
19
+ promptCacheKey?: string;
20
+ promptCacheRetention?: "in_memory" | "24h";
21
+ serviceTier?: "auto" | "default" | "flex" | "priority";
22
+ /** Executable calls accepted from one model response; resets each round. */
23
+ maxToolCalls?: number;
24
+ parallelToolCalls?: boolean;
25
+ textVerbosity?: "low" | "medium" | "high";
26
+ }
@@ -21,7 +21,6 @@ export type TurnEvent = {
21
21
  name: string;
22
22
  displayName?: string;
23
23
  arguments: string;
24
- inputSummary?: string;
25
24
  } | {
26
25
  type: "end";
27
26
  turnId: string;
@@ -1,5 +1,5 @@
1
1
  import type { ToolResult } from "./contracts.js";
2
- import type { CloudToolInvocation, CloudToolWait } from "./cloud-agent.js";
2
+ import { type CloudToolInvocation, type CloudToolWait } from "./cloud-agent.js";
3
3
  /** External job state is supplied by its product owner; Core owns no job queue or polling policy. */
4
4
  export type BusinessToolObservation = {
5
5
  kind: "result";
@@ -0,0 +1,3 @@
1
+ import type { ChatMessage, EmbeddedRuntimeOptions, ModelContextPreparation, ModelContextProjection } from "./contracts.js";
2
+ /** Reuse the canonical fallback after product retrieval; token estimates are advisory. */
3
+ export declare function prepareSlidingWindowContext(messages: readonly ChatMessage[], context: ModelContextPreparation, countMessageTokens?: EmbeddedRuntimeOptions["countMessageTokens"]): ModelContextProjection;
@@ -17,7 +17,7 @@ import type { ToolResult } from '../contracts/tool-result.js';
17
17
  export type { WireUsageRecord as UsageRecord, WireUsageSource as UsageSource } from '../contracts/usage.js';
18
18
  export type TokenUsage = import('../contracts/usage.js').WireTokenUsage;
19
19
  export type TurnEvent = import('../contracts/turn-event.js').TurnEvent;
20
- export type TurnConfig = Omit<import('../agent/types.js').TurnConfig, 'apiKey'>;
20
+ export type TurnConfig = import('../contracts/turn-config.js').TurnConfig;
21
21
  /** All three must be true on a thrown transport error before core can retry a model request. */
22
22
  export interface ModelRetryAuthorization {
23
23
  retryable: boolean;
@@ -1,5 +1,5 @@
1
1
  export { createEmbeddedAgent } from "./embedded-agent.js";
2
- export { prepareSlidingWindowContext } from "./default-runtime-ports.js";
2
+ export { prepareSlidingWindowContext } from "./context-projection.js";
3
3
  export { corePackageVersion } from "./package-version.js";
4
4
  export { AgentContentBlockValidationError, parseAgentContentBlock, } from "./content-blocks.js";
5
5
  export type { ContextAnchor, ContextEnvelope, SemanticToolCapability, ToolIdentity, UsageRecord, UsageSource, AgentLogger, ChatMessage, CreateEmbeddedAgentOptions, EmbeddedAgent, EmbeddedRuntimeOptions, ModelContextPreparation, ModelContextProjection, LLMChunk, LLMRequest, LLMTransport, ModelRetryAuthorization, ToolDefinition, ToolInvoker, ToolInvocationContext, ToolResult, TurnCheckpoint, TokenUsage, TurnConfig, TurnEvent, TurnRequest, } from "./contracts.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaozhiclaw/qlogicagent-core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Shared SaaS Agent inference and durable task runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,164 +0,0 @@
1
- /**
2
- * Pure Agent types with zero I/O framework dependencies.
3
- *
4
- * Wire-level types (ChatMessage, ToolDefinition) are canonical in
5
- * contracts/. This file re-exports them and adds
6
- * execution configuration supplied by the product.
7
- */
8
- import type { HookRegistry } from "../contracts/hooks.js";
9
- import type { WireTokenUsage } from "../contracts/usage.js";
10
- import type { AccumulatedToolCall, LLMChunk, LLMRequest, LLMTransport } from "../runtime/ports/index.js";
11
- import type { ChatMessage as WireChatMessage, ChatMessageRole as WireChatMessageRole, ThinkingBlock as WireThinkingBlock, ToolCallMessage as WireToolCallMessage, ToolDefinition as WireToolDefinition } from "../contracts/chat.js";
12
- import type { ToolCallExecutionEvidence } from "../contracts/tool-execution-evidence.js";
13
- export type ChatMessageRole = WireChatMessageRole;
14
- export type ThinkingBlock = WireThinkingBlock;
15
- export type ToolCallMessage = WireToolCallMessage;
16
- export type ChatMessage = WireChatMessage;
17
- export type { AccumulatedToolCall, LLMChunk, LLMRequest, LLMTransport, };
18
- export type ToolDefinition = WireToolDefinition;
19
- /**
20
- * Token usage unified with WireTokenUsage from contracts.
21
- * No more internal/wire split: all code uses the same field names
22
- * (inputTokens, outputTokens, reasoningTokens, cacheRead, cacheWrite).
23
- */
24
- export type TokenUsage = WireTokenUsage;
25
- export type { TurnEvent, } from "../contracts/turn-event.js";
26
- /** Observable reason why the provider loop started another inference round. */
27
- export type ToolLoopTransition = {
28
- reason: "reactive_compact_retry";
29
- } | {
30
- reason: "next_turn";
31
- };
32
- /** Terminal exit reasons from the tool loop. */
33
- export type ToolLoopTerminal = {
34
- reason: "completed";
35
- } | {
36
- reason: "aborted";
37
- } | {
38
- reason: "prompt_too_long";
39
- } | {
40
- reason: "image_error";
41
- } | {
42
- reason: "model_error";
43
- error?: unknown;
44
- } | {
45
- reason: "max_turns";
46
- } | {
47
- reason: "budget_exhausted";
48
- } | {
49
- reason: "tool_loop_limit";
50
- } | {
51
- reason: "stop_hook_prevented";
52
- } | {
53
- reason: "hook_stopped";
54
- };
55
- export interface TurnRequest {
56
- turnId: string;
57
- sessionId: string;
58
- continuation?: {
59
- completedRounds: number;
60
- usage: TokenUsage;
61
- };
62
- messages: ChatMessage[];
63
- /** Full registered tool surface before per-turn policy filtering. */
64
- availableTools?: ToolDefinition[];
65
- /** Exact tool names whose full parameter schemas are loaded only after Agent selection. */
66
- deferredToolNames?: string[];
67
- /**
68
- * Session-owned names whose deferred schemas the Agent already selected and loaded.
69
- * The loop reconciles this set against the current authoritative tool snapshot and
70
- * adds newly loaded names; it never stores schema content or capability authority.
71
- */
72
- loadedDeferredToolNames?: Set<string>;
73
- tools: ToolDefinition[];
74
- /**
75
- * Live tool-manifest rebuild, consulted each loop iteration (turnCount > 1).
76
- * It may retract or restore tools from the turn's initial authoritative snapshot.
77
- * Newly registered tools become visible on the next user turn so they cannot bypass
78
- * the complete directory, schema deferral, or permission snapshot for this turn.
79
- */
80
- refreshTools?: () => ToolDefinition[];
81
- /**
82
- * Drain user guidance queued mid-turn (运行中引导). Consulted at the top of every
83
- * tool-loop round; returned strings become user messages before the next LLM call.
84
- */
85
- drainPendingGuidance?: () => string[];
86
- /**
87
- * Drain bounded background-task results for this session. Consulted between
88
- * rounds so completed product jobs can rejoin the parent without model polling.
89
- */
90
- drainPendingTaskNotifications?: () => string[];
91
- /**
92
- * Route media a tool returns that the MAIN model can't consume (e.g. `read` returning an image
93
- * for a text-only model) to the understanding model; folds the description into the message text
94
- * and drops the raw media. Forwarded to the tool loop; mutates the message in place.
95
- */
96
- sanitizeToolResultMedia?: (message: Record<string, unknown>) => Promise<void>;
97
- systemPrompt?: string;
98
- config?: TurnConfig;
99
- }
100
- export interface TurnConfig {
101
- /** Model id, e.g. "deepseek-v4-flash" */
102
- model?: string;
103
- /** Inference credential injected by the product service. */
104
- apiKey?: string;
105
- /** Explicit max tool-call rounds per turn. Undefined means unbounded. */
106
- maxRounds?: number;
107
- /** Temperature override */
108
- temperature?: number;
109
- /** Context window size in tokens (for turn-loop-guard budget checks) */
110
- contextWindowTokens?: number;
111
- /** Max output tokens for current model */
112
- maxOutputTokens?: number;
113
- /** Tool choice strategy: "auto" (default), "none", "required" */
114
- toolChoice?: "auto" | "none" | "required";
115
- /** Max turns (tool loop iterations). 0 or undefined = use maxRounds. */
116
- maxTurns?: number;
117
- /** Max concurrent tool executions (0 = unlimited). */
118
- maxConcurrentTools?: number;
119
- /** Model requires streaming; disable transport-level non-streaming fallback. */
120
- streamRequired?: boolean;
121
- /** Reasoning effort for models that support it (GPT-5.x, o-series). */
122
- reasoning?: {
123
- effort: "auto" | "minimal" | "low" | "medium" | "high" | "xhigh";
124
- includeEncryptedReasoning?: boolean;
125
- };
126
- /** Prompt cache bucketing key used instead of the provider-level `user` field. */
127
- promptCacheKey?: string;
128
- /** Prompt cache retention: "in_memory" (5-10min) or "24h". */
129
- promptCacheRetention?: "in_memory" | "24h";
130
- /** Service tier selected by the product model configuration. */
131
- serviceTier?: "auto" | "default" | "flex" | "priority";
132
- /** Max genuinely executable tool calls accepted from one model response; resets each round. */
133
- maxToolCalls?: number;
134
- /** Disable parallel tool calling (force sequential). */
135
- parallelToolCalls?: boolean;
136
- /** Text output verbosity hint: "low", "medium", "high". */
137
- textVerbosity?: "low" | "medium" | "high";
138
- }
139
- export type { ToolCallExecutionEvidence };
140
- /**
141
- * ToolInvoker: injected execution boundary owned by the SaaS product.
142
- */
143
- export interface ToolInvoker {
144
- invoke(turnId: string, name: string, args: string, signal?: AbortSignal, invocation?: {
145
- callId: string;
146
- sessionId: string;
147
- round: number;
148
- }): Promise<import("../contracts/tool-result.js").ToolResult>;
149
- }
150
- /**
151
- * AgentLogger: structured logging interface.
152
- * The SaaS service injects its own logging implementation.
153
- */
154
- export interface AgentLogger {
155
- info(message: string): void;
156
- info(obj: Record<string, unknown>, message: string): void;
157
- warn(message: string): void;
158
- warn(obj: Record<string, unknown>, message: string): void;
159
- error(message: string): void;
160
- error(obj: Record<string, unknown>, message: string): void;
161
- debug(message: string): void;
162
- debug(obj: Record<string, unknown>, message: string): void;
163
- }
164
- export type { HookRegistry };
@@ -1,6 +0,0 @@
1
- import type { AgentRuntimePorts } from "../runtime/ports/agent-runtime-ports.js";
2
- import type { EmbeddedRuntimeOptions, ModelContextPreparation, ModelContextProjection } from "./contracts.js";
3
- import type { ChatMessage } from "./contracts.js";
4
- /** Reuse the canonical fallback after product retrieval; no second compression implementation. */
5
- export declare function prepareSlidingWindowContext(messages: readonly ChatMessage[], context: ModelContextPreparation, countMessageTokens?: EmbeddedRuntimeOptions["countMessageTokens"]): ModelContextProjection;
6
- export declare function createEmbeddedRuntimePorts(options?: EmbeddedRuntimeOptions): AgentRuntimePorts;
@@ -1,70 +0,0 @@
1
- import type { HookRegistry } from "../../contracts/hooks.js";
2
- import type { OpenAiToolCall } from "./tool-call-contracts.js";
3
- import type { AgentLogger, ChatMessage, TokenUsage, ToolInvoker } from "./agent-execution-contracts.js";
4
- export interface RuntimeCompressibleMessage {
5
- role: string;
6
- content?: string | unknown;
7
- }
8
- export interface RuntimeCompressionResult {
9
- messages: RuntimeCompressibleMessage[];
10
- droppedCount: number;
11
- tokensFreed?: number;
12
- strategy: string;
13
- }
14
- export interface ToolExecutionResultPort {
15
- callId: string;
16
- toolName: string;
17
- ok: boolean;
18
- error?: string;
19
- blocked?: boolean;
20
- blockReason?: string;
21
- durationMs?: number;
22
- details?: Record<string, unknown>;
23
- message: unknown;
24
- }
25
- export interface StreamingToolExecutorPort {
26
- addTool(toolCall: OpenAiToolCall): void;
27
- getRemainingResults(): AsyncIterable<ToolExecutionResultPort>;
28
- }
29
- export interface StreamingToolExecutorPortConfig {
30
- toolInvoker: ToolInvoker;
31
- round?: number;
32
- hooks?: HookRegistry;
33
- sessionId: string;
34
- turnId: string;
35
- log: AgentLogger;
36
- signal?: AbortSignal;
37
- maxConcurrentTools?: number;
38
- maxExecutionMs?: number;
39
- executionTimeoutMsByTool?: ReadonlyMap<string, number>;
40
- }
41
- export interface ToolLoopRuntimePorts {
42
- reviewCompletion?(messages: readonly ChatMessage[], answer: string): Promise<ChatMessage[]>;
43
- saveCheckpoint?(checkpoint: {
44
- turnId: string;
45
- sessionId: string;
46
- phase: "model_ready" | "tools_pending";
47
- messages: ChatMessage[];
48
- completedRounds: number;
49
- usage: TokenUsage;
50
- }): Promise<void>;
51
- enforceToolResultBudget(messages: Array<{
52
- role: string;
53
- content?: string | unknown;
54
- tool_call_id?: string;
55
- }>): Promise<{
56
- messages: unknown[];
57
- newlyReplacedCount: number;
58
- }>;
59
- compressMessages(messages: RuntimeCompressibleMessage[], options: {
60
- budget: number;
61
- model: string;
62
- sessionId: string;
63
- turnId: string;
64
- signal?: AbortSignal;
65
- }): RuntimeCompressionResult | Promise<RuntimeCompressionResult>;
66
- createStreamingToolExecutor(config: StreamingToolExecutorPortConfig): StreamingToolExecutorPort;
67
- }
68
- export interface AgentRuntimePorts {
69
- toolLoop: ToolLoopRuntimePorts;
70
- }
@@ -1,5 +0,0 @@
1
- export { buildToolResultMessage, type OpenAiToolCall, type ToolResultMessageInput } from "./tool-call-contracts.js";
2
- export type { AgentLogger, ChatMessage, TokenUsage, ToolDefinition, ToolInvoker, TurnEvent } from "./agent-execution-contracts.js";
3
- export type { AccumulatedToolCall, LLMChunk, LLMRequest, LLMTransport } from "./model-transport-contracts.js";
4
- export { accumulateToolCalls } from "./model-transport-contracts.js";
5
- export type { AgentRuntimePorts, RuntimeCompressibleMessage, RuntimeCompressionResult, StreamingToolExecutorPort, StreamingToolExecutorPortConfig, ToolExecutionResultPort, ToolLoopRuntimePorts } from "./agent-runtime-ports.js";
@@ -1,20 +0,0 @@
1
- export interface OpenAiToolCall {
2
- id: string;
3
- type: "function";
4
- function: {
5
- name: string;
6
- arguments: string;
7
- };
8
- }
9
- export interface ToolResultMessageInput {
10
- ok: boolean;
11
- payload?: unknown;
12
- error?: string;
13
- toolReferences?: string[];
14
- imageUrls?: string[];
15
- contentBlocks?: import("../../contracts/tool-result.js").ToolResult["contentBlocks"];
16
- structuredContent?: Record<string, unknown>;
17
- mcpMeta?: Record<string, unknown>;
18
- mcpIsError?: boolean;
19
- }
20
- export declare function buildToolResultMessage(callId: string, result: ToolResultMessageInput): import("../../contracts/chat.js").ChatMessage;