helios-ai-sdk 1.0.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/README.md +43 -0
- package/dist/sdk.cjs +173 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.cts +399 -0
- package/dist/sdk.d.ts +399 -0
- package/dist/sdk.js +173 -0
- package/dist/sdk.js.map +1 -0
- package/package.json +43 -0
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helios Embedded SDK — Comprehensive API
|
|
3
|
+
*
|
|
4
|
+
* A full-featured TypeScript SDK for embedding the Helios AI-native
|
|
5
|
+
* runtime into JavaScript/TypeScript applications.
|
|
6
|
+
*
|
|
7
|
+
* @module helios-sdk
|
|
8
|
+
*/
|
|
9
|
+
/** Supported AI providers */
|
|
10
|
+
type HeliosProvider = 'gemini' | 'openai' | 'anthropic' | 'webllm' | 'custom';
|
|
11
|
+
/** Event types emitted by the Helios runtime */
|
|
12
|
+
type HeliosEventType = 'print' | 'error' | 'trace' | 'tool_call' | 'agent_delegate' | 'prompt_start' | 'prompt_end';
|
|
13
|
+
/** A structured print payload from UI primitives */
|
|
14
|
+
interface HeliosPrintPayload {
|
|
15
|
+
type?: string;
|
|
16
|
+
title?: string;
|
|
17
|
+
content?: string;
|
|
18
|
+
value?: number;
|
|
19
|
+
max?: number;
|
|
20
|
+
label?: string;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Trace entry from the execution engine */
|
|
24
|
+
interface HeliosTraceEntry {
|
|
25
|
+
type: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
model?: string;
|
|
28
|
+
input?: string;
|
|
29
|
+
output?: string;
|
|
30
|
+
duration?: number;
|
|
31
|
+
timestamp?: number;
|
|
32
|
+
tokens?: {
|
|
33
|
+
input?: number;
|
|
34
|
+
output?: number;
|
|
35
|
+
};
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
/** Tool call event */
|
|
39
|
+
interface HeliosToolCallEvent {
|
|
40
|
+
name: string;
|
|
41
|
+
args: unknown[];
|
|
42
|
+
result?: unknown;
|
|
43
|
+
}
|
|
44
|
+
/** Agent delegation event */
|
|
45
|
+
interface HeliosAgentDelegateEvent {
|
|
46
|
+
from: string;
|
|
47
|
+
to: string;
|
|
48
|
+
task: string;
|
|
49
|
+
result?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Prompt lifecycle events */
|
|
52
|
+
interface HeliosPromptEvent {
|
|
53
|
+
prompt: string;
|
|
54
|
+
model?: string;
|
|
55
|
+
provider?: string;
|
|
56
|
+
}
|
|
57
|
+
/** Event map for typed event listeners */
|
|
58
|
+
interface HeliosEventMap {
|
|
59
|
+
print: string | HeliosPrintPayload;
|
|
60
|
+
error: Error;
|
|
61
|
+
trace: HeliosTraceEntry;
|
|
62
|
+
tool_call: HeliosToolCallEvent;
|
|
63
|
+
agent_delegate: HeliosAgentDelegateEvent;
|
|
64
|
+
prompt_start: HeliosPromptEvent;
|
|
65
|
+
prompt_end: HeliosPromptEvent & {
|
|
66
|
+
response?: string;
|
|
67
|
+
duration?: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Typed event handler */
|
|
71
|
+
type HeliosEventHandler<T extends HeliosEventType> = (data: HeliosEventMap[T]) => void;
|
|
72
|
+
/** Tool metadata for registration */
|
|
73
|
+
interface HeliosToolMetadata {
|
|
74
|
+
name: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
params?: Array<{
|
|
77
|
+
name: string;
|
|
78
|
+
type: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
}>;
|
|
81
|
+
returnType?: string;
|
|
82
|
+
}
|
|
83
|
+
/** Configuration for Helios runtime */
|
|
84
|
+
interface HeliosConfig {
|
|
85
|
+
/** AI provider API key */
|
|
86
|
+
apiKey?: string;
|
|
87
|
+
/** AI provider to use */
|
|
88
|
+
provider?: HeliosProvider;
|
|
89
|
+
/** Default model ID */
|
|
90
|
+
model?: string;
|
|
91
|
+
/** Base URL for custom API providers */
|
|
92
|
+
baseUrl?: string;
|
|
93
|
+
/** Sampling temperature (0-2) */
|
|
94
|
+
temperature?: number;
|
|
95
|
+
/** Top-K sampling */
|
|
96
|
+
topK?: number;
|
|
97
|
+
/** Top-P (nucleus) sampling */
|
|
98
|
+
topP?: number;
|
|
99
|
+
/** Maximum conversation history entries to retain */
|
|
100
|
+
memoryLimit?: number;
|
|
101
|
+
/** Auto-summarize when history exceeds limit */
|
|
102
|
+
summarizeHistory?: boolean;
|
|
103
|
+
/** Default system prompt for all AI calls */
|
|
104
|
+
systemPrompt?: string;
|
|
105
|
+
/** Maximum loop iterations before kill (default: 1,000,000) */
|
|
106
|
+
maxLoopIterations?: number;
|
|
107
|
+
/** Skip actual AI API calls (return placeholder) */
|
|
108
|
+
dryRun?: boolean;
|
|
109
|
+
/** Middleware stack */
|
|
110
|
+
middleware?: HeliosMiddleware[];
|
|
111
|
+
/** Handler for user input requests from the runtime */
|
|
112
|
+
onInputRequest?: (prompt: string) => Promise<string>;
|
|
113
|
+
}
|
|
114
|
+
/** Middleware hook interface */
|
|
115
|
+
interface HeliosMiddleware {
|
|
116
|
+
/** Unique name for this middleware */
|
|
117
|
+
name: string;
|
|
118
|
+
/** Called before each AI prompt call */
|
|
119
|
+
beforePrompt?: (context: MiddlewarePromptContext) => Promise<MiddlewarePromptContext | void>;
|
|
120
|
+
/** Called after each AI prompt call */
|
|
121
|
+
afterPrompt?: (context: MiddlewarePromptContext, response: MiddlewarePromptResponse) => Promise<MiddlewarePromptResponse | void>;
|
|
122
|
+
/** Called when a tool is invoked */
|
|
123
|
+
onToolCall?: (name: string, args: unknown[]) => Promise<void>;
|
|
124
|
+
/** Called on any runtime error */
|
|
125
|
+
onError?: (error: Error) => Promise<void>;
|
|
126
|
+
}
|
|
127
|
+
/** Context passed through prompt middleware */
|
|
128
|
+
interface MiddlewarePromptContext {
|
|
129
|
+
prompt: string;
|
|
130
|
+
model: string;
|
|
131
|
+
provider: string;
|
|
132
|
+
history: HeliosMessage[];
|
|
133
|
+
systemPrompt?: string;
|
|
134
|
+
metadata: Record<string, unknown>;
|
|
135
|
+
}
|
|
136
|
+
/** Response from prompt middleware */
|
|
137
|
+
interface MiddlewarePromptResponse {
|
|
138
|
+
text: string;
|
|
139
|
+
usage?: {
|
|
140
|
+
inputTokens?: number;
|
|
141
|
+
outputTokens?: number;
|
|
142
|
+
};
|
|
143
|
+
metadata: Record<string, unknown>;
|
|
144
|
+
}
|
|
145
|
+
/** Conversation message */
|
|
146
|
+
interface HeliosMessage {
|
|
147
|
+
role: 'user' | 'assistant' | 'system';
|
|
148
|
+
content: string;
|
|
149
|
+
timestamp: number;
|
|
150
|
+
}
|
|
151
|
+
/** Session configuration */
|
|
152
|
+
interface HeliosSessionConfig {
|
|
153
|
+
/** Session-specific system prompt (overrides global) */
|
|
154
|
+
systemPrompt?: string;
|
|
155
|
+
/** Maximum history length for this session */
|
|
156
|
+
historyLimit?: number;
|
|
157
|
+
/** Initial context data */
|
|
158
|
+
context?: Record<string, unknown>;
|
|
159
|
+
}
|
|
160
|
+
/** Agent configuration */
|
|
161
|
+
interface HeliosAgentConfig {
|
|
162
|
+
/** Agent system prompt / persona description */
|
|
163
|
+
prompt: string;
|
|
164
|
+
/** Model override for this agent */
|
|
165
|
+
model?: string;
|
|
166
|
+
/** Tool names available to this agent */
|
|
167
|
+
tools?: string[];
|
|
168
|
+
/** Whether the agent has persistent memory */
|
|
169
|
+
memory?: boolean;
|
|
170
|
+
}
|
|
171
|
+
/** Memory store entry */
|
|
172
|
+
interface HeliosMemoryEntry {
|
|
173
|
+
key: string;
|
|
174
|
+
text: string;
|
|
175
|
+
metadata?: Record<string, unknown>;
|
|
176
|
+
embedding?: number[];
|
|
177
|
+
timestamp: number;
|
|
178
|
+
}
|
|
179
|
+
/** Memory search result */
|
|
180
|
+
interface HeliosMemorySearchResult {
|
|
181
|
+
key: string;
|
|
182
|
+
text: string;
|
|
183
|
+
score: number;
|
|
184
|
+
metadata?: Record<string, unknown>;
|
|
185
|
+
}
|
|
186
|
+
declare class HeliosSDKError extends Error {
|
|
187
|
+
code: string;
|
|
188
|
+
constructor(message: string, code: string);
|
|
189
|
+
}
|
|
190
|
+
declare class HeliosConfigError extends HeliosSDKError {
|
|
191
|
+
constructor(message: string);
|
|
192
|
+
}
|
|
193
|
+
declare class HeliosExecutionError extends HeliosSDKError {
|
|
194
|
+
line?: number;
|
|
195
|
+
col?: number;
|
|
196
|
+
sourceHint?: string;
|
|
197
|
+
constructor(message: string, line?: number, col?: number, sourceHint?: string);
|
|
198
|
+
}
|
|
199
|
+
declare class HeliosCancelledError extends HeliosSDKError {
|
|
200
|
+
constructor();
|
|
201
|
+
}
|
|
202
|
+
declare class HeliosMemory {
|
|
203
|
+
private _store;
|
|
204
|
+
/** Store a text entry with optional metadata */
|
|
205
|
+
store(key: string, text: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
206
|
+
/** Search entries by text similarity (basic substring search without embeddings) */
|
|
207
|
+
search(query: string, limit?: number): Promise<HeliosMemorySearchResult[]>;
|
|
208
|
+
/** Get a specific entry by key */
|
|
209
|
+
get(key: string): HeliosMemoryEntry | undefined;
|
|
210
|
+
/** Check if a key exists */
|
|
211
|
+
has(key: string): boolean;
|
|
212
|
+
/** Remove an entry */
|
|
213
|
+
delete(key: string): boolean;
|
|
214
|
+
/** Clear all entries */
|
|
215
|
+
clear(): void;
|
|
216
|
+
/** Get total entry count */
|
|
217
|
+
get size(): number;
|
|
218
|
+
/** Export all entries as a portable array */
|
|
219
|
+
export(): HeliosMemoryEntry[];
|
|
220
|
+
/** Import entries from a previously exported array */
|
|
221
|
+
import(data: HeliosMemoryEntry[]): void;
|
|
222
|
+
}
|
|
223
|
+
declare class HeliosSession {
|
|
224
|
+
readonly id: string;
|
|
225
|
+
private helios;
|
|
226
|
+
private history;
|
|
227
|
+
private context;
|
|
228
|
+
private systemPrompt;
|
|
229
|
+
private historyLimit;
|
|
230
|
+
private abortController;
|
|
231
|
+
constructor(helios: Helios, config?: HeliosSessionConfig);
|
|
232
|
+
/** Run a Helios prompt within this session's context and history */
|
|
233
|
+
prompt(text: string, options?: {
|
|
234
|
+
model?: string;
|
|
235
|
+
schema?: string;
|
|
236
|
+
}): Promise<string>;
|
|
237
|
+
/** Run arbitrary Helios code within session context */
|
|
238
|
+
run(source: string): Promise<unknown>;
|
|
239
|
+
/** Get the conversation history */
|
|
240
|
+
getHistory(): HeliosMessage[];
|
|
241
|
+
/** Clear the conversation history */
|
|
242
|
+
clearHistory(): void;
|
|
243
|
+
/** Set the system prompt */
|
|
244
|
+
setSystemPrompt(prompt: string): void;
|
|
245
|
+
/** Add contextual data available to all prompts */
|
|
246
|
+
addContext(key: string, value: unknown): void;
|
|
247
|
+
/** Remove a context key */
|
|
248
|
+
removeContext(key: string): boolean;
|
|
249
|
+
/** Clear all context */
|
|
250
|
+
clearContext(): void;
|
|
251
|
+
/** Get current context as a plain object */
|
|
252
|
+
getContext(): Record<string, unknown>;
|
|
253
|
+
/** Cancel any running operation */
|
|
254
|
+
abort(): void;
|
|
255
|
+
private trimHistory;
|
|
256
|
+
}
|
|
257
|
+
declare class HeliosAgent {
|
|
258
|
+
readonly name: string;
|
|
259
|
+
private helios;
|
|
260
|
+
private config;
|
|
261
|
+
private tools;
|
|
262
|
+
private history;
|
|
263
|
+
private isRegistered;
|
|
264
|
+
constructor(helios: Helios, name: string, config: HeliosAgentConfig);
|
|
265
|
+
/** Register agent in the Helios runtime and make it available for delegation */
|
|
266
|
+
register(): Promise<void>;
|
|
267
|
+
/** Delegate a task to this agent */
|
|
268
|
+
delegate(task: string): Promise<string>;
|
|
269
|
+
/** Add a tool to this agent */
|
|
270
|
+
addTool(name: string, fn: Function, metadata?: Partial<HeliosToolMetadata>): void;
|
|
271
|
+
/** Remove a tool from this agent */
|
|
272
|
+
removeTool(name: string): boolean;
|
|
273
|
+
/** List tool names on this agent */
|
|
274
|
+
listTools(): string[];
|
|
275
|
+
/** Switch the agent's model */
|
|
276
|
+
setModel(model: string): void;
|
|
277
|
+
/** Get agent's conversation history */
|
|
278
|
+
getHistory(): HeliosMessage[];
|
|
279
|
+
/** Clear agent's history */
|
|
280
|
+
clearHistory(): void;
|
|
281
|
+
/** Get the agent's config */
|
|
282
|
+
getConfig(): Readonly<HeliosAgentConfig>;
|
|
283
|
+
}
|
|
284
|
+
declare class Helios {
|
|
285
|
+
private config;
|
|
286
|
+
private tools;
|
|
287
|
+
private toolMetadata;
|
|
288
|
+
private modules;
|
|
289
|
+
private listeners;
|
|
290
|
+
private middleware;
|
|
291
|
+
private sessions;
|
|
292
|
+
private agents;
|
|
293
|
+
private memory;
|
|
294
|
+
private evaluator;
|
|
295
|
+
constructor(config?: HeliosConfig);
|
|
296
|
+
/** Get the current configuration (read-only copy) */
|
|
297
|
+
getConfig(): Readonly<HeliosConfig>;
|
|
298
|
+
/** Update configuration (merges with existing) */
|
|
299
|
+
updateConfig(updates: Partial<HeliosConfig>): void;
|
|
300
|
+
/** Register an event listener */
|
|
301
|
+
on<T extends HeliosEventType>(event: T, handler: HeliosEventHandler<T>): this;
|
|
302
|
+
/** Remove an event listener */
|
|
303
|
+
off<T extends HeliosEventType>(event: T, handler: HeliosEventHandler<T>): this;
|
|
304
|
+
/** Remove all listeners for an event, or all events if no type given */
|
|
305
|
+
removeAllListeners(event?: HeliosEventType): this;
|
|
306
|
+
/** Emit an event (internal + public) */
|
|
307
|
+
emit<T extends HeliosEventType>(event: T, data: HeliosEventMap[T]): void;
|
|
308
|
+
/** Add a middleware to the stack */
|
|
309
|
+
use(middleware: HeliosMiddleware): this;
|
|
310
|
+
/** Remove a middleware by name */
|
|
311
|
+
removeMiddleware(name: string): boolean;
|
|
312
|
+
/** Run prompt through middleware beforePrompt hooks */
|
|
313
|
+
runBeforePromptMiddleware(context: MiddlewarePromptContext): Promise<MiddlewarePromptContext>;
|
|
314
|
+
/** Run response through middleware afterPrompt hooks */
|
|
315
|
+
runAfterPromptMiddleware(context: MiddlewarePromptContext, response: MiddlewarePromptResponse): Promise<MiddlewarePromptResponse>;
|
|
316
|
+
/** Notify middleware of tool calls */
|
|
317
|
+
notifyToolCallMiddleware(name: string, args: unknown[]): Promise<void>;
|
|
318
|
+
/** Notify middleware of errors */
|
|
319
|
+
notifyErrorMiddleware(error: Error): Promise<void>;
|
|
320
|
+
/** Register a JavaScript function as a Helios tool */
|
|
321
|
+
registerTool(name: string, fn: Function, metadata?: Partial<HeliosToolMetadata>): this;
|
|
322
|
+
/** Unregister a tool */
|
|
323
|
+
unregisterTool(name: string): boolean;
|
|
324
|
+
/** List registered tools */
|
|
325
|
+
listTools(): HeliosToolMetadata[];
|
|
326
|
+
/** Register a module of functions */
|
|
327
|
+
registerModule(name: string, exports: Record<string, Function>): this;
|
|
328
|
+
/** Unregister a module */
|
|
329
|
+
unregisterModule(name: string): boolean;
|
|
330
|
+
/** Execute Helios source code */
|
|
331
|
+
run(source: string, context?: Record<string, unknown>): Promise<unknown>;
|
|
332
|
+
/** Create a new conversation session */
|
|
333
|
+
createSession(config?: HeliosSessionConfig): HeliosSession;
|
|
334
|
+
/** Get a session by ID */
|
|
335
|
+
getSession(id: string): HeliosSession | undefined;
|
|
336
|
+
/** List active session IDs */
|
|
337
|
+
listSessions(): string[];
|
|
338
|
+
/** Destroy a session */
|
|
339
|
+
destroySession(id: string): boolean;
|
|
340
|
+
/** Create a new agent with declarative config */
|
|
341
|
+
createAgent(name: string, config: HeliosAgentConfig): HeliosAgent;
|
|
342
|
+
/** Get an existing agent */
|
|
343
|
+
getAgent(name: string): HeliosAgent | undefined;
|
|
344
|
+
/** List all agent names */
|
|
345
|
+
listAgents(): string[];
|
|
346
|
+
/** Destroy an agent */
|
|
347
|
+
destroyAgent(name: string): boolean;
|
|
348
|
+
/** Access the vector memory store */
|
|
349
|
+
getMemory(): HeliosMemory;
|
|
350
|
+
/** Reset all state (evaluator, sessions, agents, memory) */
|
|
351
|
+
reset(): void;
|
|
352
|
+
/** Reset only the evaluator (keeps sessions, agents, memory) */
|
|
353
|
+
resetRuntime(): void;
|
|
354
|
+
private ensureEvaluator;
|
|
355
|
+
}
|
|
356
|
+
/** Fluent builder for creating a Helios instance */
|
|
357
|
+
declare class HeliosBuilder {
|
|
358
|
+
private config;
|
|
359
|
+
private toolRegistrations;
|
|
360
|
+
private moduleRegistrations;
|
|
361
|
+
private middlewareStack;
|
|
362
|
+
private eventHandlers;
|
|
363
|
+
/** Set the AI provider */
|
|
364
|
+
provider(provider: HeliosProvider): this;
|
|
365
|
+
/** Set the API key */
|
|
366
|
+
apiKey(key: string): this;
|
|
367
|
+
/** Set the default model */
|
|
368
|
+
model(model: string): this;
|
|
369
|
+
/** Set a custom base URL */
|
|
370
|
+
baseUrl(url: string): this;
|
|
371
|
+
/** Set the system prompt */
|
|
372
|
+
systemPrompt(prompt: string): this;
|
|
373
|
+
/** Set sampling temperature */
|
|
374
|
+
temperature(temp: number): this;
|
|
375
|
+
/** Set memory limit */
|
|
376
|
+
memoryLimit(limit: number): this;
|
|
377
|
+
/** Set max loop iterations */
|
|
378
|
+
maxLoopIterations(limit: number): this;
|
|
379
|
+
/** Enable dry-run mode (no real AI calls) */
|
|
380
|
+
dryRun(enabled?: boolean): this;
|
|
381
|
+
/** Set input request handler */
|
|
382
|
+
onInputRequest(handler: (prompt: string) => Promise<string>): this;
|
|
383
|
+
/** Register a tool */
|
|
384
|
+
tool(name: string, fn: Function, metadata?: Partial<HeliosToolMetadata>): this;
|
|
385
|
+
/** Register a module */
|
|
386
|
+
module(name: string, exports: Record<string, Function>): this;
|
|
387
|
+
/** Add middleware */
|
|
388
|
+
use(middleware: HeliosMiddleware): this;
|
|
389
|
+
/** Add an event handler */
|
|
390
|
+
on<T extends HeliosEventType>(event: T, handler: HeliosEventHandler<T>): this;
|
|
391
|
+
/** Build the Helios instance */
|
|
392
|
+
build(): Helios;
|
|
393
|
+
}
|
|
394
|
+
/** Create a HeliosBuilder for fluent configuration */
|
|
395
|
+
declare function createHelios(): HeliosBuilder;
|
|
396
|
+
/** Quick-start: Create a Helios instance with minimal config */
|
|
397
|
+
declare function helios(config?: HeliosConfig): Helios;
|
|
398
|
+
|
|
399
|
+
export { Helios, HeliosAgent, type HeliosAgentConfig, type HeliosAgentDelegateEvent, HeliosBuilder, HeliosCancelledError, type HeliosConfig, HeliosConfigError, type HeliosEventHandler, type HeliosEventMap, type HeliosEventType, HeliosExecutionError, HeliosMemory, type HeliosMemoryEntry, type HeliosMemorySearchResult, type HeliosMessage, type HeliosMiddleware, type HeliosPrintPayload, type HeliosPromptEvent, type HeliosProvider, HeliosSDKError, HeliosSession, type HeliosSessionConfig, type HeliosToolCallEvent, type HeliosToolMetadata, type HeliosTraceEntry, type MiddlewarePromptContext, type MiddlewarePromptResponse, createHelios, helios };
|