opc-agent 3.0.1 → 4.0.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 +404 -74
- package/README.zh-CN.md +82 -0
- package/dist/channels/dingtalk.d.ts +17 -0
- package/dist/channels/dingtalk.js +38 -0
- package/dist/channels/googlechat.d.ts +14 -0
- package/dist/channels/googlechat.js +37 -0
- package/dist/channels/imessage.d.ts +13 -0
- package/dist/channels/imessage.js +28 -0
- package/dist/channels/irc.d.ts +20 -0
- package/dist/channels/irc.js +71 -0
- package/dist/channels/line.d.ts +14 -0
- package/dist/channels/line.js +28 -0
- package/dist/channels/matrix.d.ts +15 -0
- package/dist/channels/matrix.js +28 -0
- package/dist/channels/mattermost.d.ts +18 -0
- package/dist/channels/mattermost.js +49 -0
- package/dist/channels/msteams.d.ts +14 -0
- package/dist/channels/msteams.js +28 -0
- package/dist/channels/nostr.d.ts +14 -0
- package/dist/channels/nostr.js +28 -0
- package/dist/channels/qq.d.ts +15 -0
- package/dist/channels/qq.js +28 -0
- package/dist/channels/signal.d.ts +14 -0
- package/dist/channels/signal.js +28 -0
- package/dist/channels/sms.d.ts +15 -0
- package/dist/channels/sms.js +28 -0
- package/dist/channels/twitch.d.ts +17 -0
- package/dist/channels/twitch.js +59 -0
- package/dist/channels/voice-call.d.ts +27 -0
- package/dist/channels/voice-call.js +82 -0
- package/dist/channels/whatsapp.d.ts +14 -0
- package/dist/channels/whatsapp.js +28 -0
- package/dist/cli/chat.d.ts +2 -0
- package/dist/cli/chat.js +134 -0
- package/dist/cli/setup.d.ts +4 -0
- package/dist/cli/setup.js +303 -0
- package/dist/cli.js +142 -6
- package/dist/core/api-server.d.ts +25 -0
- package/dist/core/api-server.js +286 -0
- package/dist/core/audio.d.ts +50 -0
- package/dist/core/audio.js +68 -0
- package/dist/core/context-discovery.d.ts +16 -0
- package/dist/core/context-discovery.js +107 -0
- package/dist/core/context-refs.d.ts +29 -0
- package/dist/core/context-refs.js +162 -0
- package/dist/core/gateway.d.ts +53 -0
- package/dist/core/gateway.js +80 -0
- package/dist/core/heartbeat.d.ts +19 -0
- package/dist/core/heartbeat.js +50 -0
- package/dist/core/hooks.d.ts +28 -0
- package/dist/core/hooks.js +82 -0
- package/dist/core/ide-bridge.d.ts +53 -0
- package/dist/core/ide-bridge.js +97 -0
- package/dist/core/node-network.d.ts +23 -0
- package/dist/core/node-network.js +77 -0
- package/dist/core/profiles.d.ts +27 -0
- package/dist/core/profiles.js +131 -0
- package/dist/core/sandbox.d.ts +25 -0
- package/dist/core/sandbox.js +84 -1
- package/dist/core/session-manager.d.ts +33 -0
- package/dist/core/session-manager.js +157 -0
- package/dist/core/vision.d.ts +45 -0
- package/dist/core/vision.js +177 -0
- package/dist/hub/brain-seed.d.ts +14 -0
- package/dist/hub/brain-seed.js +77 -0
- package/dist/hub/client.d.ts +25 -0
- package/dist/hub/client.js +44 -0
- package/dist/index.d.ts +66 -1
- package/dist/index.js +95 -3
- package/dist/memory/context-compressor.d.ts +43 -0
- package/dist/memory/context-compressor.js +167 -0
- package/dist/memory/index.d.ts +4 -0
- package/dist/memory/index.js +5 -1
- package/dist/memory/user-profiler.d.ts +50 -0
- package/dist/memory/user-profiler.js +201 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +54 -1
- package/dist/scheduler/cron-engine.d.ts +41 -0
- package/dist/scheduler/cron-engine.js +200 -0
- package/dist/scheduler/index.d.ts +3 -0
- package/dist/scheduler/index.js +7 -0
- package/dist/schema/oad.d.ts +12 -12
- package/dist/security/approvals.d.ts +53 -0
- package/dist/security/approvals.js +115 -0
- package/dist/security/elevated.d.ts +41 -0
- package/dist/security/elevated.js +89 -0
- package/dist/security/index.d.ts +6 -0
- package/dist/security/index.js +7 -1
- package/dist/security/secrets.d.ts +34 -0
- package/dist/security/secrets.js +115 -0
- package/dist/skills/builtin/index.d.ts +6 -0
- package/dist/skills/builtin/index.js +402 -0
- package/dist/skills/marketplace.d.ts +30 -0
- package/dist/skills/marketplace.js +142 -0
- package/dist/skills/types.d.ts +34 -0
- package/dist/skills/types.js +16 -0
- package/dist/studio/server.d.ts +25 -0
- package/dist/studio/server.js +780 -0
- package/dist/studio/templates-data.d.ts +21 -0
- package/dist/studio/templates-data.js +148 -0
- package/dist/studio-ui/index.html +2502 -1073
- package/dist/tools/builtin/browser.d.ts +47 -0
- package/dist/tools/builtin/browser.js +284 -0
- package/dist/tools/builtin/home-assistant.d.ts +12 -0
- package/dist/tools/builtin/home-assistant.js +126 -0
- package/dist/tools/builtin/index.d.ts +7 -1
- package/dist/tools/builtin/index.js +23 -2
- package/dist/tools/builtin/rl-tools.d.ts +13 -0
- package/dist/tools/builtin/rl-tools.js +228 -0
- package/dist/tools/builtin/vision.d.ts +6 -0
- package/dist/tools/builtin/vision.js +61 -0
- package/dist/tools/builtin/web-search.d.ts +9 -0
- package/dist/tools/builtin/web-search.js +150 -0
- package/dist/tools/document-processor.d.ts +39 -0
- package/dist/tools/document-processor.js +188 -0
- package/dist/tools/image-generator.d.ts +42 -0
- package/dist/tools/image-generator.js +136 -0
- package/dist/tools/web-scraper.d.ts +20 -0
- package/dist/tools/web-scraper.js +148 -0
- package/dist/tools/web-search.d.ts +51 -0
- package/dist/tools/web-search.js +152 -0
- package/install.ps1 +154 -0
- package/install.sh +164 -0
- package/package.json +63 -52
- package/src/channels/dingtalk.ts +46 -0
- package/src/channels/googlechat.ts +42 -0
- package/src/channels/imessage.ts +32 -0
- package/src/channels/irc.ts +82 -0
- package/src/channels/line.ts +33 -0
- package/src/channels/matrix.ts +34 -0
- package/src/channels/mattermost.ts +57 -0
- package/src/channels/msteams.ts +33 -0
- package/src/channels/nostr.ts +33 -0
- package/src/channels/qq.ts +34 -0
- package/src/channels/signal.ts +33 -0
- package/src/channels/sms.ts +34 -0
- package/src/channels/twitch.ts +65 -0
- package/src/channels/voice-call.ts +100 -0
- package/src/channels/whatsapp.ts +33 -0
- package/src/cli/chat.ts +99 -0
- package/src/cli/setup.ts +314 -0
- package/src/cli.ts +148 -6
- package/src/core/api-server.ts +277 -0
- package/src/core/audio.ts +98 -0
- package/src/core/context-discovery.ts +85 -0
- package/src/core/context-refs.ts +140 -0
- package/src/core/gateway.ts +106 -0
- package/src/core/heartbeat.ts +51 -0
- package/src/core/hooks.ts +105 -0
- package/src/core/ide-bridge.ts +133 -0
- package/src/core/node-network.ts +86 -0
- package/src/core/profiles.ts +122 -0
- package/src/core/sandbox.ts +100 -0
- package/src/core/session-manager.ts +137 -0
- package/src/core/vision.ts +180 -0
- package/src/hub/brain-seed.ts +54 -0
- package/src/hub/client.ts +60 -0
- package/src/index.ts +86 -1
- package/src/memory/context-compressor.ts +189 -0
- package/src/memory/index.ts +4 -0
- package/src/memory/user-profiler.ts +215 -0
- package/src/providers/index.ts +64 -1
- package/src/scheduler/cron-engine.ts +191 -0
- package/src/scheduler/index.ts +2 -0
- package/src/security/approvals.ts +143 -0
- package/src/security/elevated.ts +105 -0
- package/src/security/index.ts +6 -0
- package/src/security/secrets.ts +129 -0
- package/src/skills/builtin/index.ts +408 -0
- package/src/skills/marketplace.ts +113 -0
- package/src/skills/types.ts +42 -0
- package/src/studio/server.ts +1591 -791
- package/src/studio/templates-data.ts +178 -0
- package/src/studio-ui/index.html +2502 -1073
- package/src/tools/builtin/browser.ts +299 -0
- package/src/tools/builtin/home-assistant.ts +116 -0
- package/src/tools/builtin/index.ts +37 -28
- package/src/tools/builtin/rl-tools.ts +243 -0
- package/src/tools/builtin/vision.ts +64 -0
- package/src/tools/builtin/web-search.ts +126 -0
- package/src/tools/document-processor.ts +213 -0
- package/src/tools/image-generator.ts +150 -0
- package/src/tools/web-scraper.ts +179 -0
- package/src/tools/web-search.ts +180 -0
- package/tests/api-server.test.ts +148 -0
- package/tests/approvals.test.ts +89 -0
- package/tests/audio.test.ts +40 -0
- package/tests/browser.test.ts +179 -0
- package/tests/builtin-tools.test.ts +83 -83
- package/tests/channels-extra.test.ts +45 -0
- package/tests/context-compressor.test.ts +172 -0
- package/tests/context-refs.test.ts +121 -0
- package/tests/cron-engine.test.ts +101 -0
- package/tests/document-processor.test.ts +69 -0
- package/tests/e2e-nocode.test.ts +442 -0
- package/tests/elevated.test.ts +69 -0
- package/tests/gateway.test.ts +63 -71
- package/tests/home-assistant.test.ts +40 -0
- package/tests/hooks.test.ts +79 -0
- package/tests/ide-bridge.test.ts +38 -0
- package/tests/image-generator.test.ts +84 -0
- package/tests/node-network.test.ts +74 -0
- package/tests/profiles.test.ts +61 -0
- package/tests/rl-tools.test.ts +93 -0
- package/tests/sandbox-manager.test.ts +46 -0
- package/tests/secrets.test.ts +107 -0
- package/tests/settings-api.test.ts +148 -0
- package/tests/setup.test.ts +73 -0
- package/tests/studio.test.ts +402 -229
- package/tests/tools/builtin-extended.test.ts +138 -138
- package/tests/user-profiler.test.ts +169 -0
- package/tests/v090-features.test.ts +254 -0
- package/tests/vision.test.ts +61 -0
- package/tests/voice-call.test.ts +47 -0
- package/tests/voice-interaction.test.ts +38 -0
- package/tests/web-search.test.ts +155 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignalChannel = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
class SignalChannel extends index_1.BaseChannel {
|
|
6
|
+
type = 'signal';
|
|
7
|
+
config;
|
|
8
|
+
constructor(config = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
async start() {
|
|
13
|
+
try {
|
|
14
|
+
require('signal-cli');
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new Error('Install signal-cli to use the SignalChannel. Run: npm install signal-cli');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async stop() {
|
|
21
|
+
// cleanup
|
|
22
|
+
}
|
|
23
|
+
async send(chatId, text) {
|
|
24
|
+
throw new Error('SignalChannel: not yet connected. Call start() first.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SignalChannel = SignalChannel;
|
|
28
|
+
//# sourceMappingURL=signal.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseChannel } from './index';
|
|
2
|
+
export interface SMSChannelConfig {
|
|
3
|
+
accountSid?: string;
|
|
4
|
+
authToken?: string;
|
|
5
|
+
fromNumber?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class SMSChannel extends BaseChannel {
|
|
8
|
+
readonly type = "sms";
|
|
9
|
+
private config;
|
|
10
|
+
constructor(config?: SMSChannelConfig);
|
|
11
|
+
start(): Promise<void>;
|
|
12
|
+
stop(): Promise<void>;
|
|
13
|
+
send(chatId: string, text: string): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=sms.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SMSChannel = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
class SMSChannel extends index_1.BaseChannel {
|
|
6
|
+
type = 'sms';
|
|
7
|
+
config;
|
|
8
|
+
constructor(config = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
async start() {
|
|
13
|
+
try {
|
|
14
|
+
require('twilio');
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new Error('Install twilio to use the SMSChannel. Run: npm install twilio');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async stop() {
|
|
21
|
+
// cleanup
|
|
22
|
+
}
|
|
23
|
+
async send(chatId, text) {
|
|
24
|
+
throw new Error('SMSChannel: not yet connected. Call start() first.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SMSChannel = SMSChannel;
|
|
28
|
+
//# sourceMappingURL=sms.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseChannel } from './index';
|
|
2
|
+
export interface TwitchChannelConfig {
|
|
3
|
+
username: string;
|
|
4
|
+
oauthToken: string;
|
|
5
|
+
channels: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare class TwitchChannel extends BaseChannel {
|
|
8
|
+
readonly type = "twitch";
|
|
9
|
+
private config;
|
|
10
|
+
private client;
|
|
11
|
+
private running;
|
|
12
|
+
constructor(config: TwitchChannelConfig);
|
|
13
|
+
start(): Promise<void>;
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
send(channel: string, text: string): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=twitch.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TwitchChannel = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
class TwitchChannel extends index_1.BaseChannel {
|
|
6
|
+
type = 'twitch';
|
|
7
|
+
config;
|
|
8
|
+
client = null;
|
|
9
|
+
running = false;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super();
|
|
12
|
+
if (!config.username || !config.oauthToken || !config.channels?.length) {
|
|
13
|
+
throw new Error('TwitchChannel requires username, oauthToken, and channels in config');
|
|
14
|
+
}
|
|
15
|
+
this.config = config;
|
|
16
|
+
}
|
|
17
|
+
async start() {
|
|
18
|
+
let tmi;
|
|
19
|
+
try {
|
|
20
|
+
tmi = require('tmi.js');
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new Error('Install tmi.js to use the TwitchChannel. Run: npm install tmi.js');
|
|
24
|
+
}
|
|
25
|
+
this.client = new tmi.Client({
|
|
26
|
+
identity: { username: this.config.username, password: this.config.oauthToken },
|
|
27
|
+
channels: this.config.channels,
|
|
28
|
+
});
|
|
29
|
+
await this.client.connect();
|
|
30
|
+
this.running = true;
|
|
31
|
+
this.client.on('message', async (channel, tags, message, self) => {
|
|
32
|
+
if (self || !this.handler)
|
|
33
|
+
return;
|
|
34
|
+
const msg = {
|
|
35
|
+
id: tags.id || Date.now().toString(),
|
|
36
|
+
role: 'user',
|
|
37
|
+
content: message,
|
|
38
|
+
timestamp: Date.now(),
|
|
39
|
+
metadata: { channel, username: tags.username, tags },
|
|
40
|
+
};
|
|
41
|
+
await this.handler(msg);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async stop() {
|
|
45
|
+
if (this.client) {
|
|
46
|
+
await this.client.disconnect();
|
|
47
|
+
this.client = null;
|
|
48
|
+
}
|
|
49
|
+
this.running = false;
|
|
50
|
+
}
|
|
51
|
+
async send(channel, text) {
|
|
52
|
+
if (!this.running || !this.client) {
|
|
53
|
+
throw new Error('TwitchChannel: not started. Call start() first.');
|
|
54
|
+
}
|
|
55
|
+
await this.client.say(channel, text);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.TwitchChannel = TwitchChannel;
|
|
59
|
+
//# sourceMappingURL=twitch.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export interface VoiceCallConfig {
|
|
3
|
+
provider: 'twilio' | 'vonage' | 'webrtc' | 'sip';
|
|
4
|
+
credentials?: Record<string, string>;
|
|
5
|
+
sttProvider?: string;
|
|
6
|
+
ttsProvider?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class VoiceCallManager extends EventEmitter {
|
|
9
|
+
private config;
|
|
10
|
+
private calls;
|
|
11
|
+
private audioListeners;
|
|
12
|
+
constructor(config: VoiceCallConfig);
|
|
13
|
+
private ensureCredentials;
|
|
14
|
+
startCall(to: string): Promise<string>;
|
|
15
|
+
endCall(callId: string): Promise<void>;
|
|
16
|
+
onIncoming(callback: (callId: string, from: string) => void): void;
|
|
17
|
+
simulateIncoming(from: string): string;
|
|
18
|
+
sendAudio(callId: string, audio: Buffer): Promise<void>;
|
|
19
|
+
onAudio(callId: string, callback: (audio: Buffer) => void): void;
|
|
20
|
+
getCallStatus(callId: string): 'ringing' | 'active' | 'ended';
|
|
21
|
+
listActiveCalls(): Array<{
|
|
22
|
+
callId: string;
|
|
23
|
+
from: string;
|
|
24
|
+
startedAt: number;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=voice-call.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VoiceCallManager = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
class VoiceCallManager extends events_1.EventEmitter {
|
|
7
|
+
config;
|
|
8
|
+
calls = new Map();
|
|
9
|
+
audioListeners = new Map();
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super();
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
ensureCredentials() {
|
|
15
|
+
if (!this.config.credentials || Object.keys(this.config.credentials).length === 0) {
|
|
16
|
+
throw new Error(`Voice call provider "${this.config.provider}" requires credentials. ` +
|
|
17
|
+
`Please configure credentials for ${this.config.provider} in your VoiceCallConfig.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async startCall(to) {
|
|
21
|
+
this.ensureCredentials();
|
|
22
|
+
const callId = (0, crypto_1.randomUUID)();
|
|
23
|
+
const call = {
|
|
24
|
+
callId,
|
|
25
|
+
from: 'self',
|
|
26
|
+
to,
|
|
27
|
+
status: 'ringing',
|
|
28
|
+
startedAt: Date.now(),
|
|
29
|
+
};
|
|
30
|
+
this.calls.set(callId, call);
|
|
31
|
+
// Simulate connection
|
|
32
|
+
setTimeout(() => {
|
|
33
|
+
const c = this.calls.get(callId);
|
|
34
|
+
if (c && c.status === 'ringing')
|
|
35
|
+
c.status = 'active';
|
|
36
|
+
}, 100);
|
|
37
|
+
return callId;
|
|
38
|
+
}
|
|
39
|
+
async endCall(callId) {
|
|
40
|
+
const call = this.calls.get(callId);
|
|
41
|
+
if (!call)
|
|
42
|
+
throw new Error(`Call ${callId} not found`);
|
|
43
|
+
call.status = 'ended';
|
|
44
|
+
this.audioListeners.delete(callId);
|
|
45
|
+
}
|
|
46
|
+
onIncoming(callback) {
|
|
47
|
+
this.on('incoming', callback);
|
|
48
|
+
}
|
|
49
|
+
simulateIncoming(from) {
|
|
50
|
+
const callId = (0, crypto_1.randomUUID)();
|
|
51
|
+
const call = { callId, from, to: 'self', status: 'ringing', startedAt: Date.now() };
|
|
52
|
+
this.calls.set(callId, call);
|
|
53
|
+
this.emit('incoming', callId, from);
|
|
54
|
+
return callId;
|
|
55
|
+
}
|
|
56
|
+
async sendAudio(callId, audio) {
|
|
57
|
+
const call = this.calls.get(callId);
|
|
58
|
+
if (!call)
|
|
59
|
+
throw new Error(`Call ${callId} not found`);
|
|
60
|
+
if (call.status !== 'active')
|
|
61
|
+
throw new Error(`Call ${callId} is not active`);
|
|
62
|
+
// Stub: would send audio to provider
|
|
63
|
+
}
|
|
64
|
+
onAudio(callId, callback) {
|
|
65
|
+
const listeners = this.audioListeners.get(callId) || [];
|
|
66
|
+
listeners.push(callback);
|
|
67
|
+
this.audioListeners.set(callId, listeners);
|
|
68
|
+
}
|
|
69
|
+
getCallStatus(callId) {
|
|
70
|
+
const call = this.calls.get(callId);
|
|
71
|
+
if (!call)
|
|
72
|
+
throw new Error(`Call ${callId} not found`);
|
|
73
|
+
return call.status;
|
|
74
|
+
}
|
|
75
|
+
listActiveCalls() {
|
|
76
|
+
return Array.from(this.calls.values())
|
|
77
|
+
.filter(c => c.status !== 'ended')
|
|
78
|
+
.map(({ callId, from, startedAt }) => ({ callId, from, startedAt }));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.VoiceCallManager = VoiceCallManager;
|
|
82
|
+
//# sourceMappingURL=voice-call.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseChannel } from './index';
|
|
2
|
+
export interface WhatsAppChannelConfig {
|
|
3
|
+
phoneNumber?: string;
|
|
4
|
+
authDir?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class WhatsAppChannel extends BaseChannel {
|
|
7
|
+
readonly type = "whatsapp";
|
|
8
|
+
private config;
|
|
9
|
+
constructor(config?: WhatsAppChannelConfig);
|
|
10
|
+
start(): Promise<void>;
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
send(chatId: string, text: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=whatsapp.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhatsAppChannel = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
class WhatsAppChannel extends index_1.BaseChannel {
|
|
6
|
+
type = 'whatsapp';
|
|
7
|
+
config;
|
|
8
|
+
constructor(config = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
async start() {
|
|
13
|
+
try {
|
|
14
|
+
require('@whiskeysockets/baileys');
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new Error('Install @whiskeysockets/baileys to use the WhatsAppChannel. Run: npm install @whiskeysockets/baileys');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async stop() {
|
|
21
|
+
// cleanup
|
|
22
|
+
}
|
|
23
|
+
async send(chatId, text) {
|
|
24
|
+
throw new Error('WhatsAppChannel: not yet connected. Call start() first.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.WhatsAppChannel = WhatsAppChannel;
|
|
28
|
+
//# sourceMappingURL=whatsapp.js.map
|
package/dist/cli/chat.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.runChat = runChat;
|
|
37
|
+
const readline = __importStar(require("readline"));
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const os = __importStar(require("os"));
|
|
41
|
+
const providers_1 = require("../providers");
|
|
42
|
+
const OPC_HOME = path.join(os.homedir(), '.opc');
|
|
43
|
+
const CONFIG_PATH = path.join(OPC_HOME, 'config.json');
|
|
44
|
+
const c = {
|
|
45
|
+
green: (s) => `\x1b[32m${s}\x1b[0m`,
|
|
46
|
+
red: (s) => `\x1b[31m${s}\x1b[0m`,
|
|
47
|
+
cyan: (s) => `\x1b[36m${s}\x1b[0m`,
|
|
48
|
+
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
49
|
+
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
50
|
+
};
|
|
51
|
+
function loadConfig() {
|
|
52
|
+
if (!fs.existsSync(CONFIG_PATH))
|
|
53
|
+
return {};
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function runChat() {
|
|
62
|
+
const config = loadConfig();
|
|
63
|
+
if (!config.provider || !config.model) {
|
|
64
|
+
console.log(`${c.red('✘')} 未找到配置。请先运行 ${c.cyan('opc setup')} 完成初始设置。`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
const agentId = config.defaultAgent;
|
|
68
|
+
let agentConfig = {};
|
|
69
|
+
if (agentId) {
|
|
70
|
+
const agentPath = path.join(OPC_HOME, 'agents', agentId, 'config.json');
|
|
71
|
+
if (fs.existsSync(agentPath)) {
|
|
72
|
+
try {
|
|
73
|
+
agentConfig = JSON.parse(fs.readFileSync(agentPath, 'utf-8'));
|
|
74
|
+
}
|
|
75
|
+
catch { /* ignore */ }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const agentName = agentConfig.name || 'AI 助手';
|
|
79
|
+
const systemPrompt = agentConfig.description
|
|
80
|
+
? `你是「${agentName}」,${agentConfig.description}。请用简洁友好的方式回答。`
|
|
81
|
+
: `你是「${agentName}」,一个智能 AI 助手。请用简洁友好的方式回答。`;
|
|
82
|
+
console.log('');
|
|
83
|
+
console.log(c.bold(`💬 与「${agentName}」对话`));
|
|
84
|
+
console.log(c.dim(' 输入 /quit 退出'));
|
|
85
|
+
console.log('');
|
|
86
|
+
let provider;
|
|
87
|
+
try {
|
|
88
|
+
provider = (0, providers_1.createProvider)({
|
|
89
|
+
provider: config.provider,
|
|
90
|
+
model: config.model,
|
|
91
|
+
apiKey: config.apiKey,
|
|
92
|
+
baseUrl: config.baseUrl,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
console.log(`${c.red('✘')} 无法初始化模型: ${err.message}`);
|
|
97
|
+
console.log(c.dim(` Provider: ${config.provider}, Model: ${config.model}`));
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
const messages = [
|
|
101
|
+
{ role: 'system', content: systemPrompt },
|
|
102
|
+
];
|
|
103
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
104
|
+
const askQuestion = () => {
|
|
105
|
+
rl.question(c.cyan('你: '), async (input) => {
|
|
106
|
+
const trimmed = input.trim();
|
|
107
|
+
if (!trimmed) {
|
|
108
|
+
askQuestion();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (trimmed === '/quit' || trimmed === '/exit' || trimmed === '/q') {
|
|
112
|
+
console.log(c.dim('\n👋 再见!'));
|
|
113
|
+
rl.close();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
messages.push({ role: 'user', content: trimmed });
|
|
117
|
+
try {
|
|
118
|
+
process.stdout.write(c.green(`${agentName}: `));
|
|
119
|
+
const response = await provider.chat(messages);
|
|
120
|
+
const reply = typeof response === 'string' ? response : response?.content || response?.message?.content || JSON.stringify(response);
|
|
121
|
+
console.log(reply);
|
|
122
|
+
console.log('');
|
|
123
|
+
messages.push({ role: 'assistant', content: reply });
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
console.log(c.red(`\n 错误: ${err.message}`));
|
|
127
|
+
console.log('');
|
|
128
|
+
}
|
|
129
|
+
askQuestion();
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
askQuestion();
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=chat.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as readline from 'readline';
|
|
2
|
+
export declare function createRL(input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream): readline.Interface;
|
|
3
|
+
export declare function runSetup(input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=setup.d.ts.map
|