@makaio/adapter-openai-node 1.0.0-dev-1779051654000
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 +186 -0
- package/descriptor.json +21 -0
- package/dist/index.d.mts +2118 -0
- package/dist/index.mjs +1790 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Makaio GmbH
|
|
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,186 @@
|
|
|
1
|
+
# @makaio/adapter-openai-node
|
|
2
|
+
|
|
3
|
+
OpenAI adapter implementation using the official OpenAI Node SDK for agentic chat completions.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { OpenAIAdapter, createOpenAINodeAdapter } from '@makaio/adapter-openai-node';
|
|
9
|
+
import { MakaioBus } from '@makaio/bus-core';
|
|
10
|
+
import { AdapterSubjects } from '@makaio/contracts';
|
|
11
|
+
|
|
12
|
+
// Using the convenience factory
|
|
13
|
+
const adapter = await createOpenAINodeAdapter();
|
|
14
|
+
|
|
15
|
+
const result = await MakaioBus.request(AdapterSubjects.startAgent, {
|
|
16
|
+
adapterId: adapter.adapterId,
|
|
17
|
+
role: 'lead',
|
|
18
|
+
initialMessage: 'Inspect this repository',
|
|
19
|
+
model: 'gpt-4.1',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Or using the class directly
|
|
23
|
+
const directAdapter = new OpenAIAdapter();
|
|
24
|
+
await directAdapter.init();
|
|
25
|
+
|
|
26
|
+
const directResult = await MakaioBus.request(AdapterSubjects.startAgent, {
|
|
27
|
+
adapterId: directAdapter.adapterId,
|
|
28
|
+
role: 'lead',
|
|
29
|
+
initialMessage: 'Inspect this repository',
|
|
30
|
+
model: 'gpt-4.1',
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Architecture
|
|
35
|
+
|
|
36
|
+
This adapter implements a three-layer architecture for clean separation of concerns:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
OpenAIAdapter (extends AIAdapter)
|
|
40
|
+
↓ creates via agentFactory()
|
|
41
|
+
OpenAIAgent (extends BaseStreamAgent)
|
|
42
|
+
↓ creates via connectorFactory()
|
|
43
|
+
OpenAINodeConnector (extends BaseStreamConnector)
|
|
44
|
+
↓ wraps
|
|
45
|
+
OpenAI SDK Client
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Layer Responsibilities
|
|
49
|
+
|
|
50
|
+
| Layer | Class | Responsibility |
|
|
51
|
+
|-------|-------|----------------|
|
|
52
|
+
| **Adapter** | `OpenAIAdapter` | Handle `adapter.startAgent` RPC, manage agent lifecycle, emit adapter events |
|
|
53
|
+
| **Agent** | `OpenAIAgent` | Wire connector events to global `agent.*` subjects, enrich payloads with agent context |
|
|
54
|
+
| **Connector** | `OpenAINodeConnector` | SDK client setup, credentials, tool loading, stream-session lifecycle |
|
|
55
|
+
| **Session** | `OpenAIConnectorSession` | OpenAI message history, streaming API calls, and the agentic tool-call loop |
|
|
56
|
+
|
|
57
|
+
### Agentic Loop Pattern
|
|
58
|
+
|
|
59
|
+
The session implements the standard agentic loop:
|
|
60
|
+
|
|
61
|
+
1. Send user message to OpenAI
|
|
62
|
+
2. Process streaming response
|
|
63
|
+
3. If `tool_calls` present, execute tools via Bus RPC and recurse
|
|
64
|
+
4. When no `tool_calls`, mark turn complete
|
|
65
|
+
|
|
66
|
+
## Key Concepts
|
|
67
|
+
|
|
68
|
+
`OpenAIAgent`, `OpenAINodeConnector`, `OpenAIConnectorSession`, `OpenAIConnectorTurn`, and
|
|
69
|
+
namespace exports are public for framework implementers and tests. Most applications should use
|
|
70
|
+
the `./server` runtime contribution or `createOpenAINodeAdapter()` rather than constructing the
|
|
71
|
+
lower layers directly.
|
|
72
|
+
|
|
73
|
+
### Semantic Event Subjects
|
|
74
|
+
|
|
75
|
+
Raw SDK events are normalized into typed semantic subjects:
|
|
76
|
+
|
|
77
|
+
| Subject | Description |
|
|
78
|
+
|---------|-------------|
|
|
79
|
+
| `chunk` | Streaming text delta |
|
|
80
|
+
| `usage` | Token usage metrics |
|
|
81
|
+
| `tool_calls` | Tool call requests from model |
|
|
82
|
+
| `tool_started` | Tool execution started |
|
|
83
|
+
| `tool_completed` | Tool execution finished |
|
|
84
|
+
| `message_complete` | Full message assembled |
|
|
85
|
+
| `reasoning_delta` | Reasoning content delta (o1-style) |
|
|
86
|
+
| `reasoning_complete` | Full reasoning assembled |
|
|
87
|
+
| `agent_started` | Agent turn started |
|
|
88
|
+
| `agent_complete` | Agent turn finished |
|
|
89
|
+
| `error` | Error occurred |
|
|
90
|
+
|
|
91
|
+
`sdk.event` carries an envelope with an `event` property. The exported `SdkEvent` type is the
|
|
92
|
+
envelope; use `SdkEventMessage` internally when you need the nested discriminated union.
|
|
93
|
+
|
|
94
|
+
### Session and Turn Management
|
|
95
|
+
|
|
96
|
+
- `OpenAIConnectorSession` - Manages turn lifecycle and message history
|
|
97
|
+
- `OpenAIConnectorTurn` - Handles a single turn's streaming and tool execution
|
|
98
|
+
- `UserMessageQueue` - Internal queue from adapter core
|
|
99
|
+
|
|
100
|
+
### Tool Approval Flow
|
|
101
|
+
|
|
102
|
+
Tool execution routes through the approval system:
|
|
103
|
+
|
|
104
|
+
1. Connector emits `tool_approval` RPC on scoped bus
|
|
105
|
+
2. Agent wires to global `AgentSubjects.toolApprove`
|
|
106
|
+
3. Approval handler responds with approve/deny
|
|
107
|
+
4. Connector proceeds or skips based on response
|
|
108
|
+
|
|
109
|
+
## Exports
|
|
110
|
+
|
|
111
|
+
### Classes
|
|
112
|
+
|
|
113
|
+
| Export | Description |
|
|
114
|
+
|--------|-------------|
|
|
115
|
+
| `OpenAIAdapter` | Domain-level adapter, handles `adapter.*` subjects |
|
|
116
|
+
| `OpenAIAgent` | Agent wrapper, handles `agent.*` subjects |
|
|
117
|
+
| `OpenAINodeConnector` | SDK connector, extends `BaseStreamConnector` |
|
|
118
|
+
| `OpenAIConnectorSession` | Session state management |
|
|
119
|
+
| `OpenAIConnectorTurn` | Single turn execution |
|
|
120
|
+
| `UserMessageQueue` | Internal queue from adapter core |
|
|
121
|
+
|
|
122
|
+
### Namespace and Subjects
|
|
123
|
+
|
|
124
|
+
| Export | Description |
|
|
125
|
+
|--------|-------------|
|
|
126
|
+
| `OpenAINodeConnectorNamespace` | Bus namespace with typed schemas |
|
|
127
|
+
| `OpenAINodeConnectorSubjects` | Pre-extracted subject constants |
|
|
128
|
+
| `OPENAI_NODE_NAMESPACE` | Namespace string constant |
|
|
129
|
+
| `SdkEvent` | `sdk.event` envelope with nested `event` discriminated union |
|
|
130
|
+
|
|
131
|
+
### Configuration
|
|
132
|
+
|
|
133
|
+
| Export | Description |
|
|
134
|
+
|--------|-------------|
|
|
135
|
+
| `OpenAISessionConfig` | Session configuration type |
|
|
136
|
+
| `createTestConfig` | Conformance test suite configuration |
|
|
137
|
+
|
|
138
|
+
### Runtime Contribution
|
|
139
|
+
|
|
140
|
+
Runtime registration is contributed by `@makaio/adapter-openai-node/server`.
|
|
141
|
+
That entrypoint default-exports the `openaiNodePackage` `MakaioExtension`
|
|
142
|
+
descriptor, whose `adapters[]` entry wraps the internal definition from
|
|
143
|
+
`src/definition.ts`.
|
|
144
|
+
|
|
145
|
+
## File Structure
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
src/
|
|
149
|
+
├── index.ts # Public API exports
|
|
150
|
+
├── adapter.ts # OpenAIAdapter class
|
|
151
|
+
├── agent.ts # OpenAIAgent class
|
|
152
|
+
├── connector.ts # OpenAINodeConnector class
|
|
153
|
+
├── session.ts # Session management
|
|
154
|
+
├── turn.ts # Turn execution
|
|
155
|
+
├── config.ts # Configuration factory
|
|
156
|
+
├── constants.ts # Namespace constants
|
|
157
|
+
├── definition.ts # Internal adapter definition
|
|
158
|
+
├── package.ts # MakaioExtension package descriptor
|
|
159
|
+
├── server.ts # Server entrypoint exporting the package descriptor
|
|
160
|
+
├── provider.ts # Provider registration
|
|
161
|
+
├── provider.fetcher.ts # Model fetcher
|
|
162
|
+
├── model-normalization.ts # Model metadata normalization
|
|
163
|
+
├── mcp-integration.ts # MCP tool integration
|
|
164
|
+
├── tool-handling.ts # Tool approval and execution
|
|
165
|
+
├── stream-bridge.ts # SDK stream normalization
|
|
166
|
+
├── schemas.ts # Provider config and credential schemas
|
|
167
|
+
├── namespaces/
|
|
168
|
+
│ ├── index.ts # Namespace registration
|
|
169
|
+
│ └── schemas/ # Event type schemas
|
|
170
|
+
│ ├── chunk.ts
|
|
171
|
+
│ ├── message.ts
|
|
172
|
+
│ ├── reasoning.ts
|
|
173
|
+
│ ├── tool-calls.ts
|
|
174
|
+
│ └── usage.ts
|
|
175
|
+
├── types/
|
|
176
|
+
│ └── index.ts # TypeScript type definitions
|
|
177
|
+
└── utils/
|
|
178
|
+
├── blockToContentPart.ts
|
|
179
|
+
├── buildChatCompletionRequest.ts
|
|
180
|
+
├── classifyOpenAIError.ts
|
|
181
|
+
└── convertMessageHistory.ts
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
*Part of the Makaio AI framework*
|
package/descriptor.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openai-node",
|
|
3
|
+
"displayName": "OpenAI",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"makaio": {
|
|
6
|
+
"framework": ">=0.1.0"
|
|
7
|
+
},
|
|
8
|
+
"entrypoints": {
|
|
9
|
+
"server": true
|
|
10
|
+
},
|
|
11
|
+
"contributions": {
|
|
12
|
+
"adapters": [
|
|
13
|
+
{
|
|
14
|
+
"name": "openai-node",
|
|
15
|
+
"displayName": "OpenAI",
|
|
16
|
+
"description": "OpenAI chat completions with streaming and tool calling",
|
|
17
|
+
"protocols": ["openai"]
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
}
|