@moxxy/agent 0.2.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 +87 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
- package/src/index.test.ts +42 -0
- package/src/index.ts +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Moxxy (moxxy.ai)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @moxxy/agent
|
|
2
|
+
|
|
3
|
+
The fastest way to run a [moxxy](https://moxxy.ai) agent — **one install, one
|
|
4
|
+
call.** Batteries included: it bundles the runtime (`@moxxy/core`), the default
|
|
5
|
+
loop, and the OpenAI + Anthropic providers behind drop-in presets.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @moxxy/agent
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Hello, agent
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { setupAgent, openaiPreset } from '@moxxy/agent';
|
|
15
|
+
|
|
16
|
+
const { ask } = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));
|
|
17
|
+
|
|
18
|
+
console.log(await ask('Write a haiku about TypeScript.'));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Stream the events instead:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const { stream } = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));
|
|
25
|
+
|
|
26
|
+
for await (const event of stream('Explain async generators.')) {
|
|
27
|
+
if (event.type === 'assistant_chunk') process.stdout.write(event.delta);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Claude, or both
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { setupAgent, openaiPreset, anthropicPreset } from '@moxxy/agent';
|
|
35
|
+
|
|
36
|
+
// Just Claude:
|
|
37
|
+
const claude = setupAgent(anthropicPreset({ apiKey: process.env.ANTHROPIC_API_KEY }));
|
|
38
|
+
|
|
39
|
+
// Or register both and switch per turn (the first preset is active):
|
|
40
|
+
const agent = setupAgent([
|
|
41
|
+
openaiPreset({ apiKey: process.env.OPENAI_API_KEY }),
|
|
42
|
+
anthropicPreset({ apiKey: process.env.ANTHROPIC_API_KEY }),
|
|
43
|
+
]);
|
|
44
|
+
await agent.ask('Hi from OpenAI');
|
|
45
|
+
agent.setProvider('anthropic');
|
|
46
|
+
await agent.ask('Now from Claude');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Add tools, swap blocks live
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { setupAgent, openaiPreset } from '@moxxy/agent';
|
|
53
|
+
import { defineTool } from '@moxxy/sdk';
|
|
54
|
+
import { z } from 'zod';
|
|
55
|
+
|
|
56
|
+
const agent = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));
|
|
57
|
+
|
|
58
|
+
agent.addTool(
|
|
59
|
+
defineTool({
|
|
60
|
+
name: 'get_weather',
|
|
61
|
+
description: 'Current weather for a city.',
|
|
62
|
+
inputSchema: z.object({ city: z.string() }),
|
|
63
|
+
handler: async ({ city }) => `Sunny in ${city}.`,
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
console.log(await agent.ask("What's the weather in Paris?"));
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`agent.session` is the live moxxy [`Session`](https://www.npmjs.com/package/@moxxy/core)
|
|
71
|
+
— full control for anything the sugar doesn't cover.
|
|
72
|
+
|
|
73
|
+
## Presets
|
|
74
|
+
|
|
75
|
+
| preset | options |
|
|
76
|
+
|---|---|
|
|
77
|
+
| `openaiPreset(opts?)` | `apiKey` (→ `OPENAI_API_KEY`), `model`, `baseURL` (OpenAI-compatible vendors: z.ai/xAI/Google/Ollama) |
|
|
78
|
+
| `anthropicPreset(opts?)` | `apiKey` (→ `ANTHROPIC_API_KEY`), `model` |
|
|
79
|
+
|
|
80
|
+
Need more control or a different provider/mode? Drop down to
|
|
81
|
+
[`@moxxy/core`](https://www.npmjs.com/package/@moxxy/core)'s `setupAgent({ plugins, provider, tools, … })`
|
|
82
|
+
and register any blocks you like — `@moxxy/agent` re-exports `setupAgent` and all
|
|
83
|
+
its types.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@moxxy/agent` — the batteries-included entry to moxxy.
|
|
3
|
+
*
|
|
4
|
+
* One install, one call. Where `@moxxy/core`'s {@link setupAgent} is the flexible,
|
|
5
|
+
* block-agnostic factory (you bring the plugins), this package bundles the
|
|
6
|
+
* default loop + the OpenAI and Anthropic providers behind drop-in **presets**:
|
|
7
|
+
*
|
|
8
|
+
* import { setupAgent, openaiPreset } from '@moxxy/agent';
|
|
9
|
+
* const { ask } = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));
|
|
10
|
+
* console.log(await ask('Hello!'));
|
|
11
|
+
*
|
|
12
|
+
* A preset is just a pre-filled {@link AgentPreset}, so they compose — pass an
|
|
13
|
+
* array to register several providers at once (the first is active; swap with
|
|
14
|
+
* `agent.setProvider(name)`):
|
|
15
|
+
*
|
|
16
|
+
* const agent = setupAgent([openaiPreset({ apiKey: a }), anthropicPreset({ apiKey: b })]);
|
|
17
|
+
* agent.setProvider('anthropic'); // for the next turn
|
|
18
|
+
*/
|
|
19
|
+
import type { AgentPreset } from '@moxxy/core';
|
|
20
|
+
export interface ProviderPresetOptions {
|
|
21
|
+
/** API key. Defaults to the provider's conventional env var
|
|
22
|
+
* (`OPENAI_API_KEY` / `ANTHROPIC_API_KEY`). */
|
|
23
|
+
readonly apiKey?: string;
|
|
24
|
+
/** Override the model id (otherwise the provider's default catalog applies). */
|
|
25
|
+
readonly model?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface OpenAIPresetOptions extends ProviderPresetOptions {
|
|
28
|
+
/** Point at an OpenAI-compatible endpoint (z.ai, xAI, Google, Ollama/local). */
|
|
29
|
+
readonly baseURL?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* One-shop OpenAI (and OpenAI-compatible) preset: the default loop + the OpenAI
|
|
33
|
+
* provider, configured + activated. `setupAgent(openaiPreset({ apiKey }))`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function openaiPreset(opts?: OpenAIPresetOptions): AgentPreset;
|
|
36
|
+
/**
|
|
37
|
+
* One-shop Anthropic (Claude) preset: the default loop + the Anthropic provider,
|
|
38
|
+
* configured + activated. `setupAgent(anthropicPreset({ apiKey }))`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function anthropicPreset(opts?: ProviderPresetOptions): AgentPreset;
|
|
41
|
+
export { setupAgent, type Agent, type AgentPreset, type SetupAgentOptions, type MoxxyEvent, type Plugin, type ToolDef, type PermissionResolver, } from '@moxxy/core';
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK/C,MAAM,WAAW,qBAAqB;IACpC;oDACgD;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,gFAAgF;IAChF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB;IAChE,gFAAgF;IAChF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAOD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,mBAAwB,GAAG,WAAW,CAYxE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,GAAE,qBAA0B,GAAG,WAAW,CAW7E;AAGD,OAAO,EACL,UAAU,EACV,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@moxxy/agent` — the batteries-included entry to moxxy.
|
|
3
|
+
*
|
|
4
|
+
* One install, one call. Where `@moxxy/core`'s {@link setupAgent} is the flexible,
|
|
5
|
+
* block-agnostic factory (you bring the plugins), this package bundles the
|
|
6
|
+
* default loop + the OpenAI and Anthropic providers behind drop-in **presets**:
|
|
7
|
+
*
|
|
8
|
+
* import { setupAgent, openaiPreset } from '@moxxy/agent';
|
|
9
|
+
* const { ask } = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));
|
|
10
|
+
* console.log(await ask('Hello!'));
|
|
11
|
+
*
|
|
12
|
+
* A preset is just a pre-filled {@link AgentPreset}, so they compose — pass an
|
|
13
|
+
* array to register several providers at once (the first is active; swap with
|
|
14
|
+
* `agent.setProvider(name)`):
|
|
15
|
+
*
|
|
16
|
+
* const agent = setupAgent([openaiPreset({ apiKey: a }), anthropicPreset({ apiKey: b })]);
|
|
17
|
+
* agent.setProvider('anthropic'); // for the next turn
|
|
18
|
+
*/
|
|
19
|
+
import defaultModePlugin from '@moxxy/mode-default';
|
|
20
|
+
import openaiPlugin from '@moxxy/plugin-provider-openai';
|
|
21
|
+
import anthropicPlugin from '@moxxy/plugin-provider-anthropic';
|
|
22
|
+
/** Drop `undefined` config fields so they don't override provider defaults. */
|
|
23
|
+
function clean(config) {
|
|
24
|
+
return Object.fromEntries(Object.entries(config).filter(([, v]) => v !== undefined));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One-shop OpenAI (and OpenAI-compatible) preset: the default loop + the OpenAI
|
|
28
|
+
* provider, configured + activated. `setupAgent(openaiPreset({ apiKey }))`.
|
|
29
|
+
*/
|
|
30
|
+
export function openaiPreset(opts = {}) {
|
|
31
|
+
return {
|
|
32
|
+
plugins: [defaultModePlugin, openaiPlugin],
|
|
33
|
+
provider: {
|
|
34
|
+
name: 'openai',
|
|
35
|
+
config: clean({
|
|
36
|
+
apiKey: opts.apiKey ?? process.env.OPENAI_API_KEY,
|
|
37
|
+
model: opts.model,
|
|
38
|
+
baseURL: opts.baseURL,
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One-shop Anthropic (Claude) preset: the default loop + the Anthropic provider,
|
|
45
|
+
* configured + activated. `setupAgent(anthropicPreset({ apiKey }))`.
|
|
46
|
+
*/
|
|
47
|
+
export function anthropicPreset(opts = {}) {
|
|
48
|
+
return {
|
|
49
|
+
plugins: [defaultModePlugin, anthropicPlugin],
|
|
50
|
+
provider: {
|
|
51
|
+
name: 'anthropic',
|
|
52
|
+
config: clean({
|
|
53
|
+
apiKey: opts.apiKey ?? process.env.ANTHROPIC_API_KEY,
|
|
54
|
+
model: opts.model,
|
|
55
|
+
}),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Re-export the core entry + its types so an app needs only `@moxxy/agent`.
|
|
60
|
+
export { setupAgent, } from '@moxxy/core';
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,YAAY,MAAM,+BAA+B,CAAC;AACzD,OAAO,eAAe,MAAM,kCAAkC,CAAC;AAe/D,+EAA+E;AAC/E,SAAS,KAAK,CAAC,MAA+B;IAC5C,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;AACvF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B,EAAE;IACzD,OAAO;QACL,OAAO,EAAE,CAAC,iBAAiB,EAAE,YAAY,CAAC;QAC1C,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK,CAAC;gBACZ,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc;gBACjD,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC;SACH;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAA8B,EAAE;IAC9D,OAAO;QACL,OAAO,EAAE,CAAC,iBAAiB,EAAE,eAAe,CAAC;QAC7C,QAAQ,EAAE;YACR,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,KAAK,CAAC;gBACZ,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB;gBACpD,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC;SACH;KACF,CAAC;AACJ,CAAC;AAED,4EAA4E;AAC5E,OAAO,EACL,UAAU,GAQX,MAAM,aAAa,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moxxy/agent",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Batteries-included entry to moxxy: one install + one call to run an agent. Bundles @moxxy/core, the default loop, and the OpenAI + Anthropic providers behind drop-in presets — `setupAgent(openaiPreset({ apiKey }))`.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"moxxy",
|
|
7
|
+
"agent",
|
|
8
|
+
"agentic",
|
|
9
|
+
"llm",
|
|
10
|
+
"openai",
|
|
11
|
+
"anthropic",
|
|
12
|
+
"sdk"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://moxxy.ai",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/moxxy-ai/moxxy/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/moxxy-ai/moxxy.git",
|
|
21
|
+
"directory": "packages/agent"
|
|
22
|
+
},
|
|
23
|
+
"author": "Michal Makowski <michal.makowski97@gmail.com>",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"src"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@moxxy/core": "0.3.0",
|
|
43
|
+
"@moxxy/sdk": "0.15.0",
|
|
44
|
+
"@moxxy/mode-default": "0.1.0",
|
|
45
|
+
"@moxxy/plugin-provider-openai": "0.1.0",
|
|
46
|
+
"@moxxy/plugin-provider-anthropic": "0.2.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.10.0",
|
|
50
|
+
"typescript": "^5.7.3",
|
|
51
|
+
"vitest": "^2.1.8",
|
|
52
|
+
"@moxxy/vitest-preset": "0.0.0",
|
|
53
|
+
"@moxxy/tsconfig": "0.0.0"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsc -p tsconfig.json",
|
|
57
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"clean": "rm -rf dist .turbo"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { setupAgent, openaiPreset, anthropicPreset } from './index.js';
|
|
4
|
+
|
|
5
|
+
const ORIGINAL_OPENAI = process.env.OPENAI_API_KEY;
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
if (ORIGINAL_OPENAI === undefined) delete process.env.OPENAI_API_KEY;
|
|
8
|
+
else process.env.OPENAI_API_KEY = ORIGINAL_OPENAI;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('@moxxy/agent presets', () => {
|
|
12
|
+
it('openaiPreset → a single-call agent with openai active', () => {
|
|
13
|
+
const agent = setupAgent(openaiPreset({ apiKey: 'sk-test' }));
|
|
14
|
+
expect(agent.session.providers.getActiveName()).toBe('openai');
|
|
15
|
+
expect(typeof agent.ask).toBe('function');
|
|
16
|
+
expect(typeof agent.stream).toBe('function');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('anthropicPreset → anthropic active', () => {
|
|
20
|
+
const agent = setupAgent(anthropicPreset({ apiKey: 'sk-ant' }));
|
|
21
|
+
expect(agent.session.providers.getActiveName()).toBe('anthropic');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('an array of presets registers both providers (first active) and de-dupes the shared mode', () => {
|
|
25
|
+
const agent = setupAgent([openaiPreset({ apiKey: 'a' }), anthropicPreset({ apiKey: 'b' })]);
|
|
26
|
+
expect(agent.session.providers.getActiveName()).toBe('openai');
|
|
27
|
+
expect(
|
|
28
|
+
agent.session.providers
|
|
29
|
+
.list()
|
|
30
|
+
.map((d) => d.name)
|
|
31
|
+
.sort(),
|
|
32
|
+
).toEqual(['anthropic', 'openai']);
|
|
33
|
+
agent.setProvider('anthropic');
|
|
34
|
+
expect(agent.session.providers.getActiveName()).toBe('anthropic');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('falls back to the conventional env var for the api key', () => {
|
|
38
|
+
process.env.OPENAI_API_KEY = 'env-key';
|
|
39
|
+
expect(openaiPreset().provider?.config?.apiKey).toBe('env-key');
|
|
40
|
+
expect(openaiPreset({ apiKey: 'explicit' }).provider?.config?.apiKey).toBe('explicit');
|
|
41
|
+
});
|
|
42
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@moxxy/agent` — the batteries-included entry to moxxy.
|
|
3
|
+
*
|
|
4
|
+
* One install, one call. Where `@moxxy/core`'s {@link setupAgent} is the flexible,
|
|
5
|
+
* block-agnostic factory (you bring the plugins), this package bundles the
|
|
6
|
+
* default loop + the OpenAI and Anthropic providers behind drop-in **presets**:
|
|
7
|
+
*
|
|
8
|
+
* import { setupAgent, openaiPreset } from '@moxxy/agent';
|
|
9
|
+
* const { ask } = setupAgent(openaiPreset({ apiKey: process.env.OPENAI_API_KEY }));
|
|
10
|
+
* console.log(await ask('Hello!'));
|
|
11
|
+
*
|
|
12
|
+
* A preset is just a pre-filled {@link AgentPreset}, so they compose — pass an
|
|
13
|
+
* array to register several providers at once (the first is active; swap with
|
|
14
|
+
* `agent.setProvider(name)`):
|
|
15
|
+
*
|
|
16
|
+
* const agent = setupAgent([openaiPreset({ apiKey: a }), anthropicPreset({ apiKey: b })]);
|
|
17
|
+
* agent.setProvider('anthropic'); // for the next turn
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { AgentPreset } from '@moxxy/core';
|
|
21
|
+
import defaultModePlugin from '@moxxy/mode-default';
|
|
22
|
+
import openaiPlugin from '@moxxy/plugin-provider-openai';
|
|
23
|
+
import anthropicPlugin from '@moxxy/plugin-provider-anthropic';
|
|
24
|
+
|
|
25
|
+
export interface ProviderPresetOptions {
|
|
26
|
+
/** API key. Defaults to the provider's conventional env var
|
|
27
|
+
* (`OPENAI_API_KEY` / `ANTHROPIC_API_KEY`). */
|
|
28
|
+
readonly apiKey?: string;
|
|
29
|
+
/** Override the model id (otherwise the provider's default catalog applies). */
|
|
30
|
+
readonly model?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface OpenAIPresetOptions extends ProviderPresetOptions {
|
|
34
|
+
/** Point at an OpenAI-compatible endpoint (z.ai, xAI, Google, Ollama/local). */
|
|
35
|
+
readonly baseURL?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Drop `undefined` config fields so they don't override provider defaults. */
|
|
39
|
+
function clean(config: Record<string, unknown>): Record<string, unknown> {
|
|
40
|
+
return Object.fromEntries(Object.entries(config).filter(([, v]) => v !== undefined));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* One-shop OpenAI (and OpenAI-compatible) preset: the default loop + the OpenAI
|
|
45
|
+
* provider, configured + activated. `setupAgent(openaiPreset({ apiKey }))`.
|
|
46
|
+
*/
|
|
47
|
+
export function openaiPreset(opts: OpenAIPresetOptions = {}): AgentPreset {
|
|
48
|
+
return {
|
|
49
|
+
plugins: [defaultModePlugin, openaiPlugin],
|
|
50
|
+
provider: {
|
|
51
|
+
name: 'openai',
|
|
52
|
+
config: clean({
|
|
53
|
+
apiKey: opts.apiKey ?? process.env.OPENAI_API_KEY,
|
|
54
|
+
model: opts.model,
|
|
55
|
+
baseURL: opts.baseURL,
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* One-shop Anthropic (Claude) preset: the default loop + the Anthropic provider,
|
|
63
|
+
* configured + activated. `setupAgent(anthropicPreset({ apiKey }))`.
|
|
64
|
+
*/
|
|
65
|
+
export function anthropicPreset(opts: ProviderPresetOptions = {}): AgentPreset {
|
|
66
|
+
return {
|
|
67
|
+
plugins: [defaultModePlugin, anthropicPlugin],
|
|
68
|
+
provider: {
|
|
69
|
+
name: 'anthropic',
|
|
70
|
+
config: clean({
|
|
71
|
+
apiKey: opts.apiKey ?? process.env.ANTHROPIC_API_KEY,
|
|
72
|
+
model: opts.model,
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Re-export the core entry + its types so an app needs only `@moxxy/agent`.
|
|
79
|
+
export {
|
|
80
|
+
setupAgent,
|
|
81
|
+
type Agent,
|
|
82
|
+
type AgentPreset,
|
|
83
|
+
type SetupAgentOptions,
|
|
84
|
+
type MoxxyEvent,
|
|
85
|
+
type Plugin,
|
|
86
|
+
type ToolDef,
|
|
87
|
+
type PermissionResolver,
|
|
88
|
+
} from '@moxxy/core';
|