@ap3x/agent-core 0.1.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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +29 -0
  3. package/dist/agent-errors.d.ts +54 -0
  4. package/dist/agent-errors.d.ts.map +1 -0
  5. package/dist/agent-loop.d.ts +30 -0
  6. package/dist/agent-loop.d.ts.map +1 -0
  7. package/dist/agent.d.ts +160 -0
  8. package/dist/agent.d.ts.map +1 -0
  9. package/dist/backend.d.ts +67 -0
  10. package/dist/backend.d.ts.map +1 -0
  11. package/dist/compaction.d.ts +147 -0
  12. package/dist/compaction.d.ts.map +1 -0
  13. package/dist/concurrency.d.ts +32 -0
  14. package/dist/concurrency.d.ts.map +1 -0
  15. package/dist/conversation.d.ts +215 -0
  16. package/dist/conversation.d.ts.map +1 -0
  17. package/dist/env.d.ts +125 -0
  18. package/dist/env.d.ts.map +1 -0
  19. package/dist/errors.d.ts +37 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/harness.d.ts +110 -0
  22. package/dist/harness.d.ts.map +1 -0
  23. package/dist/index.d.ts +28 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +4153 -0
  26. package/dist/loader.d.ts +142 -0
  27. package/dist/loader.d.ts.map +1 -0
  28. package/dist/logger.d.ts +36 -0
  29. package/dist/logger.d.ts.map +1 -0
  30. package/dist/output-formatter.d.ts +27 -0
  31. package/dist/output-formatter.d.ts.map +1 -0
  32. package/dist/prompt-templates.d.ts +78 -0
  33. package/dist/prompt-templates.d.ts.map +1 -0
  34. package/dist/result.d.ts +26 -0
  35. package/dist/result.d.ts.map +1 -0
  36. package/dist/serialization.d.ts +75 -0
  37. package/dist/serialization.d.ts.map +1 -0
  38. package/dist/session-repo.d.ts +90 -0
  39. package/dist/session-repo.d.ts.map +1 -0
  40. package/dist/session.d.ts +251 -0
  41. package/dist/session.d.ts.map +1 -0
  42. package/dist/shell-blocklist.d.ts +18 -0
  43. package/dist/shell-blocklist.d.ts.map +1 -0
  44. package/dist/skills.d.ts +95 -0
  45. package/dist/skills.d.ts.map +1 -0
  46. package/dist/system-prompt.d.ts +90 -0
  47. package/dist/system-prompt.d.ts.map +1 -0
  48. package/dist/tools.d.ts +61 -0
  49. package/dist/tools.d.ts.map +1 -0
  50. package/dist/types.d.ts +320 -0
  51. package/dist/types.d.ts.map +1 -0
  52. package/dist/uuid.d.ts +23 -0
  53. package/dist/uuid.d.ts.map +1 -0
  54. package/package.json +33 -0
@@ -0,0 +1,320 @@
1
+ import type { AssistantMessage, AssistantMessageEvent, Context, ImageContent, Message, Model, SimpleStreamOptions, StopReason, TSchema, TextContent, Tool, ToolCall, ToolResultMessage, Usage } from "@ap3x/ai";
2
+ import type { CompactionSettings } from "./compaction";
3
+ /**
4
+ * Extensible interface for host-defined custom message types. A host adds its
5
+ * own transcript message types by declaration-merging into this interface:
6
+ *
7
+ * ```ts
8
+ * declare module "@ap3x/agent-core" {
9
+ * interface CustomAgentMessages {
10
+ * note: { role: "note"; text: string; timestamp: number };
11
+ * }
12
+ * }
13
+ * ```
14
+ *
15
+ * Empty by default, so `CustomAgentMessages[keyof CustomAgentMessages]` is
16
+ * `never` and {@link AgentMessage} stays exactly the `@ap3x/ai` {@link Message}
17
+ * union until a host augments it. A host that adds a custom type is responsible
18
+ * for mapping it down to a standard `Message` via
19
+ * {@link AgentHooks.convertToLlm} before the provider is called.
20
+ */
21
+ export interface CustomAgentMessages {
22
+ }
23
+ /**
24
+ * A message in an agent transcript: the `@ap3x/ai` {@link Message} union
25
+ * (`user` | `assistant` | `toolResult`) plus any host-defined custom message
26
+ * types registered through {@link CustomAgentMessages}. With no augmentation
27
+ * this is exactly {@link Message}.
28
+ */
29
+ export type AgentMessage = Message | CustomAgentMessages[keyof CustomAgentMessages];
30
+ /** Provider-agnostic reasoning intensity used across the agent surface. */
31
+ export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
32
+ /** A snapshot of everything the loop needs to produce the next assistant turn. */
33
+ export interface AgentContext {
34
+ systemPrompt?: string;
35
+ messages: AgentMessage[];
36
+ tools?: Tool[];
37
+ }
38
+ /** The structured payload a tool returns from {@link AgentTool.execute}. */
39
+ export interface AgentToolResult<TDetails = unknown> {
40
+ /** Model-visible content blocks for the resulting `toolResult` message. */
41
+ content: (TextContent | ImageContent)[];
42
+ /** Structured, non-model-visible payload preserved on the message. */
43
+ details?: TDetails;
44
+ /** When true, signals the loop should stop after this batch (see batch rule). */
45
+ terminate?: boolean;
46
+ /** Marks the tool result as an error result. */
47
+ isError?: boolean;
48
+ }
49
+ /** A partial result streamed mid-execution via the `onUpdate` callback. */
50
+ export type AgentToolUpdate<TDetails = unknown> = Partial<AgentToolResult<TDetails>>;
51
+ /**
52
+ * A callable tool the agent can invoke. Extends the `@ap3x/ai` {@link Tool}
53
+ * (name + description + TypeBox/JSON-schema parameters) with an executor.
54
+ */
55
+ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = unknown> extends Tool<TParameters> {
56
+ /** Optional human-friendly label for UIs/logs. */
57
+ label?: string;
58
+ /** Force this tool to run sequentially even when the batch is parallel. */
59
+ executionMode?: "sequential" | "parallel";
60
+ /**
61
+ * Reshape raw model-provided arguments before validation. Only the returned
62
+ * object is used when it differs by reference from the input (identity check).
63
+ */
64
+ prepareArguments?: (rawArguments: Record<string, unknown>) => Record<string, unknown>;
65
+ /** Run the tool. Throwing is allowed; the loop wraps throws into error results. */
66
+ execute: (toolCallId: string, args: Record<string, unknown>, signal?: AbortSignal, onUpdate?: (update: AgentToolUpdate<TDetails>) => void) => Promise<AgentToolResult<TDetails>> | AgentToolResult<TDetails>;
67
+ }
68
+ /** Any registered tool, regardless of its parameter schema / details type. */
69
+ export type AnyAgentTool = AgentTool<TSchema, unknown>;
70
+ /**
71
+ * How a host-queued pending message is delivered to a live (or next) run.
72
+ * - `steer`: inject mid-run at the next turn boundary — before the next
73
+ * assistant turn streams. A steer left in the queue at the final turn (queued
74
+ * after that turn's steering drain) is rescued as a follow-up so it still
75
+ * extends the run instead of being dropped.
76
+ * - `followUp`: extend the run once it would otherwise stop.
77
+ * - `nextTurn`: at the Agent level this shares the follow-up drain (delivered
78
+ * when the run would stop), but is tagged distinctly so a host/harness can
79
+ * layer richer next-prompt semantics on top (see P28b-2).
80
+ */
81
+ export type QueueMode = "steer" | "followUp" | "nextTurn";
82
+ /** Lifecycle + streaming events emitted by the loop. */
83
+ export type AgentEvent = {
84
+ type: "agent_start";
85
+ } | {
86
+ type: "agent_end";
87
+ messages: AgentMessage[];
88
+ } | {
89
+ /**
90
+ * The Agent's pending message queue changed (a `steer`/`followUp`/
91
+ * `nextTurn` was enqueued, or entries were drained into a run). Each array
92
+ * is a snapshot of the messages still queued under that mode. Emitted only
93
+ * when the queue actually changes, so a run that never touches the queue
94
+ * stays byte-identical.
95
+ */
96
+ type: "queue_update";
97
+ steer: AgentMessage[];
98
+ followUp: AgentMessage[];
99
+ nextTurn: AgentMessage[];
100
+ } | {
101
+ type: "turn_start";
102
+ } | {
103
+ type: "turn_end";
104
+ message: AssistantMessage;
105
+ toolResults: ToolResultMessage[];
106
+ } | {
107
+ /**
108
+ * A mid-run compaction was swapped into the working context. Emitted once
109
+ * per successful swap (SOFT and HARD paths alike) so a host can persist a
110
+ * durable compaction boundary. The two counts are swap-time snapshots: a
111
+ * persister must re-derive the kept count at persist time as
112
+ * `retainedAtSwap + (finalNewMessageCount - newMessagesAtSwap)`, because
113
+ * new messages keep arriving after the swap.
114
+ */
115
+ type: "compaction";
116
+ summary: string;
117
+ tokensBefore: number;
118
+ /** Real messages kept in the working context at swap time (excludes the synthetic summary message). */
119
+ retainedAtSwap: number;
120
+ /** The run's new-message count at swap time. */
121
+ newMessagesAtSwap: number;
122
+ } | {
123
+ type: "message_start";
124
+ message: AgentMessage;
125
+ } | {
126
+ type: "message_update";
127
+ message: AssistantMessage;
128
+ assistantMessageEvent: AssistantMessageEvent;
129
+ } | {
130
+ type: "message_end";
131
+ message: AgentMessage;
132
+ } | {
133
+ type: "tool_execution_start";
134
+ toolCallId: string;
135
+ toolName: string;
136
+ args: Record<string, unknown>;
137
+ } | {
138
+ type: "tool_execution_update";
139
+ toolCallId: string;
140
+ toolName: string;
141
+ update: AgentToolUpdate;
142
+ } | {
143
+ type: "tool_execution_end";
144
+ toolCallId: string;
145
+ toolName: string;
146
+ result: ToolResultMessage;
147
+ isError: boolean;
148
+ };
149
+ /** Sink the loop drives with each {@link AgentEvent}; may be async. */
150
+ export type AgentEventSink = (event: AgentEvent) => void | Promise<void>;
151
+ /** The function that turns a model + context into a streamed assistant message. */
152
+ export type StreamFn = (model: Model<string>, context: Context, options?: SimpleStreamOptions) => import("@ap3x/ai").AssistantMessageEventStream;
153
+ /** Decision returned by {@link AgentHooks.beforeToolCall} to gate a tool. */
154
+ export interface ToolCallGate {
155
+ block?: boolean;
156
+ reason?: string;
157
+ /**
158
+ * Replacement arguments adopted for the execution. Re-validated against the
159
+ * tool's schema; a failing rewrite becomes an isError tool result and the
160
+ * tool does not run.
161
+ */
162
+ updatedArgs?: Record<string, unknown>;
163
+ }
164
+ /**
165
+ * Rich context handed to {@link AgentHooks.beforeToolCall} as an optional
166
+ * trailing argument. It is additive — the leading positional args are kept for
167
+ * backward compatibility — and is supplied only when the loop drives the call.
168
+ */
169
+ export interface BeforeToolCallContext {
170
+ /** The assistant message that requested this tool call. */
171
+ assistantMessage: AssistantMessage;
172
+ /** The raw tool-call block from the assistant message. */
173
+ toolCall: ToolCall;
174
+ /** Validated tool arguments (post-schema coercion). */
175
+ args: Record<string, unknown>;
176
+ /** The loop's working context at the moment the call is prepared. */
177
+ agentContext: AgentContext;
178
+ /** The run's abort signal; the hook is responsible for honoring it. */
179
+ signal?: AbortSignal;
180
+ }
181
+ /**
182
+ * Rich context handed to {@link AgentHooks.afterToolCall} as an optional
183
+ * trailing argument (additive). Extends the before-context with the executed
184
+ * result and its current error flag.
185
+ */
186
+ export interface AfterToolCallContext {
187
+ /** The assistant message that requested this tool call. */
188
+ assistantMessage: AssistantMessage;
189
+ /** The raw tool-call block from the assistant message. */
190
+ toolCall: ToolCall;
191
+ /** Validated tool arguments (post-schema coercion). */
192
+ args: Record<string, unknown>;
193
+ /** The executed tool result before any `afterToolCall` overrides. */
194
+ result: AgentToolResult;
195
+ /** Whether the executed result is currently treated as an error. */
196
+ isError: boolean;
197
+ /** The loop's working context at the moment the call is finalized. */
198
+ agentContext: AgentContext;
199
+ /** The run's abort signal; the hook is responsible for honoring it. */
200
+ signal?: AbortSignal;
201
+ }
202
+ /** Hooks that can observe and patch loop behaviour. All are optional. */
203
+ export interface AgentHooks {
204
+ /**
205
+ * Prune/replace the message list before it is sent to the provider. May
206
+ * return a promise (awaited) and receives the run's abort signal, so a host
207
+ * can run async/LLM-backed compaction here. Existing sync hooks keep working.
208
+ */
209
+ transformContext?: (messages: AgentMessage[], signal?: AbortSignal) => AgentMessage[] | Promise<AgentMessage[]>;
210
+ /**
211
+ * Convert the transcript into the LLM-domain message list handed to the
212
+ * provider. Applied AFTER {@link transformContext}, as the final step before
213
+ * the model call — the seam where a host maps its own transcript messages
214
+ * (e.g. host-specific/custom message types) down to standard `@ap3x/ai`
215
+ * {@link Message}s. Return the messages the model should see. When this hook
216
+ * is absent the (already transformed) transcript passes straight through, so
217
+ * the provider context is byte-identical without it.
218
+ */
219
+ convertToLlm?: (messages: AgentMessage[]) => Message[] | Promise<Message[]>;
220
+ /**
221
+ * Inspect/gate a tool call before it runs; return `{block, reason}` to block.
222
+ * The optional trailing `context` carries the assistant message, raw tool
223
+ * call, validated args, the working {@link AgentContext} and the abort signal
224
+ * (present when the loop drives the call).
225
+ */
226
+ beforeToolCall?: (toolName: string, args: Record<string, unknown>, toolCallId: string, context?: BeforeToolCallContext) => ToolCallGate | undefined | Promise<ToolCallGate | undefined>;
227
+ /**
228
+ * Patch a tool result after it runs. Returned fields override field-by-field.
229
+ * The optional trailing `context` mirrors {@link AfterToolCallContext}.
230
+ */
231
+ afterToolCall?: (toolName: string, result: AgentToolResult, toolCallId: string, context?: AfterToolCallContext) => Partial<AgentToolResult> | undefined | Promise<Partial<AgentToolResult> | undefined>;
232
+ /** Observe each completed assistant message. */
233
+ onResponse?: (message: AssistantMessage) => void | Promise<void>;
234
+ /**
235
+ * Resolve an API key per model call. Consulted once before each provider
236
+ * request so a host can supply a freshly-minted short-lived key (e.g. an
237
+ * expiring Copilot token). Return `undefined` to fall back to the default
238
+ * auth resolution. When this hook is absent behaviour is unchanged.
239
+ */
240
+ getApiKey?: (provider: string) => string | undefined | Promise<string | undefined>;
241
+ /**
242
+ * Supply steering messages to inject mid-run. Consulted once at each turn
243
+ * boundary — before the next assistant turn streams — so returned messages
244
+ * enter the working context and the transcript ahead of that turn. Return
245
+ * `[]` to inject nothing (no busy-loop or re-injection). The loop does not
246
+ * consult this once the run is aborting. When this hook is absent behaviour
247
+ * is unchanged.
248
+ */
249
+ getSteeringMessages?: () => AgentMessage[] | Promise<AgentMessage[]>;
250
+ /**
251
+ * Supply follow-up messages when the loop would otherwise stop — an assistant
252
+ * turn requesting no tools, or a terminating tool batch. Non-empty messages
253
+ * become the next user turn and the loop continues (post-stop extension); `[]`
254
+ * lets the loop stop as before. `maxLoops` still bounds the run, and an
255
+ * error/aborted stop is never extended. When this hook is absent behaviour is
256
+ * unchanged.
257
+ */
258
+ getFollowUpMessages?: () => AgentMessage[] | Promise<AgentMessage[]>;
259
+ /**
260
+ * PreCompact veto. Consulted just before the loop would LAUNCH a compaction
261
+ * (hard or soft tier). Return `{ defer: true }` to skip launching this turn
262
+ * (re-consulted next turn; at the hard tier the run proceeds un-compacted at
263
+ * the host's risk). An already-launched in-flight compaction still applies.
264
+ * A throwing hook never blocks compaction. Absent = unchanged behaviour.
265
+ */
266
+ beforeCompaction?: () => {
267
+ defer?: boolean;
268
+ } | undefined | Promise<{
269
+ defer?: boolean;
270
+ } | undefined>;
271
+ }
272
+ /** Tunable configuration for one run of the loop. */
273
+ export interface AgentLoopConfig {
274
+ model: Model<string>;
275
+ systemPrompt?: string;
276
+ tools?: AnyAgentTool[];
277
+ /** Reasoning level forwarded to the provider's simple entry point. */
278
+ reasoning?: Exclude<ThinkingLevel, "off">;
279
+ /**
280
+ * Hard cap on assistant turns; the loop stops once reached. Defaults to a
281
+ * high, non-truncating guard (see `DEFAULT_MAX_LOOPS`) so legitimate long
282
+ * tool runs aren't silently cut. Set a low number to cap explicitly, or
283
+ * `Infinity` to disable the guard entirely (an uncapped loop).
284
+ */
285
+ maxLoops?: number;
286
+ /** Sequential or parallel tool execution. Default: "parallel". */
287
+ toolExecution?: "sequential" | "parallel";
288
+ /** Per-call provider options merged into the stream request. */
289
+ streamOptions?: SimpleStreamOptions;
290
+ /** Hooks observing/patching the loop. */
291
+ hooks?: AgentHooks;
292
+ /** Provider entry point. Default: `@ap3x/ai` `streamSimple`. */
293
+ streamFn?: StreamFn;
294
+ /** Auto-compaction tunables. Absent → DEFAULT_COMPACTION_SETTINGS (enabled). */
295
+ compaction?: CompactionSettings;
296
+ /**
297
+ * Summary of a PRIOR compaction (e.g. the durable CompactionEntry a resumed
298
+ * session was seeded from). Seeds the loop's summary threading so this run's
299
+ * FIRST compaction merges into it (UPDATE_SUMMARIZATION) rather than
300
+ * re-summarizing the seeded summary message as ordinary text.
301
+ */
302
+ previousSummary?: string;
303
+ /** Test seam: override the summary-generation call (mirrors compact()'s `complete`). */
304
+ compactionComplete?: (model: Model<string>, context: Context, options?: SimpleStreamOptions) => Promise<AssistantMessage>;
305
+ /**
306
+ * Chooses the model per assistant turn. Return undefined to use `model`. Precedence: turn > config.
307
+ * Affects only the assistant-response stream: compaction (context-window tiering and summarization)
308
+ * always uses the static `model`.
309
+ */
310
+ selectModel?: (info: ModelSelectionInfo) => AgentLoopConfig["model"] | undefined;
311
+ }
312
+ /** Input to AgentLoopConfig.selectModel — one call per assistant turn. */
313
+ export interface ModelSelectionInfo {
314
+ /** 0-based assistant turn counter for this run. */
315
+ turn: number;
316
+ /** Current working transcript (read-only). */
317
+ messages: readonly AgentMessage[];
318
+ }
319
+ export type { AssistantMessage, StopReason, ToolCall, ToolResultMessage, Usage };
320
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,qBAAqB,EACrB,OAAO,EACP,YAAY,EACZ,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,UAAU,EACV,OAAO,EACP,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACjB,KAAK,EACN,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;;;;;;;;;;;;;;;GAiBG;AAGH,MAAM,WAAW,mBAAmB;CAAG;AAEvC;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,mBAAmB,CAAC,MAAM,mBAAmB,CAAC,CAAC;AAEpF,2EAA2E;AAC3E,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpF,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;CAChB;AAED,4EAA4E;AAC5E,MAAM,WAAW,eAAe,CAAC,QAAQ,GAAG,OAAO;IACjD,2EAA2E;IAC3E,OAAO,EAAE,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC;IACxC,sEAAsE;IACtE,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,iFAAiF;IACjF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,2EAA2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AC9C,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;CACnC;AAED,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC"}
package/dist/uuid.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A dependency-free, time-ordered, monotonic UUIDv7 generator.
3
+ *
4
+ * UUIDv7 packs a 48-bit Unix-millisecond timestamp into the high bytes, which
5
+ * makes the resulting string lexically sortable by creation time. To keep ids
6
+ * unique and ordered even when many are minted within the same millisecond, we
7
+ * carry a monotonic counter that increments while the clock is frozen, and only
8
+ * reseed it from fresh randomness once the millisecond advances.
9
+ */
10
+ /** Generate a monotonic, sortable UUIDv7 string. */
11
+ export declare function uuidv7(): string;
12
+ /**
13
+ * A short, collision-checked id derived from a {@link uuidv7}.
14
+ *
15
+ * Takes the id's trailing (random) hex, NOT the leading hex: a uuidv7 begins
16
+ * with a 48-bit millisecond timestamp, so two ids minted in the same
17
+ * millisecond share an identical prefix. Front-slicing would make every
18
+ * candidate in a millisecond identical — silently colliding when no `existing`
19
+ * set is given, and defeating the retry loop when one is. Slicing the random
20
+ * tail gives genuine intra-millisecond entropy.
21
+ */
22
+ export declare function shortId(existing?: ReadonlySet<string>, length?: number): string;
23
+ //# sourceMappingURL=uuid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAoBH,oDAAoD;AACpD,wBAAgB,MAAM,IAAI,MAAM,CAkD/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAM1E"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@ap3x/agent-core",
3
+ "version": "0.1.0",
4
+ "description": "Agent loop, tool calling, sessions, compaction, and the AgentBackend interface",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/AP3X-Dev/AP3X.git",
8
+ "directory": "packages/agent-core"
9
+ },
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": ["dist"],
24
+ "scripts": {
25
+ "build": "tsup src/index.ts --format esm --clean --tsconfig tsconfig.build.json && tsc -p tsconfig.build.json",
26
+ "prepublishOnly": "node ../../scripts/publish-gate.mjs",
27
+ "test": "vitest run"
28
+ },
29
+ "dependencies": {
30
+ "@ap3x/ai": "0.1.0",
31
+ "yaml": "^2.9.0"
32
+ }
33
+ }