@xiaozhiclaw/qlogicagent-core 0.1.4 → 0.1.6

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.
@@ -0,0 +1,76 @@
1
+ import { type AgentContentBlock } from "./content-blocks.js";
2
+ import type { CreateEmbeddedAgentOptions, ToolResult, TurnCheckpoint, TurnEvent, TurnRequest } from "./contracts.js";
3
+ export interface CloudExecutionContext {
4
+ applicationId: string;
5
+ tenantId: string;
6
+ actorId: string;
7
+ scopeId: string;
8
+ definitionVersion: string;
9
+ }
10
+ export interface CloudToolInvocation {
11
+ context: Readonly<CloudExecutionContext>;
12
+ turnId: string;
13
+ sessionId: string;
14
+ callId: string;
15
+ round: number;
16
+ name: string;
17
+ arguments: string;
18
+ }
19
+ export interface CloudCheckpoint extends TurnCheckpoint {
20
+ schemaVersion: 1;
21
+ context: CloudExecutionContext;
22
+ /** Exact model/tool/Skill configuration, not a credential or an authorization. */
23
+ binding: string;
24
+ contentBlocks: AgentContentBlock[];
25
+ }
26
+ export interface CloudTurnRequest extends Omit<TurnRequest, "continuation"> {
27
+ context: CloudExecutionContext;
28
+ resume?: CloudCheckpoint;
29
+ }
30
+ export interface CloudToolWait {
31
+ kind: "wait";
32
+ wait: {
33
+ id: string;
34
+ kind: "input" | "confirmation" | "external";
35
+ reference: string;
36
+ };
37
+ }
38
+ export type CloudTurnEvent = TurnEvent | {
39
+ type: "waiting";
40
+ turnId: string;
41
+ invocation: CloudToolInvocation;
42
+ wait: CloudToolWait["wait"];
43
+ };
44
+ export interface CloudToolReceipt {
45
+ invocation: CloudToolInvocation;
46
+ result: ToolResult;
47
+ }
48
+ /** Only the product may supply reconciled receipts; this function never executes tools. */
49
+ export declare function completeCloudToolCheckpoint(input: CloudCheckpoint, receipts: CloudToolReceipt[]): CloudCheckpoint;
50
+ export interface CloudAgentOptions extends Omit<CreateEmbeddedAgentOptions, "toolInvoker" | "runtime"> {
51
+ toolInvoker: {
52
+ invoke(invocation: CloudToolInvocation, signal?: AbortSignal): Promise<ToolResult | CloudToolWait>;
53
+ };
54
+ /** The product revalidates the authenticated actor before inference and each effect. */
55
+ authorize(context: Readonly<CloudExecutionContext>, action: {
56
+ type: "model";
57
+ } | {
58
+ type: "tool";
59
+ name: string;
60
+ callId: string;
61
+ }): Promise<void>;
62
+ runtime?: Omit<NonNullable<CreateEmbeddedAgentOptions["runtime"]>, "onCheckpoint">;
63
+ checkpoints?: {
64
+ save(checkpoint: CloudCheckpoint): Promise<void>;
65
+ };
66
+ /** Awaited before a successful result is acknowledged or another model step starts. */
67
+ onToolResult?(invocation: CloudToolInvocation, result: ToolResult): Promise<void>;
68
+ onWait?(invocation: CloudToolInvocation, wait: CloudToolWait["wait"]): Promise<void>;
69
+ }
70
+ export interface CloudAgent {
71
+ run(request: CloudTurnRequest, signal?: AbortSignal): AsyncGenerator<CloudTurnEvent>;
72
+ }
73
+ declare function canonical(value: unknown): string;
74
+ export { canonical as canonicalCloudValue };
75
+ /** A product-hosted adapter over the canonical loop; it owns no database or job scheduler. */
76
+ export declare function createCloudAgent(options: CloudAgentOptions): CloudAgent;
@@ -0,0 +1,76 @@
1
+ import { type CloudAgentOptions, type CloudCheckpoint, type CloudExecutionContext, type CloudToolReceipt, type CloudToolWait, type CloudTurnEvent, type CloudTurnRequest } from "./cloud-agent.js";
2
+ import type { ToolResult } from "./contracts.js";
3
+ export type CloudTaskStatus = "queued" | "running" | "waiting_input" | "waiting_confirmation" | "waiting_external" | "reconciliation_required" | "completed" | "stopped" | "failed" | "cancelled";
4
+ export interface CloudTaskSnapshot {
5
+ id: string;
6
+ revision: number;
7
+ cursor: number;
8
+ status: CloudTaskStatus;
9
+ request: CloudTurnRequest;
10
+ checkpoint?: CloudCheckpoint;
11
+ receipts: CloudToolReceipt[];
12
+ wait?: {
13
+ invocation: CloudToolReceipt["invocation"];
14
+ descriptor: CloudToolWait["wait"];
15
+ };
16
+ errorCode?: string;
17
+ }
18
+ export type CloudTaskEventPayload = CloudTurnEvent | {
19
+ type: "task_status";
20
+ status: CloudTaskStatus;
21
+ } | {
22
+ type: "checkpoint";
23
+ phase: CloudCheckpoint["phase"];
24
+ } | {
25
+ type: "receipt";
26
+ callId: string;
27
+ round: number;
28
+ name: string;
29
+ };
30
+ export interface CloudTaskEvent {
31
+ cursor: number;
32
+ event: CloudTaskEventPayload;
33
+ }
34
+ export interface CloudTaskClaim {
35
+ task: CloudTaskSnapshot;
36
+ leaseId: string;
37
+ }
38
+ /** Product-owned atomic persistence. Every query is scope-bound; update and cancel fence workers. */
39
+ export interface CloudTaskStore {
40
+ /** Deduplicate the id/request in the authenticated product scope. */
41
+ create(task: CloudTaskSnapshot): Promise<CloudTaskSnapshot>;
42
+ load(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
43
+ /** Atomically claim only queued work; never steal a running or terminal task. */
44
+ claim(context: CloudExecutionContext, id: string): Promise<CloudTaskClaim | null>;
45
+ /** False on expired/revoked lease or cancellation. Products set their lease duration. */
46
+ renew(context: CloudExecutionContext, id: string, leaseId: string): Promise<boolean>;
47
+ /** CAS + live lease check + snapshot + next contiguous event cursor in one transaction. */
48
+ update(context: CloudExecutionContext, id: string, expectedRevision: number, task: CloudTaskSnapshot, event: CloudTaskEventPayload, leaseId?: string): Promise<CloudTaskSnapshot>;
49
+ release(context: CloudExecutionContext, id: string, leaseId: string): Promise<void>;
50
+ events(context: CloudExecutionContext, id: string, after: number, limit: number): Promise<CloudTaskEvent[]>;
51
+ /** Atomic cancel and lease invalidation; terminal tasks stay unchanged. */
52
+ cancel(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
53
+ /** Only an expired worker may be fenced and moved to reconciliation_required. */
54
+ interrupt(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
55
+ }
56
+ export interface CloudTaskRuntimeOptions {
57
+ store: CloudTaskStore;
58
+ agent: Omit<CloudAgentOptions, "checkpoints" | "onToolResult" | "onWait">;
59
+ authorize(context: CloudExecutionContext, action: "create" | "read" | "execute" | "cancel" | "complete_wait" | "recover"): Promise<void>;
60
+ /** Validate actual employee approval/input or query the original external job; never trust browser results. */
61
+ authorizeCompletion(task: CloudTaskSnapshot, waitId: string, result: ToolResult): Promise<void>;
62
+ /** Required for interrupted model calls or unresolved effects. The product proves billing/retry safety. */
63
+ authorizeRecovery?(task: CloudTaskSnapshot, receipts: CloudToolReceipt[]): Promise<void>;
64
+ heartbeatMs?: number;
65
+ }
66
+ export interface CloudTaskRuntime {
67
+ create(id: string, request: CloudTurnRequest): Promise<CloudTaskSnapshot>;
68
+ get(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
69
+ events(context: CloudExecutionContext, id: string, after?: number, limit?: number): Promise<CloudTaskEvent[]>;
70
+ /** Called by the existing product worker, independently from browser subscriptions. */
71
+ execute(context: CloudExecutionContext, id: string, workerSignal?: AbortSignal): Promise<void>;
72
+ cancel(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
73
+ completeWait(context: CloudExecutionContext, id: string, waitId: string, result: ToolResult): Promise<CloudTaskSnapshot>;
74
+ recover(context: CloudExecutionContext, id: string, receipts?: CloudToolReceipt[]): Promise<CloudTaskSnapshot>;
75
+ }
76
+ export declare function createCloudTaskRuntime(options: CloudTaskRuntimeOptions): CloudTaskRuntime;
@@ -0,0 +1,109 @@
1
+ export type AgentEngineeringFormat = "dxf" | "dwg" | "step" | "stp" | "glb" | "gltf";
2
+ export type AgentEngineeringPreviewMode = "direct" | "browser_conversion" | "external_conversion_required";
3
+ export type AgentEngineeringParseStatus = "parsed" | "partial" | "conversion_required";
4
+ export interface AgentEngineeringMetadata {
5
+ format: AgentEngineeringFormat;
6
+ previewMode: AgentEngineeringPreviewMode;
7
+ parseStatus: AgentEngineeringParseStatus;
8
+ summary: string;
9
+ }
10
+ export type AgentAttachmentKind = "image" | "spreadsheet" | "presentation" | "document" | "engineering_2d" | "engineering_3d" | "file";
11
+ export interface AgentAttachment {
12
+ id: string;
13
+ kind: AgentAttachmentKind;
14
+ fileName: string;
15
+ mimeType: string;
16
+ byteSize: number;
17
+ downloadUrl: string;
18
+ expiresAt: string;
19
+ note: string;
20
+ engineering: AgentEngineeringMetadata | null;
21
+ }
22
+ export interface AgentInputAttachmentEvidence {
23
+ id: string;
24
+ kind: "engineering_2d" | "engineering_3d" | "file";
25
+ fileName: string;
26
+ mimeType: string;
27
+ byteSize: number;
28
+ engineering: AgentEngineeringMetadata | null;
29
+ extractedText: string;
30
+ }
31
+ export interface AgentAttachmentContentBlock {
32
+ id: string;
33
+ type: "attachment";
34
+ attachment: AgentAttachment;
35
+ }
36
+ export interface AgentChoiceContentBlock {
37
+ id: string;
38
+ type: "choice";
39
+ prompt: string;
40
+ selection: "single" | "multiple";
41
+ options: Array<{
42
+ id: string;
43
+ label: string;
44
+ description: string;
45
+ }>;
46
+ required: boolean;
47
+ minSelections: number;
48
+ maxSelections: number;
49
+ submitLabel: string;
50
+ }
51
+ export type AgentTableCell = string | number | boolean | null;
52
+ export interface AgentTableContentBlock {
53
+ id: string;
54
+ type: "table";
55
+ title: string;
56
+ caption: string;
57
+ columns: Array<{
58
+ key: string;
59
+ label: string;
60
+ align: "start" | "center" | "end";
61
+ }>;
62
+ rows: Array<Record<string, AgentTableCell>>;
63
+ }
64
+ export interface AgentDiagramContentBlock {
65
+ id: string;
66
+ type: "diagram";
67
+ title: string;
68
+ direction: "horizontal" | "vertical";
69
+ nodes: Array<{
70
+ id: string;
71
+ label: string;
72
+ description: string;
73
+ tone: "neutral" | "info" | "success" | "warning" | "danger";
74
+ }>;
75
+ edges: Array<{
76
+ from: string;
77
+ to: string;
78
+ label: string;
79
+ }>;
80
+ }
81
+ export type AgentContentBlock = AgentAttachmentContentBlock | AgentChoiceContentBlock | AgentTableContentBlock | AgentDiagramContentBlock;
82
+ export interface StandardPresentationToolDefinition {
83
+ type: "function";
84
+ function: {
85
+ name: StandardPresentationToolName;
86
+ description: string;
87
+ parameters: Record<string, unknown>;
88
+ };
89
+ }
90
+ export declare const standardPresentationToolNames: readonly ["response_present_choice", "response_present_table", "response_present_diagram"];
91
+ export type StandardPresentationToolName = typeof standardPresentationToolNames[number];
92
+ export declare const standardPresentationToolDefinitions: StandardPresentationToolDefinition[];
93
+ export declare class AgentContentBlockValidationError extends Error {
94
+ constructor(message: string);
95
+ }
96
+ export declare function parseAgentContentBlock(value: unknown): AgentContentBlock;
97
+ export declare function createStandardPresentationToolResult(toolName: string, rawArguments: string, createId?: () => string): {
98
+ result: string;
99
+ contentBlocks: AgentContentBlock[];
100
+ };
101
+ export interface EngineeringFileAnalysis {
102
+ format: AgentEngineeringFormat;
103
+ status: AgentEngineeringParseStatus;
104
+ previewMode: AgentEngineeringPreviewMode;
105
+ metadata: Record<string, unknown>;
106
+ extractedText: string;
107
+ }
108
+ export declare function isEngineeringFile(fileName: string): boolean;
109
+ export declare function analyzeEngineeringFile(fileName: string, bytes: Uint8Array): EngineeringFileAnalysis | null;
@@ -1,3 +1,4 @@
1
+ import type { AgentContentBlock } from "./content-blocks.js";
1
2
  export interface AgentLogger {
2
3
  info(message: string): void;
3
4
  info(context: Record<string, unknown>, message: string): void;
@@ -31,6 +32,9 @@ export interface ChatMessage {
31
32
  }
32
33
  export interface ToolDefinition {
33
34
  type: "function";
35
+ meta?: {
36
+ executionTimeoutMs?: number;
37
+ };
34
38
  function: {
35
39
  name: string;
36
40
  description: string;
@@ -97,6 +101,7 @@ export type LLMChunk = {
97
101
  } | {
98
102
  type: "error";
99
103
  message: string;
104
+ outcome?: "rejected" | "unknown";
100
105
  } | {
101
106
  type: "done";
102
107
  finishReason: string;
@@ -104,14 +109,32 @@ export type LLMChunk = {
104
109
  export interface LLMTransport {
105
110
  stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
106
111
  }
112
+ /** All three must be true on a thrown transport error before core can retry a model request. */
113
+ export interface ModelRetryAuthorization {
114
+ retryable: boolean;
115
+ safeToRetry: boolean;
116
+ automaticRetryAuthorized: boolean;
117
+ /** Product transport evidence: a definitive rejection is terminal; unknown outcomes require reconciliation. */
118
+ outcome?: "rejected" | "unknown";
119
+ }
120
+ export interface ToolInvocationContext {
121
+ callId: string;
122
+ sessionId: string;
123
+ round: number;
124
+ }
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
+ }
107
136
  export interface ToolInvoker {
108
- invoke(turnId: string, name: string, args: string, signal?: AbortSignal): Promise<{
109
- result: string;
110
- error?: string;
111
- toolReferences?: string[];
112
- imageUrls?: string[];
113
- details?: Record<string, unknown>;
114
- }>;
137
+ invoke(turnId: string, name: string, args: string, signal?: AbortSignal, invocation?: ToolInvocationContext): Promise<ToolResult>;
115
138
  }
116
139
  export interface TurnConfig {
117
140
  model?: string;
@@ -126,6 +149,11 @@ export interface TurnConfig {
126
149
  parallelToolCalls?: boolean;
127
150
  streamRequired?: boolean;
128
151
  toolChoice?: "auto" | "none" | "required";
152
+ reasoning?: LLMRequest["reasoning"];
153
+ promptCacheKey?: string;
154
+ promptCacheRetention?: LLMRequest["promptCacheRetention"];
155
+ serviceTier?: LLMRequest["serviceTier"];
156
+ textVerbosity?: LLMRequest["textVerbosity"];
129
157
  }
130
158
  export interface TurnRequest {
131
159
  turnId: string;
@@ -135,6 +163,11 @@ export interface TurnRequest {
135
163
  tools: ToolDefinition[];
136
164
  systemPrompt?: string;
137
165
  config?: TurnConfig;
166
+ /** product-validated continuation; cloud consumers should use CloudCheckpoint. */
167
+ continuation?: {
168
+ completedRounds: number;
169
+ usage: TokenUsage;
170
+ };
138
171
  }
139
172
  export interface TokenUsage {
140
173
  inputTokens?: number;
@@ -190,6 +223,12 @@ export type TurnEvent = {
190
223
  type: "reasoning_delta";
191
224
  turnId: string;
192
225
  text: string;
226
+ } | {
227
+ type: "lifecycle";
228
+ turnId: string;
229
+ kind: "context_compression";
230
+ status: string;
231
+ detail: string;
193
232
  } | {
194
233
  type: "annotations";
195
234
  turnId: string;
@@ -221,6 +260,7 @@ export type TurnEvent = {
221
260
  model?: string;
222
261
  provider?: string;
223
262
  recoveryTrace?: Record<string, number>;
263
+ contentBlocks?: AgentContentBlock[];
224
264
  } | {
225
265
  type: "error";
226
266
  turnId: string;
@@ -230,6 +270,15 @@ export type TurnEvent = {
230
270
  };
231
271
  export interface EmbeddedRuntimeOptions {
232
272
  maxToolResultChars?: number;
273
+ onCheckpoint?: (checkpoint: TurnCheckpoint) => Promise<void>;
274
+ }
275
+ export interface TurnCheckpoint {
276
+ turnId: string;
277
+ sessionId: string;
278
+ phase: "model_ready" | "tools_pending";
279
+ messages: ChatMessage[];
280
+ completedRounds: number;
281
+ usage: TokenUsage;
233
282
  }
234
283
  export interface EmbeddedAgent {
235
284
  run(request: TurnRequest, signal?: AbortSignal): AsyncGenerator<TurnEvent>;
@@ -0,0 +1,2 @@
1
+ import type { CreateEmbeddedAgentOptions, EmbeddedAgent } from "./contracts.js";
2
+ export declare function createEmbeddedAgent(options: CreateEmbeddedAgentOptions): EmbeddedAgent;
@@ -1,3 +1,8 @@
1
- import type { CreateEmbeddedAgentOptions, EmbeddedAgent } from "./contracts.js";
2
- export declare function createEmbeddedAgent(options: CreateEmbeddedAgentOptions): EmbeddedAgent;
3
- export type { AgentLogger, ChatMessage, CreateEmbeddedAgentOptions, EmbeddedAgent, EmbeddedRuntimeOptions, LLMChunk, LLMRequest, LLMTransport, ToolDefinition, ToolInvoker, TurnConfig, TurnEvent, TurnRequest, } from "./contracts.js";
1
+ export { createEmbeddedAgent } from "./embedded-agent.js";
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";
5
+ export type { CloudAgent, CloudAgentOptions, CloudCheckpoint, CloudExecutionContext, CloudToolInvocation, CloudToolReceipt, CloudToolWait, CloudTurnEvent, CloudTurnRequest, } from "./cloud-agent.js";
6
+ export { createCloudTaskRuntime } from "./cloud-task.js";
7
+ export type { CloudTaskStore, CloudTaskSnapshot, CloudTaskStatus, CloudTaskClaim, CloudTaskEvent, CloudTaskEventPayload, CloudTaskRuntime, CloudTaskRuntimeOptions, } from "./cloud-task.js";
8
+ export type { AgentAttachment, AgentAttachmentContentBlock, AgentAttachmentKind, AgentChoiceContentBlock, AgentContentBlock, AgentDiagramContentBlock, AgentEngineeringFormat, AgentEngineeringMetadata, AgentEngineeringParseStatus, AgentEngineeringPreviewMode, AgentInputAttachmentEvidence, AgentTableCell, AgentTableContentBlock, EngineeringFileAnalysis, StandardPresentationToolDefinition, StandardPresentationToolName, } from "./content-blocks.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xiaozhiclaw/qlogicagent-core",
3
- "version": "0.1.4",
4
- "description": "Host-neutral qlogicagent tool-loop runtime for server embedding",
3
+ "version": "0.1.6",
4
+ "description": "Shared SaaS Agent inference and durable task runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/types/embedded/index.d.ts",
@@ -15,19 +15,13 @@
15
15
  "dist/",
16
16
  "README.md"
17
17
  ],
18
- "scripts": {
19
- "build": "node scripts/build.mjs",
20
- "prepare": "node scripts/build.mjs"
21
- },
22
18
  "publishConfig": {
23
19
  "access": "public"
24
20
  },
25
21
  "engines": {
26
22
  "node": ">=24.0.0 <25"
27
23
  },
28
- "devDependencies": {
29
- "@types/node": "^22.15.0",
30
- "esbuild": "^0.28.0",
31
- "typescript": "^5.9.3"
24
+ "scripts": {
25
+ "build": "node scripts/build.mjs"
32
26
  }
33
- }
27
+ }