@mcp-abap-adt/sap-aicore-llm 11.0.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 +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/sap-core-ai-provider.d.ts +90 -0
- package/dist/sap-core-ai-provider.d.ts.map +1 -0
- package/dist/sap-core-ai-provider.js +394 -0
- package/dist/sap-core-ai-provider.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @mcp-abap-adt/sap-aicore-llm
|
|
2
|
+
|
|
3
|
+
SAP AI Core LLM provider for @mcp-abap-adt/llm-agent / @mcp-abap-adt/llm-agent-server.
|
|
4
|
+
|
|
5
|
+
Exports:
|
|
6
|
+
- `SapCoreAIProvider` — implements ILlm, calls SAP AI Core orchestration API.
|
|
7
|
+
- `SapCoreAIConfig` — configuration type.
|
|
8
|
+
|
|
9
|
+
Optional peer dependency. Install when smart-server.yaml names `sap-ai-sdk` or `sap-core-ai` as LLM provider, or when constructing SapCoreAIProvider programmatically.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,oBAAoB,EACpB,eAAe,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SAP AI SDK LLM Provider
|
|
3
|
+
*
|
|
4
|
+
* Implementation of LLMProvider interface using @sap-ai-sdk/orchestration.
|
|
5
|
+
* Authentication is handled automatically via AICORE_SERVICE_KEY environment variable.
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* - Agent → SapCoreAIProvider → OrchestrationClient → SAP AI Core → External LLM
|
|
9
|
+
*/
|
|
10
|
+
import type { IModelInfo, LLMProviderConfig, LLMResponse, Message } from '@mcp-abap-adt/llm-agent';
|
|
11
|
+
import { BaseLLMProvider } from '@mcp-abap-adt/llm-agent';
|
|
12
|
+
/**
|
|
13
|
+
* OAuth2 Client Credentials for programmatic SAP AI Core authentication.
|
|
14
|
+
* When provided, bypasses the AICORE_SERVICE_KEY environment variable.
|
|
15
|
+
*/
|
|
16
|
+
export interface SapAICoreCredentials {
|
|
17
|
+
/** OAuth2 client ID (e.g. 'sb-xxx...') */
|
|
18
|
+
clientId: string;
|
|
19
|
+
/** OAuth2 client secret */
|
|
20
|
+
clientSecret: string;
|
|
21
|
+
/** Token endpoint URL (e.g. 'https://xxx.authentication.xxx.hana.ondemand.com/oauth/token') */
|
|
22
|
+
tokenServiceUrl: string;
|
|
23
|
+
/** SAP AI Core API base URL (e.g. 'https://api.ai.xxx.aicore.cfapps.xxx.hana.ondemand.com') */
|
|
24
|
+
servicUrl: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SapCoreAIConfig extends LLMProviderConfig {
|
|
27
|
+
/** Model name (e.g. 'gpt-4o', 'claude-3-5-sonnet'). Default: 'gpt-4o' */
|
|
28
|
+
model?: string;
|
|
29
|
+
/** Temperature for generation. Default: 0.7 */
|
|
30
|
+
temperature?: number;
|
|
31
|
+
/** Max tokens for generation. Default: 16384 */
|
|
32
|
+
maxTokens?: number;
|
|
33
|
+
/** SAP AI Core resource group */
|
|
34
|
+
resourceGroup?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Programmatic OAuth2 credentials for SAP AI Core.
|
|
37
|
+
* When set, the SDK uses these instead of the AICORE_SERVICE_KEY env var.
|
|
38
|
+
*/
|
|
39
|
+
credentials?: SapAICoreCredentials;
|
|
40
|
+
/** Optional logger */
|
|
41
|
+
log?: {
|
|
42
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
43
|
+
error(message: string, meta?: Record<string, unknown>): void;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* SAP AI SDK Provider implementation
|
|
48
|
+
*
|
|
49
|
+
* Uses @sap-ai-sdk/orchestration for authentication and LLM access.
|
|
50
|
+
* A new OrchestrationClient is created per call because tools may change between calls.
|
|
51
|
+
*/
|
|
52
|
+
export declare class SapCoreAIProvider extends BaseLLMProvider<SapCoreAIConfig> {
|
|
53
|
+
readonly model: string;
|
|
54
|
+
readonly resourceGroup?: string;
|
|
55
|
+
private log?;
|
|
56
|
+
private readonly destination?;
|
|
57
|
+
private readonly httpsAgent;
|
|
58
|
+
private modelsCache;
|
|
59
|
+
private modelsCacheExpiry;
|
|
60
|
+
private static readonly MODELS_CACHE_TTL_MS;
|
|
61
|
+
private modelOverride?;
|
|
62
|
+
private static summarizeMessages;
|
|
63
|
+
private static summarizeStreamingError;
|
|
64
|
+
/** Set a per-request model override. Cleared after each chat/streamChat call. */
|
|
65
|
+
setModelOverride(model?: string): void;
|
|
66
|
+
constructor(config: SapCoreAIConfig);
|
|
67
|
+
chat(messages: Message[], tools?: unknown[]): Promise<LLMResponse>;
|
|
68
|
+
streamChat(messages: Message[], tools?: unknown[]): AsyncIterable<LLMResponse>;
|
|
69
|
+
/**
|
|
70
|
+
* Fetch all models from SAP AI Core, caching the result for MODELS_CACHE_TTL_MS.
|
|
71
|
+
* Returns ALL models regardless of capability — callers filter as needed.
|
|
72
|
+
*/
|
|
73
|
+
private _fetchAllModels;
|
|
74
|
+
getModels(): Promise<IModelInfo[]>;
|
|
75
|
+
getEmbeddingModels(): Promise<IModelInfo[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Extract detailed error information from SAP AI SDK / axios errors.
|
|
78
|
+
*/
|
|
79
|
+
private static extractErrorDetail;
|
|
80
|
+
/**
|
|
81
|
+
* Create an OrchestrationClient with the given tools configuration.
|
|
82
|
+
* Tools are expected in OpenAI function format (already converted by the agent layer).
|
|
83
|
+
*/
|
|
84
|
+
private createClient;
|
|
85
|
+
/**
|
|
86
|
+
* Format messages for the SAP AI SDK (OpenAI-compatible format).
|
|
87
|
+
*/
|
|
88
|
+
private formatMessages;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=sap-core-ai-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sap-core-ai-provider.d.ts","sourceRoot":"","sources":["../src/sap-core-ai-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,OAAO,EACR,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAM1D;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,+FAA+F;IAC/F,eAAe,EAAE,MAAM,CAAC;IACxB,+FAA+F;IAC/F,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,WAAW,CAAC,EAAE,oBAAoB,CAAC;IACnC,sBAAsB;IACtB,GAAG,CAAC,EAAE;QACJ,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EA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;;;OAGG;IACH,OAAO,CAAC,YAAY;IA6BpB;;OAEG;IACH,OAAO,CAAC,cAAc;CA+BvB"}
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SAP AI SDK LLM Provider
|
|
3
|
+
*
|
|
4
|
+
* Implementation of LLMProvider interface using @sap-ai-sdk/orchestration.
|
|
5
|
+
* Authentication is handled automatically via AICORE_SERVICE_KEY environment variable.
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* - Agent → SapCoreAIProvider → OrchestrationClient → SAP AI Core → External LLM
|
|
9
|
+
*/
|
|
10
|
+
import https from 'node:https';
|
|
11
|
+
import { BaseLLMProvider } from '@mcp-abap-adt/llm-agent';
|
|
12
|
+
import { OrchestrationClient, } from '@sap-ai-sdk/orchestration';
|
|
13
|
+
/**
|
|
14
|
+
* SAP AI SDK Provider implementation
|
|
15
|
+
*
|
|
16
|
+
* Uses @sap-ai-sdk/orchestration for authentication and LLM access.
|
|
17
|
+
* A new OrchestrationClient is created per call because tools may change between calls.
|
|
18
|
+
*/
|
|
19
|
+
export class SapCoreAIProvider extends BaseLLMProvider {
|
|
20
|
+
model;
|
|
21
|
+
resourceGroup;
|
|
22
|
+
log;
|
|
23
|
+
destination;
|
|
24
|
+
httpsAgent;
|
|
25
|
+
modelsCache = null;
|
|
26
|
+
modelsCacheExpiry = 0;
|
|
27
|
+
static MODELS_CACHE_TTL_MS = 300_000; // 5 min
|
|
28
|
+
modelOverride;
|
|
29
|
+
static summarizeMessages(messages) {
|
|
30
|
+
const totalChars = messages.reduce((sum, msg) => {
|
|
31
|
+
const content = typeof msg.content === 'string'
|
|
32
|
+
? msg.content
|
|
33
|
+
: JSON.stringify(msg.content ?? '');
|
|
34
|
+
return sum + content.length;
|
|
35
|
+
}, 0);
|
|
36
|
+
return {
|
|
37
|
+
totalChars,
|
|
38
|
+
roles: messages.map((msg, index) => ({
|
|
39
|
+
index,
|
|
40
|
+
role: msg.role,
|
|
41
|
+
contentLength: typeof msg.content === 'string'
|
|
42
|
+
? msg.content.length
|
|
43
|
+
: JSON.stringify(msg.content ?? '').length,
|
|
44
|
+
hasToolCalls: 'tool_calls' in msg && Array.isArray(msg.tool_calls),
|
|
45
|
+
toolCallCount: 'tool_calls' in msg && Array.isArray(msg.tool_calls)
|
|
46
|
+
? msg.tool_calls.length
|
|
47
|
+
: 0,
|
|
48
|
+
toolCallId: 'tool_call_id' in msg ? (msg.tool_call_id ?? null) : null,
|
|
49
|
+
})),
|
|
50
|
+
tail: messages.slice(-4).map((msg, index) => {
|
|
51
|
+
const content = typeof msg.content === 'string'
|
|
52
|
+
? msg.content
|
|
53
|
+
: JSON.stringify(msg.content ?? '');
|
|
54
|
+
return {
|
|
55
|
+
index: messages.length - Math.min(messages.length, 4) + index,
|
|
56
|
+
role: msg.role,
|
|
57
|
+
preview: content.length > 240
|
|
58
|
+
? `${content.slice(0, 240)}...[truncated]`
|
|
59
|
+
: content,
|
|
60
|
+
hasToolCalls: 'tool_calls' in msg && Array.isArray(msg.tool_calls),
|
|
61
|
+
toolCallNames: 'tool_calls' in msg && Array.isArray(msg.tool_calls)
|
|
62
|
+
? msg.tool_calls.map((tc) => tc.function?.name || '')
|
|
63
|
+
: [],
|
|
64
|
+
toolCallId: 'tool_call_id' in msg ? (msg.tool_call_id ?? null) : null,
|
|
65
|
+
};
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
static summarizeStreamingError(error) {
|
|
70
|
+
// biome-ignore lint/suspicious/noExplicitAny: diagnostic error shape from SDK/axios
|
|
71
|
+
const err = error;
|
|
72
|
+
const cause = err?.cause;
|
|
73
|
+
return {
|
|
74
|
+
error: SapCoreAIProvider.extractErrorDetail(error),
|
|
75
|
+
name: err?.name,
|
|
76
|
+
message: err?.message,
|
|
77
|
+
cause: cause?.message || cause,
|
|
78
|
+
causeCode: cause?.code,
|
|
79
|
+
status: err?.response?.status,
|
|
80
|
+
responseData: typeof err?.response?.data === 'string'
|
|
81
|
+
? err.response.data
|
|
82
|
+
: err?.response?.data
|
|
83
|
+
? JSON.stringify(err.response.data)
|
|
84
|
+
: undefined,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Set a per-request model override. Cleared after each chat/streamChat call. */
|
|
88
|
+
setModelOverride(model) {
|
|
89
|
+
this.modelOverride = model;
|
|
90
|
+
}
|
|
91
|
+
constructor(config) {
|
|
92
|
+
super(config);
|
|
93
|
+
// Skip validateConfig() — SAP SDK handles auth via AICORE_SERVICE_KEY env var
|
|
94
|
+
this.model = config.model || 'gpt-4o';
|
|
95
|
+
this.resourceGroup = config.resourceGroup;
|
|
96
|
+
this.log = config.log;
|
|
97
|
+
this.httpsAgent = new https.Agent({
|
|
98
|
+
keepAlive: true,
|
|
99
|
+
timeout: 60_000,
|
|
100
|
+
});
|
|
101
|
+
if (config.credentials) {
|
|
102
|
+
this.destination = {
|
|
103
|
+
url: config.credentials.servicUrl,
|
|
104
|
+
authentication: 'OAuth2ClientCredentials',
|
|
105
|
+
clientId: config.credentials.clientId,
|
|
106
|
+
clientSecret: config.credentials.clientSecret,
|
|
107
|
+
tokenServiceUrl: config.credentials.tokenServiceUrl,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async chat(messages, tools) {
|
|
112
|
+
try {
|
|
113
|
+
this.log?.debug('Sending chat request via SAP AI SDK', {
|
|
114
|
+
model: this.modelOverride ?? this.model,
|
|
115
|
+
messageCount: messages.length,
|
|
116
|
+
toolCount: tools?.length || 0,
|
|
117
|
+
maxTokens: this.config.maxTokens,
|
|
118
|
+
temperature: this.config.temperature,
|
|
119
|
+
});
|
|
120
|
+
const formatted = this.formatMessages(messages);
|
|
121
|
+
const client = this.createClient(formatted, tools);
|
|
122
|
+
const response = await client.chatCompletion(undefined, {
|
|
123
|
+
httpsAgent: this.httpsAgent,
|
|
124
|
+
});
|
|
125
|
+
const toolCalls = response.getToolCalls();
|
|
126
|
+
const content = response.getContent() || '';
|
|
127
|
+
const finishReason = response.getFinishReason();
|
|
128
|
+
this.log?.debug('Received response from SAP AI SDK', { finishReason });
|
|
129
|
+
return {
|
|
130
|
+
content,
|
|
131
|
+
finishReason,
|
|
132
|
+
raw: {
|
|
133
|
+
choices: [
|
|
134
|
+
{
|
|
135
|
+
message: {
|
|
136
|
+
role: 'assistant',
|
|
137
|
+
content,
|
|
138
|
+
...(toolCalls ? { tool_calls: toolCalls } : {}),
|
|
139
|
+
},
|
|
140
|
+
finish_reason: finishReason,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
usage: response.getTokenUsage(),
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
const detail = SapCoreAIProvider.extractErrorDetail(error);
|
|
149
|
+
this.log?.error('SAP AI SDK API error', { error: detail });
|
|
150
|
+
// biome-ignore lint/suspicious/noExplicitAny: diagnostic error details
|
|
151
|
+
const axiosErr = error;
|
|
152
|
+
if (axiosErr?.response?.data) {
|
|
153
|
+
this.log?.error('SAP AI SDK response body', {
|
|
154
|
+
status: axiosErr.response.status,
|
|
155
|
+
data: typeof axiosErr.response.data === 'string'
|
|
156
|
+
? axiosErr.response.data
|
|
157
|
+
: JSON.stringify(axiosErr.response.data),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`SAP AI SDK API error: ${detail}`);
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
this.modelOverride = undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async *streamChat(messages, tools) {
|
|
167
|
+
const model = this.modelOverride ?? this.model;
|
|
168
|
+
const messageSummary = SapCoreAIProvider.summarizeMessages(messages);
|
|
169
|
+
const toolCount = tools?.length || 0;
|
|
170
|
+
let streamOpened = false;
|
|
171
|
+
let chunkIndex = 0;
|
|
172
|
+
let emittedContentChunks = 0;
|
|
173
|
+
let emittedContentChars = 0;
|
|
174
|
+
try {
|
|
175
|
+
this.log?.debug('SAP AI SDK streamChat start', {
|
|
176
|
+
model,
|
|
177
|
+
resourceGroup: this.resourceGroup ?? 'default',
|
|
178
|
+
messageCount: messages.length,
|
|
179
|
+
toolCount,
|
|
180
|
+
maxTokens: this.config.maxTokens,
|
|
181
|
+
temperature: this.config.temperature,
|
|
182
|
+
messageSummary,
|
|
183
|
+
});
|
|
184
|
+
const formatted = this.formatMessages(messages);
|
|
185
|
+
this.log?.debug('SAP AI SDK streamChat messages formatted', {
|
|
186
|
+
model,
|
|
187
|
+
formattedMessageCount: formatted.length,
|
|
188
|
+
messageSummary,
|
|
189
|
+
});
|
|
190
|
+
const client = this.createClient(formatted, tools);
|
|
191
|
+
this.log?.debug('SAP AI SDK streamChat client created', {
|
|
192
|
+
model,
|
|
193
|
+
toolCount,
|
|
194
|
+
});
|
|
195
|
+
// Each stream gets its own agent to prevent connection multiplexing.
|
|
196
|
+
// A shared keepAlive agent can cause SAP AI Core to route SSE chunks
|
|
197
|
+
// to the wrong stream when multiple requests share the same XSUAA user.
|
|
198
|
+
const streamAgent = new https.Agent({
|
|
199
|
+
keepAlive: false,
|
|
200
|
+
timeout: 120_000,
|
|
201
|
+
});
|
|
202
|
+
this.log?.debug('SAP AI SDK streamChat opening stream', {
|
|
203
|
+
model,
|
|
204
|
+
keepAlive: false,
|
|
205
|
+
timeoutMs: 120_000,
|
|
206
|
+
});
|
|
207
|
+
const streamResponse = await client.stream(undefined, undefined, undefined, { httpsAgent: streamAgent });
|
|
208
|
+
streamOpened = true;
|
|
209
|
+
this.log?.debug('SAP AI SDK streamChat stream opened', {
|
|
210
|
+
model,
|
|
211
|
+
messageCount: messages.length,
|
|
212
|
+
toolCount,
|
|
213
|
+
});
|
|
214
|
+
for await (const chunk of streamResponse.stream) {
|
|
215
|
+
chunkIndex += 1;
|
|
216
|
+
// TokenUsage is only available in the final chunk (final_result.usage)
|
|
217
|
+
const tokenUsage = chunk.getTokenUsage();
|
|
218
|
+
const deltaContent = chunk.getDeltaContent() || '';
|
|
219
|
+
if (deltaContent) {
|
|
220
|
+
emittedContentChunks += 1;
|
|
221
|
+
emittedContentChars += deltaContent.length;
|
|
222
|
+
}
|
|
223
|
+
const finishReason = chunk.getFinishReason();
|
|
224
|
+
this.log?.debug('SAP AI SDK streamChat chunk received', {
|
|
225
|
+
model,
|
|
226
|
+
chunkIndex,
|
|
227
|
+
hasContent: deltaContent.length > 0,
|
|
228
|
+
contentLength: deltaContent.length,
|
|
229
|
+
emittedContentChunks,
|
|
230
|
+
emittedContentChars,
|
|
231
|
+
finishReason,
|
|
232
|
+
usage: tokenUsage
|
|
233
|
+
? {
|
|
234
|
+
promptTokens: tokenUsage.prompt_tokens || 0,
|
|
235
|
+
completionTokens: tokenUsage.completion_tokens || 0,
|
|
236
|
+
totalTokens: tokenUsage.total_tokens || 0,
|
|
237
|
+
}
|
|
238
|
+
: undefined,
|
|
239
|
+
});
|
|
240
|
+
yield {
|
|
241
|
+
content: deltaContent,
|
|
242
|
+
finishReason,
|
|
243
|
+
raw: chunk,
|
|
244
|
+
...(tokenUsage
|
|
245
|
+
? {
|
|
246
|
+
usage: {
|
|
247
|
+
prompt_tokens: tokenUsage.prompt_tokens || 0,
|
|
248
|
+
completion_tokens: tokenUsage.completion_tokens || 0,
|
|
249
|
+
total_tokens: tokenUsage.total_tokens || 0,
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
: {}),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
this.log?.debug('SAP AI SDK streamChat completed', {
|
|
256
|
+
model,
|
|
257
|
+
chunkCount: chunkIndex,
|
|
258
|
+
emittedContentChunks,
|
|
259
|
+
emittedContentChars,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
this.log?.error('SAP AI SDK streaming error', {
|
|
264
|
+
model,
|
|
265
|
+
resourceGroup: this.resourceGroup ?? 'default',
|
|
266
|
+
streamOpened,
|
|
267
|
+
chunkIndex,
|
|
268
|
+
emittedContentChunks,
|
|
269
|
+
emittedContentChars,
|
|
270
|
+
toolCount,
|
|
271
|
+
messageSummary,
|
|
272
|
+
...SapCoreAIProvider.summarizeStreamingError(error),
|
|
273
|
+
});
|
|
274
|
+
const detail = SapCoreAIProvider.extractErrorDetail(error);
|
|
275
|
+
throw new Error(`SAP AI SDK streaming error: ${detail}`);
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
this.modelOverride = undefined;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Fetch all models from SAP AI Core, caching the result for MODELS_CACHE_TTL_MS.
|
|
283
|
+
* Returns ALL models regardless of capability — callers filter as needed.
|
|
284
|
+
*/
|
|
285
|
+
async _fetchAllModels() {
|
|
286
|
+
if (this.modelsCache && Date.now() < this.modelsCacheExpiry) {
|
|
287
|
+
return this.modelsCache;
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const { ScenarioApi } = await import('@sap-ai-sdk/ai-api');
|
|
291
|
+
const result = await ScenarioApi.scenarioQueryModels('foundation-models', { 'AI-Resource-Group': this.resourceGroup ?? 'default' }).execute();
|
|
292
|
+
const models = [];
|
|
293
|
+
for (const r of result.resources) {
|
|
294
|
+
const latest = r.versions?.find((v) => v.isLatest) ?? r.versions?.[0];
|
|
295
|
+
if (!latest)
|
|
296
|
+
continue;
|
|
297
|
+
models.push({
|
|
298
|
+
id: r.model,
|
|
299
|
+
displayName: r.displayName,
|
|
300
|
+
owned_by: r.provider,
|
|
301
|
+
provider: r.provider,
|
|
302
|
+
capabilities: latest.capabilities,
|
|
303
|
+
contextLength: latest.contextLength,
|
|
304
|
+
streamingSupported: latest.streamingSupported,
|
|
305
|
+
deprecated: latest.deprecated,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
this.modelsCache = models;
|
|
309
|
+
this.modelsCacheExpiry =
|
|
310
|
+
Date.now() + SapCoreAIProvider.MODELS_CACHE_TTL_MS;
|
|
311
|
+
return models;
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
// Fallback to configured model if AI API is not available
|
|
315
|
+
return [{ id: this.model }];
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
async getModels() {
|
|
319
|
+
return this._fetchAllModels();
|
|
320
|
+
}
|
|
321
|
+
async getEmbeddingModels() {
|
|
322
|
+
const all = await this._fetchAllModels();
|
|
323
|
+
return all.filter((m) => m.capabilities?.includes('embeddings'));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Extract detailed error information from SAP AI SDK / axios errors.
|
|
327
|
+
*/
|
|
328
|
+
static extractErrorDetail(error) {
|
|
329
|
+
if (error !== null && typeof error === 'object') {
|
|
330
|
+
// biome-ignore lint/suspicious/noExplicitAny: axios error shape is untyped
|
|
331
|
+
const axiosError = error;
|
|
332
|
+
if (axiosError.response?.data) {
|
|
333
|
+
const data = axiosError.response.data;
|
|
334
|
+
const detail = typeof data === 'string' ? data : JSON.stringify(data).slice(0, 500);
|
|
335
|
+
return `${axiosError.message} — ${detail}`;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return error instanceof Error ? error.message : String(error);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Create an OrchestrationClient with the given tools configuration.
|
|
342
|
+
* Tools are expected in OpenAI function format (already converted by the agent layer).
|
|
343
|
+
*/
|
|
344
|
+
createClient(messages, tools) {
|
|
345
|
+
// biome-ignore lint/suspicious/noExplicitAny: SDK model type is a string literal union but the API accepts any model name
|
|
346
|
+
const orchConfig = {
|
|
347
|
+
promptTemplating: {
|
|
348
|
+
model: {
|
|
349
|
+
name: this.modelOverride ?? this.model,
|
|
350
|
+
params: {
|
|
351
|
+
max_tokens: this.config.maxTokens || 16384,
|
|
352
|
+
temperature: this.config.temperature || 0.7,
|
|
353
|
+
...(tools?.length ? { tool_choice: 'auto' } : {}),
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
prompt: {
|
|
357
|
+
template: messages,
|
|
358
|
+
...(tools?.length ? { tools } : {}),
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
return new OrchestrationClient(orchConfig, this.resourceGroup ? { resourceGroup: this.resourceGroup } : undefined, this.destination);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Format messages for the SAP AI SDK (OpenAI-compatible format).
|
|
366
|
+
*/
|
|
367
|
+
formatMessages(messages) {
|
|
368
|
+
return messages.map((msg) => {
|
|
369
|
+
if (msg.role === 'assistant' &&
|
|
370
|
+
msg.tool_calls &&
|
|
371
|
+
msg.tool_calls.length > 0) {
|
|
372
|
+
return {
|
|
373
|
+
role: 'assistant',
|
|
374
|
+
content: msg.content || undefined,
|
|
375
|
+
tool_calls: msg.tool_calls,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
if (msg.role === 'tool' && msg.tool_call_id) {
|
|
379
|
+
return {
|
|
380
|
+
role: 'tool',
|
|
381
|
+
content: typeof msg.content === 'string'
|
|
382
|
+
? msg.content
|
|
383
|
+
: JSON.stringify(msg.content ?? ''),
|
|
384
|
+
tool_call_id: msg.tool_call_id,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
role: msg.role,
|
|
389
|
+
content: msg.content ?? '',
|
|
390
|
+
};
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
//# sourceMappingURL=sap-core-ai-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sap-core-ai-provider.js","sourceRoot":"","sources":["../src/sap-core-ai-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,YAAY,CAAC;AAO/B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAEL,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AAsCnC;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SA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;wBAC7B,CAAC,CAAC,GAAG,CAAC,OAAO;wBACb,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;oBACvC,YAAY,EAAE,GAAG,CAAC,YAAY;iBAC/B,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,GAAG,CAAC,IAAyB;gBACnC,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;aAC3B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcp-abap-adt/sap-aicore-llm",
|
|
3
|
+
"version": "11.0.0",
|
|
4
|
+
"description": "SAP AI Core LLM provider (ILlm) for @mcp-abap-adt/llm-agent.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"clean": "tsc -p tsconfig.json --clean",
|
|
23
|
+
"test": "node --import tsx/esm --test --test-reporter=spec 'src/**/*.test.ts'"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@mcp-abap-adt/llm-agent": "*",
|
|
27
|
+
"@sap-ai-sdk/ai-api": "^2.9.0",
|
|
28
|
+
"@sap-ai-sdk/orchestration": "^2.9.0"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/fr0ster/llm-agent.git"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|