connectonion 0.0.18 → 0.0.20
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/dist/connect/auth.d.ts +17 -0
- package/dist/connect/auth.d.ts.map +1 -0
- package/dist/connect/auth.js +90 -0
- package/dist/connect/chat-item-mapper.d.ts +12 -0
- package/dist/connect/chat-item-mapper.d.ts.map +1 -0
- package/dist/connect/chat-item-mapper.js +169 -0
- package/dist/connect/endpoint.d.ts +9 -4
- package/dist/connect/endpoint.d.ts.map +1 -1
- package/dist/connect/endpoint.js +9 -25
- package/dist/connect/index.d.ts +7 -0
- package/dist/connect/index.d.ts.map +1 -1
- package/dist/connect/remote-agent.d.ts +54 -69
- package/dist/connect/remote-agent.d.ts.map +1 -1
- package/dist/connect/remote-agent.js +185 -686
- package/dist/connect/types.d.ts +8 -0
- package/dist/connect/types.d.ts.map +1 -1
- package/dist/connect/ws-handlers.d.ts +14 -0
- package/dist/connect/ws-handlers.d.ts.map +1 -0
- package/dist/connect/ws-handlers.js +188 -0
- package/dist/react/index.d.ts +5 -95
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8 -230
- package/dist/react/store.d.ts +44 -0
- package/dist/react/store.d.ts.map +1 -0
- package/dist/react/store.js +61 -0
- package/dist/react/use-agent-for-human.d.ts +152 -0
- package/dist/react/use-agent-for-human.d.ts.map +1 -0
- package/dist/react/use-agent-for-human.js +204 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @llm-note
|
|
3
|
+
* Dependencies: imports from [src/address] | imported by [src/connect/remote-agent.ts, src/connect/handlers.ts]
|
|
4
|
+
* Data flow: ensureKeys resolves or generates Ed25519 keypair | signPayload signs messages for authenticated requests
|
|
5
|
+
* State/Effects: ensureKeys may write to localStorage (browser) | no persistent module state
|
|
6
|
+
*/
|
|
7
|
+
import * as address from '../address';
|
|
8
|
+
export declare function isBrowser(): boolean;
|
|
9
|
+
export declare function sortedStringify(obj: Record<string, unknown>): string;
|
|
10
|
+
export declare function ensureKeys(existing?: address.AddressData): address.AddressData;
|
|
11
|
+
/**
|
|
12
|
+
* Sign a payload with Ed25519 keys.
|
|
13
|
+
* Returns the signed envelope { payload, from, signature, timestamp }
|
|
14
|
+
* or a fallback { prompt } if no keys provided.
|
|
15
|
+
*/
|
|
16
|
+
export declare function signPayload(keys: address.AddressData | undefined, payload: Record<string, unknown>): Record<string, unknown>;
|
|
17
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/connect/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,wBAAgB,SAAS,IAAI,OAAO,CAInC;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAOpE;AAED,wBAAgB,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAQ9E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,OAAO,CAAC,WAAW,GAAG,SAAS,EACrC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
|
|
@@ -0,0 +1,90 @@
|
|
|
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.isBrowser = isBrowser;
|
|
37
|
+
exports.sortedStringify = sortedStringify;
|
|
38
|
+
exports.ensureKeys = ensureKeys;
|
|
39
|
+
exports.signPayload = signPayload;
|
|
40
|
+
/**
|
|
41
|
+
* @llm-note
|
|
42
|
+
* Dependencies: imports from [src/address] | imported by [src/connect/remote-agent.ts, src/connect/handlers.ts]
|
|
43
|
+
* Data flow: ensureKeys resolves or generates Ed25519 keypair | signPayload signs messages for authenticated requests
|
|
44
|
+
* State/Effects: ensureKeys may write to localStorage (browser) | no persistent module state
|
|
45
|
+
*/
|
|
46
|
+
const address = __importStar(require("../address"));
|
|
47
|
+
function isBrowser() {
|
|
48
|
+
return typeof globalThis !== 'undefined' &&
|
|
49
|
+
typeof globalThis.window !== 'undefined' &&
|
|
50
|
+
typeof globalThis.localStorage !== 'undefined';
|
|
51
|
+
}
|
|
52
|
+
function sortedStringify(obj) {
|
|
53
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
54
|
+
const sortedObj = {};
|
|
55
|
+
for (const key of sortedKeys) {
|
|
56
|
+
sortedObj[key] = obj[key];
|
|
57
|
+
}
|
|
58
|
+
return JSON.stringify(sortedObj);
|
|
59
|
+
}
|
|
60
|
+
function ensureKeys(existing) {
|
|
61
|
+
if (existing)
|
|
62
|
+
return existing;
|
|
63
|
+
const inBrowser = isBrowser();
|
|
64
|
+
const loaded = inBrowser ? address.loadBrowser() : address.load();
|
|
65
|
+
if (loaded)
|
|
66
|
+
return loaded;
|
|
67
|
+
const keys = inBrowser ? address.generateBrowser() : address.generate();
|
|
68
|
+
if (inBrowser)
|
|
69
|
+
address.saveBrowser(keys);
|
|
70
|
+
return keys;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Sign a payload with Ed25519 keys.
|
|
74
|
+
* Returns the signed envelope { payload, from, signature, timestamp }
|
|
75
|
+
* or a fallback { prompt } if no keys provided.
|
|
76
|
+
*/
|
|
77
|
+
function signPayload(keys, payload) {
|
|
78
|
+
if (!keys) {
|
|
79
|
+
return { prompt: payload.prompt };
|
|
80
|
+
}
|
|
81
|
+
const canonicalMessage = sortedStringify(payload);
|
|
82
|
+
const signer = isBrowser() ? address.signBrowser : address.sign;
|
|
83
|
+
const signature = signer(keys, canonicalMessage);
|
|
84
|
+
return {
|
|
85
|
+
payload,
|
|
86
|
+
from: keys.address,
|
|
87
|
+
signature,
|
|
88
|
+
timestamp: payload.timestamp,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @llm-note
|
|
3
|
+
* Dependencies: imports from [src/connect/types] | imported by [src/connect/handlers.ts]
|
|
4
|
+
* Data flow: pure function — maps server event → ChatItem mutations on the chatItems array
|
|
5
|
+
* State/Effects: mutates chatItems array in-place (push via addItem, update existing entries)
|
|
6
|
+
* Integration: called by handlers.ts for stream event types (tool_call, llm_call, etc.)
|
|
7
|
+
*/
|
|
8
|
+
import { ChatItem, ChatItemType } from './types';
|
|
9
|
+
export declare function mapEventToChatItem(chatItems: ChatItem[], event: Record<string, unknown>, addItem: (item: Partial<ChatItem> & {
|
|
10
|
+
type: ChatItemType;
|
|
11
|
+
}) => void): void;
|
|
12
|
+
//# sourceMappingURL=chat-item-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-item-mapper.d.ts","sourceRoot":"","sources":["../../src/connect/chat-item-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,QAAQ,EAAE,EACrB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,KAAK,IAAI,GAClE,IAAI,CAqLN"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapEventToChatItem = mapEventToChatItem;
|
|
4
|
+
function mapEventToChatItem(chatItems, event, addItem) {
|
|
5
|
+
switch (event.type) {
|
|
6
|
+
case 'tool_call': {
|
|
7
|
+
const toolId = (event.tool_id || event.id);
|
|
8
|
+
addItem({
|
|
9
|
+
type: 'tool_call',
|
|
10
|
+
id: toolId,
|
|
11
|
+
name: event.name,
|
|
12
|
+
args: event.args,
|
|
13
|
+
status: 'running',
|
|
14
|
+
});
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case 'tool_result': {
|
|
18
|
+
const toolId = (event.tool_id || event.id);
|
|
19
|
+
const existing = chatItems.find((e) => e.type === 'tool_call' && e.id === toolId);
|
|
20
|
+
if (existing) {
|
|
21
|
+
existing.status = event.status === 'error' ? 'error' : 'done';
|
|
22
|
+
existing.result = event.result;
|
|
23
|
+
if (typeof event.timing_ms === 'number') {
|
|
24
|
+
existing.timing_ms = event.timing_ms;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case 'llm_call': {
|
|
30
|
+
addItem({
|
|
31
|
+
type: 'thinking',
|
|
32
|
+
id: event.id,
|
|
33
|
+
status: 'running',
|
|
34
|
+
model: event.model,
|
|
35
|
+
});
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case 'llm_result': {
|
|
39
|
+
const llmId = event.id;
|
|
40
|
+
const existingThinking = chatItems.find((e) => e.type === 'thinking' && e.id === llmId);
|
|
41
|
+
if (existingThinking) {
|
|
42
|
+
existingThinking.status = event.status === 'error' ? 'error' : 'done';
|
|
43
|
+
if (typeof event.duration_ms === 'number')
|
|
44
|
+
existingThinking.duration_ms = event.duration_ms;
|
|
45
|
+
if (event.model)
|
|
46
|
+
existingThinking.model = event.model;
|
|
47
|
+
if (event.usage) {
|
|
48
|
+
existingThinking.usage = event.usage;
|
|
49
|
+
}
|
|
50
|
+
if (typeof event.context_percent === 'number')
|
|
51
|
+
existingThinking.context_percent = event.context_percent;
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case 'thinking': {
|
|
56
|
+
addItem({
|
|
57
|
+
type: 'thinking',
|
|
58
|
+
id: event.id != null ? String(event.id) : undefined,
|
|
59
|
+
status: 'done',
|
|
60
|
+
content: event.content,
|
|
61
|
+
kind: event.kind,
|
|
62
|
+
});
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case 'assistant': {
|
|
66
|
+
if (event.content) {
|
|
67
|
+
addItem({
|
|
68
|
+
type: 'agent',
|
|
69
|
+
id: event.id != null ? String(event.id) : undefined,
|
|
70
|
+
content: event.content,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'agent_image': {
|
|
76
|
+
const imageData = event.image;
|
|
77
|
+
if (imageData) {
|
|
78
|
+
const lastAgent = chatItems.filter((e) => e.type === 'agent').pop();
|
|
79
|
+
if (lastAgent) {
|
|
80
|
+
if (!lastAgent.images)
|
|
81
|
+
lastAgent.images = [];
|
|
82
|
+
lastAgent.images.push(imageData);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
addItem({
|
|
86
|
+
type: 'agent',
|
|
87
|
+
id: event.id != null ? String(event.id) : undefined,
|
|
88
|
+
content: '',
|
|
89
|
+
images: [imageData],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'intent': {
|
|
96
|
+
const intentId = event.id;
|
|
97
|
+
const status = event.status;
|
|
98
|
+
if (status === 'analyzing') {
|
|
99
|
+
addItem({ type: 'intent', id: intentId, status: 'analyzing' });
|
|
100
|
+
}
|
|
101
|
+
else if (status === 'understood') {
|
|
102
|
+
const existing = chatItems.find((e) => e.type === 'intent' && e.id === intentId);
|
|
103
|
+
if (existing) {
|
|
104
|
+
existing.status = 'understood';
|
|
105
|
+
existing.ack = event.ack;
|
|
106
|
+
existing.is_build = event.is_build;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'eval': {
|
|
112
|
+
const evalId = event.id;
|
|
113
|
+
const evalStatus = event.status;
|
|
114
|
+
if (evalStatus === 'evaluating') {
|
|
115
|
+
addItem({
|
|
116
|
+
type: 'eval',
|
|
117
|
+
id: evalId,
|
|
118
|
+
status: 'evaluating',
|
|
119
|
+
expected: event.expected,
|
|
120
|
+
eval_path: event.eval_path,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else if (evalStatus === 'done') {
|
|
124
|
+
const existing = chatItems.find((e) => e.type === 'eval' && e.id === evalId);
|
|
125
|
+
if (existing) {
|
|
126
|
+
existing.status = 'done';
|
|
127
|
+
existing.passed = event.passed;
|
|
128
|
+
existing.summary = event.summary;
|
|
129
|
+
existing.expected = event.expected;
|
|
130
|
+
existing.eval_path = event.eval_path;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'compact': {
|
|
136
|
+
const compactId = event.id;
|
|
137
|
+
const compactStatus = event.status;
|
|
138
|
+
if (compactStatus === 'compacting') {
|
|
139
|
+
addItem({
|
|
140
|
+
type: 'compact',
|
|
141
|
+
id: compactId,
|
|
142
|
+
status: 'compacting',
|
|
143
|
+
context_percent: event.context_percent,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
const existing = chatItems.find((e) => e.type === 'compact' && e.id === compactId);
|
|
148
|
+
if (existing) {
|
|
149
|
+
existing.status = compactStatus;
|
|
150
|
+
existing.context_before = event.context_before;
|
|
151
|
+
existing.context_after = event.context_after;
|
|
152
|
+
existing.message = event.message;
|
|
153
|
+
existing.error = event.error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'tool_blocked': {
|
|
159
|
+
addItem({
|
|
160
|
+
type: 'tool_blocked',
|
|
161
|
+
tool: event.tool,
|
|
162
|
+
reason: event.reason,
|
|
163
|
+
message: event.message,
|
|
164
|
+
command: event.command,
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @llm-note
|
|
3
|
+
* Dependencies: imports from [src/connect/types] | imported by [src/connect/remote-agent.ts, src/connect/handlers.ts, src/connect/index.ts]
|
|
4
|
+
* Data flow: resolveEndpoint fetches agent endpoints from relay → verifies identity → returns {httpUrl, wsUrl}
|
|
5
|
+
* State/Effects: HTTP fetch requests to relay/agent endpoints (timeout-bounded) | no persistent state
|
|
6
|
+
* Integration: exposes resolveEndpoint(), fetchAgentInfo(), getWebSocketCtor(), generateUUID(), normalizeRelayUrl(), DEFAULT_RELAY
|
|
7
|
+
*/
|
|
1
8
|
import { AgentInfo, ResolvedEndpoint, WebSocketCtor } from './types';
|
|
2
9
|
export declare const DEFAULT_RELAY = "wss://oo.openonion.ai";
|
|
3
|
-
export declare function
|
|
10
|
+
export declare function getWebSocketCtor(): WebSocketCtor;
|
|
4
11
|
export declare function generateUUID(): string;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function canonicalJSON(obj: Record<string, unknown>): string;
|
|
7
|
-
export declare function normalizeRelayBase(relayUrl: string): string;
|
|
12
|
+
export declare function normalizeRelayUrl(relayUrl: string): string;
|
|
8
13
|
export declare function resolveEndpoint(agentAddress: string, relayUrl: string, timeoutMs?: number): Promise<ResolvedEndpoint | null>;
|
|
9
14
|
/**
|
|
10
15
|
* Fetch agent info by resolving through relay then hitting /info endpoint.
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/connect/endpoint.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAErE,eAAO,MAAM,aAAa,0BAA0B,CAAC;AAErD,wBAAgB,gBAAgB,IAAI,aAAa,CAQhD;AAED,wBAAgB,YAAY,IAAI,MAAM,CASrC;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQ1D;AAaD,wBAAsB,eAAe,CACnC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,SAAS,SAAO,GACf,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA6BlC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,EACpB,QAAQ,SAAgB,GACvB,OAAO,CAAC,SAAS,CAAC,CA0BpB"}
|
package/dist/connect/endpoint.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_RELAY = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.getWebSocketCtor = getWebSocketCtor;
|
|
5
5
|
exports.generateUUID = generateUUID;
|
|
6
|
-
exports.
|
|
7
|
-
exports.canonicalJSON = canonicalJSON;
|
|
8
|
-
exports.normalizeRelayBase = normalizeRelayBase;
|
|
6
|
+
exports.normalizeRelayUrl = normalizeRelayUrl;
|
|
9
7
|
exports.resolveEndpoint = resolveEndpoint;
|
|
10
8
|
exports.fetchAgentInfo = fetchAgentInfo;
|
|
11
9
|
exports.DEFAULT_RELAY = 'wss://oo.openonion.ai';
|
|
12
|
-
function
|
|
10
|
+
function getWebSocketCtor() {
|
|
13
11
|
const g = globalThis;
|
|
14
12
|
if (typeof g.WebSocket === 'function') {
|
|
15
13
|
return g.WebSocket;
|
|
@@ -22,27 +20,13 @@ function generateUUID() {
|
|
|
22
20
|
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
23
21
|
return crypto.randomUUID();
|
|
24
22
|
}
|
|
25
|
-
// Fallback for older environments
|
|
26
23
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
27
24
|
const r = (Math.random() * 16) | 0;
|
|
28
25
|
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
29
26
|
return v.toString(16);
|
|
30
27
|
});
|
|
31
28
|
}
|
|
32
|
-
function
|
|
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) {
|
|
29
|
+
function normalizeRelayUrl(relayUrl) {
|
|
46
30
|
let normalized = relayUrl.replace(/\/$/, '');
|
|
47
31
|
if (normalized.endsWith('/ws/announce')) {
|
|
48
32
|
normalized = normalized.slice(0, -('/ws/announce'.length));
|
|
@@ -52,7 +36,7 @@ function normalizeRelayBase(relayUrl) {
|
|
|
52
36
|
}
|
|
53
37
|
return normalized;
|
|
54
38
|
}
|
|
55
|
-
function
|
|
39
|
+
function sortByProximity(endpoints) {
|
|
56
40
|
return [...endpoints].sort((a, b) => {
|
|
57
41
|
const getPriority = (url) => {
|
|
58
42
|
if (url.includes('localhost') || url.includes('127.0.0.1'))
|
|
@@ -65,7 +49,7 @@ function sortEndpoints(endpoints) {
|
|
|
65
49
|
});
|
|
66
50
|
}
|
|
67
51
|
async function resolveEndpoint(agentAddress, relayUrl, timeoutMs = 3000) {
|
|
68
|
-
const normalizedRelay =
|
|
52
|
+
const normalizedRelay = normalizeRelayUrl(relayUrl);
|
|
69
53
|
const httpsRelay = normalizedRelay.replace(/^wss?:\/\//, 'https://');
|
|
70
54
|
const response = await fetch(`${httpsRelay}/api/relay/agents/${agentAddress}`, {
|
|
71
55
|
signal: AbortSignal.timeout(timeoutMs),
|
|
@@ -75,7 +59,7 @@ async function resolveEndpoint(agentAddress, relayUrl, timeoutMs = 3000) {
|
|
|
75
59
|
const agentInfo = await response.json();
|
|
76
60
|
if (!agentInfo.endpoints?.length)
|
|
77
61
|
return null;
|
|
78
|
-
const httpEndpoints =
|
|
62
|
+
const httpEndpoints = sortByProximity(agentInfo.endpoints).filter(ep => ep.startsWith('http'));
|
|
79
63
|
for (const httpUrl of httpEndpoints) {
|
|
80
64
|
const infoResponse = await fetch(`${httpUrl}/info`, {
|
|
81
65
|
signal: AbortSignal.timeout(timeoutMs),
|
|
@@ -109,14 +93,14 @@ async function resolveEndpoint(agentAddress, relayUrl, timeoutMs = 3000) {
|
|
|
109
93
|
* ```
|
|
110
94
|
*/
|
|
111
95
|
async function fetchAgentInfo(agentAddress, relayUrl = exports.DEFAULT_RELAY) {
|
|
112
|
-
const httpsRelay =
|
|
96
|
+
const httpsRelay = normalizeRelayUrl(relayUrl).replace(/^wss?:\/\//, 'https://');
|
|
113
97
|
const relayRes = await fetch(`${httpsRelay}/api/relay/agents/${agentAddress}`, {
|
|
114
98
|
signal: AbortSignal.timeout(5000),
|
|
115
99
|
});
|
|
116
100
|
if (!relayRes.ok)
|
|
117
101
|
return { address: agentAddress, online: false };
|
|
118
102
|
const { endpoints = [] } = await relayRes.json();
|
|
119
|
-
const httpEndpoints =
|
|
103
|
+
const httpEndpoints = sortByProximity(endpoints.filter(ep => ep.startsWith('http')));
|
|
120
104
|
for (const httpUrl of httpEndpoints) {
|
|
121
105
|
const infoRes = await fetch(`${httpUrl}/info`, { signal: AbortSignal.timeout(3000) });
|
|
122
106
|
if (!infoRes.ok)
|
package/dist/connect/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @llm-note
|
|
3
|
+
* Dependencies: imports from [src/connect/types, src/connect/remote-agent, src/connect/endpoint] | imported by [src/index.ts, src/react/]
|
|
4
|
+
* Data flow: connect(agentAddress, options?) → new RemoteAgent(agentAddress, options)
|
|
5
|
+
* State/Effects: pure factory, no state
|
|
6
|
+
* Integration: barrel for connect subsystem — re-exports types, RemoteAgent, fetchAgentInfo
|
|
7
|
+
*/
|
|
1
8
|
import { ConnectOptions } from './types';
|
|
2
9
|
import { RemoteAgent } from './remote-agent';
|
|
3
10
|
export * from './types';
|
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connect/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,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"}
|
|
@@ -1,94 +1,79 @@
|
|
|
1
|
-
import { AgentStatus, ApprovalMode, ChatItem, ConnectionState, ConnectOptions, Response, SessionState } from './types';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
* ```
|
|
2
|
+
* @llm-note
|
|
3
|
+
* Dependencies: imports from [src/connect/types, src/connect/endpoint, src/connect/auth, src/connect/handlers, src/address]
|
|
4
|
+
* Data flow: input() → _connectAndSend() → creates WS + Promise → attachWsHandlers() dispatches events → resolve on OUTPUT
|
|
5
|
+
* State/Effects: owns WebSocket lifecycle + mutable _chatItems + _currentSession
|
|
6
|
+
* Integration: public API consumed by connect() factory and React useAgentForHuman hook
|
|
18
7
|
*/
|
|
8
|
+
import * as address from '../address';
|
|
9
|
+
import { AgentStatus, ApprovalMode, ChatItem, ChatItemType, ConnectionState, ConnectOptions, ResolvedEndpoint, Response, SessionState, WebSocketCtor, WebSocketLike } from './types';
|
|
19
10
|
export declare class RemoteAgent {
|
|
20
|
-
/** Agent's public address */
|
|
21
11
|
readonly address: string;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
private _reconnectBaseDelay;
|
|
43
|
-
private _shouldReconnect;
|
|
12
|
+
_keys?: address.AddressData;
|
|
13
|
+
_relayUrl: string;
|
|
14
|
+
_directUrl?: string;
|
|
15
|
+
_resolvedEndpoint?: ResolvedEndpoint;
|
|
16
|
+
_endpointResolutionAttempted: boolean;
|
|
17
|
+
_WS: WebSocketCtor;
|
|
18
|
+
_status: AgentStatus;
|
|
19
|
+
_connectionState: ConnectionState;
|
|
20
|
+
_currentSession: SessionState | null;
|
|
21
|
+
_chatItems: ChatItem[];
|
|
22
|
+
_activeWs: WebSocketLike | null;
|
|
23
|
+
_pendingPrompt: string | null;
|
|
24
|
+
_pendingInputId: string | null;
|
|
25
|
+
_pendingSessionId: string | null;
|
|
26
|
+
_lastPingTime: number;
|
|
27
|
+
_healthCheckInterval: ReturnType<typeof setInterval> | null;
|
|
28
|
+
_reconnectAttempts: number;
|
|
29
|
+
_maxReconnectAttempts: number;
|
|
30
|
+
_reconnectBaseDelay: number;
|
|
31
|
+
_shouldReconnect: boolean;
|
|
44
32
|
constructor(agentAddress: string, options?: ConnectOptions);
|
|
33
|
+
get agentAddress(): string;
|
|
45
34
|
get status(): AgentStatus;
|
|
46
35
|
get connectionState(): ConnectionState;
|
|
47
36
|
get currentSession(): SessionState | null;
|
|
48
37
|
get ui(): ChatItem[];
|
|
49
38
|
get mode(): ApprovalMode;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
reset(): void;
|
|
55
|
-
resetConversation(): void;
|
|
39
|
+
get error(): Error | null;
|
|
40
|
+
_error: Error | null;
|
|
41
|
+
_onMessage: (() => void) | null;
|
|
42
|
+
set onMessage(fn: (() => void) | null);
|
|
56
43
|
input(prompt: string, options?: {
|
|
57
44
|
images?: string[];
|
|
58
45
|
timeoutMs?: number;
|
|
59
46
|
}): Promise<Response>;
|
|
47
|
+
/** Reconnect to an existing session to receive pending output without adding duplicate UI items */
|
|
48
|
+
reconnect(sessionId?: string): Promise<Response>;
|
|
60
49
|
inputAsync(prompt: string, options?: {
|
|
61
50
|
images?: string[];
|
|
62
51
|
timeoutMs?: number;
|
|
63
52
|
}): Promise<Response>;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
setMode(mode: ApprovalMode, options?: {
|
|
54
|
+
turns?: number;
|
|
55
|
+
}): void;
|
|
56
|
+
reset(): void;
|
|
57
|
+
resetConversation(): void;
|
|
58
|
+
send(message: Record<string, unknown>): void;
|
|
59
|
+
signOnboard(options: {
|
|
67
60
|
inviteCode?: string;
|
|
68
61
|
payment?: number;
|
|
62
|
+
}): Record<string, unknown>;
|
|
63
|
+
checkSession(sessionId?: string): Promise<'running' | 'done' | 'not_found'>;
|
|
64
|
+
checkSessionStatus(sessionId: string): Promise<'running' | 'suspended' | 'completed' | 'not_found'>;
|
|
65
|
+
_addChatItem(event: Partial<ChatItem> & {
|
|
66
|
+
type: ChatItemType;
|
|
69
67
|
}): void;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
private
|
|
76
|
-
private
|
|
77
|
-
private
|
|
78
|
-
private _stopHealthCheck;
|
|
79
|
-
private _attemptReconnect;
|
|
68
|
+
_clearPlaceholder(): void;
|
|
69
|
+
_stopPingMonitor(): void;
|
|
70
|
+
_attemptReconnect(resolve: (value: Response) => void, reject: (reason?: any) => void): void;
|
|
71
|
+
_sendInput(ws: WebSocketLike, inputId: string, prompt: string, sessionId: string, isDirect: boolean, images?: string[]): void;
|
|
72
|
+
private _startPingMonitor;
|
|
73
|
+
private _resolveWsUrl;
|
|
74
|
+
private _resolveEndpointOnce;
|
|
75
|
+
private _connectAndSend;
|
|
80
76
|
private _reconnect;
|
|
81
|
-
private _tryResolveEndpoint;
|
|
82
|
-
private _streamInput;
|
|
83
|
-
/**
|
|
84
|
-
* Attach onmessage/onerror/onclose to a WebSocket.
|
|
85
|
-
* Shared by _streamInput (initial connection) and _reconnect.
|
|
86
|
-
*/
|
|
87
|
-
private _attachMessageHandlers;
|
|
88
|
-
private _removeOptimisticThinking;
|
|
89
|
-
private _handleStreamEvent;
|
|
90
|
-
private _addChatItem;
|
|
91
|
-
private _signPayload;
|
|
92
77
|
toString(): string;
|
|
93
78
|
}
|
|
94
79
|
//# sourceMappingURL=remote-agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-agent.d.ts","sourceRoot":"","sources":["../../src/connect/remote-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remote-agent.d.ts","sourceRoot":"","sources":["../../src/connect/remote-agent.ts"],"names":[],"mappings":"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"}
|