@fevex/core 0.1.0-alpha.0 → 0.1.0-alpha.2
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/README.md +770 -52
- package/dist/agents/index.d.mts +1 -22
- package/dist/agents/index.mjs +1 -1
- package/dist/channels/index.d.mts +2 -0
- package/dist/channels/index.mjs +150 -0
- package/dist/evals/index.d.mts +153 -0
- package/dist/evals/index.mjs +422 -0
- package/dist/fevex-Ddyi6z6L.d.mts +60 -0
- package/dist/http/index.d.mts +90 -0
- package/dist/http/index.mjs +470 -0
- package/dist/index-B4PIkqOU.d.mts +80 -0
- package/dist/index-Bg9rr8Qe.d.mts +50 -0
- package/dist/index-Bgcxgy66.d.mts +82 -0
- package/dist/index-CTIwrVf9.d.mts +51 -0
- package/dist/index-CqOjvtQ9.d.mts +132 -0
- package/dist/index-CrOId2px.d.mts +66 -0
- package/dist/index-DeXUtyd9.d.mts +70 -0
- package/dist/index-DviHtsLo.d.mts +58 -0
- package/dist/index-Dx_LotWZ.d.mts +425 -0
- package/dist/index-dkFyTNh4.d.mts +21 -0
- package/dist/index.d.mts +39 -15
- package/dist/index.mjs +3505 -194
- package/dist/knowledge/index.d.mts +2 -0
- package/dist/knowledge/index.mjs +89 -0
- package/dist/model-stream-u2xMsEaf.mjs +251 -0
- package/dist/models/index.d.mts +2 -27
- package/dist/observability/index.d.mts +2 -0
- package/dist/observability/index.mjs +1 -0
- package/dist/policies/index.d.mts +2 -0
- package/dist/policies/index.mjs +6 -0
- package/dist/run-error-Cr17wPGH.mjs +23 -0
- package/dist/runtime/index.d.mts +2 -17
- package/dist/runtime/index.mjs +141 -1
- package/dist/sandbox/index.d.mts +2 -0
- package/dist/sandbox/index.mjs +122 -0
- package/dist/teams/index.d.mts +2 -0
- package/dist/teams/index.mjs +2 -0
- package/dist/teams-Ctz676G4.mjs +82 -0
- package/dist/testing/index.d.mts +34 -8
- package/dist/testing/index.mjs +572 -23
- package/dist/tools/index.d.mts +3 -31
- package/dist/tools/index.mjs +222 -2
- package/dist/types-CuoRx12Q.d.mts +333 -0
- package/dist/workflows/index.d.mts +2 -0
- package/dist/workflows/index.mjs +6 -0
- package/package.json +39 -3
- package/dist/index-D_RBJmVt.d.mts +0 -44
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as MemoryQuery, c as MemoryWrite, d as defineContextProvider, f as defineSkill, i as KnowledgeContext, l as SkillDefinition, n as ContextBlock, o as MemoryRecord, r as ContextProvider, s as MemoryStore, t as InMemoryMemoryStore, u as createMemoryContextProvider } from "../index-DeXUtyd9.mjs";
|
|
2
|
+
export { ContextBlock, ContextProvider, InMemoryMemoryStore, KnowledgeContext, MemoryQuery, MemoryRecord, MemoryStore, MemoryWrite, SkillDefinition, createMemoryContextProvider, defineContextProvider, defineSkill };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//#region src/knowledge/in-memory-memory-store.ts
|
|
2
|
+
/** Volatile keyword-search memory store for tests and local development. */
|
|
3
|
+
var InMemoryMemoryStore = class {
|
|
4
|
+
#records = /* @__PURE__ */ new Map();
|
|
5
|
+
async search(query, context) {
|
|
6
|
+
context.signal?.throwIfAborted();
|
|
7
|
+
const terms = query.query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
8
|
+
const scored = [...this.#records.values()].filter((record) => matchesScope(record, query)).map((record) => ({
|
|
9
|
+
record,
|
|
10
|
+
score: score(record.content, terms)
|
|
11
|
+
})).filter(({ score }) => !terms.length || score > 0).sort((left, right) => right.score - left.score || right.record.createdAt.localeCompare(left.record.createdAt));
|
|
12
|
+
return scored.slice(0, query.limit ?? scored.length).map(({ record }) => structuredClone(record));
|
|
13
|
+
}
|
|
14
|
+
async write(record, context) {
|
|
15
|
+
context.signal?.throwIfAborted();
|
|
16
|
+
const saved = {
|
|
17
|
+
id: crypto.randomUUID(),
|
|
18
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19
|
+
...structuredClone(record)
|
|
20
|
+
};
|
|
21
|
+
this.#records.set(saved.id, saved);
|
|
22
|
+
return structuredClone(saved);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function matchesScope(record, query) {
|
|
26
|
+
return matches(record.agentName, query.agentName) && matches(record.sessionId, query.sessionId) && matches(record.namespace, query.namespace) && matches(record.actor?.id, query.actor?.id);
|
|
27
|
+
}
|
|
28
|
+
function matches(left, right) {
|
|
29
|
+
return right === void 0 || left === void 0 || left === right;
|
|
30
|
+
}
|
|
31
|
+
function score(content, terms) {
|
|
32
|
+
const text = content.toLowerCase();
|
|
33
|
+
return terms.reduce((total, term) => total + (text.includes(term) ? 1 : 0), 0);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/knowledge/knowledge.ts
|
|
37
|
+
function defineContextProvider(provider) {
|
|
38
|
+
return provider;
|
|
39
|
+
}
|
|
40
|
+
function defineSkill(skill) {
|
|
41
|
+
return defineContextProvider({
|
|
42
|
+
name: skill.name,
|
|
43
|
+
async read() {
|
|
44
|
+
return [{
|
|
45
|
+
id: `${skill.name}:instructions`,
|
|
46
|
+
content: skill.instructions
|
|
47
|
+
}, ...(skill.resources ?? []).map((resource, index) => {
|
|
48
|
+
const normalized = isSkillResource(resource) ? resource : { content: resource };
|
|
49
|
+
return {
|
|
50
|
+
id: normalized.id ?? `${skill.name}:resource:${index + 1}`,
|
|
51
|
+
content: stringifyKnowledge(normalized.content),
|
|
52
|
+
...normalized.metadata === void 0 ? {} : { metadata: normalized.metadata }
|
|
53
|
+
};
|
|
54
|
+
})];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function isSkillResource(value) {
|
|
59
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && "content" in value && (value.id === void 0 || typeof value.id === "string");
|
|
60
|
+
}
|
|
61
|
+
function createMemoryContextProvider(options) {
|
|
62
|
+
return defineContextProvider({
|
|
63
|
+
name: options.name ?? "memory",
|
|
64
|
+
async read(context) {
|
|
65
|
+
return (await options.store.search({
|
|
66
|
+
query: context.input,
|
|
67
|
+
limit: options.limit,
|
|
68
|
+
agentName: context.agentName,
|
|
69
|
+
sessionId: context.sessionId,
|
|
70
|
+
namespace: context.context?.namespace,
|
|
71
|
+
actor: context.context?.actor
|
|
72
|
+
}, context)).map((record) => ({
|
|
73
|
+
id: record.id,
|
|
74
|
+
content: record.content,
|
|
75
|
+
metadata: {
|
|
76
|
+
...record.metadata ?? {},
|
|
77
|
+
createdAt: record.createdAt,
|
|
78
|
+
...record.agentName === void 0 ? {} : { agentName: record.agentName },
|
|
79
|
+
...record.sessionId === void 0 ? {} : { sessionId: record.sessionId }
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function stringifyKnowledge(value) {
|
|
86
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { InMemoryMemoryStore, createMemoryContextProvider, defineContextProvider, defineSkill };
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
//#region src/internal/json.ts
|
|
2
|
+
const invalidJsonValue = Symbol("invalid-json-value");
|
|
3
|
+
function normalizeJsonValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
4
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
5
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : invalidJsonValue;
|
|
6
|
+
if (Array.isArray(value)) {
|
|
7
|
+
const normalized = [];
|
|
8
|
+
for (const item of value) {
|
|
9
|
+
const normalizedItem = normalizeJsonValue(item, seen);
|
|
10
|
+
if (normalizedItem === invalidJsonValue) return invalidJsonValue;
|
|
11
|
+
normalized.push(normalizedItem);
|
|
12
|
+
}
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
15
|
+
if (typeof value !== "object" || value === void 0) return invalidJsonValue;
|
|
16
|
+
const prototype = Object.getPrototypeOf(value);
|
|
17
|
+
if (prototype !== null && prototype !== Object.prototype) return invalidJsonValue;
|
|
18
|
+
if (seen.has(value)) return invalidJsonValue;
|
|
19
|
+
seen.add(value);
|
|
20
|
+
const normalized = {};
|
|
21
|
+
for (const [key, item] of Object.entries(value)) {
|
|
22
|
+
if (item === void 0) continue;
|
|
23
|
+
const normalizedItem = normalizeJsonValue(item, seen);
|
|
24
|
+
if (normalizedItem === invalidJsonValue) return invalidJsonValue;
|
|
25
|
+
Object.defineProperty(normalized, key, {
|
|
26
|
+
value: normalizedItem,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
seen.delete(value);
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
function toJsonValue(value, errorMessage) {
|
|
36
|
+
let normalized;
|
|
37
|
+
try {
|
|
38
|
+
normalized = normalizeJsonValue(value);
|
|
39
|
+
} catch {
|
|
40
|
+
throw new TypeError(errorMessage);
|
|
41
|
+
}
|
|
42
|
+
if (normalized === invalidJsonValue) throw new TypeError(errorMessage);
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
function serializeJsonValue(value) {
|
|
46
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
47
|
+
}
|
|
48
|
+
function serializeValue(value, errorMessage) {
|
|
49
|
+
return serializeJsonValue(toJsonValue(value, errorMessage));
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/internal/run-support.ts
|
|
53
|
+
function toErrorMessage(error) {
|
|
54
|
+
if (error instanceof Error) return error.message;
|
|
55
|
+
if (typeof error === "string") return error;
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(error) ?? String(error);
|
|
58
|
+
} catch {
|
|
59
|
+
return String(error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function abortable(operation, signal) {
|
|
63
|
+
signal?.throwIfAborted();
|
|
64
|
+
if (!signal) return await operation();
|
|
65
|
+
const result = await new Promise((resolve, reject) => {
|
|
66
|
+
let settled = false;
|
|
67
|
+
const finish = (callback) => {
|
|
68
|
+
if (settled) return;
|
|
69
|
+
settled = true;
|
|
70
|
+
signal.removeEventListener("abort", onAbort);
|
|
71
|
+
callback();
|
|
72
|
+
};
|
|
73
|
+
const onAbort = () => finish(() => reject(signal.reason));
|
|
74
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
75
|
+
if (signal.aborted) {
|
|
76
|
+
onAbort();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
Promise.resolve().then(() => {
|
|
80
|
+
signal.throwIfAborted();
|
|
81
|
+
return operation();
|
|
82
|
+
}).then((value) => finish(() => resolve(value)), (error) => finish(() => reject(error)));
|
|
83
|
+
});
|
|
84
|
+
signal.throwIfAborted();
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
function cancellationReason(signal) {
|
|
88
|
+
return signal.reason instanceof Error && signal.reason.name === "TimeoutError" ? "timeout" : "aborted";
|
|
89
|
+
}
|
|
90
|
+
function addUsage(first, second) {
|
|
91
|
+
if (!first) return second;
|
|
92
|
+
if (!second) return first;
|
|
93
|
+
const inputTokens = first.inputTokens === void 0 && second.inputTokens === void 0 ? void 0 : (first.inputTokens ?? 0) + (second.inputTokens ?? 0);
|
|
94
|
+
const outputTokens = first.outputTokens === void 0 && second.outputTokens === void 0 ? void 0 : (first.outputTokens ?? 0) + (second.outputTokens ?? 0);
|
|
95
|
+
const totalTokens = first.totalTokens === void 0 && second.totalTokens === void 0 ? void 0 : (first.totalTokens ?? 0) + (second.totalTokens ?? 0);
|
|
96
|
+
return {
|
|
97
|
+
...inputTokens !== void 0 ? { inputTokens } : {},
|
|
98
|
+
...outputTokens !== void 0 ? { outputTokens } : {},
|
|
99
|
+
...totalTokens !== void 0 ? { totalTokens } : {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function assertTokenBudget(agentName, limitName, usageName, limit, stepUsage, totalUsage) {
|
|
103
|
+
if (limit === void 0 || limit === false) return;
|
|
104
|
+
const stepTokens = stepUsage?.[usageName];
|
|
105
|
+
if (stepTokens === void 0 || !Number.isFinite(stepTokens) || stepTokens < 0) throw new Error(`Agent "${agentName}" cannot enforce ${limitName}: model usage.${usageName} is missing or invalid`);
|
|
106
|
+
if ((totalUsage?.[usageName] ?? 0) > limit) throw new Error(`Agent "${agentName}" exceeded ${limitName} limit of ${limit}`);
|
|
107
|
+
}
|
|
108
|
+
function assertContinuationBudget(agentName, limitName, usageName, limit, totalUsage) {
|
|
109
|
+
if (limit !== void 0 && limit !== false && (totalUsage?.[usageName] ?? 0) >= limit) throw new Error(`Agent "${agentName}" exhausted ${limitName} limit of ${limit} before completing`);
|
|
110
|
+
}
|
|
111
|
+
function remainingOutputTokens(limit, usage) {
|
|
112
|
+
if (limit === void 0 || limit === false) return void 0;
|
|
113
|
+
return limit - (usage?.outputTokens ?? 0);
|
|
114
|
+
}
|
|
115
|
+
function eventUsage(usage) {
|
|
116
|
+
if (usage === void 0) return void 0;
|
|
117
|
+
const value = toJsonValue(usage, "Model usage must be JSON-serializable");
|
|
118
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("Model usage must be a JSON object");
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/internal/model-stream.ts
|
|
123
|
+
const MAX_DELTA_CHARS = 512;
|
|
124
|
+
const MAX_DELTA_DELAY_MS = 32;
|
|
125
|
+
function isRecord(value) {
|
|
126
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
127
|
+
}
|
|
128
|
+
function canonicalJson(value) {
|
|
129
|
+
if (Array.isArray(value)) return value.map(canonicalJson);
|
|
130
|
+
if (!isRecord(value)) return value;
|
|
131
|
+
const prototype = Object.getPrototypeOf(value);
|
|
132
|
+
if (prototype !== Object.prototype && prototype !== null) return value;
|
|
133
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => [key, canonicalJson(item)]));
|
|
134
|
+
}
|
|
135
|
+
function assertConsistentOutput(result, outputText) {
|
|
136
|
+
if (result.output === void 0) {
|
|
137
|
+
if (outputText) throw new TypeError("Model stream emitted output without a final output");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (typeof result.output === "string") {
|
|
141
|
+
if (result.output !== outputText) throw new TypeError("Model stream deltas do not match the final output");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!outputText) throw new TypeError("Model stream returned JSON output without output deltas");
|
|
145
|
+
let parsed;
|
|
146
|
+
try {
|
|
147
|
+
parsed = JSON.parse(outputText);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
throw new TypeError("Model stream output deltas are not valid JSON", { cause: error });
|
|
150
|
+
}
|
|
151
|
+
if (JSON.stringify(canonicalJson(parsed)) !== JSON.stringify(canonicalJson(result.output))) throw new TypeError("Model stream deltas do not match the final JSON output");
|
|
152
|
+
}
|
|
153
|
+
function assertStreamEvent(value) {
|
|
154
|
+
if (!isRecord(value)) throw new TypeError("ModelGateway stream event must be an object");
|
|
155
|
+
if (value.type === "output.delta") {
|
|
156
|
+
if (typeof value.delta !== "string") throw new TypeError("ModelGateway output.delta must contain a string delta");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (value.type === "completed") {
|
|
160
|
+
if (!isRecord(value.result)) throw new TypeError("ModelGateway completed event must contain a result");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
throw new TypeError("ModelGateway returned an unknown stream event");
|
|
164
|
+
}
|
|
165
|
+
function takeCharacters(value, count) {
|
|
166
|
+
const characters = Array.from(value);
|
|
167
|
+
return [characters.slice(0, count).join(""), characters.slice(count).join("")];
|
|
168
|
+
}
|
|
169
|
+
async function* readModelStream(model, input) {
|
|
170
|
+
input.signal?.throwIfAborted();
|
|
171
|
+
const stream = model.stream(input);
|
|
172
|
+
if (!stream || typeof stream[Symbol.asyncIterator] !== "function") throw new TypeError("ModelGateway.stream must return an AsyncIterable");
|
|
173
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
174
|
+
let pending;
|
|
175
|
+
let completed;
|
|
176
|
+
let outputText = "";
|
|
177
|
+
let buffer = "";
|
|
178
|
+
let firstDelta = true;
|
|
179
|
+
let bufferedAt = 0;
|
|
180
|
+
const next = () => {
|
|
181
|
+
const promise = abortable(() => iterator.next(), input.signal);
|
|
182
|
+
promise.catch(() => {});
|
|
183
|
+
return promise;
|
|
184
|
+
};
|
|
185
|
+
try {
|
|
186
|
+
while (true) {
|
|
187
|
+
if (buffer && Array.from(buffer).length >= MAX_DELTA_CHARS) {
|
|
188
|
+
const [chunk, rest] = takeCharacters(buffer, MAX_DELTA_CHARS);
|
|
189
|
+
buffer = rest;
|
|
190
|
+
bufferedAt = performance.now();
|
|
191
|
+
yield chunk;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
pending ??= next();
|
|
195
|
+
let item;
|
|
196
|
+
if (buffer) {
|
|
197
|
+
const remaining = Math.max(0, MAX_DELTA_DELAY_MS - (performance.now() - bufferedAt));
|
|
198
|
+
const raced = await Promise.race([pending.then((value) => ({
|
|
199
|
+
type: "item",
|
|
200
|
+
value
|
|
201
|
+
})), new Promise((resolve) => {
|
|
202
|
+
setTimeout(() => resolve({ type: "flush" }), remaining);
|
|
203
|
+
})]);
|
|
204
|
+
if (raced.type === "flush") {
|
|
205
|
+
const chunk = buffer;
|
|
206
|
+
buffer = "";
|
|
207
|
+
bufferedAt = 0;
|
|
208
|
+
yield chunk;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
item = raced.value;
|
|
212
|
+
} else item = await pending;
|
|
213
|
+
pending = void 0;
|
|
214
|
+
if (item.done) {
|
|
215
|
+
if (!completed) throw new TypeError("ModelGateway stream ended without completed");
|
|
216
|
+
assertConsistentOutput(completed, outputText);
|
|
217
|
+
return completed;
|
|
218
|
+
}
|
|
219
|
+
assertStreamEvent(item.value);
|
|
220
|
+
if (completed) throw new TypeError("ModelGateway stream emitted an event after completed");
|
|
221
|
+
if (item.value.type === "completed") {
|
|
222
|
+
completed = item.value.result;
|
|
223
|
+
if (buffer) {
|
|
224
|
+
const chunk = buffer;
|
|
225
|
+
buffer = "";
|
|
226
|
+
bufferedAt = 0;
|
|
227
|
+
yield chunk;
|
|
228
|
+
}
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (!item.value.delta) continue;
|
|
232
|
+
outputText += item.value.delta;
|
|
233
|
+
buffer += item.value.delta;
|
|
234
|
+
if (firstDelta) {
|
|
235
|
+
const [chunk, rest] = takeCharacters(buffer, MAX_DELTA_CHARS);
|
|
236
|
+
firstDelta = false;
|
|
237
|
+
buffer = rest;
|
|
238
|
+
bufferedAt = performance.now();
|
|
239
|
+
yield chunk;
|
|
240
|
+
} else if (!bufferedAt) bufferedAt = performance.now();
|
|
241
|
+
}
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (buffer) yield buffer;
|
|
244
|
+
throw error;
|
|
245
|
+
} finally {
|
|
246
|
+
if (pending) pending.catch(() => {});
|
|
247
|
+
if (iterator.return) Promise.resolve(iterator.return()).catch(() => {});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
export { assertTokenBudget as a, remainingOutputTokens as c, serializeValue as d, toJsonValue as f, assertContinuationBudget as i, toErrorMessage as l, abortable as n, cancellationReason as o, addUsage as r, eventUsage as s, readModelStream as t, serializeJsonValue as u };
|
package/dist/models/index.d.mts
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type ReasoningEffort = 'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high';
|
|
4
|
-
interface ModelUsage {
|
|
5
|
-
inputTokens?: number;
|
|
6
|
-
outputTokens?: number;
|
|
7
|
-
totalTokens?: number;
|
|
8
|
-
}
|
|
9
|
-
interface ModelGenerateInput {
|
|
10
|
-
messages: AgentMessage[];
|
|
11
|
-
tools?: ToolSpec[];
|
|
12
|
-
reasoning?: ReasoningEffort;
|
|
13
|
-
modelOptions?: Record<string, unknown>;
|
|
14
|
-
outputSchema?: JsonObject;
|
|
15
|
-
signal?: AbortSignal;
|
|
16
|
-
}
|
|
17
|
-
interface ModelGenerateResult<TOutput = unknown> {
|
|
18
|
-
output?: TOutput;
|
|
19
|
-
toolCalls?: ToolCall[];
|
|
20
|
-
usage?: ModelUsage;
|
|
21
|
-
}
|
|
22
|
-
interface ModelGateway {
|
|
23
|
-
generate(input: ModelGenerateInput): Promise<ModelGenerateResult>;
|
|
24
|
-
}
|
|
25
|
-
type ModelRef = string | ModelGateway;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { ModelGateway, ModelGenerateInput, ModelGenerateResult, ModelRef, ModelUsage, ReasoningEffort };
|
|
1
|
+
import { a as ModelResult, c as ReasoningEffort, i as ModelRef, l as ToolChoice, n as ModelInput, o as ModelStreamEvent, r as ModelMetadata, s as ModelUsage, t as ModelGateway } from "../index-CTIwrVf9.mjs";
|
|
2
|
+
export { ModelGateway, ModelInput, ModelMetadata, ModelRef, ModelResult, ModelStreamEvent, ModelUsage, ReasoningEffort, ToolChoice };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as TraceAnnotation, c as TraceContentPolicy, d as TraceRedactor, f as TraceRedactorInput, h as TraceStatus, i as RunTrace, l as TraceCost, m as TraceSpanKind, n as CostCalculatorInput, o as TraceContent, p as TraceSpan, r as ObservabilityOptions, s as TraceContentKind, t as CostCalculator, u as TraceExporter } from "../index-B4PIkqOU.mjs";
|
|
2
|
+
export { CostCalculator, CostCalculatorInput, ObservabilityOptions, RunTrace, TraceAnnotation, TraceContent, TraceContentKind, TraceContentPolicy, TraceCost, TraceExporter, TraceRedactor, TraceRedactorInput, TraceSpan, TraceSpanKind, TraceStatus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/run-error.ts
|
|
2
|
+
var FevexRunError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
runId;
|
|
5
|
+
name = "FevexRunError";
|
|
6
|
+
constructor(code, message, runId, options) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.runId = runId;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var RunPausedError = class extends FevexRunError {
|
|
13
|
+
runId;
|
|
14
|
+
pause;
|
|
15
|
+
name = "RunPausedError";
|
|
16
|
+
constructor(runId, pause) {
|
|
17
|
+
super("RUN_PAUSED", `Run "${runId}" is paused`, runId);
|
|
18
|
+
this.runId = runId;
|
|
19
|
+
this.pause = pause;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { RunPausedError as n, FevexRunError as t };
|
package/dist/runtime/index.d.mts
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
-
//#region src/runtime/index.d.ts
|
|
5
|
-
interface RunRequest<TInput = unknown, TOutput = unknown> {
|
|
6
|
-
input: TInput;
|
|
7
|
-
context?: ExecutionContext;
|
|
8
|
-
outputSchema?: StandardSchemaV1<unknown, TOutput>;
|
|
9
|
-
signal?: AbortSignal;
|
|
10
|
-
}
|
|
11
|
-
interface RunResult<TOutput = unknown> {
|
|
12
|
-
output: TOutput;
|
|
13
|
-
events?: AgentEvent[];
|
|
14
|
-
usage?: ModelUsage;
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
export { RunRequest, RunResult };
|
|
1
|
+
import { A as RunStore, B as WorkflowBudgetUsage, C as RunCheckpoint, D as RunRequest, E as RunRecord, F as TeamRun, G as WorkflowWaitRecord, H as WorkflowCompensationRecord, I as TimerResolution, K as isDurableRunStore, L as ToolExecutionRecord, M as SessionId, N as StoredRunCheckpoint, O as RunResult, P as TeamCheckpoint, R as ToolExecutionResolution, S as ResumeRunResolution, T as RunPause, U as WorkflowRun, V as WorkflowCheckpoint, W as WorkflowStepRecord, _ as EventResolution, a as AgentRun, b as ListEventsOptions, c as ApprovalRequest, d as CoordinatorRun, f as CredentialStore, g as ElicitationResolution, h as ElicitationRequest, i as InMemoryRunStore, j as Session, k as RunStatus, l as ApprovalResolution, m as ElicitationMode, o as AgentRunPause, p as DurableRunStore, q as validateListEventsOptions, s as ApprovalMode, u as CoordinatorCheckpoint, v as ExecutionCommit, w as RunLease, x as PendingToolExecution, y as ExecutionCreate, z as ToolExecutionStatus } from "../index-Dx_LotWZ.mjs";
|
|
2
|
+
export { AgentRun, AgentRunPause, ApprovalMode, ApprovalRequest, ApprovalResolution, CoordinatorCheckpoint, CoordinatorRun, CredentialStore, DurableRunStore, ElicitationMode, ElicitationRequest, ElicitationResolution, EventResolution, ExecutionCommit, ExecutionCreate, InMemoryRunStore, ListEventsOptions, PendingToolExecution, ResumeRunResolution, RunCheckpoint, RunLease, RunPause, RunRecord, RunRequest, RunResult, RunStatus, RunStore, Session, SessionId, StoredRunCheckpoint, TeamCheckpoint, TeamRun, TimerResolution, ToolExecutionRecord, ToolExecutionResolution, ToolExecutionStatus, WorkflowBudgetUsage, WorkflowCheckpoint, WorkflowCompensationRecord, WorkflowRun, WorkflowStepRecord, WorkflowWaitRecord, isDurableRunStore, validateListEventsOptions };
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -1 +1,141 @@
|
|
|
1
|
-
|
|
1
|
+
import { t as FevexRunError } from "../run-error-Cr17wPGH.mjs";
|
|
2
|
+
//#region src/runtime/run-store.ts
|
|
3
|
+
function validateListEventsOptions(options) {
|
|
4
|
+
if (options.limit !== void 0 && (!Number.isSafeInteger(options.limit) || options.limit < 1)) throw new TypeError("Event limit must be a positive safe integer");
|
|
5
|
+
if (options.order !== void 0 && options.order !== "asc" && options.order !== "desc") throw new TypeError("Event order must be asc or desc");
|
|
6
|
+
}
|
|
7
|
+
function isDurableRunStore(store) {
|
|
8
|
+
const value = store;
|
|
9
|
+
return [
|
|
10
|
+
value.getCheckpoint,
|
|
11
|
+
value.getToolExecution,
|
|
12
|
+
value.createExecution,
|
|
13
|
+
value.commitExecution,
|
|
14
|
+
value.acquireLease,
|
|
15
|
+
value.renewLease,
|
|
16
|
+
value.releaseLease
|
|
17
|
+
].every((method) => typeof method === "function");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/runtime/in-memory-run-store.ts
|
|
21
|
+
/**
|
|
22
|
+
* In-process durable store intended for development and tests.
|
|
23
|
+
*
|
|
24
|
+
* Values are cloned at the boundary so callers cannot mutate persisted state.
|
|
25
|
+
* Data is lost when the process exits.
|
|
26
|
+
*/
|
|
27
|
+
var InMemoryRunStore = class {
|
|
28
|
+
#runs = /* @__PURE__ */ new Map();
|
|
29
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
30
|
+
#events = /* @__PURE__ */ new Map();
|
|
31
|
+
#checkpoints = /* @__PURE__ */ new Map();
|
|
32
|
+
#toolExecutions = /* @__PURE__ */ new Map();
|
|
33
|
+
#leases = /* @__PURE__ */ new Map();
|
|
34
|
+
async getRun(runId) {
|
|
35
|
+
const run = this.#runs.get(runId);
|
|
36
|
+
return run === void 0 ? void 0 : structuredClone(run);
|
|
37
|
+
}
|
|
38
|
+
async saveRun(run) {
|
|
39
|
+
this.#runs.set(run.id, structuredClone(run));
|
|
40
|
+
if (!this.#events.has(run.id)) this.#events.set(run.id, []);
|
|
41
|
+
}
|
|
42
|
+
async getSession(sessionId) {
|
|
43
|
+
const session = this.#sessions.get(sessionId);
|
|
44
|
+
return session === void 0 ? void 0 : structuredClone(session);
|
|
45
|
+
}
|
|
46
|
+
async saveSession(session) {
|
|
47
|
+
const current = this.#sessions.get(session.id);
|
|
48
|
+
if (this.#sessionBusy(session.id) || (current?.revision ?? 0) !== (session.revision ?? 0)) throw new FevexRunError("RUN_CONFLICT", `Session "${session.id}" is active or was modified`);
|
|
49
|
+
session.revision = (session.revision ?? 0) + 1;
|
|
50
|
+
this.#sessions.set(session.id, structuredClone(session));
|
|
51
|
+
}
|
|
52
|
+
async appendEvent(event) {
|
|
53
|
+
const events = this.#events.get(event.runId);
|
|
54
|
+
if (!events) throw new Error(`Run "${event.runId}" does not exist`);
|
|
55
|
+
events.push(structuredClone(event));
|
|
56
|
+
}
|
|
57
|
+
async listEvents(runId, options = {}) {
|
|
58
|
+
validateListEventsOptions(options);
|
|
59
|
+
const events = this.#events.get(runId);
|
|
60
|
+
if (!events) throw new Error(`Run "${runId}" does not exist`);
|
|
61
|
+
let start = 0;
|
|
62
|
+
if (options.after !== void 0) {
|
|
63
|
+
const cursor = events.findIndex(({ id }) => id === options.after);
|
|
64
|
+
if (cursor < 0) throw new FevexRunError("INVALID_CURSOR", `Event cursor "${options.after}" does not exist in run "${runId}"`, runId);
|
|
65
|
+
start = cursor + 1;
|
|
66
|
+
}
|
|
67
|
+
const sequence = start ? events[start - 1].sequence : -1;
|
|
68
|
+
const ordered = events.filter((event) => event.sequence > sequence).sort((a, b) => options.order === "desc" ? b.sequence - a.sequence : a.sequence - b.sequence);
|
|
69
|
+
return structuredClone(ordered.slice(0, options.limit));
|
|
70
|
+
}
|
|
71
|
+
async getCheckpoint(runId) {
|
|
72
|
+
const checkpoint = this.#checkpoints.get(runId);
|
|
73
|
+
return checkpoint === void 0 ? void 0 : structuredClone(checkpoint);
|
|
74
|
+
}
|
|
75
|
+
async getToolExecution(runId, toolCallId) {
|
|
76
|
+
const execution = this.#toolExecutions.get(`${runId}:${toolCallId}`);
|
|
77
|
+
return execution === void 0 ? void 0 : structuredClone(execution);
|
|
78
|
+
}
|
|
79
|
+
async createExecution(create) {
|
|
80
|
+
if (this.#runs.has(create.run.id)) return false;
|
|
81
|
+
const session = create.session;
|
|
82
|
+
const currentSession = this.#sessions.get(create.run.sessionId);
|
|
83
|
+
if (!session || session.id !== create.run.sessionId || this.#sessionBusy(session.id) || (currentSession?.revision ?? 0) !== (session.revision ?? 0)) return false;
|
|
84
|
+
const run = structuredClone(create.run);
|
|
85
|
+
run.revision = 1;
|
|
86
|
+
this.#runs.set(run.id, run);
|
|
87
|
+
create.run.revision = 1;
|
|
88
|
+
session.revision = (session.revision ?? 0) + 1;
|
|
89
|
+
this.#sessions.set(session.id, structuredClone(session));
|
|
90
|
+
this.#events.set(run.id, structuredClone(create.events));
|
|
91
|
+
this.#checkpoints.set(run.id, structuredClone(create.checkpoint));
|
|
92
|
+
create.lease.generation = 1;
|
|
93
|
+
this.#leases.set(run.id, structuredClone(create.lease));
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
async commitExecution(commit) {
|
|
97
|
+
const current = this.#runs.get(commit.run.id);
|
|
98
|
+
if (!current || current.revision !== commit.expectedRevision) return false;
|
|
99
|
+
const lease = this.#leases.get(commit.run.id);
|
|
100
|
+
if (!lease || !commit.lease || !(commit.lease.generation > 0) || lease.ownerId !== commit.lease.ownerId || lease.generation !== commit.lease.generation || !(Date.parse(lease.expiresAt) > Date.now())) return false;
|
|
101
|
+
if (commit.session && (commit.session.id !== current.sessionId || (this.#sessions.get(current.sessionId)?.revision ?? 0) !== (commit.session.revision ?? 0) || this.#sessionBusy(current.sessionId, current.id))) return false;
|
|
102
|
+
const run = structuredClone(commit.run);
|
|
103
|
+
run.revision = commit.expectedRevision + 1;
|
|
104
|
+
this.#runs.set(run.id, run);
|
|
105
|
+
commit.run.revision = run.revision;
|
|
106
|
+
if (commit.session) {
|
|
107
|
+
commit.session.revision = (commit.session.revision ?? 0) + 1;
|
|
108
|
+
this.#sessions.set(commit.session.id, structuredClone(commit.session));
|
|
109
|
+
}
|
|
110
|
+
if (commit.checkpoint === null) this.#checkpoints.delete(run.id);
|
|
111
|
+
else if (commit.checkpoint) this.#checkpoints.set(run.id, structuredClone(commit.checkpoint));
|
|
112
|
+
if (commit.toolExecution) this.#toolExecutions.set(`${run.id}:${commit.toolExecution.toolCallId}`, structuredClone(commit.toolExecution));
|
|
113
|
+
const events = this.#events.get(run.id);
|
|
114
|
+
if (!events) throw new Error(`Run "${run.id}" does not exist`);
|
|
115
|
+
for (const event of commit.events ?? []) events.push(structuredClone(event));
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
#sessionBusy(sessionId, exceptRunId) {
|
|
119
|
+
return [...this.#runs.values()].some((run) => run.sessionId === sessionId && run.id !== exceptRunId && (run.status === "running" || run.status === "paused"));
|
|
120
|
+
}
|
|
121
|
+
async acquireLease(lease) {
|
|
122
|
+
const current = this.#leases.get(lease.runId);
|
|
123
|
+
if (current && Date.parse(current.expiresAt) > Date.now()) return false;
|
|
124
|
+
lease.generation = (current?.generation ?? 0) + 1;
|
|
125
|
+
this.#leases.set(lease.runId, structuredClone(lease));
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
async renewLease(lease) {
|
|
129
|
+
const current = this.#leases.get(lease.runId);
|
|
130
|
+
if (!current || current.ownerId !== lease.ownerId || current.generation !== lease.generation || !(Date.parse(current.expiresAt) > Date.now())) return false;
|
|
131
|
+
this.#leases.set(lease.runId, structuredClone(lease));
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
async releaseLease(runId, ownerId, generation) {
|
|
135
|
+
if (!(generation > 0)) return;
|
|
136
|
+
const current = this.#leases.get(runId);
|
|
137
|
+
if (current?.ownerId === ownerId && current.generation === generation) current.expiresAt = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
//#endregion
|
|
141
|
+
export { InMemoryRunStore, isDurableRunStore, validateListEventsOptions };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SandboxError, c as sandboxResultToJson, i as SandboxCapabilities, n as createLocalSandbox, o as SandboxRunRequest, r as Sandbox, s as SandboxRunResult, t as LocalSandboxOptions } from "../index-CrOId2px.mjs";
|
|
2
|
+
export { LocalSandboxOptions, Sandbox, SandboxCapabilities, SandboxError, SandboxRunRequest, SandboxRunResult, createLocalSandbox, sandboxResultToJson };
|