@xiaozhiclaw/qlogicagent-core 0.1.5 → 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.
- package/README.md +48 -30
- package/dist/index.js +10 -10
- package/dist/types/embedded/cloud-agent.d.ts +76 -0
- package/dist/types/embedded/cloud-task.d.ts +76 -0
- package/dist/types/embedded/contracts.d.ts +54 -8
- package/dist/types/embedded/embedded-agent.d.ts +2 -0
- package/dist/types/embedded/index.d.ts +6 -3
- package/package.json +5 -11
|
@@ -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;
|
|
@@ -32,6 +32,9 @@ export interface ChatMessage {
|
|
|
32
32
|
}
|
|
33
33
|
export interface ToolDefinition {
|
|
34
34
|
type: "function";
|
|
35
|
+
meta?: {
|
|
36
|
+
executionTimeoutMs?: number;
|
|
37
|
+
};
|
|
35
38
|
function: {
|
|
36
39
|
name: string;
|
|
37
40
|
description: string;
|
|
@@ -98,6 +101,7 @@ export type LLMChunk = {
|
|
|
98
101
|
} | {
|
|
99
102
|
type: "error";
|
|
100
103
|
message: string;
|
|
104
|
+
outcome?: "rejected" | "unknown";
|
|
101
105
|
} | {
|
|
102
106
|
type: "done";
|
|
103
107
|
finishReason: string;
|
|
@@ -105,15 +109,32 @@ export type LLMChunk = {
|
|
|
105
109
|
export interface LLMTransport {
|
|
106
110
|
stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
|
|
107
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
|
+
}
|
|
108
136
|
export interface ToolInvoker {
|
|
109
|
-
invoke(turnId: string, name: string, args: string, signal?: AbortSignal): Promise<
|
|
110
|
-
result: string;
|
|
111
|
-
error?: string;
|
|
112
|
-
toolReferences?: string[];
|
|
113
|
-
imageUrls?: string[];
|
|
114
|
-
contentBlocks?: AgentContentBlock[];
|
|
115
|
-
details?: Record<string, unknown>;
|
|
116
|
-
}>;
|
|
137
|
+
invoke(turnId: string, name: string, args: string, signal?: AbortSignal, invocation?: ToolInvocationContext): Promise<ToolResult>;
|
|
117
138
|
}
|
|
118
139
|
export interface TurnConfig {
|
|
119
140
|
model?: string;
|
|
@@ -128,6 +149,11 @@ export interface TurnConfig {
|
|
|
128
149
|
parallelToolCalls?: boolean;
|
|
129
150
|
streamRequired?: boolean;
|
|
130
151
|
toolChoice?: "auto" | "none" | "required";
|
|
152
|
+
reasoning?: LLMRequest["reasoning"];
|
|
153
|
+
promptCacheKey?: string;
|
|
154
|
+
promptCacheRetention?: LLMRequest["promptCacheRetention"];
|
|
155
|
+
serviceTier?: LLMRequest["serviceTier"];
|
|
156
|
+
textVerbosity?: LLMRequest["textVerbosity"];
|
|
131
157
|
}
|
|
132
158
|
export interface TurnRequest {
|
|
133
159
|
turnId: string;
|
|
@@ -137,6 +163,11 @@ export interface TurnRequest {
|
|
|
137
163
|
tools: ToolDefinition[];
|
|
138
164
|
systemPrompt?: string;
|
|
139
165
|
config?: TurnConfig;
|
|
166
|
+
/** product-validated continuation; cloud consumers should use CloudCheckpoint. */
|
|
167
|
+
continuation?: {
|
|
168
|
+
completedRounds: number;
|
|
169
|
+
usage: TokenUsage;
|
|
170
|
+
};
|
|
140
171
|
}
|
|
141
172
|
export interface TokenUsage {
|
|
142
173
|
inputTokens?: number;
|
|
@@ -192,6 +223,12 @@ export type TurnEvent = {
|
|
|
192
223
|
type: "reasoning_delta";
|
|
193
224
|
turnId: string;
|
|
194
225
|
text: string;
|
|
226
|
+
} | {
|
|
227
|
+
type: "lifecycle";
|
|
228
|
+
turnId: string;
|
|
229
|
+
kind: "context_compression";
|
|
230
|
+
status: string;
|
|
231
|
+
detail: string;
|
|
195
232
|
} | {
|
|
196
233
|
type: "annotations";
|
|
197
234
|
turnId: string;
|
|
@@ -233,6 +270,15 @@ export type TurnEvent = {
|
|
|
233
270
|
};
|
|
234
271
|
export interface EmbeddedRuntimeOptions {
|
|
235
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;
|
|
236
282
|
}
|
|
237
283
|
export interface EmbeddedAgent {
|
|
238
284
|
run(request: TurnRequest, signal?: AbortSignal): AsyncGenerator<TurnEvent>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function createEmbeddedAgent(options: CreateEmbeddedAgentOptions): EmbeddedAgent;
|
|
1
|
+
export { createEmbeddedAgent } from "./embedded-agent.js";
|
|
3
2
|
export { AgentContentBlockValidationError, analyzeEngineeringFile, createStandardPresentationToolResult, isEngineeringFile, parseAgentContentBlock, standardPresentationToolDefinitions, standardPresentationToolNames, } from "./content-blocks.js";
|
|
4
|
-
export type { AgentLogger, ChatMessage, CreateEmbeddedAgentOptions, EmbeddedAgent, EmbeddedRuntimeOptions, LLMChunk, LLMRequest, LLMTransport, ToolDefinition, ToolInvoker, TurnConfig, TurnEvent, TurnRequest, } from "./contracts.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";
|
|
5
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
|
-
"description": "
|
|
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
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"esbuild": "^0.28.0",
|
|
31
|
-
"typescript": "^5.9.3"
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "node scripts/build.mjs"
|
|
32
26
|
}
|
|
33
|
-
}
|
|
27
|
+
}
|