Skip to content

Commit f431650

Browse files
authored
Merge pull request #1012 from objectstack-ai/copilot/add-llm-adapter-interface-to-spec
2 parents 8202582 + 2c7ad7d commit f431650

12 files changed

Lines changed: 221 additions & 58 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- **Promoted `LLMAdapter` interface to `@objectstack/spec/contracts`** — Moved the `LLMAdapter`
12+
adapter contract from `@objectstack/service-ai` internal types to the canonical protocol layer
13+
(`packages/spec/src/contracts/llm-adapter.ts`). Third-party adapter implementations (OpenAI,
14+
Anthropic, Ollama, etc.) can now depend solely on `@objectstack/spec` for type alignment.
15+
`service-ai` re-exports the interface for backward compatibility.
16+
1017
### Fixed
1118
- **ObjectQL build failure** — Fixed TypeScript TS2345 errors in `packages/objectql/src/protocol.ts`
1219
where `SchemaRegistry.registerItem()` calls failed type checking for the `keyField` parameter.

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ Final polish and advanced features.
879879
| 15 | Feed Service | `IFeedService` || `@objectstack/service-feed` | In-memory feed/chatter (comments, reactions, subscriptions) |
880880
| 16 | Search Service | `ISearchService` || `@objectstack/service-search` (planned) | Spec only |
881881
| 17 | Notification Service | `INotificationService` || `@objectstack/service-notification` (planned) | Spec only |
882-
| 18 | AI Service | `IAIService` || `@objectstack/service-ai` | LLM adapter layer, ToolRegistry, conversation management, REST/SSE routes (52 tests) |
882+
| 18 | AI Service | `IAIService` || `@objectstack/service-ai` | LLM adapter layer (`LLMAdapter` contract in spec), ToolRegistry, conversation management, REST/SSE routes (52 tests) |
883883
| 19 | Automation Service | `IAutomationService` || `@objectstack/service-automation` | DAG engine + HTTP API CRUD + Client SDK + typed returns (67 tests) |
884884
| 20 | Workflow Service | `IWorkflowService` || `@objectstack/service-workflow` (planned) | Spec only |
885885
| 21 | GraphQL Service | `IGraphQLService` || `@objectstack/service-graphql` (planned) | Spec only |

packages/services/service-ai/src/__tests__/ai-service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ToolRegistry } from '../tools/tool-registry.js';
88
import { InMemoryConversationService } from '../conversation/in-memory-conversation-service.js';
99
import { buildAIRoutes } from '../routes/ai-routes.js';
1010
import { AIServicePlugin } from '../plugin.js';
11-
import type { LLMAdapter } from '../adapters/types.js';
11+
import type { LLMAdapter } from '@objectstack/spec/contracts';
1212

1313
// Suppress logger output in tests
1414
const silentLogger = {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

3-
export type { LLMAdapter } from './types.js';
3+
export type { LLMAdapter } from '@objectstack/spec/contracts';
44
export { MemoryLLMAdapter } from './memory-adapter.js';

packages/services/service-ai/src/adapters/memory-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
AIResult,
77
AIStreamEvent,
88
} from '@objectstack/spec/contracts';
9-
import type { LLMAdapter } from './types.js';
9+
import type { LLMAdapter } from '@objectstack/spec/contracts';
1010

1111
/**
1212
* MemoryLLMAdapter — deterministic in-memory adapter for testing & development.
Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,3 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

3-
import type {
4-
AIMessage,
5-
AIRequestOptions,
6-
AIResult,
7-
AIStreamEvent,
8-
} from '@objectstack/spec/contracts';
9-
10-
/**
11-
* LLM Provider Adapter Interface
12-
*
13-
* Adapters translate between the ObjectStack AI protocol and concrete
14-
* LLM provider SDKs (OpenAI, Anthropic, Ollama, etc.).
15-
*
16-
* Each adapter is a thin wrapper — all orchestration, conversation
17-
* management, and tool execution logic lives in the AI service layer.
18-
*/
19-
export interface LLMAdapter {
20-
/** Unique adapter identifier (e.g. 'openai', 'anthropic', 'memory') */
21-
readonly name: string;
22-
23-
/**
24-
* Generate a chat completion.
25-
* @param messages - Conversation messages
26-
* @param options - Request configuration (includes tool definitions)
27-
*/
28-
chat(messages: AIMessage[], options?: AIRequestOptions): Promise<AIResult>;
29-
30-
/**
31-
* Generate a text completion from a single prompt.
32-
* @param prompt - Input prompt string
33-
* @param options - Request configuration
34-
*/
35-
complete(prompt: string, options?: AIRequestOptions): Promise<AIResult>;
36-
37-
/**
38-
* Stream a chat completion as an async iterable of events.
39-
* Implementations that do not support streaming may omit this method.
40-
*/
41-
streamChat?(messages: AIMessage[], options?: AIRequestOptions): AsyncIterable<AIStreamEvent>;
42-
43-
/**
44-
* Generate embedding vectors.
45-
*/
46-
embed?(input: string | string[], model?: string): Promise<number[][]>;
47-
48-
/**
49-
* List models available through this adapter.
50-
*/
51-
listModels?(): Promise<string[]>;
52-
}
3+
export type { LLMAdapter } from '@objectstack/spec/contracts';

packages/services/service-ai/src/ai-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import type {
77
AIStreamEvent,
88
IAIService,
99
IAIConversationService,
10+
LLMAdapter,
1011
} from '@objectstack/spec/contracts';
1112
import type { Logger } from '@objectstack/spec/contracts';
1213
import { createLogger } from '@objectstack/core';
13-
import type { LLMAdapter } from './adapters/types.js';
1414
import { MemoryLLMAdapter } from './adapters/memory-adapter.js';
1515
import { ToolRegistry } from './tools/tool-registry.js';
1616
import { InMemoryConversationService } from './conversation/in-memory-conversation-service.js';

packages/services/service-ai/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type { AIServicePluginOptions } from './plugin.js';
1010

1111
// Adapters
1212
export { MemoryLLMAdapter } from './adapters/memory-adapter.js';
13-
export type { LLMAdapter } from './adapters/types.js';
13+
export type { LLMAdapter } from '@objectstack/spec/contracts';
1414

1515
// Conversation
1616
export { InMemoryConversationService } from './conversation/in-memory-conversation-service.js';

packages/services/service-ai/src/plugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import type { Plugin, PluginContext } from '@objectstack/core';
4-
import type { IAIService } from '@objectstack/spec/contracts';
4+
import type { IAIService, LLMAdapter } from '@objectstack/spec/contracts';
55
import { AIService } from './ai-service.js';
66
import type { AIServiceConfig } from './ai-service.js';
7-
import type { LLMAdapter } from './adapters/types.js';
87
import { buildAIRoutes } from './routes/ai-routes.js';
98

109
/**

packages/spec/src/contracts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export * from './analytics-service.js';
2929
export * from './realtime-service.js';
3030
export * from './job-service.js';
3131
export * from './ai-service.js';
32+
export * from './llm-adapter.js';
3233
export * from './i18n-service.js';
3334
export * from './ui-service.js';
3435
export * from './workflow-service.js';

0 commit comments

Comments
 (0)