@cartanova/qgrid-ai-sdk 2.0.0 → 2.0.2
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 +3 -2
- package/dist/index.js +17 -15
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,8 @@ 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
|
-
|
|
33
|
+
/** qgrid 서버 주소. 기본값: QGRID_URL 환경변수 또는 http://localhost:44900 */
|
|
34
|
+
serverUrl?: string;
|
|
34
35
|
projectName?: string;
|
|
35
36
|
tokenName?: string;
|
|
36
37
|
/**
|
|
@@ -51,7 +52,7 @@ type QgridLoggerConfig = {
|
|
|
51
52
|
};
|
|
52
53
|
//#endregion
|
|
53
54
|
//#region src/logger.d.ts
|
|
54
|
-
declare function createQgridLogger(config
|
|
55
|
+
declare function createQgridLogger(config?: QgridLoggerConfig): TelemetrySettings;
|
|
55
56
|
//#endregion
|
|
56
57
|
//#region src/index.d.ts
|
|
57
58
|
declare function qgrid(modelId: QgridSupportedModel, config?: QgridProviderConfig): LanguageModelV3;
|
package/dist/index.js
CHANGED
|
@@ -237,7 +237,9 @@ 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 onLogError = config.onLogError ?? ((e) => console.warn(`[qgrid-logger] ${e.message}`));
|
|
241
243
|
const runs = /* @__PURE__ */ new Map();
|
|
242
244
|
const keyTtl = typeof config.staleRunTimeoutMs === "number" && config.staleRunTimeoutMs > 0 ? config.staleRunTimeoutMs : DEFAULT_STALE_RUN_TIMEOUT_MS;
|
|
243
245
|
const suppressedQgrid = timedKeySet();
|
|
@@ -249,7 +251,7 @@ function createQgridLogger(config) {
|
|
|
249
251
|
runs.delete(runKey);
|
|
250
252
|
if (run.watchdog) clearTimeout(run.watchdog);
|
|
251
253
|
run.cleanupAbortListener?.();
|
|
252
|
-
for (const pending of run.pendingToolCalls) run.pendingSteps.push(appendStep(
|
|
254
|
+
for (const pending of run.pendingToolCalls) run.pendingSteps.push(appendStep(serverUrl, {
|
|
253
255
|
requestLogId: run.requestLogId,
|
|
254
256
|
stepIndex: pending.stepIndex,
|
|
255
257
|
type: "tool_call",
|
|
@@ -258,10 +260,10 @@ function createQgridLogger(config) {
|
|
|
258
260
|
toolName: pending.toolName,
|
|
259
261
|
toolArgs: pending.toolArgs,
|
|
260
262
|
toolDurationMs: run.toolDurations.get(pending.toolCallId)
|
|
261
|
-
}).catch((e) =>
|
|
263
|
+
}).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e)))));
|
|
262
264
|
run.pendingToolCalls = [];
|
|
263
265
|
await Promise.allSettled(run.pendingSteps);
|
|
264
|
-
await finishRun(
|
|
266
|
+
await finishRun(serverUrl, {
|
|
265
267
|
requestLogId: run.requestLogId,
|
|
266
268
|
status: result.status,
|
|
267
269
|
response: result.response,
|
|
@@ -273,7 +275,7 @@ function createQgridLogger(config) {
|
|
|
273
275
|
totalDurationMs: Date.now() - run.startTime,
|
|
274
276
|
history: run.history,
|
|
275
277
|
...result.errorMessage ? { errorMessage: result.errorMessage } : {}
|
|
276
|
-
}).catch((e) =>
|
|
278
|
+
}).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e))));
|
|
277
279
|
};
|
|
278
280
|
let autoRunIdCounter = 0;
|
|
279
281
|
const resolveRunKey = (event) => {
|
|
@@ -289,7 +291,7 @@ function createQgridLogger(config) {
|
|
|
289
291
|
if (!event.metadata?.qgridRunId && !event.functionId && event.metadata) event.metadata.qgridRunId = `auto-${++autoRunIdCounter}`;
|
|
290
292
|
const runKey = resolveRunKey(event);
|
|
291
293
|
if (quarantined.has(runKey)) {
|
|
292
|
-
|
|
294
|
+
onLogError(/* @__PURE__ */ new Error("createQgridLogger: telemetry key is quarantined after overlap"));
|
|
293
295
|
return;
|
|
294
296
|
}
|
|
295
297
|
if (event.model.provider === "qgrid") {
|
|
@@ -303,12 +305,12 @@ function createQgridLogger(config) {
|
|
|
303
305
|
errorMessage: msg
|
|
304
306
|
});
|
|
305
307
|
quarantined.add(runKey, keyTtl);
|
|
306
|
-
|
|
308
|
+
onLogError(new Error(msg));
|
|
307
309
|
return;
|
|
308
310
|
}
|
|
309
311
|
try {
|
|
310
312
|
const messages = event.messages ?? (Array.isArray(event.prompt) ? event.prompt : void 0);
|
|
311
|
-
const result = await createRun(
|
|
313
|
+
const result = await createRun(serverUrl, {
|
|
312
314
|
userPrompt: extractUserPrompt(event.prompt, messages),
|
|
313
315
|
systemPrompt: extractSystemPrompt(event.system),
|
|
314
316
|
modelName: event.model.modelId,
|
|
@@ -358,7 +360,7 @@ function createQgridLogger(config) {
|
|
|
358
360
|
finishing: false
|
|
359
361
|
});
|
|
360
362
|
} catch (e) {
|
|
361
|
-
|
|
363
|
+
onLogError(e instanceof Error ? e : new Error(String(e)));
|
|
362
364
|
}
|
|
363
365
|
},
|
|
364
366
|
onToolCallFinish(event) {
|
|
@@ -379,7 +381,7 @@ function createQgridLogger(config) {
|
|
|
379
381
|
const tr = content.find((p) => p.type === "tool-result" && p.toolCallId === pending.toolCallId);
|
|
380
382
|
const te = content.find((p) => p.type === "tool-error" && p.toolCallId === pending.toolCallId);
|
|
381
383
|
if (tr || te) {
|
|
382
|
-
run.pendingSteps.push(appendStep(
|
|
384
|
+
run.pendingSteps.push(appendStep(serverUrl, {
|
|
383
385
|
requestLogId: run.requestLogId,
|
|
384
386
|
stepIndex: pending.stepIndex,
|
|
385
387
|
type: "tool_call",
|
|
@@ -390,12 +392,12 @@ function createQgridLogger(config) {
|
|
|
390
392
|
toolResult: tr && "output" in tr ? safeStringify(tr.output) : void 0,
|
|
391
393
|
toolDurationMs: run.toolDurations.get(pending.toolCallId),
|
|
392
394
|
error: te && "error" in te ? safeStringify(te.error) : void 0
|
|
393
|
-
}).catch((e) =>
|
|
395
|
+
}).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e)))));
|
|
394
396
|
run.toolDurations.delete(pending.toolCallId);
|
|
395
397
|
} else remainingPending.push(pending);
|
|
396
398
|
}
|
|
397
399
|
run.pendingToolCalls = remainingPending;
|
|
398
|
-
run.pendingSteps.push(appendStep(
|
|
400
|
+
run.pendingSteps.push(appendStep(serverUrl, {
|
|
399
401
|
requestLogId: run.requestLogId,
|
|
400
402
|
stepIndex: stepNumber,
|
|
401
403
|
type: "generate",
|
|
@@ -406,13 +408,13 @@ function createQgridLogger(config) {
|
|
|
406
408
|
finishReason,
|
|
407
409
|
reasoningText: typeof reasoningText === "string" && reasoningText.length > 0 ? reasoningText : void 0,
|
|
408
410
|
reasoningTokens: usage.outputTokenDetails?.reasoningTokens
|
|
409
|
-
}).catch((e) =>
|
|
411
|
+
}).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e)))));
|
|
410
412
|
const toolCalls = content.filter((p) => p.type === "tool-call");
|
|
411
413
|
for (const [i, tc] of toolCalls.entries()) {
|
|
412
414
|
const tr = content.find((p) => p.type === "tool-result" && p.toolCallId === tc.toolCallId);
|
|
413
415
|
const te = content.find((p) => p.type === "tool-error" && p.toolCallId === tc.toolCallId);
|
|
414
416
|
if (tr || te) {
|
|
415
|
-
run.pendingSteps.push(appendStep(
|
|
417
|
+
run.pendingSteps.push(appendStep(serverUrl, {
|
|
416
418
|
requestLogId: run.requestLogId,
|
|
417
419
|
stepIndex: stepNumber,
|
|
418
420
|
type: "tool_call",
|
|
@@ -423,7 +425,7 @@ function createQgridLogger(config) {
|
|
|
423
425
|
toolResult: tr && "output" in tr ? safeStringify(tr.output) : void 0,
|
|
424
426
|
toolDurationMs: run.toolDurations.get(tc.toolCallId),
|
|
425
427
|
error: te && "error" in te ? safeStringify(te.error) : void 0
|
|
426
|
-
}).catch((e) =>
|
|
428
|
+
}).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e)))));
|
|
427
429
|
run.toolDurations.delete(tc.toolCallId);
|
|
428
430
|
} else run.pendingToolCalls.push({
|
|
429
431
|
stepIndex: stepNumber,
|