@feltdb/feltkit 0.5.3 → 0.5.5
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/dist/app.d.ts +22 -0
- package/dist/app.js +6 -2
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +5 -1
- package/dist/appboundry/build.js +7 -3
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +32 -4
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.d.ts +20 -0
- package/dist/appboundry/host.js +25 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/eve/index.d.ts +8 -0
- package/dist/eve/index.js +9 -0
- package/dist/eve/index.js.map +1 -1
- package/dist/runtime/context.d.ts +11 -2
- package/dist/runtime/generation.d.ts +28 -64
- package/dist/runtime/generation.js +30 -262
- package/dist/runtime/generation.js.map +1 -1
- package/dist/runtime/projects.d.ts +10 -1
- package/dist/runtime/projects.js +14 -3
- package/dist/runtime/projects.js.map +1 -1
- package/dist/runtime/runtime.d.ts +4 -0
- package/dist/runtime/runtime.js +4 -1
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/server/eve.d.ts +31 -0
- package/dist/server/eve.js +117 -22
- package/dist/server/eve.js.map +1 -1
- package/dist/server/project.js +3 -0
- package/dist/server/project.js.map +1 -1
- package/docs/AGENT-CONTROL.md +5 -0
- package/docs/APPBOUNDRY.md +10 -3
- package/docs/GENERATION.md +7 -0
- package/docs/README.md +2 -2
- package/package.json +9 -9
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-agent/SKILL.md +1 -1
- package/skills/feltkit-data/SKILL.md +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
|
@@ -1,53 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model generation: open-ended text, streamed, with tool calls.
|
|
3
|
+
*
|
|
4
|
+
* The sibling of decisions.ts. The same ModelHost resolves the model, the provider protocol, the
|
|
5
|
+
* endpoint and the credential (AppPort Services Intelligence + FeltKit custody, or a Resolver
|
|
6
|
+
* reference), so generation inherits the same custody, receipts and error taxonomy. The provider
|
|
7
|
+
* protocols are AppPort Services' `streamGeneration` (OpenAI chat completions, OpenAI-compatible
|
|
8
|
+
* servers and Anthropic Messages, all streamed), the same code an AppBoundry host runs for its guests
|
|
9
|
+
* (`model@1`); this module maps its failures to FeltKit's model errors and hints.
|
|
10
|
+
*
|
|
11
|
+
* A model's tool call is *data*: a name and an input. Nothing here runs it. The caller turns it
|
|
12
|
+
* into a proposal (runtime/agent.ts), which runs only through AppPort, as the task owner, and
|
|
13
|
+
* only after approval when it is consequential.
|
|
14
|
+
*
|
|
15
|
+
* Cancellation: the caller's AbortSignal aborts the provider request. A cancelled generation is
|
|
16
|
+
* a result (finish: "cancelled", with the text received so far), not an error, so its receipt is
|
|
17
|
+
* still recorded.
|
|
18
|
+
*/
|
|
19
|
+
import { supportsGeneration, generationDigest, sseEvents, capabilityName, DEFAULT_GENERATION_TIMEOUT_MS, DEFAULT_MAX_TOKENS, type GenerationRole, type ToolCall, type GenerationMessage, type ToolDefinition, type GenerationRequest, type FinishReason, type GenerationResult } from "@appport/services";
|
|
1
20
|
import { type ModelConnection, type ModelResolution } from "./decisions.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
/** The provider's id for this call, used to send its result back. */
|
|
5
|
-
id: string;
|
|
6
|
-
/** The capability name ("tasks.create"), not the provider-safe tool name. */
|
|
7
|
-
name: string;
|
|
8
|
-
input: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
export interface GenerationMessage {
|
|
11
|
-
role: GenerationRole;
|
|
12
|
-
content: string;
|
|
13
|
-
/** role "assistant": the tool calls the model made in this turn. */
|
|
14
|
-
toolCalls?: ToolCall[];
|
|
15
|
-
/** role "tool": which call this is the result of. */
|
|
16
|
-
toolCallId?: string;
|
|
17
|
-
}
|
|
18
|
-
export interface ToolDefinition {
|
|
19
|
-
/** An AppPort capability name, e.g. "tasks.create". */
|
|
20
|
-
name: string;
|
|
21
|
-
description?: string;
|
|
22
|
-
/** JSON Schema of the capability's input (an object schema). */
|
|
23
|
-
inputSchema: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
export interface GenerationRequest {
|
|
26
|
-
messages: GenerationMessage[];
|
|
27
|
-
tools?: ToolDefinition[];
|
|
28
|
-
maxTokens?: number;
|
|
29
|
-
temperature?: number;
|
|
30
|
-
signal?: AbortSignal;
|
|
31
|
-
/** Called with each piece of text as it arrives. */
|
|
32
|
-
onDelta?: (text: string) => void;
|
|
33
|
-
}
|
|
34
|
-
export type FinishReason = "stop" | "tool_calls" | "length" | "cancelled" | "refusal";
|
|
35
|
-
export interface GenerationResult {
|
|
36
|
-
text: string;
|
|
37
|
-
toolCalls: ToolCall[];
|
|
38
|
-
finish: FinishReason;
|
|
39
|
-
/** Token counts, and the cost when the provider reports one (e.g. a gateway's usage.cost, in its currency). */
|
|
40
|
-
usage: {
|
|
41
|
-
inputTokens: number | null;
|
|
42
|
-
outputTokens: number | null;
|
|
43
|
-
cost?: number | null;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
/** The digest of a generation's input (messages and tool names): identifies it without storing it twice. */
|
|
47
|
-
export declare function generationDigest(request: {
|
|
48
|
-
messages: GenerationMessage[];
|
|
49
|
-
tools?: ToolDefinition[];
|
|
50
|
-
}): string;
|
|
21
|
+
export { supportsGeneration, generationDigest, sseEvents, capabilityName, DEFAULT_GENERATION_TIMEOUT_MS, DEFAULT_MAX_TOKENS };
|
|
22
|
+
export type { GenerationRole, ToolCall, GenerationMessage, ToolDefinition, GenerationRequest, FinishReason, GenerationResult };
|
|
51
23
|
/** An error that ended a stream, with the text that arrived before it (not sent to callers; recorded as evidence). */
|
|
52
24
|
export type GenerationError = Error & {
|
|
53
25
|
partialText?: string;
|
|
@@ -58,7 +30,8 @@ export interface GenerationReceipt {
|
|
|
58
30
|
model: string;
|
|
59
31
|
protocol: string;
|
|
60
32
|
endpoint: string;
|
|
61
|
-
|
|
33
|
+
/** Where the model came from: a Resolver reference, the Intelligence selection, or (in an AppBoundry artifact) the host's model binding. */
|
|
34
|
+
source: "resolver" | "intelligence" | "host";
|
|
62
35
|
resolution?: ModelResolution;
|
|
63
36
|
credential: string | null;
|
|
64
37
|
finish: FinishReason;
|
|
@@ -72,23 +45,14 @@ export interface GenerationReceipt {
|
|
|
72
45
|
/** sha256 of the request messages and tool names: proves which input produced the output without storing it twice. */
|
|
73
46
|
inputDigest: string;
|
|
74
47
|
}
|
|
75
|
-
export declare const DEFAULT_GENERATION_TIMEOUT_MS = 120000;
|
|
76
|
-
export declare const DEFAULT_MAX_TOKENS = 1024;
|
|
77
48
|
/**
|
|
78
|
-
* Provider tool names allow [A-Za-z0-9_-] only
|
|
79
|
-
*
|
|
80
|
-
* mapping as @appport/mcp's toToolName, without its 64-character truncation (refused instead).
|
|
49
|
+
* Provider tool names allow [A-Za-z0-9_-] only; AppPort capability names map "." ↔ "_" exactly.
|
|
50
|
+
* A name that cannot be offered is refused (FeltKit's INVALID_ARGUMENT), never truncated.
|
|
81
51
|
*/
|
|
82
52
|
export declare function toolName(capability: string): string;
|
|
83
|
-
export declare const capabilityName: (tool: string) => string;
|
|
84
|
-
/** Split a fetch body into SSE events ({ event, data }). Tolerates \r\n and multi-line data. */
|
|
85
|
-
export declare function sseEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<{
|
|
86
|
-
event: string | null;
|
|
87
|
-
data: string;
|
|
88
|
-
}>;
|
|
89
|
-
export declare function supportsGeneration(protocol: string): boolean;
|
|
90
53
|
/**
|
|
91
|
-
* Stream one generation over a resolved connection
|
|
92
|
-
* what was received with finish "cancelled";
|
|
54
|
+
* Stream one generation over a resolved connection (AppPort Services' streamGeneration). Cancellation
|
|
55
|
+
* by the caller's signal returns what was received with finish "cancelled"; a failure is FeltKit's
|
|
56
|
+
* model error with the text received before it.
|
|
93
57
|
*/
|
|
94
58
|
export declare function streamGeneration(protocol: string, connection: ModelConnection, request: GenerationRequest): Promise<GenerationResult>;
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The sibling of decisions.ts. The same ModelHost resolves the model, the provider protocol, the
|
|
5
5
|
* endpoint and the credential (AppPort Services Intelligence + FeltKit custody, or a Resolver
|
|
6
|
-
* reference), so generation inherits the same custody, receipts and error taxonomy.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - Anthropic Messages with `stream: true`
|
|
6
|
+
* reference), so generation inherits the same custody, receipts and error taxonomy. The provider
|
|
7
|
+
* protocols are AppPort Services' `streamGeneration` (OpenAI chat completions, OpenAI-compatible
|
|
8
|
+
* servers and Anthropic Messages, all streamed), the same code an AppBoundry host runs for its guests
|
|
9
|
+
* (`model@1`); this module maps its failures to FeltKit's model errors and hints.
|
|
11
10
|
*
|
|
12
11
|
* A model's tool call is *data*: a name and an input. Nothing here runs it. The caller turns it
|
|
13
12
|
* into a proposal (runtime/agent.ts), which runs only through AppPort, as the task owner, and
|
|
@@ -17,279 +16,48 @@
|
|
|
17
16
|
* a result (finish: "cancelled", with the text received so far), not an error, so its receipt is
|
|
18
17
|
* still recorded.
|
|
19
18
|
*/
|
|
20
|
-
import {
|
|
19
|
+
import { IntelligenceGenerationError, streamGeneration as streamSharedGeneration, supportsGeneration, generationDigest, sseEvents, capabilityName, toolName as sharedToolName, DEFAULT_GENERATION_TIMEOUT_MS, DEFAULT_MAX_TOKENS, } from "@appport/services";
|
|
21
20
|
import { modelError } from "./decisions.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
export { supportsGeneration, generationDigest, sseEvents, capabilityName, DEFAULT_GENERATION_TIMEOUT_MS, DEFAULT_MAX_TOKENS };
|
|
22
|
+
const HINTS = {
|
|
23
|
+
unsupported: "Shorten the capability name.",
|
|
24
|
+
unavailable: "Nothing more was generated. Check the endpoint is reachable and the provider's status, then try again.",
|
|
25
|
+
credential_refused: "Nothing was generated. Replace the API key (Studio → Models, `feltkit credential set`, or Resolver).",
|
|
26
|
+
provider_error: "Nothing more was generated. Check the model name and the provider's status.",
|
|
27
|
+
malformed: "Check the endpoint is the provider's API.",
|
|
28
|
+
timeout: "Raise agent.generationTimeoutMs, ask for less output, or check the provider.",
|
|
29
|
+
unknown_protocol: "Use an OpenAI, OpenAI-compatible or Anthropic provider.",
|
|
30
|
+
};
|
|
31
|
+
/** A shared generation failure as FeltKit's model error, keeping its problem, details and partial text. */
|
|
32
|
+
function asModelError(error) {
|
|
33
|
+
if (!(error instanceof IntelligenceGenerationError))
|
|
34
|
+
return error;
|
|
35
|
+
const mapped = modelError(error.problem, error.message, HINTS[error.problem] ?? "Nothing was generated.", error.details);
|
|
36
|
+
return error.partialText !== undefined ? Object.assign(mapped, { partialText: error.partialText }) : mapped;
|
|
25
37
|
}
|
|
26
|
-
export const DEFAULT_GENERATION_TIMEOUT_MS = 120_000;
|
|
27
|
-
export const DEFAULT_MAX_TOKENS = 1024;
|
|
28
38
|
/**
|
|
29
|
-
* Provider tool names allow [A-Za-z0-9_-] only
|
|
30
|
-
*
|
|
31
|
-
* mapping as @appport/mcp's toToolName, without its 64-character truncation (refused instead).
|
|
39
|
+
* Provider tool names allow [A-Za-z0-9_-] only; AppPort capability names map "." ↔ "_" exactly.
|
|
40
|
+
* A name that cannot be offered is refused (FeltKit's INVALID_ARGUMENT), never truncated.
|
|
32
41
|
*/
|
|
33
42
|
export function toolName(capability) {
|
|
34
|
-
const name = capability.replace(/\./g, "_");
|
|
35
|
-
if (!/^[a-z][a-z0-9_]{0,63}$/.test(name))
|
|
36
|
-
throw modelError("unsupported", `Capability "${capability}" cannot be offered to a model as a tool (its name must map to [a-z0-9_], at most 64 characters).`, "Shorten the capability name.");
|
|
37
|
-
return name;
|
|
38
|
-
}
|
|
39
|
-
export const capabilityName = (tool) => tool.replace(/_/g, ".");
|
|
40
|
-
// ---- Server-sent events -------------------------------------------------------------------
|
|
41
|
-
/** Split a fetch body into SSE events ({ event, data }). Tolerates \r\n and multi-line data. */
|
|
42
|
-
export async function* sseEvents(body) {
|
|
43
|
-
const reader = body.getReader();
|
|
44
|
-
const decoder = new TextDecoder();
|
|
45
|
-
let buffer = "";
|
|
46
|
-
try {
|
|
47
|
-
for (;;) {
|
|
48
|
-
const { value, done } = await reader.read();
|
|
49
|
-
if (done)
|
|
50
|
-
break;
|
|
51
|
-
buffer += decoder.decode(value, { stream: true });
|
|
52
|
-
let index;
|
|
53
|
-
while ((index = buffer.search(/\r?\n\r?\n/)) >= 0) {
|
|
54
|
-
const raw = buffer.slice(0, index);
|
|
55
|
-
buffer = buffer.slice(index).replace(/^\r?\n\r?\n/, "");
|
|
56
|
-
let event = null;
|
|
57
|
-
const data = [];
|
|
58
|
-
for (const line of raw.split(/\r?\n/)) {
|
|
59
|
-
if (line.startsWith(":"))
|
|
60
|
-
continue;
|
|
61
|
-
const colon = line.indexOf(":");
|
|
62
|
-
const field = colon < 0 ? line : line.slice(0, colon);
|
|
63
|
-
const val = colon < 0 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
64
|
-
if (field === "event")
|
|
65
|
-
event = val;
|
|
66
|
-
else if (field === "data")
|
|
67
|
-
data.push(val);
|
|
68
|
-
}
|
|
69
|
-
if (data.length)
|
|
70
|
-
yield { event, data: data.join("\n") };
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
finally {
|
|
75
|
-
reader.releaseLock();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const scrub = (text, secret) => (secret ? text.split(secret).join("[redacted]") : text).replace(/\b(sk|key)-[A-Za-z0-9_-]{12,}/g, "[redacted]");
|
|
79
|
-
/** POST and return the streaming body, mapping transport and HTTP failures to model problems. */
|
|
80
|
-
async function open(connection, url, headers, body, signal) {
|
|
81
|
-
let response;
|
|
82
43
|
try {
|
|
83
|
-
|
|
44
|
+
return sharedToolName(capability);
|
|
84
45
|
}
|
|
85
46
|
catch (error) {
|
|
86
|
-
|
|
87
|
-
throw error; // the caller decides: cancelled or timed out
|
|
88
|
-
const cause = scrub(String(error?.cause?.code ?? error?.message ?? error), connection.credential);
|
|
89
|
-
throw modelError("unavailable", `${connection.provider} could not be reached at ${new URL(url).origin} (${cause}).`, "Nothing was generated. Check the endpoint is reachable.", { provider: connection.provider });
|
|
90
|
-
}
|
|
91
|
-
if (!response.ok || !response.body) {
|
|
92
|
-
const text = scrub(await response.text().catch(() => ""), connection.credential);
|
|
93
|
-
if (response.status === 401 || response.status === 403) {
|
|
94
|
-
throw modelError("credential_refused", `${connection.provider} refused the credential (HTTP ${response.status}).`, "Nothing was generated. Replace the API key (Studio → Models, `feltkit credential set`, or Resolver).", { provider: connection.provider, status: response.status });
|
|
95
|
-
}
|
|
96
|
-
throw modelError("provider_error", `${connection.provider} answered HTTP ${response.status}: ${text.slice(0, 300)}`, "Nothing was generated. Check the model name and the provider's status.", { provider: connection.provider, status: response.status });
|
|
97
|
-
}
|
|
98
|
-
return response.body;
|
|
99
|
-
}
|
|
100
|
-
function parse(data, provider) {
|
|
101
|
-
try {
|
|
102
|
-
return JSON.parse(data);
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
throw modelError("malformed", `${provider} streamed an event that is not JSON.`, "Check the endpoint is the provider's API.", { provider });
|
|
47
|
+
throw asModelError(error);
|
|
106
48
|
}
|
|
107
49
|
}
|
|
108
|
-
function parseInput(raw, provider, name) {
|
|
109
|
-
if (!raw.trim())
|
|
110
|
-
return {};
|
|
111
|
-
try {
|
|
112
|
-
const value = JSON.parse(raw);
|
|
113
|
-
if (value && typeof value === "object" && !Array.isArray(value))
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
// fall through
|
|
118
|
-
}
|
|
119
|
-
throw modelError("malformed", `${provider} called tool ${name} with input that is not a JSON object.`, "The tool call was not used.", { provider });
|
|
120
|
-
}
|
|
121
|
-
const join = (endpoint, path) => `${endpoint.replace(/\/+$/, "")}${path}`;
|
|
122
|
-
// ---- OpenAI chat completions --------------------------------------------------------------
|
|
123
|
-
async function openaiStream(connection, request, signal) {
|
|
124
|
-
const messages = request.messages.map((m) => {
|
|
125
|
-
if (m.role === "tool")
|
|
126
|
-
return { role: "tool", tool_call_id: m.toolCallId, content: m.content };
|
|
127
|
-
if (m.role === "assistant" && m.toolCalls?.length) {
|
|
128
|
-
return { role: "assistant", content: m.content || null, tool_calls: m.toolCalls.map((c) => ({ id: c.id, type: "function", function: { name: toolName(c.name), arguments: JSON.stringify(c.input) } })) };
|
|
129
|
-
}
|
|
130
|
-
return { role: m.role, content: m.content };
|
|
131
|
-
});
|
|
132
|
-
const body = {
|
|
133
|
-
model: connection.model,
|
|
134
|
-
messages,
|
|
135
|
-
stream: true,
|
|
136
|
-
stream_options: { include_usage: true },
|
|
137
|
-
max_tokens: request.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
138
|
-
...(request.temperature !== undefined ? { temperature: request.temperature } : {}),
|
|
139
|
-
...(request.tools?.length ? { tools: request.tools.map((t) => ({ type: "function", function: { name: toolName(t.name), ...(t.description ? { description: t.description } : {}), parameters: t.inputSchema } })) } : {}),
|
|
140
|
-
};
|
|
141
|
-
const stream = await open(connection, join(connection.endpoint, "/chat/completions"), connection.credential ? { authorization: `Bearer ${connection.credential}` } : {}, body, signal);
|
|
142
|
-
let text = "";
|
|
143
|
-
let finish = "stop";
|
|
144
|
-
const usage = { inputTokens: null, outputTokens: null };
|
|
145
|
-
const calls = new Map();
|
|
146
|
-
for await (const event of sseEvents(stream)) {
|
|
147
|
-
if (event.data === "[DONE]")
|
|
148
|
-
break;
|
|
149
|
-
const chunk = parse(event.data, connection.provider);
|
|
150
|
-
if (chunk?.error)
|
|
151
|
-
throw modelError("provider_error", `${connection.provider} reported: ${scrub(String(chunk.error.message ?? JSON.stringify(chunk.error)), connection.credential).slice(0, 300)}`, "Nothing more was generated.", { provider: connection.provider });
|
|
152
|
-
if (chunk?.usage) {
|
|
153
|
-
usage.inputTokens = chunk.usage.prompt_tokens ?? null;
|
|
154
|
-
usage.outputTokens = chunk.usage.completion_tokens ?? null;
|
|
155
|
-
if (typeof chunk.usage.cost === "number")
|
|
156
|
-
usage.cost = chunk.usage.cost;
|
|
157
|
-
}
|
|
158
|
-
const choice = chunk?.choices?.[0];
|
|
159
|
-
if (!choice)
|
|
160
|
-
continue;
|
|
161
|
-
const delta = choice.delta ?? {};
|
|
162
|
-
if (typeof delta.content === "string" && delta.content) {
|
|
163
|
-
text += delta.content;
|
|
164
|
-
request.onDelta?.(delta.content);
|
|
165
|
-
}
|
|
166
|
-
for (const call of delta.tool_calls ?? []) {
|
|
167
|
-
const at = calls.get(call.index ?? 0) ?? { id: "", name: "", args: "" };
|
|
168
|
-
if (call.id)
|
|
169
|
-
at.id = call.id;
|
|
170
|
-
if (call.function?.name)
|
|
171
|
-
at.name += call.function.name;
|
|
172
|
-
if (call.function?.arguments)
|
|
173
|
-
at.args += call.function.arguments;
|
|
174
|
-
calls.set(call.index ?? 0, at);
|
|
175
|
-
}
|
|
176
|
-
if (choice.finish_reason)
|
|
177
|
-
finish = choice.finish_reason === "tool_calls" ? "tool_calls" : choice.finish_reason === "length" ? "length" : choice.finish_reason === "content_filter" ? "refusal" : "stop";
|
|
178
|
-
}
|
|
179
|
-
const toolCalls = [...calls.entries()].sort(([a], [b]) => a - b).map(([, c]) => ({ id: c.id, name: capabilityName(c.name), input: parseInput(c.args, connection.provider, c.name) }));
|
|
180
|
-
return { text, toolCalls, finish: toolCalls.length ? "tool_calls" : finish, usage };
|
|
181
|
-
}
|
|
182
|
-
// ---- Anthropic Messages -------------------------------------------------------------------
|
|
183
|
-
async function anthropicStream(connection, request, signal) {
|
|
184
|
-
const system = request.messages.filter((m) => m.role === "system").map((m) => m.content).join("\n\n");
|
|
185
|
-
const messages = [];
|
|
186
|
-
for (const m of request.messages) {
|
|
187
|
-
if (m.role === "system")
|
|
188
|
-
continue;
|
|
189
|
-
if (m.role === "tool") {
|
|
190
|
-
const block = { type: "tool_result", tool_use_id: m.toolCallId, content: m.content };
|
|
191
|
-
const last = messages.at(-1);
|
|
192
|
-
// Consecutive tool results go in one user turn, as the API requires.
|
|
193
|
-
if (last?.role === "user" && Array.isArray(last.content) && last.content.every((b) => b.type === "tool_result"))
|
|
194
|
-
last.content.push(block);
|
|
195
|
-
else
|
|
196
|
-
messages.push({ role: "user", content: [block] });
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
if (m.role === "assistant" && m.toolCalls?.length) {
|
|
200
|
-
messages.push({ role: "assistant", content: [...(m.content ? [{ type: "text", text: m.content }] : []), ...m.toolCalls.map((c) => ({ type: "tool_use", id: c.id, name: toolName(c.name), input: c.input }))] });
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
messages.push({ role: m.role, content: m.content });
|
|
204
|
-
}
|
|
205
|
-
const base = connection.endpoint.replace(/\/+$/, "");
|
|
206
|
-
const url = base.endsWith("/v1") ? `${base}/messages` : `${base}/v1/messages`;
|
|
207
|
-
const body = {
|
|
208
|
-
model: connection.model,
|
|
209
|
-
max_tokens: request.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
210
|
-
stream: true,
|
|
211
|
-
messages,
|
|
212
|
-
...(system ? { system } : {}),
|
|
213
|
-
...(request.temperature !== undefined ? { temperature: request.temperature } : {}),
|
|
214
|
-
...(request.tools?.length ? { tools: request.tools.map((t) => ({ name: toolName(t.name), ...(t.description ? { description: t.description } : {}), input_schema: t.inputSchema })) } : {}),
|
|
215
|
-
};
|
|
216
|
-
const stream = await open(connection, url, { "anthropic-version": "2023-06-01", ...(connection.credential ? { "x-api-key": connection.credential } : {}) }, body, signal);
|
|
217
|
-
let text = "";
|
|
218
|
-
let finish = "stop";
|
|
219
|
-
const usage = { inputTokens: null, outputTokens: null };
|
|
220
|
-
const blocks = new Map();
|
|
221
|
-
for await (const event of sseEvents(stream)) {
|
|
222
|
-
const data = parse(event.data, connection.provider);
|
|
223
|
-
switch (data?.type) {
|
|
224
|
-
case "message_start":
|
|
225
|
-
usage.inputTokens = data.message?.usage?.input_tokens ?? null;
|
|
226
|
-
break;
|
|
227
|
-
case "content_block_start":
|
|
228
|
-
blocks.set(data.index, { type: data.content_block?.type, id: data.content_block?.id, name: data.content_block?.name, json: "" });
|
|
229
|
-
break;
|
|
230
|
-
case "content_block_delta": {
|
|
231
|
-
const d = data.delta ?? {};
|
|
232
|
-
if (d.type === "text_delta" && d.text) {
|
|
233
|
-
text += d.text;
|
|
234
|
-
request.onDelta?.(d.text);
|
|
235
|
-
}
|
|
236
|
-
else if (d.type === "input_json_delta") {
|
|
237
|
-
const block = blocks.get(data.index);
|
|
238
|
-
if (block)
|
|
239
|
-
block.json += d.partial_json ?? "";
|
|
240
|
-
}
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
case "message_delta":
|
|
244
|
-
if (data.usage?.output_tokens !== undefined)
|
|
245
|
-
usage.outputTokens = data.usage.output_tokens;
|
|
246
|
-
if (data.delta?.stop_reason)
|
|
247
|
-
finish = data.delta.stop_reason === "tool_use" ? "tool_calls" : data.delta.stop_reason === "max_tokens" ? "length" : data.delta.stop_reason === "refusal" ? "refusal" : "stop";
|
|
248
|
-
break;
|
|
249
|
-
case "error":
|
|
250
|
-
throw modelError("provider_error", `${connection.provider} reported: ${scrub(String(data.error?.message ?? "an error"), connection.credential).slice(0, 300)}`, "Nothing more was generated.", { provider: connection.provider });
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
const toolCalls = [...blocks.entries()]
|
|
254
|
-
.sort(([a], [b]) => a - b)
|
|
255
|
-
.filter(([, b]) => b.type === "tool_use")
|
|
256
|
-
.map(([, b]) => ({ id: b.id ?? "", name: capabilityName(b.name ?? ""), input: parseInput(b.json, connection.provider, b.name ?? "") }));
|
|
257
|
-
return { text, toolCalls, finish: toolCalls.length ? "tool_calls" : finish, usage };
|
|
258
|
-
}
|
|
259
|
-
const PROTOCOL_STREAMS = {
|
|
260
|
-
openai: openaiStream,
|
|
261
|
-
"openai-compatible": openaiStream,
|
|
262
|
-
anthropic: anthropicStream,
|
|
263
|
-
};
|
|
264
|
-
export function supportsGeneration(protocol) {
|
|
265
|
-
return protocol in PROTOCOL_STREAMS;
|
|
266
|
-
}
|
|
267
50
|
/**
|
|
268
|
-
* Stream one generation over a resolved connection
|
|
269
|
-
* what was received with finish "cancelled";
|
|
51
|
+
* Stream one generation over a resolved connection (AppPort Services' streamGeneration). Cancellation
|
|
52
|
+
* by the caller's signal returns what was received with finish "cancelled"; a failure is FeltKit's
|
|
53
|
+
* model error with the text received before it.
|
|
270
54
|
*/
|
|
271
55
|
export async function streamGeneration(protocol, connection, request) {
|
|
272
|
-
const run = PROTOCOL_STREAMS[protocol];
|
|
273
|
-
if (!run)
|
|
274
|
-
throw modelError("unknown_protocol", `FeltKit cannot generate with the "${protocol}" protocol.`, "Use an OpenAI, OpenAI-compatible or Anthropic provider.");
|
|
275
|
-
const timeoutMs = connection.timeoutMs ?? DEFAULT_GENERATION_TIMEOUT_MS;
|
|
276
|
-
const timeout = AbortSignal.timeout(timeoutMs);
|
|
277
|
-
const signal = request.signal ? AbortSignal.any([request.signal, timeout]) : timeout;
|
|
278
|
-
let text = "";
|
|
279
|
-
const tracked = { ...request, onDelta: (d) => ((text += d), request.onDelta?.(d)) };
|
|
280
56
|
try {
|
|
281
|
-
return await
|
|
57
|
+
return await streamSharedGeneration(protocol, connection, request);
|
|
282
58
|
}
|
|
283
59
|
catch (error) {
|
|
284
|
-
|
|
285
|
-
return { text, toolCalls: [], finish: "cancelled", usage: { inputTokens: null, outputTokens: null } };
|
|
286
|
-
const partial = (e) => Object.assign(e, { partialText: text });
|
|
287
|
-
if (timeout.aborted)
|
|
288
|
-
throw partial(modelError("timeout", `${connection.provider} did not finish within ${timeoutMs} ms.`, "Raise agent.generationTimeoutMs, ask for less output, or check the provider.", { provider: connection.provider, timeoutMs }));
|
|
289
|
-
if (error?.details && error.code)
|
|
290
|
-
throw partial(error);
|
|
291
|
-
// The connection ended mid-stream (reset, closed, terminated): the provider stopped answering.
|
|
292
|
-
throw partial(modelError("unavailable", `The connection to ${connection.provider} ended before the generation finished (${scrub(String(error?.message ?? error), connection.credential).slice(0, 200)}).`, "Nothing more was generated. Try again; check the provider's status if it persists.", { provider: connection.provider }));
|
|
60
|
+
throw asModelError(error);
|
|
293
61
|
}
|
|
294
62
|
}
|
|
295
63
|
//# sourceMappingURL=generation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generation.js","sourceRoot":"","sources":["../../src/runtime/generation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAA8C,MAAM,gBAAgB,CAAC;AAiDxF,4GAA4G;AAC5G,MAAM,UAAU,gBAAgB,CAAC,OAAoE;IACnG,OAAO,UAAU,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAChK,CAAC;AAuBD,MAAM,CAAC,MAAM,6BAA6B,GAAG,OAAO,CAAC;AACrD,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,UAAkB;IACzC,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,UAAU,CAAC,a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EAAE,CAAC;QACf,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,QAAgB,EAAE,UAA2B,EAAE,OAA0B;IAC9G,IAAI,CAAC;QACH,OAAO,MAAM,sBAAsB,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -3,6 +3,8 @@ import type { InstanceIdentity } from "./instance.js";
|
|
|
3
3
|
import type { FeltKitRuntime } from "./runtime.js";
|
|
4
4
|
export interface RuntimeRecord {
|
|
5
5
|
pid: number;
|
|
6
|
+
/** The host that wrote it (written since this field exists; a record without it is judged by pid alone, as before). */
|
|
7
|
+
host?: string;
|
|
6
8
|
url: string;
|
|
7
9
|
environment: string;
|
|
8
10
|
application: string;
|
|
@@ -13,7 +15,14 @@ export declare function writeAtomic(path: string, content: string, mode?: number
|
|
|
13
15
|
export declare function adminToken(runtimeDir: string): string;
|
|
14
16
|
export declare function readAdminToken(runtimeDir: string): string | null;
|
|
15
17
|
export declare function isAlive(pid: number): boolean;
|
|
16
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* The live owner of an environment, or null. Stale records are ignored, by FeltDB's own rule for its lock:
|
|
20
|
+
* - a dead pid;
|
|
21
|
+
* - this process's own pid: a record left by an earlier run that had this pid (a restarted container or VM boots the
|
|
22
|
+
* same way, so after an unclean stop the new process is often that very pid, and would otherwise refuse itself);
|
|
23
|
+
* - another host's record: its pid says nothing here. This check is advisory (it only names the running server); the
|
|
24
|
+
* state's FeltDB lock, which refuses another host's lock, stays the authority.
|
|
25
|
+
*/
|
|
17
26
|
export declare function readRuntimeRecord(runtimeDir: string): RuntimeRecord | null;
|
|
18
27
|
export declare function writeRuntimeRecord(runtimeDir: string, record: RuntimeRecord): void;
|
|
19
28
|
export declare function clearRuntimeRecord(runtimeDir: string): void;
|
package/dist/runtime/projects.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { randomBytes } from "node:crypto";
|
|
15
|
-
import { homedir } from "node:os";
|
|
15
|
+
import { homedir, hostname } from "node:os";
|
|
16
16
|
import { join, resolve } from "node:path";
|
|
17
17
|
import { describeStorage, resolveEnvironment } from "./environment.js";
|
|
18
18
|
import { describeProduction, readDeployment } from "./deployment.js";
|
|
@@ -48,13 +48,24 @@ export function isAlive(pid) {
|
|
|
48
48
|
return error.code === "EPERM";
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* The live owner of an environment, or null. Stale records are ignored, by FeltDB's own rule for its lock:
|
|
53
|
+
* - a dead pid;
|
|
54
|
+
* - this process's own pid: a record left by an earlier run that had this pid (a restarted container or VM boots the
|
|
55
|
+
* same way, so after an unclean stop the new process is often that very pid, and would otherwise refuse itself);
|
|
56
|
+
* - another host's record: its pid says nothing here. This check is advisory (it only names the running server); the
|
|
57
|
+
* state's FeltDB lock, which refuses another host's lock, stays the authority.
|
|
58
|
+
*/
|
|
52
59
|
export function readRuntimeRecord(runtimeDir) {
|
|
53
60
|
const file = join(runtimeDir, "runtime.json");
|
|
54
61
|
if (!existsSync(file))
|
|
55
62
|
return null;
|
|
56
63
|
try {
|
|
57
64
|
const record = JSON.parse(readFileSync(file, "utf8"));
|
|
65
|
+
if (record.host !== undefined && record.host !== hostname())
|
|
66
|
+
return null;
|
|
67
|
+
if (record.pid === process.pid)
|
|
68
|
+
return null;
|
|
58
69
|
return isAlive(record.pid) ? record : null;
|
|
59
70
|
}
|
|
60
71
|
catch {
|
|
@@ -63,7 +74,7 @@ export function readRuntimeRecord(runtimeDir) {
|
|
|
63
74
|
}
|
|
64
75
|
export function writeRuntimeRecord(runtimeDir, record) {
|
|
65
76
|
mkdirSync(runtimeDir, { recursive: true });
|
|
66
|
-
writeAtomic(join(runtimeDir, "runtime.json"), JSON.stringify(record, null, 2));
|
|
77
|
+
writeAtomic(join(runtimeDir, "runtime.json"), JSON.stringify({ ...record, host: record.host ?? hostname() }, null, 2));
|
|
67
78
|
}
|
|
68
79
|
export function clearRuntimeRecord(runtimeDir) {
|
|
69
80
|
const file = join(runtimeDir, "runtime.json");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/runtime/projects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/runtime/projects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAyB,MAAM,iBAAiB,CAAC;AAe5F,MAAM,UAAU,WAAW,CAAC,IAAY,EAA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CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,KAAK,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,CAAC;YAC7Q,CAAC;YACD,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,kBAAkB,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;gBAClG,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC;YAC9J,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAG,KAAe,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;YACpJ,CAAC;QACH,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -225,10 +225,14 @@ export interface ProjectAgentSessions {
|
|
|
225
225
|
message: string;
|
|
226
226
|
origin: import("./context.js").AgentSessionOrigin;
|
|
227
227
|
key?: string;
|
|
228
|
+
owner?: string;
|
|
228
229
|
}): Promise<{
|
|
229
230
|
sessionId: string;
|
|
230
231
|
created: boolean;
|
|
231
232
|
}>;
|
|
233
|
+
send(agent: string, caller: Principal | null, sessionId: string, message: string): Promise<{
|
|
234
|
+
delivered: boolean;
|
|
235
|
+
}>;
|
|
232
236
|
end(agent: string, caller: Principal | null, sessionId: string, reason?: string): Promise<{
|
|
233
237
|
ended: boolean;
|
|
234
238
|
}>;
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -2623,7 +2623,9 @@ export class FeltKitRuntime {
|
|
|
2623
2623
|
for (const m of request.messages)
|
|
2624
2624
|
roles[m.role] = (roles[m.role] ?? 0) + 1;
|
|
2625
2625
|
// The record exists before the provider is contacted: every attempt has an outcome.
|
|
2626
|
-
|
|
2626
|
+
// Without a turn's task, the generation gets one of its own (per call), so it is recorded all the same.
|
|
2627
|
+
const taskId = request.taskId ?? (await agent.openTask({ principal: p, objective: "model generation", key: `generation:${requestId}` })).taskId;
|
|
2628
|
+
const handle = await agent.beginGeneration(taskId, p, { digest: generationDigest(request), messages: request.messages.length, roles, tools: (request.tools ?? []).map((t) => t.name) });
|
|
2627
2629
|
emit({ type: "generation.started", generationId: handle.generationId });
|
|
2628
2630
|
let streamed = "";
|
|
2629
2631
|
let outcome;
|
|
@@ -2685,6 +2687,7 @@ export class FeltKitRuntime {
|
|
|
2685
2687
|
checkpoint: (taskId) => agent.control.checkpoint(taskId, signedIn()),
|
|
2686
2688
|
acknowledge: (taskId, instructionId, input) => agent.control.acknowledge(taskId, instructionId, input, signedIn()),
|
|
2687
2689
|
startSession: (agentName, input) => this.#agentSessions().start(agentName, principal, input),
|
|
2690
|
+
sendToSession: (agentName, sessionId, message) => this.#agentSessions().send(agentName, principal, sessionId, message),
|
|
2688
2691
|
endSession: (agentName, sessionId, reason) => this.#agentSessions().end(agentName, principal, sessionId, reason),
|
|
2689
2692
|
propose: async (taskId, proposal) => {
|
|
2690
2693
|
const p = signedIn();
|