@prysm-ai/core 0.1.0 → 0.3.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/CHANGELOG.md +53 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/package.json +79 -11
- package/src/index.ts +49 -0
- package/tsconfig.json +9 -0
- package/agent.d.ts +0 -13
- package/agent.js +0 -38
- package/agent.types.d.ts +0 -100
- package/agent.types.js +0 -17
- package/errors.d.ts +0 -20
- package/errors.js +0 -40
- package/hooks.d.ts +0 -23
- package/hooks.js +0 -1
- package/index.d.ts +0 -4
- package/index.js +0 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @prysm-ai/core
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 发布 0.2.0 版本
|
|
8
|
+
|
|
9
|
+
核心变更:
|
|
10
|
+
- 重构 @prysm-ai/core 为统一入口包,导出所有子包
|
|
11
|
+
- @prysm-ai/agent 新增 types.ts 定义核心类型
|
|
12
|
+
- 删除 core 包自有类型定义,改为纯 re-export
|
|
13
|
+
- 新增 createModel 工厂函数
|
|
14
|
+
- 支持流式输出 chatStream
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @prysm-ai/llm@0.3.0
|
|
20
|
+
- @prysm-ai/agent@0.3.0
|
|
21
|
+
- @prysm-ai/tools@0.3.0
|
|
22
|
+
- @prysm-ai/memory@0.3.0
|
|
23
|
+
- @prysm-ai/utils@0.3.0
|
|
24
|
+
- @prysm-ai/logger@0.3.0
|
|
25
|
+
- @prysm-ai/metrics@0.3.0
|
|
26
|
+
- @prysm-ai/tracing@0.3.0
|
|
27
|
+
- @prysm-ai/enterprise@0.3.0
|
|
28
|
+
- @prysm-ai/mcp@0.3.0
|
|
29
|
+
- @prysm-ai/skills@0.3.0
|
|
30
|
+
- @prysm-ai/multiagent@0.3.0
|
|
31
|
+
- @prysm-ai/rag@0.3.0
|
|
32
|
+
- @prysm-ai/prompts@0.3.0
|
|
33
|
+
|
|
34
|
+
## 0.2.0
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- 发布第一个版本,包含核心功能:
|
|
39
|
+
- core: 核心抽象类(Agent、Context、Storage 等)
|
|
40
|
+
- llm: LLM 抽象层,支持 OpenAI/Anthropic 提供商,新增 createModel 工厂函数
|
|
41
|
+
- agent: Agent 框架核心实现
|
|
42
|
+
- tools: 工具系统
|
|
43
|
+
- memory: 记忆系统
|
|
44
|
+
- prompts: 提示词模板管理
|
|
45
|
+
- logger: 日志系统
|
|
46
|
+
- metrics: 指标系统
|
|
47
|
+
- tracing: 链路追踪
|
|
48
|
+
- enterprise: 企业级功能
|
|
49
|
+
- mcp: Model Context Protocol
|
|
50
|
+
- skills: 技能系统
|
|
51
|
+
- multiagent: 多 Agent 协作
|
|
52
|
+
- rag: 检索增强生成
|
|
53
|
+
- utils: 工具函数库
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { createModel, type CreateModelOptions } from '@prysm-ai/llm';
|
|
2
|
+
export { OpenAIProvider, AnthropicProvider } from '@prysm-ai/llm';
|
|
3
|
+
export { LLMRouter } from '@prysm-ai/llm';
|
|
4
|
+
export type { ModelInfo } from '@prysm-ai/llm';
|
|
5
|
+
export { Agent } from '@prysm-ai/agent';
|
|
6
|
+
export type { AgentHooks } from '@prysm-ai/agent';
|
|
7
|
+
export { createTool } from '@prysm-ai/tools';
|
|
8
|
+
export type { Tool, ToolDefinition, ToolResult } from '@prysm-ai/tools';
|
|
9
|
+
export * from '@prysm-ai/memory';
|
|
10
|
+
export * from '@prysm-ai/utils';
|
|
11
|
+
export * from '@prysm-ai/logger';
|
|
12
|
+
export * from '@prysm-ai/metrics';
|
|
13
|
+
export * from '@prysm-ai/tracing';
|
|
14
|
+
export * from '@prysm-ai/prompts';
|
|
15
|
+
export * from '@prysm-ai/rag';
|
|
16
|
+
export * from '@prysm-ai/mcp';
|
|
17
|
+
export * from '@prysm-ai/skills';
|
|
18
|
+
export * from '@prysm-ai/multiagent';
|
|
19
|
+
export * from '@prysm-ai/enterprise';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGxE,cAAc,kBAAkB,CAAC;AAGjC,cAAc,iBAAiB,CAAC;AAGhC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,eAAe,CAAC;AAG9B,cAAc,eAAe,CAAC;AAG9B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Core package - unified entry point
|
|
2
|
+
// Re-export all subpackages with explicit exports to avoid conflicts
|
|
3
|
+
// LLM package - most commonly used
|
|
4
|
+
export { createModel } from '@prysm-ai/llm';
|
|
5
|
+
export { OpenAIProvider, AnthropicProvider } from '@prysm-ai/llm';
|
|
6
|
+
export { LLMRouter } from '@prysm-ai/llm';
|
|
7
|
+
// Agent package
|
|
8
|
+
export { Agent } from '@prysm-ai/agent';
|
|
9
|
+
// Tools package
|
|
10
|
+
export { createTool } from '@prysm-ai/tools';
|
|
11
|
+
// Memory package
|
|
12
|
+
export * from '@prysm-ai/memory';
|
|
13
|
+
// Utils package
|
|
14
|
+
export * from '@prysm-ai/utils';
|
|
15
|
+
// Logger package
|
|
16
|
+
export * from '@prysm-ai/logger';
|
|
17
|
+
// Metrics package
|
|
18
|
+
export * from '@prysm-ai/metrics';
|
|
19
|
+
// Tracing package
|
|
20
|
+
export * from '@prysm-ai/tracing';
|
|
21
|
+
// Prompts package
|
|
22
|
+
export * from '@prysm-ai/prompts';
|
|
23
|
+
// RAG package
|
|
24
|
+
export * from '@prysm-ai/rag';
|
|
25
|
+
// MCP package
|
|
26
|
+
export * from '@prysm-ai/mcp';
|
|
27
|
+
// Skills package
|
|
28
|
+
export * from '@prysm-ai/skills';
|
|
29
|
+
// Multiagent package
|
|
30
|
+
export * from '@prysm-ai/multiagent';
|
|
31
|
+
// Enterprise package
|
|
32
|
+
export * from '@prysm-ai/enterprise';
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,qEAAqE;AAErE,mCAAmC;AACnC,OAAO,EAAE,WAAW,EAA2B,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,gBAAgB;AAChB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,gBAAgB;AAChB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,iBAAiB;AACjB,cAAc,kBAAkB,CAAC;AAEjC,gBAAgB;AAChB,cAAc,iBAAiB,CAAC;AAEhC,iBAAiB;AACjB,cAAc,kBAAkB,CAAC;AAEjC,kBAAkB;AAClB,cAAc,mBAAmB,CAAC;AAElC,kBAAkB;AAClB,cAAc,mBAAmB,CAAC;AAElC,kBAAkB;AAClB,cAAc,mBAAmB,CAAC;AAElC,cAAc;AACd,cAAc,eAAe,CAAC;AAE9B,cAAc;AACd,cAAc,eAAe,CAAC;AAE9B,iBAAiB;AACjB,cAAc,kBAAkB,CAAC;AAEjC,qBAAqB;AACrB,cAAc,sBAAsB,CAAC;AAErC,qBAAqB;AACrB,cAAc,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,94 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prysm-ai/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Agent
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Enterprise AI Agent Framework - Unified Entry Point",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
|
|
11
|
-
"
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./llm": {
|
|
11
|
+
"import": "./dist/llm.js",
|
|
12
|
+
"types": "./dist/llm.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./agent": {
|
|
15
|
+
"import": "./dist/agent.js",
|
|
16
|
+
"types": "./dist/agent.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./tools": {
|
|
19
|
+
"import": "./dist/tools.js",
|
|
20
|
+
"types": "./dist/tools.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./memory": {
|
|
23
|
+
"import": "./dist/memory.js",
|
|
24
|
+
"types": "./dist/memory.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./utils": {
|
|
27
|
+
"import": "./dist/utils.js",
|
|
28
|
+
"types": "./dist/utils.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./logger": {
|
|
31
|
+
"import": "./dist/logger.js",
|
|
32
|
+
"types": "./dist/logger.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./metrics": {
|
|
35
|
+
"import": "./dist/metrics.js",
|
|
36
|
+
"types": "./dist/metrics.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./tracing": {
|
|
39
|
+
"import": "./dist/tracing.js",
|
|
40
|
+
"types": "./dist/tracing.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"./prompts": {
|
|
43
|
+
"import": "./dist/prompts.js",
|
|
44
|
+
"types": "./dist/prompts.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"./rag": {
|
|
47
|
+
"import": "./dist/rag.js",
|
|
48
|
+
"types": "./dist/rag.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./mcp": {
|
|
51
|
+
"import": "./dist/mcp.js",
|
|
52
|
+
"types": "./dist/mcp.d.ts"
|
|
53
|
+
},
|
|
54
|
+
"./skills": {
|
|
55
|
+
"import": "./dist/skills.js",
|
|
56
|
+
"types": "./dist/skills.d.ts"
|
|
57
|
+
},
|
|
58
|
+
"./multiagent": {
|
|
59
|
+
"import": "./dist/multiagent.js",
|
|
60
|
+
"types": "./dist/multiagent.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"./enterprise": {
|
|
63
|
+
"import": "./dist/enterprise.js",
|
|
64
|
+
"types": "./dist/enterprise.d.ts"
|
|
12
65
|
}
|
|
13
66
|
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"zod": "^3.23.0",
|
|
69
|
+
"@prysm-ai/tools": "0.3.0",
|
|
70
|
+
"@prysm-ai/agent": "0.3.0",
|
|
71
|
+
"@prysm-ai/memory": "0.3.0",
|
|
72
|
+
"@prysm-ai/llm": "0.3.0",
|
|
73
|
+
"@prysm-ai/utils": "0.3.0",
|
|
74
|
+
"@prysm-ai/tracing": "0.3.0",
|
|
75
|
+
"@prysm-ai/metrics": "0.3.0",
|
|
76
|
+
"@prysm-ai/prompts": "0.3.0",
|
|
77
|
+
"@prysm-ai/mcp": "0.3.0",
|
|
78
|
+
"@prysm-ai/logger": "0.3.0",
|
|
79
|
+
"@prysm-ai/rag": "0.3.0",
|
|
80
|
+
"@prysm-ai/skills": "0.3.0",
|
|
81
|
+
"@prysm-ai/multiagent": "0.3.0",
|
|
82
|
+
"@prysm-ai/enterprise": "0.3.0"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"typescript": "^5.4.0"
|
|
86
|
+
},
|
|
14
87
|
"scripts": {
|
|
15
88
|
"build": "tsc",
|
|
89
|
+
"build:prod": "tsc",
|
|
16
90
|
"build:watch": "tsc --watch",
|
|
17
91
|
"typecheck": "tsc --noEmit",
|
|
18
92
|
"clean": "rm -rf dist"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"zod": "^3.23.0"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"typescript": "^5.4.0"
|
|
25
93
|
}
|
|
26
94
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Core package - unified entry point
|
|
2
|
+
// Re-export all subpackages with explicit exports to avoid conflicts
|
|
3
|
+
|
|
4
|
+
// LLM package - most commonly used
|
|
5
|
+
export { createModel, type CreateModelOptions } from '@prysm-ai/llm';
|
|
6
|
+
export { OpenAIProvider, AnthropicProvider } from '@prysm-ai/llm';
|
|
7
|
+
export { LLMRouter } from '@prysm-ai/llm';
|
|
8
|
+
export type { ModelInfo } from '@prysm-ai/llm';
|
|
9
|
+
|
|
10
|
+
// Agent package
|
|
11
|
+
export { Agent } from '@prysm-ai/agent';
|
|
12
|
+
export type { AgentHooks } from '@prysm-ai/agent';
|
|
13
|
+
|
|
14
|
+
// Tools package
|
|
15
|
+
export { createTool } from '@prysm-ai/tools';
|
|
16
|
+
export type { Tool, ToolDefinition, ToolResult } from '@prysm-ai/tools';
|
|
17
|
+
|
|
18
|
+
// Memory package
|
|
19
|
+
export * from '@prysm-ai/memory';
|
|
20
|
+
|
|
21
|
+
// Utils package
|
|
22
|
+
export * from '@prysm-ai/utils';
|
|
23
|
+
|
|
24
|
+
// Logger package
|
|
25
|
+
export * from '@prysm-ai/logger';
|
|
26
|
+
|
|
27
|
+
// Metrics package
|
|
28
|
+
export * from '@prysm-ai/metrics';
|
|
29
|
+
|
|
30
|
+
// Tracing package
|
|
31
|
+
export * from '@prysm-ai/tracing';
|
|
32
|
+
|
|
33
|
+
// Prompts package
|
|
34
|
+
export * from '@prysm-ai/prompts';
|
|
35
|
+
|
|
36
|
+
// RAG package
|
|
37
|
+
export * from '@prysm-ai/rag';
|
|
38
|
+
|
|
39
|
+
// MCP package
|
|
40
|
+
export * from '@prysm-ai/mcp';
|
|
41
|
+
|
|
42
|
+
// Skills package
|
|
43
|
+
export * from '@prysm-ai/skills';
|
|
44
|
+
|
|
45
|
+
// Multiagent package
|
|
46
|
+
export * from '@prysm-ai/multiagent';
|
|
47
|
+
|
|
48
|
+
// Enterprise package
|
|
49
|
+
export * from '@prysm-ai/enterprise';
|
package/tsconfig.json
ADDED
package/agent.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig, Turn, ChatMessage } from './agent.types.js';
|
|
2
|
-
import type { AgentHooks } from './hooks.js';
|
|
3
|
-
export declare class Agent {
|
|
4
|
-
private hooks;
|
|
5
|
-
constructor(_config: AgentConfig, hooks?: AgentHooks);
|
|
6
|
-
start(): Promise<void>;
|
|
7
|
-
end(): Promise<void>;
|
|
8
|
-
runTurn(turn: Turn): Promise<TurnResult>;
|
|
9
|
-
}
|
|
10
|
-
export interface TurnResult {
|
|
11
|
-
messages: ChatMessage[];
|
|
12
|
-
interrupted: boolean;
|
|
13
|
-
}
|
package/agent.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export class Agent {
|
|
2
|
-
hooks;
|
|
3
|
-
constructor(_config, hooks) {
|
|
4
|
-
this.hooks = hooks ?? {};
|
|
5
|
-
}
|
|
6
|
-
async start() {
|
|
7
|
-
if (this.hooks.beforeAgentStart) {
|
|
8
|
-
await this.hooks.beforeAgentStart();
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
async end() {
|
|
12
|
-
if (this.hooks.afterAgentEnd) {
|
|
13
|
-
await this.hooks.afterAgentEnd();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async runTurn(turn) {
|
|
17
|
-
const { context } = turn;
|
|
18
|
-
// Before turn hook
|
|
19
|
-
if (this.hooks.beforeTurn) {
|
|
20
|
-
const shouldContinue = await this.hooks.beforeTurn(turn, context);
|
|
21
|
-
if (shouldContinue === false) {
|
|
22
|
-
this.hooks.beforeTurnSkip?.(turn, context, 'Hook returned false');
|
|
23
|
-
return { messages: [], interrupted: true };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
// Execute turn logic
|
|
28
|
-
// ... (will be implemented in later phases)
|
|
29
|
-
return { messages: [], interrupted: false };
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
if (this.hooks.onTurnError) {
|
|
33
|
-
await this.hooks.onTurnError(turn, error, context);
|
|
34
|
-
}
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
package/agent.types.d.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const ChatMessageRoleSchema: z.ZodEnum<["system", "user", "assistant", "tool"]>;
|
|
3
|
-
export type ChatMessageRole = z.infer<typeof ChatMessageRoleSchema>;
|
|
4
|
-
export interface ChatMessage {
|
|
5
|
-
id: string;
|
|
6
|
-
role: ChatMessageRole;
|
|
7
|
-
content: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
toolCallId?: string;
|
|
10
|
-
metadata?: Record<string, unknown>;
|
|
11
|
-
}
|
|
12
|
-
export declare function createChatMessage(role: ChatMessageRole, content: string, options?: Partial<ChatMessage> & {
|
|
13
|
-
id?: string;
|
|
14
|
-
}): ChatMessage;
|
|
15
|
-
export interface ToolDefinition {
|
|
16
|
-
type: 'function';
|
|
17
|
-
function: {
|
|
18
|
-
name: string;
|
|
19
|
-
description: string;
|
|
20
|
-
parameters: {
|
|
21
|
-
type: 'object';
|
|
22
|
-
properties: Record<string, unknown>;
|
|
23
|
-
required?: string[];
|
|
24
|
-
additionalProperties?: boolean;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export interface ToolCall {
|
|
29
|
-
id: string;
|
|
30
|
-
name: string;
|
|
31
|
-
arguments: Record<string, unknown>;
|
|
32
|
-
}
|
|
33
|
-
export interface ToolResult {
|
|
34
|
-
success: boolean;
|
|
35
|
-
data?: unknown;
|
|
36
|
-
error?: string;
|
|
37
|
-
}
|
|
38
|
-
export interface Turn {
|
|
39
|
-
id: string;
|
|
40
|
-
messages: ChatMessage[];
|
|
41
|
-
context: TurnContext;
|
|
42
|
-
}
|
|
43
|
-
export interface TurnContext {
|
|
44
|
-
tenantId: string | null;
|
|
45
|
-
userId: string | null;
|
|
46
|
-
sessionId: string;
|
|
47
|
-
metadata: Record<string, unknown>;
|
|
48
|
-
isBatchMode: boolean;
|
|
49
|
-
batchConfig?: {
|
|
50
|
-
maxConcurrency: number;
|
|
51
|
-
onProgress?: (completed: number, total: number) => void;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export interface AgentConfig {
|
|
55
|
-
llm: LLMConfig;
|
|
56
|
-
tools: ToolDefinition[];
|
|
57
|
-
maxTurns?: number;
|
|
58
|
-
timeoutMs?: number;
|
|
59
|
-
}
|
|
60
|
-
export interface LLMConfig {
|
|
61
|
-
provider: 'openai' | 'anthropic' | 'local';
|
|
62
|
-
apiKey?: string;
|
|
63
|
-
model?: string;
|
|
64
|
-
temperature?: number;
|
|
65
|
-
maxTokens?: number;
|
|
66
|
-
baseUrl?: string;
|
|
67
|
-
}
|
|
68
|
-
export interface LLMRequestOptions {
|
|
69
|
-
temperature?: number;
|
|
70
|
-
maxTokens?: number;
|
|
71
|
-
stop?: string[];
|
|
72
|
-
stream?: boolean;
|
|
73
|
-
}
|
|
74
|
-
export interface LLMResponse {
|
|
75
|
-
content: string;
|
|
76
|
-
reasoning?: string;
|
|
77
|
-
finishReason?: string;
|
|
78
|
-
usage?: {
|
|
79
|
-
inputTokens: number;
|
|
80
|
-
outputTokens: number;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
export type AgentEvent = {
|
|
84
|
-
type: 'turn_start';
|
|
85
|
-
turnId: string;
|
|
86
|
-
sessionId: string;
|
|
87
|
-
} | {
|
|
88
|
-
type: 'turn_end';
|
|
89
|
-
turnId: string;
|
|
90
|
-
sessionId: string;
|
|
91
|
-
} | {
|
|
92
|
-
type: 'tool_call_start';
|
|
93
|
-
toolCall: ToolCall;
|
|
94
|
-
turnId: string;
|
|
95
|
-
} | {
|
|
96
|
-
type: 'tool_call_end';
|
|
97
|
-
toolCall: ToolCall;
|
|
98
|
-
result: ToolResult;
|
|
99
|
-
turnId: string;
|
|
100
|
-
};
|
package/agent.types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
// Chat Message
|
|
3
|
-
export const ChatMessageRoleSchema = z.enum(['system', 'user', 'assistant', 'tool']);
|
|
4
|
-
export function createChatMessage(role, content, options) {
|
|
5
|
-
const result = {
|
|
6
|
-
id: options?.id ?? crypto.randomUUID(),
|
|
7
|
-
role,
|
|
8
|
-
content,
|
|
9
|
-
};
|
|
10
|
-
if (options?.name !== undefined)
|
|
11
|
-
result.name = options.name;
|
|
12
|
-
if (options?.toolCallId !== undefined)
|
|
13
|
-
result.toolCallId = options.toolCallId;
|
|
14
|
-
if (options?.metadata !== undefined)
|
|
15
|
-
result.metadata = options.metadata;
|
|
16
|
-
return result;
|
|
17
|
-
}
|
package/errors.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare class AgentError extends Error {
|
|
2
|
-
code: string;
|
|
3
|
-
statusCode?: number | undefined;
|
|
4
|
-
context?: Record<string, unknown> | undefined;
|
|
5
|
-
constructor(message: string, code: string, statusCode?: number | undefined, context?: Record<string, unknown> | undefined);
|
|
6
|
-
}
|
|
7
|
-
export declare class LLMError extends AgentError {
|
|
8
|
-
constructor(message: string, context?: Record<string, unknown>);
|
|
9
|
-
}
|
|
10
|
-
export declare class ToolExecutionError extends AgentError {
|
|
11
|
-
toolName: string;
|
|
12
|
-
constructor(message: string, toolName: string, context?: Record<string, unknown>);
|
|
13
|
-
}
|
|
14
|
-
export declare class TurnTimeoutError extends AgentError {
|
|
15
|
-
constructor(sessionId: string, timeoutMs: number);
|
|
16
|
-
}
|
|
17
|
-
export declare class ValidationError extends AgentError {
|
|
18
|
-
errors?: unknown[] | undefined;
|
|
19
|
-
constructor(message: string, errors?: unknown[] | undefined);
|
|
20
|
-
}
|
package/errors.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export class AgentError extends Error {
|
|
2
|
-
code;
|
|
3
|
-
statusCode;
|
|
4
|
-
context;
|
|
5
|
-
constructor(message, code, statusCode, context) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.code = code;
|
|
8
|
-
this.statusCode = statusCode;
|
|
9
|
-
this.context = context;
|
|
10
|
-
this.name = 'AgentError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export class LLMError extends AgentError {
|
|
14
|
-
constructor(message, context) {
|
|
15
|
-
super(message, 'LLM_ERROR', undefined, context);
|
|
16
|
-
this.name = 'LLMError';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export class ToolExecutionError extends AgentError {
|
|
20
|
-
toolName;
|
|
21
|
-
constructor(message, toolName, context) {
|
|
22
|
-
super(message, 'TOOL_EXECUTION_ERROR', undefined, context);
|
|
23
|
-
this.toolName = toolName;
|
|
24
|
-
this.name = 'ToolExecutionError';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export class TurnTimeoutError extends AgentError {
|
|
28
|
-
constructor(sessionId, timeoutMs) {
|
|
29
|
-
super(`Turn timeout after ${timeoutMs}ms`, 'TURN_TIMEOUT', undefined, { sessionId, timeoutMs });
|
|
30
|
-
this.name = 'TurnTimeoutError';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export class ValidationError extends AgentError {
|
|
34
|
-
errors;
|
|
35
|
-
constructor(message, errors) {
|
|
36
|
-
super(message, 'VALIDATION_ERROR', 400, { errors });
|
|
37
|
-
this.errors = errors;
|
|
38
|
-
this.name = 'ValidationError';
|
|
39
|
-
}
|
|
40
|
-
}
|
package/hooks.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Turn, TurnContext, ToolCall, ToolResult, ChatMessage, LLMRequestOptions, LLMResponse, AgentEvent } from './agent.types.js';
|
|
2
|
-
import type { AgentError } from './errors.js';
|
|
3
|
-
export interface ToolExecutionContext {
|
|
4
|
-
tenantId: string | null;
|
|
5
|
-
sessionId: string;
|
|
6
|
-
turnId: string;
|
|
7
|
-
toolName: string;
|
|
8
|
-
}
|
|
9
|
-
export interface AgentHooks {
|
|
10
|
-
beforeAgentStart?(): Promise<void>;
|
|
11
|
-
afterAgentEnd?(): Promise<void>;
|
|
12
|
-
beforeTurn?(turn: Turn, context: TurnContext): Promise<void | boolean>;
|
|
13
|
-
beforeTurnSkip?(turn: Turn, context: TurnContext, reason: string): void;
|
|
14
|
-
afterTurn?(turn: Turn, context: TurnContext): Promise<void>;
|
|
15
|
-
onTurnError?(turn: Turn, error: AgentError, context: TurnContext): Promise<void>;
|
|
16
|
-
beforeToolCall?(toolCall: ToolCall, context: ToolExecutionContext): Promise<void | boolean>;
|
|
17
|
-
beforeToolCallSkip?(toolCall: ToolCall, context: ToolExecutionContext, reason: string): void;
|
|
18
|
-
afterToolCall?(toolCall: ToolCall, result: ToolResult, context: ToolExecutionContext): Promise<void>;
|
|
19
|
-
beforeLLMCall?(messages: ChatMessage[], options: LLMRequestOptions): Promise<void>;
|
|
20
|
-
afterLLMCall?(response: LLMResponse): Promise<void>;
|
|
21
|
-
onError?(error: AgentError, context: TurnContext): Promise<void>;
|
|
22
|
-
onEvent?(event: AgentEvent): Promise<void>;
|
|
23
|
-
}
|
package/hooks.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/index.d.ts
DELETED
package/index.js
DELETED