@cartanova/qgrid-ai-sdk 2.9.4 → 2.9.6
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/README.ko.md +8 -2
- package/README.md +36 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +39 -19
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -211,7 +211,7 @@ const { text } = await generateText({
|
|
|
211
211
|
| `serviceTier` | `string` | OpenAI 전용 | OpenAI/codex service tier |
|
|
212
212
|
| `timeoutMs` | 양의 정수, 최대 `1_800_000` | Anthropic 전용 | 서버의 Claude Code 프로세스 제한시간(ms). SDK의 non-stream HTTP 제한은 이 값보다 60초 길게 설정. 기본값은 240초 |
|
|
213
213
|
| `imageGeneration` | `boolean` | OpenAI 전용, non-stream | codex 내장 `image_generation` tool 활성화 ([아래](#image-generation) 참조) |
|
|
214
|
-
| `imageGenerationOptions` | `{ quality?, size? }` | OpenAI 전용 | 이미지
|
|
214
|
+
| `imageGenerationOptions` | `{ quality?, size?, background? }` | OpenAI 전용 | 이미지 생성 옵션. `background: "transparent"`는 전용 경로 사용. 실제 크기·품질은 응답 metadata 확인 ([아래](#image-generation)). |
|
|
215
215
|
| `fallbackModels` | `string[]` | 예약 | 향후 qgrid 서버 fallback routing용 예약 필드. 현재 동작하지 않으며 Claude Code의 Fable refusal fallback과 무관 |
|
|
216
216
|
|
|
217
217
|
```typescript
|
|
@@ -252,7 +252,7 @@ const { text } = await generateText({
|
|
|
252
252
|
|
|
253
253
|
### Image Generation
|
|
254
254
|
|
|
255
|
-
OpenAI/codex 경로 전용, `generateText` 전용입니다.
|
|
255
|
+
OpenAI/codex 경로 전용, `generateText` 전용입니다. 요청별로 이미지 생성을 활성화하고 결과를 AI SDK `files`로 받습니다. 투명 배경은 Codex 전용 Images 경로를, 그 외에는 내장 `image_generation` 도구를 사용합니다.
|
|
256
256
|
|
|
257
257
|
```typescript
|
|
258
258
|
const result = await generateText({
|
|
@@ -291,6 +291,12 @@ const result = await generateText({
|
|
|
291
291
|
- 이미지 생성 요청은 provider 대화 상태를 보관하지 않고 전체 input을 직접 전송합니다.
|
|
292
292
|
- 레퍼런스 이미지는 JSON data URL로 전송됩니다. 큰 사진은 압축하거나 리사이즈해서 전달하세요. 과도하게 큰 base64 입력은 SDK가 거부하며, 사진에는 WebP/JPEG를 권장합니다.
|
|
293
293
|
- 이미지 비용은 `gpt-image-2` 공개 단가표 기반 **추정치**로 request log의 `image_cost_usd`에 별도 기록됩니다 (codex가 정확한 이미지 tool 사용량을 노출하지 않음).
|
|
294
|
+
- `imageGenerationOptions.background`는 `"auto" | "opaque" | "transparent"`를 지원합니다. `"transparent"` 요청만 기존 ChatGPT 구독 토큰으로 Codex 전용 `images/generations` 또는 `images/edits` 경로를 사용합니다. 나머지는 기존 Responses 도구 경로를 유지합니다. 투명 경로는 텍스트 모델 없이 `gpt-image-2`를 직접 실행하며, tools·structured output은 지원하지 않습니다. 레퍼런스는 최대 5장입니다. 불투명·완전 빈 이미지·손상된 PNG는 오류로 처리하고, 별도 배경 제거로 대체하지 않습니다.
|
|
295
|
+
- 실제 출력 정보는 `result.providerMetadata.qgrid.imageGeneration` 배열에 있습니다(`contentIndex`, `model`, `route`, `size`, `quality`, `background`, 이미지 `usage`). `result.content` 파일 파트에도 metadata가 있지만 `result.files[]`에는 없습니다. 실호출에서 `1024x1024`/`high` 요청이 `1254x1254`/`medium`으로 반환됐으므로, 요청값을 최종 출력값으로 간주하면 안 됩니다. qgrid는 실제 PNG 크기를 보고하며 리사이즈하지 않습니다.
|
|
296
|
+
- 투명 경로는 텍스트 모델을 실행하지 않아 일반 토큰 usage·비용이 0입니다. 이미지 usage는 별도로 보존하고, `image_cost_usd`는 보고된 토큰과 공개 API 단가로 추정합니다. 알려진 text/image input은 구분하고 불명확한 input은 보수적으로 계산하며, 캐시 할인은 반영하지 않습니다. 구독 청구액을 뜻하지 않습니다.
|
|
297
|
+
- 명시한 이미지 옵션은 이미지 도구 로그의 `requestedOptions`에 기록하며 `pricingAssumption`과 구분합니다. 옵션 생략 시 비용 추정에 쓰는 `1536x1024`/`medium`은 실제 출력 크기·품질의 기본값을 보장하지 않습니다.
|
|
298
|
+
|
|
299
|
+
투명 생성은 위 `imageGenerationOptions`에 `background: "transparent"`를 추가하고, 프롬프트에도 피사체 밖의 투명 배경을 명시하세요. 크로마키·배경색 지시는 제거해야 합니다. 이 기능이 포함된 서버와 SDK가 모두 필요하며, 저장 시 PNG 알파를 유지하세요. 정확한 최종 크기는 소비 앱의 명시적인 crop/resize 정책으로 처리합니다.
|
|
294
300
|
|
|
295
301
|
## Telemetry Logger
|
|
296
302
|
|
package/README.md
CHANGED
|
@@ -220,7 +220,7 @@ const { text } = await generateText({
|
|
|
220
220
|
| `serviceTier` | `string` | OpenAI only | OpenAI/codex service tier |
|
|
221
221
|
| `timeoutMs` | positive integer, max `1_800_000` | Anthropic only | Server-side Claude Code process timeout in milliseconds. The SDK's non-stream HTTP budget is 60 seconds longer. Defaults to 240 seconds |
|
|
222
222
|
| `imageGeneration` | `boolean` | OpenAI only, non-stream | Enables codex's built-in `image_generation` tool (see [below](#image-generation)) |
|
|
223
|
-
| `imageGenerationOptions` | `{ quality?, size? }` | OpenAI only | Image
|
|
223
|
+
| `imageGenerationOptions` | `{ quality?, size?, background?, outputFormat? }` | OpenAI only | Image controls; `outputFormat` selects PNG/JPEG/WebP on Responses. `background: "transparent"` selects standalone Images (PNG only). Read actual size/quality from response metadata ([below](#image-generation)). |
|
|
224
224
|
| `fallbackModels` | `string[]` | reserved | Reserved for future qgrid server-side fallback routing. Not functional yet and unrelated to Claude Code's Fable refusal fallback |
|
|
225
225
|
|
|
226
226
|
```typescript
|
|
@@ -261,7 +261,7 @@ const { text } = await generateText({
|
|
|
261
261
|
|
|
262
262
|
### Image Generation
|
|
263
263
|
|
|
264
|
-
OpenAI/codex route only, `generateText` only. Enables
|
|
264
|
+
OpenAI/codex route only, `generateText` only. Enables image generation for that single request and returns the image through AI SDK `files`. Transparent backgrounds use standalone Codex Images; other requests use the hosted `image_generation` tool.
|
|
265
265
|
|
|
266
266
|
```typescript
|
|
267
267
|
const result = await generateText({
|
|
@@ -270,14 +270,16 @@ const result = await generateText({
|
|
|
270
270
|
providerOptions: {
|
|
271
271
|
qgrid: {
|
|
272
272
|
imageGeneration: true,
|
|
273
|
-
imageGenerationOptions: { quality: "medium", size: "1536x1024" },
|
|
273
|
+
imageGenerationOptions: { quality: "medium", size: "1536x1024", outputFormat: "webp" },
|
|
274
274
|
},
|
|
275
275
|
},
|
|
276
276
|
});
|
|
277
277
|
|
|
278
|
-
const image = result.files[0]; // mediaType: "image/
|
|
278
|
+
const image = result.files[0]; // mediaType: "image/webp", base64
|
|
279
279
|
```
|
|
280
280
|
|
|
281
|
+
Since 2.9.6, `imageGenerationOptions.outputFormat` accepts `"png" | "jpeg" | "webp"`; omission keeps PNG. qgrid preserves the returned image format in `mediaType` rather than converting the image. Save files with the matching extension. Transparent background requests only support PNG and reject JPEG/WebP before generation. `result.files[].mediaType` retains the AI SDK standard `string` type; no qgrid-specific wrapper or type assertion is needed.
|
|
282
|
+
|
|
281
283
|
Reference images can be passed through normal AI SDK multimodal message parts:
|
|
282
284
|
|
|
283
285
|
```typescript
|
|
@@ -300,6 +302,36 @@ const result = await generateText({
|
|
|
300
302
|
- Image-generation requests do not retain provider conversation state. Their full input is sent directly.
|
|
301
303
|
- Reference images are sent as JSON data URLs. Compress or resize large photos before passing them in; oversized base64 inputs are rejected by the SDK. WebP/JPEG is recommended for photos.
|
|
302
304
|
- The image cost is an **estimate** based on the public `gpt-image-2` price table, recorded separately as `image_cost_usd` on the request log (codex does not expose exact image-tool usage).
|
|
305
|
+
- `imageGenerationOptions.background` accepts `"auto" | "opaque" | "transparent"`. Only `"transparent"` uses Codex's standalone `images/generations` or `images/edits` endpoint with the existing ChatGPT subscription token. Other image requests keep the hosted Responses tool. The transparent route runs `gpt-image-2` directly, without a text driver; it rejects tools and structured output. It accepts up to five reference images and preserves PNG bytes. Fully opaque, entirely empty, or invalid PNG results fail explicitly; there is no background-removal fallback.
|
|
306
|
+
- Transparent image output metadata is available in `result.providerMetadata.qgrid.imageGeneration` (an array containing `contentIndex`, `model`, `route`, `size`, `quality`, `background`, and optional image `usage`). Per-file metadata also appears on `result.content` file parts, not on `result.files[]`. Request options are hints: a live `1024x1024`/`high` request returned `1254x1254`/`medium`. qgrid reports the actual PNG dimensions and does not resize it.
|
|
307
|
+
- On the transparent route, regular token usage/cost is zero because no text driver ran. Image usage is preserved separately and `image_cost_usd` is an API-price estimate from reported usage, with known text/image input splits and conservative pricing for unknown input. It omits cache discounts and is not subscription billing.
|
|
308
|
+
- Explicit image options are recorded as `requestedOptions` in the synthetic image tool log, separately from `pricingAssumption`. When size/quality are omitted, the `1536x1024`/`medium` pricing defaults do not establish actual output dimensions or quality.
|
|
309
|
+
|
|
310
|
+
Transparent generation example (requires a server and SDK containing this feature):
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
import { generateText } from "ai";
|
|
314
|
+
import { qgrid, type QgridProviderOptions } from "@cartanova/qgrid-ai-sdk";
|
|
315
|
+
|
|
316
|
+
const result = await generateText({
|
|
317
|
+
model: qgrid("openai/gpt-5.5", { projectName: "deti" }),
|
|
318
|
+
prompt: "An isolated character. Everything outside the character must be transparent, with no backdrop or checkerboard.",
|
|
319
|
+
providerOptions: {
|
|
320
|
+
qgrid: {
|
|
321
|
+
imageGeneration: true,
|
|
322
|
+
imageGenerationOptions: {
|
|
323
|
+
background: "transparent",
|
|
324
|
+
quality: "high",
|
|
325
|
+
size: "1024x1536",
|
|
326
|
+
},
|
|
327
|
+
} satisfies QgridProviderOptions,
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
const png = result.files[0];
|
|
331
|
+
const observed = result.providerMetadata?.qgrid?.imageGeneration;
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Remove green-screen or other background instructions when requesting transparency. Preserve the returned PNG alpha when saving; exact final dimensions require an explicit downstream crop/resize policy.
|
|
303
335
|
|
|
304
336
|
## Telemetry Logger
|
|
305
337
|
|
package/dist/index.d.ts
CHANGED
|
@@ -66,13 +66,16 @@ type QgridOpenAIProviderOptions = QgridCommonProviderOptions & {
|
|
|
66
66
|
*/
|
|
67
67
|
imageGeneration?: boolean;
|
|
68
68
|
/**
|
|
69
|
-
* Image generation
|
|
70
|
-
*
|
|
71
|
-
* public calculator table.
|
|
69
|
+
* Image generation controls. The Responses backend selects the image model;
|
|
70
|
+
* quality/size cost estimates use the GPT Image 2 public calculator table.
|
|
72
71
|
*/
|
|
73
72
|
imageGenerationOptions?: {
|
|
73
|
+
/** Responses output format. Defaults to PNG; transparent output only supports PNG. */
|
|
74
|
+
outputFormat?: "png" | "jpeg" | "webp";
|
|
74
75
|
quality?: "low" | "medium" | "high";
|
|
75
76
|
size?: "1024x1024" | "1024x1536" | "1536x1024";
|
|
77
|
+
/** Transparent uses Codex standalone Images and validates PNG alpha. See README for limits. */
|
|
78
|
+
background?: "auto" | "opaque" | "transparent";
|
|
76
79
|
};
|
|
77
80
|
};
|
|
78
81
|
/** `providerOptions.qgrid` — Anthropic(Claude Code) 모델용. */
|
|
@@ -94,6 +97,28 @@ type QgridAnthropicProviderOptions = QgridCommonProviderOptions & {
|
|
|
94
97
|
*/
|
|
95
98
|
type QgridProviderOptions = QgridOpenAIProviderOptions | QgridAnthropicProviderOptions;
|
|
96
99
|
type QgridSupportedModel = "openai/gpt-6-astra" | "openai/gpt-5.6-sol" | "openai/gpt-5.6-terra" | "openai/gpt-5.6-luna" | "openai/gpt-5.5" | "openai/gpt-5.4" | "openai/gpt-5.2" | "openai/gpt-5.4-mini" | "openai/gpt-5.3-codex" | "openai/gpt-5.3-codex-spark" | "anthropic/claude-fable-5-1" | "anthropic/claude-fable-5" | "anthropic/claude-haiku-4-5" | "anthropic/claude-sonnet-4" | "anthropic/claude-sonnet-4-5" | "anthropic/claude-sonnet-4-6" | "anthropic/claude-sonnet-4-7" | "anthropic/claude-sonnet-5" | "anthropic/claude-opus-4" | "anthropic/claude-opus-4-1" | "anthropic/claude-opus-4-5" | "anthropic/claude-opus-4-6" | "anthropic/claude-opus-4-7" | "anthropic/claude-opus-4-8" | "anthropic/claude-opus-5";
|
|
100
|
+
/** Observed image response values. Usage is response-level and appears on the first image only. */
|
|
101
|
+
type QgridImageGenerationMetadata = {
|
|
102
|
+
route: "codex-images";
|
|
103
|
+
model: "gpt-image-2";
|
|
104
|
+
background?: string;
|
|
105
|
+
quality?: string;
|
|
106
|
+
size?: string;
|
|
107
|
+
usage?: {
|
|
108
|
+
input_tokens: number;
|
|
109
|
+
output_tokens: number;
|
|
110
|
+
total_tokens: number;
|
|
111
|
+
input_tokens_details?: {
|
|
112
|
+
image_tokens: number;
|
|
113
|
+
text_tokens: number;
|
|
114
|
+
cached_tokens?: number;
|
|
115
|
+
};
|
|
116
|
+
output_tokens_details?: {
|
|
117
|
+
image_tokens: number;
|
|
118
|
+
text_tokens: number;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
97
122
|
type QgridLoggerConfig = {
|
|
98
123
|
/** qgrid 서버 주소. default: process.env.QGRID_URL, 없으면 기본값은 "http://localhost:44900" */
|
|
99
124
|
serverUrl?: string;
|
|
@@ -129,4 +154,4 @@ declare function createQgridLogger(config?: QgridLoggerConfig): TelemetrySetting
|
|
|
129
154
|
declare function qgrid(modelId: QgridOpenAIModel, config?: QgridOpenAIProviderConfig): LanguageModelV3;
|
|
130
155
|
declare function qgrid(modelId: QgridAnthropicModel, config?: QgridAnthropicProviderConfig): LanguageModelV3;
|
|
131
156
|
//#endregion
|
|
132
|
-
export { type QgridAnthropicEffort, type QgridAnthropicModel, type QgridAnthropicProviderConfig, type QgridAnthropicProviderOptions, type QgridLoggerConfig, type QgridOpenAIEffort, type QgridOpenAIModel, type QgridOpenAIProviderConfig, type QgridOpenAIProviderOptions, type QgridProviderConfig, type QgridProviderOptions, type QgridSupportedModel, createQgridLogger, qgrid as default, qgrid };
|
|
157
|
+
export { type QgridAnthropicEffort, type QgridAnthropicModel, type QgridAnthropicProviderConfig, type QgridAnthropicProviderOptions, type QgridImageGenerationMetadata, type QgridLoggerConfig, type QgridOpenAIEffort, type QgridOpenAIModel, type QgridOpenAIProviderConfig, type QgridOpenAIProviderOptions, type QgridProviderConfig, type QgridProviderOptions, type QgridSupportedModel, createQgridLogger, qgrid as default, qgrid };
|
package/dist/index.js
CHANGED
|
@@ -475,22 +475,36 @@ function extractPromptAndHistory(messages, options = {}) {
|
|
|
475
475
|
text: extracted.text
|
|
476
476
|
}]
|
|
477
477
|
});
|
|
478
|
-
} else if (msg.role === "assistant") {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
478
|
+
} else if (msg.role === "assistant") for (const part of msg.content) if ("text" in part && typeof part.text === "string") history.push({
|
|
479
|
+
type: "message",
|
|
480
|
+
role: "assistant",
|
|
481
|
+
content: [{
|
|
482
|
+
type: "output_text",
|
|
483
|
+
text: part.text
|
|
484
|
+
}]
|
|
485
|
+
});
|
|
486
|
+
else if ("toolName" in part && part.type === "tool-call") history.push({
|
|
487
|
+
type: "function_call",
|
|
488
|
+
name: part.toolName,
|
|
489
|
+
arguments: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
|
|
490
|
+
call_id: part.toolCallId
|
|
491
|
+
});
|
|
492
|
+
else {
|
|
493
|
+
const url = extractImageUrl(part);
|
|
494
|
+
if (!url) continue;
|
|
495
|
+
if (includeImages) {
|
|
496
|
+
imageUrls.push(url);
|
|
497
|
+
history.push({
|
|
498
|
+
type: "message",
|
|
499
|
+
role: "assistant",
|
|
500
|
+
content: [{
|
|
501
|
+
type: "input_image",
|
|
502
|
+
image_url: url
|
|
503
|
+
}]
|
|
504
|
+
});
|
|
505
|
+
} else droppedImageCount++;
|
|
506
|
+
}
|
|
507
|
+
else if (msg.role === "tool") {
|
|
494
508
|
for (const part of msg.content) if ("toolName" in part && part.type === "tool-result") {
|
|
495
509
|
const output = part.output;
|
|
496
510
|
const text = "value" in output ? typeof output.value === "string" ? output.value : JSON.stringify(output.value) : JSON.stringify(output);
|
|
@@ -1062,6 +1076,10 @@ async function deriveCacheAffinityKey(modelId, sessionKey) {
|
|
|
1062
1076
|
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1063
1077
|
}
|
|
1064
1078
|
function qgridProviderMetadata(data) {
|
|
1079
|
+
const imageGeneration = data.content?.flatMap((item, contentIndex) => item.type === "image" && item.generation ? [{
|
|
1080
|
+
contentIndex,
|
|
1081
|
+
...item.generation
|
|
1082
|
+
}] : []);
|
|
1065
1083
|
return { qgrid: {
|
|
1066
1084
|
model: data.model,
|
|
1067
1085
|
requestedModel: data.requestedModel ?? data.model,
|
|
@@ -1071,7 +1089,8 @@ function qgridProviderMetadata(data) {
|
|
|
1071
1089
|
costUsd: data.costUsd,
|
|
1072
1090
|
costSource: data.costSource,
|
|
1073
1091
|
cacheCreation5mInputTokens: data.usage.cache_creation_5m_input_tokens ?? null,
|
|
1074
|
-
cacheCreation1hInputTokens: data.usage.cache_creation_1h_input_tokens ?? null
|
|
1092
|
+
cacheCreation1hInputTokens: data.usage.cache_creation_1h_input_tokens ?? null,
|
|
1093
|
+
...imageGeneration?.length ? { imageGeneration } : {}
|
|
1075
1094
|
} };
|
|
1076
1095
|
}
|
|
1077
1096
|
function getQgridProviderOptions(options) {
|
|
@@ -1218,8 +1237,9 @@ function qgrid(modelId, config) {
|
|
|
1218
1237
|
});
|
|
1219
1238
|
else if (item.type === "image") content.push({
|
|
1220
1239
|
type: "file",
|
|
1221
|
-
mediaType: "image/png",
|
|
1222
|
-
data: item.data
|
|
1240
|
+
mediaType: item.mediaType ?? "image/png",
|
|
1241
|
+
data: item.data,
|
|
1242
|
+
...item.generation ? { providerMetadata: { qgrid: { imageGeneration: item.generation } } } : {}
|
|
1223
1243
|
});
|
|
1224
1244
|
else if (item.type === "tool-call") content.push({
|
|
1225
1245
|
type: "tool-call",
|