@moxxy/sdk 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/dist/agent.d.ts +39 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +2 -0
- package/dist/agent.js.map +1 -0
- package/dist/cache-strategy.d.ts +35 -0
- package/dist/cache-strategy.d.ts.map +1 -0
- package/dist/cache-strategy.js +2 -0
- package/dist/cache-strategy.js.map +1 -0
- package/dist/channel.d.ts +146 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +2 -0
- package/dist/channel.js.map +1 -0
- package/dist/client-session.d.ts +83 -0
- package/dist/client-session.d.ts.map +1 -0
- package/dist/client-session.js +2 -0
- package/dist/client-session.js.map +1 -0
- package/dist/command.d.ts +90 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +15 -0
- package/dist/command.js.map +1 -0
- package/dist/compactor-helpers.d.ts +34 -0
- package/dist/compactor-helpers.d.ts.map +1 -0
- package/dist/compactor-helpers.js +156 -0
- package/dist/compactor-helpers.js.map +1 -0
- package/dist/compactor.d.ts +20 -0
- package/dist/compactor.d.ts.map +1 -0
- package/dist/compactor.js +2 -0
- package/dist/compactor.js.map +1 -0
- package/dist/define.d.ts +51 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +71 -0
- package/dist/define.js.map +1 -0
- package/dist/elision-helpers.d.ts +27 -0
- package/dist/elision-helpers.d.ts.map +1 -0
- package/dist/elision-helpers.js +109 -0
- package/dist/elision-helpers.js.map +1 -0
- package/dist/elision-state.d.ts +49 -0
- package/dist/elision-state.d.ts.map +1 -0
- package/dist/elision-state.js +144 -0
- package/dist/elision-state.js.map +1 -0
- package/dist/embedding-cache.d.ts +32 -0
- package/dist/embedding-cache.d.ts.map +1 -0
- package/dist/embedding-cache.js +0 -0
- package/dist/embedding-cache.js.map +1 -0
- package/dist/embedding.d.ts +21 -0
- package/dist/embedding.d.ts.map +1 -0
- package/dist/embedding.js +2 -0
- package/dist/embedding.js.map +1 -0
- package/dist/errors.d.ts +81 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +241 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +193 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/hooks.d.ts +52 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +2 -0
- package/dist/hooks.js.map +1 -0
- package/dist/ids.d.ts +18 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +7 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/install-hints.d.ts +26 -0
- package/dist/install-hints.d.ts.map +1 -0
- package/dist/install-hints.js +15 -0
- package/dist/install-hints.js.map +1 -0
- package/dist/isolation.d.ts +125 -0
- package/dist/isolation.d.ts.map +1 -0
- package/dist/isolation.js +11 -0
- package/dist/isolation.js.map +1 -0
- package/dist/log.d.ts +11 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +2 -0
- package/dist/log.js.map +1 -0
- package/dist/mode-helpers.d.ts +99 -0
- package/dist/mode-helpers.d.ts.map +1 -0
- package/dist/mode-helpers.js +368 -0
- package/dist/mode-helpers.js.map +1 -0
- package/dist/mode.d.ts +133 -0
- package/dist/mode.d.ts.map +1 -0
- package/dist/mode.js +2 -0
- package/dist/mode.js.map +1 -0
- package/dist/permission.d.ts +35 -0
- package/dist/permission.d.ts.map +1 -0
- package/dist/permission.js +2 -0
- package/dist/permission.js.map +1 -0
- package/dist/plugin.d.ts +88 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -0
- package/dist/provider-utils.d.ts +40 -0
- package/dist/provider-utils.d.ts.map +1 -0
- package/dist/provider-utils.js +163 -0
- package/dist/provider-utils.js.map +1 -0
- package/dist/provider.d.ts +219 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +2 -0
- package/dist/provider.js.map +1 -0
- package/dist/requirements.d.ts +22 -0
- package/dist/requirements.d.ts.map +1 -0
- package/dist/requirements.js +2 -0
- package/dist/requirements.js.map +1 -0
- package/dist/schemas.d.ts +228 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +88 -0
- package/dist/schemas.js.map +1 -0
- package/dist/session-like.d.ts +111 -0
- package/dist/session-like.d.ts.map +1 -0
- package/dist/session-like.js +2 -0
- package/dist/session-like.js.map +1 -0
- package/dist/skill.d.ts +30 -0
- package/dist/skill.d.ts.map +1 -0
- package/dist/skill.js +2 -0
- package/dist/skill.js.map +1 -0
- package/dist/subagent.d.ts +45 -0
- package/dist/subagent.d.ts.map +1 -0
- package/dist/subagent.js +11 -0
- package/dist/subagent.js.map +1 -0
- package/dist/token-accounting.d.ts +73 -0
- package/dist/token-accounting.d.ts.map +1 -0
- package/dist/token-accounting.js +129 -0
- package/dist/token-accounting.js.map +1 -0
- package/dist/tool-dispatch.d.ts +19 -0
- package/dist/tool-dispatch.d.ts.map +1 -0
- package/dist/tool-dispatch.js +118 -0
- package/dist/tool-dispatch.js.map +1 -0
- package/dist/tool-gating.d.ts +32 -0
- package/dist/tool-gating.d.ts.map +1 -0
- package/dist/tool-gating.js +83 -0
- package/dist/tool-gating.js.map +1 -0
- package/dist/tool.d.ts +166 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +2 -0
- package/dist/tool.js.map +1 -0
- package/dist/transcriber.d.ts +64 -0
- package/dist/transcriber.d.ts.map +1 -0
- package/dist/transcriber.js +21 -0
- package/dist/transcriber.js.map +1 -0
- package/dist/tunnel.d.ts +25 -0
- package/dist/tunnel.d.ts.map +1 -0
- package/dist/tunnel.js +2 -0
- package/dist/tunnel.js.map +1 -0
- package/dist/type-contracts.d.ts +2 -0
- package/dist/type-contracts.d.ts.map +1 -0
- package/dist/type-contracts.js +4 -0
- package/dist/type-contracts.js.map +1 -0
- package/dist/types.test-d.d.ts +2 -0
- package/dist/types.test-d.d.ts.map +1 -0
- package/dist/types.test-d.js +22 -0
- package/dist/types.test-d.js.map +1 -0
- package/dist/view-renderer.d.ts +97 -0
- package/dist/view-renderer.d.ts.map +1 -0
- package/dist/view-renderer.js +72 -0
- package/dist/view-renderer.js.map +1 -0
- package/package.json +38 -0
- package/src/agent.ts +38 -0
- package/src/cache-strategy.ts +39 -0
- package/src/channel.ts +158 -0
- package/src/client-session.ts +88 -0
- package/src/command.ts +86 -0
- package/src/compactor-helpers.test.ts +206 -0
- package/src/compactor-helpers.ts +163 -0
- package/src/compactor.ts +20 -0
- package/src/define.test.ts +76 -0
- package/src/define.ts +113 -0
- package/src/elision-helpers.ts +143 -0
- package/src/elision-state.ts +170 -0
- package/src/embedding-cache.ts +0 -0
- package/src/embedding.ts +22 -0
- package/src/errors.test.ts +176 -0
- package/src/errors.ts +308 -0
- package/src/events.ts +250 -0
- package/src/hooks.ts +54 -0
- package/src/ids.ts +16 -0
- package/src/index.ts +304 -0
- package/src/install-hints.ts +43 -0
- package/src/isolation.ts +148 -0
- package/src/log.ts +11 -0
- package/src/loop-helpers.test.ts +78 -0
- package/src/mode-helpers.ts +483 -0
- package/src/mode.ts +139 -0
- package/src/package-root.test.ts +40 -0
- package/src/permission.ts +37 -0
- package/src/plugin.ts +92 -0
- package/src/provider-utils.test.ts +84 -0
- package/src/provider-utils.ts +171 -0
- package/src/provider.ts +195 -0
- package/src/requirements.ts +35 -0
- package/src/schemas.test.ts +106 -0
- package/src/schemas.ts +97 -0
- package/src/session-like.ts +118 -0
- package/src/skill.ts +34 -0
- package/src/subagent.ts +46 -0
- package/src/token-accounting.test.ts +93 -0
- package/src/token-accounting.ts +202 -0
- package/src/token-efficiency.test.ts +459 -0
- package/src/tool-dispatch.ts +137 -0
- package/src/tool-gating.ts +107 -0
- package/src/tool.ts +175 -0
- package/src/transcriber.ts +71 -0
- package/src/tunnel.ts +26 -0
- package/src/type-contracts.ts +4 -0
- package/src/types.test-d.ts +29 -0
- package/src/view-renderer.test.ts +90 -0
- package/src/view-renderer.ts +156 -0
package/src/events.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import type { EventId, PluginId, SessionId, SkillId, ToolCallId, TurnId } from './ids.js';
|
|
2
|
+
|
|
3
|
+
export type EventSource = 'user' | 'model' | 'tool' | 'plugin' | 'system' | 'compactor';
|
|
4
|
+
|
|
5
|
+
export interface EventBase {
|
|
6
|
+
readonly id: EventId;
|
|
7
|
+
readonly seq: number;
|
|
8
|
+
readonly ts: number;
|
|
9
|
+
readonly sessionId: SessionId;
|
|
10
|
+
readonly turnId: TurnId;
|
|
11
|
+
readonly causationId?: EventId;
|
|
12
|
+
readonly source: EventSource;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface UserPromptAttachment {
|
|
16
|
+
readonly kind: 'stdin' | 'file' | 'image' | 'audio';
|
|
17
|
+
/**
|
|
18
|
+
* Inline payload. For images this is base64-encoded bytes; for audio it
|
|
19
|
+
* is either base64-encoded bytes (when the channel hands raw audio
|
|
20
|
+
* straight through to a model with `supportsAudio`) or the transcript
|
|
21
|
+
* (when the channel pre-transcribed via the session's Transcriber).
|
|
22
|
+
* Channels SHOULD set `name` to disambiguate the two; `mediaType` is
|
|
23
|
+
* required when carrying raw audio bytes.
|
|
24
|
+
*/
|
|
25
|
+
readonly content: string;
|
|
26
|
+
/** Human-readable label, e.g. the file path, `image.png`, or `voice.ogg`. */
|
|
27
|
+
readonly name?: string;
|
|
28
|
+
/** MIME type — required for images and raw audio so providers translate correctly. */
|
|
29
|
+
readonly mediaType?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface UserPromptEvent extends EventBase {
|
|
33
|
+
readonly type: 'user_prompt';
|
|
34
|
+
readonly text: string;
|
|
35
|
+
readonly attachments?: ReadonlyArray<UserPromptAttachment>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AssistantChunkEvent extends EventBase {
|
|
39
|
+
readonly type: 'assistant_chunk';
|
|
40
|
+
readonly delta: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AssistantMessageEvent extends EventBase {
|
|
44
|
+
readonly type: 'assistant_message';
|
|
45
|
+
readonly content: string;
|
|
46
|
+
readonly stopReason: 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence' | 'error';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ToolCallRequestedEvent extends EventBase {
|
|
50
|
+
readonly type: 'tool_call_requested';
|
|
51
|
+
readonly callId: ToolCallId;
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly input: unknown;
|
|
54
|
+
readonly skillContext?: SkillId;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ToolCallApprovedEvent extends EventBase {
|
|
58
|
+
readonly type: 'tool_call_approved';
|
|
59
|
+
readonly callId: ToolCallId;
|
|
60
|
+
readonly decidedBy: 'policy' | 'resolver' | 'hook';
|
|
61
|
+
readonly mode: 'allow' | 'allow_session' | 'allow_always';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ToolCallDeniedEvent extends EventBase {
|
|
65
|
+
readonly type: 'tool_call_denied';
|
|
66
|
+
readonly callId: ToolCallId;
|
|
67
|
+
readonly decidedBy: 'policy' | 'resolver' | 'hook';
|
|
68
|
+
readonly reason: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ToolResultEvent extends EventBase {
|
|
72
|
+
readonly type: 'tool_result';
|
|
73
|
+
readonly callId: ToolCallId;
|
|
74
|
+
readonly ok: boolean;
|
|
75
|
+
readonly output?: unknown;
|
|
76
|
+
readonly error?: { message: string; kind: 'aborted' | 'threw' | 'denied' | 'timeout' };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface SkillInvokedEvent extends EventBase {
|
|
80
|
+
readonly type: 'skill_invoked';
|
|
81
|
+
readonly skillId: SkillId;
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly reason: 'trigger_match' | 'classifier' | 'manual' | 'load_skill_tool';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface SkillCreatedEvent extends EventBase {
|
|
87
|
+
readonly type: 'skill_created';
|
|
88
|
+
readonly skillId: SkillId;
|
|
89
|
+
readonly name: string;
|
|
90
|
+
readonly path: string;
|
|
91
|
+
readonly scope: 'user' | 'project';
|
|
92
|
+
readonly originatingPrompt: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface PluginRegisteredEvent extends EventBase {
|
|
96
|
+
readonly type: 'plugin_registered';
|
|
97
|
+
readonly pluginId: PluginId;
|
|
98
|
+
readonly name: string;
|
|
99
|
+
readonly version: string;
|
|
100
|
+
// Keep in sync with PluginKind (plugin.ts). Inlined rather than imported to
|
|
101
|
+
// avoid an events↔plugin type cycle (dep-cruiser flags circular deps).
|
|
102
|
+
readonly kind: ReadonlyArray<
|
|
103
|
+
| 'tools'
|
|
104
|
+
| 'provider'
|
|
105
|
+
| 'mode'
|
|
106
|
+
| 'compactor'
|
|
107
|
+
| 'cache-strategy'
|
|
108
|
+
| 'view-renderer'
|
|
109
|
+
| 'tunnel-provider'
|
|
110
|
+
| 'mcp'
|
|
111
|
+
| 'cli'
|
|
112
|
+
| 'channel'
|
|
113
|
+
| 'hooks'
|
|
114
|
+
| 'agent'
|
|
115
|
+
| 'command'
|
|
116
|
+
| 'transcriber'
|
|
117
|
+
>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface PluginUnregisteredEvent extends EventBase {
|
|
121
|
+
readonly type: 'plugin_unregistered';
|
|
122
|
+
readonly pluginId: PluginId;
|
|
123
|
+
readonly name: string;
|
|
124
|
+
readonly reason: 'reload' | 'shutdown' | 'disabled';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface ModeIterationEvent extends EventBase {
|
|
128
|
+
readonly type: 'mode_iteration';
|
|
129
|
+
readonly strategy: string;
|
|
130
|
+
readonly iteration: number;
|
|
131
|
+
readonly routing?: 'resolved' | 'unresolved' | 'synthesized';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface CompactionEvent extends EventBase {
|
|
135
|
+
readonly type: 'compaction';
|
|
136
|
+
readonly compactor: string;
|
|
137
|
+
/**
|
|
138
|
+
* Inclusive `[fromSeq, toSeq]` range of event `seq` values this summary
|
|
139
|
+
* replaces — NOT array indices. Consumers (`projectMessagesFromLog`,
|
|
140
|
+
* `estimateContextTokens`) test `event.seq` against these bounds, so a
|
|
141
|
+
* compactor MUST emit the `seq` of the first/last replaced event. (Today
|
|
142
|
+
* `seq === arrayIndex` in the primary log, but that is not guaranteed for
|
|
143
|
+
* mirrors or partial views — emit seqs to stay correct regardless.)
|
|
144
|
+
*/
|
|
145
|
+
readonly replacedRange: readonly [number, number];
|
|
146
|
+
readonly summary: string;
|
|
147
|
+
readonly tokensSaved: number;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Records a turn-boundary elision step (context-on-demand). Events at or below
|
|
152
|
+
* `elidedThrough` (and not covered by a compaction) are projected as compact
|
|
153
|
+
* stubs the model can expand with the `recall` tool. The high-water mark only
|
|
154
|
+
* advances on whole-turn boundaries, so the elided prefix stays byte-stable
|
|
155
|
+
* across the inner iterations of a turn — which is what lets prompt caching
|
|
156
|
+
* keep hitting.
|
|
157
|
+
*/
|
|
158
|
+
export interface ElisionEvent extends EventBase {
|
|
159
|
+
readonly type: 'elision';
|
|
160
|
+
/** Inclusive seq high-water mark: events with `seq <= elidedThrough` are stubbed. */
|
|
161
|
+
readonly elidedThrough: number;
|
|
162
|
+
/** Turn-aligned [from,to] seq ranges newly stubbed by this step (informational). */
|
|
163
|
+
readonly stubbedRanges: ReadonlyArray<readonly [number, number]>;
|
|
164
|
+
/**
|
|
165
|
+
* Whether old user/assistant text turns (not just bulky tool results) are
|
|
166
|
+
* collapsed to stubs. Carried on the event so `projectMessagesFromLog` stays
|
|
167
|
+
* a pure function of the log (no need to thread config through projection).
|
|
168
|
+
* Note: even when true, conversational elision auto-disables for the session
|
|
169
|
+
* once seq-based `recall` calls reach `conversationalRecallThreshold`.
|
|
170
|
+
*/
|
|
171
|
+
readonly elideConversational: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Adaptive safety: after this many `recall({ seq })` calls (the form used to
|
|
174
|
+
* recall elided TEXT turns), conversational elision turns off for the rest of
|
|
175
|
+
* the session. Carried on the event so projection decides it from the log.
|
|
176
|
+
*/
|
|
177
|
+
readonly conversationalRecallThreshold: number;
|
|
178
|
+
/** Cap on total bytes of recalled content pinned verbatim below the HWM. */
|
|
179
|
+
readonly maxRecallBytes: number;
|
|
180
|
+
/** Tool names whose results are never stubbed (kept verbatim regardless of age). */
|
|
181
|
+
readonly neverElideTools: ReadonlyArray<string>;
|
|
182
|
+
readonly tokensSaved: number;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface ProviderRequestEvent extends EventBase {
|
|
186
|
+
readonly type: 'provider_request';
|
|
187
|
+
readonly provider: string;
|
|
188
|
+
readonly model: string;
|
|
189
|
+
readonly inputTokens?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface ProviderResponseEvent extends EventBase {
|
|
193
|
+
readonly type: 'provider_response';
|
|
194
|
+
readonly provider: string;
|
|
195
|
+
readonly model: string;
|
|
196
|
+
readonly inputTokens?: number;
|
|
197
|
+
readonly outputTokens?: number;
|
|
198
|
+
readonly cacheReadTokens?: number;
|
|
199
|
+
readonly cacheCreationTokens?: number;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface ErrorEvent extends EventBase {
|
|
203
|
+
readonly type: 'error';
|
|
204
|
+
readonly kind: 'retryable' | 'fatal' | 'tool_threw' | 'hook_failed' | 'provider_failed';
|
|
205
|
+
readonly message: string;
|
|
206
|
+
readonly sourceEventId?: EventId;
|
|
207
|
+
readonly attempt?: number;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface AbortEvent extends EventBase {
|
|
211
|
+
readonly type: 'abort';
|
|
212
|
+
readonly reason: string;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface PluginEvent extends EventBase {
|
|
216
|
+
readonly type: 'plugin_event';
|
|
217
|
+
readonly pluginId: PluginId;
|
|
218
|
+
readonly subtype: string;
|
|
219
|
+
readonly payload: unknown;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export type MoxxyEvent =
|
|
223
|
+
| UserPromptEvent
|
|
224
|
+
| AssistantChunkEvent
|
|
225
|
+
| AssistantMessageEvent
|
|
226
|
+
| ToolCallRequestedEvent
|
|
227
|
+
| ToolCallApprovedEvent
|
|
228
|
+
| ToolCallDeniedEvent
|
|
229
|
+
| ToolResultEvent
|
|
230
|
+
| SkillInvokedEvent
|
|
231
|
+
| SkillCreatedEvent
|
|
232
|
+
| PluginRegisteredEvent
|
|
233
|
+
| PluginUnregisteredEvent
|
|
234
|
+
| ModeIterationEvent
|
|
235
|
+
| CompactionEvent
|
|
236
|
+
| ElisionEvent
|
|
237
|
+
| ProviderRequestEvent
|
|
238
|
+
| ProviderResponseEvent
|
|
239
|
+
| ErrorEvent
|
|
240
|
+
| AbortEvent
|
|
241
|
+
| PluginEvent;
|
|
242
|
+
|
|
243
|
+
export type MoxxyEventType = MoxxyEvent['type'];
|
|
244
|
+
export type MoxxyEventOfType<T extends MoxxyEventType> = Extract<MoxxyEvent, { type: T }>;
|
|
245
|
+
|
|
246
|
+
export type EmittedEvent = MoxxyEvent extends infer E
|
|
247
|
+
? E extends MoxxyEvent
|
|
248
|
+
? Omit<E, 'id' | 'seq' | 'ts'> & { ts?: number }
|
|
249
|
+
: never
|
|
250
|
+
: never;
|
package/src/hooks.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { MoxxyEvent, ToolCallRequestedEvent, ToolResultEvent } from './events.js';
|
|
2
|
+
import type { EventLogReader } from './log.js';
|
|
3
|
+
import type { PendingToolCall } from './permission.js';
|
|
4
|
+
import type { ProviderRequest } from './provider.js';
|
|
5
|
+
import type { SessionId, TurnId } from './ids.js';
|
|
6
|
+
|
|
7
|
+
export interface AppContext {
|
|
8
|
+
readonly sessionId: SessionId;
|
|
9
|
+
readonly cwd: string;
|
|
10
|
+
readonly log: EventLogReader;
|
|
11
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TurnContext extends AppContext {
|
|
15
|
+
readonly turnId: TurnId;
|
|
16
|
+
readonly iteration: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ToolCallContext extends TurnContext {
|
|
20
|
+
readonly call: PendingToolCall;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ToolResultContext extends TurnContext {
|
|
24
|
+
readonly result: ToolResultEvent;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ToolCallVerdict =
|
|
28
|
+
| { readonly action: 'allow' }
|
|
29
|
+
| { readonly action: 'deny'; readonly reason: string }
|
|
30
|
+
| { readonly action: 'rewrite'; readonly input: unknown };
|
|
31
|
+
|
|
32
|
+
export interface LifecycleHooks {
|
|
33
|
+
onInit?(ctx: AppContext): void | Promise<void>;
|
|
34
|
+
onTurnStart?(ctx: TurnContext): void | Promise<void>;
|
|
35
|
+
onBeforeProviderCall?(req: ProviderRequest, ctx: TurnContext): ProviderRequest | void | Promise<ProviderRequest | void>;
|
|
36
|
+
onToolCall?(ctx: ToolCallContext): ToolCallVerdict | void | Promise<ToolCallVerdict | void>;
|
|
37
|
+
onToolResult?(ctx: ToolResultContext): ToolResultEvent | void | Promise<ToolResultEvent | void>;
|
|
38
|
+
onEvent?(event: MoxxyEvent, ctx: AppContext): void | Promise<void>;
|
|
39
|
+
onTurnEnd?(ctx: TurnContext): void | Promise<void>;
|
|
40
|
+
onShutdown?(ctx: AppContext): void | Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface HookDispatcher {
|
|
44
|
+
dispatchInit(ctx: AppContext): Promise<void>;
|
|
45
|
+
dispatchTurnStart(ctx: TurnContext): Promise<void>;
|
|
46
|
+
dispatchBeforeProviderCall(req: ProviderRequest, ctx: TurnContext): Promise<ProviderRequest>;
|
|
47
|
+
dispatchToolCall(ctx: ToolCallContext): Promise<ToolCallVerdict>;
|
|
48
|
+
dispatchToolResult(ctx: ToolResultContext): Promise<ToolResultEvent>;
|
|
49
|
+
dispatchEvent(event: MoxxyEvent, ctx: AppContext): Promise<void>;
|
|
50
|
+
dispatchTurnEnd(ctx: TurnContext): Promise<void>;
|
|
51
|
+
dispatchShutdown(ctx: AppContext): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type ToolCallRequest = ToolCallRequestedEvent;
|
package/src/ids.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const brand: unique symbol;
|
|
2
|
+
type Brand<T, B extends string> = T & { readonly [brand]: B };
|
|
3
|
+
|
|
4
|
+
export type EventId = Brand<string, 'EventId'>;
|
|
5
|
+
export type TurnId = Brand<string, 'TurnId'>;
|
|
6
|
+
export type ToolCallId = Brand<string, 'ToolCallId'>;
|
|
7
|
+
export type SessionId = Brand<string, 'SessionId'>;
|
|
8
|
+
export type PluginId = Brand<string, 'PluginId'>;
|
|
9
|
+
export type SkillId = Brand<string, 'SkillId'>;
|
|
10
|
+
|
|
11
|
+
export const asEventId = (s: string): EventId => s as EventId;
|
|
12
|
+
export const asTurnId = (s: string): TurnId => s as TurnId;
|
|
13
|
+
export const asToolCallId = (s: string): ToolCallId => s as ToolCallId;
|
|
14
|
+
export const asSessionId = (s: string): SessionId => s as SessionId;
|
|
15
|
+
export const asPluginId = (s: string): PluginId => s as PluginId;
|
|
16
|
+
export const asSkillId = (s: string): SkillId => s as SkillId;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
EventId,
|
|
3
|
+
TurnId,
|
|
4
|
+
ToolCallId,
|
|
5
|
+
SessionId,
|
|
6
|
+
PluginId,
|
|
7
|
+
SkillId,
|
|
8
|
+
} from './ids.js';
|
|
9
|
+
export { asEventId, asTurnId, asToolCallId, asSessionId, asPluginId, asSkillId } from './ids.js';
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
EventBase,
|
|
13
|
+
EventSource,
|
|
14
|
+
MoxxyEvent,
|
|
15
|
+
MoxxyEventType,
|
|
16
|
+
MoxxyEventOfType,
|
|
17
|
+
EmittedEvent,
|
|
18
|
+
UserPromptEvent,
|
|
19
|
+
UserPromptAttachment,
|
|
20
|
+
AssistantChunkEvent,
|
|
21
|
+
AssistantMessageEvent,
|
|
22
|
+
ToolCallRequestedEvent,
|
|
23
|
+
ToolCallApprovedEvent,
|
|
24
|
+
ToolCallDeniedEvent,
|
|
25
|
+
ToolResultEvent,
|
|
26
|
+
SkillInvokedEvent,
|
|
27
|
+
SkillCreatedEvent,
|
|
28
|
+
PluginRegisteredEvent,
|
|
29
|
+
PluginUnregisteredEvent,
|
|
30
|
+
ModeIterationEvent,
|
|
31
|
+
CompactionEvent,
|
|
32
|
+
ProviderRequestEvent,
|
|
33
|
+
ProviderResponseEvent,
|
|
34
|
+
ErrorEvent,
|
|
35
|
+
AbortEvent,
|
|
36
|
+
PluginEvent,
|
|
37
|
+
} from './events.js';
|
|
38
|
+
|
|
39
|
+
export type { EventLogReader } from './log.js';
|
|
40
|
+
|
|
41
|
+
export type {
|
|
42
|
+
RunTurnOptions,
|
|
43
|
+
SessionLogReader,
|
|
44
|
+
SessionLike,
|
|
45
|
+
SessionInfo,
|
|
46
|
+
ProviderInfo,
|
|
47
|
+
ToolInfo,
|
|
48
|
+
SkillInfo,
|
|
49
|
+
CommandInfo,
|
|
50
|
+
} from './session-like.js';
|
|
51
|
+
|
|
52
|
+
export type {
|
|
53
|
+
ClientSession,
|
|
54
|
+
ProvidersClientView,
|
|
55
|
+
ModesClientView,
|
|
56
|
+
ToolsClientView,
|
|
57
|
+
CommandsClientView,
|
|
58
|
+
SkillsClientView,
|
|
59
|
+
AgentsClientView,
|
|
60
|
+
TranscribersClientView,
|
|
61
|
+
RequirementsClientView,
|
|
62
|
+
PermissionsClientView,
|
|
63
|
+
} from './client-session.js';
|
|
64
|
+
|
|
65
|
+
export type {
|
|
66
|
+
PermissionMode,
|
|
67
|
+
PermissionDecision,
|
|
68
|
+
PermissionRule,
|
|
69
|
+
PendingToolCall,
|
|
70
|
+
PermissionContext,
|
|
71
|
+
PermissionResolver,
|
|
72
|
+
} from './permission.js';
|
|
73
|
+
|
|
74
|
+
export type {
|
|
75
|
+
ToolContext,
|
|
76
|
+
ToolDef,
|
|
77
|
+
ToolCompactPresentation,
|
|
78
|
+
BrokeredFs,
|
|
79
|
+
BrokeredStat,
|
|
80
|
+
BrokeredFetch,
|
|
81
|
+
BrokeredFetchInit,
|
|
82
|
+
BrokeredFetchResponse,
|
|
83
|
+
BrokeredExec,
|
|
84
|
+
BrokeredExecOpts,
|
|
85
|
+
BrokeredExecResult,
|
|
86
|
+
} from './tool.js';
|
|
87
|
+
|
|
88
|
+
export type {
|
|
89
|
+
FsCapability,
|
|
90
|
+
NetCapability,
|
|
91
|
+
CapabilitySpec,
|
|
92
|
+
IsolationStrength,
|
|
93
|
+
ToolIsolationSpec,
|
|
94
|
+
IsolatedToolCall,
|
|
95
|
+
Isolator,
|
|
96
|
+
HandlerModuleRef,
|
|
97
|
+
} from './isolation.js';
|
|
98
|
+
export { ISOLATION_RANK } from './isolation.js';
|
|
99
|
+
|
|
100
|
+
export type {
|
|
101
|
+
SubagentSpec,
|
|
102
|
+
SubagentResult,
|
|
103
|
+
SubagentSpawner,
|
|
104
|
+
} from './subagent.js';
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export type {
|
|
108
|
+
ContentBlock,
|
|
109
|
+
ProviderMessage,
|
|
110
|
+
ProviderRequest,
|
|
111
|
+
ProviderEvent,
|
|
112
|
+
CacheHint,
|
|
113
|
+
TokenUsage,
|
|
114
|
+
ModelDescriptor,
|
|
115
|
+
LLMProvider,
|
|
116
|
+
ProviderDef,
|
|
117
|
+
ProviderKeyValidation,
|
|
118
|
+
ProviderVault,
|
|
119
|
+
ProviderAuthContext,
|
|
120
|
+
ProviderOAuthResult,
|
|
121
|
+
ProviderOAuthStatus,
|
|
122
|
+
ProviderAuthDescriptor,
|
|
123
|
+
} from './provider.js';
|
|
124
|
+
export type { CacheStrategyDef, CacheStrategyContext } from './cache-strategy.js';
|
|
125
|
+
export type {
|
|
126
|
+
ViewNode,
|
|
127
|
+
ViewAction,
|
|
128
|
+
ViewDoc,
|
|
129
|
+
ViewParseError,
|
|
130
|
+
ViewParseResult,
|
|
131
|
+
AttrType,
|
|
132
|
+
AttrSpec,
|
|
133
|
+
ViewTagSpec,
|
|
134
|
+
ViewRendererDef,
|
|
135
|
+
} from './view-renderer.js';
|
|
136
|
+
export { VIEW_PRIMITIVES, VIEW_COMPONENTS, DEFAULT_VIEW_TAGS } from './view-renderer.js';
|
|
137
|
+
export type { TunnelProviderDef, TunnelHandle, TunnelOpenOptions } from './tunnel.js';
|
|
138
|
+
export { isRetryableError, toFriendlyError, zodToJsonSchema, type StopReason } from './provider-utils.js';
|
|
139
|
+
export {
|
|
140
|
+
MoxxyError,
|
|
141
|
+
classifyHttpStatus,
|
|
142
|
+
classifyNetworkError,
|
|
143
|
+
type MoxxyErrorCode,
|
|
144
|
+
type MoxxyErrorInit,
|
|
145
|
+
} from './errors.js';
|
|
146
|
+
export {
|
|
147
|
+
collectProviderStream,
|
|
148
|
+
projectMessagesFromLog,
|
|
149
|
+
projectMessages,
|
|
150
|
+
buildSystemPromptWithSkills,
|
|
151
|
+
type CollectedToolUse,
|
|
152
|
+
type StreamResult,
|
|
153
|
+
type ProjectMessagesOptions,
|
|
154
|
+
type ProjectedMessages,
|
|
155
|
+
} from './mode-helpers.js';
|
|
156
|
+
export { dispatchToolCall } from './tool-dispatch.js';
|
|
157
|
+
|
|
158
|
+
export type { TokenBudget, CompactContext, CompactorDef } from './compactor.js';
|
|
159
|
+
export { estimateContextTokens, runCompactionIfNeeded } from './compactor-helpers.js';
|
|
160
|
+
export {
|
|
161
|
+
runElisionIfNeeded,
|
|
162
|
+
resolveElisionSettings,
|
|
163
|
+
type ResolvedElisionSettings,
|
|
164
|
+
} from './elision-helpers.js';
|
|
165
|
+
export {
|
|
166
|
+
computeElisionState,
|
|
167
|
+
toolResultStub,
|
|
168
|
+
conversationalStub,
|
|
169
|
+
toolResultBytes,
|
|
170
|
+
toolResultStubbed,
|
|
171
|
+
conversationalStubbed,
|
|
172
|
+
TINY_TURN_CHARS,
|
|
173
|
+
type ElisionState,
|
|
174
|
+
} from './elision-state.js';
|
|
175
|
+
export {
|
|
176
|
+
applyLazyTools,
|
|
177
|
+
buildToolIndex,
|
|
178
|
+
loadedToolNames,
|
|
179
|
+
ALWAYS_ON_TOOLS,
|
|
180
|
+
type GatedTools,
|
|
181
|
+
} from './tool-gating.js';
|
|
182
|
+
|
|
183
|
+
export {
|
|
184
|
+
summarizeSessionTokens,
|
|
185
|
+
summarizeSessionTokensFromEvents,
|
|
186
|
+
summarizeTokensByModel,
|
|
187
|
+
addModelTotals,
|
|
188
|
+
usageEventFields,
|
|
189
|
+
type SessionTokenSummary,
|
|
190
|
+
type ModelUsageTotals,
|
|
191
|
+
} from './token-accounting.js';
|
|
192
|
+
|
|
193
|
+
export type { Skill, SkillDef, SkillFrontmatter, SkillScope, SkillSchedule } from './skill.js';
|
|
194
|
+
|
|
195
|
+
export type { AgentDef } from './agent.js';
|
|
196
|
+
|
|
197
|
+
export type {
|
|
198
|
+
CommandDef,
|
|
199
|
+
CommandContext,
|
|
200
|
+
CommandOutput,
|
|
201
|
+
CommandHandlerResult,
|
|
202
|
+
} from './command.js';
|
|
203
|
+
|
|
204
|
+
export type {
|
|
205
|
+
ToolRegistry,
|
|
206
|
+
SkillRegistry,
|
|
207
|
+
PluginHostHandle,
|
|
208
|
+
ModeContext,
|
|
209
|
+
ModeDef,
|
|
210
|
+
ElisionSettings,
|
|
211
|
+
ApprovalResolver,
|
|
212
|
+
ApprovalRequest,
|
|
213
|
+
ApprovalDecision,
|
|
214
|
+
ApprovalOption,
|
|
215
|
+
} from './mode.js';
|
|
216
|
+
|
|
217
|
+
export type {
|
|
218
|
+
AppContext,
|
|
219
|
+
TurnContext,
|
|
220
|
+
ToolCallContext,
|
|
221
|
+
ToolResultContext,
|
|
222
|
+
ToolCallVerdict,
|
|
223
|
+
ToolCallRequest,
|
|
224
|
+
LifecycleHooks,
|
|
225
|
+
HookDispatcher,
|
|
226
|
+
} from './hooks.js';
|
|
227
|
+
|
|
228
|
+
export type {
|
|
229
|
+
PluginKind,
|
|
230
|
+
PluginSpec,
|
|
231
|
+
Plugin,
|
|
232
|
+
PluginManifest,
|
|
233
|
+
ResolvedPluginManifest,
|
|
234
|
+
} from './plugin.js';
|
|
235
|
+
|
|
236
|
+
export type {
|
|
237
|
+
Channel,
|
|
238
|
+
ChannelHandle,
|
|
239
|
+
ChannelStartOptsBase,
|
|
240
|
+
ChannelFactoryDeps,
|
|
241
|
+
ChannelDef,
|
|
242
|
+
ChannelAvailability,
|
|
243
|
+
ChannelRegistry,
|
|
244
|
+
ChannelSubcommand,
|
|
245
|
+
ChannelSubcommandContext,
|
|
246
|
+
ChannelCommandArgs,
|
|
247
|
+
} from './channel.js';
|
|
248
|
+
export type { EmbeddingProvider } from './embedding.js';
|
|
249
|
+
export { CachedEmbeddingProvider } from './embedding-cache.js';
|
|
250
|
+
|
|
251
|
+
export type {
|
|
252
|
+
RequirementKind,
|
|
253
|
+
RequirementState,
|
|
254
|
+
MoxxyRequirement,
|
|
255
|
+
RequirementIssue,
|
|
256
|
+
RequirementCheck,
|
|
257
|
+
} from './requirements.js';
|
|
258
|
+
|
|
259
|
+
export type {
|
|
260
|
+
Transcriber,
|
|
261
|
+
TranscriberDef,
|
|
262
|
+
TranscriptionResult,
|
|
263
|
+
TranscriptionSegment,
|
|
264
|
+
TranscribeOptions,
|
|
265
|
+
} from './transcriber.js';
|
|
266
|
+
|
|
267
|
+
export interface PluginLoader {
|
|
268
|
+
load(manifest: import('./plugin.js').ResolvedPluginManifest): Promise<import('./plugin.js').Plugin>;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export {
|
|
272
|
+
definePlugin,
|
|
273
|
+
defineTool,
|
|
274
|
+
defineProvider,
|
|
275
|
+
defineMode,
|
|
276
|
+
defineCompactor,
|
|
277
|
+
defineCacheStrategy,
|
|
278
|
+
defineViewRenderer,
|
|
279
|
+
defineTunnelProvider,
|
|
280
|
+
defineChannel,
|
|
281
|
+
definePermission,
|
|
282
|
+
defineSkill,
|
|
283
|
+
defineTranscriber,
|
|
284
|
+
defineCommand,
|
|
285
|
+
defineAgent,
|
|
286
|
+
} from './define.js';
|
|
287
|
+
|
|
288
|
+
export {
|
|
289
|
+
skillFrontmatterSchema,
|
|
290
|
+
pluginManifestSchema,
|
|
291
|
+
moxxyPackageSchema,
|
|
292
|
+
requirementSchema,
|
|
293
|
+
type SkillFrontmatterInput,
|
|
294
|
+
type PluginManifestInput,
|
|
295
|
+
type MoxxyPackageInput,
|
|
296
|
+
} from './schemas.js';
|
|
297
|
+
|
|
298
|
+
export {
|
|
299
|
+
getInstallHint,
|
|
300
|
+
type InstallHint,
|
|
301
|
+
type InstallTarget,
|
|
302
|
+
} from './install-hints.js';
|
|
303
|
+
|
|
304
|
+
export { z } from 'zod';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic "how does the user install <thing> on their OS" helper, used by
|
|
3
|
+
* plugins that depend on a native binary they can't bundle themselves.
|
|
4
|
+
* Voice input wants ffmpeg; a transcription plugin might want
|
|
5
|
+
* `sox`/`opus-tools`; a doc-rendering plugin might want `pandoc`. Each
|
|
6
|
+
* caller passes either a single package name (when it's the same across
|
|
7
|
+
* platforms — the common case for widely-packaged tools) or a per-
|
|
8
|
+
* platform map for tools whose package name differs.
|
|
9
|
+
*
|
|
10
|
+
* The helper is informational. We never auto-run a system installer
|
|
11
|
+
* here: package managers prompt for sudo/UAC, and that doesn't fit a
|
|
12
|
+
* TUI cleanly. Callers render the returned command in their UI and the
|
|
13
|
+
* user runs it themselves.
|
|
14
|
+
*/
|
|
15
|
+
export interface InstallTarget {
|
|
16
|
+
/** Canonical package name. Used when `perPlatform` has no entry for the active OS. */
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** Override the package name on specific platforms (e.g. `winget` IDs). */
|
|
19
|
+
readonly perPlatform?: Partial<Record<NodeJS.Platform, string>>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface InstallHint {
|
|
23
|
+
readonly command: string;
|
|
24
|
+
readonly manager: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getInstallHint(
|
|
28
|
+
target: string | InstallTarget,
|
|
29
|
+
platform: NodeJS.Platform = process.platform,
|
|
30
|
+
): InstallHint {
|
|
31
|
+
const spec: InstallTarget = typeof target === 'string' ? { name: target } : target;
|
|
32
|
+
const pkg = spec.perPlatform?.[platform] ?? spec.name;
|
|
33
|
+
if (platform === 'darwin') {
|
|
34
|
+
return { command: `brew install ${pkg}`, manager: 'Homebrew' };
|
|
35
|
+
}
|
|
36
|
+
if (platform === 'win32') {
|
|
37
|
+
return { command: `winget install ${pkg}`, manager: 'winget' };
|
|
38
|
+
}
|
|
39
|
+
if (platform === 'linux') {
|
|
40
|
+
return { command: `sudo apt install ${pkg}`, manager: 'apt' };
|
|
41
|
+
}
|
|
42
|
+
return { command: `install ${pkg} via your platform's package manager`, manager: 'manual' };
|
|
43
|
+
}
|