@axsdk/core 0.1.1

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/sse.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ export declare const SSEConnectionStatus: {
2
+ DISCONNECTED: string;
3
+ CONNECTING: string;
4
+ CONNECTED: string;
5
+ RECONNECTING: string;
6
+ ERROR: string;
7
+ };
8
+ export interface SSEConfig {
9
+ appId?: string;
10
+ apiKey?: string;
11
+ appUserId?: string;
12
+ sessionId?: string;
13
+ initialRetryDelay?: number;
14
+ maxRetryDelay?: number;
15
+ retryBackoffMultiplier?: number;
16
+ enableLogging?: boolean;
17
+ headers?: Record<string, string>;
18
+ }
19
+ export interface SSEEventData {
20
+ [key: string]: unknown;
21
+ }
22
+ export type SSEEventCallback = (data: SSEEventData) => void;
23
+ export declare class SSE {
24
+ private config;
25
+ private connection;
26
+ private status;
27
+ private retryDelay;
28
+ private retryTimer;
29
+ private shouldReconnect;
30
+ private messageCount;
31
+ constructor(config?: SSEConfig);
32
+ start(): void;
33
+ stop(): Promise<void>;
34
+ getStatus(): string;
35
+ isConnected(): boolean;
36
+ getMessageCount(): number;
37
+ private buildHeaders;
38
+ private closeConnection;
39
+ private connect;
40
+ private readStream;
41
+ private processBuffer;
42
+ private handleMessage;
43
+ private handleConnectionError;
44
+ private scheduleReconnect;
45
+ private increaseRetryDelay;
46
+ private resetRetryDelay;
47
+ private updateStatus;
48
+ }
49
+ export declare function getSSEService(config: SSEConfig): SSE | undefined;
@@ -0,0 +1,54 @@
1
+ import { type StoreApi } from 'zustand/vanilla';
2
+ import type { ChatSession, ChatMessage, AXSDKTranslationsSchema } from "./types/index";
3
+ export interface AppState {
4
+ isLoading: boolean;
5
+ apiKey: string | undefined;
6
+ appId: string | undefined;
7
+ appUserId: string | undefined;
8
+ appAuthToken: string | undefined;
9
+ language: string;
10
+ setApiKey: (apiKey: string | undefined) => void;
11
+ setAppId: (appId: string | undefined) => void;
12
+ getAppUserId: () => string;
13
+ resetAppUserId: () => void;
14
+ setLanguage: (language: string) => void;
15
+ setAppAuthToken: (token: string | undefined) => void;
16
+ }
17
+ export declare const appStore: Omit<StoreApi<AppState>, "setState" | "persist"> & {
18
+ setState(partial: AppState | Partial<AppState> | ((state: AppState) => AppState | Partial<AppState>), replace?: false | undefined): unknown;
19
+ setState(state: AppState | ((state: AppState) => AppState), replace: true): unknown;
20
+ persist: {
21
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<AppState, unknown, unknown>>) => void;
22
+ clearStorage: () => void;
23
+ rehydrate: () => Promise<void> | void;
24
+ hasHydrated: () => boolean;
25
+ onHydrate: (fn: (state: AppState) => void) => () => void;
26
+ onFinishHydration: (fn: (state: AppState) => void) => () => void;
27
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<AppState, unknown, unknown>>;
28
+ };
29
+ };
30
+ export interface ChatState {
31
+ isLoading: boolean;
32
+ isOpen: boolean;
33
+ session: ChatSession | null;
34
+ setSession: (session: ChatSession | null) => void;
35
+ messages: ChatMessage[];
36
+ setMessages: (messages: ChatMessage[]) => void;
37
+ updateMessage: (message: ChatMessage) => void;
38
+ setIsOpen: (isOpen: boolean) => void;
39
+ translations: Record<string, AXSDKTranslationsSchema>;
40
+ setTranslations: (translations: Record<string, AXSDKTranslationsSchema>) => void;
41
+ }
42
+ export declare const chatStore: Omit<StoreApi<ChatState>, "setState" | "persist"> & {
43
+ setState(partial: ChatState | Partial<ChatState> | ((state: ChatState) => ChatState | Partial<ChatState>), replace?: false | undefined): unknown;
44
+ setState(state: ChatState | ((state: ChatState) => ChatState), replace: true): unknown;
45
+ persist: {
46
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ChatState, unknown, unknown>>) => void;
47
+ clearStorage: () => void;
48
+ rehydrate: () => Promise<void> | void;
49
+ hasHydrated: () => boolean;
50
+ onHydrate: (fn: (state: ChatState) => void) => () => void;
51
+ onFinishHydration: (fn: (state: ChatState) => void) => () => void;
52
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<ChatState, unknown, unknown>>;
53
+ };
54
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import z from "zod";
2
+ export type AXHandler = (command: string, args: Record<string, unknown>) => Promise<unknown>;
3
+ export declare const AXSDKTranslationsSchema: z.ZodRecord<z.ZodString, z.ZodString>;
4
+ export type AXSDKTranslationsSchema = z.infer<typeof AXSDKTranslationsSchema>;
5
+ export declare const AXSDKConfigSchema: z.ZodObject<{
6
+ apiKey: z.ZodString;
7
+ appId: z.ZodString;
8
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
9
+ axHandler: z.ZodCustom<AXHandler, AXHandler>;
10
+ language: z.ZodOptional<z.ZodString>;
11
+ debug: z.ZodOptional<z.ZodBoolean>;
12
+ translations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>>>;
13
+ }, z.core.$strip>;
14
+ export type AXSDKConfig = z.infer<typeof AXSDKConfigSchema>;
@@ -0,0 +1,122 @@
1
+ export interface MessageTime {
2
+ created: number;
3
+ updated?: number;
4
+ completed?: number;
5
+ }
6
+ export interface ChatSession {
7
+ id: string;
8
+ status: string;
9
+ title: string;
10
+ time: MessageTime;
11
+ }
12
+ export interface MessageModel {
13
+ providerID: string;
14
+ modelID: string;
15
+ }
16
+ export interface TokenInfo {
17
+ total: number;
18
+ input: number;
19
+ output: number;
20
+ reasoning: number;
21
+ cache: {
22
+ read: number;
23
+ write: number;
24
+ };
25
+ }
26
+ export interface OpenRouterReasoningDetail {
27
+ type: string;
28
+ text: string;
29
+ format: string;
30
+ index: number;
31
+ }
32
+ export interface OpenRouterMetadata {
33
+ reasoning_details: OpenRouterReasoningDetail[];
34
+ }
35
+ export interface BasePart {
36
+ type: string;
37
+ id: string;
38
+ sessionID: string;
39
+ messageID: string;
40
+ }
41
+ export interface TextPart extends BasePart {
42
+ type: "text" | "reasoning";
43
+ text?: string;
44
+ time: {
45
+ start: number;
46
+ end: number;
47
+ };
48
+ }
49
+ export interface ReasoningPart extends TextPart {
50
+ type: "reasoning";
51
+ text?: string;
52
+ metadata?: {
53
+ openrouter: OpenRouterMetadata;
54
+ };
55
+ }
56
+ export interface StepStartPart extends BasePart {
57
+ type: "step-start";
58
+ snapshot?: string;
59
+ text?: string;
60
+ }
61
+ export interface StepFinishPart extends BasePart {
62
+ type: "step-finish";
63
+ text?: string;
64
+ reason?: string;
65
+ snapshot?: string;
66
+ cost?: number;
67
+ tokens?: TokenInfo;
68
+ }
69
+ export interface ToolPartState {
70
+ status: string;
71
+ input?: Record<string, unknown>;
72
+ output?: string;
73
+ title?: string;
74
+ metadata?: Record<string, unknown>;
75
+ time?: {
76
+ start: number;
77
+ end: number;
78
+ };
79
+ }
80
+ export interface ToolPart extends BasePart {
81
+ type: "tool";
82
+ callID: string;
83
+ tool: string;
84
+ state: ToolPartState;
85
+ metadata?: Record<string, unknown>;
86
+ }
87
+ export type MessagePart = TextPart | ReasoningPart | StepStartPart | StepFinishPart | ToolPart;
88
+ export interface UserMessageInfo {
89
+ role: "user";
90
+ time: MessageTime;
91
+ agent: string;
92
+ model: MessageModel;
93
+ id: string;
94
+ sessionID: string;
95
+ finish?: string;
96
+ }
97
+ export interface AssistantMessageInfo {
98
+ role: "assistant";
99
+ time: MessageTime;
100
+ agent: string;
101
+ parentID?: string;
102
+ modelID?: string;
103
+ providerID?: string;
104
+ mode?: string;
105
+ cost?: number;
106
+ tokens?: TokenInfo;
107
+ finish?: string;
108
+ id: string;
109
+ sessionID: string;
110
+ }
111
+ export type MessageInfo = UserMessageInfo | AssistantMessageInfo;
112
+ export interface ChatMessagePayload {
113
+ info: MessageInfo;
114
+ parts: MessagePart[];
115
+ }
116
+ export interface ChatMessage {
117
+ info: MessageInfo;
118
+ parts?: MessagePart[];
119
+ role?: string;
120
+ timestamp?: Date | string | number;
121
+ finish?: string;
122
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./axsdk";
2
+ export * from "./chat";
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@axsdk/core",
3
+ "version": "0.1.1",
4
+ "private": false,
5
+ "description": "axsdk core",
6
+ "keywords": [],
7
+ "homepage": "https://github.com/layorix/axsdk-sdk-js",
8
+ "bugs": {
9
+ "url": "https://github.com/layorix/axsdk-sdk-js/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/layorix/axsdk-sdk-js.git"
14
+ },
15
+ "license": "MIT",
16
+ "author": "layorixinc@gmail.com",
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/lib.d.ts",
21
+ "import": "./dist/lib.js",
22
+ "require": "./dist/lib.cjs",
23
+ "source": "./src/lib.ts"
24
+ }
25
+ },
26
+ "main": "./dist/lib.js",
27
+ "types": "./dist/lib.d.ts",
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "scripts": {
32
+ "dev": "bun ./src/index.ts",
33
+ "build": "bun ./build.ts && bun build:types",
34
+ "build:types": "bunx tsc --emitDeclarationOnly"
35
+ },
36
+ "dependencies": {
37
+ "eventemitter3": "^5.0.4",
38
+ "html2canvas": "^1.4.1",
39
+ "nanoid": "^5.1.6",
40
+ "zod": "^4.3.6",
41
+ "zustand": "^5.0.11"
42
+ },
43
+ "devDependencies": {
44
+ "@types/bun": "latest"
45
+ },
46
+ "peerDependencies": {
47
+ "typescript": "^5"
48
+ },
49
+ "module": "./dist/lib.js"
50
+ }