@theoremjs/agents 0.3.5-next.959.g351c307 → 0.3.5-next.961.g4178e57
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/labels.js +1 -1
- package/esm/src/guardrails/sanitize.d.ts +1 -7
- package/esm/src/guardrails/sanitize.js +5 -11
- package/esm/src/kernel/engine/runner/mod.js +1 -8
- package/esm/src/kernel/engine/runner/nested.js +4 -7
- package/esm/src/kernel/engine/runner/refused-media.d.ts +1 -8
- package/esm/src/kernel/engine/runner/refused-media.js +0 -27
- package/esm/src/kernel/engine/runner/state.d.ts +0 -2
- package/esm/src/kernel/registry/attachments.d.ts +7 -25
- package/esm/src/kernel/registry/attachments.js +10 -43
- package/esm/src/kernel/registry/ingress.js +2 -2
- package/esm/src/kernel/turn-events.d.ts +3 -8
- package/package.json +1 -1
|
@@ -560,7 +560,7 @@ const DEFAULTS = {
|
|
|
560
560
|
'tool.background_field': 'Set to true to get a reply now and let this call finish after the turn. Leave out to wait for its result.',
|
|
561
561
|
'tool.background_started': '{tool} has started and is still running. You do not have its result, so do not state or guess one, and do not call {tool} again. Tell the person it is under way and that the result comes later.',
|
|
562
562
|
'tool.late_result': 'The {tool} call you started earlier has finished. This is what it returned:',
|
|
563
|
-
'tool.after_field': 'Names of other tools you call in this same step, as search_web, that must finish before this call starts
|
|
563
|
+
'tool.after_field': 'Names of other tools you call in this same step, as search_web, that must finish before this call starts; tool names, not call ids. Leave out to set no order.',
|
|
564
564
|
'tool.not_visible': "Tool '{tool}' is not visible this turn",
|
|
565
565
|
'tool.builtin_not_enabled': "Builtin '{tool}' is not enabled this turn",
|
|
566
566
|
'tool.provider_native': "Tool '{tool}' is a provider builtin — execution is handled by the model provider, not the kernel",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type LeftOutFile } from '../kernel/registry/attachments.js';
|
|
2
1
|
import type { NormalizedTurnRequest, Profile, TurnContext, TurnEvent, TurnHistoryMessage, TurnRequest } from '../kernel/types.js';
|
|
3
2
|
import { type Boundary } from './boundaries.js';
|
|
4
3
|
import { type BoundaryReader } from './detect-at.js';
|
|
@@ -28,8 +27,6 @@ interface SanitizedTurnRequest {
|
|
|
28
27
|
events: TurnEvent[];
|
|
29
28
|
/** Set when a match blocks: the request does not reach the model, and the turn ends on this. */
|
|
30
29
|
refusal?: TheoremError;
|
|
31
|
-
/** The files the profile does not take, left out of `request`; the turn goes on without them. */
|
|
32
|
-
leftOut: LeftOutFile[];
|
|
33
30
|
}
|
|
34
31
|
/**
|
|
35
32
|
* `req.system` is host-assembled per turn — it interpolates retrieval and user
|
|
@@ -37,10 +34,7 @@ interface SanitizedTurnRequest {
|
|
|
37
34
|
* path and stays verbatim.
|
|
38
35
|
*/
|
|
39
36
|
declare function sanitizeTurnRequestWithEvents(req: TurnRequest, profile: Profile): SanitizedTurnRequest;
|
|
40
|
-
/**
|
|
41
|
-
* The turn request with its input cleaned under the profile's guardrails. Throws when a match
|
|
42
|
-
* blocks it, and when the profile does not take one of its files: nothing here goes on without it.
|
|
43
|
-
*/
|
|
37
|
+
/** The turn request with its input cleaned under the profile's guardrails. Throws when a match blocks it. */
|
|
44
38
|
declare function sanitizeTurnRequest(req: TurnRequest, profile: Profile): NormalizedTurnRequest;
|
|
45
39
|
export type { SanitizedTurnRequest };
|
|
46
40
|
export { contextText, requestRefused, sanitizeContext, sanitizeHistory, sanitizeProjectId, sanitizeTurnRequest, sanitizeTurnRequestWithEvents, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sanitizeTurnBlobs } from '../kernel/registry/attachments.js';
|
|
2
2
|
import { CONTEXT_SENDERS } from '../kernel/schema.js';
|
|
3
3
|
import { mapSystemPrompt } from '../kernel/system-parts.js';
|
|
4
4
|
import { recordOf } from './boundaries.js';
|
|
@@ -124,9 +124,9 @@ function sanitizeTurnRequestWithEvents(req, profile) {
|
|
|
124
124
|
const told = sanitizeContext(input.context, () => boundaryReader('context', detect));
|
|
125
125
|
const repair = sanitizeRepair(input.repair, at.repair);
|
|
126
126
|
const history = input.history ? sanitizeHistory(input.history, at.history) : undefined;
|
|
127
|
-
const { attachments, voice
|
|
127
|
+
const { attachments, voice } = input.attachments?.length || input.voice?.length
|
|
128
128
|
? sanitizeTurnBlobs(profile, input.attachments, input.voice, at)
|
|
129
|
-
:
|
|
129
|
+
: input;
|
|
130
130
|
const events = [];
|
|
131
131
|
let refusal;
|
|
132
132
|
for (const boundary of REQUEST_BOUNDARIES) {
|
|
@@ -159,19 +159,13 @@ function sanitizeTurnRequestWithEvents(req, profile) {
|
|
|
159
159
|
},
|
|
160
160
|
events,
|
|
161
161
|
...(refusal ? { refusal } : {}),
|
|
162
|
-
leftOut,
|
|
163
162
|
};
|
|
164
163
|
}
|
|
165
|
-
/**
|
|
166
|
-
* The turn request with its input cleaned under the profile's guardrails. Throws when a match
|
|
167
|
-
* blocks it, and when the profile does not take one of its files: nothing here goes on without it.
|
|
168
|
-
*/
|
|
164
|
+
/** The turn request with its input cleaned under the profile's guardrails. Throws when a match blocks it. */
|
|
169
165
|
function sanitizeTurnRequest(req, profile) {
|
|
170
|
-
const { request, refusal
|
|
166
|
+
const { request, refusal } = sanitizeTurnRequestWithEvents(req, profile);
|
|
171
167
|
if (refusal)
|
|
172
168
|
throw refusal;
|
|
173
|
-
if (leftOut.length > 0)
|
|
174
|
-
throw attachmentsRefused(leftOut.flatMap((file) => file.issues));
|
|
175
169
|
return request;
|
|
176
170
|
}
|
|
177
171
|
export { contextText, requestRefused, sanitizeContext, sanitizeHistory, sanitizeProjectId, sanitizeTurnRequest, sanitizeTurnRequestWithEvents, };
|
|
@@ -24,7 +24,6 @@ import { endThrownSpan, endTurnSpan, guardrailAttributes, guardrailCheckAttribut
|
|
|
24
24
|
import { sumEventTokens, sumTurnTokens } from '../usage.js';
|
|
25
25
|
import { runAttemptsWithValidation } from './gates.js';
|
|
26
26
|
import { createAgentCaller, NESTED_THROWS, turnError } from './nested.js';
|
|
27
|
-
import { leftOutNotes, leftOutReport, turnMediaRefused } from './refused-media.js';
|
|
28
27
|
import { applyTurnStage, landLateResultsAt, unreadLateResultsAt, } from './stages.js';
|
|
29
28
|
import { cutConversation, openTurnState, } from './state.js';
|
|
30
29
|
import { shouldSkipStreamEvent } from './stream.js';
|
|
@@ -266,8 +265,6 @@ async function* emitTurn(args) {
|
|
|
266
265
|
...(args.steers ? { steers: args.steers } : {}),
|
|
267
266
|
});
|
|
268
267
|
args.outState.state = state;
|
|
269
|
-
if (args.leftOut)
|
|
270
|
-
state.leftOut = args.leftOut;
|
|
271
268
|
const opening = { stage: 'pre_turn', step: 0 };
|
|
272
269
|
const late = yield* unreadLateResultsAt(state, profile, {
|
|
273
270
|
...opening,
|
|
@@ -308,11 +305,10 @@ async function* emitTurn(args) {
|
|
|
308
305
|
}
|
|
309
306
|
yield* runAttemptsWithValidation(safe, profile, generation, system, provider, state);
|
|
310
307
|
const tokens = sumTurnTokens(state.allEmittedEvents);
|
|
311
|
-
const mediaRefused = turnMediaRefused(state.leftOut, state.mediaRefused);
|
|
312
308
|
const done = turnDoneOf({
|
|
313
309
|
stop: state.lastStop ?? { kind: 'completed' },
|
|
314
310
|
steps: state.stepCount,
|
|
315
|
-
...(mediaRefused ? { mediaRefused } : {}),
|
|
311
|
+
...(state.mediaRefused ? { mediaRefused: state.mediaRefused } : {}),
|
|
316
312
|
...(state.providerState &&
|
|
317
313
|
!cutConversation(state) &&
|
|
318
314
|
!('providerContinuation' in profile && profile.providerContinuation?.history === 'stateless') &&
|
|
@@ -340,7 +336,6 @@ async function* streamTurnEvents(ctx, profile, gen, provider, compactionSpec) {
|
|
|
340
336
|
background: ctx.background,
|
|
341
337
|
steers: ctx.steers,
|
|
342
338
|
outState: ctx,
|
|
343
|
-
leftOut: ctx.leftOut,
|
|
344
339
|
})) {
|
|
345
340
|
const crashes = [];
|
|
346
341
|
const attached = await maybeAttachAfter(event, ctx, gen, compactionSpec, crashes);
|
|
@@ -529,8 +524,6 @@ async function* runTurnBody(ctx, provider) {
|
|
|
529
524
|
if (sanitized.refusal)
|
|
530
525
|
throw sanitized.refusal;
|
|
531
526
|
const { profile, generation: gen } = resolveTurnInRegistry(ctx.registry, ctx.safe);
|
|
532
|
-
gen.input.push(...leftOutNotes(sanitized.leftOut, profile.labels));
|
|
533
|
-
ctx.leftOut = leftOutReport(sanitized.leftOut);
|
|
534
527
|
const t1Policy = await applyT1Policy(ctx.registry.tools, gen.tools, profile, ctx.safe);
|
|
535
528
|
if (t1Policy) {
|
|
536
529
|
yield deliver(ctx, hookFailed('tools.t1Policy', t1Policy.crashed, { span: ctx.root }));
|
|
@@ -2,7 +2,6 @@ import { errorCopyText, isAbortError, TheoremError, throwIfAborted, toErrorEvent
|
|
|
2
2
|
import { labelText } from '../../../guardrails/labels.js';
|
|
3
3
|
import { hookCrashFailure, hookFailed } from '../../hook-failure.js';
|
|
4
4
|
import { nestedTurnModel, resolveRegisteredTurnModel } from '../../provider-dispatch.js';
|
|
5
|
-
import { assertTurnAttachments } from '../../registry/attachments.js';
|
|
6
5
|
import { profileAllowsInject } from '../../stop.js';
|
|
7
6
|
import { agentProfileProblem, agentToolOutputOf, splitHostInput, } from '../../tools/agent.js';
|
|
8
7
|
import { findLast } from '../../util/find-last.js';
|
|
@@ -74,15 +73,14 @@ function createAgentCaller(args) {
|
|
|
74
73
|
throw new TheoremError('internal', `Agent tool "${tool.name}" ran without a span`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
75
74
|
}
|
|
76
75
|
const { speech, ...sent } = modelInput;
|
|
77
|
-
const
|
|
78
|
-
const events = yield* nestedEvents(() => assertTurnAttachments(profile, turnInput.attachments, turnInput.voice), args.runNested({
|
|
76
|
+
const events = yield* nestedEvents(args.runNested({
|
|
79
77
|
req: {
|
|
80
78
|
...(speech ? { speech } : {}),
|
|
81
79
|
...fields,
|
|
82
80
|
profile: tool.profile,
|
|
83
81
|
execution: req.execution,
|
|
84
82
|
pageExecution: req.pageExecution,
|
|
85
|
-
input:
|
|
83
|
+
input: fields.input ?? sent,
|
|
86
84
|
...(signal ? { signal } : {}),
|
|
87
85
|
...(req.onAgentCall ? { onAgentCall: req.onAgentCall } : {}),
|
|
88
86
|
},
|
|
@@ -97,17 +95,16 @@ function createAgentCaller(args) {
|
|
|
97
95
|
};
|
|
98
96
|
}
|
|
99
97
|
/** Relays an agent's turn and keeps its events; a turn refused before it starts ends in its error event. */
|
|
100
|
-
async function* nestedEvents(
|
|
98
|
+
async function* nestedEvents(turn) {
|
|
101
99
|
const events = [];
|
|
102
100
|
try {
|
|
103
|
-
check();
|
|
104
101
|
for await (const event of turn) {
|
|
105
102
|
events.push(event);
|
|
106
103
|
yield event;
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
106
|
catch (err) {
|
|
110
|
-
// why: A
|
|
107
|
+
// why: A turn refused before it starts (a file the agent does not take) throws; the caller's model reads it like any other failed call.
|
|
111
108
|
if (!(err instanceof TheoremError) || NESTED_THROWS.has(err.kind) || isAbortError(err)) {
|
|
112
109
|
throw err;
|
|
113
110
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { LeftOutFile } from '../../registry/attachments.js';
|
|
2
1
|
import type { MediaRefused, RefusedMedia } from '../../turn-events.js';
|
|
3
|
-
import type {
|
|
2
|
+
import type { Profile, TurnHistoryMessage } from '../../types.js';
|
|
4
3
|
import type { StepExecutionState } from './state.js';
|
|
5
4
|
/** The files a retry took out, and how to put them back if the retry fails too. */
|
|
6
5
|
export interface RefusedMediaTry {
|
|
@@ -25,9 +24,3 @@ export declare function dropMedia(state: StepExecutionState, said: string, label
|
|
|
25
24
|
export declare function restoreMedia(state: StepExecutionState, tried: RefusedMediaTry): void;
|
|
26
25
|
/** What the host reads on `done`. */
|
|
27
26
|
export declare function refusedReport(tried: RefusedMediaTry): MediaRefused;
|
|
28
|
-
/** The note the model reads in place of each file the profile does not take. */
|
|
29
|
-
export declare function leftOutNotes(leftOut: readonly LeftOutFile[], labels: Profile['labels']): InteractionPart[];
|
|
30
|
-
/** The files the profile does not take, as `done.mediaRefused` reports them; `said` names each check that failed. */
|
|
31
|
-
export declare function leftOutReport(leftOut: readonly LeftOutFile[]): MediaRefused | undefined;
|
|
32
|
-
/** The turn's report: the files left out at ingress, then the ones the provider refused. */
|
|
33
|
-
export declare function turnMediaRefused(leftOut: MediaRefused | undefined, refused: MediaRefused | undefined): MediaRefused | undefined;
|
|
@@ -92,30 +92,3 @@ export function restoreMedia(state, tried) {
|
|
|
92
92
|
export function refusedReport(tried) {
|
|
93
93
|
return { dropped: tried.dropped, said: tried.said };
|
|
94
94
|
}
|
|
95
|
-
/** The note the model reads in place of each file the profile does not take. */
|
|
96
|
-
export function leftOutNotes(leftOut, labels) {
|
|
97
|
-
return leftOut.map((file) => ({
|
|
98
|
-
type: 'text',
|
|
99
|
-
text: labelText(noteKey(file.mimeType.toLowerCase(), false), {}, labels),
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
102
|
-
/** The files the profile does not take, as `done.mediaRefused` reports them; `said` names each check that failed. */
|
|
103
|
-
export function leftOutReport(leftOut) {
|
|
104
|
-
if (leftOut.length === 0)
|
|
105
|
-
return undefined;
|
|
106
|
-
return {
|
|
107
|
-
dropped: leftOut.map((file) => ({ mimeType: file.mimeType, from: 'input' })),
|
|
108
|
-
said: leftOut
|
|
109
|
-
.map((file) => `${file.mimeType}: ${file.issues.map((issue) => issue.code).join(', ')}`)
|
|
110
|
-
.join('\n'),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/** The turn's report: the files left out at ingress, then the ones the provider refused. */
|
|
114
|
-
export function turnMediaRefused(leftOut, refused) {
|
|
115
|
-
if (!leftOut || !refused)
|
|
116
|
-
return leftOut ?? refused;
|
|
117
|
-
return {
|
|
118
|
-
dropped: [...leftOut.dropped, ...refused.dropped],
|
|
119
|
-
said: `${leftOut.said}\n${refused.said}`,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
@@ -45,8 +45,6 @@ interface StepExecutionState {
|
|
|
45
45
|
/** The files this turn's refused calls went without: each type the provider named once, or every file once. */
|
|
46
46
|
mediaTry?: RefusedMediaTry;
|
|
47
47
|
mediaRefused?: MediaRefused;
|
|
48
|
-
/** The files the profile does not take, left out before the turn began. */
|
|
49
|
-
leftOut?: MediaRefused;
|
|
50
48
|
allEmittedEvents: TurnEvent[];
|
|
51
49
|
attemptEvents: TurnEvent[];
|
|
52
50
|
/**
|
|
@@ -36,10 +36,7 @@ export interface AttachmentRules {
|
|
|
36
36
|
voice?: string[];
|
|
37
37
|
limits?: MediaLimits;
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
* The one attachment check. The headless interface runs it before a send; at ingress the kernel
|
|
41
|
-
* runs it on each file, leaves out the files it names, and throws only on what names no file.
|
|
42
|
-
*/
|
|
39
|
+
/** The one attachment check: the kernel throws on it at ingress and the headless interface runs it before a send. */
|
|
43
40
|
declare function attachmentIssues(rules: AttachmentRules, files: AttachmentFacts[], clips: AttachmentFacts[]): AttachmentValidationIssue[];
|
|
44
41
|
/** The user-facing wording key and params for an attachment issue. */
|
|
45
42
|
declare function attachmentIssueCopy(issue: AttachmentValidationIssue): ErrorCopy;
|
|
@@ -49,29 +46,14 @@ declare function attachmentIssueText(issue: AttachmentValidationIssue, labels?:
|
|
|
49
46
|
declare function attachmentsRefused(issues: readonly AttachmentValidationIssue[]): TheoremError;
|
|
50
47
|
/** The decoded size of inline base64 data; throws when it is not base64. */
|
|
51
48
|
declare function base64Bytes(data: string): number;
|
|
52
|
-
/**
|
|
49
|
+
/** Provider references are checked for MIME and count; byte limits apply to inline blobs only. */
|
|
53
50
|
declare function assertTurnAttachments(profile: Profile, attachments: Array<TurnBlob | TurnMediaRef> | undefined, voice: TurnBlob[] | undefined): void;
|
|
54
|
-
/** A file the turn goes without, and what the check found wrong with it. */
|
|
55
|
-
interface LeftOutFile {
|
|
56
|
-
mimeType: string;
|
|
57
|
-
channel: 'attachment' | 'voice';
|
|
58
|
-
issues: AttachmentValidationIssue[];
|
|
59
|
-
}
|
|
60
|
-
interface TurnFiles {
|
|
61
|
-
attachments?: Array<TurnBlob | TurnMediaRef>;
|
|
62
|
-
voice?: TurnBlob[];
|
|
63
|
-
leftOut: LeftOutFile[];
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* invariant: a file the profile does not take is left out and the turn goes on; what names no file
|
|
67
|
-
* (too many files, too many bytes in all) refuses the turn, since no one file is at fault.
|
|
68
|
-
* Provider references are checked for MIME and count; byte limits apply to inline blobs only.
|
|
69
|
-
*/
|
|
70
|
-
declare function splitTurnAttachments(profile: Profile, attachments: Array<TurnBlob | TurnMediaRef> | undefined, voice: TurnBlob[] | undefined): TurnFiles;
|
|
71
51
|
/** Provider file references pass through unsanitized: the kernel has no bytes to scan. */
|
|
72
52
|
declare function sanitizeTurnBlobs(profile: Profile, attachments: Array<TurnBlob | TurnMediaRef> | undefined, voice: TurnBlob[] | undefined, at: {
|
|
73
53
|
attachment: BoundaryReader;
|
|
74
54
|
voice: BoundaryReader;
|
|
75
|
-
}):
|
|
76
|
-
|
|
77
|
-
|
|
55
|
+
}): {
|
|
56
|
+
attachments?: Array<TurnBlob | TurnMediaRef>;
|
|
57
|
+
voice?: TurnBlob[];
|
|
58
|
+
};
|
|
59
|
+
export { assertTurnAttachments, attachmentIssueCopy, attachmentIssues, attachmentIssueText, attachmentsRefused, base64Bytes, isTextFile, isTextFileData, isTurnMediaRef, maxBytesForMime, modelTextFile, requireMediaLimits, resolveMediaLimits, rewriteTextFile, sanitizeCsvText, sanitizeTurnBlobs, textFileText, };
|
|
@@ -277,10 +277,7 @@ function limitIssues(files, limits) {
|
|
|
277
277
|
}
|
|
278
278
|
return issues;
|
|
279
279
|
}
|
|
280
|
-
/**
|
|
281
|
-
* The one attachment check. The headless interface runs it before a send; at ingress the kernel
|
|
282
|
-
* runs it on each file, leaves out the files it names, and throws only on what names no file.
|
|
283
|
-
*/
|
|
280
|
+
/** The one attachment check: the kernel throws on it at ingress and the headless interface runs it before a send. */
|
|
284
281
|
function attachmentIssues(rules, files, clips) {
|
|
285
282
|
const issues = [];
|
|
286
283
|
if (files.length > 0 && !rules.attachments) {
|
|
@@ -348,46 +345,19 @@ function factsOf(item) {
|
|
|
348
345
|
facts.sizeBytes = base64Bytes(item.data);
|
|
349
346
|
return facts;
|
|
350
347
|
}
|
|
351
|
-
/**
|
|
348
|
+
/** Provider references are checked for MIME and count; byte limits apply to inline blobs only. */
|
|
352
349
|
function assertTurnAttachments(profile, attachments, voice) {
|
|
353
350
|
if (!hasTurnBlobs(attachments, voice))
|
|
354
351
|
return;
|
|
352
|
+
const limits = requireMediaLimits(profile);
|
|
355
353
|
const issues = attachmentIssues({
|
|
356
354
|
attachments: profileAccept(profile, 'attachments'),
|
|
357
355
|
voice: profileAccept(profile, 'voice'),
|
|
358
|
-
limits
|
|
356
|
+
limits,
|
|
359
357
|
}, (attachments ?? []).map(factsOf), (voice ?? []).map(factsOf));
|
|
360
358
|
if (issues.length > 0)
|
|
361
359
|
throw attachmentsRefused(issues);
|
|
362
360
|
}
|
|
363
|
-
/**
|
|
364
|
-
* invariant: a file the profile does not take is left out and the turn goes on; what names no file
|
|
365
|
-
* (too many files, too many bytes in all) refuses the turn, since no one file is at fault.
|
|
366
|
-
* Provider references are checked for MIME and count; byte limits apply to inline blobs only.
|
|
367
|
-
*/
|
|
368
|
-
function splitTurnAttachments(profile, attachments, voice) {
|
|
369
|
-
if (!hasTurnBlobs(attachments, voice))
|
|
370
|
-
return { attachments, voice, leftOut: [] };
|
|
371
|
-
const rules = {
|
|
372
|
-
attachments: profileAccept(profile, 'attachments'),
|
|
373
|
-
voice: profileAccept(profile, 'voice'),
|
|
374
|
-
limits: requireMediaLimits(profile),
|
|
375
|
-
};
|
|
376
|
-
const leftOut = [];
|
|
377
|
-
const keep = (items, channel) => items?.filter((item) => {
|
|
378
|
-
const one = [factsOf(item)];
|
|
379
|
-
const issues = channel === 'voice' ? attachmentIssues(rules, [], one) : attachmentIssues(rules, one, []);
|
|
380
|
-
if (issues.length === 0)
|
|
381
|
-
return true;
|
|
382
|
-
leftOut.push({ mimeType: item.mimeType, channel, issues });
|
|
383
|
-
return false;
|
|
384
|
-
});
|
|
385
|
-
const kept = { attachments: keep(attachments, 'attachment'), voice: keep(voice, 'voice') };
|
|
386
|
-
const issues = attachmentIssues(rules, (kept.attachments ?? []).map(factsOf), (kept.voice ?? []).map(factsOf));
|
|
387
|
-
if (issues.length > 0)
|
|
388
|
-
throw attachmentsRefused(issues);
|
|
389
|
-
return { ...kept, leftOut };
|
|
390
|
-
}
|
|
391
361
|
function sanitizeAttachment(blob, reader) {
|
|
392
362
|
if (isTurnMediaRef(blob)) {
|
|
393
363
|
return blob;
|
|
@@ -410,15 +380,12 @@ function hasTurnBlobs(attachments, voice) {
|
|
|
410
380
|
}
|
|
411
381
|
/** Provider file references pass through unsanitized: the kernel has no bytes to scan. */
|
|
412
382
|
function sanitizeTurnBlobs(profile, attachments, voice, at) {
|
|
413
|
-
|
|
383
|
+
assertTurnAttachments(profile, attachments, voice);
|
|
414
384
|
return {
|
|
415
|
-
attachments:
|
|
416
|
-
?
|
|
417
|
-
:
|
|
418
|
-
voice:
|
|
419
|
-
? kept.voice.map((blob) => sanitizeAttachment(blob, at.voice))
|
|
420
|
-
: kept.voice,
|
|
421
|
-
leftOut: kept.leftOut,
|
|
385
|
+
attachments: attachments?.length
|
|
386
|
+
? attachments.map((blob) => sanitizeAttachment(blob, at.attachment))
|
|
387
|
+
: attachments,
|
|
388
|
+
voice: voice?.length ? voice.map((blob) => sanitizeAttachment(blob, at.voice)) : voice,
|
|
422
389
|
};
|
|
423
390
|
}
|
|
424
|
-
export { assertTurnAttachments, attachmentIssueCopy, attachmentIssues, attachmentIssueText, attachmentsRefused, base64Bytes, isTextFile, isTextFileData, isTurnMediaRef, maxBytesForMime, modelTextFile, requireMediaLimits, resolveMediaLimits, rewriteTextFile, sanitizeCsvText, sanitizeTurnBlobs,
|
|
391
|
+
export { assertTurnAttachments, attachmentIssueCopy, attachmentIssues, attachmentIssueText, attachmentsRefused, base64Bytes, isTextFile, isTextFileData, isTurnMediaRef, maxBytesForMime, modelTextFile, requireMediaLimits, resolveMediaLimits, rewriteTextFile, sanitizeCsvText, sanitizeTurnBlobs, textFileText, };
|
|
@@ -85,7 +85,7 @@ function assertMediaMime(mime) {
|
|
|
85
85
|
}
|
|
86
86
|
return kind;
|
|
87
87
|
}
|
|
88
|
-
/** Runs after `
|
|
88
|
+
/** Runs after `assertTurnAttachments`. A reference's uri passes untouched: the host owns the upload. */
|
|
89
89
|
function mediaParts(blobs) {
|
|
90
90
|
return blobs.map((blob) => {
|
|
91
91
|
const kind = assertMediaMime(blob.mimeType);
|
|
@@ -142,7 +142,7 @@ function pinnedReferenceParts(profile) {
|
|
|
142
142
|
? mediaParts(profile.image.references)
|
|
143
143
|
: [];
|
|
144
144
|
}
|
|
145
|
-
/** `sanitizeTurnRequest` has already
|
|
145
|
+
/** `sanitizeTurnRequest` has already checked the blobs against the profile's limits and accept lists. */
|
|
146
146
|
function extractMediaParts(profile, req) {
|
|
147
147
|
const files = req.input?.attachments ?? [];
|
|
148
148
|
const clips = req.input?.voice ?? [];
|
|
@@ -591,17 +591,12 @@ export interface RefusedMedia {
|
|
|
591
591
|
from: 'input' | 'history' | 'tool';
|
|
592
592
|
}
|
|
593
593
|
/**
|
|
594
|
-
* The turn went on without files
|
|
595
|
-
*
|
|
596
|
-
* listed only when the same call, sent without it, was accepted: that is the proof it was at fault.
|
|
594
|
+
* The turn went on without files the provider refused. Set only when the same call, sent
|
|
595
|
+
* without them, was accepted: that is the proof the files were at fault.
|
|
597
596
|
*/
|
|
598
597
|
export interface MediaRefused {
|
|
599
598
|
dropped: RefusedMedia[];
|
|
600
|
-
/**
|
|
601
|
-
* Why, for the builder only: `forClient` strips the whole report. A line per file left out
|
|
602
|
-
* names its type and each check it failed (`image/gif: mime_not_allowed`); then the provider's
|
|
603
|
-
* own reason.
|
|
604
|
-
*/
|
|
599
|
+
/** The provider's own reason, for the builder only: `forClient` strips the whole report. */
|
|
605
600
|
said: string;
|
|
606
601
|
}
|
|
607
602
|
export interface DoneBase {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/agents",
|
|
3
|
-
"version": "0.3.5-next.
|
|
3
|
+
"version": "0.3.5-next.961.g4178e57",
|
|
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",
|