@digilogiclabs/platform-core 1.15.0 → 1.16.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/dist/index.d.mts CHANGED
@@ -3,8 +3,8 @@ export { aH as AIConfigSchema, aA as AIProviderSchema, a4 as BackoffOptions, aO
3
3
  import { a as ILogger, I as ICache, c as IAI, A as AIConfig, d as AIChatRequest, e as AIChatResponse, f as AIStreamChunk, g as AIStreamCallback, h as AICompletionRequest, i as AICompletionResponse, j as AIEmbeddingRequest, k as AIEmbeddingResponse, l as AIModelConfig, m as AIModelType, n as AIProvider } from './IAI-D8wA_i8N.mjs';
4
4
  export { z as AIChatChoice, G as AIError, F as AIErrorCode, u as AIErrorMessages, B as AIFinishReason, w as AIMessage, v as AIRole, E as AIRouterConfig, y as AITool, x as AIToolCall, D as AIUsageInfo, C as ConsoleLogger, o as ICacheOptions, K as ISpan, b as ITracing, q as LogEntry, L as LogLevel, p as LogMeta, r as LoggerConfig, M as MemoryAI, H as MemoryTracing, N as NoopLogger, J as NoopTracing, R as RoutingStrategy, S as SpanContext, V as SpanEvent, Q as SpanKind, O as SpanOptions, P as SpanStatus, U as SpanStatusCode, T as TracingConfig, s as createAIError, t as isAIError } from './IAI-D8wA_i8N.mjs';
5
5
  export { w as IMigrationDatabase, I as IMigrator, q as Migration, r as MigrationRecord, t as MigrationResult, u as MigrationStatus, M as Migrator, v as MigratorConfig, S as SQL, o as createBetaInvitesTable, n as createBetaSettingsTable, p as createBetaTestersTable, f as createDomainVerificationsTable, c as createMigration, b as createSsoOidcConfigsTable, m as createSsoSessionsTable, k as createTenantInvitationsTable, j as createTenantMembersTable, l as createTenantUsageTable, i as createTenantsTable, h as createVerifiedDomainsTable, d as defineMigration, e as enterpriseMigrations, g as generateVersion, a as getEnterpriseMigrations, s as sqlMigration } from './index-DzQ0Js5Z.mjs';
6
- import { I as IAIUsage, A as AIUsageConfig, U as UsageRecord, a as UsageQuery, b as UsageQueryResult, Q as Quota, c as QuotaType, d as UsageCategory, e as QuotaStatus, B as Budget, f as BudgetStatus, g as UsageInterval, h as UsageSummary, i as UsageTrend, C as CostBreakdown, j as UsageInvoice, k as AlertType, l as UsageAlert } from './agents-Cd2eEX5M.mjs';
7
- export { F as AgentBudget, p as AgentCumulativeUsage, r as AgentIterationCallback, q as AgentIterationEvent, t as AgentLoopOptions, u as AgentLoopResult, s as AgentStopReason, n as AgentTool, o as AgentToolResult, x as AgentTracer, w as AgentTracerOptions, E as AgentUsageRecordParams, G as AgentUsageTracker, z as AgentUsageTrackerOptions, D as DEFAULT_AGENT_LOOP_OPTIONS, M as MemoryAIUsage, T as ToolExecutor, J as TracedAIOptions, m as UsageInvoiceItem, y as createAgentTracer, H as createAgentUsageTracker, K as createTracedAI, v as runAgentLoop } from './agents-Cd2eEX5M.mjs';
6
+ import { I as IAIUsage, A as AIUsageConfig, U as UsageRecord, a as UsageQuery, b as UsageQueryResult, Q as Quota, c as QuotaType, d as UsageCategory, e as QuotaStatus, B as Budget, f as BudgetStatus, g as UsageInterval, h as UsageSummary, i as UsageTrend, C as CostBreakdown, j as UsageInvoice, k as AlertType, l as UsageAlert } from './agents-DGciJI27.mjs';
7
+ export { G as AgentBudget, q as AgentCumulativeUsage, s as AgentIterationCallback, r as AgentIterationEvent, u as AgentLoopOptions, v as AgentLoopResult, t as AgentStopReason, o as AgentTool, p as AgentToolResult, y as AgentTracer, x as AgentTracerOptions, F as AgentUsageRecordParams, H as AgentUsageTracker, E as AgentUsageTrackerOptions, D as DEFAULT_AGENT_LOOP_OPTIONS, M as MemoryAIUsage, O as OllamaAdapter, n as OllamaAdapterConfig, T as ToolExecutor, K as TracedAIOptions, m as UsageInvoiceItem, z as createAgentTracer, J as createAgentUsageTracker, L as createTracedAI, w as runAgentLoop } from './agents-DGciJI27.mjs';
8
8
  import { aS as IBeta, aT as BetaConfig, aU as BetaSettings, aV as UpdateBetaSettingsOptions, aW as CreateBetaCodesOptions, aX as BetaInviteCode, aY as ListBetaCodesOptions, aZ as BetaValidationResult, a_ as BetaConsumeResult, a$ as BetaTester, b0 as BetaStats, b1 as BetaCodeUsageReport } from './env-BJWliXSO.mjs';
9
9
  export { al as AllowlistConfig, A as ApiError, d as ApiErrorCode, f as ApiErrorCodeType, h as ApiPaginatedResponse, Q as ApiSecurityConfig, V as ApiSecurityContext, g as ApiSuccessResponse, aD as AuditRequest, H as AuthCookiesConfig, N as AuthMethod, aL as BetaClientConfig, b6 as BetaCodeStatus, C as CommonApiErrors, ar as CommonRateLimits, ac as DateRangeInput, a6 as DateRangeSchema, ag as DeploymentStage, aa as EmailInput, $ as EmailSchema, E as EnvValidationConfig, p as EnvValidationResult, ai as FlagDefinition, aj as FlagDefinitions, ah as FlagValue, r as KEYCLOAK_DEFAULT_ROLES, F as KeycloakCallbacksConfig, K as KeycloakConfig, G as KeycloakJwtFields, q as KeycloakTokenSet, ae as LoginInput, a8 as LoginSchema, b2 as MemoryBeta, ay as OpsAuditActor, aA as OpsAuditEvent, aC as OpsAuditLoggerOptions, aB as OpsAuditRecord, az as OpsAuditResource, b7 as PG_ERROR_MAP, ab as PaginationInput, a5 as PaginationSchema, a0 as PasswordSchema, a3 as PersonNameSchema, a2 as PhoneSchema, aq as RateLimitCheckResult, b as RateLimitOptions, P as RateLimitPreset, a as RateLimitRule, R as RateLimitStore, J as RedirectCallbackConfig, ak as ResolvedFlags, O as RouteAuditConfig, ad as SearchQueryInput, a7 as SearchQuerySchema, U as SecuritySession, af as SignupInput, a9 as SignupSchema, a1 as SlugSchema, aF as StandardAuditActionType, aE as StandardAuditActions, S as StandardRateLimitPresets, T as TokenRefreshResult, _ as WrapperPresets, ao as buildAllowlist, I as buildAuthCookies, Z as buildErrorBody, M as buildKeycloakCallbacks, e as buildPagination, Y as buildRateLimitHeaders, aw as buildRateLimitResponseHeaders, L as buildRedirectCallback, y as buildTokenRefreshParams, n as checkEnvVars, at as checkRateLimit, c as classifyError, aR as clearStoredBetaCode, aJ as createAuditActor, aK as createAuditLogger, aM as createBetaClient, an as createFeatureFlags, as as createMemoryRateLimitStore, a4 as createSafeTextSchema, am as detectStage, aG as extractAuditIp, aI as extractAuditRequestId, aH as extractAuditUserAgent, X as extractClientIp, aN as fetchBetaSettings, b3 as generateBetaCode, b5 as generateBetaId, l as getBoolEnv, B as getEndSessionEndpoint, o as getEnvSummary, m as getIntEnv, k as getOptionalEnv, au as getRateLimitStatus, j as getRequiredEnv, aQ as getStoredBetaCode, z as getTokenEndpoint, w as hasAllRoles, u as hasAnyRole, t as hasRole, ap as isAllowlisted, i as isApiError, x as isTokenExpired, b4 as normalizeBetaCode, s as parseKeycloakRoles, D as refreshKeycloakToken, av as resetRateLimitForKey, ax as resolveIdentifier, W as resolveRateLimitIdentifier, aP as storeBetaCode, aO as validateBetaCode, v as validateEnvVars } from './env-BJWliXSO.mjs';
10
10
  export { H as HTML_TAG_PATTERN, i as URL_DOMAIN_PATTERN, U as URL_PROTOCOL_PATTERN, c as constantTimeEqual, b as containsHtml, a as containsUrls, f as defangUrl, e as escapeHtml, g as getCorrelationId, d as sanitizeApiError, h as sanitizeForEmail, s as stripHtml } from './security-BvLXaQkv.mjs';
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@ export { aH as AIConfigSchema, aA as AIProviderSchema, a4 as BackoffOptions, aO
3
3
  import { a as ILogger, I as ICache, c as IAI, A as AIConfig, d as AIChatRequest, e as AIChatResponse, f as AIStreamChunk, g as AIStreamCallback, h as AICompletionRequest, i as AICompletionResponse, j as AIEmbeddingRequest, k as AIEmbeddingResponse, l as AIModelConfig, m as AIModelType, n as AIProvider } from './IAI-D8wA_i8N.js';
4
4
  export { z as AIChatChoice, G as AIError, F as AIErrorCode, u as AIErrorMessages, B as AIFinishReason, w as AIMessage, v as AIRole, E as AIRouterConfig, y as AITool, x as AIToolCall, D as AIUsageInfo, C as ConsoleLogger, o as ICacheOptions, K as ISpan, b as ITracing, q as LogEntry, L as LogLevel, p as LogMeta, r as LoggerConfig, M as MemoryAI, H as MemoryTracing, N as NoopLogger, J as NoopTracing, R as RoutingStrategy, S as SpanContext, V as SpanEvent, Q as SpanKind, O as SpanOptions, P as SpanStatus, U as SpanStatusCode, T as TracingConfig, s as createAIError, t as isAIError } from './IAI-D8wA_i8N.js';
5
5
  export { w as IMigrationDatabase, I as IMigrator, q as Migration, r as MigrationRecord, t as MigrationResult, u as MigrationStatus, M as Migrator, v as MigratorConfig, S as SQL, o as createBetaInvitesTable, n as createBetaSettingsTable, p as createBetaTestersTable, f as createDomainVerificationsTable, c as createMigration, b as createSsoOidcConfigsTable, m as createSsoSessionsTable, k as createTenantInvitationsTable, j as createTenantMembersTable, l as createTenantUsageTable, i as createTenantsTable, h as createVerifiedDomainsTable, d as defineMigration, e as enterpriseMigrations, g as generateVersion, a as getEnterpriseMigrations, s as sqlMigration } from './index-DzQ0Js5Z.js';
6
- import { I as IAIUsage, A as AIUsageConfig, U as UsageRecord, a as UsageQuery, b as UsageQueryResult, Q as Quota, c as QuotaType, d as UsageCategory, e as QuotaStatus, B as Budget, f as BudgetStatus, g as UsageInterval, h as UsageSummary, i as UsageTrend, C as CostBreakdown, j as UsageInvoice, k as AlertType, l as UsageAlert } from './agents-CntmA45w.js';
7
- export { F as AgentBudget, p as AgentCumulativeUsage, r as AgentIterationCallback, q as AgentIterationEvent, t as AgentLoopOptions, u as AgentLoopResult, s as AgentStopReason, n as AgentTool, o as AgentToolResult, x as AgentTracer, w as AgentTracerOptions, E as AgentUsageRecordParams, G as AgentUsageTracker, z as AgentUsageTrackerOptions, D as DEFAULT_AGENT_LOOP_OPTIONS, M as MemoryAIUsage, T as ToolExecutor, J as TracedAIOptions, m as UsageInvoiceItem, y as createAgentTracer, H as createAgentUsageTracker, K as createTracedAI, v as runAgentLoop } from './agents-CntmA45w.js';
6
+ import { I as IAIUsage, A as AIUsageConfig, U as UsageRecord, a as UsageQuery, b as UsageQueryResult, Q as Quota, c as QuotaType, d as UsageCategory, e as QuotaStatus, B as Budget, f as BudgetStatus, g as UsageInterval, h as UsageSummary, i as UsageTrend, C as CostBreakdown, j as UsageInvoice, k as AlertType, l as UsageAlert } from './agents-Cc65YUoW.js';
7
+ export { G as AgentBudget, q as AgentCumulativeUsage, s as AgentIterationCallback, r as AgentIterationEvent, u as AgentLoopOptions, v as AgentLoopResult, t as AgentStopReason, o as AgentTool, p as AgentToolResult, y as AgentTracer, x as AgentTracerOptions, F as AgentUsageRecordParams, H as AgentUsageTracker, E as AgentUsageTrackerOptions, D as DEFAULT_AGENT_LOOP_OPTIONS, M as MemoryAIUsage, O as OllamaAdapter, n as OllamaAdapterConfig, T as ToolExecutor, K as TracedAIOptions, m as UsageInvoiceItem, z as createAgentTracer, J as createAgentUsageTracker, L as createTracedAI, w as runAgentLoop } from './agents-Cc65YUoW.js';
8
8
  import { aS as IBeta, aT as BetaConfig, aU as BetaSettings, aV as UpdateBetaSettingsOptions, aW as CreateBetaCodesOptions, aX as BetaInviteCode, aY as ListBetaCodesOptions, aZ as BetaValidationResult, a_ as BetaConsumeResult, a$ as BetaTester, b0 as BetaStats, b1 as BetaCodeUsageReport } from './env-BJWliXSO.js';
9
9
  export { al as AllowlistConfig, A as ApiError, d as ApiErrorCode, f as ApiErrorCodeType, h as ApiPaginatedResponse, Q as ApiSecurityConfig, V as ApiSecurityContext, g as ApiSuccessResponse, aD as AuditRequest, H as AuthCookiesConfig, N as AuthMethod, aL as BetaClientConfig, b6 as BetaCodeStatus, C as CommonApiErrors, ar as CommonRateLimits, ac as DateRangeInput, a6 as DateRangeSchema, ag as DeploymentStage, aa as EmailInput, $ as EmailSchema, E as EnvValidationConfig, p as EnvValidationResult, ai as FlagDefinition, aj as FlagDefinitions, ah as FlagValue, r as KEYCLOAK_DEFAULT_ROLES, F as KeycloakCallbacksConfig, K as KeycloakConfig, G as KeycloakJwtFields, q as KeycloakTokenSet, ae as LoginInput, a8 as LoginSchema, b2 as MemoryBeta, ay as OpsAuditActor, aA as OpsAuditEvent, aC as OpsAuditLoggerOptions, aB as OpsAuditRecord, az as OpsAuditResource, b7 as PG_ERROR_MAP, ab as PaginationInput, a5 as PaginationSchema, a0 as PasswordSchema, a3 as PersonNameSchema, a2 as PhoneSchema, aq as RateLimitCheckResult, b as RateLimitOptions, P as RateLimitPreset, a as RateLimitRule, R as RateLimitStore, J as RedirectCallbackConfig, ak as ResolvedFlags, O as RouteAuditConfig, ad as SearchQueryInput, a7 as SearchQuerySchema, U as SecuritySession, af as SignupInput, a9 as SignupSchema, a1 as SlugSchema, aF as StandardAuditActionType, aE as StandardAuditActions, S as StandardRateLimitPresets, T as TokenRefreshResult, _ as WrapperPresets, ao as buildAllowlist, I as buildAuthCookies, Z as buildErrorBody, M as buildKeycloakCallbacks, e as buildPagination, Y as buildRateLimitHeaders, aw as buildRateLimitResponseHeaders, L as buildRedirectCallback, y as buildTokenRefreshParams, n as checkEnvVars, at as checkRateLimit, c as classifyError, aR as clearStoredBetaCode, aJ as createAuditActor, aK as createAuditLogger, aM as createBetaClient, an as createFeatureFlags, as as createMemoryRateLimitStore, a4 as createSafeTextSchema, am as detectStage, aG as extractAuditIp, aI as extractAuditRequestId, aH as extractAuditUserAgent, X as extractClientIp, aN as fetchBetaSettings, b3 as generateBetaCode, b5 as generateBetaId, l as getBoolEnv, B as getEndSessionEndpoint, o as getEnvSummary, m as getIntEnv, k as getOptionalEnv, au as getRateLimitStatus, j as getRequiredEnv, aQ as getStoredBetaCode, z as getTokenEndpoint, w as hasAllRoles, u as hasAnyRole, t as hasRole, ap as isAllowlisted, i as isApiError, x as isTokenExpired, b4 as normalizeBetaCode, s as parseKeycloakRoles, D as refreshKeycloakToken, av as resetRateLimitForKey, ax as resolveIdentifier, W as resolveRateLimitIdentifier, aP as storeBetaCode, aO as validateBetaCode, v as validateEnvVars } from './env-BJWliXSO.js';
10
10
  export { H as HTML_TAG_PATTERN, i as URL_DOMAIN_PATTERN, U as URL_PROTOCOL_PATTERN, c as constantTimeEqual, b as containsHtml, a as containsUrls, f as defangUrl, e as escapeHtml, g as getCorrelationId, d as sanitizeApiError, h as sanitizeForEmail, s as stripHtml } from './security-BvLXaQkv.js';
package/dist/index.js CHANGED
@@ -7224,6 +7224,7 @@ __export(src_exports, {
7224
7224
  NoopTracing: () => NoopTracing,
7225
7225
  NotificationTemplates: () => NotificationTemplates,
7226
7226
  ObservabilityConfigSchema: () => ObservabilityConfigSchema,
7227
+ OllamaAdapter: () => OllamaAdapter,
7227
7228
  OpenAIAdapter: () => OpenAIAdapter,
7228
7229
  PG_ERROR_MAP: () => PG_ERROR_MAP,
7229
7230
  PaginationSchema: () => PaginationSchema,
@@ -30439,6 +30440,304 @@ init_AnthropicAdapter();
30439
30440
  // src/adapters/google/index.ts
30440
30441
  init_GoogleAIAdapter();
30441
30442
 
30443
+ // src/adapters/ollama/OllamaAdapter.ts
30444
+ init_IAI();
30445
+ var OllamaAdapter = class {
30446
+ baseUrl;
30447
+ defaultModel;
30448
+ defaultEmbeddingModel;
30449
+ timeoutMs;
30450
+ constructor(config) {
30451
+ this.baseUrl = (config?.baseUrl ?? "http://localhost:11434").replace(
30452
+ /\/$/,
30453
+ ""
30454
+ );
30455
+ this.defaultModel = config?.defaultModel ?? "qwen2.5:3b";
30456
+ this.defaultEmbeddingModel = config?.defaultEmbeddingModel ?? "nomic-embed-text";
30457
+ this.timeoutMs = config?.timeoutMs ?? 12e4;
30458
+ }
30459
+ async chat(request) {
30460
+ const model = request.model ?? this.defaultModel;
30461
+ const ollamaReq = {
30462
+ model,
30463
+ messages: request.messages.map((m) => ({
30464
+ role: m.role === "tool" ? "assistant" : m.role,
30465
+ content: m.content
30466
+ })),
30467
+ stream: false,
30468
+ options: {
30469
+ temperature: request.temperature,
30470
+ num_predict: request.maxTokens,
30471
+ top_p: request.topP,
30472
+ stop: request.stop ? Array.isArray(request.stop) ? request.stop : [request.stop] : void 0
30473
+ }
30474
+ };
30475
+ const response = await this.fetch(
30476
+ "/api/chat",
30477
+ ollamaReq
30478
+ );
30479
+ const usage = {
30480
+ promptTokens: response.prompt_eval_count ?? 0,
30481
+ completionTokens: response.eval_count ?? 0,
30482
+ totalTokens: (response.prompt_eval_count ?? 0) + (response.eval_count ?? 0),
30483
+ estimatedCostUsd: 0
30484
+ // Local — zero cost
30485
+ };
30486
+ return {
30487
+ id: `ollama-${Date.now()}`,
30488
+ model: response.model ?? model,
30489
+ provider: "custom",
30490
+ choices: [
30491
+ {
30492
+ index: 0,
30493
+ message: {
30494
+ role: "assistant",
30495
+ content: response.message.content
30496
+ },
30497
+ finishReason: "stop"
30498
+ }
30499
+ ],
30500
+ usage,
30501
+ created: /* @__PURE__ */ new Date(),
30502
+ finishReason: "stop"
30503
+ };
30504
+ }
30505
+ async *chatStream(request) {
30506
+ const model = request.model ?? this.defaultModel;
30507
+ const ollamaReq = {
30508
+ model,
30509
+ messages: request.messages.map((m) => ({
30510
+ role: m.role === "tool" ? "assistant" : m.role,
30511
+ content: m.content
30512
+ })),
30513
+ stream: true,
30514
+ options: {
30515
+ temperature: request.temperature,
30516
+ num_predict: request.maxTokens,
30517
+ top_p: request.topP
30518
+ }
30519
+ };
30520
+ const controller = new AbortController();
30521
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
30522
+ try {
30523
+ const res = await fetch(`${this.baseUrl}/api/chat`, {
30524
+ method: "POST",
30525
+ headers: { "Content-Type": "application/json" },
30526
+ body: JSON.stringify(ollamaReq),
30527
+ signal: controller.signal
30528
+ });
30529
+ if (!res.ok) {
30530
+ throw createAIError("server_error", `Ollama error: ${res.status}`);
30531
+ }
30532
+ const reader = res.body?.getReader();
30533
+ if (!reader) return;
30534
+ const decoder = new TextDecoder();
30535
+ let buffer = "";
30536
+ while (true) {
30537
+ const { done, value } = await reader.read();
30538
+ if (done) break;
30539
+ buffer += decoder.decode(value, { stream: true });
30540
+ const lines = buffer.split("\n");
30541
+ buffer = lines.pop() ?? "";
30542
+ for (const line of lines) {
30543
+ if (!line.trim()) continue;
30544
+ const chunk = JSON.parse(line);
30545
+ yield {
30546
+ id: `ollama-stream-${Date.now()}`,
30547
+ model,
30548
+ provider: "custom",
30549
+ delta: {
30550
+ content: chunk.message?.content ?? ""
30551
+ },
30552
+ finishReason: chunk.done ? "stop" : void 0
30553
+ };
30554
+ }
30555
+ }
30556
+ } finally {
30557
+ clearTimeout(timer);
30558
+ }
30559
+ }
30560
+ async chatWithCallback(request, callback) {
30561
+ let fullContent = "";
30562
+ for await (const chunk of this.chatStream(request)) {
30563
+ await callback(chunk);
30564
+ if (chunk.delta.content) {
30565
+ fullContent += chunk.delta.content;
30566
+ }
30567
+ }
30568
+ const model = request.model ?? this.defaultModel;
30569
+ return {
30570
+ id: `ollama-${Date.now()}`,
30571
+ model,
30572
+ provider: "custom",
30573
+ choices: [
30574
+ {
30575
+ index: 0,
30576
+ message: { role: "assistant", content: fullContent },
30577
+ finishReason: "stop"
30578
+ }
30579
+ ],
30580
+ usage: {
30581
+ promptTokens: 0,
30582
+ completionTokens: 0,
30583
+ totalTokens: 0,
30584
+ estimatedCostUsd: 0
30585
+ },
30586
+ created: /* @__PURE__ */ new Date(),
30587
+ finishReason: "stop"
30588
+ };
30589
+ }
30590
+ async complete(request) {
30591
+ const response = await this.chat({
30592
+ messages: [{ role: "user", content: request.prompt }],
30593
+ model: request.model,
30594
+ temperature: request.temperature,
30595
+ maxTokens: request.maxTokens
30596
+ });
30597
+ return {
30598
+ id: response.id,
30599
+ model: response.model,
30600
+ provider: "custom",
30601
+ text: response.choices[0]?.message.content ?? "",
30602
+ usage: response.usage,
30603
+ created: response.created,
30604
+ finishReason: response.finishReason
30605
+ };
30606
+ }
30607
+ async *completeStream(request) {
30608
+ yield* this.chatStream({
30609
+ messages: [{ role: "user", content: request.prompt }],
30610
+ model: request.model,
30611
+ temperature: request.temperature,
30612
+ maxTokens: request.maxTokens
30613
+ });
30614
+ }
30615
+ async embed(request) {
30616
+ const model = request.model ?? this.defaultEmbeddingModel;
30617
+ const response = await this.fetch("/api/embed", {
30618
+ model,
30619
+ input: request.input
30620
+ });
30621
+ return {
30622
+ id: `ollama-emb-${Date.now()}`,
30623
+ model,
30624
+ provider: "custom",
30625
+ embeddings: response.embeddings,
30626
+ usage: {
30627
+ promptTokens: 0,
30628
+ completionTokens: 0,
30629
+ totalTokens: 0,
30630
+ estimatedCostUsd: 0
30631
+ },
30632
+ created: /* @__PURE__ */ new Date()
30633
+ };
30634
+ }
30635
+ async similarity(text1, text2, model) {
30636
+ const response = await this.embed({ input: [text1, text2], model });
30637
+ const [a, b] = response.embeddings;
30638
+ if (!a || !b) return 0;
30639
+ let dot = 0, normA = 0, normB = 0;
30640
+ for (let i = 0; i < a.length; i++) {
30641
+ dot += a[i] * b[i];
30642
+ normA += a[i] * a[i];
30643
+ normB += b[i] * b[i];
30644
+ }
30645
+ return dot / (Math.sqrt(normA) * Math.sqrt(normB));
30646
+ }
30647
+ async listModels() {
30648
+ try {
30649
+ const response = await this.fetch(
30650
+ "/api/tags",
30651
+ null,
30652
+ "GET"
30653
+ );
30654
+ return response.models.map((m) => ({
30655
+ modelId: m.name,
30656
+ provider: "custom",
30657
+ capabilities: ["chat", "completion"],
30658
+ maxContextTokens: 4096,
30659
+ maxOutputTokens: 2048,
30660
+ inputCostPer1K: 0,
30661
+ outputCostPer1K: 0,
30662
+ supportsStreaming: true,
30663
+ supportsTools: false,
30664
+ supportsVision: false
30665
+ }));
30666
+ } catch {
30667
+ return [];
30668
+ }
30669
+ }
30670
+ async getModel(modelId) {
30671
+ const models = await this.listModels();
30672
+ return models.find((m) => m.modelId === modelId) ?? null;
30673
+ }
30674
+ async supportsCapability(modelId, capability) {
30675
+ const model = await this.getModel(modelId);
30676
+ return model?.capabilities.includes(capability) ?? false;
30677
+ }
30678
+ async estimateTokens(text, _model) {
30679
+ return Math.ceil(text.length / 4);
30680
+ }
30681
+ async estimateCost() {
30682
+ return 0;
30683
+ }
30684
+ async healthCheck() {
30685
+ try {
30686
+ const start = Date.now();
30687
+ await this.fetch("/api/tags", null, "GET");
30688
+ const latency = Date.now() - start;
30689
+ return {
30690
+ healthy: true,
30691
+ providers: {
30692
+ custom: { available: true, latencyMs: latency },
30693
+ openai: { available: false, error: "Not configured" },
30694
+ anthropic: { available: false, error: "Not configured" },
30695
+ google: { available: false, error: "Not configured" },
30696
+ azure: { available: false, error: "Not configured" },
30697
+ bedrock: { available: false, error: "Not configured" }
30698
+ }
30699
+ };
30700
+ } catch (err) {
30701
+ return {
30702
+ healthy: false,
30703
+ providers: {
30704
+ custom: {
30705
+ available: false,
30706
+ error: err instanceof Error ? err.message : "Ollama unavailable"
30707
+ },
30708
+ openai: { available: false, error: "Not configured" },
30709
+ anthropic: { available: false, error: "Not configured" },
30710
+ google: { available: false, error: "Not configured" },
30711
+ azure: { available: false, error: "Not configured" },
30712
+ bedrock: { available: false, error: "Not configured" }
30713
+ }
30714
+ };
30715
+ }
30716
+ }
30717
+ async fetch(path, body, method = "POST") {
30718
+ const controller = new AbortController();
30719
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
30720
+ try {
30721
+ const res = await fetch(`${this.baseUrl}${path}`, {
30722
+ method,
30723
+ headers: body ? { "Content-Type": "application/json" } : void 0,
30724
+ body: body ? JSON.stringify(body) : void 0,
30725
+ signal: controller.signal
30726
+ });
30727
+ if (!res.ok) {
30728
+ const text = await res.text().catch(() => "");
30729
+ throw createAIError(
30730
+ "server_error",
30731
+ `Ollama ${method} ${path}: ${res.status} ${text}`
30732
+ );
30733
+ }
30734
+ return await res.json();
30735
+ } finally {
30736
+ clearTimeout(timer);
30737
+ }
30738
+ }
30739
+ };
30740
+
30442
30741
  // src/adapters/pinecone/index.ts
30443
30742
  init_PineconeRAG();
30444
30743
 
@@ -33422,6 +33721,7 @@ function getEnterpriseMigrations(features) {
33422
33721
  NoopTracing,
33423
33722
  NotificationTemplates,
33424
33723
  ObservabilityConfigSchema,
33724
+ OllamaAdapter,
33425
33725
  OpenAIAdapter,
33426
33726
  PG_ERROR_MAP,
33427
33727
  PaginationSchema,