@agentuity/coder-tui 3.0.0-alpha.2 → 3.0.0-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/src/index.ts CHANGED
@@ -21,6 +21,7 @@ import { OutputViewerOverlay, type StoredResult } from './output-viewer.ts';
21
21
  import { setNativeRemoteExtensionContext } from './native-remote-ui-context.ts';
22
22
  import { handleRemoteUiRequest } from './remote-ui-handler.ts';
23
23
  import { buildInboundRpcPromptText, getInboundRpcDeliverAs } from './inbound-rpc.ts';
24
+ import { applyCoderAuthHeaders, getCoderAuthCurlArgs } from './auth.ts';
24
25
  import type {
25
26
  HubAction,
26
27
  HubResponse,
@@ -43,9 +44,8 @@ const HUB_URL_ENV = 'AGENTUITY_CODER_HUB_URL';
43
44
  const AGENT_ENV = 'AGENTUITY_CODER_AGENT';
44
45
  const REMOTE_SESSION_ENV = 'AGENTUITY_CODER_REMOTE_SESSION';
45
46
  const NATIVE_REMOTE_ENV = 'AGENTUITY_CODER_NATIVE_REMOTE';
46
- // TODO: Remove/Change when we get Agentuity service level auth enabled, this is just temporary
47
+ // Populated by `agentuity coder start` for hub bootstrap and runtime auth.
47
48
  const API_KEY_ENV = 'AGENTUITY_CODER_API_KEY';
48
- const API_KEY_HEADER = 'x-agentuity-auth-api-key';
49
49
  const RECONNECT_WAIT_TIMEOUT_MS = 120_000;
50
50
 
51
51
  type HubUiStatus = 'connected' | 'reconnecting' | 'offline';
@@ -117,12 +117,11 @@ function log(msg: string): void {
117
117
  }
118
118
 
119
119
  /** Build headers object with API key if available. Merges with any existing headers. */
120
- // TODO: Remove/Change when we get Agentuity service level auth enabled, this is just temporary
121
120
  function authHeaders(extra?: Record<string, string>): Record<string, string> {
122
121
  const apiKey = process.env[API_KEY_ENV];
122
+ const orgId = process.env.AGENTUITY_ORGID;
123
123
  const headers: Record<string, string> = { ...extra };
124
- if (apiKey) headers[API_KEY_HEADER] = apiKey;
125
- return headers;
124
+ return applyCoderAuthHeaders(headers, apiKey, orgId);
126
125
  }
127
126
 
128
127
  // ══════════════════════════════════════════════
@@ -173,9 +172,9 @@ function fetchInitMessageSync(hubUrl: string, agentRole?: string): InitMessage |
173
172
  'node:child_process'
174
173
  ) as typeof import('node:child_process');
175
174
  const apiKey = process.env[API_KEY_ENV];
175
+ const orgId = process.env.AGENTUITY_ORGID;
176
176
  const curlArgs = ['-s', '--connect-timeout', '3', '--max-time', '5'];
177
- // TODO: Remove/Change when we get Agentuity service level auth enabled, this is just temporary
178
- if (apiKey) curlArgs.push('-H', `${API_KEY_HEADER}: ${apiKey}`);
177
+ curlArgs.push(...getCoderAuthCurlArgs(apiKey, orgId));
179
178
  curlArgs.push(httpUrl);
180
179
  const result = execFileSync('curl', curlArgs, { encoding: 'utf-8' });
181
180
 
@@ -417,7 +416,6 @@ export function agentuityCoderHub(pi: ExtensionAPI) {
417
416
  // ══════════════════════════════════════════════
418
417
 
419
418
  const client = new HubClient();
420
- // TODO: Remove/Change when we get Agentuity service level auth enabled, this is just temporary
421
419
  client.apiKey = process.env[API_KEY_ENV] || null;
422
420
  let cachedInitMessage: InitMessage | null = initMsg;
423
421
  let currentSessionId: string | null = initMsg.sessionId ?? null;
@@ -22,6 +22,7 @@ import {
22
22
  syncRemoteLifecycleWorkingMessage,
23
23
  type RemoteLifecycleState,
24
24
  } from './remote-lifecycle.ts';
25
+ import { resolveCoderOrgId } from './auth.ts';
25
26
 
26
27
  const DEBUG = !!process.env['AGENTUITY_DEBUG'];
27
28
 
@@ -267,9 +268,10 @@ export class RemoteSession {
267
268
  wsHeaders['Authorization'] = `Bearer ${this.apiKey}`;
268
269
  }
269
270
  }
270
- if (this.orgId) {
271
- url.searchParams.set('orgId', this.orgId);
272
- wsHeaders['x-agentuity-orgid'] = this.orgId;
271
+ const orgId = resolveCoderOrgId(this.orgId);
272
+ if (orgId) {
273
+ url.searchParams.set('orgId', orgId);
274
+ wsHeaders['x-agentuity-orgid'] = orgId;
273
275
  }
274
276
 
275
277
  log(`${isReconnect ? 'Reconnecting' : 'Connecting'} to ${url.toString()}`);