@xiaozhiclaw/qlogicagent-core 0.4.1 → 0.5.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.
@@ -28,6 +28,8 @@ export type TurnEvent = {
28
28
  content: string;
29
29
  /** Adapter lifecycle only; it is not a semantic task-success claim. */
30
30
  turnStatus?: "completed" | "stopped";
31
+ /** Product-requested pause at a durable model-ready boundary. */
32
+ stopReason?: "paused";
31
33
  /** Task success remains unverified unless a higher-level product workflow proves it. */
32
34
  taskOutcome?: "unverified";
33
35
  usage?: WireTokenUsage;
@@ -1,5 +1,5 @@
1
- /** Token accounting returned by an Agent turn. */
2
- export type WireUsageSource = "llmrouter.settlement" | "provider.reported" | "host.observed" | "estimated";
1
+ /** Opaque provenance supplied by the product transport, not a Core billing classification. */
2
+ export type WireUsageSource = string;
3
3
  export interface WireUsageRecord {
4
4
  schemaVersion: 1;
5
5
  source: WireUsageSource;
@@ -1,43 +1,10 @@
1
1
  import type { ToolDefinition } from "./contracts.js";
2
- /** Versioned platform knowledge; enterprise data and permission facts stay product-owned. */
2
+ /** Product-owned context. Core does not require any particular domain, resources or roles. */
3
3
  export interface BusinessAssistantContext {
4
- module: {
5
- id: string;
6
- version: string;
7
- fields: Record<string, unknown>[];
8
- operations: Array<{
9
- id: string;
10
- description: string;
11
- prerequisites: string[];
12
- }>;
13
- };
14
- enterprise: {
15
- configurationRevision: string;
16
- configuration: Record<string, unknown>;
17
- dataSources: Array<{
18
- id: string;
19
- state: "ready" | "missing" | "unavailable";
20
- reference?: string;
21
- }>;
22
- };
23
- employee: {
24
- permissionRevision: string;
25
- allowedOperations: string[];
26
- };
27
- knowledge: {
28
- revision: string;
29
- skill: string;
30
- examples: Array<{
31
- operation: string;
32
- input: string;
33
- expectedOutcome: string;
34
- evidenceReference: string;
35
- }>;
36
- exceptions: Array<{
37
- code: string;
38
- handling: string;
39
- }>;
40
- };
4
+ /** Explicit trusted instructions from the product; no other context field becomes a system instruction. */
5
+ instructions?: string;
6
+ /** JSON-serializable facts, revisions and references whose names and meanings belong to the product. */
7
+ [section: string]: unknown;
41
8
  }
42
9
  export interface BusinessGoal {
43
10
  id: string;
@@ -64,7 +31,7 @@ export interface BusinessGoalEvidence {
64
31
  export interface BusinessGoalOutcome extends BusinessGoalEvidence {
65
32
  status: "satisfied" | "incomplete";
66
33
  }
67
- /** Validate the product's versioned context without choosing or narrowing its tools. */
34
+ /** Check only the transport shape; product validation and authorization stay outside Core. */
68
35
  export declare function validateBusinessAssistantContext(value: BusinessAssistantContext, tools: ToolDefinition[]): void;
69
36
  export declare function validateBusinessGoal(goal: BusinessGoal): void;
70
37
  export declare function verifyBusinessGoalEvidence(goal: BusinessGoal, evidence: BusinessGoalEvidence): BusinessGoalOutcome;
@@ -0,0 +1,37 @@
1
+ import type { ToolResult } from "./contracts.js";
2
+ import type { CloudToolInvocation, CloudToolWait } from "./cloud-agent.js";
3
+ /** External job state is supplied by its product owner; Core owns no job queue or polling policy. */
4
+ export type BusinessToolObservation = {
5
+ kind: "result";
6
+ result: ToolResult;
7
+ } | {
8
+ kind: "pending";
9
+ reference: string;
10
+ progress?: Record<string, unknown>;
11
+ resources?: string[];
12
+ } | {
13
+ kind: "unknown";
14
+ reference: string;
15
+ detail?: string;
16
+ };
17
+ export interface BusinessToolPort {
18
+ /** Persist/deduplicate by the complete original invocation before acknowledging a job.
19
+ * Forward invocation.taskBudget unchanged to every paid generation endpoint.
20
+ */
21
+ submit(invocation: Readonly<CloudToolInvocation>, signal?: AbortSignal): Promise<BusinessToolObservation>;
22
+ /** Query the original invocation only. Absence/unknown is never permission to submit again. */
23
+ query(invocation: Readonly<CloudToolInvocation>, signal?: AbortSignal): Promise<BusinessToolObservation>;
24
+ /** Product cancellation is a request, not proof that a job or its charge did not execute. */
25
+ cancel?(invocation: Readonly<CloudToolInvocation>, signal?: AbortSignal): Promise<BusinessToolObservation>;
26
+ }
27
+ export interface BusinessToolAdapter {
28
+ invoke(invocation: CloudToolInvocation, signal?: AbortSignal): Promise<ToolResult | CloudToolWait>;
29
+ /** Resume an external wait or reconcile an interrupted submission by querying its original operation. */
30
+ resolve(invocation: CloudToolInvocation, signal?: AbortSignal): Promise<ToolResult | CloudToolWait>;
31
+ cancel(invocation: CloudToolInvocation, signal?: AbortSignal): Promise<ToolResult | CloudToolWait>;
32
+ }
33
+ export declare function createBusinessToolAdapter(options: {
34
+ port: BusinessToolPort;
35
+ /** Durable product progress/resource projection. Awaited before acknowledging any observation. */
36
+ observe?(invocation: Readonly<CloudToolInvocation>, observation: Readonly<BusinessToolObservation>): Promise<void>;
37
+ }): BusinessToolAdapter;
@@ -5,7 +5,9 @@ import { type AgentContentBlock } from "./content-blocks.js";
5
5
  import type { CreateEmbeddedAgentOptions, ToolResult, TurnCheckpoint, TurnEvent, TurnRequest, LLMRequest } from "./contracts.js";
6
6
  export interface CloudExecutionContext {
7
7
  applicationId: string;
8
+ /** Opaque product data namespace, such as a personal workspace; it need not represent an organization. */
8
9
  tenantId: string;
10
+ /** Product-defined user or service identity; Core does not require an employee role. */
9
11
  actorId: string;
10
12
  scopeId: string;
11
13
  definitionVersion: string;
@@ -58,6 +60,8 @@ export type CloudTurnEvent = TurnEvent | {
58
60
  export interface CloudToolReceipt {
59
61
  invocation: CloudToolInvocation;
60
62
  result: ToolResult;
63
+ /** Original wait identity, retained in the same receipt for lost-acknowledgement recovery. */
64
+ wait?: CloudToolWait["wait"];
61
65
  }
62
66
  /** Only the product may supply reconciled receipts; this function never executes tools. */
63
67
  export declare function completeCloudToolCheckpoint(input: CloudCheckpoint, receipts: CloudToolReceipt[]): CloudCheckpoint;
@@ -77,6 +81,9 @@ export interface CloudAgentOptions extends Omit<CreateEmbeddedAgentOptions, "too
77
81
  checkpoints?: {
78
82
  save(checkpoint: CloudCheckpoint): Promise<void>;
79
83
  };
84
+ /** Product-owned pause intent. Checked after saving a safe model-ready boundary;
85
+ * an in-flight inference or atomic tool operation is never interrupted as a pause. */
86
+ shouldPause?(context: Readonly<CloudExecutionContext>, checkpoint: Readonly<CloudCheckpoint>): Promise<boolean>;
80
87
  /** Awaited before a successful result is acknowledged or another model step starts. */
81
88
  onToolResult?(invocation: CloudToolInvocation, result: ToolResult): Promise<void>;
82
89
  onWait?(invocation: CloudToolInvocation, wait: CloudToolWait["wait"]): Promise<void>;
@@ -82,8 +82,8 @@ export interface CloudTaskRuntimeOptions {
82
82
  resolveGoal?(task: CloudTaskSnapshot): Promise<BusinessGoal | undefined>;
83
83
  /** Feed independently checked evidence back through the same loop; no separate correction runner. */
84
84
  goalFeedback?(task: CloudTaskSnapshot, outcome: BusinessGoalOutcome): Promise<ChatMessage[]>;
85
- authorize(context: CloudExecutionContext, action: "create" | "read" | "execute" | "cancel" | "complete_wait" | "recover" | "append_input"): Promise<void>;
86
- /** Validate actual employee approval/input or query the original external job; never trust browser results. */
85
+ authorize(context: CloudExecutionContext, action: "create" | "read" | "execute" | "cancel" | "complete_wait" | "recover" | "append_input" | "resume"): Promise<void>;
86
+ /** Validate product-authorized approval/input or query the original external job; never trust browser results. */
87
87
  authorizeCompletion(task: CloudTaskSnapshot, waitId: string, result: ToolResult): Promise<void>;
88
88
  /** Required for interrupted model calls or unresolved effects. The product proves billing/retry safety. */
89
89
  authorizeRecovery?(task: CloudTaskSnapshot, receipts: CloudToolReceipt[]): Promise<ModelRecoveryProof[] | void>;
@@ -101,6 +101,8 @@ export interface CloudTaskRuntime {
101
101
  /** Called by the existing product worker, independently from browser subscriptions. */
102
102
  execute(context: CloudExecutionContext, id: string, workerSignal?: AbortSignal): Promise<void>;
103
103
  cancel(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
104
+ /** Resume a durable pause without a new user input, identity or budget. */
105
+ resume(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
104
106
  /** Continue a resolved task on explicit user input, preserving its identity and original budgets. */
105
107
  appendInput(context: CloudExecutionContext, id: string, input: {
106
108
  id: string;
@@ -1,111 +1,13 @@
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[];
3
- export type AgentEngineeringFormat = "dxf" | "dwg" | "step" | "stp" | "glb" | "gltf";
4
- export type AgentEngineeringPreviewMode = "direct" | "browser_conversion" | "external_conversion_required";
5
- export type AgentEngineeringParseStatus = "parsed" | "partial" | "conversion_required";
6
- export interface AgentEngineeringMetadata {
7
- format: AgentEngineeringFormat;
8
- previewMode: AgentEngineeringPreviewMode;
9
- parseStatus: AgentEngineeringParseStatus;
10
- summary: string;
11
- }
12
- export type AgentAttachmentKind = "image" | "spreadsheet" | "presentation" | "document" | "engineering_2d" | "engineering_3d" | "file";
13
- export interface AgentAttachment {
14
- id: string;
15
- kind: AgentAttachmentKind;
16
- fileName: string;
17
- mimeType: string;
18
- byteSize: number;
19
- downloadUrl: string;
20
- expiresAt: string;
21
- note: string;
22
- engineering: AgentEngineeringMetadata | null;
23
- }
24
- export interface AgentInputAttachmentEvidence {
25
- id: string;
26
- kind: "engineering_2d" | "engineering_3d" | "file";
27
- fileName: string;
28
- mimeType: string;
29
- byteSize: number;
30
- engineering: AgentEngineeringMetadata | null;
31
- extractedText: string;
32
- }
33
- export interface AgentAttachmentContentBlock {
34
- id: string;
35
- type: "attachment";
36
- attachment: AgentAttachment;
37
- }
38
- export interface AgentChoiceContentBlock {
1
+ /** Product-defined presentation payload. Core only owns its transport identity. */
2
+ export interface AgentContentBlock {
39
3
  id: string;
40
- type: "choice";
41
- prompt: string;
42
- selection: "single" | "multiple";
43
- options: Array<{
44
- id: string;
45
- label: string;
46
- description: string;
47
- }>;
48
- required: boolean;
49
- minSelections: number;
50
- maxSelections: number;
51
- submitLabel: string;
4
+ type: string;
5
+ [key: string]: unknown;
52
6
  }
53
- export type AgentTableCell = string | number | boolean | null;
54
- export interface AgentTableContentBlock {
55
- id: string;
56
- type: "table";
57
- title: string;
58
- caption: string;
59
- columns: Array<{
60
- key: string;
61
- label: string;
62
- align: "start" | "center" | "end";
63
- }>;
64
- rows: Array<Record<string, AgentTableCell>>;
65
- }
66
- export interface AgentDiagramContentBlock {
67
- id: string;
68
- type: "diagram";
69
- title: string;
70
- direction: "horizontal" | "vertical";
71
- nodes: Array<{
72
- id: string;
73
- label: string;
74
- description: string;
75
- tone: "neutral" | "info" | "success" | "warning" | "danger";
76
- }>;
77
- edges: Array<{
78
- from: string;
79
- to: string;
80
- label: string;
81
- }>;
82
- }
83
- export type AgentContentBlock = AgentAttachmentContentBlock | AgentChoiceContentBlock | AgentTableContentBlock | AgentDiagramContentBlock;
84
- export interface StandardPresentationToolDefinition {
85
- type: "function";
86
- function: {
87
- name: StandardPresentationToolName;
88
- description: string;
89
- parameters: Record<string, unknown>;
90
- };
91
- }
92
- export declare const standardPresentationToolNames: readonly ["response_present_choice", "response_present_table", "response_present_diagram"];
93
- export type StandardPresentationToolName = typeof standardPresentationToolNames[number];
94
- export declare const standardPresentationToolDefinitions: StandardPresentationToolDefinition[];
95
7
  export declare class AgentContentBlockValidationError extends Error {
96
8
  constructor(message: string);
97
9
  }
10
+ /** Check the envelope without interpreting product types, fields or UI constraints. */
98
11
  export declare function parseAgentContentBlock(value: unknown): AgentContentBlock;
99
- export declare function createStandardPresentationToolResult(toolName: string, rawArguments: string, createId?: () => string): {
100
- result: string;
101
- contentBlocks: AgentContentBlock[];
102
- };
103
- export interface EngineeringFileAnalysis {
104
- format: AgentEngineeringFormat;
105
- status: AgentEngineeringParseStatus;
106
- previewMode: AgentEngineeringPreviewMode;
107
- metadata: Record<string, unknown>;
108
- extractedText: string;
109
- }
110
- export declare function isEngineeringFile(fileName: string): boolean;
111
- export declare function analyzeEngineeringFile(fileName: string, bytes: Uint8Array): EngineeringFileAnalysis | null;
12
+ /** Standard MCP evidence stays in tool receipts; product presentations also reach the result projection. */
13
+ export declare function parsePresentationBlocks(blocks: Array<AgentContentBlock | Record<string, unknown>>): AgentContentBlock[];
@@ -49,12 +49,32 @@ export interface TurnRequest {
49
49
  };
50
50
  }
51
51
  export interface EmbeddedRuntimeOptions {
52
+ /** Product-owned retrieval and model context projection before each inference.
53
+ * Original tool receipts remain complete; checkpoints retain the projected context.
54
+ * Keep task facts and complete tool call/result groups, and honour cancellation.
55
+ */
56
+ prepareContext?: (messages: readonly ChatMessage[], context: ModelContextPreparation) => Promise<ModelContextProjection>;
57
+ /** Model-aware message measurement; the fallback is an advisory estimate. */
58
+ countMessageTokens?: (message: Readonly<ChatMessage>, model: string) => number;
52
59
  /** Product-owned model projection; receipts retain the full result. Return undefined to keep it. */
53
60
  projectToolResult?: (message: Readonly<ChatMessage>) => Promise<string | undefined>;
54
61
  /** Evidence or new questions supplied by the product before accepting a model's final answer. */
55
62
  reviewCompletion?: (messages: readonly ChatMessage[], answer: string) => Promise<ChatMessage[]>;
56
63
  onCheckpoint?: (checkpoint: TurnCheckpoint) => Promise<void>;
57
64
  }
65
+ export interface ModelContextPreparation {
66
+ model: string;
67
+ /** Context capacity after reserving configured output; Infinity when capacity metadata is disabled. */
68
+ inputBudgetTokens: number;
69
+ sessionId: string;
70
+ turnId: string;
71
+ signal?: AbortSignal;
72
+ }
73
+ export interface ModelContextProjection {
74
+ messages: ChatMessage[];
75
+ droppedCount: number;
76
+ strategy: string;
77
+ }
58
78
  export interface TurnCheckpoint {
59
79
  turnId: string;
60
80
  sessionId: string;
@@ -0,0 +1,6 @@
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,12 +1,15 @@
1
1
  export { createEmbeddedAgent } from "./embedded-agent.js";
2
+ export { prepareSlidingWindowContext } from "./default-runtime-ports.js";
2
3
  export { corePackageVersion } from "./package-version.js";
3
- export { AgentContentBlockValidationError, analyzeEngineeringFile, createStandardPresentationToolResult, isEngineeringFile, parseAgentContentBlock, standardPresentationToolDefinitions, standardPresentationToolNames, } from "./content-blocks.js";
4
- 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 { AgentContentBlockValidationError, parseAgentContentBlock, } from "./content-blocks.js";
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";
5
6
  export type { ModelOperation, ModelRecoveryProof } from "./model-operation.js";
6
7
  export type { TaskMonetaryBudget } from "../runtime/ports/model-transport-contracts.js";
7
8
  export type { BusinessAssistantContext, BusinessGoal, BusinessGoalEvidence, BusinessGoalOutcome } from "./business-contracts.js";
9
+ export { createBusinessToolAdapter } from "./business-tool-adapter.js";
10
+ export type { BusinessToolAdapter, BusinessToolPort, BusinessToolObservation } from "./business-tool-adapter.js";
8
11
  export { createCloudAgent, completeCloudToolCheckpoint, canonicalCloudValue } from "./cloud-agent.js";
9
12
  export type { CloudAgent, CloudAgentOptions, CloudCheckpoint, CloudExecutionContext, CloudToolInvocation, CloudToolReceipt, CloudToolWait, CloudTurnEvent, CloudTurnRequest, } from "./cloud-agent.js";
10
13
  export { createCloudTaskRuntime } from "./cloud-task.js";
11
14
  export type { CloudTaskStore, CloudTaskSnapshot, CloudTaskStatus, CloudTaskClaim, CloudTaskEvent, CloudTaskEventPayload, CloudTaskRuntime, CloudTaskRuntimeOptions, } from "./cloud-task.js";
12
- export type { AgentAttachment, AgentAttachmentContentBlock, AgentAttachmentKind, AgentChoiceContentBlock, AgentContentBlock, AgentDiagramContentBlock, AgentEngineeringFormat, AgentEngineeringMetadata, AgentEngineeringParseStatus, AgentEngineeringPreviewMode, AgentInputAttachmentEvidence, AgentTableCell, AgentTableContentBlock, EngineeringFileAnalysis, StandardPresentationToolDefinition, StandardPresentationToolName, } from "./content-blocks.js";
15
+ export type { AgentContentBlock } from "./content-blocks.js";
@@ -59,7 +59,10 @@ export interface ToolLoopRuntimePorts {
59
59
  compressMessages(messages: RuntimeCompressibleMessage[], options: {
60
60
  budget: number;
61
61
  model: string;
62
- }): RuntimeCompressionResult;
62
+ sessionId: string;
63
+ turnId: string;
64
+ signal?: AbortSignal;
65
+ }): RuntimeCompressionResult | Promise<RuntimeCompressionResult>;
63
66
  createStreamingToolExecutor(config: StreamingToolExecutorPortConfig): StreamingToolExecutorPort;
64
67
  }
65
68
  export interface AgentRuntimePorts {
@@ -4,7 +4,9 @@ import type { ModelOperation, ModelRecoveryProof } from "../../embedded/model-op
4
4
  /** Immutable product task ceiling, enforced by the model service's financial authority. */
5
5
  export interface TaskMonetaryBudget {
6
6
  id: string;
7
- currency: "CNY";
7
+ /** Currency or accounting unit accepted by the product's financial authority. */
8
+ currency: string;
9
+ /** Positive exact decimal; precision/range are owned by that financial authority. */
8
10
  maxAmount: string;
9
11
  }
10
12
  export interface LLMRequest {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaozhiclaw/qlogicagent-core",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Shared SaaS Agent inference and durable task runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",