@things-factory/ai-client-base 10.1.303 → 10.1.304
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-server/service/agent/agent-settings-save.d.ts +2 -0
- package/dist-server/service/agent/agent-settings-save.js +2 -0
- package/dist-server/service/agent/agent-spec.d.ts +6 -0
- package/dist-server/service/agent/agent-spec.js +13 -1
- package/dist-server/service/agent/ai-client-for.js +4 -0
- package/dist-server/service/agent/image-price.d.ts +18 -0
- package/dist-server/service/agent/image-price.js +26 -0
- package/dist-server/service/agent/index.d.ts +1 -0
- package/dist-server/service/agent/index.js +1 -0
- package/dist-server/service/providers/gemini.d.ts +3 -1
- package/dist-server/service/providers/gemini.js +18 -0
- package/dist-server/service/providers/openai.d.ts +3 -1
- package/dist-server/service/providers/openai.js +16 -0
- package/dist-server/service/types.d.ts +19 -0
- package/package.json +5 -5
|
@@ -8,6 +8,8 @@ export interface AiAgentWrite {
|
|
|
8
8
|
model: string;
|
|
9
9
|
baseURL?: string;
|
|
10
10
|
organization?: string;
|
|
11
|
+
/** The model the agent makes pictures with (ADR-0226 decision 8-1) - its provider's default when empty. */
|
|
12
|
+
imageModel?: string;
|
|
11
13
|
active: boolean;
|
|
12
14
|
/** A new key. Left out, the stored key stays (ADR-0112 decision 3). */
|
|
13
15
|
apiKey?: string;
|
|
@@ -88,6 +88,8 @@ function normalize(write, storedById) {
|
|
|
88
88
|
model,
|
|
89
89
|
...(write.baseURL?.trim() && { baseURL: write.baseURL.trim() }),
|
|
90
90
|
...(write.provider === 'openai' && write.organization?.trim() && { organization: write.organization.trim() }),
|
|
91
|
+
/* Only a provider that makes pictures keeps an image model (Anthropic and Claude Code make none). */
|
|
92
|
+
...(agent_spec_js_1.DEFAULT_IMAGE_MODELS[write.provider] && write.imageModel?.trim() && { imageModel: write.imageModel.trim() }),
|
|
91
93
|
active: write.active !== false
|
|
92
94
|
};
|
|
93
95
|
}
|
|
@@ -28,6 +28,8 @@ export interface AiAgentSpec {
|
|
|
28
28
|
baseURL?: string;
|
|
29
29
|
/** OpenAI only. */
|
|
30
30
|
organization?: string;
|
|
31
|
+
/** The model this agent makes pictures with (ADR-0226 decision 8-1) - its provider's default when empty. */
|
|
32
|
+
imageModel?: string;
|
|
31
33
|
/** Off takes the agent out of this domain and every domain below it. */
|
|
32
34
|
active: boolean;
|
|
33
35
|
}
|
|
@@ -50,3 +52,7 @@ export declare function isAiAgentProvider(value: unknown): value is AiAgentProvi
|
|
|
50
52
|
*/
|
|
51
53
|
export declare function parseAiAgentsSetting(value: string | null | undefined): AiAgentsSetting;
|
|
52
54
|
export declare function stringifyAiAgentsSetting(setting: AiAgentsSetting): string;
|
|
55
|
+
/** The image model each provider makes pictures with when an agent names none; a provider absent here makes none. */
|
|
56
|
+
export declare const DEFAULT_IMAGE_MODELS: Partial<Record<AiAgentProvider, string>>;
|
|
57
|
+
/** The model an agent makes pictures with, or nothing when its provider makes none (Anthropic, Claude Code). */
|
|
58
|
+
export declare function imageModelOf(spec: Pick<AiAgentSpec, 'provider' | 'imageModel'>): string | undefined;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* This file is the shape and its parsing - no database.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.AI_AGENT_KEY_PREFIX = exports.AI_AGENTS_SETTING_CATEGORY = exports.AI_AGENTS_SETTING = exports.AI_AGENT_PROVIDERS = void 0;
|
|
10
|
+
exports.DEFAULT_IMAGE_MODELS = exports.AI_AGENT_KEY_PREFIX = exports.AI_AGENTS_SETTING_CATEGORY = exports.AI_AGENTS_SETTING = exports.AI_AGENT_PROVIDERS = void 0;
|
|
11
11
|
exports.aiProviderNeedsKey = aiProviderNeedsKey;
|
|
12
12
|
exports.aiProviderAvailable = aiProviderAvailable;
|
|
13
13
|
exports.aiProvidersOffered = aiProvidersOffered;
|
|
@@ -15,6 +15,7 @@ exports.aiAgentKeyName = aiAgentKeyName;
|
|
|
15
15
|
exports.isAiAgentProvider = isAiAgentProvider;
|
|
16
16
|
exports.parseAiAgentsSetting = parseAiAgentsSetting;
|
|
17
17
|
exports.stringifyAiAgentsSetting = stringifyAiAgentsSetting;
|
|
18
|
+
exports.imageModelOf = imageModelOf;
|
|
18
19
|
/**
|
|
19
20
|
* The providers an agent may name. Three, by decision (2026-10-12); and claude-code (2026-11-13): Claude Code logged in
|
|
20
21
|
* on the server's own machine, for development -- it needs no key, and is offered only where it can answer.
|
|
@@ -80,6 +81,7 @@ function parseAiAgentsSetting(value) {
|
|
|
80
81
|
model,
|
|
81
82
|
...(text(one.baseURL) && { baseURL: text(one.baseURL) }),
|
|
82
83
|
...(one.provider === 'openai' && text(one.organization) && { organization: text(one.organization) }),
|
|
84
|
+
...(text(one.imageModel) && { imageModel: text(one.imageModel) }),
|
|
83
85
|
active: one.active !== false
|
|
84
86
|
}
|
|
85
87
|
];
|
|
@@ -101,4 +103,14 @@ function stringifyAiAgentsSetting(setting) {
|
|
|
101
103
|
function text(value) {
|
|
102
104
|
return typeof value === 'string' ? value.trim() : '';
|
|
103
105
|
}
|
|
106
|
+
/** The image model each provider makes pictures with when an agent names none; a provider absent here makes none. */
|
|
107
|
+
exports.DEFAULT_IMAGE_MODELS = {
|
|
108
|
+
openai: 'gpt-image-1.5',
|
|
109
|
+
gemini: 'gemini-2.5-flash-image'
|
|
110
|
+
};
|
|
111
|
+
/** The model an agent makes pictures with, or nothing when its provider makes none (Anthropic, Claude Code). */
|
|
112
|
+
function imageModelOf(spec) {
|
|
113
|
+
const fallback = exports.DEFAULT_IMAGE_MODELS[spec.provider];
|
|
114
|
+
return fallback ? spec.imageModel || fallback : undefined;
|
|
115
|
+
}
|
|
104
116
|
//# sourceMappingURL=agent-spec.js.map
|
|
@@ -10,6 +10,7 @@ exports.setAIClientForTesting = setAIClientForTesting;
|
|
|
10
10
|
const shell_1 = require("@things-factory/shell");
|
|
11
11
|
const factory_js_1 = require("../factory.js");
|
|
12
12
|
const agent_directory_js_1 = require("./agent-directory.js");
|
|
13
|
+
const agent_spec_js_1 = require("./agent-spec.js");
|
|
13
14
|
/* The usage rows still being written: a request's answer does not wait for its row. */
|
|
14
15
|
const recording = new Set();
|
|
15
16
|
/**
|
|
@@ -133,6 +134,9 @@ function meter(client, entry, request) {
|
|
|
133
134
|
...(client.chatWithTools && {
|
|
134
135
|
chatWithTools: (messages, tools, options) => measured('chatWithTools', options, o => client.chatWithTools(messages, tools, o))
|
|
135
136
|
}),
|
|
137
|
+
...(client.generateImage && {
|
|
138
|
+
generateImage: (prompt, options) => measured('generateImage', options, o => client.generateImage(prompt, { ...options, model: options?.model ?? (0, agent_spec_js_1.imageModelOf)(spec), onUsage: o.onUsage }))
|
|
139
|
+
}),
|
|
136
140
|
listModels: () => client.listModels()
|
|
137
141
|
};
|
|
138
142
|
return metered;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What one made picture costs (ADR-0226 decision 8, 8-1) - what the 「AI로 만들기」 window shows beside each model and
|
|
3
|
+
* quality, and what a made picture records as its cost.
|
|
4
|
+
*
|
|
5
|
+
* The model price table (model-price.ts) keeps prices per token, and the usage row of an image call keeps the tokens the
|
|
6
|
+
* provider reports, as every call does. A picture's price is set per picture and per quality step, which no token price
|
|
7
|
+
* says; these are LiteLLM's figures of 2026-11-21 for a 1024x1024 picture, in USD.
|
|
8
|
+
*/
|
|
9
|
+
export type ImageQuality = 'low' | 'medium' | 'high';
|
|
10
|
+
export interface ImagePrice {
|
|
11
|
+
/** USD per picture at each quality step the model has; a model with one price has it under `medium`. */
|
|
12
|
+
perImage: Partial<Record<ImageQuality, number>>;
|
|
13
|
+
}
|
|
14
|
+
export declare const IMAGE_PRICES: Record<string, ImagePrice>;
|
|
15
|
+
/** The quality steps a model offers - those it has a price for, `medium` alone for a model this table does not know. */
|
|
16
|
+
export declare function imageQualitiesOf(model: string): ImageQuality[];
|
|
17
|
+
/** USD for one picture of `model` at `quality` - undefined for a model this table does not know. */
|
|
18
|
+
export declare function imagePriceOf(model: string, quality?: ImageQuality): number | undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IMAGE_PRICES = void 0;
|
|
4
|
+
exports.imageQualitiesOf = imageQualitiesOf;
|
|
5
|
+
exports.imagePriceOf = imagePriceOf;
|
|
6
|
+
exports.IMAGE_PRICES = {
|
|
7
|
+
'gpt-image-1.5': { perImage: { low: 0.009, medium: 0.034, high: 0.133 } },
|
|
8
|
+
'gemini-2.5-flash-image': { perImage: { medium: 0.039 } }
|
|
9
|
+
};
|
|
10
|
+
/** The quality steps a model offers - those it has a price for, `medium` alone for a model this table does not know. */
|
|
11
|
+
function imageQualitiesOf(model) {
|
|
12
|
+
const known = exports.IMAGE_PRICES[bare(model)]?.perImage;
|
|
13
|
+
return known ? ['low', 'medium', 'high'].filter(one => known[one] !== undefined) : ['medium'];
|
|
14
|
+
}
|
|
15
|
+
/** USD for one picture of `model` at `quality` - undefined for a model this table does not know. */
|
|
16
|
+
function imagePriceOf(model, quality = 'medium') {
|
|
17
|
+
const known = exports.IMAGE_PRICES[bare(model)]?.perImage;
|
|
18
|
+
if (!known)
|
|
19
|
+
return undefined;
|
|
20
|
+
return known[quality] ?? known.medium ?? Object.values(known)[0];
|
|
21
|
+
}
|
|
22
|
+
/* A provider may answer with `models/…` or a dated name; the table holds the bare one. */
|
|
23
|
+
function bare(model) {
|
|
24
|
+
return model.replace(/^models\//, '').replace(/-(\d{4}-\d{2}-\d{2}|\d{8})$/, '');
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=image-price.js.map
|
|
@@ -5,5 +5,6 @@ export * from './provider-models.js';
|
|
|
5
5
|
export * from './agent-settings-save.js';
|
|
6
6
|
export * from './ai-usage-summary.js';
|
|
7
7
|
export * from './model-price.js';
|
|
8
|
+
export * from './image-price.js';
|
|
8
9
|
export { AiUsage } from './ai-usage.js';
|
|
9
10
|
export { AiModelPrice } from './ai-model-price.js';
|
|
@@ -9,6 +9,7 @@ tslib_1.__exportStar(require("./provider-models.js"), exports);
|
|
|
9
9
|
tslib_1.__exportStar(require("./agent-settings-save.js"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./ai-usage-summary.js"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./model-price.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./image-price.js"), exports);
|
|
12
13
|
var ai_usage_js_1 = require("./ai-usage.js");
|
|
13
14
|
Object.defineProperty(exports, "AiUsage", { enumerable: true, get: function () { return ai_usage_js_1.AiUsage; } });
|
|
14
15
|
var ai_model_price_js_1 = require("./ai-model-price.js");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AIChatOptions, AIClient, AIClientConfig, AIJSONOptions, AIMessage, AITool, AIToolChatOptions, AIToolChatResult, AIVisionOptions } from '../types.js';
|
|
1
|
+
import type { AIImage, AIImageOptions, AIChatOptions, AIClient, AIClientConfig, AIJSONOptions, AIMessage, AITool, AIToolChatOptions, AIToolChatResult, AIVisionOptions } from '../types.js';
|
|
2
2
|
export declare class GeminiAIClient implements AIClient {
|
|
3
3
|
readonly id: string;
|
|
4
4
|
private sdk;
|
|
@@ -13,6 +13,8 @@ export declare class GeminiAIClient implements AIClient {
|
|
|
13
13
|
}, prompt: string, options?: AIVisionOptions): Promise<string>;
|
|
14
14
|
private buildModel;
|
|
15
15
|
chatWithTools(messages: AIMessage[], tools: AITool[], options?: AIToolChatOptions): Promise<AIToolChatResult>;
|
|
16
|
+
/** A picture from words (ADR-0226 decision 8) - an image model's generateContent answers with inline image data. */
|
|
17
|
+
generateImage(prompt: string, options?: AIImageOptions): Promise<AIImage>;
|
|
16
18
|
/**
|
|
17
19
|
* The SDK has no model list, so this reads the REST one. A conversation model is one that answers
|
|
18
20
|
* generateContent; embedding and other models are left out.
|
|
@@ -122,6 +122,24 @@ class GeminiAIClient {
|
|
|
122
122
|
stopReason: normalizeGeminiStopReason(candidate?.finishReason, toolCalls.length > 0)
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
/** A picture from words (ADR-0226 decision 8) - an image model's generateContent answers with inline image data. */
|
|
126
|
+
async generateImage(prompt, options = {}) {
|
|
127
|
+
const model = options.model || 'gemini-2.5-flash-image';
|
|
128
|
+
const base = (this.baseURL || 'https://generativelanguage.googleapis.com').replace(/\/+$/, '');
|
|
129
|
+
const response = await fetch(`${base}/v1beta/models/${encodeURIComponent(model)}:generateContent`, {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
headers: { 'content-type': 'application/json', 'x-goog-api-key': this.apiKey },
|
|
132
|
+
body: JSON.stringify({ contents: [{ parts: [{ text: prompt }] }], generationConfig: { responseModalities: ['IMAGE'] } })
|
|
133
|
+
});
|
|
134
|
+
if (!response.ok)
|
|
135
|
+
throw new Error(`${model} answered ${response.status}: ${(await response.text()).slice(0, 300)}`);
|
|
136
|
+
const body = await response.json();
|
|
137
|
+
options.onUsage?.((0, usage_js_1.geminiUsageOf)(model, body?.usageMetadata));
|
|
138
|
+
const part = (body?.candidates?.[0]?.content?.parts ?? []).find((one) => one?.inlineData?.data);
|
|
139
|
+
if (!part)
|
|
140
|
+
throw new Error(`${model} answered no picture`);
|
|
141
|
+
return { data: Buffer.from(part.inlineData.data, 'base64'), mimetype: part.inlineData.mimeType || 'image/png', model };
|
|
142
|
+
}
|
|
125
143
|
/**
|
|
126
144
|
* The SDK has no model list, so this reads the REST one. A conversation model is one that answers
|
|
127
145
|
* generateContent; embedding and other models are left out.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AIChatOptions, AIClient, AIClientConfig, AIJSONOptions, AIMessage, AITool, AIToolChatOptions, AIToolChatResult, AIVisionOptions } from '../types.js';
|
|
1
|
+
import type { AIImage, AIImageOptions, AIChatOptions, AIClient, AIClientConfig, AIJSONOptions, AIMessage, AITool, AIToolChatOptions, AIToolChatResult, AIVisionOptions } from '../types.js';
|
|
2
2
|
export declare class OpenAIAIClient implements AIClient {
|
|
3
3
|
readonly id: string;
|
|
4
4
|
private sdk;
|
|
@@ -19,6 +19,8 @@ export declare class OpenAIAIClient implements AIClient {
|
|
|
19
19
|
url: string;
|
|
20
20
|
}, prompt: string, options?: AIVisionOptions): Promise<string>;
|
|
21
21
|
chatWithTools(messages: AIMessage[], tools: AITool[], options?: AIToolChatOptions): Promise<AIToolChatResult>;
|
|
22
|
+
/** A picture from words (ADR-0226 decision 8) - the Images API; a gpt-image model answers in base64. */
|
|
23
|
+
generateImage(prompt: string, options?: AIImageOptions): Promise<AIImage>;
|
|
22
24
|
listModels(): Promise<string[]>;
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
@@ -145,6 +145,22 @@ class OpenAIAIClient {
|
|
|
145
145
|
stopReason: normalizeOpenAIStopReason(choice?.finish_reason)
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
+
/** A picture from words (ADR-0226 decision 8) - the Images API; a gpt-image model answers in base64. */
|
|
149
|
+
async generateImage(prompt, options = {}) {
|
|
150
|
+
const model = options.model || 'gpt-image-1.5';
|
|
151
|
+
const response = await this.sdk.images.generate({
|
|
152
|
+
model,
|
|
153
|
+
prompt,
|
|
154
|
+
n: 1,
|
|
155
|
+
size: (options.size || '1024x1024'),
|
|
156
|
+
...(options.quality && { quality: options.quality })
|
|
157
|
+
});
|
|
158
|
+
options.onUsage?.((0, usage_js_1.openAIUsageOf)(model, response?.usage));
|
|
159
|
+
const encoded = response?.data?.[0]?.b64_json;
|
|
160
|
+
if (!encoded)
|
|
161
|
+
throw new Error(`${model} answered no picture`);
|
|
162
|
+
return { data: Buffer.from(encoded, 'base64'), mimetype: 'image/png', model };
|
|
163
|
+
}
|
|
148
164
|
async listModels() {
|
|
149
165
|
const ids = [];
|
|
150
166
|
for await (const model of this.sdk.models.list())
|
|
@@ -172,6 +172,8 @@ export interface AIClient {
|
|
|
172
172
|
vision?(image: Buffer | Uint8Array | {
|
|
173
173
|
url: string;
|
|
174
174
|
}, prompt: string, options?: AIVisionOptions): Promise<string>;
|
|
175
|
+
/** Makes a picture from words (ADR-0226 decision 8). Only providers that make pictures have it. */
|
|
176
|
+
generateImage?(prompt: string, options?: AIImageOptions): Promise<AIImage>;
|
|
175
177
|
/**
|
|
176
178
|
* Tool calling — LLM 이 자유 텍스트 대신 정의된 도구를 schema-검증된 인자로 호출.
|
|
177
179
|
* 각 도구의 parameters 가 enum/required 강제 → invalid type / 누락 필드 봉쇄.
|
|
@@ -190,6 +192,23 @@ export interface AIClient {
|
|
|
190
192
|
/** The ids of the conversation models this key may call, sorted. Reading it also proves the key is accepted. */
|
|
191
193
|
listModels(): Promise<string[]>;
|
|
192
194
|
}
|
|
195
|
+
/** What a made picture asks for (ADR-0226 decision 8-1). */
|
|
196
|
+
export interface AIImageOptions {
|
|
197
|
+
/** The image model; the agent's image model when not given. */
|
|
198
|
+
model?: string;
|
|
199
|
+
/** low, medium or high - the provider's quality steps where it has them. */
|
|
200
|
+
quality?: 'low' | 'medium' | 'high';
|
|
201
|
+
/** WIDTHxHEIGHT, e.g. 1024x1024. */
|
|
202
|
+
size?: string;
|
|
203
|
+
onUsage?: (usage: AIProviderUsage) => void;
|
|
204
|
+
}
|
|
205
|
+
/** A made picture. */
|
|
206
|
+
export interface AIImage {
|
|
207
|
+
data: Buffer;
|
|
208
|
+
mimetype: string;
|
|
209
|
+
/** The model that made it, as the provider said. */
|
|
210
|
+
model: string;
|
|
211
|
+
}
|
|
193
212
|
export interface AIClientConfig {
|
|
194
213
|
/** 등록된 provider 이름 (예: 'anthropic', 'openai', 'gemini') */
|
|
195
214
|
provider: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/ai-client-base",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.304",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"config",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@anthropic-ai/sdk": "^0.40.0",
|
|
40
40
|
"@google/generative-ai": "^0.24.0",
|
|
41
|
-
"@things-factory/auth-base": "^10.1.
|
|
41
|
+
"@things-factory/auth-base": "^10.1.304",
|
|
42
42
|
"@things-factory/env": "^10.1.298",
|
|
43
|
-
"@things-factory/setting-base": "^10.1.
|
|
44
|
-
"@things-factory/shell": "^10.1.
|
|
43
|
+
"@things-factory/setting-base": "^10.1.304",
|
|
44
|
+
"@things-factory/shell": "^10.1.304",
|
|
45
45
|
"openai": "^4.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "76ce38519069ba90190d69d2a9d6c130bc981cf0"
|
|
48
48
|
}
|