@agentshouse/kit 0.2.1-alpha.4 → 0.2.1-alpha.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/dist/acp.js CHANGED
@@ -2,13 +2,13 @@ import { ndJsonStream, PROTOCOL_VERSION, } from '@agentclientprotocol/sdk';
2
2
  import { spawn } from 'node:child_process';
3
3
  import { readdirSync, readFileSync } from 'node:fs';
4
4
  import { Readable, Writable } from 'node:stream';
5
- import { CLIS, KIT_VERSION, cliCommand } from './clis.js';
5
+ import { CLIS, KIT_VERSION, cliCommand, withoutProxy } from './clis.js';
6
6
  export const TURN_STARTED = 'kit/turn_started';
7
7
  export const TURN_ENDED = 'kit/turn_ended';
8
- export async function startAdapter(kind, cwd, app, jobs = () => undefined, env = process.env) {
8
+ export async function startAdapter(kind, cwd, app, jobs = () => undefined, added = {}) {
9
9
  const child = spawn(cliCommand(kind), CLIS[kind].args, {
10
10
  cwd,
11
- env,
11
+ env: { ...withoutProxy(), ...added },
12
12
  stdio: ['pipe', 'pipe', 'pipe'],
13
13
  detached: true,
14
14
  });
package/dist/bridge.js CHANGED
@@ -23,6 +23,18 @@ async function received(request) {
23
23
  text += chunk;
24
24
  return text;
25
25
  }
26
+ function relay(request, response, target, authorization) {
27
+ const send = target.protocol === 'https:' ? httpsRequest : httpRequest;
28
+ const forwarded = send(target, {
29
+ method: request.method,
30
+ headers: { ...request.headers, host: target.host, ...(authorization === undefined ? {} : { authorization }) },
31
+ }, (answer) => {
32
+ response.writeHead(answer.statusCode, answer.headers);
33
+ answer.pipe(response);
34
+ });
35
+ forwarded.on('error', () => response.destroy());
36
+ request.pipe(forwarded);
37
+ }
26
38
  export async function openBridge(house, conversationId, signal) {
27
39
  const origin = (await readEnrolment()).house;
28
40
  const { credential } = await house.post(`/kit/conversations/${conversationId}/credential`, {}, signal);
@@ -69,6 +81,10 @@ export async function openBridge(house, conversationId, signal) {
69
81
  const bridge = createServer(async (request, response) => {
70
82
  try {
71
83
  const path = request.url ?? '';
84
+ if (URL.canParse(path)) {
85
+ relay(request, response, new URL(path));
86
+ return;
87
+ }
72
88
  const forwarded = FORWARDED.has(path) ? await forward(path, await received(request)) : { status: 404, text: '' };
73
89
  response.writeHead(forwarded.status, { 'content-type': 'application/json' }).end(forwarded.text);
74
90
  }
@@ -86,13 +102,7 @@ export async function openBridge(house, conversationId, signal) {
86
102
  response.writeHead(404).end();
87
103
  return;
88
104
  }
89
- const send = target.protocol === 'https:' ? httpsRequest : httpRequest;
90
- const forwarded = send(target, { method: request.method, headers: { ...request.headers, host: target.host, authorization } }, (answer) => {
91
- response.writeHead(answer.statusCode, answer.headers);
92
- answer.pipe(response);
93
- });
94
- forwarded.on('error', () => response.destroy());
95
- request.pipe(forwarded);
105
+ relay(request, response, target, authorization);
96
106
  });
97
107
  git.listen(0, '127.0.0.1');
98
108
  await once(git, 'listening');
package/dist/clis.js CHANGED
@@ -65,6 +65,7 @@ export const CLIS = {
65
65
  };
66
66
  const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
67
67
  export const KIT_VERSION = KIT_PACKAGE.version;
68
+ const PROXY = /^https?_proxy$/i;
68
69
  export function pinned(kind) {
69
70
  return KIT_PACKAGE.peerDependencies[CLIS[kind].package];
70
71
  }
@@ -83,9 +84,12 @@ export async function installedRelease(kind) {
83
84
  return null;
84
85
  }
85
86
  }
87
+ export function withoutProxy() {
88
+ return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
89
+ }
86
90
  export function run(command, args, timeoutMs) {
87
91
  return new Promise((resolve) => {
88
- const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], timeout: timeoutMs });
92
+ const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], timeout: timeoutMs, env: withoutProxy() });
89
93
  let output = '';
90
94
  child.stdout.on('data', (chunk) => {
91
95
  output += chunk.toString('utf8');
@@ -254,7 +254,7 @@ export class Conversations {
254
254
  }
255
255
  conversation.opening = bridge;
256
256
  try {
257
- const adapter = await startAdapter(route.kind, route.working_directory, app, (job) => this.job(conversation, job), { ...process.env, ...bridge.env });
257
+ const adapter = await startAdapter(route.kind, route.working_directory, app, (job) => this.job(conversation, job), bridge.env);
258
258
  void adapter.exited.then(() => bridge.close());
259
259
  const agent = adapter.connection.agent;
260
260
  const cwd = route.working_directory;
@@ -5,9 +5,9 @@ import { request } from 'node:http';
5
5
  import { basename } from 'node:path';
6
6
  const USAGE = "usage: house <tool> ['<arguments as JSON>']";
7
7
  const socketPath = process.env.HOUSE_BRIDGE;
8
- function bridged(path, body) {
8
+ function bridged(path, body, headers = { 'content-type': 'application/json' }) {
9
9
  return new Promise((resolve, reject) => {
10
- const sent = request({ socketPath, path, method: 'POST', headers: { 'content-type': 'application/json' } }, (answer) => {
10
+ const sent = request({ socketPath, path, method: 'POST', headers }, (answer) => {
11
11
  let text = '';
12
12
  answer.setEncoding('utf8');
13
13
  answer.on('data', (chunk) => {
@@ -21,7 +21,7 @@ function bridged(path, body) {
21
21
  });
22
22
  });
23
23
  sent.on('error', reject);
24
- sent.end(JSON.stringify(body));
24
+ sent.end(body instanceof Buffer ? body : JSON.stringify(body));
25
25
  });
26
26
  }
27
27
  async function mcp(method, params) {
@@ -42,15 +42,10 @@ async function upload(path, roomRef) {
42
42
  bytes: bytes.length,
43
43
  sha256: createHash('sha256').update(bytes).digest('hex'),
44
44
  }));
45
- const answer = await fetch(declared.upload.url, {
46
- method: 'POST',
47
- headers: { 'content-type': 'application/octet-stream', 'x-house-byte-operation': declared.upload.operation },
48
- body: bytes,
45
+ return bridged(declared.upload.url, bytes, {
46
+ 'content-type': 'application/octet-stream',
47
+ 'x-house-byte-operation': declared.upload.operation,
49
48
  });
50
- const text = await answer.text();
51
- if (!answer.ok)
52
- throw new Error(`House refused the bytes of ${path} with ${answer.status}: ${text}`);
53
- return text;
54
49
  }
55
50
  async function house([verb, argument]) {
56
51
  if (verb === undefined || verb === '--help') {
package/dist/kit-main.js CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
+ import { setGlobalProxyFromEnv } from 'node:http';
2
3
  import { login } from './login.js';
3
4
  import { resident } from './resident.js';
4
5
  const [command, ...argv] = process.argv.slice(2);
6
+ setGlobalProxyFromEnv();
5
7
  async function run() {
6
8
  if (command === 'login')
7
9
  return login(argv);
package/dist/sign-in.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createInterface } from 'node:readline';
3
3
  import { killTree } from './acp.js';
4
- import { CLIS, cliCommand } from './clis.js';
4
+ import { CLIS, cliCommand, withoutProxy } from './clis.js';
5
5
  import { holdSecretInput } from './secret-input.js';
6
6
  const ESCAPE = /\u001b\[[\d;]*m/g;
7
7
  const LINK = /https:\/\/\S+/;
@@ -39,7 +39,11 @@ export class SignIns {
39
39
  async login(input) {
40
40
  await this.agents.installed();
41
41
  const login = CLIS[input.cli].login;
42
- const child = spawn(cliCommand(input.cli), login.args, { stdio: ['pipe', 'pipe', 'pipe'], detached: true });
42
+ const child = spawn(cliCommand(input.cli), login.args, {
43
+ stdio: ['pipe', 'pipe', 'pipe'],
44
+ detached: true,
45
+ env: withoutProxy(),
46
+ });
43
47
  const running = () => child.exitCode === null && child.signalCode === null;
44
48
  let link;
45
49
  let code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-alpha.4",
3
+ "version": "0.2.1-alpha.5",
4
4
  "description": "House Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {