@sayknow-cli/agent-core 0.4.1 → 0.4.3

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.
@@ -0,0 +1,526 @@
1
+ import type { AssistantMessage, AssistantMessageEvent, AssistantMessageEventStream, Effort, ImageContent, Message, Model, SimpleStreamOptions, Static, streamSimple, TextContent, Tool, ToolChoice, ToolResultMessage, TransportFailureFacts, TSchema } from "@sayknow-cli/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
+ /** Stable identifier for a managed logical run, shared by all of its retry attempts. */
9
+ export type ManagedLogicalRunId = number;
10
+ /** Terminal completion requested for a logical run. */
11
+ export interface RunTerminalRequest {
12
+ stopReason: "cancelled" | "error" | "exhausted";
13
+ messages?: AgentMessage[];
14
+ }
15
+ /**
16
+ * Ownership token supplied when Agent invokes a retry continuation.
17
+ *
18
+ * A continuation MUST verify `isCurrent()` immediately before starting a
19
+ * follow-up invocation and abandon the retry when it returns false. The token
20
+ * becomes invalid when its originating run is force-aborted or superseded.
21
+ * Coding-agent retry continuations must accept this argument and must not call
22
+ * `agent.continue()` after ownership has been lost.
23
+ */
24
+ export interface ManagedAttemptContinuationOwnership {
25
+ /** Per-attempt run-loop id; use only for attempt-local ownership checks. */
26
+ readonly runId: number;
27
+ /** Stable managed logical-run id; use for all terminal completion requests. */
28
+ readonly logicalRunId: ManagedLogicalRunId;
29
+ readonly generation: number;
30
+ isCurrent(): boolean;
31
+ }
32
+ /** Runs after a discarded attempt is idle, only while its ownership token remains current. */
33
+ export type ManagedAttemptContinuation = (ownership: ManagedAttemptContinuationOwnership) => void | Promise<void>;
34
+ /** Decision returned by managed fallback policy for one provisional attempt. */
35
+ export type ManagedAttemptDecision = {
36
+ type: "retry";
37
+ continuation: ManagedAttemptContinuation;
38
+ } | {
39
+ type: "maintenance";
40
+ continuation: ManagedAttemptContinuation;
41
+ } | {
42
+ type: "terminal";
43
+ terminal: RunTerminalRequest;
44
+ };
45
+ /** Structured result for one managed upstream invocation. */
46
+ export type ManagedAttemptOutcome = {
47
+ type: "retryable_discarded";
48
+ failure: {
49
+ message: AssistantMessage;
50
+ /** Exact provider transport facts, including retry headers, for fallback policy. */
51
+ transportFailure?: TransportFailureFacts;
52
+ };
53
+ } | {
54
+ type: "context_overflow_discarded";
55
+ message: AssistantMessage;
56
+ } | {
57
+ type: "run_terminal";
58
+ reason: "cancelled" | "error" | "exhausted";
59
+ };
60
+ export type ManagedAttemptOutcomeHandler = (outcome: ManagedAttemptOutcome) => ManagedAttemptDecision | Promise<ManagedAttemptDecision>;
61
+ /**
62
+ * Outcome of a cooperative mid-run context-maintenance checkpoint (see
63
+ * {@link AgentLoopConfig.maintainContext}). Any value other than "not-needed"
64
+ * means the checkpoint mutated (or attempted to mutate) durable context, so the
65
+ * loop ends the current run without the lossy `agent_end` finalization and the
66
+ * maintenance owner resumes the run on the rewritten context.
67
+ */
68
+ export type MidRunMaintenanceOutcome = "not-needed" | "pruned" | "compacted" | "promoted" | "failed" | "aborted";
69
+ /**
70
+ * Configuration for the agent loop.
71
+ */
72
+ export interface AgentLoopConfig extends SimpleStreamOptions {
73
+ model: Model;
74
+ /**
75
+ * Supplies a fresh opaque token at each concrete managed transport invocation.
76
+ * The callback runs at the stream boundary so controller accounting matches
77
+ * upstream request count, including multi-step tool turns.
78
+ */
79
+ nextFallbackAttempt?: (model: Model) => SimpleStreamOptions["fallbackAttempt"];
80
+ /** Called after a managed upstream request is accepted and committed. */
81
+ onManagedAttemptAccepted?: () => void | Promise<void>;
82
+ /** Receives a managed invocation outcome without publishing provisional lifecycle events. */
83
+ onManagedAttemptOutcome?: ManagedAttemptOutcomeHandler;
84
+ /**
85
+ * When to interrupt tool execution for steering messages.
86
+ * - "immediate" = check after each tool call (default)
87
+ * - "wait" = defer steering until the current turn completes
88
+ */
89
+ interruptMode?: "immediate" | "wait";
90
+ /**
91
+ * Optional session identifier forwarded to LLM providers.
92
+ * Used by providers that support session-based caching (e.g., OpenAI code provider).
93
+ */
94
+ sessionId?: string;
95
+ /**
96
+ * Optional provider-facing cache/session affinity identifier. When set, this
97
+ * is forwarded to providers as StreamOptions.sessionId while `sessionId`
98
+ * remains the logical agent conversation id for telemetry/metadata.
99
+ */
100
+ providerSessionId?: string;
101
+ /**
102
+ * Optional resolver called per LLM request to produce request metadata.
103
+ * When set, the agent loop evaluates it **after** `getApiKey` resolves the
104
+ * session-sticky credential, ensuring the metadata's `account_uuid` reflects
105
+ * the credential actually used for the request (not the credential that was
106
+ * current when `AgentLoopConfig` was first constructed). Overrides the static
107
+ * `metadata` field when present.
108
+ */
109
+ metadataResolver?: (provider: string) => Record<string, unknown> | undefined;
110
+ /**
111
+ * Converts AgentMessage[] to LLM-compatible Message[] before each LLM call.
112
+ *
113
+ * Each AgentMessage must be converted to a UserMessage, AssistantMessage, or ToolResultMessage
114
+ * that the LLM can understand. AgentMessages that cannot be converted (e.g., UI-only notifications,
115
+ * status messages) should be filtered out.
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * convertToLlm: (messages) => messages.flatMap(m => {
120
+ * if (m.role === "custom") {
121
+ * // Convert custom message to user message
122
+ * return [{ role: "user", content: m.content, timestamp: m.timestamp }];
123
+ * }
124
+ * if (m.role === "notification") {
125
+ * // Filter out UI-only messages
126
+ * return [];
127
+ * }
128
+ * // Pass through standard LLM messages
129
+ * return [m];
130
+ * })
131
+ * ```
132
+ */
133
+ convertToLlm: (messages: AgentMessage[]) => Message[] | Promise<Message[]>;
134
+ /**
135
+ * Optional transform applied to the context before `convertToLlm`.
136
+ *
137
+ * Use this for operations that work at the AgentMessage level:
138
+ * - Context window management (pruning old messages)
139
+ * - Injecting context from external sources
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * transformContext: async (messages) => {
144
+ * if (estimateTokens(messages) > MAX_TOKENS) {
145
+ * return pruneOldMessages(messages);
146
+ * }
147
+ * return messages;
148
+ * }
149
+ * ```
150
+ */
151
+ transformContext?: (messages: AgentMessage[], signal?: AbortSignal) => Promise<AgentMessage[]>;
152
+ /**
153
+ * Resolves an API key dynamically for each LLM call.
154
+ *
155
+ * Useful for short-lived OAuth tokens (e.g., GitHub Copilot) that may expire
156
+ * during long-running tool execution phases.
157
+ */
158
+ getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
159
+ /** Returns the credential type selected by the most recent getApiKey call for this session/provider. */
160
+ getAuthCredentialType?: (provider: string) => "api_key" | "oauth" | undefined;
161
+ /**
162
+ * Returns steering messages to inject into the conversation mid-run.
163
+ *
164
+ * Called after each tool execution to check for user interruptions unless interruptMode is "wait".
165
+ * If messages are returned, remaining tool calls are skipped and
166
+ * these messages are added to the context before the next LLM call.
167
+ */
168
+ getSteeringMessages?: () => Promise<AgentMessage[]>;
169
+ /**
170
+ * Returns follow-up messages to process after the agent would otherwise stop.
171
+ *
172
+ * Called when the agent has no more tool calls and no steering messages.
173
+ * If messages are returned, they're added to the context and the agent
174
+ * continues with another turn.
175
+ */
176
+ getFollowUpMessages?: () => Promise<AgentMessage[]>;
177
+ /**
178
+ * Cooperative pause checkpoint evaluated at safe loop boundaries.
179
+ *
180
+ * Called after completed tool execution has been emitted and before the loop
181
+ * polls steering/follow-up queues or schedules another assistant response.
182
+ * Returning true ends the current loop with `agent_end.stopReason === "paused"`
183
+ * without aborting any in-flight model or tool work.
184
+ */
185
+ shouldPause?: () => boolean;
186
+ /**
187
+ * Hook fired right before the loop would exit.
188
+ *
189
+ * Called when the agent has no more tool calls and no steering messages,
190
+ * immediately before polling follow-up messages.
191
+ */
192
+ onBeforeYield?: () => Promise<void> | void;
193
+ /**
194
+ * Provides tool execution context, resolved per tool call.
195
+ * Use for late-bound UI or session state access.
196
+ */
197
+ getToolContext?: (toolCall?: ToolCallContext) => AgentToolContext | undefined;
198
+ /**
199
+ * Refreshes prompt/tool context from live session state before each model call.
200
+ * Use this when tool availability or the system prompt can change mid-turn.
201
+ */
202
+ syncContextBeforeModelCall?: (context: AgentContext) => void | Promise<void>;
203
+ /**
204
+ * Cooperative mid-run context-maintenance checkpoint.
205
+ *
206
+ * Invoked at the top of every loop iteration AFTER pending tool-result /
207
+ * steering messages have been materialized into durable context and BEFORE
208
+ * {@link syncContextBeforeModelCall} and the model call. This is the only
209
+ * boundary where the full unsent context (tool results + dequeued steering)
210
+ * is already durable, so a long uninterrupted tool loop can be bounded here
211
+ * before it grows past the provider window.
212
+ *
213
+ * The callback owns the maintenance decision (prune / compact / promote) and
214
+ * receives the minimal cancellation-aware lifecycle: `signal` is the
215
+ * non-optional loop signal, and `awaitEventDrain(invocationSignal)` waits for
216
+ * prior event consumer bodies with loop and invocation cancellation composed.
217
+ * Any outcome other than "not-needed" ends the current run with
218
+ * `agent_end.stopReason === "maintenance"` (NOT the lossy pause / completed
219
+ * finalization); the callback's continuation owner resumes the run on the
220
+ * rewritten context.
221
+ */
222
+ maintainContext?: (context: AgentContext, lifecycle: {
223
+ signal: AbortSignal;
224
+ awaitEventDrain: (invocationSignal: AbortSignal) => Promise<void>;
225
+ }) => Promise<MidRunMaintenanceOutcome> | MidRunMaintenanceOutcome;
226
+ /**
227
+ * Optional transform applied to tool call arguments before execution.
228
+ * Use for deobfuscating secrets or rewriting arguments.
229
+ */
230
+ transformToolCallArguments?: (args: Record<string, unknown>, toolName: string) => Record<string, unknown>;
231
+ /**
232
+ * Enable intent tracing for tool calls.
233
+ * When enabled, the harness injects a `string` field into tool schemas sent to the model,
234
+ * then strips from arguments before executing tools.
235
+ */
236
+ intentTracing?: boolean;
237
+ /**
238
+ * Append-only context mode — stabilizes system prompt + tool spec bytes
239
+ * across turns so provider prefix caches hit at maximum rate.
240
+ *
241
+ * When set, the loop reads messages from the append-only log (stable
242
+ * byte prefix) and caches system prompt + tools. Tools exclude per-turn
243
+ * `_i` intent fields.
244
+ */
245
+ appendOnlyContext?: AppendOnlyContextManager;
246
+ /**
247
+ * Inspect assistant streaming events before they are published to the outer agent event stream.
248
+ * Callers may abort synchronously to stop consuming buffered provider events.
249
+ */
250
+ onAssistantMessageEvent?: (message: AssistantMessage, event: AssistantMessageEvent) => void;
251
+ /** Called for non-content tool-choice incapability stream events. */
252
+ onToolChoiceIncapability?: (event: Extract<AssistantMessageEvent, {
253
+ type: "toolChoiceIncapability";
254
+ }>) => void;
255
+ /**
256
+ * Called when GPT-5 Harmony protocol leakage is detected and mitigated.
257
+ */
258
+ onHarmonyLeak?: (event: HarmonyAuditEvent) => void | Promise<void>;
259
+ /**
260
+ * Dynamic tool choice override, resolved per LLM call.
261
+ * When set and returns a value, overrides the static `toolChoice`.
262
+ */
263
+ getToolChoice?: () => ToolChoice | undefined;
264
+ /**
265
+ * Dynamic reasoning effort override, resolved per LLM call.
266
+ * When set and returns a value, overrides the static `reasoning` captured
267
+ * at run-loop start. Use this so mid-run thinking-level changes apply on
268
+ * the next model call instead of waiting for the next prompt.
269
+ */
270
+ getReasoning?: () => Effort | undefined;
271
+ /**
272
+ * Called after a tool call has been validated and is about to execute.
273
+ *
274
+ * Return `{ block: true }` to prevent execution. The loop emits an error tool
275
+ * result instead (using `reason` as the error text, or a default if omitted).
276
+ *
277
+ * Mutating `context.args` in place changes the arguments passed to `tool.execute`
278
+ * — the loop does **not** re-validate after this hook runs.
279
+ *
280
+ * The hook receives the tool abort signal (`signal`) and is responsible for
281
+ * honoring it. Throwing surfaces as a tool-error result and does not abort the
282
+ * rest of the batch.
283
+ */
284
+ beforeToolCall?: (context: BeforeToolCallContext, signal?: AbortSignal) => Promise<BeforeToolCallResult | undefined> | BeforeToolCallResult | undefined;
285
+ /**
286
+ * Called after a tool finishes executing, before `tool_execution_end` and the
287
+ * tool-result message are emitted.
288
+ *
289
+ * Return an `AfterToolCallResult` to override individual fields of the executed
290
+ * tool result. Omitted fields keep their original values; there is no deep merge.
291
+ *
292
+ * Throwing surfaces as a tool-error result and does not abort the rest of the batch.
293
+ */
294
+ afterToolCall?: (context: AfterToolCallContext, signal?: AbortSignal) => Promise<AfterToolCallResult | undefined> | AfterToolCallResult | undefined;
295
+ /**
296
+ * Opt-in OpenTelemetry instrumentation. Passing `{}` enables the loop's
297
+ * GenAI-semantic-convention spans (`invoke_agent`, `chat`, `execute_tool`)
298
+ * using the global tracer provider. Leaving this field undefined disables
299
+ * the instrumentation entirely — the loop performs zero tracer lookups.
300
+ *
301
+ * See {@link AgentTelemetryConfig} for the full surface (hooks, content
302
+ * capture, cost estimator, agent identity).
303
+ */
304
+ telemetry?: AgentTelemetryConfig;
305
+ }
306
+ /**
307
+ * Batch/sequencing metadata for the tool call currently being processed.
308
+ */
309
+ export interface ToolCallContext {
310
+ batchId: string;
311
+ index: number;
312
+ total: number;
313
+ toolCalls: Array<{
314
+ id: string;
315
+ name: string;
316
+ }>;
317
+ }
318
+ /** A single tool-call content block emitted by an assistant message. */
319
+ export type AgentToolCall = Extract<AssistantMessage["content"][number], {
320
+ type: "toolCall";
321
+ }>;
322
+ /**
323
+ * Result returned from `beforeToolCall`.
324
+ *
325
+ * Set `block: true` to prevent the tool from executing. The loop emits an error tool
326
+ * result instead, using `reason` as the error text (or a default if omitted).
327
+ *
328
+ * Mutating the `args` reference passed in `BeforeToolCallContext` is supported and
329
+ * survives into execution — the loop does **not** re-validate after this hook runs.
330
+ */
331
+ export interface BeforeToolCallResult {
332
+ block?: boolean;
333
+ reason?: string;
334
+ }
335
+ /**
336
+ * Partial override returned from `afterToolCall`.
337
+ *
338
+ * Merge semantics are field-by-field; omitted fields keep the executed values.
339
+ * No deep merge is performed.
340
+ */
341
+ export interface AfterToolCallResult {
342
+ /** If provided, replaces the tool result content array in full. */
343
+ content?: (TextContent | ImageContent)[];
344
+ /** If provided, replaces the tool result details payload in full. */
345
+ details?: unknown;
346
+ /** If provided, replaces the error flag carried with the tool result. */
347
+ isError?: boolean;
348
+ }
349
+ /** Context passed to `beforeToolCall`. */
350
+ export interface BeforeToolCallContext {
351
+ /** The assistant message that requested the tool call. */
352
+ assistantMessage: AssistantMessage;
353
+ /** The raw tool call block from `assistantMessage.content`. */
354
+ toolCall: AgentToolCall;
355
+ /**
356
+ * Validated tool arguments. The same reference is forwarded to `tool.execute`
357
+ * (after any `transformToolCallArguments` pass), so in-place mutations stick.
358
+ */
359
+ args: Record<string, unknown>;
360
+ /** Current agent context at the time the tool call is prepared. */
361
+ context: AgentContext;
362
+ }
363
+ /** Context passed to `afterToolCall`. */
364
+ export interface AfterToolCallContext {
365
+ /** The assistant message that requested the tool call. */
366
+ assistantMessage: AssistantMessage;
367
+ /** The raw tool call block from `assistantMessage.content`. */
368
+ toolCall: AgentToolCall;
369
+ /** Validated tool arguments used for execution (post `beforeToolCall` mutations). */
370
+ args: Record<string, unknown>;
371
+ /** The executed tool result before any `afterToolCall` overrides are applied. */
372
+ result: AgentToolResult<any>;
373
+ /** Whether the executed tool result is currently treated as an error. */
374
+ isError: boolean;
375
+ /** Current agent context at the time the tool call is finalized. */
376
+ context: AgentContext;
377
+ }
378
+ /**
379
+ * Extensible interface for custom app messages.
380
+ * Apps can extend via declaration merging:
381
+ *
382
+ * @example
383
+ * ```typescript
384
+ * declare module "@sayknow-cli/agent" {
385
+ * interface CustomAgentMessages {
386
+ * artifact: ArtifactMessage;
387
+ * notification: NotificationMessage;
388
+ * }
389
+ * }
390
+ * ```
391
+ */
392
+ export interface CustomAgentMessages {
393
+ }
394
+ /**
395
+ * AgentMessage: Union of LLM messages + custom messages.
396
+ * This abstraction allows apps to add custom message types while maintaining
397
+ * type safety and compatibility with the base LLM messages.
398
+ */
399
+ export type AgentMessage = Message | CustomAgentMessages[keyof CustomAgentMessages];
400
+ /**
401
+ * Agent state containing all configuration and conversation data.
402
+ */
403
+ export interface AgentState {
404
+ systemPrompt: string[];
405
+ model: Model | undefined;
406
+ thinkingLevel?: Effort;
407
+ tools: AgentTool<any>[];
408
+ messages: AgentMessage[];
409
+ isStreaming: boolean;
410
+ streamMessage: AgentMessage | null;
411
+ pendingToolCalls: Set<string>;
412
+ error?: string;
413
+ }
414
+ export interface AgentToolResult<T = any, _TInput = unknown> {
415
+ content: (TextContent | ImageContent)[];
416
+ details?: T;
417
+ isError?: boolean;
418
+ }
419
+ export type AgentToolUpdateCallback<T = any, TInput = unknown> = (partialResult: AgentToolResult<T, TInput>) => void;
420
+ /** Options passed to renderResult */
421
+ export interface RenderResultOptions {
422
+ /** Whether the result view is expanded */
423
+ expanded: boolean;
424
+ /** Whether this is a partial/streaming result */
425
+ isPartial: boolean;
426
+ /** Current spinner frame index for animated elements (optional) */
427
+ spinnerFrame?: number;
428
+ }
429
+ /**
430
+ * Context passed to tool execution.
431
+ * Apps can extend via declaration merging.
432
+ */
433
+ export interface AgentToolContext {
434
+ }
435
+ 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>>;
436
+ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any, TTheme = unknown> extends Tool<TParameters> {
437
+ label: string;
438
+ /** If true, tool is excluded unless explicitly listed in --tools or agent's tools field */
439
+ hidden?: boolean;
440
+ /** If true, tool can stage a pending action that requires explicit resolution via the resolve tool. */
441
+ deferrable?: boolean;
442
+ /** Built-in tool loading behavior. "essential" loads initially; "discoverable" can be activated by tool search. */
443
+ loadMode?: "essential" | "discoverable";
444
+ /** Short one-line summary used for tool discovery indexes. */
445
+ summary?: string;
446
+ /** If true, tool execution ignores abort signals (runs to completion) */
447
+ nonAbortable?: boolean;
448
+ /**
449
+ * Concurrency mode for tool scheduling when multiple calls are in one turn.
450
+ * - "shared": can run alongside other shared tools (default)
451
+ * - "exclusive": runs alone; other tools wait until it finishes
452
+ */
453
+ concurrency?: "shared" | "exclusive";
454
+ /** If true, argument validation errors are non-fatal: raw args are passed to execute() instead of returning an error to the LLM. */
455
+ lenientArgValidation?: boolean;
456
+ /**
457
+ * Controls how the INTENT_FIELD (`_i`) is handled for this tool.
458
+ * - `"require"` (default): `_i` is injected and required in the parameter schema.
459
+ * - `"optional"`: `_i` is injected as an optional/nullable field.
460
+ * - `"omit"`: `_i` is NOT injected. Use for tools where intent is obvious (yield, resolve, todo_write, …).
461
+ * - function: `_i` is NOT injected; intent is derived dynamically from (potentially partial / streaming) args.
462
+ */
463
+ intent?: "omit" | "optional" | "require" | ((args: Partial<Static<TParameters>>) => string | undefined);
464
+ /** The main execution callback for this tool. */
465
+ execute: AgentToolExecFn<TParameters, TDetails, TTheme>;
466
+ /** Optional custom rendering for tool call display (returns UI component) */
467
+ renderCall?: (args: Static<TParameters>, options: RenderResultOptions, theme: TTheme) => unknown;
468
+ /** Optional custom rendering for tool result display (returns UI component) */
469
+ renderResult?: (result: AgentToolResult<TDetails, TParameters>, options: RenderResultOptions, theme: TTheme) => unknown;
470
+ }
471
+ export interface AgentContext {
472
+ systemPrompt: string[];
473
+ messages: AgentMessage[];
474
+ tools?: AgentTool<any>[];
475
+ }
476
+ /**
477
+ * Events emitted by the Agent for UI updates.
478
+ * These events provide fine-grained lifecycle information for messages, turns, and tool executions.
479
+ */
480
+ export type AgentEvent = {
481
+ type: "agent_start";
482
+ } | {
483
+ type: "agent_end";
484
+ messages: AgentMessage[];
485
+ /** Indicates whether the loop ended normally, suspended, cancelled, or entered maintenance. */
486
+ stopReason?: "completed" | "paused" | "cancelled" | "maintenance";
487
+ /** Present iff `stopReason === "maintenance"`; the maintenance outcome. */
488
+ maintenanceOutcome?: MidRunMaintenanceOutcome;
489
+ /** Present iff `AgentTelemetryConfig` was supplied on this run. */
490
+ telemetry?: AgentRunSummary;
491
+ coverage?: AgentRunCoverage;
492
+ } | {
493
+ type: "turn_start";
494
+ } | {
495
+ type: "turn_end";
496
+ message: AgentMessage;
497
+ toolResults: ToolResultMessage[];
498
+ } | {
499
+ type: "message_start";
500
+ message: AgentMessage;
501
+ } | {
502
+ type: "message_update";
503
+ message: AgentMessage;
504
+ assistantMessageEvent: AssistantMessageEvent;
505
+ } | {
506
+ type: "message_end";
507
+ message: AgentMessage;
508
+ } | {
509
+ type: "tool_execution_start";
510
+ toolCallId: string;
511
+ toolName: string;
512
+ args: any;
513
+ intent?: string;
514
+ } | {
515
+ type: "tool_execution_update";
516
+ toolCallId: string;
517
+ toolName: string;
518
+ args: any;
519
+ partialResult: any;
520
+ } | {
521
+ type: "tool_execution_end";
522
+ toolCallId: string;
523
+ toolName: string;
524
+ result: any;
525
+ isError?: boolean;
526
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@sayknow-cli/agent-core",
4
- "version": "0.4.1",
4
+ "version": "0.4.3",
5
5
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
6
6
  "homepage": "https://sayknow-cli.com",
7
7
  "author": "jaybeyond",
@@ -25,7 +25,7 @@
25
25
  "state-management"
26
26
  ],
27
27
  "main": "./src/index.ts",
28
- "types": "./src/index.ts",
28
+ "types": "./dist/types/index.d.ts",
29
29
  "scripts": {
30
30
  "check": "biome check . && bun run check:types",
31
31
  "check:types": "tsgo -p tsconfig.json --noEmit",
@@ -35,9 +35,9 @@
35
35
  "fmt": "biome format --write ."
36
36
  },
37
37
  "dependencies": {
38
- "@sayknow-cli/ai": "0.4.1",
39
- "@sayknow-cli/natives": "0.4.1",
40
- "@sayknow-cli/utils": "0.4.1",
38
+ "@sayknow-cli/ai": "0.4.3",
39
+ "@sayknow-cli/natives": "0.4.3",
40
+ "@sayknow-cli/utils": "0.4.3",
41
41
  "@opentelemetry/api": "^1.9.0"
42
42
  },
43
43
  "devDependencies": {
@@ -51,23 +51,24 @@
51
51
  "files": [
52
52
  "src",
53
53
  "README.md",
54
- "CHANGELOG.md"
54
+ "CHANGELOG.md",
55
+ "dist/types"
55
56
  ],
56
57
  "exports": {
57
58
  ".": {
58
- "types": "./src/index.ts",
59
+ "types": "./dist/types/index.d.ts",
59
60
  "import": "./src/index.ts"
60
61
  },
61
62
  "./compaction": {
62
- "types": "./src/compaction.ts",
63
+ "types": "./dist/types/compaction.d.ts",
63
64
  "import": "./src/compaction.ts"
64
65
  },
65
66
  "./compaction/*": {
66
- "types": "./src/compaction/*.ts",
67
+ "types": "./dist/types/compaction/*.d.ts",
67
68
  "import": "./src/compaction/*.ts"
68
69
  },
69
70
  "./*": {
70
- "types": "./src/*.ts",
71
+ "types": "./dist/types/*.d.ts",
71
72
  "import": "./src/*.ts"
72
73
  }
73
74
  }