maestro-core 0.1.1 → 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/README.md +89 -9
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
# maestro-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
In-process tool-calling agent runtime for SaaS products. Model-agnostic, transport-agnostic, framework-agnostic kernel with port-based governance — powers user-support chat with shared quota, cost, audit, memory, and prompt-cache machinery without a remote gateway hop.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## What ships
|
|
6
|
+
|
|
7
|
+
### `0.2.0` (current)
|
|
8
|
+
|
|
9
|
+
- **`runChatTurn`** — one call replaces ~300 LoC of stream orchestration. Pre-call quota gate, model selection, AI SDK tool building, prompt-cache breakpoints, memory injection, turn-row persistence, post-call accounting, SSE response. Lives at `maestro-core/runtime`.
|
|
10
|
+
- Quota gate: `AiQuotaDeniedError`, `enforceQuotaOrThrow`, `checkAndEnforce`
|
|
11
|
+
- Memory load + format: `loadMemoryBlock`, `formatMemoryBlock`
|
|
12
|
+
- Empty-recovery decision: `decideEmptyRecovery`
|
|
13
|
+
- Provider fallback helpers: `shouldFallback`, `mapModelIdToOpenAI`
|
|
14
|
+
- Window-math helpers for `QuotaStore` impls: `dailyTokensWindow`, `hourlyToolCallsWindow`, etc.
|
|
15
|
+
- Model router: `selectChatModel` (fast/smart heuristic, configurable thresholds)
|
|
16
|
+
- Cost estimator: `estimateCost` with built-in Anthropic + OpenAI pricing
|
|
17
|
+
|
|
18
|
+
### `0.1.x` (carried forward)
|
|
6
19
|
|
|
7
20
|
- `ToolEnvelope<T>` — uniform success/failure shape every tool returns
|
|
8
21
|
- `defineAgentTool<TInput, TOutput, TCtx>` — tool definition factory with generic context extension
|
|
@@ -13,19 +26,17 @@ Runtime kernel for the Maestro agent platform. In-process tool-calling runtime w
|
|
|
13
26
|
- AI SDK adapter (`maestro-core/adapters/ai-sdk`) — wraps registry into `ToolSet` with audit + cache breakpoint
|
|
14
27
|
- MCP server adapter (`maestro-core/adapters/mcp-server`) — registers the same registry on an MCP server
|
|
15
28
|
|
|
16
|
-
`runChatTurn` (the full streaming orchestrator) lands in `0.2.0`.
|
|
17
|
-
|
|
18
29
|
## Install
|
|
19
30
|
|
|
20
31
|
```bash
|
|
21
32
|
pnpm add maestro-core zod
|
|
22
|
-
#
|
|
23
|
-
pnpm add ai
|
|
24
|
-
#
|
|
33
|
+
# for the runtime + AI SDK adapter:
|
|
34
|
+
pnpm add ai @ai-sdk/anthropic
|
|
35
|
+
# for the MCP server adapter:
|
|
25
36
|
pnpm add @modelcontextprotocol/sdk
|
|
26
37
|
```
|
|
27
38
|
|
|
28
|
-
## Quickstart
|
|
39
|
+
## Quickstart — defining a tool
|
|
29
40
|
|
|
30
41
|
```ts
|
|
31
42
|
import { ok, err, defineAgentTool, type BaseToolContext } from 'maestro-core'
|
|
@@ -46,9 +57,78 @@ export const lookupTool = defineAgentTool<z.ZodObject<{ id: z.ZodNumber }>, { na
|
|
|
46
57
|
})
|
|
47
58
|
```
|
|
48
59
|
|
|
60
|
+
## Quickstart — running a chat turn
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { runChatTurn, AiQuotaDeniedError } from 'maestro-core/runtime'
|
|
64
|
+
|
|
65
|
+
export async function POST(req: Request) {
|
|
66
|
+
const { messages } = await req.json()
|
|
67
|
+
const ctx: MyCtx = { /* tenantId, principal, transport, locale, timezone, requestId, role */ }
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
return await runChatTurn({
|
|
71
|
+
threadId,
|
|
72
|
+
ctx,
|
|
73
|
+
messages,
|
|
74
|
+
tools: [lookupTool /* ... */],
|
|
75
|
+
systemPrompt: {
|
|
76
|
+
static: 'You are a helpful assistant for record lookups.',
|
|
77
|
+
dynamic: undefined, // optional per-tenant prose; memory facts auto-append
|
|
78
|
+
},
|
|
79
|
+
models: {
|
|
80
|
+
fast: 'claude-haiku-4-5-20251001',
|
|
81
|
+
smart: 'claude-sonnet-4-6',
|
|
82
|
+
},
|
|
83
|
+
ports: {
|
|
84
|
+
turnStore: myTurnStore,
|
|
85
|
+
keyProvider: myKeyProvider,
|
|
86
|
+
auditStore: myAuditStore,
|
|
87
|
+
memoryStore: myMemoryStore, // optional
|
|
88
|
+
quotaStore: myQuotaStore, // optional but recommended
|
|
89
|
+
telemetry: myTelemetrySink, // defaults to Noop
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
} catch (e) {
|
|
93
|
+
if (e instanceof AiQuotaDeniedError) {
|
|
94
|
+
return Response.json(
|
|
95
|
+
{ error: 'quota_exceeded', payload: e.payload },
|
|
96
|
+
{ status: 429 }
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
throw e
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Provider fallback
|
|
105
|
+
|
|
106
|
+
`shouldFallback` + `mapModelIdToOpenAI` give you composable retry against OpenAI when Anthropic hits a transient failure:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { runChatTurn, shouldFallback, mapModelIdToOpenAI } from 'maestro-core/runtime'
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
return await runChatTurn({ ..., models: anthropicModels })
|
|
113
|
+
} catch (e) {
|
|
114
|
+
if (shouldFallback(e)) {
|
|
115
|
+
return runChatTurn({
|
|
116
|
+
...,
|
|
117
|
+
models: {
|
|
118
|
+
fast: mapModelIdToOpenAI(anthropicModels.fast),
|
|
119
|
+
smart: mapModelIdToOpenAI(anthropicModels.smart),
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
throw e
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Built-in retry wrapper inside `runChatTurn` is tracked for `0.2.1`.
|
|
128
|
+
|
|
49
129
|
## Design
|
|
50
130
|
|
|
51
|
-
See [DESIGN.md](https://github.com/costasoftware/maestro/blob/main/DESIGN.md) for the architecture, port interfaces, and
|
|
131
|
+
See [DESIGN.md](https://github.com/costasoftware/maestro/blob/main/DESIGN.md) for the architecture, port interfaces, migration roadmap, and what's explicitly deferred.
|
|
52
132
|
|
|
53
133
|
## License
|
|
54
134
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maestro-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Runtime kernel for the Maestro agent platform — tool envelope, tool definition factory, base context, port interfaces, and AI-SDK + MCP adapters.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Costa Software",
|
|
@@ -43,6 +43,10 @@
|
|
|
43
43
|
"./adapters/mcp-server": {
|
|
44
44
|
"types": "./dist/adapters/mcp-server.d.ts",
|
|
45
45
|
"import": "./dist/adapters/mcp-server.js"
|
|
46
|
+
},
|
|
47
|
+
"./runtime": {
|
|
48
|
+
"types": "./dist/runtime/index.d.ts",
|
|
49
|
+
"import": "./dist/runtime/index.js"
|
|
46
50
|
}
|
|
47
51
|
},
|
|
48
52
|
"files": [
|
|
@@ -57,11 +61,15 @@
|
|
|
57
61
|
"clean": "rm -rf dist .turbo *.tsbuildinfo"
|
|
58
62
|
},
|
|
59
63
|
"peerDependencies": {
|
|
64
|
+
"@ai-sdk/anthropic": "^3.0.0",
|
|
60
65
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
61
66
|
"ai": "^6.0.0",
|
|
62
67
|
"zod": "^3.25.0"
|
|
63
68
|
},
|
|
64
69
|
"peerDependenciesMeta": {
|
|
70
|
+
"@ai-sdk/anthropic": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
65
73
|
"@modelcontextprotocol/sdk": {
|
|
66
74
|
"optional": true
|
|
67
75
|
},
|
|
@@ -70,6 +78,7 @@
|
|
|
70
78
|
}
|
|
71
79
|
},
|
|
72
80
|
"devDependencies": {
|
|
81
|
+
"@ai-sdk/anthropic": "^3.0.71",
|
|
73
82
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
74
83
|
"@types/node": "^22.10.0",
|
|
75
84
|
"ai": "^6.0.0",
|