@halo-sdk/core 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.
Files changed (54) hide show
  1. package/README.md +8 -0
  2. package/dist/halo-agent.d.ts +73 -0
  3. package/dist/halo-agent.d.ts.map +1 -0
  4. package/dist/halo-agent.js +95 -0
  5. package/dist/halo-agent.js.map +1 -0
  6. package/dist/halo-session.d.ts +60 -0
  7. package/dist/halo-session.d.ts.map +1 -0
  8. package/dist/halo-session.js +80 -0
  9. package/dist/halo-session.js.map +1 -0
  10. package/dist/halo.d.ts +20 -0
  11. package/dist/halo.d.ts.map +1 -0
  12. package/dist/halo.js +20 -0
  13. package/dist/halo.js.map +1 -0
  14. package/dist/index.d.ts +11 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +6 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/log.d.ts +22 -0
  19. package/dist/log.d.ts.map +1 -0
  20. package/dist/log.js +41 -0
  21. package/dist/log.js.map +1 -0
  22. package/dist/model-adapter.d.ts +45 -0
  23. package/dist/model-adapter.d.ts.map +1 -0
  24. package/dist/model-adapter.js +2 -0
  25. package/dist/model-adapter.js.map +1 -0
  26. package/dist/prefix.d.ts +35 -0
  27. package/dist/prefix.d.ts.map +1 -0
  28. package/dist/prefix.js +84 -0
  29. package/dist/prefix.js.map +1 -0
  30. package/dist/session-impl.d.ts +62 -0
  31. package/dist/session-impl.d.ts.map +1 -0
  32. package/dist/session-impl.js +308 -0
  33. package/dist/session-impl.js.map +1 -0
  34. package/dist/session.d.ts +72 -0
  35. package/dist/session.d.ts.map +1 -0
  36. package/dist/session.js +2 -0
  37. package/dist/session.js.map +1 -0
  38. package/dist/strategies.d.ts +26 -0
  39. package/dist/strategies.d.ts.map +1 -0
  40. package/dist/strategies.js +2 -0
  41. package/dist/strategies.js.map +1 -0
  42. package/dist/tool-utils.d.ts +14 -0
  43. package/dist/tool-utils.d.ts.map +1 -0
  44. package/dist/tool-utils.js +36 -0
  45. package/dist/tool-utils.js.map +1 -0
  46. package/dist/tool.d.ts +22 -0
  47. package/dist/tool.d.ts.map +1 -0
  48. package/dist/tool.js +23 -0
  49. package/dist/tool.js.map +1 -0
  50. package/dist/types.d.ts +51 -0
  51. package/dist/types.d.ts.map +1 -0
  52. package/dist/types.js +2 -0
  53. package/dist/types.js.map +1 -0
  54. package/package.json +44 -0
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # @halo-sdk/core
2
+
3
+ Core types, factory, and session management for Halo AI SDK.
4
+
5
+ - `Halo` — factory for creating sessions
6
+ - `HaloAgent` — cache-aware AI agent with automatic tool-call loop
7
+ - `StablePrefix` — SHA-256 fingerprinted prefix management
8
+ - `MessageLog` — in-memory message history
@@ -0,0 +1,73 @@
1
+ import type { ChatMessage, ToolCall, ToolDefinition, ToolSpec } from "./types.js";
2
+ import type { TurnResult, TurnChunk, ToolResult, SessionStats, HaloAgentOptions } from "./session.js";
3
+ /**
4
+ * A cache-aware AI agent with automatic tool-call loop.
5
+ *
6
+ * Create one via `new HaloAgent(opts)` or `halo.agent(opts)`.
7
+ * Each agent maintains a stable prefix (system prompt + tools + few-shots)
8
+ * that enables prefix caching across turns.
9
+ */
10
+ export declare class HaloAgent {
11
+ private _impl;
12
+ constructor(opts: HaloAgentOptions);
13
+ /** Read-only agent statistics. Updated after every turn. */
14
+ get stats(): Readonly<SessionStats>;
15
+ /**
16
+ * Run a prompt with automatic tool-call loop.
17
+ * This is the default entry point for 80% of use-cases.
18
+ */
19
+ run(input: string, opts?: {
20
+ maxSteps?: number;
21
+ onToolCall?: (call: ToolCall) => Promise<ToolResult>;
22
+ onStep?: (step: {
23
+ step: number;
24
+ content: string;
25
+ toolCalls: ToolCall[];
26
+ }) => void;
27
+ }): Promise<TurnResult>;
28
+ /**
29
+ * Send a message. Tool calls are returned, NOT automatically executed.
30
+ * Use submitToolResult() to feed results back.
31
+ */
32
+ send(input: string): Promise<TurnResult>;
33
+ /** Stream a message. */
34
+ stream(input: string): AsyncGenerator<TurnChunk>;
35
+ /** Submit a tool execution result. Triggers another model call. */
36
+ submitToolResult(result: ToolResult): Promise<TurnResult>;
37
+ /**
38
+ * Stream-compatible entry for AI SDK (useChat) integration.
39
+ *
40
+ * Accepts UIMessages from `useChat()`, hydrates prior history,
41
+ * and streams the response. When tools with `execute` are present,
42
+ * the full tool-call loop runs automatically via `run()`.
43
+ */
44
+ sdkStream(messages: {
45
+ role: string;
46
+ content: string;
47
+ }[]): AsyncGenerator<TurnChunk>;
48
+ /** Add a tool to the agent. Triggers cache miss for the NEXT turn only. */
49
+ addTool(spec: ToolSpec): void;
50
+ /** Add a named tool with an optional execute function. */
51
+ addTool(name: string, def: ToolDefinition): void;
52
+ /** Remove a tool. Same cache-miss semantics. */
53
+ removeTool(name: string): void;
54
+ /** Add a few-shot example. Same cache-miss semantics. */
55
+ addFewShot(msg: ChatMessage): void;
56
+ /** Remove a few-shot example by index. */
57
+ removeFewShot(index: number): boolean;
58
+ /**
59
+ * Start a keep-alive timer that sends periodic pings to maintain
60
+ * server-side KV cache warmth. Call stop() when the long-running
61
+ * task is done.
62
+ */
63
+ keepAlive(intervalMs?: number): {
64
+ stop: () => void;
65
+ };
66
+ /** Restore conversation state from external history (e.g. previous API calls). */
67
+ hydrate(messages: ChatMessage[]): void;
68
+ /** Clear conversation history without changing the prefix. */
69
+ clearLog(): void;
70
+ /** Change the system prompt. Triggers cache miss. */
71
+ setSystem(system: string): void;
72
+ }
73
+ //# sourceMappingURL=halo-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"halo-agent.d.ts","sourceRoot":"","sources":["../src/halo-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,gBAAgB,EACjB,MAAM,cAAc,C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,GAAG,IAAI;IAGlC,0CAA0C;IAC1C,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAMrC;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,IAAI,CAAA;KAAE;IAMpD,kFAAkF;IAClF,OAAO,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI;IAMtC,8DAA8D;IAC9D,QAAQ,IAAI,IAAI;IAGhB,qDAAqD;IACrD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAGhC"}
@@ -0,0 +1,95 @@
1
+ import { HaloAgentImpl } from "./session-impl.js";
2
+ /**
3
+ * A cache-aware AI agent with automatic tool-call loop.
4
+ *
5
+ * Create one via `new HaloAgent(opts)` or `halo.agent(opts)`.
6
+ * Each agent maintains a stable prefix (system prompt + tools + few-shots)
7
+ * that enables prefix caching across turns.
8
+ */
9
+ export class HaloAgent {
10
+ _impl;
11
+ constructor(opts) {
12
+ this._impl = new HaloAgentImpl(opts);
13
+ }
14
+ // ── Core ──
15
+ /** Read-only agent statistics. Updated after every turn. */
16
+ get stats() {
17
+ return this._impl.stats;
18
+ }
19
+ /**
20
+ * Run a prompt with automatic tool-call loop.
21
+ * This is the default entry point for 80% of use-cases.
22
+ */
23
+ async run(input, opts) {
24
+ return this._impl.run(input, opts);
25
+ }
26
+ /**
27
+ * Send a message. Tool calls are returned, NOT automatically executed.
28
+ * Use submitToolResult() to feed results back.
29
+ */
30
+ async send(input) {
31
+ return this._impl.send(input);
32
+ }
33
+ /** Stream a message. */
34
+ async *stream(input) {
35
+ yield* this._impl.stream(input);
36
+ }
37
+ /** Submit a tool execution result. Triggers another model call. */
38
+ async submitToolResult(result) {
39
+ return this._impl.submitToolResult(result);
40
+ }
41
+ /**
42
+ * Stream-compatible entry for AI SDK (useChat) integration.
43
+ *
44
+ * Accepts UIMessages from `useChat()`, hydrates prior history,
45
+ * and streams the response. When tools with `execute` are present,
46
+ * the full tool-call loop runs automatically via `run()`.
47
+ */
48
+ async *sdkStream(messages) {
49
+ yield* this._impl.sdkStream(messages);
50
+ }
51
+ addTool(specOrName, def) {
52
+ if (typeof specOrName === "string") {
53
+ this._impl.addTool(specOrName, def);
54
+ }
55
+ else {
56
+ this._impl.addTool(specOrName);
57
+ }
58
+ }
59
+ /** Remove a tool. Same cache-miss semantics. */
60
+ removeTool(name) {
61
+ this._impl.removeTool(name);
62
+ }
63
+ /** Add a few-shot example. Same cache-miss semantics. */
64
+ addFewShot(msg) {
65
+ this._impl.addFewShot(msg);
66
+ }
67
+ /** Remove a few-shot example by index. */
68
+ removeFewShot(index) {
69
+ return this._impl.removeFewShot(index);
70
+ }
71
+ // ── Keep-alive ──
72
+ /**
73
+ * Start a keep-alive timer that sends periodic pings to maintain
74
+ * server-side KV cache warmth. Call stop() when the long-running
75
+ * task is done.
76
+ */
77
+ keepAlive(intervalMs) {
78
+ return this._impl.keepAlive(intervalMs);
79
+ }
80
+ // ── Hydrate ──
81
+ /** Restore conversation state from external history (e.g. previous API calls). */
82
+ hydrate(messages) {
83
+ this._impl.hydrate(messages);
84
+ }
85
+ // ── Lifecycle ──
86
+ /** Clear conversation history without changing the prefix. */
87
+ clearLog() {
88
+ this._impl.clearLog();
89
+ }
90
+ /** Change the system prompt. Triggers cache miss. */
91
+ setSystem(system) {
92
+ this._impl.setSystem(system);
93
+ }
94
+ }
95
+ //# sourceMappingURL=halo-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"halo-agent.js","sourceRoot":"","sources":["../src/halo-agent.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,OAAO,SAAS;IACZ,KAAK,CAAgB;IAE7B,YAAY,IAAsB;QAChC,IAAI,CAAC,KAAK,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,aAAa;IAEb,4DAA4D;I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,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,0CAA0C;IAC1C,aAAa,CAAC,KAAa;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,mBAAmB;IAEnB;;;;OAIG;IACH,SAAS,CAAC,UAAmB;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED,gBAAgB;IAEhB,kFAAkF;IAClF,OAAO,CAAC,QAAuB;QAC7B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,kBAAkB;IAElB,8DAA8D;IAC9D,QAAQ;QACN,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IACD,qDAAqD;IACrD,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,60 @@
1
+ import type { ChatMessage, ToolCall, ToolDefinition, ToolSpec } from "./types.js";
2
+ import type { TurnResult, TurnChunk, ToolResult, SessionStats, HaloSessionOptions } from "./session.js";
3
+ /**
4
+ * Public API for a single cache-aware conversation session.
5
+ *
6
+ * Create one via `new HaloSession(opts)` or `halo.session(opts)`.
7
+ * Each session maintains a stable prefix (system prompt + tools + few-shots)
8
+ * that enables DeepSeek's prefix caching across turns.
9
+ */
10
+ export declare class HaloSession {
11
+ private _impl;
12
+ constructor(opts: HaloSessionOptions);
13
+ /** Read-only session statistics. Updated after every turn. */
14
+ get stats(): Readonly<SessionStats>;
15
+ /**
16
+ * Run a prompt with automatic tool-call loop.
17
+ * This is the default entry point for 80% of use-cases.
18
+ */
19
+ run(input: string, opts?: {
20
+ maxSteps?: number;
21
+ onToolCall?: (call: ToolCall) => Promise<ToolResult>;
22
+ onStep?: (step: {
23
+ step: number;
24
+ content: string;
25
+ toolCalls: ToolCall[];
26
+ }) => void;
27
+ }): Promise<TurnResult>;
28
+ /**
29
+ * Send a message. Tool calls are returned, NOT automatically executed.
30
+ * Use submitToolResult() to feed results back.
31
+ */
32
+ send(input: string): Promise<TurnResult>;
33
+ /** Stream a message. */
34
+ stream(input: string): AsyncGenerator<TurnChunk>;
35
+ /** Submit a tool execution result. Triggers another model call. */
36
+ submitToolResult(result: ToolResult): Promise<TurnResult>;
37
+ /** Add a tool to the session. Triggers cache miss for the NEXT turn only. */
38
+ addTool(spec: ToolSpec): void;
39
+ /** Add a named tool with an optional execute function. */
40
+ addTool(name: string, def: ToolDefinition): void;
41
+ /** Remove a tool. Same cache-miss semantics. */
42
+ removeTool(name: string): void;
43
+ /** Add a few-shot example. Same cache-miss semantics. */
44
+ addFewShot(msg: ChatMessage): void;
45
+ /** Remove a few-shot example by index. */
46
+ removeFewShot(index: number): boolean;
47
+ /**
48
+ * Start a keep-alive timer that sends periodic pings to maintain
49
+ * server-side KV cache warmth. Call stop() when the long-running
50
+ * task is done.
51
+ */
52
+ keepAlive(intervalMs?: number): {
53
+ stop: () => void;
54
+ };
55
+ /** Clear conversation history without changing the prefix. */
56
+ clearLog(): void;
57
+ /** Change the system prompt. Triggers cache miss. */
58
+ setSystem(system: string): void;
59
+ }
60
+ //# sourceMappingURL=halo-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"halo-session.d.ts","sourceRoot":"","sources":["../src/halo-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAGtB;;;;;;GAMG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAkB;gBAEnB,IAAI,EAAE,kBAAkB;IAMpC,8DAA8D;IAC9D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M,GAAG,IAAI;CAGhC"}
@@ -0,0 +1,80 @@
1
+ import { HaloSessionImpl } from "./session-impl.js";
2
+ /**
3
+ * Public API for a single cache-aware conversation session.
4
+ *
5
+ * Create one via `new HaloSession(opts)` or `halo.session(opts)`.
6
+ * Each session maintains a stable prefix (system prompt + tools + few-shots)
7
+ * that enables DeepSeek's prefix caching across turns.
8
+ */
9
+ export class HaloSession {
10
+ _impl;
11
+ constructor(opts) {
12
+ this._impl = new HaloSessionImpl(opts);
13
+ }
14
+ // ── Core ──
15
+ /** Read-only session statistics. Updated after every turn. */
16
+ get stats() {
17
+ return this._impl.stats;
18
+ }
19
+ /**
20
+ * Run a prompt with automatic tool-call loop.
21
+ * This is the default entry point for 80% of use-cases.
22
+ */
23
+ async run(input, opts) {
24
+ return this._impl.run(input, opts);
25
+ }
26
+ /**
27
+ * Send a message. Tool calls are returned, NOT automatically executed.
28
+ * Use submitToolResult() to feed results back.
29
+ */
30
+ async send(input) {
31
+ return this._impl.send(input);
32
+ }
33
+ /** Stream a message. */
34
+ async *stream(input) {
35
+ yield* this._impl.stream(input);
36
+ }
37
+ /** Submit a tool execution result. Triggers another model call. */
38
+ async submitToolResult(result) {
39
+ return this._impl.submitToolResult(result);
40
+ }
41
+ addTool(specOrName, def) {
42
+ if (typeof specOrName === "string") {
43
+ this._impl.addTool(specOrName, def);
44
+ }
45
+ else {
46
+ this._impl.addTool(specOrName);
47
+ }
48
+ }
49
+ /** Remove a tool. Same cache-miss semantics. */
50
+ removeTool(name) {
51
+ this._impl.removeTool(name);
52
+ }
53
+ /** Add a few-shot example. Same cache-miss semantics. */
54
+ addFewShot(msg) {
55
+ this._impl.addFewShot(msg);
56
+ }
57
+ /** Remove a few-shot example by index. */
58
+ removeFewShot(index) {
59
+ return this._impl.removeFewShot(index);
60
+ }
61
+ // ── Keep-alive ──
62
+ /**
63
+ * Start a keep-alive timer that sends periodic pings to maintain
64
+ * server-side KV cache warmth. Call stop() when the long-running
65
+ * task is done.
66
+ */
67
+ keepAlive(intervalMs) {
68
+ return this._impl.keepAlive(intervalMs);
69
+ }
70
+ // ── Lifecycle ──
71
+ /** Clear conversation history without changing the prefix. */
72
+ clearLog() {
73
+ this._impl.clearLog();
74
+ }
75
+ /** Change the system prompt. Triggers cache miss. */
76
+ setSystem(system) {
77
+ this._impl.setSystem(system);
78
+ }
79
+ }
80
+ //# sourceMappingURL=halo-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"halo-session.js","sourceRoot":"","sources":["../src/halo-session.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACd,KAAK,CAAkB;IAE/B,YAAY,IAAwB;QAClC,IAAI,CAAC,KAAK,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,aAAa;IAEb,8DAA8D;IAC9D,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG,CACP,KAAa,EACb,IAIC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,wBAAwB;IACxB,KAAK,CAAC,CAAC,MAAM,CAAC,KAAa;QACzB,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,mEAAmE;IACnE,KAAK,CAAC,gBAAgB,CAAC,MAAkB;QACvC,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAQD,OAAO,CAAC,UAA6B,EAAE,GAAoB;QACzD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,GAAI,CAAC,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,gDAAgD;IAChD,UAAU,CAAC,IAAY;QACrB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IACD,yDAAyD;IACzD,UAAU,CAAC,GAAgB;QACzB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,0CAA0C;IAC1C,aAAa,CAAC,KAAa;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,mBAAmB;IAEnB;;;;OAIG;IACH,SAAS,CAAC,UAAmB;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED,kBAAkB;IAElB,8DAA8D;IAC9D,QAAQ;QACN,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IACD,qDAAqD;IACrD,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACF"}
package/dist/halo.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { HaloAgent } from "./halo-agent.js";
2
+ import type { AgentEvent } from "./session.js";
3
+ import type { ModelAdapter } from "./model-adapter.js";
4
+ import type { ContextStrategy, RepairStrategy } from "./strategies.js";
5
+ import type { ToolSpec, ChatMessage, ToolDefinition } from "./types.js";
6
+ export declare class Halo {
7
+ private _adapter;
8
+ constructor(opts: {
9
+ adapter: ModelAdapter;
10
+ });
11
+ agent(opts: {
12
+ system: string;
13
+ tools?: ToolSpec[] | Record<string, ToolDefinition<any>>;
14
+ fewShots?: ChatMessage[];
15
+ context?: ContextStrategy;
16
+ repair?: RepairStrategy;
17
+ on?: (event: AgentEvent, payload: unknown) => void;
18
+ }): HaloAgent;
19
+ }
20
+ //# sourceMappingURL=halo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"halo.d.ts","sourceRoot":"","sources":["../src/halo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAoB,UAAU,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAExE,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAe;gBAEnB,IAAI,EAAE;QAAE,OAAO,EAAE,YAAY,CAAA;KAAE;IAI3C,KAAK,CAAC,IAAI,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;QACzD,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;QAEzB,OAAO,CAAC,EAAE,eAAe,CAAC;QAC1B,MAAM,CAAC,EAAE,cAAc,CAAC;QAExB,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;KACpD,GAAG,SAAS;CAad"}
package/dist/halo.js ADDED
@@ -0,0 +1,20 @@
1
+ import { HaloAgent } from "./halo-agent.js";
2
+ export class Halo {
3
+ _adapter;
4
+ constructor(opts) {
5
+ this._adapter = opts.adapter;
6
+ }
7
+ agent(opts) {
8
+ const agentOpts = {
9
+ adapter: this._adapter,
10
+ system: opts.system,
11
+ tools: opts.tools,
12
+ fewShots: opts.fewShots,
13
+ context: opts.context,
14
+ repair: opts.repair,
15
+ on: opts.on,
16
+ };
17
+ return new HaloAgent(agentOpts);
18
+ }
19
+ }
20
+ //# sourceMappingURL=halo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"halo.js","sourceRoot":"","sources":["../src/halo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM5C,MAAM,OAAO,IAAI;IACP,QAAQ,CAAe;IAE/B,YAAY,IAA+B;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,IASL;QACC,MAAM,SAAS,GAAqB;YAClC,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,EAAE,EAAE,IAAI,CAAC,EAAE;SACZ,CAAC;QAEF,OAAO,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ export type { ChatMessage, ToolCall, ToolDefinition, ToolSpec, Role, Usage } from "./types.js";
2
+ export type { ModelAdapter, ModelCapabilities, PricingInfo } from "./model-adapter.js";
3
+ export type { ContextStrategy, RepairStrategy, RepairResult, } from "./strategies.js";
4
+ export type { TurnResult, TurnChunk, ToolResult, AgentEvent, CacheMissReason, SessionStats, PricingSnapshot, HaloAgentOptions, } from "./session.js";
5
+ export { StablePrefix } from "./prefix.js";
6
+ export { MessageLog } from "./log.js";
7
+ export { HaloAgent } from "./halo-agent.js";
8
+ export { Halo } from "./halo.js";
9
+ export { tool } from "./tool.js";
10
+ export type { HaloAgentImpl } from "./session-impl.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC/F,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACvF,YAAY,EACV,eAAe,EACf,cAAc,EACd,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,eAAe,EACf,YAAY,EACZ,eAAe,EACf,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { StablePrefix } from "./prefix.js";
2
+ export { MessageLog } from "./log.js";
3
+ export { HaloAgent } from "./halo-agent.js";
4
+ export { Halo } from "./halo.js";
5
+ export { tool } from "./tool.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
package/dist/log.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { ChatMessage } from "./types.js";
2
+ export declare class MessageLog {
3
+ private _entries;
4
+ private _storageLimit;
5
+ private _version;
6
+ constructor(opts?: {
7
+ storageLimit?: number;
8
+ });
9
+ /** Append a message. Bumps version. */
10
+ append(msg: ChatMessage): void;
11
+ /** Replace all entries. Use to restore conversation state from external history. */
12
+ hydrate(messages: ChatMessage[]): void;
13
+ /** Returns a shallow copy of the full history. */
14
+ toFullHistory(): ChatMessage[];
15
+ /** Returns a copy of the most recent N entries. */
16
+ recent(n: number): ChatMessage[];
17
+ /** Number of messages currently held. */
18
+ get length(): number;
19
+ /** Monotonic version. Consumers compare against their own snapshot. */
20
+ get version(): number;
21
+ }
22
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAK;gBAET,IAAI,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE;IAI5C,uCAAuC;IACvC,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAW9B,oFAAoF;IACpF,OAAO,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI;IAKtC,kDAAkD;IAClD,aAAa,IAAI,WAAW,EAAE;IAI9B,mDAAmD;IACnD,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE;IAIhC,yCAAyC;IACzC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,uEAAuE;IACvE,IAAI,OAAO,IAAI,MAAM,CAEpB;CACF"}
package/dist/log.js ADDED
@@ -0,0 +1,41 @@
1
+ export class MessageLog {
2
+ _entries = [];
3
+ _storageLimit;
4
+ _version = 0;
5
+ constructor(opts) {
6
+ this._storageLimit = opts?.storageLimit ?? 10_000;
7
+ }
8
+ /** Append a message. Bumps version. */
9
+ append(msg) {
10
+ if (!msg || typeof msg !== "object" || !("role" in msg)) {
11
+ throw new Error(`invalid log entry: ${JSON.stringify(msg)}`);
12
+ }
13
+ this._entries.push(msg);
14
+ if (this._entries.length > this._storageLimit) {
15
+ this._entries.shift();
16
+ }
17
+ this._version++;
18
+ }
19
+ /** Replace all entries. Use to restore conversation state from external history. */
20
+ hydrate(messages) {
21
+ this._entries = [...messages];
22
+ this._version++;
23
+ }
24
+ /** Returns a shallow copy of the full history. */
25
+ toFullHistory() {
26
+ return this._entries.map((e) => ({ ...e }));
27
+ }
28
+ /** Returns a copy of the most recent N entries. */
29
+ recent(n) {
30
+ return this._entries.slice(-n).map((e) => ({ ...e }));
31
+ }
32
+ /** Number of messages currently held. */
33
+ get length() {
34
+ return this._entries.length;
35
+ }
36
+ /** Monotonic version. Consumers compare against their own snapshot. */
37
+ get version() {
38
+ return this._version;
39
+ }
40
+ }
41
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,UAAU;IACb,QAAQ,GAAkB,EAAE,CAAC;IAC7B,aAAa,CAAS;IACtB,QAAQ,GAAG,CAAC,CAAC;IAErB,YAAY,IAAgC;QAC1C,IAAI,CAAC,aAAa,GAAG,IAAI,EAAE,YAAY,IAAI,MAAM,CAAC;IACpD,CAAC;IAED,uCAAuC;IACvC,MAAM,CAAC,GAAgB;QACrB,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YAC9C,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,oFAAoF;IACpF,OAAO,CAAC,QAAuB;QAC7B,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;QAC9B,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,kDAAkD;IAClD,aAAa;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,mDAAmD;IACnD,MAAM,CAAC,CAAS;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,yCAAyC;IACzC,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,uEAAuE;IACvE,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,45 @@
1
+ import type { ChatMessage, ToolCall, ToolSpec, Usage } from "./types.js";
2
+ import type { TurnChunk } from "./session.js";
3
+ export interface ModelCapabilities {
4
+ toolUse: boolean;
5
+ streaming: boolean;
6
+ }
7
+ /** Pricing information for cost-tracking. Exposed by adapters that support caching. */
8
+ export interface PricingInfo {
9
+ inputPricePer1k: number;
10
+ cachedInputPricePer1k: number;
11
+ }
12
+ export interface ModelAdapter {
13
+ /**
14
+ * Send a chat request with separated stable prefix and dynamic history.
15
+ *
16
+ * The separation lets adapters apply provider-specific caching strategies:
17
+ * - DeepSeek / OpenAI-compatible: concat `[...prefix, ...history]` (prefix caching)
18
+ * - Anthropic: mark prefix messages with `cache_control` breakpoints
19
+ * - Gemini: use prefix to create/manage a `CachedContent` resource
20
+ */
21
+ chat(prefix: ChatMessage[], history: ChatMessage[], tools?: ToolSpec[]): Promise<{
22
+ content: string;
23
+ toolCalls: ToolCall[];
24
+ usage: Usage;
25
+ }>;
26
+ /** Stream variant with the same prefix/history separation. */
27
+ stream(prefix: ChatMessage[], history: ChatMessage[], tools?: ToolSpec[]): AsyncGenerator<TurnChunk>;
28
+ readonly modelId: string;
29
+ readonly contextWindow: number;
30
+ readonly capabilities: ModelCapabilities;
31
+ /**
32
+ * Pricing data for cache-savings estimation.
33
+ * Omit if the provider doesn't support caching — savings will be `null`.
34
+ */
35
+ readonly pricing?: PricingInfo;
36
+ /**
37
+ * Optional: provider-specific cache keep-alive.
38
+ * The session falls back to a periodic ping (sending prefix + "ping" message)
39
+ * when this is not implemented.
40
+ */
41
+ keepAlive?(prefix: ChatMessage[]): {
42
+ stop: () => void;
43
+ };
44
+ }
45
+ //# sourceMappingURL=model-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-adapter.d.ts","sourceRoot":"","sources":["../src/model-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,uFAAuF;AACvF,MAAM,WAAW,WAAW;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,IAAI,CACF,MAAM,EAAE,WAAW,EAAE,EACrB,OAAO,EAAE,WAAW,EAAE,EACtB,KAAK,CAAC,EAAE,QAAQ,EAAE,GACjB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,QAAQ,EAAE,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IAErE,8DAA8D;IAC9D,MAAM,CACJ,MAAM,EAAE,WAAW,EAAE,EACrB,OAAO,EAAE,WAAW,EAAE,EACtB,KAAK,CAAC,EAAE,QAAQ,EAAE,GACjB,cAAc,CAAC,SAAS,CAAC,CAAC;IAE7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;IAEzC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;IAE/B;;;;OAIG;IACH,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG;QAAE,IAAI,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CACzD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=model-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-adapter.js","sourceRoot":"","sources":["../src/model-adapter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import type { ChatMessage, ToolSpec } from "./types.js";
2
+ export interface StablePrefixOptions {
3
+ system: string;
4
+ tools: ToolSpec[];
5
+ fewShots?: ChatMessage[];
6
+ hashFn?: (input: string) => string;
7
+ }
8
+ export declare class StablePrefix {
9
+ private _system;
10
+ private _toolSpecs;
11
+ private readonly _fewShots;
12
+ private readonly _hashFn;
13
+ private _fingerprintCache;
14
+ constructor(opts: StablePrefixOptions);
15
+ /** Messages that form the stable prefix: [system, ...fewShots]. */
16
+ toMessages(): ChatMessage[];
17
+ /** Shallow copy of the tool list. */
18
+ tools(): ToolSpec[];
19
+ /** SHA-256[:16] fingerprint of the entire prefix. */
20
+ get fingerprint(): string;
21
+ get diagnostics(): {
22
+ systemHash: string;
23
+ toolSpecsHash: string;
24
+ fewShotsHash: string;
25
+ toolCount: number;
26
+ toolNames: string[];
27
+ };
28
+ addTool(spec: ToolSpec): boolean;
29
+ removeTool(name: string): boolean;
30
+ addFewShot(msg: ChatMessage): void;
31
+ removeFewShot(index: number): boolean;
32
+ private invalidate;
33
+ private computeFingerprint;
34
+ }
35
+ //# sourceMappingURL=prefix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../src/prefix.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACpC;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IACpD,OAAO,CAAC,iBAAiB,CAAuB;gBAEpC,IAAI,EAAE,mBAAmB;IAOrC,mEAAmE;IACnE,UAAU,IAAI,WAAW,EAAE;IAI3B,qCAAqC;IACrC,KAAK,IAAI,QAAQ,EAAE;IAInB,qDAAqD;IACrD,IAAI,WAAW,IAAI,MAAM,CAIxB;IAED,IAAI,WAAW;;;;;;MAQd;IAID,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO;IAShC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAQjC,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAKlC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IASrC,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,kBAAkB;CAQ3B"}