@devxiyang/agent-kernel 0.0.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 +525 -0
- package/dist/core/agent/agent.d.ts +132 -0
- package/dist/core/agent/agent.d.ts.map +1 -0
- package/dist/core/agent/agent.js +301 -0
- package/dist/core/agent/agent.js.map +1 -0
- package/dist/core/agent/index.d.ts +13 -0
- package/dist/core/agent/index.d.ts.map +1 -0
- package/dist/core/agent/index.js +10 -0
- package/dist/core/agent/index.js.map +1 -0
- package/dist/core/agent/loop.d.ts +30 -0
- package/dist/core/agent/loop.d.ts.map +1 -0
- package/dist/core/agent/loop.js +378 -0
- package/dist/core/agent/loop.js.map +1 -0
- package/dist/core/agent/types.d.ts +231 -0
- package/dist/core/agent/types.d.ts.map +1 -0
- package/dist/core/agent/types.js +9 -0
- package/dist/core/agent/types.js.map +1 -0
- package/dist/core/agent/wrap-tool.d.ts +12 -0
- package/dist/core/agent/wrap-tool.d.ts.map +1 -0
- package/dist/core/agent/wrap-tool.js +37 -0
- package/dist/core/agent/wrap-tool.js.map +1 -0
- package/dist/core/kernel/index.d.ts +12 -0
- package/dist/core/kernel/index.d.ts.map +1 -0
- package/dist/core/kernel/index.js +10 -0
- package/dist/core/kernel/index.js.map +1 -0
- package/dist/core/kernel/kernel.d.ts +15 -0
- package/dist/core/kernel/kernel.d.ts.map +1 -0
- package/dist/core/kernel/kernel.js +320 -0
- package/dist/core/kernel/kernel.js.map +1 -0
- package/dist/core/kernel/session-store.d.ts +24 -0
- package/dist/core/kernel/session-store.d.ts.map +1 -0
- package/dist/core/kernel/session-store.js +90 -0
- package/dist/core/kernel/session-store.js.map +1 -0
- package/dist/core/kernel/types.d.ts +215 -0
- package/dist/core/kernel/types.d.ts.map +1 -0
- package/dist/core/kernel/types.js +11 -0
- package/dist/core/kernel/types.js.map +1 -0
- package/dist/event-stream.d.ts +25 -0
- package/dist/event-stream.d.ts.map +1 -0
- package/dist/event-stream.js +58 -0
- package/dist/event-stream.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Kernel module.
|
|
3
|
+
*
|
|
4
|
+
* Covers token usage tracking, multimodal content parts, conversation entries
|
|
5
|
+
* (AgentEntry / AgentMessage), the persistent store format (StoredEntry),
|
|
6
|
+
* compaction, and the AgentKernel interface.
|
|
7
|
+
*/
|
|
8
|
+
/** Token counts and estimated cost for a single LLM call or an aggregated run. */
|
|
9
|
+
export type Usage = {
|
|
10
|
+
/** Tokens in the prompt (input to the model). */
|
|
11
|
+
input: number;
|
|
12
|
+
/** Tokens in the completion (output from the model). */
|
|
13
|
+
output: number;
|
|
14
|
+
/** Tokens read from the prompt cache. */
|
|
15
|
+
cacheRead: number;
|
|
16
|
+
/** Tokens written to the prompt cache. */
|
|
17
|
+
cacheWrite: number;
|
|
18
|
+
/** Sum of all token categories. */
|
|
19
|
+
totalTokens: number;
|
|
20
|
+
/** Estimated cost breakdown in USD. */
|
|
21
|
+
cost: {
|
|
22
|
+
input: number;
|
|
23
|
+
output: number;
|
|
24
|
+
cacheRead: number;
|
|
25
|
+
cacheWrite: number;
|
|
26
|
+
total: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** Raw binary or base64-encoded string. */
|
|
30
|
+
export type DataContent = string | Uint8Array;
|
|
31
|
+
/** Discriminated source: file path / HTTP URL, or raw binary / base64. */
|
|
32
|
+
type UrlSource = {
|
|
33
|
+
url: string;
|
|
34
|
+
};
|
|
35
|
+
type DataSource = {
|
|
36
|
+
data: DataContent;
|
|
37
|
+
};
|
|
38
|
+
type MediaSource = UrlSource | DataSource;
|
|
39
|
+
export type ImageMediaType = 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp' | 'image/bmp' | 'image/svg+xml' | 'image/tiff' | (string & {});
|
|
40
|
+
export type AudioMediaType = 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/flac' | 'audio/aac' | 'audio/webm' | 'audio/mp4' | (string & {});
|
|
41
|
+
export type VideoMediaType = 'video/mp4' | 'video/webm' | 'video/ogg' | 'video/quicktime' | 'video/x-msvideo' | (string & {});
|
|
42
|
+
export type FileMediaType = 'application/pdf' | 'application/json' | 'application/xml' | 'text/plain' | 'text/html' | 'text/csv' | 'text/markdown' | (string & {});
|
|
43
|
+
export type TextPart = {
|
|
44
|
+
type: 'text';
|
|
45
|
+
text: string;
|
|
46
|
+
};
|
|
47
|
+
export type ImagePart = {
|
|
48
|
+
type: 'image';
|
|
49
|
+
mediaType?: ImageMediaType;
|
|
50
|
+
} & MediaSource;
|
|
51
|
+
export type AudioPart = {
|
|
52
|
+
type: 'audio';
|
|
53
|
+
mediaType?: AudioMediaType;
|
|
54
|
+
} & MediaSource;
|
|
55
|
+
export type VideoPart = {
|
|
56
|
+
type: 'video';
|
|
57
|
+
mediaType?: VideoMediaType;
|
|
58
|
+
} & MediaSource;
|
|
59
|
+
export type FilePart = {
|
|
60
|
+
type: 'file';
|
|
61
|
+
mediaType: FileMediaType;
|
|
62
|
+
filename?: string;
|
|
63
|
+
} & MediaSource;
|
|
64
|
+
/** Union of all content parts usable in user messages and tool results. */
|
|
65
|
+
export type ContentPart = TextPart | ImagePart | AudioPart | VideoPart | FilePart;
|
|
66
|
+
/** Reason the model stopped generating. 'error' and 'aborted' are set by the loop, not the provider. */
|
|
67
|
+
export type StopReason = 'stop' | 'tool_use' | 'error' | 'aborted' | 'length' | 'content_filter' | (string & {});
|
|
68
|
+
/** Minimal descriptor of a single tool invocation requested by the LLM. */
|
|
69
|
+
export type ToolCallInfo = {
|
|
70
|
+
toolCallId: string;
|
|
71
|
+
toolName: string;
|
|
72
|
+
/** Raw JSON object the LLM produced as the tool's arguments. */
|
|
73
|
+
input: Record<string, unknown>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* A single turn in the conversation, as stored in the kernel.
|
|
77
|
+
*
|
|
78
|
+
* - user — one or more content parts from the human
|
|
79
|
+
* - assistant — model response: text, optional reasoning, and/or tool calls
|
|
80
|
+
* - tool_result — result of executing a tool requested by the model
|
|
81
|
+
* - summary — compacted representation of a range of earlier entries
|
|
82
|
+
*/
|
|
83
|
+
export type AgentEntry = {
|
|
84
|
+
type: 'user';
|
|
85
|
+
payload: {
|
|
86
|
+
parts: ContentPart[];
|
|
87
|
+
};
|
|
88
|
+
} | {
|
|
89
|
+
type: 'assistant';
|
|
90
|
+
payload: {
|
|
91
|
+
text: string;
|
|
92
|
+
reasoning?: string;
|
|
93
|
+
toolCalls: ToolCallInfo[];
|
|
94
|
+
stopReason?: StopReason;
|
|
95
|
+
error?: string;
|
|
96
|
+
};
|
|
97
|
+
usage?: Usage;
|
|
98
|
+
} | {
|
|
99
|
+
type: 'tool_result';
|
|
100
|
+
payload: {
|
|
101
|
+
toolCallId: string;
|
|
102
|
+
toolName: string;
|
|
103
|
+
content: string | ContentPart[];
|
|
104
|
+
isError: boolean;
|
|
105
|
+
};
|
|
106
|
+
} | {
|
|
107
|
+
type: 'summary';
|
|
108
|
+
payload: {
|
|
109
|
+
text: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Normalised message format passed to StreamFn.
|
|
114
|
+
* Provider adapters translate this into their own SDK's message shape.
|
|
115
|
+
* Three roles mirror the OpenAI / Anthropic convention: user, assistant, tool.
|
|
116
|
+
*/
|
|
117
|
+
export type AgentMessage = {
|
|
118
|
+
role: 'user';
|
|
119
|
+
content: string | ContentPart[];
|
|
120
|
+
} | {
|
|
121
|
+
role: 'assistant';
|
|
122
|
+
content: string | Array<TextPart | {
|
|
123
|
+
type: 'reasoning';
|
|
124
|
+
text: string;
|
|
125
|
+
} | {
|
|
126
|
+
type: 'tool-call';
|
|
127
|
+
toolCallId: string;
|
|
128
|
+
toolName: string;
|
|
129
|
+
input: Record<string, unknown>;
|
|
130
|
+
}>;
|
|
131
|
+
} | {
|
|
132
|
+
role: 'tool';
|
|
133
|
+
content: Array<{
|
|
134
|
+
type: 'tool-result';
|
|
135
|
+
toolCallId: string;
|
|
136
|
+
toolName: string;
|
|
137
|
+
content: string | ContentPart[];
|
|
138
|
+
isError: boolean;
|
|
139
|
+
}>;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* An AgentEntry decorated with persistence metadata.
|
|
143
|
+
* Forms a linked tree (parentId → id) that supports conversation branching.
|
|
144
|
+
*/
|
|
145
|
+
export type StoredEntry = AgentEntry & {
|
|
146
|
+
/** Auto-incrementing unique identifier within a session. */
|
|
147
|
+
readonly id: number;
|
|
148
|
+
/** ID of the preceding entry on this branch, or null for the root. */
|
|
149
|
+
readonly parentId: number | null;
|
|
150
|
+
/** Unix timestamp (ms) at which this entry was written. */
|
|
151
|
+
readonly timestamp: number;
|
|
152
|
+
};
|
|
153
|
+
/** Return value of kernel.append() and kernel.compact(). */
|
|
154
|
+
export type AppendResult = {
|
|
155
|
+
ok: true;
|
|
156
|
+
id: number;
|
|
157
|
+
} | {
|
|
158
|
+
ok: false;
|
|
159
|
+
reason: string;
|
|
160
|
+
};
|
|
161
|
+
/** Sentinel type string used to identify compaction records in kernel.jsonl. */
|
|
162
|
+
export declare const COMPACTION_TYPE: "__compaction__";
|
|
163
|
+
/**
|
|
164
|
+
* A compaction marker written to kernel.jsonl. Records the original entry range
|
|
165
|
+
* so that a compact can be replayed on load, then replaced in-memory by a summary.
|
|
166
|
+
*/
|
|
167
|
+
export type CompactionEntry = {
|
|
168
|
+
type: typeof COMPACTION_TYPE;
|
|
169
|
+
payload: {
|
|
170
|
+
fromId: number;
|
|
171
|
+
toId: number;
|
|
172
|
+
summary: AgentEntry;
|
|
173
|
+
};
|
|
174
|
+
usage?: Usage;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Tracks the context window utilisation for the current session.
|
|
178
|
+
* The loop checks `used >= limit` to decide whether to fire `onContextFull`.
|
|
179
|
+
*/
|
|
180
|
+
export interface TokenBudget {
|
|
181
|
+
/** Tokens consumed by the last assistant step (from usage.input). */
|
|
182
|
+
readonly used: number;
|
|
183
|
+
/** Maximum allowed context size before compaction is triggered. */
|
|
184
|
+
readonly limit: number;
|
|
185
|
+
/** Set the context size limit (e.g. model's context window * 0.8). */
|
|
186
|
+
set(limit: number): void;
|
|
187
|
+
}
|
|
188
|
+
export interface AgentKernel {
|
|
189
|
+
append(entry: AgentEntry): AppendResult;
|
|
190
|
+
read(): StoredEntry[];
|
|
191
|
+
compact(fromId: number, toId: number, summaryText: string): AppendResult;
|
|
192
|
+
readonly budget: TokenBudget;
|
|
193
|
+
/** Current context size: last assistant entry's usage.input. */
|
|
194
|
+
readonly contextSize: number;
|
|
195
|
+
readonly leafId: number | null;
|
|
196
|
+
peek(): StoredEntry | null;
|
|
197
|
+
branch(toId: number): void;
|
|
198
|
+
/** Build provider-agnostic messages from current branch (compaction-aware). */
|
|
199
|
+
buildMessages(): AgentMessage[];
|
|
200
|
+
/** Full conversation history, never compacted. UI reads this. */
|
|
201
|
+
readLog(): AgentEntry[];
|
|
202
|
+
}
|
|
203
|
+
export type SessionMeta = {
|
|
204
|
+
createdAt: number;
|
|
205
|
+
title?: string;
|
|
206
|
+
};
|
|
207
|
+
export interface KernelOptions {
|
|
208
|
+
/** Session directory and ID for persistence. Omit for in-memory mode. */
|
|
209
|
+
dir: string;
|
|
210
|
+
sessionId: string;
|
|
211
|
+
/** Optional metadata to set/merge on the session. `createdAt` is auto-set and cannot be overwritten. */
|
|
212
|
+
meta?: Partial<Omit<SessionMeta, 'createdAt'>>;
|
|
213
|
+
}
|
|
214
|
+
export {};
|
|
215
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/kernel/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG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KAAK,EAAE,UAAU,GAAG,YAAY,CAAA;IACvC,IAAI,IAAI,WAAW,EAAE,CAAA;IAGrB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,YAAY,CAAA;IAGxE,QAAQ,CAAC,MAAM,EAAO,WAAW,CAAA;IACjC,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAG5B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,IAAI,IAAI,WAAW,GAAG,IAAI,CAAA;IAC1B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAG1B,+EAA+E;IAC/E,aAAa,IAAI,YAAY,EAAE,CAAA;IAG/B,iEAAiE;IACjE,OAAO,IAAI,UAAU,EAAE,CAAA;CACxB;AAID,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAK,MAAM,CAAA;CAClB,CAAA;AAID,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,GAAG,EAAQ,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,wGAAwG;IACxG,IAAI,CAAC,EAAM,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAA;CACnD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Kernel module.
|
|
3
|
+
*
|
|
4
|
+
* Covers token usage tracking, multimodal content parts, conversation entries
|
|
5
|
+
* (AgentEntry / AgentMessage), the persistent store format (StoredEntry),
|
|
6
|
+
* compaction, and the AgentKernel interface.
|
|
7
|
+
*/
|
|
8
|
+
// ─── Compaction ───────────────────────────────────────────────────────────────
|
|
9
|
+
/** Sentinel type string used to identify compaction records in kernel.jsonl. */
|
|
10
|
+
export const COMPACTION_TYPE = '__compaction__';
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/kernel/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmJH,iFAAiF;AAEjF,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAyB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic push/iterate event stream.
|
|
3
|
+
*
|
|
4
|
+
* Producer calls push() to emit events and end(result) or error(err) to finish.
|
|
5
|
+
* Consumer iterates with `for await (const event of stream)` and awaits stream.result().
|
|
6
|
+
*/
|
|
7
|
+
export declare class EventStream<T, R> {
|
|
8
|
+
private readonly queue;
|
|
9
|
+
private readonly waiters;
|
|
10
|
+
private done;
|
|
11
|
+
private readonly resultP;
|
|
12
|
+
private resolveResult;
|
|
13
|
+
private rejectResult;
|
|
14
|
+
constructor();
|
|
15
|
+
/** Emit one event to the next waiting consumer, or buffer it if none is waiting. */
|
|
16
|
+
push(event: T): void;
|
|
17
|
+
/** Signal successful completion. Resolves the result promise and unblocks all consumers. */
|
|
18
|
+
end(result: R): void;
|
|
19
|
+
/** Signal an error. Rejects the result promise and unblocks all consumers. */
|
|
20
|
+
error(err: Error): void;
|
|
21
|
+
/** Await the final result value (resolves after end(), rejects after error()). */
|
|
22
|
+
result(): Promise<R>;
|
|
23
|
+
[Symbol.asyncIterator](): AsyncGenerator<T>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=event-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-stream.d.ts","sourceRoot":"","sources":["../src/event-stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,WAAW,CAAC,CAAC,EAAE,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAY;IACpC,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,YAAY,CAAsB;;IAS1C,oFAAoF;IACpF,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAMpB,4FAA4F;IAC5F,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAMpB,8EAA8E;IAC9E,KAAK,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI;IAMvB,kFAAkF;IAClF,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC;IAEb,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC;CASnD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic push/iterate event stream.
|
|
3
|
+
*
|
|
4
|
+
* Producer calls push() to emit events and end(result) or error(err) to finish.
|
|
5
|
+
* Consumer iterates with `for await (const event of stream)` and awaits stream.result().
|
|
6
|
+
*/
|
|
7
|
+
export class EventStream {
|
|
8
|
+
queue = [];
|
|
9
|
+
waiters = [];
|
|
10
|
+
done = false;
|
|
11
|
+
resultP;
|
|
12
|
+
resolveResult;
|
|
13
|
+
rejectResult;
|
|
14
|
+
constructor() {
|
|
15
|
+
this.resultP = new Promise((res, rej) => {
|
|
16
|
+
this.resolveResult = res;
|
|
17
|
+
this.rejectResult = rej;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** Emit one event to the next waiting consumer, or buffer it if none is waiting. */
|
|
21
|
+
push(event) {
|
|
22
|
+
const waiter = this.waiters.shift();
|
|
23
|
+
if (waiter) {
|
|
24
|
+
waiter(event);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.queue.push(event);
|
|
28
|
+
}
|
|
29
|
+
/** Signal successful completion. Resolves the result promise and unblocks all consumers. */
|
|
30
|
+
end(result) {
|
|
31
|
+
this.done = true;
|
|
32
|
+
this.resolveResult(result);
|
|
33
|
+
this.waiters.splice(0).forEach((w) => w(null));
|
|
34
|
+
}
|
|
35
|
+
/** Signal an error. Rejects the result promise and unblocks all consumers. */
|
|
36
|
+
error(err) {
|
|
37
|
+
this.done = true;
|
|
38
|
+
this.rejectResult(err);
|
|
39
|
+
this.waiters.splice(0).forEach((w) => w(null));
|
|
40
|
+
}
|
|
41
|
+
/** Await the final result value (resolves after end(), rejects after error()). */
|
|
42
|
+
result() { return this.resultP; }
|
|
43
|
+
async *[Symbol.asyncIterator]() {
|
|
44
|
+
while (true) {
|
|
45
|
+
if (this.queue.length > 0) {
|
|
46
|
+
yield this.queue.shift();
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (this.done)
|
|
50
|
+
return;
|
|
51
|
+
const item = await new Promise((res) => this.waiters.push(res));
|
|
52
|
+
if (item === null)
|
|
53
|
+
return;
|
|
54
|
+
yield item;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=event-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-stream.js","sourceRoot":"","sources":["../src/event-stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACL,KAAK,GAAY,EAAE,CAAA;IACnB,OAAO,GAAiC,EAAE,CAAA;IACnD,IAAI,GAAG,KAAK,CAAA;IACH,OAAO,CAAY;IAC5B,aAAa,CAAiB;IAC9B,YAAY,CAAsB;IAE1C;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACzC,IAAI,CAAC,aAAa,GAAG,GAAG,CAAA;YACxB,IAAI,CAAC,YAAY,GAAI,GAAG,CAAA;QAC1B,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,oFAAoF;IACpF,IAAI,CAAC,KAAQ;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAA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AAI,IAAI,KAAK,IAAI;gBAAE,OAAM;YACzB,MAAM,IAAI,CAAA;QACZ,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module agent-kernel
|
|
3
|
+
*
|
|
4
|
+
* Package root. Re-exports the full public Agent API and the EventStream utility.
|
|
5
|
+
*
|
|
6
|
+
* Common imports:
|
|
7
|
+
* import { createAgent, wrapTool, type AgentTool } from '@devxiyang/agent-kernel'
|
|
8
|
+
* import { EventStream } from '@devxiyang/agent-kernel'
|
|
9
|
+
*/
|
|
10
|
+
export * from './core/agent';
|
|
11
|
+
export { EventStream } from './event-stream';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module agent-kernel
|
|
3
|
+
*
|
|
4
|
+
* Package root. Re-exports the full public Agent API and the EventStream utility.
|
|
5
|
+
*
|
|
6
|
+
* Common imports:
|
|
7
|
+
* import { createAgent, wrapTool, type AgentTool } from '@devxiyang/agent-kernel'
|
|
8
|
+
* import { EventStream } from '@devxiyang/agent-kernel'
|
|
9
|
+
*/
|
|
10
|
+
export * from './core/agent';
|
|
11
|
+
export { EventStream } from './event-stream';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devxiyang/agent-kernel",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Agent kernel and loop library",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/devxiyang/agent.kernel.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"agent",
|
|
12
|
+
"agent-runtime",
|
|
13
|
+
"llm",
|
|
14
|
+
"tools",
|
|
15
|
+
"kernel",
|
|
16
|
+
"typescript"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./agent": {
|
|
27
|
+
"types": "./dist/core/agent/index.d.ts",
|
|
28
|
+
"import": "./dist/core/agent/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./kernel": {
|
|
31
|
+
"types": "./dist/core/kernel/index.d.ts",
|
|
32
|
+
"import": "./dist/core/kernel/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./event-stream": {
|
|
35
|
+
"types": "./dist/event-stream.d.ts",
|
|
36
|
+
"import": "./dist/event-stream.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"clean": "rm -rf dist",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:watch": "vitest"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^24.0.0",
|
|
51
|
+
"typescript": "^5.8.0",
|
|
52
|
+
"vitest": "^4.0.18"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@sinclair/typebox": "^0.34.48"
|
|
56
|
+
}
|
|
57
|
+
}
|