@cartanova/qgrid-ai-sdk 2.0.0 → 2.0.3

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/index.d.ts CHANGED
@@ -30,8 +30,15 @@ type QgridProviderOptions = {
30
30
  };
31
31
  type QgridSupportedModel = "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-haiku-4-5" | "anthropic/claude-sonnet-4" | "anthropic/claude-sonnet-4-5" | "anthropic/claude-sonnet-4-6" | "anthropic/claude-sonnet-4-7" | "anthropic/claude-opus-4" | "anthropic/claude-opus-4-1" | "anthropic/claude-opus-4-5" | "anthropic/claude-opus-4-6" | "anthropic/claude-opus-4-7";
32
32
  type QgridLoggerConfig = {
33
- serverUrl: string;
33
+ /** qgrid 서버 주소. default: process.env.QGRID_URL, 없으면 기본값은 "http://localhost:44900" */
34
+ serverUrl?: string;
35
+ /**
36
+ * 프로젝트 이름. default: process.env.QGRID_PROJECT_NAME, 없으면 기본값은 ""
37
+ */
34
38
  projectName?: string;
39
+ /**
40
+ * 토큰 이름. 외부에서 호출할경우 기본값은 "external"
41
+ */
35
42
  tokenName?: string;
36
43
  /**
37
44
  * Fallback timeout for runs that receive onStart but never receive onFinish.
@@ -51,7 +58,7 @@ type QgridLoggerConfig = {
51
58
  };
52
59
  //#endregion
53
60
  //#region src/logger.d.ts
54
- declare function createQgridLogger(config: QgridLoggerConfig): TelemetrySettings;
61
+ declare function createQgridLogger(config?: QgridLoggerConfig): TelemetrySettings;
55
62
  //#endregion
56
63
  //#region src/index.d.ts
57
64
  declare function qgrid(modelId: QgridSupportedModel, config?: QgridProviderConfig): LanguageModelV3;
package/dist/index.js CHANGED
@@ -237,7 +237,11 @@ function timedKeySet() {
237
237
  }
238
238
  };
239
239
  }
240
- function createQgridLogger(config) {
240
+ function createQgridLogger(config = {}) {
241
+ const serverUrl = config.serverUrl ?? process.env.QGRID_URL ?? "http://localhost:44900";
242
+ const projectName = config.projectName ?? process.env.QGRID_PROJECT_NAME;
243
+ config.tokenName ?? process.env.QGRID_TOKEN_NAME;
244
+ const onLogError = config.onLogError ?? ((e) => console.warn(`[qgrid-logger] ${e.message}`));
241
245
  const runs = /* @__PURE__ */ new Map();
242
246
  const keyTtl = typeof config.staleRunTimeoutMs === "number" && config.staleRunTimeoutMs > 0 ? config.staleRunTimeoutMs : DEFAULT_STALE_RUN_TIMEOUT_MS;
243
247
  const suppressedQgrid = timedKeySet();
@@ -249,7 +253,7 @@ function createQgridLogger(config) {
249
253
  runs.delete(runKey);
250
254
  if (run.watchdog) clearTimeout(run.watchdog);
251
255
  run.cleanupAbortListener?.();
252
- for (const pending of run.pendingToolCalls) run.pendingSteps.push(appendStep(config.serverUrl, {
256
+ for (const pending of run.pendingToolCalls) run.pendingSteps.push(appendStep(serverUrl, {
253
257
  requestLogId: run.requestLogId,
254
258
  stepIndex: pending.stepIndex,
255
259
  type: "tool_call",
@@ -258,10 +262,10 @@ function createQgridLogger(config) {
258
262
  toolName: pending.toolName,
259
263
  toolArgs: pending.toolArgs,
260
264
  toolDurationMs: run.toolDurations.get(pending.toolCallId)
261
- }).catch((e) => config.onLogError?.(e instanceof Error ? e : new Error(String(e)))));
265
+ }).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e)))));
262
266
  run.pendingToolCalls = [];
263
267
  await Promise.allSettled(run.pendingSteps);
264
- await finishRun(config.serverUrl, {
268
+ await finishRun(serverUrl, {
265
269
  requestLogId: run.requestLogId,
266
270
  status: result.status,
267
271
  response: result.response,
@@ -271,9 +275,8 @@ function createQgridLogger(config) {
271
275
  totalCacheReadTokens: result.totalUsage?.inputTokenDetails?.cacheReadTokens ?? 0,
272
276
  totalCacheCreationTokens: result.totalUsage?.inputTokenDetails?.cacheWriteTokens ?? 0,
273
277
  totalDurationMs: Date.now() - run.startTime,
274
- history: run.history,
275
278
  ...result.errorMessage ? { errorMessage: result.errorMessage } : {}
276
- }).catch((e) => config.onLogError?.(e instanceof Error ? e : new Error(String(e))));
279
+ }).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e))));
277
280
  };
278
281
  let autoRunIdCounter = 0;
279
282
  const resolveRunKey = (event) => {
@@ -289,7 +292,7 @@ function createQgridLogger(config) {
289
292
  if (!event.metadata?.qgridRunId && !event.functionId && event.metadata) event.metadata.qgridRunId = `auto-${++autoRunIdCounter}`;
290
293
  const runKey = resolveRunKey(event);
291
294
  if (quarantined.has(runKey)) {
292
- config.onLogError?.(/* @__PURE__ */ new Error("createQgridLogger: telemetry key is quarantined after overlap"));
295
+ onLogError(/* @__PURE__ */ new Error("createQgridLogger: telemetry key is quarantined after overlap"));
293
296
  return;
294
297
  }
295
298
  if (event.model.provider === "qgrid") {
@@ -303,16 +306,18 @@ function createQgridLogger(config) {
303
306
  errorMessage: msg
304
307
  });
305
308
  quarantined.add(runKey, keyTtl);
306
- config.onLogError?.(new Error(msg));
309
+ onLogError(new Error(msg));
307
310
  return;
308
311
  }
309
312
  try {
310
313
  const messages = event.messages ?? (Array.isArray(event.prompt) ? event.prompt : void 0);
311
- const result = await createRun(config.serverUrl, {
314
+ const history = serializeHistory(messages);
315
+ const result = await createRun(serverUrl, {
312
316
  userPrompt: extractUserPrompt(event.prompt, messages),
313
317
  systemPrompt: extractSystemPrompt(event.system),
314
318
  modelName: event.model.modelId,
315
- projectName: config.projectName
319
+ projectName,
320
+ history
316
321
  });
317
322
  let watchdogTimeout = DEFAULT_STALE_RUN_TIMEOUT_MS;
318
323
  if (typeof config.staleRunTimeoutMs === "number") watchdogTimeout = config.staleRunTimeoutMs;
@@ -352,13 +357,12 @@ function createQgridLogger(config) {
352
357
  pendingToolCalls: [],
353
358
  startTime: Date.now(),
354
359
  toolDurations: /* @__PURE__ */ new Map(),
355
- history: serializeHistory(messages),
356
360
  watchdog,
357
361
  cleanupAbortListener,
358
362
  finishing: false
359
363
  });
360
364
  } catch (e) {
361
- config.onLogError?.(e instanceof Error ? e : new Error(String(e)));
365
+ onLogError(e instanceof Error ? e : new Error(String(e)));
362
366
  }
363
367
  },
364
368
  onToolCallFinish(event) {
@@ -379,7 +383,7 @@ function createQgridLogger(config) {
379
383
  const tr = content.find((p) => p.type === "tool-result" && p.toolCallId === pending.toolCallId);
380
384
  const te = content.find((p) => p.type === "tool-error" && p.toolCallId === pending.toolCallId);
381
385
  if (tr || te) {
382
- run.pendingSteps.push(appendStep(config.serverUrl, {
386
+ run.pendingSteps.push(appendStep(serverUrl, {
383
387
  requestLogId: run.requestLogId,
384
388
  stepIndex: pending.stepIndex,
385
389
  type: "tool_call",
@@ -390,12 +394,12 @@ function createQgridLogger(config) {
390
394
  toolResult: tr && "output" in tr ? safeStringify(tr.output) : void 0,
391
395
  toolDurationMs: run.toolDurations.get(pending.toolCallId),
392
396
  error: te && "error" in te ? safeStringify(te.error) : void 0
393
- }).catch((e) => config.onLogError?.(e instanceof Error ? e : new Error(String(e)))));
397
+ }).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e)))));
394
398
  run.toolDurations.delete(pending.toolCallId);
395
399
  } else remainingPending.push(pending);
396
400
  }
397
401
  run.pendingToolCalls = remainingPending;
398
- run.pendingSteps.push(appendStep(config.serverUrl, {
402
+ run.pendingSteps.push(appendStep(serverUrl, {
399
403
  requestLogId: run.requestLogId,
400
404
  stepIndex: stepNumber,
401
405
  type: "generate",
@@ -406,13 +410,13 @@ function createQgridLogger(config) {
406
410
  finishReason,
407
411
  reasoningText: typeof reasoningText === "string" && reasoningText.length > 0 ? reasoningText : void 0,
408
412
  reasoningTokens: usage.outputTokenDetails?.reasoningTokens
409
- }).catch((e) => config.onLogError?.(e instanceof Error ? e : new Error(String(e)))));
413
+ }).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e)))));
410
414
  const toolCalls = content.filter((p) => p.type === "tool-call");
411
415
  for (const [i, tc] of toolCalls.entries()) {
412
416
  const tr = content.find((p) => p.type === "tool-result" && p.toolCallId === tc.toolCallId);
413
417
  const te = content.find((p) => p.type === "tool-error" && p.toolCallId === tc.toolCallId);
414
418
  if (tr || te) {
415
- run.pendingSteps.push(appendStep(config.serverUrl, {
419
+ run.pendingSteps.push(appendStep(serverUrl, {
416
420
  requestLogId: run.requestLogId,
417
421
  stepIndex: stepNumber,
418
422
  type: "tool_call",
@@ -423,7 +427,7 @@ function createQgridLogger(config) {
423
427
  toolResult: tr && "output" in tr ? safeStringify(tr.output) : void 0,
424
428
  toolDurationMs: run.toolDurations.get(tc.toolCallId),
425
429
  error: te && "error" in te ? safeStringify(te.error) : void 0
426
- }).catch((e) => config.onLogError?.(e instanceof Error ? e : new Error(String(e)))));
430
+ }).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e)))));
427
431
  run.toolDurations.delete(tc.toolCallId);
428
432
  } else run.pendingToolCalls.push({
429
433
  stepIndex: stepNumber,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cartanova/qgrid-ai-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.0.3",
4
4
  "description": "AI SDK LanguageModelV3 provider for qgrid",
5
5
  "repository": {
6
6
  "type": "git",