@owlmeans/llm 0.1.16 → 0.1.18-rc.0
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/README.md +1 -0
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/llm/SKILL.md +29 -12
- package/build/consts.d.ts +7 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +7 -0
- package/build/consts.js.map +1 -1
- package/build/errors.d.ts.map +1 -1
- package/build/errors.js.map +1 -1
- package/build/execution/service.d.ts.map +1 -1
- package/build/execution/service.js.map +1 -1
- package/build/execution/utils.d.ts.map +1 -1
- package/build/helpers/cache.d.ts.map +1 -1
- package/build/helpers/json.d.ts.map +1 -1
- package/build/helpers/messages.d.ts.map +1 -1
- package/build/helpers/retry.d.ts.map +1 -1
- package/build/helpers/spectate.d.ts.map +1 -1
- package/build/model.d.ts.map +1 -1
- package/build/model.js +2 -1
- package/build/model.js.map +1 -1
- package/build/plugins/anthropic.d.ts.map +1 -1
- package/build/plugins/anthropic.js +12 -11
- package/build/plugins/anthropic.js.map +1 -1
- package/build/plugins/index.d.ts.map +1 -1
- package/build/plugins/openai.d.ts +7 -5
- package/build/plugins/openai.d.ts.map +1 -1
- package/build/plugins/openai.js +9 -7
- package/build/plugins/openai.js.map +1 -1
- package/build/plugins/utils.d.ts +17 -0
- package/build/plugins/utils.d.ts.map +1 -1
- package/build/plugins/utils.js +30 -0
- package/build/plugins/utils.js.map +1 -1
- package/build/prompt/render.d.ts.map +1 -1
- package/build/prompt/service.d.ts.map +1 -1
- package/build/prompt/service.js.map +1 -1
- package/build/service.d.ts.map +1 -1
- package/build/service.js.map +1 -1
- package/build/utils/config.d.ts.map +1 -1
- package/build/utils/null-report.d.ts.map +1 -1
- package/build/utils/prompt.d.ts +13 -0
- package/build/utils/prompt.d.ts.map +1 -1
- package/build/utils/prompt.js +50 -1
- package/build/utils/prompt.js.map +1 -1
- package/build/utils/schema.d.ts.map +1 -1
- package/build/utils/stream.d.ts.map +1 -1
- package/build/utils/stream.js.map +1 -1
- package/package.json +7 -7
- package/src/consts.ts +8 -0
- package/src/model.ts +2 -1
- package/src/plugins/anthropic.ts +12 -11
- package/src/plugins/openai.ts +9 -8
- package/src/plugins/utils.ts +30 -0
- package/src/utils/prompt.ts +51 -1
- package/tests/internals.spec.ts +67 -2
- package/tests/model.spec.ts +7 -1
- package/tests/plugins.spec.ts +23 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/prompt/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AASlE,OAAO,KAAK,EACoC,aAAa,EAAE,oBAAoB,EACjF,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAKnB,gGAAgG;AAChG,MAAM,MAAM,gBAAgB,GAC1B,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAA;AAEpF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/prompt/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AASlE,OAAO,KAAK,EACoC,aAAa,EAAE,oBAAoB,EACjF,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAKnB,gGAAgG;AAChG,MAAM,MAAM,gBAAgB,GAC1B,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAA;AAEpF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,YAClB,oBAAoB,QACvB,MAAM,aAAa,KACxB,gBAuIF,CAAA;AAED,eAAO,MAAM,iBAAiB,aACnB,oBAAo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0FAA0F;AAC1F,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,WAAW,GAAG,cAAc,GAAG,UAAU,GAAG,SAAS,CAAC,CAAA;AAE9G;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAKlE,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAe,cAAc,EAAE,MAAM,YAAY,CAAA;AAE5F,0FAA0F;AAC1F,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,WAAW,GAAG,cAAc,GAAG,UAAU,GAAG,SAAS,CAAC,CAAA;AAE9G;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,YAAa,iBAAiB,QAAQ,MAAM,UAAU,KAAG,aA8ElF,CAAA;AAED,eAAO,MAAM,cAAc,YAAa,iBAAiB,UAAS,MAAM,KAAiB,UAMxF,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,OAC1E,CAAC,WACG,iBAAiB,UACnB,MAAM,KACZ,CAAC,GAAG,cAQN,CAAA"}
|
package/build/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAMlD;;;;;;;;;;;;;;;GAeG;AACH,MA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AAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;YAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YAChC,CAAC;YAED,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAA0B,EAAE,KAAK,GAAW,WAAW,EAAc,EAAE;IACpG,MAAM,OAAO,GAAe,aAAa,CACvC,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAe,CAC3D,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,GAAM,EACN,OAA0B,EAC1B,KAAK,GAAW,WAAW,EACP,EAAE;IACtB,MAAM,OAAO,GAAG,GAAyB,CAAA;IAEzC,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;IAEvD,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAEtC,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAA;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAA;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UAAW,aAAa,KAAG,OAAO,CAAC,WAAW,CAGpE,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,WAAW,WAAY,OAAO,CAAC,WAAW,CAAC,KAAG,MACV,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"null-report.d.ts","sourceRoot":"","sources":["../../src/utils/null-report.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAA;AAEhF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,0FAA0F;IAC1F,OAAO,EAAE,aAAa,CAAA;IACtB,mFAAmF;IACnF,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAC5B,IAAI,EAAE,oBAAoB,EAAE,CAAA;IAC5B,GAAG,EAAE,cAAc,GAAG,IAAI,CAAA;IAC1B,MAAM,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAAA;IACnD,QAAQ,EAAE,OAAO,CAAA;CAClB;AAKD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"null-report.d.ts","sourceRoot":"","sources":["../../src/utils/null-report.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAA;AAEhF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,0FAA0F;IAC1F,OAAO,EAAE,aAAa,CAAA;IACtB,mFAAmF;IACnF,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAC5B,IAAI,EAAE,oBAAoB,EAAE,CAAA;IAC5B,GAAG,EAAE,cAAc,GAAG,IAAI,CAAA;IAC1B,MAAM,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAAA;IACnD,QAAQ,EAAE,OAAO,CAAA;CAClB;AAKD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,MAAO,gBAAgB,KAAG,WA4DrD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,cACV,YAAY,eACV,OAAO,KACjB,gBAAgB,KAClB,OAAO,CAAC,IAAI,CAsBd,CAAA"}
|
package/build/utils/prompt.d.ts
CHANGED
|
@@ -13,6 +13,19 @@ import type { MessageFieldWithRole } from '@langchain/core/messages';
|
|
|
13
13
|
* makes the per-request count a function of THIS call alone.
|
|
14
14
|
*/
|
|
15
15
|
export declare const stripCacheMarkers: (msgs: MessageFieldWithRole[]) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Remove whitespace-only text content so no request carries a blank text block.
|
|
18
|
+
*
|
|
19
|
+
* Anthropic rejects one outright (`400 messages: text content blocks must contain
|
|
20
|
+
* non-whitespace text`), and a 400 is fatal — a single blank block, typically a file
|
|
21
|
+
* read that returned nothing, kills the whole call with no retry. Blank text blocks
|
|
22
|
+
* are dropped from block arrays; a message left without content is removed, with two
|
|
23
|
+
* exceptions: a tool result keeps its `tool_use` pairing by carrying a stub instead,
|
|
24
|
+
* and an AI message that still holds tool calls keeps an empty string, which
|
|
25
|
+
* serializes without a text block. An input that loses every message gets one stub
|
|
26
|
+
* user message so the request stays valid.
|
|
27
|
+
*/
|
|
28
|
+
export declare const dropBlankContent: (msgs: MessageFieldWithRole[]) => void;
|
|
16
29
|
/**
|
|
17
30
|
* Ensure the word "json" appears somewhere in the prompt. Several providers refuse or
|
|
18
31
|
* silently ignore a JSON mode unless it does; when it is missing the JSON instruction is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/utils/prompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/utils/prompt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAyBpE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,SAAU,oBAAoB,EAAE,KAAG,IAkBhE,CAAA;AAQD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,SAAU,oBAAoB,EAAE,KAAG,IA6B/D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,SAAU,oBAAoB,EAAE,KAAG,IAGhE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,SAAU,oBAAoB,EAAE,mBAAmB,OAAO,GAAG,SAAS,KAAG,IAIjG,CAAA"}
|
package/build/utils/prompt.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import { EMPTY_CONTENT_STUB, JSON_INSTRUCTION, NO_THINK_DIRECTIVE } from '../consts.js';
|
|
2
3
|
const messageMentions = (msg, needle) => {
|
|
3
4
|
if (typeof msg.content === 'string')
|
|
4
5
|
return msg.content.toLowerCase().includes(needle);
|
|
@@ -51,6 +52,54 @@ export const stripCacheMarkers = (msgs) => {
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
};
|
|
55
|
+
const isBlankTextBlock = (part) => typeof part === 'object' && part !== null
|
|
56
|
+
&& part.type === 'text'
|
|
57
|
+
&& typeof part.text === 'string'
|
|
58
|
+
&& part.text.trim() === '';
|
|
59
|
+
/**
|
|
60
|
+
* Remove whitespace-only text content so no request carries a blank text block.
|
|
61
|
+
*
|
|
62
|
+
* Anthropic rejects one outright (`400 messages: text content blocks must contain
|
|
63
|
+
* non-whitespace text`), and a 400 is fatal — a single blank block, typically a file
|
|
64
|
+
* read that returned nothing, kills the whole call with no retry. Blank text blocks
|
|
65
|
+
* are dropped from block arrays; a message left without content is removed, with two
|
|
66
|
+
* exceptions: a tool result keeps its `tool_use` pairing by carrying a stub instead,
|
|
67
|
+
* and an AI message that still holds tool calls keeps an empty string, which
|
|
68
|
+
* serializes without a text block. An input that loses every message gets one stub
|
|
69
|
+
* user message so the request stays valid.
|
|
70
|
+
*/
|
|
71
|
+
export const dropBlankContent = (msgs) => {
|
|
72
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
73
|
+
const msg = msgs[i];
|
|
74
|
+
let content = msg.content;
|
|
75
|
+
if (Array.isArray(content)) {
|
|
76
|
+
const kept = content.filter(part => !isBlankTextBlock(part));
|
|
77
|
+
if (kept.length !== content.length) {
|
|
78
|
+
msg.content = kept;
|
|
79
|
+
}
|
|
80
|
+
if (kept.length > 0) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
content = '';
|
|
84
|
+
}
|
|
85
|
+
if (typeof content === 'string' && content.trim() === '') {
|
|
86
|
+
const role = msg instanceof BaseMessage ? msg.getType() : `${msg.role}`;
|
|
87
|
+
const toolCalls = msg.tool_calls;
|
|
88
|
+
if (role === 'tool') {
|
|
89
|
+
msg.content = EMPTY_CONTENT_STUB;
|
|
90
|
+
}
|
|
91
|
+
else if (toolCalls != null && toolCalls.length > 0) {
|
|
92
|
+
msg.content = '';
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
msgs.splice(i, 1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (msgs.length === 0) {
|
|
100
|
+
msgs.push({ role: 'user', content: EMPTY_CONTENT_STUB });
|
|
101
|
+
}
|
|
102
|
+
};
|
|
54
103
|
/**
|
|
55
104
|
* Ensure the word "json" appears somewhere in the prompt. Several providers refuse or
|
|
56
105
|
* silently ignore a JSON mode unless it does; when it is missing the JSON instruction is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/utils/prompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/utils/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEvF,MAAM,eAAe,GAAG,CAAC,GAAyB,EAAE,MAAc,EAAW,EAAE;IAC7E,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACtF,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CACrB,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI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CAAC,OAAO,KAAK,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QAAE,OAAM;IACzG,eAAe,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAA;AAC3C,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAGhE;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAGhE;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,OAAO,GAAG,UAAU,cAAc,CAAC,CAAC,CAAC,KAAG;IAC9E,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IACxB,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,CAAA;IAC9B,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;CAK9B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,GAAG,SAAS,KAAG,MAGpD,CAAA;AAED,0EAA0E;AAC1E,eAAO,MAAM,WAAW,GAAI,CAAC,UAAU,CAAC,QAAQ,MAAM,GAAG,SAAS,KAAG,CAKpE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,MAAM,GAAG,SAM9D,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAuB,kBAAkB,CAAC,CAAC,EACzC,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EACzD,SAAS,GAAE,MAAgC,GAC1C,cAAc,CAAC,CAAC,CAAC,CAwBnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAEtD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAsB,EAAE;IACzE,MAAM,CAAC,GAAG,KAGT,CAAA;IACD,OAAO,CAAC,CAAC,iBAAiB,EAAE,aAAa,IAAI,CAAC,CAAC,GAAG,EAAE,iBAAiB,EAAE,aAAa,CAAA;AACtF,CAAC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,kBAAkB,CACvC,KAAyD,EACzD,
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAEtD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAsB,EAAE;IACzE,MAAM,CAAC,GAAG,KAGT,CAAA;IACD,OAAO,CAAC,CAAC,iBAAiB,EAAE,aAAa,IAAI,CAAC,CAAC,GAAG,EAAE,iBAAiB,EAAE,aAAa,CAAA;AACtF,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"scripts": {
|
|
@@ -47,18 +47,18 @@
|
|
|
47
47
|
"@langchain/core": "^1.1.39",
|
|
48
48
|
"@langchain/openai": "^1.4.4",
|
|
49
49
|
"@owlmeans/dep-config": "workspace:*",
|
|
50
|
-
"@owlmeans/test": "^0.1.
|
|
50
|
+
"@owlmeans/test": "^0.1.18-rc.0",
|
|
51
51
|
"@types/bun": "^1.3.14",
|
|
52
52
|
"@types/node": "^26.1.0",
|
|
53
53
|
"nodemon": "^3.1.14",
|
|
54
|
-
"typescript": "^
|
|
54
|
+
"typescript": "^7.0.2"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
58
|
-
"@owlmeans/basic-ids": "^0.1.
|
|
59
|
-
"@owlmeans/context": "^0.1.
|
|
60
|
-
"@owlmeans/error": "^0.1.
|
|
61
|
-
"@owlmeans/llm-common": "^0.1.
|
|
58
|
+
"@owlmeans/basic-ids": "^0.1.18-rc.0",
|
|
59
|
+
"@owlmeans/context": "^0.1.18-rc.0",
|
|
60
|
+
"@owlmeans/error": "^0.1.18-rc.0",
|
|
61
|
+
"@owlmeans/llm-common": "^0.1.18-rc.0",
|
|
62
62
|
"ajv": "^8.17.1"
|
|
63
63
|
},
|
|
64
64
|
"publishConfig": {
|
package/src/consts.ts
CHANGED
|
@@ -99,6 +99,14 @@ export const NO_THINK_DIRECTIVE = '/no_think'
|
|
|
99
99
|
/** Tool name used for structured output when a schema carries no usable title/name. */
|
|
100
100
|
export const DEFAULT_TOOL_NAME = 'extract'
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Placeholder content for a message that must survive blank-content sanitization —
|
|
104
|
+
* a tool result whose `tool_use` pairing may not be broken, or an input whose every
|
|
105
|
+
* message was blank. Providers reject whitespace-only text outright, so the stub is
|
|
106
|
+
* the smallest honest signal that the caller supplied nothing.
|
|
107
|
+
*/
|
|
108
|
+
export const EMPTY_CONTENT_STUB = '(empty)'
|
|
109
|
+
|
|
102
110
|
/** Default effort tier when a policy does not specify one. */
|
|
103
111
|
export const DEFAULT_EFFORT = ExecutionEffort.Standard
|
|
104
112
|
|
package/src/model.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { spectate } from './helpers/spectate.js'
|
|
|
18
18
|
import { idleTimeout, readConfig } from './utils/config.js'
|
|
19
19
|
import { reportNull } from './utils/null-report.js'
|
|
20
20
|
import type { NullReportParams } from './utils/null-report.js'
|
|
21
|
-
import { applyNoThink, ensureJsonMention, stripCacheMarkers } from './utils/prompt.js'
|
|
21
|
+
import { applyNoThink, dropBlankContent, ensureJsonMention, stripCacheMarkers } from './utils/prompt.js'
|
|
22
22
|
import { resolveSchemaValidator, toToolName, unwrapNamed } from './utils/schema.js'
|
|
23
23
|
import { streamWithDeadline } from './utils/stream.js'
|
|
24
24
|
import type {
|
|
@@ -121,6 +121,7 @@ export const makeLlmModel = ({
|
|
|
121
121
|
// markers live on its own objects. The budget is per request, so clear them and
|
|
122
122
|
// re-place our own below; otherwise they accumulate until the provider 400s.
|
|
123
123
|
stripCacheMarkers(msgs)
|
|
124
|
+
dropBlankContent(msgs)
|
|
124
125
|
let reserved = 0
|
|
125
126
|
|
|
126
127
|
if (prompts != null) {
|
package/src/plugins/anthropic.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { CacheTtl } from '@owlmeans/llm-common'
|
|
|
7
7
|
import type { LlmPlugin } from './types.js'
|
|
8
8
|
import { CHARS_PER_TOKEN, MAX_CACHE_BREAKPOINTS, MIN_CACHEABLE_TOKENS } from '../consts.js'
|
|
9
9
|
import { readConfig } from '../utils/config.js'
|
|
10
|
-
import { escalateMaxTokens, makeClientOptions } from './utils.js'
|
|
10
|
+
import { escalateMaxTokens, isBadRequest, makeClientOptions } from './utils.js'
|
|
11
11
|
|
|
12
12
|
/** Model-name prefix that supports prompt caching through `cache_control` markers. */
|
|
13
13
|
const CACHEABLE_PREFIX = 'claude-'
|
|
@@ -221,16 +221,17 @@ export const anthropicPlugin: LlmPlugin = {
|
|
|
221
221
|
|
|
222
222
|
/**
|
|
223
223
|
* A malformed request (bad schema, unsupported parameter, oversized `max_tokens`, too
|
|
224
|
-
* many cache breakpoints) cannot be fixed by retrying —
|
|
225
|
-
* of burning the budget.
|
|
224
|
+
* many cache breakpoints, an input past the context window) cannot be fixed by retrying —
|
|
225
|
+
* surface it immediately instead of burning the budget.
|
|
226
226
|
*
|
|
227
|
-
* The `
|
|
228
|
-
* carries its OWN nested copy of
|
|
229
|
-
*
|
|
230
|
-
* `
|
|
231
|
-
*
|
|
227
|
+
* The `isBadRequest` walk is not redundant with the `instanceof`, and neither is a plain
|
|
228
|
+
* `e.status === 400`. `@langchain/anthropic` carries its OWN nested copy of
|
|
229
|
+
* `@anthropic-ai/sdk`, so the error it throws is an instance of a DIFFERENT
|
|
230
|
+
* `BadRequestError` class than the one imported here; and langchain additionally re-wraps
|
|
231
|
+
* the failure in its own typed error (`ContextOverflowError` for an oversized prompt),
|
|
232
|
+
* which holds the 400 only under `cause`. Each layer alone turned a fatal 400 into eight
|
|
233
|
+
* full retries — a single unfixable request became minutes of thrash with the real cause
|
|
234
|
+
* buried under the repeats.
|
|
232
235
|
*/
|
|
233
|
-
isFatal: e => e instanceof BadRequestError || (e
|
|
234
|
-
? e as Error
|
|
235
|
-
: null,
|
|
236
|
+
isFatal: e => e instanceof BadRequestError || isBadRequest(e) ? e as Error : null,
|
|
236
237
|
}
|
package/src/plugins/openai.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { BaseChatModel } from '@langchain/core/language_models/chat_models'
|
|
|
3
3
|
import { ModelProvider, StructuredMode } from '@owlmeans/llm-common'
|
|
4
4
|
import type { LlmPlugin, LlmRefineParams } from './types.js'
|
|
5
5
|
import type { ModelConfig } from '../types.js'
|
|
6
|
-
import { escalateMaxTokens, makeConfiguration } from './utils.js'
|
|
6
|
+
import { escalateMaxTokens, isBadRequest, makeConfiguration } from './utils.js'
|
|
7
7
|
|
|
8
8
|
/** Model families served through OpenAI's Responses API rather than chat completions. */
|
|
9
9
|
const RESPONSES_API_PREFIXES = ['gpt-5', 'codex-']
|
|
@@ -35,14 +35,15 @@ export const openAiFamily = {
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* A 400 means the request itself is malformed — a schema the endpoint rejects, an
|
|
38
|
-
* unsupported parameter, a `max_tokens` above the model's per-request limit
|
|
39
|
-
* re-sends the same shape (and the escalator raises
|
|
40
|
-
* strictly worse), so eight attempts only bury the
|
|
41
|
-
* rather than an SDK class: aggregators and
|
|
42
|
-
* types, and
|
|
38
|
+
* unsupported parameter, a `max_tokens` above the model's per-request limit, an input
|
|
39
|
+
* past the context window. Retrying re-sends the same shape (and the escalator raises
|
|
40
|
+
* `max_tokens`, making some of those strictly worse), so eight attempts only bury the
|
|
41
|
+
* real message. Matched through `isBadRequest` rather than an SDK class: aggregators and
|
|
42
|
+
* nested SDK copies throw their own error types, and langchain re-wraps the failure in a
|
|
43
|
+
* typed error that keeps the 400 only under `cause` — so both an `instanceof` and a
|
|
44
|
+
* surface `status` read silently miss it.
|
|
43
45
|
*/
|
|
44
|
-
isFatal: (e: unknown): Error | null =>
|
|
45
|
-
(e as { status?: unknown })?.status === 400 ? e as Error : null,
|
|
46
|
+
isFatal: (e: unknown): Error | null => isBadRequest(e) ? e as Error : null,
|
|
46
47
|
|
|
47
48
|
refine: ({ base, attempt, temperature, maxOutputCap }: LlmRefineParams): BaseChatModel => {
|
|
48
49
|
const model = base as ChatOpenAI
|
package/src/plugins/utils.ts
CHANGED
|
@@ -36,3 +36,33 @@ export const makeClientOptions = (
|
|
|
36
36
|
*/
|
|
37
37
|
export const escalateMaxTokens = (base: number | undefined, attempt: number, cap: number): number =>
|
|
38
38
|
Math.min((base ?? 2048) * Math.pow(2, attempt), cap)
|
|
39
|
+
|
|
40
|
+
/** How deep to follow `cause` before giving up — guards a self-referential chain. */
|
|
41
|
+
const MAX_CAUSE_DEPTH = 8
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether the error is — or wraps — an HTTP 400 from a provider.
|
|
45
|
+
*
|
|
46
|
+
* A 400 means the request itself is malformed: a schema the endpoint rejects, an
|
|
47
|
+
* unsupported parameter, a `max_tokens` above the per-request limit, or an input past the
|
|
48
|
+
* context window. Retrying re-sends the same shape and the retry escalator only raises the
|
|
49
|
+
* OUTPUT budget, so none of those can improve with another attempt.
|
|
50
|
+
*
|
|
51
|
+
* The check walks the `cause` chain and never uses `instanceof`. Two independent reasons:
|
|
52
|
+
* `@langchain/anthropic` and `@langchain/openai` bundle their own nested copies of the
|
|
53
|
+
* provider SDKs, so their errors are instances of a DIFFERENT class than the one this
|
|
54
|
+
* package imports; and langchain re-wraps provider failures in its own typed errors
|
|
55
|
+
* (`ContextOverflowError` and friends) that carry the original only as `cause`, with no
|
|
56
|
+
* `status` of their own. Either one silently defeats a surface-level check — an oversized
|
|
57
|
+
* prompt then burns all eight attempts on a request that cannot succeed.
|
|
58
|
+
*/
|
|
59
|
+
export const isBadRequest = (e: unknown): boolean => {
|
|
60
|
+
let current: unknown = e
|
|
61
|
+
for (let depth = 0; current != null && depth < MAX_CAUSE_DEPTH; ++depth) {
|
|
62
|
+
if ((current as { status?: unknown }).status === 400) return true
|
|
63
|
+
const cause = (current as { cause?: unknown }).cause
|
|
64
|
+
if (cause === current) return false
|
|
65
|
+
current = cause
|
|
66
|
+
}
|
|
67
|
+
return false
|
|
68
|
+
}
|
package/src/utils/prompt.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { BaseMessage } from '@langchain/core/messages'
|
|
1
2
|
import type { MessageFieldWithRole } from '@langchain/core/messages'
|
|
2
|
-
import { JSON_INSTRUCTION, NO_THINK_DIRECTIVE } from '../consts.js'
|
|
3
|
+
import { EMPTY_CONTENT_STUB, JSON_INSTRUCTION, NO_THINK_DIRECTIVE } from '../consts.js'
|
|
3
4
|
|
|
4
5
|
const messageMentions = (msg: MessageFieldWithRole, needle: string): boolean => {
|
|
5
6
|
if (typeof msg.content === 'string') return msg.content.toLowerCase().includes(needle)
|
|
@@ -56,6 +57,55 @@ export const stripCacheMarkers = (msgs: MessageFieldWithRole[]): void => {
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
const isBlankTextBlock = (part: unknown): boolean =>
|
|
61
|
+
typeof part === 'object' && part !== null
|
|
62
|
+
&& (part as Record<string, unknown>).type === 'text'
|
|
63
|
+
&& typeof (part as Record<string, unknown>).text === 'string'
|
|
64
|
+
&& (part as Record<string, string>).text.trim() === ''
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Remove whitespace-only text content so no request carries a blank text block.
|
|
68
|
+
*
|
|
69
|
+
* Anthropic rejects one outright (`400 messages: text content blocks must contain
|
|
70
|
+
* non-whitespace text`), and a 400 is fatal — a single blank block, typically a file
|
|
71
|
+
* read that returned nothing, kills the whole call with no retry. Blank text blocks
|
|
72
|
+
* are dropped from block arrays; a message left without content is removed, with two
|
|
73
|
+
* exceptions: a tool result keeps its `tool_use` pairing by carrying a stub instead,
|
|
74
|
+
* and an AI message that still holds tool calls keeps an empty string, which
|
|
75
|
+
* serializes without a text block. An input that loses every message gets one stub
|
|
76
|
+
* user message so the request stays valid.
|
|
77
|
+
*/
|
|
78
|
+
export const dropBlankContent = (msgs: MessageFieldWithRole[]): void => {
|
|
79
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
80
|
+
const msg = msgs[i]
|
|
81
|
+
let content = msg.content
|
|
82
|
+
if (Array.isArray(content)) {
|
|
83
|
+
const kept = content.filter(part => !isBlankTextBlock(part))
|
|
84
|
+
if (kept.length !== content.length) {
|
|
85
|
+
msg.content = kept as unknown as typeof msg.content
|
|
86
|
+
}
|
|
87
|
+
if (kept.length > 0) {
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
content = ''
|
|
91
|
+
}
|
|
92
|
+
if (typeof content === 'string' && content.trim() === '') {
|
|
93
|
+
const role = msg instanceof BaseMessage ? msg.getType() : `${msg.role}`
|
|
94
|
+
const toolCalls = (msg as { tool_calls?: unknown[] }).tool_calls
|
|
95
|
+
if (role === 'tool') {
|
|
96
|
+
msg.content = EMPTY_CONTENT_STUB
|
|
97
|
+
} else if (toolCalls != null && toolCalls.length > 0) {
|
|
98
|
+
msg.content = ''
|
|
99
|
+
} else {
|
|
100
|
+
msgs.splice(i, 1)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (msgs.length === 0) {
|
|
105
|
+
msgs.push({ role: 'user', content: EMPTY_CONTENT_STUB })
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
59
109
|
/**
|
|
60
110
|
* Ensure the word "json" appears somewhere in the prompt. Several providers refuse or
|
|
61
111
|
* silently ignore a JSON mode unless it does; when it is missing the JSON instruction is
|
package/tests/internals.spec.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { AIMessage, ToolMessage } from '@langchain/core/messages'
|
|
2
3
|
import type { MessageFieldWithRole } from '@langchain/core/messages'
|
|
3
|
-
import { JSON_INSTRUCTION, NO_THINK_DIRECTIVE } from '../src/consts.js'
|
|
4
|
-
import { applyNoThink, ensureJsonMention } from '../src/utils/prompt.js'
|
|
4
|
+
import { EMPTY_CONTENT_STUB, JSON_INSTRUCTION, NO_THINK_DIRECTIVE } from '../src/consts.js'
|
|
5
|
+
import { applyNoThink, dropBlankContent, ensureJsonMention } from '../src/utils/prompt.js'
|
|
5
6
|
import { toToolName, unwrapNamed } from '../src/utils/schema.js'
|
|
6
7
|
import { getChunkFinishReason, streamWithDeadline } from '../src/utils/stream.js'
|
|
7
8
|
|
|
@@ -58,6 +59,70 @@ describe('utils/prompt — thinking suppression', () => {
|
|
|
58
59
|
})
|
|
59
60
|
})
|
|
60
61
|
|
|
62
|
+
describe('utils/prompt — blank content sanitization', () => {
|
|
63
|
+
test('drops a whitespace-only user message and keeps the rest', () => {
|
|
64
|
+
const msgs: MessageFieldWithRole[] = [
|
|
65
|
+
{ role: 'user', content: 'the task' },
|
|
66
|
+
{ role: 'user', content: '\n\n ' },
|
|
67
|
+
{ role: 'user', content: 'the file' },
|
|
68
|
+
]
|
|
69
|
+
dropBlankContent(msgs)
|
|
70
|
+
expect(msgs.map(m => m.content)).toEqual(['the task', 'the file'])
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('filters blank text blocks out of block arrays, keeping non-text blocks', () => {
|
|
74
|
+
const msgs: MessageFieldWithRole[] = [{
|
|
75
|
+
role: 'user',
|
|
76
|
+
content: [
|
|
77
|
+
{ type: 'text', text: ' \n' },
|
|
78
|
+
{ type: 'text', text: 'kept' },
|
|
79
|
+
{ type: 'image_url', image_url: { url: 'data:,x' } },
|
|
80
|
+
],
|
|
81
|
+
}]
|
|
82
|
+
dropBlankContent(msgs)
|
|
83
|
+
expect(msgs).toHaveLength(1)
|
|
84
|
+
expect(msgs[0]!.content).toEqual([
|
|
85
|
+
{ type: 'text', text: 'kept' },
|
|
86
|
+
{ type: 'image_url', image_url: { url: 'data:,x' } },
|
|
87
|
+
])
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('removes a message whose block array becomes empty', () => {
|
|
91
|
+
const msgs: MessageFieldWithRole[] = [
|
|
92
|
+
{ role: 'user', content: 'the task' },
|
|
93
|
+
{ role: 'user', content: [{ type: 'text', text: ' ' }] },
|
|
94
|
+
]
|
|
95
|
+
dropBlankContent(msgs)
|
|
96
|
+
expect(msgs.map(m => m.content)).toEqual(['the task'])
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('stubs a blank tool result instead of dropping it', () => {
|
|
100
|
+
const msgs = [
|
|
101
|
+
{ role: 'user', content: 'run it' },
|
|
102
|
+
new ToolMessage({ tool_call_id: 'call_1', content: ' ' }),
|
|
103
|
+
] as MessageFieldWithRole[]
|
|
104
|
+
dropBlankContent(msgs)
|
|
105
|
+
expect(msgs).toHaveLength(2)
|
|
106
|
+
expect((msgs[1] as ToolMessage).content).toBe(EMPTY_CONTENT_STUB)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('keeps a blank AI message that carries tool calls, with empty string content', () => {
|
|
110
|
+
const msgs = [
|
|
111
|
+
{ role: 'user', content: 'run it' },
|
|
112
|
+
new AIMessage({ content: '\n', tool_calls: [{ id: 'call_1', name: 'run', args: {} }] }),
|
|
113
|
+
] as MessageFieldWithRole[]
|
|
114
|
+
dropBlankContent(msgs)
|
|
115
|
+
expect(msgs).toHaveLength(2)
|
|
116
|
+
expect((msgs[1] as AIMessage).content).toBe('')
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('replaces an all-blank input with a single stub user message', () => {
|
|
120
|
+
const msgs: MessageFieldWithRole[] = [{ role: 'user', content: ' ' }]
|
|
121
|
+
dropBlankContent(msgs)
|
|
122
|
+
expect(msgs).toEqual([{ role: 'user', content: EMPTY_CONTENT_STUB }])
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
|
|
61
126
|
describe('utils/schema — tool naming and unwrapping', () => {
|
|
62
127
|
test('sanitises a schema title into a provider-acceptable tool name', () => {
|
|
63
128
|
expect(toToolName('User Story')).toBe('User_Story')
|
package/tests/model.spec.ts
CHANGED
|
@@ -112,5 +112,11 @@ const suite = (name: string, configs: () => ModelConfig[], skip: string | null)
|
|
|
112
112
|
})
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
// The live OpenRouter suite is DISABLED unconditionally: OpenRouter is an aggregator outside
|
|
116
|
+
// the main model set (OpenAI + Anthropic), so it bills a separate account and serves models no
|
|
117
|
+
// deployment runs — a `402 requires more credits` there reads as a failure of the code under
|
|
118
|
+
// test. The gate alone was not enough, since it runs the moment OPENROUTER_SECRET is present in
|
|
119
|
+
// any developer's .env. The `Compatible` provider itself stays covered offline by plugins.spec.ts
|
|
120
|
+
// (baseUrl/kwargs shaping). Drop the literal below back to the gate expression to re-enable.
|
|
121
|
+
suite('openrouter', openRouterConfigs, 'disabled: OpenRouter is outside the main model set')
|
|
116
122
|
suite('anthropic', anthropicConfigs, 'skip' in gates.anthropic ? gates.anthropic.reason : null)
|
package/tests/plugins.spec.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { describe, expect, test } from 'bun:test'
|
|
|
2
2
|
import { ChatAnthropic } from '@langchain/anthropic'
|
|
3
3
|
import { ChatOpenAI } from '@langchain/openai'
|
|
4
4
|
import { BadRequestError } from '@anthropic-ai/sdk'
|
|
5
|
+
import { ContextOverflowError } from '@langchain/core/errors'
|
|
5
6
|
import { ModelProvider, PromptBlock, StructuredMode } from '@owlmeans/llm-common'
|
|
6
7
|
import {
|
|
7
8
|
anthropicPlugin, compatiblePlugin, makeLlmService, openAiPlugin, pluginFor, pluginOf,
|
|
@@ -430,11 +431,33 @@ describe('@owlmeans/llm — fatal error classification', () => {
|
|
|
430
431
|
expect(compatiblePlugin.isFatal?.(foreign)).toBe(foreign)
|
|
431
432
|
})
|
|
432
433
|
|
|
434
|
+
// langchain re-wraps a provider failure in its own typed error and keeps the original
|
|
435
|
+
// only under `cause`, so the wrapper carries no `status` of its own. An oversized prompt
|
|
436
|
+
// arrives this way — and since the retry escalator raises only the OUTPUT budget, every
|
|
437
|
+
// one of the eight attempts re-sent the same over-limit input and failed identically.
|
|
438
|
+
test('a 400 wrapped in a langchain error is still fatal', () => {
|
|
439
|
+
const raw = Object.assign(new Error('prompt is too long: 323182 tokens > 200000 maximum'), { status: 400 })
|
|
440
|
+
const wrapped = ContextOverflowError.fromError(raw)
|
|
441
|
+
expect(anthropicPlugin.isFatal?.(wrapped)).toBe(wrapped)
|
|
442
|
+
expect(openAiPlugin.isFatal?.(wrapped)).toBe(wrapped)
|
|
443
|
+
expect(compatiblePlugin.isFatal?.(wrapped)).toBe(wrapped)
|
|
444
|
+
|
|
445
|
+
const nested = Object.assign(new Error('outer'), { cause: wrapped })
|
|
446
|
+
expect(anthropicPlugin.isFatal?.(nested)).toBe(nested)
|
|
447
|
+
})
|
|
448
|
+
|
|
433
449
|
test('a retryable status is not treated as fatal', () => {
|
|
434
450
|
const overloaded = Object.assign(new Error('529'), { status: 529 })
|
|
435
451
|
expect(anthropicPlugin.isFatal?.(overloaded)).toBeNull()
|
|
436
452
|
expect(openAiPlugin.isFatal?.(overloaded)).toBeNull()
|
|
437
453
|
})
|
|
454
|
+
|
|
455
|
+
// The cause walk must terminate on a chain that points back at itself.
|
|
456
|
+
test('a self-referential cause chain does not hang', () => {
|
|
457
|
+
const looped: Error & { cause?: unknown } = new Error('loop')
|
|
458
|
+
looped.cause = looped
|
|
459
|
+
expect(anthropicPlugin.isFatal?.(looped)).toBeNull()
|
|
460
|
+
})
|
|
438
461
|
})
|
|
439
462
|
|
|
440
463
|
describe('@owlmeans/llm — service', () => {
|