@hopgoldy/agent-bridge 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/README.md +90 -0
- package/dist/agent-bridge.js +2019 -0
- package/dist/cli.js +2016 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.js +1 -0
- package/dist/media-prompt.js +13 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
type ClientOutputEvent = {
|
|
2
|
+
type: "user.message";
|
|
3
|
+
clientSessionId: string;
|
|
4
|
+
text: string;
|
|
5
|
+
} | {
|
|
6
|
+
type: "command.session.new";
|
|
7
|
+
clientSessionId: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "command.session.compact";
|
|
10
|
+
clientSessionId: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: "command.session.stop";
|
|
13
|
+
clientSessionId: string;
|
|
14
|
+
};
|
|
15
|
+
type AgentInputEvent = {
|
|
16
|
+
type: "user.message";
|
|
17
|
+
text: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "command.session.compact";
|
|
20
|
+
};
|
|
21
|
+
interface OutboundAttachment {
|
|
22
|
+
kind: "image" | "file";
|
|
23
|
+
filePath: string;
|
|
24
|
+
fileName?: string;
|
|
25
|
+
caption?: string;
|
|
26
|
+
}
|
|
27
|
+
type AgentOutputPayload = {
|
|
28
|
+
type: "assistant.message";
|
|
29
|
+
text: string;
|
|
30
|
+
attachments?: OutboundAttachment[];
|
|
31
|
+
} | {
|
|
32
|
+
type: "assistant.thinking";
|
|
33
|
+
text?: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "assistant.tool.running";
|
|
36
|
+
toolName: string;
|
|
37
|
+
text?: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "assistant.tool.done";
|
|
40
|
+
toolName: string;
|
|
41
|
+
text?: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: "assistant.tool.error";
|
|
44
|
+
toolName: string;
|
|
45
|
+
text?: string;
|
|
46
|
+
} | {
|
|
47
|
+
type: "session.compacting";
|
|
48
|
+
text?: string;
|
|
49
|
+
};
|
|
50
|
+
type AgentOutputEvent = AgentOutputPayload & {
|
|
51
|
+
agentSessionId: string;
|
|
52
|
+
};
|
|
53
|
+
type ClientInputEvent = AgentOutputPayload & {
|
|
54
|
+
clientSessionId: string;
|
|
55
|
+
};
|
|
56
|
+
type LegacyAgentInputEvent = AgentInputEvent;
|
|
57
|
+
interface IMAdapter {
|
|
58
|
+
start(onOutput: (event: ClientOutputEvent) => Promise<void> | void): Promise<void>;
|
|
59
|
+
stop(): Promise<void>;
|
|
60
|
+
input(event: ClientInputEvent): Promise<void>;
|
|
61
|
+
isBusy(): Promise<boolean>;
|
|
62
|
+
}
|
|
63
|
+
interface AgentAdapter {
|
|
64
|
+
start(onOutput: (event: AgentOutputEvent) => Promise<void> | void): Promise<void>;
|
|
65
|
+
stop(): Promise<void>;
|
|
66
|
+
abort?(): Promise<void>;
|
|
67
|
+
input(event: AgentInputEvent): Promise<void>;
|
|
68
|
+
isBusy(): Promise<boolean>;
|
|
69
|
+
}
|
|
70
|
+
interface ConfigSelectOption {
|
|
71
|
+
label: string;
|
|
72
|
+
value: string;
|
|
73
|
+
}
|
|
74
|
+
interface ConfigInputOptions {
|
|
75
|
+
defaultValue?: string;
|
|
76
|
+
required?: boolean;
|
|
77
|
+
secret?: boolean;
|
|
78
|
+
validate?: (value: string) => string | null;
|
|
79
|
+
}
|
|
80
|
+
interface ConfigCollectContext {
|
|
81
|
+
input(label: string, opts?: ConfigInputOptions): Promise<string>;
|
|
82
|
+
select(label: string, options: ConfigSelectOption[]): Promise<string>;
|
|
83
|
+
confirm(label: string, defaultValue?: boolean): Promise<boolean>;
|
|
84
|
+
close(): void;
|
|
85
|
+
}
|
|
86
|
+
interface ConfigAdapter<TConfig = unknown> {
|
|
87
|
+
collect(ctx: ConfigCollectContext): Promise<TConfig>;
|
|
88
|
+
validate(config: TConfig): Promise<void> | void;
|
|
89
|
+
summarize?(config: TConfig): string;
|
|
90
|
+
}
|
|
91
|
+
interface ClientModule<TConfig = unknown> {
|
|
92
|
+
readonly type: string;
|
|
93
|
+
createConfigCollector?: () => ConfigAdapter<TConfig>;
|
|
94
|
+
createClientAdapter(config: TConfig): IMAdapter;
|
|
95
|
+
}
|
|
96
|
+
interface AgentModule<TConfig = unknown> {
|
|
97
|
+
readonly type: string;
|
|
98
|
+
createConfigCollector?: () => ConfigAdapter<TConfig>;
|
|
99
|
+
createAgentSession(args: {
|
|
100
|
+
config: TConfig;
|
|
101
|
+
}): Promise<{
|
|
102
|
+
agentSessionId: string;
|
|
103
|
+
agentAdapter: AgentAdapter;
|
|
104
|
+
}>;
|
|
105
|
+
resumeAgentSession?(args: {
|
|
106
|
+
config: TConfig;
|
|
107
|
+
agentSessionId: string;
|
|
108
|
+
}): Promise<AgentAdapter>;
|
|
109
|
+
}
|
|
110
|
+
interface FeishuClientConfig {
|
|
111
|
+
appId: string;
|
|
112
|
+
appSecret: string;
|
|
113
|
+
domain?: "feishu" | "lark";
|
|
114
|
+
encryptKey?: string;
|
|
115
|
+
verificationToken?: string;
|
|
116
|
+
requireMentionInGroup?: boolean;
|
|
117
|
+
}
|
|
118
|
+
interface PiCodingAgentConfig {
|
|
119
|
+
bin?: string;
|
|
120
|
+
sessionDir?: string;
|
|
121
|
+
model?: string;
|
|
122
|
+
extraArgs?: string[];
|
|
123
|
+
}
|
|
124
|
+
type ClientConfig = {
|
|
125
|
+
type: "feishu";
|
|
126
|
+
config: FeishuClientConfig;
|
|
127
|
+
};
|
|
128
|
+
type AgentConfig = {
|
|
129
|
+
type: "pi-coding-agent";
|
|
130
|
+
config: PiCodingAgentConfig;
|
|
131
|
+
};
|
|
132
|
+
interface ChannelConfig {
|
|
133
|
+
client: ClientConfig;
|
|
134
|
+
agent: AgentConfig;
|
|
135
|
+
}
|
|
136
|
+
interface AppDefaults {
|
|
137
|
+
agentIdleTimeoutMs: number;
|
|
138
|
+
}
|
|
139
|
+
interface AppConfig {
|
|
140
|
+
channels: Record<string, ChannelConfig>;
|
|
141
|
+
defaults: AppDefaults;
|
|
142
|
+
}
|
|
143
|
+
interface ChannelRunner {
|
|
144
|
+
stop(): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
interface GatewayCoreOptions {
|
|
147
|
+
imAdapter: IMAdapter;
|
|
148
|
+
agentModule: AgentModule<any>;
|
|
149
|
+
agentConfig: AgentConfig["config"];
|
|
150
|
+
agentIdleTimeoutMs: number;
|
|
151
|
+
bindingStore?: SessionBindingStore;
|
|
152
|
+
}
|
|
153
|
+
interface SessionBindingStore {
|
|
154
|
+
load(): Promise<Record<string, string>>;
|
|
155
|
+
save(bindings: Record<string, string>): Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
interface RunChannelOptions {
|
|
158
|
+
channelName: string;
|
|
159
|
+
channelConfig: ChannelConfig;
|
|
160
|
+
defaults: AppDefaults;
|
|
161
|
+
}
|
|
162
|
+
interface FeishuInboundMessage {
|
|
163
|
+
chatId: string;
|
|
164
|
+
chatType: "p2p" | "group";
|
|
165
|
+
messageId: string;
|
|
166
|
+
text: string;
|
|
167
|
+
mentionedBot?: boolean;
|
|
168
|
+
raw?: unknown;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type { AgentAdapter, AgentConfig, AgentInputEvent, AgentModule, AgentOutputEvent, AppConfig, AppDefaults, ChannelConfig, ChannelRunner, ClientConfig, ClientInputEvent, ClientModule, ClientOutputEvent, ConfigAdapter, ConfigCollectContext, ConfigInputOptions, ConfigSelectOption, FeishuClientConfig, FeishuInboundMessage, GatewayCoreOptions, IMAdapter, LegacyAgentInputEvent, OutboundAttachment, PiCodingAgentConfig, RunChannelOptions, SessionBindingStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/modules/agent/pi-coding-agent/adapter/media-prompt.ts
|
|
2
|
+
var MEDIA_CONVENTION_PROMPT = `When you want to send a local image or file to the user in this chat, include a line containing \`MEDIA:<absolute_path>\` in your reply (the path must point to a file that actually exists on disk). You can put it inline in a sentence or on its own line. Do not use this for files the user should not receive (e.g. credentials, temp scratch files unrelated to the request).`;
|
|
3
|
+
function media_prompt_default(pi) {
|
|
4
|
+
pi.on("before_agent_start", (event) => ({
|
|
5
|
+
systemPrompt: `${event.systemPrompt}
|
|
6
|
+
|
|
7
|
+
${MEDIA_CONVENTION_PROMPT}`
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
MEDIA_CONVENTION_PROMPT,
|
|
12
|
+
media_prompt_default as default
|
|
13
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hopgoldy/agent-bridge",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "IM to Pi bridge with dual-adapter architecture",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"im",
|
|
8
|
+
"bridge",
|
|
9
|
+
"feishu",
|
|
10
|
+
"pi",
|
|
11
|
+
"cli"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/HoPGoldy/agent-bridge"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/HoPGoldy/agent-bridge/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/HoPGoldy/agent-bridge#readme",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"bin": {
|
|
24
|
+
"agent-bridge": "./dist/agent-bridge.js"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/cli.js",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@clack/prompts": "^1.7.0",
|
|
42
|
+
"@larksuiteoapi/node-sdk": "^1.64.0",
|
|
43
|
+
"commander": "^12.1.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^24.3.0",
|
|
47
|
+
"@vitest/coverage-v8": "^3.2.7",
|
|
48
|
+
"commit-and-tag-version": "^12.7.3",
|
|
49
|
+
"cross-env": "^10.0.0",
|
|
50
|
+
"tsup": "^8.5.1",
|
|
51
|
+
"tsx": "^4.20.4",
|
|
52
|
+
"typescript": "^5.9.2",
|
|
53
|
+
"vitest": "^3.2.4"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup",
|
|
57
|
+
"prepublishOnly": "npm run build",
|
|
58
|
+
"dev": "cross-env NODE_ENV=development tsx bin/agent-bridge.ts",
|
|
59
|
+
"test": "vitest run --passWithNoTests",
|
|
60
|
+
"test:coverage": "vitest run --coverage",
|
|
61
|
+
"start": "node ./dist/agent-bridge.js",
|
|
62
|
+
"release": "commit-and-tag-version && git push --follow-tags origin main"
|
|
63
|
+
}
|
|
64
|
+
}
|