@agentconnect/sdk 0.1.2 → 0.1.5
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 +2 -2
- package/dist/host.d.ts +10 -0
- package/dist/host.js +184 -0
- package/dist/index.d.ts +58 -3
- package/dist/index.js +126 -12
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -70,9 +70,9 @@ session.on('raw_line', (event) => {
|
|
|
70
70
|
console.log('CLI:', event.line);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
session.on('
|
|
73
|
+
session.on('detail', (event) => {
|
|
74
74
|
if (event.provider === 'codex') {
|
|
75
|
-
console.log('Codex
|
|
75
|
+
console.log('Codex detail:', event.providerDetail);
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
```
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type EnsureHostOptions = {
|
|
2
|
+
host?: string;
|
|
3
|
+
port?: number;
|
|
4
|
+
appPath?: string;
|
|
5
|
+
cliPackage?: string;
|
|
6
|
+
runtime?: string;
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function ensureAgentConnectHost(options?: EnsureHostOptions): Promise<void>;
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import net from 'net';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
const HOST_KEY = '__agentconnectHostState__';
|
|
6
|
+
function getState() {
|
|
7
|
+
const globalAny = globalThis;
|
|
8
|
+
if (!globalAny[HOST_KEY]) {
|
|
9
|
+
globalAny[HOST_KEY] = { status: 'idle' };
|
|
10
|
+
}
|
|
11
|
+
return globalAny[HOST_KEY];
|
|
12
|
+
}
|
|
13
|
+
function findExecutable(name) {
|
|
14
|
+
const envPath = process.env.PATH || '';
|
|
15
|
+
const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
|
|
16
|
+
for (const entry of envPath.split(path.delimiter)) {
|
|
17
|
+
if (!entry)
|
|
18
|
+
continue;
|
|
19
|
+
for (const ext of extensions) {
|
|
20
|
+
const candidate = path.join(entry, `${name}${ext}`);
|
|
21
|
+
try {
|
|
22
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
23
|
+
return candidate;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
function findPackageRoot(startDir, pkgName) {
|
|
33
|
+
let current = startDir;
|
|
34
|
+
while (true) {
|
|
35
|
+
const candidate = path.join(current, 'node_modules', pkgName, 'package.json');
|
|
36
|
+
if (fs.existsSync(candidate))
|
|
37
|
+
return path.dirname(candidate);
|
|
38
|
+
const parent = path.dirname(current);
|
|
39
|
+
if (parent === current)
|
|
40
|
+
break;
|
|
41
|
+
current = parent;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function resolveCliEntry(appPath, cliPackage) {
|
|
46
|
+
const pkgRoot = findPackageRoot(appPath, cliPackage);
|
|
47
|
+
if (!pkgRoot) {
|
|
48
|
+
throw new Error(`AgentConnect CLI not found. Install ${cliPackage} and retry.`);
|
|
49
|
+
}
|
|
50
|
+
const pkgJsonPath = path.join(pkgRoot, 'package.json');
|
|
51
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
|
52
|
+
let entry = pkg.main || 'dist/index.js';
|
|
53
|
+
if (typeof pkg.bin === 'string') {
|
|
54
|
+
entry = pkg.bin;
|
|
55
|
+
}
|
|
56
|
+
else if (pkg.bin && typeof pkg.bin === 'object') {
|
|
57
|
+
entry = pkg.bin.agentconnect || entry;
|
|
58
|
+
}
|
|
59
|
+
const resolved = path.join(pkgRoot, entry);
|
|
60
|
+
if (!fs.existsSync(resolved)) {
|
|
61
|
+
throw new Error(`AgentConnect CLI entry not found at ${resolved}`);
|
|
62
|
+
}
|
|
63
|
+
return resolved;
|
|
64
|
+
}
|
|
65
|
+
function resolveRuntime(runtime) {
|
|
66
|
+
if (runtime)
|
|
67
|
+
return runtime;
|
|
68
|
+
const override = process.env.AGENTCONNECT_NODE;
|
|
69
|
+
if (override)
|
|
70
|
+
return override;
|
|
71
|
+
if (!process.execPath.toLowerCase().includes('bun'))
|
|
72
|
+
return process.execPath;
|
|
73
|
+
return findExecutable('node') || 'node';
|
|
74
|
+
}
|
|
75
|
+
function isPortOpen(host, port, timeoutMs = 300) {
|
|
76
|
+
return new Promise((resolve) => {
|
|
77
|
+
const socket = new net.Socket();
|
|
78
|
+
const finalize = (result) => {
|
|
79
|
+
socket.destroy();
|
|
80
|
+
resolve(result);
|
|
81
|
+
};
|
|
82
|
+
socket.setTimeout(timeoutMs);
|
|
83
|
+
socket.once('error', () => finalize(false));
|
|
84
|
+
socket.once('timeout', () => finalize(false));
|
|
85
|
+
socket.connect(port, host, () => finalize(true));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function waitForPort(host, port, child, timeoutMs) {
|
|
89
|
+
const start = Date.now();
|
|
90
|
+
while (Date.now() - start < timeoutMs) {
|
|
91
|
+
if (await isPortOpen(host, port))
|
|
92
|
+
return true;
|
|
93
|
+
if (child?.exitCode !== null)
|
|
94
|
+
return false;
|
|
95
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
96
|
+
}
|
|
97
|
+
return isPortOpen(host, port);
|
|
98
|
+
}
|
|
99
|
+
function registerCleanup(state) {
|
|
100
|
+
if (state.cleanupRegistered)
|
|
101
|
+
return;
|
|
102
|
+
state.cleanupRegistered = true;
|
|
103
|
+
process.on('exit', () => {
|
|
104
|
+
state.child?.kill('SIGTERM');
|
|
105
|
+
});
|
|
106
|
+
process.on('SIGINT', () => {
|
|
107
|
+
state.child?.kill('SIGTERM');
|
|
108
|
+
process.exit(0);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async function startHost(options, state) {
|
|
112
|
+
const cliPath = resolveCliEntry(options.appPath, options.cliPackage);
|
|
113
|
+
const args = [
|
|
114
|
+
cliPath,
|
|
115
|
+
'dev',
|
|
116
|
+
'--host',
|
|
117
|
+
options.host,
|
|
118
|
+
'--port',
|
|
119
|
+
String(options.port),
|
|
120
|
+
'--app',
|
|
121
|
+
options.appPath,
|
|
122
|
+
];
|
|
123
|
+
const runtime = resolveRuntime(options.runtime);
|
|
124
|
+
if (options.debug) {
|
|
125
|
+
console.info('[AgentConnect][Host] starting', { runtime, args });
|
|
126
|
+
}
|
|
127
|
+
const child = spawn(runtime, args, { stdio: options.debug ? 'pipe' : 'ignore' });
|
|
128
|
+
state.child = child;
|
|
129
|
+
state.status = 'starting';
|
|
130
|
+
registerCleanup(state);
|
|
131
|
+
if (options.debug) {
|
|
132
|
+
child.stdout?.on('data', (chunk) => {
|
|
133
|
+
console.info('[AgentConnect][Host]', String(chunk).trim());
|
|
134
|
+
});
|
|
135
|
+
child.stderr?.on('data', (chunk) => {
|
|
136
|
+
console.error('[AgentConnect][Host]', String(chunk).trim());
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
child.on('error', (error) => {
|
|
140
|
+
if (options.debug) {
|
|
141
|
+
console.error('[AgentConnect][Host] spawn error', error);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
child.on('exit', () => {
|
|
145
|
+
if (state.child === child) {
|
|
146
|
+
state.status = 'idle';
|
|
147
|
+
state.child = undefined;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const started = await waitForPort(options.host, options.port, child, options.timeoutMs);
|
|
151
|
+
if (!started) {
|
|
152
|
+
child.kill('SIGTERM');
|
|
153
|
+
throw new Error('AgentConnect host failed to start. Ensure Node.js 20+ is installed.');
|
|
154
|
+
}
|
|
155
|
+
state.status = 'running';
|
|
156
|
+
}
|
|
157
|
+
export async function ensureAgentConnectHost(options = {}) {
|
|
158
|
+
const state = getState();
|
|
159
|
+
const resolvedOptions = {
|
|
160
|
+
host: options.host || process.env.AGENTCONNECT_HOST || '127.0.0.1',
|
|
161
|
+
port: options.port || Number(process.env.AGENTCONNECT_PORT || 9630),
|
|
162
|
+
appPath: options.appPath || process.env.AGENTCONNECT_APP_PATH || process.cwd(),
|
|
163
|
+
cliPackage: options.cliPackage || process.env.AGENTCONNECT_CLI_PACKAGE || '@agentconnect/cli',
|
|
164
|
+
runtime: options.runtime || '',
|
|
165
|
+
timeoutMs: options.timeoutMs || 8000,
|
|
166
|
+
debug: options.debug ?? process.env.AGENTCONNECT_DEBUG === '1',
|
|
167
|
+
};
|
|
168
|
+
if (await isPortOpen(resolvedOptions.host, resolvedOptions.port)) {
|
|
169
|
+
state.status = 'running';
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (state.startPromise)
|
|
173
|
+
return state.startPromise;
|
|
174
|
+
state.startPromise = startHost(resolvedOptions, state)
|
|
175
|
+
.catch((error) => {
|
|
176
|
+
state.status = 'idle';
|
|
177
|
+
state.child = undefined;
|
|
178
|
+
throw error;
|
|
179
|
+
})
|
|
180
|
+
.finally(() => {
|
|
181
|
+
state.startPromise = undefined;
|
|
182
|
+
});
|
|
183
|
+
return state.startPromise;
|
|
184
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ProviderId = 'claude' | 'codex' | 'local';
|
|
1
|
+
export type ProviderId = 'claude' | 'codex' | 'cursor' | 'local';
|
|
2
2
|
export type PackageManager = 'bun' | 'pnpm' | 'npm' | 'brew' | 'unknown';
|
|
3
3
|
export type InstallResult = {
|
|
4
4
|
installed: boolean;
|
|
@@ -11,6 +11,13 @@ export type ProviderInfo = {
|
|
|
11
11
|
installed: boolean;
|
|
12
12
|
loggedIn: boolean;
|
|
13
13
|
version?: string;
|
|
14
|
+
updateAvailable?: boolean;
|
|
15
|
+
latestVersion?: string;
|
|
16
|
+
updateCheckedAt?: number;
|
|
17
|
+
updateSource?: 'cli' | 'npm' | 'bun' | 'brew' | 'winget' | 'script' | 'unknown';
|
|
18
|
+
updateCommand?: string;
|
|
19
|
+
updateMessage?: string;
|
|
20
|
+
updateInProgress?: boolean;
|
|
14
21
|
};
|
|
15
22
|
export type ReasoningEffortOption = {
|
|
16
23
|
id: string;
|
|
@@ -25,30 +32,74 @@ export type ModelInfo = {
|
|
|
25
32
|
reasoningEfforts?: ReasoningEffortOption[];
|
|
26
33
|
defaultReasoningEffort?: string;
|
|
27
34
|
};
|
|
35
|
+
export type ProviderDetailLevel = 'minimal' | 'raw';
|
|
36
|
+
export type ProviderDetail = {
|
|
37
|
+
eventType: string;
|
|
38
|
+
data?: Record<string, unknown>;
|
|
39
|
+
raw?: unknown;
|
|
40
|
+
};
|
|
28
41
|
export type SessionEvent = {
|
|
29
42
|
type: 'delta';
|
|
30
43
|
text: string;
|
|
44
|
+
providerSessionId?: string | null;
|
|
45
|
+
providerDetail?: ProviderDetail;
|
|
31
46
|
} | {
|
|
32
47
|
type: 'final';
|
|
33
48
|
text: string;
|
|
34
49
|
providerSessionId?: string | null;
|
|
50
|
+
providerDetail?: ProviderDetail;
|
|
35
51
|
} | {
|
|
36
52
|
type: 'usage';
|
|
37
53
|
usage: Record<string, number>;
|
|
54
|
+
providerSessionId?: string | null;
|
|
55
|
+
providerDetail?: ProviderDetail;
|
|
38
56
|
} | {
|
|
39
57
|
type: 'status';
|
|
40
58
|
status: 'thinking' | 'idle' | 'error';
|
|
41
59
|
error?: string;
|
|
60
|
+
providerSessionId?: string | null;
|
|
61
|
+
providerDetail?: ProviderDetail;
|
|
42
62
|
} | {
|
|
43
63
|
type: 'error';
|
|
44
64
|
message: string;
|
|
65
|
+
providerSessionId?: string | null;
|
|
66
|
+
providerDetail?: ProviderDetail;
|
|
45
67
|
} | {
|
|
46
68
|
type: 'raw_line';
|
|
47
69
|
line: string;
|
|
70
|
+
providerSessionId?: string | null;
|
|
71
|
+
providerDetail?: ProviderDetail;
|
|
72
|
+
} | {
|
|
73
|
+
type: 'message';
|
|
74
|
+
provider?: ProviderId;
|
|
75
|
+
role: 'system' | 'user' | 'assistant';
|
|
76
|
+
content: string;
|
|
77
|
+
contentParts?: unknown;
|
|
78
|
+
providerSessionId?: string | null;
|
|
79
|
+
providerDetail?: ProviderDetail;
|
|
48
80
|
} | {
|
|
49
|
-
type: '
|
|
81
|
+
type: 'thinking';
|
|
50
82
|
provider?: ProviderId;
|
|
51
|
-
|
|
83
|
+
phase: 'delta' | 'start' | 'completed' | 'error';
|
|
84
|
+
text?: string;
|
|
85
|
+
timestampMs?: number;
|
|
86
|
+
providerSessionId?: string | null;
|
|
87
|
+
providerDetail?: ProviderDetail;
|
|
88
|
+
} | {
|
|
89
|
+
type: 'tool_call';
|
|
90
|
+
provider?: ProviderId;
|
|
91
|
+
name?: string;
|
|
92
|
+
callId?: string;
|
|
93
|
+
input?: unknown;
|
|
94
|
+
output?: unknown;
|
|
95
|
+
phase?: 'delta' | 'start' | 'completed' | 'error';
|
|
96
|
+
providerSessionId?: string | null;
|
|
97
|
+
providerDetail?: ProviderDetail;
|
|
98
|
+
} | {
|
|
99
|
+
type: 'detail';
|
|
100
|
+
provider?: ProviderId;
|
|
101
|
+
providerSessionId?: string | null;
|
|
102
|
+
providerDetail: ProviderDetail;
|
|
52
103
|
};
|
|
53
104
|
export type ProviderLoginOptions = {
|
|
54
105
|
baseUrl?: string;
|
|
@@ -74,11 +125,13 @@ export type SessionCreateOptions = {
|
|
|
74
125
|
temperature?: number;
|
|
75
126
|
maxTokens?: number;
|
|
76
127
|
topP?: number;
|
|
128
|
+
providerDetailLevel?: ProviderDetailLevel;
|
|
77
129
|
};
|
|
78
130
|
export type SessionSendOptions = {
|
|
79
131
|
metadata?: Record<string, unknown>;
|
|
80
132
|
cwd?: string;
|
|
81
133
|
repoRoot?: string;
|
|
134
|
+
providerDetailLevel?: ProviderDetailLevel;
|
|
82
135
|
};
|
|
83
136
|
export type SessionResumeOptions = {
|
|
84
137
|
model?: string;
|
|
@@ -86,6 +139,7 @@ export type SessionResumeOptions = {
|
|
|
86
139
|
providerSessionId?: string | null;
|
|
87
140
|
cwd?: string;
|
|
88
141
|
repoRoot?: string;
|
|
142
|
+
providerDetailLevel?: ProviderDetailLevel;
|
|
89
143
|
};
|
|
90
144
|
export interface AgentConnectSession {
|
|
91
145
|
id: string;
|
|
@@ -111,6 +165,7 @@ export interface AgentConnectClient {
|
|
|
111
165
|
list(): Promise<ProviderInfo[]>;
|
|
112
166
|
status(provider: ProviderId): Promise<ProviderInfo>;
|
|
113
167
|
ensureInstalled(provider: ProviderId): Promise<InstallResult>;
|
|
168
|
+
update(provider: ProviderId): Promise<ProviderInfo>;
|
|
114
169
|
login(provider: ProviderId, options?: ProviderLoginOptions): Promise<{
|
|
115
170
|
loggedIn: boolean;
|
|
116
171
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -161,6 +161,7 @@ class AgentConnectSessionImpl {
|
|
|
161
161
|
metadata: normalized.metadata,
|
|
162
162
|
cwd: normalized.cwd,
|
|
163
163
|
repoRoot: normalized.repoRoot,
|
|
164
|
+
providerDetailLevel: normalized.providerDetailLevel,
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
167
|
async cancel() {
|
|
@@ -199,7 +200,8 @@ class AgentConnectSessionImpl {
|
|
|
199
200
|
const candidate = options;
|
|
200
201
|
if ('metadata' in candidate ||
|
|
201
202
|
'cwd' in candidate ||
|
|
202
|
-
'repoRoot' in candidate
|
|
203
|
+
'repoRoot' in candidate ||
|
|
204
|
+
'providerDetailLevel' in candidate) {
|
|
203
205
|
return candidate;
|
|
204
206
|
}
|
|
205
207
|
return { metadata: options };
|
|
@@ -228,8 +230,34 @@ class AgentConnectClientImpl {
|
|
|
228
230
|
});
|
|
229
231
|
}
|
|
230
232
|
normalizeEvent(type, data) {
|
|
233
|
+
const parseProviderDetail = () => {
|
|
234
|
+
const detail = data?.providerDetail;
|
|
235
|
+
if (!detail || typeof detail !== 'object')
|
|
236
|
+
return undefined;
|
|
237
|
+
const record = detail;
|
|
238
|
+
const eventType = typeof record.eventType === 'string' ? record.eventType : '';
|
|
239
|
+
if (!eventType)
|
|
240
|
+
return undefined;
|
|
241
|
+
const raw = 'raw' in record ? record.raw : undefined;
|
|
242
|
+
const dataField = record.data && typeof record.data === 'object'
|
|
243
|
+
? record.data
|
|
244
|
+
: undefined;
|
|
245
|
+
const out = { eventType };
|
|
246
|
+
if (dataField)
|
|
247
|
+
out.data = dataField;
|
|
248
|
+
if (raw !== undefined)
|
|
249
|
+
out.raw = raw;
|
|
250
|
+
return out;
|
|
251
|
+
};
|
|
252
|
+
const providerDetail = parseProviderDetail();
|
|
253
|
+
const providerSessionId = typeof data?.providerSessionId === 'string' ? data.providerSessionId : undefined;
|
|
231
254
|
if (type === 'delta') {
|
|
232
|
-
return {
|
|
255
|
+
return {
|
|
256
|
+
type: 'delta',
|
|
257
|
+
text: String(data?.text ?? ''),
|
|
258
|
+
providerSessionId,
|
|
259
|
+
...(providerDetail && { providerDetail }),
|
|
260
|
+
};
|
|
233
261
|
}
|
|
234
262
|
if (type === 'final') {
|
|
235
263
|
const providerSessionId = typeof data?.providerSessionId === 'string'
|
|
@@ -237,28 +265,110 @@ class AgentConnectClientImpl {
|
|
|
237
265
|
: typeof data?.sessionId === 'string'
|
|
238
266
|
? data.sessionId
|
|
239
267
|
: undefined;
|
|
240
|
-
return {
|
|
268
|
+
return {
|
|
269
|
+
type: 'final',
|
|
270
|
+
text: String(data?.text ?? ''),
|
|
271
|
+
providerSessionId,
|
|
272
|
+
...(providerDetail && { providerDetail }),
|
|
273
|
+
};
|
|
241
274
|
}
|
|
242
275
|
if (type === 'usage') {
|
|
243
|
-
return {
|
|
276
|
+
return {
|
|
277
|
+
type: 'usage',
|
|
278
|
+
usage: data?.usage ?? {},
|
|
279
|
+
providerSessionId,
|
|
280
|
+
...(providerDetail && { providerDetail }),
|
|
281
|
+
};
|
|
244
282
|
}
|
|
245
283
|
if (type === 'status') {
|
|
246
284
|
const status = String(data?.status ?? 'idle');
|
|
247
285
|
const error = typeof data?.error === 'string' ? data.error : undefined;
|
|
248
|
-
return {
|
|
286
|
+
return {
|
|
287
|
+
type: 'status',
|
|
288
|
+
status,
|
|
289
|
+
error,
|
|
290
|
+
providerSessionId,
|
|
291
|
+
...(providerDetail && { providerDetail }),
|
|
292
|
+
};
|
|
249
293
|
}
|
|
250
294
|
if (type === 'error') {
|
|
251
|
-
return {
|
|
295
|
+
return {
|
|
296
|
+
type: 'error',
|
|
297
|
+
message: String(data?.message ?? 'Unknown error'),
|
|
298
|
+
providerSessionId,
|
|
299
|
+
...(providerDetail && { providerDetail }),
|
|
300
|
+
};
|
|
252
301
|
}
|
|
253
302
|
if (type === 'raw_line') {
|
|
254
|
-
return {
|
|
303
|
+
return {
|
|
304
|
+
type: 'raw_line',
|
|
305
|
+
line: String(data?.line ?? ''),
|
|
306
|
+
providerSessionId,
|
|
307
|
+
...(providerDetail && { providerDetail }),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
if (type === 'message') {
|
|
311
|
+
const provider = typeof data?.provider === 'string' ? data.provider : undefined;
|
|
312
|
+
const role = data?.role === 'system' || data?.role === 'user' || data?.role === 'assistant'
|
|
313
|
+
? data.role
|
|
314
|
+
: 'assistant';
|
|
315
|
+
const content = String(data?.content ?? '');
|
|
316
|
+
const contentParts = data?.contentParts;
|
|
317
|
+
return {
|
|
318
|
+
type: 'message',
|
|
319
|
+
provider,
|
|
320
|
+
role,
|
|
321
|
+
content,
|
|
322
|
+
contentParts,
|
|
323
|
+
providerSessionId,
|
|
324
|
+
providerDetail,
|
|
325
|
+
};
|
|
255
326
|
}
|
|
256
|
-
if (type === '
|
|
327
|
+
if (type === 'thinking') {
|
|
257
328
|
const provider = typeof data?.provider === 'string' ? data.provider : undefined;
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
329
|
+
const phase = data?.phase === 'start' ||
|
|
330
|
+
data?.phase === 'completed' ||
|
|
331
|
+
data?.phase === 'error' ||
|
|
332
|
+
data?.phase === 'delta'
|
|
333
|
+
? data.phase
|
|
334
|
+
: 'delta';
|
|
335
|
+
const text = typeof data?.text === 'string' ? data.text : undefined;
|
|
336
|
+
const timestampMs = typeof data?.timestampMs === 'number' ? data.timestampMs : undefined;
|
|
337
|
+
return {
|
|
338
|
+
type: 'thinking',
|
|
339
|
+
provider,
|
|
340
|
+
phase,
|
|
341
|
+
text,
|
|
342
|
+
timestampMs,
|
|
343
|
+
providerSessionId,
|
|
344
|
+
providerDetail,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if (type === 'tool_call') {
|
|
348
|
+
const provider = typeof data?.provider === 'string' ? data.provider : undefined;
|
|
349
|
+
const name = typeof data?.name === 'string' ? data.name : undefined;
|
|
350
|
+
const callId = typeof data?.callId === 'string' ? data.callId : undefined;
|
|
351
|
+
const phase = data?.phase === 'start' ||
|
|
352
|
+
data?.phase === 'completed' ||
|
|
353
|
+
data?.phase === 'error' ||
|
|
354
|
+
data?.phase === 'delta'
|
|
355
|
+
? data.phase
|
|
356
|
+
: undefined;
|
|
357
|
+
return {
|
|
358
|
+
type: 'tool_call',
|
|
359
|
+
provider,
|
|
360
|
+
name,
|
|
361
|
+
callId,
|
|
362
|
+
input: data?.input,
|
|
363
|
+
output: data?.output,
|
|
364
|
+
phase,
|
|
365
|
+
providerSessionId,
|
|
366
|
+
providerDetail,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
if (type === 'detail' && providerDetail) {
|
|
370
|
+
const provider = typeof data?.provider === 'string' ? data.provider : undefined;
|
|
371
|
+
return { type: 'detail', provider, providerDetail, providerSessionId };
|
|
262
372
|
}
|
|
263
373
|
return null;
|
|
264
374
|
}
|
|
@@ -280,6 +390,10 @@ class AgentConnectClientImpl {
|
|
|
280
390
|
const res = (await this.request('acp.providers.status', { provider }));
|
|
281
391
|
return res.provider;
|
|
282
392
|
},
|
|
393
|
+
update: async (provider) => {
|
|
394
|
+
const res = (await this.request('acp.providers.update', { provider }));
|
|
395
|
+
return res.provider;
|
|
396
|
+
},
|
|
283
397
|
ensureInstalled: async (provider) => {
|
|
284
398
|
return (await this.request('acp.providers.ensureInstalled', { provider }));
|
|
285
399
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentconnect/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/rayzhudev/agent-connect",
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
21
|
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./host": {
|
|
24
|
+
"import": "./dist/host.js",
|
|
25
|
+
"types": "./dist/host.d.ts",
|
|
26
|
+
"default": "./dist/host.js"
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
29
|
"files": [
|
|
@@ -29,6 +34,7 @@
|
|
|
29
34
|
"dev": "tsc --watch"
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
37
|
+
"@types/node": "^20.0.0",
|
|
32
38
|
"typescript": "^5.6.2"
|
|
33
39
|
},
|
|
34
40
|
"engines": {
|