@infinityi/engine-lib 1.0.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/LICENSE +21 -0
- package/README.md +488 -0
- package/dist/agent/agent-registry.d.ts +46 -0
- package/dist/agent/as-tool.d.ts +64 -0
- package/dist/agent/define.d.ts +35 -0
- package/dist/agent/handoff.d.ts +39 -0
- package/dist/agent/index.d.ts +20 -0
- package/dist/agent/index.js +38 -0
- package/dist/agent/registry.d.ts +27 -0
- package/dist/agent/types.d.ts +109 -0
- package/dist/context/index.d.ts +11 -0
- package/dist/context/index.js +21 -0
- package/dist/context/providers.d.ts +25 -0
- package/dist/context/types.d.ts +63 -0
- package/dist/context/window.d.ts +41 -0
- package/dist/errors.d.ts +93 -0
- package/dist/errors.js +24 -0
- package/dist/events/hub.d.ts +15 -0
- package/dist/events/index.d.ts +26 -0
- package/dist/events/index.js +24 -0
- package/dist/events/subscribers.d.ts +57 -0
- package/dist/events/telemetry.d.ts +61 -0
- package/dist/events/types.d.ts +39 -0
- package/dist/execution/index.d.ts +11 -0
- package/dist/execution/index.js +22 -0
- package/dist/execution/run.d.ts +35 -0
- package/dist/execution/types.d.ts +203 -0
- package/dist/execution/usage.d.ts +14 -0
- package/dist/index-02s1fjxr.js +226 -0
- package/dist/index-19pwq79t.js +0 -0
- package/dist/index-1p6mb2vz.js +32 -0
- package/dist/index-64tt9696.js +1796 -0
- package/dist/index-7690reng.js +96 -0
- package/dist/index-bqg01r42.js +354 -0
- package/dist/index-d4xz3abn.js +0 -0
- package/dist/index-dexgmwg6.js +148 -0
- package/dist/index-fkr3rcq9.js +97 -0
- package/dist/index-jg19te9v.js +0 -0
- package/dist/index-jp2b31xs.js +101 -0
- package/dist/index-jxgj4z08.js +68 -0
- package/dist/index-kte2h4k2.js +0 -0
- package/dist/index-pwr8179t.js +492 -0
- package/dist/index-rentvdpp.js +27 -0
- package/dist/index-vnby35rm.js +84 -0
- package/dist/index-w34cbktd.js +14 -0
- package/dist/index-xsv43c5j.js +39 -0
- package/dist/index-yrqrxwjt.js +148 -0
- package/dist/index-zfgr4xx3.js +90 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +117 -0
- package/dist/lifecycle/component.d.ts +74 -0
- package/dist/lifecycle/index.d.ts +12 -0
- package/dist/lifecycle/index.js +72 -0
- package/dist/messages/factory.d.ts +24 -0
- package/dist/messages/index.d.ts +8 -0
- package/dist/messages/index.js +17 -0
- package/dist/messages/types.d.ts +52 -0
- package/dist/providers/adapter.d.ts +42 -0
- package/dist/providers/anthropic/index.d.ts +31 -0
- package/dist/providers/anthropic/map.d.ts +12 -0
- package/dist/providers/anthropic/stream.d.ts +9 -0
- package/dist/providers/google/index.d.ts +29 -0
- package/dist/providers/google/map.d.ts +13 -0
- package/dist/providers/google/stream.d.ts +11 -0
- package/dist/providers/http.d.ts +61 -0
- package/dist/providers/index.d.ts +32 -0
- package/dist/providers/index.js +35 -0
- package/dist/providers/openai/index.d.ts +34 -0
- package/dist/providers/openai/map.d.ts +10 -0
- package/dist/providers/openai/stream.d.ts +9 -0
- package/dist/providers/openai-compatible/index.d.ts +37 -0
- package/dist/providers/openai-compatible/map.d.ts +13 -0
- package/dist/providers/openai-compatible/stream.d.ts +11 -0
- package/dist/providers/shared.d.ts +34 -0
- package/dist/providers/sse.d.ts +19 -0
- package/dist/providers/stream.d.ts +69 -0
- package/dist/providers/types.d.ts +137 -0
- package/dist/runtime/index.d.ts +11 -0
- package/dist/runtime/index.js +11 -0
- package/dist/runtime/secret.d.ts +12 -0
- package/dist/runtime/types.d.ts +27 -0
- package/dist/schema/builder.d.ts +70 -0
- package/dist/schema/index.d.ts +13 -0
- package/dist/schema/index.js +15 -0
- package/dist/schema/json-schema.d.ts +19 -0
- package/dist/schema/types.d.ts +70 -0
- package/dist/schema/validate.d.ts +19 -0
- package/dist/session/index.d.ts +11 -0
- package/dist/session/index.js +8 -0
- package/dist/session/session.d.ts +31 -0
- package/dist/session/store.d.ts +20 -0
- package/dist/session/types.d.ts +55 -0
- package/dist/testing/conformance.d.ts +106 -0
- package/dist/testing/conformance.js +132 -0
- package/dist/testing/index.d.ts +84 -0
- package/dist/testing/index.js +31 -0
- package/dist/tools/define.d.ts +42 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/result.d.ts +36 -0
- package/dist/tools/types.d.ts +85 -0
- package/docs/README.md +36 -0
- package/examples/README.md +24 -0
- package/examples/incident-analysis.ts +100 -0
- package/examples/lifecycle.ts +53 -0
- package/examples/multi-agent.ts +93 -0
- package/examples/terminal-coder.ts +80 -0
- package/package.json +114 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/session/store.ts
|
|
2
|
+
class InMemorySessionStore {
|
|
3
|
+
entries = new Map;
|
|
4
|
+
load(id) {
|
|
5
|
+
const entry = this.entries.get(id);
|
|
6
|
+
if (entry === undefined)
|
|
7
|
+
return Promise.resolve(undefined);
|
|
8
|
+
const state = {
|
|
9
|
+
id,
|
|
10
|
+
messages: [...entry.messages],
|
|
11
|
+
...entry.metadata !== undefined ? { metadata: { ...entry.metadata } } : {}
|
|
12
|
+
};
|
|
13
|
+
return Promise.resolve(state);
|
|
14
|
+
}
|
|
15
|
+
append(id, messages) {
|
|
16
|
+
const entry = this.entries.get(id);
|
|
17
|
+
if (entry === undefined) {
|
|
18
|
+
this.entries.set(id, { messages: [...messages] });
|
|
19
|
+
} else {
|
|
20
|
+
entry.messages.push(...messages);
|
|
21
|
+
}
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
save(state) {
|
|
25
|
+
this.entries.set(state.id, {
|
|
26
|
+
messages: [...state.messages],
|
|
27
|
+
...state.metadata !== undefined ? { metadata: { ...state.metadata } } : {}
|
|
28
|
+
});
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
}
|
|
31
|
+
delete(id) {
|
|
32
|
+
this.entries.delete(id);
|
|
33
|
+
return Promise.resolve();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/session/session.ts
|
|
38
|
+
function generateId() {
|
|
39
|
+
return `session_${crypto.randomUUID()}`;
|
|
40
|
+
}
|
|
41
|
+
function createSession(opts = {}) {
|
|
42
|
+
const id = opts.id ?? generateId();
|
|
43
|
+
const store = opts.store ?? new InMemorySessionStore;
|
|
44
|
+
const seed = opts.messages;
|
|
45
|
+
const metadata = opts.metadata;
|
|
46
|
+
let seedPromise;
|
|
47
|
+
const ensureSeeded = () => {
|
|
48
|
+
if (seedPromise !== undefined)
|
|
49
|
+
return seedPromise;
|
|
50
|
+
seedPromise = (async () => {
|
|
51
|
+
if (seed === undefined || seed.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
const existing = await store.load(id);
|
|
54
|
+
if (existing === undefined || existing.messages.length === 0) {
|
|
55
|
+
await store.append(id, seed);
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
return seedPromise;
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
id,
|
|
62
|
+
...metadata !== undefined ? { metadata } : {},
|
|
63
|
+
async messages() {
|
|
64
|
+
await ensureSeeded();
|
|
65
|
+
const state = await store.load(id);
|
|
66
|
+
return state === undefined ? [] : [...state.messages];
|
|
67
|
+
},
|
|
68
|
+
async append(messages) {
|
|
69
|
+
await ensureSeeded();
|
|
70
|
+
if (messages.length === 0)
|
|
71
|
+
return;
|
|
72
|
+
await store.append(id, messages);
|
|
73
|
+
},
|
|
74
|
+
async clear() {
|
|
75
|
+
const inflight = seedPromise;
|
|
76
|
+
seedPromise = Promise.resolve();
|
|
77
|
+
if (inflight !== undefined) {
|
|
78
|
+
await inflight.catch(() => {});
|
|
79
|
+
}
|
|
80
|
+
await store.delete(id);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export { InMemorySessionStore, createSession };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/tools/define.ts
|
|
2
|
+
function defineTool(spec) {
|
|
3
|
+
if (typeof spec.name !== "string" || spec.name.trim() === "") {
|
|
4
|
+
throw new TypeError("defineTool: `name` must be a non-empty string");
|
|
5
|
+
}
|
|
6
|
+
const tool = {
|
|
7
|
+
name: spec.name,
|
|
8
|
+
...spec.description !== undefined ? { description: spec.description } : {},
|
|
9
|
+
parameters: spec.parameters,
|
|
10
|
+
execute: spec.execute
|
|
11
|
+
};
|
|
12
|
+
return Object.freeze(tool);
|
|
13
|
+
}
|
|
14
|
+
export { defineTool };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// node_modules/@infinityi/forge/dist/index-63ccs1gh.js
|
|
2
|
+
var REDACTED = "[REDACTED]";
|
|
3
|
+
var INSPECT_CUSTOM = Symbol.for("nodejs.util.inspect.custom");
|
|
4
|
+
|
|
5
|
+
class Secret {
|
|
6
|
+
#value;
|
|
7
|
+
constructor(value) {
|
|
8
|
+
this.#value = value;
|
|
9
|
+
}
|
|
10
|
+
unwrap() {
|
|
11
|
+
return this.#value;
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
return REDACTED;
|
|
15
|
+
}
|
|
16
|
+
toJSON() {
|
|
17
|
+
return REDACTED;
|
|
18
|
+
}
|
|
19
|
+
[INSPECT_CUSTOM]() {
|
|
20
|
+
return `Secret <${REDACTED}>`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function isSecret(value) {
|
|
24
|
+
return value instanceof Secret;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// node_modules/@infinityi/forge/dist/index-y8kftjjy.js
|
|
28
|
+
var LEAF_BRAND = Symbol.for("forge/config/leaf");
|
|
29
|
+
|
|
30
|
+
// node_modules/@infinityi/forge/dist/index-yxhr4ame.js
|
|
31
|
+
var TRUE_TOKENS = new Set(["true", "1", "yes"]);
|
|
32
|
+
var FALSE_TOKENS = new Set(["false", "0", "no"]);
|
|
33
|
+
|
|
34
|
+
// src/runtime/secret.ts
|
|
35
|
+
function resolveSecret(value) {
|
|
36
|
+
return isSecret(value) ? value.unwrap() : value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { Secret, isSecret, resolveSecret };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContextWindowError
|
|
3
|
+
} from "./index-7690reng.js";
|
|
4
|
+
import {
|
|
5
|
+
system
|
|
6
|
+
} from "./index-1p6mb2vz.js";
|
|
7
|
+
|
|
8
|
+
// src/context/providers.ts
|
|
9
|
+
function renderItem(item) {
|
|
10
|
+
const body = typeof item.content === "string" ? item.content : JSON.stringify(item.content, null, 2) ?? "";
|
|
11
|
+
return item.title !== undefined && item.title !== "" ? `## ${item.title}
|
|
12
|
+
${body}` : body;
|
|
13
|
+
}
|
|
14
|
+
function staticContext(content, title) {
|
|
15
|
+
const item = { content, ...title !== undefined ? { title } : {} };
|
|
16
|
+
return {
|
|
17
|
+
name: "static",
|
|
18
|
+
resolve: () => [item]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function dynamicContext(name, fn, title) {
|
|
22
|
+
return {
|
|
23
|
+
name,
|
|
24
|
+
resolve: async (ctx) => {
|
|
25
|
+
const content = await fn(ctx);
|
|
26
|
+
return [{ content, ...title !== undefined ? { title } : {} }];
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async function resolveContext(providers, ctx) {
|
|
31
|
+
if (providers === undefined || providers.length === 0)
|
|
32
|
+
return [];
|
|
33
|
+
const resolved = await Promise.all(providers.map((p) => p.resolve(ctx)));
|
|
34
|
+
const blocks = resolved.flat().map(renderItem).filter((s) => s !== "");
|
|
35
|
+
if (blocks.length === 0)
|
|
36
|
+
return [];
|
|
37
|
+
return [system(blocks.join(`
|
|
38
|
+
|
|
39
|
+
`))];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/context/window.ts
|
|
43
|
+
function partChars(part) {
|
|
44
|
+
switch (part.type) {
|
|
45
|
+
case "text":
|
|
46
|
+
return part.text.length;
|
|
47
|
+
case "tool_result":
|
|
48
|
+
return part.content.reduce((n, t) => n + t.text.length, 0);
|
|
49
|
+
case "tool_call":
|
|
50
|
+
return part.name.length + JSON.stringify(part.arguments ?? null).length;
|
|
51
|
+
case "image":
|
|
52
|
+
return part.data.length;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function estimateTokens(messages) {
|
|
56
|
+
let chars = 0;
|
|
57
|
+
for (const message of messages) {
|
|
58
|
+
for (const part of message.content)
|
|
59
|
+
chars += partChars(part);
|
|
60
|
+
}
|
|
61
|
+
return Math.ceil(chars / 4);
|
|
62
|
+
}
|
|
63
|
+
function transcript(messages) {
|
|
64
|
+
return messages.map((m) => {
|
|
65
|
+
const body = m.content.map((p) => {
|
|
66
|
+
if (p.type === "text")
|
|
67
|
+
return p.text;
|
|
68
|
+
if (p.type === "tool_result")
|
|
69
|
+
return p.content.map((t) => t.text).join(" ");
|
|
70
|
+
if (p.type === "tool_call")
|
|
71
|
+
return `[tool_call ${p.name} ${JSON.stringify(p.arguments)}]`;
|
|
72
|
+
return "";
|
|
73
|
+
}).filter((s) => s !== "").join(" ");
|
|
74
|
+
return `${m.role}: ${body}`;
|
|
75
|
+
}).join(`
|
|
76
|
+
`);
|
|
77
|
+
}
|
|
78
|
+
function truncateOldest() {
|
|
79
|
+
return {
|
|
80
|
+
name: "truncate-oldest",
|
|
81
|
+
reduce(messages, ctx) {
|
|
82
|
+
const systemMsgs = messages.filter((m) => m.role === "system");
|
|
83
|
+
const rest = messages.filter((m) => m.role !== "system");
|
|
84
|
+
const kept = [...rest];
|
|
85
|
+
while (kept.length > 0 && ctx.countTokens([...systemMsgs, ...kept]) > ctx.maxTokens) {
|
|
86
|
+
kept.shift();
|
|
87
|
+
}
|
|
88
|
+
const result = [...systemMsgs, ...kept];
|
|
89
|
+
const tokens = ctx.countTokens(result);
|
|
90
|
+
if (tokens > ctx.maxTokens) {
|
|
91
|
+
throw new ContextWindowError(`context window exceeded: ${tokens} tokens > limit ${ctx.maxTokens} (irreducible)`, { tokens, limit: ctx.maxTokens });
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function summarizeOldest(opts = {}) {
|
|
98
|
+
const keepRecent = opts.keepRecent ?? 4;
|
|
99
|
+
return {
|
|
100
|
+
name: "summarize-oldest",
|
|
101
|
+
async reduce(messages, ctx) {
|
|
102
|
+
const systemMsgs = messages.filter((m) => m.role === "system");
|
|
103
|
+
const rest = messages.filter((m) => m.role !== "system");
|
|
104
|
+
const splitAt = Math.max(0, rest.length - keepRecent);
|
|
105
|
+
const older = rest.slice(0, splitAt);
|
|
106
|
+
const recent = rest.slice(splitAt);
|
|
107
|
+
let result;
|
|
108
|
+
if (older.length === 0) {
|
|
109
|
+
result = [...systemMsgs, ...recent];
|
|
110
|
+
} else {
|
|
111
|
+
const req = {
|
|
112
|
+
model: ctx.model,
|
|
113
|
+
messages: [
|
|
114
|
+
system("Summarize the following conversation transcript concisely, preserving " + "facts, decisions, and open questions. Output only the summary."),
|
|
115
|
+
{ role: "user", content: [{ type: "text", text: transcript(older) }] }
|
|
116
|
+
]
|
|
117
|
+
};
|
|
118
|
+
const completion = await ctx.provider.complete(req, ctx.engine);
|
|
119
|
+
const summaryText = completion.message.content.filter((p) => p.type === "text").map((p) => p.text).join("");
|
|
120
|
+
const summary = system(`Summary of earlier conversation:
|
|
121
|
+
${summaryText}`);
|
|
122
|
+
result = [...systemMsgs, summary, ...recent];
|
|
123
|
+
}
|
|
124
|
+
const tokens = ctx.countTokens(result);
|
|
125
|
+
if (tokens > ctx.maxTokens) {
|
|
126
|
+
throw new ContextWindowError(`context window exceeded: ${tokens} tokens > limit ${ctx.maxTokens} (irreducible)`, { tokens, limit: ctx.maxTokens });
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function applyContextWindow(messages, window, ctx) {
|
|
133
|
+
if (window === undefined)
|
|
134
|
+
return messages;
|
|
135
|
+
const countTokens = window.countTokens ?? estimateTokens;
|
|
136
|
+
if (countTokens(messages) <= window.maxTokens)
|
|
137
|
+
return messages;
|
|
138
|
+
const strategy = window.strategy ?? truncateOldest();
|
|
139
|
+
return strategy.reduce([...messages], {
|
|
140
|
+
maxTokens: window.maxTokens,
|
|
141
|
+
countTokens,
|
|
142
|
+
provider: ctx.provider,
|
|
143
|
+
model: ctx.model,
|
|
144
|
+
engine: ctx.engine
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { staticContext, dynamicContext, resolveContext, estimateTokens, truncateOldest, summarizeOldest, applyContextWindow };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/providers/stream.ts
|
|
2
|
+
function parseArguments(text) {
|
|
3
|
+
if (text.trim() === "")
|
|
4
|
+
return;
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(text);
|
|
7
|
+
} catch {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class StreamAccumulator {
|
|
13
|
+
model;
|
|
14
|
+
text = "";
|
|
15
|
+
finishReason = "stop";
|
|
16
|
+
usage;
|
|
17
|
+
toolCalls = new Map;
|
|
18
|
+
push(event) {
|
|
19
|
+
switch (event.type) {
|
|
20
|
+
case "message_start":
|
|
21
|
+
this.model = event.model;
|
|
22
|
+
break;
|
|
23
|
+
case "text_delta":
|
|
24
|
+
this.text += event.text;
|
|
25
|
+
break;
|
|
26
|
+
case "tool_call_start":
|
|
27
|
+
this.toolCalls.set(event.index, {
|
|
28
|
+
id: event.id,
|
|
29
|
+
name: event.name,
|
|
30
|
+
argumentsText: ""
|
|
31
|
+
});
|
|
32
|
+
break;
|
|
33
|
+
case "tool_call_delta": {
|
|
34
|
+
const call = this.toolCalls.get(event.index);
|
|
35
|
+
if (call)
|
|
36
|
+
call.argumentsText += event.argumentsTextDelta;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "tool_call_end":
|
|
40
|
+
break;
|
|
41
|
+
case "finish":
|
|
42
|
+
this.finishReason = event.finishReason;
|
|
43
|
+
if (event.usage !== undefined)
|
|
44
|
+
this.usage = event.usage;
|
|
45
|
+
break;
|
|
46
|
+
case "error":
|
|
47
|
+
this.finishReason = "error";
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
result(model, raw) {
|
|
52
|
+
const resolvedModel = this.model ?? model;
|
|
53
|
+
const ordered = [...this.toolCalls.entries()].sort(([a], [b]) => a - b).map(([, c]) => c);
|
|
54
|
+
const content = [];
|
|
55
|
+
if (this.text !== "")
|
|
56
|
+
content.push({ type: "text", text: this.text });
|
|
57
|
+
for (const call of ordered) {
|
|
58
|
+
const part = {
|
|
59
|
+
type: "tool_call",
|
|
60
|
+
id: call.id,
|
|
61
|
+
name: call.name,
|
|
62
|
+
arguments: parseArguments(call.argumentsText)
|
|
63
|
+
};
|
|
64
|
+
content.push(part);
|
|
65
|
+
}
|
|
66
|
+
const message = { role: "assistant", content };
|
|
67
|
+
const toolCalls = ordered.map((call) => ({
|
|
68
|
+
id: call.id,
|
|
69
|
+
name: call.name,
|
|
70
|
+
arguments: parseArguments(call.argumentsText),
|
|
71
|
+
argumentsText: call.argumentsText
|
|
72
|
+
}));
|
|
73
|
+
return {
|
|
74
|
+
message,
|
|
75
|
+
toolCalls,
|
|
76
|
+
finishReason: this.toolCalls.size > 0 && this.finishReason === "stop" ? "tool_calls" : this.finishReason,
|
|
77
|
+
...this.usage !== undefined ? { usage: this.usage } : {},
|
|
78
|
+
model: resolvedModel,
|
|
79
|
+
raw
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function collectStream(events, model, raw) {
|
|
84
|
+
const accumulator = new StreamAccumulator;
|
|
85
|
+
for await (const event of events)
|
|
86
|
+
accumulator.push(event);
|
|
87
|
+
return accumulator.result(model, raw);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { StreamAccumulator, collectStream };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@infinityi/engine-lib` — agent infrastructure for TypeScript, built on
|
|
3
|
+
* `@infinityi/forge`.
|
|
4
|
+
*
|
|
5
|
+
* This root barrel re-exports the stable, ergonomic public surface: schemas,
|
|
6
|
+
* messages, errors, provider factories, tools, agents, multi-agent helpers, the
|
|
7
|
+
* execution loop, sessions, context helpers, and event subscribers.
|
|
8
|
+
*
|
|
9
|
+
* Lower-level adapter and transport helpers are intentionally kept off the root
|
|
10
|
+
* import. Every domain is importable from its own subpath for tree-shaking and
|
|
11
|
+
* for advanced integrations:
|
|
12
|
+
* `@infinityi/engine-lib/schema`, `@infinityi/engine-lib/messages`, `@infinityi/engine-lib/errors`,
|
|
13
|
+
* `@infinityi/engine-lib/runtime`, `@infinityi/engine-lib/providers`, `@infinityi/engine-lib/tools`,
|
|
14
|
+
* `@infinityi/engine-lib/agent`, `@infinityi/engine-lib/execution`, `@infinityi/engine-lib/session`,
|
|
15
|
+
* `@infinityi/engine-lib/context`, `@infinityi/engine-lib/events`, and `@infinityi/engine-lib/lifecycle`
|
|
16
|
+
* (forge lifecycle adapter). Test-only helpers live on `@infinityi/engine-lib/testing`,
|
|
17
|
+
* and the fixture-driven provider battery on `@infinityi/engine-lib/testing/conformance`
|
|
18
|
+
* (the only subpath that imports a test runner).
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
export { AgentError, CancelledError, ContextWindowError, ExecutionError, MaxHandoffsExceededError, MaxStepsExceededError, ProviderError, SchemaValidationError, ToolError, ToolValidationError, } from "./errors";
|
|
23
|
+
export type { SchemaIssue } from "./errors";
|
|
24
|
+
export { asSchema, fromJsonSchema, s, toJsonSchema, validateJsonSchema } from "./schema/index";
|
|
25
|
+
export type { Infer, JsonSchema, SafeParseResult, Schema } from "./schema/index";
|
|
26
|
+
export { assistant, normalizeContent, system, text, toolResult, user, } from "./messages/index";
|
|
27
|
+
export type { ContentPart, ImagePart, Message, Role, TextPart, ToolCallPart, ToolResultPart, } from "./messages/index";
|
|
28
|
+
export { isSecret, resolveSecret, Secret } from "./runtime/index";
|
|
29
|
+
export type { EngineContext, TelemetryHandle } from "./runtime/index";
|
|
30
|
+
export { createAnthropic, createGoogle, createOpenAI, createOpenAICompatible, } from "./providers/index";
|
|
31
|
+
export type { AnthropicOptions, CompletionRequest, CompletionResult, FinishReason, GoogleOptions, OpenAICompatibleOptions, OpenAIOptions, Provider, ProviderCapabilities, ProviderTool, ResponseSchema, StreamEvent, ToolCall, ToolChoice, Usage, } from "./providers/index";
|
|
32
|
+
export { defineTool } from "./tools/index";
|
|
33
|
+
export type { ToolContext, ToolDefinition, ToolFailure, ToolResult, ToolSpec, ToolSuccess, } from "./tools/index";
|
|
34
|
+
export { defineAgent } from "./agent/index";
|
|
35
|
+
export type { AgentDefinition, AgentHooks, GenerationSettings, InstructionContext, Instructions, } from "./agent/index";
|
|
36
|
+
export { asTool, createAgentRegistry } from "./agent/index";
|
|
37
|
+
export type { AgentRegistry, AsToolOptions } from "./agent/index";
|
|
38
|
+
export { runAgent } from "./execution/index";
|
|
39
|
+
export type { AnyRunOptions, BufferedRunOptions, RunBridge, RunEvent, RunHandle, RunInput, RunOptions, RunResult, StreamingRunOptions, } from "./execution/index";
|
|
40
|
+
export { createSession, InMemorySessionStore } from "./session/index";
|
|
41
|
+
export type { CreateSessionOptions, Session, SessionState, SessionStore, } from "./session/index";
|
|
42
|
+
export { dynamicContext, staticContext, summarizeOldest, truncateOldest, } from "./context/index";
|
|
43
|
+
export type { ContextItem, ContextProvider, ContextStrategy, ContextStrategyContext, ContextWindowOptions, TokenCounter, } from "./context/index";
|
|
44
|
+
export { createEventHub, loggingSubscriber, messageBusSubscriber, } from "./events/index";
|
|
45
|
+
export type { EventHub, EventHubOptions, LoggingSubscriberOptions, LogLevel, MessageBusSubscriberOptions, RunSubscriber, } from "./events/index";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import"./index-kte2h4k2.js";
|
|
2
|
+
import"./index-d4xz3abn.js";
|
|
3
|
+
import {
|
|
4
|
+
loggingSubscriber,
|
|
5
|
+
messageBusSubscriber
|
|
6
|
+
} from "./index-jxgj4z08.js";
|
|
7
|
+
import {
|
|
8
|
+
InMemorySessionStore,
|
|
9
|
+
createSession
|
|
10
|
+
} from "./index-vnby35rm.js";
|
|
11
|
+
import"./index-19pwq79t.js";
|
|
12
|
+
import"./index-jg19te9v.js";
|
|
13
|
+
import {
|
|
14
|
+
createAnthropic,
|
|
15
|
+
createGoogle,
|
|
16
|
+
createOpenAI,
|
|
17
|
+
createOpenAICompatible
|
|
18
|
+
} from "./index-64tt9696.js";
|
|
19
|
+
import"./index-bqg01r42.js";
|
|
20
|
+
import {
|
|
21
|
+
Secret,
|
|
22
|
+
isSecret,
|
|
23
|
+
resolveSecret
|
|
24
|
+
} from "./index-xsv43c5j.js";
|
|
25
|
+
import {
|
|
26
|
+
asTool,
|
|
27
|
+
createAgentRegistry,
|
|
28
|
+
defineAgent
|
|
29
|
+
} from "./index-jp2b31xs.js";
|
|
30
|
+
import {
|
|
31
|
+
runAgent
|
|
32
|
+
} from "./index-pwr8179t.js";
|
|
33
|
+
import {
|
|
34
|
+
dynamicContext,
|
|
35
|
+
staticContext,
|
|
36
|
+
summarizeOldest,
|
|
37
|
+
truncateOldest
|
|
38
|
+
} from "./index-yrqrxwjt.js";
|
|
39
|
+
import {
|
|
40
|
+
createEventHub
|
|
41
|
+
} from "./index-fkr3rcq9.js";
|
|
42
|
+
import {
|
|
43
|
+
asSchema,
|
|
44
|
+
fromJsonSchema,
|
|
45
|
+
s,
|
|
46
|
+
toJsonSchema,
|
|
47
|
+
validateJsonSchema
|
|
48
|
+
} from "./index-02s1fjxr.js";
|
|
49
|
+
import"./index-zfgr4xx3.js";
|
|
50
|
+
import {
|
|
51
|
+
AgentError,
|
|
52
|
+
CancelledError,
|
|
53
|
+
ContextWindowError,
|
|
54
|
+
ExecutionError,
|
|
55
|
+
MaxHandoffsExceededError,
|
|
56
|
+
MaxStepsExceededError,
|
|
57
|
+
ProviderError,
|
|
58
|
+
SchemaValidationError,
|
|
59
|
+
ToolError,
|
|
60
|
+
ToolValidationError
|
|
61
|
+
} from "./index-7690reng.js";
|
|
62
|
+
import {
|
|
63
|
+
defineTool
|
|
64
|
+
} from "./index-w34cbktd.js";
|
|
65
|
+
import"./index-rentvdpp.js";
|
|
66
|
+
import {
|
|
67
|
+
assistant,
|
|
68
|
+
normalizeContent,
|
|
69
|
+
system,
|
|
70
|
+
text,
|
|
71
|
+
toolResult,
|
|
72
|
+
user
|
|
73
|
+
} from "./index-1p6mb2vz.js";
|
|
74
|
+
export {
|
|
75
|
+
validateJsonSchema,
|
|
76
|
+
user,
|
|
77
|
+
truncateOldest,
|
|
78
|
+
toolResult,
|
|
79
|
+
toJsonSchema,
|
|
80
|
+
text,
|
|
81
|
+
system,
|
|
82
|
+
summarizeOldest,
|
|
83
|
+
staticContext,
|
|
84
|
+
s,
|
|
85
|
+
runAgent,
|
|
86
|
+
resolveSecret,
|
|
87
|
+
normalizeContent,
|
|
88
|
+
messageBusSubscriber,
|
|
89
|
+
loggingSubscriber,
|
|
90
|
+
isSecret,
|
|
91
|
+
fromJsonSchema,
|
|
92
|
+
dynamicContext,
|
|
93
|
+
defineTool,
|
|
94
|
+
defineAgent,
|
|
95
|
+
createSession,
|
|
96
|
+
createOpenAICompatible,
|
|
97
|
+
createOpenAI,
|
|
98
|
+
createGoogle,
|
|
99
|
+
createEventHub,
|
|
100
|
+
createAnthropic,
|
|
101
|
+
createAgentRegistry,
|
|
102
|
+
assistant,
|
|
103
|
+
asTool,
|
|
104
|
+
asSchema,
|
|
105
|
+
ToolValidationError,
|
|
106
|
+
ToolError,
|
|
107
|
+
Secret,
|
|
108
|
+
SchemaValidationError,
|
|
109
|
+
ProviderError,
|
|
110
|
+
MaxStepsExceededError,
|
|
111
|
+
MaxHandoffsExceededError,
|
|
112
|
+
InMemorySessionStore,
|
|
113
|
+
ExecutionError,
|
|
114
|
+
ContextWindowError,
|
|
115
|
+
CancelledError,
|
|
116
|
+
AgentError
|
|
117
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agentRuntimeComponent` — adapt the engine-lib runtime to a
|
|
3
|
+
* `@infinityi/forge/lifecycle` {@link Component} (Phase 8).
|
|
4
|
+
*
|
|
5
|
+
* engine-lib itself is mostly stateless — providers are HTTP clients, sessions
|
|
6
|
+
* live behind a {@link SessionStore} — so this adapter doesn't invent a runtime
|
|
7
|
+
* object. Instead it bundles the pieces an app wires up (providers, an optional
|
|
8
|
+
* session store, telemetry) into the tiny `{ name, start?, stop?, healthcheck? }`
|
|
9
|
+
* seam Forge orchestrates, so the runtime boots and drains cleanly alongside the
|
|
10
|
+
* rest of a Forge application (Principle 6 — composable; Principle 7 — no global
|
|
11
|
+
* state, just a plain object).
|
|
12
|
+
*
|
|
13
|
+
* - `start()` fail-fast validates the config (unique provider names, non-empty
|
|
14
|
+
* default models) and, if `probeOnStart`, probes every provider so a bad
|
|
15
|
+
* deployment rolls back during `forge.boot` instead of failing the first run.
|
|
16
|
+
* - `healthcheck()` maps provider probes to a Forge {@link HealthResult}
|
|
17
|
+
* (`healthy` / `degraded` / `unhealthy`) for readiness/liveness routes.
|
|
18
|
+
* - `stop()` runs the optional `onStop` hook (e.g. flush/close a durable session
|
|
19
|
+
* store), bounded by the shutdown `signal`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { forge } from "@infinityi/forge/lifecycle";
|
|
24
|
+
* import { agentRuntimeComponent } from "@infinityi/engine-lib/lifecycle";
|
|
25
|
+
*
|
|
26
|
+
* const app = await forge.boot({
|
|
27
|
+
* components: [
|
|
28
|
+
* agentRuntimeComponent({
|
|
29
|
+
* providers: [openai],
|
|
30
|
+
* sessionStore: store,
|
|
31
|
+
* probe: (p, signal) => p.complete({ messages: [user("ping")] }, { signal }).then(() => {}),
|
|
32
|
+
* probeOnStart: true,
|
|
33
|
+
* onStop: () => store.close(),
|
|
34
|
+
* }),
|
|
35
|
+
* ],
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @module
|
|
40
|
+
*/
|
|
41
|
+
import type { Component } from "@infinityi/forge/lifecycle";
|
|
42
|
+
import type { Provider } from "../providers/types";
|
|
43
|
+
import type { TelemetryHandle } from "../runtime/types";
|
|
44
|
+
import type { SessionStore } from "../session/types";
|
|
45
|
+
/** Probe a single provider for readiness; rejects/throws when unhealthy. */
|
|
46
|
+
export type ProviderProbe = (provider: Provider, signal: AbortSignal) => Promise<void> | void;
|
|
47
|
+
/** Configuration for {@link agentRuntimeComponent}. */
|
|
48
|
+
export interface AgentRuntimeOptions {
|
|
49
|
+
/** Component id used in logs / health output. Default `"agent-runtime"`. */
|
|
50
|
+
readonly name?: string;
|
|
51
|
+
/** Providers the runtime serves; validated on start and probed on health. */
|
|
52
|
+
readonly providers?: readonly Provider[];
|
|
53
|
+
/** Session store the runtime uses; surfaced for health/reporting. */
|
|
54
|
+
readonly sessionStore?: SessionStore;
|
|
55
|
+
/** Telemetry handle (reserved for runtime wiring; not required). */
|
|
56
|
+
readonly telemetry?: TelemetryHandle;
|
|
57
|
+
/**
|
|
58
|
+
* Optional readiness probe run per provider during `healthcheck` (and during
|
|
59
|
+
* `start` when {@link AgentRuntimeOptions.probeOnStart} is set).
|
|
60
|
+
*/
|
|
61
|
+
readonly probe?: ProviderProbe;
|
|
62
|
+
/** Probe every provider during `start`, failing boot if any probe rejects. */
|
|
63
|
+
readonly probeOnStart?: boolean;
|
|
64
|
+
/** Flush/close hook run on `stop` (e.g. close a durable session store). */
|
|
65
|
+
readonly onStop?: (signal: AbortSignal) => Promise<void> | void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Adapt an engine-lib runtime into a Forge lifecycle {@link Component}.
|
|
69
|
+
*
|
|
70
|
+
* The returned object only contributes the seams it can implement: `start`
|
|
71
|
+
* (always), `stop` (always — runs `onStop` when provided), and `healthcheck`
|
|
72
|
+
* (always — a no-op-healthy probe when none is configured).
|
|
73
|
+
*/
|
|
74
|
+
export declare function agentRuntimeComponent(opts: AgentRuntimeOptions): Component;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@infinityi/engine-lib/lifecycle` — Forge lifecycle integration (Phase 8).
|
|
3
|
+
*
|
|
4
|
+
* Opt-in subpath that adapts the engine-lib runtime to a
|
|
5
|
+
* `@infinityi/forge/lifecycle` {@link Component} via {@link agentRuntimeComponent},
|
|
6
|
+
* so the runtime starts, health-checks, and drains inside a Forge app. Importing
|
|
7
|
+
* it is the only thing that pulls in the forge lifecycle surface.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
export { agentRuntimeComponent } from "./component";
|
|
12
|
+
export type { AgentRuntimeOptions, ProviderProbe } from "./component";
|