@prysm-ai/core 0.1.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/agent.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { AgentConfig, Turn, ChatMessage } from './agent.types.js';
2
+ import type { AgentHooks } from './hooks.js';
3
+ export declare class Agent {
4
+ private hooks;
5
+ constructor(_config: AgentConfig, hooks?: AgentHooks);
6
+ start(): Promise<void>;
7
+ end(): Promise<void>;
8
+ runTurn(turn: Turn): Promise<TurnResult>;
9
+ }
10
+ export interface TurnResult {
11
+ messages: ChatMessage[];
12
+ interrupted: boolean;
13
+ }
package/agent.js ADDED
@@ -0,0 +1,38 @@
1
+ export class Agent {
2
+ hooks;
3
+ constructor(_config, hooks) {
4
+ this.hooks = hooks ?? {};
5
+ }
6
+ async start() {
7
+ if (this.hooks.beforeAgentStart) {
8
+ await this.hooks.beforeAgentStart();
9
+ }
10
+ }
11
+ async end() {
12
+ if (this.hooks.afterAgentEnd) {
13
+ await this.hooks.afterAgentEnd();
14
+ }
15
+ }
16
+ async runTurn(turn) {
17
+ const { context } = turn;
18
+ // Before turn hook
19
+ if (this.hooks.beforeTurn) {
20
+ const shouldContinue = await this.hooks.beforeTurn(turn, context);
21
+ if (shouldContinue === false) {
22
+ this.hooks.beforeTurnSkip?.(turn, context, 'Hook returned false');
23
+ return { messages: [], interrupted: true };
24
+ }
25
+ }
26
+ try {
27
+ // Execute turn logic
28
+ // ... (will be implemented in later phases)
29
+ return { messages: [], interrupted: false };
30
+ }
31
+ catch (error) {
32
+ if (this.hooks.onTurnError) {
33
+ await this.hooks.onTurnError(turn, error, context);
34
+ }
35
+ throw error;
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,100 @@
1
+ import { z } from 'zod';
2
+ export declare const ChatMessageRoleSchema: z.ZodEnum<["system", "user", "assistant", "tool"]>;
3
+ export type ChatMessageRole = z.infer<typeof ChatMessageRoleSchema>;
4
+ export interface ChatMessage {
5
+ id: string;
6
+ role: ChatMessageRole;
7
+ content: string;
8
+ name?: string;
9
+ toolCallId?: string;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ export declare function createChatMessage(role: ChatMessageRole, content: string, options?: Partial<ChatMessage> & {
13
+ id?: string;
14
+ }): ChatMessage;
15
+ export interface ToolDefinition {
16
+ type: 'function';
17
+ function: {
18
+ name: string;
19
+ description: string;
20
+ parameters: {
21
+ type: 'object';
22
+ properties: Record<string, unknown>;
23
+ required?: string[];
24
+ additionalProperties?: boolean;
25
+ };
26
+ };
27
+ }
28
+ export interface ToolCall {
29
+ id: string;
30
+ name: string;
31
+ arguments: Record<string, unknown>;
32
+ }
33
+ export interface ToolResult {
34
+ success: boolean;
35
+ data?: unknown;
36
+ error?: string;
37
+ }
38
+ export interface Turn {
39
+ id: string;
40
+ messages: ChatMessage[];
41
+ context: TurnContext;
42
+ }
43
+ export interface TurnContext {
44
+ tenantId: string | null;
45
+ userId: string | null;
46
+ sessionId: string;
47
+ metadata: Record<string, unknown>;
48
+ isBatchMode: boolean;
49
+ batchConfig?: {
50
+ maxConcurrency: number;
51
+ onProgress?: (completed: number, total: number) => void;
52
+ };
53
+ }
54
+ export interface AgentConfig {
55
+ llm: LLMConfig;
56
+ tools: ToolDefinition[];
57
+ maxTurns?: number;
58
+ timeoutMs?: number;
59
+ }
60
+ export interface LLMConfig {
61
+ provider: 'openai' | 'anthropic' | 'local';
62
+ apiKey?: string;
63
+ model?: string;
64
+ temperature?: number;
65
+ maxTokens?: number;
66
+ baseUrl?: string;
67
+ }
68
+ export interface LLMRequestOptions {
69
+ temperature?: number;
70
+ maxTokens?: number;
71
+ stop?: string[];
72
+ stream?: boolean;
73
+ }
74
+ export interface LLMResponse {
75
+ content: string;
76
+ reasoning?: string;
77
+ finishReason?: string;
78
+ usage?: {
79
+ inputTokens: number;
80
+ outputTokens: number;
81
+ };
82
+ }
83
+ export type AgentEvent = {
84
+ type: 'turn_start';
85
+ turnId: string;
86
+ sessionId: string;
87
+ } | {
88
+ type: 'turn_end';
89
+ turnId: string;
90
+ sessionId: string;
91
+ } | {
92
+ type: 'tool_call_start';
93
+ toolCall: ToolCall;
94
+ turnId: string;
95
+ } | {
96
+ type: 'tool_call_end';
97
+ toolCall: ToolCall;
98
+ result: ToolResult;
99
+ turnId: string;
100
+ };
package/agent.types.js ADDED
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ // Chat Message
3
+ export const ChatMessageRoleSchema = z.enum(['system', 'user', 'assistant', 'tool']);
4
+ export function createChatMessage(role, content, options) {
5
+ const result = {
6
+ id: options?.id ?? crypto.randomUUID(),
7
+ role,
8
+ content,
9
+ };
10
+ if (options?.name !== undefined)
11
+ result.name = options.name;
12
+ if (options?.toolCallId !== undefined)
13
+ result.toolCallId = options.toolCallId;
14
+ if (options?.metadata !== undefined)
15
+ result.metadata = options.metadata;
16
+ return result;
17
+ }
package/errors.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export declare class AgentError extends Error {
2
+ code: string;
3
+ statusCode?: number | undefined;
4
+ context?: Record<string, unknown> | undefined;
5
+ constructor(message: string, code: string, statusCode?: number | undefined, context?: Record<string, unknown> | undefined);
6
+ }
7
+ export declare class LLMError extends AgentError {
8
+ constructor(message: string, context?: Record<string, unknown>);
9
+ }
10
+ export declare class ToolExecutionError extends AgentError {
11
+ toolName: string;
12
+ constructor(message: string, toolName: string, context?: Record<string, unknown>);
13
+ }
14
+ export declare class TurnTimeoutError extends AgentError {
15
+ constructor(sessionId: string, timeoutMs: number);
16
+ }
17
+ export declare class ValidationError extends AgentError {
18
+ errors?: unknown[] | undefined;
19
+ constructor(message: string, errors?: unknown[] | undefined);
20
+ }
package/errors.js ADDED
@@ -0,0 +1,40 @@
1
+ export class AgentError extends Error {
2
+ code;
3
+ statusCode;
4
+ context;
5
+ constructor(message, code, statusCode, context) {
6
+ super(message);
7
+ this.code = code;
8
+ this.statusCode = statusCode;
9
+ this.context = context;
10
+ this.name = 'AgentError';
11
+ }
12
+ }
13
+ export class LLMError extends AgentError {
14
+ constructor(message, context) {
15
+ super(message, 'LLM_ERROR', undefined, context);
16
+ this.name = 'LLMError';
17
+ }
18
+ }
19
+ export class ToolExecutionError extends AgentError {
20
+ toolName;
21
+ constructor(message, toolName, context) {
22
+ super(message, 'TOOL_EXECUTION_ERROR', undefined, context);
23
+ this.toolName = toolName;
24
+ this.name = 'ToolExecutionError';
25
+ }
26
+ }
27
+ export class TurnTimeoutError extends AgentError {
28
+ constructor(sessionId, timeoutMs) {
29
+ super(`Turn timeout after ${timeoutMs}ms`, 'TURN_TIMEOUT', undefined, { sessionId, timeoutMs });
30
+ this.name = 'TurnTimeoutError';
31
+ }
32
+ }
33
+ export class ValidationError extends AgentError {
34
+ errors;
35
+ constructor(message, errors) {
36
+ super(message, 'VALIDATION_ERROR', 400, { errors });
37
+ this.errors = errors;
38
+ this.name = 'ValidationError';
39
+ }
40
+ }
package/hooks.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import type { Turn, TurnContext, ToolCall, ToolResult, ChatMessage, LLMRequestOptions, LLMResponse, AgentEvent } from './agent.types.js';
2
+ import type { AgentError } from './errors.js';
3
+ export interface ToolExecutionContext {
4
+ tenantId: string | null;
5
+ sessionId: string;
6
+ turnId: string;
7
+ toolName: string;
8
+ }
9
+ export interface AgentHooks {
10
+ beforeAgentStart?(): Promise<void>;
11
+ afterAgentEnd?(): Promise<void>;
12
+ beforeTurn?(turn: Turn, context: TurnContext): Promise<void | boolean>;
13
+ beforeTurnSkip?(turn: Turn, context: TurnContext, reason: string): void;
14
+ afterTurn?(turn: Turn, context: TurnContext): Promise<void>;
15
+ onTurnError?(turn: Turn, error: AgentError, context: TurnContext): Promise<void>;
16
+ beforeToolCall?(toolCall: ToolCall, context: ToolExecutionContext): Promise<void | boolean>;
17
+ beforeToolCallSkip?(toolCall: ToolCall, context: ToolExecutionContext, reason: string): void;
18
+ afterToolCall?(toolCall: ToolCall, result: ToolResult, context: ToolExecutionContext): Promise<void>;
19
+ beforeLLMCall?(messages: ChatMessage[], options: LLMRequestOptions): Promise<void>;
20
+ afterLLMCall?(response: LLMResponse): Promise<void>;
21
+ onError?(error: AgentError, context: TurnContext): Promise<void>;
22
+ onEvent?(event: AgentEvent): Promise<void>;
23
+ }
package/hooks.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './agent.js';
2
+ export * from './agent.types.js';
3
+ export * from './errors.js';
4
+ export * from './hooks.js';
package/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './agent.js';
2
+ export * from './agent.types.js';
3
+ export * from './errors.js';
4
+ export * from './hooks.js';
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@prysm-ai/core",
3
+ "version": "0.1.0",
4
+ "description": "Agent core engine",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "build:watch": "tsc --watch",
17
+ "typecheck": "tsc --noEmit",
18
+ "clean": "rm -rf dist"
19
+ },
20
+ "dependencies": {
21
+ "zod": "^3.23.0"
22
+ },
23
+ "devDependencies": {
24
+ "typescript": "^5.4.0"
25
+ }
26
+ }