sakuya-types 0.1.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.
Files changed (2) hide show
  1. package/index.ts +101 -0
  2. package/package.json +15 -0
package/index.ts ADDED
@@ -0,0 +1,101 @@
1
+ import type { AgentTool } from "@mariozechner/pi-agent-core";
2
+ export { Type } from "@mariozechner/pi-ai";
3
+
4
+ // ── Message types ──────────────────────────────────────────────
5
+
6
+ export type SourceType = string;
7
+
8
+ export type TriggerType = "direct" | "mention" | "reply" | "scheduled" | "passive";
9
+
10
+ export interface SenderInfo {
11
+ id: string;
12
+ name?: string;
13
+ username?: string;
14
+ isBot?: boolean;
15
+ }
16
+
17
+ export interface AttachmentRef {
18
+ type: "image" | "document";
19
+ path: string;
20
+ mimeType?: string;
21
+ size?: number;
22
+ fileName?: string;
23
+ }
24
+
25
+ export interface InboundMessage {
26
+ id: string;
27
+ source: SourceType;
28
+ channelKey: string;
29
+ sender: SenderInfo;
30
+ text?: string;
31
+ command?: { name: string; args: string };
32
+ attachments: AttachmentRef[];
33
+ replyToMessageId?: string;
34
+ raw?: Record<string, unknown>;
35
+ receivedAt: string;
36
+ trigger: TriggerType;
37
+ }
38
+
39
+ // ── Adapter types ──────────────────────────────────────────────
40
+
41
+ export interface AdapterMessageHandler {
42
+ onInbound: (message: InboundMessage) => Promise<void>;
43
+ }
44
+
45
+ export interface Adapter {
46
+ readonly name: string;
47
+ start(): Promise<void>;
48
+ stop(): Promise<void>;
49
+ canHandleChannel(channelKey: string): boolean;
50
+ canHandleFile?(path: string): boolean;
51
+ sendMessage(channelKey: string, text: string, replyToMessageId?: string): Promise<string>;
52
+ sendFile?(channelKey: string, filePath: string, caption?: string): Promise<string>;
53
+ setReaction?(channelKey: string, messageId: string, emoji: string): Promise<string>;
54
+ fetchImageContent?(channelKey: string, path: string): Promise<{ data: string; mimeType: string }>;
55
+ }
56
+
57
+ // ── Tool types ─────────────────────────────────────────────────
58
+
59
+ /** Context available to tool factories at runtime */
60
+ export interface ToolContext {
61
+ currentChannelKey: string;
62
+ workspaceDir: string;
63
+ currentMessageId?: string;
64
+ }
65
+
66
+ // ── Extension types ────────────────────────────────────────────
67
+
68
+ /** Tool factory: called per agent run with the current ToolContext */
69
+ export type ToolFactory = (ctx: ToolContext) => AgentTool;
70
+
71
+ /** Adapter factory: receives messageHandler, returns an Adapter */
72
+ export type AdapterFactory = (handler: AdapterMessageHandler) => Adapter;
73
+
74
+ /**
75
+ * Context passed to extension activate()
76
+ */
77
+ export interface ExtensionContext {
78
+ /** Register an adapter factory. The handler is injected automatically at startup. */
79
+ registerAdapter(factory: AdapterFactory): void;
80
+ /**
81
+ * Register a tool factory.
82
+ * The factory is called every time an agent session starts to create fresh tool instances.
83
+ */
84
+ registerTool(factory: ToolFactory): void;
85
+ /** Absolute path to the directory containing the extension file */
86
+ extensionDir: string;
87
+ /** Sakuya workspace directory (~/.sakuya) */
88
+ workspaceDir: string;
89
+ }
90
+
91
+ /**
92
+ * Every extension module must default-export an object implementing this interface.
93
+ */
94
+ export interface SakuyaExtension {
95
+ /** Unique extension identifier for logging */
96
+ name: string;
97
+ /** Lifecycle hook: called when extension is loaded during daemon startup */
98
+ activate(ctx: ExtensionContext): void | Promise<void>;
99
+ /** Lifecycle hook: called during daemon shutdown for cleanup */
100
+ deactivate?(): void | Promise<void>;
101
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "sakuya-types",
3
+ "version": "0.1.0",
4
+ "description": "Type definitions for Sakuya extensions",
5
+ "type": "module",
6
+ "main": "index.ts",
7
+ "types": "index.ts",
8
+ "files": [
9
+ "index.ts"
10
+ ],
11
+ "peerDependencies": {
12
+ "@mariozechner/pi-agent-core": ">=0.61.0"
13
+ },
14
+ "license": "ISC"
15
+ }