@gajae-code/agent-core 0.1.1
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/CHANGELOG.md +482 -0
- package/README.md +473 -0
- package/dist/types/agent-loop.d.ts +55 -0
- package/dist/types/agent.d.ts +334 -0
- package/dist/types/append-only-context.d.ts +113 -0
- package/dist/types/compaction/branch-summarization.d.ts +94 -0
- package/dist/types/compaction/compaction.d.ts +166 -0
- package/dist/types/compaction/entries.d.ts +103 -0
- package/dist/types/compaction/errors.d.ts +26 -0
- package/dist/types/compaction/index.d.ts +11 -0
- package/dist/types/compaction/messages.d.ts +61 -0
- package/dist/types/compaction/openai.d.ts +58 -0
- package/dist/types/compaction/pruning.d.ts +18 -0
- package/dist/types/compaction/utils.d.ts +32 -0
- package/dist/types/compaction.d.ts +1 -0
- package/dist/types/harmony-leak.d.ts +99 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/proxy.d.ts +84 -0
- package/dist/types/run-collector.d.ts +196 -0
- package/dist/types/telemetry.d.ts +588 -0
- package/dist/types/thinking.d.ts +17 -0
- package/dist/types/types.d.ts +407 -0
- package/package.json +75 -0
- package/src/agent-loop.ts +1279 -0
- package/src/agent.ts +1399 -0
- package/src/append-only-context.ts +297 -0
- package/src/compaction/branch-summarization.ts +339 -0
- package/src/compaction/compaction.ts +1065 -0
- package/src/compaction/entries.ts +133 -0
- package/src/compaction/errors.ts +31 -0
- package/src/compaction/index.ts +12 -0
- package/src/compaction/messages.ts +212 -0
- package/src/compaction/openai.ts +552 -0
- package/src/compaction/prompts/auto-handoff-threshold-focus.md +1 -0
- package/src/compaction/prompts/branch-summary-context.md +5 -0
- package/src/compaction/prompts/branch-summary-preamble.md +2 -0
- package/src/compaction/prompts/branch-summary.md +30 -0
- package/src/compaction/prompts/compaction-short-summary.md +9 -0
- package/src/compaction/prompts/compaction-summary-context.md +5 -0
- package/src/compaction/prompts/compaction-summary.md +38 -0
- package/src/compaction/prompts/compaction-turn-prefix.md +17 -0
- package/src/compaction/prompts/compaction-update-summary.md +45 -0
- package/src/compaction/prompts/file-operations.md +10 -0
- package/src/compaction/prompts/handoff-document.md +49 -0
- package/src/compaction/prompts/summarization-system.md +3 -0
- package/src/compaction/pruning.ts +92 -0
- package/src/compaction/utils.ts +185 -0
- package/src/compaction.ts +1 -0
- package/src/harmony-leak.ts +427 -0
- package/src/index.ts +19 -0
- package/src/proxy.ts +326 -0
- package/src/run-collector.ts +631 -0
- package/src/telemetry.ts +2018 -0
- package/src/thinking.ts +19 -0
- package/src/types.ts +467 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import type { AssistantMessage, AssistantMessageEvent, AssistantMessageEventStream, Effort, ImageContent, Message, Model, SimpleStreamOptions, Static, streamSimple, TextContent, Tool, ToolChoice, ToolResultMessage, TSchema } from "@gajae-code/ai";
|
|
2
|
+
import type { AppendOnlyContextManager } from "./append-only-context";
|
|
3
|
+
import type { HarmonyAuditEvent } from "./harmony-leak";
|
|
4
|
+
import type { AgentRunCoverage, AgentRunSummary } from "./run-collector";
|
|
5
|
+
import type { AgentTelemetryConfig } from "./telemetry";
|
|
6
|
+
/** Stream function - can return sync or Promise for async config lookup */
|
|
7
|
+
export type StreamFn = (...args: Parameters<typeof streamSimple>) => AssistantMessageEventStream | Promise<AssistantMessageEventStream>;
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for the agent loop.
|
|
10
|
+
*/
|
|
11
|
+
export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
12
|
+
model: Model;
|
|
13
|
+
/**
|
|
14
|
+
* When to interrupt tool execution for steering messages.
|
|
15
|
+
* - "immediate" = check after each tool call (default)
|
|
16
|
+
* - "wait" = defer steering until the current turn completes
|
|
17
|
+
*/
|
|
18
|
+
interruptMode?: "immediate" | "wait";
|
|
19
|
+
/**
|
|
20
|
+
* Optional session identifier forwarded to LLM providers.
|
|
21
|
+
* Used by providers that support session-based caching (e.g., OpenAI code provider).
|
|
22
|
+
*/
|
|
23
|
+
sessionId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Optional resolver called per LLM request to produce request metadata.
|
|
26
|
+
* When set, the agent loop evaluates it **after** `getApiKey` resolves the
|
|
27
|
+
* session-sticky credential, ensuring the metadata's `account_uuid` reflects
|
|
28
|
+
* the credential actually used for the request (not the credential that was
|
|
29
|
+
* current when `AgentLoopConfig` was first constructed). Overrides the static
|
|
30
|
+
* `metadata` field when present.
|
|
31
|
+
*/
|
|
32
|
+
metadataResolver?: (provider: string) => Record<string, unknown> | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Converts AgentMessage[] to LLM-compatible Message[] before each LLM call.
|
|
35
|
+
*
|
|
36
|
+
* Each AgentMessage must be converted to a UserMessage, AssistantMessage, or ToolResultMessage
|
|
37
|
+
* that the LLM can understand. AgentMessages that cannot be converted (e.g., UI-only notifications,
|
|
38
|
+
* status messages) should be filtered out.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* convertToLlm: (messages) => messages.flatMap(m => {
|
|
43
|
+
* if (m.role === "custom") {
|
|
44
|
+
* // Convert custom message to user message
|
|
45
|
+
* return [{ role: "user", content: m.content, timestamp: m.timestamp }];
|
|
46
|
+
* }
|
|
47
|
+
* if (m.role === "notification") {
|
|
48
|
+
* // Filter out UI-only messages
|
|
49
|
+
* return [];
|
|
50
|
+
* }
|
|
51
|
+
* // Pass through standard LLM messages
|
|
52
|
+
* return [m];
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
convertToLlm: (messages: AgentMessage[]) => Message[] | Promise<Message[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Optional transform applied to the context before `convertToLlm`.
|
|
59
|
+
*
|
|
60
|
+
* Use this for operations that work at the AgentMessage level:
|
|
61
|
+
* - Context window management (pruning old messages)
|
|
62
|
+
* - Injecting context from external sources
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* transformContext: async (messages) => {
|
|
67
|
+
* if (estimateTokens(messages) > MAX_TOKENS) {
|
|
68
|
+
* return pruneOldMessages(messages);
|
|
69
|
+
* }
|
|
70
|
+
* return messages;
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
transformContext?: (messages: AgentMessage[], signal?: AbortSignal) => Promise<AgentMessage[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Resolves an API key dynamically for each LLM call.
|
|
77
|
+
*
|
|
78
|
+
* Useful for short-lived OAuth tokens (e.g., GitHub Copilot) that may expire
|
|
79
|
+
* during long-running tool execution phases.
|
|
80
|
+
*/
|
|
81
|
+
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Returns steering messages to inject into the conversation mid-run.
|
|
84
|
+
*
|
|
85
|
+
* Called after each tool execution to check for user interruptions unless interruptMode is "wait".
|
|
86
|
+
* If messages are returned, remaining tool calls are skipped and
|
|
87
|
+
* these messages are added to the context before the next LLM call.
|
|
88
|
+
*/
|
|
89
|
+
getSteeringMessages?: () => Promise<AgentMessage[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Returns follow-up messages to process after the agent would otherwise stop.
|
|
92
|
+
*
|
|
93
|
+
* Called when the agent has no more tool calls and no steering messages.
|
|
94
|
+
* If messages are returned, they're added to the context and the agent
|
|
95
|
+
* continues with another turn.
|
|
96
|
+
*/
|
|
97
|
+
getFollowUpMessages?: () => Promise<AgentMessage[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Hook fired right before the loop would exit.
|
|
100
|
+
*
|
|
101
|
+
* Called when the agent has no more tool calls and no steering messages,
|
|
102
|
+
* immediately before polling follow-up messages.
|
|
103
|
+
*/
|
|
104
|
+
onBeforeYield?: () => Promise<void> | void;
|
|
105
|
+
/**
|
|
106
|
+
* Provides tool execution context, resolved per tool call.
|
|
107
|
+
* Use for late-bound UI or session state access.
|
|
108
|
+
*/
|
|
109
|
+
getToolContext?: (toolCall?: ToolCallContext) => AgentToolContext | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Refreshes prompt/tool context from live session state before each model call.
|
|
112
|
+
* Use this when tool availability or the system prompt can change mid-turn.
|
|
113
|
+
*/
|
|
114
|
+
syncContextBeforeModelCall?: (context: AgentContext) => void | Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Optional transform applied to tool call arguments before execution.
|
|
117
|
+
* Use for deobfuscating secrets or rewriting arguments.
|
|
118
|
+
*/
|
|
119
|
+
transformToolCallArguments?: (args: Record<string, unknown>, toolName: string) => Record<string, unknown>;
|
|
120
|
+
/**
|
|
121
|
+
* Enable intent tracing for tool calls.
|
|
122
|
+
* When enabled, the harness injects a `string` field into tool schemas sent to the model,
|
|
123
|
+
* then strips from arguments before executing tools.
|
|
124
|
+
*/
|
|
125
|
+
intentTracing?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Append-only context mode — stabilizes system prompt + tool spec bytes
|
|
128
|
+
* across turns so provider prefix caches hit at maximum rate.
|
|
129
|
+
*
|
|
130
|
+
* When set, the loop reads messages from the append-only log (stable
|
|
131
|
+
* byte prefix) and caches system prompt + tools. Tools exclude per-turn
|
|
132
|
+
* `_i` intent fields.
|
|
133
|
+
*/
|
|
134
|
+
appendOnlyContext?: AppendOnlyContextManager;
|
|
135
|
+
/**
|
|
136
|
+
* Inspect assistant streaming events before they are published to the outer agent event stream.
|
|
137
|
+
* Callers may abort synchronously to stop consuming buffered provider events.
|
|
138
|
+
*/
|
|
139
|
+
onAssistantMessageEvent?: (message: AssistantMessage, event: AssistantMessageEvent) => void;
|
|
140
|
+
/**
|
|
141
|
+
* Called when GPT-5 Harmony protocol leakage is detected and mitigated.
|
|
142
|
+
*/
|
|
143
|
+
onHarmonyLeak?: (event: HarmonyAuditEvent) => void | Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Dynamic tool choice override, resolved per LLM call.
|
|
146
|
+
* When set and returns a value, overrides the static `toolChoice`.
|
|
147
|
+
*/
|
|
148
|
+
getToolChoice?: () => ToolChoice | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* Dynamic reasoning effort override, resolved per LLM call.
|
|
151
|
+
* When set and returns a value, overrides the static `reasoning` captured
|
|
152
|
+
* at run-loop start. Use this so mid-run thinking-level changes apply on
|
|
153
|
+
* the next model call instead of waiting for the next prompt.
|
|
154
|
+
*/
|
|
155
|
+
getReasoning?: () => Effort | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Called after a tool call has been validated and is about to execute.
|
|
158
|
+
*
|
|
159
|
+
* Return `{ block: true }` to prevent execution. The loop emits an error tool
|
|
160
|
+
* result instead (using `reason` as the error text, or a default if omitted).
|
|
161
|
+
*
|
|
162
|
+
* Mutating `context.args` in place changes the arguments passed to `tool.execute`
|
|
163
|
+
* — the loop does **not** re-validate after this hook runs.
|
|
164
|
+
*
|
|
165
|
+
* The hook receives the tool abort signal (`signal`) and is responsible for
|
|
166
|
+
* honoring it. Throwing surfaces as a tool-error result and does not abort the
|
|
167
|
+
* rest of the batch.
|
|
168
|
+
*/
|
|
169
|
+
beforeToolCall?: (context: BeforeToolCallContext, signal?: AbortSignal) => Promise<BeforeToolCallResult | undefined> | BeforeToolCallResult | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Called after a tool finishes executing, before `tool_execution_end` and the
|
|
172
|
+
* tool-result message are emitted.
|
|
173
|
+
*
|
|
174
|
+
* Return an `AfterToolCallResult` to override individual fields of the executed
|
|
175
|
+
* tool result. Omitted fields keep their original values; there is no deep merge.
|
|
176
|
+
*
|
|
177
|
+
* Throwing surfaces as a tool-error result and does not abort the rest of the batch.
|
|
178
|
+
*/
|
|
179
|
+
afterToolCall?: (context: AfterToolCallContext, signal?: AbortSignal) => Promise<AfterToolCallResult | undefined> | AfterToolCallResult | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Opt-in OpenTelemetry instrumentation. Passing `{}` enables the loop's
|
|
182
|
+
* GenAI-semantic-convention spans (`invoke_agent`, `chat`, `execute_tool`)
|
|
183
|
+
* using the global tracer provider. Leaving this field undefined disables
|
|
184
|
+
* the instrumentation entirely — the loop performs zero tracer lookups.
|
|
185
|
+
*
|
|
186
|
+
* See {@link AgentTelemetryConfig} for the full surface (hooks, content
|
|
187
|
+
* capture, cost estimator, agent identity).
|
|
188
|
+
*/
|
|
189
|
+
telemetry?: AgentTelemetryConfig;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Batch/sequencing metadata for the tool call currently being processed.
|
|
193
|
+
*/
|
|
194
|
+
export interface ToolCallContext {
|
|
195
|
+
batchId: string;
|
|
196
|
+
index: number;
|
|
197
|
+
total: number;
|
|
198
|
+
toolCalls: Array<{
|
|
199
|
+
id: string;
|
|
200
|
+
name: string;
|
|
201
|
+
}>;
|
|
202
|
+
}
|
|
203
|
+
/** A single tool-call content block emitted by an assistant message. */
|
|
204
|
+
export type AgentToolCall = Extract<AssistantMessage["content"][number], {
|
|
205
|
+
type: "toolCall";
|
|
206
|
+
}>;
|
|
207
|
+
/**
|
|
208
|
+
* Result returned from `beforeToolCall`.
|
|
209
|
+
*
|
|
210
|
+
* Set `block: true` to prevent the tool from executing. The loop emits an error tool
|
|
211
|
+
* result instead, using `reason` as the error text (or a default if omitted).
|
|
212
|
+
*
|
|
213
|
+
* Mutating the `args` reference passed in `BeforeToolCallContext` is supported and
|
|
214
|
+
* survives into execution — the loop does **not** re-validate after this hook runs.
|
|
215
|
+
*/
|
|
216
|
+
export interface BeforeToolCallResult {
|
|
217
|
+
block?: boolean;
|
|
218
|
+
reason?: string;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Partial override returned from `afterToolCall`.
|
|
222
|
+
*
|
|
223
|
+
* Merge semantics are field-by-field; omitted fields keep the executed values.
|
|
224
|
+
* No deep merge is performed.
|
|
225
|
+
*/
|
|
226
|
+
export interface AfterToolCallResult {
|
|
227
|
+
/** If provided, replaces the tool result content array in full. */
|
|
228
|
+
content?: (TextContent | ImageContent)[];
|
|
229
|
+
/** If provided, replaces the tool result details payload in full. */
|
|
230
|
+
details?: unknown;
|
|
231
|
+
/** If provided, replaces the error flag carried with the tool result. */
|
|
232
|
+
isError?: boolean;
|
|
233
|
+
}
|
|
234
|
+
/** Context passed to `beforeToolCall`. */
|
|
235
|
+
export interface BeforeToolCallContext {
|
|
236
|
+
/** The assistant message that requested the tool call. */
|
|
237
|
+
assistantMessage: AssistantMessage;
|
|
238
|
+
/** The raw tool call block from `assistantMessage.content`. */
|
|
239
|
+
toolCall: AgentToolCall;
|
|
240
|
+
/**
|
|
241
|
+
* Validated tool arguments. The same reference is forwarded to `tool.execute`
|
|
242
|
+
* (after any `transformToolCallArguments` pass), so in-place mutations stick.
|
|
243
|
+
*/
|
|
244
|
+
args: Record<string, unknown>;
|
|
245
|
+
/** Current agent context at the time the tool call is prepared. */
|
|
246
|
+
context: AgentContext;
|
|
247
|
+
}
|
|
248
|
+
/** Context passed to `afterToolCall`. */
|
|
249
|
+
export interface AfterToolCallContext {
|
|
250
|
+
/** The assistant message that requested the tool call. */
|
|
251
|
+
assistantMessage: AssistantMessage;
|
|
252
|
+
/** The raw tool call block from `assistantMessage.content`. */
|
|
253
|
+
toolCall: AgentToolCall;
|
|
254
|
+
/** Validated tool arguments used for execution (post `beforeToolCall` mutations). */
|
|
255
|
+
args: Record<string, unknown>;
|
|
256
|
+
/** The executed tool result before any `afterToolCall` overrides are applied. */
|
|
257
|
+
result: AgentToolResult<any>;
|
|
258
|
+
/** Whether the executed tool result is currently treated as an error. */
|
|
259
|
+
isError: boolean;
|
|
260
|
+
/** Current agent context at the time the tool call is finalized. */
|
|
261
|
+
context: AgentContext;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Extensible interface for custom app messages.
|
|
265
|
+
* Apps can extend via declaration merging:
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* declare module "@gajae-code/agent" {
|
|
270
|
+
* interface CustomAgentMessages {
|
|
271
|
+
* artifact: ArtifactMessage;
|
|
272
|
+
* notification: NotificationMessage;
|
|
273
|
+
* }
|
|
274
|
+
* }
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
export interface CustomAgentMessages {
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* AgentMessage: Union of LLM messages + custom messages.
|
|
281
|
+
* This abstraction allows apps to add custom message types while maintaining
|
|
282
|
+
* type safety and compatibility with the base LLM messages.
|
|
283
|
+
*/
|
|
284
|
+
export type AgentMessage = Message | CustomAgentMessages[keyof CustomAgentMessages];
|
|
285
|
+
/**
|
|
286
|
+
* Agent state containing all configuration and conversation data.
|
|
287
|
+
*/
|
|
288
|
+
export interface AgentState {
|
|
289
|
+
systemPrompt: string[];
|
|
290
|
+
model: Model;
|
|
291
|
+
thinkingLevel?: Effort;
|
|
292
|
+
tools: AgentTool<any>[];
|
|
293
|
+
messages: AgentMessage[];
|
|
294
|
+
isStreaming: boolean;
|
|
295
|
+
streamMessage: AgentMessage | null;
|
|
296
|
+
pendingToolCalls: Set<string>;
|
|
297
|
+
error?: string;
|
|
298
|
+
}
|
|
299
|
+
export interface AgentToolResult<T = any, _TInput = unknown> {
|
|
300
|
+
content: (TextContent | ImageContent)[];
|
|
301
|
+
details?: T;
|
|
302
|
+
isError?: boolean;
|
|
303
|
+
}
|
|
304
|
+
export type AgentToolUpdateCallback<T = any, TInput = unknown> = (partialResult: AgentToolResult<T, TInput>) => void;
|
|
305
|
+
/** Options passed to renderResult */
|
|
306
|
+
export interface RenderResultOptions {
|
|
307
|
+
/** Whether the result view is expanded */
|
|
308
|
+
expanded: boolean;
|
|
309
|
+
/** Whether this is a partial/streaming result */
|
|
310
|
+
isPartial: boolean;
|
|
311
|
+
/** Current spinner frame index for animated elements (optional) */
|
|
312
|
+
spinnerFrame?: number;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Context passed to tool execution.
|
|
316
|
+
* Apps can extend via declaration merging.
|
|
317
|
+
*/
|
|
318
|
+
export interface AgentToolContext {
|
|
319
|
+
}
|
|
320
|
+
export type AgentToolExecFn<TParameters extends TSchema = TSchema, TDetails = any, TTheme = unknown> = (this: AgentTool<TParameters, TDetails, TTheme>, toolCallId: string, params: Static<TParameters>, signal?: AbortSignal, onUpdate?: AgentToolUpdateCallback<TDetails, TParameters>, context?: AgentToolContext) => Promise<AgentToolResult<TDetails, TParameters>>;
|
|
321
|
+
export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any, TTheme = unknown> extends Tool<TParameters> {
|
|
322
|
+
label: string;
|
|
323
|
+
/** If true, tool is excluded unless explicitly listed in --tools or agent's tools field */
|
|
324
|
+
hidden?: boolean;
|
|
325
|
+
/** If true, tool can stage a pending action that requires explicit resolution via the resolve tool. */
|
|
326
|
+
deferrable?: boolean;
|
|
327
|
+
/** Built-in tool loading behavior. "essential" loads initially; "discoverable" can be activated by tool search. */
|
|
328
|
+
loadMode?: "essential" | "discoverable";
|
|
329
|
+
/** Short one-line summary used for tool discovery indexes. */
|
|
330
|
+
summary?: string;
|
|
331
|
+
/** If true, tool execution ignores abort signals (runs to completion) */
|
|
332
|
+
nonAbortable?: boolean;
|
|
333
|
+
/**
|
|
334
|
+
* Concurrency mode for tool scheduling when multiple calls are in one turn.
|
|
335
|
+
* - "shared": can run alongside other shared tools (default)
|
|
336
|
+
* - "exclusive": runs alone; other tools wait until it finishes
|
|
337
|
+
*/
|
|
338
|
+
concurrency?: "shared" | "exclusive";
|
|
339
|
+
/** If true, argument validation errors are non-fatal: raw args are passed to execute() instead of returning an error to the LLM. */
|
|
340
|
+
lenientArgValidation?: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Controls how the INTENT_FIELD (`_i`) is handled for this tool.
|
|
343
|
+
* - `"require"` (default): `_i` is injected and required in the parameter schema.
|
|
344
|
+
* - `"optional"`: `_i` is injected as an optional/nullable field.
|
|
345
|
+
* - `"omit"`: `_i` is NOT injected. Use for tools where intent is obvious (yield, resolve, todo_write, …).
|
|
346
|
+
* - function: `_i` is NOT injected; intent is derived dynamically from (potentially partial / streaming) args.
|
|
347
|
+
*/
|
|
348
|
+
intent?: "omit" | "optional" | "require" | ((args: Partial<Static<TParameters>>) => string | undefined);
|
|
349
|
+
/** The main execution callback for this tool. */
|
|
350
|
+
execute: AgentToolExecFn<TParameters, TDetails, TTheme>;
|
|
351
|
+
/** Optional custom rendering for tool call display (returns UI component) */
|
|
352
|
+
renderCall?: (args: Static<TParameters>, options: RenderResultOptions, theme: TTheme) => unknown;
|
|
353
|
+
/** Optional custom rendering for tool result display (returns UI component) */
|
|
354
|
+
renderResult?: (result: AgentToolResult<TDetails, TParameters>, options: RenderResultOptions, theme: TTheme) => unknown;
|
|
355
|
+
}
|
|
356
|
+
export interface AgentContext {
|
|
357
|
+
systemPrompt: string[];
|
|
358
|
+
messages: AgentMessage[];
|
|
359
|
+
tools?: AgentTool<any>[];
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Events emitted by the Agent for UI updates.
|
|
363
|
+
* These events provide fine-grained lifecycle information for messages, turns, and tool executions.
|
|
364
|
+
*/
|
|
365
|
+
export type AgentEvent = {
|
|
366
|
+
type: "agent_start";
|
|
367
|
+
} | {
|
|
368
|
+
type: "agent_end";
|
|
369
|
+
messages: AgentMessage[];
|
|
370
|
+
/** Present iff `AgentTelemetryConfig` was supplied on this run. */
|
|
371
|
+
telemetry?: AgentRunSummary;
|
|
372
|
+
coverage?: AgentRunCoverage;
|
|
373
|
+
} | {
|
|
374
|
+
type: "turn_start";
|
|
375
|
+
} | {
|
|
376
|
+
type: "turn_end";
|
|
377
|
+
message: AgentMessage;
|
|
378
|
+
toolResults: ToolResultMessage[];
|
|
379
|
+
} | {
|
|
380
|
+
type: "message_start";
|
|
381
|
+
message: AgentMessage;
|
|
382
|
+
} | {
|
|
383
|
+
type: "message_update";
|
|
384
|
+
message: AgentMessage;
|
|
385
|
+
assistantMessageEvent: AssistantMessageEvent;
|
|
386
|
+
} | {
|
|
387
|
+
type: "message_end";
|
|
388
|
+
message: AgentMessage;
|
|
389
|
+
} | {
|
|
390
|
+
type: "tool_execution_start";
|
|
391
|
+
toolCallId: string;
|
|
392
|
+
toolName: string;
|
|
393
|
+
args: any;
|
|
394
|
+
intent?: string;
|
|
395
|
+
} | {
|
|
396
|
+
type: "tool_execution_update";
|
|
397
|
+
toolCallId: string;
|
|
398
|
+
toolName: string;
|
|
399
|
+
args: any;
|
|
400
|
+
partialResult: any;
|
|
401
|
+
} | {
|
|
402
|
+
type: "tool_execution_end";
|
|
403
|
+
toolCallId: string;
|
|
404
|
+
toolName: string;
|
|
405
|
+
result: any;
|
|
406
|
+
isError?: boolean;
|
|
407
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@gajae-code/agent-core",
|
|
4
|
+
"version": "0.1.1",
|
|
5
|
+
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
6
|
+
"homepage": "https://gajae-code.dev",
|
|
7
|
+
"author": "Can Boluk",
|
|
8
|
+
"contributors": [
|
|
9
|
+
"Mario Zechner"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/gajae-ai/gajae-code.git",
|
|
15
|
+
"directory": "packages/agent"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/gajae-ai/gajae-code/issues"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"ai",
|
|
22
|
+
"agent",
|
|
23
|
+
"llm",
|
|
24
|
+
"transport",
|
|
25
|
+
"state-management"
|
|
26
|
+
],
|
|
27
|
+
"main": "./src/index.ts",
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"check": "biome check . && bun run check:types",
|
|
31
|
+
"check:types": "tsgo -p tsconfig.json --noEmit",
|
|
32
|
+
"lint": "biome lint .",
|
|
33
|
+
"test": "bun test",
|
|
34
|
+
"fix": "biome check --write --unsafe .",
|
|
35
|
+
"fmt": "biome format --write ."
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@gajae-code/ai": "0.1.1",
|
|
39
|
+
"@gajae-code/natives": "0.1.1",
|
|
40
|
+
"@gajae-code/utils": "0.1.1",
|
|
41
|
+
"@opentelemetry/api": "^1.9.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@opentelemetry/context-async-hooks": "^2.0.0",
|
|
45
|
+
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
46
|
+
"@types/bun": "^1.3.14"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"bun": ">=1.3.14"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"src",
|
|
53
|
+
"README.md",
|
|
54
|
+
"CHANGELOG.md",
|
|
55
|
+
"dist/types"
|
|
56
|
+
],
|
|
57
|
+
"exports": {
|
|
58
|
+
".": {
|
|
59
|
+
"types": "./dist/types/index.d.ts",
|
|
60
|
+
"import": "./src/index.ts"
|
|
61
|
+
},
|
|
62
|
+
"./compaction": {
|
|
63
|
+
"types": "./dist/types/compaction.d.ts",
|
|
64
|
+
"import": "./src/compaction.ts"
|
|
65
|
+
},
|
|
66
|
+
"./compaction/*": {
|
|
67
|
+
"types": "./dist/types/compaction/*.d.ts",
|
|
68
|
+
"import": "./src/compaction/*.ts"
|
|
69
|
+
},
|
|
70
|
+
"./*": {
|
|
71
|
+
"types": "./dist/types/*.d.ts",
|
|
72
|
+
"import": "./src/*.ts"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|