connectonion 0.0.12 → 0.0.14
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 +5 -1
- package/dist/address.d.ts +1 -1
- package/dist/address.js +1 -1
- package/dist/connect/endpoint.d.ts +27 -0
- package/dist/connect/endpoint.d.ts.map +1 -0
- package/dist/connect/endpoint.js +172 -0
- package/dist/connect/index.d.ts +45 -0
- package/dist/connect/index.d.ts.map +1 -0
- package/dist/connect/index.js +65 -0
- package/dist/connect/remote-agent.d.ts +88 -0
- package/dist/connect/remote-agent.d.ts.map +1 -0
- package/dist/{connect.js → connect/remote-agent.js} +28 -503
- package/dist/connect/types.d.ts +168 -0
- package/dist/connect/types.d.ts.map +1 -0
- package/dist/connect/types.js +2 -0
- package/package.json +1 -1
- package/dist/connect.d.ts +0 -475
- package/dist/connect.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -331,7 +331,11 @@ src/
|
|
|
331
331
|
├── trust/
|
|
332
332
|
│ ├── index.ts # Trust levels (open/careful/strict)
|
|
333
333
|
│ └── tools.ts # Whitelist checks & verification
|
|
334
|
-
├── connect
|
|
334
|
+
├── connect/
|
|
335
|
+
│ ├── index.ts # connect() factory + re-exports
|
|
336
|
+
│ ├── types.ts # ChatItem, Response, AgentStatus, ConnectOptions, etc.
|
|
337
|
+
│ ├── endpoint.ts # resolveEndpoint, fetchAgentInfo, utils
|
|
338
|
+
│ └── remote-agent.ts # RemoteAgent class
|
|
335
339
|
├── console.ts # Dual logging (stderr + file)
|
|
336
340
|
├── types.ts # Core TypeScript interfaces
|
|
337
341
|
└── index.ts # Public API exports
|
package/dist/address.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @purpose Agent address/identity management with Ed25519 key generation, signing, and verification (Python address.py parity)
|
|
3
3
|
* @llm-note
|
|
4
|
-
* Dependencies: imports from [crypto, fs, path (Node.js built-ins, conditional)] | imported by [src/connect.ts, src/index.ts, tests/connect.test.ts, tests/address.test.ts, tests/e2e/signedAgent.test.ts] | tested by [tests/address.test.ts]
|
|
4
|
+
* Dependencies: imports from [crypto, fs, path (Node.js built-ins, conditional)] | imported by [src/connect/remote-agent.ts, src/index.ts, tests/connect.test.ts, tests/address.test.ts, tests/e2e/signedAgent.test.ts] | tested by [tests/address.test.ts]
|
|
5
5
|
* Data flow: generate() → creates Ed25519 keypair → exports to raw buffers → returns AddressData{address: 0x..., publicKey, privateKey} | sign(addressData, message) → recreates privateKey from buffer → signs with crypto.sign() → returns hex signature | verify(address, message, signature) → recreates publicKey from address → verifies with crypto.verify() → returns boolean
|
|
6
6
|
* State/Effects: reads/writes .co/keys/agent.key (Node.js) | reads/writes localStorage connectonion_keys (browser) | conditional require() for Node.js modules | detects environment via globalThis.window check
|
|
7
7
|
* Integration: exposes generate(), load(coDir), save(), sign(addressData, message), verify(address, message, signature), createSignedPayload(addressData, prompt, toAddress), AddressData type | browser variants: generateBrowser(), loadBrowser(), saveBrowser(), signBrowser() | canonical JSON with sorted keys for consistent signatures
|
package/dist/address.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @purpose Agent address/identity management with Ed25519 key generation, signing, and verification (Python address.py parity)
|
|
4
4
|
* @llm-note
|
|
5
|
-
* Dependencies: imports from [crypto, fs, path (Node.js built-ins, conditional)] | imported by [src/connect.ts, src/index.ts, tests/connect.test.ts, tests/address.test.ts, tests/e2e/signedAgent.test.ts] | tested by [tests/address.test.ts]
|
|
5
|
+
* Dependencies: imports from [crypto, fs, path (Node.js built-ins, conditional)] | imported by [src/connect/remote-agent.ts, src/index.ts, tests/connect.test.ts, tests/address.test.ts, tests/e2e/signedAgent.test.ts] | tested by [tests/address.test.ts]
|
|
6
6
|
* Data flow: generate() → creates Ed25519 keypair → exports to raw buffers → returns AddressData{address: 0x..., publicKey, privateKey} | sign(addressData, message) → recreates privateKey from buffer → signs with crypto.sign() → returns hex signature | verify(address, message, signature) → recreates publicKey from address → verifies with crypto.verify() → returns boolean
|
|
7
7
|
* State/Effects: reads/writes .co/keys/agent.key (Node.js) | reads/writes localStorage connectonion_keys (browser) | conditional require() for Node.js modules | detects environment via globalThis.window check
|
|
8
8
|
* Integration: exposes generate(), load(coDir), save(), sign(addressData, message), verify(address, message, signature), createSignedPayload(addressData, prompt, toAddress), AddressData type | browser variants: generateBrowser(), loadBrowser(), saveBrowser(), signBrowser() | canonical JSON with sorted keys for consistent signatures
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AgentInfo, ResolvedEndpoint, WebSocketCtor } from './types';
|
|
2
|
+
export declare const DEFAULT_RELAY = "wss://oo.openonion.ai";
|
|
3
|
+
export declare function defaultWebSocketCtor(): WebSocketCtor;
|
|
4
|
+
export declare function generateUUID(): string;
|
|
5
|
+
export declare function isBrowserEnv(): boolean;
|
|
6
|
+
export declare function canonicalJSON(obj: Record<string, unknown>): string;
|
|
7
|
+
export declare function normalizeRelayBase(relayUrl: string): string;
|
|
8
|
+
export declare function resolveEndpoint(agentAddress: string, relayUrl: string, timeoutMs?: number): Promise<ResolvedEndpoint | null>;
|
|
9
|
+
/**
|
|
10
|
+
* Fetch agent info by resolving through relay then hitting /info endpoint.
|
|
11
|
+
*
|
|
12
|
+
* @param agentAddress - Agent's public address (0x...)
|
|
13
|
+
* @param relayUrl - Relay server URL (default: wss://oo.openonion.ai)
|
|
14
|
+
* @returns Agent info including name, tools, trust level, and online status
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { fetchAgentInfo } from 'connectonion';
|
|
19
|
+
*
|
|
20
|
+
* const info = await fetchAgentInfo('0x3d4017c3...');
|
|
21
|
+
* console.log(info.name); // "my-agent"
|
|
22
|
+
* console.log(info.online); // true
|
|
23
|
+
* console.log(info.tools); // ["search", "calculate"]
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function fetchAgentInfo(agentAddress: string, relayUrl?: string): Promise<AgentInfo>;
|
|
27
|
+
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/connect/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAErE,eAAO,MAAM,aAAa,0BAA0B,CAAC;AAErD,wBAAgB,oBAAoB,IAAI,aAAa,CAQpD;AAED,wBAAgB,YAAY,IAAI,MAAM,CAUrC;AAED,wBAAgB,YAAY,IAAI,OAAO,CAItC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAOlE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQ3D;AAaD,wBAAsB,eAAe,CACnC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,SAAS,SAAO,GACf,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA8ClC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,EACpB,QAAQ,SAAgB,GACvB,OAAO,CAAC,SAAS,CAAC,CAsDpB"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_RELAY = void 0;
|
|
4
|
+
exports.defaultWebSocketCtor = defaultWebSocketCtor;
|
|
5
|
+
exports.generateUUID = generateUUID;
|
|
6
|
+
exports.isBrowserEnv = isBrowserEnv;
|
|
7
|
+
exports.canonicalJSON = canonicalJSON;
|
|
8
|
+
exports.normalizeRelayBase = normalizeRelayBase;
|
|
9
|
+
exports.resolveEndpoint = resolveEndpoint;
|
|
10
|
+
exports.fetchAgentInfo = fetchAgentInfo;
|
|
11
|
+
exports.DEFAULT_RELAY = 'wss://oo.openonion.ai';
|
|
12
|
+
function defaultWebSocketCtor() {
|
|
13
|
+
const g = globalThis;
|
|
14
|
+
if (typeof g.WebSocket === 'function') {
|
|
15
|
+
return g.WebSocket;
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
|
+
const WS = require('ws');
|
|
19
|
+
return WS;
|
|
20
|
+
}
|
|
21
|
+
function generateUUID() {
|
|
22
|
+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
23
|
+
return crypto.randomUUID();
|
|
24
|
+
}
|
|
25
|
+
// Fallback for older environments
|
|
26
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
27
|
+
const r = (Math.random() * 16) | 0;
|
|
28
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
29
|
+
return v.toString(16);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function isBrowserEnv() {
|
|
33
|
+
return typeof globalThis !== 'undefined' &&
|
|
34
|
+
typeof globalThis.window !== 'undefined' &&
|
|
35
|
+
typeof globalThis.localStorage !== 'undefined';
|
|
36
|
+
}
|
|
37
|
+
function canonicalJSON(obj) {
|
|
38
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
39
|
+
const sortedObj = {};
|
|
40
|
+
for (const key of sortedKeys) {
|
|
41
|
+
sortedObj[key] = obj[key];
|
|
42
|
+
}
|
|
43
|
+
return JSON.stringify(sortedObj);
|
|
44
|
+
}
|
|
45
|
+
function normalizeRelayBase(relayUrl) {
|
|
46
|
+
let normalized = relayUrl.replace(/\/$/, '');
|
|
47
|
+
if (normalized.endsWith('/ws/announce')) {
|
|
48
|
+
normalized = normalized.slice(0, -('/ws/announce'.length));
|
|
49
|
+
}
|
|
50
|
+
else if (normalized.endsWith('/ws')) {
|
|
51
|
+
normalized = normalized.slice(0, -('/ws'.length));
|
|
52
|
+
}
|
|
53
|
+
return normalized;
|
|
54
|
+
}
|
|
55
|
+
function sortEndpoints(endpoints) {
|
|
56
|
+
return [...endpoints].sort((a, b) => {
|
|
57
|
+
const getPriority = (url) => {
|
|
58
|
+
if (url.includes('localhost') || url.includes('127.0.0.1'))
|
|
59
|
+
return 0;
|
|
60
|
+
if (url.includes('192.168.') || url.includes('10.') || url.includes('172.16.'))
|
|
61
|
+
return 1;
|
|
62
|
+
return 2;
|
|
63
|
+
};
|
|
64
|
+
return getPriority(a) - getPriority(b);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async function resolveEndpoint(agentAddress, relayUrl, timeoutMs = 3000) {
|
|
68
|
+
const normalizedRelay = normalizeRelayBase(relayUrl);
|
|
69
|
+
const httpsRelay = normalizedRelay.replace(/^wss?:\/\//, 'https://');
|
|
70
|
+
let agentInfo;
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(`${httpsRelay}/api/relay/agents/${agentAddress}`, {
|
|
73
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
74
|
+
});
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
agentInfo = await response.json();
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (!agentInfo.endpoints?.length) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const sortedEndpoints = sortEndpoints(agentInfo.endpoints);
|
|
87
|
+
const httpEndpoints = sortedEndpoints.filter(ep => ep.startsWith('http://') || ep.startsWith('https://'));
|
|
88
|
+
for (const httpUrl of httpEndpoints) {
|
|
89
|
+
try {
|
|
90
|
+
const infoResponse = await fetch(`${httpUrl}/info`, {
|
|
91
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
92
|
+
});
|
|
93
|
+
if (!infoResponse.ok)
|
|
94
|
+
continue;
|
|
95
|
+
const info = await infoResponse.json();
|
|
96
|
+
if (info.address === agentAddress) {
|
|
97
|
+
const baseUrl = httpUrl.replace(/^https?:\/\//, '');
|
|
98
|
+
const protocol = httpUrl.startsWith('https') ? 'wss' : 'ws';
|
|
99
|
+
const wsUrl = `${protocol}://${baseUrl}/ws`;
|
|
100
|
+
return { httpUrl, wsUrl };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Fetch agent info by resolving through relay then hitting /info endpoint.
|
|
111
|
+
*
|
|
112
|
+
* @param agentAddress - Agent's public address (0x...)
|
|
113
|
+
* @param relayUrl - Relay server URL (default: wss://oo.openonion.ai)
|
|
114
|
+
* @returns Agent info including name, tools, trust level, and online status
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { fetchAgentInfo } from 'connectonion';
|
|
119
|
+
*
|
|
120
|
+
* const info = await fetchAgentInfo('0x3d4017c3...');
|
|
121
|
+
* console.log(info.name); // "my-agent"
|
|
122
|
+
* console.log(info.online); // true
|
|
123
|
+
* console.log(info.tools); // ["search", "calculate"]
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
async function fetchAgentInfo(agentAddress, relayUrl = exports.DEFAULT_RELAY) {
|
|
127
|
+
const normalizedRelay = normalizeRelayBase(relayUrl);
|
|
128
|
+
const httpsRelay = normalizedRelay.replace(/^wss?:\/\//, 'https://');
|
|
129
|
+
let agentData;
|
|
130
|
+
try {
|
|
131
|
+
const response = await fetch(`${httpsRelay}/api/relay/agents/${agentAddress}`, {
|
|
132
|
+
signal: AbortSignal.timeout(5000),
|
|
133
|
+
});
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
agentData = { endpoints: ['http://localhost:8000'] };
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
agentData = await response.json();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
agentData = { endpoints: ['http://localhost:8000'] };
|
|
143
|
+
}
|
|
144
|
+
const endpoints = agentData.endpoints?.length
|
|
145
|
+
? agentData.endpoints
|
|
146
|
+
: ['http://localhost:8000'];
|
|
147
|
+
const httpEndpoints = sortEndpoints(endpoints.filter(ep => ep.startsWith('http://') || ep.startsWith('https://')));
|
|
148
|
+
for (const httpUrl of httpEndpoints) {
|
|
149
|
+
try {
|
|
150
|
+
const infoResponse = await fetch(`${httpUrl}/info`, {
|
|
151
|
+
signal: AbortSignal.timeout(3000),
|
|
152
|
+
});
|
|
153
|
+
if (!infoResponse.ok)
|
|
154
|
+
continue;
|
|
155
|
+
const info = await infoResponse.json();
|
|
156
|
+
if (info.address === agentAddress) {
|
|
157
|
+
return {
|
|
158
|
+
address: agentAddress,
|
|
159
|
+
name: info.name,
|
|
160
|
+
tools: info.tools,
|
|
161
|
+
trust: info.trust,
|
|
162
|
+
version: info.version,
|
|
163
|
+
online: true,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return { address: agentAddress, online: false };
|
|
172
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ConnectOptions } from './types';
|
|
2
|
+
import { RemoteAgent } from './remote-agent';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { fetchAgentInfo } from './endpoint';
|
|
5
|
+
export { RemoteAgent } from './remote-agent';
|
|
6
|
+
/**
|
|
7
|
+
* Connect to a remote agent.
|
|
8
|
+
*
|
|
9
|
+
* Two connection modes:
|
|
10
|
+
* 1. Via relay (default): Uses agent address, routes through relay server
|
|
11
|
+
* 2. Direct: Uses directUrl option, connects directly to deployed agent
|
|
12
|
+
*
|
|
13
|
+
* @param agentAddress Agent public key (0x...) - used for relay routing and signing
|
|
14
|
+
* @param options Connection options
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Via relay (default) - uses agent address
|
|
19
|
+
* const agent = connect("0x3d4017c3...");
|
|
20
|
+
* const response = await agent.input("Hello");
|
|
21
|
+
*
|
|
22
|
+
* // Direct to deployed agent (bypasses relay)
|
|
23
|
+
* const agent = connect("agent-name", {
|
|
24
|
+
* directUrl: "https://my-agent.agents.openonion.ai"
|
|
25
|
+
* });
|
|
26
|
+
* const response = await agent.input("Hello");
|
|
27
|
+
*
|
|
28
|
+
* // Access UI events for rendering
|
|
29
|
+
* console.log(agent.ui); // Array of UI events
|
|
30
|
+
* console.log(agent.status); // 'idle' | 'working' | 'waiting'
|
|
31
|
+
*
|
|
32
|
+
* // Multi-turn conversation
|
|
33
|
+
* const r1 = await agent.input("Book a flight to NYC");
|
|
34
|
+
* if (!r1.done) {
|
|
35
|
+
* const r2 = await agent.input("Tomorrow at 10am");
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* // With signing (for strict trust agents)
|
|
39
|
+
* import { address } from 'connectonion';
|
|
40
|
+
* const keys = address.load('.co');
|
|
41
|
+
* const agent = connect("0x3d4017c3...", { keys });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function connect(agentAddress: string, options?: ConnectOptions): RemoteAgent;
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connect/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,OAAO,CACrB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,cAAmB,GAC3B,WAAW,CAEb"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.RemoteAgent = exports.fetchAgentInfo = void 0;
|
|
18
|
+
exports.connect = connect;
|
|
19
|
+
const remote_agent_1 = require("./remote-agent");
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
var endpoint_1 = require("./endpoint");
|
|
22
|
+
Object.defineProperty(exports, "fetchAgentInfo", { enumerable: true, get: function () { return endpoint_1.fetchAgentInfo; } });
|
|
23
|
+
var remote_agent_2 = require("./remote-agent");
|
|
24
|
+
Object.defineProperty(exports, "RemoteAgent", { enumerable: true, get: function () { return remote_agent_2.RemoteAgent; } });
|
|
25
|
+
/**
|
|
26
|
+
* Connect to a remote agent.
|
|
27
|
+
*
|
|
28
|
+
* Two connection modes:
|
|
29
|
+
* 1. Via relay (default): Uses agent address, routes through relay server
|
|
30
|
+
* 2. Direct: Uses directUrl option, connects directly to deployed agent
|
|
31
|
+
*
|
|
32
|
+
* @param agentAddress Agent public key (0x...) - used for relay routing and signing
|
|
33
|
+
* @param options Connection options
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Via relay (default) - uses agent address
|
|
38
|
+
* const agent = connect("0x3d4017c3...");
|
|
39
|
+
* const response = await agent.input("Hello");
|
|
40
|
+
*
|
|
41
|
+
* // Direct to deployed agent (bypasses relay)
|
|
42
|
+
* const agent = connect("agent-name", {
|
|
43
|
+
* directUrl: "https://my-agent.agents.openonion.ai"
|
|
44
|
+
* });
|
|
45
|
+
* const response = await agent.input("Hello");
|
|
46
|
+
*
|
|
47
|
+
* // Access UI events for rendering
|
|
48
|
+
* console.log(agent.ui); // Array of UI events
|
|
49
|
+
* console.log(agent.status); // 'idle' | 'working' | 'waiting'
|
|
50
|
+
*
|
|
51
|
+
* // Multi-turn conversation
|
|
52
|
+
* const r1 = await agent.input("Book a flight to NYC");
|
|
53
|
+
* if (!r1.done) {
|
|
54
|
+
* const r2 = await agent.input("Tomorrow at 10am");
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* // With signing (for strict trust agents)
|
|
58
|
+
* import { address } from 'connectonion';
|
|
59
|
+
* const keys = address.load('.co');
|
|
60
|
+
* const agent = connect("0x3d4017c3...", { keys });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function connect(agentAddress, options = {}) {
|
|
64
|
+
return new remote_agent_1.RemoteAgent(agentAddress, options);
|
|
65
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AgentStatus, ApprovalMode, ChatItem, ConnectOptions, Response, SessionState } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Proxy to a remote agent with streaming support.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const agent = connect("0x123abc");
|
|
8
|
+
*
|
|
9
|
+
* // Simple usage
|
|
10
|
+
* const response = await agent.input("Search for Python docs");
|
|
11
|
+
* console.log(response.text); // Agent's response
|
|
12
|
+
* console.log(response.done); // true if complete
|
|
13
|
+
*
|
|
14
|
+
* // Access UI events for rendering
|
|
15
|
+
* console.log(agent.ui); // Array of UI events
|
|
16
|
+
* console.log(agent.status); // 'idle' | 'working' | 'waiting'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class RemoteAgent {
|
|
20
|
+
/** Agent's public address */
|
|
21
|
+
readonly address: string;
|
|
22
|
+
/** Alias for address (backwards compatibility) */
|
|
23
|
+
get agentAddress(): string;
|
|
24
|
+
private _keys?;
|
|
25
|
+
private _relayUrl;
|
|
26
|
+
private _directUrl?;
|
|
27
|
+
private _resolvedEndpoint?;
|
|
28
|
+
private _endpointResolved;
|
|
29
|
+
private _WS;
|
|
30
|
+
private _status;
|
|
31
|
+
private _currentSession;
|
|
32
|
+
private _chatItems;
|
|
33
|
+
private _activeWs;
|
|
34
|
+
private _pendingPrompt;
|
|
35
|
+
private _pendingInputId;
|
|
36
|
+
private _pendingSessionId;
|
|
37
|
+
/**
|
|
38
|
+
* Fallback counter for UI event IDs.
|
|
39
|
+
* Most events use backend-generated UUIDs; counter is only for client-only events.
|
|
40
|
+
*/
|
|
41
|
+
private _uiIdCounter;
|
|
42
|
+
private _enablePolling;
|
|
43
|
+
private _pollIntervalMs;
|
|
44
|
+
private _maxPollAttempts;
|
|
45
|
+
private _lastPingTime;
|
|
46
|
+
private _healthCheckInterval;
|
|
47
|
+
constructor(agentAddress: string, options?: ConnectOptions);
|
|
48
|
+
get status(): AgentStatus;
|
|
49
|
+
get currentSession(): SessionState | null;
|
|
50
|
+
get ui(): ChatItem[];
|
|
51
|
+
get mode(): ApprovalMode;
|
|
52
|
+
setMode(mode: ApprovalMode, options?: {
|
|
53
|
+
turns?: number;
|
|
54
|
+
}): void;
|
|
55
|
+
setPrompt(prompt: string): void;
|
|
56
|
+
reset(): void;
|
|
57
|
+
resetConversation(): void;
|
|
58
|
+
input(prompt: string, options?: {
|
|
59
|
+
images?: string[];
|
|
60
|
+
timeoutMs?: number;
|
|
61
|
+
}): Promise<Response>;
|
|
62
|
+
inputAsync(prompt: string, options?: {
|
|
63
|
+
images?: string[];
|
|
64
|
+
timeoutMs?: number;
|
|
65
|
+
}): Promise<Response>;
|
|
66
|
+
respond(answer: string | string[]): void;
|
|
67
|
+
respondToApproval(approved: boolean, scope?: 'once' | 'session', mode?: 'reject_soft' | 'reject_hard' | 'reject_explain', feedback?: string): void;
|
|
68
|
+
submitOnboard(options: {
|
|
69
|
+
inviteCode?: string;
|
|
70
|
+
payment?: number;
|
|
71
|
+
}): void;
|
|
72
|
+
respondToUlwTurnsReached(action: 'continue' | 'switch_mode', options?: {
|
|
73
|
+
turns?: number;
|
|
74
|
+
mode?: ApprovalMode;
|
|
75
|
+
}): void;
|
|
76
|
+
private _ensureKeys;
|
|
77
|
+
private _pollForResult;
|
|
78
|
+
private _startHealthCheck;
|
|
79
|
+
private _stopHealthCheck;
|
|
80
|
+
private _tryResolveEndpoint;
|
|
81
|
+
private _streamInput;
|
|
82
|
+
private _removeOptimisticThinking;
|
|
83
|
+
private _handleStreamEvent;
|
|
84
|
+
private _addChatItem;
|
|
85
|
+
private _signPayload;
|
|
86
|
+
toString(): string;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=remote-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-agent.d.ts","sourceRoot":"","sources":["../../src/connect/remote-agent.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,QAAQ,EAER,cAAc,EAEd,QAAQ,EACR,YAAY,EAGb,MAAM,SAAS,CAAC;AAUjB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,WAAW;IACtB,6BAA6B;IAC7B,SAAgB,OAAO,EAAE,MAAM,CAAC;IAEhC,kDAAkD;IAClD,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED,OAAO,CAAC,KAAK,CA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