@cartanova/qgrid-ai-sdk 2.7.6 → 2.7.9
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.js +16 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -693,6 +693,14 @@ const DEFAULT_RUN_KEY = "__qgrid_default_run__";
|
|
|
693
693
|
const DEFAULT_STALE_RUN_TIMEOUT_MS = 1800 * 1e3;
|
|
694
694
|
const STALE_RUN_GRACE_MS = 5e3;
|
|
695
695
|
const OVERLAPPING_RUN_ERROR = "createQgridLogger received overlapping runs for the same telemetry key. Pass a unique metadata.qgridRunId per AI SDK call or create a fresh logger integration per call.";
|
|
696
|
+
function isParseableJson(value) {
|
|
697
|
+
try {
|
|
698
|
+
JSON.parse(value ?? "");
|
|
699
|
+
return true;
|
|
700
|
+
} catch {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
696
704
|
function fullModelName(provider, modelId) {
|
|
697
705
|
if (!provider || !modelId) return void 0;
|
|
698
706
|
const prefix = `${provider.split(".", 1)[0] ?? provider}/`;
|
|
@@ -764,6 +772,7 @@ function createQgridLogger(config = {}) {
|
|
|
764
772
|
totalCacheReadTokens: result.totalUsage?.inputTokenDetails?.cacheReadTokens ?? 0,
|
|
765
773
|
totalCacheCreationTokens: result.totalUsage?.inputTokenDetails?.cacheWriteTokens ?? 0,
|
|
766
774
|
totalDurationMs: Date.now() - run.startTime,
|
|
775
|
+
...run.isStructured && result.status === "succeeded" ? { responseJsonOk: isParseableJson(result.response) } : {},
|
|
767
776
|
...result.errorMessage ? { errorMessage: result.errorMessage } : {}
|
|
768
777
|
}).catch((e) => onLogError(e instanceof Error ? e : new Error(String(e))));
|
|
769
778
|
};
|
|
@@ -814,12 +823,17 @@ function createQgridLogger(config = {}) {
|
|
|
814
823
|
try {
|
|
815
824
|
const messages = event.messages ?? (Array.isArray(event.prompt) ? event.prompt : void 0);
|
|
816
825
|
const history = serializeHistory(messages);
|
|
826
|
+
const responseFormat = event.output ? await event.output.responseFormat : void 0;
|
|
827
|
+
const isStructured = responseFormat?.type === "json";
|
|
828
|
+
const jsonSchema = isStructured && responseFormat.schema !== void 0 ? JSON.stringify(responseFormat.schema) ?? null : null;
|
|
817
829
|
const result = await createRun(serverUrl, {
|
|
818
830
|
userPrompt: extractUserPrompt(event.prompt, messages),
|
|
819
831
|
systemPrompt: extractSystemPrompt(event.system),
|
|
820
832
|
modelName: requestedModelName,
|
|
821
833
|
projectName,
|
|
822
|
-
history
|
|
834
|
+
history,
|
|
835
|
+
isStructured,
|
|
836
|
+
jsonSchema
|
|
823
837
|
});
|
|
824
838
|
if (reservation.errorMessage || quarantined.has(runKey) || starting.get(runKey) !== reservation) {
|
|
825
839
|
if (starting.get(runKey) === reservation) starting.delete(runKey);
|
|
@@ -873,6 +887,7 @@ function createQgridLogger(config = {}) {
|
|
|
873
887
|
runs.set(runKey, {
|
|
874
888
|
requestLogId: result.requestLogId,
|
|
875
889
|
requestedModelName,
|
|
890
|
+
isStructured,
|
|
876
891
|
pendingSteps: [],
|
|
877
892
|
pendingToolCalls: [],
|
|
878
893
|
startTime: Date.now(),
|