@nebulaos/core 0.2.0 โ 0.2.1
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.txt +21 -0
- package/README.md +206 -206
- package/dist/agent/Agent.d.ts +5 -0
- package/dist/agent/Agent.js +18 -0
- package/dist/agent/skills/index.d.ts +8 -0
- package/package.json +15 -14
- package/dist/index.cjs +0 -2958
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -3425
- package/dist/index.js.map +0 -1
- package/dist/tsup.config.d.ts +0 -2
- package/dist/tsup.config.js +0 -11
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present, iamkun
|
|
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
CHANGED
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
# @starya/nebulaos-core
|
|
2
|
-
|
|
3
|
-
The core of NebulaOS for building AI Agents and complex Workflows. This package provides the essential primitives for orchestration, state management, and model abstraction.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pnpm add @starya/nebulaos-core
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## โจ Features Overview
|
|
14
|
-
|
|
15
|
-
### ๐ค Agent System
|
|
16
|
-
- โ
**Multi-Step Reasoning** - Automatic tool calling loops with configurable max steps
|
|
17
|
-
- โ
**Streaming Support** - Real-time token streaming with `executeStream()`
|
|
18
|
-
- โ
**Tool Calling** - Function calling with Zod schema validation
|
|
19
|
-
- โ
**Parallel Tool Execution** - Execute multiple tools simultaneously
|
|
20
|
-
- โ
**Structured Outputs** - JSON mode with schema validation
|
|
21
|
-
- โ
**Memory Management** - Pluggable memory implementations (InMemory, Redis, etc.)
|
|
22
|
-
- โ
**Dynamic Instructions** - Support for async instruction resolution
|
|
23
|
-
- โ
**Request/Response Interceptors** - Middleware for RAG, sanitization, etc.
|
|
24
|
-
- โ
**Multimodal Support** - Text + Images (via ContentPart[])
|
|
25
|
-
|
|
26
|
-
### ๐ Workflow Orchestration
|
|
27
|
-
- โ
**Fluent API** - Declarative workflow definition (`.start().step().finish()`)
|
|
28
|
-
- โ
**Branching & Parallel** - Conditional paths and concurrent execution
|
|
29
|
-
- โ
**State Persistence** - Save/resume workflow state (requires state store)
|
|
30
|
-
- โ
**Retry Policies** - Exponential/Linear backoff with configurable attempts
|
|
31
|
-
- โ
**Input/Output Validation** - Zod schema validation at boundaries
|
|
32
|
-
- โ
**Queue Integration** - Async workflow execution (requires queue adapter)
|
|
33
|
-
- โ
**Event-Driven** - Lifecycle events for monitoring and logging
|
|
34
|
-
|
|
35
|
-
### ๐ Observability & Tracing
|
|
36
|
-
- โ
**Distributed Tracing** - Automatic trace/span propagation via AsyncLocalStorage
|
|
37
|
-
- โ
**Event System** - Rich lifecycle events (`execution:start`, `llm:call`, `tool:result`, etc.)
|
|
38
|
-
- โ
**Correlation IDs** - Track requests across nested operations
|
|
39
|
-
- โ
**Structured Logging** - Beautiful console logs with ANSI colors and metadata trees
|
|
40
|
-
- โ
**Log Levels** - Configurable (debug, info, warn, error)
|
|
41
|
-
- โ
**Custom Loggers** - Implement `ILogger` for Datadog, CloudWatch, etc.
|
|
42
|
-
- โ
**PII Masking** - GDPR/LGPD compliance with pluggable masking
|
|
43
|
-
|
|
44
|
-
### ๐งช Testing & Quality
|
|
45
|
-
- โ
**Provider Compliance Suite** - Reusable test suite for model providers
|
|
46
|
-
- โ
**Mock Implementations** - MockProvider, MockStateStore for unit tests
|
|
47
|
-
- โ
**Integration Tests** - Live API tests with real providers
|
|
48
|
-
- โ
**Type Safety** - Full TypeScript support with strict typing
|
|
49
|
-
- โ
**Test Coverage** - Comprehensive unit and integration tests
|
|
50
|
-
|
|
51
|
-
### ๐ Provider System
|
|
52
|
-
- โ
**Provider Abstraction** - IModel interface for any LLM (OpenAI, Anthropic, etc.)
|
|
53
|
-
- โ
**Token Usage Tracking** - Automatic accumulation across multi-step flows
|
|
54
|
-
- โ
**Streaming Protocol** - Unified chunk types (content_delta, tool_call_start, etc.)
|
|
55
|
-
- โ
**Error Handling** - Graceful degradation and retry logic
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
## ๐ Recent Updates
|
|
60
|
-
|
|
61
|
-
### v0.0.1 - Distributed Tracing & Stream Parity
|
|
62
|
-
- **Distributed Tracing**: Automatic trace/span propagation across Agent โ Workflow โ Tool chains
|
|
63
|
-
- **executeStream() Parity**: Full feature parity with execute() including token tracking, events, and max steps fallback
|
|
64
|
-
- **Enhanced Logging**: Color-coded terminal output with hierarchical metadata display
|
|
65
|
-
- **Response Interceptors**: Now run only on final responses (not intermediate tool calls)
|
|
66
|
-
- **Test Coverage**: Expanded to 22 unit tests + 7 integration tests
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## Core Components
|
|
71
|
-
|
|
72
|
-
### 1. Agent (`Agent`)
|
|
73
|
-
|
|
74
|
-
The main class that manages the lifecycle of AI interaction.
|
|
75
|
-
|
|
76
|
-
### Key Features
|
|
77
|
-
* **Memory-First**: Every agent requires a memory implementation (e.g., `InMemory`) to maintain context.
|
|
78
|
-
* **Interceptors**: Middleware to modify requests and responses.
|
|
79
|
-
* **Request Interceptors**: Run before each LLM call. Useful for context injection (RAG).
|
|
80
|
-
* **Response Interceptors**: Run **only on the final response** (or when there are no tool calls), ideal for output sanitization and formatting.
|
|
81
|
-
* **Streaming**: Native support for text and tool call streaming.
|
|
82
|
-
* **Observability**: Integrated event-based logging system with PII Masking support (GDPR/LGPD).
|
|
83
|
-
|
|
84
|
-
### Complete Example
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
import { Agent, InMemory, Tool, z } from "@starya/nebulaos-core";
|
|
88
|
-
import { OpenAI } from "@starya/nebulaos-openai";
|
|
89
|
-
|
|
90
|
-
// 1. Tools
|
|
91
|
-
const calculator = new Tool({
|
|
92
|
-
id: "calculator",
|
|
93
|
-
description: "Adds two numbers",
|
|
94
|
-
inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
95
|
-
handler: async (ctx, input) => ({ result: input.a + input.b })
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// 2. Agent
|
|
99
|
-
const agent = new Agent({
|
|
100
|
-
name: "financial-assistant",
|
|
101
|
-
model: new OpenAI({
|
|
102
|
-
apiKey: process.env.OPENAI_API_KEY!,
|
|
103
|
-
model: "gpt-4o"
|
|
104
|
-
}),
|
|
105
|
-
memory: new InMemory(),
|
|
106
|
-
instructions: "You help with financial calculations.",
|
|
107
|
-
tools: [calculator],
|
|
108
|
-
logLevel: "info", // Detailed console logs
|
|
109
|
-
interceptors: {
|
|
110
|
-
response: [
|
|
111
|
-
async (res) => {
|
|
112
|
-
// Format final output to uppercase (example)
|
|
113
|
-
if (res.content) res.content = res.content.toUpperCase();
|
|
114
|
-
return res;
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// 3. Execution
|
|
121
|
-
await agent.addMessage({ role: "user", content: "How much is 10 + 20?" });
|
|
122
|
-
const result = await agent.execute();
|
|
123
|
-
console.log(result.content);
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
## ๐ Workflow (`Workflow`)
|
|
129
|
-
|
|
130
|
-
Orchestrator for long-running and complex processes, supporting persistence, retries, and validation.
|
|
131
|
-
|
|
132
|
-
### Features
|
|
133
|
-
* **Fluent API**: Declarative definition (`.start().step().branch().finish()`).
|
|
134
|
-
* **State Persistence**: Saves the state of each step (requires `stateStore`).
|
|
135
|
-
* **Resilience**: Configurable Retry Policies (Exponential, Linear).
|
|
136
|
-
* **Type-Safe**: Input and output validation with Zod.
|
|
137
|
-
|
|
138
|
-
### Workflow Example
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
import { Workflow, MockStateStore } from "@starya/nebulaos-core";
|
|
142
|
-
import { z } from "zod";
|
|
143
|
-
|
|
144
|
-
const workflow = new Workflow({
|
|
145
|
-
id: "order-processing",
|
|
146
|
-
stateStore: new MockStateStore(), // Or real implementation (Redis/Postgres)
|
|
147
|
-
retryPolicy: {
|
|
148
|
-
maxAttempts: 3,
|
|
149
|
-
backoff: "exponential",
|
|
150
|
-
initialDelay: 1000
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
.start(async ({ input }) => {
|
|
154
|
-
console.log("Validating order", input);
|
|
155
|
-
return input;
|
|
156
|
-
})
|
|
157
|
-
.step("payment", async ({ input }) => {
|
|
158
|
-
// Payment logic
|
|
159
|
-
return { status: "paid", id: input.id };
|
|
160
|
-
})
|
|
161
|
-
.finish(async ({ input }) => {
|
|
162
|
-
return { message: `Order ${input.id} processed successfully` };
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// Execution
|
|
166
|
-
const result = await workflow.run({ id: 123, total: 500 });
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
## ๐ก๏ธ Logging & Observability
|
|
172
|
-
|
|
173
|
-
The Core emits rich events during execution (`execution:start`, `llm:call`, `tool:result`).
|
|
174
|
-
|
|
175
|
-
### Configuration
|
|
176
|
-
The default logger (`ConsoleLogger`) can be configured via `logLevel`. For production, you can implement the `ILogger` interface to send logs to Datadog, CloudWatch, etc.
|
|
177
|
-
|
|
178
|
-
### PII Masking (Privacy)
|
|
179
|
-
Protect sensitive data in logs by configuring a `piiMasker`.
|
|
180
|
-
|
|
181
|
-
```typescript
|
|
182
|
-
const agent = new Agent({
|
|
183
|
-
// ...
|
|
184
|
-
piiMasker: {
|
|
185
|
-
mask: (text) => text.replace(/\d{3}\.\d{3}\.\d{3}-\d{2}/g, "***") // Example mask
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
---
|
|
191
|
-
|
|
192
|
-
## ๐งช Testing & Compliance
|
|
193
|
-
|
|
194
|
-
### Package Tests
|
|
195
|
-
```bash
|
|
196
|
-
pnpm test
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Provider Compliance Suite
|
|
200
|
-
If you are creating a new Provider (e.g., Anthropic), use the compliance suite to ensure full compatibility.
|
|
201
|
-
|
|
202
|
-
```typescript
|
|
203
|
-
import { runProviderComplianceTests } from "@starya/nebulaos-core/test-utils";
|
|
204
|
-
|
|
205
|
-
runProviderComplianceTests(() => new MyNewProvider(...), { runLiveTests: true });
|
|
206
|
-
```
|
|
1
|
+
# @starya/nebulaos-core
|
|
2
|
+
|
|
3
|
+
The core of NebulaOS for building AI Agents and complex Workflows. This package provides the essential primitives for orchestration, state management, and model abstraction.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @starya/nebulaos-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## โจ Features Overview
|
|
14
|
+
|
|
15
|
+
### ๐ค Agent System
|
|
16
|
+
- โ
**Multi-Step Reasoning** - Automatic tool calling loops with configurable max steps
|
|
17
|
+
- โ
**Streaming Support** - Real-time token streaming with `executeStream()`
|
|
18
|
+
- โ
**Tool Calling** - Function calling with Zod schema validation
|
|
19
|
+
- โ
**Parallel Tool Execution** - Execute multiple tools simultaneously
|
|
20
|
+
- โ
**Structured Outputs** - JSON mode with schema validation
|
|
21
|
+
- โ
**Memory Management** - Pluggable memory implementations (InMemory, Redis, etc.)
|
|
22
|
+
- โ
**Dynamic Instructions** - Support for async instruction resolution
|
|
23
|
+
- โ
**Request/Response Interceptors** - Middleware for RAG, sanitization, etc.
|
|
24
|
+
- โ
**Multimodal Support** - Text + Images (via ContentPart[])
|
|
25
|
+
|
|
26
|
+
### ๐ Workflow Orchestration
|
|
27
|
+
- โ
**Fluent API** - Declarative workflow definition (`.start().step().finish()`)
|
|
28
|
+
- โ
**Branching & Parallel** - Conditional paths and concurrent execution
|
|
29
|
+
- โ
**State Persistence** - Save/resume workflow state (requires state store)
|
|
30
|
+
- โ
**Retry Policies** - Exponential/Linear backoff with configurable attempts
|
|
31
|
+
- โ
**Input/Output Validation** - Zod schema validation at boundaries
|
|
32
|
+
- โ
**Queue Integration** - Async workflow execution (requires queue adapter)
|
|
33
|
+
- โ
**Event-Driven** - Lifecycle events for monitoring and logging
|
|
34
|
+
|
|
35
|
+
### ๐ Observability & Tracing
|
|
36
|
+
- โ
**Distributed Tracing** - Automatic trace/span propagation via AsyncLocalStorage
|
|
37
|
+
- โ
**Event System** - Rich lifecycle events (`execution:start`, `llm:call`, `tool:result`, etc.)
|
|
38
|
+
- โ
**Correlation IDs** - Track requests across nested operations
|
|
39
|
+
- โ
**Structured Logging** - Beautiful console logs with ANSI colors and metadata trees
|
|
40
|
+
- โ
**Log Levels** - Configurable (debug, info, warn, error)
|
|
41
|
+
- โ
**Custom Loggers** - Implement `ILogger` for Datadog, CloudWatch, etc.
|
|
42
|
+
- โ
**PII Masking** - GDPR/LGPD compliance with pluggable masking
|
|
43
|
+
|
|
44
|
+
### ๐งช Testing & Quality
|
|
45
|
+
- โ
**Provider Compliance Suite** - Reusable test suite for model providers
|
|
46
|
+
- โ
**Mock Implementations** - MockProvider, MockStateStore for unit tests
|
|
47
|
+
- โ
**Integration Tests** - Live API tests with real providers
|
|
48
|
+
- โ
**Type Safety** - Full TypeScript support with strict typing
|
|
49
|
+
- โ
**Test Coverage** - Comprehensive unit and integration tests
|
|
50
|
+
|
|
51
|
+
### ๐ Provider System
|
|
52
|
+
- โ
**Provider Abstraction** - IModel interface for any LLM (OpenAI, Anthropic, etc.)
|
|
53
|
+
- โ
**Token Usage Tracking** - Automatic accumulation across multi-step flows
|
|
54
|
+
- โ
**Streaming Protocol** - Unified chunk types (content_delta, tool_call_start, etc.)
|
|
55
|
+
- โ
**Error Handling** - Graceful degradation and retry logic
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## ๐ Recent Updates
|
|
60
|
+
|
|
61
|
+
### v0.0.1 - Distributed Tracing & Stream Parity
|
|
62
|
+
- **Distributed Tracing**: Automatic trace/span propagation across Agent โ Workflow โ Tool chains
|
|
63
|
+
- **executeStream() Parity**: Full feature parity with execute() including token tracking, events, and max steps fallback
|
|
64
|
+
- **Enhanced Logging**: Color-coded terminal output with hierarchical metadata display
|
|
65
|
+
- **Response Interceptors**: Now run only on final responses (not intermediate tool calls)
|
|
66
|
+
- **Test Coverage**: Expanded to 22 unit tests + 7 integration tests
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Core Components
|
|
71
|
+
|
|
72
|
+
### 1. Agent (`Agent`)
|
|
73
|
+
|
|
74
|
+
The main class that manages the lifecycle of AI interaction.
|
|
75
|
+
|
|
76
|
+
### Key Features
|
|
77
|
+
* **Memory-First**: Every agent requires a memory implementation (e.g., `InMemory`) to maintain context.
|
|
78
|
+
* **Interceptors**: Middleware to modify requests and responses.
|
|
79
|
+
* **Request Interceptors**: Run before each LLM call. Useful for context injection (RAG).
|
|
80
|
+
* **Response Interceptors**: Run **only on the final response** (or when there are no tool calls), ideal for output sanitization and formatting.
|
|
81
|
+
* **Streaming**: Native support for text and tool call streaming.
|
|
82
|
+
* **Observability**: Integrated event-based logging system with PII Masking support (GDPR/LGPD).
|
|
83
|
+
|
|
84
|
+
### Complete Example
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { Agent, InMemory, Tool, z } from "@starya/nebulaos-core";
|
|
88
|
+
import { OpenAI } from "@starya/nebulaos-openai";
|
|
89
|
+
|
|
90
|
+
// 1. Tools
|
|
91
|
+
const calculator = new Tool({
|
|
92
|
+
id: "calculator",
|
|
93
|
+
description: "Adds two numbers",
|
|
94
|
+
inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
95
|
+
handler: async (ctx, input) => ({ result: input.a + input.b })
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// 2. Agent
|
|
99
|
+
const agent = new Agent({
|
|
100
|
+
name: "financial-assistant",
|
|
101
|
+
model: new OpenAI({
|
|
102
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
103
|
+
model: "gpt-4o"
|
|
104
|
+
}),
|
|
105
|
+
memory: new InMemory(),
|
|
106
|
+
instructions: "You help with financial calculations.",
|
|
107
|
+
tools: [calculator],
|
|
108
|
+
logLevel: "info", // Detailed console logs
|
|
109
|
+
interceptors: {
|
|
110
|
+
response: [
|
|
111
|
+
async (res) => {
|
|
112
|
+
// Format final output to uppercase (example)
|
|
113
|
+
if (res.content) res.content = res.content.toUpperCase();
|
|
114
|
+
return res;
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// 3. Execution
|
|
121
|
+
await agent.addMessage({ role: "user", content: "How much is 10 + 20?" });
|
|
122
|
+
const result = await agent.execute();
|
|
123
|
+
console.log(result.content);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## ๐ Workflow (`Workflow`)
|
|
129
|
+
|
|
130
|
+
Orchestrator for long-running and complex processes, supporting persistence, retries, and validation.
|
|
131
|
+
|
|
132
|
+
### Features
|
|
133
|
+
* **Fluent API**: Declarative definition (`.start().step().branch().finish()`).
|
|
134
|
+
* **State Persistence**: Saves the state of each step (requires `stateStore`).
|
|
135
|
+
* **Resilience**: Configurable Retry Policies (Exponential, Linear).
|
|
136
|
+
* **Type-Safe**: Input and output validation with Zod.
|
|
137
|
+
|
|
138
|
+
### Workflow Example
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { Workflow, MockStateStore } from "@starya/nebulaos-core";
|
|
142
|
+
import { z } from "zod";
|
|
143
|
+
|
|
144
|
+
const workflow = new Workflow({
|
|
145
|
+
id: "order-processing",
|
|
146
|
+
stateStore: new MockStateStore(), // Or real implementation (Redis/Postgres)
|
|
147
|
+
retryPolicy: {
|
|
148
|
+
maxAttempts: 3,
|
|
149
|
+
backoff: "exponential",
|
|
150
|
+
initialDelay: 1000
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
.start(async ({ input }) => {
|
|
154
|
+
console.log("Validating order", input);
|
|
155
|
+
return input;
|
|
156
|
+
})
|
|
157
|
+
.step("payment", async ({ input }) => {
|
|
158
|
+
// Payment logic
|
|
159
|
+
return { status: "paid", id: input.id };
|
|
160
|
+
})
|
|
161
|
+
.finish(async ({ input }) => {
|
|
162
|
+
return { message: `Order ${input.id} processed successfully` };
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Execution
|
|
166
|
+
const result = await workflow.run({ id: 123, total: 500 });
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## ๐ก๏ธ Logging & Observability
|
|
172
|
+
|
|
173
|
+
The Core emits rich events during execution (`execution:start`, `llm:call`, `tool:result`).
|
|
174
|
+
|
|
175
|
+
### Configuration
|
|
176
|
+
The default logger (`ConsoleLogger`) can be configured via `logLevel`. For production, you can implement the `ILogger` interface to send logs to Datadog, CloudWatch, etc.
|
|
177
|
+
|
|
178
|
+
### PII Masking (Privacy)
|
|
179
|
+
Protect sensitive data in logs by configuring a `piiMasker`.
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const agent = new Agent({
|
|
183
|
+
// ...
|
|
184
|
+
piiMasker: {
|
|
185
|
+
mask: (text) => text.replace(/\d{3}\.\d{3}\.\d{3}-\d{2}/g, "***") // Example mask
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## ๐งช Testing & Compliance
|
|
193
|
+
|
|
194
|
+
### Package Tests
|
|
195
|
+
```bash
|
|
196
|
+
pnpm test
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Provider Compliance Suite
|
|
200
|
+
If you are creating a new Provider (e.g., Anthropic), use the compliance suite to ensure full compatibility.
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { runProviderComplianceTests } from "@starya/nebulaos-core/test-utils";
|
|
204
|
+
|
|
205
|
+
runProviderComplianceTests(() => new MyNewProvider(...), { runLiveTests: true });
|
|
206
|
+
```
|
package/dist/agent/Agent.d.ts
CHANGED
|
@@ -74,6 +74,11 @@ export declare class Agent extends BaseAgent {
|
|
|
74
74
|
* This is typically called by the client package with InstrumentedHttpClient.
|
|
75
75
|
*/
|
|
76
76
|
setHttpClient(client: IHttpClient): void;
|
|
77
|
+
/**
|
|
78
|
+
* Sets the client reference on the memory and skills.
|
|
79
|
+
* Called by NebulaClient after connecting, so memory/skills can access client config.
|
|
80
|
+
*/
|
|
81
|
+
setClient(client: unknown): void;
|
|
77
82
|
private initializeSkills;
|
|
78
83
|
private resolveInstructions;
|
|
79
84
|
private isInstruction;
|
package/dist/agent/Agent.js
CHANGED
|
@@ -40,6 +40,24 @@ class Agent extends BaseAgent_js_1.BaseAgent {
|
|
|
40
40
|
setHttpClient(client) {
|
|
41
41
|
this.httpClient = client;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Sets the client reference on the memory and skills.
|
|
45
|
+
* Called by NebulaClient after connecting, so memory/skills can access client config.
|
|
46
|
+
*/
|
|
47
|
+
setClient(client) {
|
|
48
|
+
// Propagate to memory
|
|
49
|
+
const memory = this.config.memory;
|
|
50
|
+
if (memory && typeof memory.setClient === 'function') {
|
|
51
|
+
memory.setClient(client);
|
|
52
|
+
}
|
|
53
|
+
// Propagate to skills
|
|
54
|
+
const skills = this.config.skills || [];
|
|
55
|
+
for (const skill of skills) {
|
|
56
|
+
if (typeof skill.setClient === 'function') {
|
|
57
|
+
skill.setClient(client);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
43
61
|
// ==========================================================================
|
|
44
62
|
// Skills Initialization
|
|
45
63
|
// ==========================================================================
|
|
@@ -54,6 +54,14 @@ export interface ISkill {
|
|
|
54
54
|
* @returns Additional instructions text for the agent
|
|
55
55
|
*/
|
|
56
56
|
getInstructions?(): string | Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Optional method to receive the client reference.
|
|
59
|
+
* Called by the Agent when it receives setClient() from the NebulaClient.
|
|
60
|
+
* Skills can extract configuration (apiKey, serverUrl, etc.) from the client.
|
|
61
|
+
*
|
|
62
|
+
* @param client - The NebulaClient instance (typed as unknown to avoid circular dependency)
|
|
63
|
+
*/
|
|
64
|
+
setClient?(client: unknown): void;
|
|
57
65
|
}
|
|
58
66
|
/**
|
|
59
67
|
* Helper function to validate that an object implements ISkill
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nebulaos/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Core primitives for NebulaOS (Agent, Workflow, Providers)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,6 +9,13 @@
|
|
|
9
9
|
"README.md",
|
|
10
10
|
"LICENSE"
|
|
11
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"test:watch": "jest --watch",
|
|
16
|
+
"test:e2e:providers": "jest packages/core/__tests__/integration/providers.e2e.spec.ts --runInBand --testTimeout=60000",
|
|
17
|
+
"prepublishOnly": "pnpm build"
|
|
18
|
+
},
|
|
12
19
|
"repository": {
|
|
13
20
|
"type": "git",
|
|
14
21
|
"url": "https://github.com/Psyco-AI-Tech/starya-nebulaos.git",
|
|
@@ -30,27 +37,21 @@
|
|
|
30
37
|
"registry": "https://registry.npmjs.org/"
|
|
31
38
|
},
|
|
32
39
|
"dependencies": {
|
|
40
|
+
"@nebulaos/types": "workspace:*",
|
|
33
41
|
"uuid": "^9.0.1",
|
|
34
42
|
"zod": "^3.0.0",
|
|
35
|
-
"zod-to-json-schema": "^3.0.0"
|
|
36
|
-
"@nebulaos/types": "0.1.1"
|
|
43
|
+
"zod-to-json-schema": "^3.0.0"
|
|
37
44
|
},
|
|
38
45
|
"devDependencies": {
|
|
46
|
+
"@nebulaos/oci": "workspace:*",
|
|
47
|
+
"@nebulaos/openai": "workspace:*",
|
|
48
|
+
"@nebulaos/google-gemini": "workspace:*",
|
|
39
49
|
"@types/jest": "^30.0.0",
|
|
40
50
|
"@types/node": "^20.0.0",
|
|
41
51
|
"@types/uuid": "^9.0.8",
|
|
42
52
|
"dotenv": "^17.2.3",
|
|
43
53
|
"jest": "^30.2.0",
|
|
44
54
|
"ts-jest": "^29.4.6",
|
|
45
|
-
"typescript": "^5.0.0"
|
|
46
|
-
"@nebulaos/google-gemini": "0.0.1",
|
|
47
|
-
"@nebulaos/openai": "0.1.0",
|
|
48
|
-
"@nebulaos/oci": "0.0.1"
|
|
49
|
-
},
|
|
50
|
-
"scripts": {
|
|
51
|
-
"build": "tsc",
|
|
52
|
-
"test": "jest",
|
|
53
|
-
"test:watch": "jest --watch",
|
|
54
|
-
"test:e2e:providers": "jest packages/core/__tests__/integration/providers.e2e.spec.ts --runInBand --testTimeout=60000"
|
|
55
|
+
"typescript": "^5.0.0"
|
|
55
56
|
}
|
|
56
|
-
}
|
|
57
|
+
}
|