@johpaz/hive-sdk 0.1.1
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/package.json +21 -0
- package/src/channel.ts +32 -0
- package/src/hook.ts +27 -0
- package/src/index.ts +4 -0
- package/src/skill.ts +31 -0
- package/src/types.ts +5 -0
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@johpaz/hive-sdk",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Hive SDK — Build skills, channels and integrations for Hive",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"src/"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "bun test"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@johpaz/hive-core": "workspace:*",
|
|
15
|
+
"zod": "latest"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "latest",
|
|
19
|
+
"@types/bun": "latest"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/channel.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IChannel, ChannelConfig, IncomingMessage, OutboundMessage } from "@hive/core";
|
|
2
|
+
|
|
3
|
+
export interface CustomChannelConfig extends ChannelConfig {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export abstract class CustomChannel implements IChannel {
|
|
8
|
+
abstract name: string;
|
|
9
|
+
abstract accountId: string;
|
|
10
|
+
abstract config: ChannelConfig;
|
|
11
|
+
|
|
12
|
+
protected messageHandler?: (message: IncomingMessage) => Promise<void>;
|
|
13
|
+
protected running = false;
|
|
14
|
+
|
|
15
|
+
abstract start(): Promise<void>;
|
|
16
|
+
abstract stop(): Promise<void>;
|
|
17
|
+
abstract send(sessionId: string, message: OutboundMessage): Promise<void>;
|
|
18
|
+
|
|
19
|
+
onMessage(handler: (message: IncomingMessage) => Promise<void>): void {
|
|
20
|
+
this.messageHandler = handler;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
isRunning(): boolean {
|
|
24
|
+
return this.running;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected async handleMessage(message: IncomingMessage): Promise<void> {
|
|
28
|
+
if (this.messageHandler) {
|
|
29
|
+
await this.messageHandler(message);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/hook.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type HookName =
|
|
2
|
+
| "on_session_start"
|
|
3
|
+
| "on_session_end"
|
|
4
|
+
| "on_message_in"
|
|
5
|
+
| "on_message_out"
|
|
6
|
+
| "on_tool_start"
|
|
7
|
+
| "on_tool_end"
|
|
8
|
+
| "on_error"
|
|
9
|
+
| "on_compaction_start"
|
|
10
|
+
| "on_compaction_end"
|
|
11
|
+
| "on_context_overflow"
|
|
12
|
+
| "on_stuck_loop"
|
|
13
|
+
| "on_rate_limit"
|
|
14
|
+
| "on_channel_connect"
|
|
15
|
+
| "on_channel_disconnect";
|
|
16
|
+
|
|
17
|
+
export type HookHandler = (context: Record<string, unknown>) => Promise<void>;
|
|
18
|
+
|
|
19
|
+
export interface HookRegistration {
|
|
20
|
+
name: HookName;
|
|
21
|
+
handler: HookHandler;
|
|
22
|
+
priority?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function defineHook(name: HookName, handler: HookHandler): HookRegistration {
|
|
26
|
+
return { name, handler };
|
|
27
|
+
}
|
package/src/index.ts
ADDED
package/src/skill.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Tool, ToolResult } from "@hive/core";
|
|
2
|
+
|
|
3
|
+
export interface SkillDefinition {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
parameters: Record<string, unknown>;
|
|
7
|
+
run: (params: Record<string, unknown>, ctx: SkillContext) => Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SkillContext {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
agentId: string;
|
|
13
|
+
workspacePath: string;
|
|
14
|
+
config: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function defineSkill(definition: SkillDefinition): Tool {
|
|
18
|
+
return {
|
|
19
|
+
name: definition.name,
|
|
20
|
+
description: definition.description,
|
|
21
|
+
parameters: definition.parameters,
|
|
22
|
+
execute: async (params: Record<string, unknown>): Promise<ToolResult> => {
|
|
23
|
+
try {
|
|
24
|
+
const result = await definition.run(params, {} as SkillContext);
|
|
25
|
+
return { success: true, result };
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return { success: false, error: (error as Error).message };
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { Tool, ToolResult } from "@hive/core";
|
|
2
|
+
export type { IChannel, ChannelConfig, IncomingMessage, OutboundMessage } from "@hive/core";
|
|
3
|
+
export type { Config } from "@hive/core";
|
|
4
|
+
export type { AgentInstance } from "@hive/core";
|
|
5
|
+
export type { SessionInfo } from "@hive/core";
|