@xiaozhiclaw/qlogicagent-core 0.4.1 → 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.
@@ -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,67 +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
- }): RuntimeCompressionResult;
63
- createStreamingToolExecutor(config: StreamingToolExecutorPortConfig): StreamingToolExecutorPort;
64
- }
65
- export interface AgentRuntimePorts {
66
- toolLoop: ToolLoopRuntimePorts;
67
- }
@@ -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;