@agentuity/coder-tui 2.0.15 → 2.0.17

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.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/dist/chain-preview.d.ts +1 -1
  3. package/dist/chain-preview.d.ts.map +1 -1
  4. package/dist/chain-preview.js +1 -1
  5. package/dist/chain-preview.js.map +1 -1
  6. package/dist/commands.d.ts +1 -1
  7. package/dist/commands.d.ts.map +1 -1
  8. package/dist/footer.d.ts +1 -1
  9. package/dist/footer.d.ts.map +1 -1
  10. package/dist/hub-overlay.d.ts +1 -1
  11. package/dist/hub-overlay.d.ts.map +1 -1
  12. package/dist/hub-overlay.js +2 -2
  13. package/dist/hub-overlay.js.map +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +6 -6
  17. package/dist/index.js.map +1 -1
  18. package/dist/native-remote-ui-context.d.ts +1 -1
  19. package/dist/native-remote-ui-context.d.ts.map +1 -1
  20. package/dist/output-viewer.d.ts +1 -1
  21. package/dist/output-viewer.d.ts.map +1 -1
  22. package/dist/output-viewer.js +2 -2
  23. package/dist/output-viewer.js.map +1 -1
  24. package/dist/overlay.d.ts +1 -1
  25. package/dist/overlay.d.ts.map +1 -1
  26. package/dist/overlay.js +1 -1
  27. package/dist/overlay.js.map +1 -1
  28. package/dist/remote-session.d.ts +1 -1
  29. package/dist/remote-session.d.ts.map +1 -1
  30. package/dist/remote-tui.js +1 -1
  31. package/dist/remote-tui.js.map +1 -1
  32. package/dist/remote-ui-handler.d.ts +1 -1
  33. package/dist/remote-ui-handler.d.ts.map +1 -1
  34. package/dist/renderers.d.ts +2 -2
  35. package/dist/renderers.d.ts.map +1 -1
  36. package/dist/renderers.js +1 -1
  37. package/dist/renderers.js.map +1 -1
  38. package/dist/review.d.ts +1 -1
  39. package/dist/review.d.ts.map +1 -1
  40. package/dist/startup-logo.d.ts +1 -1
  41. package/dist/startup-logo.d.ts.map +1 -1
  42. package/dist/titlebar.d.ts +1 -1
  43. package/dist/titlebar.d.ts.map +1 -1
  44. package/package.json +5 -6
  45. package/src/chain-preview.ts +2 -2
  46. package/src/commands.ts +1 -1
  47. package/src/footer.ts +1 -1
  48. package/src/hub-overlay.ts +2 -2
  49. package/src/index.ts +6 -6
  50. package/src/native-remote-ui-context.ts +1 -1
  51. package/src/output-viewer.ts +2 -2
  52. package/src/overlay.ts +2 -2
  53. package/src/remote-session.ts +1 -1
  54. package/src/remote-tui.ts +1 -1
  55. package/src/remote-ui-handler.ts +1 -1
  56. package/src/renderers.ts +2 -2
  57. package/src/review.ts +1 -1
  58. package/src/startup-logo.ts +1 -1
  59. package/src/titlebar.ts +1 -1
  60. package/dist/aigateway.d.ts +0 -4
  61. package/dist/aigateway.d.ts.map +0 -1
  62. package/dist/aigateway.js +0 -173
  63. package/dist/aigateway.js.map +0 -1
  64. package/src/aigateway.ts +0 -227
package/dist/aigateway.js DELETED
@@ -1,173 +0,0 @@
1
- /**
2
- * Agentuity AI Gateway Custom Provider Extension
3
- *
4
- * Registers models from the Agentuity AI Gateway using the appropriate API type
5
- * based on model ID patterns. Models are loaded dynamically from the gateway's /models endpoint.
6
- *
7
- * Usage:
8
- * Use /model to switch to aigateway models
9
- */
10
- import { delimiter, join } from 'node:path';
11
- import { existsSync } from 'node:fs';
12
- import { execFileSync } from 'node:child_process';
13
- import { createMinimalLogger, StructuredError } from '@agentuity/core';
14
- import { AIGatewayService, } from '@agentuity/core/aigateway';
15
- import { createServerFetchAdapter } from '@agentuity/server';
16
- const KNOWN_APIS = new Set([
17
- 'openai-completions',
18
- 'mistral-conversations',
19
- 'openai-responses',
20
- 'azure-openai-responses',
21
- 'openai-codex-responses',
22
- 'anthropic-messages',
23
- 'bedrock-converse-stream',
24
- 'google-generative-ai',
25
- 'google-gemini-cli',
26
- 'google-vertex',
27
- ]);
28
- const AIGatewayModelFetchError = StructuredError('AIGatewayModelFetchError')();
29
- function getEnv(...keys) {
30
- for (const key of keys) {
31
- if (process.env[key]) {
32
- return process.env[key];
33
- }
34
- }
35
- }
36
- function normalizeCredential(value) {
37
- if (value === undefined || value === null) {
38
- return undefined;
39
- }
40
- const normalized = String(value).trim();
41
- return normalized.length > 0 ? normalized : undefined;
42
- }
43
- function isKnownApi(api) {
44
- return typeof api === 'string' && KNOWN_APIS.has(api);
45
- }
46
- function getRegion() {
47
- return getEnv('AGENTUITY_REGION') ?? 'usc';
48
- }
49
- function getBaseUrl() {
50
- const region = getRegion();
51
- return `https://aigateway-${region}.agentuity.cloud`;
52
- }
53
- async function fetchModels() {
54
- const baseUrl = getBaseUrl();
55
- let apiKey = normalizeCredential(getEnv('AGENTUITY_CODER_API_KEY', 'AGENTUITY_SDK_KEY', 'AGENTUITY_CLI_API_KEY', 'AGENTUITY_CLI_KEY'));
56
- let orgId = normalizeCredential(getEnv('AGENTUITY_ORGID', 'AGENTUITY_CLOUD_ORG_ID', 'AGENTUITY_ORG_ID'));
57
- if (!apiKey) {
58
- let found = false;
59
- const path = process.env.PATH?.split(delimiter) ?? [];
60
- for (const dir of path) {
61
- const fn = join(dir, 'agentuity');
62
- if (existsSync(fn)) {
63
- try {
64
- const res = execFileSync(fn, ['auth', 'apikey', '--json']);
65
- const apiKeyResult = JSON.parse(res.toString());
66
- apiKey = normalizeCredential(apiKeyResult.apiKey);
67
- found = true;
68
- if (!orgId) {
69
- const ores = execFileSync(fn, ['auth', 'org', 'current']);
70
- orgId = normalizeCredential(ores);
71
- if (!orgId) {
72
- console.warn('Cannot determine the org id. Use `agentuity auth org select` to select a default organization');
73
- return {};
74
- }
75
- }
76
- break;
77
- }
78
- catch (error) {
79
- throw new AIGatewayModelFetchError({
80
- message: 'Failed to fetch models from AI Gateway',
81
- cause: error,
82
- });
83
- }
84
- }
85
- }
86
- if (!found) {
87
- console.warn('AGENTUITY_SDK_KEY, AGENTUITY_CLI_API_KEY or AGENTUITY_CLI_KEY not set and cannot find the agentuit cli, cannot fetch models from AI Gateway');
88
- return {};
89
- }
90
- }
91
- if (!apiKey) {
92
- console.warn('Cannot determine the API key, cannot fetch models from AI Gateway');
93
- return {};
94
- }
95
- process.env.AGENTUITY_AIGATEWAY_KEY = apiKey;
96
- if (orgId) {
97
- process.env.AGENTUITY_AIGATEWAY_ORGID = orgId;
98
- }
99
- try {
100
- const service = new AIGatewayService(baseUrl, createServerFetchAdapter({ headers: {} }, createMinimalLogger()));
101
- return await service.listModels();
102
- }
103
- catch (error) {
104
- throw new AIGatewayModelFetchError({
105
- message: 'Failed to fetch models from AI Gateway',
106
- cause: error,
107
- });
108
- }
109
- }
110
- function sanitizeModalities(modalities) {
111
- const sanitized = (modalities ?? []).filter((modality) => modality === 'text' || modality === 'image');
112
- return sanitized.length > 0 ? sanitized : ['text'];
113
- }
114
- function toPiModel(m) {
115
- return {
116
- id: m.id,
117
- name: m.name,
118
- reasoning: m.reasoning ?? false,
119
- input: sanitizeModalities(m.input_modalities),
120
- contextWindow: m.context_window ?? 40000,
121
- maxTokens: m.max_output_tokens ?? 64000,
122
- cost: {
123
- input: m.pricing?.input ?? 0,
124
- output: m.pricing?.output ?? 0,
125
- cacheRead: m.pricing?.cached_input ?? 0,
126
- cacheWrite: 0,
127
- },
128
- compat: {
129
- supportsDeveloperRole: false,
130
- },
131
- };
132
- }
133
- export async function setupAIGateway(pi) {
134
- const models = await fetchModels();
135
- const baseUrl = getBaseUrl();
136
- const allModels = [];
137
- for (const providerModels of Object.values(models)) {
138
- if (providerModels) {
139
- allModels.push(...providerModels);
140
- }
141
- }
142
- if (allModels.length === 0) {
143
- return;
144
- }
145
- const modelsByApi = new Map();
146
- for (const m of allModels) {
147
- const apiType = m.api;
148
- if (!isKnownApi(apiType)) {
149
- continue; // THIS SHOULD NEVER HAPPEN BUT JUST IN CASE
150
- }
151
- const existing = modelsByApi.get(apiType) ?? [];
152
- existing.push(toPiModel(m));
153
- modelsByApi.set(apiType, existing);
154
- }
155
- const headers = {};
156
- if (process.env.AGENTUITY_AIGATEWAY_ORGID) {
157
- headers['x-agentuity-orgid'] = process.env.AGENTUITY_AIGATEWAY_ORGID;
158
- }
159
- for (const [apiType, providerModels] of modelsByApi) {
160
- const apitok = apiType.split('-');
161
- const name = apitok.length >= 2 ? apitok.slice(0, 2).join('-') : apitok[0];
162
- const providerName = `agentuity/${name}`;
163
- pi.registerProvider(providerName, {
164
- baseUrl,
165
- apiKey: 'AGENTUITY_AIGATEWAY_KEY',
166
- headers,
167
- authHeader: true,
168
- api: apiType,
169
- models: providerModels,
170
- });
171
- }
172
- }
173
- //# sourceMappingURL=aigateway.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aigateway.js","sourceRoot":"","sources":["../src/aigateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACN,gBAAgB,GAGhB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAe7D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAS;IAClC,oBAAoB;IACpB,uBAAuB;IACvB,kBAAkB;IAClB,wBAAwB;IACxB,wBAAwB;IACxB,oBAAoB;IACpB,yBAAyB;IACzB,sBAAsB;IACtB,mBAAmB;IACnB,eAAe;CACM,CAAC,CAAC;AAExB,MAAM,wBAAwB,GAAG,eAAe,CAAC,0BAA0B,CAAC,EAExE,CAAC;AAEL,SAAS,MAAM,CAAC,GAAG,IAAc;IAChC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO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CAAC,GAAG,CAAC,yBAAyB,CAAC;IACtE,CAAC;IAED,KAAK,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,WAAW,EAAE,CAAC;QACrD,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3E,MAAM,YAAY,GAAG,aAAa,IAAI,EAAE,CAAC;QACzC,EAAE,CAAC,gBAAgB,CAAC,YAAY,EAAE;YACjC,OAAO;YACP,MAAM,EAAE,yBAAyB;YACjC,OAAO;YACP,UAAU,EAAE,IAAI;YAChB,GAAG,EAAE,OAAO;YACZ,MAAM,EAAE,cAAc;SACtB,CAAC,CAAC;IACJ,CAAC;AACF,CAAC"}
package/src/aigateway.ts DELETED
@@ -1,227 +0,0 @@
1
- /**
2
- * Agentuity AI Gateway Custom Provider Extension
3
- *
4
- * Registers models from the Agentuity AI Gateway using the appropriate API type
5
- * based on model ID patterns. Models are loaded dynamically from the gateway's /models endpoint.
6
- *
7
- * Usage:
8
- * Use /model to switch to aigateway models
9
- */
10
- import { delimiter, join } from 'node:path';
11
- import { existsSync } from 'node:fs';
12
- import { execFileSync } from 'node:child_process';
13
- import { createMinimalLogger, StructuredError } from '@agentuity/core';
14
- import {
15
- AIGatewayService,
16
- type AIGatewayModel,
17
- type AIGatewayModels,
18
- } from '@agentuity/core/aigateway';
19
- import { createServerFetchAdapter } from '@agentuity/server';
20
- import type { ExtensionAPI, ProviderModelConfig } from '@mariozechner/pi-coding-agent';
21
-
22
- export type KnownApi =
23
- | 'openai-completions'
24
- | 'mistral-conversations'
25
- | 'openai-responses'
26
- | 'azure-openai-responses'
27
- | 'openai-codex-responses'
28
- | 'anthropic-messages'
29
- | 'bedrock-converse-stream'
30
- | 'google-generative-ai'
31
- | 'google-gemini-cli'
32
- | 'google-vertex';
33
-
34
- const KNOWN_APIS = new Set<string>([
35
- 'openai-completions',
36
- 'mistral-conversations',
37
- 'openai-responses',
38
- 'azure-openai-responses',
39
- 'openai-codex-responses',
40
- 'anthropic-messages',
41
- 'bedrock-converse-stream',
42
- 'google-generative-ai',
43
- 'google-gemini-cli',
44
- 'google-vertex',
45
- ] satisfies KnownApi[]);
46
-
47
- const AIGatewayModelFetchError = StructuredError('AIGatewayModelFetchError')<{
48
- cause?: unknown;
49
- }>();
50
-
51
- function getEnv(...keys: string[]): string | undefined {
52
- for (const key of keys) {
53
- if (process.env[key]) {
54
- return process.env[key];
55
- }
56
- }
57
- }
58
-
59
- function normalizeCredential(value: unknown): string | undefined {
60
- if (value === undefined || value === null) {
61
- return undefined;
62
- }
63
- const normalized = String(value).trim();
64
- return normalized.length > 0 ? normalized : undefined;
65
- }
66
-
67
- function isKnownApi(api: unknown): api is KnownApi {
68
- return typeof api === 'string' && KNOWN_APIS.has(api);
69
- }
70
-
71
- function getRegion(): string {
72
- return getEnv('AGENTUITY_REGION') ?? 'usc';
73
- }
74
-
75
- function getBaseUrl(): string {
76
- const region = getRegion();
77
- return `https://aigateway-${region}.agentuity.cloud`;
78
- }
79
-
80
- async function fetchModels(): Promise<AIGatewayModels> {
81
- const baseUrl = getBaseUrl();
82
- let apiKey = normalizeCredential(
83
- getEnv(
84
- 'AGENTUITY_CODER_API_KEY',
85
- 'AGENTUITY_SDK_KEY',
86
- 'AGENTUITY_CLI_API_KEY',
87
- 'AGENTUITY_CLI_KEY'
88
- )
89
- );
90
- let orgId = normalizeCredential(
91
- getEnv('AGENTUITY_ORGID', 'AGENTUITY_CLOUD_ORG_ID', 'AGENTUITY_ORG_ID')
92
- );
93
-
94
- if (!apiKey) {
95
- let found = false;
96
- const path = process.env.PATH?.split(delimiter) ?? [];
97
- for (const dir of path) {
98
- const fn = join(dir, 'agentuity');
99
- if (existsSync(fn)) {
100
- try {
101
- const res = execFileSync(fn, ['auth', 'apikey', '--json']);
102
- const apiKeyResult = JSON.parse(res.toString()) as { apiKey: string };
103
- apiKey = normalizeCredential(apiKeyResult.apiKey);
104
- found = true;
105
- if (!orgId) {
106
- const ores = execFileSync(fn, ['auth', 'org', 'current']);
107
- orgId = normalizeCredential(ores);
108
- if (!orgId) {
109
- console.warn(
110
- 'Cannot determine the org id. Use `agentuity auth org select` to select a default organization'
111
- );
112
- return {};
113
- }
114
- }
115
- break;
116
- } catch (error) {
117
- throw new AIGatewayModelFetchError({
118
- message: 'Failed to fetch models from AI Gateway',
119
- cause: error,
120
- });
121
- }
122
- }
123
- }
124
- if (!found) {
125
- console.warn(
126
- 'AGENTUITY_SDK_KEY, AGENTUITY_CLI_API_KEY or AGENTUITY_CLI_KEY not set and cannot find the agentuit cli, cannot fetch models from AI Gateway'
127
- );
128
- return {};
129
- }
130
- }
131
-
132
- if (!apiKey) {
133
- console.warn('Cannot determine the API key, cannot fetch models from AI Gateway');
134
- return {};
135
- }
136
-
137
- process.env.AGENTUITY_AIGATEWAY_KEY = apiKey;
138
- if (orgId) {
139
- process.env.AGENTUITY_AIGATEWAY_ORGID = orgId;
140
- }
141
-
142
- try {
143
- const service = new AIGatewayService(
144
- baseUrl,
145
- createServerFetchAdapter({ headers: {} }, createMinimalLogger())
146
- );
147
- return await service.listModels();
148
- } catch (error) {
149
- throw new AIGatewayModelFetchError({
150
- message: 'Failed to fetch models from AI Gateway',
151
- cause: error,
152
- });
153
- }
154
- }
155
-
156
- function sanitizeModalities(modalities: string[] | undefined): ('text' | 'image')[] {
157
- const sanitized = (modalities ?? []).filter(
158
- (modality): modality is 'text' | 'image' => modality === 'text' || modality === 'image'
159
- );
160
- return sanitized.length > 0 ? sanitized : ['text'];
161
- }
162
-
163
- function toPiModel(m: AIGatewayModel): ProviderModelConfig {
164
- return {
165
- id: m.id,
166
- name: m.name,
167
- reasoning: m.reasoning ?? false,
168
- input: sanitizeModalities(m.input_modalities),
169
- contextWindow: m.context_window ?? 40000,
170
- maxTokens: m.max_output_tokens ?? 64000,
171
- cost: {
172
- input: m.pricing?.input ?? 0,
173
- output: m.pricing?.output ?? 0,
174
- cacheRead: m.pricing?.cached_input ?? 0,
175
- cacheWrite: 0,
176
- },
177
- compat: {
178
- supportsDeveloperRole: false,
179
- },
180
- };
181
- }
182
-
183
- export async function setupAIGateway(pi: ExtensionAPI) {
184
- const models = await fetchModels();
185
- const baseUrl = getBaseUrl();
186
-
187
- const allModels: AIGatewayModel[] = [];
188
- for (const providerModels of Object.values(models)) {
189
- if (providerModels) {
190
- allModels.push(...providerModels);
191
- }
192
- }
193
- if (allModels.length === 0) {
194
- return;
195
- }
196
-
197
- const modelsByApi = new Map<KnownApi, ProviderModelConfig[]>();
198
-
199
- for (const m of allModels) {
200
- const apiType = m.api;
201
- if (!isKnownApi(apiType)) {
202
- continue; // THIS SHOULD NEVER HAPPEN BUT JUST IN CASE
203
- }
204
- const existing = modelsByApi.get(apiType) ?? [];
205
- existing.push(toPiModel(m));
206
- modelsByApi.set(apiType, existing);
207
- }
208
-
209
- const headers: Record<string, string> = {};
210
- if (process.env.AGENTUITY_AIGATEWAY_ORGID) {
211
- headers['x-agentuity-orgid'] = process.env.AGENTUITY_AIGATEWAY_ORGID;
212
- }
213
-
214
- for (const [apiType, providerModels] of modelsByApi) {
215
- const apitok = apiType.split('-');
216
- const name = apitok.length >= 2 ? apitok.slice(0, 2).join('-') : apitok[0];
217
- const providerName = `agentuity/${name}`;
218
- pi.registerProvider(providerName, {
219
- baseUrl,
220
- apiKey: 'AGENTUITY_AIGATEWAY_KEY',
221
- headers,
222
- authHeader: true,
223
- api: apiType,
224
- models: providerModels,
225
- });
226
- }
227
- }