@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/isolation.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filesystem capability declaration. Each entry is a glob; the special
|
|
3
|
+
* `$cwd` prefix resolves to `ToolContext.cwd` at call time, so a tool
|
|
4
|
+
* can declare "I only touch my own cwd" without hard-coding a path.
|
|
5
|
+
* Patterns are matched against absolute, normalized paths.
|
|
6
|
+
*/
|
|
7
|
+
export interface FsCapability {
|
|
8
|
+
readonly read?: ReadonlyArray<string>;
|
|
9
|
+
readonly write?: ReadonlyArray<string>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type NetCapability =
|
|
13
|
+
| { readonly mode: 'none' }
|
|
14
|
+
| { readonly mode: 'any' }
|
|
15
|
+
| { readonly mode: 'allowlist'; readonly hosts: ReadonlyArray<string> };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Declarative capability surface a tool requires. Plugin authors set
|
|
19
|
+
* this on `defineTool({ ..., isolation: { capabilities: {...} } })`.
|
|
20
|
+
*
|
|
21
|
+
* Treated as advisory until the user enables `@moxxy/plugin-security`.
|
|
22
|
+
* Once enabled, the active Isolator enforces these bounds at call time.
|
|
23
|
+
*/
|
|
24
|
+
export interface CapabilitySpec {
|
|
25
|
+
readonly fs?: FsCapability;
|
|
26
|
+
readonly net?: NetCapability;
|
|
27
|
+
readonly env?: ReadonlyArray<string>;
|
|
28
|
+
/** Wall-clock budget in milliseconds. Aborted via ctx.signal on overrun. */
|
|
29
|
+
readonly timeMs?: number;
|
|
30
|
+
/** Soft memory ceiling in MB. Honored only by isolators that support it. */
|
|
31
|
+
readonly memMb?: number;
|
|
32
|
+
/** Whether the tool may spawn child processes. Defaults to false. */
|
|
33
|
+
readonly subprocess?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Optional command allowlist for `ctx.exec` / brokered subprocess
|
|
36
|
+
* calls. Each entry can be a basename (`'echo'`) or absolute path
|
|
37
|
+
* (`'/bin/echo'`); a request matches if either form is in the list.
|
|
38
|
+
* Empty/omitted = no restriction beyond `subprocess: true`.
|
|
39
|
+
*/
|
|
40
|
+
readonly commands?: ReadonlyArray<string>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type IsolationStrength =
|
|
44
|
+
| 'none'
|
|
45
|
+
| 'inproc'
|
|
46
|
+
| 'worker'
|
|
47
|
+
| 'subprocess'
|
|
48
|
+
| 'vm'
|
|
49
|
+
| 'wasm'
|
|
50
|
+
| 'docker';
|
|
51
|
+
|
|
52
|
+
export interface ToolIsolationSpec {
|
|
53
|
+
/**
|
|
54
|
+
* Minimum isolator strength the tool author considers acceptable. If the
|
|
55
|
+
* user's configured isolator is weaker, the security plugin denies the
|
|
56
|
+
* call rather than silently running with insufficient isolation.
|
|
57
|
+
*/
|
|
58
|
+
readonly required?: IsolationStrength;
|
|
59
|
+
readonly capabilities: CapabilitySpec;
|
|
60
|
+
/**
|
|
61
|
+
* Module + export reference to the handler. Required for tools that
|
|
62
|
+
* want to be runnable under out-of-process isolators (`worker`,
|
|
63
|
+
* `subprocess`, …). When omitted, the tool is only executable under
|
|
64
|
+
* `none` / `inproc`; stronger isolators will deny.
|
|
65
|
+
*
|
|
66
|
+
* Convention: derive `url` from `import.meta.url` at `defineTool(...)` time:
|
|
67
|
+
* ```
|
|
68
|
+
* handlerModule: {
|
|
69
|
+
* url: new URL('./read-handler.js', import.meta.url).href,
|
|
70
|
+
* export: 'readHandler',
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
* — that keeps the pointer correct after the package is published.
|
|
74
|
+
*/
|
|
75
|
+
readonly handlerModule?: HandlerModuleRef;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Pointer to a tool's handler as a *module + export*. When present on
|
|
80
|
+
* `ToolDef.handlerModule`, stronger isolators (worker, subprocess, wasm)
|
|
81
|
+
* re-import that module on their side of the boundary and call the
|
|
82
|
+
* named export — closures aren't serializable across thread/process
|
|
83
|
+
* boundaries, so this declarative form is the only way to actually
|
|
84
|
+
* re-execute a handler outside the main process.
|
|
85
|
+
*
|
|
86
|
+
* `url` should be an absolute `file://` URL or import-resolvable path.
|
|
87
|
+
* The conventional shape is `new URL('./handler-module.js', import.meta.url).href`
|
|
88
|
+
* at `defineTool(...)` time, so the reference resolves correctly regardless
|
|
89
|
+
* of where the published package ends up on the consumer's disk.
|
|
90
|
+
*/
|
|
91
|
+
export interface HandlerModuleRef {
|
|
92
|
+
/** Module URL (typically `file://...`) the isolator can `import()`. */
|
|
93
|
+
readonly url: string;
|
|
94
|
+
/** Named export of the handler within that module. */
|
|
95
|
+
readonly export: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface IsolatedToolCall {
|
|
99
|
+
readonly toolName: string;
|
|
100
|
+
readonly input: unknown;
|
|
101
|
+
readonly callId: string;
|
|
102
|
+
readonly sessionId: string;
|
|
103
|
+
readonly turnId: string;
|
|
104
|
+
readonly cwd: string;
|
|
105
|
+
/**
|
|
106
|
+
* Set by the security plugin when the tool declared `handlerModule`.
|
|
107
|
+
* Isolators that re-execute the handler off-thread (worker/subprocess/…)
|
|
108
|
+
* read this; in-process isolators (`none`, `inproc`) ignore it because
|
|
109
|
+
* they invoke the bound closure directly.
|
|
110
|
+
*/
|
|
111
|
+
readonly moduleRef?: HandlerModuleRef;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Pluggable runtime for executing tools under a capability spec.
|
|
116
|
+
*
|
|
117
|
+
* The isolator receives:
|
|
118
|
+
* - `call.input` — the validated tool input.
|
|
119
|
+
* - `handler` — an in-process closure bound to the real `ToolContext`.
|
|
120
|
+
* In-process isolators (`none`, `inproc`) invoke this directly.
|
|
121
|
+
* - `call.moduleRef` — optional reference to the handler's source
|
|
122
|
+
* module. Out-of-process isolators (`worker`, `subprocess`, `wasm`)
|
|
123
|
+
* `import()` this on their side of the boundary and call the named
|
|
124
|
+
* export, because closures don't cross thread/process boundaries.
|
|
125
|
+
* An out-of-process isolator that receives a call with no `moduleRef`
|
|
126
|
+
* should deny: it has no way to actually run the handler in isolation.
|
|
127
|
+
*/
|
|
128
|
+
export interface Isolator {
|
|
129
|
+
readonly name: string;
|
|
130
|
+
readonly strength: IsolationStrength;
|
|
131
|
+
run(
|
|
132
|
+
call: IsolatedToolCall,
|
|
133
|
+
handler: (input: unknown) => Promise<unknown>,
|
|
134
|
+
caps: CapabilitySpec,
|
|
135
|
+
signal: AbortSignal,
|
|
136
|
+
): Promise<unknown>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Numerical ordering of isolation strengths. Higher = stricter. */
|
|
140
|
+
export const ISOLATION_RANK: Readonly<Record<IsolationStrength, number>> = Object.freeze({
|
|
141
|
+
none: 0,
|
|
142
|
+
inproc: 1,
|
|
143
|
+
worker: 2,
|
|
144
|
+
subprocess: 3,
|
|
145
|
+
vm: 4,
|
|
146
|
+
wasm: 5,
|
|
147
|
+
docker: 6,
|
|
148
|
+
});
|
package/src/log.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MoxxyEvent, MoxxyEventOfType, MoxxyEventType } from './events.js';
|
|
2
|
+
import type { TurnId } from './ids.js';
|
|
3
|
+
|
|
4
|
+
export interface EventLogReader {
|
|
5
|
+
readonly length: number;
|
|
6
|
+
at(seq: number): MoxxyEvent | undefined;
|
|
7
|
+
slice(from?: number, to?: number): ReadonlyArray<MoxxyEvent>;
|
|
8
|
+
ofType<T extends MoxxyEventType>(type: T): ReadonlyArray<MoxxyEventOfType<T>>;
|
|
9
|
+
byTurn(turnId: TurnId): ReadonlyArray<MoxxyEvent>;
|
|
10
|
+
toJSON(): ReadonlyArray<MoxxyEvent>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
asEventId,
|
|
4
|
+
asSessionId,
|
|
5
|
+
asTurnId,
|
|
6
|
+
projectMessagesFromLog,
|
|
7
|
+
type EventLogReader,
|
|
8
|
+
type MoxxyEvent,
|
|
9
|
+
type MoxxyEventOfType,
|
|
10
|
+
type MoxxyEventType,
|
|
11
|
+
type TurnId,
|
|
12
|
+
} from './index.js';
|
|
13
|
+
|
|
14
|
+
const sid = asSessionId('s1');
|
|
15
|
+
const t1 = asTurnId('t1');
|
|
16
|
+
const t2 = asTurnId('t2');
|
|
17
|
+
|
|
18
|
+
describe('projectMessagesFromLog', () => {
|
|
19
|
+
it('replaces compacted event ranges with the compaction summary', () => {
|
|
20
|
+
const log = reader([
|
|
21
|
+
event(0, { type: 'user_prompt', turnId: t1, source: 'user', text: 'old prompt' }),
|
|
22
|
+
event(1, {
|
|
23
|
+
type: 'assistant_message',
|
|
24
|
+
turnId: t1,
|
|
25
|
+
source: 'model',
|
|
26
|
+
content: 'old answer',
|
|
27
|
+
stopReason: 'end_turn',
|
|
28
|
+
}),
|
|
29
|
+
event(2, {
|
|
30
|
+
type: 'compaction',
|
|
31
|
+
turnId: t1,
|
|
32
|
+
source: 'compactor',
|
|
33
|
+
compactor: 'summarize-old-turns',
|
|
34
|
+
replacedRange: [0, 1],
|
|
35
|
+
summary: 'summary of old prompt and answer',
|
|
36
|
+
tokensSaved: 120,
|
|
37
|
+
}),
|
|
38
|
+
event(3, { type: 'user_prompt', turnId: t2, source: 'user', text: 'current prompt' }),
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
const messages = projectMessagesFromLog({ log });
|
|
42
|
+
|
|
43
|
+
expect(messages).toHaveLength(2);
|
|
44
|
+
expect(messages[0]).toMatchObject({
|
|
45
|
+
role: 'user',
|
|
46
|
+
content: [{ type: 'text', text: expect.stringContaining('summary of old prompt') }],
|
|
47
|
+
});
|
|
48
|
+
expect(messages[1]).toMatchObject({
|
|
49
|
+
role: 'user',
|
|
50
|
+
content: [{ type: 'text', text: 'current prompt' }],
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function reader(events: ReadonlyArray<MoxxyEvent>): EventLogReader {
|
|
56
|
+
return {
|
|
57
|
+
length: events.length,
|
|
58
|
+
at: (seq) => events[seq],
|
|
59
|
+
slice: (from = 0, to = events.length) => events.slice(from, to),
|
|
60
|
+
ofType: <T extends MoxxyEventType>(type: T): ReadonlyArray<MoxxyEventOfType<T>> =>
|
|
61
|
+
events.filter((e): e is MoxxyEventOfType<T> => e.type === type),
|
|
62
|
+
byTurn: (turnId: TurnId) => events.filter((e) => e.turnId === turnId),
|
|
63
|
+
toJSON: () => events,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function event(
|
|
68
|
+
seq: number,
|
|
69
|
+
partial: Omit<MoxxyEvent, 'id' | 'seq' | 'ts' | 'sessionId'>,
|
|
70
|
+
): MoxxyEvent {
|
|
71
|
+
return {
|
|
72
|
+
id: asEventId(`e${seq}`),
|
|
73
|
+
seq,
|
|
74
|
+
ts: seq,
|
|
75
|
+
sessionId: sid,
|
|
76
|
+
...partial,
|
|
77
|
+
} as MoxxyEvent;
|
|
78
|
+
}
|