@didim365/agent-cli-core 0.3.1 → 0.3.4

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.
Files changed (49) hide show
  1. package/dist/src/availability/policyCatalog.js +2 -2
  2. package/dist/src/availability/policyCatalog.js.map +1 -1
  3. package/dist/src/config/costEstimation.d.ts +1 -1
  4. package/dist/src/config/costEstimation.js +13 -4
  5. package/dist/src/config/costEstimation.js.map +1 -1
  6. package/dist/src/config/models.js +4 -3
  7. package/dist/src/config/models.js.map +1 -1
  8. package/dist/src/config/providerModels.js +16 -6
  9. package/dist/src/config/providerModels.js.map +1 -1
  10. package/dist/src/core/contentGenerator.js +10 -2
  11. package/dist/src/core/contentGenerator.js.map +1 -1
  12. package/dist/src/generated/git-commit.d.ts +2 -2
  13. package/dist/src/generated/git-commit.js +2 -2
  14. package/dist/src/hooks/hookSystem.js.map +1 -1
  15. package/dist/src/providers/didim/adapter.d.ts +68 -0
  16. package/dist/src/providers/didim/adapter.js +346 -0
  17. package/dist/src/providers/didim/adapter.js.map +1 -0
  18. package/dist/src/providers/didim/bootstrap.d.ts +25 -0
  19. package/dist/src/providers/didim/bootstrap.js +47 -0
  20. package/dist/src/providers/didim/bootstrap.js.map +1 -0
  21. package/dist/src/providers/didim/converter.d.ts +133 -0
  22. package/dist/src/providers/didim/converter.js +309 -0
  23. package/dist/src/providers/didim/converter.js.map +1 -0
  24. package/dist/src/providers/didim/index.d.ts +13 -0
  25. package/dist/src/providers/didim/index.js +16 -0
  26. package/dist/src/providers/didim/index.js.map +1 -0
  27. package/dist/src/providers/gemini/converter.js +1 -1
  28. package/dist/src/providers/gemini/converter.js.map +1 -1
  29. package/dist/src/providers/index.d.ts +2 -0
  30. package/dist/src/providers/index.js +5 -0
  31. package/dist/src/providers/index.js.map +1 -1
  32. package/dist/src/providers/openai/adapter.d.ts +27 -0
  33. package/dist/src/providers/openai/adapter.js +106 -0
  34. package/dist/src/providers/openai/adapter.js.map +1 -1
  35. package/dist/src/providers/openai/bootstrap.js +4 -1
  36. package/dist/src/providers/openai/bootstrap.js.map +1 -1
  37. package/dist/src/providers/openai/responsesConverter.d.ts +92 -0
  38. package/dist/src/providers/openai/responsesConverter.js +408 -0
  39. package/dist/src/providers/openai/responsesConverter.js.map +1 -0
  40. package/dist/src/providers/openai-compatible/adapter.js.map +1 -1
  41. package/dist/src/providers/providerConfig.d.ts +5 -1
  42. package/dist/src/providers/providerConfig.js.map +1 -1
  43. package/dist/src/providers/providerConfigIntegration.d.ts +9 -1
  44. package/dist/src/providers/providerConfigIntegration.js +7 -1
  45. package/dist/src/providers/providerConfigIntegration.js.map +1 -1
  46. package/dist/src/providers/providerSelector.d.ts +4 -0
  47. package/dist/src/providers/providerSelector.js +6 -1
  48. package/dist/src/providers/providerSelector.js.map +1 -1
  49. package/package.json +1 -1
@@ -0,0 +1,346 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * DidimAdapter — extends BaseAdapter for DidimAIStudio REST/SSE API.
8
+ *
9
+ * Unlike Claude/OpenAI adapters that wrap SDK clients, this adapter uses
10
+ * raw fetch for HTTP + ReadableStream-based SSE parsing, because
11
+ * DidimAIStudio has no official SDK.
12
+ *
13
+ * Features:
14
+ * - Non-streaming: POST /scenario-gateway/v1/invoke
15
+ * - SSE streaming: POST /scenario-gateway/v1/invoke/sse (or /sse/improved)
16
+ * - Automatic thread_id management across calls
17
+ * - Error classification (401 → AuthenticationError, etc.)
18
+ *
19
+ * @see docs/00_project/Integration_DidimAIStudio/00_master_plan.md §1.2
20
+ * @see packages/core/src/providers/didim/converter.ts (pure conversion functions)
21
+ */
22
+ import { BaseAdapter } from '../baseAdapter.js';
23
+ import { LlmError, LlmErrorType, AuthenticationError, RateLimitError, TimeoutError, ValidationError, } from '../errors.js';
24
+ import { createErrorEvent } from '../events.js';
25
+ import { getDidimEndpoint, buildDidimHeaders, buildDidimRequestBody, parseDidimResponse, convertDidimResponseToLlm, parseDidimSseEvent, convertDidimSseToLlmEvents, } from './converter.js';
26
+ // ============================================================================
27
+ // Capabilities
28
+ // ============================================================================
29
+ /**
30
+ * Didim capabilities — scenario-based gateway with limited LLM features.
31
+ *
32
+ * Enabled:
33
+ * supportsStreaming: true — SSE streaming (sse + improved modes)
34
+ *
35
+ * Not supported:
36
+ * Everything else — DidimAIStudio is a scenario gateway, not a raw LLM API.
37
+ * Token counting, tool calls, image I/O, system messages, and thinking
38
+ * are all managed server-side within the scenario.
39
+ */
40
+ const DIDIM_CAPABILITIES = {
41
+ supportsStreaming: true,
42
+ supportsToolCalls: false,
43
+ supportsImageInput: false,
44
+ supportsImageGeneration: false,
45
+ supportsEmbedding: false,
46
+ supportsTokenCount: false,
47
+ supportsSystemMessage: false,
48
+ supportsThought: false,
49
+ maxContextLength: 0,
50
+ maxOutputTokens: 0,
51
+ };
52
+ // ============================================================================
53
+ // Adapter
54
+ // ============================================================================
55
+ /**
56
+ * DidimAdapter wraps the DidimAIStudio API behind the BaseAdapter interface.
57
+ */
58
+ export class DidimAdapter extends BaseAdapter {
59
+ fetchFn;
60
+ apiKey;
61
+ serverAddress;
62
+ streamMode;
63
+ providerName = 'didim';
64
+ capabilities = DIDIM_CAPABILITIES;
65
+ /** Stored thread_id for conversation continuity. */
66
+ threadId = null;
67
+ constructor(config, fetchFn, apiKey, serverAddress, streamMode) {
68
+ super(config);
69
+ this.fetchFn = fetchFn;
70
+ this.apiKey = apiKey;
71
+ this.serverAddress = serverAddress;
72
+ this.streamMode = streamMode;
73
+ }
74
+ /**
75
+ * Generate content (non-streaming).
76
+ * POST /scenario-gateway/v1/invoke
77
+ */
78
+ async generateContent(request, _userPromptId, options) {
79
+ this.validateRequest(request);
80
+ try {
81
+ const url = this.buildEndpointUrl();
82
+ const headers = buildDidimHeaders(this.apiKey, this.threadId);
83
+ const chatText = this.extractChatText(request);
84
+ const body = buildDidimRequestBody(chatText, this.threadId);
85
+ const response = await this.fetchFn(url, {
86
+ method: 'POST',
87
+ headers,
88
+ body: JSON.stringify(body),
89
+ signal: options?.signal,
90
+ });
91
+ if (!response.ok) {
92
+ throw this.classifyHttpError(response.status, response.statusText);
93
+ }
94
+ const rawJson = (await response.json());
95
+ const parsed = parseDidimResponse(rawJson);
96
+ // Store thread_id for subsequent calls
97
+ if (parsed.threadId) {
98
+ this.threadId = parsed.threadId;
99
+ }
100
+ return convertDidimResponseToLlm(parsed, request.model);
101
+ }
102
+ catch (error) {
103
+ this.handleError(error);
104
+ }
105
+ }
106
+ /**
107
+ * Generate content as a stream of LlmEvents.
108
+ * POST /scenario-gateway/v1/invoke/sse (or /sse/improved)
109
+ */
110
+ generateContentStream(request, _userPromptId, options) {
111
+ this.validateRequest(request);
112
+ const fetchFn = this.fetchFn;
113
+ const streamMode = this.streamMode;
114
+ const classify = this.classifyHttpError.bind(this);
115
+ const storeThreadId = (id) => {
116
+ if (id)
117
+ this.threadId = id;
118
+ };
119
+ // Build request params inside closure to capture current state,
120
+ // but keep inside generator try block for error classification.
121
+ const serverAddress = this.serverAddress;
122
+ const apiKey = this.apiKey;
123
+ // Read threadId lazily at fetch time to avoid stale capture
124
+ // when generator is consumed after subsequent calls update threadId.
125
+ const getThreadId = () => this.threadId;
126
+ const chatText = this.extractChatText(request);
127
+ const signal = options?.signal;
128
+ const buildEndpoint = () => getDidimEndpoint(serverAddress, {
129
+ streaming: true,
130
+ streamMode,
131
+ });
132
+ async function* streamGenerator() {
133
+ try {
134
+ // Build URL inside try so config errors become classified Error events
135
+ let url;
136
+ try {
137
+ url = buildEndpoint();
138
+ }
139
+ catch (e) {
140
+ const message = e instanceof Error ? e.message : String(e);
141
+ yield createErrorEvent(new ValidationError(`Didim configuration error: ${message}`, {
142
+ provider: 'didim',
143
+ }), undefined, false);
144
+ return;
145
+ }
146
+ const currentThreadId = getThreadId();
147
+ const headers = buildDidimHeaders(apiKey, currentThreadId);
148
+ const body = buildDidimRequestBody(chatText, currentThreadId);
149
+ const response = await fetchFn(url, {
150
+ method: 'POST',
151
+ headers,
152
+ body: JSON.stringify(body),
153
+ signal,
154
+ });
155
+ if (!response.ok) {
156
+ const error = classify(response.status, response.statusText);
157
+ yield createErrorEvent(error, error.code, error.isRetryable);
158
+ return;
159
+ }
160
+ if (!response.body) {
161
+ yield createErrorEvent('No response body for SSE stream', undefined, false);
162
+ return;
163
+ }
164
+ const reader = response.body.getReader();
165
+ const decoder = new TextDecoder();
166
+ let buffer = '';
167
+ let currentEvent = '';
168
+ const dataLines = [];
169
+ // Track whether any delta (message_partial) has been emitted.
170
+ // If so, suppress final_message to prevent duplicate text output.
171
+ let hasDelta = false;
172
+ try {
173
+ while (true) {
174
+ const { done, value } = await reader.read();
175
+ if (done)
176
+ break;
177
+ buffer += decoder.decode(value, { stream: true });
178
+ const lines = buffer.split('\n');
179
+ // Keep incomplete last line in buffer
180
+ buffer = lines.pop() ?? '';
181
+ for (const rawLine of lines) {
182
+ // Strip trailing \r for CRLF compatibility (SSE spec §9.2.4)
183
+ const line = rawLine.endsWith('\r')
184
+ ? rawLine.slice(0, -1)
185
+ : rawLine;
186
+ // SSE spec §9.2.4: field name is everything before first colon.
187
+ // A single space after the colon, if present, is stripped.
188
+ if (line.startsWith('event:')) {
189
+ currentEvent = line.substring(6).replace(/^ /, '').trim();
190
+ }
191
+ else if (line.startsWith('data:')) {
192
+ dataLines.push(line.substring(5).replace(/^ /, ''));
193
+ }
194
+ else if (line === '' && currentEvent) {
195
+ // Empty line = event boundary
196
+ // SSE spec: multiple data: lines joined with newline
197
+ const currentData = dataLines.join('\n');
198
+ const sseEvent = parseDidimSseEvent(currentEvent, currentData, streamMode);
199
+ if (sseEvent) {
200
+ // Store thread_id from done events
201
+ if (sseEvent.type === 'done' && sseEvent.threadId) {
202
+ storeThreadId(sseEvent.threadId);
203
+ }
204
+ // Track deltas and suppress final_message when deltas
205
+ // have already been emitted (prevents duplicate output
206
+ // in improved mode where server sends both
207
+ // message_partial deltas AND a final message event).
208
+ if (sseEvent.type === 'delta') {
209
+ hasDelta = true;
210
+ }
211
+ if (sseEvent.type === 'final_message' && hasDelta) {
212
+ // Skip — content already streamed via deltas
213
+ }
214
+ else {
215
+ const llmEvents = convertDidimSseToLlmEvents(sseEvent);
216
+ for (const llmEvent of llmEvents) {
217
+ yield llmEvent;
218
+ }
219
+ }
220
+ }
221
+ currentEvent = '';
222
+ dataLines.length = 0;
223
+ }
224
+ }
225
+ }
226
+ // Flush remaining TextDecoder bytes (trailing multi-byte sequence)
227
+ const trailing = decoder.decode();
228
+ if (trailing) {
229
+ buffer += trailing;
230
+ }
231
+ // Parse any remaining lines in buffer (stream ended without final \n)
232
+ if (buffer) {
233
+ const remainingLines = buffer.split('\n');
234
+ for (const rawLine of remainingLines) {
235
+ const line = rawLine.endsWith('\r')
236
+ ? rawLine.slice(0, -1)
237
+ : rawLine;
238
+ if (line.startsWith('event:')) {
239
+ currentEvent = line.substring(6).replace(/^ /, '').trim();
240
+ }
241
+ else if (line.startsWith('data:')) {
242
+ dataLines.push(line.substring(5).replace(/^ /, ''));
243
+ }
244
+ }
245
+ }
246
+ // Flush remaining event if stream ended without trailing blank line
247
+ if (currentEvent && dataLines.length > 0) {
248
+ const currentData = dataLines.join('\n');
249
+ const sseEvent = parseDidimSseEvent(currentEvent, currentData, streamMode);
250
+ if (sseEvent) {
251
+ if (sseEvent.type === 'done' && sseEvent.threadId) {
252
+ storeThreadId(sseEvent.threadId);
253
+ }
254
+ const llmEvents = convertDidimSseToLlmEvents(sseEvent);
255
+ for (const llmEvent of llmEvents) {
256
+ yield llmEvent;
257
+ }
258
+ }
259
+ }
260
+ }
261
+ finally {
262
+ reader.releaseLock();
263
+ }
264
+ }
265
+ catch (error) {
266
+ const err = error instanceof Error ? error : new Error(String(error));
267
+ yield createErrorEvent(err, undefined, false);
268
+ }
269
+ }
270
+ return streamGenerator();
271
+ }
272
+ /**
273
+ * Extract all text parts from the last user message, concatenated.
274
+ * DidimAIStudio accepts a single `chat` string, not a message array.
275
+ */
276
+ extractChatText(request) {
277
+ // Find the last user message
278
+ for (let i = request.messages.length - 1; i >= 0; i--) {
279
+ const msg = request.messages[i];
280
+ if (msg.role === 'user') {
281
+ const texts = [];
282
+ for (const content of msg.content) {
283
+ if (content.type === 'text') {
284
+ texts.push(content.text);
285
+ }
286
+ }
287
+ return texts.join('\n');
288
+ }
289
+ }
290
+ return '';
291
+ }
292
+ /**
293
+ * Build endpoint URL with error classification.
294
+ * Wraps getDidimEndpoint to convert raw Error to ValidationError.
295
+ */
296
+ buildEndpointUrl(streaming) {
297
+ try {
298
+ return getDidimEndpoint(this.serverAddress, streaming
299
+ ? {
300
+ streaming: true,
301
+ streamMode: this.streamMode,
302
+ }
303
+ : undefined);
304
+ }
305
+ catch (e) {
306
+ const message = e instanceof Error ? e.message : String(e);
307
+ throw new ValidationError(`Didim configuration error: ${message}`, {
308
+ provider: this.providerName,
309
+ });
310
+ }
311
+ }
312
+ /**
313
+ * Classify an HTTP status code into a typed LlmError.
314
+ */
315
+ classifyHttpError(status, statusText) {
316
+ const message = `DidimAIStudio API error: ${status} ${statusText ?? ''}`.trim();
317
+ const opts = {
318
+ provider: this.providerName,
319
+ statusCode: status,
320
+ };
321
+ if (status === 401 || status === 403) {
322
+ return new AuthenticationError(message, opts);
323
+ }
324
+ if (status === 429) {
325
+ return new RateLimitError(message, opts);
326
+ }
327
+ if (status === 408) {
328
+ return new TimeoutError(message, opts);
329
+ }
330
+ if (status >= 500) {
331
+ return new LlmError(LlmErrorType.SERVER_ERROR, message, {
332
+ ...opts,
333
+ isRetryable: true,
334
+ });
335
+ }
336
+ return new LlmError(LlmErrorType.UNKNOWN, message, opts);
337
+ }
338
+ /**
339
+ * Map common config to provider-specific config.
340
+ * DidimAIStudio doesn't use standard LLM config params.
341
+ */
342
+ mapToProviderConfig(_config) {
343
+ return {};
344
+ }
345
+ }
346
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter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,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Didim provider bootstrap — registers the DidimAdapter factory
8
+ * in the ProviderRegistry.
9
+ *
10
+ * Uses a has() guard so repeated calls are idempotent (safe for HMR,
11
+ * test re-initialization, or Agent re-creation).
12
+ *
13
+ * Config resolution priority:
14
+ * 1. AdapterConfig fields (passed from contentGenerator.ts)
15
+ * 2. Environment variables (DIDIM_API_KEY, DIDIM_SERVER_ADDRESS, DIDIM_STREAM_MODE)
16
+ *
17
+ * @see docs/00_project/Integration_DidimAIStudio/00_master_plan.md
18
+ */
19
+ import { ProviderRegistry } from '../registry.js';
20
+ /**
21
+ * Register the Didim adapter factory in the provider registry.
22
+ *
23
+ * @param registry - Optional registry instance. Defaults to singleton.
24
+ */
25
+ export declare function bootstrapDidimProvider(registry?: ProviderRegistry): void;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Didim provider bootstrap — registers the DidimAdapter factory
8
+ * in the ProviderRegistry.
9
+ *
10
+ * Uses a has() guard so repeated calls are idempotent (safe for HMR,
11
+ * test re-initialization, or Agent re-creation).
12
+ *
13
+ * Config resolution priority:
14
+ * 1. AdapterConfig fields (passed from contentGenerator.ts)
15
+ * 2. Environment variables (DIDIM_API_KEY, DIDIM_SERVER_ADDRESS, DIDIM_STREAM_MODE)
16
+ *
17
+ * @see docs/00_project/Integration_DidimAIStudio/00_master_plan.md
18
+ */
19
+ import { ProviderRegistry } from '../registry.js';
20
+ import { DidimAdapter } from './adapter.js';
21
+ import { ValidationError } from '../errors.js';
22
+ /** Valid stream mode values. */
23
+ const VALID_STREAM_MODES = new Set(['sse', 'improved']);
24
+ /**
25
+ * Register the Didim adapter factory in the provider registry.
26
+ *
27
+ * @param registry - Optional registry instance. Defaults to singleton.
28
+ */
29
+ export function bootstrapDidimProvider(registry) {
30
+ const reg = registry ?? ProviderRegistry.getInstance();
31
+ if (reg.has('didim'))
32
+ return;
33
+ reg.register('didim', (config) => {
34
+ const apiKey = config.apiKey || process.env['DIDIM_API_KEY'] || '';
35
+ const serverAddress = config['serverAddress'] ||
36
+ process.env['DIDIM_SERVER_ADDRESS'] ||
37
+ '';
38
+ const streamModeRaw = config['streamMode'] ||
39
+ process.env['DIDIM_STREAM_MODE'] ||
40
+ 'sse';
41
+ if (!VALID_STREAM_MODES.has(streamModeRaw)) {
42
+ throw new ValidationError(`Invalid DIDIM_STREAM_MODE: "${streamModeRaw}". Must be "sse" or "improved".`, { provider: 'didim' });
43
+ }
44
+ return new DidimAdapter(config, globalThis.fetch.bind(globalThis), apiKey, serverAddress, streamModeRaw);
45
+ });
46
+ }
47
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/providers/didim/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,gCAAgC;AAChC,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAA2B;IAChE,MAAM,GAAG,GAAG,QAAQ,IAAI,gBAAgB,CAAC,WAAW,EAAE,CAAC;IACvD,IAAI,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,OAAO;IAE7B,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAqB,EAAE,EAAE;QAC9C,MAAM,MAAM,GACT,MAAM,CAAC,MAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;QAClE,MAAM,aAAa,GAChB,MAAM,CAAC,eAAe,CAAY;YACnC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;YACnC,EAAE,CAAC;QACL,MAAM,aAAa,GAChB,MAAM,CAAC,YAAY,CAAY;YAChC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;YAChC,KAAK,CAAC;QAER,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,eAAe,CACvB,+BAA+B,aAAa,iCAAiC,EAC7E,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtB,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,YAAY,CACrB,MAAM,EACN,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,EACjC,MAAM,EACN,aAAa,EACb,aAAgC,CACjC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * DidimAIStudio converter — pure functions for request/response transformation.
8
+ *
9
+ * Converts between the LLM-agnostic types used by the adapter layer and the
10
+ * DidimAIStudio REST/SSE API format.
11
+ *
12
+ * API contract (master plan §1.2 + 06-didiaistudio-plan.md):
13
+ * - Invoke: POST {baseUrl}/scenario-gateway/v1/invoke
14
+ * - SSE: POST {baseUrl}/scenario-gateway/v1/invoke/sse
15
+ * - Improved: POST {baseUrl}/scenario-gateway/v1/invoke/sse/improved
16
+ * - Auth: Authorization: Bearer {jwt_token}
17
+ * - Body: { chat: string, thread_id?: string }
18
+ * - Response: { response: string, thread_id: string }
19
+ *
20
+ * Improved mode event types (OpenAPI spec + 06-plan):
21
+ * - message_partial: 토큰 스트리밍 (chunk/content/message 필드)
22
+ * - message_complete: ToolMessage 완료 (message 필드 or process_name)
23
+ * - message_metadata: 실행 컨텍스트 (langgraph_node, step, model) → 비콘텐츠
24
+ * - process: 노드 진행 상황 → 비콘텐츠
25
+ * - message: 최종 완성 응답 → adapter가 delta 이후 중복 억제
26
+ * - complete/done: 실행 완료 (thread_id, qa_id)
27
+ * - error: 에러
28
+ */
29
+ import { type LlmEvent } from '../events.js';
30
+ import type { LlmGenerateResponse } from '../types.js';
31
+ /** SSE stream mode. */
32
+ export type DidimStreamMode = 'sse' | 'improved';
33
+ /** Raw response from the DidimAIStudio invoke endpoint. */
34
+ export interface DidimResponse {
35
+ response?: unknown;
36
+ thread_id?: unknown;
37
+ }
38
+ /** Parsed response in application-level types. */
39
+ export interface DidimParsedResponse {
40
+ content: string;
41
+ threadId: string | null;
42
+ }
43
+ /**
44
+ * Intermediate SSE event after parsing, before LlmEvent conversion.
45
+ *
46
+ * - delta: 토큰 스트리밍 텍스트 (message_partial, sse message)
47
+ * - final_message: improved 모드 최종 완성 응답 — adapter가 delta 이후 중복 억제
48
+ * - done: 스트림 완료 (complete/done 이벤트)
49
+ * - error: 에러
50
+ * - metadata: 비콘텐츠 메타데이터 (message_metadata, process, message_complete 중 비텍스트)
51
+ */
52
+ export type DidimSseEvent = {
53
+ type: 'delta';
54
+ text: string;
55
+ } | {
56
+ type: 'final_message';
57
+ text: string;
58
+ } | {
59
+ type: 'done';
60
+ threadId: string | null;
61
+ } | {
62
+ type: 'error';
63
+ message: string;
64
+ } | {
65
+ type: 'metadata';
66
+ eventName: string;
67
+ data: Record<string, unknown>;
68
+ };
69
+ /** Options for endpoint generation. */
70
+ export interface DidimEndpointOptions {
71
+ streaming?: boolean;
72
+ streamMode?: DidimStreamMode;
73
+ }
74
+ /**
75
+ * Normalizes a DidimAIStudio domain by stripping protocol prefixes,
76
+ * trailing slashes, and path segments. Preserves port numbers.
77
+ */
78
+ export declare function normalizeDidimDomain(raw: string): string;
79
+ /**
80
+ * Detects the protocol scheme from a raw domain/URL string.
81
+ * Returns 'http' if explicitly specified, otherwise defaults to 'https'.
82
+ *
83
+ * Supports http:// for local development (e.g., http://localhost:8008).
84
+ */
85
+ export declare function detectScheme(raw: string): 'http' | 'https';
86
+ /**
87
+ * Builds the full endpoint URL for a given domain and options.
88
+ * Preserves http:// protocol when explicitly provided (local dev support).
89
+ */
90
+ export declare function getDidimEndpoint(domain: string, options?: DidimEndpointOptions): string;
91
+ /**
92
+ * Builds HTTP headers for a DidimAIStudio request.
93
+ * Trims threadId before use — whitespace-only values are excluded.
94
+ */
95
+ export declare function buildDidimHeaders(jwtToken: string, threadId?: string | null): Record<string, string>;
96
+ /**
97
+ * Builds the JSON request body for a DidimAIStudio request.
98
+ * Trims threadId before use — whitespace-only values are excluded.
99
+ */
100
+ export declare function buildDidimRequestBody(chat: string, threadId?: string | null): Record<string, string>;
101
+ /**
102
+ * Parses a raw DidimAIStudio invoke response into typed application data.
103
+ */
104
+ export declare function parseDidimResponse(raw: DidimResponse): DidimParsedResponse;
105
+ /**
106
+ * Parses a single SSE event (event name + data string) into a DidimSseEvent.
107
+ *
108
+ * Handles both `sse` and `improved` stream modes with graceful fallback
109
+ * for malformed input (invalid JSON, unknown events, empty/whitespace keep-alive).
110
+ *
111
+ * @returns Parsed event, or `null` for ignored/keep-alive/metadata events.
112
+ */
113
+ export declare function parseDidimSseEvent(eventName: string, data: string, mode: DidimStreamMode): DidimSseEvent | null;
114
+ /**
115
+ * Generates a unique response ID for DidimAIStudio responses.
116
+ * DidimAIStudio does not provide server-side response IDs.
117
+ */
118
+ export declare function generateDidimResponseId(): string;
119
+ /**
120
+ * Converts a parsed DidimAIStudio invoke response to an LlmGenerateResponse.
121
+ */
122
+ export declare function convertDidimResponseToLlm(parsed: DidimParsedResponse, model: string): LlmGenerateResponse;
123
+ /**
124
+ * Converts a DidimSseEvent to one or more LlmEvents.
125
+ *
126
+ * Event mapping:
127
+ * - delta → TextDelta
128
+ * - final_message → TextDelta (adapter suppresses when deltas already emitted)
129
+ * - done → Finished + MessageEnd (in order)
130
+ * - error → Error
131
+ * - metadata → [] (non-content, silently skipped)
132
+ */
133
+ export declare function convertDidimSseToLlmEvents(event: DidimSseEvent): LlmEvent[];