quick-acp 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +405 -2
- package/dist/acp/agent.js +371 -0
- package/dist/acp-smoke.js +163 -0
- package/dist/concurrent-test.js +101 -0
- package/dist/doctor.js +86 -0
- package/dist/e2e.js +206 -0
- package/dist/fresh-machine-e2e.js +151 -0
- package/dist/inject-turn-test.js +119 -0
- package/dist/login-cli.js +86 -0
- package/dist/main.js +77 -0
- package/dist/no-outpost-e2e.js +86 -0
- package/dist/probe.js +308 -0
- package/dist/quick/auth.js +371 -0
- package/dist/quick/codec.js +499 -0
- package/dist/quick/credstore.js +439 -0
- package/dist/quick/gateway-contract.js +104 -0
- package/dist/quick/login.js +522 -0
- package/dist/quick/oidc.js +152 -0
- package/dist/quick/session-direct.js +200 -0
- package/dist/quick/session.js +385 -0
- package/dist/quick/transport.js +343 -0
- package/dist/tools/registry.js +411 -0
- package/dist/tools/strategies.js +188 -0
- package/dist/wss-smoke.js +230 -0
- package/package.json +53 -4
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Credential and session diagnostic.
|
|
4
|
+
*
|
|
5
|
+
* Answers, without revealing any secret:
|
|
6
|
+
* - which Quick profile is active
|
|
7
|
+
* - whether the stored login is readable from the OS credential store
|
|
8
|
+
* - whether an OIDC refresh actually produces a JWT
|
|
9
|
+
* - what the gateway host would be
|
|
10
|
+
*
|
|
11
|
+
* Run: node dist/doctor.js (add --refresh to actually mint a token)
|
|
12
|
+
*/
|
|
13
|
+
import { describeCredentialState, resolveSession, startOutpost, DEFAULT_WS_PATH, } from './quick/auth.js';
|
|
14
|
+
async function main() {
|
|
15
|
+
const doRefresh = process.argv.includes('--refresh');
|
|
16
|
+
const doJson = process.argv.includes('--json');
|
|
17
|
+
const doStart = process.argv.includes('--start-outpost');
|
|
18
|
+
if (doStart) {
|
|
19
|
+
console.log('[outpost] starting the app\'s own outpost so it refreshes the login…');
|
|
20
|
+
const r = await startOutpost();
|
|
21
|
+
if (!r.started) {
|
|
22
|
+
console.error(`[outpost] FAILED: ${r.reason}`);
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
console.log(`[outpost] up. instance token: ${r.instanceToken ? 'acquired' : 'not available'}`);
|
|
27
|
+
if (r.reason)
|
|
28
|
+
console.log(`[outpost] ${r.reason}`);
|
|
29
|
+
}
|
|
30
|
+
const state = await describeCredentialState();
|
|
31
|
+
if (doJson) {
|
|
32
|
+
console.log(JSON.stringify(state, null, 2));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log('quick-acp doctor');
|
|
36
|
+
console.log('');
|
|
37
|
+
console.log(' platform ', state['platform']);
|
|
38
|
+
console.log(' quickwork home ', state['quickworkHome']);
|
|
39
|
+
console.log(' active profile ', state['activeProfile'] ?? '(none)');
|
|
40
|
+
console.log(' outpost port ', state['outpostPort']);
|
|
41
|
+
console.log(' outpost running ', state['outpostUp'] ? 'yes' : 'no');
|
|
42
|
+
console.log(' agent binary ', state['agentBinary'] ?? '(not found)');
|
|
43
|
+
console.log(' instance token ', state['hasInstanceTokenEnv'] ? 'set' : 'not set');
|
|
44
|
+
const sl = state['storedLogin'];
|
|
45
|
+
console.log('');
|
|
46
|
+
console.log(' stored login ', sl['ok'] ? 'READABLE' : 'NOT READABLE');
|
|
47
|
+
if (sl['ok']) {
|
|
48
|
+
console.log(' source ', sl['source']);
|
|
49
|
+
console.log(' refresh token ', sl['hasRefreshToken'] ? 'present' : 'MISSING');
|
|
50
|
+
console.log(' client id ', sl['hasClientId'] ? 'present' : 'MISSING');
|
|
51
|
+
console.log(' client secret ', sl['hasClientSecret'] ? 'present' : 'MISSING');
|
|
52
|
+
console.log(' tenant ', sl['tenant'] ?? '(none)');
|
|
53
|
+
console.log(' access token ', sl['accessTokenExpired'] ? `EXPIRED at ${sl['accessTokenExpiry']}` : 'valid');
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.log(' reason ', sl['reason']);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!doRefresh) {
|
|
60
|
+
console.log('');
|
|
61
|
+
console.log('Options:');
|
|
62
|
+
console.log(' --start-outpost start the app\'s outpost so it refreshes the token');
|
|
63
|
+
console.log(' --refresh resolve a full session (needs a running outpost)');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
console.log('');
|
|
67
|
+
console.log('[session] resolving full session…');
|
|
68
|
+
try {
|
|
69
|
+
const s = await resolveSession({ force: true });
|
|
70
|
+
console.log('[session] SUCCESS');
|
|
71
|
+
console.log(' source ', s.source);
|
|
72
|
+
console.log(' ws host ', s.wsHost);
|
|
73
|
+
console.log(' ws path ', s.wsPath || DEFAULT_WS_PATH);
|
|
74
|
+
console.log(' tenant ', s.tenantUrl);
|
|
75
|
+
console.log(' surface ', s.surface);
|
|
76
|
+
console.log(' outpost id ', s.outpostId || '(empty — server will decide)');
|
|
77
|
+
console.log(' actor arn ', s.actorArn || '(none)');
|
|
78
|
+
console.log(' expires ', s.expiresAt ? new Date(s.expiresAt).toISOString() : '(unknown)');
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
console.error(`[session] FAILED: ${e instanceof Error ? e.message : String(e)}`);
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
void main();
|
|
86
|
+
//# sourceMappingURL=doctor.js.map
|
package/dist/e2e.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* End-to-end test: ACP prompt -> Quick gateway -> model -> ACP chunks.
|
|
4
|
+
*
|
|
5
|
+
* Drives the REAL agent over stdio exactly as an ACP client would, and asserts
|
|
6
|
+
* that assistant text comes back. This is the test that proves the bridge works,
|
|
7
|
+
* not just that its parts do.
|
|
8
|
+
*
|
|
9
|
+
* Requires a Quick login (uses the outpost to refresh). Not part of `verify`.
|
|
10
|
+
*
|
|
11
|
+
* node dist/e2e.js
|
|
12
|
+
* node dist/e2e.js "your prompt"
|
|
13
|
+
*/
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { dirname, join } from 'node:path';
|
|
17
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const agentPath = join(here, 'main.js');
|
|
19
|
+
const promptArg = process.argv.slice(2).find((a) => !a.startsWith('--'));
|
|
20
|
+
let nextId = 1;
|
|
21
|
+
const pending = new Map();
|
|
22
|
+
const notifications = [];
|
|
23
|
+
function send(child, method, params) {
|
|
24
|
+
const id = nextId++;
|
|
25
|
+
child.stdin?.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
pending.set(id, resolve);
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
if (!pending.has(id))
|
|
30
|
+
return;
|
|
31
|
+
pending.delete(id);
|
|
32
|
+
reject(new Error(`timeout waiting for ${method}`));
|
|
33
|
+
}, 300_000);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function notify(child, method, params) {
|
|
37
|
+
child.stdin?.write(`${JSON.stringify({ jsonrpc: '2.0', method, params })}\n`);
|
|
38
|
+
}
|
|
39
|
+
async function main() {
|
|
40
|
+
console.log('quick-acp end-to-end test');
|
|
41
|
+
console.log('');
|
|
42
|
+
const child = spawn(process.execPath, [agentPath], {
|
|
43
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
44
|
+
env: {
|
|
45
|
+
...process.env,
|
|
46
|
+
QUICK_ACP_WORKSPACE: process.cwd(),
|
|
47
|
+
QUICK_ACP_ALLOW_SHELL: '1',
|
|
48
|
+
QUICK_ACP_DEBUG: process.env.QUICK_ACP_DEBUG ?? '1',
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
child.stderr?.on('data', (c) => {
|
|
52
|
+
const text = c.toString('utf8').trimEnd();
|
|
53
|
+
if (text)
|
|
54
|
+
console.log(` [agent] ${text}`);
|
|
55
|
+
});
|
|
56
|
+
let buffer = '';
|
|
57
|
+
child.stdout?.on('data', (chunk) => {
|
|
58
|
+
buffer += chunk.toString('utf8');
|
|
59
|
+
let i;
|
|
60
|
+
while ((i = buffer.indexOf('\n')) >= 0) {
|
|
61
|
+
const line = buffer.slice(0, i).trim();
|
|
62
|
+
buffer = buffer.slice(i + 1);
|
|
63
|
+
if (!line)
|
|
64
|
+
continue;
|
|
65
|
+
let msg;
|
|
66
|
+
try {
|
|
67
|
+
msg = JSON.parse(line);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
console.log(' (non-JSON stdout:', line.slice(0, 100), ')');
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (typeof msg.id === 'number' && pending.has(msg.id)) {
|
|
74
|
+
const r = pending.get(msg.id);
|
|
75
|
+
pending.delete(msg.id);
|
|
76
|
+
r(msg);
|
|
77
|
+
}
|
|
78
|
+
else if (msg.method) {
|
|
79
|
+
notifications.push(msg);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
let failures = 0;
|
|
84
|
+
const step = async (name, fn) => {
|
|
85
|
+
try {
|
|
86
|
+
await fn();
|
|
87
|
+
console.log(` ok ${name}`);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
failures++;
|
|
92
|
+
console.log(` FAIL ${name}`);
|
|
93
|
+
console.log(` ${e instanceof Error ? e.message : String(e)}`);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
// 1. initialize
|
|
98
|
+
const inited = await step('initialize', async () => {
|
|
99
|
+
const r = await send(child, 'initialize', {
|
|
100
|
+
protocolVersion: 1,
|
|
101
|
+
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false } },
|
|
102
|
+
});
|
|
103
|
+
if (r.error)
|
|
104
|
+
throw new Error(JSON.stringify(r.error));
|
|
105
|
+
if (!r.result?.['agentCapabilities'])
|
|
106
|
+
throw new Error('no capabilities');
|
|
107
|
+
});
|
|
108
|
+
if (!inited) {
|
|
109
|
+
child.kill();
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// 2. newSession — this opens the real gateway socket
|
|
114
|
+
let sessionId = '';
|
|
115
|
+
const created = await step('session/new (opens the gateway)', async () => {
|
|
116
|
+
const r = await send(child, 'session/new', { cwd: process.cwd(), mcpServers: [] });
|
|
117
|
+
if (r.error)
|
|
118
|
+
throw new Error(`error: ${r.error.message}`);
|
|
119
|
+
const id = r.result?.['sessionId'];
|
|
120
|
+
if (typeof id !== 'string' || !id)
|
|
121
|
+
throw new Error('no sessionId returned');
|
|
122
|
+
sessionId = id;
|
|
123
|
+
});
|
|
124
|
+
if (!created) {
|
|
125
|
+
child.kill();
|
|
126
|
+
process.exitCode = 1;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// 3. prompt — the real turn
|
|
130
|
+
const prompt = promptArg ?? 'Reply with exactly the single word: PONG. No tools, no punctuation.';
|
|
131
|
+
let assistantText = '';
|
|
132
|
+
let usage = '';
|
|
133
|
+
console.log('');
|
|
134
|
+
console.log(` > prompt: ${prompt}`);
|
|
135
|
+
const replied = await step('session/prompt returns assistant text', async () => {
|
|
136
|
+
// Collect notifications concurrently with the request.
|
|
137
|
+
const collector = setInterval(() => {
|
|
138
|
+
for (const n of notifications.splice(0)) {
|
|
139
|
+
const p = n.params;
|
|
140
|
+
const update = p?.['update'];
|
|
141
|
+
if (update?.['sessionUpdate'] === 'agent_message_chunk') {
|
|
142
|
+
const content = update['content'];
|
|
143
|
+
if (typeof content?.['text'] === 'string')
|
|
144
|
+
assistantText += content['text'];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, 100);
|
|
148
|
+
try {
|
|
149
|
+
const r = await send(child, 'session/prompt', {
|
|
150
|
+
sessionId,
|
|
151
|
+
prompt: [{ type: 'text', text: prompt }],
|
|
152
|
+
});
|
|
153
|
+
if (r.error)
|
|
154
|
+
throw new Error(`error: ${r.error.message}`);
|
|
155
|
+
const stop = r.result?.['stopReason'];
|
|
156
|
+
if (stop === 'cancelled')
|
|
157
|
+
throw new Error('turn was cancelled');
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
clearInterval(collector);
|
|
161
|
+
// Drain any remaining notifications.
|
|
162
|
+
for (const n of notifications.splice(0)) {
|
|
163
|
+
const p = n.params;
|
|
164
|
+
const update = p?.['update'];
|
|
165
|
+
if (update?.['sessionUpdate'] === 'agent_message_chunk') {
|
|
166
|
+
const content = update['content'];
|
|
167
|
+
if (typeof content?.['text'] === 'string')
|
|
168
|
+
assistantText += content['text'];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
console.log('');
|
|
174
|
+
console.log(' assistant text:', assistantText ? JSON.stringify(assistantText) : '(empty)');
|
|
175
|
+
if (usage)
|
|
176
|
+
console.log(' usage:', usage);
|
|
177
|
+
if (replied && assistantText.trim().length > 0) {
|
|
178
|
+
console.log('');
|
|
179
|
+
console.log('*** END-TO-END SUCCESS ***');
|
|
180
|
+
console.log('*** ACP client -> quick-acp -> Quick gateway -> model -> ACP chunks ***');
|
|
181
|
+
}
|
|
182
|
+
else if (replied) {
|
|
183
|
+
console.log('');
|
|
184
|
+
console.log('Turn completed but no assistant text arrived.');
|
|
185
|
+
failures++;
|
|
186
|
+
process.exitCode = 1;
|
|
187
|
+
}
|
|
188
|
+
// 4. cancel path must not throw
|
|
189
|
+
await step('session/cancel is accepted', async () => {
|
|
190
|
+
notify(child, 'session/cancel', { sessionId });
|
|
191
|
+
});
|
|
192
|
+
child.kill();
|
|
193
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
194
|
+
console.log('');
|
|
195
|
+
if (failures === 0)
|
|
196
|
+
console.log('all e2e steps passed');
|
|
197
|
+
else {
|
|
198
|
+
console.log(`${failures} step(s) FAILED`);
|
|
199
|
+
process.exitCode = 1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
void main().catch((e) => {
|
|
203
|
+
console.error('fatal:', e instanceof Error ? (e.stack ?? e.message) : String(e));
|
|
204
|
+
process.exit(1);
|
|
205
|
+
});
|
|
206
|
+
//# sourceMappingURL=e2e.js.map
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Final proof for the "no official client" story, in one command.
|
|
3
|
+
*
|
|
4
|
+
* 1. sign in through the browser (OAuth + PKCE, no desktop app)
|
|
5
|
+
* 2. write ~/.quick-acp/login.json
|
|
6
|
+
* 3. build a session from that file alone (no outpost, no keychain)
|
|
7
|
+
* 4. run a real turn and print the model
|
|
8
|
+
*
|
|
9
|
+
* This is what a brand-new machine does.
|
|
10
|
+
*
|
|
11
|
+
* node dist/fresh-machine-e2e.js --start-url https://ssoins-xxx.awsapps.com/start
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync } from 'node:fs';
|
|
14
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { homedir } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { login, bridgeLoginPath } from './quick/login.js';
|
|
18
|
+
import { sessionDirect } from './quick/session-direct.js';
|
|
19
|
+
import { QuickTransport } from './quick/transport.js';
|
|
20
|
+
import { QuickChatSession } from './quick/session.js';
|
|
21
|
+
const START = process.argv.slice(2).find((a) => a.startsWith('http')) ??
|
|
22
|
+
process.env.QUICK_ACP_START_URL ??
|
|
23
|
+
'';
|
|
24
|
+
if (!START) {
|
|
25
|
+
console.error('usage: node dist/fresh-machine-e2e.js --start-url <your AWS access portal URL>');
|
|
26
|
+
console.error('');
|
|
27
|
+
console.error(' Get that URL by signing in at https://quicksight.aws.amazon.com — the browser');
|
|
28
|
+
console.error(' lands on an address like https://ssoins-xxxxxxxxxxxx.awsapps.com/start');
|
|
29
|
+
console.error(' (or set QUICK_ACP_START_URL).');
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
console.log('quick-acp: fresh-machine end-to-end test');
|
|
33
|
+
console.log('');
|
|
34
|
+
console.log('This simulates a machine with NO Quick install:');
|
|
35
|
+
console.log(' - no desktop app login');
|
|
36
|
+
console.log(' - no outpost');
|
|
37
|
+
console.log(' - only a browser sign-in');
|
|
38
|
+
console.log('');
|
|
39
|
+
console.log('=== step 1: browser sign-in ===');
|
|
40
|
+
const result = await login({
|
|
41
|
+
startUrl: START,
|
|
42
|
+
persist: false,
|
|
43
|
+
onUrl: (u) => {
|
|
44
|
+
console.log('');
|
|
45
|
+
console.log('*** OPEN THIS URL AND SIGN IN ***');
|
|
46
|
+
console.log(u);
|
|
47
|
+
console.log('');
|
|
48
|
+
console.log('waiting for the callback on http://127.0.0.1:18080 ...');
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
if (!result.ok) {
|
|
52
|
+
console.error('');
|
|
53
|
+
console.error('sign-in failed:', result.error);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
console.log('');
|
|
57
|
+
console.log('signed in');
|
|
58
|
+
console.log(' client id :', result.clientId);
|
|
59
|
+
console.log(' access tok :', result.accessToken?.slice(0, 24) + '...');
|
|
60
|
+
console.log(' refresh tok:', result.refreshToken?.slice(0, 24) + '...');
|
|
61
|
+
// Write the bridge login file. tenant_url comes from discovery; if it is empty
|
|
62
|
+
// the caller must supply it, so say so instead of writing a half-usable file.
|
|
63
|
+
if (!result.tenantUrl) {
|
|
64
|
+
console.error('');
|
|
65
|
+
console.error('signed in, but the gateway host (tenant_url) could not be discovered.');
|
|
66
|
+
console.error('Provide it explicitly: set QUICK_ACP_TENANT_URL=https://qbs-....plato.ai.aws.dev');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
console.log(' tenant :', result.tenantUrl);
|
|
70
|
+
const dir = join(homedir(), '.quick-acp');
|
|
71
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
72
|
+
const p = bridgeLoginPath();
|
|
73
|
+
await writeFile(p, JSON.stringify({
|
|
74
|
+
issuer_url: result.issuerUrl,
|
|
75
|
+
tenant_url: result.tenantUrl,
|
|
76
|
+
client_id: result.clientId,
|
|
77
|
+
client_secret: result.clientSecret,
|
|
78
|
+
access_token: result.accessToken,
|
|
79
|
+
refresh_token: result.refreshToken,
|
|
80
|
+
expires_at: result.expiresAt,
|
|
81
|
+
signed_in_at: new Date().toISOString(),
|
|
82
|
+
}, null, 2) + '\n', { encoding: 'utf8', mode: 0o600 });
|
|
83
|
+
console.log(' wrote :', p);
|
|
84
|
+
console.log('');
|
|
85
|
+
console.log('=== step 2: build a session from that file only ===');
|
|
86
|
+
// Hide the keychain profile so this genuinely tests the no-install path.
|
|
87
|
+
const savedHome = process.env.QUICK_ACP_QUICKWORK_HOME;
|
|
88
|
+
process.env.QUICK_ACP_QUICKWORK_HOME = join(homedir(), '.quick-acp', 'empty-home');
|
|
89
|
+
if (!existsSync(process.env.QUICK_ACP_QUICKWORK_HOME)) {
|
|
90
|
+
await mkdir(process.env.QUICK_ACP_QUICKWORK_HOME, { recursive: true });
|
|
91
|
+
}
|
|
92
|
+
const direct = await sessionDirect();
|
|
93
|
+
if (savedHome === undefined)
|
|
94
|
+
delete process.env.QUICK_ACP_QUICKWORK_HOME;
|
|
95
|
+
else
|
|
96
|
+
process.env.QUICK_ACP_QUICKWORK_HOME = savedHome;
|
|
97
|
+
if (!direct.ok || !direct.session) {
|
|
98
|
+
console.error(`session failed at "${direct.step}": ${direct.reason}`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
const s = direct.session;
|
|
102
|
+
console.log(' source :', s.source);
|
|
103
|
+
console.log(' ws host :', s.wsHost);
|
|
104
|
+
console.log(' jwt :', s.jwt.slice(0, 24) + '...');
|
|
105
|
+
console.log('');
|
|
106
|
+
console.log('=== step 3: real turn ===');
|
|
107
|
+
const transport = new QuickTransport(s, {
|
|
108
|
+
onTokenRefreshNeeded: async () => {
|
|
109
|
+
const again = await sessionDirect();
|
|
110
|
+
return again.ok && again.session ? again.session.jwt : null;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
const chat = new QuickChatSession({
|
|
114
|
+
transport,
|
|
115
|
+
actorArn: s.actorArn,
|
|
116
|
+
agentMode: 'smart',
|
|
117
|
+
thinkingEffort: 'high',
|
|
118
|
+
});
|
|
119
|
+
await chat.open();
|
|
120
|
+
console.log('socket open');
|
|
121
|
+
console.log('');
|
|
122
|
+
let text = '';
|
|
123
|
+
let model = '';
|
|
124
|
+
for await (const ev of chat.sendTurn([{ role: 'user', text: 'Reply with exactly the single word: PONG.' }], { agentMode: 'smart', thinkingEffort: 'high', attachments: [] })) {
|
|
125
|
+
if (ev.type === 'text') {
|
|
126
|
+
text += ev.delta;
|
|
127
|
+
process.stdout.write(ev.delta);
|
|
128
|
+
}
|
|
129
|
+
else if (ev.type === 'error') {
|
|
130
|
+
console.error(`\nERROR ${ev.code}: ${ev.message}`);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
else if (ev.type === 'turn_end') {
|
|
134
|
+
model = ev.usage?.resolvedModelId ?? '';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
console.log('\n');
|
|
138
|
+
console.log('assistant :', JSON.stringify(text));
|
|
139
|
+
console.log('model :', model || '(unreported)');
|
|
140
|
+
console.log('');
|
|
141
|
+
if (text.trim()) {
|
|
142
|
+
console.log('*** FRESH MACHINE END-TO-END SUCCESS ***');
|
|
143
|
+
console.log('*** browser sign-in -> OIDC refresh -> gateway -> model -> text ***');
|
|
144
|
+
console.log('*** no Quick install, no outpost, no Electron, no keychain entry ***');
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
console.log('no assistant text arrived');
|
|
148
|
+
process.exitCode = 1;
|
|
149
|
+
}
|
|
150
|
+
chat.close();
|
|
151
|
+
//# sourceMappingURL=fresh-machine-e2e.js.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Multi-turn and tool-loop regression test.
|
|
4
|
+
*
|
|
5
|
+
* TWO BUGS THIS LOCKS DOWN (both were live, both were invisible to the
|
|
6
|
+
* single-turn e2e):
|
|
7
|
+
*
|
|
8
|
+
* 1. Back-to-back turns returned an EMPTY second reply. The stream closed on
|
|
9
|
+
* `turn_usage`, which arrives before the server has actually finished, so the
|
|
10
|
+
* next `user_message` landed mid-close and was answered with
|
|
11
|
+
* `message_complete {text:"", initiator:"user"}` — an echo, not a reply.
|
|
12
|
+
* Fixed by closing on `message_complete` instead.
|
|
13
|
+
*
|
|
14
|
+
* 2. The `inject` tool contract was never exercised end to end, so a protocol
|
|
15
|
+
* mismatch in the tool loop would have shipped unnoticed.
|
|
16
|
+
*
|
|
17
|
+
* Requires a Quick login (uses ~/.quick-acp/login.json or the keychain).
|
|
18
|
+
*
|
|
19
|
+
* node dist/inject-turn-test.js
|
|
20
|
+
*/
|
|
21
|
+
import { sessionDirect } from './quick/session-direct.js';
|
|
22
|
+
import { QuickTransport } from './quick/transport.js';
|
|
23
|
+
import { QuickChatSession } from './quick/session.js';
|
|
24
|
+
import { defaultPolicy, toolDefs, ToolExecutor } from './tools/registry.js';
|
|
25
|
+
import { buildToolPrompt, parseToolCall, formatToolResult } from './tools/strategies.js';
|
|
26
|
+
const workspace = process.env.QUICK_ACP_WORKSPACE ?? process.cwd();
|
|
27
|
+
const direct = await sessionDirect();
|
|
28
|
+
if (!direct.ok || !direct.session) {
|
|
29
|
+
console.error(`session failed at "${direct.step}": ${direct.reason}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
const transport = new QuickTransport(direct.session, {
|
|
33
|
+
onTokenRefreshNeeded: async () => {
|
|
34
|
+
const again = await sessionDirect({ preferAccessToken: false });
|
|
35
|
+
return again.ok && again.session ? again.session.jwt : null;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const chat = new QuickChatSession({
|
|
39
|
+
transport,
|
|
40
|
+
actorArn: direct.session.actorArn,
|
|
41
|
+
agentMode: 'smart',
|
|
42
|
+
thinkingEffort: 'high',
|
|
43
|
+
});
|
|
44
|
+
await chat.open();
|
|
45
|
+
let failures = 0;
|
|
46
|
+
const check = (name, ok, detail = '') => {
|
|
47
|
+
if (ok) {
|
|
48
|
+
console.log(` ok ${name}`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
failures++;
|
|
52
|
+
console.log(` FAIL ${name}${detail ? ` — ${detail}` : ''}`);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
async function turn(text) {
|
|
56
|
+
let out = '';
|
|
57
|
+
for await (const ev of chat.sendTurn([{ role: 'user', text }], {
|
|
58
|
+
agentMode: 'smart',
|
|
59
|
+
thinkingEffort: 'high',
|
|
60
|
+
attachments: [],
|
|
61
|
+
})) {
|
|
62
|
+
if (ev.type === 'text')
|
|
63
|
+
out += ev.delta;
|
|
64
|
+
else if (ev.type === 'error')
|
|
65
|
+
throw new Error(`${ev.code}: ${ev.message}`);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
console.log('quick-acp multi-turn test');
|
|
70
|
+
console.log('');
|
|
71
|
+
// 1. Three turns back-to-back, no artificial delay. This is the regression:
|
|
72
|
+
// previously #2 came back empty and #3 answered #2.
|
|
73
|
+
console.log(' back-to-back turns:');
|
|
74
|
+
const words = ['ALPHA', 'BRAVO', 'CHARLIE'];
|
|
75
|
+
const got = [];
|
|
76
|
+
for (const w of words) {
|
|
77
|
+
got.push(await turn(`Reply with exactly the single word: ${w}`));
|
|
78
|
+
}
|
|
79
|
+
for (let i = 0; i < words.length; i++) {
|
|
80
|
+
const text = got[i].trim();
|
|
81
|
+
check(`turn ${i + 1} answered with ${words[i]}`, text.toUpperCase().includes(words[i]), `got ${JSON.stringify(text.slice(0, 60))}`);
|
|
82
|
+
}
|
|
83
|
+
// 2. The inject tool loop: model must emit the contract, we execute, it answers.
|
|
84
|
+
const policy = { ...defaultPolicy(workspace), allowShell: true };
|
|
85
|
+
const tools = toolDefs(policy);
|
|
86
|
+
const executor = new ToolExecutor(policy);
|
|
87
|
+
const preamble = buildToolPrompt(tools, workspace);
|
|
88
|
+
console.log('');
|
|
89
|
+
console.log(' inject tool loop:');
|
|
90
|
+
const task = 'Use the file_list tool on the workspace root (path "."). Then tell me how many entries it returned.';
|
|
91
|
+
let pending = `${preamble}\n\n---\n\n${task}`;
|
|
92
|
+
let sawToolCall = false;
|
|
93
|
+
let executed = false;
|
|
94
|
+
let finalText = '';
|
|
95
|
+
for (let round = 0; round < 4; round++) {
|
|
96
|
+
const reply = await turn(pending);
|
|
97
|
+
const call = parseToolCall(reply);
|
|
98
|
+
if (!call) {
|
|
99
|
+
finalText = reply;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
sawToolCall = true;
|
|
103
|
+
const result = await executor.execute(call.name, call.arguments);
|
|
104
|
+
executed = result.ok;
|
|
105
|
+
pending = formatToolResult(call, result);
|
|
106
|
+
}
|
|
107
|
+
check('model emitted a tool call', sawToolCall);
|
|
108
|
+
check('tool executed locally', executed);
|
|
109
|
+
check('model produced a final answer after the tool', finalText.trim().length > 0);
|
|
110
|
+
console.log('');
|
|
111
|
+
if (failures === 0) {
|
|
112
|
+
console.log('all multi-turn checks passed');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
console.log(`${failures} check(s) FAILED`);
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
}
|
|
118
|
+
chat.close();
|
|
119
|
+
//# sourceMappingURL=inject-turn-test.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `quick-acp-login` — sign in to Quick without the official desktop app.
|
|
4
|
+
*
|
|
5
|
+
* node dist/login-cli.js --start-url https://ssoins-xxxx.awsapps.com/start
|
|
6
|
+
*
|
|
7
|
+
* Prints the sign-in URL, waits for the browser callback on 127.0.0.1:18080,
|
|
8
|
+
* exchanges the code, and writes a profile the outpost can use.
|
|
9
|
+
*
|
|
10
|
+
* Nothing here needs the Electron shell; the only requirement is a browser and
|
|
11
|
+
* an AWS account that has Quick access.
|
|
12
|
+
*/
|
|
13
|
+
import { login, issuerFromStartUrl, quickworkHome } from './quick/login.js';
|
|
14
|
+
function arg(name) {
|
|
15
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
16
|
+
if (i >= 0 && process.argv[i + 1] && !process.argv[i + 1].startsWith('--')) {
|
|
17
|
+
return process.argv[i + 1];
|
|
18
|
+
}
|
|
19
|
+
const inline = process.argv.find((a) => a.startsWith(`--${name}=`));
|
|
20
|
+
return inline ? inline.slice(name.length + 3) : undefined;
|
|
21
|
+
}
|
|
22
|
+
async function main() {
|
|
23
|
+
const startUrl = arg('start-url') ?? arg('startUrl') ?? process.env.QUICK_ACP_START_URL;
|
|
24
|
+
if (!startUrl) {
|
|
25
|
+
console.error('quick-acp login');
|
|
26
|
+
console.error('');
|
|
27
|
+
console.error('Usage:');
|
|
28
|
+
console.error(' node dist/login-cli.js --start-url https://ssoins-xxxxx.awsapps.com/start');
|
|
29
|
+
console.error('');
|
|
30
|
+
console.error('Where to find that URL:');
|
|
31
|
+
console.error(' 1. Open https://quicksight.aws.amazon.com (or any AWS console page) and sign in');
|
|
32
|
+
console.error(' 2. Your browser lands on your AWS access portal, at an address like');
|
|
33
|
+
console.error(' https://ssoins-1a2b3c4d5e6f.awsapps.com/start');
|
|
34
|
+
console.error(' 3. Copy that whole address and pass it here');
|
|
35
|
+
console.error('');
|
|
36
|
+
console.error('Already signed into the desktop app? You do not need this command at all —');
|
|
37
|
+
console.error('the bridge reads the stored login on its own.');
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const issuer = issuerFromStartUrl(startUrl);
|
|
42
|
+
console.log('quick-acp: sign in to Quick');
|
|
43
|
+
console.log('');
|
|
44
|
+
console.log(' start URL :', startUrl);
|
|
45
|
+
console.log(' issuer :', issuer ?? '(unrecognised)');
|
|
46
|
+
console.log(' profiles :', quickworkHome());
|
|
47
|
+
console.log('');
|
|
48
|
+
if (!issuer) {
|
|
49
|
+
console.error('That does not look like an AWS access portal URL.');
|
|
50
|
+
console.error('Expected: https://ssoins-xxxxx.awsapps.com/start');
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const result = await login({
|
|
55
|
+
startUrl,
|
|
56
|
+
persist: true,
|
|
57
|
+
onUrl: (url) => {
|
|
58
|
+
console.log('Open this in your browser and sign in:');
|
|
59
|
+
console.log('');
|
|
60
|
+
console.log(' ' + url);
|
|
61
|
+
console.log('');
|
|
62
|
+
console.log('Waiting for the sign-in to finish...');
|
|
63
|
+
console.log('');
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
console.log('');
|
|
67
|
+
if (!result.ok) {
|
|
68
|
+
console.error('sign-in FAILED:', result.error);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
console.log('Signed in.');
|
|
73
|
+
console.log(' client id :', result.clientId);
|
|
74
|
+
console.log(' access token:', result.accessToken ? `${result.accessToken.slice(0, 24)}…` : '(none)');
|
|
75
|
+
console.log(' refresh tok :', result.refreshToken ? `${result.refreshToken.slice(0, 24)}…` : '(none)');
|
|
76
|
+
console.log(' expires at :', result.expiresAt ? new Date(result.expiresAt * 1000).toISOString() : '?');
|
|
77
|
+
console.log(' profile :', result.profilePath);
|
|
78
|
+
console.log('');
|
|
79
|
+
console.log('Next: start the outpost with QUICK_ACP_QUICKWORK_HOME pointing at');
|
|
80
|
+
console.log('the directory holding that profiles.json, then run the bridge as usual.');
|
|
81
|
+
}
|
|
82
|
+
void main().catch((e) => {
|
|
83
|
+
console.error('fatal:', e instanceof Error ? (e.stack ?? e.message) : String(e));
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=login-cli.js.map
|