@theoremjs/agents 0.3.4-next.596.g481e1de → 0.3.4-next.600.gb15be9a
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { kindOfHttpStatus, TheoremError, toErrorEvent, } from '../../../guardrails/error.js';
|
|
2
2
|
import { asRecord } from '../../../kernel/engine/record.js';
|
|
3
3
|
import { historyMessageParts, isMediaRefPart } from '../../../kernel/interaction-parts.js';
|
|
4
|
-
import { withCarriedToolFiles } from '../../shared/carried-tool-files.js';
|
|
4
|
+
import { withCarriedAssistantFiles, withCarriedToolFiles, } from '../../shared/carried-tool-files.js';
|
|
5
5
|
import { historyToolIdentity } from '../../shared/tool-args.js';
|
|
6
6
|
/** The fields Chat Completions gives every error; any other field is the provider's own detail. */
|
|
7
7
|
const STANDARD_ERROR_FIELDS = new Set(['message', 'type', 'param', 'code']);
|
|
@@ -127,7 +127,9 @@ function buildChatMessages(req, options) {
|
|
|
127
127
|
if (includeSystem && req.system) {
|
|
128
128
|
messages.push({ role: 'system', content: req.system });
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
// why: Chat Completions takes only text and refusals in assistant content, and endpoints that enforce it refuse the call.
|
|
131
|
+
const history = withCarriedAssistantFiles(req.history ?? []);
|
|
132
|
+
for (const h of withCarriedToolFiles(history, TOOL_MESSAGE_PART_TYPES)) {
|
|
131
133
|
messages.push(wireHistoryMessage(h));
|
|
132
134
|
}
|
|
133
135
|
if (req.input.length > 0) {
|
|
@@ -5,3 +5,9 @@ import type { InteractionPart, TurnHistoryMessage } from '../../kernel/types.js'
|
|
|
5
5
|
* one user message, so the results of a parallel call stay together.
|
|
6
6
|
*/
|
|
7
7
|
export declare function withCarriedToolFiles(messages: readonly TurnHistoryMessage[], holds: ReadonlySet<InteractionPart['type']>): TurnHistoryMessage[];
|
|
8
|
+
/**
|
|
9
|
+
* History for a wire whose assistant content holds only text. An assistant
|
|
10
|
+
* message's files leave a marker in their place and follow it in one user
|
|
11
|
+
* message, after the results of any calls it made.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withCarriedAssistantFiles(messages: readonly TurnHistoryMessage[]): TurnHistoryMessage[];
|
|
@@ -41,3 +41,32 @@ export function withCarriedToolFiles(messages, holds) {
|
|
|
41
41
|
flush();
|
|
42
42
|
return out;
|
|
43
43
|
}
|
|
44
|
+
const ASSISTANT_FILES_LEAD = { type: 'text', text: 'Files the assistant sent:' };
|
|
45
|
+
/**
|
|
46
|
+
* History for a wire whose assistant content holds only text. An assistant
|
|
47
|
+
* message's files leave a marker in their place and follow it in one user
|
|
48
|
+
* message, after the results of any calls it made.
|
|
49
|
+
*/
|
|
50
|
+
export function withCarriedAssistantFiles(messages) {
|
|
51
|
+
const out = [];
|
|
52
|
+
let carried = [];
|
|
53
|
+
for (const msg of messages) {
|
|
54
|
+
if (msg.role !== 'tool' && carried.length > 0) {
|
|
55
|
+
out.push({ role: 'user', parts: carried });
|
|
56
|
+
carried = [];
|
|
57
|
+
}
|
|
58
|
+
const files = msg.role === 'assistant' ? (msg.parts ?? []).filter((p) => p.type !== 'text') : [];
|
|
59
|
+
if (files.length === 0) {
|
|
60
|
+
out.push(msg);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
out.push({
|
|
64
|
+
...msg,
|
|
65
|
+
parts: (msg.parts ?? []).map((part) => part.type === 'text' ? part : carriedFileMarker(part)),
|
|
66
|
+
});
|
|
67
|
+
carried.push(ASSISTANT_FILES_LEAD, ...files);
|
|
68
|
+
}
|
|
69
|
+
if (carried.length > 0)
|
|
70
|
+
out.push({ role: 'user', parts: carried });
|
|
71
|
+
return out;
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/agents",
|
|
3
|
-
"version": "0.3.4-next.
|
|
3
|
+
"version": "0.3.4-next.600.gb15be9a",
|
|
4
4
|
"description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, registered tools, provider adapters, guardrails, and host-injected traces.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|