@agentuity/coder-tui 2.0.14 → 2.0.15
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/aigateway.d.ts.map +1 -1
- package/dist/aigateway.js +21 -26
- package/dist/aigateway.js.map +1 -1
- package/package.json +3 -1
- package/src/aigateway.ts +33 -62
package/dist/aigateway.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aigateway.d.ts","sourceRoot":"","sources":["../src/aigateway.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aigateway.d.ts","sourceRoot":"","sources":["../src/aigateway.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,+BAA+B,CAAC;AAEvF,MAAM,MAAM,QAAQ,GACjB,oBAAoB,GACpB,uBAAuB,GACvB,kBAAkB,GAClB,wBAAwB,GACxB,wBAAwB,GACxB,oBAAoB,GACpB,yBAAyB,GACzB,sBAAsB,GACtB,mBAAmB,GACnB,eAAe,CAAC;AAuJnB,wBAAsB,cAAc,CAAC,EAAE,EAAE,YAAY,iBA4CpD"}
|
package/dist/aigateway.js
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
import { delimiter, join } from 'node:path';
|
|
11
11
|
import { existsSync } from 'node:fs';
|
|
12
12
|
import { execFileSync } from 'node:child_process';
|
|
13
|
-
|
|
13
|
+
import { createMinimalLogger, StructuredError } from '@agentuity/core';
|
|
14
|
+
import { AIGatewayService, } from '@agentuity/core/aigateway';
|
|
15
|
+
import { createServerFetchAdapter } from '@agentuity/server';
|
|
14
16
|
const KNOWN_APIS = new Set([
|
|
15
17
|
'openai-completions',
|
|
16
18
|
'mistral-conversations',
|
|
@@ -23,6 +25,7 @@ const KNOWN_APIS = new Set([
|
|
|
23
25
|
'google-gemini-cli',
|
|
24
26
|
'google-vertex',
|
|
25
27
|
]);
|
|
28
|
+
const AIGatewayModelFetchError = StructuredError('AIGatewayModelFetchError')();
|
|
26
29
|
function getEnv(...keys) {
|
|
27
30
|
for (const key of keys) {
|
|
28
31
|
if (process.env[key]) {
|
|
@@ -72,8 +75,11 @@ async function fetchModels() {
|
|
|
72
75
|
}
|
|
73
76
|
break;
|
|
74
77
|
}
|
|
75
|
-
catch (
|
|
76
|
-
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new AIGatewayModelFetchError({
|
|
80
|
+
message: 'Failed to fetch models from AI Gateway',
|
|
81
|
+
cause: error,
|
|
82
|
+
});
|
|
77
83
|
}
|
|
78
84
|
}
|
|
79
85
|
}
|
|
@@ -90,38 +96,27 @@ async function fetchModels() {
|
|
|
90
96
|
if (orgId) {
|
|
91
97
|
process.env.AGENTUITY_AIGATEWAY_ORGID = orgId;
|
|
92
98
|
}
|
|
93
|
-
const controller = new AbortController();
|
|
94
|
-
const timeout = setTimeout(() => controller.abort(), MODEL_CATALOG_TIMEOUT_MS);
|
|
95
99
|
try {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
console.warn(`Failed to fetch models from AI Gateway: ${response.status} ${response.statusText}`);
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
const payload = (await response.json());
|
|
102
|
-
if (!payload.success) {
|
|
103
|
-
console.warn(`Failed to load models. ${payload.message} ${payload}`);
|
|
104
|
-
}
|
|
105
|
-
return payload.data;
|
|
100
|
+
const service = new AIGatewayService(baseUrl, createServerFetchAdapter({ headers: {} }, createMinimalLogger()));
|
|
101
|
+
return await service.listModels();
|
|
106
102
|
}
|
|
107
103
|
catch (error) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
console.warn('Failed to fetch models from AI Gateway:', error);
|
|
113
|
-
return {};
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
clearTimeout(timeout);
|
|
104
|
+
throw new AIGatewayModelFetchError({
|
|
105
|
+
message: 'Failed to fetch models from AI Gateway',
|
|
106
|
+
cause: error,
|
|
107
|
+
});
|
|
117
108
|
}
|
|
118
109
|
}
|
|
110
|
+
function sanitizeModalities(modalities) {
|
|
111
|
+
const sanitized = (modalities ?? []).filter((modality) => modality === 'text' || modality === 'image');
|
|
112
|
+
return sanitized.length > 0 ? sanitized : ['text'];
|
|
113
|
+
}
|
|
119
114
|
function toPiModel(m) {
|
|
120
115
|
return {
|
|
121
116
|
id: m.id,
|
|
122
117
|
name: m.name,
|
|
123
|
-
reasoning: m.reasoning,
|
|
124
|
-
input: m.input_modalities,
|
|
118
|
+
reasoning: m.reasoning ?? false,
|
|
119
|
+
input: sanitizeModalities(m.input_modalities),
|
|
125
120
|
contextWindow: m.context_window ?? 40000,
|
|
126
121
|
maxTokens: m.max_output_tokens ?? 64000,
|
|
127
122
|
cost: {
|
package/dist/aigateway.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,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AC;YAC1B,SAAS,CAAC,4CAA4C;QACvD,CAAC;QACD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAChD,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,CAAC;QAC3C,OAAO,CAAC,mBAAmB,CAAC,GAAG,OAAO,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentuity/coder-tui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "Agentuity Coder Hub extension for Pi coding agent",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Agentuity employees and contributors",
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
"prepublishOnly": "bun run clean && bun run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@agentuity/core": "2.0.15",
|
|
29
|
+
"@agentuity/server": "2.0.15",
|
|
28
30
|
"@mariozechner/pi-coding-agent": "^0.72.1",
|
|
29
31
|
"@mariozechner/pi-tui": "^0.72.1",
|
|
30
32
|
"@sinclair/typebox": "^0.34.49"
|
package/src/aigateway.ts
CHANGED
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
import { delimiter, join } from 'node:path';
|
|
11
11
|
import { existsSync } from 'node:fs';
|
|
12
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';
|
|
13
20
|
import type { ExtensionAPI, ProviderModelConfig } from '@mariozechner/pi-coding-agent';
|
|
14
21
|
|
|
15
22
|
export type KnownApi =
|
|
@@ -24,8 +31,6 @@ export type KnownApi =
|
|
|
24
31
|
| 'google-gemini-cli'
|
|
25
32
|
| 'google-vertex';
|
|
26
33
|
|
|
27
|
-
const MODEL_CATALOG_TIMEOUT_MS = 5_000;
|
|
28
|
-
|
|
29
34
|
const KNOWN_APIS = new Set<string>([
|
|
30
35
|
'openai-completions',
|
|
31
36
|
'mistral-conversations',
|
|
@@ -39,33 +44,9 @@ const KNOWN_APIS = new Set<string>([
|
|
|
39
44
|
'google-vertex',
|
|
40
45
|
] satisfies KnownApi[]);
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface AIGatewayModelResponse {
|
|
47
|
-
success: boolean;
|
|
48
|
-
data: AIGatewayModels;
|
|
49
|
-
message?: string;
|
|
50
|
-
error?: string;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
interface AIGatewayModel {
|
|
54
|
-
id: string;
|
|
55
|
-
name: string;
|
|
56
|
-
api: KnownApi;
|
|
57
|
-
reasoning: boolean;
|
|
58
|
-
input_modalities?: ('text' | 'image')[];
|
|
59
|
-
context_window?: number;
|
|
60
|
-
max_output_tokens?: number;
|
|
61
|
-
pricing?: {
|
|
62
|
-
input: number;
|
|
63
|
-
output: number;
|
|
64
|
-
cached_input: number;
|
|
65
|
-
unit: 'per_million_tokens';
|
|
66
|
-
currency: 'USD';
|
|
67
|
-
};
|
|
68
|
-
}
|
|
47
|
+
const AIGatewayModelFetchError = StructuredError('AIGatewayModelFetchError')<{
|
|
48
|
+
cause?: unknown;
|
|
49
|
+
}>();
|
|
69
50
|
|
|
70
51
|
function getEnv(...keys: string[]): string | undefined {
|
|
71
52
|
for (const key of keys) {
|
|
@@ -132,8 +113,11 @@ async function fetchModels(): Promise<AIGatewayModels> {
|
|
|
132
113
|
}
|
|
133
114
|
}
|
|
134
115
|
break;
|
|
135
|
-
} catch (
|
|
136
|
-
|
|
116
|
+
} catch (error) {
|
|
117
|
+
throw new AIGatewayModelFetchError({
|
|
118
|
+
message: 'Failed to fetch models from AI Gateway',
|
|
119
|
+
cause: error,
|
|
120
|
+
});
|
|
137
121
|
}
|
|
138
122
|
}
|
|
139
123
|
}
|
|
@@ -155,46 +139,33 @@ async function fetchModels(): Promise<AIGatewayModels> {
|
|
|
155
139
|
process.env.AGENTUITY_AIGATEWAY_ORGID = orgId;
|
|
156
140
|
}
|
|
157
141
|
|
|
158
|
-
const controller = new AbortController();
|
|
159
|
-
const timeout = setTimeout(() => controller.abort(), MODEL_CATALOG_TIMEOUT_MS);
|
|
160
|
-
|
|
161
142
|
try {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
);
|
|
168
|
-
return {};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const payload = (await response.json()) as AIGatewayModelResponse;
|
|
172
|
-
|
|
173
|
-
if (!payload.success) {
|
|
174
|
-
console.warn(`Failed to load models. ${payload.message} ${payload}`);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return payload.data;
|
|
143
|
+
const service = new AIGatewayService(
|
|
144
|
+
baseUrl,
|
|
145
|
+
createServerFetchAdapter({ headers: {} }, createMinimalLogger())
|
|
146
|
+
);
|
|
147
|
+
return await service.listModels();
|
|
178
148
|
} catch (error) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return {};
|
|
184
|
-
}
|
|
185
|
-
console.warn('Failed to fetch models from AI Gateway:', error);
|
|
186
|
-
return {};
|
|
187
|
-
} finally {
|
|
188
|
-
clearTimeout(timeout);
|
|
149
|
+
throw new AIGatewayModelFetchError({
|
|
150
|
+
message: 'Failed to fetch models from AI Gateway',
|
|
151
|
+
cause: error,
|
|
152
|
+
});
|
|
189
153
|
}
|
|
190
154
|
}
|
|
191
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
|
+
|
|
192
163
|
function toPiModel(m: AIGatewayModel): ProviderModelConfig {
|
|
193
164
|
return {
|
|
194
165
|
id: m.id,
|
|
195
166
|
name: m.name,
|
|
196
|
-
reasoning: m.reasoning,
|
|
197
|
-
input: m.input_modalities
|
|
167
|
+
reasoning: m.reasoning ?? false,
|
|
168
|
+
input: sanitizeModalities(m.input_modalities),
|
|
198
169
|
contextWindow: m.context_window ?? 40000,
|
|
199
170
|
maxTokens: m.max_output_tokens ?? 64000,
|
|
200
171
|
cost: {
|