@xiaozhiclaw/qlogicagent-core 0.1.6 → 0.2.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,5 +1,7 @@
1
+ import type { ModelOperation } from "./model-operation.js";
2
+ import { type BusinessAssistantContext, type BusinessGoal } from "./business-contracts.js";
1
3
  import { type AgentContentBlock } from "./content-blocks.js";
2
- import type { CreateEmbeddedAgentOptions, ToolResult, TurnCheckpoint, TurnEvent, TurnRequest } from "./contracts.js";
4
+ import type { CreateEmbeddedAgentOptions, ToolResult, TurnCheckpoint, TurnEvent, TurnRequest, LLMRequest } from "./contracts.js";
3
5
  export interface CloudExecutionContext {
4
6
  applicationId: string;
5
7
  tenantId: string;
@@ -22,10 +24,18 @@ export interface CloudCheckpoint extends TurnCheckpoint {
22
24
  /** Exact model/tool/Skill configuration, not a credential or an authorization. */
23
25
  binding: string;
24
26
  contentBlocks: AgentContentBlock[];
27
+ modelOperations?: ModelOperation[];
25
28
  }
26
29
  export interface CloudTurnRequest extends Omit<TurnRequest, "continuation"> {
27
30
  context: CloudExecutionContext;
28
31
  resume?: CloudCheckpoint;
32
+ assistantContext?: BusinessAssistantContext;
33
+ goal?: BusinessGoal;
34
+ /** Counts all attempts across checkpoints, including rejected attempts. */
35
+ executionBudget?: {
36
+ maxModelRequests?: number;
37
+ deadlineAtMs?: number;
38
+ };
29
39
  }
30
40
  export interface CloudToolWait {
31
41
  kind: "wait";
@@ -66,6 +76,12 @@ export interface CloudAgentOptions extends Omit<CreateEmbeddedAgentOptions, "too
66
76
  /** Awaited before a successful result is acknowledged or another model step starts. */
67
77
  onToolResult?(invocation: CloudToolInvocation, result: ToolResult): Promise<void>;
68
78
  onWait?(invocation: CloudToolInvocation, wait: CloudToolWait["wait"]): Promise<void>;
79
+ /** Await the durable attempt record before network I/O and before acknowledging completion. */
80
+ onModelOperation?(operation: ModelOperation): Promise<void>;
81
+ /** Product/model service atomically reserves money or token quota before network I/O. */
82
+ reserveModelBudget?(context: Readonly<CloudExecutionContext>, operation: Omit<ModelOperation, "response">, request: LLMRequest, signal?: AbortSignal): Promise<{
83
+ reference: string;
84
+ }>;
69
85
  }
70
86
  export interface CloudAgent {
71
87
  run(request: CloudTurnRequest, signal?: AbortSignal): AsyncGenerator<CloudTurnEvent>;
@@ -1,5 +1,7 @@
1
1
  import { type CloudAgentOptions, type CloudCheckpoint, type CloudExecutionContext, type CloudToolReceipt, type CloudToolWait, type CloudTurnEvent, type CloudTurnRequest } from "./cloud-agent.js";
2
2
  import type { ToolResult } from "./contracts.js";
3
+ import type { ModelOperation, ModelRecoveryProof } from "./model-operation.js";
4
+ import { type BusinessGoalEvidence, type BusinessGoalOutcome } from "./business-contracts.js";
3
5
  export type CloudTaskStatus = "queued" | "running" | "waiting_input" | "waiting_confirmation" | "waiting_external" | "reconciliation_required" | "completed" | "stopped" | "failed" | "cancelled";
4
6
  export interface CloudTaskSnapshot {
5
7
  id: string;
@@ -14,6 +16,10 @@ export interface CloudTaskSnapshot {
14
16
  descriptor: CloudToolWait["wait"];
15
17
  };
16
18
  errorCode?: string;
19
+ modelOperations?: ModelOperation[];
20
+ /** Durable product cancellation intent; reconciliation never resumes subsequent work. */
21
+ cancellationRequested?: boolean;
22
+ outcome?: BusinessGoalOutcome;
17
23
  }
18
24
  export type CloudTaskEventPayload = CloudTurnEvent | {
19
25
  type: "task_status";
@@ -26,6 +32,9 @@ export type CloudTaskEventPayload = CloudTurnEvent | {
26
32
  callId: string;
27
33
  round: number;
28
34
  name: string;
35
+ } | {
36
+ type: "model_operation";
37
+ operation: Omit<ModelOperation, "response">;
29
38
  };
30
39
  export interface CloudTaskEvent {
31
40
  cursor: number;
@@ -48,20 +57,28 @@ export interface CloudTaskStore {
48
57
  update(context: CloudExecutionContext, id: string, expectedRevision: number, task: CloudTaskSnapshot, event: CloudTaskEventPayload, leaseId?: string): Promise<CloudTaskSnapshot>;
49
58
  release(context: CloudExecutionContext, id: string, leaseId: string): Promise<void>;
50
59
  events(context: CloudExecutionContext, id: string, after: number, limit: number): Promise<CloudTaskEvent[]>;
51
- /** Atomic cancel and lease invalidation; terminal tasks stay unchanged. */
60
+ /** Atomic lease invalidation. Preserve unresolved model billing/effects as reconciliation_required;
61
+ * acknowledge cancelled only when their outcomes are known. Terminal tasks stay unchanged. */
52
62
  cancel(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
53
63
  /** Only an expired worker may be fenced and moved to reconciliation_required. */
54
64
  interrupt(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
55
65
  }
56
66
  export interface CloudTaskRuntimeOptions {
57
67
  store: CloudTaskStore;
58
- agent: Omit<CloudAgentOptions, "checkpoints" | "onToolResult" | "onWait">;
68
+ agent: Omit<CloudAgentOptions, "checkpoints" | "onToolResult" | "onWait" | "onModelOperation">;
69
+ /** Query authoritative product state; an LLM's success text is never completion evidence. */
70
+ verifyGoal?(task: CloudTaskSnapshot): Promise<BusinessGoalEvidence>;
59
71
  authorize(context: CloudExecutionContext, action: "create" | "read" | "execute" | "cancel" | "complete_wait" | "recover"): Promise<void>;
60
72
  /** Validate actual employee approval/input or query the original external job; never trust browser results. */
61
73
  authorizeCompletion(task: CloudTaskSnapshot, waitId: string, result: ToolResult): Promise<void>;
62
74
  /** Required for interrupted model calls or unresolved effects. The product proves billing/retry safety. */
63
- authorizeRecovery?(task: CloudTaskSnapshot, receipts: CloudToolReceipt[]): Promise<void>;
75
+ authorizeRecovery?(task: CloudTaskSnapshot, receipts: CloudToolReceipt[]): Promise<ModelRecoveryProof[] | void>;
64
76
  heartbeatMs?: number;
77
+ /** Optional bounded text batching; all control events still flush in order. */
78
+ deltaBatch?: {
79
+ maxCharacters: number;
80
+ maxDelayMs: number;
81
+ };
65
82
  }
66
83
  export interface CloudTaskRuntime {
67
84
  create(id: string, request: CloudTurnRequest): Promise<CloudTaskSnapshot>;
@@ -1,3 +1,5 @@
1
+ /** MCP wire blocks are opaque product evidence; only presentation blocks go to the UI parser. */
2
+ export declare function parsePresentationBlocks(blocks: Array<AgentContentBlock | Record<string, unknown>>): AgentContentBlock[];
1
3
  export type AgentEngineeringFormat = "dxf" | "dwg" | "step" | "stp" | "glb" | "gltf";
2
4
  export type AgentEngineeringPreviewMode = "direct" | "browser_conversion" | "external_conversion_required";
3
5
  export type AgentEngineeringParseStatus = "parsed" | "partial" | "conversion_required";
@@ -1,4 +1,3 @@
1
- import type { AgentContentBlock } from "./content-blocks.js";
2
1
  export interface AgentLogger {
3
2
  info(message: string): void;
4
3
  info(context: Record<string, unknown>, message: string): void;
@@ -9,106 +8,16 @@ export interface AgentLogger {
9
8
  debug(message: string): void;
10
9
  debug(context: Record<string, unknown>, message: string): void;
11
10
  }
12
- export interface ToolCallMessage {
13
- id: string;
14
- type: "function";
15
- function: {
16
- name: string;
17
- arguments: string;
18
- };
19
- }
20
- export interface ChatMessage {
21
- role: "system" | "user" | "assistant" | "tool";
22
- content: string | null;
23
- tool_calls?: ToolCallMessage[];
24
- tool_call_id?: string;
25
- name?: string;
26
- is_error?: boolean;
27
- reasoning_content?: string;
28
- thinkingBlocks?: Array<{
29
- thinking: string;
30
- signature: string;
31
- }>;
32
- }
33
- export interface ToolDefinition {
34
- type: "function";
35
- meta?: {
36
- executionTimeoutMs?: number;
37
- };
38
- function: {
39
- name: string;
40
- description: string;
41
- parameters?: Record<string, unknown>;
42
- };
43
- }
44
- export interface LLMRequest {
45
- model: string;
46
- messages: ChatMessage[];
47
- tools?: ToolDefinition[];
48
- toolChoice?: "auto" | "none" | "required" | {
49
- type: "function";
50
- name: string;
51
- };
52
- temperature?: number;
53
- maxTokens?: number;
54
- reasoning?: {
55
- effort: "minimal" | "low" | "medium" | "high" | "xhigh";
56
- includeEncryptedReasoning?: boolean;
57
- };
58
- maxToolCalls?: number;
59
- streamRequired?: boolean;
60
- promptCacheKey?: string;
61
- promptCacheRetention?: "in_memory" | "24h";
62
- serviceTier?: "auto" | "default" | "flex" | "priority";
63
- parallelToolCalls?: boolean;
64
- textVerbosity?: "low" | "medium" | "high";
65
- }
66
- export type LLMChunk = {
67
- type: "delta";
68
- text: string;
69
- } | {
70
- type: "tool_call_delta";
71
- index: number;
72
- id?: string;
73
- name?: string;
74
- arguments: string;
75
- } | {
76
- type: "reasoning_delta";
77
- text: string;
78
- } | {
79
- type: "reasoning_block_complete";
80
- thinking: string;
81
- signature: string;
82
- } | {
83
- type: "usage";
84
- totalPromptTokens?: number;
85
- promptTokens: number;
86
- completionTokens: number;
87
- reasoningTokens?: number;
88
- cacheReadTokens?: number;
89
- cacheCreationTokens?: number;
90
- } | {
91
- type: "response_id";
92
- id: string;
93
- } | {
94
- type: "annotations";
95
- annotations: Array<{
96
- type: string;
97
- url?: string;
98
- title?: string;
99
- [key: string]: unknown;
100
- }>;
101
- } | {
102
- type: "error";
103
- message: string;
104
- outcome?: "rejected" | "unknown";
105
- } | {
106
- type: "done";
107
- finishReason: string;
108
- };
109
- export interface LLMTransport {
110
- stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
111
- }
11
+ export type { ToolCallMessage, ChatMessage, ToolDefinition, ContextAnchor, ContextEnvelope, SemanticToolCapability, ToolIdentity } from '../contracts/chat.js';
12
+ export type { LLMRequest, LLMChunk, LLMTransport } from '../runtime/ports/model-transport-contracts.js';
13
+ export type { ToolResult } from '../contracts/tool-result.js';
14
+ import type { ChatMessage, ToolDefinition } from '../contracts/chat.js';
15
+ import type { LLMTransport } from '../runtime/ports/model-transport-contracts.js';
16
+ import type { ToolResult } from '../contracts/tool-result.js';
17
+ export type { WireUsageRecord as UsageRecord, WireUsageSource as UsageSource } from '../contracts/usage.js';
18
+ export type TokenUsage = import('../contracts/usage.js').WireTokenUsage;
19
+ export type TurnEvent = import('../contracts/turn-event.js').TurnEvent;
20
+ export type TurnConfig = Omit<import('../agent/types.js').TurnConfig, 'apiKey'>;
112
21
  /** All three must be true on a thrown transport error before core can retry a model request. */
113
22
  export interface ModelRetryAuthorization {
114
23
  retryable: boolean;
@@ -122,39 +31,9 @@ export interface ToolInvocationContext {
122
31
  sessionId: string;
123
32
  round: number;
124
33
  }
125
- export interface ToolResult {
126
- result: string;
127
- error?: string;
128
- toolReferences?: string[];
129
- imageUrls?: string[];
130
- contentBlocks?: AgentContentBlock[];
131
- structuredContent?: Record<string, unknown>;
132
- mcpMeta?: Record<string, unknown>;
133
- mcpIsError?: boolean;
134
- details?: Record<string, unknown>;
135
- }
136
34
  export interface ToolInvoker {
137
35
  invoke(turnId: string, name: string, args: string, signal?: AbortSignal, invocation?: ToolInvocationContext): Promise<ToolResult>;
138
36
  }
139
- export interface TurnConfig {
140
- model?: string;
141
- maxRounds?: number;
142
- temperature?: number;
143
- contextWindowTokens?: number;
144
- maxOutputTokens?: number;
145
- modelMaxOutputTokens?: number;
146
- maxTurns?: number;
147
- maxToolCalls?: number;
148
- maxConcurrentTools?: number;
149
- parallelToolCalls?: boolean;
150
- streamRequired?: boolean;
151
- toolChoice?: "auto" | "none" | "required";
152
- reasoning?: LLMRequest["reasoning"];
153
- promptCacheKey?: string;
154
- promptCacheRetention?: LLMRequest["promptCacheRetention"];
155
- serviceTier?: LLMRequest["serviceTier"];
156
- textVerbosity?: LLMRequest["textVerbosity"];
157
- }
158
37
  export interface TurnRequest {
159
38
  turnId: string;
160
39
  sessionId: string;
@@ -169,105 +48,6 @@ export interface TurnRequest {
169
48
  usage: TokenUsage;
170
49
  };
171
50
  }
172
- export interface TokenUsage {
173
- inputTokens?: number;
174
- outputTokens?: number;
175
- reasoningTokens?: number;
176
- cacheRead?: number;
177
- cacheWrite?: number;
178
- }
179
- export type TurnEvent = {
180
- type: "start";
181
- turnId: string;
182
- effectiveMaxRounds?: number;
183
- effectiveMaxToolCalls?: number;
184
- } | {
185
- type: "delta";
186
- turnId: string;
187
- text: string;
188
- } | {
189
- type: "tool_call";
190
- turnId: string;
191
- callId: string;
192
- name: string;
193
- displayName?: string;
194
- arguments: string;
195
- inputSummary?: string;
196
- } | {
197
- type: "tool_result";
198
- turnId: string;
199
- callId: string;
200
- name: string;
201
- ok: boolean;
202
- error?: string;
203
- outputPreview?: string;
204
- durationMs?: number;
205
- details?: Record<string, unknown>;
206
- } | {
207
- type: "tool_blocked";
208
- turnId: string;
209
- callId: string;
210
- name: string;
211
- reason: string;
212
- } | {
213
- type: "recovery";
214
- turnId: string;
215
- action: string;
216
- detail?: string;
217
- } | {
218
- type: "text_rollback";
219
- turnId: string;
220
- keepLength: number;
221
- reason: string;
222
- } | {
223
- type: "reasoning_delta";
224
- turnId: string;
225
- text: string;
226
- } | {
227
- type: "lifecycle";
228
- turnId: string;
229
- kind: "context_compression";
230
- status: string;
231
- detail: string;
232
- } | {
233
- type: "annotations";
234
- turnId: string;
235
- annotations: Array<{
236
- type: string;
237
- url?: string;
238
- title?: string;
239
- [key: string]: unknown;
240
- }>;
241
- } | {
242
- type: "tool_use_summary";
243
- turnId: string;
244
- ledgerSchemaVersion: 5;
245
- toolCalls: Array<Record<string, unknown>>;
246
- availableToolNames: string[];
247
- enabledToolNames: string[];
248
- toolCallNames: string[];
249
- blockedToolCalls: Array<{
250
- name: string;
251
- reason: string;
252
- }>;
253
- } | {
254
- type: "end";
255
- turnId: string;
256
- content: string;
257
- turnStatus?: "completed" | "stopped";
258
- taskOutcome?: "unverified";
259
- usage?: TokenUsage;
260
- model?: string;
261
- provider?: string;
262
- recoveryTrace?: Record<string, number>;
263
- contentBlocks?: AgentContentBlock[];
264
- } | {
265
- type: "error";
266
- turnId: string;
267
- error: string;
268
- code?: string;
269
- usage?: TokenUsage;
270
- };
271
51
  export interface EmbeddedRuntimeOptions {
272
52
  maxToolResultChars?: number;
273
53
  onCheckpoint?: (checkpoint: TurnCheckpoint) => Promise<void>;
@@ -1,7 +1,9 @@
1
1
  export { createEmbeddedAgent } from "./embedded-agent.js";
2
2
  export { AgentContentBlockValidationError, analyzeEngineeringFile, createStandardPresentationToolResult, isEngineeringFile, parseAgentContentBlock, standardPresentationToolDefinitions, standardPresentationToolNames, } from "./content-blocks.js";
3
- export type { AgentLogger, ChatMessage, CreateEmbeddedAgentOptions, EmbeddedAgent, EmbeddedRuntimeOptions, LLMChunk, LLMRequest, LLMTransport, ModelRetryAuthorization, ToolDefinition, ToolInvoker, ToolInvocationContext, ToolResult, TurnCheckpoint, TokenUsage, TurnConfig, TurnEvent, TurnRequest, } from "./contracts.js";
4
- export { createCloudAgent, completeCloudToolCheckpoint } from "./cloud-agent.js";
3
+ export type { ContextAnchor, ContextEnvelope, SemanticToolCapability, ToolIdentity, UsageRecord, UsageSource, AgentLogger, ChatMessage, CreateEmbeddedAgentOptions, EmbeddedAgent, EmbeddedRuntimeOptions, LLMChunk, LLMRequest, LLMTransport, ModelRetryAuthorization, ToolDefinition, ToolInvoker, ToolInvocationContext, ToolResult, TurnCheckpoint, TokenUsage, TurnConfig, TurnEvent, TurnRequest, } from "./contracts.js";
4
+ export type { ModelOperation, ModelRecoveryProof } from "./model-operation.js";
5
+ export type { BusinessAssistantContext, BusinessGoal, BusinessGoalEvidence, BusinessGoalOutcome } from "./business-contracts.js";
6
+ export { createCloudAgent, completeCloudToolCheckpoint, canonicalCloudValue } from "./cloud-agent.js";
5
7
  export type { CloudAgent, CloudAgentOptions, CloudCheckpoint, CloudExecutionContext, CloudToolInvocation, CloudToolReceipt, CloudToolWait, CloudTurnEvent, CloudTurnRequest, } from "./cloud-agent.js";
6
8
  export { createCloudTaskRuntime } from "./cloud-task.js";
7
9
  export type { CloudTaskStore, CloudTaskSnapshot, CloudTaskStatus, CloudTaskClaim, CloudTaskEvent, CloudTaskEventPayload, CloudTaskRuntime, CloudTaskRuntimeOptions, } from "./cloud-task.js";
@@ -0,0 +1,40 @@
1
+ import type { UsageRecord } from "./contracts.js";
2
+ import type { LLMChunk } from "./contracts.js";
3
+ /** Product-persisted inference attempt. Request bodies/credentials are excluded; response is separately sensitive. */
4
+ export interface ModelOperation {
5
+ requestId: string;
6
+ round: number;
7
+ attempt: number;
8
+ requestDigest: string;
9
+ model: string;
10
+ startedAtMs?: number;
11
+ finishedAtMs?: number;
12
+ status: "prepared" | "responding" | "completed" | "rejected" | "unknown";
13
+ responseId?: string;
14
+ finishReason?: string;
15
+ usage?: {
16
+ inputTokens: number;
17
+ outputTokens: number;
18
+ records?: UsageRecord[];
19
+ };
20
+ /** Sensitive original response, owned by the product store; never included in progress events. */
21
+ response?: LLMChunk[];
22
+ reconciliationReference?: string;
23
+ budgetReference?: string;
24
+ }
25
+ /** Evidence returned by the authorized product after querying its model/billing service. */
26
+ interface ModelRecoveryIdentity {
27
+ requestId: string;
28
+ requestDigest: string;
29
+ evidenceReference: string;
30
+ }
31
+ export type ModelRecoveryProof = ModelRecoveryIdentity & ({
32
+ outcome: "rejected";
33
+ safeToRetry: true;
34
+ } | {
35
+ outcome: "completed";
36
+ response: LLMChunk[];
37
+ responseId: string;
38
+ usage?: ModelOperation["usage"];
39
+ });
40
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { HookRegistry } from "../../contracts/hooks.js";
2
+ import type { WireTokenUsage } from "../../contracts/usage.js";
3
+ import type { ChatMessage as WireChatMessage, ToolDefinition as WireToolDefinition } from "../../contracts/chat.js";
4
+ export type { TurnEvent } from "../../contracts/turn-event.js";
5
+ export type ChatMessage = WireChatMessage;
6
+ export type TokenUsage = WireTokenUsage;
7
+ export type ToolDefinition = WireToolDefinition;
8
+ export interface ToolInvoker {
9
+ invoke(turnId: string, name: string, args: string, signal?: AbortSignal, invocation?: {
10
+ callId: string;
11
+ sessionId: string;
12
+ round: number;
13
+ }): Promise<import("../../contracts/tool-result.js").ToolResult>;
14
+ }
15
+ export interface AgentLogger {
16
+ info(message: string): void;
17
+ info(obj: Record<string, unknown>, message: string): void;
18
+ warn(message: string): void;
19
+ warn(obj: Record<string, unknown>, message: string): void;
20
+ error(message: string): void;
21
+ error(obj: Record<string, unknown>, message: string): void;
22
+ debug(message: string): void;
23
+ debug(obj: Record<string, unknown>, message: string): void;
24
+ }
25
+ export type { HookRegistry };
@@ -0,0 +1,66 @@
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
+ saveCheckpoint?(checkpoint: {
43
+ turnId: string;
44
+ sessionId: string;
45
+ phase: "model_ready" | "tools_pending";
46
+ messages: ChatMessage[];
47
+ completedRounds: number;
48
+ usage: TokenUsage;
49
+ }): Promise<void>;
50
+ enforceToolResultBudget(messages: Array<{
51
+ role: string;
52
+ content?: string | unknown;
53
+ tool_call_id?: string;
54
+ }>): Promise<{
55
+ messages: unknown[];
56
+ newlyReplacedCount: number;
57
+ }>;
58
+ compressMessages(messages: RuntimeCompressibleMessage[], options: {
59
+ budget: number;
60
+ model: string;
61
+ }): RuntimeCompressionResult;
62
+ createStreamingToolExecutor(config: StreamingToolExecutorPortConfig): StreamingToolExecutorPort;
63
+ }
64
+ export interface AgentRuntimePorts {
65
+ toolLoop: ToolLoopRuntimePorts;
66
+ }
@@ -0,0 +1,5 @@
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";
@@ -0,0 +1,92 @@
1
+ import type { ChatMessage, ToolDefinition } from "./agent-execution-contracts.js";
2
+ import type { WireUsageRecord } from "../../contracts/usage.js";
3
+ import type { ModelOperation, ModelRecoveryProof } from "../../embedded/model-operation.js";
4
+ export interface LLMRequest {
5
+ /** Stable product execution reference; not a provider-side idempotency guarantee. */
6
+ execution?: {
7
+ requestId: string;
8
+ requestDigest: string;
9
+ round: number;
10
+ attempt: number;
11
+ };
12
+ model: string;
13
+ messages: ChatMessage[];
14
+ tools?: ToolDefinition[];
15
+ toolChoice?: "auto" | "none" | "required" | {
16
+ type: "function";
17
+ name: string;
18
+ };
19
+ temperature?: number;
20
+ maxTokens?: number;
21
+ reasoning?: {
22
+ effort: "minimal" | "low" | "medium" | "high" | "xhigh";
23
+ includeEncryptedReasoning?: boolean;
24
+ };
25
+ /** Core-enforced executable function-call budget; not a Chat Completions wire field. */
26
+ maxToolCalls?: number;
27
+ streamRequired?: boolean;
28
+ promptCacheKey?: string;
29
+ promptCacheRetention?: "in_memory" | "24h";
30
+ serviceTier?: "auto" | "default" | "flex" | "priority";
31
+ parallelToolCalls?: boolean;
32
+ textVerbosity?: "low" | "medium" | "high";
33
+ }
34
+ export type LLMChunk = {
35
+ type: "delta";
36
+ text: string;
37
+ } | {
38
+ type: "tool_call_delta";
39
+ index: number;
40
+ id?: string;
41
+ name?: string;
42
+ arguments: string;
43
+ argumentsMode?: "append" | "replace";
44
+ } | {
45
+ type: "reasoning_delta";
46
+ text: string;
47
+ } | {
48
+ type: "reasoning_block_complete";
49
+ thinking: string;
50
+ signature: string;
51
+ } | {
52
+ type: "usage";
53
+ totalPromptTokens?: number;
54
+ promptTokens: number;
55
+ completionTokens: number;
56
+ reasoningTokens?: number;
57
+ cacheReadTokens?: number;
58
+ cacheCreationTokens?: number;
59
+ records?: WireUsageRecord[];
60
+ } | {
61
+ type: "response_id";
62
+ id: string;
63
+ } | {
64
+ type: "annotations";
65
+ annotations: Array<{
66
+ type: string;
67
+ url?: string;
68
+ title?: string;
69
+ [key: string]: unknown;
70
+ }>;
71
+ } | {
72
+ type: "error";
73
+ message: string;
74
+ outcome?: "rejected" | "unknown";
75
+ } | {
76
+ type: "done";
77
+ finishReason: string;
78
+ };
79
+ export interface AccumulatedToolCall {
80
+ id: string;
81
+ name: string;
82
+ arguments: string;
83
+ }
84
+ export interface LLMTransport {
85
+ /** Forward requested provider controls or reject unsupported ones before inference; never silently discard them. */
86
+ stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
87
+ /** Query the original service receipt without starting inference. Missing evidence must reject. */
88
+ reconcileModel?(operation: ModelOperation, apiKey: string, signal?: AbortSignal): Promise<ModelRecoveryProof>;
89
+ }
90
+ export declare function accumulateToolCalls(accumulator: Map<number, AccumulatedToolCall>, chunk: LLMChunk & {
91
+ type: "tool_call_delta";
92
+ }): void;
@@ -0,0 +1,20 @@
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaozhiclaw/qlogicagent-core",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "Shared SaaS Agent inference and durable task runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",