agentenkit 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.
- package/LICENSE +21 -0
- package/README.md +226 -0
- package/dist/adapters/inline.d.ts +27 -0
- package/dist/adapters/inline.d.ts.map +1 -0
- package/dist/adapters/inline.js +41 -0
- package/dist/adapters/inline.js.map +1 -0
- package/dist/adapters/memory.d.ts +74 -0
- package/dist/adapters/memory.d.ts.map +1 -0
- package/dist/adapters/memory.js +194 -0
- package/dist/adapters/memory.js.map +1 -0
- package/dist/adapters/prisma.d.ts +176 -0
- package/dist/adapters/prisma.d.ts.map +1 -0
- package/dist/adapters/prisma.js +107 -0
- package/dist/adapters/prisma.js.map +1 -0
- package/dist/adapters/qstash.d.ts +36 -0
- package/dist/adapters/qstash.d.ts.map +1 -0
- package/dist/adapters/qstash.js +26 -0
- package/dist/adapters/qstash.js.map +1 -0
- package/dist/adapters/redis.d.ts +49 -0
- package/dist/adapters/redis.d.ts.map +1 -0
- package/dist/adapters/redis.js +60 -0
- package/dist/adapters/redis.js.map +1 -0
- package/dist/adapters/sqlite.d.ts +67 -0
- package/dist/adapters/sqlite.d.ts.map +1 -0
- package/dist/adapters/sqlite.js +199 -0
- package/dist/adapters/sqlite.js.map +1 -0
- package/dist/adapters/upstash.d.ts +48 -0
- package/dist/adapters/upstash.d.ts.map +1 -0
- package/dist/adapters/upstash.js +46 -0
- package/dist/adapters/upstash.js.map +1 -0
- package/dist/admin/default.d.ts +15 -0
- package/dist/admin/default.d.ts.map +1 -0
- package/dist/admin/default.js +22 -0
- package/dist/admin/default.js.map +1 -0
- package/dist/admin/memory.d.ts +29 -0
- package/dist/admin/memory.d.ts.map +1 -0
- package/dist/admin/memory.js +83 -0
- package/dist/admin/memory.js.map +1 -0
- package/dist/admin/postgres.d.ts +43 -0
- package/dist/admin/postgres.d.ts.map +1 -0
- package/dist/admin/postgres.js +201 -0
- package/dist/admin/postgres.js.map +1 -0
- package/dist/admin/sqlite.d.ts +35 -0
- package/dist/admin/sqlite.d.ts.map +1 -0
- package/dist/admin/sqlite.js +187 -0
- package/dist/admin/sqlite.js.map +1 -0
- package/dist/core/admin.d.ts +88 -0
- package/dist/core/admin.d.ts.map +1 -0
- package/dist/core/admin.js +147 -0
- package/dist/core/admin.js.map +1 -0
- package/dist/core/agent.d.ts +29 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +41 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/cache.d.ts +37 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +68 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/context.d.ts +13 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +87 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/deleteThread.d.ts +14 -0
- package/dist/core/deleteThread.d.ts.map +1 -0
- package/dist/core/deleteThread.js +34 -0
- package/dist/core/deleteThread.js.map +1 -0
- package/dist/core/engine.d.ts +79 -0
- package/dist/core/engine.d.ts.map +1 -0
- package/dist/core/engine.js +489 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/follow.d.ts +50 -0
- package/dist/core/follow.d.ts.map +1 -0
- package/dist/core/follow.js +153 -0
- package/dist/core/follow.js.map +1 -0
- package/dist/core/hitl.d.ts +98 -0
- package/dist/core/hitl.d.ts.map +1 -0
- package/dist/core/hitl.js +199 -0
- package/dist/core/hitl.js.map +1 -0
- package/dist/core/keys.d.ts +26 -0
- package/dist/core/keys.d.ts.map +1 -0
- package/dist/core/keys.js +32 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/loop.d.ts +105 -0
- package/dist/core/loop.d.ts.map +1 -0
- package/dist/core/loop.js +234 -0
- package/dist/core/loop.js.map +1 -0
- package/dist/core/publish.d.ts +18 -0
- package/dist/core/publish.d.ts.map +1 -0
- package/dist/core/publish.js +34 -0
- package/dist/core/publish.js.map +1 -0
- package/dist/core/reclaim.d.ts +20 -0
- package/dist/core/reclaim.d.ts.map +1 -0
- package/dist/core/reclaim.js +56 -0
- package/dist/core/reclaim.js.map +1 -0
- package/dist/core/run.d.ts +8 -0
- package/dist/core/run.d.ts.map +1 -0
- package/dist/core/run.js +102 -0
- package/dist/core/run.js.map +1 -0
- package/dist/core/state.d.ts +50 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/state.js +39 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/stop.d.ts +7 -0
- package/dist/core/stop.d.ts.map +1 -0
- package/dist/core/stop.js +15 -0
- package/dist/core/stop.js.map +1 -0
- package/dist/core/stream.d.ts +12 -0
- package/dist/core/stream.d.ts.map +1 -0
- package/dist/core/stream.js +21 -0
- package/dist/core/stream.js.map +1 -0
- package/dist/core/subagent.d.ts +77 -0
- package/dist/core/subagent.d.ts.map +1 -0
- package/dist/core/subagent.js +261 -0
- package/dist/core/subagent.js.map +1 -0
- package/dist/core/tools.d.ts +36 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +22 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/types.d.ts +286 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +49 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/usage.d.ts +40 -0
- package/dist/core/usage.d.ts.map +1 -0
- package/dist/core/usage.js +43 -0
- package/dist/core/usage.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/ports/admin.d.ts +102 -0
- package/dist/ports/admin.d.ts.map +1 -0
- package/dist/ports/admin.js +2 -0
- package/dist/ports/admin.js.map +1 -0
- package/dist/ports/bus.d.ts +13 -0
- package/dist/ports/bus.d.ts.map +1 -0
- package/dist/ports/bus.js +2 -0
- package/dist/ports/bus.js.map +1 -0
- package/dist/ports/kv.d.ts +16 -0
- package/dist/ports/kv.d.ts.map +1 -0
- package/dist/ports/kv.js +2 -0
- package/dist/ports/kv.js.map +1 -0
- package/dist/ports/queue.d.ts +18 -0
- package/dist/ports/queue.d.ts.map +1 -0
- package/dist/ports/queue.js +2 -0
- package/dist/ports/queue.js.map +1 -0
- package/dist/ports/runtime.d.ts +260 -0
- package/dist/ports/runtime.d.ts.map +1 -0
- package/dist/ports/runtime.js +2 -0
- package/dist/ports/runtime.js.map +1 -0
- package/dist/ports/storage.d.ts +72 -0
- package/dist/ports/storage.d.ts.map +1 -0
- package/dist/ports/storage.js +2 -0
- package/dist/ports/storage.js.map +1 -0
- package/dist/runtime.d.ts +5 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +177 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +126 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { LanguageModel, ToolSet } from 'ai';
|
|
2
|
+
import type { AgentRunState } from './state.js';
|
|
3
|
+
/** Lifecycle of a thread. Durable truth lives in Storage.threads; the kv copy
|
|
4
|
+
* (`agent:state:{threadId}`) is a hot cache the engine polls (§2.1, §3.4). */
|
|
5
|
+
export type ExecutionState = 'IDLE' | 'RUNNING' | 'WAITING_FOR_INPUT' | 'CANCELLED' | 'COMPLETED' | 'FAILED';
|
|
6
|
+
export type MessageRole = 'user' | 'assistant' | 'system' | 'tool';
|
|
7
|
+
/** Generation flavor of a handle / spawned subagent (§4). */
|
|
8
|
+
export type AgentKind = 'stream-text' | 'generate-text';
|
|
9
|
+
export interface ThreadDTO {
|
|
10
|
+
id: string;
|
|
11
|
+
state: ExecutionState;
|
|
12
|
+
model: string;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
updatedAt: Date;
|
|
15
|
+
}
|
|
16
|
+
export interface MessageDTO {
|
|
17
|
+
id: string;
|
|
18
|
+
threadId: string;
|
|
19
|
+
/** Producing agent; null = main agent (§2.7) */
|
|
20
|
+
agentId: string | null;
|
|
21
|
+
role: MessageRole;
|
|
22
|
+
/** AI SDK message state, plain text, or a CONTEXT_SUMMARY envelope (§2.6) */
|
|
23
|
+
content: unknown;
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
}
|
|
26
|
+
export interface NewMessage {
|
|
27
|
+
agentId?: string | null;
|
|
28
|
+
role: MessageRole;
|
|
29
|
+
content: unknown;
|
|
30
|
+
}
|
|
31
|
+
/** Append-only event log entry: the replay source for SSE (re)connects and the
|
|
32
|
+
* durable record of INPUT_REQUIRED (HITL) requests. `seq` is assigned by the
|
|
33
|
+
* engine via Kv.incr before append (§3.4). */
|
|
34
|
+
export interface AgentEvent {
|
|
35
|
+
threadId: string;
|
|
36
|
+
seq: number;
|
|
37
|
+
type: string;
|
|
38
|
+
payload: unknown;
|
|
39
|
+
createdAt: Date;
|
|
40
|
+
}
|
|
41
|
+
/** The durable record of ONE agent run (§2.9): when it started, how it ended,
|
|
42
|
+
* what it cost. Keyed by the run id the platform already mints to fence stale
|
|
43
|
+
* workers (§2.1), so a run is observable by the same identity that makes it
|
|
44
|
+
* correct. A thread accumulates many of these over its life — `Thread.state`
|
|
45
|
+
* only ever describes the latest one. */
|
|
46
|
+
export interface RunRecord {
|
|
47
|
+
/** The run id (§2.1) for a dispatched run; the nested run's id otherwise —
|
|
48
|
+
* which is also the `agentId` its messages and events are tagged with. */
|
|
49
|
+
id: string;
|
|
50
|
+
threadId: string;
|
|
51
|
+
/** The run that spawned this one; null for a dispatched run (§2.7). */
|
|
52
|
+
parentRunId?: string | null;
|
|
53
|
+
/** 0 = the main agent, 1+ = nested. */
|
|
54
|
+
depth: number;
|
|
55
|
+
/** Registered handle for a dispatched run; the delegation's name for a
|
|
56
|
+
* nested one. */
|
|
57
|
+
agent: string;
|
|
58
|
+
model: string;
|
|
59
|
+
state: ExecutionState;
|
|
60
|
+
/** 'completed' | 'cancelled' | 'token_budget' | 'max_steps', set at finalize. */
|
|
61
|
+
stopReason?: string | null;
|
|
62
|
+
/** Why it failed, when it did. Previously dropped on the floor (§2.8). */
|
|
63
|
+
error?: string | null;
|
|
64
|
+
/** When the run was accepted and enqueued. */
|
|
65
|
+
startedAt: Date;
|
|
66
|
+
endedAt?: Date | null;
|
|
67
|
+
/** endedAt - startedAt, denormalised so a listing never recomputes it. A
|
|
68
|
+
* parked run legitimately spans however long the human took (§2.5). */
|
|
69
|
+
durationMs?: number | null;
|
|
70
|
+
/** Milliseconds between enqueue and a worker starting work — the number that
|
|
71
|
+
* says whether workers are keeping up (§2.8). */
|
|
72
|
+
queuedMs?: number | null;
|
|
73
|
+
/** Loop iterations completed, summed across every segment of the run. */
|
|
74
|
+
steps: number;
|
|
75
|
+
inputTokens: number;
|
|
76
|
+
cachedInputTokens: number;
|
|
77
|
+
outputTokens: number;
|
|
78
|
+
totalTokens: number;
|
|
79
|
+
/** §2.8 redrive attempts consumed. Only a dispatched run has these. */
|
|
80
|
+
attempts: number;
|
|
81
|
+
/** What the run was dispatched with (§2.9) — the prompt that started it, the
|
|
82
|
+
* budget it was given, and the state it carries. Present only when
|
|
83
|
+
* `recordPayloads` is on. A nested run's is its brief. */
|
|
84
|
+
prompt?: string | null;
|
|
85
|
+
tokenBudget?: number | null;
|
|
86
|
+
runState?: Record<string, unknown> | null;
|
|
87
|
+
/** A nested run's capped result, handed back to its parent (§2.7). */
|
|
88
|
+
result?: unknown;
|
|
89
|
+
}
|
|
90
|
+
export interface NewRunRecord {
|
|
91
|
+
id: string;
|
|
92
|
+
threadId: string;
|
|
93
|
+
agent: string;
|
|
94
|
+
model: string;
|
|
95
|
+
prompt?: string | null;
|
|
96
|
+
tokenBudget?: number | null;
|
|
97
|
+
runState?: Record<string, unknown> | null;
|
|
98
|
+
/** Defaults to 0 — a dispatched run. */
|
|
99
|
+
depth?: number;
|
|
100
|
+
parentRunId?: string | null;
|
|
101
|
+
}
|
|
102
|
+
export type RunPatch = Partial<Omit<RunRecord, 'id' | 'threadId'>>;
|
|
103
|
+
/** Token attribution only (§4): total tokens used. USD/credit pricing is a
|
|
104
|
+
* downstream concern computed over the recorded counters. */
|
|
105
|
+
/** Token attribution (§4): the platform records the counters; USD/credit
|
|
106
|
+
* pricing is a downstream concern computed over them. */
|
|
107
|
+
/** Cumulative token attribution across every run on a thread (§4). */
|
|
108
|
+
export interface UsageTotals {
|
|
109
|
+
/** Fresh (uncached) prompt tokens. */
|
|
110
|
+
inputTokens: number;
|
|
111
|
+
/** Prompt tokens served from the provider's prompt cache (§2.6). */
|
|
112
|
+
cachedInputTokens: number;
|
|
113
|
+
outputTokens: number;
|
|
114
|
+
/** input + cached + output. */
|
|
115
|
+
totalTokens: number;
|
|
116
|
+
}
|
|
117
|
+
/** How full the next run's prompt would be (§2.6). Token counts are the same
|
|
118
|
+
* rough estimate the engine itself compacts on, so the number a user sees is
|
|
119
|
+
* the number the platform acts on. */
|
|
120
|
+
export interface ContextUsage {
|
|
121
|
+
/** Estimated tokens the stored history occupies right now. */
|
|
122
|
+
usedTokens: number;
|
|
123
|
+
/** What history may fill: the model's window minus the output reserve. */
|
|
124
|
+
budgetTokens: number;
|
|
125
|
+
/** Compaction runs above this — `budgetTokens × compactionTrigger`. */
|
|
126
|
+
compactAtTokens: number;
|
|
127
|
+
/** Messages currently in the thread, summaries included. */
|
|
128
|
+
messages: number;
|
|
129
|
+
}
|
|
130
|
+
export interface NewUsage {
|
|
131
|
+
agentId?: string | null;
|
|
132
|
+
/** Fresh (uncached) prompt tokens. */
|
|
133
|
+
inputTokens: number;
|
|
134
|
+
/** Prompt tokens served from the provider's prompt cache (§2.6 caching). */
|
|
135
|
+
cachedInputTokens: number;
|
|
136
|
+
outputTokens: number;
|
|
137
|
+
/** input + cached + output. */
|
|
138
|
+
totalTokens: number;
|
|
139
|
+
}
|
|
140
|
+
/** Additional provider-specific options, passed through to the provider from
|
|
141
|
+
* the AI SDK. Namespaced per provider — the platform never inspects them. */
|
|
142
|
+
export interface ProviderOptions {
|
|
143
|
+
[provider: string]: any;
|
|
144
|
+
}
|
|
145
|
+
/** Shallow per-provider merge: the execute input wins over the spec default. */
|
|
146
|
+
export declare function mergeProviderOptions(base?: ProviderOptions, override?: ProviderOptions): ProviderOptions | undefined;
|
|
147
|
+
/** Dispatch ticket for the queue (§2.8). At-least-once — consumers must be
|
|
148
|
+
* idempotent. `agent` resolves via `AgentCore.getAgent`; when missing, the
|
|
149
|
+
* default handle executes. */
|
|
150
|
+
export interface RunJob {
|
|
151
|
+
threadId: string;
|
|
152
|
+
model: string;
|
|
153
|
+
agent?: string;
|
|
154
|
+
/** Identifies THIS dispatch (§2.1). A thread has one live run at a time and
|
|
155
|
+
* `agent:run:{threadId}` holds its id; a job whose id no longer matches has
|
|
156
|
+
* been replaced by a newer run and must not execute. Omitted on legacy
|
|
157
|
+
* dispatches, which keep the old no-identity behavior. */
|
|
158
|
+
runId?: string;
|
|
159
|
+
/** Epoch ms at enqueue. The worker subtracts it on pickup to record how long
|
|
160
|
+
* the job waited — the number that says whether workers keep up (§2.9). */
|
|
161
|
+
enqueuedAt?: number;
|
|
162
|
+
/** The run's state (§2.10), so a worker rehydrates exactly what the caller
|
|
163
|
+
* attached — hours later, in another process, after an approval. */
|
|
164
|
+
state?: AgentRunState;
|
|
165
|
+
tokenBudget?: number;
|
|
166
|
+
providerOptions?: ProviderOptions;
|
|
167
|
+
}
|
|
168
|
+
/** Identifies a nested run well enough to re-enter its loop (§2.7). Persisted
|
|
169
|
+
* in the INPUT_REQUIRED payload so a resume never has to read it back. */
|
|
170
|
+
export interface NestedDescriptor {
|
|
171
|
+
agentId: string;
|
|
172
|
+
name: string;
|
|
173
|
+
model: string;
|
|
174
|
+
depth: number;
|
|
175
|
+
}
|
|
176
|
+
/** Everything needed to resume a parked HITL run segment (§2.5). Persisted
|
|
177
|
+
* inside the INPUT_REQUIRED event payload so any late reader — /respond or
|
|
178
|
+
* TTL reclamation — can rebuild the dispatch ticket without extra state. */
|
|
179
|
+
export interface ResumeInfo {
|
|
180
|
+
agent: string;
|
|
181
|
+
model: string;
|
|
182
|
+
/** The run these segments belong to (§2.9). */
|
|
183
|
+
runId?: string;
|
|
184
|
+
tokenBudget?: number;
|
|
185
|
+
providerOptions?: ProviderOptions;
|
|
186
|
+
/** The run's state (§2.10). A park can outlive the process that made it, so
|
|
187
|
+
* the state has to travel on the ticket — rebuilt from here, not from a
|
|
188
|
+
* closure that is long gone. Without it every storage call after an
|
|
189
|
+
* approval loses whatever the caller attached, tenant scope included. */
|
|
190
|
+
state?: AgentRunState;
|
|
191
|
+
}
|
|
192
|
+
/** A model identity after resolution: the real provider instance (created
|
|
193
|
+
* lazily per run) and the declared context window, which feeds the §2.6
|
|
194
|
+
* compaction budget math. */
|
|
195
|
+
export interface ResolvedModel {
|
|
196
|
+
instance: () => LanguageModel;
|
|
197
|
+
contextWindow?: number;
|
|
198
|
+
}
|
|
199
|
+
/** Opt-in subagent delegation config (§2.7): the platform constructs the
|
|
200
|
+
* run-scoped spawnSubagent tool — users cannot build it themselves. */
|
|
201
|
+
export interface SubagentsConfig {
|
|
202
|
+
/** Generation flavor for spawned subagents — picks the nested loop (§4).
|
|
203
|
+
* Default: 'stream-text'. A 'generate-text' child publishes only
|
|
204
|
+
* SUBAGENT_STARTED / SUBAGENT_COMPLETED / SUBAGENT_FAILED. */
|
|
205
|
+
kind?: AgentKind;
|
|
206
|
+
/** Registry key used when a delegation call omits `model`. */
|
|
207
|
+
model?: string;
|
|
208
|
+
/** Extra tools merged into every spawned subagent's toolset
|
|
209
|
+
* (HITL-wrapped identically to the parent's tools). */
|
|
210
|
+
tools?: ToolSet;
|
|
211
|
+
}
|
|
212
|
+
export interface AgentConfig {
|
|
213
|
+
/** How long a parked HITL request stays answerable (§2.5) — expiry turns
|
|
214
|
+
* it into the timeout denial ("user had no response") and the run continues. */
|
|
215
|
+
hitlTtlMs: number;
|
|
216
|
+
/** Grace beyond the HITL TTL before orphan reclamation may claim a thread (§2.5) */
|
|
217
|
+
reclaimGraceMs: number;
|
|
218
|
+
/** AI-SDK round-trip ceiling per run (§2.1 safety cap) — the platform loop
|
|
219
|
+
* runs one executeStep (maxSteps: 1) per iteration up to this count. */
|
|
220
|
+
maxSteps: number;
|
|
221
|
+
/** Queue redrive attempts before a run finalizes FAILED (§2.8) */
|
|
222
|
+
runMaxAttempts: number;
|
|
223
|
+
/** How often a running worker re-reads the stop signal (§2.1). Also the
|
|
224
|
+
* window in which it notices that a newer run has replaced it. */
|
|
225
|
+
stopPollMs: number;
|
|
226
|
+
/** Delay (seconds) before re-dispatching a job that found the run lock still
|
|
227
|
+
* held by an OLDER run (§2.8). That job has not executed at all — dropping
|
|
228
|
+
* it would strand the user's message — so it comes back once the previous
|
|
229
|
+
* run has let go. */
|
|
230
|
+
runRedriveDelaySeconds: number;
|
|
231
|
+
/** Default per-run token budget (input + output) when neither the execute
|
|
232
|
+
* input nor the agent spec declares one. `undefined` = unbounded apart
|
|
233
|
+
* from `maxSteps` (§2.1 safety cap). */
|
|
234
|
+
tokenBudget?: number;
|
|
235
|
+
/** Subagent nesting cap (§2.7) */
|
|
236
|
+
subagentMaxDepth: number;
|
|
237
|
+
/** Concurrent subagents per run (§2.7) */
|
|
238
|
+
subagentMaxConcurrent: number;
|
|
239
|
+
/** AI-SDK step ceiling per subagent run (§2.7) — tighter than `maxSteps` */
|
|
240
|
+
subagentMaxSteps: number;
|
|
241
|
+
/** Characters of a subagent result handed back to the parent (§2.7) */
|
|
242
|
+
subagentResultCapChars: number;
|
|
243
|
+
/** Record payloads into the operational store (§2.9): the prompt and state a
|
|
244
|
+
* run was dispatched with, and the text and tool arguments/results each step
|
|
245
|
+
* produced. Off means timings and counts only.
|
|
246
|
+
*
|
|
247
|
+
* On by default because a dashboard that cannot show what happened is worth
|
|
248
|
+
* little — but this is the flag to turn off when prompts or tool payloads
|
|
249
|
+
* carry anything that should not sit in an operational database. */
|
|
250
|
+
recordPayloads: boolean;
|
|
251
|
+
/** Characters kept per recorded value, so one large prompt or tool result
|
|
252
|
+
* cannot bloat the store. */
|
|
253
|
+
payloadCapChars: number;
|
|
254
|
+
/** Universal context ceiling (§2.6) */
|
|
255
|
+
contextCeilingTokens: number;
|
|
256
|
+
/** Tokens reserved for the completion when compacting (§2.6) */
|
|
257
|
+
contextOutputReserveTokens: number;
|
|
258
|
+
/** Compact when history estimate exceeds this share of budget (§2.6) */
|
|
259
|
+
compactionTrigger: number;
|
|
260
|
+
/** Share of budget kept verbatim as the recent tail (§2.6) */
|
|
261
|
+
contextTailShare: number;
|
|
262
|
+
/** Prompt caching (§2.6): when true, the engine stamps Anthropic-style
|
|
263
|
+
* ephemeral cache breakpoints on the prompt prefix so providers that
|
|
264
|
+
* support marking cache it. OpenAI models cache automatically (≥1024
|
|
265
|
+
* tokens) and ignore the flag. Default: true. */
|
|
266
|
+
promptCaching: boolean;
|
|
267
|
+
/** Per-model native windows below the ceiling (§2.6) — merged over defaults.
|
|
268
|
+
* A `contextWindow` declared via `resolveModel` wins over this table. */
|
|
269
|
+
nativeWindows?: Record<string, number>;
|
|
270
|
+
/** Lease (seconds) for the per-thread run lock — must exceed the longest
|
|
271
|
+
* possible run segment; parked HITL waits hold NO lock (§2.8, §3.4). */
|
|
272
|
+
runLockLeaseSeconds: number;
|
|
273
|
+
/** Billing pre-execution check (§4). Return `{ ok: false, error }` to reject a run. */
|
|
274
|
+
billingPreCheck?: (threadId: string) => Promise<{
|
|
275
|
+
ok: boolean;
|
|
276
|
+
error?: string;
|
|
277
|
+
}>;
|
|
278
|
+
/** Provider-specific options applied to EVERY run (§3.1) — a reasoning
|
|
279
|
+
* budget, a service tier, a safety identifier. The lowest of three levels:
|
|
280
|
+
* an agent spec overrides this, and a run input overrides both, per
|
|
281
|
+
* provider namespace. */
|
|
282
|
+
providerOptions?: ProviderOptions;
|
|
283
|
+
}
|
|
284
|
+
export declare const DEFAULT_CONFIG: AgentConfig;
|
|
285
|
+
export declare function resolveConfig(partial?: Partial<AgentConfig>): AgentConfig;
|
|
286
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"A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C;AAEF,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CA2BzE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Shallow per-provider merge: the execute input wins over the spec default. */
|
|
2
|
+
export function mergeProviderOptions(base, override) {
|
|
3
|
+
if (!base)
|
|
4
|
+
return override;
|
|
5
|
+
if (!override)
|
|
6
|
+
return base;
|
|
7
|
+
return { ...base, ...override };
|
|
8
|
+
}
|
|
9
|
+
export const DEFAULT_CONFIG = {
|
|
10
|
+
hitlTtlMs: 15 * 60_000,
|
|
11
|
+
reclaimGraceMs: 60_000,
|
|
12
|
+
maxSteps: 25,
|
|
13
|
+
runMaxAttempts: 3,
|
|
14
|
+
stopPollMs: 500,
|
|
15
|
+
runRedriveDelaySeconds: 2,
|
|
16
|
+
subagentMaxDepth: 2,
|
|
17
|
+
subagentMaxConcurrent: 3,
|
|
18
|
+
subagentMaxSteps: 10,
|
|
19
|
+
subagentResultCapChars: 8_000,
|
|
20
|
+
recordPayloads: true,
|
|
21
|
+
payloadCapChars: 2_000,
|
|
22
|
+
contextCeilingTokens: 265_000,
|
|
23
|
+
contextOutputReserveTokens: 16_000,
|
|
24
|
+
compactionTrigger: 0.8,
|
|
25
|
+
contextTailShare: 0.25,
|
|
26
|
+
promptCaching: true,
|
|
27
|
+
runLockLeaseSeconds: 30 * 60,
|
|
28
|
+
};
|
|
29
|
+
export function resolveConfig(partial) {
|
|
30
|
+
const config = { ...DEFAULT_CONFIG, ...partial };
|
|
31
|
+
if (config.subagentMaxSteps < 1 || config.subagentMaxSteps > config.maxSteps) {
|
|
32
|
+
// A subagent must never get a looser step ceiling than its parent run (§2.7)
|
|
33
|
+
throw new Error(`Invalid config: subagentMaxSteps (${config.subagentMaxSteps}) must be between 1 and maxSteps (${config.maxSteps})`);
|
|
34
|
+
}
|
|
35
|
+
if (!Number.isInteger(config.stopPollMs) || config.stopPollMs < 1) {
|
|
36
|
+
// The poll is the only thing that delivers a stop to a running worker (§2.1)
|
|
37
|
+
throw new Error(`Invalid config: stopPollMs (${config.stopPollMs}) must be an integer of at least 1`);
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isInteger(config.runRedriveDelaySeconds) || config.runRedriveDelaySeconds < 0) {
|
|
40
|
+
throw new Error(`Invalid config: runRedriveDelaySeconds (${config.runRedriveDelaySeconds}) must be a non-negative integer`);
|
|
41
|
+
}
|
|
42
|
+
if (!Number.isInteger(config.runLockLeaseSeconds) || config.runLockLeaseSeconds < 1) {
|
|
43
|
+
// The lease is the only thing that heals a crashed worker's lock — a
|
|
44
|
+
// zero/fractional value would deadlock the thread forever (§3.4)
|
|
45
|
+
throw new Error(`Invalid config: runLockLeaseSeconds (${config.runLockLeaseSeconds}) must be an integer of at least 1`);
|
|
46
|
+
}
|
|
47
|
+
return config;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAqKA,gFAAgF;AAChF,MAAM,UAAU,oBAAoB,CAClC,IAAsB,EACtB,QAA0B;IAE1B,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC;IAC3B,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,EAAE,CAAC;AAClC,CAAC;AA8ID,MAAM,CAAC,MAAM,cAAc,GAAgB;IACzC,SAAS,EAAE,EAAE,GAAG,MAAM;IACtB,cAAc,EAAE,MAAM;IACtB,QAAQ,EAAE,EAAE;IACZ,cAAc,EAAE,CAAC;IACjB,UAAU,EAAE,GAAG;IACf,sBAAsB,EAAE,CAAC;IACzB,gBAAgB,EAAE,CAAC;IACnB,qBAAqB,EAAE,CAAC;IACxB,gBAAgB,EAAE,EAAE;IACpB,sBAAsB,EAAE,KAAK;IAC7B,cAA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AAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Token attribution (§4): the platform records the counters; USD/credit
|
|
2
|
+
* pricing is a downstream concern computed over them. */
|
|
3
|
+
export interface TokenAttribution {
|
|
4
|
+
/** Fresh (uncached) prompt tokens. */
|
|
5
|
+
inputTokens: number;
|
|
6
|
+
/** Prompt tokens served from the provider's prompt cache (§2.6). */
|
|
7
|
+
cachedInputTokens: number;
|
|
8
|
+
outputTokens: number;
|
|
9
|
+
/** input + cached + output. */
|
|
10
|
+
totalTokens: number;
|
|
11
|
+
}
|
|
12
|
+
/** Where a cache hit is reported, per provider. The AI SDK's `usage` carries
|
|
13
|
+
* only prompt/completion/total — cache counts live in provider metadata, so
|
|
14
|
+
* reading `usage` alone can never see one. */
|
|
15
|
+
export type ProviderMetadataLike = Record<string, Record<string, unknown> | undefined> | undefined;
|
|
16
|
+
type UsageLike = {
|
|
17
|
+
inputTokens?: number;
|
|
18
|
+
cachedInputTokens?: number;
|
|
19
|
+
outputTokens?: number;
|
|
20
|
+
promptTokens?: number;
|
|
21
|
+
completionTokens?: number;
|
|
22
|
+
totalTokens?: number;
|
|
23
|
+
} | undefined;
|
|
24
|
+
/** Attribute one usage report into the four canonical counters, NaN-guarded.
|
|
25
|
+
*
|
|
26
|
+
* Handles both AI-SDK namings (inputTokens/outputTokens and the older
|
|
27
|
+
* promptTokens/completionTokens), and reads cache hits out of PROVIDER
|
|
28
|
+
* METADATA, which is the only place they appear — `usage` has no field for
|
|
29
|
+
* them, so attributing from it alone reports zero cache hits forever.
|
|
30
|
+
*
|
|
31
|
+
* The two providers disagree about what "prompt tokens" means, and getting it
|
|
32
|
+
* wrong double-counts:
|
|
33
|
+
* - OpenAI's promptTokens INCLUDES the cached ones, so the fresh count is
|
|
34
|
+
* the difference.
|
|
35
|
+
* - Anthropic reports cache reads alongside input, not inside it. */
|
|
36
|
+
export declare function attributeTokens(usage: UsageLike, meta?: ProviderMetadataLike): TokenAttribution;
|
|
37
|
+
/** Total tokens used — input + cached + output, NaN-guarded. */
|
|
38
|
+
export declare function countTokens(usage: UsageLike, meta?: ProviderMetadataLike): number;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/core/usage.ts"],"names":[],"mappings":"AAAA;0DAC0D;AAE1D,MAAM,WAAW,gBAAgB;IAC/B,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;+CAE+C;AAC/C,MAAM,MAAM,oBAAoB,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,GACnD,SAAS,CAAC;AAEd,KAAK,SAAS,GAAG;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,SAAS,CAAC;AASd;;;;;;;;;;;uEAWuE;AACvE,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,EAChB,IAAI,CAAC,EAAE,oBAAoB,GAC1B,gBAAgB,CAsBlB;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAEjF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Token attribution (§4): the platform records the counters; USD/credit
|
|
2
|
+
* pricing is a downstream concern computed over them. */
|
|
3
|
+
const pick = (...vals) => {
|
|
4
|
+
for (const v of vals) {
|
|
5
|
+
if (typeof v === 'number' && Number.isFinite(v))
|
|
6
|
+
return v;
|
|
7
|
+
}
|
|
8
|
+
return 0;
|
|
9
|
+
};
|
|
10
|
+
/** Attribute one usage report into the four canonical counters, NaN-guarded.
|
|
11
|
+
*
|
|
12
|
+
* Handles both AI-SDK namings (inputTokens/outputTokens and the older
|
|
13
|
+
* promptTokens/completionTokens), and reads cache hits out of PROVIDER
|
|
14
|
+
* METADATA, which is the only place they appear — `usage` has no field for
|
|
15
|
+
* them, so attributing from it alone reports zero cache hits forever.
|
|
16
|
+
*
|
|
17
|
+
* The two providers disagree about what "prompt tokens" means, and getting it
|
|
18
|
+
* wrong double-counts:
|
|
19
|
+
* - OpenAI's promptTokens INCLUDES the cached ones, so the fresh count is
|
|
20
|
+
* the difference.
|
|
21
|
+
* - Anthropic reports cache reads alongside input, not inside it. */
|
|
22
|
+
export function attributeTokens(usage, meta) {
|
|
23
|
+
const u = usage ?? {};
|
|
24
|
+
const reportedInput = pick(u.inputTokens, u.promptTokens);
|
|
25
|
+
const outputTokens = pick(u.outputTokens, u.completionTokens);
|
|
26
|
+
const openaiCached = pick(meta?.openai?.cachedPromptTokens);
|
|
27
|
+
const anthropicCached = pick(meta?.anthropic?.cacheReadInputTokens);
|
|
28
|
+
const cachedInputTokens = pick(u.cachedInputTokens) + openaiCached + anthropicCached;
|
|
29
|
+
const inputTokens = openaiCached > 0 ? Math.max(0, reportedInput - openaiCached) : reportedInput;
|
|
30
|
+
const totalFromProvider = pick(u.totalTokens);
|
|
31
|
+
const summed = inputTokens + cachedInputTokens + outputTokens;
|
|
32
|
+
return {
|
|
33
|
+
inputTokens,
|
|
34
|
+
cachedInputTokens,
|
|
35
|
+
outputTokens,
|
|
36
|
+
totalTokens: totalFromProvider > 0 ? totalFromProvider : summed,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Total tokens used — input + cached + output, NaN-guarded. */
|
|
40
|
+
export function countTokens(usage, meta) {
|
|
41
|
+
return attributeTokens(usage, meta).totalTokens;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/core/usage.ts"],"names":[],"mappings":"AAAA;0DAC0D;AA4B1D,MAAM,IAAI,GAAG,CAAC,GAAG,IAA4B,EAAU,EAAE;IACvD,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAEF;;;;;;;;;;;uEAWuE;AACvE,MAAM,UAAU,eAAe,CAC7B,KAAgB,EAChB,IAA2B;IAE3B,MAAM,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;IACtB,MAAM,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAE9D,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAwC,CAAC,CAAC;IAClF,MAAM,eAAe,GAAG,IAAI,CAC1B,IAAI,EAAE,SAAS,EAAE,oBAA0C,CAC5D,CAAC;IACF,MAAM,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,YAAY,GAAG,eAAe,CAAC;IAErF,MAAM,WAAW,GACf,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IAE/E,MAAM,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,WAAW,GAAG,iBAAiB,GAAG,YAAY,CAAC;IAC9D,OAAO;QACL,WAAW;QACX,iBAAiB;QACjB,YAAY;QACZ,WAAW,EAAE,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM;KAChE,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,WAAW,CAAC,KAAgB,EAAE,IAA2B;IACvE,OAAO,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,WAAW,CAAC;AAClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type { Storage } from './ports/storage.js';
|
|
2
|
+
export type { EventBus } from './ports/bus.js';
|
|
3
|
+
export type { EnqueueOptions, Queue } from './ports/queue.js';
|
|
4
|
+
export type { Kv } from './ports/kv.js';
|
|
5
|
+
export type { AgentCore, AgentHandle, AgentKind, DeleteThreadResult, GenerateTextAgentSpec, RespondInput, RespondResult, ResolvedModel, RunInput, RunResult, RuntimeOptions, RuntimePorts, StopResult, StreamTextAgentSpec, SubagentsConfig, ThreadSnapshot, ThreadUsage, } from './ports/runtime.js';
|
|
6
|
+
export { setupAgentCore } from './runtime.js';
|
|
7
|
+
export { execute, executeStep, executeWithPolicy, finalize, markRequiresConfirmation, type ExecuteInput, type ExecuteOutcome, type FinalizeInput, type StepResult, } from './core/engine.js';
|
|
8
|
+
export { agentTool, type ToolContext } from './core/tools.js';
|
|
9
|
+
export { followEvents, toSseStream, sseFrame, SSE_HEADERS, type FollowOptions, type SseOptions, type SseStream, } from './core/follow.js';
|
|
10
|
+
export type { AgentRunState, BoundStorage, StorageContext } from './core/state.js';
|
|
11
|
+
export { claimRun, redriveKey, runIdKey } from './core/keys.js';
|
|
12
|
+
export { countTokens } from './core/usage.js';
|
|
13
|
+
export { respond, parkForApproval, loadPendingHitl, loadOpenHitls, withHitl, HITL_PARKED, HITL_TTL_MS, hitlKey, type HitlFrame, type HitlResponse, type ParkInput, type PendingHitl, } from './core/hitl.js';
|
|
14
|
+
export { reclaimIfOrphaned } from './core/reclaim.js';
|
|
15
|
+
export { contextBudget, contextUsage, compactContext, CONTEXT_TOKEN_CEILING } from './core/context.js';
|
|
16
|
+
export { Semaphore, runNestedAgent, spawnSubagentTool, type SubagentCtx } from './core/subagent.js';
|
|
17
|
+
export { run } from './core/run.js';
|
|
18
|
+
export { stop } from './core/stop.js';
|
|
19
|
+
export { DEFAULT_CONFIG, resolveConfig, type AgentConfig, type AgentEvent, type ExecutionState, type MessageDTO, type MessageRole, type NewMessage, type NewRunRecord, type NewUsage, type ResolvedModel as ResolvedModelDTO, type RunPatch, type RunRecord, type RunJob, type ResumeInfo, type ContextUsage, type NestedDescriptor, type ThreadDTO, type UsageTotals, } from './core/types.js';
|
|
20
|
+
export { PrismaStorage, type PrismaLike } from './adapters/prisma.js';
|
|
21
|
+
export { UpstashBus, UpstashKv, THREAD_CHANNEL, type UpstashRedisLike, type UpstashSubscriberLike } from './adapters/upstash.js';
|
|
22
|
+
export { RedisBus, RedisKv, type RedisClientLike, type RedisSubscriberLike } from './adapters/redis.js';
|
|
23
|
+
export { QStashQueue, type QStashLike, type QStashQueueOptions } from './adapters/qstash.js';
|
|
24
|
+
export { MemoryStorage, MemoryBus, MemoryQueue, MemoryKv } from './adapters/memory.js';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9D,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M,mBAAmB,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC,OAAO,EACL,cAAc,EACd,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,aAAa,IAAI,gBAAgB,EACtC,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,WAAW,GACjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACjI,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACxG,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// runtime — the factory that binds ports to behaviors
|
|
2
|
+
export { setupAgentCore } from './runtime.js';
|
|
3
|
+
// core — behaviors, all ports-only
|
|
4
|
+
export { execute, executeStep, executeWithPolicy, finalize, markRequiresConfirmation, } from './core/engine.js';
|
|
5
|
+
export { agentTool } from './core/tools.js';
|
|
6
|
+
export { followEvents, toSseStream, sseFrame, SSE_HEADERS, } from './core/follow.js';
|
|
7
|
+
export { claimRun, redriveKey, runIdKey } from './core/keys.js';
|
|
8
|
+
export { countTokens } from './core/usage.js';
|
|
9
|
+
export { respond, parkForApproval, loadPendingHitl, loadOpenHitls, withHitl, HITL_PARKED, HITL_TTL_MS, hitlKey, } from './core/hitl.js';
|
|
10
|
+
export { reclaimIfOrphaned } from './core/reclaim.js';
|
|
11
|
+
export { contextBudget, contextUsage, compactContext, CONTEXT_TOKEN_CEILING } from './core/context.js';
|
|
12
|
+
export { Semaphore, runNestedAgent, spawnSubagentTool } from './core/subagent.js';
|
|
13
|
+
export { run } from './core/run.js';
|
|
14
|
+
export { stop } from './core/stop.js';
|
|
15
|
+
// types
|
|
16
|
+
export { DEFAULT_CONFIG, resolveConfig, } from './core/types.js';
|
|
17
|
+
// reference adapters
|
|
18
|
+
export { PrismaStorage } from './adapters/prisma.js';
|
|
19
|
+
export { UpstashBus, UpstashKv, THREAD_CHANNEL } from './adapters/upstash.js';
|
|
20
|
+
export { RedisBus, RedisKv } from './adapters/redis.js';
|
|
21
|
+
export { QStashQueue } from './adapters/qstash.js';
|
|
22
|
+
export { MemoryStorage, MemoryBus, MemoryQueue, MemoryKv } from './adapters/memory.js';
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,sDAAsD;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,mCAAmC;AACnC,OAAO,EACL,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,wBAAwB,GAKzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,WAAW,GAIZ,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,OAAO,EACP,eAAe,EACf,eAAe,EACf,aAAa,EACb,QAAQ,EACR,WAAW,EACX,WAAW,EACX,OAAO,GAKR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB,EAAoB,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,QAAQ;AACR,OAAO,EACL,cAAc,EACd,aAAa,GAkBd,MAAM,iBAAiB,CAAC;AAEzB,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAmB,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAqD,MAAM,uBAAuB,CAAC;AACjI,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAkD,MAAM,qBAAqB,CAAC;AACxG,OAAO,EAAE,WAAW,EAA4C,MAAM,sBAAsB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { ExecutionState, NewRunRecord, RunPatch, RunRecord } from '../core/types.js';
|
|
2
|
+
/** Operational history — run records and step timings (§2.9).
|
|
3
|
+
*
|
|
4
|
+
* NOT a port a caller implements. agentic-kit owns this data and stores it
|
|
5
|
+
* itself: SQLite in development, Postgres in production via
|
|
6
|
+
* AGENTIC_KIT_ADMIN_DATABASE_URL. Callers only ever read it back, through
|
|
7
|
+
* `runtime.admin`, and build whatever view they want on top.
|
|
8
|
+
*
|
|
9
|
+
* It carries no StorageContext. A run's state belongs to the caller's own
|
|
10
|
+
* data (§2.10); operational history is the platform's, and scoping it by
|
|
11
|
+
* tenant is the reader's business, not the writer's. */
|
|
12
|
+
export interface AdminStore {
|
|
13
|
+
/** The platform's OWN view of threads (§2.9). Deliberately a copy of the few
|
|
14
|
+
* fields an operational view needs — not the caller's thread table, which
|
|
15
|
+
* it never reads. That is what lets a dashboard answer "what is running
|
|
16
|
+
* right now" without touching their database at all. */
|
|
17
|
+
threads: {
|
|
18
|
+
/** Record a thread at its current state. Called on every transition. */
|
|
19
|
+
upsert(thread: NewAdminThread): Promise<void>;
|
|
20
|
+
countByState(): Promise<Partial<Record<ExecutionState, number>>>;
|
|
21
|
+
list(filter: AdminThreadFilter): Promise<AdminThread[]>;
|
|
22
|
+
};
|
|
23
|
+
runs: {
|
|
24
|
+
start(run: NewRunRecord): Promise<RunRecord>;
|
|
25
|
+
patch(runId: string, patch: RunPatch): Promise<void>;
|
|
26
|
+
get(runId: string): Promise<RunRecord | null>;
|
|
27
|
+
/** Every run on a thread, newest first — nested runs included. */
|
|
28
|
+
listByThread(threadId: string): Promise<RunRecord[]>;
|
|
29
|
+
list(filter: RunFilter): Promise<RunRecord[]>;
|
|
30
|
+
/** Counts by state across every run. The "what is happening right now"
|
|
31
|
+
* aggregate, pushed down so it never drags rows into memory. */
|
|
32
|
+
countByState(): Promise<Partial<Record<ExecutionState, number>>>;
|
|
33
|
+
};
|
|
34
|
+
steps: {
|
|
35
|
+
record(step: NewStepRecord): Promise<void>;
|
|
36
|
+
/** A run's steps in order. */
|
|
37
|
+
listByRun(runId: string): Promise<StepRecord[]>;
|
|
38
|
+
/** Every step on a thread, oldest first — the shape a timeline wants. */
|
|
39
|
+
listByThread(threadId: string): Promise<StepRecord[]>;
|
|
40
|
+
};
|
|
41
|
+
/** Release any handles. Development stores hold an open file. */
|
|
42
|
+
close?(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/** One completed loop iteration (§2.9). */
|
|
45
|
+
export interface StepRecord {
|
|
46
|
+
runId: string;
|
|
47
|
+
/** Denormalised so a thread's whole timeline — across every run on it, main
|
|
48
|
+
* and nested — is one query rather than one per run. */
|
|
49
|
+
threadId: string;
|
|
50
|
+
/** Which stream ran it — null is the main agent (§2.7). */
|
|
51
|
+
agentId: string | null;
|
|
52
|
+
index: number;
|
|
53
|
+
durationMs: number;
|
|
54
|
+
finishReason: string;
|
|
55
|
+
inputTokens: number;
|
|
56
|
+
cachedInputTokens: number;
|
|
57
|
+
outputTokens: number;
|
|
58
|
+
totalTokens: number;
|
|
59
|
+
/** Tools the step executed, by name — the summary line. */
|
|
60
|
+
tools: string[];
|
|
61
|
+
/** What the step said, capped. Timing tells you where a run spent itself;
|
|
62
|
+
* this tells you what it actually did. */
|
|
63
|
+
text?: string | null;
|
|
64
|
+
/** The tools it ran, with arguments and results, each capped.
|
|
65
|
+
*
|
|
66
|
+
* Note what this means: tool arguments and results are operational data now,
|
|
67
|
+
* sitting in the platform's store. If yours carry anything you would not
|
|
68
|
+
* want there, set `recordPayloads: false`. */
|
|
69
|
+
toolCalls?: Array<{
|
|
70
|
+
toolName: string;
|
|
71
|
+
args: unknown;
|
|
72
|
+
result: unknown;
|
|
73
|
+
}>;
|
|
74
|
+
at: Date;
|
|
75
|
+
}
|
|
76
|
+
export type NewStepRecord = Omit<StepRecord, 'at'> & {
|
|
77
|
+
at?: Date;
|
|
78
|
+
};
|
|
79
|
+
export interface AdminThread {
|
|
80
|
+
id: string;
|
|
81
|
+
state: ExecutionState;
|
|
82
|
+
model: string;
|
|
83
|
+
firstSeenAt: Date;
|
|
84
|
+
updatedAt: Date;
|
|
85
|
+
}
|
|
86
|
+
export type NewAdminThread = Omit<AdminThread, 'firstSeenAt' | 'updatedAt'>;
|
|
87
|
+
export interface AdminThreadFilter {
|
|
88
|
+
state?: ExecutionState[];
|
|
89
|
+
since?: Date;
|
|
90
|
+
limit?: number;
|
|
91
|
+
}
|
|
92
|
+
export interface RunFilter {
|
|
93
|
+
/** Any of these states; omitted means all. */
|
|
94
|
+
state?: ExecutionState[];
|
|
95
|
+
agent?: string;
|
|
96
|
+
threadId?: string;
|
|
97
|
+
since?: Date;
|
|
98
|
+
until?: Date;
|
|
99
|
+
/** Newest first. Implementations cap this — core passes a bounded value. */
|
|
100
|
+
limit?: number;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=admin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/ports/admin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE1F;;;;;;;;;yDASyD;AACzD,MAAM,WAAW,UAAU;IACzB;;;6DAGyD;IACzD,OAAO,EAAE;QACP,wEAAwE;QACxE,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9C,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;KACzD,CAAC;IACF,IAAI,EAAE;QACJ,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QAC7C,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACrD,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SA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,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACxE,EAAE,EAAE,IAAI,CAAC;CACV;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG;IAAE,EAAE,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAEnE,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,cAAc,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,IAAI,CAAC;IAClB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,aAAa,GAAG,WAAW,CAAC,CAAC;AAE5E,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/ports/admin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentEvent } from '../core/types.js';
|
|
2
|
+
/** Pub/sub port: live fan-out + death notices (§2.2, §2.5).
|
|
3
|
+
*
|
|
4
|
+
* Delivery is at-most-once — the §2.5 death-notice/heartbeat/watchdog pattern
|
|
5
|
+
* exists precisely because pub/sub drops. Stronger buses may simplify the
|
|
6
|
+
* heartbeat but reclamation stays (§3.4). */
|
|
7
|
+
export interface EventBus {
|
|
8
|
+
publish(threadId: string, event: AgentEvent): Promise<void>;
|
|
9
|
+
/** Returns an unsubscribe function. The reference adapter runs the §2.5
|
|
10
|
+
* heartbeat while any subscriber is attached. */
|
|
11
|
+
subscribe(threadId: string, handler: (event: AgentEvent) => void): Promise<() => void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bus.d.ts","sourceRoot":"","sources":["../../src/ports/bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;8CAI8C;AAC9C,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D;sDACkD;IAClD,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;CACxF"}
|