@breadstone/archipel-mcp 0.0.43 → 0.0.44
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/data/guides/ai-text-generation.md +397 -107
- package/data/packages/platform-intelligence/api/Class.IntelligenceHealthIndicator.md +5 -5
- package/data/packages/platform-intelligence/api/Class.IntelligenceModule.md +26 -2
- package/data/packages/platform-intelligence/api/Class.IntelligenceTextGenerator.md +43 -9
- package/data/packages/platform-intelligence/api/Class.IntelligenceToolBase.md +93 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceToolRegistry.md +217 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicAdvisor20260301Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicBash20241022Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicBash20250124Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20250522Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20250825Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20260120Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20241022Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20250124Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20251124Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicMemory20250818Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20241022Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250124Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250429Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250728Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicToolSearchBM2520251119Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicToolSearchRegex20251119Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebFetch20250910Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebFetch20260209Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebSearch20250305Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebSearch20260209Tool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createGoogleCodeExecutionTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createGoogleEnterpriseWebSearchTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createGoogleFileSearchTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createGoogleGoogleMapsTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createGoogleGoogleSearchTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createGoogleUrlContextTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createGoogleVertexRagStoreTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createIntelligenceTool.md +27 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAIApplyPatchTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAICodeInterpreterTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAICustomTool.md +27 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAIFileSearchTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAIImageGenerationTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAILocalShellTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAIMcpTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAIShellTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAIToolSearchTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAIWebSearchPreviewTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createOpenAIWebSearchTool.md +26 -0
- package/data/packages/platform-intelligence/api/Function.createProviderOptions.md +15 -2
- package/data/packages/platform-intelligence/api/Function.loadAnthropicLanguageModel.md +4 -4
- package/data/packages/platform-intelligence/api/Function.loadGoogleLanguageModel.md +4 -4
- package/data/packages/platform-intelligence/api/Function.loadGrokLanguageModel.md +4 -4
- package/data/packages/platform-intelligence/api/Function.loadOpenAILanguageModel.md +4 -4
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModuleOptions.md +79 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextCompletion.md +30 -6
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextGenerationOptions.md +106 -5
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextGenerator.md +29 -4
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextStreamingOptions.md +183 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTool.md +39 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolRegistry.md +146 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceLanguageModelLoader.md +3 -3
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceLanguageModelLoaders.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceTextStream.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.ANTHROPIC_API_KEY.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.ANTHROPIC_BASE_URL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.ANTHROPIC_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.AnthropicIntelligenceToolNames.md +42 -0
- package/data/packages/platform-intelligence/api/Variable.GEMINI_API_KEY.md +2 -2
- package/data/packages/platform-intelligence/api/Variable.GOOGLE_API_KEY.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.GOOGLE_BASE_URL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.GOOGLE_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.GROK_API_KEY.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.GROK_BASE_URL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.GROK_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.GoogleIntelligenceToolNames.md +34 -0
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_API_KEY.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_BASE_URL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_MAX_OUTPUT_TOKENS.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_MODEL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_PROVIDER.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_TEMPERATURE.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_TOP_P.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.OPENAI_API_KEY.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.OPENAI_BASE_URL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.OPENAI_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.OpenAIIntelligenceToolNames.md +40 -0
- package/data/packages/platform-intelligence/api/Variable.PLATFORM_INTELLIGENCE_CONFIG_ENTRIES.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.XAI_API_KEY.md +2 -2
- package/data/packages/platform-intelligence/api/Variable.XAI_BASE_URL.md +2 -2
- package/data/packages/platform-intelligence/api/index.md +64 -33
- package/data/packages/platform-intelligence/index.md +278 -69
- package/package.json +1 -1
- package/data/packages/platform-intelligence/api/Class.IntelligenceCapabilityRegistrarBase.md +0 -94
- package/data/packages/platform-intelligence/api/Class.IntelligenceCapabilityRegistry.md +0 -106
- package/data/packages/platform-intelligence/api/Function.loadProviderFactory.md +0 -31
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceArtifact.md +0 -34
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceCapability.md +0 -71
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceCapabilityMetadata.md +0 -70
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceCapabilityPayload.md +0 -46
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceCapabilityRegistry.md +0 -78
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceCapabilityResult.md +0 -46
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceContext.md +0 -72
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceContextBuilder.md +0 -35
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceConversationMessageSnapshot.md +0 -70
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceConversationSnapshot.md +0 -58
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceFollowUpQuestion.md +0 -46
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceIntent.md +0 -46
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceIntentEntity.md +0 -34
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceMessageModel.md +0 -70
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceMessagePayload.md +0 -34
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePrompt.md +0 -34
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptMessage.md +0 -34
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceResponseMessage.md +0 -34
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceConversationMessageRole.md +0 -14
- package/data/packages/platform-intelligence/api/Variable.IntelligenceConversationMessageRoles.md +0 -26
|
@@ -6,7 +6,7 @@ order: 15
|
|
|
6
6
|
|
|
7
7
|
# AI Text Generation
|
|
8
8
|
|
|
9
|
-
This guide covers text generation with `platform-intelligence`: choosing an AI provider, configuring the module, generating completions,
|
|
9
|
+
This guide covers text generation with `platform-intelligence`: choosing an AI provider, configuring the module, generating completions, streaming responses, and registering class-based or provider-native AI SDK tools.
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
@@ -36,18 +36,27 @@ yarn add @ai-sdk/openai
|
|
|
36
36
|
|
|
37
37
|
## Module Registration
|
|
38
38
|
|
|
39
|
-
Import `IntelligenceModule` into your application module. It exposes `IntelligenceTextGenerator` and `
|
|
39
|
+
Import `IntelligenceModule` into your application module. It exposes `IntelligenceTextGenerator` and `IntelligenceToolRegistry` as shared providers.
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
42
|
import { Module } from '@nestjs/common';
|
|
43
|
-
import { IntelligenceModule } from '@breadstone/archipel-platform-intelligence';
|
|
43
|
+
import { IntelligenceModule, IntelligenceProviderNames } from '@breadstone/archipel-platform-intelligence';
|
|
44
|
+
import { loadOpenAILanguageModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
44
45
|
|
|
45
46
|
@Module({
|
|
46
|
-
imports: [
|
|
47
|
+
imports: [
|
|
48
|
+
IntelligenceModule.register({
|
|
49
|
+
providerLoaders: {
|
|
50
|
+
[IntelligenceProviderNames.OpenAI]: loadOpenAILanguageModel,
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
47
54
|
})
|
|
48
55
|
export class AppModule {}
|
|
49
56
|
```
|
|
50
57
|
|
|
58
|
+
Register only the provider loaders you install. The root entry does not import provider SDK packages.
|
|
59
|
+
|
|
51
60
|
---
|
|
52
61
|
|
|
53
62
|
## Configuration
|
|
@@ -79,7 +88,7 @@ Each provider resolves its API key and base URL from dedicated environment varia
|
|
|
79
88
|
# Provider-specific keys (optional — fallback from INTELLIGENCE_API_KEY)
|
|
80
89
|
OPENAI_API_KEY=sk-...
|
|
81
90
|
ANTHROPIC_API_KEY=sk-ant-...
|
|
82
|
-
|
|
91
|
+
GOOGLE_API_KEY=AI...
|
|
83
92
|
GROK_API_KEY=xai-...
|
|
84
93
|
```
|
|
85
94
|
|
|
@@ -91,8 +100,8 @@ Inject `IntelligenceTextGenerator` to generate completions:
|
|
|
91
100
|
|
|
92
101
|
```typescript
|
|
93
102
|
import { Injectable } from '@nestjs/common';
|
|
94
|
-
import {
|
|
95
|
-
import type
|
|
103
|
+
import type { Prompt } from 'ai';
|
|
104
|
+
import { IntelligenceTextGenerator, type IIntelligenceTextCompletion } from '@breadstone/archipel-platform-intelligence';
|
|
96
105
|
|
|
97
106
|
@Injectable()
|
|
98
107
|
export class SummaryService {
|
|
@@ -103,8 +112,8 @@ export class SummaryService {
|
|
|
103
112
|
}
|
|
104
113
|
|
|
105
114
|
public async summarize(content: string): Promise<string> {
|
|
106
|
-
const prompt:
|
|
107
|
-
|
|
115
|
+
const prompt: Prompt = {
|
|
116
|
+
system: 'You are a concise summarizer. Respond with a short summary.',
|
|
108
117
|
messages: [{ role: 'user', content: content }],
|
|
109
118
|
};
|
|
110
119
|
|
|
@@ -117,18 +126,12 @@ export class SummaryService {
|
|
|
117
126
|
|
|
118
127
|
### Prompt Structure
|
|
119
128
|
|
|
120
|
-
A prompt
|
|
129
|
+
A prompt uses the native AI SDK `Prompt` type. Use either a string prompt or a full message array:
|
|
121
130
|
|
|
122
131
|
```typescript
|
|
123
|
-
|
|
124
|
-
readonly
|
|
125
|
-
readonly messages:
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
interface IIntelligencePromptMessage {
|
|
129
|
-
readonly role: 'user' | 'assistant' | 'system';
|
|
130
|
-
readonly content: string;
|
|
131
|
-
}
|
|
132
|
+
type Prompt =
|
|
133
|
+
| { readonly system?: string; readonly prompt: string }
|
|
134
|
+
| { readonly system?: string; readonly messages: Array<ModelMessage> };
|
|
132
135
|
```
|
|
133
136
|
|
|
134
137
|
### Per-Request Overrides
|
|
@@ -144,13 +147,15 @@ const completion = await this._textGenerator.generateText(prompt, {
|
|
|
144
147
|
|
|
145
148
|
### Completion Response
|
|
146
149
|
|
|
147
|
-
The response includes the generated text, the provider/model used, and optional token usage telemetry:
|
|
150
|
+
The response includes the generated text, the provider/model used, provider-native sources, generated files, and optional token usage telemetry:
|
|
148
151
|
|
|
149
152
|
```typescript
|
|
150
153
|
interface IIntelligenceTextCompletion {
|
|
151
154
|
readonly text: string;
|
|
152
155
|
readonly provider: string;
|
|
153
156
|
readonly model: string;
|
|
157
|
+
readonly sources: ReadonlyArray<LanguageModelV3Source>;
|
|
158
|
+
readonly files: ReadonlyArray<GeneratedFile>;
|
|
154
159
|
readonly usage: IIntelligenceCompletionUsage | null;
|
|
155
160
|
}
|
|
156
161
|
|
|
@@ -168,8 +173,8 @@ interface IIntelligenceCompletionUsage {
|
|
|
168
173
|
Build multi-turn conversations by passing the full message history:
|
|
169
174
|
|
|
170
175
|
```typescript
|
|
171
|
-
const prompt:
|
|
172
|
-
|
|
176
|
+
const prompt: Prompt = {
|
|
177
|
+
system: 'You are a helpful fitness coach.',
|
|
173
178
|
messages: [
|
|
174
179
|
{ role: 'user', content: 'What should I eat before a workout?' },
|
|
175
180
|
{ role: 'assistant', content: 'A balanced meal with carbs and protein about 2 hours before.' },
|
|
@@ -182,124 +187,405 @@ const completion = await this._textGenerator.generateText(prompt);
|
|
|
182
187
|
|
|
183
188
|
---
|
|
184
189
|
|
|
185
|
-
##
|
|
190
|
+
## Tool Registration
|
|
191
|
+
|
|
192
|
+
The intelligence module uses native AI SDK tools. Define a class that exposes a `name` and a native `Tool`, or register provider-native tool wrappers from provider subpaths.
|
|
186
193
|
|
|
187
|
-
|
|
194
|
+
```typescript
|
|
195
|
+
import { Injectable, Module } from '@nestjs/common';
|
|
196
|
+
import { tool, type Tool } from 'ai';
|
|
197
|
+
import { z } from 'zod';
|
|
198
|
+
import { IntelligenceModule, IntelligenceProviderNames, IntelligenceToolBase } from '@breadstone/archipel-platform-intelligence';
|
|
199
|
+
import { loadOpenAILanguageModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
200
|
+
|
|
201
|
+
interface IWorkoutInput {
|
|
202
|
+
readonly goal: string;
|
|
203
|
+
}
|
|
188
204
|
|
|
189
|
-
|
|
205
|
+
interface IWorkoutOutput {
|
|
206
|
+
readonly recommendation: string;
|
|
207
|
+
}
|
|
190
208
|
|
|
191
|
-
|
|
209
|
+
@Injectable()
|
|
210
|
+
export class WorkoutRecommendationTool extends IntelligenceToolBase<IWorkoutInput, IWorkoutOutput> {
|
|
211
|
+
public override get name(): string {
|
|
212
|
+
return 'recommendWorkout';
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public override get tool(): Tool<IWorkoutInput, IWorkoutOutput> {
|
|
216
|
+
return tool({
|
|
217
|
+
description: 'Recommends a workout plan for a user goal.',
|
|
218
|
+
inputSchema: z.object({
|
|
219
|
+
goal: z.string().describe('The user fitness goal'),
|
|
220
|
+
}),
|
|
221
|
+
execute: async (input) => ({
|
|
222
|
+
recommendation: `Workout plan for ${input.goal}`,
|
|
223
|
+
}),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
@Module({
|
|
229
|
+
imports: [
|
|
230
|
+
IntelligenceModule.register({
|
|
231
|
+
providerLoaders: {
|
|
232
|
+
[IntelligenceProviderNames.OpenAI]: loadOpenAILanguageModel,
|
|
233
|
+
},
|
|
234
|
+
tools: [WorkoutRecommendationTool],
|
|
235
|
+
}),
|
|
236
|
+
],
|
|
237
|
+
})
|
|
238
|
+
export class WorkoutModule {}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Provider-defined AI SDK tools are available through tree-shakable provider subpaths. They return `IIntelligenceTool` instances and can be placed directly in the `tools` array:
|
|
192
242
|
|
|
193
243
|
```typescript
|
|
194
|
-
import
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
IIntelligenceCapabilityResult,
|
|
199
|
-
IIntelligenceContext,
|
|
200
|
-
IIntelligenceIntent,
|
|
201
|
-
} from '@breadstone/archipel-platform-intelligence';
|
|
244
|
+
import { Module } from '@nestjs/common';
|
|
245
|
+
import { IntelligenceModule, IntelligenceProviderNames } from '@breadstone/archipel-platform-intelligence';
|
|
246
|
+
import { loadOpenAILanguageModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
247
|
+
import { createOpenAIWebSearchTool } from '@breadstone/archipel-platform-intelligence/providers/openai/tools';
|
|
202
248
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
249
|
+
@Module({
|
|
250
|
+
imports: [
|
|
251
|
+
IntelligenceModule.register({
|
|
252
|
+
providerLoaders: {
|
|
253
|
+
[IntelligenceProviderNames.OpenAI]: loadOpenAILanguageModel,
|
|
254
|
+
},
|
|
255
|
+
tools: [createOpenAIWebSearchTool({ searchContextSize: 'medium' })],
|
|
256
|
+
}),
|
|
257
|
+
],
|
|
258
|
+
})
|
|
259
|
+
export class SearchModule {}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
OpenAI, Google, and Anthropic provider subpaths expose wrappers for their built-in web search, file search, code execution, URL context, shell, MCP, and versioned tool families where supported by the underlying SDK.
|
|
263
|
+
|
|
264
|
+
### Native AI SDK Passthrough
|
|
265
|
+
|
|
266
|
+
Archipel is not intended to be a closed subset of the AI SDK. `IntelligenceTextGenerator.generateText()` and `streamText()` accept native AI SDK `Prompt` objects directly. Their options extend the native AI SDK call options, while Archipel still contributes provider configuration, registered tool merging, timeout defaults, logging, and normalized completion metadata.
|
|
267
|
+
|
|
268
|
+
Use the native AI SDK prompt shape for prompt strings, multimodal `ModelMessage` arrays, system-message arrays, or other prompt forms supported by the AI SDK.
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { openai } from '@ai-sdk/openai';
|
|
272
|
+
import { Injectable, Module } from '@nestjs/common';
|
|
273
|
+
import { IntelligenceModule, IntelligenceTextGenerator, type IIntelligenceTextCompletion } from '@breadstone/archipel-platform-intelligence';
|
|
274
|
+
|
|
275
|
+
@Module({
|
|
276
|
+
imports: [
|
|
277
|
+
IntelligenceModule.register({
|
|
278
|
+
validateOnModuleInit: false,
|
|
279
|
+
}),
|
|
280
|
+
],
|
|
281
|
+
})
|
|
282
|
+
export class RawAiSdkModule {}
|
|
283
|
+
|
|
284
|
+
@Injectable()
|
|
285
|
+
export class RawAiSdkRecipeService {
|
|
286
|
+
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
287
|
+
|
|
288
|
+
public constructor(textGenerator: IntelligenceTextGenerator) {
|
|
289
|
+
this._textGenerator = textGenerator;
|
|
214
290
|
}
|
|
215
291
|
|
|
216
|
-
public async
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
292
|
+
public async generateWithNativeAiSdkOptions(): Promise<IIntelligenceTextCompletion> {
|
|
293
|
+
return this._textGenerator.generateText(
|
|
294
|
+
{
|
|
295
|
+
system: 'Answer concisely and include assumptions.',
|
|
296
|
+
prompt: 'Compare the operational risks of outdoor work tomorrow.',
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
model: openai.responses('gpt-5'),
|
|
300
|
+
headers: { 'x-use-case': 'outdoor-risk' },
|
|
301
|
+
providerOptions: {
|
|
302
|
+
openai: {
|
|
303
|
+
reasoningEffort: 'medium',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
seed: 42,
|
|
307
|
+
},
|
|
308
|
+
);
|
|
223
309
|
}
|
|
224
310
|
}
|
|
225
311
|
```
|
|
226
312
|
|
|
227
|
-
|
|
313
|
+
If every request passes a native AI SDK model, `validateOnModuleInit: false` avoids requiring platform provider configuration at startup. If no `model` option is supplied, the configured provider loader and `INTELLIGENCE_PROVIDER` / `INTELLIGENCE_MODEL` values still define the model.
|
|
314
|
+
|
|
315
|
+
### Additional OpenAI Tool Recipes
|
|
228
316
|
|
|
229
|
-
|
|
317
|
+
The same pattern works for other provider-defined OpenAI tools. Register the provider tool wrapper on the module when it is available to the whole use case, or pass request-specific tools through `generateText()` when the tool needs request data such as a `fileId`.
|
|
230
318
|
|
|
231
319
|
```typescript
|
|
232
320
|
import { Injectable } from '@nestjs/common';
|
|
321
|
+
import { stepCountIs, tool } from 'ai';
|
|
322
|
+
import { z } from 'zod';
|
|
323
|
+
import { IntelligenceTextGenerator } from '@breadstone/archipel-platform-intelligence';
|
|
324
|
+
import { OpenAIIntelligenceToolNames } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
233
325
|
import {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
326
|
+
createOpenAICodeInterpreterTool,
|
|
327
|
+
createOpenAICustomTool,
|
|
328
|
+
createOpenAIImageGenerationTool,
|
|
329
|
+
createOpenAIToolSearchTool,
|
|
330
|
+
} from '@breadstone/archipel-platform-intelligence/providers/openai/tools';
|
|
238
331
|
|
|
239
332
|
@Injectable()
|
|
240
|
-
export class
|
|
241
|
-
|
|
242
|
-
|
|
333
|
+
export class OpenAIToolRecipeService {
|
|
334
|
+
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
335
|
+
|
|
336
|
+
public constructor(textGenerator: IntelligenceTextGenerator) {
|
|
337
|
+
this._textGenerator = textGenerator;
|
|
243
338
|
}
|
|
244
339
|
|
|
245
|
-
|
|
246
|
-
return
|
|
340
|
+
public async analyseSpreadsheet(fileId: string): Promise<IIntelligenceTextCompletion> {
|
|
341
|
+
return this._textGenerator.generateText(
|
|
342
|
+
{
|
|
343
|
+
system: 'You analyze uploaded spreadsheets and explain unusual values clearly.',
|
|
344
|
+
messages: [
|
|
345
|
+
{
|
|
346
|
+
role: 'user',
|
|
347
|
+
content: 'Analyze the file, detect unusual values, and summarize the most important findings as a table.',
|
|
348
|
+
},
|
|
349
|
+
],
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
activeTools: [OpenAIIntelligenceToolNames.CodeInterpreter],
|
|
353
|
+
tools: {
|
|
354
|
+
[OpenAIIntelligenceToolNames.CodeInterpreter]: createOpenAICodeInterpreterTool({
|
|
355
|
+
container: { fileIds: [fileId] },
|
|
356
|
+
}).tool,
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
);
|
|
247
360
|
}
|
|
248
|
-
}
|
|
249
|
-
```
|
|
250
361
|
|
|
251
|
-
|
|
362
|
+
public async generateIllustration(description: string): Promise<IIntelligenceTextCompletion> {
|
|
363
|
+
return this._textGenerator.generateText(
|
|
364
|
+
{
|
|
365
|
+
prompt: description,
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
activeTools: [OpenAIIntelligenceToolNames.ImageGeneration],
|
|
369
|
+
tools: {
|
|
370
|
+
[OpenAIIntelligenceToolNames.ImageGeneration]: createOpenAIImageGenerationTool({
|
|
371
|
+
quality: 'medium',
|
|
372
|
+
size: '1024x1024',
|
|
373
|
+
}).tool,
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
);
|
|
377
|
+
}
|
|
252
378
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
379
|
+
public async answerWithDeferredTools(prompt: string): Promise<IIntelligenceTextCompletion> {
|
|
380
|
+
return this._textGenerator.generateText(
|
|
381
|
+
{
|
|
382
|
+
prompt: prompt,
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
stopWhen: stepCountIs(10),
|
|
386
|
+
tools: {
|
|
387
|
+
[OpenAIIntelligenceToolNames.ToolSearch]: createOpenAIToolSearchTool().tool,
|
|
388
|
+
get_birthdays: tool({
|
|
389
|
+
description: 'Returns employee birthdays in a date range.',
|
|
390
|
+
inputSchema: z.object({
|
|
391
|
+
from: z.string(),
|
|
392
|
+
to: z.string(),
|
|
393
|
+
}),
|
|
394
|
+
execute: async (input) => ({ from: input.from, to: input.to, employees: [] }),
|
|
395
|
+
providerOptions: {
|
|
396
|
+
openai: { deferLoading: true },
|
|
397
|
+
},
|
|
398
|
+
}),
|
|
399
|
+
search_orders: tool({
|
|
400
|
+
description: 'Searches orders using domain-specific filters.',
|
|
401
|
+
inputSchema: z.object({
|
|
402
|
+
query: z.string(),
|
|
403
|
+
}),
|
|
404
|
+
execute: async (input) => ({ query: input.query, orders: [] }),
|
|
405
|
+
providerOptions: {
|
|
406
|
+
openai: { deferLoading: true },
|
|
407
|
+
},
|
|
408
|
+
}),
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
);
|
|
412
|
+
}
|
|
256
413
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
414
|
+
public async createReadOnlyReportQuery(prompt: string): Promise<IIntelligenceTextCompletion> {
|
|
415
|
+
return this._textGenerator.generateText(
|
|
416
|
+
{
|
|
417
|
+
system: 'Create only read-only reporting queries. The query must start with SELECT.',
|
|
418
|
+
messages: [{ role: 'user', content: prompt }],
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
toolChoice: 'required',
|
|
422
|
+
stopWhen: stepCountIs(3),
|
|
423
|
+
activeTools: ['report_query'],
|
|
424
|
+
tools: {
|
|
425
|
+
report_query: createOpenAICustomTool({
|
|
426
|
+
name: 'report_query',
|
|
427
|
+
description: 'Create a strictly read-only reporting query.',
|
|
428
|
+
format: {
|
|
429
|
+
type: 'grammar',
|
|
430
|
+
syntax: 'regex',
|
|
431
|
+
definition: 'SELECT .+',
|
|
432
|
+
},
|
|
433
|
+
}).tool,
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
262
439
|
```
|
|
263
440
|
|
|
264
|
-
|
|
441
|
+
`generateIllustration()` can return generated images through `completion.files`, while web search results are exposed through `completion.sources`. The platform keeps the AI SDK tool objects intact, so provider-specific options such as `container.fileIds`, `deferLoading`, grammar formats, and image settings still pass through to OpenAI. With the currently installed OpenAI SDK, `customTool()` supports grammar-constrained provider output but not a local `execute` callback; run parser, allowlist, and tenant filtering before executing any generated query, or model that execution as a normal `tool()` when local execution is required.
|
|
442
|
+
|
|
443
|
+
### Outdoor Order Weather Risk Example
|
|
265
444
|
|
|
266
|
-
|
|
445
|
+
This is the Archipel equivalent of using one application tool together with OpenAI web search. The model is selected through configuration, for example `INTELLIGENCE_PROVIDER=openai` and `INTELLIGENCE_MODEL=gpt-5`; the use case only depends on `IntelligenceTextGenerator`.
|
|
267
446
|
|
|
268
447
|
```typescript
|
|
269
|
-
import { Injectable } from '@nestjs/common';
|
|
270
|
-
import {
|
|
271
|
-
import
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
448
|
+
import { Injectable, Module } from '@nestjs/common';
|
|
449
|
+
import { stepCountIs, tool, type Tool } from 'ai';
|
|
450
|
+
import { z } from 'zod';
|
|
451
|
+
import {
|
|
452
|
+
IntelligenceModule,
|
|
453
|
+
IntelligenceProviderNames,
|
|
454
|
+
IntelligenceTextGenerator,
|
|
455
|
+
IntelligenceToolBase,
|
|
456
|
+
type IIntelligenceTextCompletion,
|
|
275
457
|
} from '@breadstone/archipel-platform-intelligence';
|
|
458
|
+
import { OpenAIIntelligenceToolNames, loadOpenAILanguageModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
459
|
+
import { createOpenAIWebSearchTool } from '@breadstone/archipel-platform-intelligence/providers/openai/tools';
|
|
460
|
+
|
|
461
|
+
interface IOutdoorOrderLookupInput {
|
|
462
|
+
readonly date: string;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
interface IOutdoorOrder {
|
|
466
|
+
readonly id: string;
|
|
467
|
+
readonly location: string;
|
|
468
|
+
readonly scheduledAt: string;
|
|
469
|
+
readonly outdoorWork: boolean;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
interface IOutdoorOrderLookupOutput {
|
|
473
|
+
readonly date: string;
|
|
474
|
+
readonly orders: ReadonlyArray<IOutdoorOrder>;
|
|
475
|
+
}
|
|
276
476
|
|
|
277
477
|
@Injectable()
|
|
278
|
-
export class
|
|
279
|
-
|
|
478
|
+
export class OutdoorOrdersTool extends IntelligenceToolBase<IOutdoorOrderLookupInput, IOutdoorOrderLookupOutput> {
|
|
479
|
+
public override get name(): string {
|
|
480
|
+
return 'get_outdoor_orders';
|
|
481
|
+
}
|
|
280
482
|
|
|
281
|
-
|
|
282
|
-
|
|
483
|
+
public override get tool(): Tool<IOutdoorOrderLookupInput, IOutdoorOrderLookupOutput> {
|
|
484
|
+
return tool({
|
|
485
|
+
description: 'Returns outdoor field orders for the current tenant and date.',
|
|
486
|
+
inputSchema: z.object({
|
|
487
|
+
date: z.string().describe('Date in YYYY-MM-DD format'),
|
|
488
|
+
}),
|
|
489
|
+
execute: async (input: IOutdoorOrderLookupInput) => this.loadOutdoorOrders(input.date),
|
|
490
|
+
});
|
|
283
491
|
}
|
|
284
492
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
493
|
+
private async loadOutdoorOrders(date: string): Promise<IOutdoorOrderLookupOutput> {
|
|
494
|
+
return {
|
|
495
|
+
date: date,
|
|
496
|
+
orders: [
|
|
497
|
+
{
|
|
498
|
+
id: 'ord_4711',
|
|
499
|
+
location: 'Berlin',
|
|
500
|
+
scheduledAt: `${date}T08:00:00+02:00`,
|
|
501
|
+
outdoorWork: true,
|
|
502
|
+
},
|
|
503
|
+
],
|
|
504
|
+
};
|
|
296
505
|
}
|
|
297
506
|
}
|
|
507
|
+
|
|
508
|
+
@Injectable()
|
|
509
|
+
export class OutdoorOrderRiskAnalysisService {
|
|
510
|
+
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
511
|
+
|
|
512
|
+
public constructor(textGenerator: IntelligenceTextGenerator) {
|
|
513
|
+
this._textGenerator = textGenerator;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
public async analyseOutdoorOrders(date: string): Promise<{ readonly text: string; readonly sources: IIntelligenceTextCompletion['sources'] }> {
|
|
517
|
+
const result = await this._textGenerator.generateText(
|
|
518
|
+
{
|
|
519
|
+
system: 'You assess weather-related risks for tenant outdoor field orders.',
|
|
520
|
+
messages: [
|
|
521
|
+
{
|
|
522
|
+
role: 'user',
|
|
523
|
+
content: `Review outdoor field orders for ${date} and flag weather-related risks.`,
|
|
524
|
+
},
|
|
525
|
+
],
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
toolChoice: 'auto',
|
|
529
|
+
activeTools: ['get_outdoor_orders', OpenAIIntelligenceToolNames.WebSearch],
|
|
530
|
+
stopWhen: stepCountIs(3),
|
|
531
|
+
},
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
return {
|
|
535
|
+
text: result.text,
|
|
536
|
+
sources: result.sources,
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
@Module({
|
|
542
|
+
imports: [
|
|
543
|
+
IntelligenceModule.register({
|
|
544
|
+
providerLoaders: {
|
|
545
|
+
[IntelligenceProviderNames.OpenAI]: loadOpenAILanguageModel,
|
|
546
|
+
},
|
|
547
|
+
tools: [
|
|
548
|
+
OutdoorOrdersTool,
|
|
549
|
+
createOpenAIWebSearchTool({
|
|
550
|
+
externalWebAccess: true,
|
|
551
|
+
searchContextSize: 'medium',
|
|
552
|
+
filters: {
|
|
553
|
+
allowedDomains: ['dwd.de'],
|
|
554
|
+
},
|
|
555
|
+
}),
|
|
556
|
+
],
|
|
557
|
+
}),
|
|
558
|
+
],
|
|
559
|
+
providers: [OutdoorOrderRiskAnalysisService],
|
|
560
|
+
})
|
|
561
|
+
export class OutdoorOrderRiskAnalysisModule {}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
Use AI SDK request options to constrain tool use per call:
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
const completion = await this._textGenerator.generateText(prompt, {
|
|
568
|
+
toolChoice: 'auto',
|
|
569
|
+
activeTools: ['recommendWorkout'],
|
|
570
|
+
});
|
|
298
571
|
```
|
|
299
572
|
|
|
300
|
-
|
|
573
|
+
> **Capacity limit:** The registry enforces a maximum of **128** registered tools.
|
|
574
|
+
|
|
575
|
+
---
|
|
301
576
|
|
|
302
|
-
|
|
577
|
+
## Streaming Text
|
|
578
|
+
|
|
579
|
+
`streamText()` uses the same provider configuration and registered tools as `generateText()` and returns the native AI SDK stream result.
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
const stream = await this._textGenerator.streamText(prompt, {
|
|
583
|
+
activeTools: ['recommendWorkout'],
|
|
584
|
+
stopWhen: stepCountIs(3),
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
return stream.toUIMessageStreamResponse();
|
|
588
|
+
```
|
|
303
589
|
|
|
304
590
|
---
|
|
305
591
|
|
|
@@ -325,7 +611,7 @@ Two additional error classes handle configuration and validation failures:
|
|
|
325
611
|
| ---------------------------------- | ----------------------------- | --------------------------------------------------------------------- |
|
|
326
612
|
| `IntelligenceProviderError` | `INTELLIGENCE_PROVIDER` | Provider SDK failures during text generation |
|
|
327
613
|
| `IntelligenceValidationError` | `INTELLIGENCE_VALIDATION` | Invalid generation parameters (temperature, topP, maxOutputTokens) |
|
|
328
|
-
| `IntelligenceConfigurationError` | `INTELLIGENCE_CONFIGURATION` | Unsupported provider, missing API key, or missing
|
|
614
|
+
| `IntelligenceConfigurationError` | `INTELLIGENCE_CONFIGURATION` | Unsupported provider, missing API key, or missing provider loader |
|
|
329
615
|
|
|
330
616
|
### Timeout & Retry Defaults
|
|
331
617
|
|
|
@@ -362,7 +648,7 @@ try {
|
|
|
362
648
|
}
|
|
363
649
|
```
|
|
364
650
|
|
|
365
|
-
If
|
|
651
|
+
If no loader is registered for the configured provider, startup fails with a clear configuration error. If a provider subpath is imported without its AI SDK peer package installed, the application fails at that import boundary instead of pulling the provider through the root package.
|
|
366
652
|
|
|
367
653
|
---
|
|
368
654
|
|
|
@@ -372,16 +658,20 @@ If an AI SDK provider package is not installed, the error message clearly states
|
|
|
372
658
|
flowchart TB
|
|
373
659
|
subgraph IntelligenceModule[IntelligenceModule]
|
|
374
660
|
TextGenerator[IntelligenceTextGenerator\nConfigService -> provider]
|
|
375
|
-
|
|
661
|
+
ToolRegistry[IntelligenceToolRegistry]
|
|
376
662
|
end
|
|
377
663
|
|
|
378
664
|
GenerateText["generateText(prompt, options?)"]
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
665
|
+
StreamText["streamText(prompt, options?)"]
|
|
666
|
+
ResolveTools["toToolSet()\nregister(tool)"]
|
|
667
|
+
ProviderLoaders[Registered Provider Loaders\nproviders/openai, providers/anthropic, providers/google, providers/grok]
|
|
668
|
+
FeatureTools[Feature Tools\nnative AI SDK tools]
|
|
382
669
|
|
|
383
670
|
TextGenerator --> GenerateText
|
|
384
|
-
|
|
671
|
+
TextGenerator --> StreamText
|
|
672
|
+
ToolRegistry --> ResolveTools
|
|
385
673
|
TextGenerator --> ProviderLoaders
|
|
386
|
-
|
|
674
|
+
ToolRegistry --> FeatureTools
|
|
675
|
+
GenerateText --> ToolRegistry
|
|
676
|
+
StreamText --> ToolRegistry
|
|
387
677
|
```
|