@axsdk/core 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -1 +1,156 @@
1
- # axsdk-core
1
+ # @axsdk/core
2
+
3
+ Framework-agnostic JavaScript/TypeScript SDK for the AXSDK AI chat platform. Manages sessions, real-time SSE streaming, and chat state — no UI dependencies required.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # npm
9
+ npm install @axsdk/core
10
+
11
+ # bun
12
+ bun add @axsdk/core
13
+ ```
14
+
15
+ > **Peer dependency:** TypeScript ≥ 5
16
+
17
+ ## Quick Start
18
+
19
+ ```ts
20
+ import { AXSDK } from "@axsdk/core";
21
+
22
+ await AXSDK.init({
23
+ apiKey: "ak-YOUR_API_KEY",
24
+ appId: "your-app-id",
25
+
26
+ // Called by the AI when it wants your app to perform an action
27
+ axHandler: async (command, args) => {
28
+ console.log(command, args);
29
+ return { status: "OK" };
30
+ },
31
+ });
32
+
33
+ // Send a message programmatically
34
+ AXSDK.sendMessage("Hello!");
35
+
36
+ // Listen for chat events
37
+ AXSDK.eventBus().on("message.chat", (event) => {
38
+ console.log(event, AXSDK.getChatState());
39
+ });
40
+ ```
41
+
42
+ ## Configuration
43
+
44
+ `AXSDK.init(config: AXSDKConfig)` accepts:
45
+
46
+ | Field | Type | Required | Description |
47
+ |---|---|---|---|
48
+ | `apiKey` | `string` | ✅ | Your AXSDK API key |
49
+ | `appId` | `string` | ✅ | Your application identifier |
50
+ | `axHandler` | `(command, args) => Promise<unknown>` | ✅ | Callback invoked when the AI issues an action command to your app |
51
+ | `headers` | `Record<string, string>` | — | Extra HTTP headers added to every API request (e.g. `origin`) |
52
+ | `language` | `string` | — | Override UI language (defaults to `navigator.language`) |
53
+ | `debug` | `boolean` | — | Enable debug output (reasoning traces, token counts) |
54
+ | `translations` | `Record<string, Record<string, string>>` | — | Per-language UI string overrides (see below) |
55
+
56
+ ### Translation keys
57
+
58
+ | Key | Description |
59
+ |---|---|
60
+ | `chatAskMe` | Prompt shown in the closed-state speech bubble |
61
+ | `chatHide` | Prompt shown in the open-state speech bubble |
62
+ | `chatEmpty` | Placeholder shown when the chat history is empty |
63
+ | `chatIdleGuide` | Status text shown when the AI session is idle |
64
+ | `chatBusyGuide` | Status text shown when the AI session is busy |
65
+ | `chatClear` | Label for the clear-conversation button |
66
+
67
+ ```ts
68
+ await AXSDK.init({
69
+ // ...
70
+ translations: {
71
+ en: {
72
+ chatAskMe: "How can I help?",
73
+ chatEmpty: "Ask me anything.",
74
+ },
75
+ ko: {
76
+ chatAskMe: "무엇을 도와드릴까요?",
77
+ chatEmpty: "대화를 시작하세요.",
78
+ },
79
+ },
80
+ });
81
+ ```
82
+
83
+ ## API Reference
84
+
85
+ ### `AXSDK` (singleton)
86
+
87
+ | Method | Description |
88
+ |---|---|
89
+ | `init(config)` | Initialize (or reconfigure) the SDK |
90
+ | `destroy()` | Tear down SSE connections and internal listeners |
91
+ | `sendMessage(text)` | Send a user chat message |
92
+ | `setAppAuthToken(token)` | Attach an app-level auth token to all requests |
93
+ | `resetSession()` | Clear the current chat session and message history |
94
+ | `getLanguage()` | Returns the active language string |
95
+ | `t(id)` | Resolve a translation key to a string |
96
+ | `eventBus()` | Access the internal `EventEmitter` (`EventBus`) |
97
+ | `getAppStore()` | Returns the Zustand `StoreApi<AppState>` |
98
+ | `getChatStore()` | Returns the Zustand `StoreApi<ChatState>` |
99
+ | `getChatState()` | Returns a snapshot of `ChatState` |
100
+ | `axHandler()` | Returns the registered `AXHandler` callback |
101
+ | `headers()` | Returns the configured custom headers |
102
+
103
+ ### Key Types
104
+
105
+ ```ts
106
+ // SDK configuration
107
+ type AXSDKConfig = {
108
+ apiKey: string;
109
+ appId: string;
110
+ axHandler: AXHandler;
111
+ headers?: Record<string, string>;
112
+ language?: string;
113
+ debug?: boolean;
114
+ translations?: Record<string, Record<string, string>>;
115
+ };
116
+
117
+ // Handler invoked when the AI triggers an app action
118
+ type AXHandler = (command: string, args: Record<string, unknown>) => Promise<unknown>;
119
+
120
+ // Chat session
121
+ interface ChatSession {
122
+ id: string;
123
+ status: string; // "idle" | "busy"
124
+ title: string;
125
+ time: MessageTime;
126
+ }
127
+
128
+ // Chat message
129
+ interface ChatMessage {
130
+ info: MessageInfo; // includes role: "user" | "assistant"
131
+ parts?: MessagePart[];
132
+ finish?: string;
133
+ }
134
+ ```
135
+
136
+ ### Exported utilities (experimental)
137
+
138
+ | Export | Description |
139
+ |---|---|
140
+ | `captureScreenshot(options?)` | Captures the current page (or a DOM element) as a base64 data URL |
141
+ | `captureScreenshotBlob(options?)` | Same, but returns a `Blob` |
142
+
143
+ ```ts
144
+ import { captureScreenshot, captureScreenshotBlob } from "@axsdk/core";
145
+
146
+ const dataUrl = await captureScreenshot({ type: "image/jpeg", quality: 0.8 });
147
+ const blob = await captureScreenshotBlob({ element: document.querySelector("#app") });
148
+ ```
149
+
150
+ ## State Persistence
151
+
152
+ `appStore` and `chatStore` are persisted to `localStorage` under the keys `axsdk:app` and `axsdk:chat` respectively. A user ID is auto-generated and reused across page loads.
153
+
154
+ ## License
155
+
156
+ MIT
package/dist/axapi.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ApiClient, type RequestInterceptor } from "./apiclient";
1
+ import { ApiClient, type RequestInterceptor } from './apiclient';
2
2
  export declare const api: ApiClient;
3
3
  export declare function init(ri: RequestInterceptor): void;
4
4
  export declare function health(): Promise<unknown>;
package/dist/axsdk.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import EventEmitter from "eventemitter3";
1
+ import EventEmitter from 'eventemitter3';
2
2
  import { type StoreApi } from 'zustand/vanilla';
3
- import type { AXSDKConfig, AXHandler } from "./types";
4
- export type * from "./types";
5
- import { type AppState, type ChatState } from "./store";
3
+ import type { AXSDKConfig, AXHandler } from './types';
4
+ export type * from './types';
5
+ import { type AppState, type ChatState } from './store';
6
6
  declare class AxSdk extends EventEmitter {
7
7
  config: AXSDKConfig | undefined;
8
8
  constructor();
@@ -1,2 +1,2 @@
1
- import EventEmitter from "eventemitter3";
1
+ import EventEmitter from 'eventemitter3';
2
2
  export declare const EventBus: EventEmitter<string | symbol, any>;