agentfootprint 7.20.0 → 7.22.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 +10 -3
- package/README.md +1 -1
- package/ai-instructions/claude-code/SKILL.md +10 -3
- package/dist/adapters/hosting/agentcore.js +12 -2
- package/dist/adapters/hosting/agentcore.js.map +1 -1
- package/dist/adapters/llm/AnthropicProvider.js +12 -0
- package/dist/adapters/llm/AnthropicProvider.js.map +1 -1
- package/dist/adapters/llm/BedrockProvider.js +12 -0
- package/dist/adapters/llm/BedrockProvider.js.map +1 -1
- package/dist/adapters/llm/BrowserAnthropicProvider.js +45 -6
- package/dist/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
- package/dist/adapters/llm/BrowserOpenAIProvider.js +13 -0
- package/dist/adapters/llm/BrowserOpenAIProvider.js.map +1 -1
- package/dist/adapters/llm/MockProvider.js +10 -0
- package/dist/adapters/llm/MockProvider.js.map +1 -1
- package/dist/adapters/llm/OpenAIProvider.js +15 -0
- package/dist/adapters/llm/OpenAIProvider.js.map +1 -1
- package/dist/adapters/types.js +10 -0
- package/dist/adapters/types.js.map +1 -1
- package/dist/cache/CacheDecisionSubflow.js +67 -3
- package/dist/cache/CacheDecisionSubflow.js.map +1 -1
- package/dist/conventions.js +8 -0
- package/dist/conventions.js.map +1 -1
- package/dist/core/Agent.js +47 -0
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/AgentBuilder.js +13 -6
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +17 -1
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +49 -4
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/delivery/rules.js +121 -0
- package/dist/core/agent/delivery/rules.js.map +1 -0
- package/dist/core/agent/delivery/types.js +12 -0
- package/dist/core/agent/delivery/types.js.map +1 -0
- package/dist/core/agent/stages/callLLM.js +27 -1
- package/dist/core/agent/stages/callLLM.js.map +1 -1
- package/dist/core/agent/stages/deliver.js +155 -0
- package/dist/core/agent/stages/deliver.js.map +1 -0
- package/dist/core/agent/stages/seed.js +4 -0
- package/dist/core/agent/stages/seed.js.map +1 -1
- package/dist/core/slots/buildMessagesSlot.js +43 -48
- package/dist/core/slots/buildMessagesSlot.js.map +1 -1
- package/dist/esm/adapters/hosting/agentcore.d.ts +27 -0
- package/dist/esm/adapters/hosting/agentcore.js +12 -2
- package/dist/esm/adapters/hosting/agentcore.js.map +1 -1
- package/dist/esm/adapters/llm/AnthropicProvider.d.ts +2 -1
- package/dist/esm/adapters/llm/AnthropicProvider.js +12 -0
- package/dist/esm/adapters/llm/AnthropicProvider.js.map +1 -1
- package/dist/esm/adapters/llm/BedrockProvider.d.ts +2 -1
- package/dist/esm/adapters/llm/BedrockProvider.js +12 -0
- package/dist/esm/adapters/llm/BedrockProvider.js.map +1 -1
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +2 -1
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.js +45 -6
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +3 -1
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.js +13 -0
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.js.map +1 -1
- package/dist/esm/adapters/llm/MockProvider.d.ts +2 -1
- package/dist/esm/adapters/llm/MockProvider.js +10 -0
- package/dist/esm/adapters/llm/MockProvider.js.map +1 -1
- package/dist/esm/adapters/llm/OpenAIProvider.d.ts +2 -1
- package/dist/esm/adapters/llm/OpenAIProvider.js +15 -0
- package/dist/esm/adapters/llm/OpenAIProvider.js.map +1 -1
- package/dist/esm/adapters/types.d.ts +69 -0
- package/dist/esm/adapters/types.js +9 -1
- package/dist/esm/adapters/types.js.map +1 -1
- package/dist/esm/cache/CacheDecisionSubflow.d.ts +11 -0
- package/dist/esm/cache/CacheDecisionSubflow.js +67 -3
- package/dist/esm/cache/CacheDecisionSubflow.js.map +1 -1
- package/dist/esm/conventions.d.ts +8 -0
- package/dist/esm/conventions.js +8 -0
- package/dist/esm/conventions.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +16 -0
- package/dist/esm/core/Agent.js +47 -0
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/AgentBuilder.d.ts +9 -4
- package/dist/esm/core/agent/AgentBuilder.js +14 -7
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/buildAgentChart.d.ts +14 -0
- package/dist/esm/core/agent/buildAgentChart.js +17 -1
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js +49 -4
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/delivery/rules.d.ts +79 -0
- package/dist/esm/core/agent/delivery/rules.js +113 -0
- package/dist/esm/core/agent/delivery/rules.js.map +1 -0
- package/dist/esm/core/agent/delivery/types.d.ts +51 -0
- package/dist/esm/core/agent/delivery/types.js +11 -0
- package/dist/esm/core/agent/delivery/types.js.map +1 -0
- package/dist/esm/core/agent/stages/callLLM.js +27 -1
- package/dist/esm/core/agent/stages/callLLM.js.map +1 -1
- package/dist/esm/core/agent/stages/deliver.d.ts +59 -0
- package/dist/esm/core/agent/stages/deliver.js +150 -0
- package/dist/esm/core/agent/stages/deliver.js.map +1 -0
- package/dist/esm/core/agent/stages/seed.js +4 -0
- package/dist/esm/core/agent/stages/seed.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +14 -0
- package/dist/esm/core/slots/buildMessagesSlot.d.ts +23 -8
- package/dist/esm/core/slots/buildMessagesSlot.js +43 -48
- package/dist/esm/core/slots/buildMessagesSlot.js.map +1 -1
- package/dist/esm/hosting/httpHost.d.ts +62 -3
- package/dist/esm/hosting/httpHost.js +73 -9
- package/dist/esm/hosting/httpHost.js.map +1 -1
- package/dist/esm/hosting/index.d.ts +3 -1
- package/dist/esm/hosting/index.js +3 -1
- package/dist/esm/hosting/index.js.map +1 -1
- package/dist/esm/hosting/nodeHost.d.ts +21 -2
- package/dist/esm/hosting/nodeHost.js +10 -0
- package/dist/esm/hosting/nodeHost.js.map +1 -1
- package/dist/esm/hosting/types.d.ts +6 -0
- package/dist/esm/lib/injection-engine/factories/defineFact.d.ts +38 -10
- package/dist/esm/lib/injection-engine/factories/defineFact.js +20 -8
- package/dist/esm/lib/injection-engine/factories/defineFact.js.map +1 -1
- package/dist/esm/lib/injection-engine/factories/defineInstruction.d.ts +42 -15
- package/dist/esm/lib/injection-engine/factories/defineInstruction.js +17 -6
- package/dist/esm/lib/injection-engine/factories/defineInstruction.js.map +1 -1
- package/dist/esm/lib/injection-engine/messagesSlotRefusal.d.ts +70 -27
- package/dist/esm/lib/injection-engine/messagesSlotRefusal.js +91 -34
- package/dist/esm/lib/injection-engine/messagesSlotRefusal.js.map +1 -1
- package/dist/esm/lib/injection-engine/types.d.ts +35 -9
- package/dist/esm/lib/injection-engine/types.js +6 -0
- package/dist/esm/lib/injection-engine/types.js.map +1 -1
- package/dist/esm/memory/asRoleRefusal.d.ts +15 -11
- package/dist/esm/memory/asRoleRefusal.js +21 -15
- package/dist/esm/memory/asRoleRefusal.js.map +1 -1
- package/dist/esm/resilience/withCircuitBreaker.js +6 -0
- package/dist/esm/resilience/withCircuitBreaker.js.map +1 -1
- package/dist/esm/resilience/withFallback.js +18 -0
- package/dist/esm/resilience/withFallback.js.map +1 -1
- package/dist/esm/resilience/withRetry.js +8 -0
- package/dist/esm/resilience/withRetry.js.map +1 -1
- package/dist/hosting/httpHost.js +73 -9
- package/dist/hosting/httpHost.js.map +1 -1
- package/dist/hosting/index.js +3 -1
- package/dist/hosting/index.js.map +1 -1
- package/dist/hosting/nodeHost.js +10 -0
- package/dist/hosting/nodeHost.js.map +1 -1
- package/dist/lib/injection-engine/factories/defineFact.js +19 -7
- package/dist/lib/injection-engine/factories/defineFact.js.map +1 -1
- package/dist/lib/injection-engine/factories/defineInstruction.js +16 -5
- package/dist/lib/injection-engine/factories/defineInstruction.js.map +1 -1
- package/dist/lib/injection-engine/messagesSlotRefusal.js +95 -36
- package/dist/lib/injection-engine/messagesSlotRefusal.js.map +1 -1
- package/dist/lib/injection-engine/types.js +6 -0
- package/dist/lib/injection-engine/types.js.map +1 -1
- package/dist/memory/asRoleRefusal.js +21 -15
- package/dist/memory/asRoleRefusal.js.map +1 -1
- package/dist/resilience/withCircuitBreaker.js +6 -0
- package/dist/resilience/withCircuitBreaker.js.map +1 -1
- package/dist/resilience/withFallback.js +18 -0
- package/dist/resilience/withFallback.js.map +1 -1
- package/dist/resilience/withRetry.js +8 -0
- package/dist/resilience/withRetry.js.map +1 -1
- package/dist/types/adapters/hosting/agentcore.d.ts +27 -0
- package/dist/types/adapters/hosting/agentcore.d.ts.map +1 -1
- package/dist/types/adapters/llm/AnthropicProvider.d.ts +2 -1
- package/dist/types/adapters/llm/AnthropicProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/BedrockProvider.d.ts +2 -1
- package/dist/types/adapters/llm/BedrockProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/BrowserAnthropicProvider.d.ts +2 -1
- package/dist/types/adapters/llm/BrowserAnthropicProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts +3 -1
- package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/MockProvider.d.ts +2 -1
- package/dist/types/adapters/llm/MockProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/OpenAIProvider.d.ts +2 -1
- package/dist/types/adapters/llm/OpenAIProvider.d.ts.map +1 -1
- package/dist/types/adapters/types.d.ts +69 -0
- package/dist/types/adapters/types.d.ts.map +1 -1
- package/dist/types/cache/CacheDecisionSubflow.d.ts +11 -0
- package/dist/types/cache/CacheDecisionSubflow.d.ts.map +1 -1
- package/dist/types/conventions.d.ts +8 -0
- package/dist/types/conventions.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +16 -0
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/AgentBuilder.d.ts +9 -4
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts +14 -0
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/delivery/rules.d.ts +80 -0
- package/dist/types/core/agent/delivery/rules.d.ts.map +1 -0
- package/dist/types/core/agent/delivery/types.d.ts +52 -0
- package/dist/types/core/agent/delivery/types.d.ts.map +1 -0
- package/dist/types/core/agent/stages/callLLM.d.ts.map +1 -1
- package/dist/types/core/agent/stages/deliver.d.ts +60 -0
- package/dist/types/core/agent/stages/deliver.d.ts.map +1 -0
- package/dist/types/core/agent/types.d.ts +14 -0
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/slots/buildMessagesSlot.d.ts +23 -8
- package/dist/types/core/slots/buildMessagesSlot.d.ts.map +1 -1
- package/dist/types/hosting/httpHost.d.ts +62 -3
- package/dist/types/hosting/httpHost.d.ts.map +1 -1
- package/dist/types/hosting/index.d.ts +3 -1
- package/dist/types/hosting/index.d.ts.map +1 -1
- package/dist/types/hosting/nodeHost.d.ts +21 -2
- package/dist/types/hosting/nodeHost.d.ts.map +1 -1
- package/dist/types/hosting/types.d.ts +6 -0
- package/dist/types/hosting/types.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/factories/defineFact.d.ts +38 -10
- package/dist/types/lib/injection-engine/factories/defineFact.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/factories/defineInstruction.d.ts +42 -15
- package/dist/types/lib/injection-engine/factories/defineInstruction.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/messagesSlotRefusal.d.ts +70 -27
- package/dist/types/lib/injection-engine/messagesSlotRefusal.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/types.d.ts +35 -9
- package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
- package/dist/types/memory/asRoleRefusal.d.ts +15 -11
- package/dist/types/memory/asRoleRefusal.d.ts.map +1 -1
- package/dist/types/resilience/withCircuitBreaker.d.ts.map +1 -1
- package/dist/types/resilience/withFallback.d.ts.map +1 -1
- package/dist/types/resilience/withRetry.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -25,6 +25,15 @@
|
|
|
25
25
|
* `HostRequest` and `HostReply` say exactly what they said before. The gap was
|
|
26
26
|
* in the first adapter, which had no seam, not in the port, which needed none.
|
|
27
27
|
*
|
|
28
|
+
* ── The second thing a deployment gets to re-decide: who owns the socket ─────
|
|
29
|
+
* By default this file creates a server and listens on it. Pass `server` and it
|
|
30
|
+
* attaches to yours instead — because a container is sometimes given exactly
|
|
31
|
+
* one port, and an agent that privately owns the socket cannot share it with a
|
|
32
|
+
* WebSocket upgrade or with routes that were there first. Attached, the host
|
|
33
|
+
* answers its two paths, writes nothing on anyone else's, and `close()`
|
|
34
|
+
* detaches and drains without closing a socket it never opened. That is the
|
|
35
|
+
* whole difference; every other law on this page is the same either way.
|
|
36
|
+
*
|
|
28
37
|
* Pattern: Template method via configuration (Strategy on the wire format).
|
|
29
38
|
* Everything HTTP lives here and in the wires; `types.ts` knows none of it.
|
|
30
39
|
*/
|
|
@@ -64,6 +73,17 @@ const DEFAULT_CAPABILITIES = ['streaming'];
|
|
|
64
73
|
*/
|
|
65
74
|
export function httpHost(options) {
|
|
66
75
|
const { name, wire, invokePath, healthPath } = options;
|
|
76
|
+
const ownServer = options.server;
|
|
77
|
+
// Refused at construction, not ignored at serve time: a `port` next to a
|
|
78
|
+
// server this host does not bind is a caller who believes something untrue
|
|
79
|
+
// about where their agent will answer, and silently dropping it is how they
|
|
80
|
+
// stay believing it.
|
|
81
|
+
if (ownServer && (options.port !== undefined || options.hostname !== undefined)) {
|
|
82
|
+
throw new Error(`[hosting] httpHost('${name}') was given both a caller-owned 'server' and a ` +
|
|
83
|
+
`'${options.port !== undefined ? 'port' : 'hostname'}'. A server you own already has ` +
|
|
84
|
+
`an address, and this host binds nothing when you pass one. Drop the port/hostname, ` +
|
|
85
|
+
`or drop the server and let this host bind its own socket.`);
|
|
86
|
+
}
|
|
67
87
|
const port = options.port ?? 8080;
|
|
68
88
|
const hostname = options.hostname ?? '0.0.0.0';
|
|
69
89
|
const capabilities = options.capabilities ?? DEFAULT_CAPABILITIES;
|
|
@@ -71,18 +91,26 @@ export function httpHost(options) {
|
|
|
71
91
|
name,
|
|
72
92
|
capabilities,
|
|
73
93
|
async serve(handler) {
|
|
74
|
-
const { createServer } = await import('node:http');
|
|
75
94
|
const startedAt = Date.now();
|
|
76
95
|
const inFlight = new Set();
|
|
77
96
|
let accepting = true;
|
|
78
97
|
let closing;
|
|
79
|
-
const
|
|
98
|
+
const onRequest = (req, res) => {
|
|
99
|
+
// On a shared server an earlier listener may already have answered.
|
|
100
|
+
// Writing again would corrupt its reply; there is nothing to add.
|
|
101
|
+
if (res.headersSent)
|
|
102
|
+
return;
|
|
80
103
|
const path = (req.url ?? '').split('?')[0];
|
|
81
104
|
if (req.method === 'GET' && path === healthPath) {
|
|
82
105
|
sendJson(res, 200, wire.health(Date.now() - startedAt));
|
|
83
106
|
return;
|
|
84
107
|
}
|
|
85
108
|
if (req.method !== 'POST' || path !== invokePath) {
|
|
109
|
+
// On a server we own, an unmatched path is nobody else's, so saying
|
|
110
|
+
// so is the honest answer. On a server the CALLER owns it is theirs,
|
|
111
|
+
// and a 404 from us would answer for their application.
|
|
112
|
+
if (ownServer)
|
|
113
|
+
return;
|
|
86
114
|
sendJson(res, 404, wire.failure(`no route for ${req.method ?? '?'} ${path}`));
|
|
87
115
|
return;
|
|
88
116
|
}
|
|
@@ -94,14 +122,40 @@ export function httpHost(options) {
|
|
|
94
122
|
const served = serveOne(req, res, handler, wire);
|
|
95
123
|
inFlight.add(served);
|
|
96
124
|
void served.finally(() => inFlight.delete(served));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
server
|
|
101
|
-
|
|
125
|
+
};
|
|
126
|
+
let server;
|
|
127
|
+
if (ownServer) {
|
|
128
|
+
server = ownServer;
|
|
129
|
+
if (!server.listening) {
|
|
130
|
+
throw new Error(`[hosting] httpHost('${name}') was handed a server that is not listening yet. ` +
|
|
131
|
+
`This handle promises the url and port it is answering on, and a server with ` +
|
|
132
|
+
`no address has neither. Call server.listen(...) first, then serve() — ` +
|
|
133
|
+
`attaching after listen() is safe and is the intended order.`);
|
|
134
|
+
}
|
|
135
|
+
server.on('request', onRequest);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const { createServer } = await import('node:http');
|
|
139
|
+
server = createServer(onRequest);
|
|
140
|
+
await new Promise((resolve, reject) => {
|
|
141
|
+
server.once('error', reject);
|
|
142
|
+
server.listen(port, hostname, resolve);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
102
145
|
const address = server.address();
|
|
103
|
-
const
|
|
104
|
-
|
|
146
|
+
const tcp = typeof address === 'object' && address !== null ? address : undefined;
|
|
147
|
+
if (ownServer && !tcp) {
|
|
148
|
+
server.off('request', onRequest);
|
|
149
|
+
throw new Error(`[hosting] httpHost('${name}') was handed a server bound to ${JSON.stringify(address)}` +
|
|
150
|
+
` — a pipe or socket path, which has no port. This handle promises a url and a ` +
|
|
151
|
+
`port, and inventing one would be worse than refusing. Serve on a TCP server, or ` +
|
|
152
|
+
`drive the handler yourself.`);
|
|
153
|
+
}
|
|
154
|
+
const boundPort = tcp ? tcp.port : port;
|
|
155
|
+
// With our own socket the requested hostname IS the answer; with the
|
|
156
|
+
// caller's we ask the socket, because we never chose it.
|
|
157
|
+
const boundHost = ownServer ? tcp?.address ?? '127.0.0.1' : hostname;
|
|
158
|
+
const displayHost = boundHost === '0.0.0.0' || boundHost === '::' ? '127.0.0.1' : boundHost;
|
|
105
159
|
return {
|
|
106
160
|
url: `http://${displayHost}:${boundPort}`,
|
|
107
161
|
port: boundPort,
|
|
@@ -109,6 +163,16 @@ export function httpHost(options) {
|
|
|
109
163
|
// Idempotent: the first call owns the shutdown, later ones await it.
|
|
110
164
|
closing ??= (async () => {
|
|
111
165
|
accepting = false;
|
|
166
|
+
if (ownServer) {
|
|
167
|
+
// Detach FIRST. The paths stop being ours the moment close() is
|
|
168
|
+
// called, so a request arriving now falls through to the caller
|
|
169
|
+
// rather than collecting a refusal from a host that is leaving.
|
|
170
|
+
server.off('request', onRequest);
|
|
171
|
+
// Then drain what we are already serving — and stop there. The
|
|
172
|
+
// socket, the idle connections and the shutdown are the caller's.
|
|
173
|
+
await Promise.allSettled([...inFlight]);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
112
176
|
// Drain BEFORE touching sockets — an in-flight request is work the
|
|
113
177
|
// caller is still waiting on, and dropping it would be the exact
|
|
114
178
|
// thing close() promises not to do.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpHost.js","sourceRoot":"","sources":["../../../src/hosting/httpHost.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"httpHost.js","sourceRoot":"","sources":["../../../src/hosting/httpHost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAyJ9C;;;;;;;;GAQG;AACH,MAAM,cAAc,GAAqC;IACvD,eAAe,EAAE,GAAG;IACpB,kBAAkB,EAAE,GAAG;IACvB,qBAAqB,EAAE,GAAG;IAC1B,qBAAqB,EAAE,GAAG;IAC1B,kBAAkB,EAAE,GAAG;CACxB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,oBAAoB,GAA8B,CAAC,WAAW,CAAC,CAAC;AAEtE;;;;;;GAMG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D,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;aAC1D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,OAAO,CAAC,GAAY;IAC3B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,KAAuB,EACvB,IAAY,EACZ,GAAG,SAAmB;IAEtB,KAAK,MAAM,SAAS,IAAI,CAAC,IAAI,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC;QAC7C,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;QACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;IAClE,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
* itself, parameterised by the JSON dialect it speaks. `nodeHost` is one
|
|
32
32
|
* configuration of it; an adapter for someone's container runtime is
|
|
33
33
|
* another. Two paths and five body shapes are all a second HTTP adapter
|
|
34
|
-
* re-decides.
|
|
34
|
+
* re-decides. Pass `server` and it attaches to a `node:http` server YOU
|
|
35
|
+
* own instead of binding one — for the container that gets a single port
|
|
36
|
+
* and must serve a WebSocket upgrade (or anything else) beside the agent.
|
|
35
37
|
* • `memorySessions()` — conversations in a Map, for tests and local dev.
|
|
36
38
|
* • `standingAgent({ agent, sessions, host, durability? })` — the composer.
|
|
37
39
|
* • `toEnvelope` / `readEnvelope` — pack a conversation, and refuse by name to
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
* itself, parameterised by the JSON dialect it speaks. `nodeHost` is one
|
|
32
32
|
* configuration of it; an adapter for someone's container runtime is
|
|
33
33
|
* another. Two paths and five body shapes are all a second HTTP adapter
|
|
34
|
-
* re-decides.
|
|
34
|
+
* re-decides. Pass `server` and it attaches to a `node:http` server YOU
|
|
35
|
+
* own instead of binding one — for the container that gets a single port
|
|
36
|
+
* and must serve a WebSocket upgrade (or anything else) beside the agent.
|
|
35
37
|
* • `memorySessions()` — conversations in a Map, for tests and local dev.
|
|
36
38
|
* • `standingAgent({ agent, sessions, host, durability? })` — the composer.
|
|
37
39
|
* • `toEnvelope` / `readEnvelope` — pack a conversation, and refuse by name to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hosting/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hosting/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAStD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
* a colleague's convention. A path is a deployment detail, so it is a knob
|
|
17
17
|
* here and absent from the port entirely.
|
|
18
18
|
*
|
|
19
|
+
* **The socket can be yours.** Pass `server` — a `node:http` server you
|
|
20
|
+
* created and listened on — and this adapter attaches its two routes to it
|
|
21
|
+
* instead of binding one, so a WebSocket upgrade or your own routes can share
|
|
22
|
+
* the port. `close()` then detaches and drains, and your socket stays up.
|
|
23
|
+
*
|
|
19
24
|
* **Streaming is the caller's choice, not the server's.** Send
|
|
20
25
|
* `Accept: text/event-stream` and the reply is Server-Sent Events, one `chunk`
|
|
21
26
|
* event per `reply.emit(...)` then a final `complete`. Send anything else and
|
|
@@ -29,17 +34,31 @@
|
|
|
29
34
|
* never quietly drift apart on what `close()` drains or what a handler that
|
|
30
35
|
* throws does. `types.ts` knows none of it either way.
|
|
31
36
|
*/
|
|
37
|
+
/// <reference types="node" />
|
|
32
38
|
import { type HttpHost, type HttpHostHandle, type HttpWire } from './httpHost.js';
|
|
33
39
|
/** Options for {@link nodeHost}. */
|
|
34
40
|
export interface NodeHostOptions {
|
|
35
|
-
/** Port to bind. Default `8080`. Pass `0` for an ephemeral port. */
|
|
41
|
+
/** Port to bind. Default `8080`. Pass `0` for an ephemeral port. Refused alongside `server`. */
|
|
36
42
|
readonly port?: number;
|
|
37
|
-
/** Interface to bind. Default `'0.0.0.0'`. */
|
|
43
|
+
/** Interface to bind. Default `'0.0.0.0'`. Refused alongside `server`. */
|
|
38
44
|
readonly hostname?: string;
|
|
39
45
|
/** Path that takes a request. Default `'/invoke'`. */
|
|
40
46
|
readonly invokePath?: string;
|
|
41
47
|
/** Path that answers a health probe. Default `'/health'`. */
|
|
42
48
|
readonly healthPath?: string;
|
|
49
|
+
/**
|
|
50
|
+
* A `node:http` server **you** own, already listening. Given one, this
|
|
51
|
+
* adapter attaches its two routes to it instead of binding a socket of its
|
|
52
|
+
* own — the only way to serve something else (a WebSocket upgrade, routes
|
|
53
|
+
* that were there first) on the same port, which matters when the thing
|
|
54
|
+
* running your process gives it exactly one.
|
|
55
|
+
*
|
|
56
|
+
* You keep `listen()` and you keep the shutdown; `close()` detaches this
|
|
57
|
+
* host and drains what it was already serving. On a server you own the host
|
|
58
|
+
* never writes a 404 either: a path it does not own is yours to answer. The
|
|
59
|
+
* full set of laws is on `httpHost`'s own `server` option, which this is.
|
|
60
|
+
*/
|
|
61
|
+
readonly server?: import('node:http').Server;
|
|
43
62
|
}
|
|
44
63
|
/**
|
|
45
64
|
* What {@link nodeHost}'s `serve()` resolves to — a `HostHandle` that also
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
* a colleague's convention. A path is a deployment detail, so it is a knob
|
|
17
17
|
* here and absent from the port entirely.
|
|
18
18
|
*
|
|
19
|
+
* **The socket can be yours.** Pass `server` — a `node:http` server you
|
|
20
|
+
* created and listened on — and this adapter attaches its two routes to it
|
|
21
|
+
* instead of binding one, so a WebSocket upgrade or your own routes can share
|
|
22
|
+
* the port. `close()` then detaches and drains, and your socket stays up.
|
|
23
|
+
*
|
|
19
24
|
* **Streaming is the caller's choice, not the server's.** Send
|
|
20
25
|
* `Accept: text/event-stream` and the reply is Server-Sent Events, one `chunk`
|
|
21
26
|
* event per `reply.emit(...)` then a final `complete`. Send anything else and
|
|
@@ -82,8 +87,13 @@ export function nodeHost(options = {}) {
|
|
|
82
87
|
// particular runtime's container-contract path literal.
|
|
83
88
|
invokePath: options.invokePath ?? '/invoke',
|
|
84
89
|
healthPath: options.healthPath ?? '/health',
|
|
90
|
+
// Passed through as given, never defaulted: with a caller-owned server
|
|
91
|
+
// there is no port to default, and a port passed WITH one is a caller who
|
|
92
|
+
// believes something untrue about where their agent answers — `httpHost`
|
|
93
|
+
// refuses that pair by name rather than picking a winner.
|
|
85
94
|
...(options.port !== undefined && { port: options.port }),
|
|
86
95
|
...(options.hostname !== undefined && { hostname: options.hostname }),
|
|
96
|
+
...(options.server !== undefined && { server: options.server }),
|
|
87
97
|
});
|
|
88
98
|
}
|
|
89
99
|
//# sourceMappingURL=nodeHost.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeHost.js","sourceRoot":"","sources":["../../../src/hosting/nodeHost.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"nodeHost.js","sourceRoot":"","sources":["../../../src/hosting/nodeHost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,QAAQ,EAAqD,MAAM,eAAe,CAAC;AAqC5F,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAa;IAChC,WAAW,CAAC,KAAK;QACf,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,wEAAwE;QACxE,4EAA4E;QAC5E,MAAM,QAAQ,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7F,MAAM,SAAS,GAAG,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC5D,4EAA4E;QAC5E,wEAAwE;QACxE,0CAA0C;QAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;QACrC,OAAO;YACL,KAAK;YACL,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;YAC7C,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC;SAC5C,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,E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coexist. Requests arriving after it are refused with a
|
|
142
142
|
* {@link HostClosedError} naming the adapter.
|
|
143
|
+
*
|
|
144
|
+
* "Release the transport" is as strong as the port can be, because an
|
|
145
|
+
* adapter may be serving on a transport the CALLER owns rather than one it
|
|
146
|
+
* created. Releasing one of those means handing the routes back — never
|
|
147
|
+
* closing it — and a request arriving afterwards is the caller's to answer,
|
|
148
|
+
* not this host's to refuse.
|
|
143
149
|
*/
|
|
144
150
|
close(): Promise<void>;
|
|
145
151
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Produces an `Injection` with:
|
|
11
11
|
* - flavor: `'fact'`
|
|
12
12
|
* - trigger: configurable (default `'always'`)
|
|
13
|
-
* - inject: `systemPrompt`
|
|
13
|
+
* - inject: `systemPrompt` (default), or `messages` with a declared role
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* const userProfile = defineFact({
|
|
@@ -23,21 +23,14 @@
|
|
|
23
23
|
* data: `Current time: ${new Date().toISOString()}`,
|
|
24
24
|
* });
|
|
25
25
|
*/
|
|
26
|
+
import type { WireRole } from '../../../adapters/types.js';
|
|
26
27
|
import type { Injection, InjectionContext } from '../types.js';
|
|
27
28
|
import type { CachePolicy } from '../../../cache/types.js';
|
|
28
|
-
|
|
29
|
+
interface DefineFactBase {
|
|
29
30
|
readonly id: string;
|
|
30
31
|
readonly description?: string;
|
|
31
32
|
/** The fact (data string) to inject. */
|
|
32
33
|
readonly data: string;
|
|
33
|
-
/**
|
|
34
|
-
* Which slot to land in. `'system-prompt'` (the default) is the only
|
|
35
|
-
* slot a fact can land in: it is the one every provider delivers.
|
|
36
|
-
*
|
|
37
|
-
* `'messages'` is REFUSED — see {@link messagesSlotRefusal}. It was
|
|
38
|
-
* accepted before 7.19.1, recorded as injected, and never sent.
|
|
39
|
-
*/
|
|
40
|
-
readonly slot?: 'system-prompt';
|
|
41
34
|
/**
|
|
42
35
|
* Trigger control. Defaults to always-on. For conditional facts
|
|
43
36
|
* (e.g., "only show user profile after iteration 3"), pass a
|
|
@@ -53,4 +46,39 @@ export interface DefineFactOptions {
|
|
|
53
46
|
*/
|
|
54
47
|
readonly cache?: CachePolicy;
|
|
55
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* `slot` and `role` are ONE decision, so the type makes them one choice.
|
|
51
|
+
*
|
|
52
|
+
* `slot: 'messages'` requires a `role` and there is deliberately no default:
|
|
53
|
+
* who appears to speak is a meaning the app owns. (Before 7.19.1 the option
|
|
54
|
+
* existed with `role` defaulting to `'system'` — a default that reached the
|
|
55
|
+
* model on OpenAI-family providers and vanished on Anthropic-family ones.
|
|
56
|
+
* Now the role is stated, and a provider that cannot carry it refuses at run
|
|
57
|
+
* start by name.) `slot: 'system-prompt'` forbids `role`, because there is no
|
|
58
|
+
* role in a system prompt to choose.
|
|
59
|
+
*/
|
|
60
|
+
export type DefineFactOptions = DefineFactBase & ({
|
|
61
|
+
/** The default. The one placement every provider delivers. */
|
|
62
|
+
readonly slot?: 'system-prompt';
|
|
63
|
+
readonly role?: never;
|
|
64
|
+
} | {
|
|
65
|
+
/**
|
|
66
|
+
* Deliver the fact into the conversation itself — it enters
|
|
67
|
+
* `scope.history` at the injection-engine boundary, so the window
|
|
68
|
+
* strategies, the slots and the wire all see the same past.
|
|
69
|
+
* Placed at the END of the window; if its role would collide with
|
|
70
|
+
* the turn already there, delivery defers to the next boundary and
|
|
71
|
+
* says so on `messagesDelivery.deferred`.
|
|
72
|
+
*/
|
|
73
|
+
readonly slot: 'messages';
|
|
74
|
+
/**
|
|
75
|
+
* Who appears to say it. Required — no default. Refused at run start
|
|
76
|
+
* when the attached provider does not carry it inside `messages`
|
|
77
|
+
* (the Anthropic family drops `'system'` there; the OpenAI family
|
|
78
|
+
* carries it). `'tool'` is refused outright: a tool message answers a
|
|
79
|
+
* specific call, and an injection has no call to answer.
|
|
80
|
+
*/
|
|
81
|
+
readonly role: WireRole;
|
|
82
|
+
});
|
|
56
83
|
export declare function defineFact(opts: DefineFactOptions): Injection;
|
|
84
|
+
export {};
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Produces an `Injection` with:
|
|
11
11
|
* - flavor: `'fact'`
|
|
12
12
|
* - trigger: configurable (default `'always'`)
|
|
13
|
-
* - inject: `systemPrompt`
|
|
13
|
+
* - inject: `systemPrompt` (default), or `messages` with a declared role
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* const userProfile = defineFact({
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* data: `Current time: ${new Date().toISOString()}`,
|
|
24
24
|
* });
|
|
25
25
|
*/
|
|
26
|
-
import {
|
|
26
|
+
import { messagesToolRoleRefusal } from '../messagesSlotRefusal.js';
|
|
27
27
|
import { resolveCachePolicy } from '../../../cache/applyCachePolicy.js';
|
|
28
28
|
export function defineFact(opts) {
|
|
29
29
|
if (!opts.id || opts.id.trim().length === 0) {
|
|
@@ -32,16 +32,28 @@ export function defineFact(opts) {
|
|
|
32
32
|
if (!opts.data || opts.data.length === 0) {
|
|
33
33
|
throw new Error(`defineFact(${opts.id}): \`data\` is required.`);
|
|
34
34
|
}
|
|
35
|
-
// The
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
// The runtime guards read a WIDENED view on purpose. The declared type
|
|
36
|
+
// already pairs `slot` with `role` correctly, and TypeScript narrows so well
|
|
37
|
+
// that `opts.role` is provably present inside a `slot === 'messages'` branch
|
|
38
|
+
// — which makes the checks below unreachable *to the compiler* and therefore
|
|
39
|
+
// invisible to the JavaScript callers and `as never` casts they exist for. A
|
|
40
|
+
// refusal that only holds at compile time is not a refusal.
|
|
41
|
+
const raw = opts;
|
|
42
|
+
const toMessages = raw.slot === 'messages';
|
|
43
|
+
if (toMessages && !raw.role) {
|
|
44
|
+
throw new Error(`defineFact('${opts.id}'): \`slot: 'messages'\` requires a \`role\` — ` +
|
|
45
|
+
`'user', 'assistant', or 'system' on a provider that carries it. There is no ` +
|
|
46
|
+
`default: who appears to speak is a meaning your app owns, not one the library picks.`);
|
|
47
|
+
}
|
|
48
|
+
if (toMessages && raw.role === 'tool') {
|
|
49
|
+
throw new Error(messagesToolRoleRefusal(`defineFact('${opts.id}')`));
|
|
40
50
|
}
|
|
41
51
|
const trigger = opts.activeWhen
|
|
42
52
|
? { kind: 'rule', activeWhen: opts.activeWhen }
|
|
43
53
|
: { kind: 'always' };
|
|
44
|
-
const inject =
|
|
54
|
+
const inject = toMessages
|
|
55
|
+
? { messages: [{ role: raw.role, content: opts.data }] }
|
|
56
|
+
: { systemPrompt: opts.data };
|
|
45
57
|
const cache = resolveCachePolicy('fact', opts.cache);
|
|
46
58
|
// Two-stage cast (`as unknown as Injection`) is required because
|
|
47
59
|
// `flavor: 'fact'` narrows tighter than `ContextSource`. Both stages
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineFact.js","sourceRoot":"","sources":["../../../../../src/lib/injection-engine/factories/defineFact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"defineFact.js","sourceRoot":"","sources":["../../../../../src/lib/injection-engine/factories/defineFact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AA+DxE,MAAM,UAAU,UAAU,CAAC,IAAuB;IAChD,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,C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AG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1D,MAAM,EAAE,MAAe;QACvB,OAAO;QACP,MAAM;QACN,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;KACnC,CAAyB,CAAC;AAC7B,CAAC"}
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* Produces an `Injection` with:
|
|
12
12
|
* - flavor: `'instructions'`
|
|
13
13
|
* - trigger: `{ kind: 'rule', activeWhen }` (or `'always'` if omitted)
|
|
14
|
-
* - inject: `{ systemPrompt: prompt }`
|
|
14
|
+
* - inject: `{ systemPrompt: prompt }`, or `{ messages: [{ role, content }] }`
|
|
15
|
+
* when `slot: 'messages'` names the role it speaks as
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* const calmTone = defineInstruction({
|
|
@@ -27,9 +28,10 @@
|
|
|
27
28
|
* prompt: 'PII has been redacted. Do not include emails or phone numbers.',
|
|
28
29
|
* });
|
|
29
30
|
*/
|
|
31
|
+
import type { WireRole } from '../../../adapters/types.js';
|
|
30
32
|
import type { Injection, InjectionContext } from '../types.js';
|
|
31
33
|
import type { CachePolicy } from '../../../cache/types.js';
|
|
32
|
-
|
|
34
|
+
interface DefineInstructionBase {
|
|
33
35
|
readonly id: string;
|
|
34
36
|
readonly description?: string;
|
|
35
37
|
/**
|
|
@@ -41,20 +43,8 @@ export interface DefineInstructionOptions {
|
|
|
41
43
|
* `agentfootprint.context.evaluated`.
|
|
42
44
|
*/
|
|
43
45
|
readonly activeWhen?: (ctx: InjectionContext) => boolean;
|
|
44
|
-
/** Instruction text.
|
|
46
|
+
/** Instruction text. */
|
|
45
47
|
readonly prompt: string;
|
|
46
|
-
/**
|
|
47
|
-
* Where the instruction lands. `'system-prompt'` (the default) is the
|
|
48
|
-
* only slot an instruction can land in: it is the one every provider
|
|
49
|
-
* delivers.
|
|
50
|
-
*
|
|
51
|
-
* `'messages'` is REFUSED — see {@link messagesSlotRefusal}. It was
|
|
52
|
-
* accepted before 7.19.1 and documented as the recency-first
|
|
53
|
-
* placement; it was recorded as injected and never sent. To make a
|
|
54
|
-
* rule salient at the moment it matters, return it from the tool whose
|
|
55
|
-
* result it is about — a tool result IS a recent message.
|
|
56
|
-
*/
|
|
57
|
-
readonly slot?: 'system-prompt';
|
|
58
48
|
/**
|
|
59
49
|
* Cache policy for this instruction. Defaults to `'never'` —
|
|
60
50
|
* instructions are typically rule-based (volatile per-iter
|
|
@@ -66,4 +56,41 @@ export interface DefineInstructionOptions {
|
|
|
66
56
|
*/
|
|
67
57
|
readonly cache?: CachePolicy;
|
|
68
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* `slot` and `role` are ONE decision, so the type makes them one choice —
|
|
61
|
+
* see {@link DefineFactOptions} for the full reasoning. In short:
|
|
62
|
+
* `slot: 'messages'` requires a `role` with no default (who appears to speak
|
|
63
|
+
* is the app's meaning to set), and `slot: 'system-prompt'` forbids one.
|
|
64
|
+
*/
|
|
65
|
+
export type DefineInstructionOptions = DefineInstructionBase & ({
|
|
66
|
+
/**
|
|
67
|
+
* The default. Appended to the system prompt — the one placement
|
|
68
|
+
* every provider delivers. An `on-tool-return` instruction already
|
|
69
|
+
* lands on exactly the turn it matters; this is a system prompt that
|
|
70
|
+
* says it on that one turn, rather than on every turn.
|
|
71
|
+
*/
|
|
72
|
+
readonly slot?: 'system-prompt';
|
|
73
|
+
readonly role?: never;
|
|
74
|
+
} | {
|
|
75
|
+
/**
|
|
76
|
+
* Deliver the instruction into the conversation itself — it enters
|
|
77
|
+
* `scope.history` at the injection-engine boundary, at the END of the
|
|
78
|
+
* window, so the model reads it at the recency this option is
|
|
79
|
+
* reaching for. If its role would collide with the turn already at
|
|
80
|
+
* the end, delivery defers to the next boundary and says so on
|
|
81
|
+
* `messagesDelivery.deferred` rather than reordering anything.
|
|
82
|
+
*
|
|
83
|
+
* In a tool-using loop the window ends on the user's turn or on tool
|
|
84
|
+
* results, so a `'user'` role typically never gets a slot. Use
|
|
85
|
+
* `'assistant'`, use `'system'` on a provider that carries it, or
|
|
86
|
+
* return the words from the tool whose result they are about.
|
|
87
|
+
*/
|
|
88
|
+
readonly slot: 'messages';
|
|
89
|
+
/**
|
|
90
|
+
* Who appears to say it. Required — no default. Refused at run start
|
|
91
|
+
* when the attached provider does not carry it inside `messages`.
|
|
92
|
+
*/
|
|
93
|
+
readonly role: WireRole;
|
|
94
|
+
});
|
|
69
95
|
export declare function defineInstruction(opts: DefineInstructionOptions): Injection;
|
|
96
|
+
export {};
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* Produces an `Injection` with:
|
|
12
12
|
* - flavor: `'instructions'`
|
|
13
13
|
* - trigger: `{ kind: 'rule', activeWhen }` (or `'always'` if omitted)
|
|
14
|
-
* - inject: `{ systemPrompt: prompt }`
|
|
14
|
+
* - inject: `{ systemPrompt: prompt }`, or `{ messages: [{ role, content }] }`
|
|
15
|
+
* when `slot: 'messages'` names the role it speaks as
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* const calmTone = defineInstruction({
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
* prompt: 'PII has been redacted. Do not include emails or phone numbers.',
|
|
28
29
|
* });
|
|
29
30
|
*/
|
|
30
|
-
import {
|
|
31
|
+
import { messagesToolRoleRefusal } from '../messagesSlotRefusal.js';
|
|
31
32
|
import { resolveCachePolicy } from '../../../cache/applyCachePolicy.js';
|
|
32
33
|
export function defineInstruction(opts) {
|
|
33
34
|
if (!opts.id || opts.id.trim().length === 0) {
|
|
@@ -36,14 +37,24 @@ export function defineInstruction(opts) {
|
|
|
36
37
|
if (!opts.prompt || opts.prompt.length === 0) {
|
|
37
38
|
throw new Error(`defineInstruction(${opts.id}): \`prompt\` is required.`);
|
|
38
39
|
}
|
|
39
|
-
// Refused at run time as well as in the type
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
// Refused at run time as well as in the type, read through a widened view —
|
|
41
|
+
// see defineFact for why the widening is deliberate.
|
|
42
|
+
const raw = opts;
|
|
43
|
+
const toMessages = raw.slot === 'messages';
|
|
44
|
+
if (toMessages && !raw.role) {
|
|
45
|
+
throw new Error(`defineInstruction('${opts.id}'): \`slot: 'messages'\` requires a \`role\` — ` +
|
|
46
|
+
`'user', 'assistant', or 'system' on a provider that carries it. There is no ` +
|
|
47
|
+
`default: who appears to speak is a meaning your app owns, not one the library picks.`);
|
|
48
|
+
}
|
|
49
|
+
if (toMessages && raw.role === 'tool') {
|
|
50
|
+
throw new Error(messagesToolRoleRefusal(`defineInstruction('${opts.id}')`));
|
|
42
51
|
}
|
|
43
52
|
const trigger = opts.activeWhen
|
|
44
53
|
? { kind: 'rule', activeWhen: opts.activeWhen }
|
|
45
54
|
: { kind: 'always' };
|
|
46
|
-
const inject =
|
|
55
|
+
const inject = toMessages
|
|
56
|
+
? { messages: [{ role: raw.role, content: opts.prompt }] }
|
|
57
|
+
: { systemPrompt: opts.prompt };
|
|
47
58
|
const cache = resolveCachePolicy('instruction', opts.cache);
|
|
48
59
|
return Object.freeze({
|
|
49
60
|
id: opts.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineInstruction.js","sourceRoot":"","sources":["../../../../../src/lib/injection-engine/factories/defineInstruction.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"defineInstruction.js","sourceRoot":"","sources":["../../../../../src/lib/injection-engine/factories/defineInstruction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAsExE,MAAM,UAAU,iBAAiB,CAAC,IAA8B;IAC9D,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,KA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