feat(rewrite): tambah application layer — port traits & use cases TypeScript
Paket @zesdex/application (apps/packages/application): - ports: ProviderService (chat/chatStream+abort), PasswordService, TokenService, AuthService - agent: AgentTurnServiceImpl (loop 50 iterasi, auto-compact 60k chars, adaptive max-tokens 800/1600/4096, temp 0.2/0.7, ErrorTracker, eksekusi tool read-only paralel terbatas mempertahankan urutan) + compact_messages_with_ai - auth: OAuthUseCase (PKCE S256 + CSRF state), SessionServiceImpl - cms: ConversationServiceImpl, MemoryServiceImpl, SettingsServiceImpl - 11 unit test Bun (PKCE, OAuth CSRF, turn_service helper) - tsconfig paths untuk workspace @zesdex/* Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
07e84e43b3
commit
03538a455a
16 files changed
+942
-1
No files matched your search
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Port traits (interfaces) to external services. Mirrors `apps/application/src/ports/`.
|
||||
* Concrete implementations live in the infrastructure layer.
|
||||
*/
|
||||
import type { ChatMessage, StreamEvent, ToolDef } from "@zesdex/domain";
|
||||
|
||||
/** Abstraction for an LLM provider chat-completion service. */
|
||||
export interface ProviderService {
|
||||
/**
|
||||
* Send a non-streaming chat completion request.
|
||||
* Returns the assistant's `ChatMessage` and optional `[prompt, completion]` token usage.
|
||||
*/
|
||||
chat(
|
||||
messages: ChatMessage[],
|
||||
tools?: ToolDef[],
|
||||
maxTokens?: number,
|
||||
temperature?: number,
|
||||
): Promise<{ message: ChatMessage; usage: [number, number] | null }>;
|
||||
|
||||
/**
|
||||
* Send a streaming request. `onEvent` is called per parsed SSE event and
|
||||
* returns `false` to abort. Returns the fully assembled assistant message
|
||||
* and optional usage once the stream completes.
|
||||
*/
|
||||
chatStream(
|
||||
messages: ChatMessage[],
|
||||
tools: ToolDef[],
|
||||
maxTokens: number,
|
||||
temperature: number,
|
||||
onEvent: (event: StreamEvent) => boolean,
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ message: ChatMessage; usage: [number, number] | null }>;
|
||||
}
|
||||
|
||||
/** Abstraction for password hashing and verification. */
|
||||
export interface PasswordService {
|
||||
hash(password: string): Promise<string>;
|
||||
verify(password: string, hash: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
/** Abstraction for JWT-based token generation and verification. */
|
||||
export interface TokenService {
|
||||
/** Generate an `[access, refresh]` token pair for the given subject. */
|
||||
generateTokens(sub: string): [string, string];
|
||||
verifyAccessToken(token: string): string;
|
||||
verifyRefreshToken(token: string): string;
|
||||
}
|
||||
|
||||
/** High-level authentication service combining password + token issuance. */
|
||||
export interface AuthService {
|
||||
authenticate(password: string, hash: string): Promise<boolean>;
|
||||
issueTokens(sub: string): [string, string];
|
||||
}
|
||||
Reference in new issue
Block a user