@xiaozhiclaw/qlogicagent-core 0.1.5 → 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.
- package/README.md +60 -30
- package/dist/index.js +12 -9
- package/dist/types/agent/types.d.ts +164 -0
- package/dist/types/contracts/chat.d.ts +150 -0
- package/dist/types/contracts/hooks.d.ts +117 -0
- package/dist/types/contracts/tool-execution-evidence.d.ts +24 -0
- package/dist/types/contracts/tool-result.d.ts +13 -0
- package/dist/types/contracts/turn-event.d.ts +123 -0
- package/dist/types/contracts/usage.d.ts +27 -0
- package/dist/types/embedded/business-contracts.d.ts +63 -0
- package/dist/types/embedded/cloud-agent.d.ts +92 -0
- package/dist/types/embedded/cloud-task.d.ts +93 -0
- package/dist/types/embedded/content-blocks.d.ts +2 -0
- package/dist/types/embedded/contracts.d.ts +36 -210
- package/dist/types/embedded/embedded-agent.d.ts +2 -0
- package/dist/types/embedded/index.d.ts +8 -3
- package/dist/types/embedded/model-operation.d.ts +40 -0
- package/dist/types/runtime/ports/agent-execution-contracts.d.ts +25 -0
- package/dist/types/runtime/ports/agent-runtime-ports.d.ts +66 -0
- package/dist/types/runtime/ports/index.d.ts +5 -0
- package/dist/types/runtime/ports/model-transport-contracts.d.ts +92 -0
- package/dist/types/runtime/ports/tool-call-contracts.d.ts +20 -0
- package/package.json +5 -11
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ModelOperation } from "./model-operation.js";
|
|
2
|
+
import { type BusinessAssistantContext, type BusinessGoal } from "./business-contracts.js";
|
|
3
|
+
import { type AgentContentBlock } from "./content-blocks.js";
|
|
4
|
+
import type { CreateEmbeddedAgentOptions, ToolResult, TurnCheckpoint, TurnEvent, TurnRequest, LLMRequest } from "./contracts.js";
|
|
5
|
+
export interface CloudExecutionContext {
|
|
6
|
+
applicationId: string;
|
|
7
|
+
tenantId: string;
|
|
8
|
+
actorId: string;
|
|
9
|
+
scopeId: string;
|
|
10
|
+
definitionVersion: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CloudToolInvocation {
|
|
13
|
+
context: Readonly<CloudExecutionContext>;
|
|
14
|
+
turnId: string;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
callId: string;
|
|
17
|
+
round: number;
|
|
18
|
+
name: string;
|
|
19
|
+
arguments: string;
|
|
20
|
+
}
|
|
21
|
+
export interface CloudCheckpoint extends TurnCheckpoint {
|
|
22
|
+
schemaVersion: 1;
|
|
23
|
+
context: CloudExecutionContext;
|
|
24
|
+
/** Exact model/tool/Skill configuration, not a credential or an authorization. */
|
|
25
|
+
binding: string;
|
|
26
|
+
contentBlocks: AgentContentBlock[];
|
|
27
|
+
modelOperations?: ModelOperation[];
|
|
28
|
+
}
|
|
29
|
+
export interface CloudTurnRequest extends Omit<TurnRequest, "continuation"> {
|
|
30
|
+
context: CloudExecutionContext;
|
|
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
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface CloudToolWait {
|
|
41
|
+
kind: "wait";
|
|
42
|
+
wait: {
|
|
43
|
+
id: string;
|
|
44
|
+
kind: "input" | "confirmation" | "external";
|
|
45
|
+
reference: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export type CloudTurnEvent = TurnEvent | {
|
|
49
|
+
type: "waiting";
|
|
50
|
+
turnId: string;
|
|
51
|
+
invocation: CloudToolInvocation;
|
|
52
|
+
wait: CloudToolWait["wait"];
|
|
53
|
+
};
|
|
54
|
+
export interface CloudToolReceipt {
|
|
55
|
+
invocation: CloudToolInvocation;
|
|
56
|
+
result: ToolResult;
|
|
57
|
+
}
|
|
58
|
+
/** Only the product may supply reconciled receipts; this function never executes tools. */
|
|
59
|
+
export declare function completeCloudToolCheckpoint(input: CloudCheckpoint, receipts: CloudToolReceipt[]): CloudCheckpoint;
|
|
60
|
+
export interface CloudAgentOptions extends Omit<CreateEmbeddedAgentOptions, "toolInvoker" | "runtime"> {
|
|
61
|
+
toolInvoker: {
|
|
62
|
+
invoke(invocation: CloudToolInvocation, signal?: AbortSignal): Promise<ToolResult | CloudToolWait>;
|
|
63
|
+
};
|
|
64
|
+
/** The product revalidates the authenticated actor before inference and each effect. */
|
|
65
|
+
authorize(context: Readonly<CloudExecutionContext>, action: {
|
|
66
|
+
type: "model";
|
|
67
|
+
} | {
|
|
68
|
+
type: "tool";
|
|
69
|
+
name: string;
|
|
70
|
+
callId: string;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
runtime?: Omit<NonNullable<CreateEmbeddedAgentOptions["runtime"]>, "onCheckpoint">;
|
|
73
|
+
checkpoints?: {
|
|
74
|
+
save(checkpoint: CloudCheckpoint): Promise<void>;
|
|
75
|
+
};
|
|
76
|
+
/** Awaited before a successful result is acknowledged or another model step starts. */
|
|
77
|
+
onToolResult?(invocation: CloudToolInvocation, result: ToolResult): Promise<void>;
|
|
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
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
export interface CloudAgent {
|
|
87
|
+
run(request: CloudTurnRequest, signal?: AbortSignal): AsyncGenerator<CloudTurnEvent>;
|
|
88
|
+
}
|
|
89
|
+
declare function canonical(value: unknown): string;
|
|
90
|
+
export { canonical as canonicalCloudValue };
|
|
91
|
+
/** A product-hosted adapter over the canonical loop; it owns no database or job scheduler. */
|
|
92
|
+
export declare function createCloudAgent(options: CloudAgentOptions): CloudAgent;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
import type { ModelOperation, ModelRecoveryProof } from "./model-operation.js";
|
|
4
|
+
import { type BusinessGoalEvidence, type BusinessGoalOutcome } from "./business-contracts.js";
|
|
5
|
+
export type CloudTaskStatus = "queued" | "running" | "waiting_input" | "waiting_confirmation" | "waiting_external" | "reconciliation_required" | "completed" | "stopped" | "failed" | "cancelled";
|
|
6
|
+
export interface CloudTaskSnapshot {
|
|
7
|
+
id: string;
|
|
8
|
+
revision: number;
|
|
9
|
+
cursor: number;
|
|
10
|
+
status: CloudTaskStatus;
|
|
11
|
+
request: CloudTurnRequest;
|
|
12
|
+
checkpoint?: CloudCheckpoint;
|
|
13
|
+
receipts: CloudToolReceipt[];
|
|
14
|
+
wait?: {
|
|
15
|
+
invocation: CloudToolReceipt["invocation"];
|
|
16
|
+
descriptor: CloudToolWait["wait"];
|
|
17
|
+
};
|
|
18
|
+
errorCode?: string;
|
|
19
|
+
modelOperations?: ModelOperation[];
|
|
20
|
+
/** Durable product cancellation intent; reconciliation never resumes subsequent work. */
|
|
21
|
+
cancellationRequested?: boolean;
|
|
22
|
+
outcome?: BusinessGoalOutcome;
|
|
23
|
+
}
|
|
24
|
+
export type CloudTaskEventPayload = CloudTurnEvent | {
|
|
25
|
+
type: "task_status";
|
|
26
|
+
status: CloudTaskStatus;
|
|
27
|
+
} | {
|
|
28
|
+
type: "checkpoint";
|
|
29
|
+
phase: CloudCheckpoint["phase"];
|
|
30
|
+
} | {
|
|
31
|
+
type: "receipt";
|
|
32
|
+
callId: string;
|
|
33
|
+
round: number;
|
|
34
|
+
name: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "model_operation";
|
|
37
|
+
operation: Omit<ModelOperation, "response">;
|
|
38
|
+
};
|
|
39
|
+
export interface CloudTaskEvent {
|
|
40
|
+
cursor: number;
|
|
41
|
+
event: CloudTaskEventPayload;
|
|
42
|
+
}
|
|
43
|
+
export interface CloudTaskClaim {
|
|
44
|
+
task: CloudTaskSnapshot;
|
|
45
|
+
leaseId: string;
|
|
46
|
+
}
|
|
47
|
+
/** Product-owned atomic persistence. Every query is scope-bound; update and cancel fence workers. */
|
|
48
|
+
export interface CloudTaskStore {
|
|
49
|
+
/** Deduplicate the id/request in the authenticated product scope. */
|
|
50
|
+
create(task: CloudTaskSnapshot): Promise<CloudTaskSnapshot>;
|
|
51
|
+
load(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
|
|
52
|
+
/** Atomically claim only queued work; never steal a running or terminal task. */
|
|
53
|
+
claim(context: CloudExecutionContext, id: string): Promise<CloudTaskClaim | null>;
|
|
54
|
+
/** False on expired/revoked lease or cancellation. Products set their lease duration. */
|
|
55
|
+
renew(context: CloudExecutionContext, id: string, leaseId: string): Promise<boolean>;
|
|
56
|
+
/** CAS + live lease check + snapshot + next contiguous event cursor in one transaction. */
|
|
57
|
+
update(context: CloudExecutionContext, id: string, expectedRevision: number, task: CloudTaskSnapshot, event: CloudTaskEventPayload, leaseId?: string): Promise<CloudTaskSnapshot>;
|
|
58
|
+
release(context: CloudExecutionContext, id: string, leaseId: string): Promise<void>;
|
|
59
|
+
events(context: CloudExecutionContext, id: string, after: number, limit: number): Promise<CloudTaskEvent[]>;
|
|
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. */
|
|
62
|
+
cancel(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
|
|
63
|
+
/** Only an expired worker may be fenced and moved to reconciliation_required. */
|
|
64
|
+
interrupt(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
|
|
65
|
+
}
|
|
66
|
+
export interface CloudTaskRuntimeOptions {
|
|
67
|
+
store: CloudTaskStore;
|
|
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>;
|
|
71
|
+
authorize(context: CloudExecutionContext, action: "create" | "read" | "execute" | "cancel" | "complete_wait" | "recover"): Promise<void>;
|
|
72
|
+
/** Validate actual employee approval/input or query the original external job; never trust browser results. */
|
|
73
|
+
authorizeCompletion(task: CloudTaskSnapshot, waitId: string, result: ToolResult): Promise<void>;
|
|
74
|
+
/** Required for interrupted model calls or unresolved effects. The product proves billing/retry safety. */
|
|
75
|
+
authorizeRecovery?(task: CloudTaskSnapshot, receipts: CloudToolReceipt[]): Promise<ModelRecoveryProof[] | void>;
|
|
76
|
+
heartbeatMs?: number;
|
|
77
|
+
/** Optional bounded text batching; all control events still flush in order. */
|
|
78
|
+
deltaBatch?: {
|
|
79
|
+
maxCharacters: number;
|
|
80
|
+
maxDelayMs: number;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export interface CloudTaskRuntime {
|
|
84
|
+
create(id: string, request: CloudTurnRequest): Promise<CloudTaskSnapshot>;
|
|
85
|
+
get(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
|
|
86
|
+
events(context: CloudExecutionContext, id: string, after?: number, limit?: number): Promise<CloudTaskEvent[]>;
|
|
87
|
+
/** Called by the existing product worker, independently from browser subscriptions. */
|
|
88
|
+
execute(context: CloudExecutionContext, id: string, workerSignal?: AbortSignal): Promise<void>;
|
|
89
|
+
cancel(context: CloudExecutionContext, id: string): Promise<CloudTaskSnapshot>;
|
|
90
|
+
completeWait(context: CloudExecutionContext, id: string, waitId: string, result: ToolResult): Promise<CloudTaskSnapshot>;
|
|
91
|
+
recover(context: CloudExecutionContext, id: string, receipts?: CloudToolReceipt[]): Promise<CloudTaskSnapshot>;
|
|
92
|
+
}
|
|
93
|
+
export declare function createCloudTaskRuntime(options: CloudTaskRuntimeOptions): CloudTaskRuntime;
|
|
@@ -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,125 +8,31 @@ export interface AgentLogger {
|
|
|
9
8
|
debug(message: string): void;
|
|
10
9
|
debug(context: Record<string, unknown>, message: string): void;
|
|
11
10
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
thinking: string;
|
|
30
|
-
signature: string;
|
|
31
|
-
}>;
|
|
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'>;
|
|
21
|
+
/** All three must be true on a thrown transport error before core can retry a model request. */
|
|
22
|
+
export interface ModelRetryAuthorization {
|
|
23
|
+
retryable: boolean;
|
|
24
|
+
safeToRetry: boolean;
|
|
25
|
+
automaticRetryAuthorized: boolean;
|
|
26
|
+
/** Product transport evidence: a definitive rejection is terminal; unknown outcomes require reconciliation. */
|
|
27
|
+
outcome?: "rejected" | "unknown";
|
|
32
28
|
}
|
|
33
|
-
export interface
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
description: string;
|
|
38
|
-
parameters?: Record<string, unknown>;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export interface LLMRequest {
|
|
42
|
-
model: string;
|
|
43
|
-
messages: ChatMessage[];
|
|
44
|
-
tools?: ToolDefinition[];
|
|
45
|
-
toolChoice?: "auto" | "none" | "required" | {
|
|
46
|
-
type: "function";
|
|
47
|
-
name: string;
|
|
48
|
-
};
|
|
49
|
-
temperature?: number;
|
|
50
|
-
maxTokens?: number;
|
|
51
|
-
reasoning?: {
|
|
52
|
-
effort: "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
53
|
-
includeEncryptedReasoning?: boolean;
|
|
54
|
-
};
|
|
55
|
-
maxToolCalls?: number;
|
|
56
|
-
streamRequired?: boolean;
|
|
57
|
-
promptCacheKey?: string;
|
|
58
|
-
promptCacheRetention?: "in_memory" | "24h";
|
|
59
|
-
serviceTier?: "auto" | "default" | "flex" | "priority";
|
|
60
|
-
parallelToolCalls?: boolean;
|
|
61
|
-
textVerbosity?: "low" | "medium" | "high";
|
|
62
|
-
}
|
|
63
|
-
export type LLMChunk = {
|
|
64
|
-
type: "delta";
|
|
65
|
-
text: string;
|
|
66
|
-
} | {
|
|
67
|
-
type: "tool_call_delta";
|
|
68
|
-
index: number;
|
|
69
|
-
id?: string;
|
|
70
|
-
name?: string;
|
|
71
|
-
arguments: string;
|
|
72
|
-
} | {
|
|
73
|
-
type: "reasoning_delta";
|
|
74
|
-
text: string;
|
|
75
|
-
} | {
|
|
76
|
-
type: "reasoning_block_complete";
|
|
77
|
-
thinking: string;
|
|
78
|
-
signature: string;
|
|
79
|
-
} | {
|
|
80
|
-
type: "usage";
|
|
81
|
-
totalPromptTokens?: number;
|
|
82
|
-
promptTokens: number;
|
|
83
|
-
completionTokens: number;
|
|
84
|
-
reasoningTokens?: number;
|
|
85
|
-
cacheReadTokens?: number;
|
|
86
|
-
cacheCreationTokens?: number;
|
|
87
|
-
} | {
|
|
88
|
-
type: "response_id";
|
|
89
|
-
id: string;
|
|
90
|
-
} | {
|
|
91
|
-
type: "annotations";
|
|
92
|
-
annotations: Array<{
|
|
93
|
-
type: string;
|
|
94
|
-
url?: string;
|
|
95
|
-
title?: string;
|
|
96
|
-
[key: string]: unknown;
|
|
97
|
-
}>;
|
|
98
|
-
} | {
|
|
99
|
-
type: "error";
|
|
100
|
-
message: string;
|
|
101
|
-
} | {
|
|
102
|
-
type: "done";
|
|
103
|
-
finishReason: string;
|
|
104
|
-
};
|
|
105
|
-
export interface LLMTransport {
|
|
106
|
-
stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
|
|
29
|
+
export interface ToolInvocationContext {
|
|
30
|
+
callId: string;
|
|
31
|
+
sessionId: string;
|
|
32
|
+
round: number;
|
|
107
33
|
}
|
|
108
34
|
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
|
-
}>;
|
|
117
|
-
}
|
|
118
|
-
export interface TurnConfig {
|
|
119
|
-
model?: string;
|
|
120
|
-
maxRounds?: number;
|
|
121
|
-
temperature?: number;
|
|
122
|
-
contextWindowTokens?: number;
|
|
123
|
-
maxOutputTokens?: number;
|
|
124
|
-
modelMaxOutputTokens?: number;
|
|
125
|
-
maxTurns?: number;
|
|
126
|
-
maxToolCalls?: number;
|
|
127
|
-
maxConcurrentTools?: number;
|
|
128
|
-
parallelToolCalls?: boolean;
|
|
129
|
-
streamRequired?: boolean;
|
|
130
|
-
toolChoice?: "auto" | "none" | "required";
|
|
35
|
+
invoke(turnId: string, name: string, args: string, signal?: AbortSignal, invocation?: ToolInvocationContext): Promise<ToolResult>;
|
|
131
36
|
}
|
|
132
37
|
export interface TurnRequest {
|
|
133
38
|
turnId: string;
|
|
@@ -137,102 +42,23 @@ export interface TurnRequest {
|
|
|
137
42
|
tools: ToolDefinition[];
|
|
138
43
|
systemPrompt?: string;
|
|
139
44
|
config?: TurnConfig;
|
|
45
|
+
/** product-validated continuation; cloud consumers should use CloudCheckpoint. */
|
|
46
|
+
continuation?: {
|
|
47
|
+
completedRounds: number;
|
|
48
|
+
usage: TokenUsage;
|
|
49
|
+
};
|
|
140
50
|
}
|
|
141
|
-
export interface TokenUsage {
|
|
142
|
-
inputTokens?: number;
|
|
143
|
-
outputTokens?: number;
|
|
144
|
-
reasoningTokens?: number;
|
|
145
|
-
cacheRead?: number;
|
|
146
|
-
cacheWrite?: number;
|
|
147
|
-
}
|
|
148
|
-
export type TurnEvent = {
|
|
149
|
-
type: "start";
|
|
150
|
-
turnId: string;
|
|
151
|
-
effectiveMaxRounds?: number;
|
|
152
|
-
effectiveMaxToolCalls?: number;
|
|
153
|
-
} | {
|
|
154
|
-
type: "delta";
|
|
155
|
-
turnId: string;
|
|
156
|
-
text: string;
|
|
157
|
-
} | {
|
|
158
|
-
type: "tool_call";
|
|
159
|
-
turnId: string;
|
|
160
|
-
callId: string;
|
|
161
|
-
name: string;
|
|
162
|
-
displayName?: string;
|
|
163
|
-
arguments: string;
|
|
164
|
-
inputSummary?: string;
|
|
165
|
-
} | {
|
|
166
|
-
type: "tool_result";
|
|
167
|
-
turnId: string;
|
|
168
|
-
callId: string;
|
|
169
|
-
name: string;
|
|
170
|
-
ok: boolean;
|
|
171
|
-
error?: string;
|
|
172
|
-
outputPreview?: string;
|
|
173
|
-
durationMs?: number;
|
|
174
|
-
details?: Record<string, unknown>;
|
|
175
|
-
} | {
|
|
176
|
-
type: "tool_blocked";
|
|
177
|
-
turnId: string;
|
|
178
|
-
callId: string;
|
|
179
|
-
name: string;
|
|
180
|
-
reason: string;
|
|
181
|
-
} | {
|
|
182
|
-
type: "recovery";
|
|
183
|
-
turnId: string;
|
|
184
|
-
action: string;
|
|
185
|
-
detail?: string;
|
|
186
|
-
} | {
|
|
187
|
-
type: "text_rollback";
|
|
188
|
-
turnId: string;
|
|
189
|
-
keepLength: number;
|
|
190
|
-
reason: string;
|
|
191
|
-
} | {
|
|
192
|
-
type: "reasoning_delta";
|
|
193
|
-
turnId: string;
|
|
194
|
-
text: string;
|
|
195
|
-
} | {
|
|
196
|
-
type: "annotations";
|
|
197
|
-
turnId: string;
|
|
198
|
-
annotations: Array<{
|
|
199
|
-
type: string;
|
|
200
|
-
url?: string;
|
|
201
|
-
title?: string;
|
|
202
|
-
[key: string]: unknown;
|
|
203
|
-
}>;
|
|
204
|
-
} | {
|
|
205
|
-
type: "tool_use_summary";
|
|
206
|
-
turnId: string;
|
|
207
|
-
ledgerSchemaVersion: 5;
|
|
208
|
-
toolCalls: Array<Record<string, unknown>>;
|
|
209
|
-
availableToolNames: string[];
|
|
210
|
-
enabledToolNames: string[];
|
|
211
|
-
toolCallNames: string[];
|
|
212
|
-
blockedToolCalls: Array<{
|
|
213
|
-
name: string;
|
|
214
|
-
reason: string;
|
|
215
|
-
}>;
|
|
216
|
-
} | {
|
|
217
|
-
type: "end";
|
|
218
|
-
turnId: string;
|
|
219
|
-
content: string;
|
|
220
|
-
turnStatus?: "completed" | "stopped";
|
|
221
|
-
taskOutcome?: "unverified";
|
|
222
|
-
usage?: TokenUsage;
|
|
223
|
-
model?: string;
|
|
224
|
-
provider?: string;
|
|
225
|
-
recoveryTrace?: Record<string, number>;
|
|
226
|
-
contentBlocks?: AgentContentBlock[];
|
|
227
|
-
} | {
|
|
228
|
-
type: "error";
|
|
229
|
-
turnId: string;
|
|
230
|
-
error: string;
|
|
231
|
-
code?: string;
|
|
232
|
-
usage?: TokenUsage;
|
|
233
|
-
};
|
|
234
51
|
export interface EmbeddedRuntimeOptions {
|
|
235
52
|
maxToolResultChars?: number;
|
|
53
|
+
onCheckpoint?: (checkpoint: TurnCheckpoint) => Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
export interface TurnCheckpoint {
|
|
56
|
+
turnId: string;
|
|
57
|
+
sessionId: string;
|
|
58
|
+
phase: "model_ready" | "tools_pending";
|
|
59
|
+
messages: ChatMessage[];
|
|
60
|
+
completedRounds: number;
|
|
61
|
+
usage: TokenUsage;
|
|
236
62
|
}
|
|
237
63
|
export interface EmbeddedAgent {
|
|
238
64
|
run(request: TurnRequest, signal?: AbortSignal): AsyncGenerator<TurnEvent>;
|
|
@@ -1,5 +1,10 @@
|
|
|
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 { 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";
|
|
7
|
+
export type { CloudAgent, CloudAgentOptions, CloudCheckpoint, CloudExecutionContext, CloudToolInvocation, CloudToolReceipt, CloudToolWait, CloudTurnEvent, CloudTurnRequest, } from "./cloud-agent.js";
|
|
8
|
+
export { createCloudTaskRuntime } from "./cloud-task.js";
|
|
9
|
+
export type { CloudTaskStore, CloudTaskSnapshot, CloudTaskStatus, CloudTaskClaim, CloudTaskEvent, CloudTaskEventPayload, CloudTaskRuntime, CloudTaskRuntimeOptions, } from "./cloud-task.js";
|
|
5
10
|
export type { AgentAttachment, AgentAttachmentContentBlock, AgentAttachmentKind, AgentChoiceContentBlock, AgentContentBlock, AgentDiagramContentBlock, AgentEngineeringFormat, AgentEngineeringMetadata, AgentEngineeringParseStatus, AgentEngineeringPreviewMode, AgentInputAttachmentEvidence, AgentTableCell, AgentTableContentBlock, EngineeringFileAnalysis, StandardPresentationToolDefinition, StandardPresentationToolName, } from "./content-blocks.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";
|