@eoasmxd/freya-sdk 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 eoasmxd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @eoasmxd/freya-sdk
2
+
3
+ Freya 智能体系统的官方插件开发标准 SDK。本项目定义了 Freya 的核心扩展契约、插件生命周期接口及公共类型。
4
+
5
+ ## 安装
6
+
7
+ 如果你想开发第三方 Freya 插件,请在你的项目中引入本 SDK 作为开发依赖:
8
+
9
+ ```bash
10
+ npm install @eoasmxd/freya-sdk --save-dev
11
+ ```
12
+
13
+ ## 核心契约
14
+
15
+ 本 SDK 导出了以下关键契约和接口:
16
+
17
+ * `FreyaPlugin`:标准插件基类契约。
18
+ * `LLMPlugin`:大语言模型提供商插件标准接口。
19
+ * `ToolPlugin`:扩展工具(Tool)插件标准接口。
20
+
21
+ ## 快速上手
22
+
23
+ 下面是一个简单的工具插件模版:
24
+
25
+ ```typescript
26
+ import { ToolPlugin, FreyaContext } from '@eoasmxd/freya-sdk';
27
+
28
+ export class MyCustomTool implements ToolPlugin {
29
+ type = 'tool';
30
+
31
+ getId(): string {
32
+ return 'my-custom-tool';
33
+ }
34
+
35
+ async execute(context: FreyaContext, params: any): Promise<any> {
36
+ // 插件业务逻辑
37
+ return { result: 'Hello from custom tool!' };
38
+ }
39
+ }
40
+ ```
41
+
42
+ ## 开源协议
43
+
44
+ 基于 [MIT License](LICENSE) 协议开源。
@@ -0,0 +1,7 @@
1
+ export * from './types/plugin.js';
2
+ export * from './types/context.js';
3
+ export * from './types/config.js';
4
+ export * from './types/llm.js';
5
+ export * from './types/tool.js';
6
+ export * from './types/channel.js';
7
+ export * from './types/command.js';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from './types/plugin.js';
2
+ export * from './types/context.js';
3
+ export * from './types/config.js';
4
+ export * from './types/llm.js';
5
+ export * from './types/tool.js';
6
+ export * from './types/channel.js';
7
+ export * from './types/command.js';
@@ -0,0 +1,16 @@
1
+ export interface ChannelAttachment {
2
+ type: 'image' | 'file';
3
+ mimeType: string;
4
+ url?: string;
5
+ base64?: string;
6
+ path?: string;
7
+ }
8
+ export interface ChannelMessage {
9
+ channelId: string;
10
+ userId: string;
11
+ messageId: string;
12
+ sessionId: string;
13
+ content: string;
14
+ attachments?: ChannelAttachment[];
15
+ connectionId?: string;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { FreyaContext } from './context.js';
2
+ export interface FreyaSubcommand {
3
+ name: string;
4
+ description: string;
5
+ usage?: string;
6
+ }
7
+ export interface FreyaCommand {
8
+ name: string;
9
+ description: string;
10
+ alias?: string[];
11
+ subcommands?: FreyaSubcommand[];
12
+ execute(args: string[], sessionId: string, ctx: FreyaContext, connectionId?: string): Promise<string | void>;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ export interface ConfigFieldSchema {
2
+ key: string;
3
+ defaultValue?: any;
4
+ description: string;
5
+ type: 'string' | 'number' | 'boolean' | 'enum' | 'object' | 'array';
6
+ enumValues?: string[];
7
+ required?: boolean;
8
+ min?: number;
9
+ max?: number;
10
+ sensitive?: boolean;
11
+ category?: string;
12
+ uiHint?: 'text' | 'textarea' | 'password' | 'select' | 'slider';
13
+ children?: ConfigFieldSchema[];
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { ILLMService } from './llm.js';
2
+ export interface EventBus {
3
+ on(event: string, listener: (...args: any[]) => void): void;
4
+ off(event: string, listener: (...args: any[]) => void): void;
5
+ emit(event: string, ...args: any[]): void;
6
+ }
7
+ export interface Logger {
8
+ info(message: string, ...args: any[]): void;
9
+ warn(message: string, ...args: any[]): void;
10
+ error(message: string, ...args: any[]): void;
11
+ debug(message: string, ...args: any[]): void;
12
+ }
13
+ export interface FreyaPaths {
14
+ /** 程序物理安装根目录(只读代码与程序级静态资源区) */
15
+ appRoot: string;
16
+ /** 运行态主目录(用户个性化配置与持久化数据区,默认 ~/.freya) */
17
+ projectRoot: string;
18
+ /** 运行时数据持久化目录(~/.freya/data) */
19
+ dataDir: string;
20
+ /** 宿主与大模型交互隔离的文件读写沙箱(~/.freya/workspace) */
21
+ workspaceDir: string;
22
+ }
23
+ export interface FreyaContext {
24
+ eventBus: EventBus;
25
+ logger: Logger;
26
+ readonly config: Readonly<Record<string, any>>;
27
+ llm: ILLMService;
28
+ paths: FreyaPaths;
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ import type { ChannelAttachment } from './channel.js';
2
+ import type { ToolDefinition } from './tool.js';
3
+ export interface LLMConsumptionContext {
4
+ ownerType: string;
5
+ ownerId: string;
6
+ }
7
+ export interface LLMOptions {
8
+ modelId?: string;
9
+ providerId?: string;
10
+ signal?: AbortSignal;
11
+ onChunk?: (text: string) => void;
12
+ attachments?: ChannelAttachment[];
13
+ modelParams?: Record<string, any>;
14
+ modelType?: 'default' | 'router' | 'image' | 'audio';
15
+ onModelSelected?: (providerId: string, modelId: string) => void;
16
+ billingContext?: LLMConsumptionContext;
17
+ }
18
+ export interface LLMPluginOptions extends LLMOptions {
19
+ modelId: string;
20
+ providerConfig: {
21
+ apiKey: string;
22
+ baseURL?: string;
23
+ };
24
+ }
25
+ export interface LLMToolCall {
26
+ id: string;
27
+ name: string;
28
+ arguments: string;
29
+ }
30
+ export interface LLMMessage {
31
+ role: 'user' | 'assistant' | 'system' | 'tool';
32
+ content: string;
33
+ toolCalls?: LLMToolCall[];
34
+ attachments?: ChannelAttachment[];
35
+ toolCallId?: string;
36
+ }
37
+ export interface LLMTokenUsage {
38
+ promptTokens: number;
39
+ completionTokens: number;
40
+ totalTokens: number;
41
+ cachedPromptTokens?: number;
42
+ }
43
+ export interface ILLMService {
44
+ chat(messages: LLMMessage[], tools?: ToolDefinition[], options?: LLMOptions): Promise<{
45
+ message: LLMMessage;
46
+ usage?: LLMTokenUsage;
47
+ }>;
48
+ getContextWindow(modelId?: string): number;
49
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { FreyaContext } from './context.js';
2
+ import type { FreyaCommand } from './command.js';
3
+ import type { FreyaToolbox } from './tool.js';
4
+ import type { LLMMessage, LLMPluginOptions, LLMTokenUsage } from './llm.js';
5
+ import type { ToolDefinition } from './tool.js';
6
+ export type PluginType = 'llm' | 'tool' | 'channel';
7
+ export interface FreyaPlugin {
8
+ type: PluginType;
9
+ id?: string;
10
+ name?: string;
11
+ version?: string;
12
+ commands?: FreyaCommand[];
13
+ setup(ctx: FreyaContext): Promise<void>;
14
+ start?(ctx: FreyaContext): Promise<void>;
15
+ stop?(ctx: FreyaContext): Promise<void>;
16
+ }
17
+ export interface ChannelPlugin extends FreyaPlugin {
18
+ }
19
+ export interface ToolPlugin extends FreyaPlugin, FreyaToolbox {
20
+ type: 'tool';
21
+ }
22
+ export interface LLMPlugin extends FreyaPlugin {
23
+ providerTypes?: string[];
24
+ chat(messages: LLMMessage[], tools?: ToolDefinition[], options?: LLMPluginOptions): Promise<{
25
+ message: LLMMessage;
26
+ usage?: LLMTokenUsage;
27
+ }>;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { FreyaContext } from './context.js';
2
+ export interface ToolDefinition {
3
+ name: string;
4
+ description: string;
5
+ parameters: object;
6
+ }
7
+ export interface FreyaTool {
8
+ getDefinition(): ToolDefinition;
9
+ execute(args: Record<string, any>, ctx: FreyaContext): Promise<string>;
10
+ }
11
+ export interface FreyaToolbox {
12
+ getId(): string;
13
+ getTools(): FreyaTool[];
14
+ getInstructionPrompt?(): string;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@eoasmxd/freya-sdk",
3
+ "version": "0.1.2",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "description": "Freya 插件开发标准 SDK,定义所有插件扩展点接口与公共类型",
10
+ "type": "module",
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/eoasmxd/freya.git",
28
+ "directory": "packages/sdk"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^22.0.0",
32
+ "typescript": "^5.5.0"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -b --force",
36
+ "clean": "rm -rf dist"
37
+ }
38
+ }