@theoremjs/agents 0.3.4-next.855.gc82d4ec → 0.3.4-next.869.gb64db05
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/esm/src/guardrails/detectors.d.ts +91 -21
- package/esm/src/guardrails/host-patterns.d.ts +15 -2
- package/esm/src/guardrails/labels.d.ts +11 -3
- package/esm/src/guardrails/labels.js +42 -23
- package/esm/src/guardrails/quota.d.ts +9 -3
- package/esm/src/guardrails/quota.js +9 -3
- package/esm/src/guardrails/theorem-error.d.ts +5 -1
- package/esm/src/guardrails/theorem-error.js +8 -4
- package/esm/src/guardrails/types.d.ts +66 -18
- package/esm/src/guardrails/types.js +22 -3
- package/esm/src/kernel/api-catalog.d.ts +26 -75
- package/esm/src/kernel/api-catalog.js +37 -119
- package/esm/src/kernel/checkpoint.d.ts +5 -1
- package/esm/src/kernel/default-scope.d.ts +52 -10
- package/esm/src/kernel/default-scope.js +52 -10
- package/esm/src/kernel/engine/runner/gates.js +66 -22
- package/esm/src/kernel/engine/runner/state.d.ts +5 -2
- package/esm/src/kernel/engine/runner/steps.js +15 -15
- package/esm/src/kernel/engine/runner/stream.d.ts +5 -0
- package/esm/src/kernel/engine/runner/stream.js +12 -1
- package/esm/src/kernel/field-docs.d.ts +13 -0
- package/esm/src/kernel/field-docs.js +613 -0
- package/esm/src/kernel/protocols/binding.d.ts +56 -0
- package/esm/src/kernel/protocols/limits.d.ts +9 -0
- package/esm/src/kernel/protocols/provider.d.ts +5 -1
- package/esm/src/kernel/protocols/provider.js +5 -1
- package/esm/src/kernel/registry/profiles.d.ts +154 -5
- package/esm/src/kernel/schema.d.ts +5 -7
- package/esm/src/kernel/schema.js +511 -470
- package/esm/src/kernel/stop.d.ts +41 -17
- package/esm/src/kernel/stop.js +9 -1
- package/esm/src/kernel/tools/background.d.ts +4 -0
- package/esm/src/kernel/tools/types.d.ts +331 -43
- package/esm/src/kernel/turn-events.d.ts +4 -3
- package/esm/src/kernel/types.d.ts +482 -89
- package/esm/src/observability/destinations.d.ts +5 -1
- package/esm/src/observability/destinations.js +5 -1
- package/esm/src/observability/trace-catalog.js +62 -102
- package/esm/src/observability/types.d.ts +93 -19
- package/esm/src/providers/shared/carried-tool-files.js +9 -8
- package/package.json +1 -1
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { TraceSink } from './trace-sink.js';
|
|
2
2
|
/** True when the value is a trace sink. */
|
|
3
3
|
declare function isTraceSink(value: unknown): value is TraceSink;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Stores a place to write traces under an id, so that a profile can name it in observability.
|
|
6
|
+
*
|
|
7
|
+
* @remarks Register a trace sink under an id; throws when the id is empty.
|
|
8
|
+
*/
|
|
5
9
|
declare function registerTraceDestination(id: string, destination: TraceSink): void;
|
|
6
10
|
/** The sink registered under the id, or `undefined`. */
|
|
7
11
|
declare function getTraceDestination(id: string): TraceSink | undefined;
|
|
@@ -8,7 +8,11 @@ function isTraceSink(value) {
|
|
|
8
8
|
'write' in value &&
|
|
9
9
|
typeof value.write === 'function');
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Stores a place to write traces under an id, so that a profile can name it in observability.
|
|
13
|
+
*
|
|
14
|
+
* @remarks Register a trace sink under an id; throws when the id is empty.
|
|
15
|
+
*/
|
|
12
16
|
function registerTraceDestination(id, destination) {
|
|
13
17
|
const key = id.trim();
|
|
14
18
|
if (!key) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
// invariant: A key with no entry is still a real attribute: viewers show it under its raw name.
|
|
2
|
+
import { OPTION_DOCS } from '../kernel/field-docs.js';
|
|
3
|
+
import { geminiProvider } from '../providers/gemini/provider.js';
|
|
4
|
+
import { localProvider } from '../providers/local/provider.js';
|
|
5
|
+
import { openRouterProvider } from '../providers/openrouter/provider.js';
|
|
6
|
+
import { typesafeProvider } from '../providers/typesafe/provider.js';
|
|
2
7
|
/** Labels and descriptions for each attribute group. */
|
|
3
8
|
const TRACE_ATTRIBUTE_GROUPS = {
|
|
4
9
|
agent: { label: 'Agent', doc: 'Which agent ran, for which conversation, and how it ended.' },
|
|
@@ -50,82 +55,61 @@ const TRACE_FIELDS = {
|
|
|
50
55
|
events: { label: 'Events', doc: 'What happened during the span, in order.' },
|
|
51
56
|
links: { label: 'Links', doc: 'Earlier traces this span follows.' },
|
|
52
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Each value's label, with its doc from the JSDoc on its list's member (`OPTION_DOCS`). A value
|
|
60
|
+
* the list does not document throws.
|
|
61
|
+
*/
|
|
62
|
+
function listed(docs, labels) {
|
|
63
|
+
const entries = Object.entries(labels).map(([value, label]) => {
|
|
64
|
+
const doc = docs[value];
|
|
65
|
+
if (!doc)
|
|
66
|
+
throw new Error(`${value}: its list does not document it`);
|
|
67
|
+
return [value, { label, doc }];
|
|
68
|
+
});
|
|
69
|
+
return Object.fromEntries(entries);
|
|
70
|
+
}
|
|
53
71
|
const STOP_KINDS = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
provider_error: { label: 'Provider error', doc: 'The provider reported an error.' },
|
|
69
|
-
cancelled: { label: 'Cancelled', doc: 'The user or host stopped it.' },
|
|
70
|
-
step_limit: {
|
|
71
|
-
label: 'Ran out of steps',
|
|
72
|
-
doc: 'The last model call the profile allows asked for tools, so the turn ended without an answer.',
|
|
73
|
-
},
|
|
74
|
-
answer_missing: {
|
|
75
|
-
label: 'No answer',
|
|
76
|
-
doc: 'The model finished without calling the answer tool, and no repair was left.',
|
|
77
|
-
},
|
|
78
|
-
stream_incomplete: {
|
|
79
|
-
label: 'Stream cut off',
|
|
80
|
-
doc: "The provider's stream ended before the answer was complete.",
|
|
81
|
-
},
|
|
82
|
-
interrupted: { label: 'Interrupted', doc: 'The user spoke over a Live response.' },
|
|
83
|
-
generation_complete: {
|
|
84
|
-
label: 'Generation complete',
|
|
85
|
-
doc: 'Live: the model finished generating this response; the turn may still be open.',
|
|
86
|
-
},
|
|
72
|
+
...listed(OPTION_DOCS.TURN_STOP_KINDS, {
|
|
73
|
+
completed: 'Completed',
|
|
74
|
+
length: 'Hit output limit',
|
|
75
|
+
tool: 'Handed tool to host',
|
|
76
|
+
gate: 'Waiting for approval',
|
|
77
|
+
filtered: 'Filtered',
|
|
78
|
+
provider_error: 'Provider error',
|
|
79
|
+
cancelled: 'Cancelled',
|
|
80
|
+
step_limit: 'Ran out of steps',
|
|
81
|
+
answer_missing: 'No answer',
|
|
82
|
+
stream_incomplete: 'Stream cut off',
|
|
83
|
+
interrupted: 'Interrupted',
|
|
84
|
+
generation_complete: 'Generation complete',
|
|
85
|
+
}),
|
|
87
86
|
go_away: {
|
|
88
87
|
label: 'Closed by provider',
|
|
89
88
|
doc: 'Live: the provider warned the session would end, then closed it.',
|
|
90
89
|
},
|
|
91
90
|
};
|
|
92
|
-
const ERROR_KIND_OPTIONS = {
|
|
93
|
-
config:
|
|
94
|
-
request:
|
|
95
|
-
conflict:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
label: 'Unusable response',
|
|
115
|
-
doc: 'The provider answered with something that cannot be used.',
|
|
116
|
-
},
|
|
117
|
-
network: { label: 'Network', doc: 'The request never reached the provider.' },
|
|
118
|
-
timeout: { label: 'Timeout', doc: 'The model took longer than the host allowed.' },
|
|
119
|
-
safety: { label: 'Safety', doc: 'theorem or the provider held the reply back.' },
|
|
120
|
-
blocked: {
|
|
121
|
-
label: 'Blocked',
|
|
122
|
-
doc: "A guardrail or host policy stopped one of the agent's steps.",
|
|
123
|
-
},
|
|
124
|
-
declined: { label: 'Declined', doc: "The user declined one of the agent's steps." },
|
|
125
|
-
failed: { label: 'Failed', doc: "One of the agent's steps ran and failed." },
|
|
126
|
-
cancelled: { label: 'Cancelled', doc: 'The user or host stopped the turn.' },
|
|
127
|
-
internal: { label: 'Internal', doc: 'A theorem invariant broke.' },
|
|
128
|
-
};
|
|
91
|
+
const ERROR_KIND_OPTIONS = listed(OPTION_DOCS.ERROR_KINDS, {
|
|
92
|
+
config: 'Setup',
|
|
93
|
+
request: 'Host request',
|
|
94
|
+
conflict: 'Conflict',
|
|
95
|
+
not_found: 'Not found',
|
|
96
|
+
input: 'User input',
|
|
97
|
+
action: 'Not allowed',
|
|
98
|
+
auth: 'Credentials',
|
|
99
|
+
rate_limit: 'Rate limit',
|
|
100
|
+
unsupported: 'Unsupported',
|
|
101
|
+
busy: 'Busy',
|
|
102
|
+
unavailable: 'Unavailable',
|
|
103
|
+
bad_response: 'Unusable response',
|
|
104
|
+
network: 'Network',
|
|
105
|
+
timeout: 'Timeout',
|
|
106
|
+
safety: 'Safety',
|
|
107
|
+
blocked: 'Blocked',
|
|
108
|
+
declined: 'Declined',
|
|
109
|
+
failed: 'Failed',
|
|
110
|
+
cancelled: 'Cancelled',
|
|
111
|
+
internal: 'Internal',
|
|
112
|
+
});
|
|
129
113
|
/** `error.type`: an error kind, or the failing stop. An HTTP status or exception shows as is. */
|
|
130
114
|
const ERROR_TYPE_OPTIONS = {
|
|
131
115
|
...ERROR_KIND_OPTIONS,
|
|
@@ -151,11 +135,7 @@ const TOOL_ORIGIN_OPTIONS = {
|
|
|
151
135
|
mcp: { label: 'MCP', doc: 'A tool on an MCP server.' },
|
|
152
136
|
delegated: { label: 'Another agent', doc: 'A specialist agent the tool ran.' },
|
|
153
137
|
};
|
|
154
|
-
const TOOL_PERMISSION_OPTIONS = {
|
|
155
|
-
auto: { label: 'Automatic', doc: 'Runs without asking.' },
|
|
156
|
-
session_consent: { label: 'Ask once', doc: 'Asks once per session, then remembers the answer.' },
|
|
157
|
-
always_confirm: { label: 'Always ask', doc: 'Asks before every call.' },
|
|
158
|
-
};
|
|
138
|
+
const TOOL_PERMISSION_OPTIONS = listed(OPTION_DOCS.TOOL_PERMISSION, { auto: 'Automatic', session_consent: 'Ask once', always_confirm: 'Always ask' });
|
|
159
139
|
const LINK_KINDS = {
|
|
160
140
|
resume: { label: 'Resumes', doc: 'Picks up a call that stopped for approval.' },
|
|
161
141
|
continue: { label: 'Continues', doc: 'Continues an answer that stopped early.' },
|
|
@@ -202,11 +182,10 @@ const OUTPUT_TYPES = {
|
|
|
202
182
|
image: { label: 'Image', doc: 'The model answers with an image.' },
|
|
203
183
|
speech: { label: 'Speech', doc: 'The model answers in audio.' },
|
|
204
184
|
};
|
|
205
|
-
const PROVIDERS =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
};
|
|
185
|
+
const PROVIDERS = Object.fromEntries([geminiProvider, localProvider, openRouterProvider, typesafeProvider].map((provider) => [
|
|
186
|
+
provider.traceName ?? provider.id,
|
|
187
|
+
{ label: provider.name, doc: provider.description },
|
|
188
|
+
]));
|
|
210
189
|
const USAGE_SIDES = {
|
|
211
190
|
input: { label: 'Input', doc: 'Tokens the model read.' },
|
|
212
191
|
output: { label: 'Output', doc: 'Tokens the model wrote.' },
|
|
@@ -422,28 +401,9 @@ const RETRY_REASONS = {
|
|
|
422
401
|
},
|
|
423
402
|
validation: { label: 'Invalid JSON', doc: 'The structured output did not match its schema.' },
|
|
424
403
|
};
|
|
425
|
-
const COMPACTION_TIMING_OPTIONS = {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
};
|
|
429
|
-
const COMPACTION_METER_OPTIONS = {
|
|
430
|
-
history: { label: 'History', doc: 'Counts tokens across earlier turns.' },
|
|
431
|
-
input: {
|
|
432
|
-
label: 'Whole input',
|
|
433
|
-
doc: "Counts the turn's whole input: instructions, history, and attachments.",
|
|
434
|
-
},
|
|
435
|
-
};
|
|
436
|
-
const COMPACTION_OUTCOME_OPTIONS = {
|
|
437
|
-
compacted: { label: 'Compacted', doc: 'A summary replaced the earlier messages.' },
|
|
438
|
-
deferred: {
|
|
439
|
-
label: 'Kept whole',
|
|
440
|
-
doc: 'The compactor failed and the history still fits, so it was kept and compaction runs again next turn.',
|
|
441
|
-
},
|
|
442
|
-
dropped: {
|
|
443
|
-
label: 'Dropped',
|
|
444
|
-
doc: 'The compactor failed and the history no longer fits, so the earlier messages were dropped.',
|
|
445
|
-
},
|
|
446
|
-
};
|
|
404
|
+
const COMPACTION_TIMING_OPTIONS = listed(OPTION_DOCS.COMPACTION_TIMINGS, { before: 'Before the turn', after: 'After the turn' });
|
|
405
|
+
const COMPACTION_METER_OPTIONS = listed(OPTION_DOCS.COMPACTION_METERS, { history: 'History', input: 'Whole input' });
|
|
406
|
+
const COMPACTION_OUTCOME_OPTIONS = listed(OPTION_DOCS.COMPACTION_OUTCOMES, { compacted: 'Compacted', deferred: 'Kept whole', dropped: 'Dropped' });
|
|
447
407
|
/** `theorem.session` kinds: provider session signals (a finished response is its own record). */
|
|
448
408
|
const SESSION_KINDS = {
|
|
449
409
|
closing_soon: { label: 'Closing soon', doc: 'The provider warned the session will end.' },
|
|
@@ -3,19 +3,45 @@ import type { TraceSink } from './trace-sink.js';
|
|
|
3
3
|
import type { TraceAttributes } from './trace-span.js';
|
|
4
4
|
/** Which payloads land in each TraceRecord. Omitted keys use resolved defaults. */
|
|
5
5
|
export interface TraceIncludeSpec {
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Keeps each row the provider sent back, scrubbed, as it arrived, with media bytes replaced by
|
|
8
|
+
* their sha256.
|
|
9
|
+
*
|
|
10
|
+
* @remarks Scrubbed provider rows and frames (`theorem.upstream.row` events). Default: true.
|
|
11
|
+
*/
|
|
7
12
|
upstreamLog?: boolean;
|
|
8
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Keeps each request body sent to the provider, scrubbed.
|
|
15
|
+
*
|
|
16
|
+
* @remarks Scrubbed outbound request bodies (`theorem.wire.request` events). Default: false.
|
|
17
|
+
*/
|
|
9
18
|
outboundWire?: boolean;
|
|
10
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Keeps the provider's raw payload on grounding results such as search citations; upstreamLog
|
|
21
|
+
* rows keep their own copy.
|
|
22
|
+
*
|
|
23
|
+
* @remarks The provider's raw grounding payload (`raw` on `theorem.grounding` events). Default:
|
|
24
|
+
* false.
|
|
25
|
+
*/
|
|
11
26
|
evidenceRaw?: boolean;
|
|
12
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Keeps token counts and other usage figures on spans; upstreamLog rows keep their own.
|
|
29
|
+
*
|
|
30
|
+
* @remarks Usage attributes (`gen_ai.usage.*`, `theorem.usage.*`). Default: true.
|
|
31
|
+
*/
|
|
13
32
|
usage?: boolean;
|
|
14
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Keeps each guardrail decision.
|
|
35
|
+
*
|
|
36
|
+
* @remarks Guardrail decisions (`theorem.guardrail` events). Default: true.
|
|
37
|
+
*/
|
|
15
38
|
guardrailDecisions?: boolean;
|
|
16
39
|
/**
|
|
17
|
-
*
|
|
18
|
-
* debugging only
|
|
40
|
+
* Keeps the exact text each guardrail matched, unscrubbed, on the trace and the host's event
|
|
41
|
+
* stream; for debugging only.
|
|
42
|
+
*
|
|
43
|
+
* @remarks Keep `GuardrailHit.match` (the exact matched text) on guardrail events. Default:
|
|
44
|
+
* false; debugging only, so treat the store like server logs when enabled.
|
|
19
45
|
*/
|
|
20
46
|
guardrailMatchPreview?: boolean;
|
|
21
47
|
}
|
|
@@ -34,42 +60,90 @@ export type ScrubSwitch = boolean | {
|
|
|
34
60
|
* their actions: a detector set to `ignore` in the turn still cleans the trace. Defaults are on.
|
|
35
61
|
*/
|
|
36
62
|
export interface TraceScrubSpec {
|
|
37
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Removes what the data detectors (IDs, Financial, Network, Credentials) and your own detectors
|
|
65
|
+
* find from stored traces. On, it cleans with the patterns each reads the turn with; { theorem,
|
|
66
|
+
* host } picks Theorem's patterns, yours, or both for the trace alone.
|
|
67
|
+
*
|
|
68
|
+
* @remarks The data detectors (`ids`, `financial`, `network`, `credentials`) and the host's own.
|
|
69
|
+
* Default: true.
|
|
70
|
+
*/
|
|
38
71
|
sensitive?: ScrubSwitch;
|
|
39
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Removes what Injection and Tool instructions find from stored traces. On, it cleans with the
|
|
74
|
+
* patterns each reads the turn with; { theorem, host } picks Theorem's patterns, yours, or both
|
|
75
|
+
* for the trace alone.
|
|
76
|
+
*
|
|
77
|
+
* @remarks `injection`, with the orders to the agent it finds in what a tool returns. Default:
|
|
78
|
+
* true.
|
|
79
|
+
*/
|
|
40
80
|
injection?: ScrubSwitch;
|
|
41
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Removes the canary token from stored traces. The canary is Theorem's, so { theorem: false }
|
|
83
|
+
* keeps it.
|
|
84
|
+
*
|
|
85
|
+
* @remarks Never persist the canary token. It is Theorem's alone, so the host side adds nothing.
|
|
86
|
+
* Default: true.
|
|
87
|
+
*/
|
|
42
88
|
canary?: ScrubSwitch;
|
|
43
89
|
}
|
|
44
90
|
/** Omit the whole block for no tracing. */
|
|
45
91
|
export interface ProfileObservabilitySpec {
|
|
46
92
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
93
|
+
* Where traces go: a registered destination id, your own writer, or false. An unregistered id
|
|
94
|
+
* fails the turn at the start. A sink passed to runTurn replaces it.
|
|
95
|
+
*
|
|
96
|
+
* @remarks `false` is off, a string is a `registerTraceDestination` id, a TraceSink is an inline
|
|
97
|
+
* writer. `runTurn(..., sink)` still overrides this for one call.
|
|
49
98
|
*/
|
|
50
99
|
writeTo?: false | string | TraceSink;
|
|
51
100
|
/**
|
|
52
|
-
*
|
|
101
|
+
* The share of traces kept, from 0 to 1, each kept or dropped whole; a sink passed straight to
|
|
102
|
+
* runTurn keeps every trace.
|
|
103
|
+
*
|
|
104
|
+
* @remarks Fraction of traces to record, 0–1 inclusive. Default: 1. Decided by trace id, so every
|
|
53
105
|
* record of one trace is kept or dropped together.
|
|
54
106
|
*/
|
|
55
107
|
sampleRate?: number;
|
|
108
|
+
/** Which optional parts of a trace are kept. */
|
|
56
109
|
include?: TraceIncludeSpec;
|
|
57
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Attributes stamped on every trace, such as service.name.
|
|
112
|
+
*
|
|
113
|
+
* @remarks Stamped on every record as `TraceRecord.resource`, e.g. `{ 'service.name': 'harbor'
|
|
114
|
+
* }`.
|
|
115
|
+
*/
|
|
58
116
|
resource?: TraceAttributes;
|
|
59
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* What is removed from stored traces, separately from the turn's guardrails.
|
|
119
|
+
*
|
|
120
|
+
* @remarks Defaults stay on even when `guardrails.detect` is `ignore`.
|
|
121
|
+
*/
|
|
60
122
|
scrub?: TraceScrubSpec;
|
|
61
123
|
/**
|
|
62
|
-
* Days
|
|
63
|
-
*
|
|
64
|
-
*
|
|
124
|
+
* Days a trace file is kept, by its UTC day. The next write removes old files. 0 or less keeps
|
|
125
|
+
* all.
|
|
126
|
+
*
|
|
127
|
+
* @remarks Days to keep each record, handed to every destination with the record
|
|
128
|
+
* (`TraceWriteContext`): the JSONL writer prunes by it, a host store computes its own expiry from
|
|
129
|
+
* it. `<= 0` keeps records forever. Default: 14.
|
|
65
130
|
*/
|
|
66
131
|
retainForDays?: number;
|
|
67
132
|
/**
|
|
68
133
|
* File size in MiB at which a file-based destination starts a new file, handed to every
|
|
134
|
+
* destination with the record. Default 32.
|
|
135
|
+
*
|
|
136
|
+
* @remarks File size in MiB at which a file-based destination starts a new file, handed to every
|
|
69
137
|
* destination with the record (`TraceWriteContext`). Default: 32.
|
|
70
138
|
*/
|
|
71
139
|
rotateAfterMiB?: number;
|
|
72
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* Your function called when a trace can't be built or written; the turn carries on, and a
|
|
142
|
+
* destination's own error handler takes priority. An unregistered writeTo id is a config error
|
|
143
|
+
* instead.
|
|
144
|
+
*
|
|
145
|
+
* @remarks Called when record build or destination write fails. Must not throw.
|
|
146
|
+
*/
|
|
73
147
|
onWriteError?: (err: unknown) => void;
|
|
74
148
|
}
|
|
75
149
|
/** Which optional content a trace record includes, each on or off. */
|
|
@@ -32,15 +32,19 @@ export function withCarriedToolFiles(messages, holds) {
|
|
|
32
32
|
out.push(msg);
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
out.push(
|
|
36
|
-
...msg,
|
|
37
|
-
parts: (msg.parts ?? []).map((part) => holds.has(part.type) ? part : carriedFileMarker(part)),
|
|
38
|
-
});
|
|
35
|
+
out.push(withMarkers(msg, (part) => holds.has(part.type)));
|
|
39
36
|
carried.push(carriedFilesLead(msg), ...files);
|
|
40
37
|
}
|
|
41
38
|
flush();
|
|
42
39
|
return out;
|
|
43
40
|
}
|
|
41
|
+
/** The message with each part `stays` rejects swapped for its carried-file marker. */
|
|
42
|
+
function withMarkers(msg, stays) {
|
|
43
|
+
return {
|
|
44
|
+
...msg,
|
|
45
|
+
parts: (msg.parts ?? []).map((part) => (stays(part) ? part : carriedFileMarker(part))),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
44
48
|
const ASSISTANT_FILES_LEAD = { type: 'text', text: 'Files the assistant sent:' };
|
|
45
49
|
/**
|
|
46
50
|
* History for a wire whose assistant content holds only text. An assistant
|
|
@@ -60,10 +64,7 @@ export function withCarriedAssistantFiles(messages) {
|
|
|
60
64
|
out.push(msg);
|
|
61
65
|
continue;
|
|
62
66
|
}
|
|
63
|
-
out.push(
|
|
64
|
-
...msg,
|
|
65
|
-
parts: (msg.parts ?? []).map((part) => part.type === 'text' ? part : carriedFileMarker(part)),
|
|
66
|
-
});
|
|
67
|
+
out.push(withMarkers(msg, (part) => part.type === 'text'));
|
|
67
68
|
carried.push(ASSISTANT_FILES_LEAD, ...files);
|
|
68
69
|
}
|
|
69
70
|
if (carried.length > 0)
|
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.869.gb64db05",
|
|
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",
|