agentfootprint 14.2.0 → 14.3.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/AGENTS.md +2 -2
- package/CAPABILITIES.md +2 -0
- package/ai-instructions/claude-code/SKILL.md +2 -2
- package/dist/adapters/observability/auditShapes.js +8 -9
- package/dist/adapters/observability/auditShapes.js.map +1 -1
- package/dist/core/Agent.js +91 -158
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/AgentBuilder.js +29 -69
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/aroundTurn/errors.js +38 -0
- package/dist/core/agent/aroundTurn/errors.js.map +1 -0
- package/dist/core/agent/aroundTurn/funnel.js +164 -0
- package/dist/core/agent/aroundTurn/funnel.js.map +1 -0
- package/dist/core/agent/aroundTurn/guards.js +34 -0
- package/dist/core/agent/aroundTurn/guards.js.map +1 -0
- package/dist/core/agent/aroundTurn/index.js +13 -0
- package/dist/core/agent/aroundTurn/index.js.map +1 -0
- package/dist/core/agent/aroundTurn/readOnlyCopy.js +52 -0
- package/dist/core/agent/aroundTurn/readOnlyCopy.js.map +1 -0
- package/dist/core/agent/aroundTurn/types.js +6 -0
- package/dist/core/agent/aroundTurn/types.js.map +1 -0
- package/dist/core/agent/assessment/answerLayerOptions.js +72 -0
- package/dist/core/agent/assessment/answerLayerOptions.js.map +1 -0
- package/dist/core/agent/hostTurn.js +1 -0
- package/dist/core/agent/hostTurn.js.map +1 -1
- package/dist/core/agent/run/eventStageIds.js +6 -1
- package/dist/core/agent/run/eventStageIds.js.map +1 -1
- package/dist/core/agent/run/outputStrategySupport.js +62 -0
- package/dist/core/agent/run/outputStrategySupport.js.map +1 -0
- package/dist/core/agent/run/terminalRunError.js +44 -0
- package/dist/core/agent/run/terminalRunError.js.map +1 -0
- package/dist/core/runnerLive.js.map +1 -1
- package/dist/doors/time.js +11 -3
- package/dist/doors/time.js.map +1 -1
- package/dist/esm/adapters/observability/auditShapes.js +8 -9
- package/dist/esm/adapters/observability/auditShapes.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +13 -27
- package/dist/esm/core/Agent.js +86 -153
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/AgentBuilder.d.ts +22 -0
- package/dist/esm/core/agent/AgentBuilder.js +27 -67
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/aroundTurn/errors.d.ts +15 -0
- package/dist/esm/core/agent/aroundTurn/errors.js +34 -0
- package/dist/esm/core/agent/aroundTurn/errors.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/funnel.d.ts +18 -0
- package/dist/esm/core/agent/aroundTurn/funnel.js +159 -0
- package/dist/esm/core/agent/aroundTurn/funnel.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/guards.d.ts +16 -0
- package/dist/esm/core/agent/aroundTurn/guards.js +28 -0
- package/dist/esm/core/agent/aroundTurn/guards.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/index.d.ts +4 -0
- package/dist/esm/core/agent/aroundTurn/index.js +4 -0
- package/dist/esm/core/agent/aroundTurn/index.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/readOnlyCopy.d.ts +12 -0
- package/dist/esm/core/agent/aroundTurn/readOnlyCopy.js +48 -0
- package/dist/esm/core/agent/aroundTurn/readOnlyCopy.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/types.d.ts +57 -0
- package/dist/esm/core/agent/aroundTurn/types.js +5 -0
- package/dist/esm/core/agent/aroundTurn/types.js.map +1 -0
- package/dist/esm/core/agent/assessment/answerLayerOptions.d.ts +21 -0
- package/dist/esm/core/agent/assessment/answerLayerOptions.js +67 -0
- package/dist/esm/core/agent/assessment/answerLayerOptions.js.map +1 -0
- package/dist/esm/core/agent/hostTurn.d.ts +2 -0
- package/dist/esm/core/agent/hostTurn.js +1 -0
- package/dist/esm/core/agent/hostTurn.js.map +1 -1
- package/dist/esm/core/agent/run/eventStageIds.d.ts +5 -0
- package/dist/esm/core/agent/run/eventStageIds.js +5 -0
- package/dist/esm/core/agent/run/eventStageIds.js.map +1 -1
- package/dist/esm/core/agent/run/outputStrategySupport.d.ts +26 -0
- package/dist/esm/core/agent/run/outputStrategySupport.js +58 -0
- package/dist/esm/core/agent/run/outputStrategySupport.js.map +1 -0
- package/dist/esm/core/agent/run/terminalRunError.d.ts +22 -0
- package/dist/esm/core/agent/run/terminalRunError.js +40 -0
- package/dist/esm/core/agent/run/terminalRunError.js.map +1 -0
- package/dist/esm/core/runnerLive.d.ts +3 -0
- package/dist/esm/core/runnerLive.js.map +1 -1
- package/dist/esm/doors/time.d.ts +9 -2
- package/dist/esm/doors/time.js +9 -2
- package/dist/esm/doors/time.js.map +1 -1
- package/dist/esm/events/dispatcher.d.ts +4 -4
- package/dist/esm/events/dispatcher.js +4 -4
- package/dist/esm/events/payloads/agent.d.ts +8 -0
- package/dist/esm/events/payloads.d.ts +1 -1
- package/dist/esm/events/registry.d.ts +4 -5
- package/dist/esm/events/registry.js +4 -7
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/hosting/errors.d.ts +18 -15
- package/dist/esm/hosting/errors.js +23 -22
- package/dist/esm/hosting/errors.js.map +1 -1
- package/dist/esm/hosting/index.d.ts +2 -1
- package/dist/esm/hosting/index.js +2 -1
- package/dist/esm/hosting/index.js.map +1 -1
- package/dist/esm/hosting/requireCapability.d.ts +8 -0
- package/dist/esm/hosting/requireCapability.js +16 -0
- package/dist/esm/hosting/requireCapability.js.map +1 -0
- package/dist/esm/hosting/standingAgent.js +33 -34
- package/dist/esm/hosting/standingAgent.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +6 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/locales/timeAsk.js +1 -1
- package/dist/esm/locales/timeAsk.js.map +1 -1
- package/dist/esm/redaction/knownStrings.d.ts +3 -5
- package/dist/esm/redaction/knownStrings.js +2 -0
- package/dist/esm/redaction/knownStrings.js.map +1 -1
- package/dist/esm/time/readers/english/grammar.d.ts +3 -3
- package/dist/esm/time/readers/english/grammar.js +4 -4
- package/dist/esm/time/readers/english/grammar.js.map +1 -1
- package/dist/esm/time/readers/english.d.ts +1 -1
- package/dist/esm/time/readers/english.js +1 -1
- package/dist/esm/time/replyForm/bindings.d.ts +20 -1
- package/dist/esm/time/replyForm/bindings.js +31 -12
- package/dist/esm/time/replyForm/bindings.js.map +1 -1
- package/dist/events/dispatcher.js +4 -4
- package/dist/events/registry.js +4 -7
- package/dist/events/registry.js.map +1 -1
- package/dist/hosting/errors.js +25 -24
- package/dist/hosting/errors.js.map +1 -1
- package/dist/hosting/index.js +6 -4
- package/dist/hosting/index.js.map +1 -1
- package/dist/hosting/requireCapability.js +20 -0
- package/dist/hosting/requireCapability.js.map +1 -0
- package/dist/hosting/standingAgent.js +32 -33
- package/dist/hosting/standingAgent.js.map +1 -1
- package/dist/index.js +122 -131
- package/dist/index.js.map +1 -1
- package/dist/locales/timeAsk.js +1 -1
- package/dist/locales/timeAsk.js.map +1 -1
- package/dist/redaction/knownStrings.js +2 -0
- package/dist/redaction/knownStrings.js.map +1 -1
- package/dist/time/readers/english/grammar.js +4 -4
- package/dist/time/readers/english/grammar.js.map +1 -1
- package/dist/time/readers/english.js +1 -1
- package/dist/time/replyForm/bindings.js +31 -12
- package/dist/time/replyForm/bindings.js.map +1 -1
- package/dist/types/core/Agent.d.ts +13 -27
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/AgentBuilder.d.ts +22 -0
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/aroundTurn/errors.d.ts +16 -0
- package/dist/types/core/agent/aroundTurn/errors.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/funnel.d.ts +19 -0
- package/dist/types/core/agent/aroundTurn/funnel.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/guards.d.ts +17 -0
- package/dist/types/core/agent/aroundTurn/guards.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/index.d.ts +5 -0
- package/dist/types/core/agent/aroundTurn/index.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/readOnlyCopy.d.ts +13 -0
- package/dist/types/core/agent/aroundTurn/readOnlyCopy.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/types.d.ts +58 -0
- package/dist/types/core/agent/aroundTurn/types.d.ts.map +1 -0
- package/dist/types/core/agent/assessment/answerLayerOptions.d.ts +22 -0
- package/dist/types/core/agent/assessment/answerLayerOptions.d.ts.map +1 -0
- package/dist/types/core/agent/hostTurn.d.ts +2 -0
- package/dist/types/core/agent/hostTurn.d.ts.map +1 -1
- package/dist/types/core/agent/run/eventStageIds.d.ts +5 -0
- package/dist/types/core/agent/run/eventStageIds.d.ts.map +1 -1
- package/dist/types/core/agent/run/outputStrategySupport.d.ts +27 -0
- package/dist/types/core/agent/run/outputStrategySupport.d.ts.map +1 -0
- package/dist/types/core/agent/run/terminalRunError.d.ts +23 -0
- package/dist/types/core/agent/run/terminalRunError.d.ts.map +1 -0
- package/dist/types/core/runnerLive.d.ts +3 -0
- package/dist/types/core/runnerLive.d.ts.map +1 -1
- package/dist/types/doors/time.d.ts +9 -2
- package/dist/types/doors/time.d.ts.map +1 -1
- package/dist/types/events/dispatcher.d.ts +4 -4
- package/dist/types/events/payloads/agent.d.ts +8 -0
- package/dist/types/events/payloads/agent.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +1 -1
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +4 -5
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/hosting/errors.d.ts +18 -15
- package/dist/types/hosting/errors.d.ts.map +1 -1
- package/dist/types/hosting/index.d.ts +2 -1
- package/dist/types/hosting/index.d.ts.map +1 -1
- package/dist/types/hosting/requireCapability.d.ts +9 -0
- package/dist/types/hosting/requireCapability.d.ts.map +1 -0
- package/dist/types/hosting/standingAgent.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/redaction/knownStrings.d.ts +3 -5
- package/dist/types/redaction/knownStrings.d.ts.map +1 -1
- package/dist/types/time/readers/english/grammar.d.ts +3 -3
- package/dist/types/time/readers/english/grammar.d.ts.map +1 -1
- package/dist/types/time/readers/english.d.ts +1 -1
- package/dist/types/time/replyForm/bindings.d.ts +20 -1
- package/dist/types/time/replyForm/bindings.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one funnel every top-level turn of an Agent passes through.
|
|
3
|
+
*
|
|
4
|
+
* With no wrapper this hands straight to the leg, adding no await. With one,
|
|
5
|
+
* the wrapper may wrap the turn and ask for the named changes; it cannot
|
|
6
|
+
* change how the turn ended. See ./README.md for the table of what happens
|
|
7
|
+
* when a wrapper misbehaves.
|
|
8
|
+
*/
|
|
9
|
+
import { AroundTurnError } from './errors.js';
|
|
10
|
+
import { readOnlyCopy } from './readOnlyCopy.js';
|
|
11
|
+
const IDENTIFIER = /^[A-Za-z_$][\w$]{0,127}$/;
|
|
12
|
+
/** Nothing noted yet. Not `undefined`: a wrapper may throw `undefined`. */
|
|
13
|
+
const NOTHING_NOTED = Symbol('nothing noted');
|
|
14
|
+
/** The class of a thrown value, or a fixed word. Never its message, and never throws. */
|
|
15
|
+
function errorClassOf(thrown) {
|
|
16
|
+
try {
|
|
17
|
+
if (!(thrown instanceof Error))
|
|
18
|
+
return 'non-error';
|
|
19
|
+
const name = thrown.constructor?.name;
|
|
20
|
+
return typeof name === 'string' && IDENTIFIER.test(name) ? name : 'Error';
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return 'Error';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function changeProblem(kind, changes) {
|
|
27
|
+
if (changes === undefined)
|
|
28
|
+
return undefined;
|
|
29
|
+
if (typeof changes !== 'object' || changes === null || Array.isArray(changes))
|
|
30
|
+
return 'unknown-change';
|
|
31
|
+
const named = Object.keys(changes);
|
|
32
|
+
if (named.length === 0)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (kind === 'resume')
|
|
35
|
+
return 'change-on-resume';
|
|
36
|
+
return named.every((key) => key === 'time') ? undefined : 'unknown-change';
|
|
37
|
+
}
|
|
38
|
+
function readOnlyTurn(turn) {
|
|
39
|
+
return turn.kind === 'run'
|
|
40
|
+
? Object.freeze({
|
|
41
|
+
...turn,
|
|
42
|
+
input: readOnlyCopy(turn.input),
|
|
43
|
+
options: readOnlyCopy(turn.options),
|
|
44
|
+
})
|
|
45
|
+
: Object.freeze({
|
|
46
|
+
...turn,
|
|
47
|
+
checkpoint: readOnlyCopy(turn.checkpoint),
|
|
48
|
+
answer: readOnlyCopy(turn.answer),
|
|
49
|
+
options: readOnlyCopy(turn.options),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function wrapped(port, turn, leg, report) {
|
|
53
|
+
const { name } = port;
|
|
54
|
+
let running;
|
|
55
|
+
// Taken before any code the wrapper can reach runs: a `time` getter may call `proceed`.
|
|
56
|
+
let claimed = false;
|
|
57
|
+
let settled;
|
|
58
|
+
let wrapperOpen = true;
|
|
59
|
+
let lastNoted = NOTHING_NOTED;
|
|
60
|
+
const note = (error) => {
|
|
61
|
+
if (error === lastNoted)
|
|
62
|
+
return;
|
|
63
|
+
lastNoted = error;
|
|
64
|
+
try {
|
|
65
|
+
report({ wrapper: name, errorClass: errorClassOf(error) });
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// A failure to report can never change the outcome.
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
// Handled here so a wrapper that never awaits cannot crash the process.
|
|
72
|
+
const handled = (promise) => {
|
|
73
|
+
promise.catch(() => undefined);
|
|
74
|
+
return promise;
|
|
75
|
+
};
|
|
76
|
+
const refused = (reason) => {
|
|
77
|
+
const error = new AroundTurnError(reason, name);
|
|
78
|
+
if (claimed)
|
|
79
|
+
note(error);
|
|
80
|
+
return handled(Promise.reject(error));
|
|
81
|
+
};
|
|
82
|
+
const proceed = (changes) => {
|
|
83
|
+
if (!wrapperOpen)
|
|
84
|
+
return refused('late-proceed');
|
|
85
|
+
if (claimed)
|
|
86
|
+
return refused('second-proceed');
|
|
87
|
+
claimed = true;
|
|
88
|
+
let problem;
|
|
89
|
+
try {
|
|
90
|
+
problem = changeProblem(turn.kind, changes);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
// A Proxy's trap threw. No leg started, so the wrapper may still call again.
|
|
94
|
+
claimed = false;
|
|
95
|
+
return handled(Promise.reject(error));
|
|
96
|
+
}
|
|
97
|
+
if (problem !== undefined) {
|
|
98
|
+
claimed = false;
|
|
99
|
+
return refused(problem);
|
|
100
|
+
}
|
|
101
|
+
running = (async () => leg(changes))().then((value) => {
|
|
102
|
+
settled = { value };
|
|
103
|
+
}, (error) => {
|
|
104
|
+
settled = { error };
|
|
105
|
+
throw error;
|
|
106
|
+
});
|
|
107
|
+
return handled(running);
|
|
108
|
+
};
|
|
109
|
+
let thrown;
|
|
110
|
+
try {
|
|
111
|
+
await port.around(readOnlyTurn(turn), proceed);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
thrown = { error };
|
|
115
|
+
}
|
|
116
|
+
wrapperOpen = false;
|
|
117
|
+
const run = running;
|
|
118
|
+
if (run === undefined) {
|
|
119
|
+
throw thrown !== undefined ? thrown.error : new AroundTurnError('not-proceeded', name);
|
|
120
|
+
}
|
|
121
|
+
// The turn holds its lease until the run itself is over, awaited or not.
|
|
122
|
+
await run.catch(() => undefined);
|
|
123
|
+
const outcome = settled;
|
|
124
|
+
const runError = 'error' in outcome ? outcome : undefined;
|
|
125
|
+
if (thrown !== undefined && (runError === undefined || thrown.error !== runError.error))
|
|
126
|
+
note(thrown.error);
|
|
127
|
+
if (runError !== undefined)
|
|
128
|
+
throw runError.error;
|
|
129
|
+
return outcome.value;
|
|
130
|
+
}
|
|
131
|
+
/** The funnel. `undefined` is an agent with no wrapper: the leg, with nothing added. */
|
|
132
|
+
export function throughAroundTurn(port, turn, leg, report) {
|
|
133
|
+
return port === undefined ? leg(undefined) : wrapped(port, turn, leg, report);
|
|
134
|
+
}
|
|
135
|
+
function isFieldBag(value) {
|
|
136
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The input a run starts from once a wrapper's changes are applied. No `time`
|
|
140
|
+
* is the input itself. An input the run would refuse is left for it to refuse;
|
|
141
|
+
* a malformed `time` reaches the run's own reader, which refuses it by name.
|
|
142
|
+
*/
|
|
143
|
+
export function runInputWith(input, options, changes) {
|
|
144
|
+
const time = changes?.time;
|
|
145
|
+
if (time === undefined)
|
|
146
|
+
return input;
|
|
147
|
+
const bag = typeof input === 'string' ? { message: input } : input;
|
|
148
|
+
if (!isFieldBag(bag))
|
|
149
|
+
return input;
|
|
150
|
+
const stated = bag.time ?? options?.time;
|
|
151
|
+
const merged = !isFieldBag(time)
|
|
152
|
+
? time
|
|
153
|
+
: {
|
|
154
|
+
...(isFieldBag(stated) && stated),
|
|
155
|
+
...Object.fromEntries(Object.entries(time).filter(([, field]) => field !== undefined)),
|
|
156
|
+
};
|
|
157
|
+
return { ...bag, time: merged };
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=funnel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funnel.js","sourceRoot":"","sources":["../../../../../src/core/agent/aroundTurn/funnel.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAC9C,2EAA2E;AAC3E,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAE9C,yF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ACH,MAAM,UAAU,YAAY,CAC1B,KAAuB,EACvB,OAA2B,EAC3B,OAAgC;IAEhC,MAAM,IAAI,GAAY,OAAO,EAAE,IAAI,CAAC;IACpC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACrC,MAAM,GAAG,GAAY,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5E,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,MAAM,MAAM,GAAY,GAAG,CAAC,IAAI,IAAI,OAAO,EAAE,IAAI,CAAC;IAClD,MAAM,MAAM,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QAC9B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC;YACE,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC;YACjC,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;SACvF,CAAC;IACN,OAAO,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAsB,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The build-time and host-time rules around `.aroundTurn()`, as plain functions.
|
|
3
|
+
*/
|
|
4
|
+
import type { AroundTurn } from './types.js';
|
|
5
|
+
/** The builder's rule: one wrapper per agent, of the right shape. */
|
|
6
|
+
export declare function admitAroundTurn(wrapper: AroundTurn, declared: AroundTurn | undefined): AroundTurn;
|
|
7
|
+
/** A mount has no turn to wrap, so a wrapper could not run there. Refused, never skipped. */
|
|
8
|
+
export declare function refuseMountedWrapper(port: AroundTurn | undefined): void;
|
|
9
|
+
/** The two public doors a host must not route around silently. */
|
|
10
|
+
export type TurnMethod = 'run' | 'resume';
|
|
11
|
+
/**
|
|
12
|
+
* Which of `runner`'s turn doors are not the class's own — an own property or a
|
|
13
|
+
* subclass override alike. `own` is captured when the class loads, so a later
|
|
14
|
+
* patch of the prototype counts too.
|
|
15
|
+
*/
|
|
16
|
+
export declare function replacedTurnMethods(runner: object, own: Readonly<Record<TurnMethod, unknown>>): readonly TurnMethod[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The build-time and host-time rules around `.aroundTurn()`, as plain functions.
|
|
3
|
+
*/
|
|
4
|
+
import { AroundTurnError } from './errors.js';
|
|
5
|
+
/** The builder's rule: one wrapper per agent, of the right shape. */
|
|
6
|
+
export function admitAroundTurn(wrapper, declared) {
|
|
7
|
+
if (declared !== undefined)
|
|
8
|
+
throw new AroundTurnError('second-wrapper', declared.name);
|
|
9
|
+
const { name, around } = (wrapper ?? {});
|
|
10
|
+
if (typeof name !== 'string' || name.length === 0 || typeof around !== 'function')
|
|
11
|
+
throw new AroundTurnError('invalid-wrapper', typeof name === 'string' ? name : '');
|
|
12
|
+
return wrapper;
|
|
13
|
+
}
|
|
14
|
+
/** A mount has no turn to wrap, so a wrapper could not run there. Refused, never skipped. */
|
|
15
|
+
export function refuseMountedWrapper(port) {
|
|
16
|
+
if (port !== undefined)
|
|
17
|
+
throw new AroundTurnError('mounted', port.name);
|
|
18
|
+
}
|
|
19
|
+
const TURN_METHODS = ['run', 'resume'];
|
|
20
|
+
/**
|
|
21
|
+
* Which of `runner`'s turn doors are not the class's own — an own property or a
|
|
22
|
+
* subclass override alike. `own` is captured when the class loads, so a later
|
|
23
|
+
* patch of the prototype counts too.
|
|
24
|
+
*/
|
|
25
|
+
export function replacedTurnMethods(runner, own) {
|
|
26
|
+
return TURN_METHODS.filter((method) => runner[method] !== own[method]);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../../src/core/agent/aroundTurn/guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,qEAAqE;AACrE,MAAM,UAAU,eAAe,CAAC,OAAmB,EAAE,QAAgC;IACnF,IAAI,QAAQ,KAAK,SAAS;QAAE,MAAM,IAAI,eAAe,CAAC,gBAAgB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvF,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,CAAwB,CAAC;IAChE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,MAAM,KAAK,UAAU;QAC/E,MAAM,IAAI,eAAe,CAAC,iBAAiB,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,oBAAoB,CAAC,IAA4B;IAC/D,IAAI,IAAI,KAAK,SAAS;QAAE,MAAM,IAAI,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1E,CAAC;AAKD,MAAM,YAAY,GAA0B,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAE9D;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAc,EACd,GAA0C;IAE1C,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,MAAM,EAAE,EAAE,CAAE,MAAkC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,CACxE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AroundTurnError, type AroundTurnRefusal } from './errors.js';
|
|
2
|
+
export { runInputWith, throughAroundTurn } from './funnel.js';
|
|
3
|
+
export { admitAroundTurn, refuseMountedWrapper, replacedTurnMethods, type TurnMethod, } from './guards.js';
|
|
4
|
+
export type { AgentTurn, AroundTurn, ProceedWithTurn, ResumeTurn, RunTurn, TurnChanges, } from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/agent/aroundTurn/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,mBAAmB,GAEpB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A frozen copy of a turn's plain data, for the wrapper to read.
|
|
3
|
+
*
|
|
4
|
+
* The run keeps the originals, so nothing the wrapper does to its copy can
|
|
5
|
+
* reach the run, and the caller's own objects are never frozen. Anything that
|
|
6
|
+
* is not plain data — an `AbortSignal`, a sealed request handle, a `Date`, a
|
|
7
|
+
* function — keeps its identity and is passed as it is.
|
|
8
|
+
*
|
|
9
|
+
* Iterative, because a request body can nest deeper than the call stack. No
|
|
10
|
+
* getter runs: an accessor property is copied as an accessor.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readOnlyCopy<T>(value: T): T;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A frozen copy of a turn's plain data, for the wrapper to read.
|
|
3
|
+
*
|
|
4
|
+
* The run keeps the originals, so nothing the wrapper does to its copy can
|
|
5
|
+
* reach the run, and the caller's own objects are never frozen. Anything that
|
|
6
|
+
* is not plain data — an `AbortSignal`, a sealed request handle, a `Date`, a
|
|
7
|
+
* function — keeps its identity and is passed as it is.
|
|
8
|
+
*
|
|
9
|
+
* Iterative, because a request body can nest deeper than the call stack. No
|
|
10
|
+
* getter runs: an accessor property is copied as an accessor.
|
|
11
|
+
*/
|
|
12
|
+
function isPlainData(value) {
|
|
13
|
+
if (value === null || typeof value !== 'object')
|
|
14
|
+
return false;
|
|
15
|
+
if (Array.isArray(value))
|
|
16
|
+
return true;
|
|
17
|
+
const prototype = Object.getPrototypeOf(value);
|
|
18
|
+
return prototype === Object.prototype || prototype === null;
|
|
19
|
+
}
|
|
20
|
+
export function readOnlyCopy(value) {
|
|
21
|
+
const copies = new Map();
|
|
22
|
+
const pending = [];
|
|
23
|
+
const copyOf = (held) => {
|
|
24
|
+
if (!isPlainData(held))
|
|
25
|
+
return held;
|
|
26
|
+
const known = copies.get(held);
|
|
27
|
+
if (known !== undefined)
|
|
28
|
+
return known;
|
|
29
|
+
const copy = Array.isArray(held) ? [] : Object.create(Object.getPrototypeOf(held));
|
|
30
|
+
copies.set(held, copy);
|
|
31
|
+
pending.push(held);
|
|
32
|
+
return copy;
|
|
33
|
+
};
|
|
34
|
+
const root = copyOf(value);
|
|
35
|
+
for (let from = pending.pop(); from !== undefined; from = pending.pop()) {
|
|
36
|
+
const to = copies.get(from);
|
|
37
|
+
for (const key of Reflect.ownKeys(from)) {
|
|
38
|
+
const field = Object.getOwnPropertyDescriptor(from, key);
|
|
39
|
+
if ('value' in field)
|
|
40
|
+
field.value = copyOf(field.value);
|
|
41
|
+
Object.defineProperty(to, key, field);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const copy of copies.values())
|
|
45
|
+
Object.freeze(copy);
|
|
46
|
+
return root;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=readOnlyCopy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readOnlyCopy.js","sourceRoot":"","sources":["../../../../../src/core/agent/aroundTurn/readOnlyCopy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ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,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,MAAM,KAAK,GAAG,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,GAAG,CAAuB,CAAC;YAC/E,IAAI,OAAO,IAAI,KAAK;gBAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxD,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shapes of `.aroundTurn()` — what a wrapper is handed and what it may ask.
|
|
3
|
+
*/
|
|
4
|
+
import type { FlowchartCheckpoint } from 'footprintjs';
|
|
5
|
+
import type { RunTime } from '../../../time/clock.js';
|
|
6
|
+
import type { AgentRunOptions } from '../../Agent.js';
|
|
7
|
+
import type { AgentInput } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* A new turn: what `run`, `runTyped`, `followUp`, `resumeOnError` and a hosted
|
|
10
|
+
* message hand the agent. A read-only copy — editing it fails, and could not
|
|
11
|
+
* reach the run. The one change a wrapper may ask for is {@link TurnChanges}.
|
|
12
|
+
*/
|
|
13
|
+
export interface RunTurn {
|
|
14
|
+
readonly kind: 'run';
|
|
15
|
+
readonly input: AgentInput | string;
|
|
16
|
+
readonly options: AgentRunOptions | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A paused turn being answered: what `resume` and a hosted answer hand the
|
|
20
|
+
* agent. A read-only copy. A resume accepts no change: the paused turn keeps
|
|
21
|
+
* its clock and its caller.
|
|
22
|
+
*/
|
|
23
|
+
export interface ResumeTurn {
|
|
24
|
+
readonly kind: 'resume';
|
|
25
|
+
readonly checkpoint: FlowchartCheckpoint;
|
|
26
|
+
readonly answer: unknown;
|
|
27
|
+
readonly options: AgentRunOptions | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** The turn a wrapper is wrapped around, told apart by `kind`. */
|
|
30
|
+
export type AgentTurn = RunTurn | ResumeTurn;
|
|
31
|
+
/**
|
|
32
|
+
* The closed set of changes `proceed` accepts, on a `run` turn only.
|
|
33
|
+
*
|
|
34
|
+
* `time` takes the path `run({ time })` takes, so the clock row is the normal
|
|
35
|
+
* one. A field the wrapper names wins; a field it leaves out stays the
|
|
36
|
+
* caller's (`input.time`, else `options.time`).
|
|
37
|
+
*/
|
|
38
|
+
export interface TurnChanges {
|
|
39
|
+
readonly time?: RunTime;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Runs the turn. Resolves to nothing: the output, the pause and the checkpoint
|
|
43
|
+
* stay with the library. Rejects with the run's own error when the run fails.
|
|
44
|
+
* Call it once, while the wrapper is still running.
|
|
45
|
+
*/
|
|
46
|
+
export type ProceedWithTurn = (changes?: TurnChanges) => Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Work that must wrap a whole turn: awaited preparation before it, an
|
|
49
|
+
* `AsyncLocalStorage` held around it, cleanup after it. Declared with
|
|
50
|
+
* `.aroundTurn()` on the builder.
|
|
51
|
+
*/
|
|
52
|
+
export interface AroundTurn {
|
|
53
|
+
/** Named on every refusal and on `agentfootprint.agent.around_turn_failed`. */
|
|
54
|
+
readonly name: string;
|
|
55
|
+
/** Do the work and call `proceed` once. Its return value is ignored. */
|
|
56
|
+
around(turn: AgentTurn, proceed: ProceedWithTurn): void | Promise<void>;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/core/agent/aroundTurn/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { StandingLineWhen } from './compose.js';
|
|
2
|
+
/**
|
|
3
|
+
* THE ANSWER LAYER'S ARM (honesty layer 4), checked by ONE rule for both of
|
|
4
|
+
* its doors — `.answerLayer(options)` and `AgentOptions.answerLayer` — so a
|
|
5
|
+
* value one door refuses, the other refuses too: an unknown key, a
|
|
6
|
+
* `standingLine` that is neither a boolean nor `{ when }`, or a `when` outside
|
|
7
|
+
* the three modes, is refused by name. Returns the arm normalised — the line's
|
|
8
|
+
* mode (`true` → `'always'`), or `{}` for no line.
|
|
9
|
+
*/
|
|
10
|
+
export declare function answerLayerArm(options: Readonly<Record<string, unknown>>, door: string): {
|
|
11
|
+
readonly standingLine?: StandingLineWhen;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* `AgentOptions.answerLayer` as the arm `build()` resolves: `undefined` when
|
|
15
|
+
* it is absent or `false`, `{}` for `true`, an object through
|
|
16
|
+
* `answerLayerArm` — so the options door meets every refusal the builder's
|
|
17
|
+
* door does. Anything else is refused by name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function answerLayerFromOptions(value: unknown): {
|
|
20
|
+
readonly standingLine?: StandingLineWhen;
|
|
21
|
+
} | undefined;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The line's modes, as the option doors check them — keyed by the type the
|
|
3
|
+
* layer's composer decides with (`assessment/compose.ts` · `StandingLineWhen`),
|
|
4
|
+
* so a mode added there does not compile until it is listed here. A type-only
|
|
5
|
+
* import: the composer stays off a plain agent's module graph.
|
|
6
|
+
*/
|
|
7
|
+
const STANDING_LINE_MODES = Object.freeze({
|
|
8
|
+
always: true,
|
|
9
|
+
'unless-consistent': true,
|
|
10
|
+
'not-sure-or-ask': true,
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* THE ANSWER LAYER'S ARM (honesty layer 4), checked by ONE rule for both of
|
|
14
|
+
* its doors — `.answerLayer(options)` and `AgentOptions.answerLayer` — so a
|
|
15
|
+
* value one door refuses, the other refuses too: an unknown key, a
|
|
16
|
+
* `standingLine` that is neither a boolean nor `{ when }`, or a `when` outside
|
|
17
|
+
* the three modes, is refused by name. Returns the arm normalised — the line's
|
|
18
|
+
* mode (`true` → `'always'`), or `{}` for no line.
|
|
19
|
+
*/
|
|
20
|
+
export function answerLayerArm(options, door) {
|
|
21
|
+
const unknown = Object.keys(options).filter((k) => k !== 'standingLine');
|
|
22
|
+
if (unknown.length > 0) {
|
|
23
|
+
throw new Error(`${door}: unknown option(s) ${unknown.map((k) => `'${k}'`).join(', ')}. ` +
|
|
24
|
+
"The one option is standingLine (boolean, or { when: 'always' | 'unless-consistent' | " +
|
|
25
|
+
"'not-sure-or-ask' }).");
|
|
26
|
+
}
|
|
27
|
+
const line = options.standingLine;
|
|
28
|
+
if (line === undefined || line === false)
|
|
29
|
+
return {};
|
|
30
|
+
if (line === true)
|
|
31
|
+
return { standingLine: 'always' };
|
|
32
|
+
const modes = Object.keys(STANDING_LINE_MODES)
|
|
33
|
+
.map((w) => `'${w}'`)
|
|
34
|
+
.join(', ');
|
|
35
|
+
if (typeof line !== 'object' || line === null || Array.isArray(line)) {
|
|
36
|
+
throw new Error(`${door}: standingLine must be a boolean or { when } — when is one of ${modes}.`);
|
|
37
|
+
}
|
|
38
|
+
const extra = Object.keys(line).filter((k) => k !== 'when');
|
|
39
|
+
if (extra.length > 0) {
|
|
40
|
+
throw new Error(`${door}: standingLine has unknown option(s) ${extra.map((k) => `'${k}'`).join(', ')}. ` +
|
|
41
|
+
`The one option is when: ${modes}.`);
|
|
42
|
+
}
|
|
43
|
+
const when = line.when;
|
|
44
|
+
if (typeof when !== 'string' ||
|
|
45
|
+
!Object.prototype.hasOwnProperty.call(STANDING_LINE_MODES, when)) {
|
|
46
|
+
throw new Error(`${door}: standingLine.when must be one of ${modes} (got ${JSON.stringify(when) ?? 'nothing'}).`);
|
|
47
|
+
}
|
|
48
|
+
return { standingLine: when };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `AgentOptions.answerLayer` as the arm `build()` resolves: `undefined` when
|
|
52
|
+
* it is absent or `false`, `{}` for `true`, an object through
|
|
53
|
+
* `answerLayerArm` — so the options door meets every refusal the builder's
|
|
54
|
+
* door does. Anything else is refused by name.
|
|
55
|
+
*/
|
|
56
|
+
export function answerLayerFromOptions(value) {
|
|
57
|
+
if (value === undefined || value === false)
|
|
58
|
+
return undefined;
|
|
59
|
+
if (value === true)
|
|
60
|
+
return {};
|
|
61
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
62
|
+
throw new Error('AgentOptions.answerLayer must be a boolean or an object — ' +
|
|
63
|
+
"{ standingLine?: boolean | { when: 'always' | 'unless-consistent' | 'not-sure-or-ask' } }.");
|
|
64
|
+
}
|
|
65
|
+
return answerLayerArm(value, 'AgentOptions.answerLayer');
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=answerLayerOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answerLayerOptions.js","sourceRoot":"","sources":["../../../../../src/core/agent/assessment/answerLayerOptions.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,mBAAmB,GAA+C,MAAM,CAAC,MAAM,CAAC;IACpF,MAAM,EAAE,IAAI;IACZ,mBAAmB,EAAE,IAAI;IACzB,iBAAiB,EAAE,IAAI;CACxB,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,OAA0C,EAC1C,IAAY;IAEZ,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC;IACzE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,uBAAuB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,I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AAC,EAChE,CAAC;QACD,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,sCAAsC,KAAK,SAChD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,SAC1B,IAAI,CACL,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,YAAY,EAAE,IAAwB,EAAE,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAc;IAEd,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7D,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CACb,4DAA4D;YAC1D,4FAA4F,CAC/F,CAAC;IACJ,CAAC;IACD,OAAO,cAAc,CAAC,KAA0C,EAAE,0BAA0B,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -6,11 +6,13 @@ import { type RunnerPauseOutcome } from '../pause.js';
|
|
|
6
6
|
import type { RunnerLive } from '../runnerLive.js';
|
|
7
7
|
import type { AgentRunCheckpoint } from '../runCheckpoint.js';
|
|
8
8
|
import type { FlowchartCheckpoint } from 'footprintjs';
|
|
9
|
+
import type { TurnMethod } from './aroundTurn/guards.js';
|
|
9
10
|
interface HostTurnPorts {
|
|
10
11
|
run(run: RunnerInvocation<AgentRunValues>, input: AgentInput | string, options?: AgentRunOptions): Promise<AgentOutput | RunnerPauseOutcome>;
|
|
11
12
|
resume(run: RunnerInvocation<AgentRunValues>, checkpoint: FlowchartCheckpoint, input?: unknown, options?: AgentRunOptions): Promise<AgentOutput | RunnerPauseOutcome>;
|
|
12
13
|
prepareResume(checkpoint: FlowchartCheckpoint): void;
|
|
13
14
|
checkpoint(run: RunnerSelection<AgentRunValues>): AgentRunCheckpoint | undefined;
|
|
15
|
+
replaced(): readonly TurnMethod[];
|
|
14
16
|
}
|
|
15
17
|
/** Host delivery uses this invocation's result and view, captured before its native lease ends. */
|
|
16
18
|
export declare function hostedTurns(execution: RunnerExecution<AgentRunValues>, ports: HostTurnPorts): NonNullable<RunnerLive['turn']>;
|
|
@@ -26,6 +26,7 @@ export function hostedTurns(execution, ports) {
|
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
28
|
return {
|
|
29
|
+
replaced: ports.replaced,
|
|
29
30
|
run: (input, options, bind) => capture((run) => ports.run(run, input, options), bind),
|
|
30
31
|
resume: (checkpoint, input, options, bind) => {
|
|
31
32
|
ports.prepareResume(checkpoint);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostTurn.js","sourceRoot":"","sources":["../../../../src/core/agent/hostTurn.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAA2B,MAAM,aAAa,CAAC;AAGhE,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"hostTurn.js","sourceRoot":"","sources":["../../../../src/core/agent/hostTurn.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAA2B,MAAM,aAAa,CAAC;AAGhE,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAoBrF,mGAAmG;AACnG,MAAM,UAAU,WAAW,CACzB,SAA0C,EAC1C,KAAoB;IAEpB,MAAM,OAAO,GAAG,CACd,IAA0F,EAC1F,IAA2B,EACN,EAAE,CACvB,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC9B,MAAM,QAAQ,GAAG,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAChF,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AAE,OAAO,EAAE,IAAI,EAAE,EAAE;YAC3C,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAChC,OAAO,OAAO,CACZ,CAAC,GAAG,EAAE,EAAE,CACN,uBAAuB,CACrB,GAAG,CAAC,QAAQ,EAAE,KAAK,EACnB,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,QAAQ,KAAK,IAAI,EACnD,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CACpD,EACH,IAAI,CACL,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
* `session_reused`, happen inside a real stage and carry its real id.
|
|
10
10
|
*/
|
|
11
11
|
export declare const TOOL_TEARDOWN_STAGE_ID = "tool-teardown#0";
|
|
12
|
+
/**
|
|
13
|
+
* The pseudo-stage `agentfootprint.agent.around_turn_failed` is stamped with: a
|
|
14
|
+
* wrapper fails around the run, where there is no stage to inherit.
|
|
15
|
+
*/
|
|
16
|
+
export declare const AROUND_TURN_STAGE_ID = "around-turn#0";
|
|
12
17
|
/**
|
|
13
18
|
* The pseudo-stage a LATE artifact fact is stamped with — one that lands after
|
|
14
19
|
* the run its binding was made in had ended (a tool's floating upload). Its
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
* `session_reused`, happen inside a real stage and carry its real id.
|
|
10
10
|
*/
|
|
11
11
|
export const TOOL_TEARDOWN_STAGE_ID = 'tool-teardown#0';
|
|
12
|
+
/**
|
|
13
|
+
* The pseudo-stage `agentfootprint.agent.around_turn_failed` is stamped with: a
|
|
14
|
+
* wrapper fails around the run, where there is no stage to inherit.
|
|
15
|
+
*/
|
|
16
|
+
export const AROUND_TURN_STAGE_ID = 'around-turn#0';
|
|
12
17
|
/**
|
|
13
18
|
* The pseudo-stage a LATE artifact fact is stamped with — one that lands after
|
|
14
19
|
* the run its binding was made in had ended (a tool's floating upload). Its
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventStageIds.js","sourceRoot":"","sources":["../../../../../src/core/agent/run/eventStageIds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,iBAAiB,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,yBAAyB,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"eventStageIds.js","sourceRoot":"","sources":["../../../../../src/core/agent/run/eventStageIds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,iBAAiB,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,yBAAyB,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LLMProvider } from '../../../provider-contract/types.js';
|
|
2
|
+
import type { ReliabilityConfig } from '../../../reliability/types.js';
|
|
3
|
+
import type { ResolvedOutputEnforcement } from '../outputEnforcement.js';
|
|
4
|
+
/** What the run-start check reads: the first provider a run would actually call. */
|
|
5
|
+
export interface OutputStrategyTarget {
|
|
6
|
+
readonly enforcement: ResolvedOutputEnforcement | undefined;
|
|
7
|
+
readonly provider: LLMProvider;
|
|
8
|
+
readonly model: string;
|
|
9
|
+
readonly providers: ReliabilityConfig['providers'];
|
|
10
|
+
/** A configured agent resolves its model at seed; `callLLM` judges that final model. */
|
|
11
|
+
readonly modelResolvedAtSeed: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Refuse, at run start, an output strategy the provider cannot carry.
|
|
15
|
+
*
|
|
16
|
+
* Run start rather than build time: a decorated provider (`withFallback`,
|
|
17
|
+
* `withRetry`, a breaker) is only the thing it is once composed, and
|
|
18
|
+
* `withFallback` publishes the AND of its pair.
|
|
19
|
+
*
|
|
20
|
+
* A refusal rather than a quiet fall back to `'instruct'`, because the two are
|
|
21
|
+
* not interchangeable: `'tool-forced'` and `'native'` constrain the shape at
|
|
22
|
+
* generation and decoding, `'instruct'` asks for it in prose. An agent that
|
|
23
|
+
* silently got the second while its config said the first would be a promise
|
|
24
|
+
* the recording could not even show was broken.
|
|
25
|
+
*/
|
|
26
|
+
export declare function assertOutputStrategySupported(target: OutputStrategyTarget): void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { forcedToolChoiceFor, UnsupportedToolChoiceError, } from '../../../provider-contract/forcedToolChoice.js';
|
|
2
|
+
import { nativeOutputSchemaFor, UnsupportedNativeOutputError, } from '../../../provider-contract/nativeOutputSchema.js';
|
|
3
|
+
/**
|
|
4
|
+
* Refuse, at run start, an output strategy the provider cannot carry.
|
|
5
|
+
*
|
|
6
|
+
* Run start rather than build time: a decorated provider (`withFallback`,
|
|
7
|
+
* `withRetry`, a breaker) is only the thing it is once composed, and
|
|
8
|
+
* `withFallback` publishes the AND of its pair.
|
|
9
|
+
*
|
|
10
|
+
* A refusal rather than a quiet fall back to `'instruct'`, because the two are
|
|
11
|
+
* not interchangeable: `'tool-forced'` and `'native'` constrain the shape at
|
|
12
|
+
* generation and decoding, `'instruct'` asks for it in prose. An agent that
|
|
13
|
+
* silently got the second while its config said the first would be a promise
|
|
14
|
+
* the recording could not even show was broken.
|
|
15
|
+
*/
|
|
16
|
+
export function assertOutputStrategySupported(target) {
|
|
17
|
+
assertForcedToolChoiceSupported(target);
|
|
18
|
+
assertNativeOutputSchemaSupported(target);
|
|
19
|
+
}
|
|
20
|
+
function assertForcedToolChoiceSupported(target) {
|
|
21
|
+
if (target.enforcement?.schemaTool === undefined)
|
|
22
|
+
return;
|
|
23
|
+
const first = target.providers?.[0];
|
|
24
|
+
const provider = first?.provider ?? target.provider;
|
|
25
|
+
const model = first?.model ?? target.model;
|
|
26
|
+
if (provider.carriesForcedToolChoice === true) {
|
|
27
|
+
if ((first === undefined && target.modelResolvedAtSeed) || forcedToolChoiceFor(provider, model))
|
|
28
|
+
return;
|
|
29
|
+
throw new UnsupportedToolChoiceError({ provider: provider.name, model });
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Agent: .outputSchema(parser, { strategy: 'tool-forced' }) needs a provider that puts ` +
|
|
32
|
+
`a forced tool choice on its wire, and '${provider.name}' does not declare one. ` +
|
|
33
|
+
`Anthropic, Bedrock, real OpenAI/Azure and the mock do; an OpenAI-COMPATIBLE endpoint ` +
|
|
34
|
+
`behind a custom baseURL (Ollama, vLLM, …) deliberately does not, because what that ` +
|
|
35
|
+
`server does with tool_choice is not this library's to promise. Use ` +
|
|
36
|
+
`{ strategy: 'instruct', retries: N } on this provider — it works on every wire — or ` +
|
|
37
|
+
`run the forced strategy on a provider that declares the capability.`);
|
|
38
|
+
}
|
|
39
|
+
function assertNativeOutputSchemaSupported(target) {
|
|
40
|
+
const { enforcement } = target;
|
|
41
|
+
if (enforcement?.outputFormat === undefined || enforcement.nativeOutputAuto === true)
|
|
42
|
+
return;
|
|
43
|
+
const first = target.providers?.[0];
|
|
44
|
+
const provider = first?.provider ?? target.provider;
|
|
45
|
+
const model = first?.model ?? target.model;
|
|
46
|
+
if (provider.carriesNativeOutputSchema === true) {
|
|
47
|
+
if ((first === undefined && target.modelResolvedAtSeed) ||
|
|
48
|
+
nativeOutputSchemaFor(provider, model))
|
|
49
|
+
return;
|
|
50
|
+
throw new UnsupportedNativeOutputError({ provider: provider.name, model });
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Agent: .outputSchema(parser, { strategy: 'native' }) needs a provider that puts a ` +
|
|
53
|
+
`structured-output format on its wire, and '${provider.name}' does not declare one. ` +
|
|
54
|
+
`anthropic(), browserAnthropic() and the mock do; the Bedrock and gateway adapters do ` +
|
|
55
|
+
`not in this release. Use { strategy: 'instruct', retries: N } on this provider — it ` +
|
|
56
|
+
`works on every wire — or run the native strategy on a provider that declares it.`);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=outputStrategySupport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputStrategySupport.js","sourceRoot":"","sources":["../../../../../src/core/agent/run/outputStrategySupport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,kDAAkD,CAAC;AAe1D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,6BAA6B,CAAC,MAA4B;IACxE,+BAA+B,CAAC,MAAM,CAAC,CAAC;IACxC,iCAAiC,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,+BAA+B,CAAC,MAA4B;IACnE,IAAI,MAAM,CAAC,WAAW,EAAE,UAAU,KAAK,SAAS;QAAE,OAAO;IACzD,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,KAAK,EAAE,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC;IACpD,MAAM,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC;IAC3C,IAAI,QAAQ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