gencow 0.2.0 → 0.2.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gencow",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Gencow — AI Backend Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"@types/node": "^25.9.9",
|
|
47
47
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
48
48
|
"ai": "^6.0.326",
|
|
49
|
+
"@gencow/core": "0.2.0",
|
|
49
50
|
"@gencow/client": "0.2.9",
|
|
50
51
|
"@gencow/react": "0.2.9",
|
|
51
52
|
"@gencow/runtime": "0.1.0",
|
|
52
|
-
"@gencow/shared": "0.0.0",
|
|
53
53
|
"@gencow/server": "0.1.3",
|
|
54
|
-
"@gencow/
|
|
54
|
+
"@gencow/shared": "0.0.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "pnpm --dir ../.. run build:dashboard && node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-runtime.mjs && node scripts/copy-dashboard.mjs --required",
|
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
embed as aiEmbed,
|
|
7
7
|
embedMany as aiEmbedMany,
|
|
8
8
|
generateObject as aiGenerateObject,
|
|
9
|
+
NoObjectGeneratedError,
|
|
10
|
+
Output,
|
|
11
|
+
stepCountIs,
|
|
9
12
|
type GenerateObjectResult,
|
|
10
13
|
type LanguageModel,
|
|
11
14
|
type LanguageModelUsage,
|
|
@@ -186,40 +189,59 @@ async function resolveEmbeddingModel(
|
|
|
186
189
|
return model ?? provider.embeddingModel("text-embedding-3-small");
|
|
187
190
|
}
|
|
188
191
|
|
|
192
|
+
/**
|
|
193
|
+
* JSON mode only shapes the request (`response_format`). A reply that is not
|
|
194
|
+
* valid JSON (cut off at maxTokens, a refusal, an empty answer) is returned as
|
|
195
|
+
* text, as ai.chat always did, instead of throwing NoObjectGeneratedError.
|
|
196
|
+
*/
|
|
197
|
+
async function chatGenerate(
|
|
198
|
+
params: Parameters<typeof aiGenerateText>[0],
|
|
199
|
+
): Promise<{ text: string; usage: LanguageModelUsage | undefined }> {
|
|
200
|
+
try {
|
|
201
|
+
const result = (await aiGenerateText(params)) as AiGenerateTextRawResult;
|
|
202
|
+
return { text: result.text, usage: result.usage };
|
|
203
|
+
} catch (err: unknown) {
|
|
204
|
+
if (!NoObjectGeneratedError.isInstance(err)) throw err;
|
|
205
|
+
return { text: err.text ?? "", usage: err.usage };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
189
209
|
async function chat(options: {
|
|
190
210
|
model?: AiTextModel;
|
|
191
211
|
system?: string;
|
|
192
212
|
messages: AiMessage[];
|
|
193
213
|
tools?: AiTools;
|
|
194
214
|
temperature?: number;
|
|
215
|
+
/** Maximum output tokens (sent as AI SDK `maxOutputTokens`). */
|
|
195
216
|
maxTokens?: number;
|
|
196
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* Response format. `{ type: "json_object" }` enables JSON mode; the AI SDK
|
|
219
|
+
* sends it as the request's `response_format`. Other types are not mapped.
|
|
220
|
+
*/
|
|
197
221
|
responseFormat?: { type: string };
|
|
198
222
|
}): Promise<AiChatResult> {
|
|
199
223
|
try {
|
|
200
224
|
const resolvedModel = await resolveModel(options.model);
|
|
201
|
-
const result =
|
|
225
|
+
const result = await chatGenerate({
|
|
202
226
|
model: resolvedModel,
|
|
203
227
|
system: options.system,
|
|
204
228
|
messages: toModelMessages(options.messages),
|
|
205
229
|
tools: options.tools,
|
|
230
|
+
// Tool calls need further steps to produce the final answer.
|
|
231
|
+
...(options.tools && { stopWhen: stepCountIs(5) }),
|
|
206
232
|
...(options.temperature !== undefined && { temperature: options.temperature }),
|
|
207
|
-
...(options.maxTokens !== undefined && {
|
|
208
|
-
//
|
|
209
|
-
...(options.responseFormat?.type === "json_object" && {
|
|
210
|
-
|
|
211
|
-
openai: { response_format: { type: "json_object" } },
|
|
212
|
-
},
|
|
213
|
-
}),
|
|
214
|
-
} as Parameters<typeof aiGenerateText>[0])) as AiGenerateTextRawResult;
|
|
233
|
+
...(options.maxTokens !== undefined && { maxOutputTokens: options.maxTokens }),
|
|
234
|
+
// AI SDK v6 maps `Output.json()` to the Chat Completions `response_format`.
|
|
235
|
+
...(options.responseFormat?.type === "json_object" && { output: Output.json() }),
|
|
236
|
+
} as Parameters<typeof aiGenerateText>[0]);
|
|
215
237
|
|
|
216
238
|
const usage = result.usage;
|
|
217
239
|
return {
|
|
218
240
|
text: result.text,
|
|
219
241
|
usage: {
|
|
220
|
-
promptTokens: usage
|
|
221
|
-
completionTokens: usage
|
|
222
|
-
totalTokens: usage
|
|
242
|
+
promptTokens: usage?.inputTokens ?? 0,
|
|
243
|
+
completionTokens: usage?.outputTokens ?? 0,
|
|
244
|
+
totalTokens: usage?.totalTokens ?? 0,
|
|
223
245
|
},
|
|
224
246
|
// 배포 사용량은 별도로 집계되어 이 호환 필드에 표시되지 않습니다.
|
|
225
247
|
// 로컬 direct 호출은 Gencow 크레딧을 사용하지 않습니다.
|
|
@@ -477,7 +499,8 @@ async function extractText(options: VisionExtractTextInput): Promise<VisionExtra
|
|
|
477
499
|
/**
|
|
478
500
|
* Agent Loop — 도구 호출 → 결과 → 판단 → 도구 호출… 반복
|
|
479
501
|
*
|
|
480
|
-
*
|
|
502
|
+
* `maxSteps` (default 5) is kept as the public option name and maps to AI SDK v6
|
|
503
|
+
* `stopWhen: stepCountIs(maxSteps)`.
|
|
481
504
|
* 에이전트가 목표 달성까지 자동으로 도구를 반복 호출합니다.
|
|
482
505
|
*/
|
|
483
506
|
async function agent(options: {
|
|
@@ -495,7 +518,7 @@ async function agent(options: {
|
|
|
495
518
|
system: options.system,
|
|
496
519
|
messages: toModelMessages(options.messages),
|
|
497
520
|
tools: options.tools,
|
|
498
|
-
|
|
521
|
+
stopWhen: stepCountIs(options.maxSteps ?? 5),
|
|
499
522
|
onStepFinish: options.onStepFinish,
|
|
500
523
|
} as Parameters<typeof aiGenerateText>[0])) as AiGenerateTextRawResult;
|
|
501
524
|
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"Async image jobs (for generations over ~180 s or fire-and-forget; ai.image.generate() stays the default): const job = await ai.image.start({ prompt, idempotencyKey }); const result = await ai.image.waitForImage(job.id) (or ai.image.generateAsync()). Failures throw GencowAIImageJobError with code, stage, stateChanged, retryable, nextAction. Requires the deployed AI proxy; local direct mode throws AI_IMAGE_ASYNC_PROXY_REQUIRED",
|
|
28
28
|
"Reference images (a new image consistent with existing ones): await ai.image.generate({ prompt, referenceImages: [dataUrlOrPreviousResult] }), also in ai.image.start() and AI SDK generateImage({ prompt: { text, images } }). Base64 data URLs, { base64, mimeType } or { bytes, mimeType }; PNG/JPEG/WebP, at most 5 images and 20 MB in total; web URLs and masks are rejected. Needs the deployed AI proxy (local direct mode throws AI_IMAGE_REFERENCE_PROXY_REQUIRED). generate() is not retried; use start() with an idempotencyKey for retry safety. Server rejections throw GencowAIImageError (generate) or GencowAIImageJobError (start) with code, stage, stateChanged, retryable, nextAction",
|
|
29
29
|
"Pure AI SDK: generateText({ model: createGencowAI().languageModel(\"llm/economy\"), messages })",
|
|
30
|
+
"Tool calling (tools + stopWhen) and generateObject work in deployed apps as well as local direct mode; see the tools feature guide for the stopWhen pattern",
|
|
30
31
|
"ai.rerank() requires a deployed rerank route and has no provider in local direct mode; Cohere-rerank-v5.0-fast/pro are model choices, with actual provider availability determined at request time. Apply app ACLs before passing at most 100 documents; metadata is not authorization. Ranking uses the query and document text. providerPreference accepts auto or cohere; gpt_fallback returns HTTP 400 AI_RERANK_PROVIDER_UNSUPPORTED without chat-model substitution. A provider mismatch returns HTTP 503 AI_RERANK_PROVIDER_UNAVAILABLE; route/admission failures retain their own status and code",
|
|
31
32
|
"mutation 안에서: const reply = await ai.chat({ messages })",
|
|
32
33
|
"OPENAI_API_KEY 는 로컬 direct 개발 용입니다. 배포된 앱에는 앱의 provider key가 필요하지 않습니다",
|
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
"indexImports": [],
|
|
11
11
|
"guide": [
|
|
12
12
|
"gencow/tools.ts 에서 defineTools(ctx, { ... }) 로 AI 도구 정의",
|
|
13
|
-
"Legacy facade: ai.chat({ messages, tools }) 로 도구 연동 응답",
|
|
14
|
-
"Pure AI SDK: generateText({ model: createGencowAI().languageModel(\"llm/economy\"), messages, tools })",
|
|
13
|
+
"Legacy facade: ai.chat({ messages, tools }) 로 도구 연동 응답 (도구가 있으면 최대 5단계까지 최종 답을 기다립니다)",
|
|
14
|
+
"Pure AI SDK: generateText({ model: createGencowAI().languageModel(\"llm/economy\"), messages, tools, stopWhen: stepCountIs(5) })",
|
|
15
|
+
"Streaming with tools: streamText({ model: createGencowAI().languageModel(\"llm/economy\"), messages, tools, stopWhen: stepCountIs(5) }) — import { stepCountIs, streamText } from \"ai\"",
|
|
16
|
+
"AI SDK v6 has no maxSteps: pass stopWhen: stepCountIs(n) instead. Existing generated files are not rewritten by `gencow add`, so in an app that still calls ai.agent({ maxSteps }) or passes maxSteps to a raw AI SDK call, keep the same number and use stopWhen: stepCountIs(maxSteps) in its place",
|
|
15
17
|
"Existing generated gencow/tools.ts files are not overwritten by `gencow add tools`. To upgrade manually, use `import { tool, type Tool } from \"ai\";`, declare `const tools: Record<string, Tool<Record<string, unknown>, unknown>> = {};`, and pass `inputSchema: def.parameters` (not `parameters`) to `tool()`. Keep app-authored definitions and handlers unchanged, then run the app's TypeScript check; reinstall or deployment does not upgrade existing copies."
|
|
16
18
|
]
|
|
17
19
|
}
|