@falai/agent 3.1.1 → 3.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/dist/cjs/core/ResponseModal.d.ts +14 -7
- package/dist/cjs/core/ResponseModal.d.ts.map +1 -1
- package/dist/cjs/core/ResponseModal.js +37 -17
- package/dist/cjs/core/ResponseModal.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/DeepSeekProvider.d.ts +7 -1
- package/dist/cjs/providers/DeepSeekProvider.d.ts.map +1 -1
- package/dist/cjs/providers/DeepSeekProvider.js +1 -0
- package/dist/cjs/providers/DeepSeekProvider.js.map +1 -1
- package/dist/cjs/providers/GeminiProvider.d.ts +8 -0
- package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/GeminiProvider.js +1 -0
- package/dist/cjs/providers/GeminiProvider.js.map +1 -1
- package/dist/cjs/providers/GenericOpenAICompatibleProvider.d.ts +6 -1
- package/dist/cjs/providers/GenericOpenAICompatibleProvider.d.ts.map +1 -1
- package/dist/cjs/providers/GenericOpenAICompatibleProvider.js +1 -0
- package/dist/cjs/providers/GenericOpenAICompatibleProvider.js.map +1 -1
- package/dist/cjs/providers/OpenAICompatibleProvider.d.ts +23 -0
- package/dist/cjs/providers/OpenAICompatibleProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenAICompatibleProvider.js +1 -0
- package/dist/cjs/providers/OpenAICompatibleProvider.js.map +1 -1
- package/dist/cjs/providers/OpenRouterProvider.d.ts +9 -1
- package/dist/cjs/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenRouterProvider.js +1 -0
- package/dist/cjs/providers/OpenRouterProvider.js.map +1 -1
- package/dist/cjs/providers/ProviderAdapter.d.ts +18 -1
- package/dist/cjs/providers/ProviderAdapter.d.ts.map +1 -1
- package/dist/cjs/providers/ProviderAdapter.js +22 -0
- package/dist/cjs/providers/ProviderAdapter.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +1 -1
- package/dist/cjs/providers/index.d.ts.map +1 -1
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +2 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/json.d.ts +14 -0
- package/dist/cjs/utils/json.d.ts.map +1 -1
- package/dist/cjs/utils/json.js +62 -0
- package/dist/cjs/utils/json.js.map +1 -1
- package/dist/core/ResponseModal.d.ts +14 -7
- package/dist/core/ResponseModal.d.ts.map +1 -1
- package/dist/core/ResponseModal.js +38 -18
- package/dist/core/ResponseModal.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/DeepSeekProvider.d.ts +7 -1
- package/dist/providers/DeepSeekProvider.d.ts.map +1 -1
- package/dist/providers/DeepSeekProvider.js +1 -0
- package/dist/providers/DeepSeekProvider.js.map +1 -1
- package/dist/providers/GeminiProvider.d.ts +8 -0
- package/dist/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/GeminiProvider.js +1 -0
- package/dist/providers/GeminiProvider.js.map +1 -1
- package/dist/providers/GenericOpenAICompatibleProvider.d.ts +6 -1
- package/dist/providers/GenericOpenAICompatibleProvider.d.ts.map +1 -1
- package/dist/providers/GenericOpenAICompatibleProvider.js +1 -0
- package/dist/providers/GenericOpenAICompatibleProvider.js.map +1 -1
- package/dist/providers/OpenAICompatibleProvider.d.ts +23 -0
- package/dist/providers/OpenAICompatibleProvider.d.ts.map +1 -1
- package/dist/providers/OpenAICompatibleProvider.js +1 -0
- package/dist/providers/OpenAICompatibleProvider.js.map +1 -1
- package/dist/providers/OpenRouterProvider.d.ts +9 -1
- package/dist/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/providers/OpenRouterProvider.js +1 -0
- package/dist/providers/OpenRouterProvider.js.map +1 -1
- package/dist/providers/ProviderAdapter.d.ts +18 -1
- package/dist/providers/ProviderAdapter.d.ts.map +1 -1
- package/dist/providers/ProviderAdapter.js +23 -1
- package/dist/providers/ProviderAdapter.js.map +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/json.d.ts +14 -0
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js +61 -0
- package/dist/utils/json.js.map +1 -1
- package/docs/reference/providers.md +39 -0
- package/package.json +2 -2
- package/src/core/ResponseModal.ts +45 -25
- package/src/index.ts +4 -0
- package/src/providers/DeepSeekProvider.ts +8 -1
- package/src/providers/GeminiProvider.ts +9 -0
- package/src/providers/GenericOpenAICompatibleProvider.ts +7 -0
- package/src/providers/OpenAICompatibleProvider.ts +25 -0
- package/src/providers/OpenRouterProvider.ts +10 -1
- package/src/providers/ProviderAdapter.ts +26 -0
- package/src/providers/index.ts +1 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/json.ts +61 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderAdapter.js","sourceRoot":"","sources":["../../src/providers/ProviderAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,sBAAsB,EACtB,WAAW,EACX,eAAe,
|
|
1
|
+
{"version":3,"file":"ProviderAdapter.js","sourceRoot":"","sources":["../../src/providers/ProviderAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,aAAa,EACb,QAAQ,EACR,gBAAgB,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AE,KAAK,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;QACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,UAAU,GAAG;gBACX,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;gBACrB,OAAO,EAAG,UAAkD,EAAE,OAAO,IAAI,GAAG,CAAC,IAAI;gBACjF,SAAS;aACK,CAAC;QACnB,CAAC;QAED,4EAA4E;QAC5E,yEAAyE;QACzE,yEAAyE;QACzE,sBAAsB,CAAC,UAAU,EAAE,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAE1E,MAAM;YACJ,KAAK,EAAE,EAAE;YACT,WAAW,EAAE,GAAG,CAAC,IAAI;YACrB,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE;gBACR,KAAK,EAAE,GAAG,CAAC,KAAK;gBAChB,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC/D,GAAG,CAAC,GAAG,CAAC,YAAY,KAAK,SAAS;oBAChC,CAAC,CAAC;wBACE,UAAU,EAAE,GAAG,CAAC,YAAY,GAAG,CAAC,GAAG,CAAC,gBAAgB,IAAI,CAAC,CAAC;wBAC1D,YAAY,EAAE,GAAG,CAAC,YAAY;wBAC9B,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;wBACtC,+DAA+D;wBAC/D,uDAAuD;wBACvD,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;qBACzC;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;YACD,UAAU;SACX,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -16,7 +16,7 @@ export type { OpenRouterProviderOptions } from "./OpenRouterProvider.js";
|
|
|
16
16
|
export { DeepSeekProvider } from "./DeepSeekProvider.js";
|
|
17
17
|
export type { DeepSeekProviderOptions } from "./DeepSeekProvider.js";
|
|
18
18
|
export { OpenAICompatibleProvider } from "./OpenAICompatibleProvider.js";
|
|
19
|
-
export type { OpenAICompatibleProviderInit, StructuredOutputMode, } from "./OpenAICompatibleProvider.js";
|
|
19
|
+
export type { JsonWithTools, OpenAICompatibleProviderInit, StructuredOutputMode, } from "./OpenAICompatibleProvider.js";
|
|
20
20
|
export { createOpenAICompatibleProvider } from "./GenericOpenAICompatibleProvider.js";
|
|
21
21
|
export type { OpenAICompatibleOptions } from "./GenericOpenAICompatibleProvider.js";
|
|
22
22
|
export { ProviderAdapter, resolveRetryConfig } from "./ProviderAdapter.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,YAAY,EACV,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,YAAY,EAAE,uBAA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":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAOzE,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAGtF,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export { historyItemToEvent, historyToEvents, eventToHistoryItem, eventsToHistor
|
|
|
10
10
|
export { LoggerLevel, logger } from "./logger.js";
|
|
11
11
|
export { effectiveMessageText, assertUsableCompletion } from "./completion.js";
|
|
12
12
|
export { ConditionEvaluator, createConditionEvaluator, extractAIContextStrings, hasProgrammaticConditions, } from "./condition.js";
|
|
13
|
-
export { parseJSONResponse, tryParseJSONResponse } from "./json.js";
|
|
13
|
+
export { parseJSONResponse, tryParseJSONResponse, extractEmbeddedJSONObject } from "./json.js";
|
|
14
14
|
export { serializeToolResult, isToolResultLike, extractResultDirectives } from "./serialize.js";
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,cAAc,EACd,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,4BAA4B,EAC5B,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,MAAM,EACN,UAAU,EACV,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAGvD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAG/E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,cAAc,EACd,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,4BAA4B,EAC5B,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,MAAM,EACN,UAAU,EACV,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAGvD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAG/E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAG/F,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { effectiveMessageText, assertUsableCompletion } from "./completion.js";
|
|
|
20
20
|
// Condition utilities
|
|
21
21
|
export { ConditionEvaluator, createConditionEvaluator, extractAIContextStrings, hasProgrammaticConditions, } from "./condition.js";
|
|
22
22
|
// JSON utilities
|
|
23
|
-
export { parseJSONResponse, tryParseJSONResponse } from "./json.js";
|
|
23
|
+
export { parseJSONResponse, tryParseJSONResponse, extractEmbeddedJSONObject } from "./json.js";
|
|
24
24
|
// Serialization utilities
|
|
25
25
|
export { serializeToolResult, isToolResultLike, extractResultDirectives } from "./serialize.js";
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,gBAAgB;AAChB,OAAO,EACL,cAAc,EACd,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,qBAAqB;AACrB,OAAO,EACL,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,4BAA4B,EAC5B,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,qBAAqB;AACrB,OAAO,EACL,MAAM,EACN,UAAU,EACV,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB,oBAAoB;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,kBAAkB;AAClB,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,oBAAoB;AACpB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,UAAU;AACV,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAElD,qBAAqB;AACrB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE/E,sBAAsB;AACtB,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,iBAAiB;AACjB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,gBAAgB;AAChB,OAAO,EACL,cAAc,EACd,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,qBAAqB;AACrB,OAAO,EACL,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,4BAA4B,EAC5B,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,qBAAqB;AACrB,OAAO,EACL,MAAM,EACN,UAAU,EACV,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB,oBAAoB;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,kBAAkB;AAClB,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,oBAAoB;AACpB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,UAAU;AACV,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAElD,qBAAqB;AACrB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE/E,sBAAsB;AACtB,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,iBAAiB;AACjB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAE/F,0BAA0B;AAC1B,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/utils/json.d.ts
CHANGED
|
@@ -13,4 +13,18 @@ export declare function parseJSONResponse(text: string): unknown;
|
|
|
13
13
|
* Safely parse JSON response, returning undefined on failure
|
|
14
14
|
*/
|
|
15
15
|
export declare function tryParseJSONResponse(text: string): unknown;
|
|
16
|
+
/**
|
|
17
|
+
* Find a complete JSON object embedded in surrounding text.
|
|
18
|
+
*
|
|
19
|
+
* {@link parseJSONResponse} requires the WHOLE string to be the object. A model
|
|
20
|
+
* told to answer in JSON sometimes answers twice instead — the conversational
|
|
21
|
+
* text for the user, and then the protocol envelope repeating it — and such a
|
|
22
|
+
* turn parses as nothing, so the envelope travels on as user-visible content.
|
|
23
|
+
* This scans for the first balanced `{...}` that parses as an object, ignoring
|
|
24
|
+
* braces that sit inside string literals.
|
|
25
|
+
*
|
|
26
|
+
* Returns `undefined` when no complete object is present (prose that merely
|
|
27
|
+
* contains a brace, or an envelope truncated before its closing brace).
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractEmbeddedJSONObject(text: string): Record<string, unknown> | undefined;
|
|
16
30
|
//# sourceMappingURL=json.d.ts.map
|
package/dist/utils/json.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAuBvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM1D"}
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAuBvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAkB3F"}
|
package/dist/utils/json.js
CHANGED
|
@@ -40,4 +40,65 @@ export function tryParseJSONResponse(text) {
|
|
|
40
40
|
return undefined;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Find a complete JSON object embedded in surrounding text.
|
|
45
|
+
*
|
|
46
|
+
* {@link parseJSONResponse} requires the WHOLE string to be the object. A model
|
|
47
|
+
* told to answer in JSON sometimes answers twice instead — the conversational
|
|
48
|
+
* text for the user, and then the protocol envelope repeating it — and such a
|
|
49
|
+
* turn parses as nothing, so the envelope travels on as user-visible content.
|
|
50
|
+
* This scans for the first balanced `{...}` that parses as an object, ignoring
|
|
51
|
+
* braces that sit inside string literals.
|
|
52
|
+
*
|
|
53
|
+
* Returns `undefined` when no complete object is present (prose that merely
|
|
54
|
+
* contains a brace, or an envelope truncated before its closing brace).
|
|
55
|
+
*/
|
|
56
|
+
export function extractEmbeddedJSONObject(text) {
|
|
57
|
+
if (!text)
|
|
58
|
+
return undefined;
|
|
59
|
+
for (let start = text.indexOf("{"); start !== -1; start = text.indexOf("{", start + 1)) {
|
|
60
|
+
const end = findObjectEnd(text, start);
|
|
61
|
+
if (end === -1)
|
|
62
|
+
continue;
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(text.slice(start, end + 1));
|
|
65
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
66
|
+
return parsed;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Not an object after all — keep scanning for a later candidate.
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Index of the `}` closing the object that opens at `start`, or -1 when the
|
|
77
|
+
* text ends first. Quotes and their escapes are tracked so a brace inside a
|
|
78
|
+
* string value never opens or closes a level.
|
|
79
|
+
*/
|
|
80
|
+
function findObjectEnd(text, start) {
|
|
81
|
+
let depth = 0;
|
|
82
|
+
let inString = false;
|
|
83
|
+
let escaped = false;
|
|
84
|
+
for (let i = start; i < text.length; i++) {
|
|
85
|
+
const ch = text[i];
|
|
86
|
+
if (inString) {
|
|
87
|
+
if (escaped)
|
|
88
|
+
escaped = false;
|
|
89
|
+
else if (ch === "\\")
|
|
90
|
+
escaped = true;
|
|
91
|
+
else if (ch === '"')
|
|
92
|
+
inString = false;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (ch === '"')
|
|
96
|
+
inString = true;
|
|
97
|
+
else if (ch === "{")
|
|
98
|
+
depth++;
|
|
99
|
+
else if (ch === "}" && --depth === 0)
|
|
100
|
+
return i;
|
|
101
|
+
}
|
|
102
|
+
return -1;
|
|
103
|
+
}
|
|
43
104
|
//# sourceMappingURL=json.js.map
|
package/dist/utils/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IAED,kBAAkB;IAClB,IAAI,OAAO,GAAG,IAAI,CAAC,I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G,CAAC,CAAC,CAAC,CAAC;YACtD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC5E,OAAO,MAAiC,CAAC;YAC3C,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,iEAAiE;QACnE,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,IAAY,EAAE,KAAa;IAChD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEnB,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,OAAO;gBAAE,OAAO,GAAG,KAAK,CAAC;iBACxB,IAAI,EAAE,KAAK,IAAI;gBAAE,OAAO,GAAG,IAAI,CAAC;iBAChC,IAAI,EAAE,KAAK,GAAG;gBAAE,QAAQ,GAAG,KAAK,CAAC;YACtC,SAAS;QACX,CAAC;QAED,IAAI,EAAE,KAAK,GAAG;YAAE,QAAQ,GAAG,IAAI,CAAC;aAC3B,IAAI,EAAE,KAAK,GAAG;YAAE,KAAK,EAAE,CAAC;aACxB,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,KAAK,CAAC;YAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC"}
|
|
@@ -49,6 +49,39 @@ The five built-ins:
|
|
|
49
49
|
|
|
50
50
|
The two asymmetries: Anthropic reports `supportsNativeJsonSchema: false` because its JSON output is enforced via a prompt instruction, not a native schema mode — and it is the only built-in that reports `supportsPromptCaching: true`.
|
|
51
51
|
|
|
52
|
+
These flags describe the vendor. What a given **model** does is a separate question, and one of them will cost you a production agent if you guess it — see below.
|
|
53
|
+
|
|
54
|
+
## When the agent narrates a tool instead of calling it
|
|
55
|
+
|
|
56
|
+
The symptom: the model answers a turn that clearly needs a tool by *describing* the tool call — _"let me look that price up for you"_ — and stops. The tool handler never runs. It looks like a model with no initiative, and no instruction fixes it.
|
|
57
|
+
|
|
58
|
+
It is not the prompt. Every turn this framework sends carries a response schema, because that is how `message` and `collect` fields come back. Some models cannot emit a tool call while their output is pinned to a schema: the call has nowhere to go, so they write the announcement instead. Nothing fails, nothing is logged, and the turn succeeds on the wire.
|
|
59
|
+
|
|
60
|
+
Measured 2026-09-07, same request, sampled:
|
|
61
|
+
|
|
62
|
+
| model | tool called | with `jsonWithTools: "prompt"` |
|
|
63
|
+
|-------|-------------|-------------------------------|
|
|
64
|
+
| `z-ai/glm-5.3-flash` | 0/10 | 8/8 |
|
|
65
|
+
| `deepseek-v4-flash-0731` | 0/5 | — |
|
|
66
|
+
| `gemini-3.8-flash` | 3/10 | — |
|
|
67
|
+
| `gemini-3.5-flash-lite` | 10/10 | 6/6 |
|
|
68
|
+
| `gpt-5.6-luna` | 10/10 | 6/6 |
|
|
69
|
+
| `qwen3.8-flash` | 10/10 | 1/6 |
|
|
70
|
+
|
|
71
|
+
`jsonWithTools: "prompt"` on `OpenRouterProvider`, `DeepSeekProvider`, `GeminiProvider` or `createOpenAICompatibleProvider` leaves the response format off the calls that carry tools and sends the schema as prompt there instead. Calls without tools are untouched.
|
|
72
|
+
|
|
73
|
+
Do not pick it from the table — the qwen row is why. Ask the model, once, at boot:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { probeJsonWithTools } from "@providerkit/core";
|
|
77
|
+
|
|
78
|
+
const probe = await probeJsonWithTools(provider);
|
|
79
|
+
// { use: "prompt", calls: { response_format: 0, prompt: 3 }, samples: 3 }
|
|
80
|
+
if (!probe.use) throw new Error("this model cannot use tools with a schema at all");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Log `calls`, not just `use`. `0/3 and 3/3` is what makes the next model swap's regression obvious.
|
|
84
|
+
|
|
52
85
|
## Use with createAgent
|
|
53
86
|
|
|
54
87
|
`createAgent({ provider })` accepts any class that implements `AiProvider`. Swap providers by changing the constructor; nothing else in your agent has to move.
|
|
@@ -89,6 +122,7 @@ interface GeminiProviderOptions {
|
|
|
89
122
|
model: string;
|
|
90
123
|
backupModels?: string[];
|
|
91
124
|
baseUrl?: string;
|
|
125
|
+
jsonWithTools?: "response_format" | "prompt";
|
|
92
126
|
config?: RequestConfig; // temperature, topP, maxTokens, stopSequences
|
|
93
127
|
retryConfig?: { timeout?: number; retries?: number };
|
|
94
128
|
fetchImpl?: typeof fetch; // scripted wire, for tests
|
|
@@ -102,6 +136,7 @@ interface GeminiProviderOptions {
|
|
|
102
136
|
| `apiKey` | `string` | yes* | — | Throws if empty (unless `client` is set). |
|
|
103
137
|
| `model` | `string` | yes | — | Use the model id, e.g. `"gemini-3.1-pro-preview"`. |
|
|
104
138
|
| `backupModels` | `string[]` | no | `[]` | Tried in order on retriable failures (rate limits, overload, timeouts, network). |
|
|
139
|
+
| `jsonWithTools` | `"response_format" \| "prompt"` | no | `"response_format"` | How the schema rides on calls that also carry tools. `gemini-3.5-flash` and `-flash-lite` need nothing; `gemini-3.8-flash` measured 3/10 — [see above](#when-the-agent-narrates-a-tool-instead-of-calling-it). |
|
|
105
140
|
| `config` | `Partial<GenerateContentConfig>` | no | — | Vendor-typed defaults (e.g. `temperature`, `systemInstruction`). |
|
|
106
141
|
| `retryConfig.timeout` | `number` | no | `60000` | Per-attempt timeout in ms. On streams it also bounds time-to-first-token. |
|
|
107
142
|
| `retryConfig.retries` | `number` | no | `3` | Total attempts before giving up. |
|
|
@@ -212,6 +247,7 @@ interface OpenRouterProviderOptions {
|
|
|
212
247
|
backupModels?: string[];
|
|
213
248
|
siteUrl?: string;
|
|
214
249
|
siteName?: string;
|
|
250
|
+
jsonWithTools?: "response_format" | "prompt";
|
|
215
251
|
config?: Partial<Omit<ChatCompletionCreateParamsNonStreaming, "model" | "messages">>;
|
|
216
252
|
retryConfig?: { timeout?: number; retries?: number };
|
|
217
253
|
}
|
|
@@ -226,6 +262,7 @@ interface OpenRouterProviderOptions {
|
|
|
226
262
|
| `backupModels` | `string[]` | no | `[]` | Tried in order on overload/capacity errors. |
|
|
227
263
|
| `siteUrl` | `string` | no | `""` | Sent as `HTTP-Referer` for OpenRouter rankings. |
|
|
228
264
|
| `siteName` | `string` | no | `""` | Sent as `X-Title` for OpenRouter rankings. |
|
|
265
|
+
| `jsonWithTools` | `"response_format" \| "prompt"` | no | `"response_format"` | How the schema rides on calls that also carry tools. One gateway, hundreds of models, and they disagree — [see above](#when-the-agent-narrates-a-tool-instead-of-calling-it). |
|
|
229
266
|
| `config` | OpenAI params | no | — | OpenAI-shaped defaults (forwarded to OpenRouter). |
|
|
230
267
|
| `retryConfig.timeout` | `number` | no | `60000` | Per-attempt timeout in ms. |
|
|
231
268
|
| `retryConfig.retries` | `number` | no | `3` | Total attempts. |
|
|
@@ -255,6 +292,7 @@ interface DeepSeekProviderOptions {
|
|
|
255
292
|
model: string;
|
|
256
293
|
backupModels?: string[];
|
|
257
294
|
baseURL?: string;
|
|
295
|
+
jsonWithTools?: "response_format" | "prompt";
|
|
258
296
|
config?: Partial<Omit<ChatCompletionCreateParamsNonStreaming, "model" | "messages">>;
|
|
259
297
|
retryConfig?: { timeout?: number; retries?: number };
|
|
260
298
|
}
|
|
@@ -267,6 +305,7 @@ interface DeepSeekProviderOptions {
|
|
|
267
305
|
| `apiKey` | `string` | yes | — | Throws if empty. |
|
|
268
306
|
| `model` | `string` | yes | — | e.g. `"deepseek-chat"`, `"deepseek-reasoner"`. |
|
|
269
307
|
| `backupModels` | `string[]` | no | `[]` | Tried in order on overload/rate-limit errors. |
|
|
308
|
+
| `jsonWithTools` | `"response_format" \| "prompt"` | no | `"response_format"` | Reach for it here first: the measured DeepSeek flash models called a tool 0/5 under a response format — [see above](#when-the-agent-narrates-a-tool-instead-of-calling-it). |
|
|
270
309
|
| `baseURL` | `string` | no | `"https://api.deepseek.com"` | Custom endpoint for self-hosted or proxy deployments. |
|
|
271
310
|
| `config` | OpenAI params | no | — | OpenAI-shaped defaults (forwarded to DeepSeek). |
|
|
272
311
|
| `retryConfig.timeout` | `number` | no | `60000` | Per-attempt timeout in ms. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@falai/agent",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Conversational state engine for TypeScript where the AI understands, but the code is in control",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"typescript-eslint": "^8.18.2"
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"@providerkit/core": "^0.
|
|
95
|
+
"@providerkit/core": "^0.5.0",
|
|
96
96
|
"loglevel": "^1.9.2"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
@@ -45,7 +45,7 @@ import { ProviderError, SessionConflictError } from "../types/errors.js";
|
|
|
45
45
|
import { cloneDeep, mergeCollected, logger, historyToEvents, completeCurrentFlow, render, userMessage, assistantMessage } from "../utils/index.js";
|
|
46
46
|
import { createTemplateContext } from "../utils/template.js";
|
|
47
47
|
import { StreamingMessageDecoder } from "../utils/streamingMessage.js";
|
|
48
|
-
import { tryParseJSONResponse } from "../utils/json.js";
|
|
48
|
+
import { extractEmbeddedJSONObject, tryParseJSONResponse } from "../utils/json.js";
|
|
49
49
|
import type { ToolManager } from "./ToolManager.js";
|
|
50
50
|
|
|
51
51
|
/**
|
|
@@ -459,31 +459,46 @@ export class ResponseModal<TContext = unknown, TData = unknown> {
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
/**
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
462
|
+
* Recover a structured payload from a schema-mandated response the provider
|
|
463
|
+
* could not parse. Raw protocol fragments must never surface as the
|
|
464
|
+
* user-visible reply. Three shapes arrive here:
|
|
465
|
+
* - a truncated or fence-wrapped envelope → one repair-parse;
|
|
466
|
+
* - conversational prose FOLLOWED BY the envelope (the model answered
|
|
467
|
+
* twice — the observed WhatsApp leak) → recover the embedded envelope,
|
|
468
|
+
* whose "message" field is the complete intended reply;
|
|
469
|
+
* - plain prose with nothing recoverable → `undefined`; the caller passes
|
|
470
|
+
* it through untouched. (An envelope truncated mid-stream after prose
|
|
471
|
+
* also lands here: the prose is user-worthy and the fragment carries
|
|
472
|
+
* nothing recoverable.)
|
|
473
|
+
* An unrecoverable JSON-SHAPED fragment throws so the turn fails LOUDLY
|
|
474
|
+
* and the caller's rollback/retry path engages instead of leaking
|
|
475
|
+
* `{"message": "…` to an end user.
|
|
469
476
|
*/
|
|
470
477
|
private salvageStructuredOutput(
|
|
471
478
|
raw: string,
|
|
472
479
|
surface: "turn" | "stream"
|
|
473
|
-
): AgentStructuredResponse {
|
|
480
|
+
): AgentStructuredResponse | undefined {
|
|
474
481
|
const salvaged = tryParseJSONResponse(raw) as Partial<AgentStructuredResponse> | undefined;
|
|
475
482
|
if (salvaged && typeof salvaged.message === "string") {
|
|
476
483
|
logger.warn(`[ResponseModal] Salvaged malformed structured output from ${surface} via JSON repair parse.`);
|
|
477
484
|
return { ...salvaged, message: salvaged.message };
|
|
478
485
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
486
|
+
const embedded = extractEmbeddedJSONObject(raw) as Partial<AgentStructuredResponse> | undefined;
|
|
487
|
+
if (embedded && typeof embedded.message === "string") {
|
|
488
|
+
logger.warn(`[ResponseModal] Salvaged structured output embedded after prose from ${surface}.`);
|
|
489
|
+
return { ...embedded, message: embedded.message };
|
|
490
|
+
}
|
|
491
|
+
if (/^\s*(```|{)/.test(raw)) {
|
|
492
|
+
throw ResponseGenerationError.fromError(
|
|
493
|
+
new Error(
|
|
494
|
+
"Model returned a schema-mandated response that could not be parsed as JSON. " +
|
|
495
|
+
`The ${surface} was failed instead of delivering raw protocol output to the user.`
|
|
496
|
+
),
|
|
497
|
+
'structured_output_malformed',
|
|
498
|
+
{ responseSchemaName: 'response_output' }
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
return undefined;
|
|
487
502
|
}
|
|
488
503
|
|
|
489
504
|
/**
|
|
@@ -1073,10 +1088,12 @@ export class ResponseModal<TContext = unknown, TData = unknown> {
|
|
|
1073
1088
|
// rollback/retry path engages instead of leaking `{"message": "…` to
|
|
1074
1089
|
// an end user. Plain prose (not JSON-shaped at all) still passes
|
|
1075
1090
|
// through — it is not a protocol fragment.
|
|
1076
|
-
if (!structuredData && responseSchema && message
|
|
1091
|
+
if (!structuredData && responseSchema && message) {
|
|
1077
1092
|
const salvaged = this.salvageStructuredOutput(message, "turn");
|
|
1078
|
-
|
|
1079
|
-
|
|
1093
|
+
if (salvaged) {
|
|
1094
|
+
structuredData = salvaged;
|
|
1095
|
+
message = salvaged.message;
|
|
1096
|
+
}
|
|
1080
1097
|
}
|
|
1081
1098
|
|
|
1082
1099
|
const effectiveResult = structuredData ? { ...result, structured: structuredData } : result;
|
|
@@ -1467,12 +1484,15 @@ export class ResponseModal<TContext = unknown, TData = unknown> {
|
|
|
1467
1484
|
// requested but no structured payload arrived, and the accumulated
|
|
1468
1485
|
// text is JSON-shaped (a protocol fragment) — repair-parse it or
|
|
1469
1486
|
// fail the turn rather than leaking raw output to the user.
|
|
1470
|
-
if (chunk.done && !finalStructured && responseSchema && finalAccumulated
|
|
1487
|
+
if (chunk.done && !finalStructured && responseSchema && finalAccumulated) {
|
|
1471
1488
|
const salvaged = this.salvageStructuredOutput(finalAccumulated, "stream");
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1489
|
+
if (salvaged) {
|
|
1490
|
+
finalDelta = salvaged.message.startsWith(finalAccumulated)
|
|
1491
|
+
? salvaged.message.slice(finalAccumulated.length)
|
|
1492
|
+
: salvaged.message;
|
|
1493
|
+
finalStructured = salvaged;
|
|
1494
|
+
finalAccumulated = salvaged.message;
|
|
1495
|
+
}
|
|
1476
1496
|
}
|
|
1477
1497
|
|
|
1478
1498
|
// Collect data on the final chunk for any flow step — flow
|
package/src/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ export type { DeepSeekProviderOptions } from "./providers/DeepSeekProvider.js";
|
|
|
36
36
|
// Base class for building OpenAI-compatible providers (Groq, Together, etc.)
|
|
37
37
|
export { OpenAICompatibleProvider } from "./providers/OpenAICompatibleProvider.js";
|
|
38
38
|
export type {
|
|
39
|
+
JsonWithTools,
|
|
39
40
|
OpenAICompatibleProviderInit,
|
|
40
41
|
StructuredOutputMode,
|
|
41
42
|
} from "./providers/OpenAICompatibleProvider.js";
|
|
@@ -44,6 +45,9 @@ export type { OpenAICompatibleOptions } from "./providers/GenericOpenAICompatibl
|
|
|
44
45
|
// The bridge every provider above is built on — subclass it to bind any
|
|
45
46
|
// `@providerkit/core` provider to this framework's seam.
|
|
46
47
|
export { ProviderAdapter, resolveRetryConfig } from "./providers/ProviderAdapter.js";
|
|
48
|
+
// The probe's own shapes, re-exported so a consumer reading `probeJsonWithTools`
|
|
49
|
+
// off a provider does not have to add `@providerkit/core` to see its result.
|
|
50
|
+
export type { JsonWithToolsProbe, ProbeOptions } from "@providerkit/core";
|
|
47
51
|
export type {
|
|
48
52
|
ProviderAdapterInit,
|
|
49
53
|
RequestConfig,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { ProviderCapabilities } from "../types/ai.js";
|
|
8
|
-
import { OpenAICompatibleProvider } from "./OpenAICompatibleProvider.js";
|
|
8
|
+
import { OpenAICompatibleProvider, type JsonWithTools } from "./OpenAICompatibleProvider.js";
|
|
9
9
|
import type { RequestConfig } from "./ProviderAdapter.js";
|
|
10
10
|
|
|
11
11
|
export interface DeepSeekProviderOptions {
|
|
@@ -19,6 +19,12 @@ export interface DeepSeekProviderOptions {
|
|
|
19
19
|
baseURL?: string;
|
|
20
20
|
/** Request defaults sent with every call */
|
|
21
21
|
config?: RequestConfig;
|
|
22
|
+
/**
|
|
23
|
+
* See {@link JsonWithTools} — and reach for it here first. The measured
|
|
24
|
+
* DeepSeek flash models called a tool 0/5 with the schema on the response
|
|
25
|
+
* format, and narrated it instead.
|
|
26
|
+
*/
|
|
27
|
+
jsonWithTools?: JsonWithTools;
|
|
22
28
|
/** Idle-stream deadline and retry budget */
|
|
23
29
|
retryConfig?: { timeout?: number; retries?: number };
|
|
24
30
|
/** Replacement `fetch`, for tests that script the wire. */
|
|
@@ -48,6 +54,7 @@ export class DeepSeekProvider extends OpenAICompatibleProvider {
|
|
|
48
54
|
model: options.model,
|
|
49
55
|
// No Responses API here; chat completions enforces the schema natively.
|
|
50
56
|
structuredOutput: "json_schema",
|
|
57
|
+
...(options.jsonWithTools ? { jsonWithTools: options.jsonWithTools } : {}),
|
|
51
58
|
...(options.backupModels ? { backupModels: options.backupModels } : {}),
|
|
52
59
|
...(options.config ? { config: options.config } : {}),
|
|
53
60
|
...(options.retryConfig ? { retryConfig: options.retryConfig } : {}),
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { createGeminiProvider } from "@providerkit/core";
|
|
14
14
|
|
|
15
15
|
import type { ProviderCapabilities } from "../types/ai.js";
|
|
16
|
+
import type { JsonWithTools } from "./OpenAICompatibleProvider.js";
|
|
16
17
|
import { ProviderAdapter, type RequestConfig } from "./ProviderAdapter.js";
|
|
17
18
|
|
|
18
19
|
export interface GeminiProviderOptions {
|
|
@@ -24,6 +25,13 @@ export interface GeminiProviderOptions {
|
|
|
24
25
|
backupModels?: string[];
|
|
25
26
|
/** Any endpoint speaking the Gemini generateContent dialect. */
|
|
26
27
|
baseUrl?: string;
|
|
28
|
+
/**
|
|
29
|
+
* See {@link JsonWithTools}. The answer is the MODEL's, not the endpoint's:
|
|
30
|
+
* `gemini-3.5-flash` and `-flash-lite` called their tool under
|
|
31
|
+
* `responseJsonSchema` every time, while `gemini-3.8-flash` managed 3/10
|
|
32
|
+
* (2026-09-07). `probeJsonWithTools()` asks the one you serve.
|
|
33
|
+
*/
|
|
34
|
+
jsonWithTools?: JsonWithTools;
|
|
27
35
|
/** Request defaults sent with every call */
|
|
28
36
|
config?: RequestConfig;
|
|
29
37
|
/** Idle-stream deadline and retry budget */
|
|
@@ -55,6 +63,7 @@ export class GeminiProvider extends ProviderAdapter {
|
|
|
55
63
|
model: options.model,
|
|
56
64
|
id: "gemini",
|
|
57
65
|
...(options.baseUrl ? { baseUrl: options.baseUrl } : {}),
|
|
66
|
+
...(options.jsonWithTools ? { jsonWithTools: options.jsonWithTools } : {}),
|
|
58
67
|
...(options.config?.maxTokens ? { maxTokens: options.config.maxTokens } : {}),
|
|
59
68
|
...(options.config?.effort ? { effort: options.config.effort } : {}),
|
|
60
69
|
...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
import type { ProviderCapabilities } from "../types/ai.js";
|
|
30
30
|
import {
|
|
31
31
|
OpenAICompatibleProvider,
|
|
32
|
+
type JsonWithTools,
|
|
32
33
|
type StructuredOutputMode,
|
|
33
34
|
} from "./OpenAICompatibleProvider.js";
|
|
34
35
|
import type { RequestConfig } from "./ProviderAdapter.js";
|
|
@@ -54,6 +55,11 @@ export interface OpenAICompatibleOptions {
|
|
|
54
55
|
* is OpenAI-only). See {@link StructuredOutputMode}.
|
|
55
56
|
*/
|
|
56
57
|
structuredOutput?: StructuredOutputMode;
|
|
58
|
+
/**
|
|
59
|
+
* See {@link JsonWithTools}. Only affects calls that carry tools, and the
|
|
60
|
+
* answer is the model's, not the endpoint's — measure the one you serve.
|
|
61
|
+
*/
|
|
62
|
+
jsonWithTools?: JsonWithTools;
|
|
57
63
|
/** Default request parameters merged into every call. */
|
|
58
64
|
config?: RequestConfig;
|
|
59
65
|
/** Idle-stream deadline (ms) and retry count. */
|
|
@@ -106,6 +112,7 @@ class GenericOpenAICompatibleProvider extends OpenAICompatibleProvider {
|
|
|
106
112
|
// Arbitrary compatible endpoints rarely serve the Responses API; default
|
|
107
113
|
// to the broadly-supported chat json_schema strategy.
|
|
108
114
|
structuredOutput: options.structuredOutput ?? "json_schema",
|
|
115
|
+
...(options.jsonWithTools ? { jsonWithTools: options.jsonWithTools } : {}),
|
|
109
116
|
...(options.defaultHeaders ? { headers: options.defaultHeaders } : {}),
|
|
110
117
|
...(options.backupModels ? { backupModels: options.backupModels } : {}),
|
|
111
118
|
...(options.config ? { config: options.config } : {}),
|
|
@@ -23,6 +23,28 @@ import { ProviderAdapter, type ProviderAdapterInit, type RequestConfig } from ".
|
|
|
23
23
|
*/
|
|
24
24
|
export type StructuredOutputMode = "responses_parse" | "json_schema" | "json_object";
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* How the schema rides on a call that ALSO carries tools — the one turn shape
|
|
28
|
+
* an agent makes constantly and a provider seam cannot get right by itself.
|
|
29
|
+
*
|
|
30
|
+
* `"response_format"` sends both, which every shape documents and most models
|
|
31
|
+
* honour. `"prompt"` leaves the response format off those calls and sends the
|
|
32
|
+
* schema as prompt instead.
|
|
33
|
+
*
|
|
34
|
+
* Set it to `"prompt"` when the model answers a tool-worthy turn by NARRATING
|
|
35
|
+
* the tool — "let me look that up for you" — and then stopping. That is not a
|
|
36
|
+
* model without initiative: its decoder is pinned to the schema, so the tool
|
|
37
|
+
* call has nowhere to go, and no instruction can make it emit one. Nothing is
|
|
38
|
+
* logged, because from the wire's point of view nothing failed.
|
|
39
|
+
*
|
|
40
|
+
* Measured 2026-09-07, one request, sampled: `z-ai/glm-5.3-flash` called its
|
|
41
|
+
* tool 0/10 under a response format and 8/8 without one, `deepseek-v4-flash`
|
|
42
|
+
* 0/5, `gemini-3.8-flash` 3/10. It stays a setting rather than a default
|
|
43
|
+
* because the reverse is just as real — `qwen3.8-flash` went 10/10 → 1/6 the
|
|
44
|
+
* other way. Measure the model you ship; one call answers it.
|
|
45
|
+
*/
|
|
46
|
+
export type JsonWithTools = "response_format" | "prompt";
|
|
47
|
+
|
|
26
48
|
export interface OpenAICompatibleProviderInit
|
|
27
49
|
extends Omit<ProviderAdapterInit, "provider"> {
|
|
28
50
|
apiKey: string;
|
|
@@ -32,6 +54,8 @@ export interface OpenAICompatibleProviderInit
|
|
|
32
54
|
headers?: Record<string, string>;
|
|
33
55
|
config?: RequestConfig;
|
|
34
56
|
structuredOutput?: StructuredOutputMode;
|
|
57
|
+
/** See {@link JsonWithTools}. Only affects calls that carry tools. */
|
|
58
|
+
jsonWithTools?: JsonWithTools;
|
|
35
59
|
/** OpenRouter upstream-host pin, to keep a conversation's prompt cache warm. */
|
|
36
60
|
providerOrder?: string[];
|
|
37
61
|
/** Replacement `fetch`, for tests that script the wire. */
|
|
@@ -72,6 +96,7 @@ function buildProvider(init: OpenAICompatibleProviderInit, mode: StructuredOutpu
|
|
|
72
96
|
model: init.model,
|
|
73
97
|
id: init.id,
|
|
74
98
|
jsonMode: mode === "json_schema" ? "schema" : "object",
|
|
99
|
+
...(init.jsonWithTools ? { jsonWithTools: init.jsonWithTools } : {}),
|
|
75
100
|
...(init.baseUrl ? { baseUrl: init.baseUrl } : {}),
|
|
76
101
|
...(init.headers ? { headers: init.headers } : {}),
|
|
77
102
|
...(init.config?.maxTokens ? { maxTokens: init.config.maxTokens } : {}),
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { ProviderCapabilities } from "../types/ai.js";
|
|
6
|
-
import { OpenAICompatibleProvider } from "./OpenAICompatibleProvider.js";
|
|
6
|
+
import { OpenAICompatibleProvider, type JsonWithTools } from "./OpenAICompatibleProvider.js";
|
|
7
7
|
import type { RequestConfig } from "./ProviderAdapter.js";
|
|
8
8
|
|
|
9
9
|
export interface OpenRouterProviderOptions {
|
|
@@ -24,6 +24,14 @@ export interface OpenRouterProviderOptions {
|
|
|
24
24
|
* conversation's rounds. Fallbacks stay on: this is a preference, not a lock.
|
|
25
25
|
*/
|
|
26
26
|
providerOrder?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* See {@link JsonWithTools} — and reach for it here first. One gateway serves
|
|
29
|
+
* hundreds of models and they do not agree: measured through this provider,
|
|
30
|
+
* `z-ai/glm-5.3-flash` called a tool 0/10 with the schema on the response
|
|
31
|
+
* format and 8/8 with it in the prompt, while `qwen3.8-flash` went the other
|
|
32
|
+
* way, 10/10 → 1/6. Changing `model` can change the right answer here.
|
|
33
|
+
*/
|
|
34
|
+
jsonWithTools?: JsonWithTools;
|
|
27
35
|
/** Request defaults sent with every call */
|
|
28
36
|
config?: RequestConfig;
|
|
29
37
|
/** Idle-stream deadline and retry budget */
|
|
@@ -54,6 +62,7 @@ export class OpenRouterProvider extends OpenAICompatibleProvider {
|
|
|
54
62
|
// Chat completions rather than the Responses API: this gateway's
|
|
55
63
|
// json_schema passthrough is what its models actually support.
|
|
56
64
|
structuredOutput: "json_schema",
|
|
65
|
+
...(options.jsonWithTools ? { jsonWithTools: options.jsonWithTools } : {}),
|
|
57
66
|
headers: {
|
|
58
67
|
...(options.siteUrl ? { "HTTP-Referer": options.siteUrl } : {}),
|
|
59
68
|
...(options.siteName ? { "X-Title": options.siteName } : {}),
|