@lota-sdk/core 0.4.21 → 0.4.22

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": "@lota-sdk/core",
3
- "version": "0.4.21",
3
+ "version": "0.4.22",
4
4
  "files": [
5
5
  "src",
6
6
  "infrastructure/schema"
@@ -31,7 +31,7 @@
31
31
  "@ai-sdk/openai": "^3.0.54",
32
32
  "@chat-adapter/slack": "^4.26.0",
33
33
  "@chat-adapter/state-ioredis": "^4.26.0",
34
- "@lota-sdk/shared": "0.4.21",
34
+ "@lota-sdk/shared": "0.4.22",
35
35
  "@mendable/firecrawl-js": "^4.20.0",
36
36
  "@surrealdb/node": "^3.0.3",
37
37
  "ai": "^6.0.170",
@@ -892,6 +892,81 @@ function addAiGatewayReasoningRawChunks(
892
892
  return { ...params, includeRawChunks: true }
893
893
  }
894
894
 
895
+ const JSON_SCHEMA_PROPERTY_MAP_KEYS = new Set([
896
+ '$defs',
897
+ 'definitions',
898
+ 'dependentSchemas',
899
+ 'patternProperties',
900
+ 'properties',
901
+ ])
902
+
903
+ function stripJsonSchemaFormatKeywords(value: unknown): unknown {
904
+ if (Array.isArray(value)) {
905
+ return value.map((item) => stripJsonSchemaFormatKeywords(item))
906
+ }
907
+
908
+ if (!isRecord(value)) {
909
+ return value
910
+ }
911
+
912
+ let changed = false
913
+ const nextValue: Record<string, unknown> = {}
914
+
915
+ for (const [key, child] of Object.entries(value)) {
916
+ if (key === 'format') {
917
+ changed = true
918
+ continue
919
+ }
920
+
921
+ if (JSON_SCHEMA_PROPERTY_MAP_KEYS.has(key) && isRecord(child)) {
922
+ let mapChanged = false
923
+ const nextMap: Record<string, unknown> = {}
924
+ for (const [propertyName, propertySchema] of Object.entries(child)) {
925
+ const nextPropertySchema = stripJsonSchemaFormatKeywords(propertySchema)
926
+ mapChanged ||= nextPropertySchema !== propertySchema
927
+ nextMap[propertyName] = nextPropertySchema
928
+ }
929
+ changed ||= mapChanged
930
+ nextValue[key] = mapChanged ? nextMap : child
931
+ continue
932
+ }
933
+
934
+ const nextChild = stripJsonSchemaFormatKeywords(child)
935
+ changed ||= nextChild !== child
936
+ nextValue[key] = nextChild
937
+ }
938
+
939
+ return changed ? nextValue : value
940
+ }
941
+
942
+ export function normalizeAiGatewayJsonSchemas(params: AiGatewayCallOptions): AiGatewayCallOptions {
943
+ let nextParams = params
944
+
945
+ if (params.responseFormat?.type === 'json' && params.responseFormat.schema) {
946
+ const nextSchema = stripJsonSchemaFormatKeywords(params.responseFormat.schema)
947
+ if (nextSchema !== params.responseFormat.schema) {
948
+ nextParams = { ...nextParams, responseFormat: { ...params.responseFormat, schema: nextSchema } }
949
+ }
950
+ }
951
+
952
+ const sourceTools = nextParams.tools
953
+ if (!Array.isArray(sourceTools)) {
954
+ return nextParams
955
+ }
956
+
957
+ const nextTools = sourceTools.map((tool) => {
958
+ if (!isRecord(tool) || tool.type !== 'function') {
959
+ return tool
960
+ }
961
+
962
+ const inputSchema = (tool as { inputSchema: unknown }).inputSchema
963
+ const nextInputSchema = stripJsonSchemaFormatKeywords(inputSchema)
964
+ return { ...tool, inputSchema: nextInputSchema }
965
+ })
966
+
967
+ return { ...nextParams, tools: nextTools as AiGatewayCallOptions['tools'] }
968
+ }
969
+
895
970
  function resolveProviderModel(
896
971
  provider: ReturnType<typeof createOpenAI>,
897
972
  modelId: string,
@@ -942,7 +1017,9 @@ function createAiGatewayLanguageModelMiddleware(
942
1017
  Promise.resolve(
943
1018
  withDefaultAiGatewayCacheHeaders(
944
1019
  addAiGatewayReasoningRawChunks(
945
- providerId === OPENAI_CHAT_PROVIDER_ID ? normalizeAiGatewayChatProviderOptions(params, modelId) : params,
1020
+ normalizeAiGatewayJsonSchemas(
1021
+ providerId === OPENAI_CHAT_PROVIDER_ID ? normalizeAiGatewayChatProviderOptions(params, modelId) : params,
1022
+ ),
946
1023
  type,
947
1024
  ),
948
1025
  ),
@@ -14,6 +14,7 @@ export {
14
14
  injectAiGatewayChatReasoningContent,
15
15
  injectAiGatewayChatReasoningStream,
16
16
  normalizeAiGatewayChatProviderOptions,
17
+ normalizeAiGatewayJsonSchemas,
17
18
  normalizeAiGatewayUrl,
18
19
  } from './ai-gateway'
19
20
  export type { AiGatewayDeps, AiGatewayModels, RuntimeBridge } from './ai-gateway'