@keo-ai/axiom 0.1.2 → 0.1.4
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 +406 -4
- package/dist/embedding_search/enums.d.ts +6 -0
- package/dist/embedding_search/enums.js +105 -0
- package/dist/embedding_search/index.js +10 -3
- package/dist/embedding_search/types.d.ts +1 -0
- package/dist/function_call_loop/harness.d.ts +34 -0
- package/dist/function_call_loop/harness.js +48 -0
- package/dist/function_call_loop/index.d.ts +14 -0
- package/dist/function_call_loop/index.js +17 -0
- package/dist/function_call_loop/loop.d.ts +23 -0
- package/dist/function_call_loop/loop.js +472 -0
- package/dist/function_call_loop/provider.d.ts +19 -0
- package/dist/function_call_loop/provider.js +91 -0
- package/dist/function_call_loop/types.d.ts +208 -0
- package/dist/function_call_loop/types.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +36 -1
- package/package.json +1 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM 对话消息。支持 system、user、assistant、tool 四种角色。
|
|
3
|
+
* assistant 角色可携带 tool_calls;tool 角色需携带 tool_call_id。
|
|
4
|
+
*/
|
|
5
|
+
export interface Message {
|
|
6
|
+
readonly role: 'system' | 'user' | 'assistant' | 'tool';
|
|
7
|
+
readonly content: string;
|
|
8
|
+
readonly tool_calls?: ReadonlyArray<ToolCall>;
|
|
9
|
+
readonly tool_call_id?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* LLM 返回的工具调用。
|
|
13
|
+
*/
|
|
14
|
+
export interface ToolCall {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly type: 'function';
|
|
17
|
+
readonly function: {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly arguments: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 暴露给 LLM 的工具定义。
|
|
24
|
+
*/
|
|
25
|
+
export interface ToolDefinition {
|
|
26
|
+
readonly type: 'function';
|
|
27
|
+
readonly function: {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly description: string;
|
|
30
|
+
readonly parameters: unknown;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Harness 记录的执行状态。
|
|
35
|
+
*/
|
|
36
|
+
export type HarnessRecordStatus = 'pending' | 'success' | 'error' | 'timeout' | 'cancelled';
|
|
37
|
+
/**
|
|
38
|
+
* 单条执行历史记录。
|
|
39
|
+
*/
|
|
40
|
+
export interface HarnessRecord {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly turn: number;
|
|
43
|
+
readonly globalIndex: number;
|
|
44
|
+
readonly toolName: string;
|
|
45
|
+
readonly args: unknown;
|
|
46
|
+
readonly rawArgs: string;
|
|
47
|
+
readonly status: HarnessRecordStatus;
|
|
48
|
+
readonly result?: unknown;
|
|
49
|
+
readonly error?: string;
|
|
50
|
+
readonly startedAt: number;
|
|
51
|
+
readonly durationMs: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 执行前事件。
|
|
55
|
+
*/
|
|
56
|
+
export interface ToolExecutionStartEvent {
|
|
57
|
+
readonly type: 'execution:start';
|
|
58
|
+
readonly callId: string;
|
|
59
|
+
readonly toolName: string;
|
|
60
|
+
readonly args: unknown;
|
|
61
|
+
readonly turn: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 执行后事件(同时携带结果)。
|
|
65
|
+
*/
|
|
66
|
+
export interface ToolExecutionEndEvent {
|
|
67
|
+
readonly type: 'execution:end';
|
|
68
|
+
readonly callId: string;
|
|
69
|
+
readonly toolName: string;
|
|
70
|
+
readonly status: HarnessRecordStatus;
|
|
71
|
+
readonly durationMs: number;
|
|
72
|
+
readonly result?: unknown;
|
|
73
|
+
readonly error?: string;
|
|
74
|
+
readonly turn: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Loop 生命周期事件。
|
|
78
|
+
*/
|
|
79
|
+
export type LoopEvent = ToolExecutionStartEvent | ToolExecutionEndEvent;
|
|
80
|
+
/**
|
|
81
|
+
* Tool 发现函数的返回结果。
|
|
82
|
+
*/
|
|
83
|
+
export interface ToolDiscoverResult {
|
|
84
|
+
readonly name: string;
|
|
85
|
+
readonly description: string;
|
|
86
|
+
readonly parameters: unknown;
|
|
87
|
+
readonly visible: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Tool 执行上下文。
|
|
91
|
+
*/
|
|
92
|
+
export interface ToolExecuteContext {
|
|
93
|
+
readonly harness: ReadonlyArray<HarnessRecord>;
|
|
94
|
+
readonly turn: number;
|
|
95
|
+
readonly metadata: unknown;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Tool 审批配置。
|
|
99
|
+
* 当 tool 被调用时,先执行 createTicket 生成审批单,暂停 Loop 等待外部审批。
|
|
100
|
+
* createTicket 可通过 context.metadata 访问 LoopConfig 传入的 metadata,用于携带业务上下文(如用户ID、会话ID等)。
|
|
101
|
+
* 审批通过后恢复执行时,应通过某种方式(如 createTicket 内部查库)让 Loop 直接执行,无需去掉 approval 配置。
|
|
102
|
+
*/
|
|
103
|
+
export interface ApprovalConfig {
|
|
104
|
+
readonly createTicket: (args: unknown, context: ToolExecuteContext) => Promise<{
|
|
105
|
+
ticketId: string;
|
|
106
|
+
approved?: boolean;
|
|
107
|
+
}>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 注册到 Loop 中的 Tool。
|
|
111
|
+
*/
|
|
112
|
+
export interface Tool {
|
|
113
|
+
readonly name: string;
|
|
114
|
+
readonly description: string;
|
|
115
|
+
readonly parameters: unknown;
|
|
116
|
+
readonly discover?: (harness: ReadonlyArray<HarnessRecord>, metadata: unknown) => ToolDiscoverResult | Promise<ToolDiscoverResult>;
|
|
117
|
+
readonly execute: (args: unknown, context: ToolExecuteContext) => unknown | Promise<unknown>;
|
|
118
|
+
readonly approval?: ApprovalConfig;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Turn Policy 决策结果。
|
|
122
|
+
*/
|
|
123
|
+
export interface TurnPolicyResult {
|
|
124
|
+
/** 终止 Loop,此消息作为 assistant 回复写入历史 */
|
|
125
|
+
readonly message?: string;
|
|
126
|
+
/** 继续执行前作为 system 消息注入 */
|
|
127
|
+
readonly injectMessage?: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 全局轮次策略。
|
|
131
|
+
*/
|
|
132
|
+
export type TurnPolicy = (harness: ReadonlyArray<HarnessRecord>, turn: number, metadata: unknown) => TurnPolicyResult | Promise<TurnPolicyResult>;
|
|
133
|
+
/**
|
|
134
|
+
* 上下文压缩配置。
|
|
135
|
+
*/
|
|
136
|
+
export interface CompressionConfig {
|
|
137
|
+
readonly keepRounds: number;
|
|
138
|
+
readonly compress: (messages: ReadonlyArray<ReadonlyArray<Message>>) => Message[] | Promise<Message[]>;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* LLM 调用可选参数。
|
|
142
|
+
*/
|
|
143
|
+
export interface LLMCallOptions {
|
|
144
|
+
readonly model?: string;
|
|
145
|
+
readonly temperature?: number;
|
|
146
|
+
readonly maxTokens?: number;
|
|
147
|
+
readonly topP?: number;
|
|
148
|
+
readonly reasoningEffort?: 'low' | 'medium' | 'high';
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* LLM 调用接口。由外部注入,Loop 内部不绑定具体 Provider。
|
|
152
|
+
*/
|
|
153
|
+
export interface LLMCaller {
|
|
154
|
+
readonly call: (messages: ReadonlyArray<Message>, tools: ReadonlyArray<ToolDefinition>, options?: LLMCallOptions) => Promise<{
|
|
155
|
+
readonly content: string | null;
|
|
156
|
+
readonly tool_calls?: ReadonlyArray<ToolCall>;
|
|
157
|
+
}>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Loop 配置。
|
|
161
|
+
*/
|
|
162
|
+
export interface LoopConfig {
|
|
163
|
+
/** 初始消息列表,直接作为对话起点 */
|
|
164
|
+
readonly messages: ReadonlyArray<Message>;
|
|
165
|
+
readonly tools: ReadonlyArray<Tool>;
|
|
166
|
+
readonly llmCaller: LLMCaller;
|
|
167
|
+
readonly maxTurns?: number;
|
|
168
|
+
readonly turnPolicy?: TurnPolicy;
|
|
169
|
+
readonly compression?: CompressionConfig;
|
|
170
|
+
readonly metadata?: unknown;
|
|
171
|
+
/** 告警文本:当 turnPolicy 未自定义且当前轮次等于 maxTurns - 1 时塞入 Messages */
|
|
172
|
+
readonly warningMessage?: string;
|
|
173
|
+
/** 终止文本:当 turnPolicy 未自定义且当前轮次等于 maxTurns 时塞入 Messages */
|
|
174
|
+
readonly terminateMessage?: string;
|
|
175
|
+
/** 事件监听器 */
|
|
176
|
+
readonly onEvent?: (event: LoopEvent) => void | Promise<void>;
|
|
177
|
+
/** 取消信号 */
|
|
178
|
+
readonly signal?: AbortSignal;
|
|
179
|
+
/** 模型名称。未设置时从环境变量或 Provider 默认值读取 */
|
|
180
|
+
readonly model?: string;
|
|
181
|
+
/** 采样温度,范围 0~2 */
|
|
182
|
+
readonly temperature?: number;
|
|
183
|
+
/** 单次 LLM 调用的最大输出 token 数 */
|
|
184
|
+
readonly maxTokens?: number;
|
|
185
|
+
/** 核采样概率阈值,范围 0~1 */
|
|
186
|
+
readonly topP?: number;
|
|
187
|
+
/** 推理深度。仅部分模型支持 */
|
|
188
|
+
readonly reasoningEffort?: 'low' | 'medium' | 'high';
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 待审批信息。
|
|
192
|
+
*/
|
|
193
|
+
export interface PendingApprovalInfo {
|
|
194
|
+
readonly ticketId: string;
|
|
195
|
+
readonly toolName: string;
|
|
196
|
+
readonly args: unknown;
|
|
197
|
+
readonly callId: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Loop 执行结果。
|
|
201
|
+
*/
|
|
202
|
+
export interface LoopResult {
|
|
203
|
+
readonly messages: Message[];
|
|
204
|
+
readonly harness: ReadonlyArray<HarnessRecord>;
|
|
205
|
+
readonly finalContent: string | null;
|
|
206
|
+
readonly turns: number;
|
|
207
|
+
readonly pendingApproval?: PendingApprovalInfo;
|
|
208
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -32,3 +32,5 @@ export type { Model, PredictConfig, PredictWithMessagesConfig } from './predict'
|
|
|
32
32
|
/** 向量检索(Embedding + pgvector + Rerank) */
|
|
33
33
|
export { EmbeddingSearch, embed } from './embedding_search';
|
|
34
34
|
export type { EmbeddingSearchConfig, SearchResult } from './embedding_search';
|
|
35
|
+
/** Function Call Loop */
|
|
36
|
+
export * as FunctionCallLoop from './function_call_loop';
|
package/dist/index.js
CHANGED
|
@@ -19,8 +19,41 @@
|
|
|
19
19
|
*
|
|
20
20
|
* @packageDocumentation
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
25
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
26
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(o, k2, desc);
|
|
29
|
+
}) : (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
o[k2] = m[k];
|
|
32
|
+
}));
|
|
33
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
34
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
35
|
+
}) : function(o, v) {
|
|
36
|
+
o["default"] = v;
|
|
37
|
+
});
|
|
38
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
39
|
+
var ownKeys = function(o) {
|
|
40
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
41
|
+
var ar = [];
|
|
42
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
43
|
+
return ar;
|
|
44
|
+
};
|
|
45
|
+
return ownKeys(o);
|
|
46
|
+
};
|
|
47
|
+
return function (mod) {
|
|
48
|
+
if (mod && mod.__esModule) return mod;
|
|
49
|
+
var result = {};
|
|
50
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
51
|
+
__setModuleDefault(result, mod);
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
})();
|
|
22
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.embed = exports.EmbeddingSearch = exports.MODEL_REGISTRY = exports.BailianProvider = exports.Predictor = exports.LLM = void 0;
|
|
56
|
+
exports.FunctionCallLoop = exports.embed = exports.EmbeddingSearch = exports.MODEL_REGISTRY = exports.BailianProvider = exports.Predictor = exports.LLM = void 0;
|
|
24
57
|
/** LLM 静态入口类,封装 Provider 连接、故障转移和返回解析 */
|
|
25
58
|
var predict_1 = require("./predict");
|
|
26
59
|
Object.defineProperty(exports, "LLM", { enumerable: true, get: function () { return predict_1.LLM; } });
|
|
@@ -37,3 +70,5 @@ Object.defineProperty(exports, "MODEL_REGISTRY", { enumerable: true, get: functi
|
|
|
37
70
|
var embedding_search_1 = require("./embedding_search");
|
|
38
71
|
Object.defineProperty(exports, "EmbeddingSearch", { enumerable: true, get: function () { return embedding_search_1.EmbeddingSearch; } });
|
|
39
72
|
Object.defineProperty(exports, "embed", { enumerable: true, get: function () { return embedding_search_1.embed; } });
|
|
73
|
+
/** Function Call Loop */
|
|
74
|
+
exports.FunctionCallLoop = __importStar(require("./function_call_loop"));
|