@halo-sdk/core 1.0.0 → 1.0.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/README.md +50 -5
- package/dist/halo-agent.d.ts +45 -7
- package/dist/halo-agent.d.ts.map +1 -1
- package/dist/halo.d.ts +13 -2
- package/dist/halo.d.ts.map +1 -1
- package/dist/index.cjs +6934 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6895 -5
- package/dist/index.js.map +1 -1
- package/dist/model-adapter.d.ts +20 -8
- package/dist/model-adapter.d.ts.map +1 -1
- package/dist/sandbox.d.ts +78 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/session-impl.d.ts +34 -6
- package/dist/session-impl.d.ts.map +1 -1
- package/dist/session.d.ts +92 -2
- package/dist/session.d.ts.map +1 -1
- package/dist/skills.d.ts +27 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/tool.d.ts +10 -13
- package/dist/tool.d.ts.map +1 -1
- package/dist/tools-builtin.d.ts +12 -0
- package/dist/tools-builtin.d.ts.map +1 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -8
- package/dist/halo-agent.js +0 -95
- package/dist/halo-agent.js.map +0 -1
- package/dist/halo-session.d.ts +0 -60
- package/dist/halo-session.d.ts.map +0 -1
- package/dist/halo-session.js +0 -80
- package/dist/halo-session.js.map +0 -1
- package/dist/halo.js +0 -20
- package/dist/halo.js.map +0 -1
- package/dist/log.js +0 -41
- package/dist/log.js.map +0 -1
- package/dist/model-adapter.js +0 -2
- package/dist/model-adapter.js.map +0 -1
- package/dist/prefix.js +0 -84
- package/dist/prefix.js.map +0 -1
- package/dist/session-impl.js +0 -308
- package/dist/session-impl.js.map +0 -1
- package/dist/session.js +0 -2
- package/dist/session.js.map +0 -1
- package/dist/strategies.js +0 -2
- package/dist/strategies.js.map +0 -1
- package/dist/tool-utils.js +0 -36
- package/dist/tool-utils.js.map +0 -1
- package/dist/tool.js +0 -23
- package/dist/tool.js.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/model-adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatMessage, ToolCall, ToolSpec, Usage } from "./types.js";
|
|
1
|
+
import type { ChatMessage, ToolCall, ToolSpec, Usage, ResponseFormat } from "./types.js";
|
|
2
2
|
import type { TurnChunk } from "./session.js";
|
|
3
3
|
export interface ModelCapabilities {
|
|
4
4
|
toolUse: boolean;
|
|
@@ -9,22 +9,34 @@ export interface PricingInfo {
|
|
|
9
9
|
inputPricePer1k: number;
|
|
10
10
|
cachedInputPricePer1k: number;
|
|
11
11
|
}
|
|
12
|
+
/** Per-request model parameters. Overrides agent-level defaults. */
|
|
13
|
+
export interface ModelCallOptions {
|
|
14
|
+
temperature?: number;
|
|
15
|
+
topP?: number;
|
|
16
|
+
topK?: number;
|
|
17
|
+
maxTokens?: number;
|
|
18
|
+
seed?: number;
|
|
19
|
+
stop?: string[];
|
|
20
|
+
}
|
|
21
|
+
export { type ResponseFormat } from "./types.js";
|
|
22
|
+
export interface ChatParams {
|
|
23
|
+
prefix: ChatMessage[];
|
|
24
|
+
history: ChatMessage[];
|
|
25
|
+
tools?: ToolSpec[];
|
|
26
|
+
responseFormat?: ResponseFormat;
|
|
27
|
+
options?: ModelCallOptions;
|
|
28
|
+
}
|
|
12
29
|
export interface ModelAdapter {
|
|
13
30
|
/**
|
|
14
31
|
* 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
32
|
*/
|
|
21
|
-
chat(
|
|
33
|
+
chat(params: ChatParams): Promise<{
|
|
22
34
|
content: string;
|
|
23
35
|
toolCalls: ToolCall[];
|
|
24
36
|
usage: Usage;
|
|
25
37
|
}>;
|
|
26
38
|
/** Stream variant with the same prefix/history separation. */
|
|
27
|
-
stream(
|
|
39
|
+
stream(params: ChatParams): AsyncGenerator<TurnChunk>;
|
|
28
40
|
readonly modelId: string;
|
|
29
41
|
readonly contextWindow: number;
|
|
30
42
|
readonly capabilities: ModelCapabilities;
|
|
@@ -1 +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;
|
|
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,cAAc,EAAE,MAAM,YAAY,CAAC;AACzF,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,oEAAoE;AACpE,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,QAAQ,EAAE,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IAE5F,8DAA8D;IAC9D,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAEtD,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,78 @@
|
|
|
1
|
+
import type { ToolDefinition } from "./types.js";
|
|
2
|
+
export interface Sandbox {
|
|
3
|
+
/** Read file contents as UTF-8. */
|
|
4
|
+
readFile(path: string): Promise<string>;
|
|
5
|
+
/** Write or overwrite a file. Creates parent directories automatically. */
|
|
6
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
7
|
+
/** List directory entries. */
|
|
8
|
+
readdir(path: string): Promise<{
|
|
9
|
+
name: string;
|
|
10
|
+
isDirectory: boolean;
|
|
11
|
+
}[]>;
|
|
12
|
+
/** Check if a path exists. */
|
|
13
|
+
exists(path: string): Promise<boolean>;
|
|
14
|
+
/** Execute a command with structured arguments (no shell). */
|
|
15
|
+
exec?(command: string, args: string[], opts?: ExecOptions): Promise<ExecResult>;
|
|
16
|
+
/** Execute a shell command string. Requires `allowShell: true`. */
|
|
17
|
+
execShell?(command: string, opts?: ExecShellOptions): Promise<ExecResult>;
|
|
18
|
+
/** Kill all background processes and clean up. Idempotent. */
|
|
19
|
+
dispose(): Promise<void>;
|
|
20
|
+
/** Working directory — all relative paths resolve against this. */
|
|
21
|
+
readonly cwd: string;
|
|
22
|
+
/** Whether this sandbox supports command execution. */
|
|
23
|
+
readonly hasExec: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Auto-generate tool definitions matching this sandbox's capabilities.
|
|
26
|
+
* VirtualSandbox: { readFile, writeFile, readdir }
|
|
27
|
+
* ContainerSandbox: + { exec, execShell }
|
|
28
|
+
*/
|
|
29
|
+
tools(): Record<string, ToolDefinition>;
|
|
30
|
+
}
|
|
31
|
+
export interface ExecOptions {
|
|
32
|
+
/** Working directory for the command (relative to sandbox root). */
|
|
33
|
+
cwd?: string;
|
|
34
|
+
/** Additional environment variables. */
|
|
35
|
+
env?: Record<string, string>;
|
|
36
|
+
/** Timeout in ms. Default 30s. */
|
|
37
|
+
timeout?: number;
|
|
38
|
+
/** If true, returns ProcessHandle instead of waiting. */
|
|
39
|
+
background?: boolean;
|
|
40
|
+
/** Expose a port (0 = auto-assign). Requires background: true. */
|
|
41
|
+
exposePort?: number;
|
|
42
|
+
/** Host to bind. Default "127.0.0.1". */
|
|
43
|
+
bindHost?: string;
|
|
44
|
+
/** Auto-kill after ms of inactivity. Default 300_000 (5 min). */
|
|
45
|
+
portTTL?: number;
|
|
46
|
+
/** Authentication for exposed port. */
|
|
47
|
+
portAuth?: {
|
|
48
|
+
type: "token";
|
|
49
|
+
value: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface ExecShellOptions extends ExecOptions {
|
|
53
|
+
/** Must be explicitly true to use shell mode. */
|
|
54
|
+
allowShell: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface ExecResult {
|
|
57
|
+
stdout: string;
|
|
58
|
+
stderr: string;
|
|
59
|
+
exitCode: number;
|
|
60
|
+
}
|
|
61
|
+
export interface ProcessHandle {
|
|
62
|
+
pid: number;
|
|
63
|
+
/** URL when exposePort was set. */
|
|
64
|
+
url?: string;
|
|
65
|
+
stdout: AsyncIterable<string>;
|
|
66
|
+
stderr: AsyncIterable<string>;
|
|
67
|
+
kill(signal?: string): Promise<void>;
|
|
68
|
+
wait(): Promise<ExecResult>;
|
|
69
|
+
}
|
|
70
|
+
export declare class SandboxError extends Error {
|
|
71
|
+
code: string;
|
|
72
|
+
constructor(message: string, code: string);
|
|
73
|
+
}
|
|
74
|
+
/** Second argument passed to tool execute() when the agent has a sandbox. */
|
|
75
|
+
export interface ToolContext {
|
|
76
|
+
sandbox: Sandbox;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,MAAM,WAAW,OAAO;IACtB,mCAAmC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExC,2EAA2E;IAC3E,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD,8BAA8B;IAC9B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC,CAAC;IAEzE,8BAA8B;IAC9B,MAAM,CAAC,IAAI,EAAE,MAAM,GA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AAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7B;AAID,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAC;gBACD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAK1C;AAID,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
package/dist/session-impl.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChatMessage, ToolCall, ToolDefinition, ToolSpec } from "./types.js";
|
|
2
|
-
import type { TurnResult, TurnChunk, ToolResult, SessionStats, HaloAgentOptions } from "./session.js";
|
|
2
|
+
import type { TurnResult, TurnChunk, ToolResult, SessionStats, HaloAgentOptions, StreamTextOptions, StreamTextResult, GenerateObjectOptions, GenerateObjectResult } from "./session.js";
|
|
3
|
+
import type { ModelCallOptions } from "./model-adapter.js";
|
|
3
4
|
/** Internal implementation. Exported for testing only. */
|
|
4
5
|
export declare class HaloAgentImpl {
|
|
5
6
|
private _adapter;
|
|
@@ -11,9 +12,11 @@ export declare class HaloAgentImpl {
|
|
|
11
12
|
private _stats;
|
|
12
13
|
private _keepAliveTimer;
|
|
13
14
|
private _toolExecutors;
|
|
15
|
+
private _modelDefaults;
|
|
16
|
+
private _sandbox;
|
|
14
17
|
constructor(opts: HaloAgentOptions);
|
|
15
18
|
get stats(): Readonly<SessionStats>;
|
|
16
|
-
|
|
19
|
+
generateText(input: string, opts?: {
|
|
17
20
|
maxSteps?: number;
|
|
18
21
|
onToolCall?: (call: ToolCall) => Promise<ToolResult>;
|
|
19
22
|
onStep?: (s: {
|
|
@@ -21,10 +24,10 @@ export declare class HaloAgentImpl {
|
|
|
21
24
|
content: string;
|
|
22
25
|
toolCalls: ToolCall[];
|
|
23
26
|
}) => void;
|
|
24
|
-
}): Promise<TurnResult>;
|
|
25
|
-
send(input: string): Promise<TurnResult>;
|
|
26
|
-
stream(input: string): AsyncGenerator<TurnChunk>;
|
|
27
|
-
submitToolResult(result: ToolResult): Promise<TurnResult>;
|
|
27
|
+
} & ModelCallOptions): Promise<TurnResult>;
|
|
28
|
+
send(input: string, options?: ModelCallOptions): Promise<TurnResult>;
|
|
29
|
+
stream(input: string, options?: ModelCallOptions): AsyncGenerator<TurnChunk>;
|
|
30
|
+
submitToolResult(result: ToolResult, options?: ModelCallOptions): Promise<TurnResult>;
|
|
28
31
|
/**
|
|
29
32
|
* Stream-compatible entry for AI SDK (useChat) integration.
|
|
30
33
|
*
|
|
@@ -48,10 +51,35 @@ export declare class HaloAgentImpl {
|
|
|
48
51
|
keepAlive(intervalMs?: number): {
|
|
49
52
|
stop: () => void;
|
|
50
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Streaming entry with full tool-call loop.
|
|
56
|
+
* Accepts both a plain string and a ChatMessage[] (for AI SDK useChat integration).
|
|
57
|
+
*/
|
|
58
|
+
streamText(input: string | ChatMessage[], opts?: StreamTextOptions): StreamTextResult;
|
|
59
|
+
private _streamWithToolLoop;
|
|
60
|
+
/**
|
|
61
|
+
* Generate a structured object from a prompt.
|
|
62
|
+
*
|
|
63
|
+
* Schema (Zod or JSON Schema) is sent as `responseFormat` — does NOT
|
|
64
|
+
* enter StablePrefix. Tools are suppressed for this call.
|
|
65
|
+
*/
|
|
66
|
+
generateObject<T = unknown>(input: string, opts: GenerateObjectOptions<unknown>): Promise<GenerateObjectResult<T>>;
|
|
67
|
+
/**
|
|
68
|
+
* Stream a progressively-built object from a prompt.
|
|
69
|
+
*
|
|
70
|
+
* Schema is sent as `responseFormat` — does NOT enter StablePrefix.
|
|
71
|
+
* Tools are suppressed.
|
|
72
|
+
*/
|
|
73
|
+
streamObject<T = unknown>(input: string, opts: GenerateObjectOptions<unknown>): AsyncGenerator<T>;
|
|
51
74
|
/** Restore conversation state from external history. */
|
|
52
75
|
hydrate(messages: ChatMessage[]): void;
|
|
53
76
|
clearLog(): void;
|
|
54
77
|
setSystem(system: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Execute a tool call with automatic sandbox injection.
|
|
80
|
+
* Detects execute.length: 2 params → passes ToolContext.
|
|
81
|
+
*/
|
|
82
|
+
private _executeTool;
|
|
55
83
|
/** Resolve history, applying ContextStrategy (prefix is read-only). */
|
|
56
84
|
private _resolveHistory;
|
|
57
85
|
private _callModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-impl.d.ts","sourceRoot":"","sources":["../src/session-impl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"session-impl.d.ts","sourceRoot":"","sources":["../src/session-impl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,cAAc,EACd,QAAQ,EAGT,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,UAAU,EAEV,YAAY,EACZ,gBAAgB,EAEhB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAgB,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAIzE,0DAA0D;AAC1D,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,C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y } from "./strategies.js";
|
|
3
|
-
import type { ModelAdapter } from "./model-adapter.js";
|
|
3
|
+
import type { ModelAdapter, ModelCallOptions } from "./model-adapter.js";
|
|
4
|
+
import type { Sandbox } from "./sandbox.js";
|
|
4
5
|
export interface TurnResult {
|
|
5
6
|
content: string;
|
|
6
7
|
toolCalls: ToolCall[];
|
|
@@ -52,9 +53,29 @@ export interface SessionStats {
|
|
|
52
53
|
pricingSnapshot: PricingSnapshot;
|
|
53
54
|
recentDiagnostics: CacheMissReason[];
|
|
54
55
|
}
|
|
56
|
+
export type { ModelCallOptions } from "./model-adapter.js";
|
|
57
|
+
/** Agent-level model defaults. Does NOT enter StablePrefix — safe to change without cache miss. */
|
|
58
|
+
export interface ModelConfig extends ModelCallOptions {
|
|
59
|
+
}
|
|
60
|
+
/** Metadata extracted from a SKILL.md file. */
|
|
61
|
+
export interface SkillMetadata {
|
|
62
|
+
name: string;
|
|
63
|
+
description: string;
|
|
64
|
+
/** Absolute path to the skill directory (for reading SKILL.md body). */
|
|
65
|
+
path: string;
|
|
66
|
+
}
|
|
55
67
|
export interface HaloAgentOptions {
|
|
56
68
|
adapter: ModelAdapter;
|
|
57
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Prefix messages. All messages go into StablePrefix in order.
|
|
71
|
+
* The first `role: "system"` message defines the system prompt;
|
|
72
|
+
* remaining messages act as few-shot examples.
|
|
73
|
+
*
|
|
74
|
+
* Mutually exclusive with `system` / `fewShots`.
|
|
75
|
+
*/
|
|
76
|
+
messages?: ChatMessage[];
|
|
77
|
+
/** @deprecated Use `messages: [{ role: "system", content: "..." }]` instead. */
|
|
78
|
+
system?: string;
|
|
58
79
|
/**
|
|
59
80
|
* Tools available to the model.
|
|
60
81
|
*
|
|
@@ -64,9 +85,78 @@ export interface HaloAgentOptions {
|
|
|
64
85
|
* no `onToolCall` callback needed.
|
|
65
86
|
*/
|
|
66
87
|
tools?: ToolSpec[] | Record<string, ToolDefinition<any>>;
|
|
88
|
+
/** @deprecated Use `messages` with `role: "user"` / `role: "assistant"` entries instead. */
|
|
67
89
|
fewShots?: ChatMessage[];
|
|
90
|
+
/** Agent-level model defaults. Does not enter StablePrefix — safe to change without cache miss. */
|
|
91
|
+
model?: ModelConfig;
|
|
92
|
+
/**
|
|
93
|
+
* Agent Skills (agentskills.io spec).
|
|
94
|
+
* Name + description enter StablePrefix (system prompt).
|
|
95
|
+
* Runtime: a `loadSkill` tool is auto-registered.
|
|
96
|
+
*/
|
|
97
|
+
skills?: SkillMetadata[];
|
|
98
|
+
/**
|
|
99
|
+
* Sandbox for file operations and command execution.
|
|
100
|
+
* Does NOT enter StablePrefix — safe to change without cache miss.
|
|
101
|
+
*/
|
|
102
|
+
sandbox?: Sandbox;
|
|
68
103
|
context?: ContextStrategy;
|
|
69
104
|
repair?: RepairStrategy;
|
|
70
105
|
on?: (event: AgentEvent, payload: unknown) => void;
|
|
71
106
|
}
|
|
107
|
+
/** Named callbacks for streamText(). */
|
|
108
|
+
export interface StreamTextCallbacks {
|
|
109
|
+
onChunk?: (event: {
|
|
110
|
+
chunk: TurnChunk;
|
|
111
|
+
}) => void;
|
|
112
|
+
onStepFinish?: (event: {
|
|
113
|
+
text: string;
|
|
114
|
+
toolCalls: ToolCall[];
|
|
115
|
+
usage: Usage;
|
|
116
|
+
step: number;
|
|
117
|
+
}) => void;
|
|
118
|
+
onFinish?: (event: {
|
|
119
|
+
text: string;
|
|
120
|
+
usage: Usage;
|
|
121
|
+
steps: number;
|
|
122
|
+
toolCalls: ToolCall[];
|
|
123
|
+
}) => void;
|
|
124
|
+
onError?: (error: Error) => void;
|
|
125
|
+
}
|
|
126
|
+
export interface StreamTextOptions extends ModelCallOptions, StreamTextCallbacks {
|
|
127
|
+
maxSteps?: number;
|
|
128
|
+
onToolCall?: (call: ToolCall) => Promise<ToolResult>;
|
|
129
|
+
}
|
|
130
|
+
export interface GenerateObjectOptions<TSchema = Record<string, unknown>> {
|
|
131
|
+
schema: TSchema;
|
|
132
|
+
temperature?: number;
|
|
133
|
+
topP?: number;
|
|
134
|
+
maxTokens?: number;
|
|
135
|
+
seed?: number;
|
|
136
|
+
}
|
|
137
|
+
export interface GenerateObjectResult<T = unknown> {
|
|
138
|
+
object: T;
|
|
139
|
+
usage: Usage;
|
|
140
|
+
}
|
|
141
|
+
export interface StreamTextResult {
|
|
142
|
+
toDataStream(opts?: {
|
|
143
|
+
headers?: Record<string, string>;
|
|
144
|
+
}): Response;
|
|
145
|
+
toReadableStream(): ReadableStream<Uint8Array>;
|
|
146
|
+
toAsyncIterable(): AsyncIterable<TurnChunk>;
|
|
147
|
+
text: Promise<string>;
|
|
148
|
+
usage: Promise<Usage>;
|
|
149
|
+
on(event: "text-delta", fn: (payload: TurnChunk & {
|
|
150
|
+
type: "text-delta";
|
|
151
|
+
}) => void): () => void;
|
|
152
|
+
on(event: "tool-call-delta", fn: (payload: TurnChunk & {
|
|
153
|
+
type: "tool-call-delta";
|
|
154
|
+
}) => void): () => void;
|
|
155
|
+
on(event: "tool-call-ready", fn: (payload: TurnChunk & {
|
|
156
|
+
type: "tool-call-ready";
|
|
157
|
+
}) => void): () => void;
|
|
158
|
+
on(event: "done", fn: (payload: TurnChunk & {
|
|
159
|
+
type: "done";
|
|
160
|
+
}) => void): () => void;
|
|
161
|
+
}
|
|
72
162
|
//# sourceMappingURL=session.d.ts.map
|
package/dist/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src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 @@
|
|
|
1
|
+
import type { SkillMetadata } from "./session.js";
|
|
2
|
+
import type { Sandbox } from "./sandbox.js";
|
|
3
|
+
/**
|
|
4
|
+
* Discover Agent Skills from a set of directories.
|
|
5
|
+
*
|
|
6
|
+
* Scans each directory for subdirectories containing a `SKILL.md` file,
|
|
7
|
+
* parses the YAML frontmatter (`name`, `description`), and returns
|
|
8
|
+
* deduplicated metadata (first skill with a given name wins — allows
|
|
9
|
+
* project-level overrides).
|
|
10
|
+
*
|
|
11
|
+
* When `sandbox` is provided, file operations use the sandbox abstraction
|
|
12
|
+
* instead of raw Node `fs` (enables cross-platform/browser usage).
|
|
13
|
+
* Without sandbox, falls back to `node:fs/promises` (**@nodeOnly**).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const skills = await discoverSkills({
|
|
18
|
+
* directories: [".halo/skills"],
|
|
19
|
+
* sandbox: new VirtualSandbox(),
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function discoverSkills(opts: {
|
|
24
|
+
directories: string[];
|
|
25
|
+
sandbox?: Sandbox;
|
|
26
|
+
}): Promise<SkillMetadata[]>;
|
|
27
|
+
//# sourceMappingURL=skills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../src/skills.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CA6C3B"}
|
package/dist/tool.d.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import type { ToolDefinition } from "./types.js";
|
|
2
|
+
import type { ToolContext } from "./sandbox.js";
|
|
2
3
|
/**
|
|
3
4
|
* Create a tool definition with an optional built-in execute function.
|
|
4
5
|
*
|
|
5
6
|
* This is a **type-level identity** — at runtime it returns the input unchanged.
|
|
6
7
|
* It exists purely for TypeScript generic inference on `TArgs`.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* description: "Get the weather for a city",
|
|
12
|
-
* parameters: {
|
|
13
|
-
* type: "object",
|
|
14
|
-
* properties: { city: { type: "string" } },
|
|
15
|
-
* required: ["city"],
|
|
16
|
-
* },
|
|
17
|
-
* execute: async ({ city }) => `Sunny, 22°C in ${city}`,
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
9
|
+
* Two overloads support both single-arg and dual-arg execute signatures.
|
|
10
|
+
* The agent detects `execute.length` at runtime and passes `ctx` only
|
|
11
|
+
* when the function accepts a second parameter.
|
|
20
12
|
*/
|
|
21
|
-
export declare function tool<TArgs = Record<string, unknown>>(def: ToolDefinition<TArgs>
|
|
13
|
+
export declare function tool<TArgs = Record<string, unknown>>(def: ToolDefinition<TArgs> & {
|
|
14
|
+
execute?: (args: TArgs) => string | Promise<string>;
|
|
15
|
+
}): ToolDefinition<TArgs>;
|
|
16
|
+
export declare function tool<TArgs = Record<string, unknown>>(def: ToolDefinition<TArgs> & {
|
|
17
|
+
execute?: (args: TArgs, ctx: ToolContext) => string | Promise<string>;
|
|
18
|
+
}): ToolDefinition<TArgs>;
|
|
22
19
|
//# sourceMappingURL=tool.d.ts.map
|
package/dist/tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClD,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG;IAC3B,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrD,GACA,cAAc,CAAC,KAAK,CAAC,CAAC;AACzB,wBAAgB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClD,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG;IAC3B,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACvE,GACA,cAAc,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ToolDefinition } from "./types.js";
|
|
2
|
+
/** Safe calculator: evaluates arithmetic expressions with a whitelist. */
|
|
3
|
+
export declare function calculator(): ToolDefinition<{
|
|
4
|
+
expression: string;
|
|
5
|
+
}>;
|
|
6
|
+
/** Time utilities: now, parse, convert between timezones. */
|
|
7
|
+
export declare function datetime(): ToolDefinition<{
|
|
8
|
+
operation: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
tz?: string;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=tools-builtin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools-builtin.d.ts","sourceRoot":"","sources":["../src/tools-builtin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,0EAA0E;AAC1E,wBAAgB,UAAU,IAAI,cAAc,CAAC;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BnE;AAED,6DAA6D;AAC7D,wBAAgB,QAAQ,IAAI,cAAc,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC,CAsED"}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface ChatMessage {
|
|
|
7
7
|
tool_calls?: ToolCall[];
|
|
8
8
|
tool_call_id?: string;
|
|
9
9
|
name?: string;
|
|
10
|
+
/** Hint to ContextStrategy: this message can be dropped first when truncating. */
|
|
11
|
+
discardable?: boolean;
|
|
10
12
|
}
|
|
11
13
|
/** A tool call requested by the model. */
|
|
12
14
|
export interface ToolCall {
|
|
@@ -37,6 +39,15 @@ export interface ToolDefinition<TArgs = Record<string, unknown>> {
|
|
|
37
39
|
/** If provided, run() calls this automatically when the model requests this tool. */
|
|
38
40
|
execute?: (args: TArgs) => string | Promise<string>;
|
|
39
41
|
}
|
|
42
|
+
/** Structured output format. OpenAI-compatible. */
|
|
43
|
+
export interface ResponseFormat {
|
|
44
|
+
type: "json_schema";
|
|
45
|
+
json_schema: {
|
|
46
|
+
name: string;
|
|
47
|
+
schema: Record<string, unknown>;
|
|
48
|
+
strict?: boolean;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
40
51
|
/** Token usage for a single model call. */
|
|
41
52
|
export interface Usage {
|
|
42
53
|
promptTokens: number;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAE5D,6CAA6C;A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,CAAC;IACpC,qFAAqF;IACrF,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrD;AAED,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;CACH;AAED,2CAA2C;AAC3C,MAAM,WAAW,KAAK;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IAEzB,6DAA6D;IAC7D,OAAO,CAAC,EAAE;QACR,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@halo-sdk/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Core types, factory, and session management for Halo AI SDK — cache-aware agent with automatic tool-call loop",
|
|
5
|
-
"license": "MIT",
|
|
6
5
|
"keywords": [
|
|
7
|
-
"ai",
|
|
8
|
-
"llm",
|
|
9
6
|
"agent",
|
|
7
|
+
"ai",
|
|
10
8
|
"cache-first",
|
|
11
9
|
"deepseek",
|
|
10
|
+
"llm",
|
|
12
11
|
"tool-calling"
|
|
13
12
|
],
|
|
13
|
+
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/halo-sdk/halo-ai",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
|
-
"import": "./dist/index.js"
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.cjs"
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
"publishConfig": {
|
|
@@ -33,11 +34,15 @@
|
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"typescript": "^5.8.0",
|
|
36
|
-
"vitest": "^3.0.0"
|
|
37
|
+
"vitest": "^3.0.0",
|
|
38
|
+
"zod": "^4.4.3",
|
|
39
|
+
"zod-to-json-schema": "^3.25.2"
|
|
37
40
|
},
|
|
38
41
|
"scripts": {
|
|
39
|
-
"build": "tsc",
|
|
40
|
-
"dev": "
|
|
42
|
+
"build": "tsc --build --emitDeclarationOnly && tsup",
|
|
43
|
+
"dev": "tsup --watch",
|
|
44
|
+
"clean": "del-cli dist *.tsbuildinfo",
|
|
45
|
+
"publint": "publint",
|
|
41
46
|
"test": "vitest run",
|
|
42
47
|
"test:watch": "vitest"
|
|
43
48
|
}
|
package/dist/halo-agent.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
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
|
package/dist/halo-agent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;IAC5D,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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