@charming_groot/core 0.1.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 (84) hide show
  1. package/dist/config.d.ts +669 -0
  2. package/dist/config.d.ts.map +1 -0
  3. package/dist/config.js +99 -0
  4. package/dist/config.js.map +1 -0
  5. package/dist/errors/base-error.d.ts +29 -0
  6. package/dist/errors/base-error.d.ts.map +1 -0
  7. package/dist/errors/base-error.js +57 -0
  8. package/dist/errors/base-error.js.map +1 -0
  9. package/dist/errors/index.d.ts +2 -0
  10. package/dist/errors/index.d.ts.map +1 -0
  11. package/dist/errors/index.js +2 -0
  12. package/dist/errors/index.js.map +1 -0
  13. package/dist/event-bus.d.ts +14 -0
  14. package/dist/event-bus.d.ts.map +1 -0
  15. package/dist/event-bus.js +64 -0
  16. package/dist/event-bus.js.map +1 -0
  17. package/dist/index.d.ts +11 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +12 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/logger.d.ts +7 -0
  22. package/dist/logger.d.ts.map +1 -0
  23. package/dist/logger.js +33 -0
  24. package/dist/logger.js.map +1 -0
  25. package/dist/registry.d.ts +15 -0
  26. package/dist/registry.d.ts.map +1 -0
  27. package/dist/registry.js +46 -0
  28. package/dist/registry.js.map +1 -0
  29. package/dist/run-context.d.ts +20 -0
  30. package/dist/run-context.d.ts.map +1 -0
  31. package/dist/run-context.js +39 -0
  32. package/dist/run-context.js.map +1 -0
  33. package/dist/types/auth.d.ts +56 -0
  34. package/dist/types/auth.d.ts.map +1 -0
  35. package/dist/types/auth.js +2 -0
  36. package/dist/types/auth.js.map +1 -0
  37. package/dist/types/common.d.ts +15 -0
  38. package/dist/types/common.d.ts.map +1 -0
  39. package/dist/types/common.js +2 -0
  40. package/dist/types/common.js.map +1 -0
  41. package/dist/types/events.d.ts +77 -0
  42. package/dist/types/events.d.ts.map +1 -0
  43. package/dist/types/events.js +2 -0
  44. package/dist/types/events.js.map +1 -0
  45. package/dist/types/index.d.ts +8 -0
  46. package/dist/types/index.d.ts.map +1 -0
  47. package/dist/types/index.js +2 -0
  48. package/dist/types/index.js.map +1 -0
  49. package/dist/types/provider.d.ts +42 -0
  50. package/dist/types/provider.d.ts.map +1 -0
  51. package/dist/types/provider.js +2 -0
  52. package/dist/types/provider.js.map +1 -0
  53. package/dist/types/sandbox.d.ts +27 -0
  54. package/dist/types/sandbox.d.ts.map +1 -0
  55. package/dist/types/sandbox.js +2 -0
  56. package/dist/types/sandbox.js.map +1 -0
  57. package/dist/types/tool.d.ts +43 -0
  58. package/dist/types/tool.d.ts.map +1 -0
  59. package/dist/types/tool.js +8 -0
  60. package/dist/types/tool.js.map +1 -0
  61. package/package.json +34 -0
  62. package/src/config.ts +119 -0
  63. package/src/errors/base-error.ts +66 -0
  64. package/src/errors/index.ts +10 -0
  65. package/src/event-bus.ts +78 -0
  66. package/src/index.ts +74 -0
  67. package/src/logger.ts +43 -0
  68. package/src/registry.ts +62 -0
  69. package/src/run-context.ts +48 -0
  70. package/src/types/auth.ts +79 -0
  71. package/src/types/common.ts +22 -0
  72. package/src/types/events.ts +24 -0
  73. package/src/types/index.ts +54 -0
  74. package/src/types/provider.ts +50 -0
  75. package/src/types/sandbox.ts +29 -0
  76. package/src/types/tool.ts +37 -0
  77. package/tests/config.test.ts +98 -0
  78. package/tests/errors.test.ts +87 -0
  79. package/tests/event-bus.test.ts +89 -0
  80. package/tests/logger.test.ts +34 -0
  81. package/tests/registry.test.ts +90 -0
  82. package/tests/run-context.test.ts +80 -0
  83. package/tsconfig.json +9 -0
  84. package/vitest.config.ts +9 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":""}
@@ -0,0 +1,77 @@
1
+ import type { Message, LlmResponse, ToolCall } from './provider.js';
2
+ import type { ToolResult } from './tool.js';
3
+ import type { ExecutionResult } from './sandbox.js';
4
+ export interface AgentEvents {
5
+ 'agent:start': {
6
+ runId: string;
7
+ model: string;
8
+ startedAt: number;
9
+ };
10
+ 'agent:end': {
11
+ runId: string;
12
+ reason: string;
13
+ durationMs: number;
14
+ iterations: number;
15
+ };
16
+ 'agent:error': {
17
+ runId: string;
18
+ error: Error;
19
+ };
20
+ 'llm:request': {
21
+ runId: string;
22
+ messages: readonly Message[];
23
+ };
24
+ 'llm:response': {
25
+ runId: string;
26
+ response: LlmResponse;
27
+ durationMs: number;
28
+ model: string;
29
+ };
30
+ 'llm:stream': {
31
+ runId: string;
32
+ chunk: string;
33
+ };
34
+ 'tool:start': {
35
+ runId: string;
36
+ toolCall: ToolCall;
37
+ startedAt: number;
38
+ };
39
+ 'tool:end': {
40
+ runId: string;
41
+ toolCall: ToolCall;
42
+ result: ToolResult;
43
+ durationMs: number;
44
+ };
45
+ 'tool:permission': {
46
+ runId: string;
47
+ toolName: string;
48
+ };
49
+ 'sandbox:execute': {
50
+ runId: string;
51
+ language: string;
52
+ };
53
+ 'sandbox:result': {
54
+ runId: string;
55
+ result: ExecutionResult;
56
+ };
57
+ 'mcp:connected': {
58
+ server: string;
59
+ toolCount: number;
60
+ };
61
+ 'mcp:disconnected': {
62
+ server: string;
63
+ };
64
+ 'mcp:tools_changed': {
65
+ server: string;
66
+ tools: readonly string[];
67
+ };
68
+ 'context:assembled': {
69
+ runId: string;
70
+ usage: unknown;
71
+ wasCompressed: boolean;
72
+ toolCount: number;
73
+ };
74
+ }
75
+ export type EventName = keyof AgentEvents;
76
+ export type EventPayload<K extends EventName> = AgentEvents[K];
77
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,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KAAE,CAAC;IACvD,gBAAgB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,eAAe,CAAA;KAAE,CAAC;IAC7D,eAAe,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD,kBAAkB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,mBAAmB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC;IAClE,mBAAmB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,aAAa,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CACnG;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC;AAC1C,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export type { JsonValue, JsonObject, Identifiable, Timestamped, Disposable, } from './common.js';
2
+ export type { ToolParameter, ToolDescription, ToolResult, ITool, } from './tool.js';
3
+ export { toolResultSchema } from './tool.js';
4
+ export type { MessageRole, ToolCall, ToolResultMessage, Message, StopReason, LlmResponse, TokenUsage, StreamEvent, ILlmProvider, } from './provider.js';
5
+ export type { SandboxConfig, ExecutionRequest, ExecutionResult, ISandbox, } from './sandbox.js';
6
+ export type { AgentEvents, EventName, EventPayload, } from './events.js';
7
+ export type { AuthType, NoAuth, ApiKeyAuth, OAuthAuth, AzureAdAuth, AwsIamAuth, GcpServiceAccountAuth, CredentialFileAuth, AuthConfig, IAuthStrategy, ResolvedCredential, } from './auth.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,aAAa,EACb,eAAe,EACf,UAAU,EACV,KAAK,GACN,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,YAAY,EACV,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,YAAY,GACb,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,QAAQ,GACT,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,WAAW,EACX,SAAS,EACT,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,QAAQ,EACR,MAAM,EACN,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,kBAAkB,GACnB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { toolResultSchema } from './tool.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { ToolDescription } from './tool.js';
2
+ export type MessageRole = 'user' | 'assistant' | 'system';
3
+ export interface ToolCall {
4
+ readonly id: string;
5
+ readonly name: string;
6
+ readonly arguments: string;
7
+ }
8
+ export interface ToolResultMessage {
9
+ readonly toolCallId: string;
10
+ readonly content: string;
11
+ }
12
+ export interface Message {
13
+ readonly role: MessageRole;
14
+ readonly content: string;
15
+ readonly toolCalls?: readonly ToolCall[];
16
+ readonly toolResults?: readonly ToolResultMessage[];
17
+ }
18
+ export type StopReason = 'end_turn' | 'tool_use' | 'max_tokens' | 'error';
19
+ export interface LlmResponse {
20
+ readonly content: string;
21
+ readonly stopReason: StopReason;
22
+ readonly toolCalls: readonly ToolCall[];
23
+ readonly usage: TokenUsage;
24
+ }
25
+ export interface TokenUsage {
26
+ readonly inputTokens: number;
27
+ readonly outputTokens: number;
28
+ /** Time spent in extended thinking / <think> block (ms). Only set by providers that support it. */
29
+ readonly thinkingMs?: number;
30
+ }
31
+ export interface StreamEvent {
32
+ readonly type: 'text_delta' | 'tool_call_start' | 'tool_call_delta' | 'done';
33
+ readonly content?: string;
34
+ readonly toolCall?: Partial<ToolCall>;
35
+ readonly response?: LlmResponse;
36
+ }
37
+ export interface ILlmProvider {
38
+ readonly providerId: string;
39
+ chat(messages: readonly Message[], tools?: readonly ToolDescription[]): Promise<LlmResponse>;
40
+ stream(messages: readonly Message[], tools?: readonly ToolDescription[]): AsyncIterable<StreamEvent>;
41
+ }
42
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE1D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,C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AAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,SAAS,eAAe,EAAE,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;CACtG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/types/provider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ export interface SandboxConfig {
2
+ readonly image: string;
3
+ readonly memoryLimitMb: number;
4
+ readonly cpuLimit: number;
5
+ readonly timeoutMs: number;
6
+ readonly workDir: string;
7
+ }
8
+ export interface ExecutionRequest {
9
+ readonly code: string;
10
+ readonly language: string;
11
+ readonly timeoutMs?: number;
12
+ readonly stdin?: string;
13
+ }
14
+ export interface ExecutionResult {
15
+ readonly exitCode: number;
16
+ readonly stdout: string;
17
+ readonly stderr: string;
18
+ readonly timedOut: boolean;
19
+ readonly durationMs: number;
20
+ }
21
+ export interface ISandbox {
22
+ readonly containerId: string;
23
+ initialize(config: SandboxConfig): Promise<void>;
24
+ execute(request: ExecutionRequest): Promise<ExecutionResult>;
25
+ destroy(): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/types/sandbox.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../src/types/sandbox.ts"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ import type { JsonObject } from './common.js';
3
+ import type { RunContext } from '../run-context.js';
4
+ export interface ToolParameter {
5
+ readonly name: string;
6
+ readonly type: string;
7
+ readonly description: string;
8
+ readonly required: boolean;
9
+ }
10
+ export interface ToolDescription {
11
+ readonly name: string;
12
+ readonly description: string;
13
+ readonly parameters: readonly ToolParameter[];
14
+ }
15
+ export interface ToolResult {
16
+ readonly success: boolean;
17
+ readonly output: string;
18
+ readonly error?: string;
19
+ readonly metadata?: JsonObject;
20
+ }
21
+ export interface ITool {
22
+ readonly name: string;
23
+ readonly requiresPermission: boolean;
24
+ describe(): ToolDescription;
25
+ execute(params: JsonObject, context: RunContext): Promise<ToolResult>;
26
+ }
27
+ export declare const toolResultSchema: z.ZodObject<{
28
+ success: z.ZodBoolean;
29
+ output: z.ZodString;
30
+ error: z.ZodOptional<z.ZodString>;
31
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ success: boolean;
34
+ output: string;
35
+ error?: string | undefined;
36
+ metadata?: Record<string, unknown> | undefined;
37
+ }, {
38
+ success: boolean;
39
+ output: string;
40
+ error?: string | undefined;
41
+ metadata?: Record<string, unknown> | undefined;
42
+ }>;
43
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/types/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,SAAS,aAAa,EAAE,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;CAChC;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,QAAQ,IAAI,eAAe,CAAC;IAC5B,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACvE;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;EAK3B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ export const toolResultSchema = z.object({
3
+ success: z.boolean(),
4
+ output: z.string(),
5
+ error: z.string().optional(),
6
+ metadata: z.record(z.unknown()).optional(),
7
+ });
8
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/types/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+BxB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@charming_groot/core",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Core types, interfaces, and utilities for the CLI Agent framework",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest",
21
+ "clean": "rm -rf dist"
22
+ },
23
+ "dependencies": {
24
+ "zod": "^3.22.0",
25
+ "pino": "^8.17.0"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.4.0",
29
+ "vitest": "^1.6.0",
30
+ "@types/node": "^20.11.0"
31
+ },
32
+ "keywords": ["agent", "cli", "llm", "ai", "framework"],
33
+ "license": "MIT"
34
+ }
package/src/config.ts ADDED
@@ -0,0 +1,119 @@
1
+ import { z } from 'zod';
2
+ import { ConfigError } from './errors/base-error.js';
3
+
4
+ const noAuthSchema = z.object({
5
+ type: z.literal('no-auth'),
6
+ });
7
+
8
+ const apiKeyAuthSchema = z.object({
9
+ type: z.literal('api-key'),
10
+ apiKey: z.string().min(1),
11
+ });
12
+
13
+ const oauthAuthSchema = z.object({
14
+ type: z.literal('oauth'),
15
+ clientId: z.string().min(1),
16
+ clientSecret: z.string().min(1),
17
+ tokenUrl: z.string().url(),
18
+ scopes: z.array(z.string()).optional(),
19
+ accessToken: z.string().optional(),
20
+ refreshToken: z.string().optional(),
21
+ });
22
+
23
+ const azureAdAuthSchema = z.object({
24
+ type: z.literal('azure-ad'),
25
+ tenantId: z.string().min(1),
26
+ clientId: z.string().min(1),
27
+ clientSecret: z.string().optional(),
28
+ accessToken: z.string().optional(),
29
+ });
30
+
31
+ const awsIamAuthSchema = z.object({
32
+ type: z.literal('aws-iam'),
33
+ accessKeyId: z.string().optional(),
34
+ secretAccessKey: z.string().optional(),
35
+ sessionToken: z.string().optional(),
36
+ region: z.string().min(1),
37
+ profile: z.string().optional(),
38
+ });
39
+
40
+ const gcpServiceAccountAuthSchema = z.object({
41
+ type: z.literal('gcp-service-account'),
42
+ projectId: z.string().min(1),
43
+ keyFilePath: z.string().optional(),
44
+ accessToken: z.string().optional(),
45
+ });
46
+
47
+ const credentialFileAuthSchema = z.object({
48
+ type: z.literal('credential-file'),
49
+ filePath: z.string().min(1),
50
+ profile: z.string().optional(),
51
+ });
52
+
53
+ export const authConfigSchema = z.discriminatedUnion('type', [
54
+ noAuthSchema,
55
+ apiKeyAuthSchema,
56
+ oauthAuthSchema,
57
+ azureAdAuthSchema,
58
+ awsIamAuthSchema,
59
+ gcpServiceAccountAuthSchema,
60
+ credentialFileAuthSchema,
61
+ ]);
62
+
63
+ export const providerConfigSchema = z.object({
64
+ providerId: z.string().min(1),
65
+ model: z.string().min(1),
66
+ auth: authConfigSchema,
67
+ baseUrl: z.string().url().optional(),
68
+ maxTokens: z.number().int().positive().default(4096),
69
+ temperature: z.number().min(0).max(2).default(0.7),
70
+ });
71
+
72
+ export type ProviderConfig = z.infer<typeof providerConfigSchema>;
73
+
74
+ export const sandboxConfigSchema = z.object({
75
+ image: z.string().default('node:20-slim'),
76
+ memoryLimitMb: z.number().int().positive().default(512),
77
+ cpuLimit: z.number().positive().default(1),
78
+ timeoutMs: z.number().int().positive().default(30000),
79
+ workDir: z.string().default('/workspace'),
80
+ });
81
+
82
+ export type SandboxConfigInput = z.infer<typeof sandboxConfigSchema>;
83
+
84
+ export const agentConfigSchema = z.object({
85
+ provider: providerConfigSchema,
86
+ sandbox: sandboxConfigSchema.optional(),
87
+ maxIterations: z.number().int().positive().default(50),
88
+ systemPrompt: z.string().optional(),
89
+ workingDirectory: z.string().default(process.cwd()),
90
+ });
91
+
92
+ export type AgentConfig = z.infer<typeof agentConfigSchema>;
93
+
94
+ export function parseConfig<T>(schema: z.ZodType<T, z.ZodTypeDef, unknown>, raw: unknown): T {
95
+ const result = schema.safeParse(raw);
96
+ if (!result.success) {
97
+ const messages = result.error.issues
98
+ .map((issue) => `${issue.path.join('.')}: ${issue.message}`)
99
+ .join('; ');
100
+ throw new ConfigError(`Invalid configuration: ${messages}`);
101
+ }
102
+ return result.data;
103
+ }
104
+
105
+ export function parseAgentConfig(raw: unknown): AgentConfig {
106
+ return parseConfig(agentConfigSchema, raw);
107
+ }
108
+
109
+ /**
110
+ * Shorthand: convert a plain apiKey string to an AuthConfig object.
111
+ * Useful for backward-compatible CLI usage.
112
+ */
113
+ export function apiKeyAuth(apiKey: string): { type: 'api-key'; apiKey: string } {
114
+ return { type: 'api-key', apiKey };
115
+ }
116
+
117
+ export function noAuth(): { type: 'no-auth' } {
118
+ return { type: 'no-auth' };
119
+ }
@@ -0,0 +1,66 @@
1
+ export class AgentError extends Error {
2
+ readonly code: string;
3
+ readonly cause?: Error;
4
+
5
+ constructor(message: string, code: string, cause?: Error) {
6
+ super(message);
7
+ this.name = 'AgentError';
8
+ this.code = code;
9
+ this.cause = cause;
10
+ }
11
+ }
12
+
13
+ export class RegistryError extends AgentError {
14
+ constructor(message: string, cause?: Error) {
15
+ super(message, 'REGISTRY_ERROR', cause);
16
+ this.name = 'RegistryError';
17
+ }
18
+ }
19
+
20
+ export class ConfigError extends AgentError {
21
+ constructor(message: string, cause?: Error) {
22
+ super(message, 'CONFIG_ERROR', cause);
23
+ this.name = 'ConfigError';
24
+ }
25
+ }
26
+
27
+ export class ProviderError extends AgentError {
28
+ constructor(message: string, cause?: Error) {
29
+ super(message, 'PROVIDER_ERROR', cause);
30
+ this.name = 'ProviderError';
31
+ }
32
+ }
33
+
34
+ export class ToolExecutionError extends AgentError {
35
+ readonly toolName: string;
36
+
37
+ constructor(toolName: string, message: string, cause?: Error) {
38
+ super(message, 'TOOL_EXECUTION_ERROR', cause);
39
+ this.name = 'ToolExecutionError';
40
+ this.toolName = toolName;
41
+ }
42
+ }
43
+
44
+ export class SandboxError extends AgentError {
45
+ constructor(message: string, cause?: Error) {
46
+ super(message, 'SANDBOX_ERROR', cause);
47
+ this.name = 'SandboxError';
48
+ }
49
+ }
50
+
51
+ export class PermissionDeniedError extends AgentError {
52
+ readonly toolName: string;
53
+
54
+ constructor(toolName: string) {
55
+ super(`Permission denied for tool: ${toolName}`, 'PERMISSION_DENIED');
56
+ this.name = 'PermissionDeniedError';
57
+ this.toolName = toolName;
58
+ }
59
+ }
60
+
61
+ export class AbortError extends AgentError {
62
+ constructor(message = 'Operation aborted') {
63
+ super(message, 'ABORT_ERROR');
64
+ this.name = 'AbortError';
65
+ }
66
+ }
@@ -0,0 +1,10 @@
1
+ export {
2
+ AgentError,
3
+ RegistryError,
4
+ ConfigError,
5
+ ProviderError,
6
+ ToolExecutionError,
7
+ SandboxError,
8
+ PermissionDeniedError,
9
+ AbortError,
10
+ } from './base-error.js';
@@ -0,0 +1,78 @@
1
+ import type { EventName, EventPayload } from './types/events.js';
2
+
3
+ type EventHandler<K extends EventName> = (payload: EventPayload<K>) => void;
4
+
5
+ interface ListenerEntry {
6
+ readonly event: EventName;
7
+ readonly handler: EventHandler<EventName>;
8
+ readonly once: boolean;
9
+ }
10
+
11
+ export class EventBus {
12
+ private readonly listeners = new Map<EventName, ListenerEntry[]>();
13
+
14
+ on<K extends EventName>(event: K, handler: EventHandler<K>): () => void {
15
+ const entry: ListenerEntry = {
16
+ event,
17
+ handler: handler as EventHandler<EventName>,
18
+ once: false,
19
+ };
20
+ this.addListener(event, entry);
21
+ return () => this.removeListener(event, entry);
22
+ }
23
+
24
+ once<K extends EventName>(event: K, handler: EventHandler<K>): () => void {
25
+ const entry: ListenerEntry = {
26
+ event,
27
+ handler: handler as EventHandler<EventName>,
28
+ once: true,
29
+ };
30
+ this.addListener(event, entry);
31
+ return () => this.removeListener(event, entry);
32
+ }
33
+
34
+ emit<K extends EventName>(event: K, payload: EventPayload<K>): void {
35
+ const entries = this.listeners.get(event);
36
+ if (!entries) return;
37
+
38
+ const toRemove: ListenerEntry[] = [];
39
+ for (const entry of entries) {
40
+ entry.handler(payload as EventPayload<EventName>);
41
+ if (entry.once) {
42
+ toRemove.push(entry);
43
+ }
44
+ }
45
+
46
+ for (const entry of toRemove) {
47
+ this.removeListener(event, entry);
48
+ }
49
+ }
50
+
51
+ removeAllListeners(event?: EventName): void {
52
+ if (event) {
53
+ this.listeners.delete(event);
54
+ } else {
55
+ this.listeners.clear();
56
+ }
57
+ }
58
+
59
+ listenerCount(event: EventName): number {
60
+ return this.listeners.get(event)?.length ?? 0;
61
+ }
62
+
63
+ private addListener(event: EventName, entry: ListenerEntry): void {
64
+ const existing = this.listeners.get(event) ?? [];
65
+ this.listeners.set(event, [...existing, entry]);
66
+ }
67
+
68
+ private removeListener(event: EventName, entry: ListenerEntry): void {
69
+ const existing = this.listeners.get(event);
70
+ if (!existing) return;
71
+ const filtered = existing.filter((e) => e !== entry);
72
+ if (filtered.length === 0) {
73
+ this.listeners.delete(event);
74
+ } else {
75
+ this.listeners.set(event, filtered);
76
+ }
77
+ }
78
+ }
package/src/index.ts ADDED
@@ -0,0 +1,74 @@
1
+ // Types
2
+ export type {
3
+ JsonValue,
4
+ JsonObject,
5
+ Identifiable,
6
+ Timestamped,
7
+ Disposable,
8
+ ToolParameter,
9
+ ToolDescription,
10
+ ToolResult,
11
+ ITool,
12
+ MessageRole,
13
+ ToolCall,
14
+ ToolResultMessage,
15
+ Message,
16
+ StopReason,
17
+ LlmResponse,
18
+ TokenUsage,
19
+ StreamEvent,
20
+ ILlmProvider,
21
+ SandboxConfig,
22
+ ExecutionRequest,
23
+ ExecutionResult,
24
+ ISandbox,
25
+ AgentEvents,
26
+ EventName,
27
+ EventPayload,
28
+ AuthType,
29
+ NoAuth,
30
+ ApiKeyAuth,
31
+ OAuthAuth,
32
+ AzureAdAuth,
33
+ AwsIamAuth,
34
+ GcpServiceAccountAuth,
35
+ CredentialFileAuth,
36
+ AuthConfig,
37
+ IAuthStrategy,
38
+ ResolvedCredential,
39
+ } from './types/index.js';
40
+ export { toolResultSchema } from './types/index.js';
41
+
42
+ // Core modules
43
+ export { Registry } from './registry.js';
44
+ export { EventBus } from './event-bus.js';
45
+ export { RunContext } from './run-context.js';
46
+
47
+ // Config
48
+ export {
49
+ providerConfigSchema,
50
+ authConfigSchema,
51
+ sandboxConfigSchema,
52
+ agentConfigSchema,
53
+ parseConfig,
54
+ parseAgentConfig,
55
+ apiKeyAuth,
56
+ noAuth,
57
+ } from './config.js';
58
+ export type { ProviderConfig, SandboxConfigInput, AgentConfig } from './config.js';
59
+
60
+ // Logger
61
+ export { createLogger, createChildLogger, getRootLogger } from './logger.js';
62
+ export type { LogLevel, AgentLogger } from './logger.js';
63
+
64
+ // Errors
65
+ export {
66
+ AgentError,
67
+ RegistryError,
68
+ ConfigError,
69
+ ProviderError,
70
+ ToolExecutionError,
71
+ SandboxError,
72
+ PermissionDeniedError,
73
+ AbortError,
74
+ } from './errors/index.js';