operon-agents 0.1.0-alpha.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 +55 -0
- package/README.md +18 -0
- package/dist/app-server/client.d.ts +80 -0
- package/dist/app-server/client.js +187 -0
- package/dist/app-server/codec.d.ts +52 -0
- package/dist/app-server/codec.js +252 -0
- package/dist/app-server/index.d.ts +22 -0
- package/dist/app-server/index.js +22 -0
- package/dist/app-server/main.d.ts +3 -0
- package/dist/app-server/main.js +85 -0
- package/dist/app-server/protocol.d.ts +217 -0
- package/dist/app-server/protocol.js +100 -0
- package/dist/app-server/server.d.ts +51 -0
- package/dist/app-server/server.js +274 -0
- package/dist/core.d.ts +12 -0
- package/dist/core.js +12 -0
- package/dist/cron/clock.d.ts +11 -0
- package/dist/cron/clock.js +19 -0
- package/dist/cron/cron-expr.d.ts +15 -0
- package/dist/cron/cron-expr.js +267 -0
- package/dist/cron/extension.d.ts +25 -0
- package/dist/cron/extension.js +141 -0
- package/dist/cron/index.d.ts +20 -0
- package/dist/cron/index.js +11 -0
- package/dist/cron/jitter.d.ts +18 -0
- package/dist/cron/jitter.js +46 -0
- package/dist/cron/manager.d.ts +55 -0
- package/dist/cron/manager.js +123 -0
- package/dist/cron/persist.d.ts +10 -0
- package/dist/cron/persist.js +22 -0
- package/dist/cron/scheduler.d.ts +25 -0
- package/dist/cron/scheduler.js +192 -0
- package/dist/cron/session-store.d.ts +14 -0
- package/dist/cron/session-store.js +50 -0
- package/dist/cron/time-format.d.ts +2 -0
- package/dist/cron/time-format.js +12 -0
- package/dist/cron/tools.d.ts +7 -0
- package/dist/cron/tools.js +161 -0
- package/dist/cron/types.d.ts +9 -0
- package/dist/cron/types.js +2 -0
- package/dist/extensions/index.d.ts +23 -0
- package/dist/extensions/index.js +41 -0
- package/dist/extensions/loader.d.ts +121 -0
- package/dist/extensions/loader.js +285 -0
- package/dist/extensions/manager.d.ts +103 -0
- package/dist/extensions/manager.js +190 -0
- package/dist/extensions/runtime.d.ts +188 -0
- package/dist/extensions/runtime.js +1127 -0
- package/dist/extensions/services.d.ts +85 -0
- package/dist/extensions/services.js +265 -0
- package/dist/extensions/types.d.ts +594 -0
- package/dist/extensions/types.js +2 -0
- package/dist/harness.d.ts +746 -0
- package/dist/harness.js +1483 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +29 -0
- package/dist/internal.d.ts +9 -0
- package/dist/internal.js +9 -0
- package/dist/llm.d.ts +2 -0
- package/dist/llm.js +2 -0
- package/dist/local.d.ts +24 -0
- package/dist/local.js +58 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +2 -0
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.js +2 -0
- package/dist/tools.d.ts +2 -0
- package/dist/tools.js +2 -0
- package/dist/tracing.d.ts +2 -0
- package/dist/tracing.js +2 -0
- package/package.json +78 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { HeadlessCommand } from "operon-agents-core";
|
|
2
|
+
import type { AssistantMessage, CapabilityContext, CompactionGate, ChatModel, ConversationContext, Injector, LlmRequest, Message, SessionContext, StepStopReason, TerminalStepStopReason, Tool, ToolPlan, ToolResult, Usage } from "operon-agents-core";
|
|
3
|
+
import type { ExtensionDefinition, ExtensionHost, ExtensionModelRequestResult, ExtensionStepEndResult, ExtensionStepStartResult, ExtensionToolAuthorizeResult, ExtensionToolCallResult, SessionEndReason, SessionStartReason } from "./types.ts";
|
|
4
|
+
/** Shared shape of the loop-hook contexts the dispatch methods are fed from. */
|
|
5
|
+
interface StepOrigin {
|
|
6
|
+
readonly turnId: string;
|
|
7
|
+
readonly stepNumber: number;
|
|
8
|
+
readonly address?: string;
|
|
9
|
+
readonly signal: AbortSignal;
|
|
10
|
+
readonly model: ChatModel;
|
|
11
|
+
}
|
|
12
|
+
export declare class ExtensionRuntime {
|
|
13
|
+
private readonly definitions;
|
|
14
|
+
private readonly handlers;
|
|
15
|
+
private readonly tools;
|
|
16
|
+
/** Stable reference: `extensionsCapability` hands this array to the assembler, and `setup`
|
|
17
|
+
* (which runs at openSession, before any run assembles) fills it in place. */
|
|
18
|
+
private readonly injectors;
|
|
19
|
+
/** Slash commands by normalized name — surfaced to the session's registry via the
|
|
20
|
+
* `sessionCommands()` duck protocol. Two extensions claiming one name fail closed. */
|
|
21
|
+
private readonly extCommands;
|
|
22
|
+
/** Host-facing control surfaces published via `api.expose`, by extension id. */
|
|
23
|
+
private readonly exposedHandles;
|
|
24
|
+
/** Records read path: open-time snapshot buckets (built lazily off the session's shared
|
|
25
|
+
* memoized log read — zero extra traversal) + everything recorded this session. */
|
|
26
|
+
private recordSnapshot;
|
|
27
|
+
private readonly recordWrites;
|
|
28
|
+
/** Per-extension teardown: setup's cleanup + every registration, undone in reverse. */
|
|
29
|
+
private readonly scopes;
|
|
30
|
+
/** Extensions whose contributions are currently honored. An id leaves on detach (and on
|
|
31
|
+
* setup failure), which turns every `actions`/`api` closure the extension still holds
|
|
32
|
+
* into a warn-and-noop — a detached extension must not keep steering the session. */
|
|
33
|
+
private readonly live;
|
|
34
|
+
/** Changes wait here until a quiet point: mid-run requests apply at the run's stop
|
|
35
|
+
* boundary, so a turn never sees its toolset change underneath it. */
|
|
36
|
+
private pending;
|
|
37
|
+
/** Serializes flushes so concurrent attach/detach apply strictly in submission order. */
|
|
38
|
+
private flushChain;
|
|
39
|
+
private readonly memoryState;
|
|
40
|
+
private session;
|
|
41
|
+
private run;
|
|
42
|
+
/** The conversation shard the in-flight decision point belongs to; backs `actions.record`. */
|
|
43
|
+
private activeContext;
|
|
44
|
+
/** Snapshot of the last assembled registry, refreshed once per turn by `filterTools`. */
|
|
45
|
+
private allToolNames;
|
|
46
|
+
/** `null` = unrestricted. Set by `actions.setActiveTools`; applied at the next assembly. */
|
|
47
|
+
private activeToolNames;
|
|
48
|
+
private reportingWarning;
|
|
49
|
+
/** Harness reach. Absent when the capability is built standalone (bare Runner / tests). */
|
|
50
|
+
private readonly host;
|
|
51
|
+
/** This session's per-session extension arguments, by extension id. A value of `false` means
|
|
52
|
+
* "skip this extension for this session"; any other value is passed to `setup` as `params`. */
|
|
53
|
+
private readonly params;
|
|
54
|
+
constructor(definitions: readonly ExtensionDefinition[], host?: ExtensionHost, params?: Readonly<Record<string, unknown>>);
|
|
55
|
+
open(ctx: SessionContext, reason?: SessionStartReason): Promise<void>;
|
|
56
|
+
attachRun(ctx: CapabilityContext): void;
|
|
57
|
+
detachRun(): Promise<void>;
|
|
58
|
+
close(reason?: SessionEndReason): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Add an extension to the live session. Resolves once its `setup` has run and its
|
|
61
|
+
* contributions are in place — with no run in flight that is immediately; mid-run it is
|
|
62
|
+
* the current run's stop boundary, so an in-flight turn never sees its registry change.
|
|
63
|
+
* Rejects on duplicate/empty id or when `setup` throws.
|
|
64
|
+
*/
|
|
65
|
+
attach(definition: ExtensionDefinition): Promise<void>;
|
|
66
|
+
/** Ids of currently attached extensions — the reshape coordinator's affected-set probe. */
|
|
67
|
+
attachedIds(): readonly string[];
|
|
68
|
+
/** Currently attached extensions with what each declared it `uses` — the unload consumer scan. */
|
|
69
|
+
attachedExtensions(): readonly {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly uses: readonly string[];
|
|
72
|
+
}[];
|
|
73
|
+
/** The duck protocol the session's command registry consumes: dynamic commands contributed
|
|
74
|
+
* by attached extensions (`api.registerCommand`). */
|
|
75
|
+
sessionCommands(): readonly HeadlessCommand[];
|
|
76
|
+
/** The control surface `extensionId` published via `api.expose`; undefined when absent
|
|
77
|
+
* (never attached, detached, or nothing exposed). */
|
|
78
|
+
exposedHandle<T = unknown>(extensionId: string): T | undefined;
|
|
79
|
+
/** Remove an extension: its `session.end` fires, then its whole scope is torn down. */
|
|
80
|
+
detach(id: string): Promise<void>;
|
|
81
|
+
private submit;
|
|
82
|
+
private flushPending;
|
|
83
|
+
private drainPending;
|
|
84
|
+
private attachNow;
|
|
85
|
+
private detachNow;
|
|
86
|
+
/** Runs one extension's `setup` and files its scope. Failure ⇒ skipped, contributions undone. */
|
|
87
|
+
private setupExtension;
|
|
88
|
+
/**
|
|
89
|
+
* Durable audit trail: replay needs "tool X only exists after record N" to reconstruct the
|
|
90
|
+
* capability timeline. Rides the `custom` record type — audit-only, ignored by reducers.
|
|
91
|
+
*/
|
|
92
|
+
private logChange;
|
|
93
|
+
listTools(): readonly Tool[];
|
|
94
|
+
listInjectors(): readonly Injector[];
|
|
95
|
+
/**
|
|
96
|
+
* The capability's `ToolFilter`. Snapshots the full registry (so `getAllTools` has something
|
|
97
|
+
* to report) and applies the active-tool restriction, if any. Identity-returns when nothing
|
|
98
|
+
* is restricted, which lets the caller skip rebuilding the deferred-name set.
|
|
99
|
+
*/
|
|
100
|
+
filterTools: (tools: readonly Tool[]) => readonly Tool[];
|
|
101
|
+
/**
|
|
102
|
+
* Run-tier: the caller's input, before guardrails and before anything is journaled.
|
|
103
|
+
* There is no active conversation yet, so this borrows the session context's shape.
|
|
104
|
+
*/
|
|
105
|
+
beforeRun(origin: {
|
|
106
|
+
readonly address: string;
|
|
107
|
+
readonly agent: string;
|
|
108
|
+
readonly signal: AbortSignal;
|
|
109
|
+
}, input: readonly Message[]): Promise<{
|
|
110
|
+
input?: readonly Message[];
|
|
111
|
+
handled?: {
|
|
112
|
+
output?: string;
|
|
113
|
+
};
|
|
114
|
+
} | undefined>;
|
|
115
|
+
/**
|
|
116
|
+
* The capability's compaction gate. Not engine-driven: the compaction capability calls this
|
|
117
|
+
* through core's `CapabilityGates`, which is why there is no matching `LoopHooks` slot.
|
|
118
|
+
*
|
|
119
|
+
* There is no run-scoped address here (compaction is a session-level operation on one shard),
|
|
120
|
+
* so handlers get the session context shape plus the shard being compacted.
|
|
121
|
+
*/
|
|
122
|
+
compactionGate: CompactionGate;
|
|
123
|
+
beforeStep(origin: StepOrigin, context: ConversationContext, system: string | undefined): Promise<ExtensionStepStartResult | undefined>;
|
|
124
|
+
afterStep(origin: StepOrigin, context: ConversationContext, usage: Usage, stopReason: StepStopReason): Promise<ExtensionStepEndResult | undefined>;
|
|
125
|
+
runSettled(origin: StepOrigin, usage: Usage, stopReason: TerminalStepStopReason): Promise<{
|
|
126
|
+
continue: boolean;
|
|
127
|
+
} | undefined>;
|
|
128
|
+
beforeModelRequest(origin: StepOrigin, request: LlmRequest, context: ConversationContext): Promise<ExtensionModelRequestResult | undefined>;
|
|
129
|
+
/**
|
|
130
|
+
* Attach `transformHeaders` / `onPayload` / `onResponse` when anything is listening. Returns
|
|
131
|
+
* `undefined` when nothing is, so a request with no provider-tier extensions is left byte-identical.
|
|
132
|
+
*
|
|
133
|
+
* These fire once per HTTP ATTEMPT, so a retry re-runs them — the contract tells handlers to be
|
|
134
|
+
* idempotent, and the runtime does not try to dedupe on their behalf.
|
|
135
|
+
*/
|
|
136
|
+
private withProviderHooks;
|
|
137
|
+
afterModelResponse(origin: StepOrigin, request: LlmRequest, response: AssistantMessage, context: ConversationContext): Promise<AssistantMessage | undefined>;
|
|
138
|
+
beforeToolCall(origin: StepOrigin, toolName: string, toolCallId: string, tool: Tool | undefined, args: unknown): Promise<ExtensionToolCallResult | undefined>;
|
|
139
|
+
authorizeToolCall(origin: StepOrigin, toolName: string, toolCallId: string, tool: Tool | undefined, args: unknown, plan: ToolPlan): Promise<ExtensionToolAuthorizeResult | undefined>;
|
|
140
|
+
afterToolResult(origin: StepOrigin, toolName: string, toolCallId: string, tool: Tool | undefined, args: unknown, result: ToolResult): Promise<ToolResult | undefined>;
|
|
141
|
+
private apiFor;
|
|
142
|
+
/**
|
|
143
|
+
* A handle to service `name` collared to `extensionId`'s liveness — the `actions` revocation
|
|
144
|
+
* collar mirrored: liveness is checked at CALL time, including for METHODS stashed off the
|
|
145
|
+
* handle before detach (the returned function re-checks on every invocation), so nothing
|
|
146
|
+
* handed out while live keeps operating afterwards. The inner registry handle decides the
|
|
147
|
+
* probe/shape questions (probes read undefined, field access throws); only functions get
|
|
148
|
+
* the wrapper.
|
|
149
|
+
*/
|
|
150
|
+
private serviceHandle;
|
|
151
|
+
/** viaHost-backed actions promise session handles; when revoked they must reject, not fake. */
|
|
152
|
+
private static readonly PROMISE_ACTIONS;
|
|
153
|
+
/**
|
|
154
|
+
* Revocation collar: a detached extension's stashed `actions` must not keep operating the
|
|
155
|
+
* session. Liveness is checked at CALL time (not build time), so closures handed out before
|
|
156
|
+
* the detach die with it. Reads (`hasActiveRun`) pass through — a stale read is harmless,
|
|
157
|
+
* a stale steer/abort is not.
|
|
158
|
+
*/
|
|
159
|
+
private revocable;
|
|
160
|
+
private actionsFor;
|
|
161
|
+
/**
|
|
162
|
+
* Extension-originated prompts ride the `external` steer origin — they ARE an outside source
|
|
163
|
+
* as far as the transcript is concerned, and reusing it keeps the persisted `PromptOrigin`
|
|
164
|
+
* schema untouched. `source` names the extension so a fold can attribute the message.
|
|
165
|
+
*/
|
|
166
|
+
private enqueue;
|
|
167
|
+
private controls;
|
|
168
|
+
/**
|
|
169
|
+
* Host-backed action wrapper. Rejects (rather than silently resolving to something fake) when
|
|
170
|
+
* no host is present — these return values are session handles a caller would go on to use, so
|
|
171
|
+
* a no-op would just move the failure somewhere less obvious.
|
|
172
|
+
*/
|
|
173
|
+
private viaHost;
|
|
174
|
+
private sessionContext;
|
|
175
|
+
private eventContext;
|
|
176
|
+
/** Open-time record buckets, built ONCE off the session's shared memoized log read — the
|
|
177
|
+
* same single read goal/plan/todo fold from, so `records()` adds zero log traversals. One
|
|
178
|
+
* filter pass buckets every extension's records; ids are colon-free slugs so the
|
|
179
|
+
* "extension:<id>:" prefix parse is unambiguous. */
|
|
180
|
+
private ensureRecordSnapshot;
|
|
181
|
+
private stateFor;
|
|
182
|
+
private handlersFor;
|
|
183
|
+
private invoke;
|
|
184
|
+
private warn;
|
|
185
|
+
private requireSession;
|
|
186
|
+
}
|
|
187
|
+
export {};
|
|
188
|
+
//# sourceMappingURL=runtime.d.ts.map
|